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 <joao.goncalves@toradex.com> Link: https://lore.kernel.org/r/20250613-b4-amc6821-cooling-device-support-v4-2-a8fc063c55de@toradex.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
committed by
Guenter Roeck
parent
f2a32ed869
commit
b0078b2c9f
+16
-8
@@ -126,6 +126,7 @@ module_param(init, int, 0444);
|
||||
struct amc6821_data {
|
||||
struct regmap *regmap;
|
||||
struct mutex update_lock;
|
||||
enum pwm_polarity pwm_polarity;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -848,11 +849,11 @@ static int amc6821_detect(struct i2c_client *client, struct i2c_board_info *info
|
||||
return 0;
|
||||
}
|
||||
|
||||
static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client)
|
||||
static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client,
|
||||
struct device_node *fan_np)
|
||||
{
|
||||
enum pwm_polarity polarity = PWM_POLARITY_NORMAL;
|
||||
struct of_phandle_args args;
|
||||
struct device_node *fan_np;
|
||||
|
||||
/*
|
||||
* For backward compatibility, the pwminv module parameter takes
|
||||
@@ -863,10 +864,6 @@ static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client)
|
||||
if (pwminv > 0)
|
||||
return PWM_POLARITY_INVERSED;
|
||||
|
||||
fan_np = of_get_child_by_name(client->dev.of_node, "fan");
|
||||
if (!fan_np)
|
||||
return PWM_POLARITY_NORMAL;
|
||||
|
||||
if (of_parse_phandle_with_args(fan_np, "pwms", "#pwm-cells", 0, &args))
|
||||
goto out;
|
||||
of_node_put(args.np);
|
||||
@@ -877,10 +874,16 @@ static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client)
|
||||
if (args.args[1] & PWM_POLARITY_INVERTED)
|
||||
polarity = PWM_POLARITY_INVERSED;
|
||||
out:
|
||||
of_node_put(fan_np);
|
||||
return polarity;
|
||||
}
|
||||
|
||||
static void amc6821_of_fan_read_data(struct i2c_client *client,
|
||||
struct amc6821_data *data,
|
||||
struct device_node *fan_np)
|
||||
{
|
||||
data->pwm_polarity = amc6821_pwm_polarity(client, fan_np);
|
||||
}
|
||||
|
||||
static int amc6821_init_client(struct i2c_client *client, struct amc6821_data *data)
|
||||
{
|
||||
struct regmap *regmap = data->regmap;
|
||||
@@ -902,7 +905,7 @@ static int amc6821_init_client(struct i2c_client *client, struct amc6821_data *d
|
||||
return err;
|
||||
|
||||
regval = AMC6821_CONF1_START;
|
||||
if (amc6821_pwm_polarity(client) == PWM_POLARITY_INVERSED)
|
||||
if (data->pwm_polarity == PWM_POLARITY_INVERSED)
|
||||
regval |= AMC6821_CONF1_PWMINV;
|
||||
|
||||
err = regmap_update_bits(regmap, AMC6821_REG_CONF1,
|
||||
@@ -944,6 +947,7 @@ static int amc6821_probe(struct i2c_client *client)
|
||||
struct amc6821_data *data;
|
||||
struct device *hwmon_dev;
|
||||
struct regmap *regmap;
|
||||
struct device_node *fan_np __free(device_node) = NULL;
|
||||
int err;
|
||||
|
||||
data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL);
|
||||
@@ -956,6 +960,10 @@ static int amc6821_probe(struct i2c_client *client)
|
||||
"Failed to initialize regmap\n");
|
||||
data->regmap = regmap;
|
||||
|
||||
fan_np = of_get_child_by_name(dev->of_node, "fan");
|
||||
if (fan_np)
|
||||
amc6821_of_fan_read_data(client, data, fan_np);
|
||||
|
||||
err = amc6821_init_client(client, data);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
Reference in New Issue
Block a user