blob: cf1e38458b81c939ae3cf518a5c01ae687b02d79 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/leds-badge4.c
3 *
4 * Author: Christopher Hoover <ch@hpl.hp.com>
5 * Copyright (C) 2002 Hewlett-Packard Company
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
14
Russell Kinga09e64f2008-08-05 16:14:15 +010015#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/leds.h>
17#include <asm/system.h>
18
19#include "leds.h"
20
21#define LED_STATE_ENABLED 1
22#define LED_STATE_CLAIMED 2
23
24static unsigned int led_state;
25static unsigned int hw_led_state;
26
27#define LED_RED GPIO_GPIO(7)
28#define LED_GREEN GPIO_GPIO(9)
29#define LED_MASK (LED_RED|LED_GREEN)
30
31#define LED_IDLE LED_GREEN
32#define LED_TIMER LED_RED
33
34void badge4_leds_event(led_event_t evt)
35{
36 unsigned long flags;
37
38 local_irq_save(flags);
39
40 switch (evt) {
41 case led_start:
42 GPDR |= LED_MASK;
43 hw_led_state = LED_MASK;
44 led_state = LED_STATE_ENABLED;
45 break;
46
47 case led_stop:
48 led_state &= ~LED_STATE_ENABLED;
49 break;
50
51 case led_claim:
52 led_state |= LED_STATE_CLAIMED;
53 hw_led_state = LED_MASK;
54 break;
55
56 case led_release:
57 led_state &= ~LED_STATE_CLAIMED;
58 hw_led_state = LED_MASK;
59 break;
60
61#ifdef CONFIG_LEDS_TIMER
62 case led_timer:
63 if (!(led_state & LED_STATE_CLAIMED))
64 hw_led_state ^= LED_TIMER;
65 break;
66#endif
67
68#ifdef CONFIG_LEDS_CPU
69 case led_idle_start:
70 /* LED off when system is idle */
71 if (!(led_state & LED_STATE_CLAIMED))
72 hw_led_state &= ~LED_IDLE;
73 break;
74
75 case led_idle_end:
76 if (!(led_state & LED_STATE_CLAIMED))
77 hw_led_state |= LED_IDLE;
78 break;
79#endif
80
81 case led_red_on:
82 if (!(led_state & LED_STATE_CLAIMED))
83 hw_led_state &= ~LED_RED;
84 break;
85
86 case led_red_off:
87 if (!(led_state & LED_STATE_CLAIMED))
88 hw_led_state |= LED_RED;
89 break;
90
91 case led_green_on:
92 if (!(led_state & LED_STATE_CLAIMED))
93 hw_led_state &= ~LED_GREEN;
94 break;
95
96 case led_green_off:
97 if (!(led_state & LED_STATE_CLAIMED))
98 hw_led_state |= LED_GREEN;
99 break;
100
101 default:
102 break;
103 }
104
105 if (led_state & LED_STATE_ENABLED) {
106 GPSR = hw_led_state;
107 GPCR = hw_led_state ^ LED_MASK;
108 }
109
110 local_irq_restore(flags);
111}