diff options
Diffstat (limited to 'drivers/platform/x86/hp-wmi.c')
-rw-r--r-- | drivers/platform/x86/hp-wmi.c | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index fe171fad12cf..16fffe44e333 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c | |||
@@ -154,58 +154,46 @@ static int hp_wmi_dock_state(void) | |||
154 | return hp_wmi_perform_query(HPWMI_DOCK_QUERY, 0, 0); | 154 | return hp_wmi_perform_query(HPWMI_DOCK_QUERY, 0, 0); |
155 | } | 155 | } |
156 | 156 | ||
157 | static int hp_wmi_wifi_set(void *data, enum rfkill_state state) | 157 | static int hp_wmi_set_block(void *data, bool blocked) |
158 | { | 158 | { |
159 | if (state) | 159 | unsigned long b = (unsigned long) data; |
160 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x101); | 160 | int query = BIT(b + 8) | ((!!blocked) << b); |
161 | else | ||
162 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x100); | ||
163 | } | ||
164 | 161 | ||
165 | static int hp_wmi_bluetooth_set(void *data, enum rfkill_state state) | 162 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query); |
166 | { | ||
167 | if (state) | ||
168 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x202); | ||
169 | else | ||
170 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x200); | ||
171 | } | 163 | } |
172 | 164 | ||
173 | static int hp_wmi_wwan_set(void *data, enum rfkill_state state) | 165 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
174 | { | 166 | .set_block = hp_wmi_set_block, |
175 | if (state) | 167 | }; |
176 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x404); | ||
177 | else | ||
178 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x400); | ||
179 | } | ||
180 | 168 | ||
181 | static int hp_wmi_wifi_state(void) | 169 | static bool hp_wmi_wifi_state(void) |
182 | { | 170 | { |
183 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); | 171 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
184 | 172 | ||
185 | if (wireless & 0x100) | 173 | if (wireless & 0x100) |
186 | return RFKILL_STATE_UNBLOCKED; | 174 | return false; |
187 | else | 175 | else |
188 | return RFKILL_STATE_SOFT_BLOCKED; | 176 | return true; |
189 | } | 177 | } |
190 | 178 | ||
191 | static int hp_wmi_bluetooth_state(void) | 179 | static bool hp_wmi_bluetooth_state(void) |
192 | { | 180 | { |
193 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); | 181 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
194 | 182 | ||
195 | if (wireless & 0x10000) | 183 | if (wireless & 0x10000) |
196 | return RFKILL_STATE_UNBLOCKED; | 184 | return false; |
197 | else | 185 | else |
198 | return RFKILL_STATE_SOFT_BLOCKED; | 186 | return true; |
199 | } | 187 | } |
200 | 188 | ||
201 | static int hp_wmi_wwan_state(void) | 189 | static bool hp_wmi_wwan_state(void) |
202 | { | 190 | { |
203 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); | 191 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
204 | 192 | ||
205 | if (wireless & 0x1000000) | 193 | if (wireless & 0x1000000) |
206 | return RFKILL_STATE_UNBLOCKED; | 194 | return false; |
207 | else | 195 | else |
208 | return RFKILL_STATE_SOFT_BLOCKED; | 196 | return true; |
209 | } | 197 | } |
210 | 198 | ||
211 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, | 199 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, |
@@ -347,14 +335,14 @@ static void hp_wmi_notify(u32 value, void *context) | |||
347 | } | 335 | } |
348 | } else if (eventcode == 0x5) { | 336 | } else if (eventcode == 0x5) { |
349 | if (wifi_rfkill) | 337 | if (wifi_rfkill) |
350 | rfkill_force_state(wifi_rfkill, | 338 | rfkill_set_sw_state(wifi_rfkill, |
351 | hp_wmi_wifi_state()); | 339 | hp_wmi_wifi_state()); |
352 | if (bluetooth_rfkill) | 340 | if (bluetooth_rfkill) |
353 | rfkill_force_state(bluetooth_rfkill, | 341 | rfkill_set_sw_state(bluetooth_rfkill, |
354 | hp_wmi_bluetooth_state()); | 342 | hp_wmi_bluetooth_state()); |
355 | if (wwan_rfkill) | 343 | if (wwan_rfkill) |
356 | rfkill_force_state(wwan_rfkill, | 344 | rfkill_set_sw_state(wwan_rfkill, |
357 | hp_wmi_wwan_state()); | 345 | hp_wmi_wwan_state()); |
358 | } else | 346 | } else |
359 | printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", | 347 | printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", |
360 | eventcode); | 348 | eventcode); |
@@ -430,31 +418,30 @@ static int __init hp_wmi_bios_setup(struct platform_device *device) | |||
430 | goto add_sysfs_error; | 418 | goto add_sysfs_error; |
431 | 419 | ||
432 | if (wireless & 0x1) { | 420 | if (wireless & 0x1) { |
433 | wifi_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WLAN); | 421 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
434 | wifi_rfkill->name = "hp-wifi"; | 422 | RFKILL_TYPE_WLAN, |
435 | wifi_rfkill->state = hp_wmi_wifi_state(); | 423 | &hp_wmi_rfkill_ops, |
436 | wifi_rfkill->toggle_radio = hp_wmi_wifi_set; | 424 | (void *) 0); |
437 | err = rfkill_register(wifi_rfkill); | 425 | err = rfkill_register(wifi_rfkill); |
438 | if (err) | 426 | if (err) |
439 | goto add_sysfs_error; | 427 | goto register_wifi_error; |
440 | } | 428 | } |
441 | 429 | ||
442 | if (wireless & 0x2) { | 430 | if (wireless & 0x2) { |
443 | bluetooth_rfkill = rfkill_allocate(&device->dev, | 431 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
444 | RFKILL_TYPE_BLUETOOTH); | 432 | RFKILL_TYPE_BLUETOOTH, |
445 | bluetooth_rfkill->name = "hp-bluetooth"; | 433 | &hp_wmi_rfkill_ops, |
446 | bluetooth_rfkill->state = hp_wmi_bluetooth_state(); | 434 | (void *) 1); |
447 | bluetooth_rfkill->toggle_radio = hp_wmi_bluetooth_set; | ||
448 | err = rfkill_register(bluetooth_rfkill); | 435 | err = rfkill_register(bluetooth_rfkill); |
449 | if (err) | 436 | if (err) |
450 | goto register_bluetooth_error; | 437 | goto register_bluetooth_error; |
451 | } | 438 | } |
452 | 439 | ||
453 | if (wireless & 0x4) { | 440 | if (wireless & 0x4) { |
454 | wwan_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WWAN); | 441 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
455 | wwan_rfkill->name = "hp-wwan"; | 442 | RFKILL_TYPE_WWAN, |
456 | wwan_rfkill->state = hp_wmi_wwan_state(); | 443 | &hp_wmi_rfkill_ops, |
457 | wwan_rfkill->toggle_radio = hp_wmi_wwan_set; | 444 | (void *) 2); |
458 | err = rfkill_register(wwan_rfkill); | 445 | err = rfkill_register(wwan_rfkill); |
459 | if (err) | 446 | if (err) |
460 | goto register_wwan_err; | 447 | goto register_wwan_err; |
@@ -462,11 +449,15 @@ static int __init hp_wmi_bios_setup(struct platform_device *device) | |||
462 | 449 | ||
463 | return 0; | 450 | return 0; |
464 | register_wwan_err: | 451 | register_wwan_err: |
452 | rfkill_destroy(wwan_rfkill); | ||
465 | if (bluetooth_rfkill) | 453 | if (bluetooth_rfkill) |
466 | rfkill_unregister(bluetooth_rfkill); | 454 | rfkill_unregister(bluetooth_rfkill); |
467 | register_bluetooth_error: | 455 | register_bluetooth_error: |
456 | rfkill_destroy(bluetooth_rfkill); | ||
468 | if (wifi_rfkill) | 457 | if (wifi_rfkill) |
469 | rfkill_unregister(wifi_rfkill); | 458 | rfkill_unregister(wifi_rfkill); |
459 | register_wifi_error: | ||
460 | rfkill_destroy(wifi_rfkill); | ||
470 | add_sysfs_error: | 461 | add_sysfs_error: |
471 | cleanup_sysfs(device); | 462 | cleanup_sysfs(device); |
472 | return err; | 463 | return err; |
@@ -476,12 +467,18 @@ static int __exit hp_wmi_bios_remove(struct platform_device *device) | |||
476 | { | 467 | { |
477 | cleanup_sysfs(device); | 468 | cleanup_sysfs(device); |
478 | 469 | ||
479 | if (wifi_rfkill) | 470 | if (wifi_rfkill) { |
480 | rfkill_unregister(wifi_rfkill); | 471 | rfkill_unregister(wifi_rfkill); |
481 | if (bluetooth_rfkill) | 472 | rfkill_destroy(wifi_rfkill); |
473 | } | ||
474 | if (bluetooth_rfkill) { | ||
482 | rfkill_unregister(bluetooth_rfkill); | 475 | rfkill_unregister(bluetooth_rfkill); |
483 | if (wwan_rfkill) | 476 | rfkill_destroy(wifi_rfkill); |
477 | } | ||
478 | if (wwan_rfkill) { | ||
484 | rfkill_unregister(wwan_rfkill); | 479 | rfkill_unregister(wwan_rfkill); |
480 | rfkill_destroy(wwan_rfkill); | ||
481 | } | ||
485 | 482 | ||
486 | return 0; | 483 | return 0; |
487 | } | 484 | } |