530-ath9k_extra_leds.patch 7.0 KB

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