Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / arch / arm / mach-integrator / leds.c
blobcb6ac58f5e078656e26936472a891c00ac3d4ecd
1 /*
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>
7 */
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/io.h>
11 #include <linux/slab.h>
12 #include <linux/leds.h>
14 #include <mach/hardware.h>
15 #include <mach/platform.h>
17 #include "cm.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;
26 u8 mask;
30 * The triggers lines up below will only be used if the
31 * LED triggers are compiled in.
33 static const struct {
34 const char *name;
35 const char *trigger;
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);
51 if (b != LED_OFF)
52 reg |= led->mask;
53 else
54 reg &= ~led->mask;
56 while (__raw_readl(ALPHA_REG) & 1)
57 cpu_relax();
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)
74 if (b != LED_OFF)
75 cm_control(CM_CTRL_LED, CM_CTRL_LED);
76 else
77 cm_control(CM_CTRL_LED, 0);
80 static enum led_brightness cm_led_get(struct led_classdev *cdev)
82 u32 reg = cm_get();
84 return (reg & CM_CTRL_LED) ? LED_FULL : LED_OFF;
87 static int __init integrator_leds_init(void)
89 int i;
91 for (i = 0; i < ARRAY_SIZE(integrator_leds); i++) {
92 struct integrator_led *led;
94 led = kzalloc(sizeof(*led), GFP_KERNEL);
95 if (!led)
96 break;
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;
104 } else {
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;
110 led->mask = BIT(i);
112 if (led_classdev_register(NULL, &led->cdev) < 0) {
113 kfree(led);
114 break;
118 return 0;
122 * Since we may have triggers on any subsystem, defer registration
123 * until after subsystem_init.
125 fs_initcall(integrator_leds_init);
126 #endif