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 <mach/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 void omap_configure_led_gpio(int gpio)
35 if (omap_request_gpio(gpio) < 0) {
36 printk(KERN_ERR "Failed to request GPIO%d for LEDs\n", gpio);
39 gpio_direction_output(gpio, 0);
42 static int omap_led_probe(struct platform_device *dev)
44 struct omap_led_platform_data *pdata = dev->dev.platform_data;
45 struct omap_led_config *leds = pdata->leds;
48 for (i = 0; ret >= 0 && i < pdata->nr_leds; i++) {
49 omap_configure_led_gpio(leds[i].gpio);
50 if (!leds[i].cdev.brightness_set)
51 leds[i].cdev.brightness_set = omap_set_led_gpio;
53 ret = led_classdev_register(&dev->dev, &leds[i].cdev);
56 if (ret < 0 && i > 1) {
57 for (i = i - 2; i >= 0; i--)
58 led_classdev_unregister(&leds[i].cdev);
64 static int omap_led_remove(struct platform_device *dev)
66 struct omap_led_platform_data *pdata = dev->dev.platform_data;
67 struct omap_led_config *leds = pdata->leds;
70 for (i = 0; i < pdata->nr_leds; i++)
71 led_classdev_unregister(&leds[i].cdev);
77 static int omap_led_suspend(struct platform_device *dev, pm_message_t state)
79 struct omap_led_platform_data *pdata = dev->dev.platform_data;
80 struct omap_led_config *leds = pdata->leds;
83 for (i = 0; i < pdata->nr_leds; i++)
84 led_classdev_suspend(&leds[i].cdev);
89 static int omap_led_resume(struct platform_device *dev)
91 struct omap_led_platform_data *pdata = dev->dev.platform_data;
92 struct omap_led_config *leds = pdata->leds;
95 for (i = 0; i < pdata->nr_leds; i++)
96 led_classdev_resume(&leds[i].cdev);
101 #define omap_led_suspend NULL
102 #define omap_led_resume NULL
105 static struct platform_driver omap_led_driver = {
106 .probe = omap_led_probe,
107 .remove = omap_led_remove,
108 .suspend = omap_led_suspend,
109 .resume = omap_led_resume,
112 .owner = THIS_MODULE,
116 static int __init omap_led_init(void)
118 return platform_driver_register(&omap_led_driver);
121 static void __exit omap_led_exit(void)
123 platform_driver_unregister(&omap_led_driver);
126 module_init(omap_led_init);
127 module_exit(omap_led_exit);
129 MODULE_AUTHOR("Kyungmin Park<kyungmin.park@samsung.com>");
130 MODULE_DESCRIPTION("OMAP LED driver");
131 MODULE_LICENSE("GPL");