From patchwork Mon Jan 15 19:50:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabor Juhos X-Patchwork-Id: 861062 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JOeyEL0a"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zL3rV2g6fz9sBW for ; Tue, 16 Jan 2018 06:51:22 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=KJPuAMm7XPTWbcGg7oIKOYXKOv1L4jYv0m1epV7KT7g=; b=JOeyEL0aSkwlW4 +tdFQ/7uAw3g6o29ou0LZjf+JdjkDyPwgatXcedXejlqnadKU+vgn4lB8A8QSY/JOei2YS8gver0o mzjUHqM/YZlsbpSSPb0nsYyhmplmHNZo4gj6JSkZ3U4OzNdETgMWnzUCpPMiQnOrcnKWS4R8fZsl8 MhEsqkDpR6c2iw5FGoMV0Xl2muN04kircnuESJjEQl18Y6nGG4Z2H0s8/bWxKln+Qnjx++9UkTY+s smgNbOMb0W750B/p1L9/ZtOukGzstBqW79RqY05fcBdwXXDCC/B9Wb6Jje/gJjMHA1t48P+DJTmcW uIrGbELjVRSXae5o7/jQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ebAmu-0002yS-BF; Mon, 15 Jan 2018 19:51:20 +0000 Received: from arrakis.dune.hu ([78.24.191.176]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ebAmp-0002wN-6s for lede-dev@lists.infradead.org; Mon, 15 Jan 2018 19:51:18 +0000 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 67345B800CD; Mon, 15 Jan 2018 20:50:47 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 Received: from localhost.localdomain (91-82-141-223.pool.invitel.hu [91.82.141.223]) by arrakis.dune.hu (Postfix) with ESMTPSA; Mon, 15 Jan 2018 20:50:47 +0100 (CET) From: Gabor Juhos To: openwrt-devel@lists.openwrt.org, lede-dev@lists.infradead.org Date: Mon, 15 Jan 2018 20:50:43 +0100 Message-Id: <20180115195043.3059-1-juhosg@freemail.hu> X-Mailer: git-send-email 2.14.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180115_115115_611930_37450326 X-CRM114-Status: GOOD ( 13.84 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [78.24.191.176 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (juhosg[at]freemail.hu) 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Subject: [LEDE-DEV] [PATCH] ar71xx: mach-rbspi: simplify reset button registration X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gabor Juhos MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The setup code defines four individual structures for the Reset buttons of the supported boards. The only difference between the definitions is the GPIO number used for the button. Replace the different structures with one generic variant, and add a helper function to simplify the button registration. Signed-off-by: Gabor Juhos --- .../ar71xx/files/arch/mips/ath79/mach-rbspi.c | 94 +++++++--------------- 1 file changed, 30 insertions(+), 64 deletions(-) diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c index 8d8dd40e8a..0c827ed566 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c @@ -137,40 +137,17 @@ static struct flash_platform_data rbspi_spi_flash_data = { .nr_parts = ARRAY_SIZE(rbspi_spi_partitions), }; -/* Several boards only have a single reset button, wired to GPIO 1, 16 or 20 */ -#define RBSPI_GPIO_BTN_RESET01 1 -#define RBSPI_GPIO_BTN_RESET16 16 -#define RBSPI_GPIO_BTN_RESET20 20 - -static struct gpio_keys_button rbspi_gpio_keys_reset01[] __initdata = { - { - .desc = "Reset button", - .type = EV_KEY, - .code = KEY_RESTART, - .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL, - .gpio = RBSPI_GPIO_BTN_RESET01, - .active_low = 1, - }, -}; - -static struct gpio_keys_button rbspi_gpio_keys_reset16[] __initdata = { - { - .desc = "Reset button", - .type = EV_KEY, - .code = KEY_RESTART, - .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL, - .gpio = RBSPI_GPIO_BTN_RESET16, - .active_low = 1, - }, -}; - -static struct gpio_keys_button rbspi_gpio_keys_reset20[] __initdata = { +/* + * Several boards only have a single reset button, use a common + * structure for that. + */ +static struct gpio_keys_button rbspi_gpio_keys_reset[] __initdata = { { .desc = "Reset button", .type = EV_KEY, .code = KEY_RESTART, .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL, - .gpio = RBSPI_GPIO_BTN_RESET20, + .gpio = -ENOENT, /* filled dynamically */ .active_low = 1, }, }; @@ -180,6 +157,7 @@ static struct gpio_keys_button rbspi_gpio_keys_reset20[] __initdata = { #define RBMAPL_GPIO_LED_USER 14 #define RBMAPL_GPIO_LED_ETH 4 #define RBMAPL_GPIO_LED_WLAN 11 +#define RBMAPL_GPIO_BTN_RESET 16 static struct gpio_led rbmapl_leds[] __initdata = { { @@ -204,6 +182,8 @@ static struct gpio_led rbmapl_leds[] __initdata = { /* RB 941L-2nD gpios */ #define RBHAPL_GPIO_LED_USER 14 +#define RBHAPL_GPIO_BTN_RESET 16 + static struct gpio_led rbhapl_leds[] __initdata = { { .name = "rb:green:user", @@ -228,6 +208,7 @@ static struct gpio_led rbhapl_leds[] __initdata = { #define RB952_GPIO_LED_USER 4 #define RB952_GPIO_POE_POWER 14 #define RB952_GPIO_POE_STATUS 12 +#define RB952_GPIO_BTN_RESET 16 #define RB952_GPIO_USB_POWER RBSPI_SSR_GPIO(RB952_SSR_BIT_USB_POWER) #define RB952_GPIO_LED_LAN1 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN1) #define RB952_GPIO_LED_LAN2 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN2) @@ -274,6 +255,7 @@ static struct gpio_led rb952_leds[] __initdata = { #define RB962_GPIO_POE_POWER 3 #define RB962_GPIO_LED_USER 12 #define RB962_GPIO_USB_POWER 13 +#define RB962_GPIO_BTN_RESET 20 static struct gpio_led rb962_leds_gpio[] __initdata = { { @@ -348,6 +330,7 @@ static struct mdio_board_info rb962_mdio0_info[] = { /* RB wAP-2nD gpios */ #define RBWAP_GPIO_LED_USER 14 #define RBWAP_GPIO_LED_WLAN 11 +#define RBWAP_GPIO_BTN_RESET 16 static struct gpio_led rbwap_leds[] __initdata = { { @@ -396,6 +379,7 @@ static struct gpio_led rbcap_leds[] __initdata = { #define RBMAP_SSR_BIT_LED_WLAN 4 #define RBMAP_SSR_BIT_USB_POWER 5 #define RBMAP_SSR_BIT_LED_APCAP 6 +#define RBMAP_GPIO_BTN_RESET 16 #define RBMAP_GPIO_SSR_CS 11 #define RBMAP_GPIO_LED_POWER 4 #define RBMAP_GPIO_POE_POWER 14 @@ -489,22 +473,12 @@ static struct gpio_led rblhg_leds[] __initdata = { }, }; -static struct gpio_keys_button rblhg_gpio_keys[] __initdata = { - { - .desc = "Reset button", - .type = EV_KEY, - .code = KEY_RESTART, - .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL, - .gpio = RBLHG_GPIO_BTN_RESET, - .active_low = 1, - }, -}; - /* RB w APG-5HacT2HnD (wAP AC) gpios*/ #define RBWAPGSC_LED1 1 #define RBWAPGSC_LED2 8 #define RBWAPGSC_LED3 9 #define RBWAPGSC_POWERLED 16 +#define RBWAPGSC_GPIO_BTN_RESET 1 #define RBWAPGSC_GPIO_MDIO_MDC 12 #define RBWAPGSC_GPIO_MDIO_DATA 11 #define RBWAPGSC_MDIO_PHYADDR 0 @@ -690,6 +664,14 @@ static void __init rbspi_network_setup(u32 flags, int gmac1_offset, rbspi_wlan_init(1, wmac1_offset); } +static __init void rbspi_register_reset_button(int gpio) +{ + rbspi_gpio_keys_reset[0].gpio = gpio; + ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, + ARRAY_SIZE(rbspi_gpio_keys_reset), + rbspi_gpio_keys_reset); +} + /* * Init the mAP lite hardware (QCA953x). * The mAP L-2nD (mAP lite) has a single ethernet port, connected to PHY0. @@ -712,9 +694,7 @@ static void __init rbmapl_setup(void) ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmapl_leds), rbmapl_leds); /* mAP lite has a single reset button as gpio 16 */ - ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, - ARRAY_SIZE(rbspi_gpio_keys_reset16), - rbspi_gpio_keys_reset16); + rbspi_register_reset_button(RBMAPL_GPIO_BTN_RESET); /* clear internal multiplexing */ ath79_gpio_output_select(RBMAPL_GPIO_LED_ETH, AR934X_GPIO_OUT_GPIO); @@ -743,9 +723,7 @@ static void __init rbhapl_setup(void) ath79_register_leds_gpio(-1, ARRAY_SIZE(rbhapl_leds), rbhapl_leds); /* hAP lite has a single reset button as gpio 16 */ - ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, - ARRAY_SIZE(rbspi_gpio_keys_reset16), - rbspi_gpio_keys_reset16); + rbspi_register_reset_button(RBHAPL_GPIO_BTN_RESET); } /* @@ -777,9 +755,7 @@ static void __init rbspi_952_750r2_setup(u32 flags) ath79_register_leds_gpio(-1, ARRAY_SIZE(rb952_leds), rb952_leds); /* These devices have a single reset button as gpio 16 */ - ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, - ARRAY_SIZE(rbspi_gpio_keys_reset16), - rbspi_gpio_keys_reset16); + rbspi_register_reset_button(RB952_GPIO_BTN_RESET); } /* @@ -892,9 +868,7 @@ static void __init rb962_setup(void) rb962_leds_gpio); /* This device has a single reset button as gpio 20 */ - ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, - ARRAY_SIZE(rbspi_gpio_keys_reset20), - rbspi_gpio_keys_reset20); + rbspi_register_reset_button(RB962_GPIO_BTN_RESET); } /* @@ -916,9 +890,7 @@ static void __init rblhg_setup(void) ath79_register_leds_gpio(-1, ARRAY_SIZE(rblhg_leds), rblhg_leds); - ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, - ARRAY_SIZE(rblhg_gpio_keys), - rblhg_gpio_keys); + rbspi_register_reset_button(RBLHG_GPIO_BTN_RESET); } /* @@ -940,9 +912,7 @@ static void __init rbwap_setup(void) ath79_register_leds_gpio(-1, ARRAY_SIZE(rbwap_leds), rbwap_leds); /* wAP has a single reset button as GPIO 16 */ - ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, - ARRAY_SIZE(rbspi_gpio_keys_reset16), - rbspi_gpio_keys_reset16); + rbspi_register_reset_button(RBWAP_GPIO_BTN_RESET); } /* @@ -1002,9 +972,7 @@ static void __init rbmap_setup(void) ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmap_leds), rbmap_leds); /* mAP 2nD has a single reset button as gpio 16 */ - ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, - ARRAY_SIZE(rbspi_gpio_keys_reset16), - rbspi_gpio_keys_reset16); + rbspi_register_reset_button(RBMAP_GPIO_BTN_RESET); } /* @@ -1037,9 +1005,7 @@ static void __init rbwapgsc_setup(void) rbspi_wlan_init(1, 2); - ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL, - ARRAY_SIZE(rbspi_gpio_keys_reset01), - rbspi_gpio_keys_reset01); + rbspi_register_reset_button(RBWAPGSC_GPIO_BTN_RESET); ath79_gpio_function_enable(QCA955X_GPIO_FUNC_JTAG_DISABLE| QCA955X_GPIO_REG_OUT_FUNC4|