]> Pileus Git - ~andy/linux/blob - arch/arm/mach-ks8695/leds.c
Merge branch 'x86-debug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[~andy/linux] / arch / arm / mach-ks8695 / leds.c
1 /*
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 #include <linux/gpio.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14
15 #include <asm/leds.h>
16 #include <mach/devices.h>
17
18
19 static inline void ks8695_led_on(unsigned int led)
20 {
21         gpio_set_value(led, 0);
22 }
23
24 static inline void ks8695_led_off(unsigned int led)
25 {
26         gpio_set_value(led, 1);
27 }
28
29 static inline void ks8695_led_toggle(unsigned int led)
30 {
31         unsigned long is_off = gpio_get_value(led);
32         if (is_off)
33                 ks8695_led_on(led);
34         else
35                 ks8695_led_off(led);
36 }
37
38
39 /*
40  * Handle LED events.
41  */
42 static void ks8695_leds_event(led_event_t evt)
43 {
44         unsigned long flags;
45
46         local_irq_save(flags);
47
48         switch(evt) {
49         case led_start:         /* System startup */
50                 ks8695_led_on(ks8695_leds_cpu);
51                 break;
52
53         case led_stop:          /* System stop / suspend */
54                 ks8695_led_off(ks8695_leds_cpu);
55                 break;
56
57 #ifdef CONFIG_LEDS_TIMER
58         case led_timer:         /* Every 50 timer ticks */
59                 ks8695_led_toggle(ks8695_leds_timer);
60                 break;
61 #endif
62
63 #ifdef CONFIG_LEDS_CPU
64         case led_idle_start:    /* Entering idle state */
65                 ks8695_led_off(ks8695_leds_cpu);
66                 break;
67
68         case led_idle_end:      /* Exit idle state */
69                 ks8695_led_on(ks8695_leds_cpu);
70                 break;
71 #endif
72
73         default:
74                 break;
75         }
76
77         local_irq_restore(flags);
78 }
79
80
81 static int __init leds_init(void)
82 {
83         if ((ks8695_leds_timer == -1) || (ks8695_leds_cpu == -1))
84                 return -ENODEV;
85
86         leds_event = ks8695_leds_event;
87
88         leds_event(led_start);
89         return 0;
90 }
91
92 __initcall(leds_init);