3 Broadcom B43 wireless driver
6 Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
21 Boston, MA 02110-1301, USA.
29 /* Returns TRUE, if the radio is enabled in hardware. */
30 static bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
32 if (dev->phy.rev >= 3) {
33 if (!(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
34 & B43_MMIO_RADIO_HWENABLED_HI_MASK))
37 if (b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO)
38 & B43_MMIO_RADIO_HWENABLED_LO_MASK)
44 /* The poll callback for the hardware button. */
45 static void b43_rfkill_poll(struct input_polled_dev *poll_dev)
47 struct b43_wldev *dev = poll_dev->private;
48 struct b43_wl *wl = dev->wl;
50 bool report_change = 0;
52 mutex_lock(&wl->mutex);
53 B43_WARN_ON(b43_status(dev) < B43_STAT_INITIALIZED);
54 enabled = b43_is_hw_radio_enabled(dev);
55 if (unlikely(enabled != dev->radio_hw_enable)) {
56 dev->radio_hw_enable = enabled;
58 b43info(wl, "Radio hardware status changed to %s\n",
59 enabled ? "ENABLED" : "DISABLED");
61 mutex_unlock(&wl->mutex);
63 if (unlikely(report_change))
64 input_report_key(poll_dev->input, KEY_WLAN, enabled);
67 /* Called when the RFKILL toggled in software. */
68 static int b43_rfkill_soft_toggle(void *data, enum rfkill_state state)
70 struct b43_wldev *dev = data;
71 struct b43_wl *wl = dev->wl;
74 if (!wl->rfkill.registered)
77 mutex_lock(&wl->mutex);
78 B43_WARN_ON(b43_status(dev) < B43_STAT_INITIALIZED);
81 if (!dev->radio_hw_enable) {
82 /* No luck. We can't toggle the hardware RF-kill
83 * button from software. */
87 if (!dev->phy.radio_on)
88 b43_radio_turn_on(dev);
90 case RFKILL_STATE_OFF:
91 if (dev->phy.radio_on)
92 b43_radio_turn_off(dev, 0);
96 mutex_unlock(&wl->mutex);
101 char * b43_rfkill_led_name(struct b43_wldev *dev)
103 struct b43_rfkill *rfk = &(dev->wl->rfkill);
105 if (!rfk->registered)
107 return rfkill_get_led_name(rfk->rfkill);
110 void b43_rfkill_init(struct b43_wldev *dev)
112 struct b43_wl *wl = dev->wl;
113 struct b43_rfkill *rfk = &(wl->rfkill);
118 rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN);
121 snprintf(rfk->name, sizeof(rfk->name),
122 "b43-%s", wiphy_name(wl->hw->wiphy));
123 rfk->rfkill->name = rfk->name;
124 rfk->rfkill->state = RFKILL_STATE_ON;
125 rfk->rfkill->data = dev;
126 rfk->rfkill->toggle_radio = b43_rfkill_soft_toggle;
127 rfk->rfkill->user_claim_unsupported = 1;
129 rfk->poll_dev = input_allocate_polled_device();
132 rfk->poll_dev->private = dev;
133 rfk->poll_dev->poll = b43_rfkill_poll;
134 rfk->poll_dev->poll_interval = 1000; /* msecs */
136 err = rfkill_register(rfk->rfkill);
138 goto err_free_polldev;
139 err = input_register_polled_device(rfk->poll_dev);
147 rfkill_unregister(rfk->rfkill);
149 input_free_polled_device(rfk->poll_dev);
150 rfk->poll_dev = NULL;
152 rfkill_free(rfk->rfkill);
156 b43warn(wl, "RF-kill button init failed\n");
159 void b43_rfkill_exit(struct b43_wldev *dev)
161 struct b43_rfkill *rfk = &(dev->wl->rfkill);
163 if (!rfk->registered)
167 input_unregister_polled_device(rfk->poll_dev);
168 rfkill_unregister(rfk->rfkill);
169 input_free_polled_device(rfk->poll_dev);
170 rfk->poll_dev = NULL;
171 rfkill_free(rfk->rfkill);