Commit 8582bcc8 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (ltc2978) Introduce feature flags

It is becoming cumbersom to track per-chip feature support.
Introduce feature flag to simplify the code.
Tested-by: default avatarMichael Jones <mike@proclivis.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 2238835c
...@@ -97,10 +97,14 @@ struct ltc2978_data { ...@@ -97,10 +97,14 @@ struct ltc2978_data {
u16 pin_min, pin_max; u16 pin_min, pin_max;
u16 temp2_max; u16 temp2_max;
struct pmbus_driver_info info; struct pmbus_driver_info info;
u32 features;
}; };
#define to_ltc2978_data(x) container_of(x, struct ltc2978_data, info) #define to_ltc2978_data(x) container_of(x, struct ltc2978_data, info)
#define FEAT_CLEAR_PEAKS BIT(0)
#define has_clear_peaks(d) ((d)->features & FEAT_CLEAR_PEAKS)
static inline int lin11_to_val(int data) static inline int lin11_to_val(int data)
{ {
s16 e = ((s16)data) >> 11; s16 e = ((s16)data) >> 11;
...@@ -374,13 +378,12 @@ static int ltc3883_read_word_data(struct i2c_client *client, int page, int reg) ...@@ -374,13 +378,12 @@ static int ltc3883_read_word_data(struct i2c_client *client, int page, int reg)
return ret; return ret;
} }
static int ltc2978_clear_peaks(struct i2c_client *client, int page, static int ltc2978_clear_peaks(struct ltc2978_data *data,
enum chips id) struct i2c_client *client, int page)
{ {
int ret; int ret;
if (id == ltc3880 || id == ltc3882 || id == ltc3883 || id == ltc3887 || if (has_clear_peaks(data))
id == ltm4676)
ret = pmbus_write_byte(client, 0, LTC3880_MFR_CLEAR_PEAKS); ret = pmbus_write_byte(client, 0, LTC3880_MFR_CLEAR_PEAKS);
else else
ret = pmbus_write_byte(client, page, PMBUS_CLEAR_FAULTS); ret = pmbus_write_byte(client, page, PMBUS_CLEAR_FAULTS);
...@@ -399,36 +402,36 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page, ...@@ -399,36 +402,36 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page,
case PMBUS_VIRT_RESET_IIN_HISTORY: case PMBUS_VIRT_RESET_IIN_HISTORY:
data->iin_max = 0x7c00; data->iin_max = 0x7c00;
data->iin_min = 0x7bff; data->iin_min = 0x7bff;
ret = ltc2978_clear_peaks(client, 0, data->id); ret = ltc2978_clear_peaks(data, client, 0);
break; break;
case PMBUS_VIRT_RESET_PIN_HISTORY: case PMBUS_VIRT_RESET_PIN_HISTORY:
data->pin_max = 0x7c00; data->pin_max = 0x7c00;
data->pin_min = 0x7bff; data->pin_min = 0x7bff;
ret = ltc2978_clear_peaks(client, 0, data->id); ret = ltc2978_clear_peaks(data, client, 0);
break; break;
case PMBUS_VIRT_RESET_IOUT_HISTORY: case PMBUS_VIRT_RESET_IOUT_HISTORY:
data->iout_max[page] = 0x7c00; data->iout_max[page] = 0x7c00;
data->iout_min[page] = 0xfbff; data->iout_min[page] = 0xfbff;
ret = ltc2978_clear_peaks(client, page, data->id); ret = ltc2978_clear_peaks(data, client, page);
break; break;
case PMBUS_VIRT_RESET_TEMP2_HISTORY: case PMBUS_VIRT_RESET_TEMP2_HISTORY:
data->temp2_max = 0x7c00; data->temp2_max = 0x7c00;
ret = ltc2978_clear_peaks(client, page, data->id); ret = ltc2978_clear_peaks(data, client, page);
break; break;
case PMBUS_VIRT_RESET_VOUT_HISTORY: case PMBUS_VIRT_RESET_VOUT_HISTORY:
data->vout_min[page] = 0xffff; data->vout_min[page] = 0xffff;
data->vout_max[page] = 0; data->vout_max[page] = 0;
ret = ltc2978_clear_peaks(client, page, data->id); ret = ltc2978_clear_peaks(data, client, page);
break; break;
case PMBUS_VIRT_RESET_VIN_HISTORY: case PMBUS_VIRT_RESET_VIN_HISTORY:
data->vin_min = 0x7bff; data->vin_min = 0x7bff;
data->vin_max = 0x7c00; data->vin_max = 0x7c00;
ret = ltc2978_clear_peaks(client, page, data->id); ret = ltc2978_clear_peaks(data, client, page);
break; break;
case PMBUS_VIRT_RESET_TEMP_HISTORY: case PMBUS_VIRT_RESET_TEMP_HISTORY:
data->temp_min[page] = 0x7bff; data->temp_min[page] = 0x7bff;
data->temp_max[page] = 0x7c00; data->temp_max[page] = 0x7c00;
ret = ltc2978_clear_peaks(client, page, data->id); ret = ltc2978_clear_peaks(data, client, page);
break; break;
default: default:
ret = -ENODATA; ret = -ENODATA;
...@@ -603,6 +606,7 @@ static int ltc2978_probe(struct i2c_client *client, ...@@ -603,6 +606,7 @@ static int ltc2978_probe(struct i2c_client *client,
case ltc3880: case ltc3880:
case ltc3887: case ltc3887:
case ltm4676: case ltm4676:
data->features |= FEAT_CLEAR_PEAKS;
info->read_word_data = ltc3880_read_word_data; info->read_word_data = ltc3880_read_word_data;
info->pages = LTC3880_NUM_PAGES; info->pages = LTC3880_NUM_PAGES;
info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN
...@@ -617,6 +621,7 @@ static int ltc2978_probe(struct i2c_client *client, ...@@ -617,6 +621,7 @@ static int ltc2978_probe(struct i2c_client *client,
| PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
break; break;
case ltc3882: case ltc3882:
data->features |= FEAT_CLEAR_PEAKS;
info->read_word_data = ltc3880_read_word_data; info->read_word_data = ltc3880_read_word_data;
info->pages = LTC3880_NUM_PAGES; info->pages = LTC3880_NUM_PAGES;
info->func[0] = PMBUS_HAVE_VIN info->func[0] = PMBUS_HAVE_VIN
...@@ -631,6 +636,7 @@ static int ltc2978_probe(struct i2c_client *client, ...@@ -631,6 +636,7 @@ static int ltc2978_probe(struct i2c_client *client,
| PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
break; break;
case ltc3883: case ltc3883:
data->features |= FEAT_CLEAR_PEAKS;
info->read_word_data = ltc3883_read_word_data; info->read_word_data = ltc3883_read_word_data;
info->pages = LTC3883_NUM_PAGES; info->pages = LTC3883_NUM_PAGES;
info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment