hwmon: (adm1275) Introduce new feature flags
Introduce have_vout, have_vaux_status, have_pin_max, and have_uc_fault to simplify adding support for new chips. Also simplify error returns where appropriate to return immediately on error. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
904b296f30
commit
9048539b7c
|
@ -57,6 +57,10 @@ enum chips { adm1075, adm1275, adm1276 };
|
||||||
struct adm1275_data {
|
struct adm1275_data {
|
||||||
int id;
|
int id;
|
||||||
bool have_oc_fault;
|
bool have_oc_fault;
|
||||||
|
bool have_uc_fault;
|
||||||
|
bool have_vout;
|
||||||
|
bool have_vaux_status;
|
||||||
|
bool have_pin_max;
|
||||||
struct pmbus_driver_info info;
|
struct pmbus_driver_info info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,40 +105,30 @@ static int adm1275_read_word_data(struct i2c_client *client, int page, int reg)
|
||||||
|
|
||||||
switch (reg) {
|
switch (reg) {
|
||||||
case PMBUS_IOUT_UC_FAULT_LIMIT:
|
case PMBUS_IOUT_UC_FAULT_LIMIT:
|
||||||
if (data->have_oc_fault) {
|
if (!data->have_uc_fault)
|
||||||
ret = -ENXIO;
|
return -ENXIO;
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
|
ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
|
||||||
break;
|
break;
|
||||||
case PMBUS_IOUT_OC_FAULT_LIMIT:
|
case PMBUS_IOUT_OC_FAULT_LIMIT:
|
||||||
if (!data->have_oc_fault) {
|
if (!data->have_oc_fault)
|
||||||
ret = -ENXIO;
|
return -ENXIO;
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
|
ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
|
||||||
break;
|
break;
|
||||||
case PMBUS_VOUT_OV_WARN_LIMIT:
|
case PMBUS_VOUT_OV_WARN_LIMIT:
|
||||||
if (data->id != adm1075) {
|
if (data->have_vout)
|
||||||
ret = -ENODATA;
|
return -ENODATA;
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = pmbus_read_word_data(client, 0,
|
ret = pmbus_read_word_data(client, 0,
|
||||||
ADM1075_VAUX_OV_WARN_LIMIT);
|
ADM1075_VAUX_OV_WARN_LIMIT);
|
||||||
break;
|
break;
|
||||||
case PMBUS_VOUT_UV_WARN_LIMIT:
|
case PMBUS_VOUT_UV_WARN_LIMIT:
|
||||||
if (data->id != adm1075) {
|
if (data->have_vout)
|
||||||
ret = -ENODATA;
|
return -ENODATA;
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = pmbus_read_word_data(client, 0,
|
ret = pmbus_read_word_data(client, 0,
|
||||||
ADM1075_VAUX_UV_WARN_LIMIT);
|
ADM1075_VAUX_UV_WARN_LIMIT);
|
||||||
break;
|
break;
|
||||||
case PMBUS_READ_VOUT:
|
case PMBUS_READ_VOUT:
|
||||||
if (data->id != adm1075) {
|
if (data->have_vout)
|
||||||
ret = -ENODATA;
|
return -ENODATA;
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX);
|
ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX);
|
||||||
break;
|
break;
|
||||||
case PMBUS_VIRT_READ_IOUT_MAX:
|
case PMBUS_VIRT_READ_IOUT_MAX:
|
||||||
|
@ -147,10 +141,8 @@ static int adm1275_read_word_data(struct i2c_client *client, int page, int reg)
|
||||||
ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN);
|
ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN);
|
||||||
break;
|
break;
|
||||||
case PMBUS_VIRT_READ_PIN_MAX:
|
case PMBUS_VIRT_READ_PIN_MAX:
|
||||||
if (data->id == adm1275) {
|
if (!data->have_pin_max)
|
||||||
ret = -ENXIO;
|
return -ENXIO;
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = pmbus_read_word_data(client, 0, ADM1276_PEAK_PIN);
|
ret = pmbus_read_word_data(client, 0, ADM1276_PEAK_PIN);
|
||||||
break;
|
break;
|
||||||
case PMBUS_VIRT_RESET_IOUT_HISTORY:
|
case PMBUS_VIRT_RESET_IOUT_HISTORY:
|
||||||
|
@ -158,8 +150,8 @@ static int adm1275_read_word_data(struct i2c_client *client, int page, int reg)
|
||||||
case PMBUS_VIRT_RESET_VIN_HISTORY:
|
case PMBUS_VIRT_RESET_VIN_HISTORY:
|
||||||
break;
|
break;
|
||||||
case PMBUS_VIRT_RESET_PIN_HISTORY:
|
case PMBUS_VIRT_RESET_PIN_HISTORY:
|
||||||
if (data->id == adm1275)
|
if (!data->have_pin_max)
|
||||||
ret = -ENXIO;
|
return -ENXIO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = -ENODATA;
|
ret = -ENODATA;
|
||||||
|
@ -215,29 +207,31 @@ static int adm1275_read_byte_data(struct i2c_client *client, int page, int reg)
|
||||||
ret = pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT);
|
ret = pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
|
if (!data->have_oc_fault && !data->have_uc_fault)
|
||||||
|
break;
|
||||||
mfr_status = pmbus_read_byte_data(client, page,
|
mfr_status = pmbus_read_byte_data(client, page,
|
||||||
PMBUS_STATUS_MFR_SPECIFIC);
|
PMBUS_STATUS_MFR_SPECIFIC);
|
||||||
if (mfr_status < 0) {
|
if (mfr_status < 0)
|
||||||
ret = mfr_status;
|
return mfr_status;
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (mfr_status & ADM1275_MFR_STATUS_IOUT_WARN2) {
|
if (mfr_status & ADM1275_MFR_STATUS_IOUT_WARN2) {
|
||||||
ret |= data->have_oc_fault ?
|
ret |= data->have_oc_fault ?
|
||||||
PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT;
|
PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PMBUS_STATUS_VOUT:
|
case PMBUS_STATUS_VOUT:
|
||||||
if (data->id != adm1075) {
|
if (data->have_vout)
|
||||||
ret = -ENODATA;
|
return -ENODATA;
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
mfr_status = pmbus_read_byte_data(client, 0,
|
if (data->have_vaux_status) {
|
||||||
ADM1075_VAUX_STATUS);
|
mfr_status = pmbus_read_byte_data(client, 0,
|
||||||
if (mfr_status & ADM1075_VAUX_OV_WARN)
|
ADM1075_VAUX_STATUS);
|
||||||
ret |= PB_VOLTAGE_OV_WARNING;
|
if (mfr_status < 0)
|
||||||
if (mfr_status & ADM1075_VAUX_UV_WARN)
|
return mfr_status;
|
||||||
ret |= PB_VOLTAGE_UV_WARNING;
|
if (mfr_status & ADM1075_VAUX_OV_WARN)
|
||||||
|
ret |= PB_VOLTAGE_OV_WARNING;
|
||||||
|
if (mfr_status & ADM1075_VAUX_UV_WARN)
|
||||||
|
ret |= PB_VOLTAGE_UV_WARNING;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = -ENODATA;
|
ret = -ENODATA;
|
||||||
|
@ -328,11 +322,15 @@ static int adm1275_probe(struct i2c_client *client,
|
||||||
info->read_byte_data = adm1275_read_byte_data;
|
info->read_byte_data = adm1275_read_byte_data;
|
||||||
info->write_word_data = adm1275_write_word_data;
|
info->write_word_data = adm1275_write_word_data;
|
||||||
|
|
||||||
if (device_config & ADM1275_IOUT_WARN2_SELECT)
|
|
||||||
data->have_oc_fault = true;
|
|
||||||
|
|
||||||
switch (data->id) {
|
switch (data->id) {
|
||||||
case adm1075:
|
case adm1075:
|
||||||
|
if (device_config & ADM1275_IOUT_WARN2_SELECT)
|
||||||
|
data->have_oc_fault = true;
|
||||||
|
else
|
||||||
|
data->have_uc_fault = true;
|
||||||
|
data->have_pin_max = true;
|
||||||
|
data->have_vaux_status = true;
|
||||||
|
|
||||||
coefficients = adm1075_coefficients;
|
coefficients = adm1075_coefficients;
|
||||||
vindex = 0;
|
vindex = 0;
|
||||||
switch (config & ADM1075_IRANGE_MASK) {
|
switch (config & ADM1075_IRANGE_MASK) {
|
||||||
|
@ -356,6 +354,12 @@ static int adm1275_probe(struct i2c_client *client,
|
||||||
PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
|
PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
|
||||||
break;
|
break;
|
||||||
case adm1275:
|
case adm1275:
|
||||||
|
if (device_config & ADM1275_IOUT_WARN2_SELECT)
|
||||||
|
data->have_oc_fault = true;
|
||||||
|
else
|
||||||
|
data->have_uc_fault = true;
|
||||||
|
data->have_vout = true;
|
||||||
|
|
||||||
coefficients = adm1275_coefficients;
|
coefficients = adm1275_coefficients;
|
||||||
vindex = (config & ADM1275_VRANGE) ? 0 : 1;
|
vindex = (config & ADM1275_VRANGE) ? 0 : 1;
|
||||||
cindex = 2;
|
cindex = 2;
|
||||||
|
@ -368,6 +372,13 @@ static int adm1275_probe(struct i2c_client *client,
|
||||||
PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
|
PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
|
||||||
break;
|
break;
|
||||||
case adm1276:
|
case adm1276:
|
||||||
|
if (device_config & ADM1275_IOUT_WARN2_SELECT)
|
||||||
|
data->have_oc_fault = true;
|
||||||
|
else
|
||||||
|
data->have_uc_fault = true;
|
||||||
|
data->have_vout = true;
|
||||||
|
data->have_pin_max = true;
|
||||||
|
|
||||||
coefficients = adm1276_coefficients;
|
coefficients = adm1276_coefficients;
|
||||||
vindex = (config & ADM1275_VRANGE) ? 0 : 1;
|
vindex = (config & ADM1275_VRANGE) ? 0 : 1;
|
||||||
cindex = 2;
|
cindex = 2;
|
||||||
|
|
Loading…
Reference in New Issue