549-ath9k_enable_gpio_buttons.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. @@ -129,6 +131,64 @@ 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. + ath9k_hw_gpio_request_in(sc->sc_ah, pdata->btns[i].gpio,
  57. + "ath9k-gpio");
  58. + bt[i].gpio = sc->gpiochip->gchip.base + pdata->btns[i].gpio;
  59. + }
  60. +
  61. + memset(&gkpdata, 0, sizeof(struct gpio_keys_platform_data));
  62. + gkpdata.buttons = bt;
  63. + gkpdata.nbuttons = pdata->num_btns;
  64. + gkpdata.poll_interval = pdata->btn_poll_interval;
  65. +
  66. + pdev = platform_device_register_data(sc->dev, "gpio-keys-polled",
  67. + PLATFORM_DEVID_AUTO, &gkpdata,
  68. + sizeof(gkpdata));
  69. + if (!IS_ERR_OR_NULL(pdev))
  70. + sc->btnpdev = pdev;
  71. + else {
  72. + sc->btnpdev = NULL;
  73. + devm_kfree(sc->dev, bt);
  74. + }
  75. +}
  76. +
  77. +/* remove GPIO buttons */
  78. +static void ath9k_deinit_buttons(struct ath_softc *sc)
  79. +{
  80. + if (!sc->gpiochip || !sc->btnpdev)
  81. + return;
  82. +
  83. + platform_device_unregister(sc->btnpdev);
  84. +
  85. + sc->btnpdev = NULL;
  86. +}
  87. +
  88. #else /* CONFIG_GPIOLIB */
  89. static inline void ath9k_register_gpio_chip(struct ath_softc *sc)
  90. @@ -139,6 +199,14 @@ static inline void ath9k_unregister_gpio
  91. {
  92. }
  93. +static inline void ath9k_init_buttons(struct ath_softc *sc)
  94. +{
  95. +}
  96. +
  97. +static inline void ath9k_deinit_buttons(struct ath_softc *sc)
  98. +{
  99. +}
  100. +
  101. #endif /* CONFIG_GPIOLIB */
  102. /********************************/
  103. @@ -262,6 +330,7 @@ void ath_deinit_leds(struct ath_softc *s
  104. {
  105. struct ath_led *led;
  106. + ath9k_deinit_buttons(sc);
  107. while (!list_empty(&sc->leds)) {
  108. led = list_first_entry(&sc->leds, struct ath_led, list);
  109. #ifdef CONFIG_GPIOLIB
  110. @@ -293,6 +362,7 @@ void ath_init_leds(struct ath_softc *sc)
  111. ath_fill_led_pin(sc);
  112. ath9k_register_gpio_chip(sc);
  113. + ath9k_init_buttons(sc);
  114. if (pdata && pdata->led_name)
  115. strncpy(led_name, pdata->led_name, sizeof(led_name));
  116. @@ -308,7 +378,7 @@ void ath_init_leds(struct ath_softc *sc)
  117. ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger,
  118. !sc->sc_ah->config.led_active_high);
  119. - if (!pdata)
  120. + if (!pdata || !pdata->leds || !pdata->num_leds)
  121. return;
  122. for (i = 0; i < pdata->num_leds; i++)
  123. --- a/include/linux/ath9k_platform.h
  124. +++ b/include/linux/ath9k_platform.h
  125. @@ -50,6 +50,10 @@ struct ath9k_platform_data {
  126. int num_leds;
  127. const struct gpio_led *leds;
  128. const char *led_name;
  129. +
  130. + unsigned num_btns;
  131. + const struct gpio_keys_button *btns;
  132. + unsigned btn_poll_interval;
  133. };
  134. #endif /* _LINUX_ATH9K_PLATFORM_H */