Merge remote-tracking branches 'asoc/fix/atmel', 'asoc/fix/fsl', 'asoc/fix/tegra...
[linux-drm-fsl-dcu.git] / arch / arm / mach-integrator / leds.c
1 /*
2  * Driver for the 4 user LEDs found on the Integrator AP/CP baseboard
3  * Based on Versatile and RealView machine LED code
4  *
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>
13
14 #include <mach/hardware.h>
15 #include <mach/platform.h>
16
17 #include "cm.h"
18
19 #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
20
21 #define ALPHA_REG __io_address(INTEGRATOR_DBG_BASE)
22 #define LEDREG  (__io_address(INTEGRATOR_DBG_BASE) + INTEGRATOR_DBG_LEDS_OFFSET)
23
24 struct integrator_led {
25         struct led_classdev     cdev;
26         u8                      mask;
27 };
28
29 /*
30  * The triggers lines up below will only be used if the
31  * LED triggers are compiled in.
32  */
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", },
42 };
43
44 static void integrator_led_set(struct led_classdev *cdev,
45                               enum led_brightness b)
46 {
47         struct integrator_led *led = container_of(cdev,
48                                                  struct integrator_led, cdev);
49         u32 reg = __raw_readl(LEDREG);
50
51         if (b != LED_OFF)
52                 reg |= led->mask;
53         else
54                 reg &= ~led->mask;
55
56         while (__raw_readl(ALPHA_REG) & 1)
57                 cpu_relax();
58
59         __raw_writel(reg, LEDREG);
60 }
61
62 static enum led_brightness integrator_led_get(struct led_classdev *cdev)
63 {
64         struct integrator_led *led = container_of(cdev,
65                                                  struct integrator_led, cdev);
66         u32 reg = __raw_readl(LEDREG);
67
68         return (reg & led->mask) ? LED_FULL : LED_OFF;
69 }
70
71 static void cm_led_set(struct led_classdev *cdev,
72                               enum led_brightness b)
73 {
74         if (b != LED_OFF)
75                 cm_control(CM_CTRL_LED, CM_CTRL_LED);
76         else
77                 cm_control(CM_CTRL_LED, 0);
78 }
79
80 static enum led_brightness cm_led_get(struct led_classdev *cdev)
81 {
82         u32 reg = cm_get();
83
84         return (reg & CM_CTRL_LED) ? LED_FULL : LED_OFF;
85 }
86
87 static int __init integrator_leds_init(void)
88 {
89         int i;
90
91         for (i = 0; i < ARRAY_SIZE(integrator_leds); i++) {
92                 struct integrator_led *led;
93
94                 led = kzalloc(sizeof(*led), GFP_KERNEL);
95                 if (!led)
96                         break;
97
98
99                 led->cdev.name = integrator_leds[i].name;
100
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;
107                 }
108
109                 led->cdev.default_trigger = integrator_leds[i].trigger;
110                 led->mask = BIT(i);
111
112                 if (led_classdev_register(NULL, &led->cdev) < 0) {
113                         kfree(led);
114                         break;
115                 }
116         }
117
118         return 0;
119 }
120
121 /*
122  * Since we may have triggers on any subsystem, defer registration
123  * until after subsystem_init.
124  */
125 fs_initcall(integrator_leds_init);
126 #endif