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 @@ -1038,6 +1038,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 @@ -129,6 +131,64 @@ 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 + ath9k_hw_gpio_request_in(sc->sc_ah, pdata->btns[i].gpio,
64 + bt[i].gpio = sc->gpiochip->gchip.base + pdata->btns[i].gpio;
67 + memset(&gkpdata, 0, sizeof(struct gpio_keys_platform_data));
68 + gkpdata.buttons = bt;
69 + gkpdata.nbuttons = pdata->num_btns;
70 + gkpdata.poll_interval = pdata->btn_poll_interval;
72 + pdev = platform_device_register_data(sc->dev, "gpio-keys-polled",
73 + PLATFORM_DEVID_AUTO, &gkpdata,
75 + if (!IS_ERR_OR_NULL(pdev))
79 + devm_kfree(sc->dev, bt);
83 +/* remove GPIO buttons */
84 +static void ath9k_deinit_buttons(struct ath_softc *sc)
86 + if (!sc->gpiochip || !sc->btnpdev)
89 + platform_device_unregister(sc->btnpdev);
94 #else /* CONFIG_GPIOLIB */
96 static inline void ath9k_register_gpio_chip(struct ath_softc *sc)
97 @@ -139,6 +199,14 @@ static inline void ath9k_unregister_gpio
101 +static inline void ath9k_init_buttons(struct ath_softc *sc)
105 +static inline void ath9k_deinit_buttons(struct ath_softc *sc)
109 #endif /* CONFIG_GPIOLIB */
111 /********************************/
112 @@ -262,6 +330,7 @@ void ath_deinit_leds(struct ath_softc *s
116 + ath9k_deinit_buttons(sc);
117 while (!list_empty(&sc->leds)) {
118 led = list_first_entry(&sc->leds, struct ath_led, list);
119 #ifdef CONFIG_GPIOLIB
120 @@ -293,6 +362,7 @@ void ath_init_leds(struct ath_softc *sc)
121 ath_fill_led_pin(sc);
123 ath9k_register_gpio_chip(sc);
124 + ath9k_init_buttons(sc);
126 if (pdata && pdata->led_name)
127 strncpy(led_name, pdata->led_name, sizeof(led_name));
128 @@ -308,7 +378,7 @@ void ath_init_leds(struct ath_softc *sc)
129 ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger,
130 !sc->sc_ah->config.led_active_high);
133 + if (!pdata || !pdata->leds || !pdata->num_leds)
136 for (i = 0; i < pdata->num_leds; i++)
137 --- a/include/linux/ath9k_platform.h
138 +++ b/include/linux/ath9k_platform.h
139 @@ -50,6 +50,10 @@ struct ath9k_platform_data {
141 const struct gpio_led *leds;
142 const char *led_name;
145 + const struct gpio_keys_button *btns;
146 + unsigned btn_poll_interval;
149 #endif /* _LINUX_ATH9K_PLATFORM_H */