[PATCH 1/2] hwmon: (spd5118) pass spd5118_data to hwmon callbacks

From: Yo-Jung (Leo) Lin
Date: Wed Apr 16 2025 - 02:58:05 EST


Currently only the regcache is passed to the hwmon device. Pass the
whole spd5118_data for better flexibility.

Signed-off-by: Yo-Jung (Leo) Lin <leo.lin@xxxxxxxxxxxxx>
---
drivers/hwmon/spd5118.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c
index 358152868d96..3cb2eb2e0227 100644
--- a/drivers/hwmon/spd5118.c
+++ b/drivers/hwmon/spd5118.c
@@ -174,7 +174,8 @@ static int spd5118_read_enable(struct regmap *regmap, long *val)
static int spd5118_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
- struct regmap *regmap = dev_get_drvdata(dev);
+ struct spd5118_data *data = dev_get_drvdata(dev);
+ struct regmap *regmap = data->regmap;

if (type != hwmon_temp)
return -EOPNOTSUPP;
@@ -256,7 +257,8 @@ static int spd5118_temp_write(struct regmap *regmap, u32 attr, long val)
static int spd5118_write(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long val)
{
- struct regmap *regmap = dev_get_drvdata(dev);
+ struct spd5118_data *data = dev_get_drvdata(dev);
+ struct regmap *regmap = data->regmap;

switch (type) {
case hwmon_temp:
@@ -269,6 +271,8 @@ static int spd5118_write(struct device *dev, enum hwmon_sensor_types type,
static umode_t spd5118_is_visible(const void *_data, enum hwmon_sensor_types type,
u32 attr, int channel)
{
+ struct spd5118_data *data = (struct spd5118_data *)_data;
+
if (type != hwmon_temp)
return 0;

@@ -611,7 +615,7 @@ static int spd5118_probe(struct i2c_client *client)
}

hwmon_dev = devm_hwmon_device_register_with_info(dev, "spd5118",
- regmap, &spd5118_chip_info,
+ data, &spd5118_chip_info,
NULL);
if (IS_ERR(hwmon_dev))
return PTR_ERR(hwmon_dev);

--
2.43.0