提交 6be50837 编写于 作者: L Larry Finger 提交者: David S. Miller

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: NLarry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: NJohn W. Linville <linville@tuxdriver.com>
上级 93bb7f3a
...@@ -43,7 +43,7 @@ config B43LEGACY_LEDS ...@@ -43,7 +43,7 @@ config B43LEGACY_LEDS
# RFKILL support # RFKILL support
config B43LEGACY_RFKILL config B43LEGACY_RFKILL
bool bool
depends on B43LEGACY && RFKILL depends on B43LEGACY && RFKILL && RFKILL_INPUT && INPUT_POLLDEV
default y default y
config B43LEGACY_DEBUG config B43LEGACY_DEBUG
......
...@@ -1975,21 +1975,6 @@ static void b43legacy_mgmtframe_txantenna(struct b43legacy_wldev *dev, ...@@ -1975,21 +1975,6 @@ static void b43legacy_mgmtframe_txantenna(struct b43legacy_wldev *dev,
B43legacy_SHM_SH_PRPHYCTL, tmp); B43legacy_SHM_SH_PRPHYCTL, tmp);
} }
/* Returns TRUE, if the radio is enabled in hardware. */
static bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
{
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;
}
/* This is the opposite of b43legacy_chip_init() */ /* This is the opposite of b43legacy_chip_init() */
static void b43legacy_chip_exit(struct b43legacy_wldev *dev) static void b43legacy_chip_exit(struct b43legacy_wldev *dev)
{ {
...@@ -2146,32 +2131,18 @@ static void b43legacy_periodic_every15sec(struct b43legacy_wldev *dev) ...@@ -2146,32 +2131,18 @@ static void b43legacy_periodic_every15sec(struct b43legacy_wldev *dev)
b43legacy_phy_xmitpower(dev); /* FIXME: unless scanning? */ b43legacy_phy_xmitpower(dev); /* FIXME: unless scanning? */
} }
static void b43legacy_periodic_every1sec(struct b43legacy_wldev *dev)
{
bool radio_hw_enable;
/* check if radio hardware enabled status changed */
radio_hw_enable = b43legacy_is_hw_radio_enabled(dev);
if (unlikely(dev->radio_hw_enable != radio_hw_enable)) {
dev->radio_hw_enable = radio_hw_enable;
b43legacy_rfkill_toggled(dev, radio_hw_enable);
}
}
static void do_periodic_work(struct b43legacy_wldev *dev) static void do_periodic_work(struct b43legacy_wldev *dev)
{ {
unsigned int state; unsigned int state;
state = dev->periodic_state; state = dev->periodic_state;
if (state % 120 == 0) if (state % 8 == 0)
b43legacy_periodic_every120sec(dev); b43legacy_periodic_every120sec(dev);
if (state % 60 == 0) if (state % 4 == 0)
b43legacy_periodic_every60sec(dev); b43legacy_periodic_every60sec(dev);
if (state % 30 == 0) if (state % 2 == 0)
b43legacy_periodic_every30sec(dev); b43legacy_periodic_every30sec(dev);
if (state % 15 == 0) b43legacy_periodic_every15sec(dev);
b43legacy_periodic_every15sec(dev);
b43legacy_periodic_every1sec(dev);
} }
/* Estimate a "Badness" value based on the periodic work /* Estimate a "Badness" value based on the periodic work
...@@ -2182,13 +2153,11 @@ static int estimate_periodic_work_badness(unsigned int state) ...@@ -2182,13 +2153,11 @@ static int estimate_periodic_work_badness(unsigned int state)
{ {
int badness = 0; int badness = 0;
if (state % 120 == 0) /* every 120 sec */ if (state % 8 == 0) /* every 120 sec */
badness += 10; badness += 10;
if (state % 60 == 0) /* every 60 sec */ if (state % 4 == 0) /* every 60 sec */
badness += 5; badness += 5;
if (state % 30 == 0) /* every 30 sec */ if (state % 2 == 0) /* every 30 sec */
badness += 1;
if (state % 15 == 0) /* every 15 sec */
badness += 1; badness += 1;
#define BADNESS_LIMIT 4 #define BADNESS_LIMIT 4
...@@ -2246,7 +2215,7 @@ static void b43legacy_periodic_work_handler(struct work_struct *work) ...@@ -2246,7 +2215,7 @@ static void b43legacy_periodic_work_handler(struct work_struct *work)
if (b43legacy_debug(dev, B43legacy_DBG_PWORK_FAST)) if (b43legacy_debug(dev, B43legacy_DBG_PWORK_FAST))
delay = msecs_to_jiffies(50); delay = msecs_to_jiffies(50);
else else
delay = round_jiffies_relative(HZ); delay = round_jiffies_relative(HZ * 15);
queue_delayed_work(dev->wl->hw->workqueue, queue_delayed_work(dev->wl->hw->workqueue,
&dev->periodic_work, delay); &dev->periodic_work, delay);
out: out:
...@@ -3449,6 +3418,7 @@ static int b43legacy_setup_modes(struct b43legacy_wldev *dev, ...@@ -3449,6 +3418,7 @@ static int b43legacy_setup_modes(struct b43legacy_wldev *dev,
static void b43legacy_wireless_core_detach(struct b43legacy_wldev *dev) static void b43legacy_wireless_core_detach(struct b43legacy_wldev *dev)
{ {
b43legacy_rfkill_free(dev);
/* We release firmware that late to not be required to re-request /* We release firmware that late to not be required to re-request
* is all the time when we reinit the core. */ * is all the time when we reinit the core. */
b43legacy_release_firmware(dev); b43legacy_release_firmware(dev);
...@@ -3530,6 +3500,7 @@ static int b43legacy_wireless_core_attach(struct b43legacy_wldev *dev) ...@@ -3530,6 +3500,7 @@ static int b43legacy_wireless_core_attach(struct b43legacy_wldev *dev)
if (!wl->current_dev) if (!wl->current_dev)
wl->current_dev = dev; wl->current_dev = dev;
INIT_WORK(&dev->restart_work, b43legacy_chip_reset); INIT_WORK(&dev->restart_work, b43legacy_chip_reset);
b43legacy_rfkill_alloc(dev);
b43legacy_radio_turn_off(dev, 1); b43legacy_radio_turn_off(dev, 1);
b43legacy_switch_analog(dev, 0); b43legacy_switch_analog(dev, 0);
......
/* /*
Broadcom B43legacy wireless driver Broadcom B43 wireless driver
RFKILL support RFKILL support
Copyright (c) 2007 Michael Buesch <mb@bu3sch.de> Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
...@@ -27,48 +27,39 @@ ...@@ -27,48 +27,39 @@
#include "b43legacy.h" #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, if (dev->phy.rev >= 3) {
struct b43legacy_rfkill, if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
notify_work); & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
struct b43legacy_wl *wl = container_of(rfk, struct b43legacy_wl, return 1;
rfkill); } else {
struct b43legacy_wldev *dev; if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
enum rfkill_state state; & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
return 1;
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);
} }
return 0;
} }
/* Called when the RFKILL toggled in hardware. /* The poll callback for the hardware button. */
* This is called with the mutex locked. */ static void b43legacy_rfkill_poll(struct input_polled_dev *poll_dev)
void b43legacy_rfkill_toggled(struct b43legacy_wldev *dev, bool on)
{ {
struct b43legacy_wldev *dev = poll_dev->private;
struct b43legacy_wl *wl = dev->wl; struct b43legacy_wl *wl = dev->wl;
bool enabled;
mutex_lock(&wl->mutex);
B43legacy_WARN_ON(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED); B43legacy_WARN_ON(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED);
/* Update the RF status asynchronously, as rfkill will enabled = b43legacy_is_hw_radio_enabled(dev);
* call back into the software toggle handler. if (unlikely(enabled != dev->radio_hw_enable)) {
* This would deadlock if done synchronously. */ dev->radio_hw_enable = enabled;
queue_work(wl->hw->workqueue, &wl->rfkill.notify_work); 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. /* Called when the RFKILL toggled in software.
...@@ -106,7 +97,7 @@ static int b43legacy_rfkill_soft_toggle(void *data, enum rfkill_state state) ...@@ -106,7 +97,7 @@ static int b43legacy_rfkill_soft_toggle(void *data, enum rfkill_state state)
return err; 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; struct b43legacy_wl *wl = dev->wl;
...@@ -121,38 +112,74 @@ void b43legacy_rfkill_init(struct b43legacy_wldev *dev) ...@@ -121,38 +112,74 @@ void b43legacy_rfkill_init(struct b43legacy_wldev *dev)
struct b43legacy_rfkill *rfk = &(wl->rfkill); struct b43legacy_rfkill *rfk = &(wl->rfkill);
int err; 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), snprintf(rfk->name, sizeof(rfk->name),
"b43legacy-%s", wiphy_name(wl->hw->wiphy)); "b43legacy-%s", wiphy_name(wl->hw->wiphy));
rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN); rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN);
if (!rfk->rfkill) if (!rfk->rfkill) {
goto error; b43legacywarn(wl, "Failed to allocate RF-kill button\n");
return;
}
rfk->rfkill->name = rfk->name; rfk->rfkill->name = rfk->name;
rfk->rfkill->state = RFKILL_STATE_ON; rfk->rfkill->state = RFKILL_STATE_ON;
rfk->rfkill->data = dev; rfk->rfkill->data = dev;
rfk->rfkill->toggle_radio = b43legacy_rfkill_soft_toggle; rfk->rfkill->toggle_radio = b43legacy_rfkill_soft_toggle;
rfk->rfkill->user_claim_unsupported = 1; rfk->rfkill->user_claim_unsupported = 1;
INIT_WORK(&rfk->notify_work, b43legacy_notify_rfkill_press); rfk->poll_dev = input_allocate_polled_device();
if (rfk->poll_dev) {
err = rfkill_register(rfk->rfkill); rfk->poll_dev->private = dev;
if (err) rfk->poll_dev->poll = b43legacy_rfkill_poll;
goto error; rfk->poll_dev->poll_interval = 1000; /* msecs */
} else
return; b43legacywarn(wl, "Failed to allocate RF-kill polldev\n");
error:
b43legacywarn(dev->wl, "Failed to initialize the RF-kill button\n");
rfkill_free(rfk->rfkill);
rfk->rfkill = NULL;
} }
void b43legacy_rfkill_exit(struct b43legacy_wldev *dev) void b43legacy_rfkill_free(struct b43legacy_wldev *dev)
{ {
struct b43legacy_rfkill *rfk = &(dev->wl->rfkill); struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
if (!rfk->rfkill) input_free_polled_device(rfk->poll_dev);
return; rfk->poll_dev = NULL;
cancel_work_sync(&rfk->notify_work);
rfkill_unregister(rfk->rfkill);
rfkill_free(rfk->rfkill); rfkill_free(rfk->rfkill);
rfk->rfkill = NULL; rfk->rfkill = NULL;
} }
...@@ -7,21 +7,27 @@ struct b43legacy_wldev; ...@@ -7,21 +7,27 @@ struct b43legacy_wldev;
#include <linux/rfkill.h> #include <linux/rfkill.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/input-polldev.h>
struct b43legacy_rfkill { struct b43legacy_rfkill {
/* The RFKILL subsystem data structure */ /* The RFKILL subsystem data structure */
struct rfkill *rfkill; struct rfkill *rfkill;
/* The poll device for the RFKILL input button */
struct input_polled_dev *poll_dev;
/* The unique name of this rfkill switch */ /* The unique name of this rfkill switch */
char name[32]; char name[32];
/* Workqueue for asynchronous notification. */
struct work_struct notify_work;
}; };
/* All the init functions return void, because we are not interested
* in failing the b43 init process when rfkill init failed. */
void b43legacy_rfkill_alloc(struct b43legacy_wldev *dev);
void b43legacy_rfkill_free(struct b43legacy_wldev *dev);
void b43legacy_rfkill_init(struct b43legacy_wldev *dev); void b43legacy_rfkill_init(struct b43legacy_wldev *dev);
void b43legacy_rfkill_exit(struct b43legacy_wldev *dev); void b43legacy_rfkill_exit(struct b43legacy_wldev *dev);
void b43legacy_rfkill_toggled(struct b43legacy_wldev *dev, bool on);
char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev); char * b43legacy_rfkill_led_name(struct b43legacy_wldev *dev);
#else /* CONFIG_B43LEGACY_RFKILL */ #else /* CONFIG_B43LEGACY_RFKILL */
...@@ -31,17 +37,19 @@ struct b43legacy_rfkill { ...@@ -31,17 +37,19 @@ struct b43legacy_rfkill {
/* empty */ /* empty */
}; };
static inline void b43legacy_rfkill_init(struct b43legacy_wldev *dev) static inline void b43legacy_rfkill_alloc(struct b43legacy_wldev *dev)
{ {
} }
static inline void b43legacy_rfkill_exit(struct b43legacy_wldev *dev) static inline void b43legacy_rfkill_free(struct b43legacy_wldev *dev)
{ {
} }
static inline void b43legacy_rfkill_toggled(struct b43legacy_wldev *dev, static inline void b43legacy_rfkill_init(struct b43legacy_wldev *dev)
bool on) {
}
static inline void b43legacy_rfkill_exit(struct b43legacy_wldev *dev)
{ {
} }
static inline char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev) static inline char * b43legacy_rfkill_led_name(struct b43legacy_wldev *dev)
{ {
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册