blob: 184ef74e4bee53151666d7d26396964d7c36bcb6 [file] [log] [blame]
Andrew Victorfdb72fd2008-04-15 21:13:33 +01001/*
2 * LED driver for KS8695-based boards.
3 *
4 * Copyright (C) Andrew Victor
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 version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/init.h>
14
Andrew Victorfdb72fd2008-04-15 21:13:33 +010015#include <asm/leds.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010016#include <mach/devices.h>
17#include <mach/gpio.h>
Andrew Victorfdb72fd2008-04-15 21:13:33 +010018
19
20static inline void ks8695_led_on(unsigned int led)
21{
22 gpio_set_value(led, 0);
23}
24
25static inline void ks8695_led_off(unsigned int led)
26{
27 gpio_set_value(led, 1);
28}
29
30static inline void ks8695_led_toggle(unsigned int led)
31{
32 unsigned long is_off = gpio_get_value(led);
33 if (is_off)
34 ks8695_led_on(led);
35 else
36 ks8695_led_off(led);
37}
38
39
40/*
41 * Handle LED events.
42 */
43static void ks8695_leds_event(led_event_t evt)
44{
45 unsigned long flags;
46
47 local_irq_save(flags);
48
49 switch(evt) {
50 case led_start: /* System startup */
51 ks8695_led_on(ks8695_leds_cpu);
52 break;
53
54 case led_stop: /* System stop / suspend */
55 ks8695_led_off(ks8695_leds_cpu);
56 break;
57
58#ifdef CONFIG_LEDS_TIMER
59 case led_timer: /* Every 50 timer ticks */
60 ks8695_led_toggle(ks8695_leds_timer);
61 break;
62#endif
63
64#ifdef CONFIG_LEDS_CPU
65 case led_idle_start: /* Entering idle state */
66 ks8695_led_off(ks8695_leds_cpu);
67 break;
68
69 case led_idle_end: /* Exit idle state */
70 ks8695_led_on(ks8695_leds_cpu);
71 break;
72#endif
73
74 default:
75 break;
76 }
77
78 local_irq_restore(flags);
79}
80
81
82static int __init leds_init(void)
83{
84 if ((ks8695_leds_timer == -1) || (ks8695_leds_cpu == -1))
85 return -ENODEV;
86
87 leds_event = ks8695_leds_event;
88
89 leds_event(led_start);
90 return 0;
91}
92
93__initcall(leds_init);