diff options
author | Daniel Drake <dsd@laptop.org> | 2011-08-10 16:45:36 -0400 |
---|---|---|
committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2011-08-19 13:03:24 -0400 |
commit | c3503fd02558245ebbb0b48f3ae1d62416e3fd2a (patch) | |
tree | 4349bcdaaff892a3aa5b9b56631295c3a4fd798b /drivers/power/olpc_battery.c | |
parent | 35c3ae5eef3fc641c75c5e1e4307835c8efa5f6b (diff) |
olpc_battery: Bind to device tree
This is cleaner, and allows suspend/resume (wakeup) handlers to be
added in an upcoming patch.
Signed-off-by: Daniel Drake <dsd@laptop.org>
Acked-by: Andres Salomon <dilinger@queued.net>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power/olpc_battery.c')
-rw-r--r-- | drivers/power/olpc_battery.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c index 0b0ff3a936a6..9972268fea72 100644 --- a/drivers/power/olpc_battery.c +++ b/drivers/power/olpc_battery.c | |||
@@ -519,9 +519,8 @@ static struct device_attribute olpc_bat_error = { | |||
519 | * Initialisation | 519 | * Initialisation |
520 | *********************************************************************/ | 520 | *********************************************************************/ |
521 | 521 | ||
522 | static struct platform_device *bat_pdev; | ||
523 | |||
524 | static struct power_supply olpc_bat = { | 522 | static struct power_supply olpc_bat = { |
523 | .name = "olpc-battery", | ||
525 | .get_property = olpc_bat_get_property, | 524 | .get_property = olpc_bat_get_property, |
526 | .use_for_apm = 1, | 525 | .use_for_apm = 1, |
527 | }; | 526 | }; |
@@ -534,14 +533,11 @@ void olpc_battery_trigger_uevent(unsigned long cause) | |||
534 | kobject_uevent(&olpc_bat.dev->kobj, KOBJ_CHANGE); | 533 | kobject_uevent(&olpc_bat.dev->kobj, KOBJ_CHANGE); |
535 | } | 534 | } |
536 | 535 | ||
537 | static int __init olpc_bat_init(void) | 536 | static int __devinit olpc_battery_probe(struct platform_device *pdev) |
538 | { | 537 | { |
539 | int ret = 0; | 538 | int ret; |
540 | uint8_t status; | 539 | uint8_t status; |
541 | 540 | ||
542 | if (!olpc_platform_info.ecver) | ||
543 | return -ENXIO; | ||
544 | |||
545 | /* | 541 | /* |
546 | * We've seen a number of EC protocol changes; this driver requires | 542 | * We've seen a number of EC protocol changes; this driver requires |
547 | * the latest EC protocol, supported by 0x44 and above. | 543 | * the latest EC protocol, supported by 0x44 and above. |
@@ -558,15 +554,10 @@ static int __init olpc_bat_init(void) | |||
558 | 554 | ||
559 | /* Ignore the status. It doesn't actually matter */ | 555 | /* Ignore the status. It doesn't actually matter */ |
560 | 556 | ||
561 | bat_pdev = platform_device_register_simple("olpc-battery", 0, NULL, 0); | 557 | ret = power_supply_register(&pdev->dev, &olpc_ac); |
562 | if (IS_ERR(bat_pdev)) | ||
563 | return PTR_ERR(bat_pdev); | ||
564 | |||
565 | ret = power_supply_register(&bat_pdev->dev, &olpc_ac); | ||
566 | if (ret) | 558 | if (ret) |
567 | goto ac_failed; | 559 | return ret; |
568 | 560 | ||
569 | olpc_bat.name = bat_pdev->name; | ||
570 | if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */ | 561 | if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */ |
571 | olpc_bat.properties = olpc_xo15_bat_props; | 562 | olpc_bat.properties = olpc_xo15_bat_props; |
572 | olpc_bat.num_properties = ARRAY_SIZE(olpc_xo15_bat_props); | 563 | olpc_bat.num_properties = ARRAY_SIZE(olpc_xo15_bat_props); |
@@ -575,7 +566,7 @@ static int __init olpc_bat_init(void) | |||
575 | olpc_bat.num_properties = ARRAY_SIZE(olpc_xo1_bat_props); | 566 | olpc_bat.num_properties = ARRAY_SIZE(olpc_xo1_bat_props); |
576 | } | 567 | } |
577 | 568 | ||
578 | ret = power_supply_register(&bat_pdev->dev, &olpc_bat); | 569 | ret = power_supply_register(&pdev->dev, &olpc_bat); |
579 | if (ret) | 570 | if (ret) |
580 | goto battery_failed; | 571 | goto battery_failed; |
581 | 572 | ||
@@ -587,7 +578,7 @@ static int __init olpc_bat_init(void) | |||
587 | if (ret) | 578 | if (ret) |
588 | goto error_failed; | 579 | goto error_failed; |
589 | 580 | ||
590 | goto success; | 581 | return 0; |
591 | 582 | ||
592 | error_failed: | 583 | error_failed: |
593 | device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom); | 584 | device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom); |
@@ -595,22 +586,44 @@ eeprom_failed: | |||
595 | power_supply_unregister(&olpc_bat); | 586 | power_supply_unregister(&olpc_bat); |
596 | battery_failed: | 587 | battery_failed: |
597 | power_supply_unregister(&olpc_ac); | 588 | power_supply_unregister(&olpc_ac); |
598 | ac_failed: | ||
599 | platform_device_unregister(bat_pdev); | ||
600 | success: | ||
601 | return ret; | 589 | return ret; |
602 | } | 590 | } |
603 | 591 | ||
604 | static void __exit olpc_bat_exit(void) | 592 | static int __devexit olpc_battery_remove(struct platform_device *pdev) |
605 | { | 593 | { |
606 | device_remove_file(olpc_bat.dev, &olpc_bat_error); | 594 | device_remove_file(olpc_bat.dev, &olpc_bat_error); |
607 | device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom); | 595 | device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom); |
608 | power_supply_unregister(&olpc_bat); | 596 | power_supply_unregister(&olpc_bat); |
609 | power_supply_unregister(&olpc_ac); | 597 | power_supply_unregister(&olpc_ac); |
610 | platform_device_unregister(bat_pdev); | 598 | return 0; |
611 | } | 599 | } |
612 | 600 | ||
601 | static const struct of_device_id olpc_battery_ids[] __devinitconst = { | ||
602 | { .compatible = "olpc,xo1-battery" }, | ||
603 | {} | ||
604 | }; | ||
605 | MODULE_DEVICE_TABLE(of, olpc_battery_ids); | ||
606 | |||
607 | static struct platform_driver olpc_battery_drv = { | ||
608 | .driver = { | ||
609 | .name = "olpc-battery", | ||
610 | .owner = THIS_MODULE, | ||
611 | .of_match_table = olpc_battery_ids, | ||
612 | }, | ||
613 | .probe = olpc_battery_probe, | ||
614 | .remove = __devexit_p(olpc_battery_remove), | ||
615 | }; | ||
616 | |||
617 | static int __init olpc_bat_init(void) | ||
618 | { | ||
619 | return platform_driver_register(&olpc_battery_drv); | ||
620 | } | ||
613 | module_init(olpc_bat_init); | 621 | module_init(olpc_bat_init); |
622 | |||
623 | static void __exit olpc_bat_exit(void) | ||
624 | { | ||
625 | platform_driver_unregister(&olpc_battery_drv); | ||
626 | } | ||
614 | module_exit(olpc_bat_exit); | 627 | module_exit(olpc_bat_exit); |
615 | 628 | ||
616 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); | 629 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); |