diff options
Diffstat (limited to 'drivers/platform/x86/hp-wmi.c')
-rw-r--r-- | drivers/platform/x86/hp-wmi.c | 312 |
1 files changed, 273 insertions, 39 deletions
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 9e05af9c41cb..1bc4a7539ba9 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * HP WMI hotkeys | 2 | * HP WMI hotkeys |
3 | * | 3 | * |
4 | * Copyright (C) 2008 Red Hat <mjg@redhat.com> | 4 | * Copyright (C) 2008 Red Hat <mjg@redhat.com> |
5 | * Copyright (C) 2010, 2011 Anssi Hannula <anssi.hannula@iki.fi> | ||
5 | * | 6 | * |
6 | * Portions based on wistron_btns.c: | 7 | * Portions based on wistron_btns.c: |
7 | * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> | 8 | * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> |
@@ -51,6 +52,7 @@ MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); | |||
51 | #define HPWMI_HARDWARE_QUERY 0x4 | 52 | #define HPWMI_HARDWARE_QUERY 0x4 |
52 | #define HPWMI_WIRELESS_QUERY 0x5 | 53 | #define HPWMI_WIRELESS_QUERY 0x5 |
53 | #define HPWMI_HOTKEY_QUERY 0xc | 54 | #define HPWMI_HOTKEY_QUERY 0xc |
55 | #define HPWMI_WIRELESS2_QUERY 0x1b | ||
54 | 56 | ||
55 | #define PREFIX "HP WMI: " | 57 | #define PREFIX "HP WMI: " |
56 | #define UNIMP "Unimplemented " | 58 | #define UNIMP "Unimplemented " |
@@ -86,7 +88,46 @@ struct bios_args { | |||
86 | struct bios_return { | 88 | struct bios_return { |
87 | u32 sigpass; | 89 | u32 sigpass; |
88 | u32 return_code; | 90 | u32 return_code; |
89 | u32 value; | 91 | }; |
92 | |||
93 | enum hp_return_value { | ||
94 | HPWMI_RET_WRONG_SIGNATURE = 0x02, | ||
95 | HPWMI_RET_UNKNOWN_COMMAND = 0x03, | ||
96 | HPWMI_RET_UNKNOWN_CMDTYPE = 0x04, | ||
97 | HPWMI_RET_INVALID_PARAMETERS = 0x05, | ||
98 | }; | ||
99 | |||
100 | enum hp_wireless2_bits { | ||
101 | HPWMI_POWER_STATE = 0x01, | ||
102 | HPWMI_POWER_SOFT = 0x02, | ||
103 | HPWMI_POWER_BIOS = 0x04, | ||
104 | HPWMI_POWER_HARD = 0x08, | ||
105 | }; | ||
106 | |||
107 | #define IS_HWBLOCKED(x) ((x & (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) \ | ||
108 | != (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) | ||
109 | #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT) | ||
110 | |||
111 | struct bios_rfkill2_device_state { | ||
112 | u8 radio_type; | ||
113 | u8 bus_type; | ||
114 | u16 vendor_id; | ||
115 | u16 product_id; | ||
116 | u16 subsys_vendor_id; | ||
117 | u16 subsys_product_id; | ||
118 | u8 rfkill_id; | ||
119 | u8 power; | ||
120 | u8 unknown[4]; | ||
121 | }; | ||
122 | |||
123 | /* 7 devices fit into the 128 byte buffer */ | ||
124 | #define HPWMI_MAX_RFKILL2_DEVICES 7 | ||
125 | |||
126 | struct bios_rfkill2_state { | ||
127 | u8 unknown[7]; | ||
128 | u8 count; | ||
129 | u8 pad[8]; | ||
130 | struct bios_rfkill2_device_state device[HPWMI_MAX_RFKILL2_DEVICES]; | ||
90 | }; | 131 | }; |
91 | 132 | ||
92 | static const struct key_entry hp_wmi_keymap[] = { | 133 | static const struct key_entry hp_wmi_keymap[] = { |
@@ -108,6 +149,15 @@ static struct rfkill *wifi_rfkill; | |||
108 | static struct rfkill *bluetooth_rfkill; | 149 | static struct rfkill *bluetooth_rfkill; |
109 | static struct rfkill *wwan_rfkill; | 150 | static struct rfkill *wwan_rfkill; |
110 | 151 | ||
152 | struct rfkill2_device { | ||
153 | u8 id; | ||
154 | int num; | ||
155 | struct rfkill *rfkill; | ||
156 | }; | ||
157 | |||
158 | static int rfkill2_count; | ||
159 | static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES]; | ||
160 | |||
111 | static const struct dev_pm_ops hp_wmi_pm_ops = { | 161 | static const struct dev_pm_ops hp_wmi_pm_ops = { |
112 | .resume = hp_wmi_resume_handler, | 162 | .resume = hp_wmi_resume_handler, |
113 | .restore = hp_wmi_resume_handler, | 163 | .restore = hp_wmi_resume_handler, |
@@ -129,7 +179,8 @@ static struct platform_driver hp_wmi_driver = { | |||
129 | * query: The commandtype -> What should be queried | 179 | * query: The commandtype -> What should be queried |
130 | * write: The command -> 0 read, 1 write, 3 ODM specific | 180 | * write: The command -> 0 read, 1 write, 3 ODM specific |
131 | * buffer: Buffer used as input and/or output | 181 | * buffer: Buffer used as input and/or output |
132 | * buffersize: Size of buffer | 182 | * insize: Size of input buffer |
183 | * outsize: Size of output buffer | ||
133 | * | 184 | * |
134 | * returns zero on success | 185 | * returns zero on success |
135 | * an HP WMI query specific error code (which is positive) | 186 | * an HP WMI query specific error code (which is positive) |
@@ -140,25 +191,29 @@ static struct platform_driver hp_wmi_driver = { | |||
140 | * size. E.g. Battery info query (0x7) is defined to have 1 byte input | 191 | * size. E.g. Battery info query (0x7) is defined to have 1 byte input |
141 | * and 128 byte output. The caller would do: | 192 | * and 128 byte output. The caller would do: |
142 | * buffer = kzalloc(128, GFP_KERNEL); | 193 | * buffer = kzalloc(128, GFP_KERNEL); |
143 | * ret = hp_wmi_perform_query(0x7, 0, buffer, 128) | 194 | * ret = hp_wmi_perform_query(0x7, 0, buffer, 1, 128) |
144 | */ | 195 | */ |
145 | static int hp_wmi_perform_query(int query, int write, u32 *buffer, | 196 | static int hp_wmi_perform_query(int query, int write, void *buffer, |
146 | int buffersize) | 197 | int insize, int outsize) |
147 | { | 198 | { |
148 | struct bios_return bios_return; | 199 | struct bios_return *bios_return; |
149 | acpi_status status; | 200 | int actual_outsize; |
150 | union acpi_object *obj; | 201 | union acpi_object *obj; |
151 | struct bios_args args = { | 202 | struct bios_args args = { |
152 | .signature = 0x55434553, | 203 | .signature = 0x55434553, |
153 | .command = write ? 0x2 : 0x1, | 204 | .command = write ? 0x2 : 0x1, |
154 | .commandtype = query, | 205 | .commandtype = query, |
155 | .datasize = buffersize, | 206 | .datasize = insize, |
156 | .data = *buffer, | 207 | .data = 0, |
157 | }; | 208 | }; |
158 | struct acpi_buffer input = { sizeof(struct bios_args), &args }; | 209 | struct acpi_buffer input = { sizeof(struct bios_args), &args }; |
159 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; | 210 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
160 | 211 | ||
161 | status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output); | 212 | if (WARN_ON(insize > sizeof(args.data))) |
213 | return -EINVAL; | ||
214 | memcpy(&args.data, buffer, insize); | ||
215 | |||
216 | wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output); | ||
162 | 217 | ||
163 | obj = output.pointer; | 218 | obj = output.pointer; |
164 | 219 | ||
@@ -169,10 +224,26 @@ static int hp_wmi_perform_query(int query, int write, u32 *buffer, | |||
169 | return -EINVAL; | 224 | return -EINVAL; |
170 | } | 225 | } |
171 | 226 | ||
172 | bios_return = *((struct bios_return *)obj->buffer.pointer); | 227 | bios_return = (struct bios_return *)obj->buffer.pointer; |
173 | 228 | ||
174 | memcpy(buffer, &bios_return.value, sizeof(bios_return.value)); | 229 | if (bios_return->return_code) { |
230 | if (bios_return->return_code != HPWMI_RET_UNKNOWN_CMDTYPE) | ||
231 | printk(KERN_WARNING PREFIX "query 0x%x returned " | ||
232 | "error 0x%x\n", | ||
233 | query, bios_return->return_code); | ||
234 | kfree(obj); | ||
235 | return bios_return->return_code; | ||
236 | } | ||
237 | |||
238 | if (!outsize) { | ||
239 | /* ignore output data */ | ||
240 | kfree(obj); | ||
241 | return 0; | ||
242 | } | ||
175 | 243 | ||
244 | actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return))); | ||
245 | memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize); | ||
246 | memset(buffer + actual_outsize, 0, outsize - actual_outsize); | ||
176 | kfree(obj); | 247 | kfree(obj); |
177 | return 0; | 248 | return 0; |
178 | } | 249 | } |
@@ -181,7 +252,7 @@ static int hp_wmi_display_state(void) | |||
181 | { | 252 | { |
182 | int state = 0; | 253 | int state = 0; |
183 | int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state, | 254 | int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state, |
184 | sizeof(state)); | 255 | sizeof(state), sizeof(state)); |
185 | if (ret) | 256 | if (ret) |
186 | return -EINVAL; | 257 | return -EINVAL; |
187 | return state; | 258 | return state; |
@@ -191,7 +262,7 @@ static int hp_wmi_hddtemp_state(void) | |||
191 | { | 262 | { |
192 | int state = 0; | 263 | int state = 0; |
193 | int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state, | 264 | int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state, |
194 | sizeof(state)); | 265 | sizeof(state), sizeof(state)); |
195 | if (ret) | 266 | if (ret) |
196 | return -EINVAL; | 267 | return -EINVAL; |
197 | return state; | 268 | return state; |
@@ -201,7 +272,7 @@ static int hp_wmi_als_state(void) | |||
201 | { | 272 | { |
202 | int state = 0; | 273 | int state = 0; |
203 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state, | 274 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state, |
204 | sizeof(state)); | 275 | sizeof(state), sizeof(state)); |
205 | if (ret) | 276 | if (ret) |
206 | return -EINVAL; | 277 | return -EINVAL; |
207 | return state; | 278 | return state; |
@@ -211,7 +282,7 @@ static int hp_wmi_dock_state(void) | |||
211 | { | 282 | { |
212 | int state = 0; | 283 | int state = 0; |
213 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, | 284 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, |
214 | sizeof(state)); | 285 | sizeof(state), sizeof(state)); |
215 | 286 | ||
216 | if (ret) | 287 | if (ret) |
217 | return -EINVAL; | 288 | return -EINVAL; |
@@ -223,7 +294,7 @@ static int hp_wmi_tablet_state(void) | |||
223 | { | 294 | { |
224 | int state = 0; | 295 | int state = 0; |
225 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, | 296 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, |
226 | sizeof(state)); | 297 | sizeof(state), sizeof(state)); |
227 | if (ret) | 298 | if (ret) |
228 | return ret; | 299 | return ret; |
229 | 300 | ||
@@ -237,7 +308,7 @@ static int hp_wmi_set_block(void *data, bool blocked) | |||
237 | int ret; | 308 | int ret; |
238 | 309 | ||
239 | ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, | 310 | ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, |
240 | &query, sizeof(query)); | 311 | &query, sizeof(query), 0); |
241 | if (ret) | 312 | if (ret) |
242 | return -EINVAL; | 313 | return -EINVAL; |
243 | return 0; | 314 | return 0; |
@@ -252,7 +323,8 @@ static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) | |||
252 | int wireless = 0; | 323 | int wireless = 0; |
253 | int mask; | 324 | int mask; |
254 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, | 325 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, |
255 | &wireless, sizeof(wireless)); | 326 | &wireless, sizeof(wireless), |
327 | sizeof(wireless)); | ||
256 | /* TBD: Pass error */ | 328 | /* TBD: Pass error */ |
257 | 329 | ||
258 | mask = 0x200 << (r * 8); | 330 | mask = 0x200 << (r * 8); |
@@ -268,7 +340,8 @@ static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) | |||
268 | int wireless = 0; | 340 | int wireless = 0; |
269 | int mask; | 341 | int mask; |
270 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, | 342 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, |
271 | &wireless, sizeof(wireless)); | 343 | &wireless, sizeof(wireless), |
344 | sizeof(wireless)); | ||
272 | /* TBD: Pass error */ | 345 | /* TBD: Pass error */ |
273 | 346 | ||
274 | mask = 0x800 << (r * 8); | 347 | mask = 0x800 << (r * 8); |
@@ -279,6 +352,51 @@ static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) | |||
279 | return true; | 352 | return true; |
280 | } | 353 | } |
281 | 354 | ||
355 | static int hp_wmi_rfkill2_set_block(void *data, bool blocked) | ||
356 | { | ||
357 | int rfkill_id = (int)(long)data; | ||
358 | char buffer[4] = { 0x01, 0x00, rfkill_id, !blocked }; | ||
359 | |||
360 | if (hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 1, | ||
361 | buffer, sizeof(buffer), 0)) | ||
362 | return -EINVAL; | ||
363 | return 0; | ||
364 | } | ||
365 | |||
366 | static const struct rfkill_ops hp_wmi_rfkill2_ops = { | ||
367 | .set_block = hp_wmi_rfkill2_set_block, | ||
368 | }; | ||
369 | |||
370 | static int hp_wmi_rfkill2_refresh(void) | ||
371 | { | ||
372 | int err, i; | ||
373 | struct bios_rfkill2_state state; | ||
374 | |||
375 | err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 0, &state, | ||
376 | 0, sizeof(state)); | ||
377 | if (err) | ||
378 | return err; | ||
379 | |||
380 | for (i = 0; i < rfkill2_count; i++) { | ||
381 | int num = rfkill2[i].num; | ||
382 | struct bios_rfkill2_device_state *devstate; | ||
383 | devstate = &state.device[num]; | ||
384 | |||
385 | if (num >= state.count || | ||
386 | devstate->rfkill_id != rfkill2[i].id) { | ||
387 | printk(KERN_WARNING PREFIX "power configuration of " | ||
388 | "the wireless devices unexpectedly changed\n"); | ||
389 | continue; | ||
390 | } | ||
391 | |||
392 | rfkill_set_states(rfkill2[i].rfkill, | ||
393 | IS_SWBLOCKED(devstate->power), | ||
394 | IS_HWBLOCKED(devstate->power)); | ||
395 | } | ||
396 | |||
397 | return 0; | ||
398 | } | ||
399 | |||
282 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, | 400 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, |
283 | char *buf) | 401 | char *buf) |
284 | { | 402 | { |
@@ -329,7 +447,7 @@ static ssize_t set_als(struct device *dev, struct device_attribute *attr, | |||
329 | { | 447 | { |
330 | u32 tmp = simple_strtoul(buf, NULL, 10); | 448 | u32 tmp = simple_strtoul(buf, NULL, 10); |
331 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, &tmp, | 449 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, &tmp, |
332 | sizeof(tmp)); | 450 | sizeof(tmp), sizeof(tmp)); |
333 | if (ret) | 451 | if (ret) |
334 | return -EINVAL; | 452 | return -EINVAL; |
335 | 453 | ||
@@ -402,6 +520,7 @@ static void hp_wmi_notify(u32 value, void *context) | |||
402 | case HPWMI_BEZEL_BUTTON: | 520 | case HPWMI_BEZEL_BUTTON: |
403 | ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, | 521 | ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, |
404 | &key_code, | 522 | &key_code, |
523 | sizeof(key_code), | ||
405 | sizeof(key_code)); | 524 | sizeof(key_code)); |
406 | if (ret) | 525 | if (ret) |
407 | break; | 526 | break; |
@@ -412,6 +531,11 @@ static void hp_wmi_notify(u32 value, void *context) | |||
412 | key_code); | 531 | key_code); |
413 | break; | 532 | break; |
414 | case HPWMI_WIRELESS: | 533 | case HPWMI_WIRELESS: |
534 | if (rfkill2_count) { | ||
535 | hp_wmi_rfkill2_refresh(); | ||
536 | break; | ||
537 | } | ||
538 | |||
415 | if (wifi_rfkill) | 539 | if (wifi_rfkill) |
416 | rfkill_set_states(wifi_rfkill, | 540 | rfkill_set_states(wifi_rfkill, |
417 | hp_wmi_get_sw_state(HPWMI_WIFI), | 541 | hp_wmi_get_sw_state(HPWMI_WIFI), |
@@ -502,32 +626,16 @@ static void cleanup_sysfs(struct platform_device *device) | |||
502 | device_remove_file(&device->dev, &dev_attr_tablet); | 626 | device_remove_file(&device->dev, &dev_attr_tablet); |
503 | } | 627 | } |
504 | 628 | ||
505 | static int __devinit hp_wmi_bios_setup(struct platform_device *device) | 629 | static int __devinit hp_wmi_rfkill_setup(struct platform_device *device) |
506 | { | 630 | { |
507 | int err; | 631 | int err; |
508 | int wireless = 0; | 632 | int wireless = 0; |
509 | 633 | ||
510 | err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, &wireless, | 634 | err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, &wireless, |
511 | sizeof(wireless)); | 635 | sizeof(wireless), sizeof(wireless)); |
512 | if (err) | 636 | if (err) |
513 | return err; | 637 | return err; |
514 | 638 | ||
515 | err = device_create_file(&device->dev, &dev_attr_display); | ||
516 | if (err) | ||
517 | goto add_sysfs_error; | ||
518 | err = device_create_file(&device->dev, &dev_attr_hddtemp); | ||
519 | if (err) | ||
520 | goto add_sysfs_error; | ||
521 | err = device_create_file(&device->dev, &dev_attr_als); | ||
522 | if (err) | ||
523 | goto add_sysfs_error; | ||
524 | err = device_create_file(&device->dev, &dev_attr_dock); | ||
525 | if (err) | ||
526 | goto add_sysfs_error; | ||
527 | err = device_create_file(&device->dev, &dev_attr_tablet); | ||
528 | if (err) | ||
529 | goto add_sysfs_error; | ||
530 | |||
531 | if (wireless & 0x1) { | 639 | if (wireless & 0x1) { |
532 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, | 640 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
533 | RFKILL_TYPE_WLAN, | 641 | RFKILL_TYPE_WLAN, |
@@ -573,14 +681,131 @@ static int __devinit hp_wmi_bios_setup(struct platform_device *device) | |||
573 | return 0; | 681 | return 0; |
574 | register_wwan_err: | 682 | register_wwan_err: |
575 | rfkill_destroy(wwan_rfkill); | 683 | rfkill_destroy(wwan_rfkill); |
684 | wwan_rfkill = NULL; | ||
576 | if (bluetooth_rfkill) | 685 | if (bluetooth_rfkill) |
577 | rfkill_unregister(bluetooth_rfkill); | 686 | rfkill_unregister(bluetooth_rfkill); |
578 | register_bluetooth_error: | 687 | register_bluetooth_error: |
579 | rfkill_destroy(bluetooth_rfkill); | 688 | rfkill_destroy(bluetooth_rfkill); |
689 | bluetooth_rfkill = NULL; | ||
580 | if (wifi_rfkill) | 690 | if (wifi_rfkill) |
581 | rfkill_unregister(wifi_rfkill); | 691 | rfkill_unregister(wifi_rfkill); |
582 | register_wifi_error: | 692 | register_wifi_error: |
583 | rfkill_destroy(wifi_rfkill); | 693 | rfkill_destroy(wifi_rfkill); |
694 | wifi_rfkill = NULL; | ||
695 | return err; | ||
696 | } | ||
697 | |||
698 | static int __devinit hp_wmi_rfkill2_setup(struct platform_device *device) | ||
699 | { | ||
700 | int err, i; | ||
701 | struct bios_rfkill2_state state; | ||
702 | err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 0, &state, | ||
703 | 0, sizeof(state)); | ||
704 | if (err) | ||
705 | return err; | ||
706 | |||
707 | if (state.count > HPWMI_MAX_RFKILL2_DEVICES) { | ||
708 | printk(KERN_WARNING PREFIX "unable to parse 0x1b query output\n"); | ||
709 | return -EINVAL; | ||
710 | } | ||
711 | |||
712 | for (i = 0; i < state.count; i++) { | ||
713 | struct rfkill *rfkill; | ||
714 | enum rfkill_type type; | ||
715 | char *name; | ||
716 | switch (state.device[i].radio_type) { | ||
717 | case HPWMI_WIFI: | ||
718 | type = RFKILL_TYPE_WLAN; | ||
719 | name = "hp-wifi"; | ||
720 | break; | ||
721 | case HPWMI_BLUETOOTH: | ||
722 | type = RFKILL_TYPE_BLUETOOTH; | ||
723 | name = "hp-bluetooth"; | ||
724 | break; | ||
725 | case HPWMI_WWAN: | ||
726 | type = RFKILL_TYPE_WWAN; | ||
727 | name = "hp-wwan"; | ||
728 | break; | ||
729 | default: | ||
730 | printk(KERN_WARNING PREFIX "unknown device type 0x%x\n", | ||
731 | state.device[i].radio_type); | ||
732 | continue; | ||
733 | } | ||
734 | |||
735 | if (!state.device[i].vendor_id) { | ||
736 | printk(KERN_WARNING PREFIX "zero device %d while %d " | ||
737 | "reported\n", i, state.count); | ||
738 | continue; | ||
739 | } | ||
740 | |||
741 | rfkill = rfkill_alloc(name, &device->dev, type, | ||
742 | &hp_wmi_rfkill2_ops, (void *)(long)i); | ||
743 | if (!rfkill) { | ||
744 | err = -ENOMEM; | ||
745 | goto fail; | ||
746 | } | ||
747 | |||
748 | rfkill2[rfkill2_count].id = state.device[i].rfkill_id; | ||
749 | rfkill2[rfkill2_count].num = i; | ||
750 | rfkill2[rfkill2_count].rfkill = rfkill; | ||
751 | |||
752 | rfkill_init_sw_state(rfkill, | ||
753 | IS_SWBLOCKED(state.device[i].power)); | ||
754 | rfkill_set_hw_state(rfkill, | ||
755 | IS_HWBLOCKED(state.device[i].power)); | ||
756 | |||
757 | if (!(state.device[i].power & HPWMI_POWER_BIOS)) | ||
758 | printk(KERN_INFO PREFIX "device %s blocked by BIOS\n", | ||
759 | name); | ||
760 | |||
761 | err = rfkill_register(rfkill); | ||
762 | if (err) { | ||
763 | rfkill_destroy(rfkill); | ||
764 | goto fail; | ||
765 | } | ||
766 | |||
767 | rfkill2_count++; | ||
768 | } | ||
769 | |||
770 | return 0; | ||
771 | fail: | ||
772 | for (; rfkill2_count > 0; rfkill2_count--) { | ||
773 | rfkill_unregister(rfkill2[rfkill2_count - 1].rfkill); | ||
774 | rfkill_destroy(rfkill2[rfkill2_count - 1].rfkill); | ||
775 | } | ||
776 | return err; | ||
777 | } | ||
778 | |||
779 | static int __devinit hp_wmi_bios_setup(struct platform_device *device) | ||
780 | { | ||
781 | int err; | ||
782 | |||
783 | /* clear detected rfkill devices */ | ||
784 | wifi_rfkill = NULL; | ||
785 | bluetooth_rfkill = NULL; | ||
786 | wwan_rfkill = NULL; | ||
787 | rfkill2_count = 0; | ||
788 | |||
789 | if (hp_wmi_rfkill_setup(device)) | ||
790 | hp_wmi_rfkill2_setup(device); | ||
791 | |||
792 | err = device_create_file(&device->dev, &dev_attr_display); | ||
793 | if (err) | ||
794 | goto add_sysfs_error; | ||
795 | err = device_create_file(&device->dev, &dev_attr_hddtemp); | ||
796 | if (err) | ||
797 | goto add_sysfs_error; | ||
798 | err = device_create_file(&device->dev, &dev_attr_als); | ||
799 | if (err) | ||
800 | goto add_sysfs_error; | ||
801 | err = device_create_file(&device->dev, &dev_attr_dock); | ||
802 | if (err) | ||
803 | goto add_sysfs_error; | ||
804 | err = device_create_file(&device->dev, &dev_attr_tablet); | ||
805 | if (err) | ||
806 | goto add_sysfs_error; | ||
807 | return 0; | ||
808 | |||
584 | add_sysfs_error: | 809 | add_sysfs_error: |
585 | cleanup_sysfs(device); | 810 | cleanup_sysfs(device); |
586 | return err; | 811 | return err; |
@@ -588,8 +813,14 @@ add_sysfs_error: | |||
588 | 813 | ||
589 | static int __exit hp_wmi_bios_remove(struct platform_device *device) | 814 | static int __exit hp_wmi_bios_remove(struct platform_device *device) |
590 | { | 815 | { |
816 | int i; | ||
591 | cleanup_sysfs(device); | 817 | cleanup_sysfs(device); |
592 | 818 | ||
819 | for (i = 0; i < rfkill2_count; i++) { | ||
820 | rfkill_unregister(rfkill2[i].rfkill); | ||
821 | rfkill_destroy(rfkill2[i].rfkill); | ||
822 | } | ||
823 | |||
593 | if (wifi_rfkill) { | 824 | if (wifi_rfkill) { |
594 | rfkill_unregister(wifi_rfkill); | 825 | rfkill_unregister(wifi_rfkill); |
595 | rfkill_destroy(wifi_rfkill); | 826 | rfkill_destroy(wifi_rfkill); |
@@ -622,6 +853,9 @@ static int hp_wmi_resume_handler(struct device *device) | |||
622 | input_sync(hp_wmi_input_dev); | 853 | input_sync(hp_wmi_input_dev); |
623 | } | 854 | } |
624 | 855 | ||
856 | if (rfkill2_count) | ||
857 | hp_wmi_rfkill2_refresh(); | ||
858 | |||
625 | if (wifi_rfkill) | 859 | if (wifi_rfkill) |
626 | rfkill_set_states(wifi_rfkill, | 860 | rfkill_set_states(wifi_rfkill, |
627 | hp_wmi_get_sw_state(HPWMI_WIFI), | 861 | hp_wmi_get_sw_state(HPWMI_WIFI), |