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>
18 #include <asm/arch/gpio.h>
19 #include <asm/arch/hardware.h>
20 #include <asm/arch/led.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);
32 omap_set_gpio_dataout(led_dev->gpio, 1);
34 omap_set_gpio_dataout(led_dev->gpio, 0);
37 static void omap_configure_led_gpio(int gpio)
39 if (omap_request_gpio(gpio) < 0) {
40 printk(KERN_ERR "Failed to request GPIO%d for LEDs\n", gpio);
43 omap_set_gpio_direction(gpio, 0); /* OUT */
46 static int omap_led_probe(struct platform_device *dev)
48 struct omap_led_platform_data *pdata = dev->dev.platform_data;
49 struct omap_led_config *leds = pdata->leds;
52 for (i = 0; ret >= 0 && i < pdata->nr_leds; i++) {
53 omap_configure_led_gpio(leds[i].gpio);
54 if (!leds[i].cdev.brightness_set)
55 leds[i].cdev.brightness_set = omap_set_led_gpio;
57 ret = led_classdev_register(&dev->dev, &leds[i].cdev);
60 if (ret < 0 && i > 1) {
61 for (i = i - 2; i >= 0; i--)
62 led_classdev_unregister(&leds[i].cdev);
68 static int omap_led_remove(struct platform_device *dev)
70 struct omap_led_platform_data *pdata = dev->dev.platform_data;
71 struct omap_led_config *leds = pdata->leds;
74 for (i = 0; i < pdata->nr_leds; i++)
75 led_classdev_unregister(&leds[i].cdev);
81 static int omap_led_suspend(struct platform_device *dev, pm_message_t state)
83 struct omap_led_platform_data *pdata = dev->dev.platform_data;
84 struct omap_led_config *leds = pdata->leds;
87 for (i = 0; i < pdata->nr_leds; i++)
88 led_classdev_suspend(&leds[i].cdev);
93 static int omap_led_resume(struct platform_device *dev)
95 struct omap_led_platform_data *pdata = dev->dev.platform_data;
96 struct omap_led_config *leds = pdata->leds;
99 for (i = 0; i < pdata->nr_leds; i++)
100 led_classdev_resume(&leds[i].cdev);
105 #define omap_led_suspend NULL
106 #define omap_led_resume NULL
109 static struct platform_driver omap_led_driver = {
110 .probe = omap_led_probe,
111 .remove = omap_led_remove,
112 .suspend = omap_led_suspend,
113 .resume = omap_led_resume,
116 .owner = THIS_MODULE,
120 static int __init omap_led_init(void)
122 return platform_driver_register(&omap_led_driver);
125 static void __exit omap_led_exit(void)
127 platform_driver_unregister(&omap_led_driver);
130 module_init(omap_led_init);
131 module_exit(omap_led_exit);
133 MODULE_AUTHOR("Kyungmin Park<kyungmin.park@samsung.com>");
134 MODULE_DESCRIPTION("OMAP LED driver");
135 MODULE_LICENSE("GPL");