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>
14 #include <mach/hardware.h>
15 #include <mach/platform.h>
19 #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
21 #define ALPHA_REG __io_address(INTEGRATOR_DBG_BASE)
22 #define LEDREG (__io_address(INTEGRATOR_DBG_BASE) + INTEGRATOR_DBG_LEDS_OFFSET)
24 struct integrator_led
{
25 struct led_classdev cdev
;
30 * The triggers lines up below will only be used if the
31 * LED triggers are compiled in.
36 } integrator_leds
[] = {
37 { "integrator:green0", "heartbeat", },
38 { "integrator:yellow", },
39 { "integrator:red", },
40 { "integrator:green1", },
41 { "integrator:core_module", "cpu0", },
44 static void integrator_led_set(struct led_classdev
*cdev
,
45 enum led_brightness b
)
47 struct integrator_led
*led
= container_of(cdev
,
48 struct integrator_led
, cdev
);
49 u32 reg
= __raw_readl(LEDREG
);
56 while (__raw_readl(ALPHA_REG
) & 1)
59 __raw_writel(reg
, LEDREG
);
62 static enum led_brightness
integrator_led_get(struct led_classdev
*cdev
)
64 struct integrator_led
*led
= container_of(cdev
,
65 struct integrator_led
, cdev
);
66 u32 reg
= __raw_readl(LEDREG
);
68 return (reg
& led
->mask
) ? LED_FULL
: LED_OFF
;
71 static void cm_led_set(struct led_classdev
*cdev
,
72 enum led_brightness b
)
75 cm_control(CM_CTRL_LED
, CM_CTRL_LED
);
77 cm_control(CM_CTRL_LED
, 0);
80 static enum led_brightness
cm_led_get(struct led_classdev
*cdev
)
84 return (reg
& CM_CTRL_LED
) ? LED_FULL
: LED_OFF
;
87 static int __init
integrator_leds_init(void)
91 for (i
= 0; i
< ARRAY_SIZE(integrator_leds
); i
++) {
92 struct integrator_led
*led
;
94 led
= kzalloc(sizeof(*led
), GFP_KERNEL
);
99 led
->cdev
.name
= integrator_leds
[i
].name
;
101 if (i
== 4) { /* Setting for LED in core module */
102 led
->cdev
.brightness_set
= cm_led_set
;
103 led
->cdev
.brightness_get
= cm_led_get
;
105 led
->cdev
.brightness_set
= integrator_led_set
;
106 led
->cdev
.brightness_get
= integrator_led_get
;
109 led
->cdev
.default_trigger
= integrator_leds
[i
].trigger
;
112 if (led_classdev_register(NULL
, &led
->cdev
) < 0) {
122 * Since we may have triggers on any subsystem, defer registration
123 * until after subsystem_init.
125 fs_initcall(integrator_leds_init
);