fbef7d3bbf38c2d89ccaa3d3132fdf6bd3a1eea1
[openwrt/svn-archive/archive.git] / target / linux / ar7-2.6 / files / drivers / leds / leds-ar7.c
1 /*
2 * linux/drivers/leds/leds-ar7.c
3 *
4 * Copyright (C) 2007 OpenWrt.org
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/platform_device.h>
25 #include <linux/leds.h>
26 #include <linux/err.h>
27 #include <asm/io.h>
28
29 #include <asm/gpio.h>
30
31 #define DRVNAME "ar7-leds"
32 #define LONGNAME "TI AR7 LEDs driver"
33
34 MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
35 MODULE_DESCRIPTION(LONGNAME);
36 MODULE_LICENSE("GPL");
37
38 static void ar7_status_led_set(struct led_classdev *pled,
39 enum led_brightness value)
40 {
41 gpio_set_value(AR7_GPIO_BIT_STATUS_LED, value ? 0 : 1);
42 }
43
44 static struct led_classdev ar7_status_led = {
45 .name = "ar7:status",
46 .brightness_set = ar7_status_led_set,
47 };
48
49 #ifdef CONFIG_PM
50 static int ar7_leds_suspend(struct platform_device *dev,
51 pm_message_t state)
52 {
53 led_classdev_suspend(&ar7_status_led);
54 return 0;
55 }
56
57 static int ar7_leds_resume(struct platform_device *dev)
58 {
59 led_classdev_resume(&ar7_status_led);
60 return 0;
61 }
62 #else /* CONFIG_PM */
63 #define ar7_leds_suspend NULL
64 #define ar7_leds_resume NULL
65 #endif /* CONFIG_PM */
66
67 static int ar7_leds_probe(struct platform_device *pdev)
68 {
69 int rc;
70
71 rc = led_classdev_register(&pdev->dev, &ar7_status_led);
72 if (rc < 0 )
73 goto out;
74
75 ar7_gpio_enable(AR7_GPIO_BIT_STATUS_LED);
76 gpio_direction_output(AR7_GPIO_BIT_STATUS_LED);
77
78 out:
79 return rc;
80 }
81
82 static int ar7_leds_remove(struct platform_device *pdev)
83 {
84 led_classdev_unregister(&ar7_status_led);
85
86 return 0;
87 }
88
89 static struct platform_device *ar7_leds_device;
90
91 static struct platform_driver ar7_leds_driver = {
92 .probe = ar7_leds_probe,
93 .remove = ar7_leds_remove,
94 .suspend = ar7_leds_suspend,
95 .resume = ar7_leds_resume,
96 .driver = {
97 .name = DRVNAME,
98 },
99 };
100
101 static int __init ar7_leds_init(void)
102 {
103 int rc;
104
105 ar7_leds_device = platform_device_alloc(DRVNAME, -1);
106 if (!ar7_leds_device)
107 return -ENOMEM;
108
109 rc = platform_device_add(ar7_leds_device);
110 if (rc < 0)
111 goto out_put;
112
113 rc = platform_driver_register(&ar7_leds_driver);
114 if (rc < 0)
115 goto out_put;
116
117 goto out;
118
119 out_put:
120 platform_device_put(ar7_leds_device);
121 out:
122 return rc;
123 }
124
125 static void __exit ar7_leds_exit(void)
126 {
127 platform_driver_unregister(&ar7_leds_driver);
128 platform_device_unregister(ar7_leds_device);
129 }
130
131 module_init(ar7_leds_init);
132 module_exit(ar7_leds_exit);