2016-03-05 09:45:03 +00:00
|
|
|
From: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
|
|
|
|
Subject: [PATCH v5 5/8] mac80211: ath9k: enable GPIO buttons
|
|
|
|
|
|
|
|
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 <michal.cieslakiewicz@wp.pl>
|
2016-06-07 06:58:31 +00:00
|
|
|
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
2016-03-05 09:45:03 +00:00
|
|
|
---
|
|
|
|
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
|
|
|
|
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
|
2017-01-31 10:38:25 +00:00
|
|
|
@@ -1069,6 +1069,7 @@ struct ath_softc {
|
2016-03-05 09:45:03 +00:00
|
|
|
struct list_head leds;
|
2016-03-07 09:20:22 +00:00
|
|
|
#ifdef CONFIG_GPIOLIB
|
2016-03-05 09:45:03 +00:00
|
|
|
struct ath9k_gpio_chip *gpiochip;
|
|
|
|
+ struct platform_device *btnpdev; /* gpio-keys-polled */
|
|
|
|
#endif
|
2016-03-07 09:20:22 +00:00
|
|
|
#endif
|
2016-03-05 09:45:03 +00:00
|
|
|
|
|
|
|
--- a/drivers/net/wireless/ath/ath9k/gpio.c
|
|
|
|
+++ b/drivers/net/wireless/ath/ath9k/gpio.c
|
2016-03-07 09:20:22 +00:00
|
|
|
@@ -17,6 +17,8 @@
|
|
|
|
#include "ath9k.h"
|
|
|
|
#include <linux/ath9k_platform.h>
|
|
|
|
#include <linux/gpio.h>
|
2016-03-05 09:45:03 +00:00
|
|
|
+#include <linux/platform_device.h>
|
|
|
|
+#include <linux/gpio_keys.h>
|
|
|
|
|
2016-03-07 09:20:22 +00:00
|
|
|
#ifdef CPTCFG_MAC80211_LEDS
|
2016-03-05 09:45:03 +00:00
|
|
|
|
2018-12-07 08:42:09 +00:00
|
|
|
@@ -133,6 +135,67 @@ static void ath9k_unregister_gpio_chip(s
|
2016-03-05 09:45:03 +00:00
|
|
|
sc->gpiochip = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
+/******************/
|
|
|
|
+/* GPIO Buttons */
|
|
|
|
+/******************/
|
|
|
|
+
|
|
|
|
+/* add GPIO buttons */
|
2016-03-07 09:20:22 +00:00
|
|
|
+static void ath9k_init_buttons(struct ath_softc *sc)
|
2016-03-05 09:45:03 +00:00
|
|
|
+{
|
|
|
|
+ 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;
|
|
|
|
+
|
|
|
|
+ if (!pdata || !pdata->btns || !pdata->num_btns)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ bt = devm_kmemdup(sc->dev, pdata->btns,
|
|
|
|
+ pdata->num_btns * sizeof(struct gpio_keys_button),
|
|
|
|
+ GFP_KERNEL);
|
|
|
|
+ if (!bt)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < pdata->num_btns; i++) {
|
2017-11-03 06:25:21 +00:00
|
|
|
+ if (pdata->btns[i].gpio == sc->sc_ah->led_pin)
|
|
|
|
+ sc->sc_ah->led_pin = -1;
|
|
|
|
+
|
2016-05-14 15:38:56 +00:00
|
|
|
+ ath9k_hw_gpio_request_in(sc->sc_ah, pdata->btns[i].gpio,
|
|
|
|
+ "ath9k-gpio");
|
2016-03-05 09:45:03 +00:00
|
|
|
+ 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;
|
|
|
|
+
|
|
|
|
+ pdev = platform_device_register_data(sc->dev, "gpio-keys-polled",
|
|
|
|
+ PLATFORM_DEVID_AUTO, &gkpdata,
|
|
|
|
+ sizeof(gkpdata));
|
|
|
|
+ if (!IS_ERR_OR_NULL(pdev))
|
|
|
|
+ sc->btnpdev = pdev;
|
|
|
|
+ else {
|
|
|
|
+ sc->btnpdev = NULL;
|
|
|
|
+ devm_kfree(sc->dev, bt);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* remove GPIO buttons */
|
2016-03-07 09:20:22 +00:00
|
|
|
+static void ath9k_deinit_buttons(struct ath_softc *sc)
|
2016-03-05 09:45:03 +00:00
|
|
|
+{
|
|
|
|
+ if (!sc->gpiochip || !sc->btnpdev)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ platform_device_unregister(sc->btnpdev);
|
|
|
|
+
|
|
|
|
+ sc->btnpdev = NULL;
|
|
|
|
+}
|
|
|
|
+
|
2016-03-07 09:20:22 +00:00
|
|
|
#else /* CONFIG_GPIOLIB */
|
2016-03-05 09:45:03 +00:00
|
|
|
|
2016-03-07 09:20:22 +00:00
|
|
|
static inline void ath9k_register_gpio_chip(struct ath_softc *sc)
|
2018-12-07 08:42:09 +00:00
|
|
|
@@ -143,6 +206,14 @@ static inline void ath9k_unregister_gpio
|
2016-03-07 09:20:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
+static inline void ath9k_init_buttons(struct ath_softc *sc)
|
|
|
|
+{
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static inline void ath9k_deinit_buttons(struct ath_softc *sc)
|
|
|
|
+{
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
#endif /* CONFIG_GPIOLIB */
|
|
|
|
|
|
|
|
/********************************/
|
2018-12-07 08:42:09 +00:00
|
|
|
@@ -266,6 +337,7 @@ void ath_deinit_leds(struct ath_softc *s
|
2016-03-07 09:20:22 +00:00
|
|
|
{
|
|
|
|
struct ath_led *led;
|
|
|
|
|
|
|
|
+ ath9k_deinit_buttons(sc);
|
|
|
|
while (!list_empty(&sc->leds)) {
|
|
|
|
led = list_first_entry(&sc->leds, struct ath_led, list);
|
|
|
|
#ifdef CONFIG_GPIOLIB
|
2018-12-07 08:42:09 +00:00
|
|
|
@@ -305,6 +377,7 @@ void ath_init_leds(struct ath_softc *sc)
|
2017-03-22 07:04:16 +00:00
|
|
|
}
|
2016-03-05 09:45:03 +00:00
|
|
|
|
2017-03-22 06:29:32 +00:00
|
|
|
ath_fill_led_pin(sc);
|
2016-03-05 09:45:03 +00:00
|
|
|
+ ath9k_init_buttons(sc);
|
|
|
|
|
2017-03-21 22:21:57 +00:00
|
|
|
if (pdata && pdata->leds && pdata->num_leds)
|
|
|
|
for (i = 0; i < pdata->num_leds; i++) {
|
2016-03-05 09:45:03 +00:00
|
|
|
--- a/include/linux/ath9k_platform.h
|
|
|
|
+++ b/include/linux/ath9k_platform.h
|
2017-03-25 10:48:02 +00:00
|
|
|
@@ -49,6 +49,10 @@ struct ath9k_platform_data {
|
|
|
|
|
2016-03-05 09:45:03 +00:00
|
|
|
int num_leds;
|
|
|
|
const struct gpio_led *leds;
|
|
|
|
+
|
|
|
|
+ unsigned num_btns;
|
|
|
|
+ const struct gpio_keys_button *btns;
|
|
|
|
+ unsigned btn_poll_interval;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _LINUX_ATH9K_PLATFORM_H */
|