diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2011-01-04 15:28:21 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2011-01-18 13:30:27 -0500 |
commit | 3f348c5d1aaa0b8b2563f50d2d9a0c64e7d649fb (patch) | |
tree | cdd531781d22fe64c5c3cce0a56de153bf9cc397 | |
parent | 858f763c1cc37ecc6ab39dec60bb3a46606dcac4 (diff) |
MIPS: ath79: add common GPIO buttons device
Almost all boards have one or more push buttons connected to GPIO lines.
This patch adds common code to register a platform_device for them.
The patch also adds support for the buttons 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/1954/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r-- | arch/mips/ath79/Kconfig | 4 | ||||
-rw-r--r-- | arch/mips/ath79/Makefile | 1 | ||||
-rw-r--r-- | arch/mips/ath79/dev-gpio-buttons.c | 58 | ||||
-rw-r--r-- | arch/mips/ath79/dev-gpio-buttons.h | 23 | ||||
-rw-r--r-- | arch/mips/ath79/mach-pb44.c | 27 |
5 files changed, 113 insertions, 0 deletions
diff --git a/arch/mips/ath79/Kconfig b/arch/mips/ath79/Kconfig index 5bc480e28b0..185a8d6c73d 100644 --- a/arch/mips/ath79/Kconfig +++ b/arch/mips/ath79/Kconfig | |||
@@ -5,6 +5,7 @@ menu "Atheros AR71XX/AR724X/AR913X machine selection" | |||
5 | config ATH79_MACH_PB44 | 5 | config 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_GPIO_BUTTONS | ||
8 | select ATH79_DEV_LEDS_GPIO | 9 | select ATH79_DEV_LEDS_GPIO |
9 | help | 10 | help |
10 | Say 'Y' here if you want your kernel to support the | 11 | Say 'Y' here if you want your kernel to support the |
@@ -21,6 +22,9 @@ config SOC_AR724X | |||
21 | config SOC_AR913X | 22 | config SOC_AR913X |
22 | def_bool n | 23 | def_bool n |
23 | 24 | ||
25 | config ATH79_DEV_GPIO_BUTTONS | ||
26 | def_bool n | ||
27 | |||
24 | config ATH79_DEV_LEDS_GPIO | 28 | config ATH79_DEV_LEDS_GPIO |
25 | def_bool n | 29 | def_bool n |
26 | 30 | ||
diff --git a/arch/mips/ath79/Makefile b/arch/mips/ath79/Makefile index f41c0296aa2..344e9ab1e10 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 | # |
18 | obj-y += dev-common.o | 18 | obj-y += dev-common.o |
19 | obj-$(CONFIG_ATH79_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o | ||
19 | obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o | 20 | obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o |
20 | 21 | ||
21 | # | 22 | # |
diff --git a/arch/mips/ath79/dev-gpio-buttons.c b/arch/mips/ath79/dev-gpio-buttons.c new file mode 100644 index 00000000000..4b0168a11c0 --- /dev/null +++ b/arch/mips/ath79/dev-gpio-buttons.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Atheros AR71XX/AR724X/AR913X GPIO button 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-gpio-buttons.h" | ||
17 | |||
18 | void __init ath79_register_gpio_keys_polled(int id, | ||
19 | unsigned poll_interval, | ||
20 | unsigned nbuttons, | ||
21 | struct gpio_keys_button *buttons) | ||
22 | { | ||
23 | struct platform_device *pdev; | ||
24 | struct gpio_keys_platform_data pdata; | ||
25 | struct gpio_keys_button *p; | ||
26 | int err; | ||
27 | |||
28 | p = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL); | ||
29 | if (!p) | ||
30 | return; | ||
31 | |||
32 | memcpy(p, buttons, nbuttons * sizeof(*p)); | ||
33 | |||
34 | pdev = platform_device_alloc("gpio-keys-polled", id); | ||
35 | if (!pdev) | ||
36 | goto err_free_buttons; | ||
37 | |||
38 | memset(&pdata, 0, sizeof(pdata)); | ||
39 | pdata.poll_interval = poll_interval; | ||
40 | pdata.nbuttons = nbuttons; | ||
41 | pdata.buttons = p; | ||
42 | |||
43 | err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); | ||
44 | if (err) | ||
45 | goto err_put_pdev; | ||
46 | |||
47 | err = platform_device_add(pdev); | ||
48 | if (err) | ||
49 | goto err_put_pdev; | ||
50 | |||
51 | return; | ||
52 | |||
53 | err_put_pdev: | ||
54 | platform_device_put(pdev); | ||
55 | |||
56 | err_free_buttons: | ||
57 | kfree(p); | ||
58 | } | ||
diff --git a/arch/mips/ath79/dev-gpio-buttons.h b/arch/mips/ath79/dev-gpio-buttons.h new file mode 100644 index 00000000000..481847ac1cb --- /dev/null +++ b/arch/mips/ath79/dev-gpio-buttons.h | |||
@@ -0,0 +1,23 @@ | |||
1 | /* | ||
2 | * Atheros AR71XX/AR724X/AR913X GPIO button 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_GPIO_BUTTONS_H | ||
13 | #define _ATH79_DEV_GPIO_BUTTONS_H | ||
14 | |||
15 | #include <linux/input.h> | ||
16 | #include <linux/gpio_keys.h> | ||
17 | |||
18 | void ath79_register_gpio_keys_polled(int id, | ||
19 | unsigned poll_interval, | ||
20 | unsigned nbuttons, | ||
21 | struct gpio_keys_button *buttons); | ||
22 | |||
23 | #endif /* _ATH79_DEV_GPIO_BUTTONS_H */ | ||
diff --git a/arch/mips/ath79/mach-pb44.c b/arch/mips/ath79/mach-pb44.c index e176779af66..3dc5080185c 100644 --- a/arch/mips/ath79/mach-pb44.c +++ b/arch/mips/ath79/mach-pb44.c | |||
@@ -15,15 +15,21 @@ | |||
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-gpio-buttons.h" | ||
18 | #include "dev-leds-gpio.h" | 19 | #include "dev-leds-gpio.h" |
19 | 20 | ||
20 | #define PB44_GPIO_I2C_SCL 0 | 21 | #define PB44_GPIO_I2C_SCL 0 |
21 | #define PB44_GPIO_I2C_SDA 1 | 22 | #define PB44_GPIO_I2C_SDA 1 |
22 | 23 | ||
23 | #define PB44_GPIO_EXP_BASE 16 | 24 | #define PB44_GPIO_EXP_BASE 16 |
25 | #define PB44_GPIO_SW_RESET (PB44_GPIO_EXP_BASE + 6) | ||
26 | #define PB44_GPIO_SW_JUMP (PB44_GPIO_EXP_BASE + 8) | ||
24 | #define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + 9) | 27 | #define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + 9) |
25 | #define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + 10) | 28 | #define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + 10) |
26 | 29 | ||
30 | #define PB44_KEYS_POLL_INTERVAL 20 /* msecs */ | ||
31 | #define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL) | ||
32 | |||
27 | static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { | 33 | static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { |
28 | .sda_pin = PB44_GPIO_I2C_SDA, | 34 | .sda_pin = PB44_GPIO_I2C_SDA, |
29 | .scl_pin = PB44_GPIO_I2C_SCL, | 35 | .scl_pin = PB44_GPIO_I2C_SCL, |
@@ -60,6 +66,24 @@ static struct gpio_led pb44_leds_gpio[] __initdata = { | |||
60 | }, | 66 | }, |
61 | }; | 67 | }; |
62 | 68 | ||
69 | static struct gpio_keys_button pb44_gpio_keys[] __initdata = { | ||
70 | { | ||
71 | .desc = "soft_reset", | ||
72 | .type = EV_KEY, | ||
73 | .code = KEY_RESTART, | ||
74 | .debounce_interval = PB44_KEYS_DEBOUNCE_INTERVAL, | ||
75 | .gpio = PB44_GPIO_SW_RESET, | ||
76 | .active_low = 1, | ||
77 | } , { | ||
78 | .desc = "jumpstart", | ||
79 | .type = EV_KEY, | ||
80 | .code = KEY_WPS_BUTTON, | ||
81 | .debounce_interval = PB44_KEYS_DEBOUNCE_INTERVAL, | ||
82 | .gpio = PB44_GPIO_SW_JUMP, | ||
83 | .active_low = 1, | ||
84 | } | ||
85 | }; | ||
86 | |||
63 | static void __init pb44_init(void) | 87 | static void __init pb44_init(void) |
64 | { | 88 | { |
65 | i2c_register_board_info(0, pb44_i2c_board_info, | 89 | i2c_register_board_info(0, pb44_i2c_board_info, |
@@ -68,6 +92,9 @@ static void __init pb44_init(void) | |||
68 | 92 | ||
69 | ath79_register_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio), | 93 | ath79_register_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio), |
70 | pb44_leds_gpio); | 94 | pb44_leds_gpio); |
95 | ath79_register_gpio_keys_polled(-1, PB44_KEYS_POLL_INTERVAL, | ||
96 | ARRAY_SIZE(pb44_gpio_keys), | ||
97 | pb44_gpio_keys); | ||
71 | } | 98 | } |
72 | 99 | ||
73 | MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board", | 100 | MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board", |