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