549-ath9k_enable_gpio_buttons.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. From: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
  2. Subject: [PATCH v5 5/8] mac80211: ath9k: enable GPIO buttons
  3. Enable platform-defined GPIO button support for ath9k device.
  4. Key poller is activated for attached platform buttons.
  5. Requires ath9k GPIO chip access.
  6. Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
  7. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  8. ---
  9. --- a/drivers/net/wireless/ath/ath9k/ath9k.h
  10. +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
  11. @@ -1069,6 +1069,7 @@ struct ath_softc {
  12. struct list_head leds;
  13. #ifdef CONFIG_GPIOLIB
  14. struct ath9k_gpio_chip *gpiochip;
  15. + struct platform_device *btnpdev; /* gpio-keys-polled */
  16. #endif
  17. #endif
  18. --- a/drivers/net/wireless/ath/ath9k/gpio.c
  19. +++ b/drivers/net/wireless/ath/ath9k/gpio.c
  20. @@ -17,6 +17,8 @@
  21. #include "ath9k.h"
  22. #include <linux/ath9k_platform.h>
  23. #include <linux/gpio.h>
  24. +#include <linux/platform_device.h>
  25. +#include <linux/gpio_keys.h>
  26. #ifdef CPTCFG_MAC80211_LEDS
  27. @@ -133,6 +135,67 @@ static void ath9k_unregister_gpio_chip(s
  28. sc->gpiochip = NULL;
  29. }
  30. +/******************/
  31. +/* GPIO Buttons */
  32. +/******************/
  33. +
  34. +/* add GPIO buttons */
  35. +static void ath9k_init_buttons(struct ath_softc *sc)
  36. +{
  37. + struct ath9k_platform_data *pdata = sc->dev->platform_data;
  38. + struct platform_device *pdev;
  39. + struct gpio_keys_platform_data gkpdata;
  40. + struct gpio_keys_button *bt;
  41. + int i;
  42. +
  43. + if (!sc->gpiochip)
  44. + return;
  45. +
  46. + if (!pdata || !pdata->btns || !pdata->num_btns)
  47. + return;
  48. +
  49. + bt = devm_kmemdup(sc->dev, pdata->btns,
  50. + pdata->num_btns * sizeof(struct gpio_keys_button),
  51. + GFP_KERNEL);
  52. + if (!bt)
  53. + return;
  54. +
  55. + for (i = 0; i < pdata->num_btns; i++) {
  56. + if (pdata->btns[i].gpio == sc->sc_ah->led_pin)
  57. + sc->sc_ah->led_pin = -1;
  58. +
  59. + ath9k_hw_gpio_request_in(sc->sc_ah, pdata->btns[i].gpio,
  60. + "ath9k-gpio");
  61. + bt[i].gpio = sc->gpiochip->gchip.base + pdata->btns[i].gpio;
  62. + }
  63. +
  64. + memset(&gkpdata, 0, sizeof(struct gpio_keys_platform_data));
  65. + gkpdata.buttons = bt;
  66. + gkpdata.nbuttons = pdata->num_btns;
  67. + gkpdata.poll_interval = pdata->btn_poll_interval;
  68. +
  69. + pdev = platform_device_register_data(sc->dev, "gpio-keys-polled",
  70. + PLATFORM_DEVID_AUTO, &gkpdata,
  71. + sizeof(gkpdata));
  72. + if (!IS_ERR_OR_NULL(pdev))
  73. + sc->btnpdev = pdev;
  74. + else {
  75. + sc->btnpdev = NULL;
  76. + devm_kfree(sc->dev, bt);
  77. + }
  78. +}
  79. +
  80. +/* remove GPIO buttons */
  81. +static void ath9k_deinit_buttons(struct ath_softc *sc)
  82. +{
  83. + if (!sc->gpiochip || !sc->btnpdev)
  84. + return;
  85. +
  86. + platform_device_unregister(sc->btnpdev);
  87. +
  88. + sc->btnpdev = NULL;
  89. +}
  90. +
  91. #else /* CONFIG_GPIOLIB */
  92. static inline void ath9k_register_gpio_chip(struct ath_softc *sc)
  93. @@ -143,6 +206,14 @@ static inline void ath9k_unregister_gpio
  94. {
  95. }
  96. +static inline void ath9k_init_buttons(struct ath_softc *sc)
  97. +{
  98. +}
  99. +
  100. +static inline void ath9k_deinit_buttons(struct ath_softc *sc)
  101. +{
  102. +}
  103. +
  104. #endif /* CONFIG_GPIOLIB */
  105. /********************************/
  106. @@ -266,6 +337,7 @@ void ath_deinit_leds(struct ath_softc *s
  107. {
  108. struct ath_led *led;
  109. + ath9k_deinit_buttons(sc);
  110. while (!list_empty(&sc->leds)) {
  111. led = list_first_entry(&sc->leds, struct ath_led, list);
  112. #ifdef CONFIG_GPIOLIB
  113. @@ -305,6 +377,7 @@ void ath_init_leds(struct ath_softc *sc)
  114. }
  115. ath_fill_led_pin(sc);
  116. + ath9k_init_buttons(sc);
  117. if (pdata && pdata->leds && pdata->num_leds)
  118. for (i = 0; i < pdata->num_leds; i++) {
  119. --- a/include/linux/ath9k_platform.h
  120. +++ b/include/linux/ath9k_platform.h
  121. @@ -49,6 +49,10 @@ struct ath9k_platform_data {
  122. int num_leds;
  123. const struct gpio_led *leds;
  124. +
  125. + unsigned num_btns;
  126. + const struct gpio_keys_button *btns;
  127. + unsigned btn_poll_interval;
  128. };
  129. #endif /* _LINUX_ATH9K_PLATFORM_H */