1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * linux/arch/arm/mach-footbridge/ebsa285.c
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * EBSA285 machine fixup
61da177e4SLinus Torvalds */
71da177e4SLinus Torvalds #include <linux/init.h>
843024ed6SRussell King #include <linux/io.h>
970d13e08SRussell King #include <linux/spinlock.h>
10cf6856d6SBryan Wu #include <linux/slab.h>
11cf6856d6SBryan Wu #include <linux/leds.h>
121da177e4SLinus Torvalds
131da177e4SLinus Torvalds #include <asm/hardware/dec21285.h>
141da177e4SLinus Torvalds #include <asm/mach-types.h>
151da177e4SLinus Torvalds
161da177e4SLinus Torvalds #include <asm/mach/arch.h>
171da177e4SLinus Torvalds
181da177e4SLinus Torvalds #include "common.h"
191da177e4SLinus Torvalds
20cf6856d6SBryan Wu /* LEDs */
21cf6856d6SBryan Wu #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
2243024ed6SRussell King #define XBUS_AMBER_L BIT(0)
2343024ed6SRussell King #define XBUS_GREEN_L BIT(1)
2443024ed6SRussell King #define XBUS_RED_L BIT(2)
2543024ed6SRussell King #define XBUS_TOGGLE BIT(7)
2643024ed6SRussell King
27cf6856d6SBryan Wu struct ebsa285_led {
28cf6856d6SBryan Wu struct led_classdev cdev;
29cf6856d6SBryan Wu u8 mask;
30cf6856d6SBryan Wu };
31cf6856d6SBryan Wu
32cf6856d6SBryan Wu /*
33cf6856d6SBryan Wu * The triggers lines up below will only be used if the
34cf6856d6SBryan Wu * LED triggers are compiled in.
35cf6856d6SBryan Wu */
36cf6856d6SBryan Wu static const struct {
37cf6856d6SBryan Wu const char *name;
38cf6856d6SBryan Wu const char *trigger;
39cf6856d6SBryan Wu } ebsa285_leds[] = {
4067130c54SRussell King { "ebsa285:amber", "cpu0", },
4167130c54SRussell King { "ebsa285:green", "heartbeat", },
42cf6856d6SBryan Wu { "ebsa285:red",},
43cf6856d6SBryan Wu };
44cf6856d6SBryan Wu
4567130c54SRussell King static unsigned char hw_led_state;
4643024ed6SRussell King static void __iomem *xbus;
4767130c54SRussell King
ebsa285_led_set(struct led_classdev * cdev,enum led_brightness b)48cf6856d6SBryan Wu static void ebsa285_led_set(struct led_classdev *cdev,
49cf6856d6SBryan Wu enum led_brightness b)
50cf6856d6SBryan Wu {
51cf6856d6SBryan Wu struct ebsa285_led *led = container_of(cdev,
52cf6856d6SBryan Wu struct ebsa285_led, cdev);
53cf6856d6SBryan Wu
5467130c54SRussell King if (b == LED_OFF)
5567130c54SRussell King hw_led_state |= led->mask;
56cf6856d6SBryan Wu else
5767130c54SRussell King hw_led_state &= ~led->mask;
5843024ed6SRussell King writeb(hw_led_state, xbus);
59cf6856d6SBryan Wu }
60cf6856d6SBryan Wu
ebsa285_led_get(struct led_classdev * cdev)61cf6856d6SBryan Wu static enum led_brightness ebsa285_led_get(struct led_classdev *cdev)
62cf6856d6SBryan Wu {
63cf6856d6SBryan Wu struct ebsa285_led *led = container_of(cdev,
64cf6856d6SBryan Wu struct ebsa285_led, cdev);
65cf6856d6SBryan Wu
6667130c54SRussell King return hw_led_state & led->mask ? LED_OFF : LED_FULL;
67cf6856d6SBryan Wu }
68cf6856d6SBryan Wu
ebsa285_leds_init(void)69cf6856d6SBryan Wu static int __init ebsa285_leds_init(void)
70cf6856d6SBryan Wu {
71cf6856d6SBryan Wu int i;
72cf6856d6SBryan Wu
7367130c54SRussell King if (!machine_is_ebsa285())
74cf6856d6SBryan Wu return -ENODEV;
75cf6856d6SBryan Wu
7643024ed6SRussell King xbus = ioremap(XBUS_CS2, SZ_4K);
7743024ed6SRussell King if (!xbus)
7843024ed6SRussell King return -ENOMEM;
7943024ed6SRussell King
8067130c54SRussell King /* 3 LEDS all off */
8143024ed6SRussell King hw_led_state = XBUS_AMBER_L | XBUS_GREEN_L | XBUS_RED_L;
8243024ed6SRussell King writeb(hw_led_state, xbus);
83cf6856d6SBryan Wu
84cf6856d6SBryan Wu for (i = 0; i < ARRAY_SIZE(ebsa285_leds); i++) {
85cf6856d6SBryan Wu struct ebsa285_led *led;
86cf6856d6SBryan Wu
87cf6856d6SBryan Wu led = kzalloc(sizeof(*led), GFP_KERNEL);
88cf6856d6SBryan Wu if (!led)
89cf6856d6SBryan Wu break;
90cf6856d6SBryan Wu
91cf6856d6SBryan Wu led->cdev.name = ebsa285_leds[i].name;
92cf6856d6SBryan Wu led->cdev.brightness_set = ebsa285_led_set;
93cf6856d6SBryan Wu led->cdev.brightness_get = ebsa285_led_get;
94cf6856d6SBryan Wu led->cdev.default_trigger = ebsa285_leds[i].trigger;
95cf6856d6SBryan Wu led->mask = BIT(i);
96cf6856d6SBryan Wu
97cf6856d6SBryan Wu if (led_classdev_register(NULL, &led->cdev) < 0) {
98cf6856d6SBryan Wu kfree(led);
99cf6856d6SBryan Wu break;
100cf6856d6SBryan Wu }
101cf6856d6SBryan Wu }
102cf6856d6SBryan Wu
103cf6856d6SBryan Wu return 0;
104cf6856d6SBryan Wu }
105cf6856d6SBryan Wu
106cf6856d6SBryan Wu /*
107cf6856d6SBryan Wu * Since we may have triggers on any subsystem, defer registration
108cf6856d6SBryan Wu * until after subsystem_init.
109cf6856d6SBryan Wu */
110cf6856d6SBryan Wu fs_initcall(ebsa285_leds_init);
111cf6856d6SBryan Wu #endif
112cf6856d6SBryan Wu
1131da177e4SLinus Torvalds MACHINE_START(EBSA285, "EBSA285")
114e9dea0c6SRussell King /* Maintainer: Russell King */
11593ef8883SNicolas Pitre .atag_offset = 0x100,
116e9dea0c6SRussell King .video_start = 0x000a0000,
117e9dea0c6SRussell King .video_end = 0x000bffff,
118e9dea0c6SRussell King .map_io = footbridge_map_io,
1196cefe92fSRussell King .init_early = footbridge_sched_clock,
120e9dea0c6SRussell King .init_irq = footbridge_init_irq,
1216bb27d73SStephen Warren .init_time = footbridge_timer_init,
1226fca1e17SRussell King .restart = footbridge_restart,
1231da177e4SLinus Torvalds MACHINE_END
1241da177e4SLinus Torvalds
125