aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86/hp-wmi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/platform/x86/hp-wmi.c')
-rw-r--r--drivers/platform/x86/hp-wmi.c103
1 files changed, 52 insertions, 51 deletions
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index fe171fad12cf..8d931145cbfa 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
157static int hp_wmi_wifi_set(void *data, enum rfkill_state state) 157static 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
165static 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
173static int hp_wmi_wwan_set(void *data, enum rfkill_state state) 165static 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
181static int hp_wmi_wifi_state(void) 169static 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
191static int hp_wmi_bluetooth_state(void) 179static 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
201static int hp_wmi_wwan_state(void) 189static 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
211static ssize_t show_display(struct device *dev, struct device_attribute *attr, 199static 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,34 @@ 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);
425 rfkill_set_sw_state(wifi_rfkill, hp_wmi_wifi_state());
437 err = rfkill_register(wifi_rfkill); 426 err = rfkill_register(wifi_rfkill);
438 if (err) 427 if (err)
439 goto add_sysfs_error; 428 goto register_wifi_error;
440 } 429 }
441 430
442 if (wireless & 0x2) { 431 if (wireless & 0x2) {
443 bluetooth_rfkill = rfkill_allocate(&device->dev, 432 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
444 RFKILL_TYPE_BLUETOOTH); 433 RFKILL_TYPE_BLUETOOTH,
445 bluetooth_rfkill->name = "hp-bluetooth"; 434 &hp_wmi_rfkill_ops,
446 bluetooth_rfkill->state = hp_wmi_bluetooth_state(); 435 (void *) 1);
447 bluetooth_rfkill->toggle_radio = hp_wmi_bluetooth_set; 436 rfkill_set_sw_state(bluetooth_rfkill,
437 hp_wmi_bluetooth_state());
448 err = rfkill_register(bluetooth_rfkill); 438 err = rfkill_register(bluetooth_rfkill);
449 if (err) 439 if (err)
450 goto register_bluetooth_error; 440 goto register_bluetooth_error;
451 } 441 }
452 442
453 if (wireless & 0x4) { 443 if (wireless & 0x4) {
454 wwan_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WWAN); 444 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
455 wwan_rfkill->name = "hp-wwan"; 445 RFKILL_TYPE_WWAN,
456 wwan_rfkill->state = hp_wmi_wwan_state(); 446 &hp_wmi_rfkill_ops,
457 wwan_rfkill->toggle_radio = hp_wmi_wwan_set; 447 (void *) 2);
448 rfkill_set_sw_state(wwan_rfkill, hp_wmi_wwan_state());
458 err = rfkill_register(wwan_rfkill); 449 err = rfkill_register(wwan_rfkill);
459 if (err) 450 if (err)
460 goto register_wwan_err; 451 goto register_wwan_err;
@@ -462,11 +453,15 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
462 453
463 return 0; 454 return 0;
464register_wwan_err: 455register_wwan_err:
456 rfkill_destroy(wwan_rfkill);
465 if (bluetooth_rfkill) 457 if (bluetooth_rfkill)
466 rfkill_unregister(bluetooth_rfkill); 458 rfkill_unregister(bluetooth_rfkill);
467register_bluetooth_error: 459register_bluetooth_error:
460 rfkill_destroy(bluetooth_rfkill);
468 if (wifi_rfkill) 461 if (wifi_rfkill)
469 rfkill_unregister(wifi_rfkill); 462 rfkill_unregister(wifi_rfkill);
463register_wifi_error:
464 rfkill_destroy(wifi_rfkill);
470add_sysfs_error: 465add_sysfs_error:
471 cleanup_sysfs(device); 466 cleanup_sysfs(device);
472 return err; 467 return err;
@@ -476,12 +471,18 @@ static int __exit hp_wmi_bios_remove(struct platform_device *device)
476{ 471{
477 cleanup_sysfs(device); 472 cleanup_sysfs(device);
478 473
479 if (wifi_rfkill) 474 if (wifi_rfkill) {
480 rfkill_unregister(wifi_rfkill); 475 rfkill_unregister(wifi_rfkill);
481 if (bluetooth_rfkill) 476 rfkill_destroy(wifi_rfkill);
477 }
478 if (bluetooth_rfkill) {
482 rfkill_unregister(bluetooth_rfkill); 479 rfkill_unregister(bluetooth_rfkill);
483 if (wwan_rfkill) 480 rfkill_destroy(wifi_rfkill);
481 }
482 if (wwan_rfkill) {
484 rfkill_unregister(wwan_rfkill); 483 rfkill_unregister(wwan_rfkill);
484 rfkill_destroy(wwan_rfkill);
485 }
485 486
486 return 0; 487 return 0;
487} 488}