aboutsummaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/Kconfig6
-rw-r--r--drivers/power/Makefile1
-rw-r--r--drivers/power/pcf50606-charger.c260
3 files changed, 267 insertions, 0 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 04112c71a9b..16fe5304b8f 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -114,6 +114,12 @@ 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 CHARGER_PCF50606
+ tristate "Support for NXP PCF50606 MBC"
+ depends on MFD_PCF50606
+ help
+ Say Y to include support for NXP PCF50606 Battery Charger.
+
config BATTERY_PLATFORM
tristate "Platform battery driver"
help
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 2ec51dc7047..63981273a77 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o
obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o
obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o
obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
+obj-$(CONFIG_CHARGER_PCF50606) += pcf50606-charger.o
obj-$(CONFIG_BATTERY_PLATFORM) += platform_battery.o
obj-$(CONFIG_BATTERY_BQ27000_HDQ) += bq27000_battery.o
diff --git a/drivers/power/pcf50606-charger.c b/drivers/power/pcf50606-charger.c
new file mode 100644
index 00000000000..a4b77950788
--- /dev/null
+++ b/drivers/power/pcf50606-charger.c
@@ -0,0 +1,260 @@
+/* NXP PCF50606 Main Battery Charger Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50606 driver mainly by
+ * Harald Welte, Andy Green and Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/mfd/pcf50606/mbc.h>
+
+struct pcf50606_mbc {
+ struct pcf50606 *pcf;
+
+ int charger_online;
+ struct power_supply charger;
+};
+
+int pcf50606_charge_fast(struct pcf50606 *pcf, int on)
+{
+ struct pcf50606_mbc *mbc = platform_get_drvdata(pcf->mbc_pdev);
+
+ /*
+ * This is a fix to work around boot-time ordering problems if
+ * the s3c2410_udc is initialized before the pcf50606 mbc is
+ * ready.
+ */
+ if (!mbc)
+ return -ENODEV;
+
+ if (on) {
+ pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_MBCC1,
+ PCF50606_MBCC1_AUTOFST,
+ PCF50606_MBCC1_AUTOFST);\
+ mbc->charger_online = 1;
+ } else {
+ /* disable automatic fast-charge */
+ pcf50606_reg_clear_bits(pcf, PCF50606_REG_MBCC1,
+ PCF50606_MBCC1_AUTOFST);
+ /* switch to idle mode to abort existing charge process */
+ pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_MBCC1,
+ PCF50606_MBCC1_CHGMOD_MASK,
+ PCF50606_MBCC1_CHGMOD_IDLE);
+ mbc->charger_online = 0;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pcf50606_charge_fast);
+
+static const char *charge_mode_descs[] = {
+ "qualification",
+ "pre",
+ "trickle",
+ "fast_cccv",
+ "idle",
+};
+
+static ssize_t
+show_charge_mode(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct pcf50606_mbc *mbc = dev_get_drvdata(dev);
+ const char **desc = charge_mode_descs;
+
+ uint8_t charge_mode = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1);
+ charge_mode &= PCF50606_MBCC1_CHGMOD_MASK;
+ switch (charge_mode) {
+ case PCF50606_MBCC1_CHGMOD_IDLE:
+ ++desc;
+ case PCF50606_MBCC1_CHGMOD_FAST_CCCV:
+ ++desc;
+ case PCF50606_MBCC1_CHGMOD_TRICKLE:
+ ++desc;
+ case PCF50606_MBCC1_CHGMOD_PRE:
+ ++desc;
+ case PCF50606_MBCC1_CHGMOD_QUAL:
+ return sprintf(buf, "%s\n", *desc);
+ break;
+ default:
+ return sprintf(buf, "unkown: %d\n", charge_mode);
+ break;
+ }
+}
+
+static ssize_t set_charge_mode(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct pcf50606_mbc *mbc = dev_get_drvdata(dev);
+ uint8_t mbcc1 = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1);
+
+ mbcc1 &= ~PCF50606_MBCC1_CHGMOD_MASK;
+
+ if (!strcmp(buf, "qualification"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_QUAL;
+ else if (!strcmp(buf, "pre"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_PRE;
+ else if (!strcmp(buf, "trickle"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_TRICKLE;
+ else if (!strcmp(buf, "fast_cccv"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_FAST_CCCV;
+ /* We don't allow the other fast modes for security reasons */
+ else if (!strcmp(buf, "idle"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_IDLE;
+ else
+ return -EINVAL;
+
+ pcf50606_reg_write(mbc->pcf, PCF50606_REG_MBCC1, mbcc1);
+
+ return count;
+}
+
+static DEVICE_ATTR(charge_mode, S_IRUGO | S_IWUSR, show_charge_mode, set_charge_mode);
+
+static void
+pcf50606_mbc_irq_handler(int irq, void *data)
+{
+ struct pcf50606_mbc *mbc = data;
+
+ power_supply_changed(&mbc->charger);
+
+ if (mbc->pcf->pdata->mbc_event_callback)
+ mbc->pcf->pdata->mbc_event_callback(mbc->pcf, irq);
+}
+
+static int charger_get_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ union power_supply_propval *val)
+{
+ struct pcf50606_mbc *mbc = container_of(psy, struct pcf50606_mbc, charger);
+ int ret = 0;
+
+ switch (psp) {
+ case POWER_SUPPLY_PROP_ONLINE:
+ val->intval = mbc->charger_online;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+ return ret;
+}
+
+static enum power_supply_property power_props[] = {
+ POWER_SUPPLY_PROP_ONLINE,
+};
+
+static const uint8_t mbc_irq_handlers[] = {
+ PCF50606_IRQ_CHGINS,
+ PCF50606_IRQ_CHGRM,
+ PCF50606_IRQ_CHGFOK,
+ PCF50606_IRQ_CHGERR,
+ PCF50606_IRQ_CHGFRDY,
+ PCF50606_IRQ_CHGPROT,
+};
+
+static int __devinit pcf50606_mbc_probe(struct platform_device *pdev)
+{
+ struct pcf50606_mbc *mbc;
+ int ret;
+ size_t i;
+ uint8_t oocs;
+
+ mbc = kzalloc(sizeof(*mbc), GFP_KERNEL);
+ if (!mbc)
+ return -ENOMEM;
+
+ mbc->pcf = dev_to_pcf50606(pdev->dev.parent);
+
+ mbc->charger.name = "charger";
+ mbc->charger.type = POWER_SUPPLY_TYPE_MAINS;
+ mbc->charger.properties = power_props;
+ mbc->charger.num_properties = ARRAY_SIZE(power_props);
+ mbc->charger.get_property = &charger_get_property;
+ mbc->charger.supplied_to = mbc->pcf->pdata->batteries;
+ mbc->charger.num_supplicants = mbc->pcf->pdata->num_batteries;
+
+ ret = power_supply_register(&pdev->dev, &mbc->charger);
+ if (ret) {
+ dev_err(mbc->pcf->dev, "failed to register charger\n");
+ kfree(mbc);
+ return ret;
+ }
+
+ /* Set up IRQ handlers */
+ for (i = 0; i < ARRAY_SIZE(mbc_irq_handlers); i++)
+ pcf50606_register_irq(mbc->pcf, mbc_irq_handlers[i],
+ pcf50606_mbc_irq_handler, mbc);
+
+ ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_charge_mode.attr);
+ if (ret)
+ dev_err(mbc->pcf->dev, "failed to create sysfs entries\n");
+
+ oocs = pcf50606_reg_read(mbc->pcf, PCF50606_REG_OOCS);
+ if (oocs & PCF50606_OOCS_CHGOK)
+ pcf50606_mbc_irq_handler(PCF50606_IRQ_CHGINS, mbc);
+
+ platform_set_drvdata(pdev, mbc);
+
+ return 0;
+}
+
+static int __devexit pcf50606_mbc_remove(struct platform_device *pdev)
+{
+ struct pcf50606_mbc *mbc = platform_get_drvdata(pdev);
+ size_t i;
+
+ /* Remove IRQ handlers */
+ for (i = 0; i < ARRAY_SIZE(mbc_irq_handlers); i++)
+ pcf50606_free_irq(mbc->pcf, mbc_irq_handlers[i]);
+
+ power_supply_unregister(&mbc->charger);
+
+ platform_set_drvdata(pdev, NULL);
+ kfree(mbc);
+
+ return 0;
+}
+
+static struct platform_driver pcf50606_mbc_driver = {
+ .driver = {
+ .name = "pcf50606-mbc",
+ .owner = THIS_MODULE,
+ },
+ .probe = pcf50606_mbc_probe,
+ .remove = __devexit_p(pcf50606_mbc_remove),
+};
+
+static int __init pcf50606_mbc_init(void)
+{
+ return platform_driver_register(&pcf50606_mbc_driver);
+}
+module_init(pcf50606_mbc_init);
+
+static void __exit pcf50606_mbc_exit(void)
+{
+ platform_driver_unregister(&pcf50606_mbc_driver);
+}
+module_exit(pcf50606_mbc_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
+MODULE_DESCRIPTION("PCF50606 mbc driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50606-mbc");