hwmon: (pmbus): Core extension for STATUS_WORD and debugfs
cover hwmon: (pmbus): Core extension for STATUS_WORD and debugfs
From: "Edward A. James" <[email protected]>
This series adds some functionality to the pmbus core.
The first two patches provide support for the STATUS_WORD register. This allows more default alarm attributes to be used, as the upper byte of the status register is available. The third patch then uses the STATUS_INPUT bit of the status register to setup boolean attributes for input voltage and input power attributes.
The fourth patch provides support for raw reads of pmbus status registers through the debugfs interface. These can be very useful for hardware diagnostics, especially on multi-page pmbus devices, as user-space access of the i2c space could corrupt the pmbus page accounting.
Edward A. James (4):
hwmon: (pmbus): Switch status registers to 16 bit
hwmon: (pmbus): Access word data for STATUS_WORD
hwmon: (pmbus): Add generic alarm bit for iin and pin
hwmon: (pmbus): Add debugfs for status registers
drivers/hwmon/pmbus/pmbus.h | 6 + drivers/hwmon/pmbus/pmbus_core.c | 279 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 263 insertions(+), 22 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/4 hwmon: (pmbus): Switch status registers to 16 bit
From: "Edward A. James" <[email protected]>
Switch the storage of status registers to 16 bit values. This allows us to store all the bits of STATUS_WORD.
--- drivers/hwmon/pmbus/pmbus_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +7 -7
@@ -113,7 +113,7 @@ struct pmbus_data {* A single status register covers multiple attributes, * so we keep them all together. */ -u8 status[PB_NUM_STATUS_REG ]; +u16 status[PB_NUM_STATUS_REG ];u8 status_register;u8 currpage;
@@ -858,10 +858,10 @@ static int pmbus_get_boolean(struct pmbus_data *data, struct pmbus_boolean *b, {struct pmbus_sensor *s1 = b->s1;struct pmbus_sensor *s2 = b->s2; -u16 reg = (index >>8 ) &0xffff ; -u8 mask = index &0xff ; +u16 reg = (index >>16 ) &0xffff ; +u16 mask = index &0xffff ;int ret, status; -u8 regval; +u16 regval; status = data->status[reg];if (status <0 )
@@ -1002,7 +1002,7 @@ static int pmbus_add_boolean(struct pmbus_data *data, const char *name, const char *type, int seq, struct pmbus_sensor *s1, struct pmbus_sensor *s2, - u16 reg, u8 mask) + u16 reg, u16 mask) { struct pmbus_boolean *boolean;struct sensor_device_attribute *a;
@@ -1018,7 +1018,7 @@ static int pmbus_add_boolean(struct pmbus_data *data, boolean->s1 = s1; boolean->s2 = s2;pmbus_attr_init (a, boolean->name,S_IRUGO , pmbus_show_boolean,NULL , - (reg <<8 ) | mask); + (reg <<16 ) | mask);return pmbus_add_attribute (data, &a->dev_attr.attr); }
@@ -1110,7 +1110,7 @@ struct pmbus_limit_attr {*/ struct pmbus_sensor_attr {u16 reg;/* sensor register */ -u8 gbit;/* generic status bit */ +u16 gbit;/* generic status bit */ u8 nlimit;/* # of limit registers */ enum pmbus_sensor_classes class;/* sensor class */ const char *label;/* sensor label */
Signature · 1 line
1.8.3.1
PATCH 2/4 hwmon: (pmbus): Access word data for STATUS_WORD
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
Pmbus always reads byte data from the status register, even if configured to use STATUS_WORD. Use a function pointer to read the correct amount of data from the registers.
Also switch to try STATUS_WORD first before STATUS_BYTE on init.
--- drivers/hwmon/pmbus/pmbus_core.c | 54 +++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 14 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +40 -14
@@ -114,7 +114,8 @@ struct pmbus_data {* so we keep them all together. */ u16 status[PB_NUM_STATUS_REG ]; -u8 status_register; + +int (*read_status)(struct i2c_client *client,int page);u8 currpage; };
@@ -460,7 +461,7 @@ static int pmbus_check_status_cml(struct i2c_client *client)struct pmbus_data *data =i2c_get_clientdata (client);int status, status2; - status =_pmbus_read_byte_data (client,-1 , data->status_register); + status = data->read_status (client,-1 );if (status <0 || (status &PB_STATUS_CML )) { status2 =_pmbus_read_byte_data (client,-1 ,PMBUS_STATUS_CML );if (status2 <0 || (status2 &PB_CML_FAULT_INVALID_COMMAND ))
@@ -484,6 +485,23 @@ static bool pmbus_check_register(struct i2c_client *client,return rv >=0 ; } +static bool pmbus_check_status_register (struct i2c_client *client,int page) +{ +int status; +struct pmbus_data *data =i2c_get_clientdata (client); + + status = data->read_status (client, page); +if (status >=0 && !(data->flags &PMBUS_SKIP_STATUS_CHECK ) && + (status &PB_STATUS_CML )) { + status =_pmbus_read_byte_data (client,-1 ,PMBUS_STATUS_CML ); +if (status <0 || (status &PB_CML_FAULT_INVALID_COMMAND )) + status = -EIO ; + } + +pmbus_clear_fault_page (client,-1 ); +return status >=0 ; +} +bool pmbus_check_byte_register (struct i2c_client *client,int page,int reg) {return pmbus_check_register (client, _pmbus_read_byte_data, page, reg);
@@ -530,8 +548,7 @@ static struct pmbus_data *pmbus_update_device(struct device *dev)for (i =0 ; i < info->pages; i++) { data->status[PB_STATUS_BASE + i] - =_pmbus_read_byte_data (client, i, - data->status_register); + = data->read_status (client, i);for (j =0 ; j <ARRAY_SIZE (pmbus_status); j++) {struct _pmbus_status *s = &pmbus_status[j];
@@ -1199,8 +1216,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,* the generic status register for this page is accessible. */ if (!ret && attr->gbit && -pmbus_check_byte_register (client, page, - data->status_register)) { +pmbus_check_status_register (client, page)) { ret = pmbus_add_boolean(data, name, "alarm", index, NULL, NULL, PB_STATUS_BASE + page,
@@ -1921,6 +1937,16 @@ static int pmbus_identify_common(struct i2c_client *client,return 0 ; } +static int pmbus_read_status_byte (struct i2c_client *client,int page) +{ +return _pmbus_read_byte_data (client, page,PMBUS_STATUS_BYTE ); +} + +static int pmbus_read_status_word (struct i2c_client *client,int page) +{ +return _pmbus_read_word_data (client, page,PMBUS_STATUS_WORD ); +} +static int pmbus_init_common (struct i2c_client *client,struct pmbus_data *data,struct pmbus_driver_info *info) {
@@ -1928,16 +1954,16 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,int page, ret;/* -* Some PMBus chips don't support PMBUS_STATUS_BYTE, so try -* to use PMBUS_STATUS_WORD instead if that is the case. +* Some PMBus chips don't support PMBUS_STATUS_WORD, so try +* to use PMBUS_STATUS_BYTE instead if that is the case. * Bail out if both registers are not supported. */ - data->status_register =PMBUS_STATUS_BYTE ; - ret =i2c_smbus_read_byte_data (client,PMBUS_STATUS_BYTE ); -if (ret <0 || ret ==0xff ) { - data->status_register =PMBUS_STATUS_WORD ; - ret =i2c_smbus_read_word_data (client,PMBUS_STATUS_WORD ); -if (ret <0 || ret ==0xffff ) { + data->read_status = pmbus_read_status_word; + ret =i2c_smbus_read_word_data (client,PMBUS_STATUS_WORD ); +if (ret <0 || ret ==0xffff ) { + data->read_status = pmbus_read_status_byte; + ret =i2c_smbus_read_byte_data (client,PMBUS_STATUS_BYTE ); +if (ret <0 || ret ==0xff ) {dev_err (dev,"PMBus status register not found\n" );return -ENODEV ; }
Signature · 1 line
1.8.3.1
PATCH 3/4 hwmon: (pmbus): Add generic alarm bit for iin and pin
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
Add PB_STATUS_INPUT as the generic alarm bit for iin and pin. We also need to redo the status register checking before setting up the boolean attribute, since it won't necessarily check STATUS_WORD if the device doesn't support it, which we need for this bit.
--- drivers/hwmon/pmbus/pmbus_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus_core.c +9 -1
@@ -115,6 +115,7 @@ struct pmbus_data {*/ u16 status[PB_NUM_STATUS_REG ]; +bool has_status_word;/* device uses STATUS_WORD register */ int (*read_status)(struct i2c_client *client,int page);u8 currpage;
@@ -1193,6 +1194,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, const struct pmbus_sensor_attr *attr) {struct pmbus_sensor *base; +bool upper = !!(attr->gbit &0xff00 );/* need to check STATUS_WORD */ int ret;if (attr->label) {
@@ -1213,9 +1215,11 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,/* * Add generic alarm attribute only if there are no individual * alarm attributes, if there is a global alarm bit, and if -* the generic status register for this page is accessible. +* the generic status register (word or byte, depending on +* which global bit is set) for this page is accessible. */ if (!ret && attr->gbit && + (!upper || (upper && data->has_status_word)) &&pmbus_check_status_register (client, page)) { ret = pmbus_add_boolean(data, name, "alarm", index, NULL, NULL,
@@ -1472,6 +1476,7 @@ static int pmbus_add_sensor_attrs(struct i2c_client *client, .func = PMBUS_HAVE_IIN, .sfunc = PMBUS_HAVE_STATUS_INPUT, .sbase = PB_STATUS_INPUT_BASE, + .gbit = PB_STATUS_INPUT, .limit = iin_limit_attrs, .nlimit = ARRAY_SIZE(iin_limit_attrs), }, {
@@ -1556,6 +1561,7 @@ static int pmbus_add_sensor_attrs(struct i2c_client *client, .func = PMBUS_HAVE_PIN, .sfunc = PMBUS_HAVE_STATUS_INPUT, .sbase = PB_STATUS_INPUT_BASE, + .gbit = PB_STATUS_INPUT, .limit = pin_limit_attrs, .nlimit = ARRAY_SIZE(pin_limit_attrs), }, {
@@ -1967,6 +1973,8 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,dev_err (dev,"PMBus status register not found\n" );return -ENODEV ; } + }else { + data->has_status_word = true; }/* Enable PEC if the controller supports it */
Signature · 1 line
1.8.3.1
PATCH 4/4 hwmon: (pmbus): Add debugfs for status registers
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
Export all the available status registers through debugfs, if the client driver wants them.
--- drivers/hwmon/pmbus/pmbus.h | 6 ++ drivers/hwmon/pmbus/pmbus_core.c | 201 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+)
drivers/hwmon/pmbus/pmbus.h +6 -0
@@ -410,6 +410,12 @@ struct pmbus_driver_info {/* Regulator functionality, if supported by this chip driver. */ int num_regulators;const struct regulator_desc *reg_desc; + +/* +* Controls whether or not to create debugfs entries for this driver's +* devices. +*/ +bool debugfs; };/* Regulator ops */
drivers/hwmon/pmbus/pmbus_core.c +201 -0
237 lines not on this page · raw message
Signature · 1 line
1.8.3.1