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

hwmon: (pwm-fan) Make use of device properties

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>

authored by

Andy Shevchenko and committed by
Guenter Roeck
dfd977d8 9c871df0

+11 -12
+1 -1
drivers/hwmon/Kconfig
··· 1785 1785 1786 1786 config SENSORS_PWM_FAN 1787 1787 tristate "PWM fan" 1788 - depends on (PWM && OF) || COMPILE_TEST 1788 + depends on PWM || COMPILE_TEST 1789 1789 depends on THERMAL || THERMAL=n 1790 1790 help 1791 1791 If you say yes here you get support for fans connected to PWM lines.
+10 -11
drivers/hwmon/pwm-fan.c
··· 9 9 10 10 #include <linux/hwmon.h> 11 11 #include <linux/interrupt.h> 12 + #include <linux/mod_devicetable.h> 12 13 #include <linux/module.h> 13 14 #include <linux/mutex.h> 14 - #include <linux/of.h> 15 15 #include <linux/platform_device.h> 16 + #include <linux/property.h> 16 17 #include <linux/pwm.h> 17 18 #include <linux/regulator/consumer.h> 18 19 #include <linux/sysfs.h> ··· 422 421 .set_cur_state = pwm_fan_set_cur_state, 423 422 }; 424 423 425 - static int pwm_fan_of_get_cooling_data(struct device *dev, 426 - struct pwm_fan_ctx *ctx) 424 + static int pwm_fan_get_cooling_data(struct device *dev, struct pwm_fan_ctx *ctx) 427 425 { 428 - struct device_node *np = dev->of_node; 429 426 int num, i, ret; 430 427 431 - if (!of_property_present(np, "cooling-levels")) 428 + if (!device_property_present(dev, "cooling-levels")) 432 429 return 0; 433 430 434 - ret = of_property_count_u32_elems(np, "cooling-levels"); 431 + ret = device_property_count_u32(dev, "cooling-levels"); 435 432 if (ret <= 0) { 436 433 dev_err(dev, "Wrong data!\n"); 437 434 return ret ? : -EINVAL; ··· 441 442 if (!ctx->pwm_fan_cooling_levels) 442 443 return -ENOMEM; 443 444 444 - ret = of_property_read_u32_array(np, "cooling-levels", 445 - ctx->pwm_fan_cooling_levels, num); 445 + ret = device_property_read_u32_array(dev, "cooling-levels", 446 + ctx->pwm_fan_cooling_levels, num); 446 447 if (ret) { 447 448 dev_err(dev, "Property 'cooling-levels' cannot be read!\n"); 448 449 return ret; ··· 573 574 for (i = 0; i < ctx->tach_count; i++) 574 575 ctx->pulses_per_revolution[i] = 2; 575 576 576 - of_property_read_u32_array(dev->of_node, "pulses-per-revolution", 577 - ctx->pulses_per_revolution, ctx->tach_count); 577 + device_property_read_u32_array(dev, "pulses-per-revolution", 578 + ctx->pulses_per_revolution, ctx->tach_count); 578 579 } 579 580 580 581 channels = devm_kcalloc(dev, channel_count + 1, ··· 629 630 return PTR_ERR(hwmon); 630 631 } 631 632 632 - ret = pwm_fan_of_get_cooling_data(dev, ctx); 633 + ret = pwm_fan_get_cooling_data(dev, ctx); 633 634 if (ret) 634 635 return ret; 635 636