diff options
Diffstat (limited to 'drivers/net/wireless/b43legacy/rfkill.c')
-rw-r--r-- | drivers/net/wireless/b43legacy/rfkill.c | 123 |
1 files changed, 39 insertions, 84 deletions
diff --git a/drivers/net/wireless/b43legacy/rfkill.c b/drivers/net/wireless/b43legacy/rfkill.c index 4b0c7d27a51f..c6230a64505a 100644 --- a/drivers/net/wireless/b43legacy/rfkill.c +++ b/drivers/net/wireless/b43legacy/rfkill.c | |||
@@ -45,12 +45,11 @@ static bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev) | |||
45 | } | 45 | } |
46 | 46 | ||
47 | /* The poll callback for the hardware button. */ | 47 | /* The poll callback for the hardware button. */ |
48 | static void b43legacy_rfkill_poll(struct input_polled_dev *poll_dev) | 48 | static void b43legacy_rfkill_poll(struct rfkill *rfkill, void *data) |
49 | { | 49 | { |
50 | struct b43legacy_wldev *dev = poll_dev->private; | 50 | struct b43legacy_wldev *dev = data; |
51 | struct b43legacy_wl *wl = dev->wl; | 51 | struct b43legacy_wl *wl = dev->wl; |
52 | bool enabled; | 52 | bool enabled; |
53 | bool report_change = 0; | ||
54 | 53 | ||
55 | mutex_lock(&wl->mutex); | 54 | mutex_lock(&wl->mutex); |
56 | if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) { | 55 | if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) { |
@@ -60,71 +59,64 @@ static void b43legacy_rfkill_poll(struct input_polled_dev *poll_dev) | |||
60 | enabled = b43legacy_is_hw_radio_enabled(dev); | 59 | enabled = b43legacy_is_hw_radio_enabled(dev); |
61 | if (unlikely(enabled != dev->radio_hw_enable)) { | 60 | if (unlikely(enabled != dev->radio_hw_enable)) { |
62 | dev->radio_hw_enable = enabled; | 61 | dev->radio_hw_enable = enabled; |
63 | report_change = 1; | ||
64 | b43legacyinfo(wl, "Radio hardware status changed to %s\n", | 62 | b43legacyinfo(wl, "Radio hardware status changed to %s\n", |
65 | enabled ? "ENABLED" : "DISABLED"); | 63 | enabled ? "ENABLED" : "DISABLED"); |
64 | enabled = !rfkill_set_hw_state(rfkill, !enabled); | ||
65 | if (enabled != dev->phy.radio_on) { | ||
66 | if (enabled) | ||
67 | b43legacy_radio_turn_on(dev); | ||
68 | else | ||
69 | b43legacy_radio_turn_off(dev, 0); | ||
70 | } | ||
66 | } | 71 | } |
67 | mutex_unlock(&wl->mutex); | 72 | mutex_unlock(&wl->mutex); |
68 | |||
69 | /* send the radio switch event to the system - note both a key press | ||
70 | * and a release are required */ | ||
71 | if (unlikely(report_change)) { | ||
72 | input_report_key(poll_dev->input, KEY_WLAN, 1); | ||
73 | input_report_key(poll_dev->input, KEY_WLAN, 0); | ||
74 | } | ||
75 | } | 73 | } |
76 | 74 | ||
77 | /* Called when the RFKILL toggled in software. | 75 | /* Called when the RFKILL toggled in software. |
78 | * This is called without locking. */ | 76 | * This is called without locking. */ |
79 | static int b43legacy_rfkill_soft_toggle(void *data, enum rfkill_state state) | 77 | static int b43legacy_rfkill_soft_set(void *data, bool blocked) |
80 | { | 78 | { |
81 | struct b43legacy_wldev *dev = data; | 79 | struct b43legacy_wldev *dev = data; |
82 | struct b43legacy_wl *wl = dev->wl; | 80 | struct b43legacy_wl *wl = dev->wl; |
83 | int err = -EBUSY; | 81 | int ret = -EINVAL; |
84 | 82 | ||
85 | if (!wl->rfkill.registered) | 83 | if (!wl->rfkill.registered) |
86 | return 0; | 84 | return -EINVAL; |
87 | 85 | ||
88 | mutex_lock(&wl->mutex); | 86 | mutex_lock(&wl->mutex); |
89 | if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED) | 87 | if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED) |
90 | goto out_unlock; | 88 | goto out_unlock; |
91 | err = 0; | 89 | |
92 | switch (state) { | 90 | if (!dev->radio_hw_enable) |
93 | case RFKILL_STATE_UNBLOCKED: | 91 | goto out_unlock; |
94 | if (!dev->radio_hw_enable) { | 92 | |
95 | /* No luck. We can't toggle the hardware RF-kill | 93 | if (!blocked != dev->phy.radio_on) { |
96 | * button from software. */ | 94 | if (!blocked) |
97 | err = -EBUSY; | ||
98 | goto out_unlock; | ||
99 | } | ||
100 | if (!dev->phy.radio_on) | ||
101 | b43legacy_radio_turn_on(dev); | 95 | b43legacy_radio_turn_on(dev); |
102 | break; | 96 | else |
103 | case RFKILL_STATE_SOFT_BLOCKED: | ||
104 | if (dev->phy.radio_on) | ||
105 | b43legacy_radio_turn_off(dev, 0); | 97 | b43legacy_radio_turn_off(dev, 0); |
106 | break; | ||
107 | default: | ||
108 | b43legacywarn(wl, "Received unexpected rfkill state %d.\n", | ||
109 | state); | ||
110 | break; | ||
111 | } | 98 | } |
99 | ret = 0; | ||
112 | 100 | ||
113 | out_unlock: | 101 | out_unlock: |
114 | mutex_unlock(&wl->mutex); | 102 | mutex_unlock(&wl->mutex); |
115 | 103 | return ret; | |
116 | return err; | ||
117 | } | 104 | } |
118 | 105 | ||
119 | char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev) | 106 | const char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev) |
120 | { | 107 | { |
121 | struct b43legacy_rfkill *rfk = &(dev->wl->rfkill); | 108 | struct b43legacy_rfkill *rfk = &(dev->wl->rfkill); |
122 | 109 | ||
123 | if (!rfk->registered) | 110 | if (!rfk->registered) |
124 | return NULL; | 111 | return NULL; |
125 | return rfkill_get_led_name(rfk->rfkill); | 112 | return rfkill_get_led_trigger_name(rfk->rfkill); |
126 | } | 113 | } |
127 | 114 | ||
115 | static const struct rfkill_ops b43legacy_rfkill_ops = { | ||
116 | .set_block = b43legacy_rfkill_soft_set, | ||
117 | .poll = b43legacy_rfkill_poll, | ||
118 | }; | ||
119 | |||
128 | void b43legacy_rfkill_init(struct b43legacy_wldev *dev) | 120 | void b43legacy_rfkill_init(struct b43legacy_wldev *dev) |
129 | { | 121 | { |
130 | struct b43legacy_wl *wl = dev->wl; | 122 | struct b43legacy_wl *wl = dev->wl; |
@@ -133,60 +125,25 @@ void b43legacy_rfkill_init(struct b43legacy_wldev *dev) | |||
133 | 125 | ||
134 | rfk->registered = 0; | 126 | rfk->registered = 0; |
135 | 127 | ||
136 | rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN); | ||
137 | if (!rfk->rfkill) | ||
138 | goto out_error; | ||
139 | snprintf(rfk->name, sizeof(rfk->name), | 128 | snprintf(rfk->name, sizeof(rfk->name), |
140 | "b43legacy-%s", wiphy_name(wl->hw->wiphy)); | 129 | "b43legacy-%s", wiphy_name(wl->hw->wiphy)); |
141 | rfk->rfkill->name = rfk->name; | 130 | rfk->rfkill = rfkill_alloc(rfk->name, |
142 | rfk->rfkill->state = RFKILL_STATE_UNBLOCKED; | 131 | dev->dev->dev, |
143 | rfk->rfkill->data = dev; | 132 | RFKILL_TYPE_WLAN, |
144 | rfk->rfkill->toggle_radio = b43legacy_rfkill_soft_toggle; | 133 | &b43legacy_rfkill_ops, dev); |
145 | 134 | if (!rfk->rfkill) | |
146 | rfk->poll_dev = input_allocate_polled_device(); | 135 | goto out_error; |
147 | if (!rfk->poll_dev) { | ||
148 | rfkill_free(rfk->rfkill); | ||
149 | goto err_freed_rfk; | ||
150 | } | ||
151 | |||
152 | rfk->poll_dev->private = dev; | ||
153 | rfk->poll_dev->poll = b43legacy_rfkill_poll; | ||
154 | rfk->poll_dev->poll_interval = 1000; /* msecs */ | ||
155 | |||
156 | rfk->poll_dev->input->name = rfk->name; | ||
157 | rfk->poll_dev->input->id.bustype = BUS_HOST; | ||
158 | rfk->poll_dev->input->id.vendor = dev->dev->bus->boardinfo.vendor; | ||
159 | rfk->poll_dev->input->evbit[0] = BIT(EV_KEY); | ||
160 | set_bit(KEY_WLAN, rfk->poll_dev->input->keybit); | ||
161 | 136 | ||
162 | err = rfkill_register(rfk->rfkill); | 137 | err = rfkill_register(rfk->rfkill); |
163 | if (err) | 138 | if (err) |
164 | goto err_free_polldev; | 139 | goto err_free; |
165 | |||
166 | #ifdef CONFIG_RFKILL_INPUT_MODULE | ||
167 | /* B43legacy RF-kill isn't useful without the rfkill-input subsystem. | ||
168 | * Try to load the module. */ | ||
169 | err = request_module("rfkill-input"); | ||
170 | if (err) | ||
171 | b43legacywarn(wl, "Failed to load the rfkill-input module." | ||
172 | "The built-in radio LED will not work.\n"); | ||
173 | #endif /* CONFIG_RFKILL_INPUT */ | ||
174 | |||
175 | err = input_register_polled_device(rfk->poll_dev); | ||
176 | if (err) | ||
177 | goto err_unreg_rfk; | ||
178 | 140 | ||
179 | rfk->registered = 1; | 141 | rfk->registered = 1; |
180 | 142 | ||
181 | return; | 143 | return; |
182 | err_unreg_rfk: | 144 | err_free: |
183 | rfkill_unregister(rfk->rfkill); | 145 | rfkill_destroy(rfk->rfkill); |
184 | err_free_polldev: | 146 | out_error: |
185 | input_free_polled_device(rfk->poll_dev); | ||
186 | rfk->poll_dev = NULL; | ||
187 | err_freed_rfk: | ||
188 | rfk->rfkill = NULL; | ||
189 | out_error: | ||
190 | rfk->registered = 0; | 147 | rfk->registered = 0; |
191 | b43legacywarn(wl, "RF-kill button init failed\n"); | 148 | b43legacywarn(wl, "RF-kill button init failed\n"); |
192 | } | 149 | } |
@@ -199,10 +156,8 @@ void b43legacy_rfkill_exit(struct b43legacy_wldev *dev) | |||
199 | return; | 156 | return; |
200 | rfk->registered = 0; | 157 | rfk->registered = 0; |
201 | 158 | ||
202 | input_unregister_polled_device(rfk->poll_dev); | ||
203 | rfkill_unregister(rfk->rfkill); | 159 | rfkill_unregister(rfk->rfkill); |
204 | input_free_polled_device(rfk->poll_dev); | 160 | rfkill_destroy(rfk->rfkill); |
205 | rfk->poll_dev = NULL; | ||
206 | rfk->rfkill = NULL; | 161 | rfk->rfkill = NULL; |
207 | } | 162 | } |
208 | 163 | ||