hwmon: (pmbus): Introduce page_change_delay
PATCH 1/1 hwmon: (pmbus): Introduce page_change_delay
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
--- drivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 59 ++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 19 deletions(-)
drivers/hwmon/pmbus/pmbus.h +1 -0
@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */
drivers/hwmon/pmbus/pmbus_core.c +40 -19
159 lines not on this page · raw message
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
PATCH v2 1/1 hwmon: (pmbus): Introduce page_change_delay
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
---
V1 -> V2: Simplify how the backoff time is stored and computed
drivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 69 ++++++++++++++++---------------- 2 files changed, 36 insertions(+), 34 deletions(-)
drivers/hwmon/pmbus/pmbus.h +1 -0
@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */
drivers/hwmon/pmbus/pmbus_core.c +35 -34
165 lines not on this page · raw message
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
PATCH v3 1/1 hwmon: (pmbus): Introduce page_change_delay
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
---
V1 -> V2: Simplify how the backoff time is stored and computed V2 -> V3: Use the BIT macro
drivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 67 +++++++++++++++----------------- 2 files changed, 33 insertions(+), 35 deletions(-)
drivers/hwmon/pmbus/pmbus.h +1 -0
@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */
drivers/hwmon/pmbus/pmbus_core.c +32 -35
162 lines not on this page · raw message
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Guenter Roeck
maintainerQuoted 61 lines · William A. Kennington III
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
Signed-off-by William A. Kennington III <[email protected]>---
V1 -> V2: Simplify how the backoff time is stored and computed V2 -> V3: Use the BIT macrodrivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 67 +++++++++++++++----------------- 2 files changed, 33 insertions(+), 35 deletions(-)drivers/hwmon/pmbus/pmbus.h +1
-0@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */ drivers/hwmon/pmbus/pmbus_core.c +3
-14@@ -114,8 +114,8 @@ struct pmbus_data {int vout_low[PMBUS_PAGES ];/* voltage low margin */ int vout_high[PMBUS_PAGES ];/* voltage high margin */ -ktime_t write_time;/* Last SMBUS write timestamp */ -ktime_t access_time;/* Last SMBUS access timestamp */ + +ktime_t next_access_backoff;/* Wait until at least this time */ };struct pmbus_debugfs_entry {@@ -170,33 +170,30 @@ EXPORT_SYMBOL_NS_GPL(pmbus_set_update, "PMBUS");static void pmbus_wait (struct i2c_client *client) {struct pmbus_data *data =i2c_get_clientdata (client); -const struct pmbus_driver_info *info = data->info; -s64 delta; - -if (info->access_delay) { - delta =ktime_us_delta (ktime_get (), data->access_time); - -if (delta < info->access_delay) -fsleep (info->access_delay - delta); - }else if (info->write_delay) { - delta =ktime_us_delta (ktime_get (), data->write_time); +s64 delay =ktime_us_delta (data->next_access_backoff,ktime_get ()); -if (delta < info->write_delay) -fsleep (info->write_delay - delta);
drivers/hwmon/pmbus/pmbus_core.c EXPORT_SYMBOL_NS_GPL(pmbus_set_update, "PMBUS"); · line 181
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c +5
-3- } +if (delay >0 ) +fsleep (delay); } -/* Sets the last accessed timestamp for pmbus_wait */ -static void pmbus_update_ts (struct i2c_client *client,bool write_op) +#define PMBUS_OP_READ BIT(0) +#define PMBUS_OP_WRITE BIT(1) +#define PMBUS_OP_PAGE_CHANGE BIT(2)
I guess you really don't like tabs. Ok, no problem, I can fix that up when I apply the patch. Either case, please move the defines ahead of the first code block.
drivers/hwmon/pmbus/pmbus_core.c EXPORT_SYMBOL_NS_GPL(pmbus_set_update, "PMBUS"); · line 188
Quoted 7 lines
drivers/hwmon/pmbus/pmbus_core.c +4
-0+ +/* Sets the last operation timestamp for pmbus_wait */ +static void pmbus_update_ts (struct i2c_client *client,int op) {struct pmbus_data *data =i2c_get_clientdata (client);const struct pmbus_driver_info *info = data->info; +int delay = info->access_delay;
Hmm, this is a functional change. It always sets the minimum wait time to access_delay, even if the operation is a write. I guess it makes sense because otherwise there would be no delay after a write if only access_delay is set. However, that means that PMBUS_OP_READ is not really needed anymore and can be dropped.
This should be explained in the patch description.
drivers/hwmon/pmbus/pmbus_core.c EXPORT_SYMBOL_NS_GPL(pmbus_set_update, "PMBUS"); · line 194
Quoted 11 lines
drivers/hwmon/pmbus/pmbus_core.c +5
-5-if (info->access_delay) { - data->access_time =ktime_get (); - }else if (info->write_delay && write_op) { - data->write_time =ktime_get (); - } +if (op & (PMBUS_OP_WRITE |PMBUS_OP_PAGE_CHANGE )) + delay =max (delay, info->write_delay); +if (op &PMBUS_OP_PAGE_CHANGE ) + delay =max (delay, info->page_change_delay); +
I would have set PMBUS_OP_WRITE | PMBUS_OP_PAGE_CHANGE in the calling code, but this is ok too. However, please make it
if (op & (PMBUS_OP_WRITE | PMBUS_OP_PAGE_CHANGE)) {
delay = max(delay, info->write_delay);
if (op & PMBUS_OP_PAGE_CHANGE)
delay = max(delay, info->page_change_delay);
}After dropping PMBUS_OP_READ, that can be simplified further to
if (op) {
...
}Quoted 85 lines
drivers/hwmon/pmbus/pmbus_core.c +11
-9+if (delay >0 ) + data->next_access_backoff =ktime_add_us (ktime_get (), delay); }int pmbus_set_page (struct i2c_client *client,int page,int phase)@@ -211,13 +208,13 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase) data->info->pages > 1 && page != data->currpage) {pmbus_wait (client); rv =i2c_smbus_write_byte_data (client,PMBUS_PAGE , page); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_PAGE_CHANGE );if (rv <0 )return rv;pmbus_wait (client); rv =i2c_smbus_read_byte_data (client,PMBUS_PAGE ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (rv <0 )return rv;@@ -231,7 +228,7 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)pmbus_wait (client); rv =i2c_smbus_write_byte_data (client,PMBUS_PHASE , phase); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );if (rv)return rv; }@@ -251,7 +248,7 @@ int pmbus_write_byte(struct i2c_client *client, int page, u8 value)pmbus_wait (client); rv =i2c_smbus_write_byte (client, value); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -286,7 +283,7 @@ int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg,pmbus_wait (client); rv =i2c_smbus_write_word_data (client, reg, word); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -408,7 +405,7 @@ int pmbus_read_word_data(struct i2c_client *client, int page, int phase, u8 reg)pmbus_wait (client); rv =i2c_smbus_read_word_data (client, reg); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }@@ -471,7 +468,7 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg)pmbus_wait (client); rv =i2c_smbus_read_byte_data (client, reg); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }@@ -487,7 +484,7 @@ int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, u8 value)pmbus_wait (client); rv =i2c_smbus_write_byte_data (client, reg, value); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -523,7 +520,7 @@ static int pmbus_read_block_data(struct i2c_client *client, int page, u8 reg,pmbus_wait (client); rv =i2c_smbus_read_block_data (client, reg, data_buf); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_read_coefficients(struct i2c_client *client, · line 2530
Quoted 5 lines
drivers/hwmon/pmbus/pmbus_core.c +1
-1@@ -2530,7 +2527,7 @@ static int pmbus_read_coefficients(struct i2c_client *client, rv =i2c_smbus_xfer (client->adapter, client->addr, client->flags,I2C_SMBUS_WRITE ,PMBUS_COEFFICIENTS ,I2C_SMBUS_BLOCK_PROC_CALL , &data); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_READ |PMBUS_OP_WRITE );
I'd argue that this does not warrant a PMBUS_OP_WRITE in the first place. From the chip's perspective, the operation is complete after the data is returned. This is just as much a write as any other SMBus read operation (a write of an address followed by a read). If you think otherwise, please explain.
Either case, the change warrants an explanation in the patch description.
Thanks,
Guenter
Quoted 68 lines · Guenter Roeck
Quoted 66 lines · William A. Kennington III
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
Signed-off-by William A. Kennington III <[email protected]>---
V1 -> V2: Simplify how the backoff time is stored and computed V2 -> V3: Use the BIT macrodrivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 67 +++++++++++++++----------------- 2 files changed, 33 insertions(+), 35 deletions(-)drivers/hwmon/pmbus/pmbus.h +1
-0@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */ drivers/hwmon/pmbus/pmbus_core.c +5
-15@@ -114,8 +114,8 @@ struct pmbus_data {int vout_low[PMBUS_PAGES ];/* voltage low margin */ int vout_high[PMBUS_PAGES ];/* voltage high margin */ -ktime_t write_time;/* Last SMBUS write timestamp */ -ktime_t access_time;/* Last SMBUS access timestamp */ + +ktime_t next_access_backoff;/* Wait until at least this time */ };struct pmbus_debugfs_entry {@@ -170,33 +170,30 @@ EXPORT_SYMBOL_NS_GPL(pmbus_set_update, "PMBUS");static void pmbus_wait (struct i2c_client *client) {struct pmbus_data *data =i2c_get_clientdata (client); -const struct pmbus_driver_info *info = data->info; -s64 delta; - -if (info->access_delay) { - delta =ktime_us_delta (ktime_get (), data->access_time); - -if (delta < info->access_delay) -fsleep (info->access_delay - delta); - }else if (info->write_delay) { - delta =ktime_us_delta (ktime_get (), data->write_time); +s64 delay =ktime_us_delta (data->next_access_backoff,ktime_get ()); -if (delta < info->write_delay) -fsleep (info->write_delay - delta); - } +if (delay >0 ) +fsleep (delay); }
Quoted 9 lines
drivers/hwmon/pmbus/pmbus_core.c EXPORT_SYMBOL_NS_GPL(pmbus_set_update, "PMBUS"); · line 181
Quoted 5 lines
drivers/hwmon/pmbus/pmbus_core.c +3
-2-/* Sets the last accessed timestamp for pmbus_wait */ -static void pmbus_update_ts (struct i2c_client *client,bool write_op) +#define PMBUS_OP_READ BIT(0) +#define PMBUS_OP_WRITE BIT(1) +#define PMBUS_OP_PAGE_CHANGE BIT(2)I guess you really don't like tabs. Ok, no problem, I can fix that up when I apply the patch. Either case, please move the defines ahead of the first code block.
Done
Quoted 15 lines
drivers/hwmon/pmbus/pmbus_core.c EXPORT_SYMBOL_NS_GPL(pmbus_set_update, "PMBUS"); · line 188
Quoted 8 lines
drivers/hwmon/pmbus/pmbus_core.c +4
-0+ +/* Sets the last operation timestamp for pmbus_wait */ +static void pmbus_update_ts (struct i2c_client *client,int op) {struct pmbus_data *data =i2c_get_clientdata (client);const struct pmbus_driver_info *info = data->info; +int delay = info->access_delay;Hmm, this is a functional change. It always sets the minimum wait time to
access_delay, even if the operation is a write. I guess it makes sense because otherwise there would be no delay after a write if onlyaccess_delayis set. However, that means thatPMBUS_OP_READis not really needed anymore and can be dropped.
Quoted 1 line
This should be explained in the patch description.
Done
Quoted 13 lines
drivers/hwmon/pmbus/pmbus_core.c EXPORT_SYMBOL_NS_GPL(pmbus_set_update, "PMBUS"); · line 194
Quoted 12 lines
drivers/hwmon/pmbus/pmbus_core.c +5
-5-if (info->access_delay) { - data->access_time =ktime_get (); - }else if (info->write_delay && write_op) { - data->write_time =ktime_get (); - } +if (op & (PMBUS_OP_WRITE |PMBUS_OP_PAGE_CHANGE )) + delay =max (delay, info->write_delay); +if (op &PMBUS_OP_PAGE_CHANGE ) + delay =max (delay, info->page_change_delay); +
Quoted 2 lines
I would have set
PMBUS_OP_WRITE|PMBUS_OP_PAGE_CHANGEin the calling code, but this is ok too. However, please make it
Sure, I'll just move it to the callsite
Quoted 110 lines
if (op & (PMBUS_OP_WRITE | PMBUS_OP_PAGE_CHANGE)) { delay = max(delay, info->write_delay); if (op & PMBUS_OP_PAGE_CHANGE) delay = max(delay, info->page_change_delay); }After dropping
PMBUS_OP_READ, that can be simplified further toif (op) { ... }Quoted 85 lines
drivers/hwmon/pmbus/pmbus_core.c +11
-9+if (delay >0 ) + data->next_access_backoff =ktime_add_us (ktime_get (), delay); }int pmbus_set_page (struct i2c_client *client,int page,int phase)@@ -211,13 +208,13 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase) data->info->pages > 1 && page != data->currpage) {pmbus_wait (client); rv =i2c_smbus_write_byte_data (client,PMBUS_PAGE , page); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_PAGE_CHANGE );if (rv <0 )return rv;pmbus_wait (client); rv =i2c_smbus_read_byte_data (client,PMBUS_PAGE ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (rv <0 )return rv;@@ -231,7 +228,7 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)pmbus_wait (client); rv =i2c_smbus_write_byte_data (client,PMBUS_PHASE , phase); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );if (rv)return rv; }@@ -251,7 +248,7 @@ int pmbus_write_byte(struct i2c_client *client, int page, u8 value)pmbus_wait (client); rv =i2c_smbus_write_byte (client, value); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -286,7 +283,7 @@ int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg,pmbus_wait (client); rv =i2c_smbus_write_word_data (client, reg, word); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -408,7 +405,7 @@ int pmbus_read_word_data(struct i2c_client *client, int page, int phase, u8 reg)pmbus_wait (client); rv =i2c_smbus_read_word_data (client, reg); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }@@ -471,7 +468,7 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg)pmbus_wait (client); rv =i2c_smbus_read_byte_data (client, reg); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }@@ -487,7 +484,7 @@ int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, u8 value)pmbus_wait (client); rv =i2c_smbus_write_byte_data (client, reg, value); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -523,7 +520,7 @@ static int pmbus_read_block_data(struct i2c_client *client, int page, u8 reg,pmbus_wait (client); rv =i2c_smbus_read_block_data (client, reg, data_buf); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }drivers/hwmon/pmbus/pmbus_core.c static int pmbus_read_coefficients(struct i2c_client *client, · line 2530
Quoted 5 lines
drivers/hwmon/pmbus/pmbus_core.c +1
-1@@ -2530,7 +2527,7 @@ static int pmbus_read_coefficients(struct i2c_client *client, rv =i2c_smbus_xfer (client->adapter, client->addr, client->flags,I2C_SMBUS_WRITE ,PMBUS_COEFFICIENTS ,I2C_SMBUS_BLOCK_PROC_CALL , &data); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_READ |PMBUS_OP_WRITE );I'd argue that this does not warrant a
PMBUS_OP_WRITEin the first place. From the chip's perspective, the operation is complete after the data is returned. This is just as much a write as any other SMBus read operation (a write of an address followed by a read). If you think otherwise, please explain.
Quoted 1 line
Either case, the change warrants an explanation in the patch description.
The previous behavior was to treat this as a write though? I updated the description about picking the maximum delay in the code change above, but this specific instance is still classified the same.
I think technically we shouldn't do a single smbus transfer, but do the write followed by read with a write delay injected between them. I don't want to make that change here but it doesn't make sense to ignore the write delay IMHO.
Quoted 3 lines
Thanks,
Guenter
Guenter Roeck
maintainerQuoted 15 lines · William Kennington
Quoted 13 lines · Guenter Roeck
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_read_coefficients(struct i2c_client *client, · line 2530
Quoted 6 lines
drivers/hwmon/pmbus/pmbus_core.c +1
-1@@ -2530,7 +2527,7 @@ static int pmbus_read_coefficients(struct i2c_client *client, rv =i2c_smbus_xfer (client->adapter, client->addr, client->flags,I2C_SMBUS_WRITE ,PMBUS_COEFFICIENTS ,I2C_SMBUS_BLOCK_PROC_CALL , &data); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_READ |PMBUS_OP_WRITE );I'd argue that this does not warrant a
PMBUS_OP_WRITEin the first place.
From the chip's perspective, the operation is complete after the data
is returned. This is just as much a write as any other SMBus read operation (a write of an address followed by a read). If you think otherwise, please explain.
Quoted 3 lines
Quoted 1 line
Either case, the change warrants an explanation in the patch description.
The previous behavior was to treat this as a write though? I updated
That dpesn't mean that the previous code was correct.
Quoted 8 lines
the description about picking the maximum delay in the code change above, but this specific instance is still classified the same.
I think technically we shouldn't do a single smbus transfer, but do the write followed by read with a write delay injected between them. I don't want to make that change here but it doesn't make sense to ignore the write delay IMHO.
Every single SMBus read transfer is a write (chip address plus register address) followed by a read. Following your logic, every read should be treated as a write, followed by the write delay, followed by the read.
Guenter
Quoted 17 lines · Guenter Roeck
Quoted 15 lines · William Kennington
Quoted 13 lines · Guenter Roeck
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_read_coefficients(struct i2c_client *client, · line 2530
Quoted 6 lines
drivers/hwmon/pmbus/pmbus_core.c +1
-1@@ -2530,7 +2527,7 @@ static int pmbus_read_coefficients(struct i2c_client *client, rv =i2c_smbus_xfer (client->adapter, client->addr, client->flags,I2C_SMBUS_WRITE ,PMBUS_COEFFICIENTS ,I2C_SMBUS_BLOCK_PROC_CALL , &data); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_READ |PMBUS_OP_WRITE );I'd argue that this does not warrant a
PMBUS_OP_WRITEin the first place.
From the chip's perspective, the operation is complete after the data
is returned. This is just as much a write as any other SMBus read operation (a write of an address followed by a read). If you think otherwise, please explain.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Either case, the change warrants an explanation in the patch description.
The previous behavior was to treat this as a write though? I updated
That dpesn't mean that the previous code was correct.
Yeah i 100% agree, I just didn't think this is the place to be figuring out if the old decisions were accurate or not. I was keeping the behavior the same (respecting write_delay) for this operation because it's unclear to me what the purpose of the delay is for. It seems like it's actually meant to delay around the concepts of smbus read / write, not PMBUS logical reads / writes. Anyway, I left this the same for now.
Quoted 10 lines
Quoted 9 lines
the description about picking the maximum delay in the code change above, but this specific instance is still classified the same.
I think technically we shouldn't do a single smbus transfer, but do the write followed by read with a write delay injected between them. I don't want to make that change here but it doesn't make sense to ignore the write delay IMHO.
Quoted 3 lines
Every single SMBus read transfer is a write (chip address plus register address) followed by a read. Following your logic, every read should be treated as a write, followed by the write delay, followed by the read.
Understood, but I think that was the purpose of the delays when originally contributed. It's about SMBUS related issues in specific device implementations and not PMBUS logical operations.
Quoted 3 lines
Guenter
PATCH v4 1/1 hwmon: (pmbus): Introduce page_change_delay
In reply to William A. Kennington IIIWe have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
This makes a slight behavioral tweak to the existing delay logic, where it considers the longest of delays between operations, instead of always chosing the write delay over the access delay.
---
V1 -> V2: Simplify how the backoff time is stored and computed V2 -> V3: Use the BIT macro
V3 -> V4: Move defines up
Move op combos outside update call
Remove unused PMBUS_OP_READ
drivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 70 ++++++++++++++++---------------- 2 files changed, 36 insertions(+), 35 deletions(-)
drivers/hwmon/pmbus/pmbus.h +1 -0
@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */
drivers/hwmon/pmbus/pmbus_core.c +35 -35
171 lines not on this page · raw message
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Guenter Roeck
maintainerQuoted 4 lines · William A. Kennington III
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
Quoted 8 lines
This allows for a configurable delay after page changes, but not affecting other read or write operations.
This makes a slight behavioral tweak to the existing delay logic, where it considers the longest of delays between operations, instead of always chosing the write delay over the access delay.
Signed-off-by William A. Kennington III <[email protected]>
I tried to apply your patch, but it fails. Please rebase to the upstream kernel and resubmit.
Thanks,
Guenter
Quoted 9 lines · Guenter Roeck
Quoted 7 lines · William A. Kennington III
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
Quoted 8 lines
Quoted 5 lines
This makes a slight behavioral tweak to the existing delay logic, where it considers the longest of delays between operations, instead of always chosing the write delay over the access delay.
Signed-off-by William A. Kennington III <[email protected]>I tried to apply your patch, but it fails. Please rebase to the upstream kernel and resubmit.
Done in v5
Quoted 3 lines
Thanks,
Guenter
PATCH v5 1/1 hwmon: (pmbus): Introduce page_change_delay
In reply to William A. Kennington IIIWe have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
This makes a slight behavioral tweak to the existing delay logic, where it considers the longest of delays between operations, instead of always chosing the write delay over the access delay.
---
V1 -> V2: Simplify how the backoff time is stored and computed V2 -> V3: Use the BIT macro
V3 -> V4: Move defines up
Move op combos outside update call
Remove unused PMBUS_OP_READ
V4 -> V5: Rebase onto 6.15-rc1
drivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 69 ++++++++++++++++---------------- 2 files changed, 36 insertions(+), 34 deletions(-)
drivers/hwmon/pmbus/pmbus.h +1 -0
@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */
drivers/hwmon/pmbus/pmbus_core.c +35 -34
170 lines not on this page · raw message
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Quoted 4 lines · William A. Kennington III
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
Quoted 8 lines
This allows for a configurable delay after page changes, but not affecting other read or write operations.
This makes a slight behavioral tweak to the existing delay logic, where it considers the longest of delays between operations, instead of always chosing the write delay over the access delay.
Signed-off-by William A. Kennington III <[email protected]>
Applied.
Thanks,
Guenter
Guenter Roeck
maintainerQuoted 42 lines · William A. Kennington III
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
Signed-off-by William A. Kennington III <[email protected]>--- drivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 59 ++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 19 deletions(-)drivers/hwmon/pmbus/pmbus.h +1
-0@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */ drivers/hwmon/pmbus/pmbus_core.c +1
-1@@ -116,6 +116,7 @@ struct pmbus_data {int vout_high[PMBUS_PAGES ];/* voltage high margin */ ktime_t write_time;/* Last SMBUS write timestamp */ ktime_t access_time;/* Last SMBUS access timestamp */ +ktime_t page_change_time;/* Last SMBUS page change timestamp */ };struct pmbus_debugfs_entry {@@ -178,24 +179,44 @@ static void pmbus_wait(struct i2c_client *client)if (delta < info->access_delay)fsleep (info->access_delay - delta); - }else if (info->write_delay) {
drivers/hwmon/pmbus/pmbus_core.c static void pmbus_wait(struct i2c_client *client) · line 191
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c +5
-0+ } +if (info->write_delay) { delta =ktime_us_delta (ktime_get (), data->write_time);if (delta < info->write_delay)fsleep (info->write_delay - delta); } +if (info->page_change_delay) { + delta =ktime_us_delta (ktime_get (), data->page_change_time); +
page_change_time isn't actually set. I suggest to just use data->write_time. Also see below.
drivers/hwmon/pmbus/pmbus_core.c static void pmbus_wait(struct i2c_client *client) · line 199
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c +6
-2+if (delta < info->page_change_delay) +fsleep (info->page_change_delay - delta); + } } -/* Sets the last accessed timestamp for pmbus_wait */ -static void pmbus_update_ts (struct i2c_client *client,bool write_op) +#define PMBUS_OP_READ_BIT 1 +#define PMBUS_OP_WRITE_BIT 2 +#define PMBUS_OP_PAGE_CHANGE_BIT 4
#define<space>NAME<tab>BIT(...)
drivers/hwmon/pmbus/pmbus_core.c static void pmbus_wait(struct i2c_client *client) · line 203
Quoted 4 lines
drivers/hwmon/pmbus/pmbus_core.c +4
-0+ +#define PMBUS_OP_READ PMBUS_OP_READ_BIT +#define PMBUS_OP_WRITE PMBUS_OP_WRITE_BIT +#define PMBUS_OP_PAGE_CHANGE (PMBUS_OP_PAGE_CHANGE_BIT | PMBUS_OP_WRITE)
That is way too complicated. Just make it
#define PMBUS_OP_READ BIT(0)
#define PMBUS_OP_WRITE BIT(1)
#define PMBUS_OP_PAGE_CHANGE BIT(2)
A page change implies a write, so it is not necessary to combine the bits.
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c +4
-1+ +/* Sets the last operation timestamp for pmbus_wait */ +static void pmbus_update_ts (struct i2c_client *client,int op) {struct pmbus_data *data =i2c_get_clientdata (client);const struct pmbus_driver_info *info = data->info; +ktime_t now =ktime_get ();if (info->access_delay) { - data->access_time =ktime_get ();
drivers/hwmon/pmbus/pmbus_core.c static void pmbus_wait(struct i2c_client *client) · line 220
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c +7
-2- }else if (info->write_delay && write_op) { - data->write_time =ktime_get (); + data->access_time = now; + } +if (info->write_delay && (op &PMBUS_OP_WRITE_BIT )) { + data->write_time = now; + } +if (info->page_change_delay && (op &PMBUS_OP_PAGE_CHANGE_BIT )) { + data->write_time = now; }
Seems to me that we should only need write_time and not page_change_time since both will always be set together.
I also think this can be simplified if ktime_get() is always called anyway.
ktime_t now = ktime_get(); data->access_time = now; if (op & (PMBUS_OP_WRITE | PMBUS_OP_PAGE_CHANGE)) data->write_time = now;
It doesn't matter if the values are set unnecessarily if there is no delay because they won't be used in that case.
Quoted 82 lines
drivers/hwmon/pmbus/pmbus_core.c +9
-9}@@ -211,13 +232,13 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase) data->info->pages > 1 && page != data->currpage) {pmbus_wait (client); rv =i2c_smbus_write_byte_data (client,PMBUS_PAGE , page); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_PAGE_CHANGE );if (rv <0 )return rv;pmbus_wait (client); rv =i2c_smbus_read_byte_data (client,PMBUS_PAGE ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (rv <0 )return rv;@@ -231,7 +252,7 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)pmbus_wait (client); rv =i2c_smbus_write_byte_data (client,PMBUS_PHASE , phase); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );if (rv)return rv; }@@ -251,7 +272,7 @@ int pmbus_write_byte(struct i2c_client *client, int page, u8 value)pmbus_wait (client); rv =i2c_smbus_write_byte (client, value); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -286,7 +307,7 @@ int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg,pmbus_wait (client); rv =i2c_smbus_write_word_data (client, reg, word); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -408,7 +429,7 @@ int pmbus_read_word_data(struct i2c_client *client, int page, int phase, u8 reg)pmbus_wait (client); rv =i2c_smbus_read_word_data (client, reg); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }@@ -471,7 +492,7 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg)pmbus_wait (client); rv =i2c_smbus_read_byte_data (client, reg); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }@@ -487,7 +508,7 @@ int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, u8 value)pmbus_wait (client); rv =i2c_smbus_write_byte_data (client, reg, value); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -523,7 +544,7 @@ static int pmbus_read_block_data(struct i2c_client *client, int page, u8 reg,pmbus_wait (client); rv =i2c_smbus_read_block_data (client, reg, data_buf); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_read_coefficients(struct i2c_client *client, · line 2554
Quoted 5 lines
drivers/hwmon/pmbus/pmbus_core.c +1
-1@@ -2530,7 +2551,7 @@ static int pmbus_read_coefficients(struct i2c_client *client, rv =i2c_smbus_xfer (client->adapter, client->addr, client->flags,I2C_SMBUS_WRITE ,PMBUS_COEFFICIENTS ,I2C_SMBUS_BLOCK_PROC_CALL , &data); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_READ |PMBUS_OP_WRITE );
I don't immediately follow the reason for adding PMBUS_OP_READ.
Quoted 28 lines
drivers/hwmon/pmbus/pmbus_core.c +3
-3if (rv <0 )return rv;@@ -2734,7 +2755,7 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,if (!(data->flags &PMBUS_NO_CAPABILITY )) {pmbus_wait (client); ret =i2c_smbus_read_byte_data (client,PMBUS_CAPABILITY ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (ret >=0 && (ret &PB_CAPABILITY_ERROR_CHECK )) {if (i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_PEC ))@@ -2750,13 +2771,13 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, data->read_status = pmbus_read_status_word;pmbus_wait (client); ret =i2c_smbus_read_word_data (client,PMBUS_STATUS_WORD ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (ret <0 || ret ==0xffff ) { data->read_status = pmbus_read_status_byte;pmbus_wait (client); ret =i2c_smbus_read_byte_data (client,PMBUS_STATUS_BYTE ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (ret <0 || ret ==0xff ) {dev_err (dev,"PMBus status register not found\n" );
Quoted 48 lines · Guenter Roeck
Quoted 46 lines · William A. Kennington III
We have some buggy pmbus devices that require a delay after performing a page change operation before trying to issue more commands to the device.
This allows for a configurable delay after page changes, but not affecting other read or write operations.
Signed-off-by William A. Kennington III <[email protected]>--- drivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 59 ++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 19 deletions(-)drivers/hwmon/pmbus/pmbus.h +1
-0@@ -482,6 +482,7 @@ struct pmbus_driver_info {*/ int access_delay;/* in microseconds */ int write_delay;/* in microseconds */ +int page_change_delay;/* in microseconds */ };/* Regulator ops */ drivers/hwmon/pmbus/pmbus_core.c +3
-1@@ -116,6 +116,7 @@ struct pmbus_data {int vout_high[PMBUS_PAGES ];/* voltage high margin */ ktime_t write_time;/* Last SMBUS write timestamp */ ktime_t access_time;/* Last SMBUS access timestamp */ +ktime_t page_change_time;/* Last SMBUS page change timestamp */ };struct pmbus_debugfs_entry {@@ -178,24 +179,44 @@ static void pmbus_wait(struct i2c_client *client)if (delta < info->access_delay)fsleep (info->access_delay - delta); - }else if (info->write_delay) { + } +if (info->write_delay) { delta =ktime_us_delta (ktime_get (), data->write_time);
Quoted 9 lines
drivers/hwmon/pmbus/pmbus_core.c static void pmbus_wait(struct i2c_client *client) · line 191
Quoted 6 lines
drivers/hwmon/pmbus/pmbus_core.c +3
-0if (delta < info->write_delay)fsleep (info->write_delay - delta); } +if (info->page_change_delay) { + delta =ktime_us_delta (ktime_get (), data->page_change_time); +
page_change_timeisn't actually set. I suggest to just usedata->write_time. Also see below.
Yeah, I consolidated the times in v2 and will keep it in v3
Quoted 21 lines
drivers/hwmon/pmbus/pmbus_core.c static void pmbus_wait(struct i2c_client *client) · line 199
Quoted 11 lines
drivers/hwmon/pmbus/pmbus_core.c +6
-2+if (delta < info->page_change_delay) +fsleep (info->page_change_delay - delta); + } } -/* Sets the last accessed timestamp for pmbus_wait */ -static void pmbus_update_ts (struct i2c_client *client,bool write_op) +#define PMBUS_OP_READ_BIT 1 +#define PMBUS_OP_WRITE_BIT 2 +#define PMBUS_OP_PAGE_CHANGE_BIT 4#define<space>NAME<tab>BIT(...)
drivers/hwmon/pmbus/pmbus_core.c static void pmbus_wait(struct i2c_client *client) · line 203
Quoted 4 lines
drivers/hwmon/pmbus/pmbus_core.c +4
-0+ +#define PMBUS_OP_READ PMBUS_OP_READ_BIT +#define PMBUS_OP_WRITE PMBUS_OP_WRITE_BIT +#define PMBUS_OP_PAGE_CHANGE (PMBUS_OP_PAGE_CHANGE_BIT | PMBUS_OP_WRITE)That is way too complicated. Just make it
Quoted 5 lines
#define PMBUS_OP_READ BIT(0) #define PMBUS_OP_WRITE BIT(1) #define PMBUS_OP_PAGE_CHANGE BIT(2)A page change implies a write, so it is not necessary to combine the bits.
Yeah, I combined then here to make the function working with the delays consider both delays. I'll make this simpler.
Quoted 27 lines
Quoted 11 lines
drivers/hwmon/pmbus/pmbus_core.c +4
-1+ +/* Sets the last operation timestamp for pmbus_wait */ +static void pmbus_update_ts (struct i2c_client *client,int op) {struct pmbus_data *data =i2c_get_clientdata (client);const struct pmbus_driver_info *info = data->info; +ktime_t now =ktime_get ();if (info->access_delay) { - data->access_time =ktime_get ();drivers/hwmon/pmbus/pmbus_core.c static void pmbus_wait(struct i2c_client *client) · line 220
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c +7
-2- }else if (info->write_delay && write_op) { - data->write_time =ktime_get (); + data->access_time = now; + } +if (info->write_delay && (op &PMBUS_OP_WRITE_BIT )) { + data->write_time = now; + } +if (info->page_change_delay && (op &PMBUS_OP_PAGE_CHANGE_BIT )) { + data->write_time = now; }Seems to me that we should only need
write_timeand notpage_change_timesince both will always be set together.I also think this can be simplified if
ktime_get()is always called anyway.
Quoted 8 lines
ktime_t now = ktime_get(); data->access_time = now; if (op & (PMBUS_OP_WRITE | PMBUS_OP_PAGE_CHANGE)) data->write_time = now;It doesn't matter if the values are set unnecessarily if there is no delay because they won't be used in that case.
Yes, I think v2 (and shortly v3) makes this better
Quoted 80 lines
Quoted 80 lines
drivers/hwmon/pmbus/pmbus_core.c +9
-9}@@ -211,13 +232,13 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase) data->info->pages > 1 && page != data->currpage) {pmbus_wait (client); rv =i2c_smbus_write_byte_data (client,PMBUS_PAGE , page); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_PAGE_CHANGE );if (rv <0 )return rv;pmbus_wait (client); rv =i2c_smbus_read_byte_data (client,PMBUS_PAGE ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (rv <0 )return rv;@@ -231,7 +252,7 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)pmbus_wait (client); rv =i2c_smbus_write_byte_data (client,PMBUS_PHASE , phase); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );if (rv)return rv; }@@ -251,7 +272,7 @@ int pmbus_write_byte(struct i2c_client *client, int page, u8 value)pmbus_wait (client); rv =i2c_smbus_write_byte (client, value); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -286,7 +307,7 @@ int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg,pmbus_wait (client); rv =i2c_smbus_write_word_data (client, reg, word); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -408,7 +429,7 @@ int pmbus_read_word_data(struct i2c_client *client, int page, int phase, u8 reg)pmbus_wait (client); rv =i2c_smbus_read_word_data (client, reg); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }@@ -471,7 +492,7 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg)pmbus_wait (client); rv =i2c_smbus_read_byte_data (client, reg); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );return rv; }@@ -487,7 +508,7 @@ int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, u8 value)pmbus_wait (client); rv =i2c_smbus_write_byte_data (client, reg, value); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_WRITE );return rv; }@@ -523,7 +544,7 @@ static int pmbus_read_block_data(struct i2c_client *client, int page, u8 reg,pmbus_wait (client); rv =i2c_smbus_read_block_data (client, reg, data_buf); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_read_coefficients(struct i2c_client *client, · line 2554
Quoted 8 lines
drivers/hwmon/pmbus/pmbus_core.c +1
-1return rv; }@@ -2530,7 +2551,7 @@ static int pmbus_read_coefficients(struct i2c_client *client, rv =i2c_smbus_xfer (client->adapter, client->addr, client->flags,I2C_SMBUS_WRITE ,PMBUS_COEFFICIENTS ,I2C_SMBUS_BLOCK_PROC_CALL , &data); -pmbus_update_ts (client, true); +pmbus_update_ts (client,PMBUS_OP_READ |PMBUS_OP_WRITE );I don't immediately follow the reason for adding
PMBUS_OP_READ.
I can just remove it, I just added it for clarity as opposed to having it just be 0.
Quoted 30 lines
Quoted 29 lines
drivers/hwmon/pmbus/pmbus_core.c +3
-3if (rv <0 )return rv;@@ -2734,7 +2755,7 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,if (!(data->flags &PMBUS_NO_CAPABILITY )) {pmbus_wait (client); ret =i2c_smbus_read_byte_data (client,PMBUS_CAPABILITY ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (ret >=0 && (ret &PB_CAPABILITY_ERROR_CHECK )) {if (i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_PEC ))@@ -2750,13 +2771,13 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, data->read_status = pmbus_read_status_word;pmbus_wait (client); ret =i2c_smbus_read_word_data (client,PMBUS_STATUS_WORD ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (ret <0 || ret ==0xffff ) { data->read_status = pmbus_read_status_byte;pmbus_wait (client); ret =i2c_smbus_read_byte_data (client,PMBUS_STATUS_BYTE ); -pmbus_update_ts (client, false); +pmbus_update_ts (client,PMBUS_OP_READ );if (ret <0 || ret ==0xff ) {dev_err (dev,"PMBus status register not found\n" );