1 /* drivers/leds/leds-omap.c
3 * (C) 2006 Samsung Electronics
4 * Kyungmin Park <kyungmin.park@samsung.com>
6 * OMAP - LEDs GPIO driver
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/leds.h>
17 #include <linux/gpio.h>
19 #include <mach/hardware.h>
24 static void omap_set_led_gpio(struct led_classdev *led_cdev,
25 enum led_brightness value)
27 struct omap_led_config *led_dev;
29 led_dev = container_of(led_cdev, struct omap_led_config, cdev);
30 gpio_set_value(led_dev->gpio, value);
33 static int omap_led_probe(struct platform_device *dev)
35 struct omap_led_platform_data *pdata = dev->dev.platform_data;
36 struct omap_led_config *leds = pdata->leds;
39 for (i = 0; ret >= 0 && i < pdata->nr_leds; i++) {
40 ret = gpio_request(leds[i].gpio, leds[i].cdev.name);
43 gpio_direction_output(leds[i].gpio, 0);
44 if (!leds[i].cdev.brightness_set)
45 leds[i].cdev.brightness_set = omap_set_led_gpio;
47 ret = led_classdev_register(&dev->dev, &leds[i].cdev);
50 if (ret < 0 && i > 1) {
51 for (i = i - 2; i >= 0; i--) {
52 led_classdev_unregister(&leds[i].cdev);
53 gpio_free(leds[i].gpio);
60 static int omap_led_remove(struct platform_device *dev)
62 struct omap_led_platform_data *pdata = dev->dev.platform_data;
63 struct omap_led_config *leds = pdata->leds;
66 for (i = 0; i < pdata->nr_leds; i++) {
67 led_classdev_unregister(&leds[i].cdev);
68 gpio_free(leds[i].gpio);
75 static int omap_led_suspend(struct platform_device *dev, pm_message_t state)
77 struct omap_led_platform_data *pdata = dev->dev.platform_data;
78 struct omap_led_config *leds = pdata->leds;
81 for (i = 0; i < pdata->nr_leds; i++)
82 led_classdev_suspend(&leds[i].cdev);
87 static int omap_led_resume(struct platform_device *dev)
89 struct omap_led_platform_data *pdata = dev->dev.platform_data;
90 struct omap_led_config *leds = pdata->leds;
93 for (i = 0; i < pdata->nr_leds; i++)
94 led_classdev_resume(&leds[i].cdev);
99 #define omap_led_suspend NULL
100 #define omap_led_resume NULL
103 static struct platform_driver omap_led_driver = {
104 .probe = omap_led_probe,
105 .remove = omap_led_remove,
106 .suspend = omap_led_suspend,
107 .resume = omap_led_resume,
110 .owner = THIS_MODULE,
114 static int __init omap_led_init(void)
116 return platform_driver_register(&omap_led_driver);
119 static void __exit omap_led_exit(void)
121 platform_driver_unregister(&omap_led_driver);
124 module_init(omap_led_init);
125 module_exit(omap_led_exit);
127 MODULE_AUTHOR("Kyungmin Park<kyungmin.park@samsung.com>");
128 MODULE_DESCRIPTION("OMAP LED driver");
129 MODULE_LICENSE("GPL");