[PATCH v3 4/4] hwmon: (pmbus/core): Notify hwmon events

From: Naresh Solanki
Date: Wed Nov 30 2022 - 12:06:04 EST


Notify hwmon events using the pmbus irq handler.

Signed-off-by: Naresh Solanki <Naresh.Solanki@xxxxxxxxxxxxx>
---
drivers/hwmon/pmbus/pmbus_core.c | 37 +++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 613e2e484a0f..da92a08484c9 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2805,8 +2805,36 @@ static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] =
},
};

+#define to_dev_attr(_dev_attr) \
+ container_of(_dev_attr, struct device_attribute, attr)
+
+static void pmbus_notify(struct pmbus_data *data, int page, int reg, int flags)
+{
+ int i;
+
+ for (i = 0; i < data->num_attributes; i++) {
+ struct device_attribute *da = to_dev_attr(data->group.attrs[i]);
+ struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+ int index = attr->index;
+ u16 smask = pb_index_to_mask(index);
+ u8 spage = pb_index_to_page(index);
+ u16 sreg = pb_index_to_reg(index);
+
+ if (reg == sreg && page == spage && (smask & flags)) {
+ dev_dbg(data->dev, "sysfs notify: %s", da->attr.name);
+ sysfs_notify(&data->dev->kobj, NULL, da->attr.name);
+ kobject_uevent(&data->dev->kobj, KOBJ_CHANGE);
+ }
+
+ flags &= ~smask;
+
+ if (!flags)
+ break;
+ }
+}
+
static int pmbus_regulator_get_flags(struct regulator_dev *rdev, unsigned int *error,
- unsigned int *event)
+ unsigned int *event, bool notify)
{
int i, status;
const struct pmbus_regulator_status_category *cat;
@@ -2833,6 +2861,9 @@ static int pmbus_regulator_get_flags(struct regulator_dev *rdev, unsigned int *e
return status;
}

+ if (notify && status)
+ pmbus_notify(data, page, cat->reg, status);
+
for (bit = cat->bits; bit->pflag; bit++) {
if (status & bit->pflag) {
*error |= bit->rflag;
@@ -2885,7 +2916,7 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
{
unsigned int event;

- return pmbus_regulator_get_flags(rdev, flags, &event);
+ return pmbus_regulator_get_flags(rdev, flags, &event, false);
}

static int pmbus_regulator_get_status(struct regulator_dev *rdev)
@@ -3095,7 +3126,7 @@ static irqreturn_t pmbus_fault_handler(int irq, void *pdata)
if (!data->rdevs[i])
continue;

- ret = pmbus_regulator_get_flags(data->rdevs[i], &status, &event);
+ ret = pmbus_regulator_get_flags(data->rdevs[i], &status, &event, true);
if (ret)
return ret;

--
2.37.3