1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -812,6 +812,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 @@ -952,6 +955,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 @@ -1003,9 +1013,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 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, (brightness == LED_OFF));
47 + struct ath_led *led = container_of(led_cdev, struct ath_led, cdev);
48 + struct ath_softc *sc = led->sc;
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);
56 +static int ath_add_led(struct ath_softc *sc, struct ath_led *led)
58 + const struct gpio_led *gpio = led->gpio;
61 + led->cdev.name = gpio->name;
62 + led->cdev.default_trigger = gpio->default_trigger;
63 + led->cdev.brightness_set = ath_led_brightness;
65 + ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->cdev);
70 + list_add(&led->list, &sc->leds);
72 + /* Configure gpio for output */
73 + ath9k_hw_cfg_output(sc->sc_ah, gpio->gpio,
74 + AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
77 + ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, gpio->active_low);
82 +int ath_create_gpio_led(struct ath_softc *sc, int gpio_num, const char *name,
83 + const char *trigger, bool active_low)
85 + struct ath_led *led;
86 + struct gpio_led *gpio;
90 + led = kzalloc(sizeof(*led) + sizeof(*gpio) + strlen(name) + 1,
95 + led->gpio = gpio = (struct gpio_led *) (led + 1);
96 + _name = (char *) (led->gpio + 1);
98 + strcpy(_name, name);
100 + gpio->gpio = gpio_num;
101 + gpio->active_low = active_low;
102 + gpio->default_trigger = trigger;
104 + ret = ath_add_led(sc, led);
105 + if (unlikely(ret < 0))
111 void ath_deinit_leds(struct ath_softc *sc)
113 - if (!sc->led_registered)
115 + struct ath_led *led;
117 - ath_led_brightness(&sc->led_cdev, LED_OFF);
118 - led_classdev_unregister(&sc->led_cdev);
119 + while (!list_empty(&sc->leds)) {
120 + led = list_first_entry(&sc->leds, struct ath_led, list);
121 + list_del(&led->list);
122 + ath_led_brightness(&led->cdev, LED_OFF);
123 + led_classdev_unregister(&led->cdev);
128 void ath_init_leds(struct ath_softc *sc)
132 + const char *trigger;
134 + INIT_LIST_HEAD(&sc->leds);
136 if (AR_SREV_9100(sc->sc_ah))
140 - sc->led_cdev.default_trigger =
141 - ieee80211_get_radio_led_name(sc->hw);
143 - snprintf(sc->led_name, sizeof(sc->led_name),
144 - "ath9k-%s", wiphy_name(sc->hw->wiphy));
145 - sc->led_cdev.name = sc->led_name;
146 - sc->led_cdev.brightness_set = ath_led_brightness;
147 + snprintf(led_name, sizeof(led_name), "ath9k-%s",
148 + wiphy_name(sc->hw->wiphy));
150 - ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
154 + trigger = sc->led_default_trigger;
156 + trigger = ieee80211_get_radio_led_name(sc->hw);
158 - sc->led_registered = true;
159 + ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger, 1);
162 void ath_fill_led_pin(struct ath_softc *sc)
163 --- a/drivers/net/wireless/ath/ath9k/init.c
164 +++ b/drivers/net/wireless/ath/ath9k/init.c
165 @@ -903,7 +903,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));
174 --- a/drivers/net/wireless/ath/ath9k/debug.c
175 +++ b/drivers/net/wireless/ath/ath9k/debug.c
176 @@ -1406,6 +1406,61 @@ static const struct file_operations fops
177 .llseek = default_llseek,
180 +#ifdef CONFIG_MAC80211_LEDS
182 +static ssize_t write_file_gpio_led(struct file *file, const char __user *ubuf,
183 + size_t count, loff_t *ppos)
185 + struct ath_softc *sc = file->private_data;
186 + char buf[32], *str, *name, *c;
189 + bool active_low = false;
191 + len = min(count, sizeof(buf) - 1);
192 + if (copy_from_user(buf, ubuf, len))
196 + name = strchr(buf, ',');
204 + c = strchr(name, '\n');
214 + if (kstrtouint(str, 0, &gpio) < 0)
217 + if (gpio >= sc->sc_ah->caps.num_gpio_pins)
220 + if (ath_create_gpio_led(sc, gpio, name, NULL, active_low) < 0)
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,
236 int ath9k_init_debug(struct ath_hw *ah)
238 @@ -1430,6 +1485,10 @@ int ath9k_init_debug(struct ath_hw *ah)
240 debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
242 +#ifdef CONFIG_MAC80211_LEDS
243 + debugfs_create_file("gpio_led", S_IWUSR,
244 + sc->debug.debugfs_phy, sc, &fops_gpio_led);
246 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
248 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,