2007-10-11 10:44:22 +07:00
|
|
|
/*
|
|
|
|
|
2007-10-11 10:48:17 +07:00
|
|
|
Broadcom B43 wireless driver
|
2007-10-11 10:44:22 +07:00
|
|
|
RFKILL support
|
|
|
|
|
|
|
|
Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rfkill.h"
|
|
|
|
#include "radio.h"
|
|
|
|
#include "b43legacy.h"
|
|
|
|
|
2007-12-17 01:21:06 +07:00
|
|
|
#include <linux/kmod.h>
|
|
|
|
|
2007-10-11 10:44:22 +07:00
|
|
|
|
2007-10-11 10:48:17 +07:00
|
|
|
/* Returns TRUE, if the radio is enabled in hardware. */
|
|
|
|
static bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
|
2007-10-11 10:44:22 +07:00
|
|
|
{
|
2007-10-11 10:48:17 +07:00
|
|
|
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;
|
2007-10-11 10:44:22 +07:00
|
|
|
}
|
2007-10-11 10:48:17 +07:00
|
|
|
return 0;
|
2007-10-11 10:44:22 +07:00
|
|
|
}
|
|
|
|
|
2007-10-11 10:48:17 +07:00
|
|
|
/* The poll callback for the hardware button. */
|
2009-06-02 18:01:37 +07:00
|
|
|
static void b43legacy_rfkill_poll(struct rfkill *rfkill, void *data)
|
2007-10-11 10:44:22 +07:00
|
|
|
{
|
2009-06-02 18:01:37 +07:00
|
|
|
struct b43legacy_wldev *dev = data;
|
2007-10-11 10:44:22 +07:00
|
|
|
struct b43legacy_wl *wl = dev->wl;
|
2007-10-11 10:48:17 +07:00
|
|
|
bool enabled;
|
2007-10-11 10:44:22 +07:00
|
|
|
|
2007-10-11 10:48:17 +07:00
|
|
|
mutex_lock(&wl->mutex);
|
2007-12-17 01:21:06 +07:00
|
|
|
if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) {
|
|
|
|
mutex_unlock(&wl->mutex);
|
|
|
|
return;
|
|
|
|
}
|
2007-10-11 10:48:17 +07:00
|
|
|
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");
|
2009-06-02 18:01:37 +07:00
|
|
|
enabled = !rfkill_set_hw_state(rfkill, !enabled);
|
|
|
|
if (enabled != dev->phy.radio_on) {
|
|
|
|
if (enabled)
|
|
|
|
b43legacy_radio_turn_on(dev);
|
|
|
|
else
|
|
|
|
b43legacy_radio_turn_off(dev, 0);
|
|
|
|
}
|
2007-11-07 04:48:45 +07:00
|
|
|
}
|
|
|
|
mutex_unlock(&wl->mutex);
|
2007-10-11 10:44:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when the RFKILL toggled in software.
|
|
|
|
* This is called without locking. */
|
2009-06-02 18:01:37 +07:00
|
|
|
static int b43legacy_rfkill_soft_set(void *data, bool blocked)
|
2007-10-11 10:44:22 +07:00
|
|
|
{
|
|
|
|
struct b43legacy_wldev *dev = data;
|
|
|
|
struct b43legacy_wl *wl = dev->wl;
|
2009-06-02 18:01:37 +07:00
|
|
|
int ret = -EINVAL;
|
2007-10-11 10:44:22 +07:00
|
|
|
|
2007-11-07 04:48:45 +07:00
|
|
|
if (!wl->rfkill.registered)
|
2009-06-02 18:01:37 +07:00
|
|
|
return -EINVAL;
|
2007-10-11 10:44:22 +07:00
|
|
|
|
2007-11-07 04:48:45 +07:00
|
|
|
mutex_lock(&wl->mutex);
|
2007-12-17 01:21:06 +07:00
|
|
|
if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)
|
|
|
|
goto out_unlock;
|
2009-06-02 18:01:37 +07:00
|
|
|
|
|
|
|
if (!dev->radio_hw_enable)
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
if (!blocked != dev->phy.radio_on) {
|
|
|
|
if (!blocked)
|
2007-10-11 10:44:22 +07:00
|
|
|
b43legacy_radio_turn_on(dev);
|
2009-06-02 18:01:37 +07:00
|
|
|
else
|
2007-10-11 10:44:22 +07:00
|
|
|
b43legacy_radio_turn_off(dev, 0);
|
|
|
|
}
|
2009-06-02 18:01:37 +07:00
|
|
|
ret = 0;
|
2007-10-11 10:44:22 +07:00
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&wl->mutex);
|
2009-06-02 18:01:37 +07:00
|
|
|
return ret;
|
2007-10-11 10:44:22 +07:00
|
|
|
}
|
|
|
|
|
2009-06-02 18:01:37 +07:00
|
|
|
const char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev)
|
2007-10-11 10:44:22 +07:00
|
|
|
{
|
2007-12-17 01:21:06 +07:00
|
|
|
struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
|
2007-10-11 10:44:22 +07:00
|
|
|
|
2007-12-17 01:21:06 +07:00
|
|
|
if (!rfk->registered)
|
2007-10-11 10:44:22 +07:00
|
|
|
return NULL;
|
2009-06-02 18:01:37 +07:00
|
|
|
return rfkill_get_led_trigger_name(rfk->rfkill);
|
2007-10-11 10:44:22 +07:00
|
|
|
}
|
|
|
|
|
2009-06-02 18:01:37 +07:00
|
|
|
static const struct rfkill_ops b43legacy_rfkill_ops = {
|
|
|
|
.set_block = b43legacy_rfkill_soft_set,
|
|
|
|
.poll = b43legacy_rfkill_poll,
|
|
|
|
};
|
|
|
|
|
2007-10-11 10:44:22 +07:00
|
|
|
void b43legacy_rfkill_init(struct b43legacy_wldev *dev)
|
|
|
|
{
|
|
|
|
struct b43legacy_wl *wl = dev->wl;
|
|
|
|
struct b43legacy_rfkill *rfk = &(wl->rfkill);
|
|
|
|
int err;
|
|
|
|
|
2007-12-17 01:21:06 +07:00
|
|
|
rfk->registered = 0;
|
2007-10-11 10:48:17 +07:00
|
|
|
|
2007-10-11 10:44:22 +07:00
|
|
|
snprintf(rfk->name, sizeof(rfk->name),
|
|
|
|
"b43legacy-%s", wiphy_name(wl->hw->wiphy));
|
2009-06-02 18:01:37 +07:00
|
|
|
rfk->rfkill = rfkill_alloc(rfk->name,
|
|
|
|
dev->dev->dev,
|
|
|
|
RFKILL_TYPE_WLAN,
|
|
|
|
&b43legacy_rfkill_ops, dev);
|
|
|
|
if (!rfk->rfkill)
|
|
|
|
goto out_error;
|
2007-12-17 01:21:06 +07:00
|
|
|
|
|
|
|
err = rfkill_register(rfk->rfkill);
|
|
|
|
if (err)
|
2009-06-02 18:01:37 +07:00
|
|
|
goto err_free;
|
2007-12-17 01:21:06 +07:00
|
|
|
|
|
|
|
rfk->registered = 1;
|
|
|
|
|
|
|
|
return;
|
2009-06-02 18:01:37 +07:00
|
|
|
err_free:
|
|
|
|
rfkill_destroy(rfk->rfkill);
|
|
|
|
out_error:
|
2007-12-17 01:21:06 +07:00
|
|
|
rfk->registered = 0;
|
|
|
|
b43legacywarn(wl, "RF-kill button init failed\n");
|
2007-10-11 10:44:22 +07:00
|
|
|
}
|
|
|
|
|
2007-12-17 01:21:06 +07:00
|
|
|
void b43legacy_rfkill_exit(struct b43legacy_wldev *dev)
|
2007-10-11 10:44:22 +07:00
|
|
|
{
|
|
|
|
struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
|
|
|
|
|
2007-12-17 01:21:06 +07:00
|
|
|
if (!rfk->registered)
|
|
|
|
return;
|
|
|
|
rfk->registered = 0;
|
|
|
|
|
|
|
|
rfkill_unregister(rfk->rfkill);
|
2009-06-02 18:01:37 +07:00
|
|
|
rfkill_destroy(rfk->rfkill);
|
2007-10-11 10:44:22 +07:00
|
|
|
rfk->rfkill = NULL;
|
|
|
|
}
|
2007-12-17 01:21:06 +07:00
|
|
|
|