MIPS: ath79: add common GPIO LEDs device

Almost all boards have one or more LEDs connected to GPIO lines. This
patch adds common code to register a platform_device for them.

The patch also adds support for the LEDs on the PB44 board.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
Cc: linux-mips@linux-mips.org
Cc: Luis R. Rodriguez <lrodriguez@atheros.com>
Cc: Cliff Holden <Cliff.Holden@Atheros.com>
Cc: Kathy Giori <Kathy.Giori@Atheros.com>
Patchwork: https://patchwork.linux-mips.org/patch/1953/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by Gabor Juhos and committed by Ralf Baechle d8fec1fc 0cde7228

+100
+4
arch/mips/ath79/Kconfig
··· 5 5 config ATH79_MACH_PB44 6 6 bool "Atheros PB44 reference board" 7 7 select SOC_AR71XX 8 + select ATH79_DEV_LEDS_GPIO 8 9 help 9 10 Say 'Y' here if you want your kernel to support the 10 11 Atheros PB44 reference board. ··· 19 18 def_bool n 20 19 21 20 config SOC_AR913X 21 + def_bool n 22 + 23 + config ATH79_DEV_LEDS_GPIO 22 24 def_bool n 23 25 24 26 endif
+1
arch/mips/ath79/Makefile
··· 16 16 # Devices 17 17 # 18 18 obj-y += dev-common.o 19 + obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o 19 20 20 21 # 21 22 # Machines
+56
arch/mips/ath79/dev-leds-gpio.c
··· 1 + /* 2 + * Atheros AR71XX/AR724X/AR913X common GPIO LEDs support 3 + * 4 + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org> 5 + * Copyright (C) 2008 Imre Kaloz <kaloz@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 version 2 as published 9 + * by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/init.h> 13 + #include <linux/slab.h> 14 + #include <linux/platform_device.h> 15 + 16 + #include "dev-leds-gpio.h" 17 + 18 + void __init ath79_register_leds_gpio(int id, 19 + unsigned num_leds, 20 + struct gpio_led *leds) 21 + { 22 + struct platform_device *pdev; 23 + struct gpio_led_platform_data pdata; 24 + struct gpio_led *p; 25 + int err; 26 + 27 + p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL); 28 + if (!p) 29 + return; 30 + 31 + memcpy(p, leds, num_leds * sizeof(*p)); 32 + 33 + pdev = platform_device_alloc("leds-gpio", id); 34 + if (!pdev) 35 + goto err_free_leds; 36 + 37 + memset(&pdata, 0, sizeof(pdata)); 38 + pdata.num_leds = num_leds; 39 + pdata.leds = p; 40 + 41 + err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); 42 + if (err) 43 + goto err_put_pdev; 44 + 45 + err = platform_device_add(pdev); 46 + if (err) 47 + goto err_put_pdev; 48 + 49 + return; 50 + 51 + err_put_pdev: 52 + platform_device_put(pdev); 53 + 54 + err_free_leds: 55 + kfree(p); 56 + }
+21
arch/mips/ath79/dev-leds-gpio.h
··· 1 + /* 2 + * Atheros AR71XX/AR724X/AR913X common GPIO LEDs support 3 + * 4 + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org> 5 + * Copyright (C) 2008 Imre Kaloz <kaloz@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 version 2 as published 9 + * by the Free Software Foundation. 10 + */ 11 + 12 + #ifndef _ATH79_DEV_LEDS_GPIO_H 13 + #define _ATH79_DEV_LEDS_GPIO_H 14 + 15 + #include <linux/leds.h> 16 + 17 + void ath79_register_leds_gpio(int id, 18 + unsigned num_leds, 19 + struct gpio_led *leds); 20 + 21 + #endif /* _ATH79_DEV_LEDS_GPIO_H */
+18
arch/mips/ath79/mach-pb44.c
··· 15 15 #include <linux/i2c/pcf857x.h> 16 16 17 17 #include "machtypes.h" 18 + #include "dev-leds-gpio.h" 18 19 19 20 #define PB44_GPIO_I2C_SCL 0 20 21 #define PB44_GPIO_I2C_SDA 1 21 22 22 23 #define PB44_GPIO_EXP_BASE 16 24 + #define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + 9) 25 + #define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + 10) 23 26 24 27 static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { 25 28 .sda_pin = PB44_GPIO_I2C_SDA, ··· 48 45 }, 49 46 }; 50 47 48 + static struct gpio_led pb44_leds_gpio[] __initdata = { 49 + { 50 + .name = "pb44:amber:jump1", 51 + .gpio = PB44_GPIO_LED_JUMP1, 52 + .active_low = 1, 53 + }, { 54 + .name = "pb44:green:jump2", 55 + .gpio = PB44_GPIO_LED_JUMP2, 56 + .active_low = 1, 57 + }, 58 + }; 59 + 51 60 static void __init pb44_init(void) 52 61 { 53 62 i2c_register_board_info(0, pb44_i2c_board_info, 54 63 ARRAY_SIZE(pb44_i2c_board_info)); 55 64 platform_device_register(&pb44_i2c_gpio_device); 65 + 66 + ath79_register_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio), 67 + pb44_leds_gpio); 56 68 } 57 69 58 70 MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board",