blob: bcec42230389128cd03ce6294d13c8d018e288ab [file] [log] [blame]
Arnaud Patardbd4009a2007-02-12 23:09:32 +00001/*
Uwe Kleine-König58862692007-05-09 07:51:49 +02002 * drivers/leds/leds-h1940.c
Arnaud Patardbd4009a2007-02-12 23:09:32 +00003 * 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 <asm/arch/regs-gpio.h>
20#include <asm/hardware.h>
21#include <asm/arch/h1940-latch.h>
22
23/*
24 * Green led.
25 */
26void h1940_greenled_set(struct led_classdev *led_dev, enum led_brightness value)
27{
28 switch (value) {
Németh Márton4d404fd2008-03-09 20:59:57 +000029 case LED_HALF:
30 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
31 s3c2410_gpio_setpin(S3C2410_GPA7, 1);
32 break;
33 case LED_FULL:
34 h1940_latch_control(0, H1940_LATCH_LED_GREEN);
35 s3c2410_gpio_setpin(S3C2410_GPA7, 1);
36 break;
37 default:
38 case LED_OFF:
39 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
40 h1940_latch_control(H1940_LATCH_LED_GREEN, 0);
41 s3c2410_gpio_setpin(S3C2410_GPA7, 0);
42 break;
Arnaud Patardbd4009a2007-02-12 23:09:32 +000043 }
44}
45
46static struct led_classdev h1940_greenled = {
47 .name = "h1940:green",
48 .brightness_set = h1940_greenled_set,
49 .default_trigger = "h1940-charger",
50};
51
52/*
53 * Red led.
54 */
55void h1940_redled_set(struct led_classdev *led_dev, enum led_brightness value)
56{
57 switch (value) {
Németh Márton4d404fd2008-03-09 20:59:57 +000058 case LED_HALF:
59 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
60 s3c2410_gpio_setpin(S3C2410_GPA1, 1);
61 break;
62 case LED_FULL:
63 h1940_latch_control(0, H1940_LATCH_LED_RED);
64 s3c2410_gpio_setpin(S3C2410_GPA1, 1);
65 break;
66 default:
67 case LED_OFF:
68 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
69 h1940_latch_control(H1940_LATCH_LED_RED, 0);
70 s3c2410_gpio_setpin(S3C2410_GPA1, 0);
71 break;
Arnaud Patardbd4009a2007-02-12 23:09:32 +000072 }
73}
74
75static struct led_classdev h1940_redled = {
76 .name = "h1940:red",
77 .brightness_set = h1940_redled_set,
78 .default_trigger = "h1940-charger",
79};
80
81/*
82 * Blue led.
83 * (it can only be blue flashing led)
84 */
85void h1940_blueled_set(struct led_classdev *led_dev, enum led_brightness value)
86{
87 if (value) {
88 /* flashing Blue */
Németh Márton4d404fd2008-03-09 20:59:57 +000089 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
90 s3c2410_gpio_setpin(S3C2410_GPA3, 1);
Arnaud Patardbd4009a2007-02-12 23:09:32 +000091 } else {
Németh Márton4d404fd2008-03-09 20:59:57 +000092 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
93 s3c2410_gpio_setpin(S3C2410_GPA3, 0);
Arnaud Patardbd4009a2007-02-12 23:09:32 +000094 }
95
96}
97
98static struct led_classdev h1940_blueled = {
99 .name = "h1940:blue",
100 .brightness_set = h1940_blueled_set,
101 .default_trigger = "h1940-bluetooth",
102};
103
104static int __init h1940leds_probe(struct platform_device *pdev)
105{
106 int ret;
107
108 ret = led_classdev_register(&pdev->dev, &h1940_greenled);
109 if (ret)
110 goto err_green;
111
112 ret = led_classdev_register(&pdev->dev, &h1940_redled);
113 if (ret)
114 goto err_red;
115
116 ret = led_classdev_register(&pdev->dev, &h1940_blueled);
117 if (ret)
118 goto err_blue;
119
120 return 0;
121
122err_blue:
123 led_classdev_unregister(&h1940_redled);
124err_red:
125 led_classdev_unregister(&h1940_greenled);
126err_green:
127 return ret;
128}
129
130static int h1940leds_remove(struct platform_device *pdev)
131{
132 led_classdev_unregister(&h1940_greenled);
133 led_classdev_unregister(&h1940_redled);
134 led_classdev_unregister(&h1940_blueled);
135 return 0;
136}
137
138
139static struct platform_driver h1940leds_driver = {
140 .driver = {
141 .name = "h1940-leds",
Kay Sievers3c4ded92008-04-15 14:34:30 -0700142 .owner = THIS_MODULE,
Arnaud Patardbd4009a2007-02-12 23:09:32 +0000143 },
144 .probe = h1940leds_probe,
145 .remove = h1940leds_remove,
146};
147
148
149static int __init h1940leds_init(void)
150{
151 return platform_driver_register(&h1940leds_driver);
152}
153
154static void __exit h1940leds_exit(void)
155{
156 platform_driver_unregister(&h1940leds_driver);
157}
158
159module_init(h1940leds_init);
160module_exit(h1940leds_exit);
161
162MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
163MODULE_DESCRIPTION("LED driver for the iPAQ H1940");
164MODULE_LICENSE("GPL");
Kay Sievers3c4ded92008-04-15 14:34:30 -0700165MODULE_ALIAS("platform:h1940-leds");