info = pmbus_get_driver_info(psu->client);
data = to_max20730_data(info);
switch (idx) { case MAX20730_DEBUGFS_VOUT_MIN:
ret = VOLT_FROM_REG(data->mfr_voutmin * 10000);
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d.%d\n",
ret / 10000, ret % 10000); break; case MAX20730_DEBUGFS_FREQUENCY:
val = (data->mfr_devset1 & MAX20730_MFR_DEVSET1_FSW_MASK)
>> MAX20730_MFR_DEVSET1_FSW_BIT_POS;
if (val == 0)
ret = 400; elseif (val == 1)
ret = 500; elseif (val == 2 || val == 3)
ret = 600; elseif (val == 4)
ret = 700; elseif (val == 5)
ret = 800; else
ret = 900;
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); break; case MAX20730_DEBUGFS_PG_DELAY:
val = (data->mfr_devset1 & MAX20730_MFR_DEVSET1_TSTAT_MASK)
>> MAX20730_MFR_DEVSET1_TSTAT_BIT_POS;
if (val == 0)
result = "2000\n"; elseif (val == 1)
result = "125\n"; elseif (val == 2)
result = "62.5\n"; else
result = "32\n"; break; case MAX20730_DEBUGFS_INTERNAL_GAIN:
val = (data->mfr_devset1 & MAX20730_MFR_DEVSET1_RGAIN_MASK)
>> MAX20730_MFR_DEVSET1_RGAIN_BIT_POS;
if (data->id == max20734) { /* AN6209 */ if (val == 0)
result = "0.8\n"; elseif (val == 1)
result = "3.2\n"; elseif (val == 2)
result = "1.6\n"; else
result = "6.4\n";
} elseif (data->id == max20730 || data->id == max20710) { /* AN6042 or AN6140 */ if (val == 0)
result = "0.9\n"; elseif (val == 1)
result = "3.6\n"; elseif (val == 2)
result = "1.8\n"; else
result = "7.2\n";
} elseif (data->id == max20743) { /* AN6042 */ if (val == 0)
result = "0.45\n"; elseif (val == 1)
result = "1.8\n"; elseif (val == 2)
result = "0.9\n"; else
result = "3.6\n";
} else {
result = "Not supported\n";
} break; case MAX20730_DEBUGFS_BOOT_VOLTAGE:
val = (data->mfr_devset1 & MAX20730_MFR_DEVSET1_VBOOT_MASK)
>> MAX20730_MFR_DEVSET1_VBOOT_BIT_POS;
if (val == 0)
result = "0.6484\n"; elseif (val == 1)
result = "0.8984\n"; elseif (val == 2)
result = "1.0\n"; else
result = "Invalid\n"; break; case MAX20730_DEBUGFS_OUT_V_RAMP_RATE:
val = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_VRATE)
>> MAX20730_MFR_DEVSET2_VRATE_BIT_POS;
if (val == 0)
result = "4\n"; elseif (val == 1)
result = "2\n"; elseif (val == 2)
result = "1\n"; else
result = "Invalid\n"; break; case MAX20730_DEBUGFS_OC_PROTECT_MODE:
ret = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_OCPM_MASK)
>> MAX20730_MFR_DEVSET2_OCPM_BIT_POS;
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); break; case MAX20730_DEBUGFS_SS_TIMING:
val = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_SS_MASK)
>> MAX20730_MFR_DEVSET2_SS_BIT_POS;
if (val == 0)
result = "0.75\n"; elseif (val == 1)
result = "1.5\n"; elseif (val == 2)
result = "3\n"; else
result = "6\n"; break; case MAX20730_DEBUGFS_IMAX:
ret = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_IMAX_MASK)
>> MAX20730_MFR_DEVSET2_IMAX_BIT_POS;
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); break; case MAX20730_DEBUGFS_OPERATION:
ret = i2c_smbus_read_byte_data(psu->client, PMBUS_OPERATION); if (ret < 0) return ret;
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); break; case MAX20730_DEBUGFS_ON_OFF_CONFIG:
ret = i2c_smbus_read_byte_data(psu->client, PMBUS_ON_OFF_CONFIG); if (ret < 0) return ret;
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); break; case MAX20730_DEBUGFS_SMBALERT_MASK:
ret = i2c_smbus_read_word_data(psu->client,
PMBUS_SMB_ALERT_MASK); if (ret < 0) return ret;
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); break; case MAX20730_DEBUGFS_VOUT_MODE:
ret = i2c_smbus_read_byte_data(psu->client, PMBUS_VOUT_MODE); if (ret < 0) return ret;
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); break; case MAX20730_DEBUGFS_VOUT_COMMAND:
ret = i2c_smbus_read_word_data(psu->client, PMBUS_VOUT_COMMAND); if (ret < 0) return ret;
ret = VOLT_FROM_REG(ret * 10000);
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d.%d\n", ret / 10000, ret % 10000); break; case MAX20730_DEBUGFS_VOUT_MAX:
ret = i2c_smbus_read_word_data(psu->client, PMBUS_VOUT_MAX); if (ret < 0) return ret;
ret = VOLT_FROM_REG(ret * 10000);
len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d.%d\n", ret / 10000, ret % 10000); break; default:
result = "Invalid\n";
}
len = strlen(result); return simple_read_from_buffer(buf, count, ppos, result, len);
}
/* * Convert discreet value to direct data format. Strictly speaking, all passed * values are constants, so we could do that calculation manually. On the * downside, that would make the driver more difficult to maintain, so lets * use this approach.
*/ static u16 val_to_direct(int v, enum pmbus_sensor_classes class, conststruct pmbus_driver_info *info)
{ int R = info->R[class] - 3; /* take milli-units into account */ int b = info->b[class] * 1000; long d;
d = v * info->m[class] + b; /* * R < 0 is true for all callers, so we don't need to bother * about the R > 0 case.
*/ while (R < 0) {
d = DIV_ROUND_CLOSEST(d, 10);
R++;
} return (u16)d;
}
staticlong direct_to_val(u16 w, enum pmbus_sensor_classes class, conststruct pmbus_driver_info *info)
{ int R = info->R[class] - 3; int b = info->b[class] * 1000; int m = info->m[class]; long d = (s16)w;
if (m == 0) return 0;
while (R < 0) {
d *= 10;
R++;
}
d = (d - b) / m; return d;
}
staticint max20730_read_word_data(struct i2c_client *client, int page, int phase, int reg)
{ conststruct pmbus_driver_info *info = pmbus_get_driver_info(client); conststruct max20730_data *data = to_max20730_data(info); int ret = 0;
u32 max_c;
switch (reg) { case PMBUS_OT_FAULT_LIMIT: switch ((data->mfr_devset1 >> 11) & 0x3) { case 0x0:
ret = val_to_direct(150000, PSC_TEMPERATURE, info); break; case 0x1:
ret = val_to_direct(130000, PSC_TEMPERATURE, info); break; default:
ret = -ENODATA; break;
} break; case PMBUS_IOUT_OC_FAULT_LIMIT:
max_c = max_current[data->id][(data->mfr_devset1 >> 5) & 0x3];
ret = val_to_direct(max_c, PSC_CURRENT_OUT, info); break; case PMBUS_READ_VOUT:
ret = pmbus_read_word_data(client, page, phase, reg); if (ret > 0 && data->vout_voltage_divider[0] && data->vout_voltage_divider[1]) {
u64 temp = DIV_ROUND_CLOSEST_ULL((u64)ret * data->vout_voltage_divider[1],
data->vout_voltage_divider[0]);
ret = clamp_val(temp, 0, 0xffff);
} break; default:
ret = -ENODATA; break;
} return ret;
}
staticint max20730_write_word_data(struct i2c_client *client, int page, int reg, u16 word)
{ struct pmbus_driver_info *info; struct max20730_data *data;
u16 devset1; int ret = 0; int idx;
info = (struct pmbus_driver_info *)pmbus_get_driver_info(client);
data = to_max20730_data(info);
/* * Values in the datasheet are adjusted for temperature and * for the relationship between Vin and Vout. * Unfortunately, the data sheet suggests that Vout measurement * may be scaled with a resistor array. This is indeed the case * at least on the evaulation boards. As a result, any in-driver * adjustments would either be wrong or require elaborate means * to configure the scaling. Instead of doing that, just report * raw values and let userspace handle adjustments.
*/
.format[PSC_CURRENT_OUT] = direct,
.m[PSC_CURRENT_OUT] = 153,
.b[PSC_CURRENT_OUT] = 4976,
.R[PSC_CURRENT_OUT] = -1,
if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_READ_BYTE_DATA |
I2C_FUNC_SMBUS_READ_WORD_DATA |
I2C_FUNC_SMBUS_BLOCK_DATA)) return -ENODEV;
ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf); if (ret < 0) {
dev_err(&client->dev, "Failed to read Manufacturer ID\n"); return ret;
} if (ret != 5 || strncmp(buf, "MAXIM", 5)) {
buf[ret] = '\0';
dev_err(dev, "Unsupported Manufacturer ID '%s'\n", buf); return -ENODEV;
}
/* * The chips support reading PMBUS_MFR_MODEL. On both MAX20730 * and MAX20734, reading it returns M20743. Presumably that is * the reason why the command is not documented. Unfortunately, * that means that there is no reliable means to detect the chip. * However, we can at least detect the chip series. Compare * the returned value against 'M20743' and bail out if there is * a mismatch. If that doesn't work for all chips, we may have * to remove this check.
*/
ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf); if (ret < 0) {
dev_err(dev, "Failed to read Manufacturer Model\n"); return ret;
} if (ret != 6 || strncmp(buf, "M20743", 6)) {
buf[ret] = '\0';
dev_err(dev, "Unsupported Manufacturer Model '%s'\n", buf); return -ENODEV;
}
ret = i2c_smbus_read_block_data(client, PMBUS_MFR_REVISION, buf); if (ret < 0) {
dev_err(dev, "Failed to read Manufacturer Revision\n"); return ret;
} if (ret != 1 || buf[0] != 'F') {
buf[ret] = '\0';
dev_err(dev, "Unsupported Manufacturer Revision '%s'\n", buf); return -ENODEV;
}
if (client->dev.of_node)
chip_id = (uintptr_t)of_device_get_match_data(dev); else
chip_id = i2c_match_id(max20730_id, client)->driver_data;
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM;
data->id = chip_id;
mutex_init(&data->lock);
memcpy(&data->info, &max20730_info[chip_id], sizeof(data->info)); if (of_property_read_u32_array(client->dev.of_node, "vout-voltage-divider",
data->vout_voltage_divider,
ARRAY_SIZE(data->vout_voltage_divider)) != 0)
memset(data->vout_voltage_divider, 0, sizeof(data->vout_voltage_divider)); if (data->vout_voltage_divider[1] < data->vout_voltage_divider[0]) {
dev_err(dev, "The total resistance of voltage divider is less than output resistance\n"); return -EINVAL;
}
ret = i2c_smbus_read_word_data(client, MAX20730_MFR_DEVSET1); if (ret < 0) return ret;
data->mfr_devset1 = ret;
ret = pmbus_do_probe(client, &data->info); if (ret < 0) return ret;
ret = max20730_init_debugfs(client, data); if (ret)
dev_warn(dev, "Failed to register debugfs: %d\n",
ret);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.