1 From: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
2 Subject: [PATCH v5 5/8] mac80211: ath9k: enable GPIO buttons
4 Enable platform-defined GPIO button support for ath9k device.
5 Key poller is activated for attached platform buttons.
6 Requires ath9k GPIO chip access.
8 Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
12 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
13 @@ -1055,6 +1055,7 @@ struct ath_softc {
14 struct list_head leds;
16 struct ath9k_gpio_chip *gpiochip;
17 + struct platform_device *btnpdev; /* gpio-keys-polled */
21 --- a/drivers/net/wireless/ath/ath9k/gpio.c
22 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
25 #include <linux/ath9k_platform.h>
26 #include <linux/gpio.h>
27 +#include <linux/platform_device.h>
28 +#include <linux/gpio_keys.h>
30 #ifdef CPTCFG_MAC80211_LEDS
32 @@ -133,6 +135,67 @@ static void ath9k_unregister_gpio_chip(s
40 +/* add GPIO buttons */
41 +static void ath9k_init_buttons(struct ath_softc *sc)
43 + struct ath9k_platform_data *pdata = sc->dev->platform_data;
44 + struct platform_device *pdev;
45 + struct gpio_keys_platform_data gkpdata;
46 + struct gpio_keys_button *bt;
52 + if (!pdata || !pdata->btns || !pdata->num_btns)
55 + bt = devm_kmemdup(sc->dev, pdata->btns,
56 + pdata->num_btns * sizeof(struct gpio_keys_button),
61 + for (i = 0; i < pdata->num_btns; i++) {
62 + if (pdata->btns[i].gpio == sc->sc_ah->led_pin)
63 + sc->sc_ah->led_pin = -1;
65 + ath9k_hw_gpio_request_in(sc->sc_ah, pdata->btns[i].gpio,
67 + bt[i].gpio = sc->gpiochip->gchip.base + pdata->btns[i].gpio;
70 + memset(&gkpdata, 0, sizeof(struct gpio_keys_platform_data));
71 + gkpdata.buttons = bt;
72 + gkpdata.nbuttons = pdata->num_btns;
73 + gkpdata.poll_interval = pdata->btn_poll_interval;
75 + pdev = platform_device_register_data(sc->dev, "gpio-keys-polled",
76 + PLATFORM_DEVID_AUTO, &gkpdata,
78 + if (!IS_ERR_OR_NULL(pdev))
82 + devm_kfree(sc->dev, bt);
86 +/* remove GPIO buttons */
87 +static void ath9k_deinit_buttons(struct ath_softc *sc)
89 + if (!sc->gpiochip || !sc->btnpdev)
92 + platform_device_unregister(sc->btnpdev);
97 #else /* CONFIG_GPIOLIB */
99 static inline void ath9k_register_gpio_chip(struct ath_softc *sc)
100 @@ -143,6 +206,14 @@ static inline void ath9k_unregister_gpio
104 +static inline void ath9k_init_buttons(struct ath_softc *sc)
108 +static inline void ath9k_deinit_buttons(struct ath_softc *sc)
112 #endif /* CONFIG_GPIOLIB */
114 /********************************/
115 @@ -266,6 +337,7 @@ void ath_deinit_leds(struct ath_softc *s
119 + ath9k_deinit_buttons(sc);
120 while (!list_empty(&sc->leds)) {
121 led = list_first_entry(&sc->leds, struct ath_led, list);
122 #ifdef CONFIG_GPIOLIB
123 @@ -305,6 +377,7 @@ void ath_init_leds(struct ath_softc *sc)
126 ath_fill_led_pin(sc);
127 + ath9k_init_buttons(sc);
129 if (pdata && pdata->leds && pdata->num_leds)
130 for (i = 0; i < pdata->num_leds; i++) {
131 --- a/include/linux/ath9k_platform.h
132 +++ b/include/linux/ath9k_platform.h
133 @@ -49,6 +49,10 @@ struct ath9k_platform_data {
136 const struct gpio_led *leds;
139 + const struct gpio_keys_button *btns;
140 + unsigned btn_poll_interval;
143 #endif /* _LINUX_ATH9K_PLATFORM_H */