ar71xx: make leds-gpio usable with single-ended GPIOs
[openwrt/openwrt.git] / target / linux / ar71xx / patches-4.4 / 442-leds-gpio-allow-to-use-OPEN_-DRAIN-SOURCE-flags-with.patch
1 From 183148e0789bee1cd5c46ba49afcb211f636f8a2 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@freemail.hu>
3 Date: Mon, 15 Jan 2018 15:01:14 +0100
4 Subject: [PATCH] leds: gpio: allow to use OPEN_{DRAIN,SOURCE} flags with
5 legacy GPIOs
6
7 LEDs which are connected to open-source or open-drain type of GPIO lines
8 can be used only, if those are defined via devicetree.
9 Add two new fields to 'struct gpio_led' in order to make it possible to
10 specify this type of GPIO lines to the leds-gpio driver via platform data.
11 Also update the create_gpio_led() function to set the GPIOF_OPEN_DRAIN and
12 GPIOF_OPEN_SOURCE flags for the given GPIO line.
13
14 Signed-off-by: Gabor Juhos <juhosg@freemail.hu>
15 ---
16 drivers/leds/leds-gpio.c | 6 ++++++
17 include/linux/leds.h | 2 ++
18 2 files changed, 8 insertions(+)
19
20 --- a/drivers/leds/leds-gpio.c
21 +++ b/drivers/leds/leds-gpio.c
22 @@ -110,6 +110,12 @@ static int create_gpio_led(const struct
23 if (template->active_low)
24 flags |= GPIOF_ACTIVE_LOW;
25
26 + if (template->open_drain)
27 + flags |= GPIOF_OPEN_DRAIN;
28 +
29 + if (template->open_source)
30 + flags |= GPIOF_OPEN_SOURCE;
31 +
32 ret = devm_gpio_request_one(parent, template->gpio, flags,
33 template->name);
34 if (ret < 0)
35 --- a/include/linux/leds.h
36 +++ b/include/linux/leds.h
37 @@ -350,6 +350,8 @@ struct gpio_led {
38 unsigned retain_state_suspended : 1;
39 unsigned default_state : 2;
40 /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
41 + unsigned open_drain : 1;
42 + unsigned open_source : 1;
43 struct gpio_desc *gpiod;
44 };
45 #define LEDS_GPIO_DEFSTATE_OFF 0