From: Tony Lindgren Date: Thu, 10 Aug 2006 07:26:34 +0000 (+0300) Subject: ARM: OMAP: Add leds-omap.c accidentally left out X-Git-Tag: v2.6.18-omap1~115 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=247d64d8169d2f25a5f7d1b16222f2da76f51fd3;p=linux-2.6-omap-h63xx.git ARM: OMAP: Add leds-omap.c accidentally left out This file was accidentally left out from 5757cc0458b968c8f02fec99f147ffaa7761cfd0. Signed-off-by: Tony Lindgren --- diff --git a/drivers/leds/leds-omap.c b/drivers/leds/leds-omap.c new file mode 100644 index 00000000000..4667ece4001 --- /dev/null +++ b/drivers/leds/leds-omap.c @@ -0,0 +1,136 @@ +/* drivers/leds/leds-omap.c + * + * (C) 2006 Samsung Electronics + * Kyungmin Park + * + * OMAP - LEDs GPIO driver + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. +*/ + +#include +#include +#include +#include +#include + +#include +#include +#include + +/* our context */ + +static void omap_set_led_gpio(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct omap_led_config *led_dev; + + led_dev = container_of(led_cdev, struct omap_led_config, cdev); + + if (value) + omap_set_gpio_dataout(led_dev->gpio, 1); + else + omap_set_gpio_dataout(led_dev->gpio, 0); +} + +static void omap_configure_led_gpio(int gpio) +{ + if (omap_request_gpio(gpio) < 0) { + printk(KERN_ERR "Failed to request GPIO%d for LEDs\n", gpio); + return; + } + omap_set_gpio_direction(gpio, 0); /* OUT */ +} + +static int omap_led_probe(struct platform_device *dev) +{ + struct omap_led_platform_data *pdata = dev->dev.platform_data; + struct omap_led_config *leds = pdata->leds; + int i, ret = 0; + + for (i = 0; ret >= 0 && i < pdata->nr_leds; i++) { + omap_configure_led_gpio(leds[i].gpio); + if (!leds[i].cdev.brightness_set) + leds[i].cdev.brightness_set = omap_set_led_gpio; + + ret = led_classdev_register(&dev->dev, &leds[i].cdev); + } + + if (ret < 0 && i > 1) { + for (i = i - 2; i >= 0; i--) + led_classdev_unregister(&leds[i].cdev); + } + + return ret; +} + +static int omap_led_remove(struct platform_device *dev) +{ + struct omap_led_platform_data *pdata = dev->dev.platform_data; + struct omap_led_config *leds = pdata->leds; + int i; + + for (i = 0; i < pdata->nr_leds; i++) + led_classdev_unregister(&leds[i].cdev); + + return 0; +} + +#ifdef CONFIG_PM +static int omap_led_suspend(struct platform_device *dev, pm_message_t state) +{ + struct omap_led_platform_data *pdata = dev->dev.platform_data; + struct omap_led_config *leds = pdata->leds; + int i; + + for (i = 0; i < pdata->nr_leds; i++) + led_classdev_suspend(&leds[i].cdev); + + return 0; +} + +static int omap_led_resume(struct platform_device *dev) +{ + struct omap_led_platform_data *pdata = dev->dev.platform_data; + struct omap_led_config *leds = pdata->leds; + int i; + + for (i = 0; i < pdata->nr_leds; i++) + led_classdev_resume(&leds[i].cdev); + + return 0; +} +#else +#define omap_led_suspend NULL +#define omap_led_resume NULL +#endif + +static struct platform_driver omap_led_driver = { + .probe = omap_led_probe, + .remove = omap_led_remove, + .suspend = omap_led_suspend, + .resume = omap_led_resume, + .driver = { + .name = "omap-led", + .owner = THIS_MODULE, + }, +}; + +static int __init omap_led_init(void) +{ + return platform_driver_register(&omap_led_driver); +} + +static void __exit omap_led_exit(void) +{ + platform_driver_unregister(&omap_led_driver); +} + +module_init(omap_led_init); +module_exit(omap_led_exit); + +MODULE_AUTHOR("Kyungmin Park"); +MODULE_DESCRIPTION("OMAP LED driver"); +MODULE_LICENSE("GPL");