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);
11 static inline void ath_init_leds(struct ath_softc *sc)
13 @@ -963,6 +966,13 @@ void ath_ant_comb_scan(struct ath_softc
15 #define ATH9K_NUM_CHANCTX 2 /* supports 2 operating channels */
18 + struct list_head list;
19 + struct ath_softc *sc;
20 + const struct gpio_led *gpio;
21 + struct led_classdev cdev;
25 struct ieee80211_hw *hw;
27 @@ -1015,9 +1025,8 @@ struct ath_softc {
30 #ifdef CPTCFG_MAC80211_LEDS
31 - bool led_registered;
33 - struct led_classdev led_cdev;
34 + const char *led_default_trigger;
35 + struct list_head leds;
38 #ifdef CPTCFG_ATH9K_DEBUGFS
39 --- a/drivers/net/wireless/ath/ath9k/gpio.c
40 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
43 #ifdef CPTCFG_MAC80211_LEDS
45 -void ath_fill_led_pin(struct ath_softc *sc)
46 +static void ath_fill_led_pin(struct ath_softc *sc)
48 struct ath_hw *ah = sc->sc_ah;
50 @@ -39,61 +39,111 @@ void ath_fill_led_pin(struct ath_softc *
52 ah->led_pin = ATH_LED_PIN_DEF;
56 +static void ath_led_brightness(struct led_classdev *led_cdev,
57 + enum led_brightness brightness)
59 + struct ath_led *led = container_of(led_cdev, struct ath_led, cdev);
60 + struct ath_softc *sc = led->sc;
62 + ath9k_ps_wakeup(sc);
63 + ath9k_hw_set_gpio(sc->sc_ah, led->gpio->gpio,
64 + (brightness != LED_OFF) ^ led->gpio->active_low);
65 + ath9k_ps_restore(sc);
68 +static int ath_add_led(struct ath_softc *sc, struct ath_led *led)
70 + const struct gpio_led *gpio = led->gpio;
73 + led->cdev.name = gpio->name;
74 + led->cdev.default_trigger = gpio->default_trigger;
75 + led->cdev.brightness_set = ath_led_brightness;
77 + ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->cdev);
82 + list_add(&led->list, &sc->leds);
84 /* Configure gpio for output */
85 - ath9k_hw_gpio_request_out(ah, ah->led_pin, "ath9k-led",
86 + ath9k_hw_gpio_request_out(sc->sc_ah, gpio->gpio, gpio->name,
87 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
89 - /* LED off, active low */
90 - ath9k_hw_set_gpio(ah, ah->led_pin, ah->config.led_active_high ? 0 : 1);
92 + ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, gpio->active_low);
97 -static void ath_led_brightness(struct led_classdev *led_cdev,
98 - enum led_brightness brightness)
99 +int ath_create_gpio_led(struct ath_softc *sc, int gpio_num, const char *name,
100 + const char *trigger, bool active_low)
102 - struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
103 - u32 val = (brightness == LED_OFF);
104 + struct ath_led *led;
105 + struct gpio_led *gpio;
109 - if (sc->sc_ah->config.led_active_high)
111 + led = kzalloc(sizeof(*led) + sizeof(*gpio) + strlen(name) + 1,
116 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, val);
117 + led->gpio = gpio = (struct gpio_led *) (led + 1);
118 + _name = (char *) (led->gpio + 1);
120 + strcpy(_name, name);
121 + gpio->name = _name;
122 + gpio->gpio = gpio_num;
123 + gpio->active_low = active_low;
124 + gpio->default_trigger = trigger;
126 + ret = ath_add_led(sc, led);
127 + if (unlikely(ret < 0))
133 void ath_deinit_leds(struct ath_softc *sc)
135 - if (!sc->led_registered)
138 - ath_led_brightness(&sc->led_cdev, LED_OFF);
139 - led_classdev_unregister(&sc->led_cdev);
140 + struct ath_led *led;
142 - ath9k_hw_gpio_free(sc->sc_ah, sc->sc_ah->led_pin);
143 + while (!list_empty(&sc->leds)) {
144 + led = list_first_entry(&sc->leds, struct ath_led, list);
145 + list_del(&led->list);
146 + ath_led_brightness(&led->cdev, LED_OFF);
147 + led_classdev_unregister(&led->cdev);
148 + ath9k_hw_gpio_free(sc->sc_ah, led->gpio->gpio);
153 void ath_init_leds(struct ath_softc *sc)
157 + const char *trigger;
159 + INIT_LIST_HEAD(&sc->leds);
161 if (AR_SREV_9100(sc->sc_ah))
164 ath_fill_led_pin(sc);
166 - if (!ath9k_led_blink)
167 - sc->led_cdev.default_trigger =
168 - ieee80211_get_radio_led_name(sc->hw);
170 - snprintf(sc->led_name, sizeof(sc->led_name),
171 - "ath9k-%s", wiphy_name(sc->hw->wiphy));
172 - sc->led_cdev.name = sc->led_name;
173 - sc->led_cdev.brightness_set = ath_led_brightness;
174 + snprintf(led_name, sizeof(led_name), "ath9k-%s",
175 + wiphy_name(sc->hw->wiphy));
177 - ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
180 + if (ath9k_led_blink)
181 + trigger = sc->led_default_trigger;
183 + trigger = ieee80211_get_radio_led_name(sc->hw);
185 - sc->led_registered = true;
186 + ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger,
187 + !sc->sc_ah->config.led_active_high);
191 --- a/drivers/net/wireless/ath/ath9k/init.c
192 +++ b/drivers/net/wireless/ath/ath9k/init.c
193 @@ -942,7 +942,7 @@ int ath9k_init_device(u16 devid, struct
195 #ifdef CPTCFG_MAC80211_LEDS
196 /* must be initialized before ieee80211_register_hw */
197 - sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
198 + sc->led_default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
199 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
200 ARRAY_SIZE(ath9k_tpt_blink));
202 --- a/drivers/net/wireless/ath/ath9k/debug.c
203 +++ b/drivers/net/wireless/ath/ath9k/debug.c
204 @@ -1407,6 +1407,61 @@ static const struct file_operations fops
205 .llseek = default_llseek,
208 +#ifdef CONFIG_MAC80211_LEDS
210 +static ssize_t write_file_gpio_led(struct file *file, const char __user *ubuf,
211 + size_t count, loff_t *ppos)
213 + struct ath_softc *sc = file->private_data;
214 + char buf[32], *str, *name, *c;
217 + bool active_low = false;
219 + len = min(count, sizeof(buf) - 1);
220 + if (copy_from_user(buf, ubuf, len))
224 + name = strchr(buf, ',');
232 + c = strchr(name, '\n');
242 + if (kstrtouint(str, 0, &gpio) < 0)
245 + if (gpio >= sc->sc_ah->caps.num_gpio_pins)
248 + if (ath_create_gpio_led(sc, gpio, name, NULL, active_low) < 0)
254 +static const struct file_operations fops_gpio_led = {
255 + .write = write_file_gpio_led,
256 + .open = simple_open,
257 + .owner = THIS_MODULE,
258 + .llseek = default_llseek,
264 int ath9k_init_debug(struct ath_hw *ah)
266 @@ -1431,6 +1486,10 @@ int ath9k_init_debug(struct ath_hw *ah)
268 debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
270 +#ifdef CONFIG_MAC80211_LEDS
271 + debugfs_create_file("gpio_led", S_IWUSR,
272 + sc->debug.debugfs_phy, sc, &fops_gpio_led);
274 debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
276 debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,