blob: 73c70502168653d16b8f06e88cb43d912f6b53c3 [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 */
Ben Dooksdd1160d2008-06-09 22:00:49 +010026static void h1940_greenled_set(struct led_classdev *led_dev,
27 enum led_brightness value)
Arnaud Patardbd4009a2007-02-12 23:09:32 +000028{
29 switch (value) {
Németh Márton4d404fd2008-03-09 20:59:57 +000030 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;
Arnaud Patardbd4009a2007-02-12 23:09:32 +000044 }
45}
46
47static 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 */
Ben Dooksdd1160d2008-06-09 22:00:49 +010056static void h1940_redled_set(struct led_classdev *led_dev,
57 enum led_brightness value)
Arnaud Patardbd4009a2007-02-12 23:09:32 +000058{
59 switch (value) {
Németh Márton4d404fd2008-03-09 20:59:57 +000060 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;
Arnaud Patardbd4009a2007-02-12 23:09:32 +000074 }
75}
76
77static 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 */
Ben Dooksdd1160d2008-06-09 22:00:49 +010087static void h1940_blueled_set(struct led_classdev *led_dev,
88 enum led_brightness value)
Arnaud Patardbd4009a2007-02-12 23:09:32 +000089{
90 if (value) {
91 /* flashing Blue */
Németh Márton4d404fd2008-03-09 20:59:57 +000092 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
93 s3c2410_gpio_setpin(S3C2410_GPA3, 1);
Arnaud Patardbd4009a2007-02-12 23:09:32 +000094 } else {
Németh Márton4d404fd2008-03-09 20:59:57 +000095 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
96 s3c2410_gpio_setpin(S3C2410_GPA3, 0);
Arnaud Patardbd4009a2007-02-12 23:09:32 +000097 }
98
99}
100
101static struct led_classdev h1940_blueled = {
102 .name = "h1940:blue",
103 .brightness_set = h1940_blueled_set,
104 .default_trigger = "h1940-bluetooth",
105};
106
107static int __init 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
125err_blue:
126 led_classdev_unregister(&h1940_redled);
127err_red:
128 led_classdev_unregister(&h1940_greenled);
129err_green:
130 return ret;
131}
132
133static 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
142static struct platform_driver h1940leds_driver = {
143 .driver = {
144 .name = "h1940-leds",
Kay Sievers3c4ded92008-04-15 14:34:30 -0700145 .owner = THIS_MODULE,
Arnaud Patardbd4009a2007-02-12 23:09:32 +0000146 },
147 .probe = h1940leds_probe,
148 .remove = h1940leds_remove,
149};
150
151
152static int __init h1940leds_init(void)
153{
154 return platform_driver_register(&h1940leds_driver);
155}
156
157static void __exit h1940leds_exit(void)
158{
159 platform_driver_unregister(&h1940leds_driver);
160}
161
162module_init(h1940leds_init);
163module_exit(h1940leds_exit);
164
165MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
166MODULE_DESCRIPTION("LED driver for the iPAQ H1940");
167MODULE_LICENSE("GPL");
Kay Sievers3c4ded92008-04-15 14:34:30 -0700168MODULE_ALIAS("platform:h1940-leds");