diff mbox series

[5/6] hwmon: (lm95234) Add support for tempX_enable attribute

Message ID 20240718033935.205185-6-linux@roeck-us.net (mailing list archive)
State Accepted
Headers show
Series hwmon: (lm9534) Various improvements | expand

Commit Message

Guenter Roeck July 18, 2024, 3:39 a.m. UTC
LM95233/LM95234 support enabling temperature channels one by one.
Add support for tempX_enable attribute to be able to use that
functionality.

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

Comments

Tzung-Bi Shih July 18, 2024, 4:40 p.m. UTC | #1
On Wed, Jul 17, 2024 at 08:39:34PM -0700, Guenter Roeck wrote:
> LM95233/LM95234 support enabling temperature channels one by one.
> Add support for tempX_enable attribute to be able to use that
> functionality.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
diff mbox series

Patch

diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
index 1a164f47fb3e..f0df1134f811 100644
--- a/drivers/hwmon/lm95234.c
+++ b/drivers/hwmon/lm95234.c
@@ -144,6 +144,11 @@  static int lm95234_temp_write(struct device *dev, u32 attr, int channel, long va
 	struct regmap *regmap = data->regmap;
 
 	switch (attr) {
+	case hwmon_temp_enable:
+		if (val && val != 1)
+			return -EINVAL;
+		return regmap_update_bits(regmap, LM95234_REG_ENABLE,
+					  BIT(channel), val ? BIT(channel) : 0);
 	case hwmon_temp_type:
 		if (val != 1 && val != 2)
 			return -EINVAL;
@@ -183,6 +188,12 @@  static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va
 	int ret;
 
 	switch (attr) {
+	case hwmon_temp_enable:
+		ret = regmap_read(regmap, LM95234_REG_ENABLE, &regval);
+		if (ret)
+			return ret;
+		*val = !!(regval & BIT(channel));
+		break;
 	case hwmon_temp_input:
 		return lm95234_read_temp(regmap, channel, val);
 	case hwmon_temp_max_alarm:
@@ -331,6 +342,7 @@  static umode_t lm95234_is_visible(const void *_data, enum hwmon_sensor_types typ
 		case hwmon_temp_fault:
 			return channel ? 0444 : 0;
 		case hwmon_temp_max:
+		case hwmon_temp_enable:
 			return 0644;
 		case hwmon_temp_max_hyst:
 			return channel ? 0444 : 0644;
@@ -350,21 +362,21 @@  static const struct hwmon_channel_info * const lm95234_info[] = {
 	HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL),
 	HWMON_CHANNEL_INFO(temp,
 			   HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST |
-			   HWMON_T_MAX_ALARM,
+			   HWMON_T_MAX_ALARM | HWMON_T_ENABLE,
 			   HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST |
 			   HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE |
 			   HWMON_T_CRIT | HWMON_T_CRIT_HYST |
-			   HWMON_T_CRIT_ALARM | HWMON_T_OFFSET,
+			   HWMON_T_CRIT_ALARM | HWMON_T_OFFSET | HWMON_T_ENABLE,
 			   HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST |
 			   HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE |
 			   HWMON_T_CRIT | HWMON_T_CRIT_HYST |
-			   HWMON_T_CRIT_ALARM | HWMON_T_OFFSET,
+			   HWMON_T_CRIT_ALARM | HWMON_T_OFFSET | HWMON_T_ENABLE,
 			   HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST |
 			   HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE |
-			   HWMON_T_OFFSET,
+			   HWMON_T_OFFSET | HWMON_T_ENABLE,
 			   HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST |
 			   HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE |
-			   HWMON_T_OFFSET),
+			   HWMON_T_OFFSET | HWMON_T_ENABLE),
 	NULL
 };