From patchwork Wed Jan 27 00:39:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Cieslakiewicz X-Patchwork-Id: 573787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C8E6D140B9C for ; Wed, 27 Jan 2016 11:53:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=wp.pl header.i=@wp.pl header.b=yLm5aDAb; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id BA90E28C719; Wed, 27 Jan 2016 01:49:40 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RP_MATCHES_RCVD,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 347B628C703 for ; Wed, 27 Jan 2016 01:48:36 +0100 (CET) X-policyd-weight: using cached result; rate:hard: -5.5 Received: from mx3.wp.pl (mx3.wp.pl [212.77.101.10]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 27 Jan 2016 01:48:34 +0100 (CET) Received: (wp-smtpd smtp.wp.pl 10623 invoked from network); 27 Jan 2016 01:49:16 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1453855756; bh=I+pRA2Yp7msyj0YHcgVL99Xj+mcW55RlDm+nM694pB4=; h=From:To:Cc:Subject; b=yLm5aDAb6HvTvPnMoYcc7d6CC5WCknxi0KNHEwIjqrJEnvY1kzfr9iaNga1bDa0OA sBxLjgxdpULYoeE+kOrGFMh/T9c04SGC9Hn30ORLSL+bfBC1RiHDPuVEoZVphqRTHO wdXeiFy/jIfGoDgfnb0mMLzOaf+wuyfoc7dMnqes= Received: from 89-71-116-5.dynamic.chello.pl (HELO kosmio) (michal.cieslakiewicz@[89.71.116.5]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP for ; 27 Jan 2016 01:49:16 +0100 Date: Wed, 27 Jan 2016 01:39:00 +0100 From: Michal To: Hartmut Knaack Message-ID: <20160127013900.058e8048@kosmio> In-Reply-To: <20160127010415.7bcf7198@kosmio> References: <56a01420c5aba5.36587961@wp.pl> <56A2C125.1090505@gmx.de> <20160127010415.7bcf7198@kosmio> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.29; x86_64-slackware-linux-gnu) MIME-Version: 1.0 X-WP-MailID: f4b6c14929de87b47db8518039efa6c3 X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [AWOE] Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH 5/8] ath9k: enable GPIO buttons X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" From: Michal Cieslakiewicz Enable platform-defined GPIO button support for ath9k device. Key poller is activated for attached platform buttons. Requires ath9k GPIO chip access. Signed-off-by: Michal Cieslakiewicz --- .../patches/550-ath9k_enable_gpio_buttons.patch | 164 +++++++++++++++++++++ .../ar71xx/files/arch/mips/ath79/dev-ap9x-pci.c | 18 +++ .../ar71xx/files/arch/mips/ath79/dev-ap9x-pci.h | 7 + .../generic/files/include/linux/ath9k_platform.h | 4 + 4 files changed, 193 insertions(+) create mode 100644 package/kernel/mac80211/patches/550-ath9k_enable_gpio_buttons.patch diff --git a/package/kernel/mac80211/patches/550-ath9k_enable_gpio_buttons.patch b/package/kernel/mac80211/patches/550-ath9k_enable_gpio_buttons.patch new file mode 100644 index 0000000..0c8af26 --- /dev/null +++ b/package/kernel/mac80211/patches/550-ath9k_enable_gpio_buttons.patch @@ -0,0 +1,164 @@ +--- a/drivers/net/wireless/ath/ath9k/ath9k.h ++++ b/drivers/net/wireless/ath/ath9k/ath9k.h +@@ -825,6 +825,13 @@ int ath_create_gpio_led(struct ath_softc + void ath9k_register_gpio_chip(struct ath_softc *sc); + void ath9k_unregister_gpio_chip(struct ath_softc *sc); + ++/******************/ ++/* GPIO Buttons */ ++/******************/ ++ ++void ath9k_init_buttons(struct ath_softc *sc); ++void ath9k_deinit_buttons(struct ath_softc *sc); ++ + #else + static inline void ath_init_leds(struct ath_softc *sc) + { +@@ -843,6 +850,13 @@ static inline void ath9k_register_gpio_c + static inline void ath9k_unregister_gpio_chip(struct ath_softc *sc) + { + } ++ ++void ath9k_init_buttons(struct ath_softc *sc) ++{ ++} ++void ath9k_deinit_buttons(struct ath_softc *sc) ++{ ++} + #endif + + /************************/ +@@ -1039,6 +1053,7 @@ struct ath_softc { + const char *led_default_trigger; + struct list_head leds; + struct ath9k_gpio_chip *gpiochip; ++ struct platform_device *btnpdev; /* gpio-keys-polled */ + #endif + + #ifdef CPTCFG_ATH9K_DEBUGFS +--- a/drivers/net/wireless/ath/ath9k/gpio.c ++++ b/drivers/net/wireless/ath/ath9k/gpio.c +@@ -24,6 +24,8 @@ + #ifdef CPTCFG_MAC80211_LEDS + + #include ++#include ++#include + + static void ath_led_brightness(struct led_classdev *led_cdev, + enum led_brightness brightness) +@@ -312,6 +314,83 @@ void ath9k_unregister_gpio_chip(struct a + sc->gpiochip = NULL; + } + ++/******************/ ++/* GPIO Buttons */ ++/******************/ ++ ++/* add GPIO buttons */ ++void ath9k_init_buttons(struct ath_softc *sc) ++{ ++ struct ath9k_platform_data *pdata = sc->dev->platform_data; ++ struct platform_device *pdev; ++ struct gpio_keys_platform_data gkpdata; ++ struct gpio_keys_button *bt; ++ int i; ++ ++ if (!sc->gpiochip) ++ return; ++ ++ bt = kmemdup(pdata->btns, ++ pdata->num_btns * sizeof(struct gpio_keys_button), ++ GFP_KERNEL); ++ ++ if (!bt) ++ return; ++ ++ pdev = platform_device_alloc("gpio-keys-polled", PLATFORM_DEVID_AUTO); ++ ++ if (!pdev) ++ goto err_bt_free; ++ ++ for (i = 0; i < pdata->num_btns; i++) { ++ ath9k_hw_cfg_gpio_input(sc->sc_ah, pdata->btns[i].gpio); ++ bt[i].gpio = sc->gpiochip->gchip.base + pdata->btns[i].gpio; ++ } ++ ++ memset(&gkpdata, 0, sizeof(struct gpio_keys_platform_data)); ++ gkpdata.buttons = bt; ++ gkpdata.nbuttons = pdata->num_btns; ++ gkpdata.poll_interval = pdata->btn_poll_interval; ++ ++ if (platform_device_add_data(pdev, &gkpdata, sizeof(gkpdata))) ++ goto err_pdev_put; ++ ++ if (platform_device_add(pdev)) ++ goto err_pdev_put; ++ ++ sc->btnpdev = pdev; ++ ++ return; ++ ++err_pdev_put: ++ platform_device_put(pdev); ++ ++err_bt_free: ++ kfree(bt); ++} ++ ++/* remove GPIO buttons */ ++void ath9k_deinit_buttons(struct ath_softc *sc) ++{ ++ struct gpio_keys_platform_data *gkpdata; ++ struct gpio_keys_button *bt = NULL; ++ ++ if (!sc->gpiochip || !sc->btnpdev) ++ return; ++ ++ gkpdata = sc->btnpdev->dev.platform_data; ++ if (gkpdata) ++ bt = gkpdata->buttons; ++ ++ platform_device_del(sc->btnpdev); ++ platform_device_put(sc->btnpdev); ++ ++ sc->btnpdev = NULL; ++ ++ if (bt) ++ kfree(bt); ++} ++ + #endif + + /*******************/ +--- a/drivers/net/wireless/ath/ath9k/init.c ++++ b/drivers/net/wireless/ath/ath9k/init.c +@@ -981,6 +981,7 @@ int ath9k_init_device(u16 devid, struct + + ath9k_register_gpio_chip(sc); + ath_init_leds(sc); ++ ath9k_init_buttons(sc); + ath_start_rfkill_poll(sc); + + return 0; +@@ -1026,6 +1027,7 @@ void ath9k_deinit_device(struct ath_soft + ath9k_ps_wakeup(sc); + + wiphy_rfkill_stop_polling(sc->hw->wiphy); ++ ath9k_deinit_buttons(sc); + ath_deinit_leds(sc); + ath9k_unregister_gpio_chip(sc); + +--- a/include/linux/ath9k_platform.h ++++ b/include/linux/ath9k_platform.h +@@ -46,6 +46,10 @@ struct ath9k_platform_data { + int num_leds; + const struct gpio_led *leds; + const char *led_name; ++ ++ unsigned num_btns; ++ const struct gpio_keys_button *btns; ++ unsigned btn_poll_interval; + }; + + #endif /* _LINUX_ATH9K_PLATFORM_H */ diff --git a/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.c b/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.c index bf80d4d..51f361e 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.c @@ -93,6 +93,24 @@ __init void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds, } } +__init void ap9x_pci_setup_wmac_btns(unsigned wmac, + struct gpio_keys_button *btns, + unsigned num_btns, unsigned poll_interval) +{ + struct ath9k_platform_data *ap9x_wmac_data; + + if (wmac == 0) + ap9x_wmac_data = &ap9x_wmac0_data; + else if (wmac == 1) + ap9x_wmac_data = &ap9x_wmac1_data; + else + return; + + ap9x_wmac_data->btns = btns; + ap9x_wmac_data->num_btns = num_btns; + ap9x_wmac_data->btn_poll_interval = poll_interval; +} + static int ap91_pci_plat_dev_init(struct pci_dev *dev) { switch (PCI_SLOT(dev->devfn)) { diff --git a/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.h b/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.h index dcfe541..d7c0185 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.h +++ b/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.h @@ -12,6 +12,7 @@ #define _ATH79_DEV_AP9X_PCI_H struct gpio_led; +struct gpio_keys_button; struct ath9k_platform_data; #if defined(CONFIG_ATH79_DEV_AP9X_PCI) @@ -20,6 +21,8 @@ void ap9x_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val); void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds, int num_leds); void ap9x_pci_setup_wmac_led_name(unsigned wmac, const char *led_name); +void ap9x_pci_setup_wmac_btns(unsigned wmac, struct gpio_keys_button *btns, + unsigned num_btns, unsigned poll_interval); struct ath9k_platform_data *ap9x_pci_get_wmac_data(unsigned wmac); void ap91_pci_init(u8 *cal_data, u8 *mac_addr); @@ -36,6 +39,10 @@ static inline void ap9x_pci_setup_wmac_leds(unsigned wmac, int num_leds) {} static inline void ap9x_pci_setup_wmac_led_name(unsigned wmac, const char *led_name) {} +static inline void ap9x_pci_setup_wmac_btns(unsigned wmac, + struct gpio_keys_button *btns, + unsigned num_btns, + unsigned poll_interval) {} static inline struct ath9k_platform_data *ap9x_pci_get_wmac_data(unsigned wmac) { return NULL; diff --git a/target/linux/generic/files/include/linux/ath9k_platform.h b/target/linux/generic/files/include/linux/ath9k_platform.h index 823e5ac..e543a64 100644 --- a/target/linux/generic/files/include/linux/ath9k_platform.h +++ b/target/linux/generic/files/include/linux/ath9k_platform.h @@ -46,6 +46,10 @@ struct ath9k_platform_data { int num_leds; const struct gpio_led *leds; const char *led_name; + + unsigned num_btns; + const struct gpio_keys_button *btns; + unsigned btn_poll_interval; }; #endif /* _LINUX_ATH9K_PLATFORM_H */