]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/hwmon/pmbus/pmbus_core.c
hwmon: (pmbus/core) Treat parameters as paged if on multiple pages
[mirror_ubuntu-bionic-kernel.git] / drivers / hwmon / pmbus / pmbus_core.c
index 924f3ca41c65a56f40007ea3c323bfbfc9b0b980..cb9064ac4977e279daac52180e725eb7e6f749af 100644 (file)
@@ -1055,7 +1055,8 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
                                      const struct pmbus_driver_info *info,
                                      const char *name,
                                      int index, int page,
-                                     const struct pmbus_sensor_attr *attr)
+                                     const struct pmbus_sensor_attr *attr,
+                                     bool paged)
 {
        struct pmbus_sensor *base;
        bool upper = !!(attr->gbit & 0xff00);   /* need to check STATUS_WORD */
@@ -1063,7 +1064,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
 
        if (attr->label) {
                ret = pmbus_add_label(data, name, index, attr->label,
-                                     attr->paged ? page + 1 : 0);
+                                     paged ? page + 1 : 0);
                if (ret)
                        return ret;
        }
@@ -1096,6 +1097,30 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
        return 0;
 }
 
+static bool pmbus_sensor_is_paged(const struct pmbus_driver_info *info,
+                                 const struct pmbus_sensor_attr *attr)
+{
+       int p;
+
+       if (attr->paged)
+               return true;
+
+       /*
+        * Some attributes may be present on more than one page despite
+        * not being marked with the paged attribute. If that is the case,
+        * then treat the sensor as being paged and add the page suffix to the
+        * attribute name.
+        * We don't just add the paged attribute to all such attributes, in
+        * order to maintain the un-suffixed labels in the case where the
+        * attribute is only on page 0.
+        */
+       for (p = 1; p < info->pages; p++) {
+               if (info->func[p] & attr->func)
+                       return true;
+       }
+       return false;
+}
+
 static int pmbus_add_sensor_attrs(struct i2c_client *client,
                                  struct pmbus_data *data,
                                  const char *name,
@@ -1109,14 +1134,15 @@ static int pmbus_add_sensor_attrs(struct i2c_client *client,
        index = 1;
        for (i = 0; i < nattrs; i++) {
                int page, pages;
+               bool paged = pmbus_sensor_is_paged(info, attrs);
 
-               pages = attrs->paged ? info->pages : 1;
+               pages = paged ? info->pages : 1;
                for (page = 0; page < pages; page++) {
                        if (!(info->func[page] & attrs->func))
                                continue;
                        ret = pmbus_add_sensor_attrs_one(client, data, info,
                                                         name, index, page,
-                                                        attrs);
+                                                        attrs, paged);
                        if (ret)
                                return ret;
                        index++;