(gpio-fan): Add thermal control hooks
Subsystems (3)
PATCH 1/1 (gpio-fan): Add thermal control hooks
Allow gpio-fan to be used as thermal cooling device for platforms that use GPIO maps to control fans.
---
Based on v3.19-rc3
.../devicetree/bindings/gpio/gpio-fan.txt | 14 +++ drivers/hwmon/gpio-fan.c | 93 ++++++++++++++++++-- 2 files changed, 100 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-fan.txt +14 -0
@@ -11,6 +11,9 @@ Required properties: Optional properties: - alarm-gpios: This pin going active indicates something is wrong with the fan, and a udev event will be fired. +- cooling-cells: If used as a cooling device, must be <2> + Also see: Documentation/devicetree/bindings/thermal/thermal.txt + min and max states are derived from the speed-map of the fan. Examples:
@@ -23,3 +26,14 @@ Examples: 6000 2>; alarm-gpios = <&gpio1 15 1>; }; + + gpio_fan_cool: gpio_fan { + compatible = "gpio-fan"; + gpios = <&gpio2 14 1 + &gpio2 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + alarm-gpios = <&gpio1 15 1>; + #cooling-cells = <2>; /* min followed by max */ + };
drivers/hwmon/gpio-fan.c +86 -7
156 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Guenter Roeck
maintainerQuoted 27 lines · Nishanth Menon
Allow gpio-fan to be used as thermal cooling device for platforms that use GPIO maps to control fans.
Signed-off-by Nishanth Menon <[email protected]>---
Based on v3.19-rc3
.../devicetree/bindings/gpio/gpio-fan.txt | 14 +++ drivers/hwmon/gpio-fan.c | 93 ++++++++++++++++++-- 2 files changed, 100 insertions(+), 7 deletions(-)Documentation/devicetree/bindings/gpio/gpio-fan.txt +3
-0@@ -11,6 +11,9 @@ Required properties: Optional properties: - alarm-gpios: This pin going active indicates something is wrong with the fan, and a udev event will be fired. +- cooling-cells: If used as a cooling device, must be <2> + Also see: Documentation/devicetree/bindings/thermal/thermal.txt + min and max states are derived from the speed-map of the fan. Examples:
Documentation/devicetree/bindings/gpio/gpio-fan.txt Examples: · line 29
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-fan.txt +1
-0@@ -23,3 +26,14 @@ Examples: 6000 2>; alarm-gpios = <&gpio1 15 1>; }; +
Unnecessary second empty line.
Quoted 15 lines
Documentation/devicetree/bindings/gpio/gpio-fan.txt +10
-0+ gpio_fan_cool: gpio_fan { + compatible = "gpio-fan"; + gpios = <&gpio2 14 1 + &gpio2 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + alarm-gpios = <&gpio1 15 1>; + #cooling-cells = <2>; /* min followed by max */ + };drivers/hwmon/gpio-fan.c +0
-0
drivers/hwmon/gpio-fan.c line 38
Quoted 5 lines
drivers/hwmon/gpio-fan.c +2
-0@@ -34,10 +34,14 @@#include <linux/of.h> #include <linux/of_platform.h> #include <linux/of_gpio.h> +#include <linux/thermal.h> +
Unnecessary additional empty line.
Quoted 31 lines
drivers/hwmon/gpio-fan.c +20
-0struct gpio_fan_data {struct platform_device *pdev;struct device *hwmon_dev; +/* Cooling device if any */ +struct thermal_cooling_device *cdev;struct mutex lock;/* lock GPIOs operations. */ int num_ctrl;unsigned *ctrl;@@ -387,12 +391,63 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,return 0 ; } +static int gpio_fan_get_max_state (struct thermal_cooling_device *cdev, +unsigned long *state) +{ +struct gpio_fan_data *fan_data = cdev->devdata; + +if (!fan_data) +return -EINVAL ; + + *state = fan_data->num_speed -1 ; +return 0 ; +} + +static int gpio_fan_get_cur_state (struct thermal_cooling_device *cdev, +unsigned long *state) +{ +struct gpio_fan_data *fan_data = cdev->devdata; +int r; +
drivers/hwmon/gpio-fan.c static int fan_ctrl_init(struct gpio_fan_data *fan_data, · line 421
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+if (!fan_data) +return -EINVAL ; + + r =get_fan_speed_index (fan_data); +if (r <0 ) +return r; + + *state = r; +return 0 ; +
Unnecessary empty line.
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+} + +static int gpio_fan_set_cur_state (struct thermal_cooling_device *cdev, +unsigned long state) +{ +struct gpio_fan_data *fan_data = cdev->devdata; + +if (!fan_data) +return -EINVAL ; +
drivers/hwmon/gpio-fan.c static int fan_ctrl_init(struct gpio_fan_data *fan_data, · line 441
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+set_fan_speed (fan_data, state); + +return 0 ; +} + +static const struct thermal_cooling_device_ops gpio_fan_cooling_ops = { + .get_max_state = gpio_fan_get_max_state, + .get_cur_state = gpio_fan_get_cur_state, + .set_cur_state = gpio_fan_set_cur_state, +
Unnecessary empty line (checkpatch!!!)
Quoted 14 lines
drivers/hwmon/gpio-fan.c +4
-1+}; +#ifdef CONFIG_OF_GPIO /* * Translate OpenFirmware node properties into platform_data */ static int gpio_fan_get_of_pdata (struct device *dev, -struct gpio_fan_platform_data *pdata) +struct gpio_fan_platform_data *pdata, +struct gpio_fan_data *fan_data) {struct device_node *node;struct gpio_fan_speed *speed;
drivers/hwmon/gpio-fan.c static int gpio_fan_get_of_pdata(struct device *dev, · line 540
Quoted 6 lines
drivers/hwmon/gpio-fan.c +3
-0@@ -480,6 +535,12 @@ static int gpio_fan_get_of_pdata(struct device *dev, pdata->alarm = alarm; } + fan_data->cdev =thermal_of_cooling_device_register (node,"gpio-fan" , + fan_data, + &gpio_fan_cooling_ops);
Just use one continuation line here, with no spaces up front but only tabs.
drivers/hwmon/gpio-fan.c static int gpio_fan_get_of_pdata(struct device *dev, · line 543
Quoted 3 lines
drivers/hwmon/gpio-fan.c +3
-0+if (IS_ERR (fan_data->cdev)) +dev_dbg (dev,"gpio-fan has no valid cooling DT property\n" ); +
The property is optional. Why does this warrant even a debug message ?
Quoted 16 lines
drivers/hwmon/gpio-fan.c +5
-0return 0 ; }@@ -495,6 +556,11 @@ static int gpio_fan_probe(struct platform_device *pdev)struct gpio_fan_data *fan_data;struct gpio_fan_platform_data *pdata =dev_get_platdata (&pdev->dev); + fan_data =devm_kzalloc (&pdev->dev,sizeof (struct gpio_fan_data ), +GFP_KERNEL ); +if (!fan_data) +return -ENOMEM ; +#ifdef CONFIG_OF_GPIO if (!pdata) { pdata = devm_kzalloc(&pdev->dev,
drivers/hwmon/gpio-fan.c static int gpio_fan_probe(struct platform_device *pdev) · line 572
Quoted 5 lines
drivers/hwmon/gpio-fan.c +1
-1@@ -503,20 +569,19 @@ static int gpio_fan_probe(struct platform_device *pdev)if (!pdata)return -ENOMEM ; - err =gpio_fan_get_of_pdata (&pdev->dev, pdata); + err =gpio_fan_get_of_pdata (&pdev->dev, pdata, fan_data);
It is inconsistent with the code below to call thermal_of_cooling_device_register in gpio_fan_get_of_pdata (and to pass fan_data just for that purpose). Please call it from here.
Quoted 21 lines
drivers/hwmon/gpio-fan.c +4
-5if (err) return err; }#else /* CONFIG_OF_GPIO */ if (!pdata)return -EINVAL ; +/* Optional cooling device register for non Device tree platforms */ + fan_data->cdev =thermal_cooling_device_register ("gpio-fan" , + fan_data, + &gpio_fan_cooling_ops);#endif /* CONFIG_OF_GPIO */ - fan_data =devm_kzalloc (&pdev->dev,sizeof (struct gpio_fan_data ), -GFP_KERNEL ); -if (!fan_data) -return -ENOMEM ; - fan_data->pdev = pdev;platform_set_drvdata (pdev, fan_data);mutex_init (&fan_data->lock);
drivers/hwmon/gpio-fan.c static int gpio_fan_probe(struct platform_device *pdev) · line 620
Quoted 6 lines
drivers/hwmon/gpio-fan.c +3
-0@@ -550,10 +615,23 @@ static int gpio_fan_probe(struct platform_device *pdev)return 0 ; } +static int gpio_fan_remove (struct platform_device *pdev) +{ +struct gpio_fan_data *fan_data =platform_get_drvdata (pdev);
Indentation is problematic. Actually, checkpatch shows several whitespace problems as well as an unnecessary empty line. Please ensure that your patch passes checkpatch --strict.
Quoted 4 lines
drivers/hwmon/gpio-fan.c +4
-0+ +if (!IS_ERR (fan_data->cdev)) +thermal_cooling_device_unregister (fan_data->cdev); +
drivers/hwmon/gpio-fan.c static int gpio_fan_probe(struct platform_device *pdev) · line 634
Quoted 10 lines
drivers/hwmon/gpio-fan.c +6
-0+return 0 ; +} +static void gpio_fan_shutdown (struct platform_device *pdev) {struct gpio_fan_data *fan_data =dev_get_drvdata (&pdev->dev); +if (!IS_ERR (fan_data->cdev)) +thermal_cooling_device_unregister (fan_data->cdev); +
Instead of having this conditional call twice, you might as well call gpio_fan_remove() from here.
Quoted 14 lines
drivers/hwmon/gpio-fan.c +1
-0if (fan_data->ctrl)set_fan_speed (fan_data,0 ); }@@ -589,6 +667,7 @@ static SIMPLE_DEV_PM_OPS(gpio_fan_pm, gpio_fan_suspend, gpio_fan_resume);static struct platform_driver gpio_fan_driver = { .probe = gpio_fan_probe, + .remove = gpio_fan_remove, .shutdown = gpio_fan_shutdown, .driver = { .name ="gpio-fan" ,Signature · 1 line
1.7.9.5