Skip to content

Commit ab2f6bf

Browse files
wkenningtongroeck
authored andcommitted
hwmon: (max34451) Work around lost page
When requesting new pages from the max34451 we sometimes see that the firmware responds with stale or bad data to reads that happen immediately after a page change. This is due to a lack of clock stretching after page changing on the device side when it needs more time to complete the operation. To remedy this, the manufacturer recommends we wait 50us until the firmware should be ready with the new page. Signed-off-by: William A. Kennington III <william@wkennington.com> Link: https://lore.kernel.org/r/20250408011006.1314622-1-william@wkennington.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 6de6868 commit ab2f6bf

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

drivers/hwmon/pmbus/max34440.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/init.h>
1313
#include <linux/err.h>
1414
#include <linux/i2c.h>
15+
#include <linux/delay.h>
1516
#include "pmbus.h"
1617

1718
enum chips {
@@ -24,6 +25,14 @@ enum chips {
2425
max34461,
2526
};
2627

28+
/*
29+
* Firmware is sometimes not ready if we try and read the
30+
* data from the page immediately after setting. Maxim
31+
* recommends 50us delay due to the chip failing to clock
32+
* stretch long enough here.
33+
*/
34+
#define MAX34440_PAGE_CHANGE_DELAY 50
35+
2736
#define MAX34440_MFR_VOUT_PEAK 0xd4
2837
#define MAX34440_MFR_IOUT_PEAK 0xd5
2938
#define MAX34440_MFR_TEMPERATURE_PEAK 0xd6
@@ -272,6 +281,7 @@ static int max34451_set_supported_funcs(struct i2c_client *client,
272281

273282
for (page = 0; page < 16; page++) {
274283
rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
284+
fsleep(MAX34440_PAGE_CHANGE_DELAY);
275285
if (rv < 0)
276286
return rv;
277287

@@ -395,6 +405,7 @@ static struct pmbus_driver_info max34440_info[] = {
395405
.read_byte_data = max34440_read_byte_data,
396406
.read_word_data = max34440_read_word_data,
397407
.write_word_data = max34440_write_word_data,
408+
.page_change_delay = MAX34440_PAGE_CHANGE_DELAY,
398409
},
399410
[max34441] = {
400411
.pages = 12,
@@ -438,6 +449,7 @@ static struct pmbus_driver_info max34440_info[] = {
438449
.read_byte_data = max34440_read_byte_data,
439450
.read_word_data = max34440_read_word_data,
440451
.write_word_data = max34440_write_word_data,
452+
.page_change_delay = MAX34440_PAGE_CHANGE_DELAY,
441453
},
442454
[max34446] = {
443455
.pages = 7,
@@ -475,6 +487,7 @@ static struct pmbus_driver_info max34440_info[] = {
475487
.read_byte_data = max34440_read_byte_data,
476488
.read_word_data = max34440_read_word_data,
477489
.write_word_data = max34440_write_word_data,
490+
.page_change_delay = MAX34440_PAGE_CHANGE_DELAY,
478491
},
479492
[max34451] = {
480493
.pages = 21,
@@ -498,6 +511,7 @@ static struct pmbus_driver_info max34440_info[] = {
498511
.func[20] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
499512
.read_word_data = max34440_read_word_data,
500513
.write_word_data = max34440_write_word_data,
514+
.page_change_delay = MAX34440_PAGE_CHANGE_DELAY,
501515
},
502516
[max34460] = {
503517
.pages = 18,
@@ -528,6 +542,7 @@ static struct pmbus_driver_info max34440_info[] = {
528542
.func[17] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
529543
.read_word_data = max34440_read_word_data,
530544
.write_word_data = max34440_write_word_data,
545+
.page_change_delay = MAX34440_PAGE_CHANGE_DELAY,
531546
},
532547
[max34461] = {
533548
.pages = 23,
@@ -563,6 +578,7 @@ static struct pmbus_driver_info max34440_info[] = {
563578
.func[21] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
564579
.read_word_data = max34440_read_word_data,
565580
.write_word_data = max34440_write_word_data,
581+
.page_change_delay = MAX34440_PAGE_CHANGE_DELAY,
566582
},
567583
};
568584

0 commit comments

Comments
 (0)