Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

João Paulo Gonçalves and committed by
Guenter Roeck
b0078b2c f2a32ed8

+16 -8
+16 -8
drivers/hwmon/amc6821.c
··· 126 126 struct amc6821_data { 127 127 struct regmap *regmap; 128 128 struct mutex update_lock; 129 + enum pwm_polarity pwm_polarity; 129 130 }; 130 131 131 132 /* ··· 849 848 return 0; 850 849 } 851 850 852 - static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client) 851 + static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client, 852 + struct device_node *fan_np) 853 853 { 854 854 enum pwm_polarity polarity = PWM_POLARITY_NORMAL; 855 855 struct of_phandle_args args; 856 - struct device_node *fan_np; 857 856 858 857 /* 859 858 * For backward compatibility, the pwminv module parameter takes ··· 863 862 return PWM_POLARITY_NORMAL; 864 863 if (pwminv > 0) 865 864 return PWM_POLARITY_INVERSED; 866 - 867 - fan_np = of_get_child_by_name(client->dev.of_node, "fan"); 868 - if (!fan_np) 869 - return PWM_POLARITY_NORMAL; 870 865 871 866 if (of_parse_phandle_with_args(fan_np, "pwms", "#pwm-cells", 0, &args)) 872 867 goto out; ··· 874 877 if (args.args[1] & PWM_POLARITY_INVERTED) 875 878 polarity = PWM_POLARITY_INVERSED; 876 879 out: 877 - of_node_put(fan_np); 878 880 return polarity; 881 + } 882 + 883 + static void amc6821_of_fan_read_data(struct i2c_client *client, 884 + struct amc6821_data *data, 885 + struct device_node *fan_np) 886 + { 887 + data->pwm_polarity = amc6821_pwm_polarity(client, fan_np); 879 888 } 880 889 881 890 static int amc6821_init_client(struct i2c_client *client, struct amc6821_data *data) ··· 905 902 return err; 906 903 907 904 regval = AMC6821_CONF1_START; 908 - if (amc6821_pwm_polarity(client) == PWM_POLARITY_INVERSED) 905 + if (data->pwm_polarity == PWM_POLARITY_INVERSED) 909 906 regval |= AMC6821_CONF1_PWMINV; 910 907 911 908 err = regmap_update_bits(regmap, AMC6821_REG_CONF1, ··· 947 944 struct amc6821_data *data; 948 945 struct device *hwmon_dev; 949 946 struct regmap *regmap; 947 + struct device_node *fan_np __free(device_node) = NULL; 950 948 int err; 951 949 952 950 data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL); ··· 959 955 return dev_err_probe(dev, PTR_ERR(regmap), 960 956 "Failed to initialize regmap\n"); 961 957 data->regmap = regmap; 958 + 959 + fan_np = of_get_child_by_name(dev->of_node, "fan"); 960 + if (fan_np) 961 + amc6821_of_fan_read_data(client, data, fan_np); 962 962 963 963 err = amc6821_init_client(client, data); 964 964 if (err)