public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups
@ 2013-11-23  5:52 Guenter Roeck
  2013-11-23  5:52 ` [PATCH 2/2] drm/nouveau/hwmon: Convert to use devm_hwmon_device_register_with_groups Guenter Roeck
  2013-11-25 18:07 ` [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups Guenter Roeck
  0 siblings, 2 replies; 4+ messages in thread
From: Guenter Roeck @ 2013-11-23  5:52 UTC (permalink / raw)
  To: David Airlie; +Cc: lm-sensors, dri-devel, linux-kernel, Guenter Roeck

Simplify the code and fix race condition seen because
attribute files were created after hwmon device registration.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
Compile tested only; unfortunately I don't have the the necessary hardware.

 drivers/gpu/drm/radeon/radeon_pm.c |   49 +++++++++---------------------------
 1 file changed, 12 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_pm.c b/drivers/gpu/drm/radeon/radeon_pm.c
index d1385cc..dc75bb6 100644
--- a/drivers/gpu/drm/radeon/radeon_pm.c
+++ b/drivers/gpu/drm/radeon/radeon_pm.c
@@ -537,8 +537,7 @@ static ssize_t radeon_hwmon_show_temp(struct device *dev,
 				      struct device_attribute *attr,
 				      char *buf)
 {
-	struct drm_device *ddev = dev_get_drvdata(dev);
-	struct radeon_device *rdev = ddev->dev_private;
+	struct radeon_device *rdev = dev_get_drvdata(dev);
 	int temp;
 
 	if (rdev->asic->pm.get_temperature)
@@ -566,23 +565,14 @@ static ssize_t radeon_hwmon_show_temp_thresh(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%d\n", temp);
 }
 
-static ssize_t radeon_hwmon_show_name(struct device *dev,
-				      struct device_attribute *attr,
-				      char *buf)
-{
-	return sprintf(buf, "radeon\n");
-}
-
 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, radeon_hwmon_show_temp, NULL, 0);
 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, radeon_hwmon_show_temp_thresh, NULL, 0);
 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, radeon_hwmon_show_temp_thresh, NULL, 1);
-static SENSOR_DEVICE_ATTR(name, S_IRUGO, radeon_hwmon_show_name, NULL, 0);
 
 static struct attribute *hwmon_attributes[] = {
 	&sensor_dev_attr_temp1_input.dev_attr.attr,
 	&sensor_dev_attr_temp1_crit.dev_attr.attr,
 	&sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
-	&sensor_dev_attr_name.dev_attr.attr,
 	NULL
 };
 
@@ -607,11 +597,15 @@ static const struct attribute_group hwmon_attrgroup = {
 	.is_visible = hwmon_attributes_visible,
 };
 
+static const struct attribute_group *hwmon_groups[] = {
+	&hwmon_attrgroup,
+	NULL
+};
+
 static int radeon_hwmon_init(struct radeon_device *rdev)
 {
 	int err = 0;
-
-	rdev->pm.int_hwmon_dev = NULL;
+	struct device *hwmon_dev;
 
 	switch (rdev->pm.int_thermal_type) {
 	case THERMAL_TYPE_RV6XX:
@@ -624,20 +618,13 @@ static int radeon_hwmon_init(struct radeon_device *rdev)
 	case THERMAL_TYPE_KV:
 		if (rdev->asic->pm.get_temperature == NULL)
 			return err;
-		rdev->pm.int_hwmon_dev = hwmon_device_register(rdev->dev);
-		if (IS_ERR(rdev->pm.int_hwmon_dev)) {
-			err = PTR_ERR(rdev->pm.int_hwmon_dev);
+		hwmon_dev = hwmon_device_register_with_groups(rdev->dev,
+							      "radeon", rdev,
+							      hwmon_groups);
+		if (IS_ERR(hwmon_dev)) {
+			err = PTR_ERR(hwmon_dev);
 			dev_err(rdev->dev,
 				"Unable to register hwmon device: %d\n", err);
-			break;
-		}
-		dev_set_drvdata(rdev->pm.int_hwmon_dev, rdev->ddev);
-		err = sysfs_create_group(&rdev->pm.int_hwmon_dev->kobj,
-					 &hwmon_attrgroup);
-		if (err) {
-			dev_err(rdev->dev,
-				"Unable to create hwmon sysfs file: %d\n", err);
-			hwmon_device_unregister(rdev->dev);
 		}
 		break;
 	default:
@@ -647,14 +634,6 @@ static int radeon_hwmon_init(struct radeon_device *rdev)
 	return err;
 }
 
-static void radeon_hwmon_fini(struct radeon_device *rdev)
-{
-	if (rdev->pm.int_hwmon_dev) {
-		sysfs_remove_group(&rdev->pm.int_hwmon_dev->kobj, &hwmon_attrgroup);
-		hwmon_device_unregister(rdev->pm.int_hwmon_dev);
-	}
-}
-
 static void radeon_dpm_thermal_work_handler(struct work_struct *work)
 {
 	struct radeon_device *rdev =
@@ -1337,8 +1316,6 @@ static void radeon_pm_fini_old(struct radeon_device *rdev)
 
 	if (rdev->pm.power_state)
 		kfree(rdev->pm.power_state);
-
-	radeon_hwmon_fini(rdev);
 }
 
 static void radeon_pm_fini_dpm(struct radeon_device *rdev)
@@ -1358,8 +1335,6 @@ static void radeon_pm_fini_dpm(struct radeon_device *rdev)
 
 	if (rdev->pm.power_state)
 		kfree(rdev->pm.power_state);
-
-	radeon_hwmon_fini(rdev);
 }
 
 void radeon_pm_fini(struct radeon_device *rdev)
-- 
1.7.9.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] drm/nouveau/hwmon: Convert to use devm_hwmon_device_register_with_groups
  2013-11-23  5:52 [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups Guenter Roeck
@ 2013-11-23  5:52 ` Guenter Roeck
  2013-11-25 18:07 ` [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups Guenter Roeck
  1 sibling, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2013-11-23  5:52 UTC (permalink / raw)
  To: David Airlie; +Cc: lm-sensors, dri-devel, linux-kernel, Guenter Roeck

Simplify the code and resolve race conditions seen because
attribute files are created after hwmon device registration,
and removed before hwmon device removal.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
Compile tested only; unfortunately I don't have the the necessary hardware.

 drivers/gpu/drm/nouveau/nouveau_hwmon.c |  243 +++++++++++--------------------
 drivers/gpu/drm/nouveau/nouveau_hwmon.h |   11 --
 2 files changed, 84 insertions(+), 170 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
index 38a4db5..d4144b8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c
+++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
@@ -42,9 +42,7 @@
 static ssize_t
 nouveau_hwmon_show_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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	int temp = therm->temp_get(therm);
 
 	if (temp < 0)
@@ -68,9 +66,7 @@ static ssize_t
 nouveau_hwmon_temp1_auto_point1_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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n",
 	      therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_FAN_BOOST) * 1000);
@@ -80,9 +76,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -101,9 +95,7 @@ static ssize_t
 nouveau_hwmon_temp1_auto_point1_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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n",
 	 therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_FAN_BOOST_HYST) * 1000);
@@ -113,9 +105,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp_hyst(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -133,9 +123,7 @@ static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
 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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n",
 	       therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK) * 1000);
@@ -144,9 +132,7 @@ static ssize_t
 nouveau_hwmon_set_max_temp(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -164,9 +150,7 @@ 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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n",
 	  therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK_HYST) * 1000);
@@ -175,9 +159,7 @@ static ssize_t
 nouveau_hwmon_set_max_temp_hyst(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -196,9 +178,7 @@ 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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n",
 	       therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_CRITICAL) * 1000);
@@ -208,9 +188,7 @@ nouveau_hwmon_set_critical_temp(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -229,9 +207,7 @@ static ssize_t
 nouveau_hwmon_critical_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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n",
 	  therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_CRITICAL_HYST) * 1000);
@@ -242,9 +218,7 @@ nouveau_hwmon_set_critical_temp_hyst(struct device *d,
 				     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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -262,9 +236,7 @@ static ssize_t
 nouveau_hwmon_emergency_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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n",
 	       therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_SHUTDOWN) * 1000);
@@ -274,9 +246,7 @@ nouveau_hwmon_set_emergency_temp(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -295,9 +265,7 @@ static ssize_t
 nouveau_hwmon_emergency_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 nouveau_therm *therm = nouveau_therm(drm->device);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n",
 	  therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_SHUTDOWN_HYST) * 1000);
@@ -308,9 +276,7 @@ nouveau_hwmon_set_emergency_temp_hyst(struct device *d,
 				      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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -326,14 +292,6 @@ static SENSOR_DEVICE_ATTR(temp1_emergency_hyst, S_IRUGO | S_IWUSR,
 					nouveau_hwmon_set_emergency_temp_hyst,
 					0);
 
-static ssize_t nouveau_hwmon_show_name(struct device *dev,
-				      struct device_attribute *attr,
-				      char *buf)
-{
-	return sprintf(buf, "nouveau\n");
-}
-static SENSOR_DEVICE_ATTR(name, S_IRUGO, nouveau_hwmon_show_name, NULL, 0);
-
 static ssize_t nouveau_hwmon_show_update_rate(struct device *dev,
 				      struct device_attribute *attr,
 				      char *buf)
@@ -348,9 +306,7 @@ static ssize_t
 nouveau_hwmon_show_fan1_input(struct device *d, struct device_attribute *attr,
 			      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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n", therm->fan_sense(therm));
 }
@@ -361,9 +317,7 @@ static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, nouveau_hwmon_show_fan1_input,
 nouveau_hwmon_get_pwm1_enable(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	int ret;
 
 	ret = therm->attr_get(therm, NOUVEAU_THERM_ATTR_FAN_MODE);
@@ -377,9 +331,7 @@ static ssize_t
 nouveau_hwmon_set_pwm1_enable(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 	int ret;
 
@@ -399,9 +351,7 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
 static ssize_t
 nouveau_hwmon_get_pwm1(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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	int ret;
 
 	ret = therm->fan_get(therm);
@@ -415,10 +365,8 @@ static ssize_t
 nouveau_hwmon_set_pwm1(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);
-	int ret = -ENODEV;
+	struct nouveau_therm *therm = dev_get_drvdata(d);
+	int ret;
 	long value;
 
 	if (kstrtol(buf, 10, &value) == -EINVAL)
@@ -439,9 +387,7 @@ static ssize_t
 nouveau_hwmon_get_pwm1_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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	int ret;
 
 	ret = therm->attr_get(therm, NOUVEAU_THERM_ATTR_FAN_MIN_DUTY);
@@ -455,9 +401,7 @@ static ssize_t
 nouveau_hwmon_set_pwm1_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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 	int ret;
 
@@ -479,9 +423,7 @@ static ssize_t
 nouveau_hwmon_get_pwm1_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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	int ret;
 
 	ret = therm->attr_get(therm, NOUVEAU_THERM_ATTR_FAN_MAX_DUTY);
@@ -495,9 +437,7 @@ static ssize_t
 nouveau_hwmon_set_pwm1_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);
+	struct nouveau_therm *therm = dev_get_drvdata(d);
 	long value;
 	int ret;
 
@@ -516,7 +456,6 @@ static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO | S_IWUSR,
 			  nouveau_hwmon_set_pwm1_max, 0);
 
 static struct attribute *hwmon_default_attributes[] = {
-	&sensor_dev_attr_name.dev_attr.attr,
 	&sensor_dev_attr_update_rate.dev_attr.attr,
 	NULL
 };
@@ -545,18 +484,71 @@ static struct attribute *hwmon_pwm_fan_attributes[] = {
 	NULL
 };
 
+static umode_t hwmon_temp_is_visible(struct kobject *kobj,
+				     struct attribute *attr, int index)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct nouveau_therm *therm = dev_get_drvdata(dev);
+
+	if (therm->temp_get(therm) < 0)
+		return 0;
+
+	return attr->mode;
+}
+
+static umode_t hwmon_fan_rpm_is_visible(struct kobject *kobj,
+					struct attribute *attr, int index)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct nouveau_therm *therm = dev_get_drvdata(dev);
+
+	if (therm->fan_sense(therm) < 0)
+		return 0;
+
+	return attr->mode;
+}
+
+static umode_t hwmon_pwm_fan_is_visible(struct kobject *kobj,
+					struct attribute *attr, int index)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct nouveau_therm *therm = dev_get_drvdata(dev);
+
+	/*
+	 * XXX: incorrect, need better detection for this, some boards have
+	 *     the gpio entries for pwm fan control even when there's no
+	 *     actual fan connected to it... therm table?
+	 */
+	if (!therm->fan_get || therm->fan_get(therm) < 0)
+		return 0;
+
+	return attr->mode;
+}
+
 static const struct attribute_group hwmon_default_attrgroup = {
 	.attrs = hwmon_default_attributes,
 };
 static const struct attribute_group hwmon_temp_attrgroup = {
 	.attrs = hwmon_temp_attributes,
+	.is_visible = hwmon_temp_is_visible,
 };
 static const struct attribute_group hwmon_fan_rpm_attrgroup = {
 	.attrs = hwmon_fan_rpm_attributes,
+	.is_visible = hwmon_fan_rpm_is_visible,
 };
 static const struct attribute_group hwmon_pwm_fan_attrgroup = {
 	.attrs = hwmon_pwm_fan_attributes,
+	.is_visible = hwmon_pwm_fan_is_visible,
+};
+
+static const struct attribute_group *hwmon_attr_groups[] = {
+	&hwmon_default_attrgroup,
+	&hwmon_temp_attrgroup,
+	&hwmon_fan_rpm_attrgroup,
+	&hwmon_pwm_fan_attrgroup,
+	NULL
 };
+
 #endif
 
 int
@@ -565,92 +557,25 @@ 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 nouveau_therm *therm = nouveau_therm(drm->device);
-	struct nouveau_hwmon *hwmon;
 	struct device *hwmon_dev;
 	int ret = 0;
 
-	hwmon = drm->hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL);
-	if (!hwmon)
-		return -ENOMEM;
-	hwmon->dev = dev;
-
 	if (!therm || !therm->temp_get || !therm->attr_get || !therm->attr_set)
 		return -ENODEV;
 
-	hwmon_dev = hwmon_device_register(&dev->pdev->dev);
+	hwmon_dev = devm_hwmon_device_register_with_groups(&dev->pdev->dev,
+							   "nouveau", therm,
+							   hwmon_attr_groups);
 	if (IS_ERR(hwmon_dev)) {
 		ret = PTR_ERR(hwmon_dev);
 		NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret);
 		return ret;
 	}
-	dev_set_drvdata(hwmon_dev, dev);
-
-	/* set the default attributes */
-	ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_default_attrgroup);
-	if (ret) {
-		if (ret)
-			goto error;
-	}
-
-	/* if the card has a working thermal sensor */
-	if (therm->temp_get(therm) >= 0) {
-		ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
-		if (ret) {
-			if (ret)
-				goto error;
-		}
-	}
-
-	/* if the card has a pwm fan */
-	/*XXX: incorrect, need better detection for this, some boards have
-	 *     the gpio entries for pwm fan control even when there's no
-	 *     actual fan connected to it... therm table? */
-	if (therm->fan_get && therm->fan_get(therm) >= 0) {
-		ret = sysfs_create_group(&hwmon_dev->kobj,
-					 &hwmon_pwm_fan_attrgroup);
-		if (ret)
-			goto error;
-	}
-
-	/* if the card can read the fan rpm */
-	if (therm->fan_sense(therm) >= 0) {
-		ret = sysfs_create_group(&hwmon_dev->kobj,
-					 &hwmon_fan_rpm_attrgroup);
-		if (ret)
-			goto error;
-	}
-
-	hwmon->hwmon = hwmon_dev;
-
-	return 0;
-
-error:
-	NV_ERROR(drm, "Unable to create some hwmon sysfs files: %d\n", ret);
-	hwmon_device_unregister(hwmon_dev);
-	hwmon->hwmon = NULL;
-	return ret;
-#else
-	hwmon->hwmon = NULL;
-	return 0;
 #endif
+	return 0;
 }
 
 void
 nouveau_hwmon_fini(struct drm_device *dev)
 {
-#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
-	struct nouveau_hwmon *hwmon = nouveau_hwmon(dev);
-
-	if (hwmon->hwmon) {
-		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_default_attrgroup);
-		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_temp_attrgroup);
-		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_pwm_fan_attrgroup);
-		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_fan_rpm_attrgroup);
-
-		hwmon_device_unregister(hwmon->hwmon);
-	}
-
-	nouveau_drm(dev)->hwmon = NULL;
-	kfree(hwmon);
-#endif
 }
diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.h b/drivers/gpu/drm/nouveau/nouveau_hwmon.h
index 62ccbb3..21a2d1d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hwmon.h
+++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.h
@@ -25,17 +25,6 @@
 #ifndef __NOUVEAU_PM_H__
 #define __NOUVEAU_PM_H__
 
-struct nouveau_hwmon {
-	struct drm_device *dev;
-	struct device *hwmon;
-};
-
-static inline struct nouveau_hwmon *
-nouveau_hwmon(struct drm_device *dev)
-{
-	return nouveau_drm(dev)->hwmon;
-}
-
 /* nouveau_hwmon.c */
 int  nouveau_hwmon_init(struct drm_device *dev);
 void nouveau_hwmon_fini(struct drm_device *dev);
-- 
1.7.9.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups
  2013-11-23  5:52 [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups Guenter Roeck
  2013-11-23  5:52 ` [PATCH 2/2] drm/nouveau/hwmon: Convert to use devm_hwmon_device_register_with_groups Guenter Roeck
@ 2013-11-25 18:07 ` Guenter Roeck
  2013-11-26 13:55   ` Alex Deucher
  1 sibling, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2013-11-25 18:07 UTC (permalink / raw)
  To: David Airlie; +Cc: lm-sensors, dri-devel, linux-kernel

On Fri, Nov 22, 2013 at 09:52:00PM -0800, Guenter Roeck wrote:
> Simplify the code and fix race condition seen because
> attribute files were created after hwmon device registration.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> Compile tested only; unfortunately I don't have the the necessary hardware.
> 
Update: Tested working on actual hardware.

Guenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups
  2013-11-25 18:07 ` [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups Guenter Roeck
@ 2013-11-26 13:55   ` Alex Deucher
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2013-11-26 13:55 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: David Airlie, LKML, Maling list - DRI developers, lm-sensors

On Mon, Nov 25, 2013 at 1:07 PM, Guenter Roeck <linux@roeck-us.net> wrote:
> On Fri, Nov 22, 2013 at 09:52:00PM -0800, Guenter Roeck wrote:
>> Simplify the code and fix race condition seen because
>> attribute files were created after hwmon device registration.
>>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> Compile tested only; unfortunately I don't have the the necessary hardware.
>>
> Update: Tested working on actual hardware.

Applied. thanks!

Alex

>
> Guenter
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-26 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-23  5:52 [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups Guenter Roeck
2013-11-23  5:52 ` [PATCH 2/2] drm/nouveau/hwmon: Convert to use devm_hwmon_device_register_with_groups Guenter Roeck
2013-11-25 18:07 ` [PATCH 1/2] drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups Guenter Roeck
2013-11-26 13:55   ` Alex Deucher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox