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>
10 drivers/net/wireless/ath/ath9k/ath9k.h | 16 ++++++
11 drivers/net/wireless/ath/ath9k/gpio.c | 77 +++++++++++++++++++++++++++++++++
12 drivers/net/wireless/ath/ath9k/init.c | 2
13 include/linux/ath9k_platform.h | 4 +
14 4 files changed, 99 insertions(+)
16 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
17 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
18 @@ -825,6 +825,13 @@ int ath_create_gpio_led(struct ath_softc
19 void ath9k_register_gpio_chip(struct ath_softc *sc);
20 void ath9k_unregister_gpio_chip(struct ath_softc *sc);
26 +void ath9k_init_buttons(struct ath_softc *sc);
27 +void ath9k_deinit_buttons(struct ath_softc *sc);
30 static inline void ath_init_leds(struct ath_softc *sc)
32 @@ -844,6 +851,14 @@ static inline void ath9k_register_gpio_c
33 static inline void ath9k_unregister_gpio_chip(struct ath_softc *sc)
37 +static inline void ath9k_init_buttons(struct ath_softc *sc)
41 +static inline void ath9k_deinit_buttons(struct ath_softc *sc)
46 /************************/
47 @@ -1040,6 +1055,7 @@ struct ath_softc {
48 const char *led_default_trigger;
49 struct list_head leds;
50 struct ath9k_gpio_chip *gpiochip;
51 + struct platform_device *btnpdev; /* gpio-keys-polled */
54 #ifdef CPTCFG_ATH9K_DEBUGFS
55 --- a/drivers/net/wireless/ath/ath9k/gpio.c
56 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
58 #ifdef CPTCFG_MAC80211_LEDS
60 #include <asm-generic/gpio.h>
61 +#include <linux/platform_device.h>
62 +#include <linux/gpio_keys.h>
64 static void ath_led_brightness(struct led_classdev *led_cdev,
65 enum led_brightness brightness)
66 @@ -159,7 +161,7 @@ void ath_init_leds(struct ath_softc *sc)
67 ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger,
68 !sc->sc_ah->config.led_active_high);
71 + if (!pdata || !pdata->leds || !pdata->num_leds)
74 for (i = 0; i < pdata->num_leds; i++)
75 @@ -307,6 +309,63 @@ void ath9k_unregister_gpio_chip(struct a
83 +/* add GPIO buttons */
84 +void ath9k_init_buttons(struct ath_softc *sc)
86 + struct ath9k_platform_data *pdata = sc->dev->platform_data;
87 + struct platform_device *pdev;
88 + struct gpio_keys_platform_data gkpdata;
89 + struct gpio_keys_button *bt;
95 + if (!pdata || !pdata->btns || !pdata->num_btns)
98 + bt = devm_kmemdup(sc->dev, pdata->btns,
99 + pdata->num_btns * sizeof(struct gpio_keys_button),
104 + for (i = 0; i < pdata->num_btns; i++) {
105 + ath9k_hw_cfg_gpio_input(sc->sc_ah, pdata->btns[i].gpio);
106 + bt[i].gpio = sc->gpiochip->gchip.base + pdata->btns[i].gpio;
109 + memset(&gkpdata, 0, sizeof(struct gpio_keys_platform_data));
110 + gkpdata.buttons = bt;
111 + gkpdata.nbuttons = pdata->num_btns;
112 + gkpdata.poll_interval = pdata->btn_poll_interval;
114 + pdev = platform_device_register_data(sc->dev, "gpio-keys-polled",
115 + PLATFORM_DEVID_AUTO, &gkpdata,
117 + if (!IS_ERR_OR_NULL(pdev))
118 + sc->btnpdev = pdev;
120 + sc->btnpdev = NULL;
121 + devm_kfree(sc->dev, bt);
125 +/* remove GPIO buttons */
126 +void ath9k_deinit_buttons(struct ath_softc *sc)
128 + if (!sc->gpiochip || !sc->btnpdev)
131 + platform_device_unregister(sc->btnpdev);
133 + sc->btnpdev = NULL;
138 /*******************/
139 --- a/drivers/net/wireless/ath/ath9k/init.c
140 +++ b/drivers/net/wireless/ath/ath9k/init.c
141 @@ -977,6 +977,7 @@ int ath9k_init_device(u16 devid, struct
143 ath9k_register_gpio_chip(sc);
145 + ath9k_init_buttons(sc);
146 ath_start_rfkill_poll(sc);
149 @@ -1022,6 +1023,7 @@ void ath9k_deinit_device(struct ath_soft
152 wiphy_rfkill_stop_polling(sc->hw->wiphy);
153 + ath9k_deinit_buttons(sc);
155 ath9k_unregister_gpio_chip(sc);
157 --- a/include/linux/ath9k_platform.h
158 +++ b/include/linux/ath9k_platform.h
159 @@ -46,6 +46,10 @@ struct ath9k_platform_data {
161 const struct gpio_led *leds;
162 const char *led_name;
165 + const struct gpio_keys_button *btns;
166 + unsigned btn_poll_interval;
169 #endif /* _LINUX_ATH9K_PLATFORM_H */