]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/nouveau/hwmon: expose the auto_point and pwm_min/max attrs
authorOscar Salvador <osalvador.vilardaga@gmail.com>
Thu, 18 May 2017 21:24:37 +0000 (23:24 +0200)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 16 Jun 2017 04:05:02 +0000 (14:05 +1000)
This patch creates a special group attributes for attrs like "*auto_point*".
We check if we have support for them, and if we do, we gather them all in
an attribute_group's structure which is the parameter regarding special groups
of hwmon_device_register_with_info
We also do the same for pwm_min/max attrs.

Signed-off-by: Oscar Salvador <osalvador.vilardaga@gmail.com>
Reviewed-by: Martin Peres <martin.peres@free.fr>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/nouveau_hwmon.c

index bb0718579c2c3ba6172fe95996fdf6b6a38e86a2..2304189addcb746f34ea7a6d6439950406eff11f 100644 (file)
@@ -192,6 +192,27 @@ static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO | S_IWUSR,
                          nouveau_hwmon_get_pwm1_max,
                          nouveau_hwmon_set_pwm1_max, 0);
 
+static struct attribute *pwm_fan_sensor_attrs[] = {
+       &sensor_dev_attr_pwm1_min.dev_attr.attr,
+       &sensor_dev_attr_pwm1_max.dev_attr.attr,
+       NULL
+};
+static const struct attribute_group pwm_fan_sensor_group = {
+       .attrs = pwm_fan_sensor_attrs,
+};
+
+static struct attribute *temp1_auto_point_sensor_attrs[] = {
+       &sensor_dev_attr_temp1_auto_point1_pwm.dev_attr.attr,
+       &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
+       NULL
+};
+static const struct attribute_group temp1_auto_point_sensor_group = {
+       .attrs = temp1_auto_point_sensor_attrs,
+};
+
+#define N_ATTR_GROUPS   3
+
 static const u32 nouveau_config_chip[] = {
        HWMON_C_UPDATE_INTERVAL,
        0
@@ -687,17 +708,28 @@ nouveau_hwmon_init(struct drm_device *dev)
 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
        struct nouveau_drm *drm = nouveau_drm(dev);
        struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+       const struct attribute_group *special_groups[N_ATTR_GROUPS];
        struct nouveau_hwmon *hwmon;
        struct device *hwmon_dev;
        int ret = 0;
+       int i = 0;
 
        hwmon = drm->hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL);
        if (!hwmon)
                return -ENOMEM;
        hwmon->dev = dev;
 
+       if (therm && therm->attr_get && therm->attr_set) {
+               if (nvkm_therm_temp_get(therm) >= 0)
+                       special_groups[i++] = &temp1_auto_point_sensor_group;
+               if (therm->fan_get && therm->fan_get(therm) >= 0)
+                       special_groups[i++] = &pwm_fan_sensor_group;
+       }
+
+       special_groups[i] = 0;
        hwmon_dev = hwmon_device_register_with_info(dev->dev, "nouveau", dev,
-                                                       &nouveau_chip_info, NULL);
+                                                       &nouveau_chip_info,
+                                                       special_groups);
        if (IS_ERR(hwmon_dev)) {
                ret = PTR_ERR(hwmon_dev);
                NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret);