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>

authored by Gabor Juhos and committed by Ralf Baechle 3f348c5d 858f763c

+113
+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_GPIO_BUTTONS 8 9 select ATH79_DEV_LEDS_GPIO 9 10 help 10 11 Say 'Y' here if you want your kernel to support the ··· 20 19 def_bool n 21 20 22 21 config SOC_AR913X 22 + def_bool n 23 + 24 + config ATH79_DEV_GPIO_BUTTONS 23 25 def_bool n 24 26 25 27 config ATH79_DEV_LEDS_GPIO
+1
arch/mips/ath79/Makefile
··· 16 16 # Devices 17 17 # 18 18 obj-y += dev-common.o 19 + obj-$(CONFIG_ATH79_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o 19 20 obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o 20 21 21 22 #
+58
arch/mips/ath79/dev-gpio-buttons.c
··· 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 + }
+23
arch/mips/ath79/dev-gpio-buttons.h
··· 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 */
+27
arch/mips/ath79/mach-pb44.c
··· 15 15 #include <linux/i2c/pcf857x.h> 16 16 17 17 #include "machtypes.h" 18 + #include "dev-gpio-buttons.h" 18 19 #include "dev-leds-gpio.h" 19 20 20 21 #define PB44_GPIO_I2C_SCL 0 21 22 #define PB44_GPIO_I2C_SDA 1 22 23 23 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 27 #define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + 9) 25 28 #define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + 10) 29 + 30 + #define PB44_KEYS_POLL_INTERVAL 20 /* msecs */ 31 + #define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL) 26 32 27 33 static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { 28 34 .sda_pin = PB44_GPIO_I2C_SDA, ··· 66 60 }, 67 61 }; 68 62 63 + static struct gpio_keys_button pb44_gpio_keys[] __initdata = { 64 + { 65 + .desc = "soft_reset", 66 + .type = EV_KEY, 67 + .code = KEY_RESTART, 68 + .debounce_interval = PB44_KEYS_DEBOUNCE_INTERVAL, 69 + .gpio = PB44_GPIO_SW_RESET, 70 + .active_low = 1, 71 + } , { 72 + .desc = "jumpstart", 73 + .type = EV_KEY, 74 + .code = KEY_WPS_BUTTON, 75 + .debounce_interval = PB44_KEYS_DEBOUNCE_INTERVAL, 76 + .gpio = PB44_GPIO_SW_JUMP, 77 + .active_low = 1, 78 + } 79 + }; 80 + 69 81 static void __init pb44_init(void) 70 82 { 71 83 i2c_register_board_info(0, pb44_i2c_board_info, ··· 92 68 93 69 ath79_register_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio), 94 70 pb44_leds_gpio); 71 + ath79_register_gpio_keys_polled(-1, PB44_KEYS_POLL_INTERVAL, 72 + ARRAY_SIZE(pb44_gpio_keys), 73 + pb44_gpio_keys); 95 74 } 96 75 97 76 MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board",