2 * LED interface for Himalaya, the HTC PocketPC.
6 * Author: Luke Kenneth Casson Leighton, Copyright(C) 2004
8 * Copyright(C) 2004, Luke Kenneth Casson Leighton.
12 * 2004-02-19 Luke Kenneth Casson Leighton created.
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/platform_device.h>
19 #include <linux/leds.h>
20 #include <linux/soc/asic3_base.h>
23 #include <asm/hardware/ipaq-asic3.h>
24 #include <asm/arch/htcuniversal-gpio.h>
25 #include <asm/arch/htcuniversal-asic.h>
26 #include <asm/mach-types.h>
28 #include "htcuniversal_leds.h"
31 #define dprintk(x...) printk(x)
36 struct htcuniversal_led_data
{
43 struct led_properties props
;
46 #define to_htcuniversal_led_data(d) container_of(d, struct htcuniversal_led_data, props)
48 void htcuniversal_set_led (int led
, int brightness
, int duty_time
, int cycle_time
)
50 dprintk("htcuniversal_set__asic3_led\n");
51 if (led
== HTC_RED_LED
|| led
== HTC_GREENR_LED
|| led
== HTC_YELLOW_LED
) {
53 duty_time
=(duty_time
*128+500)/1000;
54 cycle_time
=(cycle_time
*128+500)/1000;
63 asic3_set_led(&htcuniversal_asic3
.dev
, 1, duty_time
, cycle_time
);
66 asic3_set_led(&htcuniversal_asic3
.dev
, 2, duty_time
, cycle_time
);
69 asic3_set_led(&htcuniversal_asic3
.dev
, 1, duty_time
, cycle_time
);
70 asic3_set_led(&htcuniversal_asic3
.dev
, 2, duty_time
, cycle_time
);
72 case HTC_BLUETOOTH_LED
:
74 asic3_set_led(&htcuniversal_asic3
.dev
, 0, duty_time
, cycle_time
);
79 EXPORT_SYMBOL(htcuniversal_set_led
);
82 int htcuniversal_led_brightness_get(struct device
*dev
, struct led_properties
*props
)
84 struct htcuniversal_led_data
*data
= to_htcuniversal_led_data(props
);
86 return data
->brightness
;
89 void htcuniversal_led_brightness_set(struct device
*dev
, struct led_properties
*props
, int value
)
91 /* Brightness levels supported by the hardware: 0 (off) and 100 (on)*/
94 struct htcuniversal_led_data
*data
= to_htcuniversal_led_data(props
);
96 data
->brightness
= value
> 0 ? 100 : 0;
97 if (! data
->brightness
&&
98 (data
->hw_num
== HTC_RED_LED
|| data
->hw_num
== HTC_GREENR_LED
|| data
->hw_num
== HTC_YELLOW_LED
)) {
100 data
->cycle_time
=1000;
102 switch (data
->hw_num
) {
106 htcuniversal_set_led(data
->hw_num
, data
->brightness
, data
->duty_time
, data
->cycle_time
);
108 case HTC_PHONE_BL_LED
:
109 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_BL_KEYP_PWR_ON
, (value
> 0) ? (1<<GPIOD_BL_KEYP_PWR_ON
) : 0);
111 case HTC_KEYBD_BL_LED
:
112 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_BL_KEYB_PWR_ON
, (value
> 0) ? (1<<GPIOD_BL_KEYB_PWR_ON
) : 0);
115 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_VIBRA_PWR_ON
, (value
> 0) ? (1<<GPIOD_VIBRA_PWR_ON
) : 0);
117 case HTC_CAM_FLASH_LED
:
118 asic3_set_gpio_out_a(&htcuniversal_asic3
.dev
, 1<<GPIOA_FLASHLIGHT
, (value
> 0) ? (1<<GPIOA_FLASHLIGHT
) : 0);
120 case HTC_BLUETOOTH_LED
:
122 htcuniversal_egpio_enable(EGPIO5_BT_3V3_ON
);
124 htcuniversal_egpio_disable(EGPIO5_BT_3V3_ON
);
128 htcuniversal_egpio_enable(EGPIO6_WIFI_ON
);
130 htcuniversal_egpio_disable(EGPIO6_WIFI_ON
);
133 printk("brightness=%d for the led=%d\n",value
, data
->hw_num
);
137 htcuniversal_led_cycle_get(struct device
*dev
, struct led_properties
*props
)
139 struct htcuniversal_led_data
*data
= to_htcuniversal_led_data(props
);
141 return data
->cycle_time
;
145 htcuniversal_led_cycle_set(struct device
*dev
, struct led_properties
*props
, int value
)
147 struct htcuniversal_led_data
*data
= to_htcuniversal_led_data(props
);
149 data
->cycle_time
=value
;
150 if (data
->brightness
)
151 htcuniversal_set_led(data
->hw_num
, data
->brightness
, data
->duty_time
, data
->cycle_time
);
156 htcuniversal_led_duty_get(struct device
*dev
, struct led_properties
*props
)
158 struct htcuniversal_led_data
*data
= to_htcuniversal_led_data(props
);
160 return data
->duty_time
;
164 htcuniversal_led_duty_set(struct device
*dev
, struct led_properties
*props
, int value
)
166 struct htcuniversal_led_data
*data
= to_htcuniversal_led_data(props
);
168 data
->duty_time
=value
;
169 if (data
->brightness
)
170 htcuniversal_set_led(data
->hw_num
, data
->brightness
, data
->duty_time
, data
->cycle_time
);
173 static struct htcuniversal_led_data leds
[] = {
179 .owner
= THIS_MODULE
,
182 .brightness_get
= htcuniversal_led_brightness_get
,
183 .brightness_set
= htcuniversal_led_brightness_set
,
187 .hw_num
=HTC_GREENR_LED
,
191 .owner
= THIS_MODULE
,
194 .brightness_get
= htcuniversal_led_brightness_get
,
195 .brightness_set
= htcuniversal_led_brightness_set
,
199 .hw_num
=HTC_YELLOW_LED
,
203 .owner
= THIS_MODULE
,
206 .brightness_get
= htcuniversal_led_brightness_get
,
207 .brightness_set
= htcuniversal_led_brightness_set
,
211 .hw_num
=HTC_PHONE_BL_LED
,
214 .owner
= THIS_MODULE
,
216 .brightness_get
= htcuniversal_led_brightness_get
,
217 .brightness_set
= htcuniversal_led_brightness_set
,
221 .hw_num
=HTC_KEYBD_BL_LED
,
224 .owner
= THIS_MODULE
,
227 .brightness_get
= htcuniversal_led_brightness_get
,
228 .brightness_set
= htcuniversal_led_brightness_set
,
235 .owner
= THIS_MODULE
,
237 .brightness_get
= htcuniversal_led_brightness_get
,
238 .brightness_set
= htcuniversal_led_brightness_set
,
242 .hw_num
=HTC_BLUETOOTH_LED
,
246 .owner
= THIS_MODULE
,
249 .brightness_get
= htcuniversal_led_brightness_get
,
250 .brightness_set
= htcuniversal_led_brightness_set
,
254 .hw_num
=HTC_WIFI_LED
,
258 .owner
= THIS_MODULE
,
260 .color
= "wifi_green",
261 .brightness_get
= htcuniversal_led_brightness_get
,
262 .brightness_set
= htcuniversal_led_brightness_set
,
266 .hw_num
=HTC_CAM_FLASH_LED
,
268 .owner
= THIS_MODULE
,
269 .name
= "flashlight",
271 .brightness_get
= htcuniversal_led_brightness_get
,
272 .brightness_set
= htcuniversal_led_brightness_set
,
277 static int htcuniversal_led_probe(struct device
*dev
)
281 dprintk("htcuniversal_led_probe\n");
282 /* Turn on the LED controllers in CDEX */
283 asic3_set_clock_cdex(&htcuniversal_asic3
.dev
,
284 CLOCK_CDEX_LED0
| CLOCK_CDEX_LED1
| CLOCK_CDEX_LED2
,
285 CLOCK_CDEX_LED0
| CLOCK_CDEX_LED1
| CLOCK_CDEX_LED2
288 htcuniversal_set_led(HTC_RED_LED
, 0, 0, 0);
289 htcuniversal_set_led(HTC_GREENR_LED
, 0, 0, 0);
290 htcuniversal_set_led(HTC_YELLOW_LED
, 0, 0, 0);
291 htcuniversal_set_led(HTC_PHONE_BL_LED
, 0, 0, 0);
292 htcuniversal_set_led(HTC_KEYBD_BL_LED
, 0, 0, 0);
293 htcuniversal_set_led(HTC_VIBRA
, 0, 0, 0);
294 htcuniversal_set_led(HTC_BLUETOOTH_LED
, 0, 0, 0);
295 htcuniversal_set_led(HTC_WIFI_LED
, 0, 0, 0);
296 htcuniversal_set_led(HTC_CAM_FLASH_LED
, 0, 0, 0);
298 for (i
= 0; i
< ARRAY_SIZE(leds
); i
++) {
299 ret
= leds_device_register(dev
, &leds
[i
].props
);
300 leds
[i
].registered
= 1;
302 printk(KERN_WARNING
"Unable to register htcuniversal led %s\n", leds
[i
].props
.color
);
303 leds
[i
].registered
= 0;
309 static int htcuniversal_led_remove(struct device
*dev
)
313 dprintk("htcuniversal_led_remove\n");
315 for (i
= 0; i
< ARRAY_SIZE(leds
); i
++) {
316 if (leds
[i
].registered
) {
317 leds_device_unregister(&leds
[i
].props
);
324 htcuniversal_led_suspend(struct device
*dev
, u32 state
, u32 level
)
326 /* Turn off the LED controllers in CDEX */
327 asic3_set_clock_cdex(&htcuniversal_asic3
.dev
,
328 ~CLOCK_CDEX_LED0
& ~CLOCK_CDEX_LED1
& ~CLOCK_CDEX_LED2
,
329 ~CLOCK_CDEX_LED0
& ~CLOCK_CDEX_LED1
& ~CLOCK_CDEX_LED2
331 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_BL_KEYP_PWR_ON
, 0);
332 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_BL_KEYB_PWR_ON
, 0);
333 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_VIBRA_PWR_ON
, 0);
339 htcuniversal_led_resume(struct device
*dev
, u32 level
)
341 /* Turn on the LED controllers in CDEX */
342 asic3_set_clock_cdex(&htcuniversal_asic3
.dev
,
343 CLOCK_CDEX_LED0
| CLOCK_CDEX_LED1
| CLOCK_CDEX_LED2
,
344 CLOCK_CDEX_LED0
| CLOCK_CDEX_LED1
| CLOCK_CDEX_LED2
347 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_BL_KEYP_PWR_ON
, leds
[HTC_PHONE_BL_LED
].brightness
? (1<<GPIOD_BL_KEYP_PWR_ON
) : 0);
348 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_BL_KEYB_PWR_ON
, leds
[HTC_KEYBD_BL_LED
].brightness
? (1<<GPIOD_BL_KEYB_PWR_ON
) : 0);
349 asic3_set_gpio_out_d(&htcuniversal_asic3
.dev
, 1<<GPIOD_VIBRA_PWR_ON
, leds
[HTC_VIBRA
].brightness
? (1<<GPIOD_VIBRA_PWR_ON
) : 0);
355 static struct device_driver htcuniversal_led_driver
= {
356 .name
= "htcuniversal_led",
357 .probe
= htcuniversal_led_probe
,
358 .remove
= htcuniversal_led_remove
,
359 .suspend
= htcuniversal_led_suspend
,
360 .resume
= htcuniversal_led_resume
,
361 .bus
= &platform_bus_type
,
365 static struct platform_device htcuniversal_led_dev
= {
366 .name
= "htcuniversal_led",
370 static int htcuniversal_led_init (void)
374 if (! machine_is_htcuniversal() )
377 ret
=driver_register(&htcuniversal_led_driver
);
379 ret
=platform_device_register(&htcuniversal_led_dev
);
383 static void htcuniversal_led_exit (void)
385 platform_device_unregister(&htcuniversal_led_dev
);
386 driver_unregister(&htcuniversal_led_driver
);
389 module_init (htcuniversal_led_init
);
390 module_exit (htcuniversal_led_exit
);
392 MODULE_LICENSE("GPL");