aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86/eeepc-laptop.c
diff options
context:
space:
mode:
authorAlan Jenkins <alan-jenkins@tuffmail.co.uk>2009-12-03 02:45:09 -0500
committerLen Brown <len.brown@intel.com>2009-12-09 15:54:32 -0500
commit854c78363f37f03e30e2856ef17d7eefc62e0d06 (patch)
tree897125099c071c0afa2b7cfb799790c0a8a8bbd8 /drivers/platform/x86/eeepc-laptop.c
parenta7624b63fdf50d7f460170891a49397280f08758 (diff)
eeepc-laptop: callbacks should use "driver data" parameter or field
Callback methods should not refer to a variable like "eeepc" (formally "ehotk"). Instead, they should extract the data they need either from a "driver data" parameter, or the "driver data" field of the object which they operate on. The "eeepc" variable can then be removed. In practice, drivers under "drivers/platform" can get away without using driver data, because it doesn't make sense to have more than one instance of them. However this makes it harder to review them for correctness. This is especially true for core ACPI developers who have not previously been exposed to this anti-pattern :-). This will serve as an example of best practice for new driver writers (whether they find it themselves, or have it pointed out during review :-). The hwmon sub-device is a special case. It uses ec_{read,write} which are defined to communicate with the (first) EC, so it does not require any driver data. It should still only be instantiated in the context of an ASUS010 device because we don't have a safe way to probe for it. Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk> CC: Bjorn Helgaas <bjorn.helgaas@hp.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/platform/x86/eeepc-laptop.c')
-rw-r--r--drivers/platform/x86/eeepc-laptop.c466
1 files changed, 268 insertions, 198 deletions
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index b9b5aebbd5b0..935ec4404f08 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -128,7 +128,7 @@ struct key_entry {
128 128
129enum { KE_KEY, KE_END }; 129enum { KE_KEY, KE_END };
130 130
131static struct key_entry eeepc_keymap[] = { 131static const struct key_entry eeepc_keymap[] = {
132 /* Sleep already handled via generic ACPI code */ 132 /* Sleep already handled via generic ACPI code */
133 {KE_KEY, 0x10, KEY_WLAN }, 133 {KE_KEY, 0x10, KEY_WLAN },
134 {KE_KEY, 0x11, KEY_WLAN }, 134 {KE_KEY, 0x11, KEY_WLAN },
@@ -153,33 +153,31 @@ static struct key_entry eeepc_keymap[] = {
153 * This is the main structure, we can use it to store useful information 153 * This is the main structure, we can use it to store useful information
154 */ 154 */
155struct eeepc_laptop { 155struct eeepc_laptop {
156 struct acpi_device *device; /* the device we are in */ 156 acpi_handle handle; /* the handle of the acpi device */
157 acpi_handle handle; /* the handle of the hotk device */
158 u32 cm_supported; /* the control methods supported 157 u32 cm_supported; /* the control methods supported
159 by this BIOS */ 158 by this BIOS */
160 u16 event_count[128]; /* count for each event */ 159 u16 event_count[128]; /* count for each event */
160
161 struct platform_device *platform_device;
162 struct device *hwmon_device;
163 struct backlight_device *backlight_device;
164
161 struct input_dev *inputdev; 165 struct input_dev *inputdev;
162 u16 *keycode_map; 166 struct key_entry *keymap;
167
163 struct rfkill *wlan_rfkill; 168 struct rfkill *wlan_rfkill;
164 struct rfkill *bluetooth_rfkill; 169 struct rfkill *bluetooth_rfkill;
165 struct rfkill *wwan3g_rfkill; 170 struct rfkill *wwan3g_rfkill;
166 struct rfkill *wimax_rfkill; 171 struct rfkill *wimax_rfkill;
172
167 struct hotplug_slot *hotplug_slot; 173 struct hotplug_slot *hotplug_slot;
168 struct mutex hotplug_lock; 174 struct mutex hotplug_lock;
169};
170
171/* The actual device the driver binds to */
172static struct eeepc_laptop *eeepc;
173
174/* The platform device */
175static struct platform_device *platform_device;
176
177/* The backlight device /sys/class/backlight */
178static struct backlight_device *eeepc_backlight_device;
179
180/* The hwmon device */
181static struct device *eeepc_hwmon_device;
182 175
176 struct led_classdev tpd_led;
177 int tpd_led_wk;
178 struct workqueue_struct *led_workqueue;
179 struct work_struct tpd_led_work;
180};
183 181
184/* 182/*
185 * ACPI Helpers 183 * ACPI Helpers
@@ -214,7 +212,7 @@ static int read_acpi_int(acpi_handle handle, const char *method, int *val)
214 } 212 }
215} 213}
216 214
217static int set_acpi(int cm, int value) 215static int set_acpi(struct eeepc_laptop *eeepc, int cm, int value)
218{ 216{
219 const char *method = cm_setv[cm]; 217 const char *method = cm_setv[cm];
220 218
@@ -228,7 +226,7 @@ static int set_acpi(int cm, int value)
228 return 0; 226 return 0;
229} 227}
230 228
231static int get_acpi(int cm) 229static int get_acpi(struct eeepc_laptop *eeepc, int cm)
232{ 230{
233 const char *method = cm_getv[cm]; 231 const char *method = cm_getv[cm];
234 int value; 232 int value;
@@ -243,6 +241,26 @@ static int get_acpi(int cm)
243 return value; 241 return value;
244} 242}
245 243
244static int acpi_setter_handle(struct eeepc_laptop *eeepc, int cm, acpi_handle *handle)
245{
246 const char *method = cm_setv[cm];
247 acpi_status status;
248
249 if (method == NULL)
250 return -ENODEV;
251 if ((eeepc->cm_supported & (0x1 << cm)) == 0)
252 return -ENODEV;
253
254 status = acpi_get_handle(eeepc->handle, (char *)method,
255 handle);
256 if (status != AE_OK) {
257 pr_warning("Error finding %s\n", method);
258 return -ENODEV;
259 }
260 return 0;
261}
262
263
246/* 264/*
247 * Sys helpers 265 * Sys helpers
248 */ 266 */
@@ -255,21 +273,24 @@ static int parse_arg(const char *buf, unsigned long count, int *val)
255 return count; 273 return count;
256} 274}
257 275
258static ssize_t store_sys_acpi(int cm, const char *buf, size_t count) 276static ssize_t store_sys_acpi(struct device *dev, int cm,
277 const char *buf, size_t count)
259{ 278{
279 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
260 int rv, value; 280 int rv, value;
261 281
262 rv = parse_arg(buf, count, &value); 282 rv = parse_arg(buf, count, &value);
263 if (rv > 0) 283 if (rv > 0)
264 value = set_acpi(cm, value); 284 value = set_acpi(eeepc, cm, value);
265 if (value < 0) 285 if (value < 0)
266 return -EIO; 286 return -EIO;
267 return rv; 287 return rv;
268} 288}
269 289
270static ssize_t show_sys_acpi(int cm, char *buf) 290static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
271{ 291{
272 int value = get_acpi(cm); 292 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
293 int value = get_acpi(eeepc, cm);
273 294
274 if (value < 0) 295 if (value < 0)
275 return -EIO; 296 return -EIO;
@@ -281,13 +302,13 @@ static ssize_t show_sys_acpi(int cm, char *buf)
281 struct device_attribute *attr, \ 302 struct device_attribute *attr, \
282 char *buf) \ 303 char *buf) \
283 { \ 304 { \
284 return show_sys_acpi(_cm, buf); \ 305 return show_sys_acpi(dev, _cm, buf); \
285 } \ 306 } \
286 static ssize_t store_##_name(struct device *dev, \ 307 static ssize_t store_##_name(struct device *dev, \
287 struct device_attribute *attr, \ 308 struct device_attribute *attr, \
288 const char *buf, size_t count) \ 309 const char *buf, size_t count) \
289 { \ 310 { \
290 return store_sys_acpi(_cm, buf, count); \ 311 return store_sys_acpi(dev, _cm, buf, count); \
291 } \ 312 } \
292 static struct device_attribute dev_attr_##_name = { \ 313 static struct device_attribute dev_attr_##_name = { \
293 .attr = { \ 314 .attr = { \
@@ -306,9 +327,9 @@ struct eeepc_cpufv {
306 int cur; 327 int cur;
307}; 328};
308 329
309static int get_cpufv(struct eeepc_cpufv *c) 330static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c)
310{ 331{
311 c->cur = get_acpi(CM_ASL_CPUFV); 332 c->cur = get_acpi(eeepc, CM_ASL_CPUFV);
312 c->num = (c->cur >> 8) & 0xff; 333 c->num = (c->cur >> 8) & 0xff;
313 c->cur &= 0xff; 334 c->cur &= 0xff;
314 if (c->cur < 0 || c->num <= 0 || c->num > 12) 335 if (c->cur < 0 || c->num <= 0 || c->num > 12)
@@ -320,11 +341,12 @@ static ssize_t show_available_cpufv(struct device *dev,
320 struct device_attribute *attr, 341 struct device_attribute *attr,
321 char *buf) 342 char *buf)
322{ 343{
344 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
323 struct eeepc_cpufv c; 345 struct eeepc_cpufv c;
324 int i; 346 int i;
325 ssize_t len = 0; 347 ssize_t len = 0;
326 348
327 if (get_cpufv(&c)) 349 if (get_cpufv(eeepc, &c))
328 return -ENODEV; 350 return -ENODEV;
329 for (i = 0; i < c.num; i++) 351 for (i = 0; i < c.num; i++)
330 len += sprintf(buf + len, "%d ", i); 352 len += sprintf(buf + len, "%d ", i);
@@ -336,9 +358,10 @@ static ssize_t show_cpufv(struct device *dev,
336 struct device_attribute *attr, 358 struct device_attribute *attr,
337 char *buf) 359 char *buf)
338{ 360{
361 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
339 struct eeepc_cpufv c; 362 struct eeepc_cpufv c;
340 363
341 if (get_cpufv(&c)) 364 if (get_cpufv(eeepc, &c))
342 return -ENODEV; 365 return -ENODEV;
343 return sprintf(buf, "%#x\n", (c.num << 8) | c.cur); 366 return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
344} 367}
@@ -347,17 +370,18 @@ static ssize_t store_cpufv(struct device *dev,
347 struct device_attribute *attr, 370 struct device_attribute *attr,
348 const char *buf, size_t count) 371 const char *buf, size_t count)
349{ 372{
373 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
350 struct eeepc_cpufv c; 374 struct eeepc_cpufv c;
351 int rv, value; 375 int rv, value;
352 376
353 if (get_cpufv(&c)) 377 if (get_cpufv(eeepc, &c))
354 return -ENODEV; 378 return -ENODEV;
355 rv = parse_arg(buf, count, &value); 379 rv = parse_arg(buf, count, &value);
356 if (rv < 0) 380 if (rv < 0)
357 return rv; 381 return rv;
358 if (!rv || value < 0 || value >= c.num) 382 if (!rv || value < 0 || value >= c.num)
359 return -EINVAL; 383 return -EINVAL;
360 set_acpi(CM_ASL_CPUFV, value); 384 set_acpi(eeepc, CM_ASL_CPUFV, value);
361 return rv; 385 return rv;
362} 386}
363 387
@@ -389,36 +413,37 @@ static struct attribute_group platform_attribute_group = {
389 .attrs = platform_attributes 413 .attrs = platform_attributes
390}; 414};
391 415
392static int eeepc_platform_init(void) 416static int eeepc_platform_init(struct eeepc_laptop *eeepc)
393{ 417{
394 int result; 418 int result;
395 419
396 platform_device = platform_device_alloc(EEEPC_LAPTOP_FILE, -1); 420 eeepc->platform_device = platform_device_alloc(EEEPC_LAPTOP_FILE, -1);
397 if (!platform_device) 421 if (!eeepc->platform_device)
398 return -ENOMEM; 422 return -ENOMEM;
423 platform_set_drvdata(eeepc->platform_device, eeepc);
399 424
400 result = platform_device_add(platform_device); 425 result = platform_device_add(eeepc->platform_device);
401 if (result) 426 if (result)
402 goto fail_platform_device; 427 goto fail_platform_device;
403 428
404 result = sysfs_create_group(&platform_device->dev.kobj, 429 result = sysfs_create_group(&eeepc->platform_device->dev.kobj,
405 &platform_attribute_group); 430 &platform_attribute_group);
406 if (result) 431 if (result)
407 goto fail_sysfs; 432 goto fail_sysfs;
408 return 0; 433 return 0;
409 434
410fail_sysfs: 435fail_sysfs:
411 platform_device_del(platform_device); 436 platform_device_del(eeepc->platform_device);
412fail_platform_device: 437fail_platform_device:
413 platform_device_put(platform_device); 438 platform_device_put(eeepc->platform_device);
414 return result; 439 return result;
415} 440}
416 441
417static void eeepc_platform_exit(void) 442static void eeepc_platform_exit(struct eeepc_laptop *eeepc)
418{ 443{
419 sysfs_remove_group(&platform_device->dev.kobj, 444 sysfs_remove_group(&eeepc->platform_device->dev.kobj,
420 &platform_attribute_group); 445 &platform_attribute_group);
421 platform_device_unregister(platform_device); 446 platform_device_unregister(eeepc->platform_device);
422} 447}
423 448
424/* 449/*
@@ -430,74 +455,76 @@ static void eeepc_platform_exit(void)
430 * subsystem asks, we avoid messing with the Asus ACPI stuff during a 455 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
431 * potentially bad time, such as a timer interrupt. 456 * potentially bad time, such as a timer interrupt.
432 */ 457 */
433static int tpd_led_wk; 458static void tpd_led_update(struct work_struct *work)
459 {
460 struct eeepc_laptop *eeepc;
434 461
435static void tpd_led_update(struct work_struct *ignored) 462 eeepc = container_of(work, struct eeepc_laptop, tpd_led_work);
436{
437 int value = tpd_led_wk;
438 set_acpi(CM_ASL_TPD, value);
439}
440 463
441static struct workqueue_struct *led_workqueue; 464 set_acpi(eeepc, CM_ASL_TPD, eeepc->tpd_led_wk);
442static DECLARE_WORK(tpd_led_work, tpd_led_update); 465}
443 466
444static void tpd_led_set(struct led_classdev *led_cdev, 467static void tpd_led_set(struct led_classdev *led_cdev,
445 enum led_brightness value) 468 enum led_brightness value)
446{ 469{
447 tpd_led_wk = (value > 0) ? 1 : 0; 470 struct eeepc_laptop *eeepc;
448 queue_work(led_workqueue, &tpd_led_work);
449}
450 471
451static struct led_classdev tpd_led = { 472 eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led);
452 .name = "eeepc::touchpad",
453 .brightness_set = tpd_led_set,
454 .max_brightness = 1
455};
456 473
457static int eeepc_led_init(struct device *dev) 474 eeepc->tpd_led_wk = (value > 0) ? 1 : 0;
475 queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
476}
477
478static int eeepc_led_init(struct eeepc_laptop *eeepc)
458{ 479{
459 int rv; 480 int rv;
460 481
461 if (get_acpi(CM_ASL_TPD) == -ENODEV) 482 if (get_acpi(eeepc, CM_ASL_TPD) == -ENODEV)
462 return 0; 483 return 0;
463 484
464 led_workqueue = create_singlethread_workqueue("led_workqueue"); 485 eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
465 if (!led_workqueue) 486 if (!eeepc->led_workqueue)
466 return -ENOMEM; 487 return -ENOMEM;
488 INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
489
490 eeepc->tpd_led.name = "eeepc::touchpad";
491 eeepc->tpd_led.brightness_set = tpd_led_set;
492 eeepc->tpd_led.max_brightness = 1;
467 493
468 rv = led_classdev_register(dev, &tpd_led); 494 rv = led_classdev_register(&eeepc->platform_device->dev,
495 &eeepc->tpd_led);
469 if (rv) { 496 if (rv) {
470 destroy_workqueue(led_workqueue); 497 destroy_workqueue(eeepc->led_workqueue);
471 return rv; 498 return rv;
472 } 499 }
473 500
474 return 0; 501 return 0;
475} 502}
476 503
477static void eeepc_led_exit(void) 504static void eeepc_led_exit(struct eeepc_laptop *eeepc)
478{ 505{
479 if (tpd_led.dev) 506 if (eeepc->tpd_led.dev)
480 led_classdev_unregister(&tpd_led); 507 led_classdev_unregister(&eeepc->tpd_led);
481 if (led_workqueue) 508 if (eeepc->led_workqueue)
482 destroy_workqueue(led_workqueue); 509 destroy_workqueue(eeepc->led_workqueue);
483} 510}
484 511
485 512
486/* 513/*
487 * PCI hotplug (for wlan rfkill) 514 * PCI hotplug (for wlan rfkill)
488 */ 515 */
489static bool eeepc_wlan_rfkill_blocked(void) 516static bool eeepc_wlan_rfkill_blocked(struct eeepc_laptop *eeepc)
490{ 517{
491 if (get_acpi(CM_ASL_WLAN) == 1) 518 if (get_acpi(eeepc, CM_ASL_WLAN) == 1)
492 return false; 519 return false;
493 return true; 520 return true;
494} 521}
495 522
496static void eeepc_rfkill_hotplug(void) 523static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc)
497{ 524{
498 struct pci_dev *dev; 525 struct pci_dev *dev;
499 struct pci_bus *bus; 526 struct pci_bus *bus;
500 bool blocked = eeepc_wlan_rfkill_blocked(); 527 bool blocked = eeepc_wlan_rfkill_blocked(eeepc);
501 528
502 if (eeepc->wlan_rfkill) 529 if (eeepc->wlan_rfkill)
503 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked); 530 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
@@ -539,15 +566,18 @@ out_unlock:
539 566
540static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data) 567static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
541{ 568{
569 struct eeepc_laptop *eeepc = data;
570
542 if (event != ACPI_NOTIFY_BUS_CHECK) 571 if (event != ACPI_NOTIFY_BUS_CHECK)
543 return; 572 return;
544 573
545 eeepc_rfkill_hotplug(); 574 eeepc_rfkill_hotplug(eeepc);
546} 575}
547 576
548static int eeepc_register_rfkill_notifier(char *node) 577static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc,
578 char *node)
549{ 579{
550 acpi_status status = AE_OK; 580 acpi_status status;
551 acpi_handle handle; 581 acpi_handle handle;
552 582
553 status = acpi_get_handle(NULL, node, &handle); 583 status = acpi_get_handle(NULL, node, &handle);
@@ -556,7 +586,7 @@ static int eeepc_register_rfkill_notifier(char *node)
556 status = acpi_install_notify_handler(handle, 586 status = acpi_install_notify_handler(handle,
557 ACPI_SYSTEM_NOTIFY, 587 ACPI_SYSTEM_NOTIFY,
558 eeepc_rfkill_notify, 588 eeepc_rfkill_notify,
559 NULL); 589 eeepc);
560 if (ACPI_FAILURE(status)) 590 if (ACPI_FAILURE(status))
561 pr_warning("Failed to register notify on %s\n", node); 591 pr_warning("Failed to register notify on %s\n", node);
562 } else 592 } else
@@ -565,7 +595,8 @@ static int eeepc_register_rfkill_notifier(char *node)
565 return 0; 595 return 0;
566} 596}
567 597
568static void eeepc_unregister_rfkill_notifier(char *node) 598static void eeepc_unregister_rfkill_notifier(struct eeepc_laptop *eeepc,
599 char *node)
569{ 600{
570 acpi_status status = AE_OK; 601 acpi_status status = AE_OK;
571 acpi_handle handle; 602 acpi_handle handle;
@@ -585,7 +616,8 @@ static void eeepc_unregister_rfkill_notifier(char *node)
585static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot, 616static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
586 u8 *value) 617 u8 *value)
587{ 618{
588 int val = get_acpi(CM_ASL_WLAN); 619 struct eeepc_laptop *eeepc = hotplug_slot->private;
620 int val = get_acpi(eeepc, CM_ASL_WLAN);
589 621
590 if (val == 1 || val == 0) 622 if (val == 1 || val == 0)
591 *value = val; 623 *value = val;
@@ -607,7 +639,7 @@ static struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
607 .get_power_status = eeepc_get_adapter_status, 639 .get_power_status = eeepc_get_adapter_status,
608}; 640};
609 641
610static int eeepc_setup_pci_hotplug(void) 642static int eeepc_setup_pci_hotplug(struct eeepc_laptop *eeepc)
611{ 643{
612 int ret = -ENOMEM; 644 int ret = -ENOMEM;
613 struct pci_bus *bus = pci_find_bus(0, 1); 645 struct pci_bus *bus = pci_find_bus(0, 1);
@@ -654,31 +686,34 @@ error_slot:
654 */ 686 */
655static int eeepc_rfkill_set(void *data, bool blocked) 687static int eeepc_rfkill_set(void *data, bool blocked)
656{ 688{
657 unsigned long asl = (unsigned long)data; 689 acpi_handle handle = data;
658 return set_acpi(asl, !blocked); 690
691 return write_acpi_int(handle, NULL, !blocked);
659} 692}
660 693
661static const struct rfkill_ops eeepc_rfkill_ops = { 694static const struct rfkill_ops eeepc_rfkill_ops = {
662 .set_block = eeepc_rfkill_set, 695 .set_block = eeepc_rfkill_set,
663}; 696};
664 697
665static int eeepc_new_rfkill(struct rfkill **rfkill, 698static int eeepc_new_rfkill(struct eeepc_laptop *eeepc,
666 const char *name, struct device *dev, 699 struct rfkill **rfkill,
700 const char *name,
667 enum rfkill_type type, int cm) 701 enum rfkill_type type, int cm)
668{ 702{
703 acpi_handle handle;
669 int result; 704 int result;
670 705
671 result = get_acpi(cm); 706 result = acpi_setter_handle(eeepc, cm, &handle);
672 if (result < 0) 707 if (result < 0)
673 return result; 708 return result;
674 709
675 *rfkill = rfkill_alloc(name, dev, type, 710 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
676 &eeepc_rfkill_ops, (void *)(unsigned long)cm); 711 &eeepc_rfkill_ops, handle);
677 712
678 if (!*rfkill) 713 if (!*rfkill)
679 return -EINVAL; 714 return -EINVAL;
680 715
681 rfkill_init_sw_state(*rfkill, get_acpi(cm) != 1); 716 rfkill_init_sw_state(*rfkill, get_acpi(eeepc, cm) != 1);
682 result = rfkill_register(*rfkill); 717 result = rfkill_register(*rfkill);
683 if (result) { 718 if (result) {
684 rfkill_destroy(*rfkill); 719 rfkill_destroy(*rfkill);
@@ -688,11 +723,11 @@ static int eeepc_new_rfkill(struct rfkill **rfkill,
688 return 0; 723 return 0;
689} 724}
690 725
691static void eeepc_rfkill_exit(void) 726static void eeepc_rfkill_exit(struct eeepc_laptop *eeepc)
692{ 727{
693 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P5"); 728 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
694 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6"); 729 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
695 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7"); 730 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
696 if (eeepc->wlan_rfkill) { 731 if (eeepc->wlan_rfkill) {
697 rfkill_unregister(eeepc->wlan_rfkill); 732 rfkill_unregister(eeepc->wlan_rfkill);
698 rfkill_destroy(eeepc->wlan_rfkill); 733 rfkill_destroy(eeepc->wlan_rfkill);
@@ -702,7 +737,7 @@ static void eeepc_rfkill_exit(void)
702 * Refresh pci hotplug in case the rfkill state was changed after 737 * Refresh pci hotplug in case the rfkill state was changed after
703 * eeepc_unregister_rfkill_notifier() 738 * eeepc_unregister_rfkill_notifier()
704 */ 739 */
705 eeepc_rfkill_hotplug(); 740 eeepc_rfkill_hotplug(eeepc);
706 if (eeepc->hotplug_slot) 741 if (eeepc->hotplug_slot)
707 pci_hp_deregister(eeepc->hotplug_slot); 742 pci_hp_deregister(eeepc->hotplug_slot);
708 743
@@ -723,41 +758,41 @@ static void eeepc_rfkill_exit(void)
723 } 758 }
724} 759}
725 760
726static int eeepc_rfkill_init(struct device *dev) 761static int eeepc_rfkill_init(struct eeepc_laptop *eeepc)
727{ 762{
728 int result = 0; 763 int result = 0;
729 764
730 mutex_init(&eeepc->hotplug_lock); 765 mutex_init(&eeepc->hotplug_lock);
731 766
732 result = eeepc_new_rfkill(&eeepc->wlan_rfkill, 767 result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
733 "eeepc-wlan", dev, 768 "eeepc-wlan", RFKILL_TYPE_WLAN,
734 RFKILL_TYPE_WLAN, CM_ASL_WLAN); 769 CM_ASL_WLAN);
735 770
736 if (result && result != -ENODEV) 771 if (result && result != -ENODEV)
737 goto exit; 772 goto exit;
738 773
739 result = eeepc_new_rfkill(&eeepc->bluetooth_rfkill, 774 result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
740 "eeepc-bluetooth", dev, 775 "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
741 RFKILL_TYPE_BLUETOOTH, CM_ASL_BLUETOOTH); 776 CM_ASL_BLUETOOTH);
742 777
743 if (result && result != -ENODEV) 778 if (result && result != -ENODEV)
744 goto exit; 779 goto exit;
745 780
746 result = eeepc_new_rfkill(&eeepc->wwan3g_rfkill, 781 result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
747 "eeepc-wwan3g", dev, 782 "eeepc-wwan3g", RFKILL_TYPE_WWAN,
748 RFKILL_TYPE_WWAN, CM_ASL_3G); 783 CM_ASL_3G);
749 784
750 if (result && result != -ENODEV) 785 if (result && result != -ENODEV)
751 goto exit; 786 goto exit;
752 787
753 result = eeepc_new_rfkill(&eeepc->wimax_rfkill, 788 result = eeepc_new_rfkill(eeepc, &eeepc->wimax_rfkill,
754 "eeepc-wimax", dev, 789 "eeepc-wimax", RFKILL_TYPE_WIMAX,
755 RFKILL_TYPE_WIMAX, CM_ASL_WIMAX); 790 CM_ASL_WIMAX);
756 791
757 if (result && result != -ENODEV) 792 if (result && result != -ENODEV)
758 goto exit; 793 goto exit;
759 794
760 result = eeepc_setup_pci_hotplug(); 795 result = eeepc_setup_pci_hotplug(eeepc);
761 /* 796 /*
762 * If we get -EBUSY then something else is handling the PCI hotplug - 797 * If we get -EBUSY then something else is handling the PCI hotplug -
763 * don't fail in this case 798 * don't fail in this case
@@ -765,26 +800,28 @@ static int eeepc_rfkill_init(struct device *dev)
765 if (result == -EBUSY) 800 if (result == -EBUSY)
766 result = 0; 801 result = 0;
767 802
768 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P5"); 803 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
769 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6"); 804 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
770 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7"); 805 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
771 /* 806 /*
772 * Refresh pci hotplug in case the rfkill state was changed during 807 * Refresh pci hotplug in case the rfkill state was changed during
773 * setup. 808 * setup.
774 */ 809 */
775 eeepc_rfkill_hotplug(); 810 eeepc_rfkill_hotplug(eeepc);
776 811
777exit: 812exit:
778 if (result && result != -ENODEV) 813 if (result && result != -ENODEV)
779 eeepc_rfkill_exit(); 814 eeepc_rfkill_exit(eeepc);
780 return result; 815 return result;
781} 816}
782 817
783/* 818/*
784 * Platform driver - hibernate/resume callbacks 819 * Platform driver - hibernate/resume callbacks
785 */ 820 */
786static int eeepc_thaw(struct device *device) 821static int eeepc_hotk_thaw(struct device *device)
787{ 822{
823 struct eeepc_laptop *eeepc = dev_get_drvdata(device);
824
788 if (eeepc->wlan_rfkill) { 825 if (eeepc->wlan_rfkill) {
789 bool wlan; 826 bool wlan;
790 827
@@ -793,35 +830,37 @@ static int eeepc_thaw(struct device *device)
793 * during suspend. Normally it restores it on resume, but 830 * during suspend. Normally it restores it on resume, but
794 * we should kick it ourselves in case hibernation is aborted. 831 * we should kick it ourselves in case hibernation is aborted.
795 */ 832 */
796 wlan = get_acpi(CM_ASL_WLAN); 833 wlan = get_acpi(eeepc, CM_ASL_WLAN);
797 set_acpi(CM_ASL_WLAN, wlan); 834 set_acpi(eeepc, CM_ASL_WLAN, wlan);
798 } 835 }
799 836
800 return 0; 837 return 0;
801} 838}
802 839
803static int eeepc_restore(struct device *device) 840static int eeepc_hotk_restore(struct device *device)
804{ 841{
842 struct eeepc_laptop *eeepc = dev_get_drvdata(device);
843
805 /* Refresh both wlan rfkill state and pci hotplug */ 844 /* Refresh both wlan rfkill state and pci hotplug */
806 if (eeepc->wlan_rfkill) 845 if (eeepc->wlan_rfkill)
807 eeepc_rfkill_hotplug(); 846 eeepc_rfkill_hotplug(eeepc);
808 847
809 if (eeepc->bluetooth_rfkill) 848 if (eeepc->bluetooth_rfkill)
810 rfkill_set_sw_state(eeepc->bluetooth_rfkill, 849 rfkill_set_sw_state(eeepc->bluetooth_rfkill,
811 get_acpi(CM_ASL_BLUETOOTH) != 1); 850 get_acpi(eeepc, CM_ASL_BLUETOOTH) != 1);
812 if (eeepc->wwan3g_rfkill) 851 if (eeepc->wwan3g_rfkill)
813 rfkill_set_sw_state(eeepc->wwan3g_rfkill, 852 rfkill_set_sw_state(eeepc->wwan3g_rfkill,
814 get_acpi(CM_ASL_3G) != 1); 853 get_acpi(eeepc, CM_ASL_3G) != 1);
815 if (eeepc->wimax_rfkill) 854 if (eeepc->wimax_rfkill)
816 rfkill_set_sw_state(eeepc->wimax_rfkill, 855 rfkill_set_sw_state(eeepc->wimax_rfkill,
817 get_acpi(CM_ASL_WIMAX) != 1); 856 get_acpi(eeepc, CM_ASL_WIMAX) != 1);
818 857
819 return 0; 858 return 0;
820} 859}
821 860
822static struct dev_pm_ops eeepc_pm_ops = { 861static struct dev_pm_ops eeepc_pm_ops = {
823 .thaw = eeepc_thaw, 862 .thaw = eeepc_hotk_thaw,
824 .restore = eeepc_restore, 863 .restore = eeepc_hotk_restore,
825}; 864};
826 865
827static struct platform_driver platform_driver = { 866static struct platform_driver platform_driver = {
@@ -947,35 +986,35 @@ static struct attribute_group hwmon_attribute_group = {
947 .attrs = hwmon_attributes 986 .attrs = hwmon_attributes
948}; 987};
949 988
950static void eeepc_hwmon_exit(void) 989static void eeepc_hwmon_exit(struct eeepc_laptop *eeepc)
951{ 990{
952 struct device *hwmon; 991 struct device *hwmon;
953 992
954 hwmon = eeepc_hwmon_device; 993 hwmon = eeepc->hwmon_device;
955 if (!hwmon) 994 if (!hwmon)
956 return ; 995 return;
957 sysfs_remove_group(&hwmon->kobj, 996 sysfs_remove_group(&hwmon->kobj,
958 &hwmon_attribute_group); 997 &hwmon_attribute_group);
959 hwmon_device_unregister(hwmon); 998 hwmon_device_unregister(hwmon);
960 eeepc_hwmon_device = NULL; 999 eeepc->hwmon_device = NULL;
961} 1000}
962 1001
963static int eeepc_hwmon_init(struct device *dev) 1002static int eeepc_hwmon_init(struct eeepc_laptop *eeepc)
964{ 1003{
965 struct device *hwmon; 1004 struct device *hwmon;
966 int result; 1005 int result;
967 1006
968 hwmon = hwmon_device_register(dev); 1007 hwmon = hwmon_device_register(&eeepc->platform_device->dev);
969 if (IS_ERR(hwmon)) { 1008 if (IS_ERR(hwmon)) {
970 pr_err("Could not register eeepc hwmon device\n"); 1009 pr_err("Could not register eeepc hwmon device\n");
971 eeepc_hwmon_device = NULL; 1010 eeepc->hwmon_device = NULL;
972 return PTR_ERR(hwmon); 1011 return PTR_ERR(hwmon);
973 } 1012 }
974 eeepc_hwmon_device = hwmon; 1013 eeepc->hwmon_device = hwmon;
975 result = sysfs_create_group(&hwmon->kobj, 1014 result = sysfs_create_group(&hwmon->kobj,
976 &hwmon_attribute_group); 1015 &hwmon_attribute_group);
977 if (result) 1016 if (result)
978 eeepc_hwmon_exit(); 1017 eeepc_hwmon_exit(eeepc);
979 return result; 1018 return result;
980} 1019}
981 1020
@@ -984,12 +1023,16 @@ static int eeepc_hwmon_init(struct device *dev)
984 */ 1023 */
985static int read_brightness(struct backlight_device *bd) 1024static int read_brightness(struct backlight_device *bd)
986{ 1025{
987 return get_acpi(CM_ASL_PANELBRIGHT); 1026 struct eeepc_laptop *eeepc = bl_get_data(bd);
1027
1028 return get_acpi(eeepc, CM_ASL_PANELBRIGHT);
988} 1029}
989 1030
990static int set_brightness(struct backlight_device *bd, int value) 1031static int set_brightness(struct backlight_device *bd, int value)
991{ 1032{
992 return set_acpi(CM_ASL_PANELBRIGHT, value); 1033 struct eeepc_laptop *eeepc = bl_get_data(bd);
1034
1035 return set_acpi(eeepc, CM_ASL_PANELBRIGHT, value);
993} 1036}
994 1037
995static int update_bl_status(struct backlight_device *bd) 1038static int update_bl_status(struct backlight_device *bd)
@@ -1002,9 +1045,9 @@ static struct backlight_ops eeepcbl_ops = {
1002 .update_status = update_bl_status, 1045 .update_status = update_bl_status,
1003}; 1046};
1004 1047
1005static int eeepc_backlight_notify(void) 1048static int eeepc_backlight_notify(struct eeepc_laptop *eeepc)
1006{ 1049{
1007 struct backlight_device *bd = eeepc_backlight_device; 1050 struct backlight_device *bd = eeepc->backlight_device;
1008 int old = bd->props.brightness; 1051 int old = bd->props.brightness;
1009 1052
1010 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); 1053 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
@@ -1012,52 +1055,55 @@ static int eeepc_backlight_notify(void)
1012 return old; 1055 return old;
1013} 1056}
1014 1057
1015static int eeepc_backlight_init(struct device *dev) 1058static int eeepc_backlight_init(struct eeepc_laptop *eeepc)
1016{ 1059{
1017 struct backlight_device *bd; 1060 struct backlight_device *bd;
1018 1061
1019 bd = backlight_device_register(EEEPC_LAPTOP_FILE, dev, 1062 bd = backlight_device_register(EEEPC_LAPTOP_FILE,
1020 NULL, &eeepcbl_ops); 1063 &eeepc->platform_device->dev,
1064 eeepc, &eeepcbl_ops);
1021 if (IS_ERR(bd)) { 1065 if (IS_ERR(bd)) {
1022 pr_err("Could not register eeepc backlight device\n"); 1066 pr_err("Could not register eeepc backlight device\n");
1023 eeepc_backlight_device = NULL; 1067 eeepc->backlight_device = NULL;
1024 return PTR_ERR(bd); 1068 return PTR_ERR(bd);
1025 } 1069 }
1026 eeepc_backlight_device = bd; 1070 eeepc->backlight_device = bd;
1027 bd->props.max_brightness = 15; 1071 bd->props.max_brightness = 15;
1028 bd->props.brightness = read_brightness(NULL); 1072 bd->props.brightness = read_brightness(bd);
1029 bd->props.power = FB_BLANK_UNBLANK; 1073 bd->props.power = FB_BLANK_UNBLANK;
1030 backlight_update_status(bd); 1074 backlight_update_status(bd);
1031 return 0; 1075 return 0;
1032} 1076}
1033 1077
1034static void eeepc_backlight_exit(void) 1078static void eeepc_backlight_exit(struct eeepc_laptop *eeepc)
1035{ 1079{
1036 if (eeepc_backlight_device) 1080 if (eeepc->backlight_device)
1037 backlight_device_unregister(eeepc_backlight_device); 1081 backlight_device_unregister(eeepc->backlight_device);
1038 eeepc_backlight_device = NULL; 1082 eeepc->backlight_device = NULL;
1039} 1083}
1040 1084
1041 1085
1042/* 1086/*
1043 * Input device (i.e. hotkeys) 1087 * Input device (i.e. hotkeys)
1044 */ 1088 */
1045static struct key_entry *eeepc_get_entry_by_scancode(int code) 1089static struct key_entry *eeepc_get_entry_by_scancode(
1090 struct eeepc_laptop *eeepc,
1091 int code)
1046{ 1092{
1047 struct key_entry *key; 1093 struct key_entry *key;
1048 1094
1049 for (key = eeepc_keymap; key->type != KE_END; key++) 1095 for (key = eeepc->keymap; key->type != KE_END; key++)
1050 if (code == key->code) 1096 if (code == key->code)
1051 return key; 1097 return key;
1052 1098
1053 return NULL; 1099 return NULL;
1054} 1100}
1055 1101
1056static void eeepc_input_notify(int event) 1102static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event)
1057{ 1103{
1058 static struct key_entry *key; 1104 static struct key_entry *key;
1059 1105
1060 key = eeepc_get_entry_by_scancode(event); 1106 key = eeepc_get_entry_by_scancode(eeepc, event);
1061 if (key) { 1107 if (key) {
1062 switch (key->type) { 1108 switch (key->type) {
1063 case KE_KEY: 1109 case KE_KEY:
@@ -1072,11 +1118,12 @@ static void eeepc_input_notify(int event)
1072 } 1118 }
1073} 1119}
1074 1120
1075static struct key_entry *eepc_get_entry_by_keycode(int code) 1121static struct key_entry *eeepc_get_entry_by_keycode(
1122 struct eeepc_laptop *eeepc, int code)
1076{ 1123{
1077 struct key_entry *key; 1124 struct key_entry *key;
1078 1125
1079 for (key = eeepc_keymap; key->type != KE_END; key++) 1126 for (key = eeepc->keymap; key->type != KE_END; key++)
1080 if (code == key->keycode && key->type == KE_KEY) 1127 if (code == key->keycode && key->type == KE_KEY)
1081 return key; 1128 return key;
1082 1129
@@ -1085,7 +1132,8 @@ static struct key_entry *eepc_get_entry_by_keycode(int code)
1085 1132
1086static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode) 1133static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
1087{ 1134{
1088 struct key_entry *key = eeepc_get_entry_by_scancode(scancode); 1135 struct eeepc_laptop *eeepc = input_get_drvdata(dev);
1136 struct key_entry *key = eeepc_get_entry_by_scancode(eeepc, scancode);
1089 1137
1090 if (key && key->type == KE_KEY) { 1138 if (key && key->type == KE_KEY) {
1091 *keycode = key->keycode; 1139 *keycode = key->keycode;
@@ -1097,18 +1145,19 @@ static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
1097 1145
1098static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode) 1146static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
1099{ 1147{
1148 struct eeepc_laptop *eeepc = input_get_drvdata(dev);
1100 struct key_entry *key; 1149 struct key_entry *key;
1101 int old_keycode; 1150 int old_keycode;
1102 1151
1103 if (keycode < 0 || keycode > KEY_MAX) 1152 if (keycode < 0 || keycode > KEY_MAX)
1104 return -EINVAL; 1153 return -EINVAL;
1105 1154
1106 key = eeepc_get_entry_by_scancode(scancode); 1155 key = eeepc_get_entry_by_scancode(eeepc, scancode);
1107 if (key && key->type == KE_KEY) { 1156 if (key && key->type == KE_KEY) {
1108 old_keycode = key->keycode; 1157 old_keycode = key->keycode;
1109 key->keycode = keycode; 1158 key->keycode = keycode;
1110 set_bit(keycode, dev->keybit); 1159 set_bit(keycode, dev->keybit);
1111 if (!eepc_get_entry_by_keycode(old_keycode)) 1160 if (!eeepc_get_entry_by_keycode(eeepc, old_keycode))
1112 clear_bit(old_keycode, dev->keybit); 1161 clear_bit(old_keycode, dev->keybit);
1113 return 0; 1162 return 0;
1114 } 1163 }
@@ -1116,7 +1165,7 @@ static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
1116 return -EINVAL; 1165 return -EINVAL;
1117} 1166}
1118 1167
1119static int eeepc_input_init(struct device *dev) 1168static int eeepc_input_init(struct eeepc_laptop *eeepc)
1120{ 1169{
1121 const struct key_entry *key; 1170 const struct key_entry *key;
1122 int result; 1171 int result;
@@ -1127,12 +1176,15 @@ static int eeepc_input_init(struct device *dev)
1127 return -ENOMEM; 1176 return -ENOMEM;
1128 } 1177 }
1129 eeepc->inputdev->name = "Asus EeePC extra buttons"; 1178 eeepc->inputdev->name = "Asus EeePC extra buttons";
1130 eeepc->inputdev->dev.parent = dev; 1179 eeepc->inputdev->dev.parent = &eeepc->platform_device->dev;
1131 eeepc->inputdev->phys = EEEPC_LAPTOP_FILE "/input0"; 1180 eeepc->inputdev->phys = EEEPC_LAPTOP_FILE "/input0";
1132 eeepc->inputdev->id.bustype = BUS_HOST; 1181 eeepc->inputdev->id.bustype = BUS_HOST;
1133 eeepc->inputdev->getkeycode = eeepc_getkeycode; 1182 eeepc->inputdev->getkeycode = eeepc_getkeycode;
1134 eeepc->inputdev->setkeycode = eeepc_setkeycode; 1183 eeepc->inputdev->setkeycode = eeepc_setkeycode;
1184 input_set_drvdata(eeepc->inputdev, eeepc);
1135 1185
1186 eeepc->keymap = kmemdup(eeepc_keymap, sizeof(eeepc_keymap),
1187 GFP_KERNEL);
1136 for (key = eeepc_keymap; key->type != KE_END; key++) { 1188 for (key = eeepc_keymap; key->type != KE_END; key++) {
1137 switch (key->type) { 1189 switch (key->type) {
1138 case KE_KEY: 1190 case KE_KEY:
@@ -1150,10 +1202,12 @@ static int eeepc_input_init(struct device *dev)
1150 return 0; 1202 return 0;
1151} 1203}
1152 1204
1153static void eeepc_input_exit(void) 1205static void eeepc_input_exit(struct eeepc_laptop *eeepc)
1154{ 1206{
1155 if (eeepc->inputdev) 1207 if (eeepc->inputdev) {
1156 input_unregister_device(eeepc->inputdev); 1208 input_unregister_device(eeepc->inputdev);
1209 kfree(eeepc->keymap);
1210 }
1157} 1211}
1158 1212
1159/* 1213/*
@@ -1161,21 +1215,22 @@ static void eeepc_input_exit(void)
1161 */ 1215 */
1162static void eeepc_acpi_notify(struct acpi_device *device, u32 event) 1216static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
1163{ 1217{
1218 struct eeepc_laptop *eeepc = acpi_driver_data(device);
1164 u16 count; 1219 u16 count;
1165 1220
1166 if (event > ACPI_MAX_SYS_NOTIFY) 1221 if (event > ACPI_MAX_SYS_NOTIFY)
1167 return; 1222 return;
1168 count = eeepc->event_count[event % 128]++; 1223 count = eeepc->event_count[event % 128]++;
1169 acpi_bus_generate_proc_event(eeepc->device, event, count); 1224 acpi_bus_generate_proc_event(device, event, count);
1170 acpi_bus_generate_netlink_event(eeepc->device->pnp.device_class, 1225 acpi_bus_generate_netlink_event(device->pnp.device_class,
1171 dev_name(&eeepc->device->dev), event, 1226 dev_name(&device->dev), event,
1172 count); 1227 count);
1173 1228
1174 if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX) { 1229 if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX) {
1175 int old_brightness, new_brightness; 1230 int old_brightness, new_brightness;
1176 1231
1177 /* Update backlight device. */ 1232 /* Update backlight device. */
1178 old_brightness = eeepc_backlight_notify(); 1233 old_brightness = eeepc_backlight_notify(eeepc);
1179 1234
1180 /* Convert brightness event to keypress (obsolescent hack). */ 1235 /* Convert brightness event to keypress (obsolescent hack). */
1181 new_brightness = event - NOTIFY_BRN_MIN; 1236 new_brightness = event - NOTIFY_BRN_MIN;
@@ -1191,10 +1246,10 @@ static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
1191 */ 1246 */
1192 } 1247 }
1193 } 1248 }
1194 eeepc_input_notify(event); 1249 eeepc_input_notify(eeepc, event);
1195} 1250}
1196 1251
1197static void cmsg_quirk(int cm, const char *name) 1252static void cmsg_quirk(struct eeepc_laptop *eeepc, int cm, const char *name)
1198{ 1253{
1199 int dummy; 1254 int dummy;
1200 1255
@@ -1208,23 +1263,23 @@ static void cmsg_quirk(int cm, const char *name)
1208 } 1263 }
1209} 1264}
1210 1265
1211static void cmsg_quirks(void) 1266static void cmsg_quirks(struct eeepc_laptop *eeepc)
1212{ 1267{
1213 cmsg_quirk(CM_ASL_LID, "LID"); 1268 cmsg_quirk(eeepc, CM_ASL_LID, "LID");
1214 cmsg_quirk(CM_ASL_TYPE, "TYPE"); 1269 cmsg_quirk(eeepc, CM_ASL_TYPE, "TYPE");
1215 cmsg_quirk(CM_ASL_PANELPOWER, "PANELPOWER"); 1270 cmsg_quirk(eeepc, CM_ASL_PANELPOWER, "PANELPOWER");
1216 cmsg_quirk(CM_ASL_TPD, "TPD"); 1271 cmsg_quirk(eeepc, CM_ASL_TPD, "TPD");
1217} 1272}
1218 1273
1219static int eeepc_acpi_init(void) 1274static int eeepc_acpi_init(struct eeepc_laptop *eeepc, struct acpi_device *device)
1220{ 1275{
1221 unsigned int init_flags; 1276 unsigned int init_flags;
1222 int result; 1277 int result;
1223 1278
1224 result = acpi_bus_get_status(eeepc->device); 1279 result = acpi_bus_get_status(device);
1225 if (result) 1280 if (result)
1226 return result; 1281 return result;
1227 if (!eeepc->device->status.present) { 1282 if (!device->status.present) {
1228 pr_err("Hotkey device not present, aborting\n"); 1283 pr_err("Hotkey device not present, aborting\n");
1229 return -ENODEV; 1284 return -ENODEV;
1230 } 1285 }
@@ -1242,25 +1297,27 @@ static int eeepc_acpi_init(void)
1242 pr_err("Get control methods supported failed\n"); 1297 pr_err("Get control methods supported failed\n");
1243 return -ENODEV; 1298 return -ENODEV;
1244 } 1299 }
1245 cmsg_quirks(); 1300 cmsg_quirks(eeepc);
1246 pr_info("Get control methods supported: 0x%x\n", eeepc->cm_supported); 1301 pr_info("Get control methods supported: 0x%x\n", eeepc->cm_supported);
1247 1302
1248 return 0; 1303 return 0;
1249} 1304}
1250 1305
1251static void __devinit eeepc_enable_camera(void) 1306static void __devinit eeepc_enable_camera(struct eeepc_laptop *eeepc)
1252{ 1307{
1253 /* 1308 /*
1254 * If the following call to set_acpi() fails, it's because there's no 1309 * If the following call to set_acpi() fails, it's because there's no
1255 * camera so we can ignore the error. 1310 * camera so we can ignore the error.
1256 */ 1311 */
1257 if (get_acpi(CM_ASL_CAMERA) == 0) 1312 if (get_acpi(eeepc, CM_ASL_CAMERA) == 0)
1258 set_acpi(CM_ASL_CAMERA, 1); 1313 set_acpi(eeepc, CM_ASL_CAMERA, 1);
1259} 1314}
1260 1315
1316static bool eeepc_device_present;
1317
1261static int __devinit eeepc_acpi_add(struct acpi_device *device) 1318static int __devinit eeepc_acpi_add(struct acpi_device *device)
1262{ 1319{
1263 struct device *dev; 1320 struct eeepc_laptop *eeepc;
1264 int result; 1321 int result;
1265 1322
1266 pr_notice(EEEPC_LAPTOP_NAME "\n"); 1323 pr_notice(EEEPC_LAPTOP_NAME "\n");
@@ -1271,53 +1328,64 @@ static int __devinit eeepc_acpi_add(struct acpi_device *device)
1271 strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME); 1328 strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
1272 strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS); 1329 strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
1273 device->driver_data = eeepc; 1330 device->driver_data = eeepc;
1274 eeepc->device = device;
1275 1331
1276 result = eeepc_acpi_init(); 1332 result = eeepc_acpi_init(eeepc, device);
1277 if (result) 1333 if (result)
1278 goto fail_platform; 1334 goto fail_platform;
1279 eeepc_enable_camera(); 1335 eeepc_enable_camera(eeepc);
1280 1336
1281 result = eeepc_platform_init(); 1337 /*
1338 * Register the platform device first. It is used as a parent for the
1339 * sub-devices below.
1340 *
1341 * Note that if there are multiple instances of this ACPI device it
1342 * will bail out, because the platform device is registered with a
1343 * fixed name. Of course it doesn't make sense to have more than one,
1344 * and machine-specific scripts find the fixed name convenient. But
1345 * It's also good for us to exclude multiple instances because both
1346 * our hwmon and our wlan rfkill subdevice use global ACPI objects
1347 * (the EC and the wlan PCI slot respectively).
1348 */
1349 result = eeepc_platform_init(eeepc);
1282 if (result) 1350 if (result)
1283 goto fail_platform; 1351 goto fail_platform;
1284 dev = &platform_device->dev;
1285 1352
1286 if (!acpi_video_backlight_support()) { 1353 if (!acpi_video_backlight_support()) {
1287 result = eeepc_backlight_init(dev); 1354 result = eeepc_backlight_init(eeepc);
1288 if (result) 1355 if (result)
1289 goto fail_backlight; 1356 goto fail_backlight;
1290 } else 1357 } else
1291 pr_info("Backlight controlled by ACPI video driver\n"); 1358 pr_info("Backlight controlled by ACPI video driver\n");
1292 1359
1293 result = eeepc_input_init(dev); 1360 result = eeepc_input_init(eeepc);
1294 if (result) 1361 if (result)
1295 goto fail_input; 1362 goto fail_input;
1296 1363
1297 result = eeepc_hwmon_init(dev); 1364 result = eeepc_hwmon_init(eeepc);
1298 if (result) 1365 if (result)
1299 goto fail_hwmon; 1366 goto fail_hwmon;
1300 1367
1301 result = eeepc_led_init(dev); 1368 result = eeepc_led_init(eeepc);
1302 if (result) 1369 if (result)
1303 goto fail_led; 1370 goto fail_led;
1304 1371
1305 result = eeepc_rfkill_init(dev); 1372 result = eeepc_rfkill_init(eeepc);
1306 if (result) 1373 if (result)
1307 goto fail_rfkill; 1374 goto fail_rfkill;
1308 1375
1376 eeepc_device_present = true;
1309 return 0; 1377 return 0;
1310 1378
1311fail_rfkill: 1379fail_rfkill:
1312 eeepc_led_exit(); 1380 eeepc_led_exit(eeepc);
1313fail_led: 1381fail_led:
1314 eeepc_hwmon_exit(); 1382 eeepc_hwmon_exit(eeepc);
1315fail_hwmon: 1383fail_hwmon:
1316 eeepc_input_exit(); 1384 eeepc_input_exit(eeepc);
1317fail_input: 1385fail_input:
1318 eeepc_backlight_exit(); 1386 eeepc_backlight_exit(eeepc);
1319fail_backlight: 1387fail_backlight:
1320 eeepc_platform_exit(); 1388 eeepc_platform_exit(eeepc);
1321fail_platform: 1389fail_platform:
1322 kfree(eeepc); 1390 kfree(eeepc);
1323 1391
@@ -1326,12 +1394,14 @@ fail_platform:
1326 1394
1327static int eeepc_acpi_remove(struct acpi_device *device, int type) 1395static int eeepc_acpi_remove(struct acpi_device *device, int type)
1328{ 1396{
1329 eeepc_backlight_exit(); 1397 struct eeepc_laptop *eeepc = acpi_driver_data(device);
1330 eeepc_rfkill_exit(); 1398
1331 eeepc_input_exit(); 1399 eeepc_backlight_exit(eeepc);
1332 eeepc_hwmon_exit(); 1400 eeepc_rfkill_exit(eeepc);
1333 eeepc_led_exit(); 1401 eeepc_input_exit(eeepc);
1334 eeepc_platform_exit(); 1402 eeepc_hwmon_exit(eeepc);
1403 eeepc_led_exit(eeepc);
1404 eeepc_platform_exit(eeepc);
1335 1405
1336 kfree(eeepc); 1406 kfree(eeepc);
1337 return 0; 1407 return 0;
@@ -1369,7 +1439,7 @@ static int __init eeepc_laptop_init(void)
1369 result = acpi_bus_register_driver(&eeepc_acpi_driver); 1439 result = acpi_bus_register_driver(&eeepc_acpi_driver);
1370 if (result < 0) 1440 if (result < 0)
1371 goto fail_acpi_driver; 1441 goto fail_acpi_driver;
1372 if (!eeepc) { 1442 if (!eeepc_device_present) {
1373 result = -ENODEV; 1443 result = -ENODEV;
1374 goto fail_no_device; 1444 goto fail_no_device;
1375 } 1445 }