hwmon: (pwm-fan) Make use of device properties
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 4 Apr 2024 19:11:39 +0000 (22:11 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 28 Apr 2024 17:08:33 +0000 (10:08 -0700)
Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

Add mod_devicetable.h include.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20240404191323.3547465-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/Kconfig
drivers/hwmon/pwm-fan.c

index caacc4057e8225a9c8a4047344d26f21eb1c6ebf..c89776d91795baf3e8ddebd4d9f1b4ad9ad84c2f 100644 (file)
@@ -1785,7 +1785,7 @@ config SENSORS_PT5161L
 
 config SENSORS_PWM_FAN
        tristate "PWM fan"
-       depends on (PWM && OF) || COMPILE_TEST
+       depends on PWM || COMPILE_TEST
        depends on THERMAL || THERMAL=n
        help
          If you say yes here you get support for fans connected to PWM lines.
index bf902610cd0794305ff7f5a6d8ab5c842198ae2b..a1712649b07e3f2cd7181854aa2b69a609b64d4c 100644 (file)
@@ -9,10 +9,11 @@
 
 #include <linux/hwmon.h>
 #include <linux/interrupt.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
-#include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/pwm.h>
 #include <linux/regulator/consumer.h>
 #include <linux/sysfs.h>
@@ -421,16 +422,14 @@ static const struct thermal_cooling_device_ops pwm_fan_cooling_ops = {
        .set_cur_state = pwm_fan_set_cur_state,
 };
 
-static int pwm_fan_of_get_cooling_data(struct device *dev,
-                                      struct pwm_fan_ctx *ctx)
+static int pwm_fan_get_cooling_data(struct device *dev, struct pwm_fan_ctx *ctx)
 {
-       struct device_node *np = dev->of_node;
        int num, i, ret;
 
-       if (!of_property_present(np, "cooling-levels"))
+       if (!device_property_present(dev, "cooling-levels"))
                return 0;
 
-       ret = of_property_count_u32_elems(np, "cooling-levels");
+       ret = device_property_count_u32(dev, "cooling-levels");
        if (ret <= 0) {
                dev_err(dev, "Wrong data!\n");
                return ret ? : -EINVAL;
@@ -442,8 +441,8 @@ static int pwm_fan_of_get_cooling_data(struct device *dev,
        if (!ctx->pwm_fan_cooling_levels)
                return -ENOMEM;
 
-       ret = of_property_read_u32_array(np, "cooling-levels",
-                                        ctx->pwm_fan_cooling_levels, num);
+       ret = device_property_read_u32_array(dev, "cooling-levels",
+                                            ctx->pwm_fan_cooling_levels, num);
        if (ret) {
                dev_err(dev, "Property 'cooling-levels' cannot be read!\n");
                return ret;
@@ -574,8 +573,8 @@ static int pwm_fan_probe(struct platform_device *pdev)
                for (i = 0; i < ctx->tach_count; i++)
                        ctx->pulses_per_revolution[i] = 2;
 
-               of_property_read_u32_array(dev->of_node, "pulses-per-revolution",
-                                          ctx->pulses_per_revolution, ctx->tach_count);
+               device_property_read_u32_array(dev, "pulses-per-revolution",
+                                              ctx->pulses_per_revolution, ctx->tach_count);
        }
 
        channels = devm_kcalloc(dev, channel_count + 1,
@@ -630,7 +629,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
                return PTR_ERR(hwmon);
        }
 
-       ret = pwm_fan_of_get_cooling_data(dev, ctx);
+       ret = pwm_fan_get_cooling_data(dev, ctx);
        if (ret)
                return ret;