aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Guinot <simon.guinot@sequanux.org>2015-02-25 12:58:19 -0500
committerGuenter Roeck <linux@roeck-us.net>2015-03-09 12:59:36 -0400
commit73ef85f42da2df8b567fea109c67ed53db937bcc (patch)
tree0b72ae38e8aeb5d432827e753b690438bae1244d
parent6552f327cab8eb6c773ba4f702cf6a371d1dc467 (diff)
hwmon: (gpio-fan) allow to use alarm support alone from DT
On some boards, such as the LaCie 2Big Network v2 or 2Big NAS (based on Marvell Kirkwood SoCs), an I2C fan controller is used but the alarm signal is wired to a separate GPIO. Unfortunately, the gpio-fan driver can't be used to handle GPIO alarm alone from DT: an error is returned if the "gpios" DT property is missing. This patch allows to use the gpio-fan driver even if the "alarm-gpios" DT property is defined alone. Signed-off-by: Simon Guinot <simon.guinot@sequanux.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--Documentation/devicetree/bindings/gpio/gpio-fan.txt6
-rw-r--r--drivers/hwmon/gpio-fan.c44
2 files changed, 27 insertions, 23 deletions
diff --git a/Documentation/devicetree/bindings/gpio/gpio-fan.txt b/Documentation/devicetree/bindings/gpio/gpio-fan.txt
index 2dd457a3469a..f996d428f132 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-fan.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio-fan.txt
@@ -2,16 +2,18 @@ Bindings for fan connected to GPIO lines
2 2
3Required properties: 3Required properties:
4- compatible : "gpio-fan" 4- compatible : "gpio-fan"
5
6Optional properties:
5- gpios: Specifies the pins that map to bits in the control value, 7- gpios: Specifies the pins that map to bits in the control value,
6 ordered MSB-->LSB. 8 ordered MSB-->LSB.
7- gpio-fan,speed-map: A mapping of possible fan RPM speeds and the 9- gpio-fan,speed-map: A mapping of possible fan RPM speeds and the
8 control value that should be set to achieve them. This array 10 control value that should be set to achieve them. This array
9 must have the RPM values in ascending order. 11 must have the RPM values in ascending order.
10
11Optional properties:
12- alarm-gpios: This pin going active indicates something is wrong with 12- alarm-gpios: This pin going active indicates something is wrong with
13 the fan, and a udev event will be fired. 13 the fan, and a udev event will be fired.
14 14
15Note: At least one the "gpios" or "alarm-gpios" properties must be set.
16
15Examples: 17Examples:
16 18
17 gpio_fan { 19 gpio_fan {
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index 36abf814b8c7..c241f5b0b7cf 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -404,10 +404,32 @@ static int gpio_fan_get_of_pdata(struct device *dev,
404 404
405 node = dev->of_node; 405 node = dev->of_node;
406 406
407 /* Alarm GPIO if one exists */
408 if (of_gpio_named_count(node, "alarm-gpios") > 0) {
409 struct gpio_fan_alarm *alarm;
410 int val;
411 enum of_gpio_flags flags;
412
413 alarm = devm_kzalloc(dev, sizeof(struct gpio_fan_alarm),
414 GFP_KERNEL);
415 if (!alarm)
416 return -ENOMEM;
417
418 val = of_get_named_gpio_flags(node, "alarm-gpios", 0, &flags);
419 if (val < 0)
420 return val;
421 alarm->gpio = val;
422 alarm->active_low = flags & OF_GPIO_ACTIVE_LOW;
423
424 pdata->alarm = alarm;
425 }
426
407 /* Fill GPIO pin array */ 427 /* Fill GPIO pin array */
408 pdata->num_ctrl = of_gpio_count(node); 428 pdata->num_ctrl = of_gpio_count(node);
409 if (pdata->num_ctrl <= 0) { 429 if (pdata->num_ctrl <= 0) {
410 dev_err(dev, "gpios DT property empty / missing"); 430 if (pdata->alarm)
431 return 0;
432 dev_err(dev, "DT properties empty / missing");
411 return -ENODEV; 433 return -ENODEV;
412 } 434 }
413 ctrl = devm_kzalloc(dev, pdata->num_ctrl * sizeof(unsigned), 435 ctrl = devm_kzalloc(dev, pdata->num_ctrl * sizeof(unsigned),
@@ -460,26 +482,6 @@ static int gpio_fan_get_of_pdata(struct device *dev,
460 } 482 }
461 pdata->speed = speed; 483 pdata->speed = speed;
462 484
463 /* Alarm GPIO if one exists */
464 if (of_gpio_named_count(node, "alarm-gpios") > 0) {
465 struct gpio_fan_alarm *alarm;
466 int val;
467 enum of_gpio_flags flags;
468
469 alarm = devm_kzalloc(dev, sizeof(struct gpio_fan_alarm),
470 GFP_KERNEL);
471 if (!alarm)
472 return -ENOMEM;
473
474 val = of_get_named_gpio_flags(node, "alarm-gpios", 0, &flags);
475 if (val < 0)
476 return val;
477 alarm->gpio = val;
478 alarm->active_low = flags & OF_GPIO_ACTIVE_LOW;
479
480 pdata->alarm = alarm;
481 }
482
483 return 0; 485 return 0;
484} 486}
485 487