pmbus: Fix error propagation for register check functions
Subsystems (2)
cover pmbus: Fix error propagation for register check functions
Hello,
This series resolves an issue with pmbus functions such as pmbus_check_byte_register() not reporting errors triggered by the PAGE command. Currently such an error is interpreted as the device not supporting the command, rather than exposing the problem that occurred.
The first patch has been sent upstream:
https://lkml.org/lkml/2017/9/5/53
The second and third patches resolve fallout from the first patch with the MAX31785 driver. The fallout primarily surrounds the driver's unusual use of virtual pages.
Andrew Jeffery (3):
hwmon: pmbus: Make reg check and clear faults functions return errors
hwmon: pmbus: Add set_page() callback
pmbus: max31785: Add handler for set_page() and PMBUS_CLEAR_FAULTS
virt pages
Documentation/hwmon/pmbus-core | 12 ++-- drivers/hwmon/pmbus/max31785.c | 13 ++++ drivers/hwmon/pmbus/pmbus.h | 7 ++- drivers/hwmon/pmbus/pmbus_core.c | 132 ++++++++++++++++++++++++++++++--------- 4 files changed, 125 insertions(+), 39 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/3 hwmon: pmbus: Make reg check and clear faults functions return errors
Some functions exposed by pmbus core conflated errors that occurred when setting the page to access with errors that occurred when accessing registers in a page. In some cases, this caused legitimate errors to be hidden under the guise of the register not being supported.
--- Documentation/hwmon/pmbus-core | 12 ++-- drivers/hwmon/pmbus/pmbus.h | 6 +- drivers/hwmon/pmbus/pmbus_core.c | 115 +++++++++++++++++++++++++++++---------- 3 files changed, 95 insertions(+), 38 deletions(-)
Documentation/hwmon/pmbus-core +6 -6
@@ -218,17 +218,17 @@ Specifically, it provides the following information. This function calls the device specific write_byte function if defined. Therefore, it must _not_ be called from that function. - bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg); + int pmbus_check_byte_register(struct i2c_client *client, int page, int reg); - Check if byte register exists. Return true if the register exists, false - otherwise. + Check if byte register exists. Returns 1 if the register exists, 0 if it does + not, and less than zero on an unexpected error. This function calls the device specific write_byte function if defined to obtain the chip status. Therefore, it must _not_ be called from that function. - bool pmbus_check_word_register(struct i2c_client *client, int page, int reg); + int pmbus_check_word_register(struct i2c_client *client, int page, int reg); - Check if word register exists. Return true if the register exists, false - otherwise. + Check if word register exists. Returns 1 if the register exists, 0 if it does + not, and less than zero on an unexpected error. This function calls the device specific write_byte function if defined to obtain the chip status. Therefore, it must _not_ be called from that function.
drivers/hwmon/pmbus/pmbus.h +3 -3
@@ -442,9 +442,9 @@ int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg, u8 mask, u8 value);int pmbus_update_fan (struct i2c_client *client,int page,int id,u8 config,u8 mask,u16 command); -void pmbus_clear_faults (struct i2c_client *client); -bool pmbus_check_byte_register (struct i2c_client *client,int page,int reg); -bool pmbus_check_word_register (struct i2c_client *client,int page,int reg); +int pmbus_clear_faults (struct i2c_client *client); +int pmbus_check_byte_register (struct i2c_client *client,int page,int reg); +int pmbus_check_word_register (struct i2c_client *client,int page,int reg);int pmbus_do_probe (struct i2c_client *client,const struct i2c_device_id *id,struct pmbus_driver_info *info);int pmbus_do_remove (struct i2c_client *client);
drivers/hwmon/pmbus/pmbus_core.c +86 -29
230 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 2/3 hwmon: pmbus: Add set_page() callback
In reply to Andrew JefferyWith the improvement to error reporting in the PMBus core, issuing CLEAR_FAULTS now propagates the error up the call chain where in the past it was swallowed. This error propagation affects the 'virtual pages' implemented in the max31785 driver: In some circumstances pmbus_clear_faults() is issued unconditionally against a device. pmbus_clear_faults() eventually calls pmbus_set_page(), which may issue a PAGE command to the device. pmbus_set_page() issues i2c_smbus_write_byte_data() directly, not routing through any of the existing write path hooks, leaving the driver with no method to intercept it.
As such, add a callback so we can intercept it.
--- drivers/hwmon/pmbus/pmbus.h | 1 + drivers/hwmon/pmbus/pmbus_core.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus.h +1 -0
@@ -394,6 +394,7 @@ struct pmbus_driver_info {* register does not exist, and that no attempt should be made to read * the standard register. */ +int (*set_page)(struct i2c_client *client,int page);int (*read_byte_data)(struct i2c_client *client,int page,int reg);int (*read_word_data)(struct i2c_client *client,int page,int reg); int (*write_word_data)(struct i2c_client *client, int page, int reg,
drivers/hwmon/pmbus/pmbus_core.c +16 -1
@@ -158,7 +158,7 @@ void pmbus_clear_cache(struct i2c_client *client) }EXPORT_SYMBOL_GPL (pmbus_clear_cache); -int pmbus_set_page (struct i2c_client *client,u8 page) +static int _pmbus_set_page (struct i2c_client *client,u8 page) {struct pmbus_data *data =i2c_get_clientdata (client);int rv =0 ;
@@ -174,6 +174,21 @@ int pmbus_set_page(struct i2c_client *client, u8 page) }return rv; } + +int pmbus_set_page (struct i2c_client *client,u8 page) +{ +struct pmbus_data *data =i2c_get_clientdata (client); +const struct pmbus_driver_info *info = data->info; +int status; + +if (info->set_page) { + status = info->set_page (client, page); +if (status != -ENODATA ) +return status; + } + +return _pmbus_set_page (client, page); +}EXPORT_SYMBOL_GPL (pmbus_set_page);int pmbus_write_byte (struct i2c_client *client,int page,u8 value)
Signature · 1 line
2.11.0
PATCH 3/3 pmbus: max31785: Add handler for set_page() and PMBUS_CLEAR_FAULTS virt pages
In reply to Andrew JefferyThe max31785 uses the concept of 'virtual pages' to manage dual tach fan inputs. These pages don't exist in hardware by definition, so don't send spurious PAGE or CLEAR_FAULTS commands to the device for these pages.
--- drivers/hwmon/pmbus/max31785.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/hwmon/pmbus/max31785.c +13 -0
@@ -117,11 +117,23 @@ static int max31785_read_byte_data(struct i2c_client *client, int page,return -ENODATA ; } +static int max31785_set_page (struct i2c_client *client,int page) +{ +return (page <MAX31785_NR_PAGES ) ? -ENODATA :0 ; +} +static int max31785_write_byte (struct i2c_client *client,int page,u8 value) {if (page <MAX31785_NR_PAGES )return -ENODATA ; +switch (value) { +case PMBUS_CLEAR_FAULTS : +return 0 ; +default : +break ; + } +return -ENOTSUPP ; }
@@ -604,6 +616,7 @@ static int max31785_of_tmp_config(struct i2c_client *client,static const struct pmbus_driver_info max31785_info = { .pages =MAX31785_NR_PAGES , + .set_page = max31785_set_page, .write_word_data = max31785_write_word_data, .read_byte_data = max31785_read_byte_data, .read_word_data = max31785_read_word_data,
Signature · 1 line
2.11.0