Skip to content

Commit c6bfb76

Browse files
author
Guenter Roeck
committed
hwmon: (pmbus) Strengthen check for status register existence
With virtual register page support, it is now possible that the status register on virtual pages does not exist or is itself virtual. To take this into account when creating alarm attributes, generate those attributes only if the status register on the respective page is known to exist. Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com> Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
1 parent 9c1ed89 commit c6bfb76

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

‎drivers/hwmon/pmbus/pmbus_core.c‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,24 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg)
254254
}
255255
EXPORT_SYMBOL_GPL(pmbus_read_byte_data);
256256

257+
/*
258+
* _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if
259+
* a device specific mapping function exists and calls it if necessary.
260+
*/
261+
static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg)
262+
{
263+
struct pmbus_data *data = i2c_get_clientdata(client);
264+
const struct pmbus_driver_info *info = data->info;
265+
int status;
266+
267+
if (info->read_byte_data) {
268+
status = info->read_byte_data(client, page, reg);
269+
if (status != -ENODATA)
270+
return status;
271+
}
272+
return pmbus_read_byte_data(client, page, reg);
273+
}
274+
257275
static void pmbus_clear_fault_page(struct i2c_client *client, int page)
258276
{
259277
pmbus_write_byte(client, page, PMBUS_CLEAR_FAULTS);
@@ -287,7 +305,7 @@ bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg)
287305
int rv;
288306
struct pmbus_data *data = i2c_get_clientdata(client);
289307

290-
rv = pmbus_read_byte_data(client, page, reg);
308+
rv = _pmbus_read_byte_data(client, page, reg);
291309
if (rv >= 0 && !(data->flags & PMBUS_SKIP_STATUS_CHECK))
292310
rv = pmbus_check_status_cml(client);
293311
pmbus_clear_fault_page(client, -1);
@@ -316,24 +334,6 @@ const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client *client)
316334
}
317335
EXPORT_SYMBOL_GPL(pmbus_get_driver_info);
318336

319-
/*
320-
* _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if
321-
* a device specific mapping function exists and calls it if necessary.
322-
*/
323-
static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg)
324-
{
325-
struct pmbus_data *data = i2c_get_clientdata(client);
326-
const struct pmbus_driver_info *info = data->info;
327-
int status;
328-
329-
if (info->read_byte_data) {
330-
status = info->read_byte_data(client, page, reg);
331-
if (status != -ENODATA)
332-
return status;
333-
}
334-
return pmbus_read_byte_data(client, page, reg);
335-
}
336-
337337
static struct pmbus_data *pmbus_update_device(struct device *dev)
338338
{
339339
struct i2c_client *client = to_i2c_client(dev);
@@ -1037,9 +1037,11 @@ static void pmbus_add_sensor_attrs_one(struct i2c_client *client,
10371037
index, page, cbase, attr);
10381038
/*
10391039
* Add generic alarm attribute only if there are no individual
1040-
* alarm attributes, and if there is a global alarm bit.
1040+
* alarm attributes, if there is a global alarm bit, and if
1041+
* the generic status register for this page is accessible.
10411042
*/
1042-
if (!have_alarm && attr->gbit)
1043+
if (!have_alarm && attr->gbit &&
1044+
pmbus_check_byte_register(client, page, PMBUS_STATUS_BYTE))
10431045
pmbus_add_boolean_reg(data, name, "alarm", index,
10441046
PB_STATUS_BASE + page,
10451047
attr->gbit);

0 commit comments

Comments
 (0)