b43: Fix rfkill radio LED

This fixes Bug #9414

Since addition of the rfkill callback, the LED associated with the off
switch on the radio has not worked for several reasons:

(1) Essential data in the rfkill structure were missing.
(2) The rfkill structure was initialized after the LED initialization.
(3) There was a minor memory leak if the radio LED structure was inited.

Once the above problems were fixed, additional difficulties were noted:

(4) The radio LED was in the wrong state at startup.
(5) The radio switch had to be manipulated twice for each state change.
(6) A circular mutex locking situation existed.
(7) If rfkill-input is built as a module, it is not automatically loaded.

This patch fixes all of the above.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

authored by Larry Finger and committed by John W. Linville 1a8d1227 cb935cb4

+47 -16
+4
drivers/net/wireless/b43/leds.c
··· 163 b43_register_led(dev, &dev->led_radio, name, 164 b43_rfkill_led_name(dev), 165 led_index, activelow); 166 break; 167 case B43_LED_WEIRD: 168 case B43_LED_ASSOC: ··· 235 b43_unregister_led(&dev->led_tx); 236 b43_unregister_led(&dev->led_rx); 237 b43_unregister_led(&dev->led_assoc); 238 }
··· 163 b43_register_led(dev, &dev->led_radio, name, 164 b43_rfkill_led_name(dev), 165 led_index, activelow); 166 + /* Sync the RF-kill LED state with the switch state. */ 167 + if (dev->radio_hw_enable) 168 + b43_led_turn_on(dev, led_index, activelow); 169 break; 170 case B43_LED_WEIRD: 171 case B43_LED_ASSOC: ··· 232 b43_unregister_led(&dev->led_tx); 233 b43_unregister_led(&dev->led_rx); 234 b43_unregister_led(&dev->led_assoc); 235 + b43_unregister_led(&dev->led_radio); 236 }
+11 -11
drivers/net/wireless/b43/main.c
··· 2163 static void b43_chip_exit(struct b43_wldev *dev) 2164 { 2165 b43_radio_turn_off(dev, 1); 2166 - b43_leds_exit(dev); 2167 b43_gpio_cleanup(dev); 2168 /* firmware is released later */ 2169 } ··· 2190 err = b43_gpio_init(dev); 2191 if (err) 2192 goto out; /* firmware is released later */ 2193 - b43_leds_init(dev); 2194 2195 err = b43_upload_initvals(dev); 2196 if (err) 2197 - goto err_leds_exit; 2198 b43_radio_turn_on(dev); 2199 2200 b43_write16(dev, 0x03E6, 0x0000); ··· 2269 2270 err_radio_off: 2271 b43_radio_turn_off(dev, 1); 2272 - err_leds_exit: 2273 - b43_leds_exit(dev); 2274 b43_gpio_cleanup(dev); 2275 return err; 2276 } ··· 3270 return; 3271 b43_set_status(dev, B43_STAT_UNINIT); 3272 3273 - mutex_unlock(&dev->wl->mutex); 3274 - b43_rfkill_exit(dev); 3275 - mutex_lock(&dev->wl->mutex); 3276 - 3277 b43_rng_exit(dev->wl); 3278 b43_pio_free(dev); 3279 b43_dma_free(dev); ··· 3399 memset(wl->mac_addr, 0, ETH_ALEN); 3400 b43_upload_card_macaddress(dev); 3401 b43_security_init(dev); 3402 - b43_rfkill_init(dev); 3403 b43_rng_init(wl); 3404 3405 b43_set_status(dev, B43_STAT_INITIALIZED); 3406 3407 - out: 3408 return err; 3409 3410 err_chip_exit: ··· 3493 int did_init = 0; 3494 int err = 0; 3495 3496 mutex_lock(&wl->mutex); 3497 3498 if (b43_status(dev) < B43_STAT_INITIALIZED) { ··· 3525 { 3526 struct b43_wl *wl = hw_to_b43_wl(hw); 3527 struct b43_wldev *dev = wl->current_dev; 3528 3529 mutex_lock(&wl->mutex); 3530 if (b43_status(dev) >= B43_STAT_STARTED)
··· 2163 static void b43_chip_exit(struct b43_wldev *dev) 2164 { 2165 b43_radio_turn_off(dev, 1); 2166 b43_gpio_cleanup(dev); 2167 /* firmware is released later */ 2168 } ··· 2191 err = b43_gpio_init(dev); 2192 if (err) 2193 goto out; /* firmware is released later */ 2194 2195 err = b43_upload_initvals(dev); 2196 if (err) 2197 + goto err_gpio_clean; 2198 b43_radio_turn_on(dev); 2199 2200 b43_write16(dev, 0x03E6, 0x0000); ··· 2271 2272 err_radio_off: 2273 b43_radio_turn_off(dev, 1); 2274 + err_gpio_clean: 2275 b43_gpio_cleanup(dev); 2276 return err; 2277 } ··· 3273 return; 3274 b43_set_status(dev, B43_STAT_UNINIT); 3275 3276 + b43_leds_exit(dev); 3277 b43_rng_exit(dev->wl); 3278 b43_pio_free(dev); 3279 b43_dma_free(dev); ··· 3405 memset(wl->mac_addr, 0, ETH_ALEN); 3406 b43_upload_card_macaddress(dev); 3407 b43_security_init(dev); 3408 b43_rng_init(wl); 3409 3410 b43_set_status(dev, B43_STAT_INITIALIZED); 3411 3412 + b43_leds_init(dev); 3413 + out: 3414 return err; 3415 3416 err_chip_exit: ··· 3499 int did_init = 0; 3500 int err = 0; 3501 3502 + /* First register RFkill. 3503 + * LEDs that are registered later depend on it. */ 3504 + b43_rfkill_init(dev); 3505 + 3506 mutex_lock(&wl->mutex); 3507 3508 if (b43_status(dev) < B43_STAT_INITIALIZED) { ··· 3527 { 3528 struct b43_wl *wl = hw_to_b43_wl(hw); 3529 struct b43_wldev *dev = wl->current_dev; 3530 + 3531 + b43_rfkill_exit(dev); 3532 3533 mutex_lock(&wl->mutex); 3534 if (b43_status(dev) >= B43_STAT_STARTED)
+32 -5
drivers/net/wireless/b43/rfkill.c
··· 25 #include "rfkill.h" 26 #include "b43.h" 27 28 29 /* Returns TRUE, if the radio is enabled in hardware. */ 30 static bool b43_is_hw_radio_enabled(struct b43_wldev *dev) ··· 52 bool report_change = 0; 53 54 mutex_lock(&wl->mutex); 55 - B43_WARN_ON(b43_status(dev) < B43_STAT_INITIALIZED); 56 enabled = b43_is_hw_radio_enabled(dev); 57 if (unlikely(enabled != dev->radio_hw_enable)) { 58 dev->radio_hw_enable = enabled; ··· 65 } 66 mutex_unlock(&wl->mutex); 67 68 - if (unlikely(report_change)) 69 - input_report_key(poll_dev->input, KEY_WLAN, enabled); 70 } 71 72 /* Called when the RFKILL toggled in software. */ ··· 78 { 79 struct b43_wldev *dev = data; 80 struct b43_wl *wl = dev->wl; 81 - int err = 0; 82 83 if (!wl->rfkill.registered) 84 return 0; 85 86 mutex_lock(&wl->mutex); 87 - B43_WARN_ON(b43_status(dev) < B43_STAT_INITIALIZED); 88 switch (state) { 89 case RFKILL_STATE_ON: 90 if (!dev->radio_hw_enable) { ··· 144 rfk->poll_dev->poll = b43_rfkill_poll; 145 rfk->poll_dev->poll_interval = 1000; /* msecs */ 146 147 err = rfkill_register(rfk->rfkill); 148 if (err) 149 goto err_free_polldev; 150 err = input_register_polled_device(rfk->poll_dev); 151 if (err) 152 goto err_unreg_rfk;
··· 25 #include "rfkill.h" 26 #include "b43.h" 27 28 + #include <linux/kmod.h> 29 + 30 31 /* Returns TRUE, if the radio is enabled in hardware. */ 32 static bool b43_is_hw_radio_enabled(struct b43_wldev *dev) ··· 50 bool report_change = 0; 51 52 mutex_lock(&wl->mutex); 53 + if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) { 54 + mutex_unlock(&wl->mutex); 55 + return; 56 + } 57 enabled = b43_is_hw_radio_enabled(dev); 58 if (unlikely(enabled != dev->radio_hw_enable)) { 59 dev->radio_hw_enable = enabled; ··· 60 } 61 mutex_unlock(&wl->mutex); 62 63 + /* send the radio switch event to the system - note both a key press 64 + * and a release are required */ 65 + if (unlikely(report_change)) { 66 + input_report_key(poll_dev->input, KEY_WLAN, 1); 67 + input_report_key(poll_dev->input, KEY_WLAN, 0); 68 + } 69 } 70 71 /* Called when the RFKILL toggled in software. */ ··· 69 { 70 struct b43_wldev *dev = data; 71 struct b43_wl *wl = dev->wl; 72 + int err = -EBUSY; 73 74 if (!wl->rfkill.registered) 75 return 0; 76 77 mutex_lock(&wl->mutex); 78 + if (b43_status(dev) < B43_STAT_INITIALIZED) 79 + goto out_unlock; 80 + err = 0; 81 switch (state) { 82 case RFKILL_STATE_ON: 83 if (!dev->radio_hw_enable) { ··· 133 rfk->poll_dev->poll = b43_rfkill_poll; 134 rfk->poll_dev->poll_interval = 1000; /* msecs */ 135 136 + rfk->poll_dev->input->name = rfk->name; 137 + rfk->poll_dev->input->id.bustype = BUS_HOST; 138 + rfk->poll_dev->input->id.vendor = dev->dev->bus->boardinfo.vendor; 139 + rfk->poll_dev->input->evbit[0] = BIT(EV_KEY); 140 + set_bit(KEY_WLAN, rfk->poll_dev->input->keybit); 141 + 142 err = rfkill_register(rfk->rfkill); 143 if (err) 144 goto err_free_polldev; 145 + 146 + #ifdef CONFIG_RFKILL_INPUT_MODULE 147 + /* B43 RF-kill isn't useful without the rfkill-input subsystem. 148 + * Try to load the module. */ 149 + err = request_module("rfkill-input"); 150 + if (err) 151 + b43warn(wl, "Failed to load the rfkill-input module. " 152 + "The built-in radio LED will not work.\n"); 153 + #endif /* CONFIG_RFKILL_INPUT */ 154 + 155 err = input_register_polled_device(rfk->poll_dev); 156 if (err) 157 goto err_unreg_rfk;