aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIke Panhc <ike.pan@canonical.com>2010-12-13 05:01:01 -0500
committerMatthew Garrett <mjg@redhat.com>2011-01-07 17:03:47 -0500
commit8693ae846cad00e6c2c40e116ec1fc50c145b559 (patch)
treeba9cbd50fe81ff249db931559ca04afee5676e3a
parenta4b5a2794a27da870c2e16db390778a4683f95f8 (diff)
ideapad: pass ideapad_priv as argument (part 1)
Passing ideapad_priv as argument and try not to using too much global variable. This is part 1 for platform driver and input device. Signed-off-by: Ike Panhc <ike.pan@canonical.com> Signed-off-by: Matthew Garrett <mjg@redhat.com>
-rw-r--r--drivers/platform/x86/ideapad-laptop.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index 3c6c5b5e1d53..37fe0d0448c9 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -301,37 +301,37 @@ static struct attribute_group ideapad_attribute_group = {
301 .attrs = ideapad_attributes 301 .attrs = ideapad_attributes
302}; 302};
303 303
304static int __devinit ideapad_platform_init(void) 304static int __devinit ideapad_platform_init(struct ideapad_private *priv)
305{ 305{
306 int result; 306 int result;
307 307
308 ideapad_priv->platform_device = platform_device_alloc("ideapad", -1); 308 priv->platform_device = platform_device_alloc("ideapad", -1);
309 if (!ideapad_priv->platform_device) 309 if (!priv->platform_device)
310 return -ENOMEM; 310 return -ENOMEM;
311 platform_set_drvdata(ideapad_priv->platform_device, ideapad_priv); 311 platform_set_drvdata(priv->platform_device, priv);
312 312
313 result = platform_device_add(ideapad_priv->platform_device); 313 result = platform_device_add(priv->platform_device);
314 if (result) 314 if (result)
315 goto fail_platform_device; 315 goto fail_platform_device;
316 316
317 result = sysfs_create_group(&ideapad_priv->platform_device->dev.kobj, 317 result = sysfs_create_group(&priv->platform_device->dev.kobj,
318 &ideapad_attribute_group); 318 &ideapad_attribute_group);
319 if (result) 319 if (result)
320 goto fail_sysfs; 320 goto fail_sysfs;
321 return 0; 321 return 0;
322 322
323fail_sysfs: 323fail_sysfs:
324 platform_device_del(ideapad_priv->platform_device); 324 platform_device_del(priv->platform_device);
325fail_platform_device: 325fail_platform_device:
326 platform_device_put(ideapad_priv->platform_device); 326 platform_device_put(priv->platform_device);
327 return result; 327 return result;
328} 328}
329 329
330static void ideapad_platform_exit(void) 330static void ideapad_platform_exit(struct ideapad_private *priv)
331{ 331{
332 sysfs_remove_group(&ideapad_priv->platform_device->dev.kobj, 332 sysfs_remove_group(&priv->platform_device->dev.kobj,
333 &ideapad_attribute_group); 333 &ideapad_attribute_group);
334 platform_device_unregister(ideapad_priv->platform_device); 334 platform_device_unregister(priv->platform_device);
335} 335}
336 336
337/* 337/*
@@ -343,7 +343,7 @@ static const struct key_entry ideapad_keymap[] = {
343 { KE_END, 0 }, 343 { KE_END, 0 },
344}; 344};
345 345
346static int __devinit ideapad_input_init(void) 346static int __devinit ideapad_input_init(struct ideapad_private *priv)
347{ 347{
348 struct input_dev *inputdev; 348 struct input_dev *inputdev;
349 int error; 349 int error;
@@ -357,7 +357,7 @@ static int __devinit ideapad_input_init(void)
357 inputdev->name = "Ideapad extra buttons"; 357 inputdev->name = "Ideapad extra buttons";
358 inputdev->phys = "ideapad/input0"; 358 inputdev->phys = "ideapad/input0";
359 inputdev->id.bustype = BUS_HOST; 359 inputdev->id.bustype = BUS_HOST;
360 inputdev->dev.parent = &ideapad_priv->platform_device->dev; 360 inputdev->dev.parent = &priv->platform_device->dev;
361 361
362 error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); 362 error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL);
363 if (error) { 363 if (error) {
@@ -371,7 +371,7 @@ static int __devinit ideapad_input_init(void)
371 goto err_free_keymap; 371 goto err_free_keymap;
372 } 372 }
373 373
374 ideapad_priv->inputdev = inputdev; 374 priv->inputdev = inputdev;
375 return 0; 375 return 0;
376 376
377err_free_keymap: 377err_free_keymap:
@@ -381,16 +381,17 @@ err_free_dev:
381 return error; 381 return error;
382} 382}
383 383
384static void __devexit ideapad_input_exit(void) 384static void __devexit ideapad_input_exit(struct ideapad_private *priv)
385{ 385{
386 sparse_keymap_free(ideapad_priv->inputdev); 386 sparse_keymap_free(priv->inputdev);
387 input_unregister_device(ideapad_priv->inputdev); 387 input_unregister_device(priv->inputdev);
388 ideapad_priv->inputdev = NULL; 388 priv->inputdev = NULL;
389} 389}
390 390
391static void ideapad_input_report(unsigned long scancode) 391static void ideapad_input_report(struct ideapad_private *priv,
392 unsigned long scancode)
392{ 393{
393 sparse_keymap_report_event(ideapad_priv->inputdev, scancode, 1, true); 394 sparse_keymap_report_event(priv->inputdev, scancode, 1, true);
394} 395}
395 396
396/* 397/*
@@ -417,11 +418,11 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
417 priv->handle = adevice->handle; 418 priv->handle = adevice->handle;
418 dev_set_drvdata(&adevice->dev, priv); 419 dev_set_drvdata(&adevice->dev, priv);
419 420
420 ret = ideapad_platform_init(); 421 ret = ideapad_platform_init(priv);
421 if (ret) 422 if (ret)
422 goto platform_failed; 423 goto platform_failed;
423 424
424 ret = ideapad_input_init(); 425 ret = ideapad_input_init(priv);
425 if (ret) 426 if (ret)
426 goto input_failed; 427 goto input_failed;
427 428
@@ -434,7 +435,7 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
434 return 0; 435 return 0;
435 436
436input_failed: 437input_failed:
437 ideapad_platform_exit(); 438 ideapad_platform_exit(priv);
438platform_failed: 439platform_failed:
439 kfree(priv); 440 kfree(priv);
440 return ret; 441 return ret;
@@ -447,8 +448,8 @@ static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type)
447 448
448 for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) 449 for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++)
449 ideapad_unregister_rfkill(adevice, i); 450 ideapad_unregister_rfkill(adevice, i);
450 ideapad_input_exit(); 451 ideapad_input_exit(priv);
451 ideapad_platform_exit(); 452 ideapad_platform_exit(priv);
452 dev_set_drvdata(&adevice->dev, NULL); 453 dev_set_drvdata(&adevice->dev, NULL);
453 kfree(priv); 454 kfree(priv);
454 455
@@ -457,6 +458,7 @@ static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type)
457 458
458static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event) 459static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
459{ 460{
461 struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
460 acpi_handle handle = adevice->handle; 462 acpi_handle handle = adevice->handle;
461 unsigned long vpc1, vpc2, vpc_bit; 463 unsigned long vpc1, vpc2, vpc_bit;
462 464
@@ -471,7 +473,7 @@ static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
471 if (vpc_bit == 9) 473 if (vpc_bit == 9)
472 ideapad_sync_rfk_state(adevice); 474 ideapad_sync_rfk_state(adevice);
473 else 475 else
474 ideapad_input_report(vpc_bit); 476 ideapad_input_report(priv, vpc_bit);
475 } 477 }
476 } 478 }
477} 479}