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