|
@@ -20,117 +20,25 @@
|
|
|
/* LED functions */
|
|
|
/********************************/
|
|
|
|
|
|
-static void ath_led_blink_work(struct work_struct *work)
|
|
|
-{
|
|
|
- struct ath_softc *sc = container_of(work, struct ath_softc,
|
|
|
- ath_led_blink_work.work);
|
|
|
-
|
|
|
- if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
|
|
|
- return;
|
|
|
-
|
|
|
- if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
|
|
|
- (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
|
|
|
- ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
|
|
|
- else
|
|
|
- ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
|
|
|
- (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
|
|
|
-
|
|
|
- ieee80211_queue_delayed_work(sc->hw,
|
|
|
- &sc->ath_led_blink_work,
|
|
|
- (sc->sc_flags & SC_OP_LED_ON) ?
|
|
|
- msecs_to_jiffies(sc->led_off_duration) :
|
|
|
- msecs_to_jiffies(sc->led_on_duration));
|
|
|
-
|
|
|
- sc->led_on_duration = sc->led_on_cnt ?
|
|
|
- max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
|
|
|
- ATH_LED_ON_DURATION_IDLE;
|
|
|
- sc->led_off_duration = sc->led_off_cnt ?
|
|
|
- max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
|
|
|
- ATH_LED_OFF_DURATION_IDLE;
|
|
|
- sc->led_on_cnt = sc->led_off_cnt = 0;
|
|
|
- if (sc->sc_flags & SC_OP_LED_ON)
|
|
|
- sc->sc_flags &= ~SC_OP_LED_ON;
|
|
|
- else
|
|
|
- sc->sc_flags |= SC_OP_LED_ON;
|
|
|
-}
|
|
|
-
|
|
|
+#ifdef CONFIG_MAC80211_LEDS
|
|
|
static void ath_led_brightness(struct led_classdev *led_cdev,
|
|
|
enum led_brightness brightness)
|
|
|
{
|
|
|
- struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
|
|
|
- struct ath_softc *sc = led->sc;
|
|
|
-
|
|
|
- switch (brightness) {
|
|
|
- case LED_OFF:
|
|
|
- if (led->led_type == ATH_LED_ASSOC ||
|
|
|
- led->led_type == ATH_LED_RADIO) {
|
|
|
- ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
|
|
|
- (led->led_type == ATH_LED_RADIO));
|
|
|
- sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
|
|
|
- if (led->led_type == ATH_LED_RADIO)
|
|
|
- sc->sc_flags &= ~SC_OP_LED_ON;
|
|
|
- } else {
|
|
|
- sc->led_off_cnt++;
|
|
|
- }
|
|
|
- break;
|
|
|
- case LED_FULL:
|
|
|
- if (led->led_type == ATH_LED_ASSOC) {
|
|
|
- sc->sc_flags |= SC_OP_LED_ASSOCIATED;
|
|
|
- if (led_blink)
|
|
|
- ieee80211_queue_delayed_work(sc->hw,
|
|
|
- &sc->ath_led_blink_work, 0);
|
|
|
- } else if (led->led_type == ATH_LED_RADIO) {
|
|
|
- ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
|
|
|
- sc->sc_flags |= SC_OP_LED_ON;
|
|
|
- } else {
|
|
|
- sc->led_on_cnt++;
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
|
|
|
- char *trigger)
|
|
|
-{
|
|
|
- int ret;
|
|
|
-
|
|
|
- led->sc = sc;
|
|
|
- led->led_cdev.name = led->name;
|
|
|
- led->led_cdev.default_trigger = trigger;
|
|
|
- led->led_cdev.brightness_set = ath_led_brightness;
|
|
|
-
|
|
|
- ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
|
|
|
- if (ret)
|
|
|
- ath_err(ath9k_hw_common(sc->sc_ah),
|
|
|
- "Failed to register led:%s", led->name);
|
|
|
- else
|
|
|
- led->registered = 1;
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-static void ath_unregister_led(struct ath_led *led)
|
|
|
-{
|
|
|
- if (led->registered) {
|
|
|
- led_classdev_unregister(&led->led_cdev);
|
|
|
- led->registered = 0;
|
|
|
- }
|
|
|
+ struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
|
|
|
+ ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, (brightness == LED_OFF));
|
|
|
}
|
|
|
|
|
|
void ath_deinit_leds(struct ath_softc *sc)
|
|
|
{
|
|
|
- ath_unregister_led(&sc->assoc_led);
|
|
|
- sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
|
|
|
- ath_unregister_led(&sc->tx_led);
|
|
|
- ath_unregister_led(&sc->rx_led);
|
|
|
- ath_unregister_led(&sc->radio_led);
|
|
|
- ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
|
|
|
+ if (!sc->led_registered)
|
|
|
+ return;
|
|
|
+
|
|
|
+ ath_led_brightness(&sc->led_cdev, LED_OFF);
|
|
|
+ led_classdev_unregister(&sc->led_cdev);
|
|
|
}
|
|
|
|
|
|
void ath_init_leds(struct ath_softc *sc)
|
|
|
{
|
|
|
- char *trigger;
|
|
|
int ret;
|
|
|
|
|
|
if (AR_SREV_9287(sc->sc_ah))
|
|
@@ -144,48 +52,22 @@ void ath_init_leds(struct ath_softc *sc)
|
|
|
/* LED off, active low */
|
|
|
ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
|
|
|
|
|
|
- if (led_blink)
|
|
|
- INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
|
|
|
-
|
|
|
- trigger = ieee80211_get_radio_led_name(sc->hw);
|
|
|
- snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
|
|
|
- "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
|
|
|
- ret = ath_register_led(sc, &sc->radio_led, trigger);
|
|
|
- sc->radio_led.led_type = ATH_LED_RADIO;
|
|
|
- if (ret)
|
|
|
- goto fail;
|
|
|
-
|
|
|
- trigger = ieee80211_get_assoc_led_name(sc->hw);
|
|
|
- snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
|
|
|
- "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
|
|
|
- ret = ath_register_led(sc, &sc->assoc_led, trigger);
|
|
|
- sc->assoc_led.led_type = ATH_LED_ASSOC;
|
|
|
- if (ret)
|
|
|
- goto fail;
|
|
|
-
|
|
|
- trigger = ieee80211_get_tx_led_name(sc->hw);
|
|
|
- snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
|
|
|
- "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
|
|
|
- ret = ath_register_led(sc, &sc->tx_led, trigger);
|
|
|
- sc->tx_led.led_type = ATH_LED_TX;
|
|
|
- if (ret)
|
|
|
- goto fail;
|
|
|
-
|
|
|
- trigger = ieee80211_get_rx_led_name(sc->hw);
|
|
|
- snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
|
|
|
- "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
|
|
|
- ret = ath_register_led(sc, &sc->rx_led, trigger);
|
|
|
- sc->rx_led.led_type = ATH_LED_RX;
|
|
|
- if (ret)
|
|
|
- goto fail;
|
|
|
-
|
|
|
- return;
|
|
|
-
|
|
|
-fail:
|
|
|
- if (led_blink)
|
|
|
- cancel_delayed_work_sync(&sc->ath_led_blink_work);
|
|
|
- ath_deinit_leds(sc);
|
|
|
+ if (!led_blink)
|
|
|
+ sc->led_cdev.default_trigger =
|
|
|
+ ieee80211_get_radio_led_name(sc->hw);
|
|
|
+
|
|
|
+ snprintf(sc->led_name, sizeof(sc->led_name),
|
|
|
+ "ath9k-%s", wiphy_name(sc->hw->wiphy));
|
|
|
+ sc->led_cdev.name = sc->led_name;
|
|
|
+ sc->led_cdev.brightness_set = ath_led_brightness;
|
|
|
+
|
|
|
+ ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
|
|
|
+ if (ret < 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ sc->led_registered = true;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
/*******************/
|
|
|
/* Rfkill */
|