summaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/b43legacy/rfkill.c
diff options
context:
space:
mode:
authorLarry Finger <Larry.Finger@lwfinger.net>2007-10-10 22:48:17 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 15:03:27 -0800
commit6be50837e303c53b1e5a0138dfed132ccbabcdad (patch)
tree5664873c9ab28c798e7044adf25e4e6e34da755d /drivers/net/wireless/b43legacy/rfkill.c
parent93bb7f3a7bb5c95da10242d9763994a466c90b1d (diff)
downloadblackbird-op-linux-6be50837e303c53b1e5a0138dfed132ccbabcdad.tar.gz
blackbird-op-linux-6be50837e303c53b1e5a0138dfed132ccbabcdad.zip
b43legacy: Use input-polldev for the rfkill switch
This removes the direct call to rfkill on an rfkill event and replaces it with an input device. This way userspace is also notified about the event. This patch is the port to b43legacy of a patch for b43 by Michael Buesch <mb@bu3sch.de>. Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/b43legacy/rfkill.c')
-rw-r--r--drivers/net/wireless/b43legacy/rfkill.c135
1 files changed, 81 insertions, 54 deletions
diff --git a/drivers/net/wireless/b43legacy/rfkill.c b/drivers/net/wireless/b43legacy/rfkill.c
index db6292642057..b6bf205c6455 100644
--- a/drivers/net/wireless/b43legacy/rfkill.c
+++ b/drivers/net/wireless/b43legacy/rfkill.c
@@ -1,6 +1,6 @@
/*
- Broadcom B43legacy wireless driver
+ Broadcom B43 wireless driver
RFKILL support
Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
@@ -27,48 +27,39 @@
#include "b43legacy.h"
-static void b43legacy_notify_rfkill_press(struct work_struct *work)
+/* Returns TRUE, if the radio is enabled in hardware. */
+static bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
{
- struct b43legacy_rfkill *rfk = container_of(work,
- struct b43legacy_rfkill,
- notify_work);
- struct b43legacy_wl *wl = container_of(rfk, struct b43legacy_wl,
- rfkill);
- struct b43legacy_wldev *dev;
- enum rfkill_state state;
-
- mutex_lock(&wl->mutex);
- dev = wl->current_dev;
- if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED) {
- mutex_unlock(&wl->mutex);
- return;
- }
- if (dev->radio_hw_enable)
- state = RFKILL_STATE_ON;
- else
- state = RFKILL_STATE_OFF;
- b43legacyinfo(wl, "Radio hardware status changed to %s\n",
- dev->radio_hw_enable ? "ENABLED" : "DISABLED");
- mutex_unlock(&wl->mutex);
-
- if (rfk->rfkill) {
- /* Be careful. This calls back into the software toggle
- * routines. So we must unlock before calling. */
- rfkill_switch_all(rfk->rfkill->type, state);
+ if (dev->phy.rev >= 3) {
+ if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
+ & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
+ return 1;
+ } else {
+ if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
+ & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
+ return 1;
}
+ return 0;
}
-/* Called when the RFKILL toggled in hardware.
- * This is called with the mutex locked. */
-void b43legacy_rfkill_toggled(struct b43legacy_wldev *dev, bool on)
+/* The poll callback for the hardware button. */
+static void b43legacy_rfkill_poll(struct input_polled_dev *poll_dev)
{
+ struct b43legacy_wldev *dev = poll_dev->private;
struct b43legacy_wl *wl = dev->wl;
+ bool enabled;
+ mutex_lock(&wl->mutex);
B43legacy_WARN_ON(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED);
- /* Update the RF status asynchronously, as rfkill will
- * call back into the software toggle handler.
- * This would deadlock if done synchronously. */
- queue_work(wl->hw->workqueue, &wl->rfkill.notify_work);
+ enabled = b43legacy_is_hw_radio_enabled(dev);
+ if (unlikely(enabled != dev->radio_hw_enable)) {
+ dev->radio_hw_enable = enabled;
+ b43legacyinfo(wl, "Radio hardware status changed to %s\n",
+ enabled ? "ENABLED" : "DISABLED");
+ mutex_unlock(&wl->mutex);
+ input_report_key(poll_dev->input, KEY_WLAN, enabled);
+ } else
+ mutex_unlock(&wl->mutex);
}
/* Called when the RFKILL toggled in software.
@@ -106,7 +97,7 @@ out_unlock:
return err;
}
-char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev)
+char * b43legacy_rfkill_led_name(struct b43legacy_wldev *dev)
{
struct b43legacy_wl *wl = dev->wl;
@@ -121,38 +112,74 @@ void b43legacy_rfkill_init(struct b43legacy_wldev *dev)
struct b43legacy_rfkill *rfk = &(wl->rfkill);
int err;
+ if (rfk->rfkill) {
+ err = rfkill_register(rfk->rfkill);
+ if (err) {
+ b43legacywarn(wl, "Failed to register RF-kill button\n");
+ goto err_free_rfk;
+ }
+ }
+ if (rfk->poll_dev) {
+ err = input_register_polled_device(rfk->poll_dev);
+ if (err) {
+ b43legacywarn(wl, "Failed to register RF-kill polldev\n");
+ goto err_free_polldev;
+ }
+ }
+
+ return;
+err_free_rfk:
+ rfkill_free(rfk->rfkill);
+ rfk->rfkill = NULL;
+err_free_polldev:
+ input_free_polled_device(rfk->poll_dev);
+ rfk->poll_dev = NULL;
+}
+
+void b43legacy_rfkill_exit(struct b43legacy_wldev *dev)
+{
+ struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
+
+ if (rfk->poll_dev)
+ input_unregister_polled_device(rfk->poll_dev);
+ if (rfk->rfkill)
+ rfkill_unregister(rfk->rfkill);
+}
+
+void b43legacy_rfkill_alloc(struct b43legacy_wldev *dev)
+{
+ struct b43legacy_wl *wl = dev->wl;
+ struct b43legacy_rfkill *rfk = &(wl->rfkill);
+
snprintf(rfk->name, sizeof(rfk->name),
"b43legacy-%s", wiphy_name(wl->hw->wiphy));
+
rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN);
- if (!rfk->rfkill)
- goto error;
+ if (!rfk->rfkill) {
+ b43legacywarn(wl, "Failed to allocate RF-kill button\n");
+ return;
+ }
rfk->rfkill->name = rfk->name;
rfk->rfkill->state = RFKILL_STATE_ON;
rfk->rfkill->data = dev;
rfk->rfkill->toggle_radio = b43legacy_rfkill_soft_toggle;
rfk->rfkill->user_claim_unsupported = 1;
- INIT_WORK(&rfk->notify_work, b43legacy_notify_rfkill_press);
-
- err = rfkill_register(rfk->rfkill);
- if (err)
- goto error;
-
- return;
-error:
- b43legacywarn(dev->wl, "Failed to initialize the RF-kill button\n");
- rfkill_free(rfk->rfkill);
- rfk->rfkill = NULL;
+ rfk->poll_dev = input_allocate_polled_device();
+ if (rfk->poll_dev) {
+ rfk->poll_dev->private = dev;
+ rfk->poll_dev->poll = b43legacy_rfkill_poll;
+ rfk->poll_dev->poll_interval = 1000; /* msecs */
+ } else
+ b43legacywarn(wl, "Failed to allocate RF-kill polldev\n");
}
-void b43legacy_rfkill_exit(struct b43legacy_wldev *dev)
+void b43legacy_rfkill_free(struct b43legacy_wldev *dev)
{
struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
- if (!rfk->rfkill)
- return;
- cancel_work_sync(&rfk->notify_work);
- rfkill_unregister(rfk->rfkill);
+ input_free_polled_device(rfk->poll_dev);
+ rfk->poll_dev = NULL;
rfkill_free(rfk->rfkill);
rfk->rfkill = NULL;
}
OpenPOWER on IntegriCloud