* [PATCH 0/2] hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05] @ 2012-09-07 16:34 Jamie Lentin 2012-09-07 16:34 ` [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin ` (2 more replies) 0 siblings, 3 replies; 16+ messages in thread From: Jamie Lentin @ 2012-09-07 16:34 UTC (permalink / raw) To: Grant Likely, Rob Herring, Jean Delvare, Guenter Roeck, Jason Cooper, Andrew Lunn Cc: devicetree-discuss, Jamie Lentin, linux-arm-kernel 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 -- 1.7.10.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan 2012-09-07 16:34 [PATCH 0/2] hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05] Jamie Lentin @ 2012-09-07 16:34 ` Jamie Lentin 2012-09-07 18:36 ` Guenter Roeck [not found] ` <1347035675-23907-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2012-09-07 16:34 ` [PATCH 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan Jamie Lentin [not found] ` <1347035675-23907-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2 siblings, 2 replies; 16+ messages in thread From: Jamie Lentin @ 2012-09-07 16:34 UTC (permalink / raw) To: Grant Likely, Rob Herring, Jean Delvare, Guenter Roeck, Jason Cooper, Andrew Lunn Cc: devicetree-discuss, Jamie Lentin, linux-arm-kernel Allow a gpio-fan to be defined in devicetree, see binding documentation for details. Signed-off-by: Jamie Lentin <jm@lentin.co.uk> --- .../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 diff --git a/Documentation/devicetree/bindings/gpio/gpio-fan.txt b/Documentation/devicetree/bindings/gpio/gpio-fan.txt new file mode 100644 index 0000000..2dd457a --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-fan.txt @@ -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>; + }; diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 2f4b01b..876ce41 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -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); + 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; + } + 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; + } + pdata->num_speed = i >> 1; + speed = devm_kzalloc(dev, + pdata->num_speed * sizeof(struct gpio_fan_speed), + GFP_KERNEL); + 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; + 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); + 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; + + pdata->alarm = alarm; + } + + return 0; +} + +static const struct of_device_id of_gpio_fan_match[] = { + { .compatible = "gpio-fan", }, + {}, +}; +#endif /* CONFIG_OF_GPIO */ + static 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; + + alt_pdata = devm_kzalloc(&pdev->dev, + sizeof(struct gpio_fan_platform_data), + GFP_KERNEL); + if (!alt_pdata) + return -ENOMEM; + + 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; @@ -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), }, }; -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan 2012-09-07 16:34 ` [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin @ 2012-09-07 18:36 ` Guenter Roeck [not found] ` <1347035675-23907-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 1 sibling, 0 replies; 16+ messages in thread From: Guenter Roeck @ 2012-09-07 18:36 UTC (permalink / raw) To: Jamie Lentin Cc: Andrew Lunn, Jason Cooper, devicetree-discuss, Rob Herring, Grant Likely, Jean Delvare, linux-arm-kernel On Fri, Sep 07, 2012 at 05:34:34PM +0100, Jamie Lentin wrote: > Allow a gpio-fan to be defined in devicetree, see binding documentation > for details. > > Signed-off-by: Jamie Lentin <jm@lentin.co.uk> > --- > .../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 > > diff --git a/Documentation/devicetree/bindings/gpio/gpio-fan.txt b/Documentation/devicetree/bindings/gpio/gpio-fan.txt > new file mode 100644 > index 0000000..2dd457a > --- /dev/null > +++ b/Documentation/devicetree/bindings/gpio/gpio-fan.txt > @@ -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>; > + }; > diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c > index 2f4b01b..876ce41 100644 > --- a/drivers/hwmon/gpio-fan.c > +++ b/drivers/hwmon/gpio-fan.c > @@ -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); > + 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; > + } > + 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); > + if (i & 1) { > + dev_err(dev, "gpio-fan,speed-map contains odd number of entries"); > + return -ENODEV; > + } How about i == 0 ? > + pdata->num_speed = i >> 1; > + speed = devm_kzalloc(dev, > + pdata->num_speed * sizeof(struct gpio_fan_speed), > + GFP_KERNEL); > + 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 ? > + 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); > + 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; > + pdata->alarm = alarm; > + } > + > + return 0; > +} > + > +static const struct of_device_id of_gpio_fan_match[] = { > + { .compatible = "gpio-fan", }, > + {}, > +}; > +#endif /* CONFIG_OF_GPIO */ > + > static 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. > + alt_pdata = devm_kzalloc(&pdev->dev, > + sizeof(struct gpio_fan_platform_data), > + GFP_KERNEL); > + if (!alt_pdata) > + return -ENOMEM; > + > + 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 ? > > @@ -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), > }, > }; > > -- > 1.7.10.4 > > ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <1347035675-23907-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>]
* Re: [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan [not found] ` <1347035675-23907-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> @ 2012-09-08 7:32 ` Andrew Lunn 0 siblings, 0 replies; 16+ messages in thread From: Andrew Lunn @ 2012-09-08 7:32 UTC (permalink / raw) To: Jamie Lentin Cc: Andrew Lunn, Jason Cooper, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Rob Herring, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jean Delvare, Guenter Roeck Hi Jamie > +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); > + 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. > + int val; > + > + val = of_get_gpio(node, i); > + if (val >= 0) > + ctrl[i] = val; > + else > + return -EINVAL; > + } > + 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? > +static const struct of_device_id of_gpio_fan_match[] = { > + { .compatible = "gpio-fan", }, > + {}, > +}; This should probably have an __devinitdata attribute. Andrew ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan 2012-09-07 16:34 [PATCH 0/2] hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05] Jamie Lentin 2012-09-07 16:34 ` [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin @ 2012-09-07 16:34 ` Jamie Lentin [not found] ` <1347035675-23907-3-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> [not found] ` <1347035675-23907-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2 siblings, 1 reply; 16+ messages in thread From: Jamie Lentin @ 2012-09-07 16:34 UTC (permalink / raw) To: Grant Likely, Rob Herring, Jean Delvare, Guenter Roeck, Jason Cooper, Andrew Lunn Cc: devicetree-discuss, Jamie Lentin, linux-arm-kernel Remove more board-specific code by using devicetree to define the fan attached to both boards. Signed-off-by: Jamie Lentin <jm@lentin.co.uk> --- arch/arm/boot/dts/kirkwood-dnskw.dtsi | 10 ++++++++++ arch/arm/mach-kirkwood/board-dnskw.c | 25 ------------------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/arch/arm/boot/dts/kirkwood-dnskw.dtsi b/arch/arm/boot/dts/kirkwood-dnskw.dtsi index 7408655..9b32d02 100644 --- a/arch/arm/boot/dts/kirkwood-dnskw.dtsi +++ b/arch/arm/boot/dts/kirkwood-dnskw.dtsi @@ -25,6 +25,16 @@ }; }; + gpio_fan { + /* Fan: ADDA AD045HB-G73 40mm 6000rpm@5v */ + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + }; + ocp@f1000000 { sata@80000 { status = "okay"; diff --git a/arch/arm/mach-kirkwood/board-dnskw.c b/arch/arm/mach-kirkwood/board-dnskw.c index 4ab3506..e202a07 100644 --- a/arch/arm/mach-kirkwood/board-dnskw.c +++ b/arch/arm/mach-kirkwood/board-dnskw.c @@ -67,29 +67,6 @@ static unsigned int dnskw_mpp_config[] __initdata = { 0 }; -/* Fan: ADDA AD045HB-G73 40mm 6000rpm@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) -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
[parent not found: <1347035675-23907-3-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>]
* Re: [PATCH 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan [not found] ` <1347035675-23907-3-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> @ 2012-09-07 21:23 ` Andrew Lunn 0 siblings, 0 replies; 16+ messages in thread From: Andrew Lunn @ 2012-09-07 21:23 UTC (permalink / raw) To: Jamie Lentin Cc: Andrew Lunn, Jason Cooper, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Rob Herring, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jean Delvare, Guenter Roeck > diff --git a/arch/arm/mach-kirkwood/board-dnskw.c b/arch/arm/mach-kirkwood/board-dnskw.c > index 4ab3506..e202a07 100644 > --- a/arch/arm/mach-kirkwood/board-dnskw.c > +++ b/arch/arm/mach-kirkwood/board-dnskw.c > @@ -67,29 +67,6 @@ static unsigned int dnskw_mpp_config[] __initdata = { > 0 > }; > > -/* Fan: ADDA AD045HB-G73 40mm 6000rpm@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) > -- > 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 ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <1347035675-23907-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>]
* [PATCH V2 0/2] hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05] [not found] ` <1347035675-23907-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> @ 2012-09-10 13:51 ` Jamie Lentin [not found] ` <1347285112-13542-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 0 siblings, 1 reply; 16+ messages in thread From: Jamie Lentin @ 2012-09-10 13:51 UTC (permalink / raw) To: Grant Likely, Rob Herring, Jean Delvare, Guenter Roeck, Jason Cooper, Andrew Lunn Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Jamie Lentin, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r Thanks 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 -- 1.7.10.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <1347285112-13542-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>]
* [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan [not found] ` <1347285112-13542-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> @ 2012-09-10 13:51 ` Jamie Lentin [not found] ` <1347285112-13542-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2012-09-10 18:49 ` Guenter Roeck 2012-09-10 13:51 ` [PATCH V2 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan Jamie Lentin 1 sibling, 2 replies; 16+ messages in thread From: Jamie Lentin @ 2012-09-10 13:51 UTC (permalink / raw) To: Grant Likely, Rob Herring, Jean Delvare, Guenter Roeck, Jason Cooper, Andrew Lunn Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Jamie Lentin, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r 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] Signed-off-by: Jamie Lentin <jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> --- .../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 diff --git a/Documentation/devicetree/bindings/gpio/gpio-fan.txt b/Documentation/devicetree/bindings/gpio/gpio-fan.txt new file mode 100644 index 0000000..2dd457a --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-fan.txt @@ -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>; + }; diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 2f4b01b..f0a803b 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -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); + +#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; + 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); + if (!ctrl) + return -ENOMEM; + for (i = 0; i < pdata->num_ctrl; i++) { + int val; + + val = of_get_gpio(node, i); + if (val < 0) + return val; + ctrl[i] = val; + } + pdata->ctrl = ctrl; + + /* Get number of RPM/ctrl_val pairs in speed map */ + prop = of_find_property(node, "gpio-fan,speed-map", &i); + if (!prop) { + dev_err(dev, "gpio-fan,speed-map node missing from DT"); + return -ENODEV; + } + i = i / sizeof(u32); + if (i == 0 || i & 1) { + dev_err(dev, "gpio-fan,speed-map contains zero/odd number of entries"); + return -ENODEV; + } + pdata->num_speed = i / 2; + + /* + * Populate speed map + * Speed map is in the form <RPM ctrl_val RPM ctrl_val ...> + * this needs splitting into pairs to create gpio_fan_speed structs + */ + speed = devm_kzalloc(dev, + pdata->num_speed * sizeof(struct gpio_fan_speed), + GFP_KERNEL); + if (!speed) + return -ENOMEM; + p = NULL; + for (i = 0; i < pdata->num_speed; i++) { + p = of_prop_next_u32(prop, p, &u); + if (!p) + return -ENODEV; + speed[i].rpm = u; + p = of_prop_next_u32(prop, p, &u); + if (!p) + return -ENODEV; + speed[i].ctrl_val = u; + } + 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); + if (!alarm) + return -ENOMEM; + + val = of_get_named_gpio_flags(node, "alarm-gpios", 0, &flags); + if (val < 0) + return val; + alarm->gpio = val; + alarm->active_low = flags & OF_GPIO_ACTIVE_LOW; + + pdata->alarm = alarm; + } + + return 0; +} + +static struct of_device_id of_gpio_fan_match[] __devinitdata = { + { .compatible = "gpio-fan", }, + {}, +}; +#endif /* CONFIG_OF_GPIO */ + static 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_GPIO + if (!pdata) { + pdata = devm_kzalloc(&pdev->dev, + sizeof(struct gpio_fan_platform_data), + GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + err = gpio_fan_get_of_pdata(&pdev->dev, pdata); + if (err) + return err; + } +#else /* CONFIG_OF_GPIO */ if (!pdata) return -EINVAL; +#endif /* CONFIG_OF_GPIO */ fan_data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_fan_data), GFP_KERNEL); @@ -511,6 +626,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), }, }; -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
[parent not found: <1347285112-13542-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>]
* Re: [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan [not found] ` <1347285112-13542-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> @ 2012-09-10 15:28 ` Andrew Lunn [not found] ` <20120910152814.GA6050-g2DYL2Zd6BY@public.gmane.org> 0 siblings, 1 reply; 16+ messages in thread From: Andrew Lunn @ 2012-09-10 15:28 UTC (permalink / raw) To: Jamie Lentin Cc: Andrew Lunn, Jason Cooper, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Rob Herring, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jean Delvare, Guenter Roeck On Mon, Sep 10, 2012 at 02:51:51PM +0100, Jamie Lentin wrote: > 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] > > Signed-off-by: Jamie Lentin <jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> > --- > .../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 ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <20120910152814.GA6050-g2DYL2Zd6BY@public.gmane.org>]
* Re: [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan [not found] ` <20120910152814.GA6050-g2DYL2Zd6BY@public.gmane.org> @ 2012-09-10 16:04 ` Jamie Lentin [not found] ` <alpine.DEB.2.00.1209101656120.10589-5X291BYdrx55rAo4AelP/Ydd74u8MsAO@public.gmane.org> 0 siblings, 1 reply; 16+ messages in thread From: Jamie Lentin @ 2012-09-10 16:04 UTC (permalink / raw) To: Andrew Lunn Cc: Jason Cooper, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Rob Herring, Guenter Roeck, Jean Delvare, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r On Mon, 10 Sep 2012, Andrew Lunn wrote: > On Mon, Sep 10, 2012 at 02:51:51PM +0100, Jamie Lentin wrote: >> 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] >> >> Signed-off-by: Jamie Lentin <jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> >> --- >> .../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 --- . 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 is more detail in Documentation/SubmittingPatches > > Andrew > -- Jamie Lentin ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <alpine.DEB.2.00.1209101656120.10589-5X291BYdrx55rAo4AelP/Ydd74u8MsAO@public.gmane.org>]
* Re: [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan [not found] ` <alpine.DEB.2.00.1209101656120.10589-5X291BYdrx55rAo4AelP/Ydd74u8MsAO@public.gmane.org> @ 2012-09-10 18:15 ` Jason Cooper 0 siblings, 0 replies; 16+ messages in thread From: Jason Cooper @ 2012-09-10 18:15 UTC (permalink / raw) To: Jamie Lentin Cc: Andrew Lunn, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Rob Herring, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jean Delvare, Guenter Roeck On Mon, Sep 10, 2012 at 05:04:26PM +0100, Jamie Lentin wrote: > On Mon, 10 Sep 2012, Andrew Lunn wrote: > > >On Mon, Sep 10, 2012 at 02:51:51PM +0100, Jamie Lentin wrote: > >>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] > >> > >>Signed-off-by: Jamie Lentin <jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> > >>--- > >> .../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 --- . > > 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. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan 2012-09-10 13:51 ` [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin [not found] ` <1347285112-13542-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> @ 2012-09-10 18:49 ` Guenter Roeck [not found] ` <20120910184919.GA30872-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> 1 sibling, 1 reply; 16+ messages in thread From: Guenter Roeck @ 2012-09-10 18:49 UTC (permalink / raw) To: Jamie Lentin Cc: Andrew Lunn, Jason Cooper, devicetree-discuss, Rob Herring, Grant Likely, Jean Delvare, linux-arm-kernel On Mon, Sep 10, 2012 at 02:51:51PM +0100, Jamie Lentin wrote: > 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] > Jamie, As suggested by others, after ---, please > Signed-off-by: Jamie Lentin <jm@lentin.co.uk> > --- > .../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 > > diff --git a/Documentation/devicetree/bindings/gpio/gpio-fan.txt b/Documentation/devicetree/bindings/gpio/gpio-fan.txt > new file mode 100644 > index 0000000..2dd457a > --- /dev/null > +++ b/Documentation/devicetree/bindings/gpio/gpio-fan.txt > @@ -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>; > + }; > diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c > index 2f4b01b..f0a803b 100644 > --- a/drivers/hwmon/gpio-fan.c > +++ b/drivers/hwmon/gpio-fan.c > @@ -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); > > + > +#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/ / / > + 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 ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <20120910184919.GA30872-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>]
* [PATCH V3 1/2] hwmon: Add devicetree bindings to gpio-fan [not found] ` <20120910184919.GA30872-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> @ 2012-09-14 16:07 ` Jamie Lentin 2012-09-15 2:28 ` Guenter Roeck 0 siblings, 1 reply; 16+ messages in thread From: Jamie Lentin @ 2012-09-14 16:07 UTC (permalink / raw) To: Grant Likely, Rob Herring, Jean Delvare, Guenter Roeck, Jason Cooper, Andrew Lunn Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Jamie Lentin, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r Allow a gpio-fan to be defined in devicetree, see binding documentation for details. Signed-off-by: Jamie Lentin <jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> Acked-by: Andrew Lunn <andrew-g2DYL2Zd6BY@public.gmane.org> --- 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 diff --git a/Documentation/devicetree/bindings/gpio/gpio-fan.txt b/Documentation/devicetree/bindings/gpio/gpio-fan.txt new file mode 100644 index 0000000..2dd457a --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-fan.txt @@ -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>; + }; diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 2f4b01b..36509ae 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -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,131 @@ static ssize_t show_name(struct device *dev, static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); + +#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; + 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); + if (!pdata->num_ctrl) { + dev_err(dev, "gpios DT property empty / missing"); + return -ENODEV; + } + ctrl = devm_kzalloc(dev, pdata->num_ctrl * sizeof(unsigned), + GFP_KERNEL); + if (!ctrl) + return -ENOMEM; + for (i = 0; i < pdata->num_ctrl; i++) { + int val; + + val = of_get_gpio(node, i); + if (val < 0) + return val; + ctrl[i] = val; + } + pdata->ctrl = ctrl; + + /* Get number of RPM/ctrl_val pairs in speed map */ + prop = of_find_property(node, "gpio-fan,speed-map", &i); + if (!prop) { + dev_err(dev, "gpio-fan,speed-map DT property missing"); + return -ENODEV; + } + i = i / sizeof(u32); + if (i == 0 || i & 1) { + dev_err(dev, "gpio-fan,speed-map contains zero/odd number of entries"); + return -ENODEV; + } + pdata->num_speed = i / 2; + + /* + * Populate speed map + * Speed map is in the form <RPM ctrl_val RPM ctrl_val ...> + * this needs splitting into pairs to create gpio_fan_speed structs + */ + speed = devm_kzalloc(dev, + pdata->num_speed * sizeof(struct gpio_fan_speed), + GFP_KERNEL); + if (!speed) + return -ENOMEM; + p = NULL; + for (i = 0; i < pdata->num_speed; i++) { + p = of_prop_next_u32(prop, p, &u); + if (!p) + return -ENODEV; + speed[i].rpm = u; + p = of_prop_next_u32(prop, p, &u); + if (!p) + return -ENODEV; + speed[i].ctrl_val = u; + } + 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); + if (!alarm) + return -ENOMEM; + + val = of_get_named_gpio_flags(node, "alarm-gpios", 0, &flags); + if (val < 0) + return val; + alarm->gpio = val; + alarm->active_low = flags & OF_GPIO_ACTIVE_LOW; + + pdata->alarm = alarm; + } + + return 0; +} + +static struct of_device_id of_gpio_fan_match[] __devinitdata = { + { .compatible = "gpio-fan", }, + {}, +}; +#endif /* CONFIG_OF_GPIO */ + static 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_GPIO + if (!pdata) { + pdata = devm_kzalloc(&pdev->dev, + sizeof(struct gpio_fan_platform_data), + GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + err = gpio_fan_get_of_pdata(&pdev->dev, pdata); + if (err) + return err; + } +#else /* CONFIG_OF_GPIO */ if (!pdata) return -EINVAL; +#endif /* CONFIG_OF_GPIO */ fan_data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_fan_data), GFP_KERNEL); @@ -511,6 +630,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), }, }; -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH V3 1/2] hwmon: Add devicetree bindings to gpio-fan 2012-09-14 16:07 ` [PATCH V3 " Jamie Lentin @ 2012-09-15 2:28 ` Guenter Roeck [not found] ` <20120915022833.GA20375-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> 0 siblings, 1 reply; 16+ messages in thread From: Guenter Roeck @ 2012-09-15 2:28 UTC (permalink / raw) To: Jamie Lentin Cc: Andrew Lunn, Jason Cooper, devicetree-discuss, Rob Herring, Grant Likely, Jean Delvare, linux-arm-kernel On Fri, Sep 14, 2012 at 05:07:06PM +0100, Jamie Lentin wrote: > Allow a gpio-fan to be defined in devicetree, see binding documentation > for details. > > Signed-off-by: Jamie Lentin <jm@lentin.co.uk> > Acked-by: Andrew Lunn <andrew@lunn.ch> Acked-by: Guenter Roeck <linux@roeck-us.net> I take it this will go through the arm tree ? Guenter ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <20120915022833.GA20375-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>]
* Re: [PATCH V3 1/2] hwmon: Add devicetree bindings to gpio-fan [not found] ` <20120915022833.GA20375-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> @ 2012-09-15 3:16 ` Jason Cooper 0 siblings, 0 replies; 16+ messages in thread From: Jason Cooper @ 2012-09-15 3:16 UTC (permalink / raw) To: Guenter Roeck Cc: Andrew Lunn, Jamie Lentin, Rob Herring, Jean Delvare, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r On Fri, Sep 14, 2012 at 07:28:33PM -0700, Guenter Roeck wrote: > On Fri, Sep 14, 2012 at 05:07:06PM +0100, Jamie Lentin wrote: > > Allow a gpio-fan to be defined in devicetree, see binding documentation > > for details. > > > > Signed-off-by: Jamie Lentin <jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> > > Acked-by: Andrew Lunn <andrew-g2DYL2Zd6BY@public.gmane.org> > > Acked-by: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> > > I take it this will go through the arm tree ? Yes, unless there is an objection. thx, Jason. ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH V2 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan [not found] ` <1347285112-13542-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2012-09-10 13:51 ` [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin @ 2012-09-10 13:51 ` Jamie Lentin 1 sibling, 0 replies; 16+ messages in thread From: Jamie Lentin @ 2012-09-10 13:51 UTC (permalink / raw) To: Grant Likely, Rob Herring, Jean Delvare, Guenter Roeck, Jason Cooper, Andrew Lunn Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Jamie Lentin, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r Remove 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] Signed-off-by: Jamie Lentin <jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> --- arch/arm/boot/dts/kirkwood-dnskw.dtsi | 10 ++++++++++ arch/arm/mach-kirkwood/board-dnskw.c | 26 -------------------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/arch/arm/boot/dts/kirkwood-dnskw.dtsi b/arch/arm/boot/dts/kirkwood-dnskw.dtsi index 7408655..9b32d02 100644 --- a/arch/arm/boot/dts/kirkwood-dnskw.dtsi +++ b/arch/arm/boot/dts/kirkwood-dnskw.dtsi @@ -25,6 +25,16 @@ }; }; + gpio_fan { + /* Fan: ADDA AD045HB-G73 40mm 6000rpm@5v */ + compatible = "gpio-fan"; + gpios = <&gpio1 14 1 + &gpio1 13 1>; + gpio-fan,speed-map = <0 0 + 3000 1 + 6000 2>; + }; + ocp@f1000000 { sata@80000 { status = "okay"; diff --git a/arch/arm/mach-kirkwood/board-dnskw.c b/arch/arm/mach-kirkwood/board-dnskw.c index 4ab3506..6ac7a8d 100644 --- a/arch/arm/mach-kirkwood/board-dnskw.c +++ b/arch/arm/mach-kirkwood/board-dnskw.c @@ -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@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) -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
end of thread, other threads:[~2012-09-15 3:16 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-09-07 16:34 [PATCH 0/2] hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05] Jamie Lentin 2012-09-07 16:34 ` [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin 2012-09-07 18:36 ` Guenter Roeck [not found] ` <1347035675-23907-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2012-09-08 7:32 ` Andrew Lunn 2012-09-07 16:34 ` [PATCH 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan Jamie Lentin [not found] ` <1347035675-23907-3-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2012-09-07 21:23 ` Andrew Lunn [not found] ` <1347035675-23907-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2012-09-10 13:51 ` [PATCH V2 0/2] hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05] Jamie Lentin [not found] ` <1347285112-13542-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2012-09-10 13:51 ` [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin [not found] ` <1347285112-13542-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org> 2012-09-10 15:28 ` Andrew Lunn [not found] ` <20120910152814.GA6050-g2DYL2Zd6BY@public.gmane.org> 2012-09-10 16:04 ` Jamie Lentin [not found] ` <alpine.DEB.2.00.1209101656120.10589-5X291BYdrx55rAo4AelP/Ydd74u8MsAO@public.gmane.org> 2012-09-10 18:15 ` Jason Cooper 2012-09-10 18:49 ` Guenter Roeck [not found] ` <20120910184919.GA30872-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> 2012-09-14 16:07 ` [PATCH V3 " Jamie Lentin 2012-09-15 2:28 ` Guenter Roeck [not found] ` <20120915022833.GA20375-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> 2012-09-15 3:16 ` Jason Cooper 2012-09-10 13:51 ` [PATCH V2 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan Jamie Lentin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).