530-ath9k_extra_leds.patch 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. --- a/drivers/net/wireless/ath/ath9k/ath9k.h
  2. +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
  3. @@ -811,6 +811,9 @@ static inline int ath9k_dump_btcoex(stru
  4. void ath_init_leds(struct ath_softc *sc);
  5. void ath_deinit_leds(struct ath_softc *sc);
  6. void ath_fill_led_pin(struct ath_softc *sc);
  7. +int ath_create_gpio_led(struct ath_softc *sc, int gpio, const char *name,
  8. + const char *trigger, bool active_low);
  9. +
  10. #else
  11. static inline void ath_init_leds(struct ath_softc *sc)
  12. {
  13. @@ -951,6 +954,13 @@ void ath_ant_comb_scan(struct ath_softc
  14. #define ATH9K_NUM_CHANCTX 2 /* supports 2 operating channels */
  15. +struct ath_led {
  16. + struct list_head list;
  17. + struct ath_softc *sc;
  18. + const struct gpio_led *gpio;
  19. + struct led_classdev cdev;
  20. +};
  21. +
  22. struct ath_softc {
  23. struct ieee80211_hw *hw;
  24. struct device *dev;
  25. @@ -1003,9 +1013,8 @@ struct ath_softc {
  26. spinlock_t chan_lock;
  27. #ifdef CPTCFG_MAC80211_LEDS
  28. - bool led_registered;
  29. - char led_name[32];
  30. - struct led_classdev led_cdev;
  31. + const char *led_default_trigger;
  32. + struct list_head leds;
  33. #endif
  34. #ifdef CPTCFG_ATH9K_DEBUGFS
  35. --- a/drivers/net/wireless/ath/ath9k/gpio.c
  36. +++ b/drivers/net/wireless/ath/ath9k/gpio.c
  37. @@ -24,40 +24,102 @@
  38. static void ath_led_brightness(struct led_classdev *led_cdev,
  39. enum led_brightness brightness)
  40. {
  41. - struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
  42. - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, (brightness == LED_OFF));
  43. + struct ath_led *led = container_of(led_cdev, struct ath_led, cdev);
  44. + struct ath_softc *sc = led->sc;
  45. +
  46. + ath9k_ps_wakeup(sc);
  47. + ath9k_hw_set_gpio(sc->sc_ah, led->gpio->gpio,
  48. + (brightness != LED_OFF) ^ led->gpio->active_low);
  49. + ath9k_ps_restore(sc);
  50. +}
  51. +
  52. +static int ath_add_led(struct ath_softc *sc, struct ath_led *led)
  53. +{
  54. + const struct gpio_led *gpio = led->gpio;
  55. + int ret;
  56. +
  57. + led->cdev.name = gpio->name;
  58. + led->cdev.default_trigger = gpio->default_trigger;
  59. + led->cdev.brightness_set = ath_led_brightness;
  60. +
  61. + ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->cdev);
  62. + if (ret < 0)
  63. + return ret;
  64. +
  65. + led->sc = sc;
  66. + list_add(&led->list, &sc->leds);
  67. +
  68. + /* Configure gpio for output */
  69. + ath9k_hw_cfg_output(sc->sc_ah, gpio->gpio,
  70. + AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  71. +
  72. + /* LED off */
  73. + ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, gpio->active_low);
  74. +
  75. + return 0;
  76. +}
  77. +
  78. +int ath_create_gpio_led(struct ath_softc *sc, int gpio_num, const char *name,
  79. + const char *trigger, bool active_low)
  80. +{
  81. + struct ath_led *led;
  82. + struct gpio_led *gpio;
  83. + char *_name;
  84. + int ret;
  85. +
  86. + led = kzalloc(sizeof(*led) + sizeof(*gpio) + strlen(name) + 1,
  87. + GFP_KERNEL);
  88. + if (!led)
  89. + return -ENOMEM;
  90. +
  91. + led->gpio = gpio = (struct gpio_led *) (led + 1);
  92. + _name = (char *) (led->gpio + 1);
  93. +
  94. + strcpy(_name, name);
  95. + gpio->name = _name;
  96. + gpio->gpio = gpio_num;
  97. + gpio->active_low = active_low;
  98. + gpio->default_trigger = trigger;
  99. +
  100. + ret = ath_add_led(sc, led);
  101. + if (unlikely(ret < 0))
  102. + kfree(led);
  103. +
  104. + return ret;
  105. }
  106. void ath_deinit_leds(struct ath_softc *sc)
  107. {
  108. - if (!sc->led_registered)
  109. - return;
  110. + struct ath_led *led;
  111. - ath_led_brightness(&sc->led_cdev, LED_OFF);
  112. - led_classdev_unregister(&sc->led_cdev);
  113. + while (!list_empty(&sc->leds)) {
  114. + led = list_first_entry(&sc->leds, struct ath_led, list);
  115. + list_del(&led->list);
  116. + ath_led_brightness(&led->cdev, LED_OFF);
  117. + led_classdev_unregister(&led->cdev);
  118. + kfree(led);
  119. + }
  120. }
  121. void ath_init_leds(struct ath_softc *sc)
  122. {
  123. - int ret;
  124. + char led_name[32];
  125. + const char *trigger;
  126. +
  127. + INIT_LIST_HEAD(&sc->leds);
  128. if (AR_SREV_9100(sc->sc_ah))
  129. return;
  130. - if (!led_blink)
  131. - sc->led_cdev.default_trigger =
  132. - ieee80211_get_radio_led_name(sc->hw);
  133. -
  134. - snprintf(sc->led_name, sizeof(sc->led_name),
  135. - "ath9k-%s", wiphy_name(sc->hw->wiphy));
  136. - sc->led_cdev.name = sc->led_name;
  137. - sc->led_cdev.brightness_set = ath_led_brightness;
  138. + snprintf(led_name, sizeof(led_name), "ath9k-%s",
  139. + wiphy_name(sc->hw->wiphy));
  140. - ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
  141. - if (ret < 0)
  142. - return;
  143. + if (led_blink)
  144. + trigger = sc->led_default_trigger;
  145. + else
  146. + trigger = ieee80211_get_radio_led_name(sc->hw);
  147. - sc->led_registered = true;
  148. + ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger, 1);
  149. }
  150. void ath_fill_led_pin(struct ath_softc *sc)
  151. --- a/drivers/net/wireless/ath/ath9k/init.c
  152. +++ b/drivers/net/wireless/ath/ath9k/init.c
  153. @@ -894,7 +894,7 @@ int ath9k_init_device(u16 devid, struct
  154. #ifdef CPTCFG_MAC80211_LEDS
  155. /* must be initialized before ieee80211_register_hw */
  156. - sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
  157. + sc->led_default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
  158. IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
  159. ARRAY_SIZE(ath9k_tpt_blink));
  160. #endif
  161. --- a/drivers/net/wireless/ath/ath9k/debug.c
  162. +++ b/drivers/net/wireless/ath/ath9k/debug.c
  163. @@ -1405,6 +1405,61 @@ static const struct file_operations fops
  164. .llseek = default_llseek,
  165. };
  166. +#ifdef CONFIG_MAC80211_LEDS
  167. +
  168. +static ssize_t write_file_gpio_led(struct file *file, const char __user *ubuf,
  169. + size_t count, loff_t *ppos)
  170. +{
  171. + struct ath_softc *sc = file->private_data;
  172. + char buf[32], *str, *name, *c;
  173. + ssize_t len;
  174. + unsigned int gpio;
  175. + bool active_low = false;
  176. +
  177. + len = min(count, sizeof(buf) - 1);
  178. + if (copy_from_user(buf, ubuf, len))
  179. + return -EFAULT;
  180. +
  181. + buf[len] = '\0';
  182. + name = strchr(buf, ',');
  183. + if (!name)
  184. + return -EINVAL;
  185. +
  186. + *(name++) = 0;
  187. + if (!*name)
  188. + return -EINVAL;
  189. +
  190. + c = strchr(name, '\n');
  191. + if (c)
  192. + *c = 0;
  193. +
  194. + str = buf;
  195. + if (*str == '!') {
  196. + str++;
  197. + active_low = true;
  198. + }
  199. +
  200. + if (kstrtouint(str, 0, &gpio) < 0)
  201. + return -EINVAL;
  202. +
  203. + if (gpio >= sc->sc_ah->caps.num_gpio_pins)
  204. + return -EINVAL;
  205. +
  206. + if (ath_create_gpio_led(sc, gpio, name, NULL, active_low) < 0)
  207. + return -EINVAL;
  208. +
  209. + return count;
  210. +}
  211. +
  212. +static const struct file_operations fops_gpio_led = {
  213. + .write = write_file_gpio_led,
  214. + .open = simple_open,
  215. + .owner = THIS_MODULE,
  216. + .llseek = default_llseek,
  217. +};
  218. +
  219. +#endif
  220. +
  221. int ath9k_init_debug(struct ath_hw *ah)
  222. {
  223. @@ -1429,6 +1484,10 @@ int ath9k_init_debug(struct ath_hw *ah)
  224. &fops_eeprom);
  225. debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  226. sc, &fops_chanbw);
  227. +#ifdef CONFIG_MAC80211_LEDS
  228. + debugfs_create_file("gpio_led", S_IWUSR,
  229. + sc->debug.debugfs_phy, sc, &fops_gpio_led);
  230. +#endif
  231. debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
  232. &fops_dma);
  233. debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,