Merge branch 'for-2.6.30' into for-2.6.31
[linux-2.6] / drivers / leds / leds-h1940.c
1 /*
2  * drivers/leds/leds-h1940.c
3  * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
4  *
5  * This file is subject to the terms and conditions of the GNU General Public
6  * License.  See the file COPYING in the main directory of this archive for
7  * more details.
8  *
9  * H1940 leds driver
10  *
11  */
12
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/delay.h>
16 #include <linux/string.h>
17 #include <linux/ctype.h>
18 #include <linux/leds.h>
19 #include <mach/regs-gpio.h>
20 #include <mach/hardware.h>
21 #include <mach/h1940-latch.h>
22
23 /*
24  * Green led.
25  */
26 static void h1940_greenled_set(struct led_classdev *led_dev,
27                                enum led_brightness value)
28 {
29         switch (value) {
30         case LED_HALF:
31                 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
32                 s3c2410_gpio_setpin(S3C2410_GPA7, 1);
33                 break;
34         case LED_FULL:
35                 h1940_latch_control(0, H1940_LATCH_LED_GREEN);
36                 s3c2410_gpio_setpin(S3C2410_GPA7, 1);
37                 break;
38         default:
39         case LED_OFF:
40                 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
41                 h1940_latch_control(H1940_LATCH_LED_GREEN, 0);
42                 s3c2410_gpio_setpin(S3C2410_GPA7, 0);
43                 break;
44         }
45 }
46
47 static struct led_classdev h1940_greenled = {
48         .name                   = "h1940:green",
49         .brightness_set         = h1940_greenled_set,
50         .default_trigger        = "h1940-charger",
51 };
52
53 /*
54  * Red led.
55  */
56 static void h1940_redled_set(struct led_classdev *led_dev,
57                              enum led_brightness value)
58 {
59         switch (value) {
60         case LED_HALF:
61                 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
62                 s3c2410_gpio_setpin(S3C2410_GPA1, 1);
63                 break;
64         case LED_FULL:
65                 h1940_latch_control(0, H1940_LATCH_LED_RED);
66                 s3c2410_gpio_setpin(S3C2410_GPA1, 1);
67                 break;
68         default:
69         case LED_OFF:
70                 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
71                 h1940_latch_control(H1940_LATCH_LED_RED, 0);
72                 s3c2410_gpio_setpin(S3C2410_GPA1, 0);
73                 break;
74         }
75 }
76
77 static struct led_classdev h1940_redled = {
78         .name                   = "h1940:red",
79         .brightness_set         = h1940_redled_set,
80         .default_trigger        = "h1940-charger",
81 };
82
83 /*
84  * Blue led.
85  * (it can only be blue flashing led)
86  */
87 static void h1940_blueled_set(struct led_classdev *led_dev,
88                               enum led_brightness value)
89 {
90         if (value) {
91                 /* flashing Blue */
92                 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
93                 s3c2410_gpio_setpin(S3C2410_GPA3, 1);
94         } else {
95                 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
96                 s3c2410_gpio_setpin(S3C2410_GPA3, 0);
97         }
98
99 }
100
101 static struct led_classdev h1940_blueled = {
102         .name                   = "h1940:blue",
103         .brightness_set         = h1940_blueled_set,
104         .default_trigger        = "h1940-bluetooth",
105 };
106
107 static int __devinit h1940leds_probe(struct platform_device *pdev)
108 {
109         int ret;
110
111         ret = led_classdev_register(&pdev->dev, &h1940_greenled);
112         if (ret)
113                 goto err_green;
114
115         ret = led_classdev_register(&pdev->dev, &h1940_redled);
116         if (ret)
117                 goto err_red;
118
119         ret = led_classdev_register(&pdev->dev, &h1940_blueled);
120         if (ret)
121                 goto err_blue;
122
123         return 0;
124
125 err_blue:
126         led_classdev_unregister(&h1940_redled);
127 err_red:
128         led_classdev_unregister(&h1940_greenled);
129 err_green:
130         return ret;
131 }
132
133 static int h1940leds_remove(struct platform_device *pdev)
134 {
135         led_classdev_unregister(&h1940_greenled);
136         led_classdev_unregister(&h1940_redled);
137         led_classdev_unregister(&h1940_blueled);
138         return 0;
139 }
140
141
142 static struct platform_driver h1940leds_driver = {
143         .driver         = {
144                 .name   = "h1940-leds",
145                 .owner  = THIS_MODULE,
146         },
147         .probe          = h1940leds_probe,
148         .remove         = h1940leds_remove,
149 };
150
151
152 static int __init h1940leds_init(void)
153 {
154         return platform_driver_register(&h1940leds_driver);
155 }
156
157 static void __exit h1940leds_exit(void)
158 {
159         platform_driver_unregister(&h1940leds_driver);
160 }
161
162 module_init(h1940leds_init);
163 module_exit(h1940leds_exit);
164
165 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
166 MODULE_DESCRIPTION("LED driver for the iPAQ H1940");
167 MODULE_LICENSE("GPL");
168 MODULE_ALIAS("platform:h1940-leds");