aboutsummaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2009-12-21 17:21:07 +0100
committerLars-Peter Clausen <lars@metafoo.de>2009-12-21 17:21:07 +0100
commit2cc59440a693edb5beb1195c109ecd101f47c7d6 (patch)
tree9f2b9dddce8ba40996453f9865b84a93ca2d98c2 /drivers/power
parent270f524f6162b047846c6756a4a67ab902ecef46 (diff)
parent80b69fcb9233a7643a3d1456c11edcae078a2e17 (diff)
Merge branch 'platform_battery-2.6.32' into om-gta02-2.6.32
Conflicts: drivers/power/Kconfig drivers/power/Makefile
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/Kconfig6
-rw-r--r--drivers/power/Makefile1
-rw-r--r--drivers/power/platform_battery.c119
3 files changed, 126 insertions, 0 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 9f6a8275e12..7cd71fcb0cc 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -121,5 +121,11 @@ config HDQ_GPIO_BITBANG
Say Y to enable supoort for generic gpio based HDQ bitbang driver.
This can not be built as a module.
+config BATTERY_PLATFORM
+ tristate "Platform battery driver"
+ help
+ Say Y here to include support for battery driver that gets all
+ information from platform functions.
+
endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 225abe32627..47f57ffef19 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -32,3 +32,4 @@ obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
obj-$(CONFIG_BATTERY_BQ27000_HDQ) += bq27000_battery.o
obj-$(CONFIG_HDQ_GPIO_BITBANG) += hdq.o
+obj-$(CONFIG_BATTERY_PLATFORM) += platform_battery.o
diff --git a/drivers/power/platform_battery.c b/drivers/power/platform_battery.c
new file mode 100644
index 00000000000..99e155a2057
--- /dev/null
+++ b/drivers/power/platform_battery.c
@@ -0,0 +1,119 @@
+/*
+ * Driver for platform battery
+ *
+ * Copyright (c) Paul Fertser <fercerpav@gmail.com>
+ * Inspired by Balaji Rao <balajirrao@openmoko.org>
+ *
+ * This driver can be used for dumb batteries when all knowledge about
+ * their state belongs to the platform that does necessary ADC readings,
+ * conversions, guessimations etc.
+ *
+ * Use consistent with the GNU GPL is permitted, provided that this
+ * copyright notice is preserved in its entirety in all copies and derived
+ * works.
+ */
+
+#include <linux/module.h>
+#include <linux/param.h>
+#include <linux/delay.h>
+#include <linux/workqueue.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+#include <linux/platform_battery.h>
+
+struct platform_battery {
+ struct power_supply psy;
+ struct platform_bat_platform_data *pdata;
+};
+
+static int platform_bat_get_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ union power_supply_propval *val)
+{
+ struct platform_battery *bat =
+ container_of(psy, struct platform_battery, psy);
+ size_t i;
+ int present=1;
+
+ if (bat->pdata->is_present)
+ present = bat->pdata->is_present();
+
+ if (psp != POWER_SUPPLY_PROP_PRESENT && !present)
+ return -ENODEV;
+
+ for (i = 0; i < psy->num_properties; i++)
+ if (psy->properties[i] == psp) {
+ val->intval = bat->pdata->get_property[i]();
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static void platform_bat_ext_changed(struct power_supply *psy)
+{
+ struct platform_battery *bat =
+ container_of(psy, struct platform_battery, psy);
+ power_supply_changed(&bat->psy);
+}
+
+static int platform_battery_probe(struct platform_device *pdev)
+{
+ struct platform_battery *platform_bat;
+ struct platform_bat_platform_data *pdata =
+ (struct platform_bat_platform_data *)pdev->dev.platform_data;
+
+ platform_bat = kzalloc(sizeof(*platform_bat), GFP_KERNEL);
+ if (!platform_bat)
+ return -ENOMEM;
+
+ if (pdata->name)
+ platform_bat->psy.name = pdata->name;
+ else
+ platform_bat->psy.name = dev_name(&pdev->dev);
+ platform_bat->psy.type = POWER_SUPPLY_TYPE_BATTERY;
+ platform_bat->psy.properties = pdata->properties;
+ platform_bat->psy.num_properties = pdata->num_properties;
+ platform_bat->psy.get_property = platform_bat_get_property;
+ platform_bat->psy.external_power_changed = platform_bat_ext_changed;
+
+ platform_bat->pdata = pdata;
+ platform_set_drvdata(pdev, platform_bat);
+ power_supply_register(&pdev->dev, &platform_bat->psy);
+
+ return 0;
+}
+
+static int platform_battery_remove(struct platform_device *pdev)
+{
+ struct platform_battery *bat = platform_get_drvdata(pdev);
+
+ power_supply_unregister(&bat->psy);
+ kfree(bat);
+
+ return 0;
+}
+
+static struct platform_driver platform_battery_driver = {
+ .driver = {
+ .name = "platform_battery",
+ },
+ .probe = platform_battery_probe,
+ .remove = platform_battery_remove,
+};
+
+static int __init platform_battery_init(void)
+{
+ return platform_driver_register(&platform_battery_driver);
+}
+module_init(platform_battery_init);
+
+static void __exit platform_battery_exit(void)
+{
+ platform_driver_unregister(&platform_battery_driver);
+}
+module_exit(platform_battery_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Paul Fertser <fercerpav@gmail.com>");
+MODULE_DESCRIPTION("platform battery driver");