Re: [Nouveau] [PATCH v5 3/5] nouveau_hwmon: Remove old code, add .write/.read operations
On 26/04/17 19:46, Oscar Salvador wrote: > This patch removes old code related to the old api and transforms the > functions for the new api. It also adds the .write and .read operations. > > Signed-off-by: Oscar Salvador > --- > drivers/gpu/drm/nouveau/nouveau_hwmon.c | 722 > +++- > 1 file changed, 249 insertions(+), 473 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > index e8ea8d0..4db65fb 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > @@ -38,21 +38,17 @@ > #include > > #if defined(CONFIG_HWMON) || (defined(MODULE) && > defined(CONFIG_HWMON_MODULE)) > -static ssize_t > -nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char > *buf) > +static int > +nouveau_hwmon_show_temp(struct nouveau_drm *drm) > { > - struct drm_device *dev = dev_get_drvdata(d); > - struct nouveau_drm *drm = nouveau_drm(dev); > struct nvkm_therm *therm = nvxx_therm(&drm->client.device); > int temp = nvkm_therm_temp_get(therm); > > if (temp < 0) > return temp; > > - return snprintf(buf, PAGE_SIZE, "%d\n", temp * 1000); > + return (temp * 1000); > } > -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp, > - NULL, 0); > > static ssize_t > nouveau_hwmon_show_temp1_auto_point1_pwm(struct device *d, > @@ -129,312 +125,100 @@ static > SENSOR_DEVICE_ATTR(temp1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, > nouveau_hwmon_temp1_auto_point1_temp_hyst, > nouveau_hwmon_set_temp1_auto_point1_temp_hyst, 0); > > -static ssize_t > -nouveau_hwmon_max_temp(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 nvkm_therm *therm = nvxx_therm(&drm->client.device); > - > - return snprintf(buf, PAGE_SIZE, "%d\n", > -therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) * 1000); > -} > -static ssize_t > -nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a, > - const char *buf, size_t count) > +static int > +nouveau_hwmon_max_temp(struct nouveau_drm *drm) > { > - struct drm_device *dev = dev_get_drvdata(d); > - struct nouveau_drm *drm = nouveau_drm(dev); > struct nvkm_therm *therm = nvxx_therm(&drm->client.device); > - long value; > > - if (kstrtol(buf, 10, &value) == -EINVAL) > - return count; > - > - therm->attr_set(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK, value / 1000); > - > - return count; > + return therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) * 1000; > } > -static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, > nouveau_hwmon_max_temp, > - nouveau_hwmon_set_max_temp, > - 0); > > -static ssize_t > -nouveau_hwmon_max_temp_hyst(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 nvkm_therm *therm = nvxx_therm(&drm->client.device); > - > - return snprintf(buf, PAGE_SIZE, "%d\n", > - therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST) * 1000); > -} > -static ssize_t > -nouveau_hwmon_set_max_temp_hyst(struct device *d, struct device_attribute *a, > - const char *buf, size_t count) > +static int > +nouveau_hwmon_max_temp_hyst(struct nouveau_drm *drm) > { > - struct drm_device *dev = dev_get_drvdata(d); > - struct nouveau_drm *drm = nouveau_drm(dev); > struct nvkm_therm *therm = nvxx_therm(&drm->client.device); > - long value; > - > - if (kstrtol(buf, 10, &value) == -EINVAL) > - return count; > > - therm->attr_set(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST, > - value / 1000); > - > - return count; > + return therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST) * > 1000; > } > -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, > - nouveau_hwmon_max_temp_hyst, > - nouveau_hwmon_set_max_temp_hyst, 0); > - > -static ssize_t > -nouveau_hwmon_critical_temp(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 nvkm_therm *therm = nvxx_therm(&drm->client.device); > > - return snprintf(buf, PAGE_SIZE, "%d\n", > -therm->attr_get(therm, NVKM_THERM_ATTR_THRS_CRITICAL) * 1000); > -} > -static ssize_t > -nouveau_hwmon_set_
[PATCH v5 3/5] nouveau_hwmon: Remove old code, add .write/.read operations
This patch removes old code related to the old api and transforms the functions for the new api. It also adds the .write and .read operations. Signed-off-by: Oscar Salvador --- drivers/gpu/drm/nouveau/nouveau_hwmon.c | 722 +++- 1 file changed, 249 insertions(+), 473 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c index e8ea8d0..4db65fb 100644 --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c @@ -38,21 +38,17 @@ #include #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) -static ssize_t -nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf) +static int +nouveau_hwmon_show_temp(struct nouveau_drm *drm) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); struct nvkm_therm *therm = nvxx_therm(&drm->client.device); int temp = nvkm_therm_temp_get(therm); if (temp < 0) return temp; - return snprintf(buf, PAGE_SIZE, "%d\n", temp * 1000); + return (temp * 1000); } -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp, - NULL, 0); static ssize_t nouveau_hwmon_show_temp1_auto_point1_pwm(struct device *d, @@ -129,312 +125,100 @@ static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, nouveau_hwmon_temp1_auto_point1_temp_hyst, nouveau_hwmon_set_temp1_auto_point1_temp_hyst, 0); -static ssize_t -nouveau_hwmon_max_temp(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 nvkm_therm *therm = nvxx_therm(&drm->client.device); - - return snprintf(buf, PAGE_SIZE, "%d\n", - therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) * 1000); -} -static ssize_t -nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a, - const char *buf, size_t count) +static int +nouveau_hwmon_max_temp(struct nouveau_drm *drm) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); struct nvkm_therm *therm = nvxx_therm(&drm->client.device); - long value; - if (kstrtol(buf, 10, &value) == -EINVAL) - return count; - - therm->attr_set(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK, value / 1000); - - return count; + return therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) * 1000; } -static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, nouveau_hwmon_max_temp, - nouveau_hwmon_set_max_temp, - 0); -static ssize_t -nouveau_hwmon_max_temp_hyst(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 nvkm_therm *therm = nvxx_therm(&drm->client.device); - - return snprintf(buf, PAGE_SIZE, "%d\n", - therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST) * 1000); -} -static ssize_t -nouveau_hwmon_set_max_temp_hyst(struct device *d, struct device_attribute *a, - const char *buf, size_t count) +static int +nouveau_hwmon_max_temp_hyst(struct nouveau_drm *drm) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); struct nvkm_therm *therm = nvxx_therm(&drm->client.device); - long value; - - if (kstrtol(buf, 10, &value) == -EINVAL) - return count; - therm->attr_set(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST, - value / 1000); - - return count; + return therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST) * 1000; } -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, - nouveau_hwmon_max_temp_hyst, - nouveau_hwmon_set_max_temp_hyst, 0); - -static ssize_t -nouveau_hwmon_critical_temp(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 nvkm_therm *therm = nvxx_therm(&drm->client.device); - return snprintf(buf, PAGE_SIZE, "%d\n", - therm->attr_get(therm, NVKM_THERM_ATTR_THRS_CRITICAL) * 1000); -} -static ssize_t -nouveau_hwmon_set_critical_temp(struct device *d, struct device_attribute *a, - const char *buf, -