Skip to contentSkip to conversation

hwmon: (g762) Convert to with_info API

PATCH New Guenter Roeck 1 participant 8 messages Jul 4, 2024

Subsystems (2)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

cover hwmon: (g762) Convert to with_info API

Convert to with_info API to simplify the code and make it easier to maintain. The one notable functional change is to drop platform data support, which is and was never used in the upstream kernel.

The first five patches of this series clean up the driver. Patch 6/7 converts the driver to use regmap, and patch 7/7 converts it to use the with_info API.

----------------------------------------------------------------
Guenter Roeck (7):
hwmon: (g762) Simplify clock initialization
hwmon: (g762) Drop platform data support
hwmon: (g762) Reorder include files to be in alphabetic order
hwmon: (g762) Use bit operations
hwmon: (g762) Make chip configuration devicetree independent
hwmon: (g762) Convert to use regmap
hwmon: (g762) Convert to with_info API

 Documentation/hwmon/g762.rst       |    6 +-
 drivers/hwmon/g762.c               | 1222 ++++++++++++------------------------
 include/linux/platform_data/g762.h |   24 -
 3 files changed, 411 insertions(+), 841 deletions(-)
 delete mode 100644 include/linux/platform_data/g762.h
author maintainer
#1 lore raw

PATCH 1/7 hwmon: (g762) Simplify clock initialization

Use a device managed function to prepare and enable the clock. To match the current code, only let it fails if a device node is present (i.e., when it is mandatory). Otherwise set the default clock speed.

No functional change intended, even though the code now does set the default frequency if there is neither a devicetree node nor platform data.

---
 drivers/hwmon/g762.c | 66 +++++++++-----------------------------------
 1 file changed, 13 insertions(+), 53 deletions(-)
drivers/hwmon/g762.c +13 -53
index af1228708e25..da43a26f558d 100644
@@ -115,7 +115,6 @@ enum g762_regs {
 
 struct g762_data {
 	struct i2c_client *client;
-	struct clk *clk;
 
 	/* update mutex */
 	struct mutex update_lock;
@@ -574,66 +573,27 @@ MODULE_DEVICE_TABLE(of, g762_dt_match);
 
 /*
  * Grab clock (a required property), enable it, get (fixed) clock frequency
- * and store it. Note: upon success, clock has been prepared and enabled; it
- * must later be unprepared and disabled (e.g. during module unloading) by a
- * call to g762_of_clock_disable(). Note that a reference to clock is kept
- * in our private data structure to be used in this function.
+ * and store it.
  */
-static void g762_of_clock_disable(void *data)
+static int g762_of_clock_enable(struct device *dev)
 {
-	struct g762_data *g762 = data;
-
-	clk_disable_unprepare(g762->clk);
-	clk_put(g762->clk);
-}
-
-static int g762_of_clock_enable(struct i2c_client *client)
-{
-	struct g762_data *data;
-	unsigned long clk_freq;
+	unsigned long clk_freq = 0;
 	struct clk *clk;
 	int ret;
 
-	if (!client->dev.of_node)
-		return 0;
-
-	clk = of_clk_get(client->dev.of_node, 0);
+	clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(clk)) {
-		dev_err(&client->dev, "failed to get clock\n");
-		return PTR_ERR(clk);
+		if (dev->of_node)
+			return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
+	} else {
+		clk_freq = clk_get_rate(clk);
 	}
 
-	ret = clk_prepare_enable(clk);
-	if (ret) {
-		dev_err(&client->dev, "failed to enable clock\n");
-		goto clk_put;
-	}
-
-	clk_freq = clk_get_rate(clk);
-	ret = do_set_clk_freq(&client->dev, clk_freq);
-	if (ret) {
-		dev_err(&client->dev, "invalid clock freq %lu\n", clk_freq);
-		goto clk_unprep;
-	}
-
-	data = i2c_get_clientdata(client);
-	data->clk = clk;
-
-	ret = devm_add_action(&client->dev, g762_of_clock_disable, data);
-	if (ret) {
-		dev_err(&client->dev, "failed to add disable clock action\n");
-		goto clk_unprep;
-	}
+	ret = do_set_clk_freq(dev, clk_freq);
+	if (ret)
+		return dev_err_probe(dev, ret, "invalid clock freq %lu\n", clk_freq);
 
 	return 0;
-
- clk_unprep:
-	clk_disable_unprepare(clk);
-
- clk_put:
-	clk_put(clk);
-
-	return ret;
 }
 
 static int g762_of_prop_import_one(struct i2c_client *client,
@@ -682,7 +642,7 @@ static int g762_of_prop_import(struct i2c_client *client)
 	return 0;
 }
 
-static int g762_of_clock_enable(struct i2c_client *client)
+static int g762_of_clock_enable(struct device *dev)
 {
 	return 0;
 }
@@ -1062,7 +1022,7 @@ static int g762_probe(struct i2c_client *client)
 		return ret;
 
 	/* Get configuration via DT ... */
-	ret = g762_of_clock_enable(client);
+	ret = g762_of_clock_enable(dev);
 	if (ret)
 		return ret;
 	ret = g762_of_prop_import(client);
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH 2/7 hwmon: (g762) Drop platform data support

In reply to Guenter Roeck

There is no in-tree user (or at least not anymore), so drop platform data to simplify the code.

---
 Documentation/hwmon/g762.rst       |  4 +---
 drivers/hwmon/g762.c               | 33 ------------------------------
 include/linux/platform_data/g762.h | 24 ----------------------
 3 files changed, 1 insertion(+), 60 deletions(-)
 delete mode 100644 include/linux/platform_data/g762.h
Documentation/hwmon/g762.rst +1 -3
index 0371b3365c48..3dc5294b2181 100644
@@ -17,9 +17,7 @@ done via a userland daemon like fancontrol.
 Note that those entries do not provide ways to setup the specific
 hardware characteristics of the system (reference clock, pulses per
 fan revolution, ...); Those can be modified via devicetree bindings
-documented in Documentation/devicetree/bindings/hwmon/g762.txt or
-using a specific platform_data structure in board initialization
-file (see include/linux/platform_data/g762.h).
+documented in Documentation/devicetree/bindings/hwmon/g762.txt.
 
   fan1_target:
 	    set desired fan speed. This only makes sense in closed-loop
drivers/hwmon/g762.c +0 -33
index da43a26f558d..8573865a8989 100644
@@ -39,7 +39,6 @@
 #include <linux/kernel.h>
 #include <linux/clk.h>
 #include <linux/of.h>
-#include <linux/platform_data/g762.h>
 
 #define DRVNAME "g762"
 
@@ -648,34 +647,6 @@ static int g762_of_clock_enable(struct device *dev)
 }
 #endif
 
-/*
- * Helper to import hardware characteristics from .dts file and push
- * those to the chip.
- */
-
-static int g762_pdata_prop_import(struct i2c_client *client)
-{
-	struct g762_platform_data *pdata = dev_get_platdata(&client->dev);
-	int ret;
-
-	if (!pdata)
-		return 0;
-
-	ret = do_set_fan_gear_mode(&client->dev, pdata->fan_gear_mode);
-	if (ret)
-		return ret;
-
-	ret = do_set_pwm_polarity(&client->dev, pdata->pwm_polarity);
-	if (ret)
-		return ret;
-
-	ret = do_set_fan_startv(&client->dev, pdata->fan_startv);
-	if (ret)
-		return ret;
-
-	return do_set_clk_freq(&client->dev, pdata->clk_freq);
-}
-
 /*
  * sysfs attributes
  */
@@ -1026,10 +997,6 @@ static int g762_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 	ret = g762_of_prop_import(client);
-	if (ret)
-		return ret;
-	/* ... or platform_data */
-	ret = g762_pdata_prop_import(client);
 	if (ret)
 		return ret;
 
include/linux/platform_data/g762.h deleted +0 -24
deleted file mode 100644
index 249257ee2132..000000000000
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * Platform data structure for g762 fan controller driver
- *
- * Copyright (C) 2013, Arnaud EBALARD <[email protected]>
- */
-#ifndef __LINUX_PLATFORM_DATA_G762_H__
-#define __LINUX_PLATFORM_DATA_G762_H__
-
-/*
- * Following structure can be used to set g762 driver platform specific data
- * during board init. Note that passing a sparse structure is possible but
- * will result in non-specified attributes to be set to default value, hence
- * overloading those installed during boot (e.g. by u-boot).
- */
-
-struct g762_platform_data {
-	u32 fan_startv;
-	u32 fan_gear_mode;
-	u32 pwm_polarity;
-	u32 clk_freq;
-};
-
-#endif /* __LINUX_PLATFORM_DATA_G762_H__ */
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH 3/7 hwmon: (g762) Reorder include files to be in alphabetic order

In reply to Guenter Roeck

Alphabetic order for include files help deciding where to add new include files when needed.

No functional change.

---
 drivers/hwmon/g762.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/hwmon/g762.c +6 -6
index 8573865a8989..37d8a45610a3 100644
@@ -27,17 +27,17 @@
  *       http://www.gmt.com.tw/product/datasheet/EDS-762_3.pdf
  */
 
+#include <linux/clk.h>
 #include <linux/device.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/jiffies.h>
+#include <linux/err.h>
 #include <linux/i2c.h>
+#include <linux/init.h>
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
-#include <linux/err.h>
-#include <linux/mutex.h>
+#include <linux/jiffies.h>
 #include <linux/kernel.h>
-#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/of.h>
 
 #define DRVNAME "g762"
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

PATCH 4/7 hwmon: (g762) Use bit operations

In reply to Guenter Roeck

Use bit operations to make the code easier to read and avoid duplication. While at it, improve column alignment in defines.

No functional change.

---
 drivers/hwmon/g762.c | 130 +++++++++++++------------------------------
 1 file changed, 40 insertions(+), 90 deletions(-)
drivers/hwmon/g762.c +40 -90
index 37d8a45610a3..59077e54d47e 100644
@@ -27,6 +27,8 @@
  *       http://www.gmt.com.tw/product/datasheet/EDS-762_3.pdf
  */
 
+#include <linux/bits.h>
+#include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/err.h>
@@ -59,35 +61,32 @@ enum g762_regs {
 };
 
 /* Config register bits */
-#define G762_REG_FAN_CMD1_DET_FAN_FAIL  0x80 /* enable fan_fail signal */
-#define G762_REG_FAN_CMD1_DET_FAN_OOC   0x40 /* enable fan_out_of_control */
-#define G762_REG_FAN_CMD1_OUT_MODE      0x20 /* out mode: PWM or DC */
-#define G762_REG_FAN_CMD1_FAN_MODE      0x10 /* fan mode: closed/open-loop */
-#define G762_REG_FAN_CMD1_CLK_DIV_ID1   0x08 /* clock divisor value */
-#define G762_REG_FAN_CMD1_CLK_DIV_ID0   0x04
-#define G762_REG_FAN_CMD1_PWM_POLARITY  0x02 /* PWM polarity */
-#define G762_REG_FAN_CMD1_PULSE_PER_REV 0x01 /* pulse per fan revolution */
+#define G762_REG_FAN_CMD1_DET_FAN_FAIL	BIT(7)	/* enable fan_fail signal */
+#define G762_REG_FAN_CMD1_DET_FAN_OOC	BIT(6)	/* enable fan_out_of_control */
+#define G762_REG_FAN_CMD1_OUT_MODE	BIT(5)	/* out mode: PWM or DC */
+#define G762_REG_FAN_CMD1_FAN_MODE	BIT(4)	/* fan mode: closed/open-loop */
+#define G762_REG_FAN_CMD1_CLK_DIV_MASK	GENMASK(3, 2)
+#define G762_REG_FAN_CMD1_PWM_POLARITY	BIT(1)	/* PWM polarity */
+#define G762_REG_FAN_CMD1_PULSE_PER_REV	BIT(0)	/* pulse per fan revolution */
 
-#define G762_REG_FAN_CMD2_GEAR_MODE_1   0x08 /* fan gear mode */
-#define G762_REG_FAN_CMD2_GEAR_MODE_0   0x04
-#define G762_REG_FAN_CMD2_FAN_STARTV_1  0x02 /* fan startup voltage */
-#define G762_REG_FAN_CMD2_FAN_STARTV_0  0x01
+#define G762_REG_FAN_CMD2_GEAR_MASK	GENMASK(3, 2)
+#define G762_REG_FAN_CMD2_FAN_STARTV_MASK GENMASK(1, 0)	/* fan startup voltage */
 
-#define G762_REG_FAN_STA_FAIL           0x02 /* fan fail */
-#define G762_REG_FAN_STA_OOC            0x01 /* fan out of control */
+#define G762_REG_FAN_STA_FAIL		BIT(1)	/* fan fail */
+#define G762_REG_FAN_STA_OOC		BIT(0)	/* fan out of control */
 
 /* Config register values */
-#define G762_OUT_MODE_PWM            1
-#define G762_OUT_MODE_DC             0
+#define G762_OUT_MODE_PWM		1
+#define G762_OUT_MODE_DC		0
 
-#define G762_FAN_MODE_CLOSED_LOOP    2
-#define G762_FAN_MODE_OPEN_LOOP      1
+#define G762_FAN_MODE_CLOSED_LOOP	2
+#define G762_FAN_MODE_OPEN_LOOP		1
 
-#define G762_PWM_POLARITY_NEGATIVE   1
-#define G762_PWM_POLARITY_POSITIVE   0
+#define G762_PWM_POLARITY_NEGATIVE	1
+#define G762_PWM_POLARITY_POSITIVE	0
 
 /* Register data is read (and cached) at most once per second. */
-#define G762_UPDATE_INTERVAL    HZ
+#define G762_UPDATE_INTERVAL		HZ
 
 /*
  * Extract pulse count per fan revolution value (2 or 4) from given
@@ -101,16 +100,14 @@ enum g762_regs {
  * register value.
  */
 #define G762_CLKDIV_FROM_REG(reg) \
-	(1 << (((reg) & (G762_REG_FAN_CMD1_CLK_DIV_ID0 |	\
-			 G762_REG_FAN_CMD1_CLK_DIV_ID1)) >> 2))
+	BIT(FIELD_GET(G762_REG_FAN_CMD1_CLK_DIV_MASK, reg))
 
 /*
- * Extract fan gear mode multiplier value (0, 2 or 4) from given
+ * Extract fan gear mode multiplier value (1, 2 or 4) from given
  * FAN_CMD2 register value.
  */
 #define G762_GEARMULT_FROM_REG(reg) \
-	(1 << (((reg) & (G762_REG_FAN_CMD2_GEAR_MODE_0 |	\
-			 G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2))
+	BIT(FIELD_GET(G762_REG_FAN_CMD2_GEAR_MASK, reg))
 
 struct g762_data {
 	struct i2c_client *client;
@@ -303,32 +300,15 @@ static int do_set_fan_div(struct device *dev, unsigned long val)
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
+	if (hweight_long(val) != 1 || val > 8)
+		return -EINVAL;
+
 	mutex_lock(&data->update_lock);
-	switch (val) {
-	case 1:
-		data->fan_cmd1 &= ~G762_REG_FAN_CMD1_CLK_DIV_ID0;
-		data->fan_cmd1 &= ~G762_REG_FAN_CMD1_CLK_DIV_ID1;
-		break;
-	case 2:
-		data->fan_cmd1 |=  G762_REG_FAN_CMD1_CLK_DIV_ID0;
-		data->fan_cmd1 &= ~G762_REG_FAN_CMD1_CLK_DIV_ID1;
-		break;
-	case 4:
-		data->fan_cmd1 &= ~G762_REG_FAN_CMD1_CLK_DIV_ID0;
-		data->fan_cmd1 |=  G762_REG_FAN_CMD1_CLK_DIV_ID1;
-		break;
-	case 8:
-		data->fan_cmd1 |=  G762_REG_FAN_CMD1_CLK_DIV_ID0;
-		data->fan_cmd1 |=  G762_REG_FAN_CMD1_CLK_DIV_ID1;
-		break;
-	default:
-		ret = -EINVAL;
-		goto out;
-	}
+	data->fan_cmd1 &= ~G762_REG_FAN_CMD1_CLK_DIV_MASK;
+	data->fan_cmd1 |= FIELD_PREP(G762_REG_FAN_CMD1_CLK_DIV_MASK, __ffs(val));
 	ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
 					data->fan_cmd1);
 	data->valid = false;
- out:
 	mutex_unlock(&data->update_lock);
 
 	return ret;
@@ -343,28 +323,15 @@ static int do_set_fan_gear_mode(struct device *dev, unsigned long val)
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
+	if (val > 2)
+		return -EINVAL;
+
 	mutex_lock(&data->update_lock);
-	switch (val) {
-	case 0:
-		data->fan_cmd2 &= ~G762_REG_FAN_CMD2_GEAR_MODE_0;
-		data->fan_cmd2 &= ~G762_REG_FAN_CMD2_GEAR_MODE_1;
-		break;
-	case 1:
-		data->fan_cmd2 |=  G762_REG_FAN_CMD2_GEAR_MODE_0;
-		data->fan_cmd2 &= ~G762_REG_FAN_CMD2_GEAR_MODE_1;
-		break;
-	case 2:
-		data->fan_cmd2 &= ~G762_REG_FAN_CMD2_GEAR_MODE_0;
-		data->fan_cmd2 |=  G762_REG_FAN_CMD2_GEAR_MODE_1;
-		break;
-	default:
-		ret = -EINVAL;
-		goto out;
-	}
+	data->fan_cmd2 &= ~G762_REG_FAN_CMD2_GEAR_MASK;
+	data->fan_cmd2 |= FIELD_PREP(G762_REG_FAN_CMD2_GEAR_MASK, val);
 	ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2,
 					data->fan_cmd2);
 	data->valid = false;
- out:
 	mutex_unlock(&data->update_lock);
 
 	return ret;
@@ -526,32 +493,15 @@ static int do_set_fan_startv(struct device *dev, unsigned long val)
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
+	if (val > 3)
+		return -EINVAL;
+
 	mutex_lock(&data->update_lock);
-	switch (val) {
-	case 0:
-		data->fan_cmd2 &= ~G762_REG_FAN_CMD2_FAN_STARTV_0;
-		data->fan_cmd2 &= ~G762_REG_FAN_CMD2_FAN_STARTV_1;
-		break;
-	case 1:
-		data->fan_cmd2 |=  G762_REG_FAN_CMD2_FAN_STARTV_0;
-		data->fan_cmd2 &= ~G762_REG_FAN_CMD2_FAN_STARTV_1;
-		break;
-	case 2:
-		data->fan_cmd2 &= ~G762_REG_FAN_CMD2_FAN_STARTV_0;
-		data->fan_cmd2 |=  G762_REG_FAN_CMD2_FAN_STARTV_1;
-		break;
-	case 3:
-		data->fan_cmd2 |=  G762_REG_FAN_CMD2_FAN_STARTV_0;
-		data->fan_cmd2 |=  G762_REG_FAN_CMD2_FAN_STARTV_1;
-		break;
-	default:
-		ret = -EINVAL;
-		goto out;
-	}
+	data->fan_cmd2 &= ~G762_REG_FAN_CMD2_FAN_STARTV_MASK;
+	data->fan_cmd2 |= FIELD_PREP(G762_REG_FAN_CMD2_FAN_STARTV_MASK, val);
 	ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2,
 					data->fan_cmd2);
 	data->valid = false;
- out:
 	mutex_unlock(&data->update_lock);
 
 	return ret;
@@ -722,7 +672,7 @@ static ssize_t fan1_div_show(struct device *dev, struct device_attribute *da,
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
-	return sprintf(buf, "%d\n", G762_CLKDIV_FROM_REG(data->fan_cmd1));
+	return sprintf(buf, "%ld\n", G762_CLKDIV_FROM_REG(data->fan_cmd1));
 }
 
 static ssize_t fan1_div_store(struct device *dev, struct device_attribute *da,
@@ -753,7 +703,7 @@ static ssize_t fan1_pulses_show(struct device *dev,
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
-	return sprintf(buf, "%d\n", G762_PULSE_FROM_REG(data->fan_cmd1));
+	return sprintf(buf, "%ld\n", G762_PULSE_FROM_REG(data->fan_cmd1));
 }
 
 static ssize_t fan1_pulses_store(struct device *dev,
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH 5/7 hwmon: (g762) Make chip configuration devicetree independent

In reply to Guenter Roeck

Move chip configuration code to one place, and make it devicetree independent by using device property instead of devicetree functions to read configuration data.

---
 drivers/hwmon/g762.c | 187 ++++++++++++++++++-------------------------
 1 file changed, 77 insertions(+), 110 deletions(-)
drivers/hwmon/g762.c +77 -110
index 59077e54d47e..0ddaa0bd1075 100644
@@ -44,13 +44,6 @@
 
 #define DRVNAME "g762"
 
-static const struct i2c_device_id g762_id[] = {
-	{ "g762" },
-	{ "g763" },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, g762_id);
-
 enum g762_regs {
 	G762_REG_SET_CNT  = 0x00,
 	G762_REG_ACT_CNT  = 0x01,
@@ -315,7 +308,7 @@ static int do_set_fan_div(struct device *dev, unsigned long val)
 }
 
 /* Set fan gear mode. Accepts either 0, 1 or 2. */
-static int do_set_fan_gear_mode(struct device *dev, unsigned long val)
+static int do_set_fan_gear_mode(struct device *dev, u32 val)
 {
 	struct g762_data *data = g762_update_client(dev);
 	int ret;
@@ -507,96 +500,6 @@ static int do_set_fan_startv(struct device *dev, unsigned long val)
 	return ret;
 }
 
-/*
- * Helper to import hardware characteristics from .dts file and push
- * those to the chip.
- */
-
-#ifdef CONFIG_OF
-static const struct of_device_id g762_dt_match[] = {
-	{ .compatible = "gmt,g762" },
-	{ .compatible = "gmt,g763" },
-	{ },
-};
-MODULE_DEVICE_TABLE(of, g762_dt_match);
-
-/*
- * Grab clock (a required property), enable it, get (fixed) clock frequency
- * and store it.
- */
-static int g762_of_clock_enable(struct device *dev)
-{
-	unsigned long clk_freq = 0;
-	struct clk *clk;
-	int ret;
-
-	clk = devm_clk_get_enabled(dev, NULL);
-	if (IS_ERR(clk)) {
-		if (dev->of_node)
-			return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
-	} else {
-		clk_freq = clk_get_rate(clk);
-	}
-
-	ret = do_set_clk_freq(dev, clk_freq);
-	if (ret)
-		return dev_err_probe(dev, ret, "invalid clock freq %lu\n", clk_freq);
-
-	return 0;
-}
-
-static int g762_of_prop_import_one(struct i2c_client *client,
-				   const char *pname,
-				   int (*psetter)(struct device *dev,
-						  unsigned long val))
-{
-	int ret;
-	u32 pval;
-
-	if (of_property_read_u32(client->dev.of_node, pname, &pval))
-		return 0;
-
-	dev_dbg(&client->dev, "found %s (%d)\n", pname, pval);
-	ret = (*psetter)(&client->dev, pval);
-	if (ret)
-		dev_err(&client->dev, "unable to set %s (%d)\n", pname, pval);
-
-	return ret;
-}
-
-static int g762_of_prop_import(struct i2c_client *client)
-{
-	int ret;
-
-	if (!client->dev.of_node)
-		return 0;
-
-	ret = g762_of_prop_import_one(client, "fan_gear_mode",
-				      do_set_fan_gear_mode);
-	if (ret)
-		return ret;
-
-	ret = g762_of_prop_import_one(client, "pwm_polarity",
-				      do_set_pwm_polarity);
-	if (ret)
-		return ret;
-
-	return g762_of_prop_import_one(client, "fan_startv",
-				       do_set_fan_startv);
-}
-
-#else
-static int g762_of_prop_import(struct i2c_client *client)
-{
-	return 0;
-}
-
-static int g762_of_clock_enable(struct device *dev)
-{
-	return 0;
-}
-#endif
-
 /*
  * sysfs attributes
  */
@@ -918,6 +821,65 @@ static inline int g762_fan_init(struct device *dev)
 					 data->fan_cmd1);
 }
 
+/*
+ * Grab clock (a required property), enable it, get (fixed) clock frequency
+ * and store it.
+ */
+static int g762_clock_enable(struct device *dev)
+{
+	unsigned long clk_freq = 0;
+	struct clk *clk;
+	int ret;
+
+	clk = devm_clk_get_enabled(dev, NULL);
+	if (IS_ERR(clk)) {
+		if (dev->of_node)
+			return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
+	} else {
+		clk_freq = clk_get_rate(clk);
+	}
+
+	ret = do_set_clk_freq(dev, clk_freq);
+	if (ret)
+		return dev_err_probe(dev, ret, "invalid clock freq %lu\n", clk_freq);
+
+	return 0;
+}
+
+static int g762_configure(struct device *dev)
+{
+	u32 property;
+	int ret;
+
+	/* Enable fan failure detection and fan out of control protection */
+	ret = g762_fan_init(dev);
+	if (ret)
+		return ret;
+
+	ret = g762_clock_enable(dev);
+	if (ret)
+		return ret;
+
+	if (!device_property_read_u32(dev, "fan_gear_mode", &property)) {
+		ret = do_set_fan_gear_mode(dev, property);
+		if (ret)
+			return ret;
+	}
+
+	if (!device_property_read_u32(dev, "pwm_polarity", &property)) {
+		ret = do_set_pwm_polarity(dev, property);
+		if (ret)
+			return ret;
+	}
+
+	if (!device_property_read_u32(dev, "fan_startv", &property)) {
+		ret = do_set_fan_startv(dev, property);
+		if (ret)
+			return ret;
+	}
+	return 0;
+}
+
 static int g762_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
@@ -933,20 +895,11 @@ static int g762_probe(struct i2c_client *client)
 	if (!data)
 		return -ENOMEM;
 
-	i2c_set_clientdata(client, data);
+	dev_set_drvdata(dev, data);
 	data->client = client;
 	mutex_init(&data->update_lock);
 
-	/* Enable fan failure detection and fan out of control protection */
-	ret = g762_fan_init(dev);
-	if (ret)
-		return ret;
-
-	/* Get configuration via DT ... */
-	ret = g762_of_clock_enable(dev);
-	if (ret)
-		return ret;
-	ret = g762_of_prop_import(client);
+	ret = g762_configure(dev);
 	if (ret)
 		return ret;
 
@@ -955,10 +908,24 @@ static int g762_probe(struct i2c_client *client)
 	return PTR_ERR_OR_ZERO(hwmon_dev);
 }
 
+static const struct of_device_id g762_dt_match[] = {
+	{ .compatible = "gmt,g762" },
+	{ .compatible = "gmt,g763" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, g762_dt_match);
+
+static const struct i2c_device_id g762_id[] = {
+	{ "g762" },
+	{ "g763" },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, g762_id);
+
 static struct i2c_driver g762_driver = {
 	.driver = {
 		.name = DRVNAME,
-		.of_match_table = of_match_ptr(g762_dt_match),
+		.of_match_table = g762_dt_match,
 	},
 	.probe = g762_probe,
 	.id_table = g762_id,
Signature · 1 line
2.39.2
author maintainer
#6 lore raw

PATCH 6/7 hwmon: (g762) Convert to use regmap

In reply to Guenter Roeck

Use regmap for caching and regmap operations for register bit manipulations to simplify the code.

No functional change intended.

---
 Documentation/hwmon/g762.rst |   2 -
 drivers/hwmon/g762.c         | 523 +++++++++++++----------------------
 2 files changed, 195 insertions(+), 330 deletions(-)
Documentation/hwmon/g762.rst +0 -2
index 3dc5294b2181..0c170596a1ac 100644
@@ -68,5 +68,3 @@ is performed to match that target value. The fan speed value is computed
 based on the parameters associated with the physical characteristics of the
 system: a reference clock source frequency, a number of pulses per fan
 revolution, etc.
-
-Note that the driver will update its values at most once per second.
drivers/hwmon/g762.c +195 -328

753 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#7 lore raw

PATCH 7/7 hwmon: (g762) Convert to with_info API

In reply to Guenter Roeck

Convert to with_info API to simplify the code and make it easier to maintain.

The conversion reduces code size by about 25%.

No functional change intended.

---
 drivers/hwmon/g762.c | 473 ++++++++++++++++---------------------------
 1 file changed, 180 insertions(+), 293 deletions(-)
drivers/hwmon/g762.c +180 -293
index 5f8fd723a694..e513cd47fade 100644
@@ -35,7 +35,6 @@
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/hwmon.h>
-#include <linux/hwmon-sysfs.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
@@ -154,11 +153,11 @@ static int do_set_clk_freq(struct device *dev, unsigned long val)
 }
 
 /* Set pwm mode. Accepts either 0 (PWM mode) or 1 (DC mode) */
-static int do_set_pwm_mode(struct device *dev, unsigned long val)
+static int do_set_pwm_mode(struct device *dev, long val)
 {
 	struct g762_data *data = dev_get_drvdata(dev);
 
-	if (val && val != 1)
+	if (val < 0 || val > 1)
 		return -EINVAL;
 
 	return regmap_update_bits(data->regmap, G762_REG_FAN_CMD1,
@@ -167,11 +166,11 @@ static int do_set_pwm_mode(struct device *dev, unsigned long val)
 }
 
 /* Set fan clock divisor. Accepts either 1, 2, 4 or 8. */
-static int do_set_fan_div(struct device *dev, unsigned long val)
+static int do_set_fan_div(struct device *dev, long val)
 {
 	struct g762_data *data = dev_get_drvdata(dev);
 
-	if (hweight_long(val) != 1 || val > 8)
+	if (val < 0 || hweight_long(val) != 1 || val > 8)
 		return -EINVAL;
 
 	return regmap_update_bits(data->regmap, G762_REG_FAN_CMD1,
@@ -193,7 +192,7 @@ static int do_set_fan_gear_mode(struct device *dev, u32 val)
 }
 
 /* Set number of fan pulses per revolution. Accepts either 2 or 4. */
-static int do_set_fan_pulses(struct device *dev, unsigned long val)
+static int do_set_fan_pulses(struct device *dev, long val)
 {
 	struct g762_data *data = dev_get_drvdata(dev);
 
@@ -206,7 +205,7 @@ static int do_set_fan_pulses(struct device *dev, unsigned long val)
 }
 
 /* Set fan mode. Accepts either 1 (open-loop) or 2 (closed-loop). */
-static int do_set_pwm_enable(struct device *dev, unsigned long val)
+static int do_set_pwm_enable(struct device *dev, long val)
 {
 	struct g762_data *data = dev_get_drvdata(dev);
 	struct regmap *regmap = data->regmap;
@@ -255,11 +254,11 @@ static int do_set_pwm_polarity(struct device *dev, unsigned long val)
  * Set pwm value. Accepts values between 0 (stops the fan) and
  * 255 (full speed). This only makes sense in open-loop mode.
  */
-static int do_set_pwm(struct device *dev, unsigned long val)
+static int do_set_pwm(struct device *dev, long val)
 {
 	struct g762_data *data = dev_get_drvdata(dev);
 
-	if (val > 255)
+	if (val < 0 || val > 255)
 		return -EINVAL;
 
 	return regmap_write(data->regmap, G762_REG_SET_OUT, val);
@@ -269,7 +268,7 @@ static int do_set_pwm(struct device *dev, unsigned long val)
  * Set fan RPM value. Can be called both in closed and open-loop mode
  * but effect will only be seen after closed-loop mode is configured.
  */
-static int do_set_fan_target(struct device *dev, unsigned long val)
+static int do_set_fan_target(struct device *dev, long val)
 {
 	struct g762_data *data = dev_get_drvdata(dev);
 	struct regmap *regmap = data->regmap;
@@ -277,6 +276,9 @@ static int do_set_fan_target(struct device *dev, unsigned long val)
 	u8 set_cnt;
 	int ret;
 
+	if (val < 0)
+		return -EINVAL;
+
 	mutex_lock(&data->update_lock);
 
 	ret = regmap_read(regmap, G762_REG_FAN_CMD1, &cmd1);
@@ -346,317 +348,201 @@ static int get_fan_rpm(struct g762_data *data, int reg)
 	return ret;
 }
 
-/*
- * Read function for fan1_input sysfs file. Return current fan RPM value, or
- * 0 if fan is out of control.
- */
-static ssize_t fan1_input_show(struct device *dev,
-			       struct device_attribute *da, char *buf)
+static int g762_fan_read(struct device *dev, u32 attr, long *val)
 {
 	struct g762_data *data = dev_get_drvdata(dev);
-	u32 status;
+	u32 regval;
 	int ret;
 
-	mutex_lock(&data->update_lock);
-	ret = regmap_read(data->regmap, G762_REG_FAN_STA, &status);
-	/* reverse logic: fan out of control reporting is enabled low */
-	if (ret || !(status & G762_REG_FAN_STA_OOC))
-		goto unlock;
-
-	ret = get_fan_rpm_locked(data, G762_REG_ACT_CNT);
-	if (ret < 0)
-		goto unlock;
-
-	ret = sprintf(buf, "%u\n", ret);
-unlock:
-	mutex_unlock(&data->update_lock);
-	return ret;
+	switch (attr) {
+	case hwmon_fan_target:
+		ret = get_fan_rpm(data, G762_REG_SET_CNT);
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		break;
+	case hwmon_fan_div:
+		ret = regmap_read(data->regmap, G762_REG_FAN_CMD1, &regval);
+		if (ret < 0)
+			return ret;
+		*val = G762_CLKDIV_FROM_REG(regval);
+		break;
+	case hwmon_fan_pulses:
+		ret = regmap_read(data->regmap, G762_REG_FAN_CMD1, &regval);
+		if (ret < 0)
+			return ret;
+		*val = G762_PULSE_FROM_REG(regval);
+		break;
+	case hwmon_fan_input:
+		mutex_lock(&data->update_lock);
+		ret = regmap_read(data->regmap, G762_REG_FAN_STA, &regval);
+		if (ret || !(regval & G762_REG_FAN_STA_OOC)) {
+			mutex_unlock(&data->update_lock);
+			return ret ? : -ENODATA;
+		}
+		ret = get_fan_rpm_locked(data, G762_REG_ACT_CNT);
+		mutex_unlock(&data->update_lock);
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		break;
+	case hwmon_fan_alarm:
+		ret = regmap_read(data->regmap, G762_REG_FAN_STA, &regval);
+		if (ret < 0)
+			return ret;
+		/* G762_REG_FAN_STA_OOC is active low */
+		*val = !(regval & G762_REG_FAN_STA_OOC);
+		break;
+	case hwmon_fan_fault:
+		ret = regmap_read(data->regmap, G762_REG_FAN_STA, &regval);
+		if (ret < 0)
+			return ret;
+		*val = !!(regval & G762_REG_FAN_STA_FAIL);
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+	return 0;
 }
 
-/*
- * Read and write functions for pwm1_mode sysfs file. Get and set fan speed
- * control mode i.e. PWM (1) or DC (0).
- */
-static ssize_t pwm1_mode_show(struct device *dev, struct device_attribute *da,
-			      char *buf)
+static int g762_pwm_read(struct device *dev, u32 attr, long *val)
 {
 	struct g762_data *data = dev_get_drvdata(dev);
-	u32 cmd1;
+	u32 regval;
 	int ret;
 
-	ret = regmap_read(data->regmap, G762_REG_FAN_CMD1, &cmd1);
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%d\n", !!(cmd1 & G762_REG_FAN_CMD1_OUT_MODE));
+	switch (attr) {
+	case hwmon_pwm_input:
+		ret = regmap_read(data->regmap, G762_REG_SET_OUT, &regval);
+		if (ret < 0)
+			return ret;
+		*val = regval;
+		break;
+	case hwmon_pwm_mode:
+		ret = regmap_read(data->regmap, G762_REG_FAN_CMD1, &regval);
+		if (ret < 0)
+			return ret;
+		*val = !!(regval & G762_REG_FAN_CMD1_OUT_MODE);
+		break;
+	case hwmon_pwm_enable:
+		ret = regmap_read(data->regmap, G762_REG_FAN_CMD1, &regval);
+		if (ret < 0)
+			return ret;
+		*val = !!(regval & G762_REG_FAN_CMD1_FAN_MODE) + 1;
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+	return 0;
 }
 
-static ssize_t pwm1_mode_store(struct device *dev,
-			       struct device_attribute *da, const char *buf,
-			       size_t count)
+static int g762_read(struct device *dev, enum hwmon_sensor_types type,
+		     u32 attr, int channel, long *val)
 {
-	unsigned long val;
-	int ret;
-
-	if (kstrtoul(buf, 10, &val))
-		return -EINVAL;
-
-	ret = do_set_pwm_mode(dev, val);
-	if (ret < 0)
-		return ret;
-
-	return count;
+	switch (type) {
+	case hwmon_fan:
+		return g762_fan_read(dev, attr, val);
+	case hwmon_pwm:
+		return g762_pwm_read(dev, attr, val);
+	default:
+		return -EOPNOTSUPP;
+	}
 }
 
-/*
- * Read and write functions for fan1_div sysfs file. Get and set fan
- * controller prescaler value
- */
-static ssize_t fan1_div_show(struct device *dev, struct device_attribute *da,
-			     char *buf)
+static int g762_fan_write(struct device *dev, u32 attr, long val)
 {
-	struct g762_data *data = dev_get_drvdata(dev);
-	u32 cmd1;
-	int ret;
-
-	ret = regmap_read(data->regmap, G762_REG_FAN_CMD1, &cmd1);
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%ld\n", G762_CLKDIV_FROM_REG(cmd1));
+	switch (attr) {
+	case hwmon_fan_target:
+		return do_set_fan_target(dev, val);
+	case hwmon_fan_div:
+		return do_set_fan_div(dev, val);
+	case hwmon_fan_pulses:
+		return do_set_fan_pulses(dev, val);
+	default:
+		return -EOPNOTSUPP;
+	}
 }
 
-static ssize_t fan1_div_store(struct device *dev, struct device_attribute *da,
-			      const char *buf, size_t count)
+static int g762_pwm_write(struct device *dev, u32 attr, long val)
 {
-	unsigned long val;
-	int ret;
-
-	if (kstrtoul(buf, 10, &val))
-		return -EINVAL;
-
-	ret = do_set_fan_div(dev, val);
-	if (ret < 0)
-		return ret;
-
-	return count;
+	switch (attr) {
+	case hwmon_pwm_input:
+		return do_set_pwm(dev, val);
+	case hwmon_pwm_mode:
+		return do_set_pwm_mode(dev, val);
+	case hwmon_pwm_enable:
+		return do_set_pwm_enable(dev, val);
+	default:
+		return -EOPNOTSUPP;
+	}
 }
 
-/*
- * Read and write functions for fan1_pulses sysfs file. Get and set number
- * of tachometer pulses per fan revolution.
- */
-static ssize_t fan1_pulses_show(struct device *dev,
-				struct device_attribute *da, char *buf)
+static int g762_write(struct device *dev, enum hwmon_sensor_types type,
+		      u32 attr, int channel, long val)
 {
-	struct g762_data *data = dev_get_drvdata(dev);
-	u32 cmd1;
-	int ret;
-
-	ret = regmap_read(data->regmap, G762_REG_FAN_CMD1, &cmd1);
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%ld\n", G762_PULSE_FROM_REG(cmd1));
+	switch (type) {
+	case hwmon_fan:
+		return g762_fan_write(dev, attr, val);
+	case hwmon_pwm:
+		return g762_pwm_write(dev, attr, val);
+	default:
+		return -EOPNOTSUPP;
+	}
 }
 
-static ssize_t fan1_pulses_store(struct device *dev,
-				 struct device_attribute *da, const char *buf,
-				 size_t count)
+static umode_t g762_is_visible(const void *_data, enum hwmon_sensor_types type,
+			       u32 attr, int channel)
 {
-	unsigned long val;
-	int ret;
-
-	if (kstrtoul(buf, 10, &val))
-		return -EINVAL;
-
-	ret = do_set_fan_pulses(dev, val);
-	if (ret < 0)
-		return ret;
-
-	return count;
+	switch (type) {
+	case hwmon_fan:
+		switch (attr) {
+		case hwmon_fan_input:
+		case hwmon_fan_alarm:
+		case hwmon_fan_fault:
+			return 0444;
+		case hwmon_fan_target:
+		case hwmon_fan_div:
+		case hwmon_fan_pulses:
+			return 0644;
+		default:
+			break;
+		}
+		break;
+	case hwmon_pwm:
+		switch (attr) {
+		case hwmon_pwm_input:
+		case hwmon_pwm_mode:
+		case hwmon_pwm_enable:
+			return 0644;
+		default:
+			break;
+		}
+		break;
+	default:
+		break;
+	}
+	return 0;
 }
 
-/*
- * Read and write functions for pwm1_enable. Get and set fan speed control mode
- * (i.e. closed or open-loop).
- *
- * Following documentation about hwmon's sysfs interface, a pwm1_enable node
- * should accept the following:
- *
- *  0 : no fan speed control (i.e. fan at full speed)
- *  1 : manual fan speed control enabled (use pwm[1-*]) (open-loop)
- *  2+: automatic fan speed control enabled (use fan[1-*]_target) (closed-loop)
- *
- * but we do not accept 0 as this mode is not natively supported by the chip
- * and it is not emulated by g762 driver. -EINVAL is returned in this case.
- */
-static ssize_t pwm1_enable_show(struct device *dev,
-				struct device_attribute *da, char *buf)
-{
-	struct g762_data *data = dev_get_drvdata(dev);
-	u32 cmd1;
-	int ret;
-
-	ret = regmap_read(data->regmap, G762_REG_FAN_CMD1, &cmd1);
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%d\n",
-		       !!(cmd1 & G762_REG_FAN_CMD1_FAN_MODE) + 1);
-}
-
-static ssize_t pwm1_enable_store(struct device *dev,
-				 struct device_attribute *da, const char *buf,
-				 size_t count)
-{
-	unsigned long val;
-	int ret;
-
-	if (kstrtoul(buf, 10, &val))
-		return -EINVAL;
-
-	ret = do_set_pwm_enable(dev, val);
-	if (ret < 0)
-		return ret;
-
-	return count;
-}
-
-/*
- * Read and write functions for pwm1 sysfs file. Get and set pwm value
- * (which affects fan speed) in open-loop mode. 0 stops the fan and 255
- * makes it run at full speed.
- */
-static ssize_t pwm1_show(struct device *dev, struct device_attribute *da,
-			 char *buf)
-{
-	struct g762_data *data = dev_get_drvdata(dev);
-	int ret;
-	u32 pwm;
-
-	ret = regmap_read(data->regmap, G762_REG_SET_OUT, &pwm);
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%u\n", pwm);
-}
-
-static ssize_t pwm1_store(struct device *dev, struct device_attribute *da,
-			  const char *buf, size_t count)
-{
-	unsigned long val;
-	int ret;
-
-	if (kstrtoul(buf, 10, &val))
-		return -EINVAL;
-
-	ret = do_set_pwm(dev, val);
-	if (ret < 0)
-		return ret;
-
-	return count;
-}
-
-/*
- * Read and write function for fan1_target sysfs file. Get/set the fan speed in
- * closed-loop mode. Speed is given as a RPM value; then the chip will regulate
- * the fan speed using pulses from fan tachometer.
- *
- * Refer to rpm_from_cnt() implementation above to get info about count number
- * calculation.
- *
- * Also note that due to rounding errors it is possible that you don't read
- * back exactly the value you have set.
- */
-static ssize_t fan1_target_show(struct device *dev,
-				struct device_attribute *da, char *buf)
-{
-	struct g762_data *data = dev_get_drvdata(dev);
-	int rpm;
-
-	rpm = get_fan_rpm(data, G762_REG_SET_CNT);
-	if (rpm < 0)
-		return rpm;
-
-	return sprintf(buf, "%d\n", rpm);
-}
-
-static ssize_t fan1_target_store(struct device *dev,
-				 struct device_attribute *da, const char *buf,
-				 size_t count)
-{
-	unsigned long val;
-	int ret;
-
-	if (kstrtoul(buf, 10, &val))
-		return -EINVAL;
-
-	ret = do_set_fan_target(dev, val);
-	if (ret < 0)
-		return ret;
-
-	return count;
-}
-
-/* read function for fan1_fault sysfs file. */
-static ssize_t fan1_fault_show(struct device *dev, struct device_attribute *da,
-			       char *buf)
-{
-	struct g762_data *data = dev_get_drvdata(dev);
-	u32 status;
-	int ret;
-
-	ret = regmap_read(data->regmap, G762_REG_FAN_STA, &status);
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%u\n", !!(status & G762_REG_FAN_STA_FAIL));
-}
-
-/*
- * read function for fan1_alarm sysfs file. Note that OOC condition is
- * enabled low
- */
-static ssize_t fan1_alarm_show(struct device *dev,
-			       struct device_attribute *da, char *buf)
-{
-	struct g762_data *data = dev_get_drvdata(dev);
-	u32 status;
-	int ret;
-
-	ret = regmap_read(data->regmap, G762_REG_FAN_STA, &status);
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%u\n", !(status & G762_REG_FAN_STA_OOC));
-}
-
-static DEVICE_ATTR_RW(pwm1);
-static DEVICE_ATTR_RW(pwm1_mode);
-static DEVICE_ATTR_RW(pwm1_enable);
-static DEVICE_ATTR_RO(fan1_input);
-static DEVICE_ATTR_RO(fan1_alarm);
-static DEVICE_ATTR_RO(fan1_fault);
-static DEVICE_ATTR_RW(fan1_target);
-static DEVICE_ATTR_RW(fan1_div);
-static DEVICE_ATTR_RW(fan1_pulses);
-
-/* Driver data */
-static struct attribute *g762_attrs[] = {
-	&dev_attr_fan1_input.attr,
-	&dev_attr_fan1_alarm.attr,
-	&dev_attr_fan1_fault.attr,
-	&dev_attr_fan1_target.attr,
-	&dev_attr_fan1_div.attr,
-	&dev_attr_fan1_pulses.attr,
-	&dev_attr_pwm1.attr,
-	&dev_attr_pwm1_mode.attr,
-	&dev_attr_pwm1_enable.attr,
+static const struct hwmon_channel_info * const g762_info[] = {
+	HWMON_CHANNEL_INFO(fan,
+			   HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT |
+			   HWMON_F_TARGET | HWMON_F_DIV | HWMON_F_PULSES),
+	HWMON_CHANNEL_INFO(pwm,
+			   HWMON_PWM_INPUT | HWMON_PWM_MODE | HWMON_PWM_ENABLE),
 	NULL
 };
 
-ATTRIBUTE_GROUPS(g762);
+static const struct hwmon_ops g762_hwmon_ops = {
+	.is_visible = g762_is_visible,
+	.read = g762_read,
+	.write = g762_write,
+};
+
+static const struct hwmon_chip_info g762_chip_info = {
+	.ops = &g762_hwmon_ops,
+	.info = g762_info,
+};
 
 /*
  * Enable both fan failure detection and fan out of control protection.
@@ -770,8 +656,9 @@ static int g762_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
-	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
-							    data, g762_groups);
+	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
+							 data, &g762_chip_info,
+							 NULL);
 	return PTR_ERR_OR_ZERO(hwmon_dev);
 }
 
Signature · 1 line
2.39.2