Skip to content

Commit

Permalink
hwmon: (gpio-fan) allow to use alarm support alone from DT
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Simon Guinot authored and Guenter Roeck committed Mar 9, 2015
1 parent 6552f32 commit 73ef85f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
6 changes: 4 additions & 2 deletions Documentation/devicetree/bindings/gpio/gpio-fan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ Bindings for fan connected to GPIO lines

Required properties:
- compatible : "gpio-fan"

Optional properties:
- 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.

Note: At least one the "gpios" or "alarm-gpios" properties must be set.

Examples:

gpio_fan {
Expand Down
44 changes: 23 additions & 21 deletions drivers/hwmon/gpio-fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,32 @@ static int gpio_fan_get_of_pdata(struct device *dev,

node = dev->of_node;

/* Alarm GPIO if one exists */
if (of_gpio_named_count(node, "alarm-gpios") > 0) {
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;
}

/* Fill GPIO pin array */
pdata->num_ctrl = of_gpio_count(node);
if (pdata->num_ctrl <= 0) {
dev_err(dev, "gpios DT property empty / missing");
if (pdata->alarm)
return 0;
dev_err(dev, "DT properties empty / missing");
return -ENODEV;
}
ctrl = devm_kzalloc(dev, pdata->num_ctrl * sizeof(unsigned),
Expand Down Expand Up @@ -460,26 +482,6 @@ static int gpio_fan_get_of_pdata(struct device *dev,
}
pdata->speed = speed;

/* Alarm GPIO if one exists */
if (of_gpio_named_count(node, "alarm-gpios") > 0) {
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;
}

Expand Down

0 comments on commit 73ef85f

Please sign in to comment.