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);
11 static inline void ath_init_leds(struct ath_softc *sc)
13 @@ -953,6 +956,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 @@ -1004,9 +1014,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
42 static void ath_led_brightness(struct led_classdev *led_cdev,
43 enum led_brightness brightness)
45 - struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
46 - u32 val = (brightness == LED_OFF);
47 + struct ath_led *led = container_of(led_cdev, struct ath_led, cdev);
48 + struct ath_softc *sc = led->sc;
50 - if (sc->sc_ah->config.led_active_high)
52 + ath9k_ps_wakeup(sc);
53 + ath9k_hw_set_gpio(sc->sc_ah, led->gpio->gpio,
54 + (brightness != LED_OFF) ^ led->gpio->active_low);
55 + ath9k_ps_restore(sc);
58 +static int ath_add_led(struct ath_softc *sc, struct ath_led *led)
60 + const struct gpio_led *gpio = led->gpio;
63 + led->cdev.name = gpio->name;
64 + led->cdev.default_trigger = gpio->default_trigger;
65 + led->cdev.brightness_set = ath_led_brightness;
67 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, val);
68 + ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->cdev);
73 + list_add(&led->list, &sc->leds);
75 + /* Configure gpio for output */
76 + ath9k_hw_cfg_output(sc->sc_ah, gpio->gpio,
77 + AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
80 + ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, gpio->active_low);
85 +int ath_create_gpio_led(struct ath_softc *sc, int gpio_num, const char *name,
86 + const char *trigger, bool active_low)
88 + struct ath_led *led;
89 + struct gpio_led *gpio;
93 + led = kzalloc(sizeof(*led) + sizeof(*gpio) + strlen(name) + 1,
98 + led->gpio = gpio = (struct gpio_led *) (led + 1);
99 + _name = (char *) (led->gpio + 1);
101 + strcpy(_name, name);
102 + gpio->name = _name;
103 + gpio->gpio = gpio_num;
104 + gpio->active_low = active_low;
105 + gpio->default_trigger = trigger;
107 + ret = ath_add_led(sc, led);
108 + if (unlikely(ret < 0))
114 void ath_deinit_leds(struct ath_softc *sc)
116 - if (!sc->led_registered)
118 + struct ath_led *led;
120 - ath_led_brightness(&sc->led_cdev, LED_OFF);
121 - led_classdev_unregister(&sc->led_cdev);
122 + while (!list_empty(&sc->leds)) {
123 + led = list_first_entry(&sc->leds, struct ath_led, list);
124 + list_del(&led->list);
125 + ath_led_brightness(&led->cdev, LED_OFF);
126 + led_classdev_unregister(&led->cdev);
131 void ath_init_leds(struct ath_softc *sc)
135 + const char *trigger;
137 + INIT_LIST_HEAD(&sc->leds);
139 if (AR_SREV_9100(sc->sc_ah))
142 - if (!ath9k_led_blink)
143 - sc->led_cdev.default_trigger =
144 - ieee80211_get_radio_led_name(sc->hw);
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));
153 - ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
156 + if (ath9k_led_blink)
157 + trigger = sc->led_default_trigger;
159 + trigger = ieee80211_get_radio_led_name(sc->hw);
161 - sc->led_registered = true;
162 + ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger, 1);
165 void ath_fill_led_pin(struct ath_softc *sc)
166 --- a/drivers/net/wireless/ath/ath9k/init.c
167 +++ b/drivers/net/wireless/ath/ath9k/init.c
168 @@ -942,7 +942,7 @@ int ath9k_init_device(u16 devid, struct
170 #ifdef CPTCFG_MAC80211_LEDS
171 /* must be initialized before ieee80211_register_hw */
172 - sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
173 + sc->led_default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
174 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
175 ARRAY_SIZE(ath9k_tpt_blink));
177 --- a/drivers/net/wireless/ath/ath9k/debug.c
178 +++ b/drivers/net/wireless/ath/ath9k/debug.c
179 @@ -1393,6 +1393,61 @@ static const struct file_operations fops
180 .llseek = default_llseek,
183 +#ifdef CONFIG_MAC80211_LEDS
185 +static ssize_t write_file_gpio_led(struct file *file, const char __user *ubuf,
186 + size_t count, loff_t *ppos)
188 + struct ath_softc *sc = file->private_data;
189 + char buf[32], *str, *name, *c;
192 + bool active_low = false;
194 + len = min(count, sizeof(buf) - 1);
195 + if (copy_from_user(buf, ubuf, len))
199 + name = strchr(buf, ',');
207 + c = strchr(name, '\n');
217 + if (kstrtouint(str, 0, &gpio) < 0)
220 + if (gpio >= sc->sc_ah->caps.num_gpio_pins)
223 + if (ath_create_gpio_led(sc, gpio, name, NULL, active_low) < 0)
229 +static const struct file_operations fops_gpio_led = {
230 + .write = write_file_gpio_led,
231 + .open = simple_open,
232 + .owner = THIS_MODULE,
233 + .llseek = default_llseek,
239 int ath9k_init_debug(struct ath_hw *ah)
241 @@ -1417,6 +1472,10 @@ int ath9k_init_debug(struct ath_hw *ah)
243 debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
245 +#ifdef CONFIG_MAC80211_LEDS
246 + debugfs_create_file("gpio_led", S_IWUSR,
247 + sc->debug.debugfs_phy, sc, &fops_gpio_led);
249 debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
251 debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,