530-ath9k_extra_leds.patch 6.5 KB

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