Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for BCM6328 memory-mapped LEDs, based on leds-syscon.c |
| 3 | * |
| 4 | * Copyright 2015 Álvaro Fernández Rojas <noltari@gmail.com> |
| 5 | * Copyright 2015 Jonas Gorski <jogo@openwrt.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | */ |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/leds.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/of.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | |
| 19 | #define BCM6328_REG_INIT 0x00 |
| 20 | #define BCM6328_REG_MODE_HI 0x04 |
| 21 | #define BCM6328_REG_MODE_LO 0x08 |
| 22 | #define BCM6328_REG_HWDIS 0x0c |
| 23 | #define BCM6328_REG_STROBE 0x10 |
| 24 | #define BCM6328_REG_LNKACTSEL_HI 0x14 |
| 25 | #define BCM6328_REG_LNKACTSEL_LO 0x18 |
| 26 | #define BCM6328_REG_RBACK 0x1c |
| 27 | #define BCM6328_REG_SERMUX 0x20 |
| 28 | |
| 29 | #define BCM6328_LED_MAX_COUNT 24 |
| 30 | #define BCM6328_LED_DEF_DELAY 500 |
| 31 | #define BCM6328_LED_INTERVAL_MS 20 |
| 32 | |
| 33 | #define BCM6328_LED_INTV_MASK 0x3f |
| 34 | #define BCM6328_LED_FAST_INTV_SHIFT 6 |
| 35 | #define BCM6328_LED_FAST_INTV_MASK (BCM6328_LED_INTV_MASK << \ |
| 36 | BCM6328_LED_FAST_INTV_SHIFT) |
| 37 | #define BCM6328_SERIAL_LED_EN BIT(12) |
| 38 | #define BCM6328_SERIAL_LED_MUX BIT(13) |
| 39 | #define BCM6328_SERIAL_LED_CLK_NPOL BIT(14) |
| 40 | #define BCM6328_SERIAL_LED_DATA_PPOL BIT(15) |
| 41 | #define BCM6328_SERIAL_LED_SHIFT_DIR BIT(16) |
| 42 | #define BCM6328_LED_SHIFT_TEST BIT(30) |
| 43 | #define BCM6328_LED_TEST BIT(31) |
Álvaro Fernández Rojas | 9f82c77 | 2015-10-08 12:35:54 +0200 | [diff] [blame] | 44 | #define BCM6328_INIT_MASK (BCM6328_SERIAL_LED_EN | \ |
Álvaro Fernández Rojas | 41251e2 | 2015-12-15 21:03:45 +0100 | [diff] [blame] | 45 | BCM6328_SERIAL_LED_MUX | \ |
Álvaro Fernández Rojas | 9f82c77 | 2015-10-08 12:35:54 +0200 | [diff] [blame] | 46 | BCM6328_SERIAL_LED_CLK_NPOL | \ |
| 47 | BCM6328_SERIAL_LED_DATA_PPOL | \ |
| 48 | BCM6328_SERIAL_LED_SHIFT_DIR) |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 49 | |
| 50 | #define BCM6328_LED_MODE_MASK 3 |
Simon Arlott | b964c5b | 2015-11-15 13:34:37 +0000 | [diff] [blame] | 51 | #define BCM6328_LED_MODE_ON 0 |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 52 | #define BCM6328_LED_MODE_FAST 1 |
| 53 | #define BCM6328_LED_MODE_BLINK 2 |
Simon Arlott | b964c5b | 2015-11-15 13:34:37 +0000 | [diff] [blame] | 54 | #define BCM6328_LED_MODE_OFF 3 |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 55 | #define BCM6328_LED_SHIFT(X) ((X) << 1) |
| 56 | |
| 57 | /** |
| 58 | * struct bcm6328_led - state container for bcm6328 based LEDs |
| 59 | * @cdev: LED class device for this LED |
| 60 | * @mem: memory resource |
| 61 | * @lock: memory lock |
| 62 | * @pin: LED pin number |
| 63 | * @blink_leds: blinking LEDs |
| 64 | * @blink_delay: blinking delay |
| 65 | * @active_low: LED is active low |
| 66 | */ |
| 67 | struct bcm6328_led { |
| 68 | struct led_classdev cdev; |
| 69 | void __iomem *mem; |
| 70 | spinlock_t *lock; |
| 71 | unsigned long pin; |
| 72 | unsigned long *blink_leds; |
| 73 | unsigned long *blink_delay; |
| 74 | bool active_low; |
| 75 | }; |
| 76 | |
| 77 | static void bcm6328_led_write(void __iomem *reg, unsigned long data) |
| 78 | { |
Álvaro Fernández Rojas | a06cd4b | 2015-12-15 21:03:49 +0100 | [diff] [blame] | 79 | #ifdef CONFIG_CPU_BIG_ENDIAN |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 80 | iowrite32be(data, reg); |
Álvaro Fernández Rojas | a06cd4b | 2015-12-15 21:03:49 +0100 | [diff] [blame] | 81 | #else |
| 82 | writel(data, reg); |
| 83 | #endif |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static unsigned long bcm6328_led_read(void __iomem *reg) |
| 87 | { |
Álvaro Fernández Rojas | a06cd4b | 2015-12-15 21:03:49 +0100 | [diff] [blame] | 88 | #ifdef CONFIG_CPU_BIG_ENDIAN |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 89 | return ioread32be(reg); |
Álvaro Fernández Rojas | a06cd4b | 2015-12-15 21:03:49 +0100 | [diff] [blame] | 90 | #else |
| 91 | return readl(reg); |
| 92 | #endif |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * LEDMode 64 bits / 24 LEDs |
| 97 | * bits [31:0] -> LEDs 8-23 |
| 98 | * bits [47:32] -> LEDs 0-7 |
| 99 | * bits [63:48] -> unused |
| 100 | */ |
| 101 | static unsigned long bcm6328_pin2shift(unsigned long pin) |
| 102 | { |
| 103 | if (pin < 8) |
| 104 | return pin + 16; /* LEDs 0-7 (bits 47:32) */ |
| 105 | else |
| 106 | return pin - 8; /* LEDs 8-23 (bits 31:0) */ |
| 107 | } |
| 108 | |
| 109 | static void bcm6328_led_mode(struct bcm6328_led *led, unsigned long value) |
| 110 | { |
| 111 | void __iomem *mode; |
| 112 | unsigned long val, shift; |
| 113 | |
| 114 | shift = bcm6328_pin2shift(led->pin); |
| 115 | if (shift / 16) |
| 116 | mode = led->mem + BCM6328_REG_MODE_HI; |
| 117 | else |
| 118 | mode = led->mem + BCM6328_REG_MODE_LO; |
| 119 | |
| 120 | val = bcm6328_led_read(mode); |
| 121 | val &= ~(BCM6328_LED_MODE_MASK << BCM6328_LED_SHIFT(shift % 16)); |
| 122 | val |= (value << BCM6328_LED_SHIFT(shift % 16)); |
| 123 | bcm6328_led_write(mode, val); |
| 124 | } |
| 125 | |
| 126 | static void bcm6328_led_set(struct led_classdev *led_cdev, |
| 127 | enum led_brightness value) |
| 128 | { |
| 129 | struct bcm6328_led *led = |
| 130 | container_of(led_cdev, struct bcm6328_led, cdev); |
| 131 | unsigned long flags; |
| 132 | |
| 133 | spin_lock_irqsave(led->lock, flags); |
| 134 | *(led->blink_leds) &= ~BIT(led->pin); |
| 135 | if ((led->active_low && value == LED_OFF) || |
| 136 | (!led->active_low && value != LED_OFF)) |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 137 | bcm6328_led_mode(led, BCM6328_LED_MODE_ON); |
Simon Arlott | b964c5b | 2015-11-15 13:34:37 +0000 | [diff] [blame] | 138 | else |
| 139 | bcm6328_led_mode(led, BCM6328_LED_MODE_OFF); |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 140 | spin_unlock_irqrestore(led->lock, flags); |
| 141 | } |
| 142 | |
| 143 | static int bcm6328_blink_set(struct led_classdev *led_cdev, |
| 144 | unsigned long *delay_on, unsigned long *delay_off) |
| 145 | { |
| 146 | struct bcm6328_led *led = |
| 147 | container_of(led_cdev, struct bcm6328_led, cdev); |
| 148 | unsigned long delay, flags; |
Álvaro Fernández Rojas | 143b77c | 2015-12-15 21:03:51 +0100 | [diff] [blame^] | 149 | int rc; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 150 | |
| 151 | if (!*delay_on) |
| 152 | *delay_on = BCM6328_LED_DEF_DELAY; |
| 153 | if (!*delay_off) |
| 154 | *delay_off = BCM6328_LED_DEF_DELAY; |
| 155 | |
| 156 | if (*delay_on != *delay_off) { |
| 157 | dev_dbg(led_cdev->dev, |
| 158 | "fallback to soft blinking (delay_on != delay_off)\n"); |
| 159 | return -EINVAL; |
| 160 | } |
| 161 | |
| 162 | delay = *delay_on / BCM6328_LED_INTERVAL_MS; |
Álvaro Fernández Rojas | 41251e2 | 2015-12-15 21:03:45 +0100 | [diff] [blame] | 163 | if (delay == 0) { |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 164 | delay = 1; |
Álvaro Fernández Rojas | 41251e2 | 2015-12-15 21:03:45 +0100 | [diff] [blame] | 165 | } else if (delay > BCM6328_LED_INTV_MASK) { |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 166 | dev_dbg(led_cdev->dev, |
| 167 | "fallback to soft blinking (delay > %ums)\n", |
| 168 | BCM6328_LED_INTV_MASK * BCM6328_LED_INTERVAL_MS); |
| 169 | return -EINVAL; |
| 170 | } |
| 171 | |
| 172 | spin_lock_irqsave(led->lock, flags); |
| 173 | if (*(led->blink_leds) == 0 || |
| 174 | *(led->blink_leds) == BIT(led->pin) || |
| 175 | *(led->blink_delay) == delay) { |
| 176 | unsigned long val; |
| 177 | |
| 178 | *(led->blink_leds) |= BIT(led->pin); |
| 179 | *(led->blink_delay) = delay; |
| 180 | |
| 181 | val = bcm6328_led_read(led->mem + BCM6328_REG_INIT); |
| 182 | val &= ~BCM6328_LED_FAST_INTV_MASK; |
| 183 | val |= (delay << BCM6328_LED_FAST_INTV_SHIFT); |
| 184 | bcm6328_led_write(led->mem + BCM6328_REG_INIT, val); |
| 185 | |
| 186 | bcm6328_led_mode(led, BCM6328_LED_MODE_BLINK); |
Álvaro Fernández Rojas | 143b77c | 2015-12-15 21:03:51 +0100 | [diff] [blame^] | 187 | rc = 0; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 188 | } else { |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 189 | dev_dbg(led_cdev->dev, |
| 190 | "fallback to soft blinking (delay already set)\n"); |
Álvaro Fernández Rojas | 143b77c | 2015-12-15 21:03:51 +0100 | [diff] [blame^] | 191 | rc = -EINVAL; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 192 | } |
Álvaro Fernández Rojas | 143b77c | 2015-12-15 21:03:51 +0100 | [diff] [blame^] | 193 | spin_unlock_irqrestore(led->lock, flags); |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 194 | |
Álvaro Fernández Rojas | 143b77c | 2015-12-15 21:03:51 +0100 | [diff] [blame^] | 195 | return rc; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static int bcm6328_hwled(struct device *dev, struct device_node *nc, u32 reg, |
| 199 | void __iomem *mem, spinlock_t *lock) |
| 200 | { |
| 201 | int i, cnt; |
| 202 | unsigned long flags, val; |
| 203 | |
| 204 | spin_lock_irqsave(lock, flags); |
| 205 | val = bcm6328_led_read(mem + BCM6328_REG_HWDIS); |
| 206 | val &= ~BIT(reg); |
| 207 | bcm6328_led_write(mem + BCM6328_REG_HWDIS, val); |
| 208 | spin_unlock_irqrestore(lock, flags); |
| 209 | |
| 210 | /* Only LEDs 0-7 can be activity/link controlled */ |
| 211 | if (reg >= 8) |
| 212 | return 0; |
| 213 | |
| 214 | cnt = of_property_count_elems_of_size(nc, "brcm,link-signal-sources", |
| 215 | sizeof(u32)); |
| 216 | for (i = 0; i < cnt; i++) { |
| 217 | u32 sel; |
| 218 | void __iomem *addr; |
| 219 | |
| 220 | if (reg < 4) |
| 221 | addr = mem + BCM6328_REG_LNKACTSEL_LO; |
| 222 | else |
| 223 | addr = mem + BCM6328_REG_LNKACTSEL_HI; |
| 224 | |
| 225 | of_property_read_u32_index(nc, "brcm,link-signal-sources", i, |
| 226 | &sel); |
| 227 | |
| 228 | if (reg / 4 != sel / 4) { |
| 229 | dev_warn(dev, "invalid link signal source\n"); |
| 230 | continue; |
| 231 | } |
| 232 | |
| 233 | spin_lock_irqsave(lock, flags); |
| 234 | val = bcm6328_led_read(addr); |
| 235 | val |= (BIT(reg) << (((sel % 4) * 4) + 16)); |
| 236 | bcm6328_led_write(addr, val); |
| 237 | spin_unlock_irqrestore(lock, flags); |
| 238 | } |
| 239 | |
| 240 | cnt = of_property_count_elems_of_size(nc, |
| 241 | "brcm,activity-signal-sources", |
| 242 | sizeof(u32)); |
| 243 | for (i = 0; i < cnt; i++) { |
| 244 | u32 sel; |
| 245 | void __iomem *addr; |
| 246 | |
| 247 | if (reg < 4) |
| 248 | addr = mem + BCM6328_REG_LNKACTSEL_LO; |
| 249 | else |
| 250 | addr = mem + BCM6328_REG_LNKACTSEL_HI; |
| 251 | |
| 252 | of_property_read_u32_index(nc, "brcm,activity-signal-sources", |
| 253 | i, &sel); |
| 254 | |
| 255 | if (reg / 4 != sel / 4) { |
| 256 | dev_warn(dev, "invalid activity signal source\n"); |
| 257 | continue; |
| 258 | } |
| 259 | |
| 260 | spin_lock_irqsave(lock, flags); |
| 261 | val = bcm6328_led_read(addr); |
| 262 | val |= (BIT(reg) << ((sel % 4) * 4)); |
| 263 | bcm6328_led_write(addr, val); |
| 264 | spin_unlock_irqrestore(lock, flags); |
| 265 | } |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, |
| 271 | void __iomem *mem, spinlock_t *lock, |
| 272 | unsigned long *blink_leds, unsigned long *blink_delay) |
| 273 | { |
| 274 | struct bcm6328_led *led; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 275 | const char *state; |
| 276 | int rc; |
| 277 | |
| 278 | led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); |
| 279 | if (!led) |
| 280 | return -ENOMEM; |
| 281 | |
| 282 | led->pin = reg; |
| 283 | led->mem = mem; |
| 284 | led->lock = lock; |
| 285 | led->blink_leds = blink_leds; |
| 286 | led->blink_delay = blink_delay; |
| 287 | |
| 288 | if (of_property_read_bool(nc, "active-low")) |
| 289 | led->active_low = true; |
| 290 | |
| 291 | led->cdev.name = of_get_property(nc, "label", NULL) ? : nc->name; |
| 292 | led->cdev.default_trigger = of_get_property(nc, |
| 293 | "linux,default-trigger", |
| 294 | NULL); |
| 295 | |
| 296 | if (!of_property_read_string(nc, "default-state", &state)) { |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 297 | if (!strcmp(state, "on")) { |
| 298 | led->cdev.brightness = LED_FULL; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 299 | } else if (!strcmp(state, "keep")) { |
| 300 | void __iomem *mode; |
| 301 | unsigned long val, shift; |
| 302 | |
| 303 | shift = bcm6328_pin2shift(led->pin); |
| 304 | if (shift / 16) |
| 305 | mode = mem + BCM6328_REG_MODE_HI; |
| 306 | else |
| 307 | mode = mem + BCM6328_REG_MODE_LO; |
| 308 | |
Álvaro Fernández Rojas | d8fe160 | 2015-10-08 12:35:53 +0200 | [diff] [blame] | 309 | val = bcm6328_led_read(mode) >> |
| 310 | BCM6328_LED_SHIFT(shift % 16); |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 311 | val &= BCM6328_LED_MODE_MASK; |
Simon Arlott | b964c5b | 2015-11-15 13:34:37 +0000 | [diff] [blame] | 312 | if ((led->active_low && val == BCM6328_LED_MODE_OFF) || |
| 313 | (!led->active_low && val == BCM6328_LED_MODE_ON)) |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 314 | led->cdev.brightness = LED_FULL; |
Álvaro Fernández Rojas | d8fe160 | 2015-10-08 12:35:53 +0200 | [diff] [blame] | 315 | else |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 316 | led->cdev.brightness = LED_OFF; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 317 | } else { |
| 318 | led->cdev.brightness = LED_OFF; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 319 | } |
Álvaro Fernández Rojas | d8fe160 | 2015-10-08 12:35:53 +0200 | [diff] [blame] | 320 | } else { |
| 321 | led->cdev.brightness = LED_OFF; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 322 | } |
Álvaro Fernández Rojas | d8fe160 | 2015-10-08 12:35:53 +0200 | [diff] [blame] | 323 | |
Simon Arlott | 9d3c066 | 2015-11-16 20:24:59 +0000 | [diff] [blame] | 324 | bcm6328_led_set(&led->cdev, led->cdev.brightness); |
| 325 | |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 326 | led->cdev.brightness_set = bcm6328_led_set; |
| 327 | led->cdev.blink_set = bcm6328_blink_set; |
| 328 | |
| 329 | rc = led_classdev_register(dev, &led->cdev); |
| 330 | if (rc < 0) |
| 331 | return rc; |
| 332 | |
| 333 | dev_dbg(dev, "registered LED %s\n", led->cdev.name); |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | static int bcm6328_leds_probe(struct platform_device *pdev) |
| 339 | { |
| 340 | struct device *dev = &pdev->dev; |
| 341 | struct device_node *np = pdev->dev.of_node; |
| 342 | struct device_node *child; |
| 343 | struct resource *mem_r; |
| 344 | void __iomem *mem; |
Álvaro Fernández Rojas | 41251e2 | 2015-12-15 21:03:45 +0100 | [diff] [blame] | 345 | spinlock_t *lock; /* memory lock */ |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 346 | unsigned long val, *blink_leds, *blink_delay; |
| 347 | |
| 348 | mem_r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 349 | if (!mem_r) |
| 350 | return -EINVAL; |
| 351 | |
| 352 | mem = devm_ioremap_resource(dev, mem_r); |
| 353 | if (IS_ERR(mem)) |
| 354 | return PTR_ERR(mem); |
| 355 | |
| 356 | lock = devm_kzalloc(dev, sizeof(*lock), GFP_KERNEL); |
| 357 | if (!lock) |
| 358 | return -ENOMEM; |
| 359 | |
| 360 | blink_leds = devm_kzalloc(dev, sizeof(*blink_leds), GFP_KERNEL); |
| 361 | if (!blink_leds) |
| 362 | return -ENOMEM; |
| 363 | |
| 364 | blink_delay = devm_kzalloc(dev, sizeof(*blink_delay), GFP_KERNEL); |
| 365 | if (!blink_delay) |
| 366 | return -ENOMEM; |
| 367 | |
| 368 | spin_lock_init(lock); |
| 369 | |
| 370 | bcm6328_led_write(mem + BCM6328_REG_HWDIS, ~0); |
| 371 | bcm6328_led_write(mem + BCM6328_REG_LNKACTSEL_HI, 0); |
| 372 | bcm6328_led_write(mem + BCM6328_REG_LNKACTSEL_LO, 0); |
| 373 | |
| 374 | val = bcm6328_led_read(mem + BCM6328_REG_INIT); |
Álvaro Fernández Rojas | 9f82c77 | 2015-10-08 12:35:54 +0200 | [diff] [blame] | 375 | val &= ~(BCM6328_INIT_MASK); |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 376 | if (of_property_read_bool(np, "brcm,serial-leds")) |
| 377 | val |= BCM6328_SERIAL_LED_EN; |
Álvaro Fernández Rojas | 9f82c77 | 2015-10-08 12:35:54 +0200 | [diff] [blame] | 378 | if (of_property_read_bool(np, "brcm,serial-mux")) |
| 379 | val |= BCM6328_SERIAL_LED_MUX; |
| 380 | if (of_property_read_bool(np, "brcm,serial-clk-low")) |
| 381 | val |= BCM6328_SERIAL_LED_CLK_NPOL; |
| 382 | if (!of_property_read_bool(np, "brcm,serial-dat-low")) |
| 383 | val |= BCM6328_SERIAL_LED_DATA_PPOL; |
| 384 | if (!of_property_read_bool(np, "brcm,serial-shift-inv")) |
| 385 | val |= BCM6328_SERIAL_LED_SHIFT_DIR; |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 386 | bcm6328_led_write(mem + BCM6328_REG_INIT, val); |
| 387 | |
| 388 | for_each_available_child_of_node(np, child) { |
| 389 | int rc; |
| 390 | u32 reg; |
| 391 | |
| 392 | if (of_property_read_u32(child, "reg", ®)) |
| 393 | continue; |
| 394 | |
| 395 | if (reg >= BCM6328_LED_MAX_COUNT) { |
Álvaro Fernández Rojas | 79653fb | 2015-10-08 12:35:52 +0200 | [diff] [blame] | 396 | dev_err(dev, "invalid LED (%u >= %d)\n", reg, |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 397 | BCM6328_LED_MAX_COUNT); |
| 398 | continue; |
| 399 | } |
| 400 | |
| 401 | if (of_property_read_bool(child, "brcm,hardware-controlled")) |
| 402 | rc = bcm6328_hwled(dev, child, reg, mem, lock); |
| 403 | else |
| 404 | rc = bcm6328_led(dev, child, reg, mem, lock, |
| 405 | blink_leds, blink_delay); |
| 406 | |
Julia Lawall | 6cc7624 | 2015-10-24 16:42:29 +0200 | [diff] [blame] | 407 | if (rc < 0) { |
| 408 | of_node_put(child); |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 409 | return rc; |
Julia Lawall | 6cc7624 | 2015-10-24 16:42:29 +0200 | [diff] [blame] | 410 | } |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static const struct of_device_id bcm6328_leds_of_match[] = { |
| 417 | { .compatible = "brcm,bcm6328-leds", }, |
| 418 | { }, |
| 419 | }; |
Luis de Bethencourt | 6528ca1 | 2015-09-01 23:35:38 +0200 | [diff] [blame] | 420 | MODULE_DEVICE_TABLE(of, bcm6328_leds_of_match); |
Álvaro Fernández Rojas | fd7b025 | 2015-04-28 09:50:50 -0700 | [diff] [blame] | 421 | |
| 422 | static struct platform_driver bcm6328_leds_driver = { |
| 423 | .probe = bcm6328_leds_probe, |
| 424 | .driver = { |
| 425 | .name = "leds-bcm6328", |
| 426 | .of_match_table = bcm6328_leds_of_match, |
| 427 | }, |
| 428 | }; |
| 429 | |
| 430 | module_platform_driver(bcm6328_leds_driver); |
| 431 | |
| 432 | MODULE_AUTHOR("Álvaro Fernández Rojas <noltari@gmail.com>"); |
| 433 | MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>"); |
| 434 | MODULE_DESCRIPTION("LED driver for BCM6328 controllers"); |
| 435 | MODULE_LICENSE("GPL v2"); |
| 436 | MODULE_ALIAS("platform:leds-bcm6328"); |