All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion
@ 2016-12-27 23:28 Guenter Roeck
  2016-12-27 23:28 ` [PATCH 01/10] hwmon: Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and variants Guenter Roeck
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and SENSOR_DEVICE_ATTR_2_{RO,RW,WO}
as simplified variants of SENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 to
simplify the source code, improve readbility, and reduce the chance of
inconsistencies.

Prepare various drivers for automated conversion to the new macros.
This requires replacing various macros with explicit code to avoid confusing
coccinelle. In some cases, minor logical changes are necessary.

Symbolic file permissions are for the most part not replaced with octals
in this patch series. The resulting checkpatch warnings are accepted.
File permissions will be dropped with the conversion to the new macros.
Replacing symbols with octals just to drop the octals would be unnecessary
churn.

----------------------------------------------------------------
Guenter Roeck (10):
      hwmon: Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and variants
      hwmon: (wm831x-hwmon) Replace macros generating sensor attributes
      hwmon: (it87) Prepare for auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW}
      hwmon: (max1668) Prepare for auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW}
      hwmon: (f75375s) Replace function macro with explicit code
      hwmon: (ultra45_env) Replace macros generating sensor attributes
      hwmon: (w83l786ng) Replace function macros with explicit code
      hwmon: (w83791d) Replace function macros with explicit code
      hwmon: (w83627ehf) Replace function macros with explicit code
      hwmon: (adt7411) Replace macro generating sensor attributes

 Documentation/hwmon/hwmon-kernel-api.txt |  24 +-
 drivers/hwmon/adt7411.c                  |  16 +-
 drivers/hwmon/f75375s.c                  |  48 ++-
 drivers/hwmon/it87.c                     |  23 +-
 drivers/hwmon/max1668.c                  |  20 +-
 drivers/hwmon/ultra45_env.c              |  30 +-
 drivers/hwmon/w83627ehf.c                | 534 +++++++++++++++++++++----------
 drivers/hwmon/w83791d.c                  | 140 +++++---
 drivers/hwmon/w83l786ng.c                | 158 ++++++---
 drivers/hwmon/wm831x-hwmon.c             |  48 +--
 include/linux/hwmon-sysfs.h              |  39 +++
 11 files changed, 730 insertions(+), 350 deletions(-)

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

* [PATCH 01/10] hwmon: Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and variants
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 02/10] hwmon: (wm831x-hwmon) Replace macros generating sensor attributes Guenter Roeck
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and SENSOR_DEVICE_ATTR_2_{RO,RW,WO}
as simplified variants of SENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 to
simplify the source code, improve readbility, and reduce the chance of
inconsistencies.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 Documentation/hwmon/hwmon-kernel-api.txt | 24 +++++++++++++-------
 include/linux/hwmon-sysfs.h              | 39 ++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/Documentation/hwmon/hwmon-kernel-api.txt b/Documentation/hwmon/hwmon-kernel-api.txt
index 2505ae67e2b6..00b0341880e7 100644
--- a/Documentation/hwmon/hwmon-kernel-api.txt
+++ b/Documentation/hwmon/hwmon-kernel-api.txt
@@ -294,17 +294,25 @@ functions is used.
 The header file linux/hwmon-sysfs.h provides a number of useful macros to
 declare and use hardware monitoring sysfs attributes.
 
-In many cases, you can use the exsting define DEVICE_ATTR to declare such
-attributes. This is feasible if an attribute has no additional context. However,
-in many cases there will be additional information such as a sensor index which
-will need to be passed to the sysfs attribute handling function.
+In many cases, you can use the exsting define DEVICE_ATTR or its variants
+DEVICE_ATTR_{RW,RO,WO} to declare such attributes. This is feasible if an
+attribute has no additional context. However, in many cases there will be
+additional information such as a sensor index which will need to be passed
+to the sysfs attribute handling function.
 
 SENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 can be used to define attributes
 which need such additional context information. SENSOR_DEVICE_ATTR requires
 one additional argument, SENSOR_DEVICE_ATTR_2 requires two.
 
-SENSOR_DEVICE_ATTR defines a struct sensor_device_attribute variable.
-This structure has the following fields.
+Simplified variants of SENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 are available
+and should be used if standard attribute permissions and function names are
+feasible. Standard permissions are 0644 for SENSOR_DEVICE_ATTR[_2]_RW,
+0444 for SENSOR_DEVICE_ATTR[_2]_RO, and 0200 for SENSOR_DEVICE_ATTR[_2]_WO.
+Standard functions, similar to DEVICE_ATTR_{RW,RO,WO}, have _show and _store
+appended to the provided function name.
+
+SENSOR_DEVICE_ATTR and its variants define a struct sensor_device_attribute
+variable. This structure has the following fields.
 
 struct sensor_device_attribute {
 	struct device_attribute dev_attr;
@@ -315,8 +323,8 @@ You can use to_sensor_dev_attr to get the pointer to this structure from the
 attribute read or write function. Its parameter is the device to which the
 attribute is attached.
 
-SENSOR_DEVICE_ATTR_2 defines a struct sensor_device_attribute_2 variable,
-which is defined as follows.
+SENSOR_DEVICE_ATTR_2 and its variants define a struct sensor_device_attribute_2
+variable, which is defined as follows.
 
 struct sensor_device_attribute_2 {
 	struct device_attribute dev_attr;
diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
index 1c7b89ae6bdc..473897bbd898 100644
--- a/include/linux/hwmon-sysfs.h
+++ b/include/linux/hwmon-sysfs.h
@@ -33,10 +33,28 @@ struct sensor_device_attribute{
 	{ .dev_attr = __ATTR(_name, _mode, _show, _store),	\
 	  .index = _index }
 
+#define SENSOR_ATTR_RO(_name, _func, _index)			\
+	SENSOR_ATTR(_name, 0444, _func##_show, NULL, _index)
+
+#define SENSOR_ATTR_RW(_name, _func, _index)			\
+	SENSOR_ATTR(_name, 0644, _func##_show, _func##_store, _index)
+
+#define SENSOR_ATTR_WO(_name, _func, _index)			\
+	SENSOR_ATTR(_name, 0200, NULL, _func##_store, _index)
+
 #define SENSOR_DEVICE_ATTR(_name, _mode, _show, _store, _index)	\
 struct sensor_device_attribute sensor_dev_attr_##_name		\
 	= SENSOR_ATTR(_name, _mode, _show, _store, _index)
 
+#define SENSOR_DEVICE_ATTR_RO(_name, _func, _index)		\
+	SENSOR_DEVICE_ATTR(_name, 0444, _func##_show, NULL, _index)
+
+#define SENSOR_DEVICE_ATTR_RW(_name, _func, _index)		\
+	SENSOR_DEVICE_ATTR(_name, 0644, _func##_show, _func##_store, _index)
+
+#define SENSOR_DEVICE_ATTR_WO(_name, _func, _index)		\
+	SENSOR_DEVICE_ATTR(_name, 0200, NULL, _func##_store, _index)
+
 struct sensor_device_attribute_2 {
 	struct device_attribute dev_attr;
 	u8 index;
@@ -50,8 +68,29 @@ struct sensor_device_attribute_2 {
 	  .index = _index,					\
 	  .nr = _nr }
 
+#define SENSOR_ATTR_2_RO(_name, _func, _nr, _index)		\
+	SENSOR_ATTR_2(_name, 0444, _func##_show, NULL, _nr, _index)
+
+#define SENSOR_ATTR_2_RW(_name, _func, _nr, _index)		\
+	SENSOR_ATTR_2(_name, 0644, _func##_show, _func##_store, _nr, _index)
+
+#define SENSOR_ATTR_2_WO(_name, _func, _nr, _index)		\
+	SENSOR_ATTR_2(_name, 0200, NULL, _func##_store, _nr, _index)
+
 #define SENSOR_DEVICE_ATTR_2(_name,_mode,_show,_store,_nr,_index)	\
 struct sensor_device_attribute_2 sensor_dev_attr_##_name		\
 	= SENSOR_ATTR_2(_name, _mode, _show, _store, _nr, _index)
 
+#define SENSOR_DEVICE_ATTR_2_RO(_name, _func, _nr, _index)		\
+	SENSOR_DEVICE_ATTR_2(_name, 0444, _func##_show, NULL,		\
+			     _nr, _index)
+
+#define SENSOR_DEVICE_ATTR_2_RW(_name, _func, _nr, _index)		\
+	SENSOR_DEVICE_ATTR_2(_name, 0644, _func##_show, _func##_store,	\
+			     _nr, _index)
+
+#define SENSOR_DEVICE_ATTR_2_WO(_name, _func, _nr, _index)		\
+	SENSOR_DEVICE_ATTR_2(_name, 0200, NULL, _func##_store,		\
+			     _nr, _index)
+
 #endif /* _LINUX_HWMON_SYSFS_H */
-- 
2.7.4

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

* [PATCH 02/10] hwmon: (wm831x-hwmon) Replace macros generating sensor attributes
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
  2016-12-27 23:28 ` [PATCH 01/10] hwmon: Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and variants Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 03/10] hwmon: (it87) Prepare for auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} Guenter Roeck
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Replace macros generating sensor attributes with explicit code to ease
conversion to SENSOR_DEVICE_ATTR_{RO,RW}.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/wm831x-hwmon.c | 48 ++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/drivers/hwmon/wm831x-hwmon.c b/drivers/hwmon/wm831x-hwmon.c
index a16cce72e4e2..46d32ae94167 100644
--- a/drivers/hwmon/wm831x-hwmon.c
+++ b/drivers/hwmon/wm831x-hwmon.c
@@ -79,25 +79,35 @@ static ssize_t show_label(struct device *dev,
 	return sprintf(buf, "%s\n", input_names[channel]);
 }
 
-#define WM831X_VOLTAGE(id, name) \
-	static SENSOR_DEVICE_ATTR(in##id##_input, S_IRUGO, show_voltage, \
-				  NULL, name)
-
-#define WM831X_NAMED_VOLTAGE(id, name) \
-	WM831X_VOLTAGE(id, name); \
-	static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label,	\
-				  NULL, name)
-
-WM831X_VOLTAGE(0, WM831X_AUX_AUX1);
-WM831X_VOLTAGE(1, WM831X_AUX_AUX2);
-WM831X_VOLTAGE(2, WM831X_AUX_AUX3);
-WM831X_VOLTAGE(3, WM831X_AUX_AUX4);
-
-WM831X_NAMED_VOLTAGE(4, WM831X_AUX_SYSVDD);
-WM831X_NAMED_VOLTAGE(5, WM831X_AUX_USB);
-WM831X_NAMED_VOLTAGE(6, WM831X_AUX_BATT);
-WM831X_NAMED_VOLTAGE(7, WM831X_AUX_WALL);
-WM831X_NAMED_VOLTAGE(8, WM831X_AUX_BKUP_BATT);
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_AUX1);
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_AUX2);
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_AUX3);
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_AUX4);
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_SYSVDD);
+static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_USB);
+static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_BATT);
+static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_WALL);
+static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_voltage, NULL,
+			  WM831X_AUX_BKUP_BATT);
+
+static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO, show_label, NULL,
+			  WM831X_AUX_SYSVDD);
+static SENSOR_DEVICE_ATTR(in5_label, S_IRUGO, show_label, NULL,
+			  WM831X_AUX_USB);
+static SENSOR_DEVICE_ATTR(in6_label, S_IRUGO, show_label, NULL,
+			  WM831X_AUX_BATT);
+static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL,
+			  WM831X_AUX_WALL);
+static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL,
+			  WM831X_AUX_BKUP_BATT);
 
 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_chip_temp, NULL,
 			  WM831X_AUX_CHIP_TEMP);
-- 
2.7.4

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

* [PATCH 03/10] hwmon: (it87) Prepare for auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW}
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
  2016-12-27 23:28 ` [PATCH 01/10] hwmon: Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and variants Guenter Roeck
  2016-12-27 23:28 ` [PATCH 02/10] hwmon: (wm831x-hwmon) Replace macros generating sensor attributes Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 04/10] hwmon: (max1668) " Guenter Roeck
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} requires that attribute
permissions match the existence of show and store functions. Update
permissions as well as is_visible functions to meet that requirement.
There is no functional change associated with this patch.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/it87.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index ef4e0527bd21..15557a76bbca 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -1621,7 +1621,7 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
 static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq,
 			  set_pwm_freq, 0);
-static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO,
+static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
 			  show_pwm_temp_map, set_pwm_temp_map, 0);
 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
 			    show_auto_pwm, set_auto_pwm, 0, 0);
@@ -1649,8 +1649,9 @@ static SENSOR_DEVICE_ATTR(pwm1_auto_slope, S_IRUGO | S_IWUSR,
 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
 			  show_pwm_enable, set_pwm_enable, 1);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
-static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, set_pwm_freq, 1);
-static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO,
+static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO | S_IWUSR, show_pwm_freq,
+			  set_pwm_freq, 1);
+static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
 			  show_pwm_temp_map, set_pwm_temp_map, 1);
 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
 			    show_auto_pwm, set_auto_pwm, 1, 0);
@@ -1679,7 +1680,7 @@ static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
 			  show_pwm_enable, set_pwm_enable, 2);
 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
 static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL, 2);
-static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO,
+static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
 			  show_pwm_temp_map, set_pwm_temp_map, 2);
 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
 			    show_auto_pwm, set_auto_pwm, 2, 0);
@@ -1708,7 +1709,7 @@ static SENSOR_DEVICE_ATTR(pwm4_enable, S_IRUGO | S_IWUSR,
 			  show_pwm_enable, set_pwm_enable, 3);
 static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 3);
 static SENSOR_DEVICE_ATTR(pwm4_freq, S_IRUGO, show_pwm_freq, NULL, 3);
-static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IRUGO,
+static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IRUGO | S_IWUSR,
 			  show_pwm_temp_map, set_pwm_temp_map, 3);
 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp, S_IRUGO | S_IWUSR,
 			    show_auto_temp, set_auto_temp, 2, 1);
@@ -1727,7 +1728,7 @@ static SENSOR_DEVICE_ATTR(pwm5_enable, S_IRUGO | S_IWUSR,
 			  show_pwm_enable, set_pwm_enable, 4);
 static SENSOR_DEVICE_ATTR(pwm5, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 4);
 static SENSOR_DEVICE_ATTR(pwm5_freq, S_IRUGO, show_pwm_freq, NULL, 4);
-static SENSOR_DEVICE_ATTR(pwm5_auto_channels_temp, S_IRUGO,
+static SENSOR_DEVICE_ATTR(pwm5_auto_channels_temp, S_IRUGO | S_IWUSR,
 			  show_pwm_temp_map, set_pwm_temp_map, 4);
 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp, S_IRUGO | S_IWUSR,
 			    show_auto_temp, set_auto_temp, 2, 1);
@@ -1746,7 +1747,7 @@ static SENSOR_DEVICE_ATTR(pwm6_enable, S_IRUGO | S_IWUSR,
 			  show_pwm_enable, set_pwm_enable, 5);
 static SENSOR_DEVICE_ATTR(pwm6, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 5);
 static SENSOR_DEVICE_ATTR(pwm6_freq, S_IRUGO, show_pwm_freq, NULL, 5);
-static SENSOR_DEVICE_ATTR(pwm6_auto_channels_temp, S_IRUGO,
+static SENSOR_DEVICE_ATTR(pwm6_auto_channels_temp, S_IRUGO | S_IWUSR,
 			  show_pwm_temp_map, set_pwm_temp_map, 5);
 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp, S_IRUGO | S_IWUSR,
 			    show_auto_temp, set_auto_temp, 2, 1);
@@ -2199,12 +2200,12 @@ static umode_t it87_pwm_is_visible(struct kobject *kobj,
 		return 0;
 
 	/* pwmX_auto_channels_temp is only writable if auto pwm is supported */
-	if (a == 3 && (has_old_autopwm(data) || has_newer_autopwm(data)))
-		return attr->mode | S_IWUSR;
+	if (a == 3 && !has_old_autopwm(data) && !has_newer_autopwm(data))
+		return attr->mode & ~0200;
 
 	/* pwm2_freq is writable if there are two pwm frequency selects */
-	if (has_pwm_freq2(data) && i == 1 && a == 2)
-		return attr->mode | S_IWUSR;
+	if (!has_pwm_freq2(data) && i == 1 && a == 2)
+		return attr->mode & ~0200;
 
 	return attr->mode;
 }
-- 
2.7.4

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

* [PATCH 04/10] hwmon: (max1668) Prepare for auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW}
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
                   ` (2 preceding siblings ...)
  2016-12-27 23:28 ` [PATCH 03/10] hwmon: (it87) Prepare for auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 05/10] hwmon: (f75375s) Replace function macro with explicit code Guenter Roeck
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} requires that attribute
permissions match the existence of show and store functions. Update
attribute permissions to meet that requirement. The is_visible function
does not use the permission from the attribute and thus does not require
any modifications.

There is no functional change associated with this patch.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/max1668.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c
index 7ca889910262..cea7ab8ae21b 100644
--- a/drivers/hwmon/max1668.c
+++ b/drivers/hwmon/max1668.c
@@ -254,29 +254,29 @@ static ssize_t set_temp_min(struct device *dev,
 }
 
 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
-static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_max,
+static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp_max,
 				set_temp_max, 0);
-static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO, show_temp_min,
+static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, show_temp_min,
 				set_temp_min, 0);
 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
-static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO, show_temp_max,
+static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max,
 				set_temp_max, 1);
-static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO, show_temp_min,
+static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, show_temp_min,
 				set_temp_min, 1);
 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
-static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO, show_temp_max,
+static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max,
 				set_temp_max, 2);
-static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO, show_temp_min,
+static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO | S_IWUSR, show_temp_min,
 				set_temp_min, 2);
 static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
-static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO, show_temp_max,
+static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO | S_IWUSR, show_temp_max,
 				set_temp_max, 3);
-static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO, show_temp_min,
+static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO | S_IWUSR, show_temp_min,
 				set_temp_min, 3);
 static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4);
-static SENSOR_DEVICE_ATTR(temp5_max, S_IRUGO, show_temp_max,
+static SENSOR_DEVICE_ATTR(temp5_max, S_IRUGO | S_IWUSR, show_temp_max,
 				set_temp_max, 4);
-static SENSOR_DEVICE_ATTR(temp5_min, S_IRUGO, show_temp_min,
+static SENSOR_DEVICE_ATTR(temp5_min, S_IRUGO | S_IWUSR, show_temp_min,
 				set_temp_min, 4);
 
 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 14);
-- 
2.7.4

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

* [PATCH 05/10] hwmon: (f75375s) Replace function macro with explicit code
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
                   ` (3 preceding siblings ...)
  2016-12-27 23:28 ` [PATCH 04/10] hwmon: (max1668) " Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 06/10] hwmon: (ultra45_env) Replace macros generating sensor attributes Guenter Roeck
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Replace function macro with explicit code to to reduce code obfuscation
and to enable auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW}.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/f75375s.c | 48 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 13 deletions(-)

diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
index 80c42bea90ed..652ca4b34137 100644
--- a/drivers/hwmon/f75375s.c
+++ b/drivers/hwmon/f75375s.c
@@ -655,19 +655,41 @@ static ssize_t set_temp_max_hyst(struct device *dev,
 	return count;
 }
 
-#define show_fan(thing) \
-static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
-			char *buf)\
-{\
-	int nr = to_sensor_dev_attr(attr)->index;\
-	struct f75375_data *data = f75375_update_device(dev); \
-	return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
-}
-
-show_fan(fan);
-show_fan(fan_min);
-show_fan(fan_max);
-show_fan(fan_target);
+static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct f75375_data *data = f75375_update_device(dev);
+
+	return sprintf(buf, "%d\n", rpm_from_reg(data->fan[nr]));
+}
+
+static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct f75375_data *data = f75375_update_device(dev);
+
+	return sprintf(buf, "%d\n", rpm_from_reg(data->fan_min[nr]));
+}
+
+static ssize_t show_fan_max(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct f75375_data *data = f75375_update_device(dev);
+
+	return sprintf(buf, "%d\n", rpm_from_reg(data->fan_max[nr]));
+}
+
+static ssize_t show_fan_target(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct f75375_data *data = f75375_update_device(dev);
+
+	return sprintf(buf, "%d\n", rpm_from_reg(data->fan_target[nr]));
+}
 
 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0);
 static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO|S_IWUSR,
-- 
2.7.4

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

* [PATCH 06/10] hwmon: (ultra45_env) Replace macros generating sensor attributes
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
                   ` (4 preceding siblings ...)
  2016-12-27 23:28 ` [PATCH 05/10] hwmon: (f75375s) Replace function macro with explicit code Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 07/10] hwmon: (w83l786ng) Replace function macros with explicit code Guenter Roeck
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Replace macros generating sensor attributes with explicit code
to simplify conversion to SENSOR_DEVICE_ATTR_{RO,RW}.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/ultra45_env.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index f2816c7c918f..a74f21d6e0bc 100644
--- a/drivers/hwmon/ultra45_env.c
+++ b/drivers/hwmon/ultra45_env.c
@@ -144,17 +144,25 @@ static ssize_t show_fan_fault(struct device *dev, struct device_attribute *attr,
 	return sprintf(buf, "%d\n", (val & (1 << fan_nr)) ? 1 : 0);
 }
 
-#define fan(index)							\
-static SENSOR_DEVICE_ATTR(fan##index##_speed, S_IRUGO | S_IWUSR,	\
-		show_fan_speed, set_fan_speed, index);			\
-static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO,			\
-		show_fan_fault, NULL, index)
-
-fan(0);
-fan(1);
-fan(2);
-fan(3);
-fan(4);
+static SENSOR_DEVICE_ATTR(fan0_speed, S_IRUGO | S_IWUSR,
+			  show_fan_speed, set_fan_speed, 0);
+static SENSOR_DEVICE_ATTR(fan0_fault, S_IRUGO, show_fan_fault, NULL, 0);
+
+static SENSOR_DEVICE_ATTR(fan1_speed, S_IRUGO | S_IWUSR,
+			  show_fan_speed, set_fan_speed, 1);
+static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, show_fan_fault, NULL, 1);
+
+static SENSOR_DEVICE_ATTR(fan2_speed, S_IRUGO | S_IWUSR,
+			  show_fan_speed, set_fan_speed, 2);
+static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, show_fan_fault, NULL, 2);
+
+static SENSOR_DEVICE_ATTR(fan3_speed, S_IRUGO | S_IWUSR,
+			  show_fan_speed, set_fan_speed, 3);
+static SENSOR_DEVICE_ATTR(fan3_fault, S_IRUGO, show_fan_fault, NULL, 3);
+
+static SENSOR_DEVICE_ATTR(fan4_speed, S_IRUGO | S_IWUSR,
+			  show_fan_speed, set_fan_speed, 4);
+static SENSOR_DEVICE_ATTR(fan4_fault, S_IRUGO, show_fan_fault, NULL, 4);
 
 static SENSOR_DEVICE_ATTR(psu_fan_fault, S_IRUGO, show_fan_fault, NULL, 6);
 
-- 
2.7.4

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

* [PATCH 07/10] hwmon: (w83l786ng) Replace function macros with explicit code
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
                   ` (5 preceding siblings ...)
  2016-12-27 23:28 ` [PATCH 06/10] hwmon: (ultra45_env) Replace macros generating sensor attributes Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 08/10] hwmon: (w83791d) " Guenter Roeck
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Replace function macros with explicit code to to reduce code obfuscation
and to simplify auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} and
SENSOR_ATTR_{RO,RW}.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/w83l786ng.c | 158 ++++++++++++++++++++++++++++++----------------
 1 file changed, 105 insertions(+), 53 deletions(-)

diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
index 330299613d38..cc3845358544 100644
--- a/drivers/hwmon/w83l786ng.c
+++ b/drivers/hwmon/w83l786ng.c
@@ -231,43 +231,72 @@ static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
 	return data;
 }
 
-/* following are the sysfs callback functions */
-#define show_in_reg(reg) \
-static ssize_t \
-show_##reg(struct device *dev, struct device_attribute *attr, \
-	   char *buf) \
-{ \
-	int nr = to_sensor_dev_attr(attr)->index; \
-	struct w83l786ng_data *data = w83l786ng_update_device(dev); \
-	return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
+static ssize_t
+show_in(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
+}
+
+static ssize_t
+show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
+}
+
+static ssize_t
+show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
 }
 
-show_in_reg(in)
-show_in_reg(in_min)
-show_in_reg(in_max)
-
-#define store_in_reg(REG, reg) \
-static ssize_t \
-store_in_##reg(struct device *dev, struct device_attribute *attr, \
-	       const char *buf, size_t count) \
-{ \
-	int nr = to_sensor_dev_attr(attr)->index; \
-	struct w83l786ng_data *data = dev_get_drvdata(dev); \
-	struct i2c_client *client = data->client; \
-	unsigned long val; \
-	int err = kstrtoul(buf, 10, &val); \
-	if (err) \
-		return err; \
-	mutex_lock(&data->update_lock); \
-	data->in_##reg[nr] = IN_TO_REG(val); \
-	w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
-			      data->in_##reg[nr]); \
-	mutex_unlock(&data->update_lock); \
-	return count; \
+static ssize_t
+store_in_min(struct device *dev, struct device_attribute *attr, const char *buf,
+	     size_t count)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = dev_get_drvdata(dev);
+	struct i2c_client *client = data->client;
+	unsigned long val;
+	int err = kstrtoul(buf, 10, &val);
+
+	if (err)
+		return err;
+	mutex_lock(&data->update_lock);
+	data->in_min[nr] = IN_TO_REG(val);
+	w83l786ng_write_value(client, W83L786NG_REG_IN_MIN(nr),
+			      data->in_min[nr]);
+	mutex_unlock(&data->update_lock);
+	return count;
 }
 
-store_in_reg(MIN, min)
-store_in_reg(MAX, max)
+static ssize_t
+store_in_max(struct device *dev, struct device_attribute *attr, const char *buf,
+	     size_t count)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = dev_get_drvdata(dev);
+	struct i2c_client *client = data->client;
+	unsigned long val;
+	int err = kstrtoul(buf, 10, &val);
+
+	if (err)
+		return err;
+	mutex_lock(&data->update_lock);
+	data->in_max[nr] = IN_TO_REG(val);
+	w83l786ng_write_value(client, W83L786NG_REG_IN_MAX(nr),
+			      data->in_max[nr]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
 
 static struct sensor_device_attribute sda_in_input[] = {
 	SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
@@ -287,18 +316,27 @@ static struct sensor_device_attribute sda_in_max[] = {
 	SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
 };
 
-#define show_fan_reg(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-			  char *buf) \
-{ \
-	int nr = to_sensor_dev_attr(attr)->index; \
-	struct w83l786ng_data *data = w83l786ng_update_device(dev); \
-	return sprintf(buf, "%d\n", \
-		FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
+static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n",
+		       FAN_FROM_REG(data->fan[nr],
+				    DIV_FROM_REG(data->fan_div[nr])));
 }
 
-show_fan_reg(fan);
-show_fan_reg(fan_min);
+static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n",
+		       FAN_FROM_REG(data->fan_min[nr],
+				    DIV_FROM_REG(data->fan_div[nr])));
+}
 
 static ssize_t
 store_fan_min(struct device *dev, struct device_attribute *attr,
@@ -471,18 +509,32 @@ static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
 		      show_temp, store_temp, 1, 2),
 };
 
-#define show_pwm_reg(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-			  char *buf) \
-{ \
-	struct w83l786ng_data *data = w83l786ng_update_device(dev); \
-	int nr = to_sensor_dev_attr(attr)->index; \
-	return sprintf(buf, "%d\n", data->reg[nr]); \
+static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+	int nr = to_sensor_dev_attr(attr)->index;
+
+	return sprintf(buf, "%d\n", data->pwm_mode[nr]);
 }
 
-show_pwm_reg(pwm_mode)
-show_pwm_reg(pwm_enable)
-show_pwm_reg(pwm)
+static ssize_t show_pwm_enable(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+	int nr = to_sensor_dev_attr(attr)->index;
+
+	return sprintf(buf, "%d\n", data->pwm_enable[nr]);
+}
+
+static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+	int nr = to_sensor_dev_attr(attr)->index;
+
+	return sprintf(buf, "%d\n", data->pwm[nr]);
+}
 
 static ssize_t
 store_pwm_mode(struct device *dev, struct device_attribute *attr,
-- 
2.7.4

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

* [PATCH 08/10] hwmon: (w83791d) Replace function macros with explicit code
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
                   ` (6 preceding siblings ...)
  2016-12-27 23:28 ` [PATCH 07/10] hwmon: (w83l786ng) Replace function macros with explicit code Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 09/10] hwmon: (w83627ehf) " Guenter Roeck
  2016-12-27 23:28 ` [PATCH 10/10] hwmon: (adt7411) Replace macro generating sensor attributes Guenter Roeck
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Replace function macros with explicit code to to reduce code obfuscation
and to simplify auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} and
SENSOR_ATTR_{RO,RW}.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/w83791d.c | 140 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 93 insertions(+), 47 deletions(-)

diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 8af6081b4ab4..9a9d89697672 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -363,44 +363,82 @@ static struct i2c_driver w83791d_driver = {
 };
 
 /* following are the sysfs callback functions */
-#define show_in_reg(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-			char *buf) \
-{ \
-	struct sensor_device_attribute *sensor_attr = \
-						to_sensor_dev_attr(attr); \
-	struct w83791d_data *data = w83791d_update_device(dev); \
-	int nr = sensor_attr->index; \
-	return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
+
+static ssize_t show_in(struct device *dev, struct device_attribute *attr,
+		       char *buf)
+{
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	struct w83791d_data *data = w83791d_update_device(dev);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
+}
+
+static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	struct w83791d_data *data = w83791d_update_device(dev);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
+}
+
+static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	struct w83791d_data *data = w83791d_update_device(dev);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
+}
+
+static ssize_t store_in_min(struct device *dev,
+			    struct device_attribute *attr,
+			    const char *buf, size_t count)
+{
+	struct sensor_device_attribute *sensor_attr =
+						to_sensor_dev_attr(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct w83791d_data *data = i2c_get_clientdata(client);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err)
+		return err;
+	mutex_lock(&data->update_lock);
+	data->in_min[nr] = IN_TO_REG(val);
+	w83791d_write(client, W83791D_REG_IN_MIN[nr], data->in_min[nr]);
+	mutex_unlock(&data->update_lock);
+
+	return count;
 }
 
-show_in_reg(in);
-show_in_reg(in_min);
-show_in_reg(in_max);
-
-#define store_in_reg(REG, reg) \
-static ssize_t store_in_##reg(struct device *dev, \
-				struct device_attribute *attr, \
-				const char *buf, size_t count) \
-{ \
-	struct sensor_device_attribute *sensor_attr = \
-						to_sensor_dev_attr(attr); \
-	struct i2c_client *client = to_i2c_client(dev); \
-	struct w83791d_data *data = i2c_get_clientdata(client); \
-	int nr = sensor_attr->index; \
-	unsigned long val; \
-	int err = kstrtoul(buf, 10, &val); \
-	if (err) \
-		return err; \
-	mutex_lock(&data->update_lock); \
-	data->in_##reg[nr] = IN_TO_REG(val); \
-	w83791d_write(client, W83791D_REG_IN_##REG[nr], data->in_##reg[nr]); \
-	mutex_unlock(&data->update_lock); \
-	 \
-	return count; \
+static ssize_t store_in_max(struct device *dev,
+			    struct device_attribute *attr,
+			    const char *buf, size_t count)
+{
+	struct sensor_device_attribute *sensor_attr =
+						to_sensor_dev_attr(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct w83791d_data *data = i2c_get_clientdata(client);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err)
+		return err;
+	mutex_lock(&data->update_lock);
+	data->in_max[nr] = IN_TO_REG(val);
+	w83791d_write(client, W83791D_REG_IN_MAX[nr], data->in_max[nr]);
+	mutex_unlock(&data->update_lock);
+
+	return count;
 }
-store_in_reg(MIN, min);
-store_in_reg(MAX, max);
 
 static struct sensor_device_attribute sda_in_input[] = {
 	SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
@@ -529,20 +567,28 @@ static struct sensor_device_attribute sda_in_alarm[] = {
 	SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 14),
 };
 
-#define show_fan_reg(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-				char *buf) \
-{ \
-	struct sensor_device_attribute *sensor_attr = \
-						to_sensor_dev_attr(attr); \
-	struct w83791d_data *data = w83791d_update_device(dev); \
-	int nr = sensor_attr->index; \
-	return sprintf(buf, "%d\n", \
-		FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
+static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	struct w83791d_data *data = w83791d_update_device(dev);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n",
+		FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr])));
 }
 
-show_fan_reg(fan);
-show_fan_reg(fan_min);
+static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	struct w83791d_data *data = w83791d_update_device(dev);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n",
+		FAN_FROM_REG(data->fan_min[nr],
+			     DIV_FROM_REG(data->fan_div[nr])));
+}
 
 static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr,
 				const char *buf, size_t count)
-- 
2.7.4

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

* [PATCH 09/10] hwmon: (w83627ehf) Replace function macros with explicit code
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
                   ` (7 preceding siblings ...)
  2016-12-27 23:28 ` [PATCH 08/10] hwmon: (w83791d) " Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  2016-12-27 23:28 ` [PATCH 10/10] hwmon: (adt7411) Replace macro generating sensor attributes Guenter Roeck
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Replace function macros with explicit code to to reduce code obfuscation
and to simplify auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} and
SENSOR_ATTR_{RO,RW}.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/w83627ehf.c | 534 +++++++++++++++++++++++++++++++---------------
 1 file changed, 363 insertions(+), 171 deletions(-)

diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index ab346ed142de..94820051f9e4 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -933,46 +933,83 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
 /*
  * Sysfs callback functions
  */
-#define show_in_reg(reg) \
-static ssize_t \
-show_##reg(struct device *dev, struct device_attribute *attr, \
-	   char *buf) \
-{ \
-	struct w83627ehf_data *data = w83627ehf_update_device(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr, \
-		       data->scale_in)); \
-}
-show_in_reg(in)
-show_in_reg(in_min)
-show_in_reg(in_max)
-
-#define store_in_reg(REG, reg) \
-static ssize_t \
-store_in_##reg(struct device *dev, struct device_attribute *attr, \
-	       const char *buf, size_t count) \
-{ \
-	struct w83627ehf_data *data = dev_get_drvdata(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	unsigned long val; \
-	int err; \
-	err = kstrtoul(buf, 10, &val); \
-	if (err < 0) \
-		return err; \
-	mutex_lock(&data->update_lock); \
-	data->in_##reg[nr] = in_to_reg(val, nr, data->scale_in); \
-	w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \
-			      data->in_##reg[nr]); \
-	mutex_unlock(&data->update_lock); \
-	return count; \
-}
-
-store_in_reg(MIN, min)
-store_in_reg(MAX, max)
+
+static ssize_t
+show_in(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%ld\n",
+		       in_from_reg(data->in[nr], nr, data->scale_in));
+}
+
+static ssize_t
+show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%ld\n",
+		       in_from_reg(data->in_min[nr], nr, data->scale_in));
+}
+
+static ssize_t
+show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%ld\n",
+		       in_from_reg(data->in_max[nr], nr, data->scale_in));
+}
+
+static ssize_t
+store_in_min(struct device *dev, struct device_attribute *attr,
+	     const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	mutex_lock(&data->update_lock);
+	data->in_min[nr] = in_to_reg(val, nr, data->scale_in);
+	w83627ehf_write_value(data, W83627EHF_REG_IN_MIN(nr), data->in_min[nr]);
+	mutex_unlock(&data->update_lock);
+
+	return count;
+}
+
+static ssize_t
+store_in_max(struct device *dev, struct device_attribute *attr,
+	     const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	mutex_lock(&data->update_lock);
+	data->in_max[nr] = in_to_reg(val, nr, data->scale_in);
+	w83627ehf_write_value(data, W83627EHF_REG_IN_MAX(nr), data->in_max[nr]);
+	mutex_unlock(&data->update_lock);
+
+	return count;
+}
 
 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
 			  char *buf)
@@ -1204,43 +1241,81 @@ show_temp_label(struct device *dev, struct device_attribute *attr, char *buf)
 	return sprintf(buf, "%s\n", data->temp_label[data->temp_src[nr]]);
 }
 
-#define show_temp_reg(addr, reg) \
-static ssize_t \
-show_##reg(struct device *dev, struct device_attribute *attr, \
-	   char *buf) \
-{ \
-	struct w83627ehf_data *data = w83627ehf_update_device(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->reg[nr])); \
-}
-show_temp_reg(reg_temp, temp);
-show_temp_reg(reg_temp_over, temp_max);
-show_temp_reg(reg_temp_hyst, temp_max_hyst);
-
-#define store_temp_reg(addr, reg) \
-static ssize_t \
-store_##reg(struct device *dev, struct device_attribute *attr, \
-	    const char *buf, size_t count) \
-{ \
-	struct w83627ehf_data *data = dev_get_drvdata(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	int err; \
-	long val; \
-	err = kstrtol(buf, 10, &val); \
-	if (err < 0) \
-		return err; \
-	mutex_lock(&data->update_lock); \
-	data->reg[nr] = LM75_TEMP_TO_REG(val); \
-	w83627ehf_write_temp(data, data->addr[nr], data->reg[nr]); \
-	mutex_unlock(&data->update_lock); \
-	return count; \
-}
-store_temp_reg(reg_temp_over, temp_max);
-store_temp_reg(reg_temp_hyst, temp_max_hyst);
+static ssize_t
+show_temp(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->temp[nr]));
+}
+
+static ssize_t
+show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->temp_max[nr]));
+}
+
+static ssize_t
+show_temp_max_hyst(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n",
+		       LM75_TEMP_FROM_REG(data->temp_max_hyst[nr]));
+}
+
+static ssize_t
+store_temp_max(struct device *dev, struct device_attribute *attr,
+	       const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	int err;
+	long val;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	mutex_lock(&data->update_lock);
+	data->temp_max[nr] = LM75_TEMP_TO_REG(val);
+	w83627ehf_write_temp(data, data->reg_temp_over[nr], data->temp_max[nr]);
+	mutex_unlock(&data->update_lock);
+
+	return count;
+}
+
+static ssize_t
+store_temp_max_hyst(struct device *dev, struct device_attribute *attr,
+		    const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	int err;
+	long val;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	mutex_lock(&data->update_lock);
+	data->temp_max_hyst[nr] = LM75_TEMP_TO_REG(val);
+	w83627ehf_write_temp(data, data->reg_temp_hyst[nr],
+			     data->temp_max_hyst[nr]);
+	mutex_unlock(&data->update_lock);
+
+	return count;
+}
 
 static ssize_t
 show_temp_offset(struct device *dev, struct device_attribute *attr, char *buf)
@@ -1371,20 +1446,35 @@ static struct sensor_device_attribute sda_temp_offset[] = {
 		    store_temp_offset, 2),
 };
 
-#define show_pwm_reg(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-			  char *buf) \
-{ \
-	struct w83627ehf_data *data = w83627ehf_update_device(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	return sprintf(buf, "%d\n", data->reg[nr]); \
+static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->pwm_mode[nr]);
 }
 
-show_pwm_reg(pwm_mode)
-show_pwm_reg(pwm_enable)
-show_pwm_reg(pwm)
+static ssize_t show_pwm_enable(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->pwm_enable[nr]);
+}
+
+static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->pwm[nr]);
+}
 
 static ssize_t
 store_pwm_mode(struct device *dev, struct device_attribute *attr,
@@ -1485,19 +1575,25 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
 }
 
 
-#define show_tol_temp(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-				char *buf) \
-{ \
-	struct w83627ehf_data *data = w83627ehf_update_device(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	return sprintf(buf, "%d\n", data->reg[nr] * 1000); \
+static ssize_t show_tolerance(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->tolerance[nr] * 1000);
 }
 
-show_tol_temp(tolerance)
-show_tol_temp(target_temp)
+static ssize_t show_target_temp(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->target_temp[nr] * 1000);
+}
 
 static ssize_t
 store_target_temp(struct device *dev, struct device_attribute *attr,
@@ -1615,77 +1711,173 @@ static struct sensor_device_attribute sda_tolerance[] = {
 
 /* Smart Fan registers */
 
-#define fan_functions(reg, REG) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-		       char *buf) \
-{ \
-	struct w83627ehf_data *data = w83627ehf_update_device(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	return sprintf(buf, "%d\n", data->reg[nr]); \
-} \
-static ssize_t \
-store_##reg(struct device *dev, struct device_attribute *attr, \
-			    const char *buf, size_t count) \
-{ \
-	struct w83627ehf_data *data = dev_get_drvdata(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	unsigned long val; \
-	int err; \
-	err = kstrtoul(buf, 10, &val); \
-	if (err < 0) \
-		return err; \
-	val = clamp_val(val, 1, 255); \
-	mutex_lock(&data->update_lock); \
-	data->reg[nr] = val; \
-	w83627ehf_write_value(data, data->REG_##REG[nr], val); \
-	mutex_unlock(&data->update_lock); \
-	return count; \
-}
-
-fan_functions(fan_start_output, FAN_START_OUTPUT)
-fan_functions(fan_stop_output, FAN_STOP_OUTPUT)
-fan_functions(fan_max_output, FAN_MAX_OUTPUT)
-fan_functions(fan_step_output, FAN_STEP_OUTPUT)
-
-#define fan_time_functions(reg, REG) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-				char *buf) \
-{ \
-	struct w83627ehf_data *data = w83627ehf_update_device(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	return sprintf(buf, "%d\n", \
-			step_time_from_reg(data->reg[nr], \
-					   data->pwm_mode[nr])); \
-} \
-\
-static ssize_t \
-store_##reg(struct device *dev, struct device_attribute *attr, \
-			const char *buf, size_t count) \
-{ \
-	struct w83627ehf_data *data = dev_get_drvdata(dev); \
-	struct sensor_device_attribute *sensor_attr = \
-		to_sensor_dev_attr(attr); \
-	int nr = sensor_attr->index; \
-	unsigned long val; \
-	int err; \
-	err = kstrtoul(buf, 10, &val); \
-	if (err < 0) \
-		return err; \
-	val = step_time_to_reg(val, data->pwm_mode[nr]); \
-	mutex_lock(&data->update_lock); \
-	data->reg[nr] = val; \
-	w83627ehf_write_value(data, data->REG_##REG[nr], val); \
-	mutex_unlock(&data->update_lock); \
-	return count; \
-} \
-
-fan_time_functions(fan_stop_time, FAN_STOP_TIME)
+static ssize_t show_fan_start_output(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr =
+		to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->fan_start_output[nr]);
+}
+
+static ssize_t
+store_fan_start_output(struct device *dev, struct device_attribute *attr,
+		       const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	val = clamp_val(val, 1, 255);
+	mutex_lock(&data->update_lock);
+	data->fan_start_output[nr] = val;
+	w83627ehf_write_value(data, data->REG_FAN_START_OUTPUT[nr], val);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_fan_stop_output(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr =
+		to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->fan_stop_output[nr]);
+}
+
+static ssize_t
+store_fan_stop_output(struct device *dev, struct device_attribute *attr,
+		      const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	val = clamp_val(val, 1, 255);
+	mutex_lock(&data->update_lock);
+	data->fan_stop_output[nr] = val;
+	w83627ehf_write_value(data, data->REG_FAN_STOP_OUTPUT[nr], val);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_fan_max_output(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr =
+		to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->fan_max_output[nr]);
+}
+
+static ssize_t
+store_fan_max_output(struct device *dev, struct device_attribute *attr,
+		      const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	val = clamp_val(val, 1, 255);
+	mutex_lock(&data->update_lock);
+	data->fan_max_output[nr] = val;
+	w83627ehf_write_value(data, data->REG_FAN_MAX_OUTPUT[nr], val);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_fan_step_output(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr =
+		to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n", data->fan_step_output[nr]);
+}
+
+static ssize_t
+store_fan_step_output(struct device *dev, struct device_attribute *attr,
+		      const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	val = clamp_val(val, 1, 255);
+	mutex_lock(&data->update_lock);
+	data->fan_step_output[nr] = val;
+	w83627ehf_write_value(data, data->REG_FAN_STEP_OUTPUT[nr], val);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_fan_stop_time(struct device *dev,
+				  struct device_attribute *attr, char *buf)
+{
+	struct w83627ehf_data *data = w83627ehf_update_device(dev);
+	struct sensor_device_attribute *sensor_attr =
+		to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+
+	return sprintf(buf, "%d\n",
+		       step_time_from_reg(data->fan_stop_time[nr],
+					  data->pwm_mode[nr]));
+}
+
+static ssize_t
+store_fan_stop_time(struct device *dev, struct device_attribute *attr,
+		    const char *buf, size_t count)
+{
+	struct w83627ehf_data *data = dev_get_drvdata(dev);
+	struct sensor_device_attribute *sensor_attr =
+		to_sensor_dev_attr(attr);
+	int nr = sensor_attr->index;
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(buf, 10, &val);
+	if (err < 0)
+		return err;
+	val = step_time_to_reg(val, data->pwm_mode[nr]);
+	mutex_lock(&data->update_lock);
+	data->fan_stop_time[nr] = val;
+	w83627ehf_write_value(data, data->REG_FAN_STOP_TIME[nr], val);
+	mutex_unlock(&data->update_lock);
+
+	return count;
+}
 
 static ssize_t name_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
-- 
2.7.4

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

* [PATCH 10/10] hwmon: (adt7411) Replace macro generating sensor attributes
  2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
                   ` (8 preceding siblings ...)
  2016-12-27 23:28 ` [PATCH 09/10] hwmon: (w83627ehf) " Guenter Roeck
@ 2016-12-27 23:28 ` Guenter Roeck
  9 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2016-12-27 23:28 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Replace macro generating sensor attributes with explicit code to ease
conversion to SENSOR_DEVICE_ATTR_{RO,RW}.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/adt7411.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
index b939f8a115ba..bc6e8cd80b68 100644
--- a/drivers/hwmon/adt7411.c
+++ b/drivers/hwmon/adt7411.c
@@ -199,13 +199,15 @@ static ssize_t adt7411_set_bit(struct device *dev,
 	return ret < 0 ? ret : count;
 }
 
-#define ADT7411_BIT_ATTR(__name, __reg, __bit) \
-	SENSOR_DEVICE_ATTR_2(__name, S_IRUGO | S_IWUSR, adt7411_show_bit, \
-	adt7411_set_bit, __bit, __reg)
-
-static ADT7411_BIT_ATTR(no_average, ADT7411_REG_CFG2, ADT7411_CFG2_DISABLE_AVG);
-static ADT7411_BIT_ATTR(fast_sampling, ADT7411_REG_CFG3, ADT7411_CFG3_ADC_CLK_225);
-static ADT7411_BIT_ATTR(adc_ref_vdd, ADT7411_REG_CFG3, ADT7411_CFG3_REF_VDD);
+static SENSOR_DEVICE_ATTR_2(no_average, S_IRUGO | S_IWUSR,
+			    adt7411_show_bit, adt7411_set_bit,
+			    ADT7411_CFG2_DISABLE_AVG, ADT7411_REG_CFG2);
+static SENSOR_DEVICE_ATTR_2(fast_sampling, S_IRUGO | S_IWUSR,
+			    adt7411_show_bit, adt7411_set_bit,
+			    ADT7411_CFG3_ADC_CLK_225, ADT7411_REG_CFG3);
+static SENSOR_DEVICE_ATTR_2(adc_ref_vdd, S_IRUGO | S_IWUSR,
+			    adt7411_show_bit, adt7411_set_bit,
+			    ADT7411_CFG3_REF_VDD, ADT7411_REG_CFG3);
 
 static struct attribute *adt7411_attrs[] = {
 	&sensor_dev_attr_no_average.dev_attr.attr,
-- 
2.7.4

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

end of thread, other threads:[~2016-12-27 23:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
2016-12-27 23:28 ` [PATCH 01/10] hwmon: Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and variants Guenter Roeck
2016-12-27 23:28 ` [PATCH 02/10] hwmon: (wm831x-hwmon) Replace macros generating sensor attributes Guenter Roeck
2016-12-27 23:28 ` [PATCH 03/10] hwmon: (it87) Prepare for auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} Guenter Roeck
2016-12-27 23:28 ` [PATCH 04/10] hwmon: (max1668) " Guenter Roeck
2016-12-27 23:28 ` [PATCH 05/10] hwmon: (f75375s) Replace function macro with explicit code Guenter Roeck
2016-12-27 23:28 ` [PATCH 06/10] hwmon: (ultra45_env) Replace macros generating sensor attributes Guenter Roeck
2016-12-27 23:28 ` [PATCH 07/10] hwmon: (w83l786ng) Replace function macros with explicit code Guenter Roeck
2016-12-27 23:28 ` [PATCH 08/10] hwmon: (w83791d) " Guenter Roeck
2016-12-27 23:28 ` [PATCH 09/10] hwmon: (w83627ehf) " Guenter Roeck
2016-12-27 23:28 ` [PATCH 10/10] hwmon: (adt7411) Replace macro generating sensor attributes Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.