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