2 * Driver for the 4 user LEDs found on the Integrator AP/CP baseboard
3 * Based on Versatile and RealView machine LED code
5 * License terms: GNU General Public License (GPL) version 2
6 * Author: Bryan Wu <bryan.wu@canonical.com>
8 #include <linux/kernel.h>
9 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/leds.h>
15 #include <mach/hardware.h>
16 #include <mach/platform.h>
18 #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
20 #define ALPHA_REG __io_address(INTEGRATOR_DBG_BASE)
21 #define LEDREG (__io_address(INTEGRATOR_DBG_BASE) + INTEGRATOR_DBG_LEDS_OFFSET)
23 struct integrator_led
{
24 struct led_classdev cdev
;
29 * The triggers lines up below will only be used if the
30 * LED triggers are compiled in.
35 } integrator_leds
[] = {
36 { "integrator:green0", "heartbeat", },
37 { "integrator:yellow", },
38 { "integrator:red", },
39 { "integrator:green1", },
40 { "integrator:core_module", "cpu0", },
43 static void integrator_led_set(struct led_classdev
*cdev
,
44 enum led_brightness b
)
46 struct integrator_led
*led
= container_of(cdev
,
47 struct integrator_led
, cdev
);
48 u32 reg
= __raw_readl(LEDREG
);
55 while (__raw_readl(ALPHA_REG
) & 1)
58 __raw_writel(reg
, LEDREG
);
61 static enum led_brightness
integrator_led_get(struct led_classdev
*cdev
)
63 struct integrator_led
*led
= container_of(cdev
,
64 struct integrator_led
, cdev
);
65 u32 reg
= __raw_readl(LEDREG
);
67 return (reg
& led
->mask
) ? LED_FULL
: LED_OFF
;
70 static void cm_led_set(struct led_classdev
*cdev
,
71 enum led_brightness b
)
74 cm_control(CM_CTRL_LED
, CM_CTRL_LED
);
76 cm_control(CM_CTRL_LED
, 0);
79 static enum led_brightness
cm_led_get(struct led_classdev
*cdev
)
81 u32 reg
= readl(CM_CTRL
);
83 return (reg
& CM_CTRL_LED
) ? LED_FULL
: LED_OFF
;
86 static int __init
integrator_leds_init(void)
90 for (i
= 0; i
< ARRAY_SIZE(integrator_leds
); i
++) {
91 struct integrator_led
*led
;
93 led
= kzalloc(sizeof(*led
), GFP_KERNEL
);
98 led
->cdev
.name
= integrator_leds
[i
].name
;
100 if (i
== 4) { /* Setting for LED in core module */
101 led
->cdev
.brightness_set
= cm_led_set
;
102 led
->cdev
.brightness_get
= cm_led_get
;
104 led
->cdev
.brightness_set
= integrator_led_set
;
105 led
->cdev
.brightness_get
= integrator_led_get
;
108 led
->cdev
.default_trigger
= integrator_leds
[i
].trigger
;
111 if (led_classdev_register(NULL
, &led
->cdev
) < 0) {
121 * Since we may have triggers on any subsystem, defer registration
122 * until after subsystem_init.
124 fs_initcall(integrator_leds_init
);