]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge remote-tracking branch 'battery/master'
authorStephen Rothwell <sfr@canb.auug.org.au>
Wed, 3 Oct 2012 04:29:55 +0000 (14:29 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 3 Oct 2012 04:29:55 +0000 (14:29 +1000)
Conflicts:
include/linux/mfd/88pm860x.h

1  2 
drivers/mfd/88pm860x-core.c
drivers/power/Kconfig
drivers/power/Makefile
drivers/power/ab8500_btemp.c
drivers/power/ab8500_charger.c
drivers/power/ab8500_fg.c
drivers/power/charger-manager.c
drivers/power/wm97xx_battery.c
include/linux/mfd/88pm860x.h

index 59d117e9fa313840bfc95190b3e9160e8deec742,2abd607eb05b53396490ea4420af17328b596dd9..8fa86edf70d46ae77d7e47589b6641a3e411ba58
  
  #include <linux/kernel.h>
  #include <linux/module.h>
 +#include <linux/err.h>
  #include <linux/i2c.h>
  #include <linux/irq.h>
  #include <linux/interrupt.h>
 +#include <linux/irqdomain.h>
 +#include <linux/of.h>
 +#include <linux/of_platform.h>
  #include <linux/platform_device.h>
 +#include <linux/regmap.h>
 +#include <linux/slab.h>
  #include <linux/mfd/core.h>
  #include <linux/mfd/88pm860x.h>
  #include <linux/regulator/machine.h>
+ #include <linux/power/charger-manager.h>
  
  #define INT_STATUS_NUM                        3
  
 -static struct resource bk_resources[] __devinitdata = {
 -      {PM8606_BACKLIGHT1, PM8606_BACKLIGHT1, "backlight-0", IORESOURCE_IO,},
 -      {PM8606_BACKLIGHT2, PM8606_BACKLIGHT2, "backlight-1", IORESOURCE_IO,},
 -      {PM8606_BACKLIGHT3, PM8606_BACKLIGHT3, "backlight-2", IORESOURCE_IO,},
 -};
 -
 -static struct resource led_resources[] __devinitdata = {
 -      {PM8606_LED1_RED,   PM8606_LED1_RED,   "led0-red",   IORESOURCE_IO,},
 -      {PM8606_LED1_GREEN, PM8606_LED1_GREEN, "led0-green", IORESOURCE_IO,},
 -      {PM8606_LED1_BLUE,  PM8606_LED1_BLUE,  "led0-blue",  IORESOURCE_IO,},
 -      {PM8606_LED2_RED,   PM8606_LED2_RED,   "led1-red",   IORESOURCE_IO,},
 -      {PM8606_LED2_GREEN, PM8606_LED2_GREEN, "led1-green", IORESOURCE_IO,},
 -      {PM8606_LED2_BLUE,  PM8606_LED2_BLUE,  "led1-blue",  IORESOURCE_IO,},
 -};
 -
 -static struct resource regulator_resources[] __devinitdata = {
 -      {PM8607_ID_BUCK1, PM8607_ID_BUCK1, "buck-1", IORESOURCE_IO,},
 -      {PM8607_ID_BUCK2, PM8607_ID_BUCK2, "buck-2", IORESOURCE_IO,},
 -      {PM8607_ID_BUCK3, PM8607_ID_BUCK3, "buck-3", IORESOURCE_IO,},
 -      {PM8607_ID_LDO1,  PM8607_ID_LDO1,  "ldo-01", IORESOURCE_IO,},
 -      {PM8607_ID_LDO2,  PM8607_ID_LDO2,  "ldo-02", IORESOURCE_IO,},
 -      {PM8607_ID_LDO3,  PM8607_ID_LDO3,  "ldo-03", IORESOURCE_IO,},
 -      {PM8607_ID_LDO4,  PM8607_ID_LDO4,  "ldo-04", IORESOURCE_IO,},
 -      {PM8607_ID_LDO5,  PM8607_ID_LDO5,  "ldo-05", IORESOURCE_IO,},
 -      {PM8607_ID_LDO6,  PM8607_ID_LDO6,  "ldo-06", IORESOURCE_IO,},
 -      {PM8607_ID_LDO7,  PM8607_ID_LDO7,  "ldo-07", IORESOURCE_IO,},
 -      {PM8607_ID_LDO8,  PM8607_ID_LDO8,  "ldo-08", IORESOURCE_IO,},
 -      {PM8607_ID_LDO9,  PM8607_ID_LDO9,  "ldo-09", IORESOURCE_IO,},
 -      {PM8607_ID_LDO10, PM8607_ID_LDO10, "ldo-10", IORESOURCE_IO,},
 -      {PM8607_ID_LDO11, PM8607_ID_LDO11, "ldo-11", IORESOURCE_IO,},
 -      {PM8607_ID_LDO12, PM8607_ID_LDO12, "ldo-12", IORESOURCE_IO,},
 -      {PM8607_ID_LDO13, PM8607_ID_LDO13, "ldo-13", IORESOURCE_IO,},
 -      {PM8607_ID_LDO14, PM8607_ID_LDO14, "ldo-14", IORESOURCE_IO,},
 -      {PM8607_ID_LDO15, PM8607_ID_LDO15, "ldo-15", IORESOURCE_IO,},
 +static struct resource bk0_resources[] __devinitdata = {
 +      {2, 2, "duty cycle", IORESOURCE_REG, },
 +      {3, 3, "always on",  IORESOURCE_REG, },
 +      {3, 3, "current",    IORESOURCE_REG, },
 +};
 +static struct resource bk1_resources[] __devinitdata = {
 +      {4, 4, "duty cycle", IORESOURCE_REG, },
 +      {5, 5, "always on",  IORESOURCE_REG, },
 +      {5, 5, "current",    IORESOURCE_REG, },
 +};
 +static struct resource bk2_resources[] __devinitdata = {
 +      {6, 6, "duty cycle", IORESOURCE_REG, },
 +      {7, 7, "always on",  IORESOURCE_REG, },
 +      {5, 5, "current",    IORESOURCE_REG, },
 +};
 +
 +static struct resource led0_resources[] __devinitdata = {
 +      /* RGB1 Red LED */
 +      {0xd, 0xd, "control", IORESOURCE_REG, },
 +      {0xc, 0xc, "blink",   IORESOURCE_REG, },
 +};
 +static struct resource led1_resources[] __devinitdata = {
 +      /* RGB1 Green LED */
 +      {0xe, 0xe, "control", IORESOURCE_REG, },
 +      {0xc, 0xc, "blink",   IORESOURCE_REG, },
 +};
 +static struct resource led2_resources[] __devinitdata = {
 +      /* RGB1 Blue LED */
 +      {0xf, 0xf, "control", IORESOURCE_REG, },
 +      {0xc, 0xc, "blink",   IORESOURCE_REG, },
 +};
 +static struct resource led3_resources[] __devinitdata = {
 +      /* RGB2 Red LED */
 +      {0x9, 0x9, "control", IORESOURCE_REG, },
 +      {0x8, 0x8, "blink",   IORESOURCE_REG, },
 +};
 +static struct resource led4_resources[] __devinitdata = {
 +      /* RGB2 Green LED */
 +      {0xa, 0xa, "control", IORESOURCE_REG, },
 +      {0x8, 0x8, "blink",   IORESOURCE_REG, },
 +};
 +static struct resource led5_resources[] __devinitdata = {
 +      /* RGB2 Blue LED */
 +      {0xb, 0xb, "control", IORESOURCE_REG, },
 +      {0x8, 0x8, "blink",   IORESOURCE_REG, },
 +};
 +
 +static struct resource buck1_resources[] __devinitdata = {
 +      {0x24, 0x24, "buck set", IORESOURCE_REG, },
 +};
 +static struct resource buck2_resources[] __devinitdata = {
 +      {0x25, 0x25, "buck set", IORESOURCE_REG, },
 +};
 +static struct resource buck3_resources[] __devinitdata = {
 +      {0x26, 0x26, "buck set", IORESOURCE_REG, },
 +};
 +static struct resource ldo1_resources[] __devinitdata = {
 +      {0x10, 0x10, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo2_resources[] __devinitdata = {
 +      {0x11, 0x11, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo3_resources[] __devinitdata = {
 +      {0x12, 0x12, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo4_resources[] __devinitdata = {
 +      {0x13, 0x13, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo5_resources[] __devinitdata = {
 +      {0x14, 0x14, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo6_resources[] __devinitdata = {
 +      {0x15, 0x15, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo7_resources[] __devinitdata = {
 +      {0x16, 0x16, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo8_resources[] __devinitdata = {
 +      {0x17, 0x17, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo9_resources[] __devinitdata = {
 +      {0x18, 0x18, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo10_resources[] __devinitdata = {
 +      {0x19, 0x19, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo12_resources[] __devinitdata = {
 +      {0x1a, 0x1a, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo_vibrator_resources[] __devinitdata = {
 +      {0x28, 0x28, "ldo set", IORESOURCE_REG, },
 +};
 +static struct resource ldo14_resources[] __devinitdata = {
 +      {0x1b, 0x1b, "ldo set", IORESOURCE_REG, },
  };
  
  static struct resource touch_resources[] __devinitdata = {
@@@ -150,151 -85,55 +151,152 @@@ static struct resource battery_resource
  static struct resource charger_resources[] __devinitdata = {
        {PM8607_IRQ_CHG,  PM8607_IRQ_CHG,  "charger detect",  IORESOURCE_IRQ,},
        {PM8607_IRQ_CHG_DONE,  PM8607_IRQ_CHG_DONE,  "charging done",       IORESOURCE_IRQ,},
-       {PM8607_IRQ_CHG_FAULT, PM8607_IRQ_CHG_FAULT, "charging timeout",    IORESOURCE_IRQ,},
+       {PM8607_IRQ_CHG_FAIL,  PM8607_IRQ_CHG_FAIL,  "charging timeout",    IORESOURCE_IRQ,},
+       {PM8607_IRQ_CHG_FAULT, PM8607_IRQ_CHG_FAULT, "charging fault",      IORESOURCE_IRQ,},
        {PM8607_IRQ_GPADC1,    PM8607_IRQ_GPADC1,    "battery temperature", IORESOURCE_IRQ,},
        {PM8607_IRQ_VBAT, PM8607_IRQ_VBAT, "battery voltage", IORESOURCE_IRQ,},
        {PM8607_IRQ_VCHG, PM8607_IRQ_VCHG, "vchg voltage",    IORESOURCE_IRQ,},
  };
  
 -static struct resource preg_resources[] __devinitdata = {
 -      {PM8606_ID_PREG,  PM8606_ID_PREG,  "preg",   IORESOURCE_IO,},
 -};
 -
  static struct resource rtc_resources[] __devinitdata = {
        {PM8607_IRQ_RTC, PM8607_IRQ_RTC, "rtc", IORESOURCE_IRQ,},
  };
  
 -static struct mfd_cell bk_devs[] = {
 -      {"88pm860x-backlight", 0,},
 -      {"88pm860x-backlight", 1,},
 -      {"88pm860x-backlight", 2,},
 -};
 -
 -static struct mfd_cell led_devs[] = {
 -      {"88pm860x-led", 0,},
 -      {"88pm860x-led", 1,},
 -      {"88pm860x-led", 2,},
 -      {"88pm860x-led", 3,},
 -      {"88pm860x-led", 4,},
 -      {"88pm860x-led", 5,},
 -};
 -
 -static struct mfd_cell regulator_devs[] = {
 -      {"88pm860x-regulator", 0,},
 -      {"88pm860x-regulator", 1,},
 -      {"88pm860x-regulator", 2,},
 -      {"88pm860x-regulator", 3,},
 -      {"88pm860x-regulator", 4,},
 -      {"88pm860x-regulator", 5,},
 -      {"88pm860x-regulator", 6,},
 -      {"88pm860x-regulator", 7,},
 -      {"88pm860x-regulator", 8,},
 -      {"88pm860x-regulator", 9,},
 -      {"88pm860x-regulator", 10,},
 -      {"88pm860x-regulator", 11,},
 -      {"88pm860x-regulator", 12,},
 -      {"88pm860x-regulator", 13,},
 -      {"88pm860x-regulator", 14,},
 -      {"88pm860x-regulator", 15,},
 -      {"88pm860x-regulator", 16,},
 -      {"88pm860x-regulator", 17,},
 +static struct mfd_cell bk_devs[] __devinitdata = {
 +      {
 +              .name = "88pm860x-backlight",
 +              .id = 0,
 +              .num_resources = ARRAY_SIZE(bk0_resources),
 +              .resources = bk0_resources,
 +      }, {
 +              .name = "88pm860x-backlight",
 +              .id = 1,
 +              .num_resources = ARRAY_SIZE(bk1_resources),
 +              .resources = bk1_resources,
 +      }, {
 +              .name = "88pm860x-backlight",
 +              .id = 2,
 +              .num_resources = ARRAY_SIZE(bk2_resources),
 +              .resources = bk2_resources,
 +      },
 +};
 +
 +static struct mfd_cell led_devs[] __devinitdata = {
 +      {
 +              .name = "88pm860x-led",
 +              .id = 0,
 +              .num_resources = ARRAY_SIZE(led0_resources),
 +              .resources = led0_resources,
 +      }, {
 +              .name = "88pm860x-led",
 +              .id = 1,
 +              .num_resources = ARRAY_SIZE(led1_resources),
 +              .resources = led1_resources,
 +      }, {
 +              .name = "88pm860x-led",
 +              .id = 2,
 +              .num_resources = ARRAY_SIZE(led2_resources),
 +              .resources = led2_resources,
 +      }, {
 +              .name = "88pm860x-led",
 +              .id = 3,
 +              .num_resources = ARRAY_SIZE(led3_resources),
 +              .resources = led3_resources,
 +      }, {
 +              .name = "88pm860x-led",
 +              .id = 4,
 +              .num_resources = ARRAY_SIZE(led4_resources),
 +              .resources = led4_resources,
 +      }, {
 +              .name = "88pm860x-led",
 +              .id = 5,
 +              .num_resources = ARRAY_SIZE(led5_resources),
 +              .resources = led5_resources,
 +      },
 +};
 +
 +static struct mfd_cell reg_devs[] __devinitdata = {
 +      {
 +              .name = "88pm860x-regulator",
 +              .id = 0,
 +              .num_resources = ARRAY_SIZE(buck1_resources),
 +              .resources = buck1_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 1,
 +              .num_resources = ARRAY_SIZE(buck2_resources),
 +              .resources = buck2_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 2,
 +              .num_resources = ARRAY_SIZE(buck3_resources),
 +              .resources = buck3_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 3,
 +              .num_resources = ARRAY_SIZE(ldo1_resources),
 +              .resources = ldo1_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 4,
 +              .num_resources = ARRAY_SIZE(ldo2_resources),
 +              .resources = ldo2_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 5,
 +              .num_resources = ARRAY_SIZE(ldo3_resources),
 +              .resources = ldo3_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 6,
 +              .num_resources = ARRAY_SIZE(ldo4_resources),
 +              .resources = ldo4_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 7,
 +              .num_resources = ARRAY_SIZE(ldo5_resources),
 +              .resources = ldo5_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 8,
 +              .num_resources = ARRAY_SIZE(ldo6_resources),
 +              .resources = ldo6_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 9,
 +              .num_resources = ARRAY_SIZE(ldo7_resources),
 +              .resources = ldo7_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 10,
 +              .num_resources = ARRAY_SIZE(ldo8_resources),
 +              .resources = ldo8_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 11,
 +              .num_resources = ARRAY_SIZE(ldo9_resources),
 +              .resources = ldo9_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 12,
 +              .num_resources = ARRAY_SIZE(ldo10_resources),
 +              .resources = ldo10_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 13,
 +              .num_resources = ARRAY_SIZE(ldo12_resources),
 +              .resources = ldo12_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 14,
 +              .num_resources = ARRAY_SIZE(ldo_vibrator_resources),
 +              .resources = ldo_vibrator_resources,
 +      }, {
 +              .name = "88pm860x-regulator",
 +              .id = 15,
 +              .num_resources = ARRAY_SIZE(ldo14_resources),
 +              .resources = ldo14_resources,
 +      },
  };
  
  static struct mfd_cell touch_devs[] = {
@@@ -318,10 -157,15 +320,15 @@@ static struct regulator_init_data preg_
        .consumer_supplies      = &preg_supply[0],
  };
  
+ static struct charger_regulator chg_desc_regulator_data[] = {
+       { .regulator_name = "preg", },
+ };
  static struct mfd_cell power_devs[] = {
        {"88pm860x-battery", -1,},
        {"88pm860x-charger", -1,},
        {"88pm860x-preg",    -1,},
+       {"charger-manager", -1,},
  };
  
  static struct mfd_cell rtc_devs[] = {
@@@ -523,12 -367,15 +530,12 @@@ static void pm860x_irq_sync_unlock(stru
  
  static void pm860x_irq_enable(struct irq_data *data)
  {
 -      struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
 -      pm860x_irqs[data->irq - chip->irq_base].enable
 -              = pm860x_irqs[data->irq - chip->irq_base].offs;
 +      pm860x_irqs[data->hwirq].enable = pm860x_irqs[data->hwirq].offs;
  }
  
  static void pm860x_irq_disable(struct irq_data *data)
  {
 -      struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
 -      pm860x_irqs[data->irq - chip->irq_base].enable = 0;
 +      pm860x_irqs[data->hwirq].enable = 0;
  }
  
  static struct irq_chip pm860x_irq_chip = {
        .irq_disable    = pm860x_irq_disable,
  };
  
 -static int __devinit device_gpadc_init(struct pm860x_chip *chip,
 -                                     struct pm860x_platform_data *pdata)
 +static int pm860x_irq_domain_map(struct irq_domain *d, unsigned int virq,
 +                               irq_hw_number_t hw)
  {
 -      struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
 -                              : chip->companion;
 -      int data;
 -      int ret;
 -
 -      /* initialize GPADC without activating it */
 -
 -      if (!pdata || !pdata->touch)
 -              return -EINVAL;
 -
 -      /* set GPADC MISC1 register */
 -      data = 0;
 -      data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK;
 -      data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK;
 -      data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK;
 -      data |= (pdata->touch->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK;
 -      if (data) {
 -              ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
 -              if (ret < 0)
 -                      goto out;
 -      }
 -      /* set tsi prebias time */
 -      if (pdata->touch->tsi_prebias) {
 -              data = pdata->touch->tsi_prebias;
 -              ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
 -              if (ret < 0)
 -                      goto out;
 -      }
 -      /* set prebias & prechg time of pen detect */
 -      data = 0;
 -      data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
 -      data |= (pdata->touch->pen_prechg << 5) & PM8607_PD_PRECHG_MASK;
 -      if (data) {
 -              ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
 -              if (ret < 0)
 -                      goto out;
 -      }
 -
 -      ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
 -                            PM8607_GPADC_EN, PM8607_GPADC_EN);
 -out:
 -      return ret;
 +      irq_set_chip_data(virq, d->host_data);
 +      irq_set_chip_and_handler(virq, &pm860x_irq_chip, handle_edge_irq);
 +      irq_set_nested_thread(virq, 1);
 +#ifdef CONFIG_ARM
 +      set_irq_flags(virq, IRQF_VALID);
 +#else
 +      irq_set_noprobe(virq);
 +#endif
 +      return 0;
  }
  
 +static struct irq_domain_ops pm860x_irq_domain_ops = {
 +      .map    = pm860x_irq_domain_map,
 +      .xlate  = irq_domain_xlate_onetwocell,
 +};
 +
  static int __devinit device_irq_init(struct pm860x_chip *chip,
                                     struct pm860x_platform_data *pdata)
  {
                                : chip->companion;
        unsigned char status_buf[INT_STATUS_NUM];
        unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
 -      int i, data, mask, ret = -EINVAL;
 -      int __irq;
 -
 -      if (!pdata || !pdata->irq_base) {
 -              dev_warn(chip->dev, "No interrupt support on IRQ base\n");
 -              return -EINVAL;
 -      }
 +      int data, mask, ret = -EINVAL;
 +      int nr_irqs, irq_base = -1;
 +      struct device_node *node = i2c->dev.of_node;
  
        mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR
                | PM8607_B0_MISC1_INT_MASK;
                goto out;
  
        mutex_init(&chip->irq_lock);
 -      chip->irq_base = pdata->irq_base;
 +
 +      if (pdata && pdata->irq_base)
 +              irq_base = pdata->irq_base;
 +      nr_irqs = ARRAY_SIZE(pm860x_irqs);
 +      chip->irq_base = irq_alloc_descs(irq_base, 0, nr_irqs, 0);
 +      if (chip->irq_base < 0) {
 +              dev_err(&i2c->dev, "Failed to allocate interrupts, ret:%d\n",
 +                      chip->irq_base);
 +              ret = -EBUSY;
 +              goto out;
 +      }
 +      irq_domain_add_legacy(node, nr_irqs, chip->irq_base, 0,
 +                            &pm860x_irq_domain_ops, chip);
        chip->core_irq = i2c->irq;
        if (!chip->core_irq)
                goto out;
  
 -      /* register IRQ by genirq */
 -      for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
 -              __irq = i + chip->irq_base;
 -              irq_set_chip_data(__irq, chip);
 -              irq_set_chip_and_handler(__irq, &pm860x_irq_chip,
 -                                       handle_edge_irq);
 -              irq_set_nested_thread(__irq, 1);
 -#ifdef CONFIG_ARM
 -              set_irq_flags(__irq, IRQF_VALID);
 -#else
 -              irq_set_noprobe(__irq);
 -#endif
 -      }
 -
 -      ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags,
 +      ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags | IRQF_ONESHOT,
                                   "88pm860x", chip);
        if (ret) {
                dev_err(chip->dev, "Failed to request IRQ: %d\n", ret);
@@@ -741,122 -622,108 +748,122 @@@ static void __devinit device_osc_init(s
  static void __devinit device_bk_init(struct pm860x_chip *chip,
                                     struct pm860x_platform_data *pdata)
  {
 -      int ret;
 -      int i, j, id;
 -
 -      if ((pdata == NULL) || (pdata->backlight == NULL))
 -              return;
 -
 -      if (pdata->num_backlights > ARRAY_SIZE(bk_devs))
 -              pdata->num_backlights = ARRAY_SIZE(bk_devs);
 -
 -      for (i = 0; i < pdata->num_backlights; i++) {
 -              bk_devs[i].platform_data = &pdata->backlight[i];
 -              bk_devs[i].pdata_size = sizeof(struct pm860x_backlight_pdata);
 -
 -              for (j = 0; j < ARRAY_SIZE(bk_devs); j++) {
 -                      id = bk_resources[j].start;
 -                      if (pdata->backlight[i].flags != id)
 -                              continue;
 -
 -                      bk_devs[i].num_resources = 1;
 -                      bk_devs[i].resources = &bk_resources[j];
 -                      ret = mfd_add_devices(chip->dev, 0,
 -                                            &bk_devs[i], 1,
 -                                            &bk_resources[j], 0, NULL);
 -                      if (ret < 0) {
 -                              dev_err(chip->dev, "Failed to add "
 -                                      "backlight subdev\n");
 -                              return;
 -                      }
 +      int ret, i;
 +
 +      if (pdata && pdata->backlight) {
 +              if (pdata->num_backlights > ARRAY_SIZE(bk_devs))
 +                      pdata->num_backlights = ARRAY_SIZE(bk_devs);
 +              for (i = 0; i < pdata->num_backlights; i++) {
 +                      bk_devs[i].platform_data = &pdata->backlight[i];
 +                      bk_devs[i].pdata_size =
 +                              sizeof(struct pm860x_backlight_pdata);
                }
        }
 +      ret = mfd_add_devices(chip->dev, 0, bk_devs,
 +                            ARRAY_SIZE(bk_devs), NULL, 0, NULL);
 +      if (ret < 0)
 +              dev_err(chip->dev, "Failed to add backlight subdev\n");
  }
  
  static void __devinit device_led_init(struct pm860x_chip *chip,
                                      struct pm860x_platform_data *pdata)
  {
 -      int ret;
 -      int i, j, id;
 -
 -      if ((pdata == NULL) || (pdata->led == NULL))
 -              return;
 -
 -      if (pdata->num_leds > ARRAY_SIZE(led_devs))
 -              pdata->num_leds = ARRAY_SIZE(led_devs);
 -
 -      for (i = 0; i < pdata->num_leds; i++) {
 -              led_devs[i].platform_data = &pdata->led[i];
 -              led_devs[i].pdata_size = sizeof(struct pm860x_led_pdata);
 -
 -              for (j = 0; j < ARRAY_SIZE(led_devs); j++) {
 -                      id = led_resources[j].start;
 -                      if (pdata->led[i].flags != id)
 -                              continue;
 -
 -                      led_devs[i].num_resources = 1;
 -                      led_devs[i].resources = &led_resources[j],
 -                      ret = mfd_add_devices(chip->dev, 0,
 -                                            &led_devs[i], 1,
 -                                            &led_resources[j], 0, NULL);
 -                      if (ret < 0) {
 -                              dev_err(chip->dev, "Failed to add "
 -                                      "led subdev\n");
 -                              return;
 -                      }
 +      int ret, i;
 +
 +      if (pdata && pdata->led) {
 +              if (pdata->num_leds > ARRAY_SIZE(led_devs))
 +                      pdata->num_leds = ARRAY_SIZE(led_devs);
 +              for (i = 0; i < pdata->num_leds; i++) {
 +                      led_devs[i].platform_data = &pdata->led[i];
 +                      led_devs[i].pdata_size =
 +                              sizeof(struct pm860x_led_pdata);
                }
        }
 +      ret = mfd_add_devices(chip->dev, 0, led_devs,
 +                            ARRAY_SIZE(led_devs), NULL, 0, NULL);
 +      if (ret < 0) {
 +              dev_err(chip->dev, "Failed to add led subdev\n");
 +              return;
 +      }
  }
  
  static void __devinit device_regulator_init(struct pm860x_chip *chip,
                                            struct pm860x_platform_data *pdata)
  {
 -      struct regulator_init_data *initdata;
        int ret;
 -      int i, seq;
  
 -      if ((pdata == NULL) || (pdata->regulator == NULL))
 +      if (pdata == NULL)
 +              return;
 +      if (pdata->buck1) {
 +              reg_devs[0].platform_data = pdata->buck1;
 +              reg_devs[0].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->buck2) {
 +              reg_devs[1].platform_data = pdata->buck2;
 +              reg_devs[1].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->buck3) {
 +              reg_devs[2].platform_data = pdata->buck3;
 +              reg_devs[2].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo1) {
 +              reg_devs[3].platform_data = pdata->ldo1;
 +              reg_devs[3].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo2) {
 +              reg_devs[4].platform_data = pdata->ldo2;
 +              reg_devs[4].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo3) {
 +              reg_devs[5].platform_data = pdata->ldo3;
 +              reg_devs[5].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo4) {
 +              reg_devs[6].platform_data = pdata->ldo4;
 +              reg_devs[6].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo5) {
 +              reg_devs[7].platform_data = pdata->ldo5;
 +              reg_devs[7].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo6) {
 +              reg_devs[8].platform_data = pdata->ldo6;
 +              reg_devs[8].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo7) {
 +              reg_devs[9].platform_data = pdata->ldo7;
 +              reg_devs[9].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo8) {
 +              reg_devs[10].platform_data = pdata->ldo8;
 +              reg_devs[10].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo9) {
 +              reg_devs[11].platform_data = pdata->ldo9;
 +              reg_devs[11].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo10) {
 +              reg_devs[12].platform_data = pdata->ldo10;
 +              reg_devs[12].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo12) {
 +              reg_devs[13].platform_data = pdata->ldo12;
 +              reg_devs[13].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo_vibrator) {
 +              reg_devs[14].platform_data = pdata->ldo_vibrator;
 +              reg_devs[14].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      if (pdata->ldo14) {
 +              reg_devs[15].platform_data = pdata->ldo14;
 +              reg_devs[15].pdata_size = sizeof(struct regulator_init_data);
 +      }
 +      ret = mfd_add_devices(chip->dev, 0, reg_devs,
 +                            ARRAY_SIZE(reg_devs), NULL, 0, NULL);
 +      if (ret < 0) {
 +              dev_err(chip->dev, "Failed to add regulator subdev\n");
                return;
 -
 -      if (pdata->num_regulators > ARRAY_SIZE(regulator_devs))
 -              pdata->num_regulators = ARRAY_SIZE(regulator_devs);
 -
 -      for (i = 0, seq = -1; i < pdata->num_regulators; i++) {
 -              initdata = &pdata->regulator[i];
 -              seq = *(unsigned int *)initdata->driver_data;
 -              if ((seq < 0) || (seq > PM8607_ID_RG_MAX)) {
 -                      dev_err(chip->dev, "Wrong ID(%d) on regulator(%s)\n",
 -                              seq, initdata->constraints.name);
 -                      goto out;
 -              }
 -              regulator_devs[i].platform_data = &pdata->regulator[i];
 -              regulator_devs[i].pdata_size = sizeof(struct regulator_init_data);
 -              regulator_devs[i].num_resources = 1;
 -              regulator_devs[i].resources = &regulator_resources[seq];
 -
 -              ret = mfd_add_devices(chip->dev, 0, &regulator_devs[i], 1,
 -                                    &regulator_resources[seq], 0, NULL);
 -              if (ret < 0) {
 -                      dev_err(chip->dev, "Failed to add regulator subdev\n");
 -                      goto out;
 -              }
        }
 -out:
 -      return;
  }
  
  static void __devinit device_rtc_init(struct pm860x_chip *chip,
@@@ -925,10 -792,25 +932,23 @@@ static void __devinit device_power_init
  
        power_devs[2].platform_data = &preg_init_data;
        power_devs[2].pdata_size = sizeof(struct regulator_init_data);
 -      power_devs[2].num_resources = ARRAY_SIZE(preg_resources);
 -      power_devs[2].resources = &preg_resources[0],
        ret = mfd_add_devices(chip->dev, 0, &power_devs[2], 1,
 -                            &preg_resources[0], chip->irq_base, NULL);
 +                            NULL, chip->irq_base, NULL);
        if (ret < 0)
                dev_err(chip->dev, "Failed to add preg subdev\n");
+       if (pdata->chg_desc) {
+               pdata->chg_desc->charger_regulators =
+                       &chg_desc_regulator_data[0];
+               pdata->chg_desc->num_charger_regulators =
+                       ARRAY_SIZE(chg_desc_regulator_data),
+               power_devs[3].platform_data = pdata->chg_desc;
+               power_devs[3].pdata_size = sizeof(*pdata->chg_desc);
+               ret = mfd_add_devices(chip->dev, 0, &power_devs[3], 1,
+                                     NULL, chip->irq_base, NULL);
+               if (ret < 0)
+                       dev_err(chip->dev, "Failed to add chg-manager subdev\n");
+       }
  }
  
  static void __devinit device_onkey_init(struct pm860x_chip *chip,
@@@ -1006,6 -888,10 +1026,6 @@@ static void __devinit device_8607_init(
                goto out;
        }
  
 -      ret = device_gpadc_init(chip, pdata);
 -      if (ret < 0)
 -              goto out;
 -
        ret = device_irq_init(chip, pdata);
        if (ret < 0)
                goto out;
@@@ -1029,8 -915,8 +1049,8 @@@ static void __devinit device_8606_init(
        device_led_init(chip, pdata);
  }
  
 -int __devinit pm860x_device_init(struct pm860x_chip *chip,
 -                     struct pm860x_platform_data *pdata)
 +static int __devinit pm860x_device_init(struct pm860x_chip *chip,
 +                                      struct pm860x_platform_data *pdata)
  {
        chip->core_irq = 0;
  
        return 0;
  }
  
 -void __devexit pm860x_device_exit(struct pm860x_chip *chip)
 +static void __devexit pm860x_device_exit(struct pm860x_chip *chip)
  {
        device_irq_exit(chip);
        mfd_remove_devices(chip->dev);
  }
  
 +static int verify_addr(struct i2c_client *i2c)
 +{
 +      unsigned short addr_8607[] = {0x30, 0x34};
 +      unsigned short addr_8606[] = {0x10, 0x11};
 +      int size, i;
 +
 +      if (i2c == NULL)
 +              return 0;
 +      size = ARRAY_SIZE(addr_8606);
 +      for (i = 0; i < size; i++) {
 +              if (i2c->addr == *(addr_8606 + i))
 +                      return CHIP_PM8606;
 +      }
 +      size = ARRAY_SIZE(addr_8607);
 +      for (i = 0; i < size; i++) {
 +              if (i2c->addr == *(addr_8607 + i))
 +                      return CHIP_PM8607;
 +      }
 +      return 0;
 +}
 +
 +static struct regmap_config pm860x_regmap_config = {
 +      .reg_bits = 8,
 +      .val_bits = 8,
 +};
 +
 +static int __devinit pm860x_dt_init(struct device_node *np,
 +                                  struct device *dev,
 +                                  struct pm860x_platform_data *pdata)
 +{
 +      int ret;
 +
 +      if (of_get_property(np, "marvell,88pm860x-irq-read-clr", NULL))
 +              pdata->irq_mode = 1;
 +      ret = of_property_read_u32(np, "marvell,88pm860x-slave-addr",
 +                                 &pdata->companion_addr);
 +      if (ret) {
 +              dev_err(dev, "Not found \"marvell,88pm860x-slave-addr\" "
 +                      "property\n");
 +              pdata->companion_addr = 0;
 +      }
 +      return 0;
 +}
 +
 +static int __devinit pm860x_probe(struct i2c_client *client,
 +                                const struct i2c_device_id *id)
 +{
 +      struct pm860x_platform_data *pdata = client->dev.platform_data;
 +      struct device_node *node = client->dev.of_node;
 +      struct pm860x_chip *chip;
 +      int ret;
 +
 +      if (node && !pdata) {
 +              /* parse DT to get platform data */
 +              pdata = devm_kzalloc(&client->dev,
 +                                   sizeof(struct pm860x_platform_data),
 +                                   GFP_KERNEL);
 +              if (!pdata)
 +                      return -ENOMEM;
 +              ret = pm860x_dt_init(node, &client->dev, pdata);
 +              if (ret)
 +                      goto err;
 +      } else if (!pdata) {
 +              pr_info("No platform data in %s!\n", __func__);
 +              return -EINVAL;
 +      }
 +
 +      chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL);
 +      if (chip == NULL) {
 +              ret = -ENOMEM;
 +              goto err;
 +      }
 +
 +      chip->id = verify_addr(client);
 +      chip->regmap = regmap_init_i2c(client, &pm860x_regmap_config);
 +      if (IS_ERR(chip->regmap)) {
 +              ret = PTR_ERR(chip->regmap);
 +              dev_err(&client->dev, "Failed to allocate register map: %d\n",
 +                              ret);
 +              kfree(chip);
 +              return ret;
 +      }
 +      chip->client = client;
 +      i2c_set_clientdata(client, chip);
 +      chip->dev = &client->dev;
 +      dev_set_drvdata(chip->dev, chip);
 +
 +      /*
 +       * Both client and companion client shares same platform driver.
 +       * Driver distinguishes them by pdata->companion_addr.
 +       * pdata->companion_addr is only assigned if companion chip exists.
 +       * At the same time, the companion_addr shouldn't equal to client
 +       * address.
 +       */
 +      if (pdata->companion_addr && (pdata->companion_addr != client->addr)) {
 +              chip->companion_addr = pdata->companion_addr;
 +              chip->companion = i2c_new_dummy(chip->client->adapter,
 +                                              chip->companion_addr);
 +              chip->regmap_companion = regmap_init_i2c(chip->companion,
 +                                                      &pm860x_regmap_config);
 +              if (IS_ERR(chip->regmap_companion)) {
 +                      ret = PTR_ERR(chip->regmap_companion);
 +                      dev_err(&chip->companion->dev,
 +                              "Failed to allocate register map: %d\n", ret);
 +                      return ret;
 +              }
 +              i2c_set_clientdata(chip->companion, chip);
 +      }
 +
 +      pm860x_device_init(chip, pdata);
 +      return 0;
 +err:
 +      if (node)
 +              devm_kfree(&client->dev, pdata);
 +      return ret;
 +}
 +
 +static int __devexit pm860x_remove(struct i2c_client *client)
 +{
 +      struct pm860x_chip *chip = i2c_get_clientdata(client);
 +
 +      pm860x_device_exit(chip);
 +      if (chip->companion) {
 +              regmap_exit(chip->regmap_companion);
 +              i2c_unregister_device(chip->companion);
 +      }
 +      regmap_exit(chip->regmap);
 +      kfree(chip);
 +      return 0;
 +}
 +
 +#ifdef CONFIG_PM_SLEEP
 +static int pm860x_suspend(struct device *dev)
 +{
 +      struct i2c_client *client = container_of(dev, struct i2c_client, dev);
 +      struct pm860x_chip *chip = i2c_get_clientdata(client);
 +
 +      if (device_may_wakeup(dev) && chip->wakeup_flag)
 +              enable_irq_wake(chip->core_irq);
 +      return 0;
 +}
 +
 +static int pm860x_resume(struct device *dev)
 +{
 +      struct i2c_client *client = container_of(dev, struct i2c_client, dev);
 +      struct pm860x_chip *chip = i2c_get_clientdata(client);
 +
 +      if (device_may_wakeup(dev) && chip->wakeup_flag)
 +              disable_irq_wake(chip->core_irq);
 +      return 0;
 +}
 +#endif
 +
 +static SIMPLE_DEV_PM_OPS(pm860x_pm_ops, pm860x_suspend, pm860x_resume);
 +
 +static const struct i2c_device_id pm860x_id_table[] = {
 +      { "88PM860x", 0 },
 +      {}
 +};
 +MODULE_DEVICE_TABLE(i2c, pm860x_id_table);
 +
 +static const struct of_device_id pm860x_dt_ids[] = {
 +      { .compatible = "marvell,88pm860x", },
 +      {},
 +};
 +MODULE_DEVICE_TABLE(of, pm860x_dt_ids);
 +
 +static struct i2c_driver pm860x_driver = {
 +      .driver = {
 +              .name   = "88PM860x",
 +              .owner  = THIS_MODULE,
 +              .pm     = &pm860x_pm_ops,
 +              .of_match_table = of_match_ptr(pm860x_dt_ids),
 +      },
 +      .probe          = pm860x_probe,
 +      .remove         = __devexit_p(pm860x_remove),
 +      .id_table       = pm860x_id_table,
 +};
 +
 +static int __init pm860x_i2c_init(void)
 +{
 +      int ret;
 +      ret = i2c_add_driver(&pm860x_driver);
 +      if (ret != 0)
 +              pr_err("Failed to register 88PM860x I2C driver: %d\n", ret);
 +      return ret;
 +}
 +subsys_initcall(pm860x_i2c_init);
 +
 +static void __exit pm860x_i2c_exit(void)
 +{
 +      i2c_del_driver(&pm860x_driver);
 +}
 +module_exit(pm860x_i2c_exit);
 +
  MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x");
  MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  MODULE_LICENSE("GPL");
diff --combined drivers/power/Kconfig
index 80978196aae8b0a59d100a3bc09818dccdd6200b,9d80477358417ba1a772f3a66fdfc88d16686a46..49a89397231834a67fc1436026f563fadfe57e10
@@@ -29,13 -29,6 +29,13 @@@ config APM_POWE
          Say Y here to enable support APM status emulation using
          battery class devices.
  
 +config GENERIC_ADC_BATTERY
 +      tristate "Generic battery support using IIO"
 +      depends on IIO
 +      help
 +        Say Y here to enable support for the generic battery driver
 +        which uses IIO framework to read adc.
 +
  config MAX8925_POWER
        tristate "MAX8925 battery charger support"
        depends on MFD_MAX8925
@@@ -69,6 -62,12 +69,12 @@@ config TEST_POWE
        help
          This driver is used for testing. It's safe to say M here.
  
+ config BATTERY_88PM860X
+       tristate "Marvell 88PM860x battery driver"
+       depends on MFD_88PM860X
+       help
+         Say Y here to enable battery monitor for Marvell 88PM860x chip.
  config BATTERY_DS2760
        tristate "DS2760 battery driver (HP iPAQ & others)"
        depends on W1 && W1_SLAVE_DS2760
@@@ -174,7 -173,6 +180,6 @@@ config BATTERY_DA903
  config BATTERY_DA9052
        tristate "Dialog DA9052 Battery"
        depends on PMIC_DA9052
-       depends on BROKEN
        help
          Say Y here to enable support for batteries charger integrated into
          DA9052 PMIC.
@@@ -210,6 -208,12 +215,12 @@@ config BATTERY_S3C_AD
        help
          Say Y here to enable support for iPAQ h1930/h1940/rx1950 battery
  
+ config CHARGER_88PM860X
+       tristate "Marvell 88PM860x Charger driver"
+       depends on MFD_88PM860X && BATTERY_88PM860X
+       help
+         Say Y here to enable charger for Marvell 88PM860x chip.
  config CHARGER_PCF50633
        tristate "NXP PCF50633 MBC"
        depends on MFD_PCF50633
@@@ -262,6 -266,13 +273,13 @@@ config CHARGER_LP872
        help
          Say Y here to enable support for LP8727 Charger Driver.
  
+ config CHARGER_LP8788
+       tristate "TI LP8788 charger driver"
+       depends on MFD_LP8788
+       depends on LP8788_ADC
+       help
+         Say Y to enable support for the LP8788 linear charger.
  config CHARGER_GPIO
        tristate "GPIO charger"
        depends on GPIOLIB
diff --combined drivers/power/Makefile
index e0b4d4284e1d56508d815b860cc56cff71101e12,059c0a931526a134306c0d5f519770a2527eeead..b949cf85590c623610f1ada865114c3d709372f9
@@@ -5,7 -5,6 +5,7 @@@ power_supply-$(CONFIG_SYSFS)             += power_
  power_supply-$(CONFIG_LEDS_TRIGGERS)  += power_supply_leds.o
  
  obj-$(CONFIG_POWER_SUPPLY)    += power_supply.o
 +obj-$(CONFIG_GENERIC_ADC_BATTERY)     += generic-adc-battery.o
  
  obj-$(CONFIG_PDA_POWER)               += pda_power.o
  obj-$(CONFIG_APM_POWER)               += apm_power.o
@@@ -15,6 -14,7 +15,7 @@@ obj-$(CONFIG_WM831X_POWER)    += wm831x_po
  obj-$(CONFIG_WM8350_POWER)    += wm8350_power.o
  obj-$(CONFIG_TEST_POWER)      += test_power.o
  
+ obj-$(CONFIG_BATTERY_88PM860X)        += 88pm860x_battery.o
  obj-$(CONFIG_BATTERY_DS2760)  += ds2760_battery.o
  obj-$(CONFIG_BATTERY_DS2780)  += ds2780_battery.o
  obj-$(CONFIG_BATTERY_DS2781)  += ds2781_battery.o
@@@ -32,6 -32,7 +33,7 @@@ obj-$(CONFIG_BATTERY_MAX17040)        += max17
  obj-$(CONFIG_BATTERY_MAX17042)        += max17042_battery.o
  obj-$(CONFIG_BATTERY_Z2)      += z2_battery.o
  obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o
+ obj-$(CONFIG_CHARGER_88PM860X)        += 88pm860x_charger.o
  obj-$(CONFIG_CHARGER_PCF50633)        += pcf50633-charger.o
  obj-$(CONFIG_BATTERY_JZ4740)  += jz4740-battery.o
  obj-$(CONFIG_BATTERY_INTEL_MID)       += intel_mid_battery.o
@@@ -40,6 -41,7 +42,7 @@@ obj-$(CONFIG_CHARGER_ISP1704) += isp170
  obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o
  obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o
  obj-$(CONFIG_CHARGER_LP8727)  += lp8727_charger.o
+ obj-$(CONFIG_CHARGER_LP8788)  += lp8788-charger.o
  obj-$(CONFIG_CHARGER_GPIO)    += gpio-charger.o
  obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o
  obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o
index 3041514f4d3f2d38469048dbf5ee96bf879483b6,2b76943ff9cf09ce679927bf9acb27dea95384a1..e3b6395b20ddc226f2324ddfecbf820469accd03
@@@ -1014,11 -1014,12 +1014,12 @@@ static int __devinit ab8500_btemp_probe
                create_singlethread_workqueue("ab8500_btemp_wq");
        if (di->btemp_wq == NULL) {
                dev_err(di->dev, "failed to create work queue\n");
+               ret = -ENOMEM;
                goto free_device_info;
        }
  
        /* Init work for measuring temperature periodically */
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->btemp_periodic_work,
 +      INIT_DEFERRABLE_WORK(&di->btemp_periodic_work,
                ab8500_btemp_periodic_work);
  
        /* Identify the battery */
index 0701dbc2b7e1fe4b506cd0394a12bdaed6e0b91d,c2ef94702e49cf70de79106b09fca1e55339e23e..26ff759e2220572579ba9f01c319d21b0cdb96ec
@@@ -2614,13 -2614,14 +2614,14 @@@ static int __devinit ab8500_charger_pro
                create_singlethread_workqueue("ab8500_charger_wq");
        if (di->charger_wq == NULL) {
                dev_err(di->dev, "failed to create work queue\n");
+               ret = -ENOMEM;
                goto free_device_info;
        }
  
        /* Init work for HW failure check */
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->check_hw_failure_work,
 +      INIT_DEFERRABLE_WORK(&di->check_hw_failure_work,
                ab8500_charger_check_hw_failure_work);
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->check_usbchgnotok_work,
 +      INIT_DEFERRABLE_WORK(&di->check_usbchgnotok_work,
                ab8500_charger_check_usbchargernotok_work);
  
        /*
         * watchdog have to be kicked by the charger driver
         * when the AC charger is disabled
         */
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->kick_wd_work,
 +      INIT_DEFERRABLE_WORK(&di->kick_wd_work,
                ab8500_charger_kick_watchdog_work);
  
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->check_vbat_work,
 +      INIT_DEFERRABLE_WORK(&di->check_vbat_work,
                ab8500_charger_check_vbat_work);
  
        /* Init work for charger detection */
index 5c9e7c263c382f93244a70e4be7f7ddb7a455fcc,11633e327d381e986373aa4153ae8a027c4500e3..2db8cc254399c8093ffcfbbc78c965d68d73f14e
@@@ -2506,6 -2506,7 +2506,7 @@@ static int __devinit ab8500_fg_probe(st
        di->fg_wq = create_singlethread_workqueue("ab8500_fg_wq");
        if (di->fg_wq == NULL) {
                dev_err(di->dev, "failed to create work queue\n");
+               ret = -ENOMEM;
                goto free_device_info;
        }
  
        INIT_WORK(&di->fg_acc_cur_work, ab8500_fg_acc_cur_work);
  
        /* Init work for reinitialising the fg algorithm */
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->fg_reinit_work,
 +      INIT_DEFERRABLE_WORK(&di->fg_reinit_work,
                ab8500_fg_reinit_work);
  
        /* Work delayed Queue to run the state machine */
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->fg_periodic_work,
 +      INIT_DEFERRABLE_WORK(&di->fg_periodic_work,
                ab8500_fg_periodic_work);
  
        /* Work to check low battery condition */
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->fg_low_bat_work,
 +      INIT_DEFERRABLE_WORK(&di->fg_low_bat_work,
                ab8500_fg_low_bat_work);
  
        /* Init work for HW failure check */
 -      INIT_DELAYED_WORK_DEFERRABLE(&di->fg_check_hw_failure_work,
 +      INIT_DEFERRABLE_WORK(&di->fg_check_hw_failure_work,
                ab8500_fg_check_hw_failure_work);
  
        /* Initialize OVV, and other registers */
index 7ff83cf43c8c1ad5d06407b9eba1358f0bdb9053,92dfa5c64876171fc62317086a64f15f9b2c89d6..8a0aca6364c7e8ba9ab68261b598afe2e155ad18
@@@ -22,6 -22,7 +22,7 @@@
  #include <linux/platform_device.h>
  #include <linux/power/charger-manager.h>
  #include <linux/regulator/consumer.h>
+ #include <linux/sysfs.h>
  
  static const char * const default_event_names[] = {
        [CM_EVENT_UNKNOWN] = "Unknown",
@@@ -226,6 -227,58 +227,58 @@@ static bool is_charging(struct charger_
        return charging;
  }
  
+ /**
+  * is_full_charged - Returns true if the battery is fully charged.
+  * @cm: the Charger Manager representing the battery.
+  */
+ static bool is_full_charged(struct charger_manager *cm)
+ {
+       struct charger_desc *desc = cm->desc;
+       union power_supply_propval val;
+       int ret = 0;
+       int uV;
+       /* If there is no battery, it cannot be charged */
+       if (!is_batt_present(cm)) {
+               val.intval = 0;
+               goto out;
+       }
+       if (cm->fuel_gauge && desc->fullbatt_full_capacity > 0) {
+               /* Not full if capacity of fuel gauge isn't full */
+               ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
+                               POWER_SUPPLY_PROP_CHARGE_FULL, &val);
+               if (!ret && val.intval > desc->fullbatt_full_capacity) {
+                       val.intval = 1;
+                       goto out;
+               }
+       }
+       /* Full, if it's over the fullbatt voltage */
+       if (desc->fullbatt_uV > 0) {
+               ret = get_batt_uV(cm, &uV);
+               if (!ret && uV >= desc->fullbatt_uV) {
+                       val.intval = 1;
+                       goto out;
+               }
+       }
+       /* Full, if the capacity is more than fullbatt_soc */
+       if (cm->fuel_gauge && desc->fullbatt_soc > 0) {
+               ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
+                               POWER_SUPPLY_PROP_CAPACITY, &val);
+               if (!ret && val.intval >= desc->fullbatt_soc) {
+                       val.intval = 1;
+                       goto out;
+               }
+       }
+       val.intval = 0;
+ out:
+       return val.intval ? true : false;
+ }
  /**
   * is_polling_required - Return true if need to continue polling for this CM.
   * @cm: the Charger Manager representing the battery.
@@@ -271,9 -324,45 +324,45 @@@ static int try_charger_enable(struct ch
        if (enable) {
                if (cm->emergency_stop)
                        return -EAGAIN;
-               for (i = 0 ; i < desc->num_charger_regulators ; i++)
-                       regulator_enable(desc->charger_regulators[i].consumer);
+               /*
+                * Save start time of charging to limit
+                * maximum possible charging time.
+                */
+               cm->charging_start_time = ktime_to_ms(ktime_get());
+               cm->charging_end_time = 0;
+               for (i = 0 ; i < desc->num_charger_regulators ; i++) {
+                       if (desc->charger_regulators[i].externally_control)
+                               continue;
+                       err = regulator_enable(desc->charger_regulators[i].consumer);
+                       if (err < 0) {
+                               dev_warn(cm->dev,
+                                       "Cannot enable %s regulator\n",
+                                       desc->charger_regulators[i].regulator_name);
+                       }
+               }
        } else {
+               /*
+                * Save end time of charging to maintain fully charged state
+                * of battery after full-batt.
+                */
+               cm->charging_start_time = 0;
+               cm->charging_end_time = ktime_to_ms(ktime_get());
+               for (i = 0 ; i < desc->num_charger_regulators ; i++) {
+                       if (desc->charger_regulators[i].externally_control)
+                               continue;
+                       err = regulator_disable(desc->charger_regulators[i].consumer);
+                       if (err < 0) {
+                               dev_warn(cm->dev,
+                                       "Cannot disable %s regulator\n",
+                                       desc->charger_regulators[i].regulator_name);
+                       }
+               }
                /*
                 * Abnormal battery state - Stop charging forcibly,
                 * even if charger was enabled at the other places
@@@ -400,15 -489,62 +489,62 @@@ static void fullbatt_vchk(struct work_s
                return;
        }
  
-       diff = cm->fullbatt_vchk_uV;
+       diff = desc->fullbatt_uV;
        diff -= batt_uV;
  
-       dev_dbg(cm->dev, "VBATT dropped %duV after full-batt.\n", diff);
+       dev_info(cm->dev, "VBATT dropped %duV after full-batt.\n", diff);
  
        if (diff > desc->fullbatt_vchkdrop_uV) {
                try_charger_restart(cm);
-               uevent_notify(cm, "Recharge");
+               uevent_notify(cm, "Recharging");
+       }
+ }
+ /**
+  * check_charging_duration - Monitor charging/discharging duration
+  * @cm: the Charger Manager representing the battery.
+  *
+  * If whole charging duration exceed 'charging_max_duration_ms',
+  * cm stop charging to prevent overcharge/overheat. If discharging
+  * duration exceed 'discharging _max_duration_ms', charger cable is
+  * attached, after full-batt, cm start charging to maintain fully
+  * charged state for battery.
+  */
+ static int check_charging_duration(struct charger_manager *cm)
+ {
+       struct charger_desc *desc = cm->desc;
+       u64 curr = ktime_to_ms(ktime_get());
+       u64 duration;
+       int ret = false;
+       if (!desc->charging_max_duration_ms &&
+                       !desc->discharging_max_duration_ms)
+               return ret;
+       if (cm->charger_enabled) {
+               duration = curr - cm->charging_start_time;
+               if (duration > desc->charging_max_duration_ms) {
+                       dev_info(cm->dev, "Charging duration exceed %lldms",
+                                desc->charging_max_duration_ms);
+                       uevent_notify(cm, "Discharging");
+                       try_charger_enable(cm, false);
+                       ret = true;
+               }
+       } else if (is_ext_pwr_online(cm) && !cm->charger_enabled) {
+               duration = curr - cm->charging_end_time;
+               if (duration > desc->charging_max_duration_ms &&
+                               is_ext_pwr_online(cm)) {
+                       dev_info(cm->dev, "DisCharging duration exceed %lldms",
+                                desc->discharging_max_duration_ms);
+                       uevent_notify(cm, "Recharing");
+                       try_charger_enable(cm, true);
+                       ret = true;
+               }
        }
+       return ret;
  }
  
  /**
@@@ -426,10 -562,14 +562,14 @@@ static bool _cm_monitor(struct charger_
        dev_dbg(cm->dev, "monitoring (%2.2d.%3.3dC)\n",
                cm->last_temp_mC / 1000, cm->last_temp_mC % 1000);
  
-       /* It has been stopped or charging already */
-       if (!!temp == !!cm->emergency_stop)
+       /* It has been stopped already */
+       if (temp && cm->emergency_stop)
                return false;
  
+       /*
+        * Check temperature whether overheat or cold.
+        * If temperature is out of range normal state, stop charging.
+        */
        if (temp) {
                cm->emergency_stop = temp;
                if (!try_charger_enable(cm, false)) {
                        else
                                uevent_notify(cm, "COLD");
                }
+       /*
+        * Check whole charging duration and discharing duration
+        * after full-batt.
+        */
+       } else if (!cm->emergency_stop && check_charging_duration(cm)) {
+               dev_dbg(cm->dev,
+                       "Charging/Discharging duration is out of range");
+       /*
+        * Check dropped voltage of battery. If battery voltage is more
+        * dropped than fullbatt_vchkdrop_uV after fully charged state,
+        * charger-manager have to recharge battery.
+        */
+       } else if (!cm->emergency_stop && is_ext_pwr_online(cm) &&
+                       !cm->charger_enabled) {
+               fullbatt_vchk(&cm->fullbatt_vchk_work.work);
+       /*
+        * Check whether fully charged state to protect overcharge
+        * if charger-manager is charging for battery.
+        */
+       } else if (!cm->emergency_stop && is_full_charged(cm) &&
+                       cm->charger_enabled) {
+               dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged.\n");
+               uevent_notify(cm, default_event_names[CM_EVENT_BATT_FULL]);
+               try_charger_enable(cm, false);
+               fullbatt_vchk(&cm->fullbatt_vchk_work.work);
        } else {
                cm->emergency_stop = 0;
-               if (!try_charger_enable(cm, true))
-                       uevent_notify(cm, "CHARGING");
+               if (is_ext_pwr_online(cm)) {
+                       if (!try_charger_enable(cm, true))
+                               uevent_notify(cm, "CHARGING");
+               }
        }
  
        return true;
@@@ -509,8 -680,9 +680,8 @@@ static void _setup_polling(struct work_
        if (!delayed_work_pending(&cm_monitor_work) ||
            (delayed_work_pending(&cm_monitor_work) &&
             time_after(next_polling, _next_polling))) {
 -              cancel_delayed_work_sync(&cm_monitor_work);
                next_polling = jiffies + polling_jiffy;
 -              queue_delayed_work(cm_wq, &cm_monitor_work, polling_jiffy);
 +              mod_delayed_work(cm_wq, &cm_monitor_work, polling_jiffy);
        }
  
  out:
@@@ -545,8 -717,10 +716,8 @@@ static void fullbatt_handler(struct cha
        if (cm_suspended)
                device_set_wakeup_capable(cm->dev, true);
  
 -      if (delayed_work_pending(&cm->fullbatt_vchk_work))
 -              cancel_delayed_work(&cm->fullbatt_vchk_work);
 -      queue_delayed_work(cm_wq, &cm->fullbatt_vchk_work,
 -                         msecs_to_jiffies(desc->fullbatt_vchkdrop_ms));
 +      mod_delayed_work(cm_wq, &cm->fullbatt_vchk_work,
 +                       msecs_to_jiffies(desc->fullbatt_vchkdrop_ms));
        cm->fullbatt_vchk_jiffies_at = jiffies + msecs_to_jiffies(
                                       desc->fullbatt_vchkdrop_ms);
  
@@@ -701,47 -875,10 +872,10 @@@ static int charger_get_property(struct 
                        val->intval = 0;
                break;
        case POWER_SUPPLY_PROP_CHARGE_FULL:
-               if (cm->fuel_gauge) {
-                       if (cm->fuel_gauge->get_property(cm->fuel_gauge,
-                           POWER_SUPPLY_PROP_CHARGE_FULL, val) == 0)
-                               break;
-               }
-               if (is_ext_pwr_online(cm)) {
-                       /* Not full if it's charging. */
-                       if (is_charging(cm)) {
-                               val->intval = 0;
-                               break;
-                       }
-                       /*
-                        * Full if it's powered but not charging andi
-                        * not forced stop by emergency
-                        */
-                       if (!cm->emergency_stop) {
-                               val->intval = 1;
-                               break;
-                       }
-               }
-               /* Full if it's over the fullbatt voltage */
-               ret = get_batt_uV(cm, &uV);
-               if (!ret && desc->fullbatt_uV > 0 && uV >= desc->fullbatt_uV &&
-                   !is_charging(cm)) {
+               if (is_full_charged(cm))
                        val->intval = 1;
-                       break;
-               }
-               /* Full if the cap is 100 */
-               if (cm->fuel_gauge) {
-                       ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
-                                       POWER_SUPPLY_PROP_CAPACITY, val);
-                       if (!ret && val->intval >= 100 && !is_charging(cm)) {
-                               val->intval = 1;
-                               break;
-                       }
-               }
-               val->intval = 0;
+               else
+                       val->intval = 0;
                ret = 0;
                break;
        case POWER_SUPPLY_PROP_CHARGE_NOW:
@@@ -1031,7 -1168,26 +1165,26 @@@ static int charger_extcon_notifier(stru
        struct charger_cable *cable =
                container_of(self, struct charger_cable, nb);
  
+       /*
+        * The newly state of charger cable.
+        * If cable is attached, cable->attached is true.
+        */
        cable->attached = event;
+       /*
+        * Setup monitoring to check battery state
+        * when charger cable is attached.
+        */
+       if (cable->attached && is_polling_required(cable->cm)) {
+               if (work_pending(&setup_polling))
+                       cancel_work_sync(&setup_polling);
+               schedule_work(&setup_polling);
+       }
+       /*
+        * Setup work for controlling charger(regulator)
+        * according to charger cable.
+        */
        schedule_work(&cable->wq);
  
        return NOTIFY_DONE;
@@@ -1068,12 -1224,101 +1221,101 @@@ static int charger_extcon_init(struct c
        return ret;
  }
  
+ /* help function of sysfs node to control charger(regulator) */
+ static ssize_t charger_name_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+ {
+       struct charger_regulator *charger
+               = container_of(attr, struct charger_regulator, attr_name);
+       return sprintf(buf, "%s\n", charger->regulator_name);
+ }
+ static ssize_t charger_state_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+ {
+       struct charger_regulator *charger
+               = container_of(attr, struct charger_regulator, attr_state);
+       int state = 0;
+       if (!charger->externally_control)
+               state = regulator_is_enabled(charger->consumer);
+       return sprintf(buf, "%s\n", state ? "enabled" : "disabled");
+ }
+ static ssize_t charger_externally_control_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+ {
+       struct charger_regulator *charger = container_of(attr,
+                       struct charger_regulator, attr_externally_control);
+       return sprintf(buf, "%d\n", charger->externally_control);
+ }
+ static ssize_t charger_externally_control_store(struct device *dev,
+                               struct device_attribute *attr, const char *buf,
+                               size_t count)
+ {
+       struct charger_regulator *charger
+               = container_of(attr, struct charger_regulator,
+                                       attr_externally_control);
+       struct charger_manager *cm = charger->cm;
+       struct charger_desc *desc = cm->desc;
+       int i;
+       int ret;
+       int externally_control;
+       int chargers_externally_control = 1;
+       ret = sscanf(buf, "%d", &externally_control);
+       if (ret == 0) {
+               ret = -EINVAL;
+               return ret;
+       }
+       if (!externally_control) {
+               charger->externally_control = 0;
+               return count;
+       }
+       for (i = 0; i < desc->num_charger_regulators; i++) {
+               if (&desc->charger_regulators[i] != charger &&
+                             !desc->charger_regulators[i].externally_control) {
+                       /*
+                        * At least, one charger is controlled by
+                        * charger-manager
+                        */
+                       chargers_externally_control = 0;
+                       break;
+               }
+       }
+       if (!chargers_externally_control) {
+               if (cm->charger_enabled) {
+                       try_charger_enable(charger->cm, false);
+                       charger->externally_control = externally_control;
+                       try_charger_enable(charger->cm, true);
+               } else {
+                       charger->externally_control = externally_control;
+               }
+       } else {
+               dev_warn(cm->dev,
+                       "'%s' regulator should be controlled "
+                       "in charger-manager because charger-manager "
+                       "must need at least one charger for charging\n",
+                       charger->regulator_name);
+       }
+       return count;
+ }
  static int charger_manager_probe(struct platform_device *pdev)
  {
        struct charger_desc *desc = dev_get_platdata(&pdev->dev);
        struct charger_manager *cm;
        int ret = 0, i = 0;
        int j = 0;
+       int chargers_externally_control = 1;
        union power_supply_propval val;
  
        if (g_desc && !rtc_dev && g_desc->rtc_name) {
                desc->fullbatt_vchkdrop_ms = 0;
                desc->fullbatt_vchkdrop_uV = 0;
        }
+       if (desc->fullbatt_soc == 0) {
+               dev_info(&pdev->dev, "Ignoring full-battery soc(state of"
+                                       " charge) threshold as it is not"
+                                       " supplied.");
+       }
+       if (desc->fullbatt_full_capacity == 0) {
+               dev_info(&pdev->dev, "Ignoring full-battery full capacity"
+                                       " threshold as it is not supplied.");
+       }
  
        if (!desc->charger_regulators || desc->num_charger_regulators < 1) {
                ret = -EINVAL;
                goto err_chg_stat;
        }
  
+       if (!desc->charging_max_duration_ms ||
+                       !desc->discharging_max_duration_ms) {
+               dev_info(&pdev->dev, "Cannot limit charging duration "
+                        "checking mechanism to prevent overcharge/overheat "
+                        "and control discharging duration");
+               desc->charging_max_duration_ms = 0;
+               desc->discharging_max_duration_ms = 0;
+       }
        platform_set_drvdata(pdev, cm);
  
        memcpy(&cm->charger_psy, &psy_default, sizeof(psy_default));
        for (i = 0 ; i < desc->num_charger_regulators ; i++) {
                struct charger_regulator *charger
                                        = &desc->charger_regulators[i];
+               char buf[11];
+               char *str;
  
                charger->consumer = regulator_get(&pdev->dev,
                                        charger->regulator_name);
                        ret = -EINVAL;
                        goto err_chg_get;
                }
+               charger->cm = cm;
  
                for (j = 0 ; j < charger->num_cables ; j++) {
                        struct charger_cable *cable = &charger->cables[j];
                        cable->charger = charger;
                        cable->cm = cm;
                }
+               /* Create sysfs entry to control charger(regulator) */
+               snprintf(buf, 10, "charger.%d", i);
+               str = kzalloc(sizeof(char) * (strlen(buf) + 1), GFP_KERNEL);
+               if (!str) {
+                       for (i--; i >= 0; i--) {
+                               charger = &desc->charger_regulators[i];
+                               kfree(charger->attr_g.name);
+                       }
+                       ret = -ENOMEM;
+                       goto err_extcon;
+               }
+               strcpy(str, buf);
+               charger->attrs[0] = &charger->attr_name.attr;
+               charger->attrs[1] = &charger->attr_state.attr;
+               charger->attrs[2] = &charger->attr_externally_control.attr;
+               charger->attrs[3] = NULL;
+               charger->attr_g.name = str;
+               charger->attr_g.attrs = charger->attrs;
+               sysfs_attr_init(&charger->attr_name.attr);
+               charger->attr_name.attr.name = "name";
+               charger->attr_name.attr.mode = 0444;
+               charger->attr_name.show = charger_name_show;
+               sysfs_attr_init(&charger->attr_state.attr);
+               charger->attr_state.attr.name = "state";
+               charger->attr_state.attr.mode = 0444;
+               charger->attr_state.show = charger_state_show;
+               sysfs_attr_init(&charger->attr_externally_control.attr);
+               charger->attr_externally_control.attr.name
+                               = "externally_control";
+               charger->attr_externally_control.attr.mode = 0644;
+               charger->attr_externally_control.show
+                               = charger_externally_control_show;
+               charger->attr_externally_control.store
+                               = charger_externally_control_store;
+               if (!desc->charger_regulators[i].externally_control ||
+                               !chargers_externally_control) {
+                       chargers_externally_control = 0;
+               }
+               dev_info(&pdev->dev, "'%s' regulator's externally_control"
+                               "is %d\n", charger->regulator_name,
+                               charger->externally_control);
+               ret = sysfs_create_group(&cm->charger_psy.dev->kobj,
+                               &charger->attr_g);
+               if (ret < 0) {
+                       dev_info(&pdev->dev, "Cannot create sysfs entry"
+                                       "of %s regulator\n",
+                                       charger->regulator_name);
+               }
+       }
+       if (chargers_externally_control) {
+               dev_err(&pdev->dev, "Cannot register regulator because "
+                               "charger-manager must need at least "
+                               "one charger for charging battery\n");
+               ret = -EINVAL;
+               goto err_chg_enable;
        }
  
        ret = try_charger_enable(cm, true);
        return 0;
  
  err_chg_enable:
+       for (i = 0; i < desc->num_charger_regulators; i++) {
+               struct charger_regulator *charger;
+               charger = &desc->charger_regulators[i];
+               sysfs_remove_group(&cm->charger_psy.dev->kobj,
+                               &charger->attr_g);
+               kfree(charger->attr_g.name);
+       }
  err_extcon:
        for (i = 0 ; i < desc->num_charger_regulators ; i++) {
                struct charger_regulator *charger
index 1245fe1f48c336d588a7d2f42a3263d84a18524d,0ba331a06dcc38326ce4f6d15b72860ef00d9622..e128a813dc24c33ea54f476c618cdf9218fa0431
@@@ -146,7 -146,7 +146,7 @@@ static irqreturn_t wm97xx_chrg_irq(int 
  #ifdef CONFIG_PM
  static int wm97xx_bat_suspend(struct device *dev)
  {
 -      flush_work_sync(&bat_work);
 +      flush_work(&bat_work);
        return 0;
  }
  
@@@ -212,8 -212,10 +212,10 @@@ static int __devinit wm97xx_bat_probe(s
                props++;        /* POWER_SUPPLY_PROP_VOLTAGE_MIN */
  
        prop = kzalloc(props * sizeof(*prop), GFP_KERNEL);
-       if (!prop)
+       if (!prop) {
+               ret = -ENOMEM;
                goto err3;
+       }
  
        prop[i++] = POWER_SUPPLY_PROP_PRESENT;
        if (pdata->charge_gpio >= 0)
index ef3e6b701179e3c09d6898d2f3df288fd50866cc,b7c5a3c27c98d5c6d30ff85a407de688135bf091..17c9a87e5be227d46e6a324feda043da8d95f947
@@@ -34,11 -34,42 +34,26 @@@ enum 
        PM8606_ID_MAX,
  };
  
 -enum {
 -      PM8606_BACKLIGHT1 = 0,
 -      PM8606_BACKLIGHT2,
 -      PM8606_BACKLIGHT3,
 -};
 -
 -enum {
 -      PM8606_LED1_RED = 0,
 -      PM8606_LED1_GREEN,
 -      PM8606_LED1_BLUE,
 -      PM8606_LED2_RED,
 -      PM8606_LED2_GREEN,
 -      PM8606_LED2_BLUE,
 -      PM8607_LED_VIBRATOR,
 -};
 -
  
  /* 8606 Registers */
  #define PM8606_DCM_BOOST              (0x00)
  #define PM8606_PWM                    (0x01)
  
+ #define PM8607_MISC2                  (0x42)
+ /* Power Up Log Register */
+ #define PM8607_POWER_UP_LOG           (0x3F)
+ /* Charger Control Registers */
+ #define PM8607_CCNT                   (0x47)
+ #define PM8607_CHG_CTRL1              (0x48)
+ #define PM8607_CHG_CTRL2              (0x49)
+ #define PM8607_CHG_CTRL3              (0x4A)
+ #define PM8607_CHG_CTRL4              (0x4B)
+ #define PM8607_CHG_CTRL5              (0x4C)
+ #define PM8607_CHG_CTRL6              (0x4D)
+ #define PM8607_CHG_CTRL7              (0x4E)
  /* Backlight Registers */
  #define PM8606_WLED1A                 (0x02)
  #define PM8606_WLED1B                 (0x03)
@@@ -189,6 -220,71 +204,71 @@@ enum 
  #define PM8607_PD_PREBIAS             (0x56)  /* prebias time */
  #define PM8607_GPADC_MISC1            (0x57)
  
+ /* bit definitions of  MEAS_EN1*/
+ #define PM8607_MEAS_EN1_VBAT          (1 << 0)
+ #define PM8607_MEAS_EN1_VCHG          (1 << 1)
+ #define PM8607_MEAS_EN1_VSYS          (1 << 2)
+ #define PM8607_MEAS_EN1_TINT          (1 << 3)
+ #define PM8607_MEAS_EN1_RFTMP         (1 << 4)
+ #define PM8607_MEAS_EN1_TBAT          (1 << 5)
+ #define PM8607_MEAS_EN1_GPADC2                (1 << 6)
+ #define PM8607_MEAS_EN1_GPADC3                (1 << 7)
+ /* Battery Monitor Registers */
+ #define PM8607_GP_BIAS2                       (0x5A)
+ #define PM8607_VBAT_LOWTH             (0x5B)
+ #define PM8607_VCHG_LOWTH             (0x5C)
+ #define PM8607_VSYS_LOWTH             (0x5D)
+ #define PM8607_TINT_LOWTH             (0x5E)
+ #define PM8607_GPADC0_LOWTH           (0x5F)
+ #define PM8607_GPADC1_LOWTH           (0x60)
+ #define PM8607_GPADC2_LOWTH           (0x61)
+ #define PM8607_GPADC3_LOWTH           (0x62)
+ #define PM8607_VBAT_HIGHTH            (0x63)
+ #define PM8607_VCHG_HIGHTH            (0x64)
+ #define PM8607_VSYS_HIGHTH            (0x65)
+ #define PM8607_TINT_HIGHTH            (0x66)
+ #define PM8607_GPADC0_HIGHTH          (0x67)
+ #define PM8607_GPADC1_HIGHTH          (0x68)
+ #define PM8607_GPADC2_HIGHTH          (0x69)
+ #define PM8607_GPADC3_HIGHTH          (0x6A)
+ #define PM8607_IBAT_MEAS1             (0x6B)
+ #define PM8607_IBAT_MEAS2             (0x6C)
+ #define PM8607_VBAT_MEAS1             (0x6D)
+ #define PM8607_VBAT_MEAS2             (0x6E)
+ #define PM8607_VCHG_MEAS1             (0x6F)
+ #define PM8607_VCHG_MEAS2             (0x70)
+ #define PM8607_VSYS_MEAS1             (0x71)
+ #define PM8607_VSYS_MEAS2             (0x72)
+ #define PM8607_TINT_MEAS1             (0x73)
+ #define PM8607_TINT_MEAS2             (0x74)
+ #define PM8607_GPADC0_MEAS1           (0x75)
+ #define PM8607_GPADC0_MEAS2           (0x76)
+ #define PM8607_GPADC1_MEAS1           (0x77)
+ #define PM8607_GPADC1_MEAS2           (0x78)
+ #define PM8607_GPADC2_MEAS1           (0x79)
+ #define PM8607_GPADC2_MEAS2           (0x7A)
+ #define PM8607_GPADC3_MEAS1           (0x7B)
+ #define PM8607_GPADC3_MEAS2           (0x7C)
+ #define PM8607_CCNT_MEAS1             (0x95)
+ #define PM8607_CCNT_MEAS2             (0x96)
+ #define PM8607_VBAT_AVG                       (0x97)
+ #define PM8607_VCHG_AVG                       (0x98)
+ #define PM8607_VSYS_AVG                       (0x99)
+ #define PM8607_VBAT_MIN                       (0x9A)
+ #define PM8607_VCHG_MIN                       (0x9B)
+ #define PM8607_VSYS_MIN                       (0x9C)
+ #define PM8607_VBAT_MAX                       (0x9D)
+ #define PM8607_VCHG_MAX                       (0x9E)
+ #define PM8607_VSYS_MAX                       (0x9F)
+ #define PM8607_GPADC_MISC2            (0x59)
+ #define PM8607_GPADC0_GP_BIAS_A0      (1 << 0)
+ #define PM8607_GPADC1_GP_BIAS_A1      (1 << 1)
+ #define PM8607_GPADC2_GP_BIAS_A2      (1 << 2)
+ #define PM8607_GPADC3_GP_BIAS_A3      (1 << 3)
+ #define PM8607_GPADC2_GP_BIAS_OUT2    (1 << 6)
  /* RTC Control Registers */
  #define PM8607_RTC1                   (0xA0)
  #define PM8607_RTC_COUNTER1           (0xA1)
@@@ -306,7 -402,7 +386,7 @@@ struct pm860x_chip 
        struct regmap           *regmap_companion;
  
        int                     buck3_double;   /* DVC ramp slope double */
 -      unsigned short          companion_addr;
 +      int                     companion_addr;
        unsigned short          osc_vote;
        int                     id;
        int                     irq_mode;
@@@ -324,12 -420,16 +404,12 @@@ enum 
  };
  
  struct pm860x_backlight_pdata {
 -      int             id;
        int             pwm;
        int             iset;
 -      unsigned long   flags;
  };
  
  struct pm860x_led_pdata {
 -      int             id;
        int             iset;
 -      unsigned long   flags;
  };
  
  struct pm860x_rtc_pdata {
@@@ -350,7 -450,8 +430,8 @@@ struct pm860x_touch_pdata 
  };
  
  struct pm860x_power_pdata {
-       unsigned        fast_charge;    /* charge current */
+       int             max_capacity;
+       int             resistor;
  };
  
  struct pm860x_platform_data {
        struct pm860x_rtc_pdata         *rtc;
        struct pm860x_touch_pdata       *touch;
        struct pm860x_power_pdata       *power;
 -      struct regulator_init_data      *regulator;
 -
 -      unsigned short  companion_addr; /* I2C address of companion chip */
+       struct charger_desc             *chg_desc;
 +      struct regulator_init_data      *buck1;
 +      struct regulator_init_data      *buck2;
 +      struct regulator_init_data      *buck3;
 +      struct regulator_init_data      *ldo1;
 +      struct regulator_init_data      *ldo2;
 +      struct regulator_init_data      *ldo3;
 +      struct regulator_init_data      *ldo4;
 +      struct regulator_init_data      *ldo5;
 +      struct regulator_init_data      *ldo6;
 +      struct regulator_init_data      *ldo7;
 +      struct regulator_init_data      *ldo8;
 +      struct regulator_init_data      *ldo9;
 +      struct regulator_init_data      *ldo10;
 +      struct regulator_init_data      *ldo12;
 +      struct regulator_init_data      *ldo_vibrator;
 +      struct regulator_init_data      *ldo14;
 +
 +      int             companion_addr; /* I2C address of companion chip */
        int             i2c_port;       /* Controlled by GI2C or PI2C */
        int             irq_mode;       /* Clear interrupt by read/write(0/1) */
        int             irq_base;       /* IRQ base number of 88pm860x */
        int             num_leds;
        int             num_backlights;
 -      int             num_regulators;
  };
  
  extern int pm8606_osc_enable(struct pm860x_chip *, unsigned short);
@@@ -402,4 -490,8 +484,4 @@@ extern int pm860x_page_bulk_write(struc
  extern int pm860x_page_set_bits(struct i2c_client *, int, unsigned char,
                                unsigned char);
  
 -extern int pm860x_device_init(struct pm860x_chip *chip,
 -                            struct pm860x_platform_data *pdata) __devinit ;
 -extern void pm860x_device_exit(struct pm860x_chip *chip) __devexit ;
 -
  #endif /* __LINUX_MFD_88PM860X_H */