Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-footbridge/ebsa285.c |
| 3 | * |
| 4 | * EBSA285 machine fixup |
| 5 | */ |
| 6 | #include <linux/init.h> |
Russell King | 43024ed | 2013-11-30 13:41:26 +0000 | [diff] [blame] | 7 | #include <linux/io.h> |
Russell King | 70d13e0 | 2008-12-06 08:25:16 +0000 | [diff] [blame] | 8 | #include <linux/spinlock.h> |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 9 | #include <linux/slab.h> |
| 10 | #include <linux/leds.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | #include <asm/hardware/dec21285.h> |
| 13 | #include <asm/mach-types.h> |
| 14 | |
| 15 | #include <asm/mach/arch.h> |
| 16 | |
| 17 | #include "common.h" |
| 18 | |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 19 | /* LEDs */ |
| 20 | #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS) |
Russell King | 43024ed | 2013-11-30 13:41:26 +0000 | [diff] [blame] | 21 | #define XBUS_AMBER_L BIT(0) |
| 22 | #define XBUS_GREEN_L BIT(1) |
| 23 | #define XBUS_RED_L BIT(2) |
| 24 | #define XBUS_TOGGLE BIT(7) |
| 25 | |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 26 | struct ebsa285_led { |
| 27 | struct led_classdev cdev; |
| 28 | u8 mask; |
| 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * The triggers lines up below will only be used if the |
| 33 | * LED triggers are compiled in. |
| 34 | */ |
| 35 | static const struct { |
| 36 | const char *name; |
| 37 | const char *trigger; |
| 38 | } ebsa285_leds[] = { |
Russell King | 67130c5 | 2013-11-29 00:54:38 +0000 | [diff] [blame] | 39 | { "ebsa285:amber", "cpu0", }, |
| 40 | { "ebsa285:green", "heartbeat", }, |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 41 | { "ebsa285:red",}, |
| 42 | }; |
| 43 | |
Russell King | 67130c5 | 2013-11-29 00:54:38 +0000 | [diff] [blame] | 44 | static unsigned char hw_led_state; |
Russell King | 43024ed | 2013-11-30 13:41:26 +0000 | [diff] [blame] | 45 | static void __iomem *xbus; |
Russell King | 67130c5 | 2013-11-29 00:54:38 +0000 | [diff] [blame] | 46 | |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 47 | static void ebsa285_led_set(struct led_classdev *cdev, |
| 48 | enum led_brightness b) |
| 49 | { |
| 50 | struct ebsa285_led *led = container_of(cdev, |
| 51 | struct ebsa285_led, cdev); |
| 52 | |
Russell King | 67130c5 | 2013-11-29 00:54:38 +0000 | [diff] [blame] | 53 | if (b == LED_OFF) |
| 54 | hw_led_state |= led->mask; |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 55 | else |
Russell King | 67130c5 | 2013-11-29 00:54:38 +0000 | [diff] [blame] | 56 | hw_led_state &= ~led->mask; |
Russell King | 43024ed | 2013-11-30 13:41:26 +0000 | [diff] [blame] | 57 | writeb(hw_led_state, xbus); |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static enum led_brightness ebsa285_led_get(struct led_classdev *cdev) |
| 61 | { |
| 62 | struct ebsa285_led *led = container_of(cdev, |
| 63 | struct ebsa285_led, cdev); |
| 64 | |
Russell King | 67130c5 | 2013-11-29 00:54:38 +0000 | [diff] [blame] | 65 | return hw_led_state & led->mask ? LED_OFF : LED_FULL; |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static int __init ebsa285_leds_init(void) |
| 69 | { |
| 70 | int i; |
| 71 | |
Russell King | 67130c5 | 2013-11-29 00:54:38 +0000 | [diff] [blame] | 72 | if (!machine_is_ebsa285()) |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 73 | return -ENODEV; |
| 74 | |
Russell King | 43024ed | 2013-11-30 13:41:26 +0000 | [diff] [blame] | 75 | xbus = ioremap(XBUS_CS2, SZ_4K); |
| 76 | if (!xbus) |
| 77 | return -ENOMEM; |
| 78 | |
Russell King | 67130c5 | 2013-11-29 00:54:38 +0000 | [diff] [blame] | 79 | /* 3 LEDS all off */ |
Russell King | 43024ed | 2013-11-30 13:41:26 +0000 | [diff] [blame] | 80 | hw_led_state = XBUS_AMBER_L | XBUS_GREEN_L | XBUS_RED_L; |
| 81 | writeb(hw_led_state, xbus); |
Bryan Wu | cf6856d | 2012-03-14 02:05:24 +0800 | [diff] [blame] | 82 | |
| 83 | for (i = 0; i < ARRAY_SIZE(ebsa285_leds); i++) { |
| 84 | struct ebsa285_led *led; |
| 85 | |
| 86 | led = kzalloc(sizeof(*led), GFP_KERNEL); |
| 87 | if (!led) |
| 88 | break; |
| 89 | |
| 90 | led->cdev.name = ebsa285_leds[i].name; |
| 91 | led->cdev.brightness_set = ebsa285_led_set; |
| 92 | led->cdev.brightness_get = ebsa285_led_get; |
| 93 | led->cdev.default_trigger = ebsa285_leds[i].trigger; |
| 94 | led->mask = BIT(i); |
| 95 | |
| 96 | if (led_classdev_register(NULL, &led->cdev) < 0) { |
| 97 | kfree(led); |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Since we may have triggers on any subsystem, defer registration |
| 107 | * until after subsystem_init. |
| 108 | */ |
| 109 | fs_initcall(ebsa285_leds_init); |
| 110 | #endif |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | MACHINE_START(EBSA285, "EBSA285") |
Russell King | e9dea0c | 2005-07-03 17:38:58 +0100 | [diff] [blame] | 113 | /* Maintainer: Russell King */ |
Nicolas Pitre | 93ef888 | 2011-07-05 22:38:11 -0400 | [diff] [blame] | 114 | .atag_offset = 0x100, |
Russell King | e9dea0c | 2005-07-03 17:38:58 +0100 | [diff] [blame] | 115 | .video_start = 0x000a0000, |
| 116 | .video_end = 0x000bffff, |
| 117 | .map_io = footbridge_map_io, |
Russell King | 6cefe92 | 2013-11-29 01:03:35 +0000 | [diff] [blame] | 118 | .init_early = footbridge_sched_clock, |
Russell King | e9dea0c | 2005-07-03 17:38:58 +0100 | [diff] [blame] | 119 | .init_irq = footbridge_init_irq, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 120 | .init_time = footbridge_timer_init, |
Russell King | 6fca1e1 | 2011-11-03 19:47:54 +0000 | [diff] [blame] | 121 | .restart = footbridge_restart, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | MACHINE_END |
| 123 | |