Leds
Hi all,
how can specify a led device in a dts file? These leds are connected with gpio to the microprocessor. I can't find anything like a led node in the dts files of the other boards. Have you got any suggestions?
Regards,
Marco
Hi Marco,
Quoted 3 lines · On Fri, 08 Feb 2008 11:02:16 +0100 Marco Stornelli…
how can specify a led device in a dts file? These leds are connected with gpio to the microprocessor. I can't find anything like a led node in the dts files of the other boards. Have you got any suggestions?
Although I'm not sure if it's the "standard" way, we just added a "home-made" node like this:
resetLED@c0018000 {
device_type = "leds";
compatible = "reset-leds";
reg = <c0018000 00008000>;
};and then just get the info in the probe function for the led driver we placed in drivers/leds/:
/* Get device info from OF tree */
np = of_find_compatible_node(NULL, "leds", "reset-leds");
if (!np) {
dev_err(&pdev->dev, "Could not find device tree node for reset-leds\n");
goto error_classdev;
}
if (of_address_to_resource(np, 0, &res)) {
dev_err(&pdev->dev, "Could not convert reset-leds device tree address\n");
of_node_put(np);
goto error_classdev;
}
...At least this was all the information we needed from the device tree.
// Simon
Simon Kagstrom ha scritto:
Quoted 35 lines
Hi Marco,
Quoted 3 lines · On Fri, 08 Feb 2008 11:02:16 +0100 Marco Stornelli…
how can specify a led device in a dts file? These leds are connected with gpio to the microprocessor. I can't find anything like a led node in the dts files of the other boards. Have you got any suggestions?
Although I'm not sure if it's the "standard" way, we just added a "home-made" node like this:
resetLED@c0018000 { device_type = "leds"; compatible = "reset-leds"; reg = <c0018000 00008000>; };and then just get the info in the probe function for the led driver we placed in
drivers/leds/:/* Get device info from OF tree */ np = of_find_compatible_node(NULL, "leds", "reset-leds"); if (!np) { dev_err(&pdev->dev, "Could not find device tree node for reset-leds\n"); goto error_classdev; } if (of_address_to_resource(np, 0, &res)) { dev_err(&pdev->dev, "Could not convert reset-leds device tree address\n"); of_node_put(np); goto error_classdev; } ...
Quoted 4 lines
At least this was all the information we needed from the device tree.
// Simon
Thanks. In this case where have you added the device registration? In the probe function? Have you registered the driver with of_register_platform_driver()?
Quoted 9 lines · On Fri, 08 Feb 2008 11:43:25 +0100 Marco Stornelli…
Quoted 9 lines
Although I'm not sure if it's the "standard" way, we just added a "home-made" node like this:
resetLED@c0018000 { device_type = "leds"; compatible = "reset-leds"; reg = <c0018000 00008000>; };
Quoted 3 lines
Thanks. In this case where have you added the device registration? In the probe function? Have you registered the driver with
of_register_platform_driver()?
We put it in the module init function and registered it as a platform device:
static int __init led_init(void)
{
int ret;
ret = platform_driver_register(&led_driver);
if (ret < 0)
return -ENODEV;
pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
if (IS_ERR(pdev)) {
ret = PTR_ERR(pdev);
platform_driver_unregister(&led_driver);
}
return ret;
}And just use the device tree stuff to read out the device address. The driver itself is quite similar to other led drivers found in the same directory, so you can probably base your work on those.
This was for kernel 2.6.21, I'm not sure if these things have changed for newer kernels (although I would guess most of it is the same).
// Simon
Quoted 9 lines · Simon Kagstrom
Hi Marco,
Quoted 3 lines · On Fri, 08 Feb 2008 11:02:16 +0100 Marco Stornelli…
how can specify a led device in a dts file? These leds are connected with gpio to the microprocessor. I can't find anything like a led node in the dts files of the other boards. Have you got any suggestions?
Quoted 8 lines
Although I'm not sure if it's the "standard" way, we just added a "home-made" node like this:
resetLED@c0018000 { device_type = "leds"; compatible = "reset-leds"; reg = <c0018000 00008000>; };
I've been thinking about this a bit over the last couple of months, and I think that there is a better way. Since many LEDs are simply hooked up to GPIO blocks and we're moving towards a common GPIO api (and device tree binding), I think it would be better to use two nodes; a node for the gpio block and a node for all the LEDs in the system. For example (the GPIO dt bindings may differ from my example here, but you get the gist):
GPIO0: gpio-controller@1418 {
#gpio-cells = <2>;
compatible = "fsl,qe-pario-bank";
reg = <0x1418 0x18>;
gpio-controller;
};
GPIO1: gpio-controller@1460 {
#gpio-cells = <2>;
compatible = "fsl,qe-pario-bank";
reg = <0x1460 0x18>;
gpio-controller;
};leds@0 {
compatible = "gpio-leds";
led-labels = "led1", "led2", "led3", "led4";
gpios = <&GPIO0 2 0 /* LED1 */
&GPIO0 3 0 /* LED2 */
&GPIO1 8 0 /* LED3 */
&GPIO1 9 0 /* LED4 */
>;
/* More properties are probably needed here to correctly setupthe output levels */
};
Doing it this way means the GPIO block will be usable for more than just LEDs. Plus once the 'gpio-leds' driver is written leds can be hooked up almost trivially on new boards.
Cheers,
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.