Skip to content

Commit 19932f8

Browse files
actorrenogroeck
authored andcommitted
hwmon: (pmbus/max34440) Fix support for max34451
The max344** family has an issue with some PMBUS address being switched. This includes max34451 however version MAX34451-NA6 and later has this issue fixed and this commit supports that update. Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com> Link: https://lore.kernel.org/r/20250407-dev_adpm12160-v3-1-9cd3095445c8@analog.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 9c47e45 commit 19932f8

1 file changed

Lines changed: 44 additions & 4 deletions

File tree

drivers/hwmon/pmbus/max34440.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,21 @@ enum chips { max34440, max34441, max34446, max34451, max34460, max34461 };
3434
/*
3535
* The whole max344* family have IOUT_OC_WARN_LIMIT and IOUT_OC_FAULT_LIMIT
3636
* swapped from the standard pmbus spec addresses.
37+
* For max34451, version MAX34451ETNA6+ and later has this issue fixed.
3738
*/
3839
#define MAX34440_IOUT_OC_WARN_LIMIT 0x46
3940
#define MAX34440_IOUT_OC_FAULT_LIMIT 0x4A
4041

42+
#define MAX34451ETNA6_MFR_REV 0x0012
43+
4144
#define MAX34451_MFR_CHANNEL_CONFIG 0xe4
4245
#define MAX34451_MFR_CHANNEL_CONFIG_SEL_MASK 0x3f
4346

4447
struct max34440_data {
4548
int id;
4649
struct pmbus_driver_info info;
50+
u8 iout_oc_warn_limit;
51+
u8 iout_oc_fault_limit;
4752
};
4853

4954
#define to_max34440_data(x) container_of(x, struct max34440_data, info)
@@ -60,11 +65,11 @@ static int max34440_read_word_data(struct i2c_client *client, int page,
6065
switch (reg) {
6166
case PMBUS_IOUT_OC_FAULT_LIMIT:
6267
ret = pmbus_read_word_data(client, page, phase,
63-
MAX34440_IOUT_OC_FAULT_LIMIT);
68+
data->iout_oc_fault_limit);
6469
break;
6570
case PMBUS_IOUT_OC_WARN_LIMIT:
6671
ret = pmbus_read_word_data(client, page, phase,
67-
MAX34440_IOUT_OC_WARN_LIMIT);
72+
data->iout_oc_warn_limit);
6873
break;
6974
case PMBUS_VIRT_READ_VOUT_MIN:
7075
ret = pmbus_read_word_data(client, page, phase,
@@ -133,11 +138,11 @@ static int max34440_write_word_data(struct i2c_client *client, int page,
133138

134139
switch (reg) {
135140
case PMBUS_IOUT_OC_FAULT_LIMIT:
136-
ret = pmbus_write_word_data(client, page, MAX34440_IOUT_OC_FAULT_LIMIT,
141+
ret = pmbus_write_word_data(client, page, data->iout_oc_fault_limit,
137142
word);
138143
break;
139144
case PMBUS_IOUT_OC_WARN_LIMIT:
140-
ret = pmbus_write_word_data(client, page, MAX34440_IOUT_OC_WARN_LIMIT,
145+
ret = pmbus_write_word_data(client, page, data->iout_oc_warn_limit,
141146
word);
142147
break;
143148
case PMBUS_VIRT_RESET_POUT_HISTORY:
@@ -235,6 +240,25 @@ static int max34451_set_supported_funcs(struct i2c_client *client,
235240
*/
236241

237242
int page, rv;
243+
bool max34451_na6 = false;
244+
245+
rv = i2c_smbus_read_word_data(client, PMBUS_MFR_REVISION);
246+
if (rv < 0)
247+
return rv;
248+
249+
if (rv >= MAX34451ETNA6_MFR_REV) {
250+
max34451_na6 = true;
251+
data->info.format[PSC_VOLTAGE_IN] = direct;
252+
data->info.format[PSC_CURRENT_IN] = direct;
253+
data->info.m[PSC_VOLTAGE_IN] = 1;
254+
data->info.b[PSC_VOLTAGE_IN] = 0;
255+
data->info.R[PSC_VOLTAGE_IN] = 3;
256+
data->info.m[PSC_CURRENT_IN] = 1;
257+
data->info.b[PSC_CURRENT_IN] = 0;
258+
data->info.R[PSC_CURRENT_IN] = 2;
259+
data->iout_oc_fault_limit = PMBUS_IOUT_OC_FAULT_LIMIT;
260+
data->iout_oc_warn_limit = PMBUS_IOUT_OC_WARN_LIMIT;
261+
}
238262

239263
for (page = 0; page < 16; page++) {
240264
rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
@@ -251,16 +275,30 @@ static int max34451_set_supported_funcs(struct i2c_client *client,
251275
case 0x20:
252276
data->info.func[page] = PMBUS_HAVE_VOUT |
253277
PMBUS_HAVE_STATUS_VOUT;
278+
279+
if (max34451_na6)
280+
data->info.func[page] |= PMBUS_HAVE_VIN |
281+
PMBUS_HAVE_STATUS_INPUT;
254282
break;
255283
case 0x21:
256284
data->info.func[page] = PMBUS_HAVE_VOUT;
285+
286+
if (max34451_na6)
287+
data->info.func[page] |= PMBUS_HAVE_VIN;
257288
break;
258289
case 0x22:
259290
data->info.func[page] = PMBUS_HAVE_IOUT |
260291
PMBUS_HAVE_STATUS_IOUT;
292+
293+
if (max34451_na6)
294+
data->info.func[page] |= PMBUS_HAVE_IIN |
295+
PMBUS_HAVE_STATUS_INPUT;
261296
break;
262297
case 0x23:
263298
data->info.func[page] = PMBUS_HAVE_IOUT;
299+
300+
if (max34451_na6)
301+
data->info.func[page] |= PMBUS_HAVE_IIN;
264302
break;
265303
default:
266304
break;
@@ -494,6 +532,8 @@ static int max34440_probe(struct i2c_client *client)
494532
return -ENOMEM;
495533
data->id = i2c_match_id(max34440_id, client)->driver_data;
496534
data->info = max34440_info[data->id];
535+
data->iout_oc_fault_limit = MAX34440_IOUT_OC_FAULT_LIMIT;
536+
data->iout_oc_warn_limit = MAX34440_IOUT_OC_WARN_LIMIT;
497537

498538
if (data->id == max34451) {
499539
rv = max34451_set_supported_funcs(client, data);

0 commit comments

Comments
 (0)