Skip to content

Commit b0078b2

Browse files
JPSGoncalvesgroeck
authored andcommitted
hwmon: (amc6821) Move reading fan data from OF to a function
Move fan property reading from OF to a separate function. This keeps OF data handling separate from the code logic and makes it easier to add features like cooling device support that use the same fan node. Signed-off-by: João Paulo Gonçalves <[email protected]> Link: https://lore.kernel.org/r/20250613-b4-amc6821-cooling-device-support-v4-2-a8fc063c55de@toradex.com Signed-off-by: Guenter Roeck <[email protected]>
1 parent f2a32ed commit b0078b2

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

drivers/hwmon/amc6821.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ module_param(init, int, 0444);
126126
struct amc6821_data {
127127
struct regmap *regmap;
128128
struct mutex update_lock;
129+
enum pwm_polarity pwm_polarity;
129130
};
130131

131132
/*
@@ -848,11 +849,11 @@ static int amc6821_detect(struct i2c_client *client, struct i2c_board_info *info
848849
return 0;
849850
}
850851

851-
static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client)
852+
static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client,
853+
struct device_node *fan_np)
852854
{
853855
enum pwm_polarity polarity = PWM_POLARITY_NORMAL;
854856
struct of_phandle_args args;
855-
struct device_node *fan_np;
856857

857858
/*
858859
* For backward compatibility, the pwminv module parameter takes
@@ -863,10 +864,6 @@ static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client)
863864
if (pwminv > 0)
864865
return PWM_POLARITY_INVERSED;
865866

866-
fan_np = of_get_child_by_name(client->dev.of_node, "fan");
867-
if (!fan_np)
868-
return PWM_POLARITY_NORMAL;
869-
870867
if (of_parse_phandle_with_args(fan_np, "pwms", "#pwm-cells", 0, &args))
871868
goto out;
872869
of_node_put(args.np);
@@ -877,10 +874,16 @@ static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client)
877874
if (args.args[1] & PWM_POLARITY_INVERTED)
878875
polarity = PWM_POLARITY_INVERSED;
879876
out:
880-
of_node_put(fan_np);
881877
return polarity;
882878
}
883879

880+
static void amc6821_of_fan_read_data(struct i2c_client *client,
881+
struct amc6821_data *data,
882+
struct device_node *fan_np)
883+
{
884+
data->pwm_polarity = amc6821_pwm_polarity(client, fan_np);
885+
}
886+
884887
static int amc6821_init_client(struct i2c_client *client, struct amc6821_data *data)
885888
{
886889
struct regmap *regmap = data->regmap;
@@ -902,7 +905,7 @@ static int amc6821_init_client(struct i2c_client *client, struct amc6821_data *d
902905
return err;
903906

904907
regval = AMC6821_CONF1_START;
905-
if (amc6821_pwm_polarity(client) == PWM_POLARITY_INVERSED)
908+
if (data->pwm_polarity == PWM_POLARITY_INVERSED)
906909
regval |= AMC6821_CONF1_PWMINV;
907910

908911
err = regmap_update_bits(regmap, AMC6821_REG_CONF1,
@@ -944,6 +947,7 @@ static int amc6821_probe(struct i2c_client *client)
944947
struct amc6821_data *data;
945948
struct device *hwmon_dev;
946949
struct regmap *regmap;
950+
struct device_node *fan_np __free(device_node) = NULL;
947951
int err;
948952

949953
data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL);
@@ -956,6 +960,10 @@ static int amc6821_probe(struct i2c_client *client)
956960
"Failed to initialize regmap\n");
957961
data->regmap = regmap;
958962

963+
fan_np = of_get_child_by_name(dev->of_node, "fan");
964+
if (fan_np)
965+
amc6821_of_fan_read_data(client, data, fan_np);
966+
959967
err = amc6821_init_client(client, data);
960968
if (err)
961969
return err;

0 commit comments

Comments
 (0)