1 /*
2  *  linux/arch/arm/mach-integrator/leds.c
3  *
4  *  Integrator LED control routines
5  *
6  *  Copyright (C) 1999 ARM Limited
7  *  Copyright (C) 2000 Deep Blue Solutions Ltd
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 
26 #include <asm/hardware.h>
27 #include <asm/io.h>
28 #include <asm/leds.h>
29 #include <asm/system.h>
30 #include <asm/mach-types.h>
31 
32 static int saved_leds;
33 
integrator_leds_event(led_event_t ledevt)34 static void integrator_leds_event(led_event_t ledevt)
35 {
36 	unsigned long flags;
37 	const unsigned int dbg_base = IO_ADDRESS(INTEGRATOR_DBG_BASE);
38 	const unsigned int hdr_ctrl = IO_ADDRESS(INTEGRATOR_HDR_BASE) +
39 					INTEGRATOR_HDR_CTRL_OFFSET;
40 	unsigned int ctrl;
41 	unsigned int update_alpha_leds;
42 
43 	// yup, change the LEDs
44 	local_irq_save(flags);
45 	update_alpha_leds = 0;
46 
47 	switch(ledevt) {
48 	case led_idle_start:
49 		ctrl = __raw_readl(hdr_ctrl);
50 		ctrl &= ~INTEGRATOR_HDR_CTRL_LED;
51 		__raw_writel(ctrl, hdr_ctrl);
52 		break;
53 
54 	case led_idle_end:
55 		ctrl = __raw_readl(hdr_ctrl);
56 		ctrl |= INTEGRATOR_HDR_CTRL_LED;
57 		__raw_writel(ctrl, hdr_ctrl);
58 		break;
59 
60 	case led_timer:
61 		saved_leds ^= GREEN_LED;
62 		update_alpha_leds = 1;
63 		break;
64 
65 	case led_red_on:
66 		saved_leds |= RED_LED;
67 		update_alpha_leds = 1;
68 		break;
69 
70 	case led_red_off:
71 		saved_leds &= ~RED_LED;
72 		update_alpha_leds = 1;
73 		break;
74 
75 	default:
76 		break;
77 	}
78 
79 	if (update_alpha_leds) {
80 		while (__raw_readl(dbg_base + INTEGRATOR_DBG_ALPHA_OFFSET) & 1);
81 		__raw_writel(saved_leds, dbg_base + INTEGRATOR_DBG_LEDS_OFFSET);
82 	}
83 	local_irq_restore(flags);
84 }
85 
leds_init(void)86 static int __init leds_init(void)
87 {
88 	if (machine_is_integrator())
89 		leds_event = integrator_leds_event;
90 
91 	return 0;
92 }
93 
94 __initcall(leds_init);
95