blob: 081c778a10ac954a3a11a99716a21762cc5292f0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * DIGITAL Shark LED control routines.
3 *
Bryan Wu408a4b22012-03-14 01:31:30 +08004 * Driver for the 3 user LEDs found on the Shark
5 * Based on Versatile and RealView machine LED code
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
Bryan Wu408a4b22012-03-14 01:31:30 +08007 * License terms: GNU General Public License (GPL) version 2
8 * Author: Bryan Wu <bryan.wu@canonical.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Russell Kingfced80c2008-09-06 12:10:45 +010012#include <linux/io.h>
Bryan Wu408a4b22012-03-14 01:31:30 +080013#include <linux/ioport.h>
14#include <linux/slab.h>
15#include <linux/leds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Bryan Wu408a4b22012-03-14 01:31:30 +080017#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Bryan Wu408a4b22012-03-14 01:31:30 +080019#if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
20struct shark_led {
21 struct led_classdev cdev;
22 u8 mask;
23};
Alexander Schulzeab184c2009-01-08 18:05:58 +010024
Bryan Wu408a4b22012-03-14 01:31:30 +080025/*
26 * The triggers lines up below will only be used if the
27 * LED triggers are compiled in.
28 */
29static const struct {
30 const char *name;
31 const char *trigger;
32} shark_leds[] = {
33 { "shark:amber0", "default-on", }, /* Bit 5 */
34 { "shark:green", "heartbeat", }, /* Bit 6 */
35 { "shark:amber1", "cpu0" }, /* Bit 7 */
36};
Alexander Schulzeab184c2009-01-08 18:05:58 +010037
Bryan Wu408a4b22012-03-14 01:31:30 +080038static u16 led_reg_read(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Bryan Wu408a4b22012-03-14 01:31:30 +080040 outw(0x09, 0x24);
41 return inw(0x26);
42}
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Bryan Wu408a4b22012-03-14 01:31:30 +080044static void led_reg_write(u16 value)
45{
46 outw(0x09, 0x24);
47 outw(value, 0x26);
48}
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Bryan Wu408a4b22012-03-14 01:31:30 +080050static void shark_led_set(struct led_classdev *cdev,
51 enum led_brightness b)
52{
53 struct shark_led *led = container_of(cdev,
54 struct shark_led, cdev);
55 u16 reg = led_reg_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Bryan Wu408a4b22012-03-14 01:31:30 +080057 if (b != LED_OFF)
58 reg |= led->mask;
59 else
60 reg &= ~led->mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Bryan Wu408a4b22012-03-14 01:31:30 +080062 led_reg_write(reg);
63}
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Bryan Wu408a4b22012-03-14 01:31:30 +080065static enum led_brightness shark_led_get(struct led_classdev *cdev)
66{
67 struct shark_led *led = container_of(cdev,
68 struct shark_led, cdev);
69 u16 reg = led_reg_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Bryan Wu408a4b22012-03-14 01:31:30 +080071 return (reg & led->mask) ? LED_FULL : LED_OFF;
72}
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bryan Wu408a4b22012-03-14 01:31:30 +080074static int __init shark_leds_init(void)
75{
76 int i;
77 u16 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Bryan Wu408a4b22012-03-14 01:31:30 +080079 if (!machine_is_shark())
80 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Bryan Wu408a4b22012-03-14 01:31:30 +080082 for (i = 0; i < ARRAY_SIZE(shark_leds); i++) {
83 struct shark_led *led;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Bryan Wu408a4b22012-03-14 01:31:30 +080085 led = kzalloc(sizeof(*led), GFP_KERNEL);
86 if (!led)
87 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Bryan Wu408a4b22012-03-14 01:31:30 +080089 led->cdev.name = shark_leds[i].name;
90 led->cdev.brightness_set = shark_led_set;
91 led->cdev.brightness_get = shark_led_get;
92 led->cdev.default_trigger = shark_leds[i].trigger;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Bryan Wu408a4b22012-03-14 01:31:30 +080094 /* Count in 5 bits offset */
95 led->mask = BIT(i + 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Bryan Wu408a4b22012-03-14 01:31:30 +080097 if (led_classdev_register(NULL, &led->cdev) < 0) {
98 kfree(led);
99 break;
100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 /* Make LEDs independent of power-state */
Bryan Wu408a4b22012-03-14 01:31:30 +0800104 request_region(0x24, 4, "led_reg");
105 reg = led_reg_read();
106 reg |= 1 << 10;
107 led_reg_write(reg);
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 return 0;
110}
111
Bryan Wu408a4b22012-03-14 01:31:30 +0800112/*
113 * Since we may have triggers on any subsystem, defer registration
114 * until after subsystem_init.
115 */
116fs_initcall(shark_leds_init);
117#endif