All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] olpc_battery: convert to platform device
@ 2011-02-16 22:28 Daniel Drake
  2011-02-16 22:34 ` Dmitry Torokhov
  2011-02-16 22:44 ` David Woodhouse
  0 siblings, 2 replies; 51+ messages in thread
From: Daniel Drake @ 2011-02-16 22:28 UTC (permalink / raw)
  To: cbou, dwmw2
  Cc: linux-kernel, x86, tglx, mingo, hpa, dilinger, dmitry.torokhov

This is needed so that suspend/resume (wakeup) support can be added.

Signed-off-by: Daniel Drake <dsd@laptop.org>
---
 arch/x86/platform/olpc/olpc.c |   15 +++++++++++
 drivers/power/olpc_battery.c  |   53 +++++++++++++++++++++++-----------------
 2 files changed, 45 insertions(+), 23 deletions(-)

v2: add MODULE_ALIAS thanks to Dmitry Torokhov

v3: fix __devexit annotation thanks to Dmitry

diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
index edaf3fe..a5fb933 100644
--- a/arch/x86/platform/olpc/olpc.c
+++ b/arch/x86/platform/olpc/olpc.c
@@ -239,6 +239,17 @@ static int __init add_xo1_platform_devices(void)
 	return 0;
 }
 
+static int __init add_common_platform_devices(void)
+{
+	struct platform_device *pdev;
+
+	pdev = platform_device_register_simple("olpc-battery", -1, NULL, 0);
+	if (IS_ERR(pdev))
+		return PTR_ERR(pdev);
+
+	return 0;
+}
+
 static int __init olpc_init(void)
 {
 	int r = 0;
@@ -269,6 +280,10 @@ static int __init olpc_init(void)
 			olpc_platform_info.boardrev >> 4,
 			olpc_platform_info.ecver);
 
+	r = add_common_platform_devices();
+	if (r)
+		return r;
+
 	if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
 		r = add_xo1_platform_devices();
 		if (r)
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 0b0ff3a..18580b4 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -519,8 +519,6 @@ static struct device_attribute olpc_bat_error = {
  *		Initialisation
  *********************************************************************/
 
-static struct platform_device *bat_pdev;
-
 static struct power_supply olpc_bat = {
 	.get_property = olpc_bat_get_property,
 	.use_for_apm = 1,
@@ -534,14 +532,11 @@ void olpc_battery_trigger_uevent(unsigned long cause)
 		kobject_uevent(&olpc_bat.dev->kobj, KOBJ_CHANGE);
 }
 
-static int __init olpc_bat_init(void)
+static int __devinit olpc_battery_probe(struct platform_device *pdev)
 {
-	int ret = 0;
+	int ret;
 	uint8_t status;
 
-	if (!olpc_platform_info.ecver)
-		return -ENXIO;
-
 	/*
 	 * We've seen a number of EC protocol changes; this driver requires
 	 * the latest EC protocol, supported by 0x44 and above.
@@ -552,21 +547,16 @@ static int __init olpc_bat_init(void)
 		return -ENXIO;
 	}
 
+	/* Ignore the status. It doesn't actually matter */
 	ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &status, 1);
 	if (ret)
 		return ret;
 
-	/* Ignore the status. It doesn't actually matter */
-
-	bat_pdev = platform_device_register_simple("olpc-battery", 0, NULL, 0);
-	if (IS_ERR(bat_pdev))
-		return PTR_ERR(bat_pdev);
-
-	ret = power_supply_register(&bat_pdev->dev, &olpc_ac);
+	ret = power_supply_register(&pdev->dev, &olpc_ac);
 	if (ret)
-		goto ac_failed;
+		return ret;
 
-	olpc_bat.name = bat_pdev->name;
+	olpc_bat.name = pdev->name;
 	if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */
 		olpc_bat.properties = olpc_xo15_bat_props;
 		olpc_bat.num_properties = ARRAY_SIZE(olpc_xo15_bat_props);
@@ -575,7 +565,7 @@ static int __init olpc_bat_init(void)
 		olpc_bat.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
 	}
 
-	ret = power_supply_register(&bat_pdev->dev, &olpc_bat);
+	ret = power_supply_register(&pdev->dev, &olpc_bat);
 	if (ret)
 		goto battery_failed;
 
@@ -587,7 +577,7 @@ static int __init olpc_bat_init(void)
 	if (ret)
 		goto error_failed;
 
-	goto success;
+	return 0;
 
 error_failed:
 	device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
@@ -595,19 +585,35 @@ eeprom_failed:
 	power_supply_unregister(&olpc_bat);
 battery_failed:
 	power_supply_unregister(&olpc_ac);
-ac_failed:
-	platform_device_unregister(bat_pdev);
-success:
 	return ret;
 }
 
-static void __exit olpc_bat_exit(void)
+static int __devexit olpc_battery_remove(struct platform_device *pdev)
 {
 	device_remove_file(olpc_bat.dev, &olpc_bat_error);
 	device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
 	power_supply_unregister(&olpc_bat);
 	power_supply_unregister(&olpc_ac);
-	platform_device_unregister(bat_pdev);
+	return 0;
+}
+
+static struct platform_driver olpc_battery_drv = {
+	.driver = {
+		.name = "olpc-battery",
+		.owner = THIS_MODULE,
+	},
+	.probe = olpc_battery_probe,
+	.remove = __devexit_p(olpc_battery_remove),
+};
+
+static int __init olpc_bat_init(void)
+{
+	return platform_driver_register(&olpc_battery_drv);
+}
+
+static void __exit olpc_bat_exit(void)
+{
+	platform_driver_unregister(&olpc_battery_drv);
 }
 
 module_init(olpc_bat_init);
@@ -616,3 +622,4 @@ module_exit(olpc_bat_exit);
 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Battery driver for One Laptop Per Child 'XO' machine");
+MODULE_ALIAS("platform:olpc-battery");
-- 
1.7.4


^ permalink raw reply related	[flat|nested] 51+ messages in thread

end of thread, other threads:[~2011-02-24  6:38 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-16 22:28 [PATCH v3] olpc_battery: convert to platform device Daniel Drake
2011-02-16 22:34 ` Dmitry Torokhov
2011-02-16 22:44 ` David Woodhouse
2011-02-16 23:39   ` H. Peter Anvin
2011-02-18 23:42   ` Daniel Drake
2011-02-19  3:06     ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-19  3:06       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Andres Salomon
2011-02-19  3:06       ` Andres Salomon
2011-02-19  3:12       ` [PATCH] of/pdt: don't bother parsing pkg2path results, return as-is Andres Salomon
2011-02-19  3:12         ` Andres Salomon
2011-02-19  3:12         ` Andres Salomon
2011-02-23 19:45         ` [PATCH] of/pdt: don't bother parsing pkg2path results, return Grant Likely
2011-02-23 19:45           ` [PATCH] of/pdt: don't bother parsing pkg2path results, return as-is Grant Likely
2011-02-23 19:45           ` Grant Likely
2011-02-23 19:43       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-23 19:43         ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Grant Likely
2011-02-23 19:43         ` Grant Likely
2011-02-23 19:54         ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-23 19:54           ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Andres Salomon
2011-02-23 19:54           ` Andres Salomon
2011-02-23 20:06           ` Daniel Drake
2011-02-23 20:06             ` Daniel Drake
     [not found]             ` <AANLkTi=D1eWGsN4JVWEGeHp3AXfpbOOKr9Fq7juGAXtT-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-23 20:37               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-23 20:37                 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Grant Likely
2011-02-23 20:37                 ` Grant Likely
2011-02-23 20:35           ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-23 20:35             ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Grant Likely
2011-02-23 23:03       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-23 23:03         ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Andres Salomon
     [not found]         ` <20110223150357.5a40793d-pFFUokh25LWsTnJN9+BGXg@public.gmane.org>
2011-02-23 23:28           ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-23 23:28             ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Grant Likely
2011-02-23 23:28             ` Grant Likely
2011-02-24  0:16             ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  0:16               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Andres Salomon
2011-02-24  4:06               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-24  4:06                 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Grant Likely
     [not found]                 ` <20110224040638.GB22111-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>
2011-02-24  4:36                   ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  4:36                     ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Andres Salomon
2011-02-24  4:36                     ` Andres Salomon
2011-02-24  5:38                     ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-24  5:38                       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Grant Likely
2011-02-24  6:38                       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  6:38                         ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v4) Andres Salomon
2011-02-24  0:34             ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  0:34               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) Andres Salomon
2011-02-24  2:47               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-24  2:47                 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) Grant Likely
2011-02-24  2:51                 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  2:51                   ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) Andres Salomon
2011-02-24  3:25                   ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-24  3:25                     ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) Grant Likely

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.