0084-mac80211-ath9k-enable-GPIO-buttons.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sun, 29 May 2016 13:38:45 +0200
  3. Subject: 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.
  7. Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
  8. Backport of r48921
  9. diff --git a/package/kernel/mac80211/patches/550-ath9k_enable_gpio_buttons.patch b/package/kernel/mac80211/patches/550-ath9k_enable_gpio_buttons.patch
  10. new file mode 100644
  11. index 0000000..e3a8cec
  12. --- /dev/null
  13. +++ b/package/kernel/mac80211/patches/550-ath9k_enable_gpio_buttons.patch
  14. @@ -0,0 +1,169 @@
  15. +From: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
  16. +Subject: [PATCH v5 5/8] mac80211: ath9k: enable GPIO buttons
  17. +
  18. +Enable platform-defined GPIO button support for ath9k device.
  19. +Key poller is activated for attached platform buttons.
  20. +Requires ath9k GPIO chip access.
  21. +
  22. +Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
  23. +---
  24. + drivers/net/wireless/ath/ath9k/ath9k.h | 16 ++++++
  25. + drivers/net/wireless/ath/ath9k/gpio.c | 77 +++++++++++++++++++++++++++++++++
  26. + drivers/net/wireless/ath/ath9k/init.c | 2
  27. + include/linux/ath9k_platform.h | 4 +
  28. + 4 files changed, 99 insertions(+)
  29. +
  30. +--- a/drivers/net/wireless/ath/ath9k/ath9k.h
  31. ++++ b/drivers/net/wireless/ath/ath9k/ath9k.h
  32. +@@ -825,6 +825,13 @@ int ath_create_gpio_led(struct ath_softc
  33. + void ath9k_register_gpio_chip(struct ath_softc *sc);
  34. + void ath9k_unregister_gpio_chip(struct ath_softc *sc);
  35. +
  36. ++/******************/
  37. ++/* GPIO Buttons */
  38. ++/******************/
  39. ++
  40. ++void ath9k_init_buttons(struct ath_softc *sc);
  41. ++void ath9k_deinit_buttons(struct ath_softc *sc);
  42. ++
  43. + #else
  44. + static inline void ath_init_leds(struct ath_softc *sc)
  45. + {
  46. +@@ -844,6 +851,14 @@ static inline void ath9k_register_gpio_c
  47. + static inline void ath9k_unregister_gpio_chip(struct ath_softc *sc)
  48. + {
  49. + }
  50. ++
  51. ++static inline void ath9k_init_buttons(struct ath_softc *sc)
  52. ++{
  53. ++}
  54. ++
  55. ++static inline void ath9k_deinit_buttons(struct ath_softc *sc)
  56. ++{
  57. ++}
  58. + #endif
  59. +
  60. + /************************/
  61. +@@ -1040,6 +1055,7 @@ struct ath_softc {
  62. + const char *led_default_trigger;
  63. + struct list_head leds;
  64. + struct ath9k_gpio_chip *gpiochip;
  65. ++ struct platform_device *btnpdev; /* gpio-keys-polled */
  66. + #endif
  67. +
  68. + #ifdef CPTCFG_ATH9K_DEBUGFS
  69. +--- a/drivers/net/wireless/ath/ath9k/gpio.c
  70. ++++ b/drivers/net/wireless/ath/ath9k/gpio.c
  71. +@@ -24,6 +24,8 @@
  72. + #ifdef CPTCFG_MAC80211_LEDS
  73. +
  74. + #include <asm-generic/gpio.h>
  75. ++#include <linux/platform_device.h>
  76. ++#include <linux/gpio_keys.h>
  77. +
  78. + static void ath_led_brightness(struct led_classdev *led_cdev,
  79. + enum led_brightness brightness)
  80. +@@ -159,7 +161,7 @@ void ath_init_leds(struct ath_softc *sc)
  81. + ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger,
  82. + !sc->sc_ah->config.led_active_high);
  83. +
  84. +- if (!pdata)
  85. ++ if (!pdata || !pdata->leds || !pdata->num_leds)
  86. + return;
  87. +
  88. + for (i = 0; i < pdata->num_leds; i++)
  89. +@@ -307,6 +309,63 @@ void ath9k_unregister_gpio_chip(struct a
  90. + sc->gpiochip = NULL;
  91. + }
  92. +
  93. ++/******************/
  94. ++/* GPIO Buttons */
  95. ++/******************/
  96. ++
  97. ++/* add GPIO buttons */
  98. ++void ath9k_init_buttons(struct ath_softc *sc)
  99. ++{
  100. ++ struct ath9k_platform_data *pdata = sc->dev->platform_data;
  101. ++ struct platform_device *pdev;
  102. ++ struct gpio_keys_platform_data gkpdata;
  103. ++ struct gpio_keys_button *bt;
  104. ++ int i;
  105. ++
  106. ++ if (!sc->gpiochip)
  107. ++ return;
  108. ++
  109. ++ if (!pdata || !pdata->btns || !pdata->num_btns)
  110. ++ return;
  111. ++
  112. ++ bt = devm_kmemdup(sc->dev, pdata->btns,
  113. ++ pdata->num_btns * sizeof(struct gpio_keys_button),
  114. ++ GFP_KERNEL);
  115. ++ if (!bt)
  116. ++ return;
  117. ++
  118. ++ for (i = 0; i < pdata->num_btns; i++) {
  119. ++ ath9k_hw_cfg_gpio_input(sc->sc_ah, pdata->btns[i].gpio);
  120. ++ bt[i].gpio = sc->gpiochip->gchip.base + pdata->btns[i].gpio;
  121. ++ }
  122. ++
  123. ++ memset(&gkpdata, 0, sizeof(struct gpio_keys_platform_data));
  124. ++ gkpdata.buttons = bt;
  125. ++ gkpdata.nbuttons = pdata->num_btns;
  126. ++ gkpdata.poll_interval = pdata->btn_poll_interval;
  127. ++
  128. ++ pdev = platform_device_register_data(sc->dev, "gpio-keys-polled",
  129. ++ PLATFORM_DEVID_AUTO, &gkpdata,
  130. ++ sizeof(gkpdata));
  131. ++ if (!IS_ERR_OR_NULL(pdev))
  132. ++ sc->btnpdev = pdev;
  133. ++ else {
  134. ++ sc->btnpdev = NULL;
  135. ++ devm_kfree(sc->dev, bt);
  136. ++ }
  137. ++}
  138. ++
  139. ++/* remove GPIO buttons */
  140. ++void ath9k_deinit_buttons(struct ath_softc *sc)
  141. ++{
  142. ++ if (!sc->gpiochip || !sc->btnpdev)
  143. ++ return;
  144. ++
  145. ++ platform_device_unregister(sc->btnpdev);
  146. ++
  147. ++ sc->btnpdev = NULL;
  148. ++}
  149. ++
  150. + #endif
  151. +
  152. + /*******************/
  153. +--- a/drivers/net/wireless/ath/ath9k/init.c
  154. ++++ b/drivers/net/wireless/ath/ath9k/init.c
  155. +@@ -977,6 +977,7 @@ int ath9k_init_device(u16 devid, struct
  156. +
  157. + ath9k_register_gpio_chip(sc);
  158. + ath_init_leds(sc);
  159. ++ ath9k_init_buttons(sc);
  160. + ath_start_rfkill_poll(sc);
  161. +
  162. + return 0;
  163. +@@ -1022,6 +1023,7 @@ void ath9k_deinit_device(struct ath_soft
  164. + ath9k_ps_wakeup(sc);
  165. +
  166. + wiphy_rfkill_stop_polling(sc->hw->wiphy);
  167. ++ ath9k_deinit_buttons(sc);
  168. + ath_deinit_leds(sc);
  169. + ath9k_unregister_gpio_chip(sc);
  170. +
  171. +--- a/include/linux/ath9k_platform.h
  172. ++++ b/include/linux/ath9k_platform.h
  173. +@@ -46,6 +46,10 @@ struct ath9k_platform_data {
  174. + int num_leds;
  175. + const struct gpio_led *leds;
  176. + const char *led_name;
  177. ++
  178. ++ unsigned num_btns;
  179. ++ const struct gpio_keys_button *btns;
  180. ++ unsigned btn_poll_interval;
  181. + };
  182. +
  183. + #endif /* _LINUX_ATH9K_PLATFORM_H */
  184. 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
  185. index bf80d4d..20bb06e 100644
  186. --- a/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.c
  187. +++ b/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.c
  188. @@ -93,6 +93,20 @@ __init void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds,
  189. }
  190. }
  191. +__init void ap9x_pci_setup_wmac_btns(unsigned wmac,
  192. + struct gpio_keys_button *btns,
  193. + unsigned num_btns, unsigned poll_interval)
  194. +{
  195. + struct ath9k_platform_data *ap9x_wmac_data;
  196. +
  197. + if (!(ap9x_wmac_data = ap9x_pci_get_wmac_data(wmac)))
  198. + return;
  199. +
  200. + ap9x_wmac_data->btns = btns;
  201. + ap9x_wmac_data->num_btns = num_btns;
  202. + ap9x_wmac_data->btn_poll_interval = poll_interval;
  203. +}
  204. +
  205. static int ap91_pci_plat_dev_init(struct pci_dev *dev)
  206. {
  207. switch (PCI_SLOT(dev->devfn)) {
  208. 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
  209. index dcfe541..d7c0185 100644
  210. --- a/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.h
  211. +++ b/target/linux/ar71xx/files/arch/mips/ath79/dev-ap9x-pci.h
  212. @@ -12,6 +12,7 @@
  213. #define _ATH79_DEV_AP9X_PCI_H
  214. struct gpio_led;
  215. +struct gpio_keys_button;
  216. struct ath9k_platform_data;
  217. #if defined(CONFIG_ATH79_DEV_AP9X_PCI)
  218. @@ -20,6 +21,8 @@ void ap9x_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val);
  219. void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds,
  220. int num_leds);
  221. void ap9x_pci_setup_wmac_led_name(unsigned wmac, const char *led_name);
  222. +void ap9x_pci_setup_wmac_btns(unsigned wmac, struct gpio_keys_button *btns,
  223. + unsigned num_btns, unsigned poll_interval);
  224. struct ath9k_platform_data *ap9x_pci_get_wmac_data(unsigned wmac);
  225. void ap91_pci_init(u8 *cal_data, u8 *mac_addr);
  226. @@ -36,6 +39,10 @@ static inline void ap9x_pci_setup_wmac_leds(unsigned wmac,
  227. int num_leds) {}
  228. static inline void ap9x_pci_setup_wmac_led_name(unsigned wmac,
  229. const char *led_name) {}
  230. +static inline void ap9x_pci_setup_wmac_btns(unsigned wmac,
  231. + struct gpio_keys_button *btns,
  232. + unsigned num_btns,
  233. + unsigned poll_interval) {}
  234. static inline struct ath9k_platform_data *ap9x_pci_get_wmac_data(unsigned wmac)
  235. {
  236. return NULL;
  237. diff --git a/target/linux/generic/files/include/linux/ath9k_platform.h b/target/linux/generic/files/include/linux/ath9k_platform.h
  238. index 823e5ac..e543a64 100644
  239. --- a/target/linux/generic/files/include/linux/ath9k_platform.h
  240. +++ b/target/linux/generic/files/include/linux/ath9k_platform.h
  241. @@ -46,6 +46,10 @@ struct ath9k_platform_data {
  242. int num_leds;
  243. const struct gpio_led *leds;
  244. const char *led_name;
  245. +
  246. + unsigned num_btns;
  247. + const struct gpio_keys_button *btns;
  248. + unsigned btn_poll_interval;
  249. };
  250. #endif /* _LINUX_ATH9K_PLATFORM_H */