Re: LED module not creating /sys/class/leds entry

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 5, 2013 at 4:33 PM, Ian Pilcher <arequipeno@xxxxxxxxx> wrote:
> (I sent this question to linux-kernel before discovering the existence
> of this list.  I apologize for cross-posting, but this seems like a
> better forum for this question.)
>
> I am trying to understand the LED API.  I have created an extremely
> simple "dummy" LED module (see below), which loads without any errors,
> but /sys/class/leds is empty.
>

This API will create the sysfs node for your:
 return led_classdev_register(&pdev->dev, &dummy_led_cdev);

> Any pointers on what additional steps I need to take to get my "LED" to
> show up are greatly appreciated.
>

Your dummy driver is basically right, the /sys/class/leds/dummy should
be shown up.
But you missed to register this platform device in your kernel. You
should put some code in your specific's board file, like
arch/arm/mach-omap2/board-omap3beagle.c.

Define a structure to tell kernel that you have a dummy led device.

+static struct platform_device leds_dummy_device = {
+       .name   = "dummy-led",
+       .id     = 0,
+};

Then register it in your board init code:
+       platform_device_register(&leds_dummy_device);

NOTE: the .name should match the name in your driver code like "dummy-led"

Then you will get the right things.

The better why is to use Device Tree instead of platform device register.

-Bryan

> Thanks!
>
> #include <linux/leds.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
>
> static enum led_brightness dummy_led_brightness = LED_OFF;
>
> static void dummy_led_set_brightness(struct led_classdev *cdev,
>                                      enum led_brightness brightness)
> {
>         dummy_led_brightness = brightness;
> }
>
> static enum led_brightness dummy_led_get_brightness(struct led_classdev
> *cdev)
> {
>         return dummy_led_brightness;
> }
>
> static struct led_classdev dummy_led_cdev = {
>         .name = "dummy",
>         .brightness_set = dummy_led_set_brightness,
>         .brightness_get = dummy_led_get_brightness,
> };
>
> static int dummy_led_probe(struct platform_device *pdev)
> {
>         return led_classdev_register(&pdev->dev, &dummy_led_cdev);
> }
>
> static int dummy_led_remove(struct platform_device *pdev)
> {
>         led_classdev_unregister(&dummy_led_cdev);
>         return 0;
> }
>
> static struct platform_driver dummy_led_driver = {
>         .probe = dummy_led_probe,
>         .remove = dummy_led_remove,
>         .driver = {
>                 .name = "dummy-led",
>                 .owner = THIS_MODULE,
>         },
> };
>
> static int __init dummy_led_init(void)
> {
>         return platform_driver_register(&dummy_led_driver);
> }
>
> static void __exit dummy_led_exit(void)
> {
>     platform_driver_unregister(&dummy_led_driver);
> }
>
> module_init(dummy_led_init);
> module_exit(dummy_led_exit);
>
> MODULE_LICENSE("GPL");
> MODULE_DESCRIPTION("Dummy LED driver");
> MODULE_AUTHOR("Ian Pilcher <arequipeno@xxxxxxxxx>");
>
> --
> ========================================================================
> Ian Pilcher                                         arequipeno@xxxxxxxxx
> Sometimes there's nothing left to do but crash and burn...or die trying.
> ========================================================================
> --
> To unsubscribe from this list: send the line "unsubscribe linux-leds" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux