Skip to content

Commit ef48d08

Browse files
Linus Walleijgclement
authored andcommitted
ARM: orion5x: Convert DNS323 board to GPIO descriptors for LEDs
This makes the LEDs on the D-Link DNS323 Orion5x board use GPIO descriptors instead of hardcoded GPIOs from the global numberspace. Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Gregory CLEMENT <[email protected]>
1 parent 79f46f6 commit ef48d08

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

arch/arm/mach-orion5x/dns323-setup.c

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
*/
1616
#include <linux/gpio.h>
17+
#include <linux/gpio/machine.h>
1718
#include <linux/kernel.h>
1819
#include <linux/init.h>
1920
#include <linux/delay.h>
@@ -254,37 +255,64 @@ static int __init dns323_read_mac_addr(void)
254255
static struct gpio_led dns323ab_leds[] = {
255256
{
256257
.name = "power:blue",
257-
.gpio = DNS323_GPIO_LED_POWER2,
258258
.default_trigger = "default-on",
259259
}, {
260260
.name = "right:amber",
261-
.gpio = DNS323_GPIO_LED_RIGHT_AMBER,
262-
.active_low = 1,
263261
}, {
264262
.name = "left:amber",
265-
.gpio = DNS323_GPIO_LED_LEFT_AMBER,
266-
.active_low = 1,
267263
},
268264
};
269265

266+
static struct gpiod_lookup_table dns323a1_leds_gpio_table = {
267+
.dev_id = "leds-gpio",
268+
.table = {
269+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323_GPIO_LED_POWER2, NULL,
270+
0, GPIO_ACTIVE_LOW),
271+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323_GPIO_LED_RIGHT_AMBER, NULL,
272+
1, GPIO_ACTIVE_LOW),
273+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323_GPIO_LED_LEFT_AMBER, NULL,
274+
2, GPIO_ACTIVE_LOW),
275+
{ },
276+
},
277+
};
278+
279+
/* B1 is the same but power LED is active high */
280+
static struct gpiod_lookup_table dns323b1_leds_gpio_table = {
281+
.dev_id = "leds-gpio",
282+
.table = {
283+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323_GPIO_LED_POWER2, NULL,
284+
0, GPIO_ACTIVE_HIGH),
285+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323_GPIO_LED_RIGHT_AMBER, NULL,
286+
1, GPIO_ACTIVE_LOW),
287+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323_GPIO_LED_LEFT_AMBER, NULL,
288+
2, GPIO_ACTIVE_LOW),
289+
{ },
290+
},
291+
};
270292

271293
static struct gpio_led dns323c_leds[] = {
272294
{
273295
.name = "power:blue",
274-
.gpio = DNS323C_GPIO_LED_POWER,
275296
.default_trigger = "timer",
276-
.active_low = 1,
277297
}, {
278298
.name = "right:amber",
279-
.gpio = DNS323C_GPIO_LED_RIGHT_AMBER,
280-
.active_low = 1,
281299
}, {
282300
.name = "left:amber",
283-
.gpio = DNS323C_GPIO_LED_LEFT_AMBER,
284-
.active_low = 1,
285301
},
286302
};
287303

304+
static struct gpiod_lookup_table dns323c_leds_gpio_table = {
305+
.dev_id = "leds-gpio",
306+
.table = {
307+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323C_GPIO_LED_POWER, NULL,
308+
0, GPIO_ACTIVE_LOW),
309+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323C_GPIO_LED_RIGHT_AMBER, NULL,
310+
1, GPIO_ACTIVE_LOW),
311+
GPIO_LOOKUP_IDX("orion_gpio0", DNS323C_GPIO_LED_LEFT_AMBER, NULL,
312+
2, GPIO_ACTIVE_LOW),
313+
{ },
314+
},
315+
};
288316

289317
static struct gpio_led_platform_data dns323ab_led_data = {
290318
.num_leds = ARRAY_SIZE(dns323ab_leds),
@@ -621,16 +649,21 @@ static void __init dns323_init(void)
621649
/* The 5181 power LED is active low and requires
622650
* DNS323_GPIO_LED_POWER1 to also be low.
623651
*/
624-
dns323ab_leds[0].active_low = 1;
625-
gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
626-
gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
627-
fallthrough;
652+
gpiod_add_lookup_table(&dns323a1_leds_gpio_table);
653+
gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
654+
gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
655+
i2c_register_board_info(0, dns323ab_i2c_devices,
656+
ARRAY_SIZE(dns323ab_i2c_devices));
657+
658+
break;
628659
case DNS323_REV_B1:
660+
gpiod_add_lookup_table(&dns323b1_leds_gpio_table);
629661
i2c_register_board_info(0, dns323ab_i2c_devices,
630662
ARRAY_SIZE(dns323ab_i2c_devices));
631663
break;
632664
case DNS323_REV_C1:
633665
/* Hookup LEDs & Buttons */
666+
gpiod_add_lookup_table(&dns323c_leds_gpio_table);
634667
dns323_gpio_leds.dev.platform_data = &dns323c_led_data;
635668
dns323_button_device.dev.platform_data = &dns323c_button_data;
636669

0 commit comments

Comments
 (0)