Add LED driven by multiple gpio.
Subsystems (2)
PATCH 1/1 Add LED driven by multiple gpio.
Hello, on our board we have one LED with 2 gpio connected to it:
- when gpio0 is on and gpio1 on - LED is orange.
- when gpio0 is on and gpio1 off - LED is green.
- when gpio0 is off and gpio1 on - LED is red.
- when gpio0 is off and gpio1 off - LED is off.
We want use led_trigger (nand-disk) on this LED.
Below patch which we use for get one LED on 2 gpios. Can be this in mainline, or may be exist other - better way?
Signature · 2 lines
Dmitry Bondar, simicon.com
Quoted 1 line
From
27f61d2bf3264f1434c0e568c5adb82fafc591b1Mon Sep 17 00:00:00 2001
From: Dmitry Bondar <[email protected]>
Date: Fri, 22 Apr 2016 18:33:44 +0300
Subject: [PATCH 0/2] Add LED driven by multiple gpio
Hello, on our board we have one LED with 2 gpio connected to it:
- when gpio0 is on and gpio1 on - LED is orange.
- when gpio0 is on and gpio1 off - LED is green.
- when gpio0 is off and gpio1 on - LED is red.
- when gpio0 is off and gpio1 off - LED is off.
We want use led_trigger (nand-disk) on this LED.
Below patch which we use for get one LED on 2 gpios. Can be this in mainline, or may be exist other - better way?
Dmitry Bondar (2):
add multiple gpio led(mgpio-led) description to device tree add multiple gpio led(mgpio-led) driver
.../devicetree/bindings/leds/leds-mgpio.txt | 31 ++++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-mgpio.c | 191 ++++++++++++++++++++ 4 files changed, 231 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mgpio.txt create mode 100644 drivers/leds/leds-mgpio.c
Signature · 1 line
1.7.10.4
Quoted 1 line
From
359cf82ccd8ca100b4330596843af17fbaa85a9eMon Sep 17 00:00:00 2001
From: Dmitry Bondar <[email protected]>
Date: Fri, 22 Apr 2016 17:46:33 +0300
Subject: [PATCH 1/2] Add LED driven by multiple gpio
led(mgpio-led) description to
device tree
--- .../devicetree/bindings/leds/leds-mgpio.txt | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mgpio.txt
Documentation/devicetree/bindings/leds/leds-mgpio.txt new file +31 -0
@@ -0,0 +1,31 @@ +LED connected to multiple GPIO lines +For example red/green/orange led with to 2 gpio connectd to it. + +Required properties: +- compatible : should be "mgpio-led". +- gpios : Should specify the LED's GPIOs, see "gpios property" in + Documentation/devicetree/bindings/gpio/gpio.txt. Active low LEDs should be + indicated using flags in the GPIO specifier. +- color_names: list of colors +- color_vals: list of gpio values for each color + in example below for red led gpio 23 must be 0 and gpio 8 must be 1 + +Optional properties: +- label : + see Documentation/devicetree/bindings/leds/common.txt +- linux,default-trigger : + see Documentation/devicetree/bindings/leds/common.txt +- default-color + string from color-names +Examples: + +led_uplink{ + compatible = "simicon,mgpio-led"; + label = "uplink"; + gpios = <&portb 23 GPIO_ACTIVE_HIGH>, <&portb 8 GPIO_ACTIVE_HIGH>; + color_vals = <1 1>, <0 1>, <1 0>; + color_names = "orange", "red", "green"; + default-color = "green"; + linux,default-trigger = "heartbeat"; +}; +
Signature · 1 line
1.7.10.4
Quoted 1 line
From
27f61d2bf3264f1434c0e568c5adb82fafc591b1Mon Sep 17 00:00:00 2001
From: Dmitry Bondar <[email protected]>
Date: Fri, 22 Apr 2016 17:50:04 +0300
Subject: [PATCH 2/2] Add LED driven by multiple gpio
led(mgpio-led) driver
--- drivers/leds/Kconfig | 8 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-mgpio.c | 191 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 drivers/leds/leds-mgpio.c
drivers/leds/Kconfig +8 -0
@@ -616,6 +616,14 @@ config LEDS_VERSATILE This option enabled support for the LEDs on the ARM Versatile and RealView boards. Say Y to enabled these. +config LEDS_MGPIO + tristate "LED driven by multiple gpio" + depends on LEDS_CLASS + depends on GPIOLIB || COMPILE_TEST + help + This option enables support for the LEDs connected to + multiple GPIO outputs. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig"
drivers/leds/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o +obj-$(CONFIG_LEDS_MGPIO) += leds-mgpio.c # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
drivers/leds/leds-mgpio.c new file +191 -0
191 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Hi Dmitry,
First of all, please don't send patches as attachments but use git send-email on each of them.
Regarding the driver - if the LEDs are not driven by some LED controller device, then this patch fits better for GPIO subsystem IMO.
Quoted 9 lines · Dmitry Bondar
Hello, on our board we have one LED with 2 gpio connected to it:
- when gpio0 is on and gpio1 on - LED is orange.
- when gpio0 is on and gpio1 off - LED is green.
- when gpio0 is off and gpio1 on - LED is red.
- when gpio0 is off and gpio1 off - LED is off.
We want useled_trigger(nand-disk) on this LED.
Below patch which we use for get one LED on 2 gpios. Can be this in mainline, or may be exist other - better way?
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 7 lines · Jacek Anaszewski
Hi Dmitry,
First of all, please don't send patches as attachments but use git send-email on each of them.
Regarding the driver - if the LEDs are not driven by some LED controller device, then this patch fits better for GPIO subsystem IMO.
Of course the driver should register LED class device anyway, but the main question is how the GPIO logic is implemented. Is it some publicly available chip or a circuit composed of discrete elements?
Quoted 12 lines · Dmitry Bondar
Quoted 9 lines
Hello, on our board we have one LED with 2 gpio connected to it:
- when gpio0 is on and gpio1 on - LED is orange.
- when gpio0 is on and gpio1 off - LED is green.
- when gpio0 is off and gpio1 on - LED is red.
- when gpio0 is off and gpio1 off - LED is off.
We want useled_trigger(nand-disk) on this LED.
Below patch which we use for get one LED on 2 gpios. Can be this in mainline, or may be exist other - better way?
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 9 lines · On Mon, 25 Apr 2016 11:14:38 +0300 Dmitry Bondar <[email protected]> wrote:
Hello, on our board we have one LED with 2 gpio connected to it:
- when gpio0 is on and gpio1 on - LED is orange.
- when gpio0 is on and gpio1 off - LED is green.
- when gpio0 is off and gpio1 on - LED is red.
- when gpio0 is off and gpio1 off - LED is off.
We want useled_trigger(nand-disk) on this LED.
Below patch which we use for get one LED on 2 gpios. Can be this in mainline, or may be exist other - better way?
It sounds like what you have is two independent GPIO controlled LEDs:
one green and the other red (even if they are part of the same IC). Given the current infrastructure, I have modeled such cases as two separate LEDs in the devicetree, named <device>:green:<function> and <device>:red:<function>. Userspace is then responsible for controlling them appropriately to get the desired color.
Unless I'm mistaken, in your case (nand-disk) there are blinking combinations you wouldn't be able to achieve this way, but there are a number you can do:
- off/green: green:nand-disk red:off
- off/red: green:off red:nand-disk
- off/orange: green:nand-disk red:nand-disk
- green/orange: green:on red:nand-disk
- red/orange: green:nand-disk red:on
The other cases (e.g. green/red) would need an inverted nand-disk trigger (on while inactive, off while active).
I'm hoping that if the RGB LED framework comes to fruition, that there will be some way to combine arbitrary single-color LED devices into a logical RGB LED. I suspect there are many boards that would find it useful to expose a single RGB LED to userspace (and triggers), as opposed to separate R, G, and B LEDs.
Hi David,
Quoted 31 lines · David Rivshin (Allworx)
Quoted 9 lines · On Mon, 25 Apr 2016 11:14:38 +0300 Dmitry Bondar <[email protected]> wrote:
Hello, on our board we have one LED with 2 gpio connected to it:
- when gpio0 is on and gpio1 on - LED is orange.
- when gpio0 is on and gpio1 off - LED is green.
- when gpio0 is off and gpio1 on - LED is red.
- when gpio0 is off and gpio1 off - LED is off.
We want useled_trigger(nand-disk) on this LED.
Below patch which we use for get one LED on 2 gpios. Can be this in mainline, or may be exist other - better way?It sounds like what you have is two independent GPIO controlled LEDs:
one green and the other red (even if they are part of the same IC). Given the current infrastructure, I have modeled such cases as two separate LEDs in the devicetree, named <device>:green:<function> and <device>:red:<function>. Userspace is then responsible for controlling them appropriately to get the desired color.Unless I'm mistaken, in your case (nand-disk) there are blinking combinations you wouldn't be able to achieve this way, but there are a number you can do:
- off/green: green:nand-disk red:off
- off/red: green:off red:nand-disk
- off/orange: green:nand-disk red:nand-disk
- green/orange: green:on red:nand-disk
- red/orange: green:nand-disk red:on
The other cases (e.g. green/red) would need an inverted nand-disk trigger (on while inactive, off while active).
Quoted 3 lines
I'm hoping that if the RGB LED framework comes to fruition, that there will be some way to combine arbitrary single-color LED devices into a logical RGB LED.
It turns out that rgb-pattern trigger, we were discussing some time ago, would be useful also for LEDs of arbitrary colors. It should be given more generic name then, e.g. three-led-composite or so. The "color" sysfs attribute exposed by the trigger could be replaced with "subled_id", that would accept values 0, 1 or 2.
Brightness of such a compound LED could be set with:
led_trigger_3led_event(sturct led_trigger *trig,
enum led_brightness led1,
enum led_brightness led2,
enum led_brightness led3)
Maybe we should think about making this scalable using C ellipsis feature:
led_trigger_3led_event(sturct led_trigger *trig,
enum led_brightness led1,
...)
Signature · 2 lines
Best regards, Jacek Anaszewski
Hi!
Quoted 17 lines
Quoted 3 lines
I'm hoping that if the RGB LED framework comes to fruition, that there will be some way to combine arbitrary single-color LED devices into a logical RGB LED.
It turns out that rgb-pattern trigger, we were discussing some time ago, would be useful also for LEDs of arbitrary colors. It should be given more generic name then, e.g. three-led-composite or so. The "color" sysfs attribute exposed by the trigger could be replaced with "
subled_id", that would accept values 0, 1 or 2.Brightness of such a compound LED could be set with:
led_trigger_3led_event(sturct
led_trigger*trig,
enumled_brightnessled1,
enumled_brightnessled2,
enumled_brightnessled3)
Quoted 6 lines
Maybe we should think about making this scalable using C ellipsis feature:
led_trigger_3led_event(sturct
led_trigger*trig,
enumled_brightnessled1,
...)
You don't need (and should not need) elipsis.
led_trigger_many_leds_event(sturct led_trigger *trig,
int num_leds,
enum led_brightness *brightness)
...should be fine.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi Pavel,
Quoted 26 lines · Pavel Machek
Hi!
Quoted 17 lines
Quoted 3 lines
I'm hoping that if the RGB LED framework comes to fruition, that there will be some way to combine arbitrary single-color LED devices into a logical RGB LED.
It turns out that rgb-pattern trigger, we were discussing some time ago, would be useful also for LEDs of arbitrary colors. It should be given more generic name then, e.g. three-led-composite or so. The "color" sysfs attribute exposed by the trigger could be replaced with "
subled_id", that would accept values 0, 1 or 2.Brightness of such a compound LED could be set with:
led_trigger_3led_event(sturct
led_trigger*trig,
enumled_brightnessled1,
enumled_brightnessled2,
enumled_brightnessled3)Quoted 6 lines
Maybe we should think about making this scalable using C ellipsis feature:
led_trigger_3led_event(sturct
led_trigger*trig,
enumled_brightnessled1,
...)
Quoted 5 lines
You don't need (and should not need) elipsis.
led_trigger_many_leds_event(sturct
led_trigger*trig,
intnum_leds,
enumled_brightness*brightness)
Right, this is more straightforward approach.
Signature · 2 lines
Best regards, Jacek Anaszewski