From 50c19bce3b44e95f0347fc0f946e3c2fe830a285 Mon Sep 17 00:00:00 2001 From: Gianni Vialetto Date: Tue, 8 Jul 2014 13:08:57 +0200 Subject: [PATCH] Expose LINEAR_MIN and LINEAR_MAX as hwmon sysfs properties Signed-off-by: Gianni Vialetto --- .../gpu/drm/nouveau/core/include/subdev/therm.h | 2 + drivers/gpu/drm/nouveau/core/subdev/therm/base.c | 14 +++++ drivers/gpu/drm/nouveau/nouveau_hwmon.c | 72 ++++++++++++++++++++++ 3 files changed, 88 insertions(+) diff --git a/drivers/gpu/drm/nouveau/core/include/subdev/therm.h b/drivers/gpu/drm/nouveau/core/include/subdev/therm.h index d4a6817..29ccf23 100644 --- a/drivers/gpu/drm/nouveau/core/include/subdev/therm.h +++ b/drivers/gpu/drm/nouveau/core/include/subdev/therm.h @@ -23,6 +23,8 @@ enum nouveau_therm_attr_type { NOUVEAU_THERM_ATTR_THRS_CRITICAL_HYST = 15, NOUVEAU_THERM_ATTR_THRS_SHUTDOWN = 16, NOUVEAU_THERM_ATTR_THRS_SHUTDOWN_HYST = 17, + NOUVEAU_THERM_ATTR_THRS_LINEAR_MIN = 18, + NOUVEAU_THERM_ATTR_THRS_LINEAR_MAX = 19, }; struct nouveau_therm { diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/base.c b/drivers/gpu/drm/nouveau/core/subdev/therm/base.c index 9ad01da..a56018f 100644 --- a/drivers/gpu/drm/nouveau/core/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/core/subdev/therm/base.c @@ -221,6 +221,10 @@ nouveau_therm_attr_get(struct nouveau_therm *therm, return priv->bios_sensor.thrs_shutdown.temp; case NOUVEAU_THERM_ATTR_THRS_SHUTDOWN_HYST: return priv->bios_sensor.thrs_shutdown.hysteresis; + case NOUVEAU_THERM_ATTR_THRS_LINEAR_MIN: + return priv->fan->bios.linear_min_temp; + case NOUVEAU_THERM_ATTR_THRS_LINEAR_MAX: + return priv->fan->bios.linear_max_temp; } return -EINVAL; @@ -281,6 +285,16 @@ nouveau_therm_attr_set(struct nouveau_therm *therm, priv->bios_sensor.thrs_shutdown.hysteresis = value; priv->sensor.program_alarms(therm); return 0; + case NOUVEAU_THERM_ATTR_THRS_LINEAR_MIN: + if (value < 0) + value = 0; + priv->fan->bios.linear_min_temp = value; + return 0; + case NOUVEAU_THERM_ATTR_THRS_LINEAR_MAX: + if (value < 0) + value = 0; + priv->fan->bios.linear_max_temp = value; + return 0; } return -EINVAL; diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c index 19fd767..5b7c830 100644 --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c @@ -516,6 +516,76 @@ static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO | S_IWUSR, nouveau_hwmon_get_pwm1_max, nouveau_hwmon_set_pwm1_max, 0); +static ssize_t +nouveau_hwmon_linear_min(struct device *d, struct device_attribute *a, + char *buf) +{ + struct drm_device *dev = dev_get_drvdata(d); + struct nouveau_drm *drm = nouveau_drm(dev); + struct nouveau_therm *therm = nouveau_therm(drm->device); + + return snprintf(buf, PAGE_SIZE, "%d\n", + therm->attr_get(therm, + NOUVEAU_THERM_ATTR_THRS_LINEAR_MIN) * 1000); +} +static ssize_t +nouveau_hwmon_set_linear_min(struct device *d, struct device_attribute *a, + const char *buf, + size_t count) +{ + struct drm_device *dev = dev_get_drvdata(d); + struct nouveau_drm *drm = nouveau_drm(dev); + struct nouveau_therm *therm = nouveau_therm(drm->device); + long value; + + if (kstrtol(buf, 10, &value) == -EINVAL) + return count; + + therm->attr_set(therm, + NOUVEAU_THERM_ATTR_THRS_LINEAR_MIN, value / 1000); + + return count; +} +static SENSOR_DEVICE_ATTR(temp1_linear_min, S_IRUGO | S_IWUSR, + nouveau_hwmon_linear_min, + nouveau_hwmon_set_linear_min, + 0); + +static ssize_t +nouveau_hwmon_linear_max(struct device *d, struct device_attribute *a, + char *buf) +{ + struct drm_device *dev = dev_get_drvdata(d); + struct nouveau_drm *drm = nouveau_drm(dev); + struct nouveau_therm *therm = nouveau_therm(drm->device); + + return snprintf(buf, PAGE_SIZE, "%d\n", + therm->attr_get(therm, + NOUVEAU_THERM_ATTR_THRS_LINEAR_MAX) * 1000); +} +static ssize_t +nouveau_hwmon_set_linear_max(struct device *d, struct device_attribute *a, + const char *buf, + size_t count) +{ + struct drm_device *dev = dev_get_drvdata(d); + struct nouveau_drm *drm = nouveau_drm(dev); + struct nouveau_therm *therm = nouveau_therm(drm->device); + long value; + + if (kstrtol(buf, 10, &value) == -EINVAL) + return count; + + therm->attr_set(therm, + NOUVEAU_THERM_ATTR_THRS_LINEAR_MAX, value / 1000); + + return count; +} +static SENSOR_DEVICE_ATTR(temp1_linear_max, S_IRUGO | S_IWUSR, + nouveau_hwmon_linear_max, + nouveau_hwmon_set_linear_max, + 0); + static struct attribute *hwmon_default_attributes[] = { &sensor_dev_attr_name.dev_attr.attr, &sensor_dev_attr_update_rate.dev_attr.attr, @@ -532,6 +602,8 @@ static struct attribute *hwmon_temp_attributes[] = { &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, &sensor_dev_attr_temp1_emergency.dev_attr.attr, &sensor_dev_attr_temp1_emergency_hyst.dev_attr.attr, + &sensor_dev_attr_temp1_linear_min.dev_attr.attr, + &sensor_dev_attr_temp1_linear_max.dev_attr.attr, NULL }; static struct attribute *hwmon_fan_rpm_attributes[] = { -- 2.0.1