rtl8187: add radio led and fix warnings on suspend
authorHerton Ronaldo Krzesinski <herton@mandriva.com.br>
Wed, 9 Dec 2009 16:56:13 +0000 (14:56 -0200)
committerJohn W. Linville <linville@tuxdriver.com>
Thu, 10 Dec 2009 21:09:51 +0000 (16:09 -0500)
Michael Buesch reports that his rtl8187 gives warnings on suspend
("queueing ieee80211 work while going to suspend" warnings), as rtl8187
can call ieee80211_queue_delayed_work after mac80211 is suspended.

This change enhances rtl8187 led code so we can avoid queuing work after
mac80211 is suspended: now we register a radio led and make additional
checks to ensure led is off/on properly as mac80211 wants.

Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
Tested-by: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Stable <stable@vger.kernel.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/rtl818x/rtl8187.h
drivers/net/wireless/rtl818x/rtl8187_leds.c
drivers/net/wireless/rtl818x/rtl8187_leds.h

index b1a24de0b7b01a99f2186fb0a421a36e4969aade..6af0f3f71f3a4b6f01789da274a31fdbcba00897 100644 (file)
@@ -108,6 +108,7 @@ struct rtl8187_priv {
        struct delayed_work work;
        struct ieee80211_hw *dev;
 #ifdef CONFIG_RTL8187_LEDS
+       struct rtl8187_led led_radio;
        struct rtl8187_led led_tx;
        struct rtl8187_led led_rx;
        struct delayed_work led_on;
index cf8a4a40fdf677ebb06f99a9311c25ddd96981a2..ded44c045eb24307a6377e18eec161a27247d922 100644 (file)
@@ -105,19 +105,36 @@ static void rtl8187_led_brightness_set(struct led_classdev *led_dev,
        struct rtl8187_led *led = container_of(led_dev, struct rtl8187_led,
                                               led_dev);
        struct ieee80211_hw *hw = led->dev;
-       struct rtl8187_priv *priv = hw->priv;
+       struct rtl8187_priv *priv;
+       static bool radio_on;
 
-       if (brightness == LED_OFF) {
-               ieee80211_queue_delayed_work(hw, &priv->led_off, 0);
-               /* The LED is off for 1/20 sec so that it just blinks. */
-               ieee80211_queue_delayed_work(hw, &priv->led_on, HZ / 20);
-       } else
-               ieee80211_queue_delayed_work(hw, &priv->led_on, 0);
+       if (!hw)
+               return;
+       priv = hw->priv;
+       if (led->is_radio) {
+               if (brightness == LED_FULL) {
+                       ieee80211_queue_delayed_work(hw, &priv->led_on, 0);
+                       radio_on = true;
+               } else if (radio_on) {
+                       radio_on = false;
+                       cancel_delayed_work_sync(&priv->led_on);
+                       ieee80211_queue_delayed_work(hw, &priv->led_off, 0);
+               }
+       } else if (radio_on) {
+               if (brightness == LED_OFF) {
+                       ieee80211_queue_delayed_work(hw, &priv->led_off, 0);
+                       /* The LED is off for 1/20 sec - it just blinks. */
+                       ieee80211_queue_delayed_work(hw, &priv->led_on,
+                                                    HZ / 20);
+               } else
+                       ieee80211_queue_delayed_work(hw, &priv->led_on, 0);
+       }
 }
 
 static int rtl8187_register_led(struct ieee80211_hw *dev,
                                struct rtl8187_led *led, const char *name,
-                               const char *default_trigger, u8 ledpin)
+                               const char *default_trigger, u8 ledpin,
+                               bool is_radio)
 {
        int err;
        struct rtl8187_priv *priv = dev->priv;
@@ -128,6 +145,7 @@ static int rtl8187_register_led(struct ieee80211_hw *dev,
                return -EINVAL;
        led->dev = dev;
        led->ledpin = ledpin;
+       led->is_radio = is_radio;
        strncpy(led->name, name, sizeof(led->name));
 
        led->led_dev.name = led->name;
@@ -145,7 +163,11 @@ static int rtl8187_register_led(struct ieee80211_hw *dev,
 
 static void rtl8187_unregister_led(struct rtl8187_led *led)
 {
+       struct ieee80211_hw *hw = led->dev;
+       struct rtl8187_priv *priv = hw->priv;
+
        led_classdev_unregister(&led->led_dev);
+       flush_delayed_work(&priv->led_off);
        led->dev = NULL;
 }
 
@@ -182,34 +204,38 @@ void rtl8187_leds_init(struct ieee80211_hw *dev, u16 custid)
        INIT_DELAYED_WORK(&priv->led_on, led_turn_on);
        INIT_DELAYED_WORK(&priv->led_off, led_turn_off);
 
+       snprintf(name, sizeof(name),
+                "rtl8187-%s::radio", wiphy_name(dev->wiphy));
+       err = rtl8187_register_led(dev, &priv->led_radio, name,
+                        ieee80211_get_radio_led_name(dev), ledpin, true);
+       if (err)
+               return;
+
        snprintf(name, sizeof(name),
                 "rtl8187-%s::tx", wiphy_name(dev->wiphy));
        err = rtl8187_register_led(dev, &priv->led_tx, name,
-                        ieee80211_get_tx_led_name(dev), ledpin);
+                        ieee80211_get_tx_led_name(dev), ledpin, false);
        if (err)
-               goto error;
+               goto err_tx;
+
        snprintf(name, sizeof(name),
                 "rtl8187-%s::rx", wiphy_name(dev->wiphy));
        err = rtl8187_register_led(dev, &priv->led_rx, name,
-                        ieee80211_get_rx_led_name(dev), ledpin);
-       if (!err) {
-               ieee80211_queue_delayed_work(dev, &priv->led_on, 0);
+                        ieee80211_get_rx_led_name(dev), ledpin, false);
+       if (!err)
                return;
-       }
-       /* registration of RX LED failed - unregister TX */
+
+       /* registration of RX LED failed - unregister */
        rtl8187_unregister_led(&priv->led_tx);
-error:
-       /* If registration of either failed, cancel delayed work */
-       cancel_delayed_work_sync(&priv->led_off);
-       cancel_delayed_work_sync(&priv->led_on);
+err_tx:
+       rtl8187_unregister_led(&priv->led_radio);
 }
 
 void rtl8187_leds_exit(struct ieee80211_hw *dev)
 {
        struct rtl8187_priv *priv = dev->priv;
 
-       /* turn the LED off before exiting */
-       ieee80211_queue_delayed_work(dev, &priv->led_off, 0);
+       rtl8187_unregister_led(&priv->led_radio);
        rtl8187_unregister_led(&priv->led_rx);
        rtl8187_unregister_led(&priv->led_tx);
        cancel_delayed_work_sync(&priv->led_off);
index a0332027aeadf1c42fbfc52e590a1531cb03cad2..efe8041bdda42af9ea74e240171b83580f140aaf 100644 (file)
@@ -47,6 +47,8 @@ struct rtl8187_led {
        u8 ledpin;
        /* The unique name string for this LED device. */
        char name[RTL8187_LED_MAX_NAME_LEN + 1];
+       /* If the LED is radio or tx/rx */
+       bool is_radio;
 };
 
 void rtl8187_leds_init(struct ieee80211_hw *dev, u16 code);