diff options
Diffstat (limited to 'drivers/platform/x86/hp-wmi.c')
-rw-r--r-- | drivers/platform/x86/hp-wmi.c | 102 |
1 files changed, 48 insertions, 54 deletions
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 46a7a6e8ed9..4ac2311c00a 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c | |||
@@ -168,58 +168,46 @@ static int hp_wmi_tablet_state(void) | |||
168 | return (ret & 0x4) ? 1 : 0; | 168 | return (ret & 0x4) ? 1 : 0; |
169 | } | 169 | } |
170 | 170 | ||
171 | static int hp_wmi_wifi_set(void *data, enum rfkill_state state) | 171 | static int hp_wmi_set_block(void *data, bool blocked) |
172 | { | 172 | { |
173 | if (state) | 173 | unsigned long b = (unsigned long) data; |
174 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x101); | 174 | int query = BIT(b + 8) | ((!!blocked) << b); |
175 | else | ||
176 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x100); | ||
177 | } | ||
178 | 175 | ||
179 | static int hp_wmi_bluetooth_set(void *data, enum rfkill_state state) | 176 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query); |
180 | { | ||
181 | if (state) | ||
182 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x202); | ||
183 | else | ||
184 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x200); | ||
185 | } | 177 | } |
186 | 178 | ||
187 | static int hp_wmi_wwan_set(void *data, enum rfkill_state state) | 179 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
188 | { | 180 | .set_block = hp_wmi_set_block, |
189 | if (state) | 181 | }; |
190 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x404); | ||
191 | else | ||
192 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x400); | ||
193 | } | ||
194 | 182 | ||
195 | static int hp_wmi_wifi_state(void) | 183 | static bool hp_wmi_wifi_state(void) |
196 | { | 184 | { |
197 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); | 185 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
198 | 186 | ||
199 | if (wireless & 0x100) | 187 | if (wireless & 0x100) |
200 | return RFKILL_STATE_UNBLOCKED; | 188 | return false; |
201 | else | 189 | else |
202 | return RFKILL_STATE_SOFT_BLOCKED; | 190 | return true; |
203 | } | 191 | } |
204 | 192 | ||
205 | static int hp_wmi_bluetooth_state(void) | 193 | static bool hp_wmi_bluetooth_state(void) |
206 | { | 194 | { |
207 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); | 195 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
208 | 196 | ||
209 | if (wireless & 0x10000) | 197 | if (wireless & 0x10000) |
210 | return RFKILL_STATE_UNBLOCKED; | 198 | return false; |
211 | else | 199 | else |
212 | return RFKILL_STATE_SOFT_BLOCKED; | 200 | return true; |
213 | } | 201 | } |
214 | 202 | ||
215 | static int hp_wmi_wwan_state(void) | 203 | static bool hp_wmi_wwan_state(void) |
216 | { | 204 | { |
217 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); | 205 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
218 | 206 | ||
219 | if (wireless & 0x1000000) | 207 | if (wireless & 0x1000000) |
220 | return RFKILL_STATE_UNBLOCKED; | 208 | return false; |
221 | else | 209 | else |
222 | return RFKILL_STATE_SOFT_BLOCKED; | 210 | return true; |
223 | } | 211 | } |
224 | 212 | ||
225 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, | 213 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, |
@@ -371,14 +359,14 @@ static void hp_wmi_notify(u32 value, void *context) | |||
371 | input_sync(hp_wmi_input_dev); | 359 | input_sync(hp_wmi_input_dev); |
372 | } else if (eventcode == 0x5) { | 360 | } else if (eventcode == 0x5) { |
373 | if (wifi_rfkill) | 361 | if (wifi_rfkill) |
374 | rfkill_force_state(wifi_rfkill, | 362 | rfkill_set_sw_state(wifi_rfkill, |
375 | hp_wmi_wifi_state()); | 363 | hp_wmi_wifi_state()); |
376 | if (bluetooth_rfkill) | 364 | if (bluetooth_rfkill) |
377 | rfkill_force_state(bluetooth_rfkill, | 365 | rfkill_set_sw_state(bluetooth_rfkill, |
378 | hp_wmi_bluetooth_state()); | 366 | hp_wmi_bluetooth_state()); |
379 | if (wwan_rfkill) | 367 | if (wwan_rfkill) |
380 | rfkill_force_state(wwan_rfkill, | 368 | rfkill_set_sw_state(wwan_rfkill, |
381 | hp_wmi_wwan_state()); | 369 | hp_wmi_wwan_state()); |
382 | } else | 370 | } else |
383 | printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", | 371 | printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", |
384 | eventcode); | 372 | eventcode); |
@@ -459,34 +447,30 @@ static int __init hp_wmi_bios_setup(struct platform_device *device) | |||
459 | goto add_sysfs_error; | 447 | goto add_sysfs_error; |
460 | 448 | ||
461 | if (wireless & 0x1) { | 449 | if (wireless & 0x1) { |
462 | wifi_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WLAN); | 450 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
463 | wifi_rfkill->name = "hp-wifi"; | 451 | RFKILL_TYPE_WLAN, |
464 | wifi_rfkill->state = hp_wmi_wifi_state(); | 452 | &hp_wmi_rfkill_ops, |
465 | wifi_rfkill->toggle_radio = hp_wmi_wifi_set; | 453 | (void *) 0); |
466 | wifi_rfkill->user_claim_unsupported = 1; | ||
467 | err = rfkill_register(wifi_rfkill); | 454 | err = rfkill_register(wifi_rfkill); |
468 | if (err) | 455 | if (err) |
469 | goto add_sysfs_error; | 456 | goto register_wifi_error; |
470 | } | 457 | } |
471 | 458 | ||
472 | if (wireless & 0x2) { | 459 | if (wireless & 0x2) { |
473 | bluetooth_rfkill = rfkill_allocate(&device->dev, | 460 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
474 | RFKILL_TYPE_BLUETOOTH); | 461 | RFKILL_TYPE_BLUETOOTH, |
475 | bluetooth_rfkill->name = "hp-bluetooth"; | 462 | &hp_wmi_rfkill_ops, |
476 | bluetooth_rfkill->state = hp_wmi_bluetooth_state(); | 463 | (void *) 1); |
477 | bluetooth_rfkill->toggle_radio = hp_wmi_bluetooth_set; | ||
478 | bluetooth_rfkill->user_claim_unsupported = 1; | ||
479 | err = rfkill_register(bluetooth_rfkill); | 464 | err = rfkill_register(bluetooth_rfkill); |
480 | if (err) | 465 | if (err) |
481 | goto register_bluetooth_error; | 466 | goto register_bluetooth_error; |
482 | } | 467 | } |
483 | 468 | ||
484 | if (wireless & 0x4) { | 469 | if (wireless & 0x4) { |
485 | wwan_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WWAN); | 470 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
486 | wwan_rfkill->name = "hp-wwan"; | 471 | RFKILL_TYPE_WWAN, |
487 | wwan_rfkill->state = hp_wmi_wwan_state(); | 472 | &hp_wmi_rfkill_ops, |
488 | wwan_rfkill->toggle_radio = hp_wmi_wwan_set; | 473 | (void *) 2); |
489 | wwan_rfkill->user_claim_unsupported = 1; | ||
490 | err = rfkill_register(wwan_rfkill); | 474 | err = rfkill_register(wwan_rfkill); |
491 | if (err) | 475 | if (err) |
492 | goto register_wwan_err; | 476 | goto register_wwan_err; |
@@ -494,11 +478,15 @@ static int __init hp_wmi_bios_setup(struct platform_device *device) | |||
494 | 478 | ||
495 | return 0; | 479 | return 0; |
496 | register_wwan_err: | 480 | register_wwan_err: |
481 | rfkill_destroy(wwan_rfkill); | ||
497 | if (bluetooth_rfkill) | 482 | if (bluetooth_rfkill) |
498 | rfkill_unregister(bluetooth_rfkill); | 483 | rfkill_unregister(bluetooth_rfkill); |
499 | register_bluetooth_error: | 484 | register_bluetooth_error: |
485 | rfkill_destroy(bluetooth_rfkill); | ||
500 | if (wifi_rfkill) | 486 | if (wifi_rfkill) |
501 | rfkill_unregister(wifi_rfkill); | 487 | rfkill_unregister(wifi_rfkill); |
488 | register_wifi_error: | ||
489 | rfkill_destroy(wifi_rfkill); | ||
502 | add_sysfs_error: | 490 | add_sysfs_error: |
503 | cleanup_sysfs(device); | 491 | cleanup_sysfs(device); |
504 | return err; | 492 | return err; |
@@ -508,12 +496,18 @@ static int __exit hp_wmi_bios_remove(struct platform_device *device) | |||
508 | { | 496 | { |
509 | cleanup_sysfs(device); | 497 | cleanup_sysfs(device); |
510 | 498 | ||
511 | if (wifi_rfkill) | 499 | if (wifi_rfkill) { |
512 | rfkill_unregister(wifi_rfkill); | 500 | rfkill_unregister(wifi_rfkill); |
513 | if (bluetooth_rfkill) | 501 | rfkill_destroy(wifi_rfkill); |
502 | } | ||
503 | if (bluetooth_rfkill) { | ||
514 | rfkill_unregister(bluetooth_rfkill); | 504 | rfkill_unregister(bluetooth_rfkill); |
515 | if (wwan_rfkill) | 505 | rfkill_destroy(wifi_rfkill); |
506 | } | ||
507 | if (wwan_rfkill) { | ||
516 | rfkill_unregister(wwan_rfkill); | 508 | rfkill_unregister(wwan_rfkill); |
509 | rfkill_destroy(wwan_rfkill); | ||
510 | } | ||
517 | 511 | ||
518 | return 0; | 512 | return 0; |
519 | } | 513 | } |