aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2011-01-04 15:28:18 -0500
committerRalf Baechle <ralf@linux-mips.org>2011-01-18 13:30:26 -0500
commitd8fec1fc80cd8639449e2b5012688f5be109eeaf (patch)
tree57882250166f98d561b126bf664f5abaef3a0a22 /arch
parent0cde72284c9c7d4b348ece9e1fe136f787185cd7 (diff)
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>
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/ath79/Kconfig4
-rw-r--r--arch/mips/ath79/Makefile1
-rw-r--r--arch/mips/ath79/dev-leds-gpio.c56
-rw-r--r--arch/mips/ath79/dev-leds-gpio.h21
-rw-r--r--arch/mips/ath79/mach-pb44.c18
5 files changed, 100 insertions, 0 deletions
diff --git a/arch/mips/ath79/Kconfig b/arch/mips/ath79/Kconfig
index fabb2b0412d..5bc480e28b0 100644
--- a/arch/mips/ath79/Kconfig
+++ b/arch/mips/ath79/Kconfig
@@ -5,6 +5,7 @@ menu "Atheros AR71XX/AR724X/AR913X machine selection"
5config ATH79_MACH_PB44 5config ATH79_MACH_PB44
6 bool "Atheros PB44 reference board" 6 bool "Atheros PB44 reference board"
7 select SOC_AR71XX 7 select SOC_AR71XX
8 select ATH79_DEV_LEDS_GPIO
8 help 9 help
9 Say 'Y' here if you want your kernel to support the 10 Say 'Y' here if you want your kernel to support the
10 Atheros PB44 reference board. 11 Atheros PB44 reference board.
@@ -20,4 +21,7 @@ config SOC_AR724X
20config SOC_AR913X 21config SOC_AR913X
21 def_bool n 22 def_bool n
22 23
24config ATH79_DEV_LEDS_GPIO
25 def_bool n
26
23endif 27endif
diff --git a/arch/mips/ath79/Makefile b/arch/mips/ath79/Makefile
index c3093f7d401..f41c0296aa2 100644
--- a/arch/mips/ath79/Makefile
+++ b/arch/mips/ath79/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
16# Devices 16# Devices
17# 17#
18obj-y += dev-common.o 18obj-y += dev-common.o
19obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o
19 20
20# 21#
21# Machines 22# Machines
diff --git a/arch/mips/ath79/dev-leds-gpio.c b/arch/mips/ath79/dev-leds-gpio.c
new file mode 100644
index 00000000000..cdade68dcd1
--- /dev/null
+++ b/arch/mips/ath79/dev-leds-gpio.c
@@ -0,0 +1,56 @@
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
18void __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
51err_put_pdev:
52 platform_device_put(pdev);
53
54err_free_leds:
55 kfree(p);
56}
diff --git a/arch/mips/ath79/dev-leds-gpio.h b/arch/mips/ath79/dev-leds-gpio.h
new file mode 100644
index 00000000000..6e5d8851ebc
--- /dev/null
+++ b/arch/mips/ath79/dev-leds-gpio.h
@@ -0,0 +1,21 @@
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
17void ath79_register_leds_gpio(int id,
18 unsigned num_leds,
19 struct gpio_led *leds);
20
21#endif /* _ATH79_DEV_LEDS_GPIO_H */
diff --git a/arch/mips/ath79/mach-pb44.c b/arch/mips/ath79/mach-pb44.c
index ffc24d7a255..e176779af66 100644
--- a/arch/mips/ath79/mach-pb44.c
+++ b/arch/mips/ath79/mach-pb44.c
@@ -15,11 +15,14 @@
15#include <linux/i2c/pcf857x.h> 15#include <linux/i2c/pcf857x.h>
16 16
17#include "machtypes.h" 17#include "machtypes.h"
18#include "dev-leds-gpio.h"
18 19
19#define PB44_GPIO_I2C_SCL 0 20#define PB44_GPIO_I2C_SCL 0
20#define PB44_GPIO_I2C_SDA 1 21#define PB44_GPIO_I2C_SDA 1
21 22
22#define PB44_GPIO_EXP_BASE 16 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
24static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { 27static struct i2c_gpio_platform_data pb44_i2c_gpio_data = {
25 .sda_pin = PB44_GPIO_I2C_SDA, 28 .sda_pin = PB44_GPIO_I2C_SDA,
@@ -45,11 +48,26 @@ static struct i2c_board_info pb44_i2c_board_info[] __initdata = {
45 }, 48 },
46}; 49};
47 50
51static struct gpio_led pb44_leds_gpio[] __initdata = {
52 {
53 .name = "pb44:amber:jump1",
54 .gpio = PB44_GPIO_LED_JUMP1,
55 .active_low = 1,
56 }, {
57 .name = "pb44:green:jump2",
58 .gpio = PB44_GPIO_LED_JUMP2,
59 .active_low = 1,
60 },
61};
62
48static void __init pb44_init(void) 63static void __init pb44_init(void)
49{ 64{
50 i2c_register_board_info(0, pb44_i2c_board_info, 65 i2c_register_board_info(0, pb44_i2c_board_info,
51 ARRAY_SIZE(pb44_i2c_board_info)); 66 ARRAY_SIZE(pb44_i2c_board_info));
52 platform_device_register(&pb44_i2c_gpio_device); 67 platform_device_register(&pb44_i2c_gpio_device);
68
69 ath79_register_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio),
70 pb44_leds_gpio);
53} 71}
54 72
55MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board", 73MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board",