530-ath9k_extra_leds.patch 7.1 KB

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