1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -504,6 +504,9 @@ static inline u16 ath9k_btcoex_aggr_limi
4 #ifdef CONFIG_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 @@ -624,6 +627,13 @@ struct ath9k_vif_iter_data {
14 int nothers; /* number of vifs not specified above. */
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 @@ -667,9 +677,8 @@ struct ath_softc {
28 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
30 #ifdef CONFIG_MAC80211_LEDS
31 - bool led_registered;
33 - struct led_classdev led_cdev;
34 + const char *led_default_trigger;
35 + struct list_head leds;
38 struct ath9k_hw_cal_data caldata;
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))
138 @@ -57,26 +124,15 @@ void ath_init_leds(struct ath_softc *sc)
139 sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
142 - /* Configure gpio 1 for output */
143 - ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
144 - AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
145 - /* LED off, active low */
146 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
149 - sc->led_cdev.default_trigger =
150 - ieee80211_get_radio_led_name(sc->hw);
152 - snprintf(sc->led_name, sizeof(sc->led_name),
153 - "ath9k-%s", wiphy_name(sc->hw->wiphy));
154 - sc->led_cdev.name = sc->led_name;
155 - sc->led_cdev.brightness_set = ath_led_brightness;
156 + snprintf(led_name, sizeof(led_name), "ath9k-%s",
157 + wiphy_name(sc->hw->wiphy));
159 - ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
163 + trigger = sc->led_default_trigger;
165 + trigger = ieee80211_get_radio_led_name(sc->hw);
167 - sc->led_registered = true;
168 + ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger, 1);
172 --- a/drivers/net/wireless/ath/ath9k/init.c
173 +++ b/drivers/net/wireless/ath/ath9k/init.c
174 @@ -759,7 +759,7 @@ int ath9k_init_device(u16 devid, struct
176 #ifdef CONFIG_MAC80211_LEDS
177 /* must be initialized before ieee80211_register_hw */
178 - sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
179 + sc->led_default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
180 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
181 ARRAY_SIZE(ath9k_tpt_blink));
183 --- a/drivers/net/wireless/ath/ath9k/debug.c
184 +++ b/drivers/net/wireless/ath/ath9k/debug.c
185 @@ -1252,6 +1252,61 @@ static const struct file_operations fops
186 .llseek = default_llseek,
189 +#ifdef CONFIG_MAC80211_LEDS
191 +static ssize_t write_file_gpio_led(struct file *file, const char __user *ubuf,
192 + size_t count, loff_t *ppos)
194 + struct ath_softc *sc = file->private_data;
195 + char buf[32], *str, *name, *c;
198 + bool active_low = false;
200 + len = min(count, sizeof(buf) - 1);
201 + if (copy_from_user(buf, ubuf, len))
205 + name = strchr(buf, ',');
213 + c = strchr(name, '\n');
223 + if (kstrtouint(str, 0, &gpio) < 0)
226 + if (gpio >= sc->sc_ah->caps.num_gpio_pins)
229 + if (ath_create_gpio_led(sc, gpio, name, NULL, active_low) < 0)
235 +static const struct file_operations fops_gpio_led = {
236 + .write = write_file_gpio_led,
237 + .open = ath9k_debugfs_open,
238 + .owner = THIS_MODULE,
239 + .llseek = default_llseek,
244 #ifdef CONFIG_ATH9K_MAC_DEBUG
246 void ath9k_debug_samp_bb_mac(struct ath_softc *sc)
247 @@ -1681,6 +1736,11 @@ int ath9k_init_debug(struct ath_hw *ah)
251 +#ifdef CONFIG_MAC80211_LEDS
252 + debugfs_create_file("gpio_led", S_IWUSR,
253 + sc->debug.debugfs_phy, sc, &fops_gpio_led);
256 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
257 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);