hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05]
Subsystems (5)
cover hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05]
This is an attempt at getting DT support into gpio-fan, in a similar fashion to gpio-leds and gpio-keys. I guess the most contentious bit is going to be the bindings.
Tested on a D-Link DNS-320.
Feedback appreciated!
Jamie Lentin (2):
hwmon: Add devicetree bindings to gpio-fan
ARM: kirkwood: Use devicetree to define DNS-32[05] fan
.../devicetree/bindings/gpio/gpio-fan.txt | 25 +++++ arch/arm/boot/dts/kirkwood-dnskw.dtsi | 10 ++ arch/arm/mach-kirkwood/board-dnskw.c | 25 ----- drivers/hwmon/gpio-fan.c | 111 ++++++++++++++++++++ 4 files changed, 146 insertions(+), 25 deletions(-) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txt
Signature · 1 line
1.7.10.4
PATCH 1/2 hwmon: Add devicetree bindings to gpio-fan
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
--- .../devicetree/bindings/gpio/gpio-fan.txt | 25 +++++ drivers/hwmon/gpio-fan.c | 111 ++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txt
Documentation/devicetree/bindings/gpio/gpio-fan.txt new file +25 -0
@@ -0,0 +1,25 @@ +Bindings for fan connected to GPIO lines + +Required properties: +- compatible : "gpio-fan" +- gpios: Specifies the pins that map to bits in the control value, + ordered MSB-->LSB. +- gpio-fan,speed-map: A mapping of possible fan RPM speeds and the + control value that should be set to achieve them. This array + must have the RPM values in ascending order. + +Optional properties: +- alarm-gpios: This pin going active indicates something is wrong with + the fan, and a udev event will be fired. + +Examples: + + gpio_fan { + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + alarm-gpios = <&gpio1 15 1>; + };
drivers/hwmon/gpio-fan.c +111 -0
135 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Guenter Roeck
maintainerPATCH 1/2 hwmon: Add devicetree bindings to gpio-fan
Quoted 80 lines · Jamie Lentin
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
Signed-off-by Jamie Lentin <[email protected]>--- .../devicetree/bindings/gpio/gpio-fan.txt | 25 +++++ drivers/hwmon/gpio-fan.c | 111 ++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txtDocumentation/devicetree/bindings/gpio/gpio-fan.txt new file +25
-0@@ -0,0 +1,25 @@ +Bindings for fan connected to GPIO lines + +Required properties: +- compatible : "gpio-fan" +- gpios: Specifies the pins that map to bits in the control value, + ordered MSB-->LSB. +- gpio-fan,speed-map: A mapping of possible fan RPM speeds and the + control value that should be set to achieve them. This array + must have the RPM values in ascending order. + +Optional properties: +- alarm-gpios: This pin going active indicates something is wrong with + the fan, and a udev event will be fired. + +Examples: + + gpio_fan { + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + alarm-gpios = <&gpio1 15 1>; + };drivers/hwmon/gpio-fan.c +24
-0@@ -31,6 +31,8 @@#include <linux/hwmon.h> #include <linux/gpio.h> #include <linux/gpio-fan.h> +#include <linux/of_platform.h> +#include <linux/of_gpio.h> struct gpio_fan_data {struct platform_device *pdev;@@ -400,12 +402,120 @@ static ssize_t show_name(struct device *dev, static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); + +#ifdef CONFIG_OF +/* +* Translate OpenFirmware node properties into platform_data +*/ +static int gpio_fan_get_of_pdata (struct device *dev, +struct gpio_fan_platform_data *pdata) +{ +struct device_node *node; +struct gpio_fan_speed *speed; +unsigned *ctrl; +unsigned i; +u32 u; +struct property *prop; +const __be32 *p; + + node = dev->of_node; + +/* Fill GPIO pin array */ + pdata->num_ctrl =of_gpio_count (node); + ctrl =devm_kzalloc (dev, pdata->num_ctrl *sizeof (unsigned ), +GFP_KERNEL );
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 436
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+if (!ctrl) +return -ENOMEM ; +for (i =0 ; i <of_gpio_count (node); i++) { +int val; + + val =of_get_gpio (node, i); +if (val >=0 ) + ctrl[i] = val; +else +return -EINVAL ;
I very much prefer not to hide the error code and reverse the logic.
if (val < 0) return val; ctrl[i] = val;
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 443
Quoted 7 lines
drivers/hwmon/gpio-fan.c +7
-0+ } + pdata->ctrl = ctrl; + +/* Get speed map array size */ + i =0 ; +of_property_for_each_u32 (node,"gpio-fan,speed-map" , prop, p, u) + i++;
Looking through the of code, isn't there a function which returns the number of elements ?
Something like
int length; struct property *prop; prop = of_find_property(node, "gpio-fan,speed-map", &length);
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 447
Quoted 4 lines
drivers/hwmon/gpio-fan.c +4
-0+if (i &1 ) { +dev_err (dev,"gpio-fan,speed-map contains odd number of entries" ); +return -ENODEV ; + }
How about i == 0 ?
Quoted 4 lines
drivers/hwmon/gpio-fan.c +4
-0+ pdata->num_speed = i >>1 ; + speed =devm_kzalloc (dev, + pdata->num_speed *sizeof (struct gpio_fan_speed ), +GFP_KERNEL );
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 461
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+if (!speed) +return -ENOMEM ; + +/* Populate speed map */ + i =0 ; +of_property_for_each_u32 (node,"gpio-fan,speed-map" , prop, p, u) { +if (i &1 ) + speed[i >>1 ].ctrl_val = (int )u; +else + speed[i >>1 ].rpm = (int )u;
Are those type casts necessary ?
Quoted 12 lines
drivers/hwmon/gpio-fan.c +12
-0+ i++; + } + pdata->speed = speed; + +/* Alarm GPIO if one exists */ +if (of_gpio_named_count (node,"alarm-gpios" )) { +struct gpio_fan_alarm *alarm; +int val; +enum of_gpio_flags flags; + + alarm =devm_kzalloc (dev,sizeof (struct gpio_fan_alarm ), +GFP_KERNEL );
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 483
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+if (!alarm) +return -ENOMEM ; + + val =of_get_named_gpio_flags (node,"alarm-gpios" ,0 , &flags); +if (val >=0 ) { + alarm->gpio = val; + alarm->active_low = flags &OF_GPIO_ACTIVE_LOW ; + }else +return -EINVAL ; +
How about
if (val < 0) return val; alarm->gpio = val; alarm->active_low = flags & OF_GPIO_ACTIVE_LOW;
Quoted 12 lines
drivers/hwmon/gpio-fan.c +12
-0+ pdata->alarm = alarm; + } + +return 0 ; +} + +static const struct of_device_id of_gpio_fan_match[] = { + { .compatible ="gpio-fan" , }, + {}, +}; +#endif /* CONFIG_OF_GPIO */ +
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 505
Quoted 10 lines
drivers/hwmon/gpio-fan.c +4
-0static int __devinit gpio_fan_probe (struct platform_device *pdev) {int err;struct gpio_fan_data *fan_data;struct gpio_fan_platform_data *pdata = pdev->dev.platform_data; +#ifdef CONFIG_OF +if (!pdata) { +struct gpio_fan_platform_data *alt_pdata; +
Why not just use pdata ? I don't really see a reason for introducing a second variable. After all, we know here that pdata is NULL, and that it won't be used.
Quoted 5 lines
drivers/hwmon/gpio-fan.c +5
-0+ alt_pdata =devm_kzalloc (&pdev->dev, +sizeof (struct gpio_fan_platform_data ), +GFP_KERNEL ); +if (!alt_pdata) +return -ENOMEM ;
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 520
Quoted 10 lines
drivers/hwmon/gpio-fan.c +8
-0+ + err =gpio_fan_get_of_pdata (&pdev->dev, alt_pdata); +if (err) +return err; + pdata = alt_pdata; + } +#endif /* CONFIG_OF_GPIO */ +if (!pdata)return -EINVAL ;
#else case, maybe ?
Quoted 13 lines
drivers/hwmon/gpio-fan.c +1
-0@@ -511,6 +621,7 @@ static struct platform_driver gpio_fan_driver = { .driver = { .name = "gpio-fan", .pm = GPIO_FAN_PM, + .of_match_table = of_match_ptr(of_gpio_fan_match), }, };Signature · 1 line
1.7.10.4
PATCH 1/2 hwmon: Add devicetree bindings to gpio-fan
In reply to Jamie LentinHi Jamie
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+static int gpio_fan_get_of_pdata (struct device *dev, +struct gpio_fan_platform_data *pdata) +{ +struct device_node *node; +struct gpio_fan_speed *speed; +unsigned *ctrl; +unsigned i; +u32 u; +struct property *prop; +const __be32 *p;
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 429
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+ + node = dev->of_node; + +/* Fill GPIO pin array */ + pdata->num_ctrl =of_gpio_count (node); + ctrl =devm_kzalloc (dev, pdata->num_ctrl *sizeof (unsigned ), +GFP_KERNEL ); +if (!ctrl) +return -ENOMEM ; +for (i =0 ; i <of_gpio_count (node); i++) {
It seems unlikely the number of gpio pins is going to change while inside this loop. So just use pdata->num_ctrl instead of counting them every iteration.
Quoted 8 lines
drivers/hwmon/gpio-fan.c +8
-0+int val; + + val =of_get_gpio (node, i); +if (val >=0 ) + ctrl[i] = val; +else +return -EINVAL ; + }
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 447
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+ pdata->ctrl = ctrl; + +/* Get speed map array size */ + i =0 ; +of_property_for_each_u32 (node,"gpio-fan,speed-map" , prop, p, u) + i++; +if (i &1 ) { +dev_err (dev,"gpio-fan,speed-map contains odd number of entries" ); +return -ENODEV ; + }
This is not so clear on the first reading. i is the number of numbers in the speed-map, and each entry needs two numbers, hence the (i & 1). Maybe a comment to explain this? Or see if there is an of_ function which returns records instead of individual properties?
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 493
Quoted 4 lines
drivers/hwmon/gpio-fan.c +4
-0+static const struct of_device_id of_gpio_fan_match[] = { + { .compatible ="gpio-fan" , }, + {}, +};
This should probably have an __devinitdata attribute.
Andrew
PATCH 2/2 ARM: kirkwood: Use devicetree to define DNS-32[05] fan
In reply to Jamie LentinRemove more board-specific code by using devicetree to define the fan attached to both boards.
--- arch/arm/boot/dts/kirkwood-dnskw.dtsi | 10 ++++++++++ arch/arm/mach-kirkwood/board-dnskw.c | 25 ------------------------- 2 files changed, 10 insertions(+), 25 deletions(-)
arch/arm/boot/dts/kirkwood-dnskw.dtsi +10 -0
@@ -25,6 +25,16 @@ }; }; + gpio_fan { + /* Fan: ADDA AD045HB-G73 40mm 6000rpm at 5v */ + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + }; + ocp at f1000000 { sata at 80000 { status = "okay";
arch/arm/mach-kirkwood/board-dnskw.c +0 -25
@@ -67,29 +67,6 @@ static unsigned int dnskw_mpp_config[] __initdata = { 0 }; -/* Fan: ADDA AD045HB-G73 40mm 6000rpm at 5v */ -static struct gpio_fan_speed dnskw_fan_speed[] = { - {0 ,0 }, - {3000 ,1 }, - {6000 ,2 }, -}; -static unsigned dnskw_fan_pins[] = {46 ,45 }; - -static struct gpio_fan_platform_data dnskw_fan_data = { - .num_ctrl =ARRAY_SIZE (dnskw_fan_pins), - .ctrl = dnskw_fan_pins, - .num_speed =ARRAY_SIZE (dnskw_fan_speed), - .speed = dnskw_fan_speed, -}; - -static struct platform_device dnskw_fan_device = { - .name ="gpio-fan" , - .id =-1 , - .dev = { - .platform_data = &dnskw_fan_data, - }, -}; -static void dnskw_power_off (void ) {gpio_set_value (36 ,1 );
@@ -114,8 +91,6 @@ void __init dnskw_init(void)kirkwood_ehci_init ();kirkwood_ge00_init (&dnskw_ge00_data); -platform_device_register (&dnskw_fan_device); -/* Register power-off GPIO. */ if (gpio_request (36 ,"dnskw:power:off" ) ==0 &&gpio_direction_output (36 ,0 ) ==0 )
Signature · 1 line
1.7.10.4
PATCH 2/2 ARM: kirkwood: Use devicetree to define DNS-32[05] fan
Quoted 46 lines
arch/arm/mach-kirkwood/board-dnskw.c +0
-25@@ -67,29 +67,6 @@ static unsigned int dnskw_mpp_config[] __initdata = { 0 }; -/* Fan: ADDA AD045HB-G73 40mm 6000rpm at 5v */ -static struct gpio_fan_speed dnskw_fan_speed[] = { - {0 ,0 }, - {3000 ,1 }, - {6000 ,2 }, -}; -static unsigned dnskw_fan_pins[] = {46 ,45 }; - -static struct gpio_fan_platform_data dnskw_fan_data = { - .num_ctrl =ARRAY_SIZE (dnskw_fan_pins), - .ctrl = dnskw_fan_pins, - .num_speed =ARRAY_SIZE (dnskw_fan_speed), - .speed = dnskw_fan_speed, -}; - -static struct platform_device dnskw_fan_device = { - .name ="gpio-fan" , - .id =-1 , - .dev = { - .platform_data = &dnskw_fan_data, - }, -}; -static void dnskw_power_off (void ) {gpio_set_value (36 ,1 );@@ -114,8 +91,6 @@ void __init dnskw_init(void)kirkwood_ehci_init ();kirkwood_ge00_init (&dnskw_ge00_data); -platform_device_register (&dnskw_fan_device); -/* Register power-off GPIO. */ if (gpio_request (36 ,"dnskw:power:off" ) ==0 &&gpio_direction_output (36 ,0 ) ==0 )Signature · 1 line
1.7.10.4
Hi Jamie
Minor point. I expect you can remove the header file gpio-fan.h.
There are also a few other headers files which can be removed, but i suggest you do this in a separate cleanup patch. I think ata_platform.h, input.h, leds.h, map.h, bridge-regs.h and maybe also kirkwood.h are no longer needed.
Andrew
v2 cover hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05]
In reply to Jamie LentinThanks to Guenter & Andrew---all the feedback made sense, and hopefully this patchset addresses everything.
This is an attempt at getting DT support into gpio-fan, in a similar fashion to gpio-leds and gpio-keys. I guess the most contentious bit is going to be the bindings.
Tested on a D-Link DNS-320.
Changes since V1:-
* Don't hide return codes [Guenter Roeck]
* Remove typecast noise [Guenter Roeck]
* Use of_find_property instead of counting u32s [Guenter Roeck]
* Don't count GPIOs twice [Andrew Lunn]
* Use of_prop_next_u32 to get records in a more obvious fashion
* Use CONFIG_OF_GPIO instead of CONFIG_OF
* Apply __devinitdata to of_gpio_fan_match [Andrew Lunn]
* Remove useless gpio-fan.h [Andrew Lunn]
Feedback appreciated!
Jamie Lentin (2):
hwmon: Add devicetree bindings to gpio-fan
ARM: kirkwood: Use devicetree to define DNS-32[05] fan
.../devicetree/bindings/gpio/gpio-fan.txt | 25 +++++ arch/arm/boot/dts/kirkwood-dnskw.dtsi | 10 ++ arch/arm/mach-kirkwood/board-dnskw.c | 26 ----- drivers/hwmon/gpio-fan.c | 116 ++++++++++++++++++++ 4 files changed, 151 insertions(+), 26 deletions(-) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txt
Signature · 1 line
1.7.10.4
PATCH v2 1/2 hwmon: Add devicetree bindings to gpio-fan
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
Changes since V1:-
* Don't hide return codes [Guenter Roeck]
* Remove typecast noise [Guenter Roeck]
* Use of_find_property instead of counting u32s [Guenter Roeck]
* Don't count GPIOs twice [Andrew Lunn]
* Use of_prop_next_u32 to get records in a more obvious fashion
* Use CONFIG_OF_GPIO instead of CONFIG_OF
* Apply __devinitdata to of_gpio_fan_match [Andrew Lunn]
--- .../devicetree/bindings/gpio/gpio-fan.txt | 25 +++++ drivers/hwmon/gpio-fan.c | 116 ++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txt
Documentation/devicetree/bindings/gpio/gpio-fan.txt new file +25 -0
@@ -0,0 +1,25 @@ +Bindings for fan connected to GPIO lines + +Required properties: +- compatible : "gpio-fan" +- gpios: Specifies the pins that map to bits in the control value, + ordered MSB-->LSB. +- gpio-fan,speed-map: A mapping of possible fan RPM speeds and the + control value that should be set to achieve them. This array + must have the RPM values in ascending order. + +Optional properties: +- alarm-gpios: This pin going active indicates something is wrong with + the fan, and a udev event will be fired. + +Examples: + + gpio_fan { + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + alarm-gpios = <&gpio1 15 1>; + };
drivers/hwmon/gpio-fan.c +116 -0
142 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v2 1/2 hwmon: Add devicetree bindings to gpio-fan
Quoted 12 lines · Jamie Lentin
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
Changes since V1:-
* Don't hide return codes [Guenter Roeck]
* Remove typecast noise [Guenter Roeck]
* Useof_find_propertyinstead of counting u32s [Guenter Roeck]
* Don't count GPIOs twice [Andrew Lunn]
* Useof_prop_next_u32to get records in a more obvious fashion
* UseCONFIG_OF_GPIOinstead ofCONFIG_OF
* Apply__devinitdatatoof_gpio_fan_match[Andrew Lunn]
Quoted 6 lines
Signed-off-by Jamie Lentin <[email protected]>--- .../devicetree/bindings/gpio/gpio-fan.txt | 25 +++++ drivers/hwmon/gpio-fan.c | 116 ++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txt
Hi Jamie
Thanks for addressing all the issues raised. However...
Anything before the --- ends up in the changelog entry. Anything afterwards does not.
The changes you made to address review comments is not something for the changelog, so Changes since V1:- should be after the --- .
There is more detail in Documentation/SubmittingPatches
Andrew
PATCH v2 1/2 hwmon: Add devicetree bindings to gpio-fan
Quoted 22 lines · Andrew Lunn
Quoted 12 lines · Jamie Lentin
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
Changes since V1:-
* Don't hide return codes [Guenter Roeck]
* Remove typecast noise [Guenter Roeck]
* Useof_find_propertyinstead of counting u32s [Guenter Roeck]
* Don't count GPIOs twice [Andrew Lunn]
* Useof_prop_next_u32to get records in a more obvious fashion
* UseCONFIG_OF_GPIOinstead ofCONFIG_OF
* Apply__devinitdatatoof_gpio_fan_match[Andrew Lunn]Quoted 6 lines
Signed-off-by Jamie Lentin <[email protected]>--- .../devicetree/bindings/gpio/gpio-fan.txt | 25 +++++ drivers/hwmon/gpio-fan.c | 116 ++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txtHi Jamie
Quoted 7 lines
Thanks for addressing all the issues raised. However...
Anything before the --- ends up in the changelog entry. Anything afterwards does not.
The changes you made to address review comments is not something for the changelog, so Changes since V1:- should be after the --- .
Okay, whilst I was submitting the initial DT support it was suggested by Grant Likely they should be above the '---'. I think I prefer this also, but I'll go with whatever is more likely to get patches accepted :)
Can resend with the content jiggled if you want, but will put them after the '---' in future.
Quoted 5 lines
There is more detail in
Documentation/SubmittingPatchesAndrew
Signature · 1 line
Jamie Lentin
PATCH v2 1/2 hwmon: Add devicetree bindings to gpio-fan
Quoted 32 lines · Jamie Lentin
Quoted 22 lines · Andrew Lunn
Quoted 12 lines · Jamie Lentin
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
Changes since V1:-
* Don't hide return codes [Guenter Roeck]
* Remove typecast noise [Guenter Roeck]
* Useof_find_propertyinstead of counting u32s [Guenter Roeck]
* Don't count GPIOs twice [Andrew Lunn]
* Useof_prop_next_u32to get records in a more obvious fashion
* UseCONFIG_OF_GPIOinstead ofCONFIG_OF
* Apply__devinitdatatoof_gpio_fan_match[Andrew Lunn]Quoted 6 lines
Signed-off-by Jamie Lentin <[email protected]>---
.../devicetree/bindings/gpio/gpio-fan.txt| 25 +++++drivers/hwmon/gpio-fan.c| 116 ++++++++++++++++++++2 files changed, 141 insertions(+)create mode 100644
Documentation/devicetree/bindings/gpio/gpio-fan.txtHi Jamie
Quoted 7 lines
Thanks for addressing all the issues raised. However...
Anything before the --- ends up in the changelog entry. Anything afterwards does not.
The changes you made to address review comments is not something for the changelog, so Changes since V1:- should be after the --- .
Quoted 7 lines
Okay, whilst I was submitting the initial DT support it was suggested by Grant Likely they should be above the '---'. I think I prefer this also, but I'll go with whatever is more likely to get patches accepted :)
Can resend with the content jiggled if you want, but will put them after the '---' in future.
There's no need to resend if this is the only issue. I'll just clean it up when I pull it in. In the future, though, please do as Andrew suggested.
thx,
Jason.
Guenter Roeck
maintainerPATCH v2 1/2 hwmon: Add devicetree bindings to gpio-fan
In reply to Jamie LentinQuoted 12 lines · Jamie Lentin
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
Changes since V1:-
* Don't hide return codes [Guenter Roeck]
* Remove typecast noise [Guenter Roeck]
* Useof_find_propertyinstead of counting u32s [Guenter Roeck]
* Don't count GPIOs twice [Andrew Lunn]
* Useof_prop_next_u32to get records in a more obvious fashion
* UseCONFIG_OF_GPIOinstead ofCONFIG_OF
* Apply__devinitdatatoof_gpio_fan_match[Andrew Lunn]
Jamie,
As suggested by others, after ---, please
Quoted 55 lines
Signed-off-by Jamie Lentin <[email protected]>--- .../devicetree/bindings/gpio/gpio-fan.txt | 25 +++++ drivers/hwmon/gpio-fan.c | 116 ++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txtDocumentation/devicetree/bindings/gpio/gpio-fan.txt new file +25
-0@@ -0,0 +1,25 @@ +Bindings for fan connected to GPIO lines + +Required properties: +- compatible : "gpio-fan" +- gpios: Specifies the pins that map to bits in the control value, + ordered MSB-->LSB. +- gpio-fan,speed-map: A mapping of possible fan RPM speeds and the + control value that should be set to achieve them. This array + must have the RPM values in ascending order. + +Optional properties: +- alarm-gpios: This pin going active indicates something is wrong with + the fan, and a udev event will be fired. + +Examples: + + gpio_fan { + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + alarm-gpios = <&gpio1 15 1>; + };drivers/hwmon/gpio-fan.c +2
-0@@ -31,6 +31,8 @@#include <linux/hwmon.h> #include <linux/gpio.h> #include <linux/gpio-fan.h> +#include <linux/of_platform.h> +#include <linux/of_gpio.h> struct gpio_fan_data {struct platform_device *pdev;@@ -400,14 +402,127 @@ static ssize_t show_name(struct device *dev, static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 414
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+ +#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 device_node *node; +struct gpio_fan_speed *speed;
s/ / /
drivers/hwmon/gpio-fan.c static ssize_t show_name(struct device *dev, · line 424
Quoted 10 lines
drivers/hwmon/gpio-fan.c +10
-0+unsigned *ctrl; +unsigned i; +u32 u; +struct property *prop; +const __be32 *p; + + node = dev->of_node; + +/* Fill GPIO pin array */ + pdata->num_ctrl =of_gpio_count (node);
All other callers of this function check if the result is > 0.
Thanks,
Guenter
PATCH v3 1/2 hwmon: Add devicetree bindings to gpio-fan
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
---
Changes since V2:-
* Correct error message terminology
* Check of_gpio_count returns some GPIOs [Guenter Roeck]
* Whitespace fix [Guenter Roeck]
Changes since V1:-
* Don't hide return codes [Guenter Roeck]
* Remove typecast noise [Guenter Roeck]
* Use of_find_property instead of counting u32s [Guenter Roeck]
* Don't count GPIOs twice [Andrew Lunn]
* Use of_prop_next_u32 to get records in a more obvious fashion
* Use CONFIG_OF_GPIO instead of CONFIG_OF
* Apply __devinitdata to of_gpio_fan_match [Andrew Lunn]
--- .../devicetree/bindings/gpio/gpio-fan.txt | 25 ++++ drivers/hwmon/gpio-fan.c | 120 ++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-fan.txt
Documentation/devicetree/bindings/gpio/gpio-fan.txt new file +25 -0
@@ -0,0 +1,25 @@ +Bindings for fan connected to GPIO lines + +Required properties: +- compatible : "gpio-fan" +- gpios: Specifies the pins that map to bits in the control value, + ordered MSB-->LSB. +- gpio-fan,speed-map: A mapping of possible fan RPM speeds and the + control value that should be set to achieve them. This array + must have the RPM values in ascending order. + +Optional properties: +- alarm-gpios: This pin going active indicates something is wrong with + the fan, and a udev event will be fired. + +Examples: + + gpio_fan { + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + alarm-gpios = <&gpio1 15 1>; + };
drivers/hwmon/gpio-fan.c +120 -0
146 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Guenter Roeck
maintainerPATCH v3 1/2 hwmon: Add devicetree bindings to gpio-fan
Quoted 5 lines · Jamie Lentin
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
Signed-off-by Jamie Lentin <[email protected]>Acked-by Andrew Lunn <[email protected]>
I take it this will go through the arm tree ?
Guenter
PATCH v3 1/2 hwmon: Add devicetree bindings to gpio-fan
Quoted 10 lines · Guenter Roeck
Quoted 5 lines · Jamie Lentin
Allow a gpio-fan to be defined in devicetree, see binding documentation for details.
Signed-off-by Jamie Lentin <[email protected]>Acked-by Andrew Lunn <[email protected]>Acked-by Guenter Roeck <[email protected]>I take it this will go through the arm tree ?
Yes, unless there is an objection.
thx,
Jason.
PATCH v2 2/2 ARM: kirkwood: Use devicetree to define DNS-32[05] fan
In reply to Jamie LentinRemove more board-specific code by using devicetree to define the fan attached to both boards.
Changes since V1:-
* Remove now-useless gpio-fan.h [Andrew Lunn]
--- arch/arm/boot/dts/kirkwood-dnskw.dtsi | 10 ++++++++++ arch/arm/mach-kirkwood/board-dnskw.c | 26 -------------------------- 2 files changed, 10 insertions(+), 26 deletions(-)
arch/arm/boot/dts/kirkwood-dnskw.dtsi +10 -0
@@ -25,6 +25,16 @@ }; }; + gpio_fan { + /* Fan: ADDA AD045HB-G73 40mm 6000rpm at 5v */ + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + }; + ocp at f1000000 { sata at 80000 { status = "okay";
arch/arm/mach-kirkwood/board-dnskw.c +0 -26
@@ -19,7 +19,6 @@#include <linux/of.h> #include <linux/gpio.h> #include <linux/input.h> -#include <linux/gpio-fan.h> #include <linux/leds.h> #include <asm/mach-types.h> #include <asm/mach/arch.h>
@@ -67,29 +66,6 @@ static unsigned int dnskw_mpp_config[] __initdata = { 0 }; -/* Fan: ADDA AD045HB-G73 40mm 6000rpm at 5v */ -static struct gpio_fan_speed dnskw_fan_speed[] = { - {0 ,0 }, - {3000 ,1 }, - {6000 ,2 }, -}; -static unsigned dnskw_fan_pins[] = {46 ,45 }; - -static struct gpio_fan_platform_data dnskw_fan_data = { - .num_ctrl =ARRAY_SIZE (dnskw_fan_pins), - .ctrl = dnskw_fan_pins, - .num_speed =ARRAY_SIZE (dnskw_fan_speed), - .speed = dnskw_fan_speed, -}; - -static struct platform_device dnskw_fan_device = { - .name ="gpio-fan" , - .id =-1 , - .dev = { - .platform_data = &dnskw_fan_data, - }, -}; -static void dnskw_power_off (void ) {gpio_set_value (36 ,1 );
@@ -114,8 +90,6 @@ void __init dnskw_init(void)kirkwood_ehci_init ();kirkwood_ge00_init (&dnskw_ge00_data); -platform_device_register (&dnskw_fan_device); -/* Register power-off GPIO. */ if (gpio_request (36 ,"dnskw:power:off" ) ==0 &&gpio_direction_output (36 ,0 ) ==0 )
Signature · 1 line
1.7.10.4