Merge branch 'mfd/wm8994' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[linux-2.6.git] / drivers / power / wm831x_power.c
index 2a4c8b0..6cc2ca6 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/err.h>
 #include <linux/platform_device.h>
 #include <linux/power_supply.h>
+#include <linux/slab.h>
 
 #include <linux/mfd/wm831x/core.h>
 #include <linux/mfd/wm831x/auxadc.h>
 struct wm831x_power {
        struct wm831x *wm831x;
        struct power_supply wall;
-       struct power_supply backup;
        struct power_supply usb;
        struct power_supply battery;
+       char wall_name[20];
+       char usb_name[20];
+       char battery_name[20];
 };
 
 static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
@@ -267,7 +270,6 @@ static void wm831x_config_battery(struct wm831x *wm831x)
        ret = wm831x_set_bits(wm831x, WM831X_CHARGER_CONTROL_1,
                              WM831X_CHG_ENA_MASK |
                              WM831X_CHG_FAST_MASK |
-                             WM831X_CHG_ITERM_MASK |
                              WM831X_CHG_ITERM_MASK,
                              reg1);
        if (ret != 0)
@@ -454,125 +456,6 @@ static irqreturn_t wm831x_bat_irq(int irq, void *data)
 
 
 /*********************************************************************
- *             Backup supply properties
- *********************************************************************/
-
-static void wm831x_config_backup(struct wm831x *wm831x)
-{
-       struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data;
-       struct wm831x_backup_pdata *pdata;
-       int ret, reg;
-
-       if (!wm831x_pdata || !wm831x_pdata->backup) {
-               dev_warn(wm831x->dev,
-                        "No backup battery charger configuration\n");
-               return;
-       }
-
-       pdata = wm831x_pdata->backup;
-
-       reg = 0;
-
-       if (pdata->charger_enable)
-               reg |= WM831X_BKUP_CHG_ENA | WM831X_BKUP_BATT_DET_ENA;
-       if (pdata->no_constant_voltage)
-               reg |= WM831X_BKUP_CHG_MODE;
-
-       switch (pdata->vlim) {
-       case 2500:
-               break;
-       case 3100:
-               reg |= WM831X_BKUP_CHG_VLIM;
-               break;
-       default:
-               dev_err(wm831x->dev, "Invalid backup voltage limit %dmV\n",
-                       pdata->vlim);
-       }
-
-       switch (pdata->ilim) {
-       case 100:
-               break;
-       case 200:
-               reg |= 1;
-               break;
-       case 300:
-               reg |= 2;
-               break;
-       case 400:
-               reg |= 3;
-               break;
-       default:
-               dev_err(wm831x->dev, "Invalid backup current limit %duA\n",
-                       pdata->ilim);
-       }
-
-       ret = wm831x_reg_unlock(wm831x);
-       if (ret != 0) {
-               dev_err(wm831x->dev, "Failed to unlock registers: %d\n", ret);
-               return;
-       }
-
-       ret = wm831x_set_bits(wm831x, WM831X_BACKUP_CHARGER_CONTROL,
-                             WM831X_BKUP_CHG_ENA_MASK |
-                             WM831X_BKUP_CHG_MODE_MASK |
-                             WM831X_BKUP_BATT_DET_ENA_MASK |
-                             WM831X_BKUP_CHG_VLIM_MASK |
-                             WM831X_BKUP_CHG_ILIM_MASK,
-                             reg);
-       if (ret != 0)
-               dev_err(wm831x->dev,
-                       "Failed to set backup charger config: %d\n", ret);
-
-       wm831x_reg_lock(wm831x);
-}
-
-static int wm831x_backup_get_prop(struct power_supply *psy,
-                                 enum power_supply_property psp,
-                                 union power_supply_propval *val)
-{
-       struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev->parent);
-       struct wm831x *wm831x = wm831x_power->wm831x;
-       int ret = 0;
-
-       ret = wm831x_reg_read(wm831x, WM831X_BACKUP_CHARGER_CONTROL);
-       if (ret < 0)
-               return ret;
-
-       switch (psp) {
-       case POWER_SUPPLY_PROP_STATUS:
-               if (ret & WM831X_BKUP_CHG_STS)
-                       val->intval = POWER_SUPPLY_STATUS_CHARGING;
-               else
-                       val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
-               break;
-
-       case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-               ret = wm831x_power_read_voltage(wm831x, WM831X_AUX_BKUP_BATT,
-                                               val);
-               break;
-
-       case POWER_SUPPLY_PROP_PRESENT:
-               if (ret & WM831X_BKUP_CHG_STS)
-                       val->intval = 1;
-               else
-                       val->intval = 0;
-               break;
-
-       default:
-               ret = -EINVAL;
-               break;
-       }
-
-       return ret;
-}
-
-static enum power_supply_property wm831x_backup_props[] = {
-       POWER_SUPPLY_PROP_STATUS,
-       POWER_SUPPLY_PROP_VOLTAGE_NOW,
-       POWER_SUPPLY_PROP_PRESENT,
-};
-
-/*********************************************************************
  *             Initialisation
  *********************************************************************/
 
@@ -595,10 +478,7 @@ static irqreturn_t wm831x_pwr_src_irq(int irq, void *data)
 
        dev_dbg(wm831x->dev, "Power source changed\n");
 
-       /* Just notify for everything - little harm in overnotifying.
-        * The backup battery is not a power source while the system
-        * is running so skip that.
-        */
+       /* Just notify for everything - little harm in overnotifying. */
        power_supply_changed(&wm831x_power->battery);
        power_supply_changed(&wm831x_power->usb);
        power_supply_changed(&wm831x_power->wall);
@@ -609,11 +489,11 @@ static irqreturn_t wm831x_pwr_src_irq(int irq, void *data)
 static __devinit int wm831x_power_probe(struct platform_device *pdev)
 {
        struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
+       struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data;
        struct wm831x_power *power;
        struct power_supply *usb;
        struct power_supply *battery;
        struct power_supply *wall;
-       struct power_supply *backup;
        int ret, irq, i;
 
        power = kzalloc(sizeof(struct wm831x_power), GFP_KERNEL);
@@ -626,15 +506,29 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
        usb = &power->usb;
        battery = &power->battery;
        wall = &power->wall;
-       backup = &power->backup;
+
+       if (wm831x_pdata && wm831x_pdata->wm831x_num) {
+               snprintf(power->wall_name, sizeof(power->wall_name),
+                        "wm831x-wall.%d", wm831x_pdata->wm831x_num);
+               snprintf(power->battery_name, sizeof(power->wall_name),
+                        "wm831x-battery.%d", wm831x_pdata->wm831x_num);
+               snprintf(power->usb_name, sizeof(power->wall_name),
+                        "wm831x-usb.%d", wm831x_pdata->wm831x_num);
+       } else {
+               snprintf(power->wall_name, sizeof(power->wall_name),
+                        "wm831x-wall");
+               snprintf(power->battery_name, sizeof(power->wall_name),
+                        "wm831x-battery");
+               snprintf(power->usb_name, sizeof(power->wall_name),
+                        "wm831x-usb");
+       }
 
        /* We ignore configuration failures since we can still read back
-        * the status without enabling either of the chargers.
+        * the status without enabling the charger.
         */
        wm831x_config_battery(wm831x);
-       wm831x_config_backup(wm831x);
 
-       wall->name = "wm831x-wall";
+       wall->name = power->wall_name;
        wall->type = POWER_SUPPLY_TYPE_MAINS;
        wall->properties = wm831x_wall_props;
        wall->num_properties = ARRAY_SIZE(wm831x_wall_props);
@@ -643,7 +537,7 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
        if (ret)
                goto err_kmalloc;
 
-       battery->name = "wm831x-battery";
+       battery->name = power->battery_name;
        battery->properties = wm831x_bat_props;
        battery->num_properties = ARRAY_SIZE(wm831x_bat_props);
        battery->get_property = wm831x_bat_get_prop;
@@ -652,7 +546,7 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
        if (ret)
                goto err_wall;
 
-       usb->name = "wm831x-usb",
+       usb->name = power->usb_name,
        usb->type = POWER_SUPPLY_TYPE_USB;
        usb->properties = wm831x_usb_props;
        usb->num_properties = ARRAY_SIZE(wm831x_usb_props);
@@ -661,29 +555,20 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
        if (ret)
                goto err_battery;
 
-       backup->name = "wm831x-backup";
-       backup->type = POWER_SUPPLY_TYPE_BATTERY;
-       backup->properties = wm831x_backup_props;
-       backup->num_properties = ARRAY_SIZE(wm831x_backup_props);
-       backup->get_property = wm831x_backup_get_prop;
-       ret = power_supply_register(&pdev->dev, backup);
-       if (ret)
-               goto err_usb;
-
        irq = platform_get_irq_byname(pdev, "SYSLO");
-       ret = wm831x_request_irq(wm831x, irq, wm831x_syslo_irq,
-                                IRQF_TRIGGER_RISING, "SYSLO",
-                                power);
+       ret = request_threaded_irq(irq, NULL, wm831x_syslo_irq,
+                                  IRQF_TRIGGER_RISING, "System power low",
+                                  power);
        if (ret != 0) {
                dev_err(&pdev->dev, "Failed to request SYSLO IRQ %d: %d\n",
                        irq, ret);
-               goto err_backup;
+               goto err_usb;
        }
 
        irq = platform_get_irq_byname(pdev, "PWR SRC");
-       ret = wm831x_request_irq(wm831x, irq, wm831x_pwr_src_irq,
-                                IRQF_TRIGGER_RISING, "Power source",
-                                power);
+       ret = request_threaded_irq(irq, NULL, wm831x_pwr_src_irq,
+                                  IRQF_TRIGGER_RISING, "Power source",
+                                  power);
        if (ret != 0) {
                dev_err(&pdev->dev, "Failed to request PWR SRC IRQ %d: %d\n",
                        irq, ret);
@@ -692,10 +577,10 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
 
        for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) {
                irq = platform_get_irq_byname(pdev, wm831x_bat_irqs[i]);
-               ret = wm831x_request_irq(wm831x, irq, wm831x_bat_irq,
-                                        IRQF_TRIGGER_RISING,
-                                        wm831x_bat_irqs[i],
-                                        power);
+               ret = request_threaded_irq(irq, NULL, wm831x_bat_irq,
+                                          IRQF_TRIGGER_RISING,
+                                          wm831x_bat_irqs[i],
+                                          power);
                if (ret != 0) {
                        dev_err(&pdev->dev,
                                "Failed to request %s IRQ %d: %d\n",
@@ -709,15 +594,13 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
 err_bat_irq:
        for (; i >= 0; i--) {
                irq = platform_get_irq_byname(pdev, wm831x_bat_irqs[i]);
-               wm831x_free_irq(wm831x, irq, power);
+               free_irq(irq, power);
        }
        irq = platform_get_irq_byname(pdev, "PWR SRC");
-       wm831x_free_irq(wm831x, irq, power);
+       free_irq(irq, power);
 err_syslo:
        irq = platform_get_irq_byname(pdev, "SYSLO");
-       wm831x_free_irq(wm831x, irq, power);
-err_backup:
-       power_supply_unregister(backup);
+       free_irq(irq, power);
 err_usb:
        power_supply_unregister(usb);
 err_battery:
@@ -732,24 +615,23 @@ err_kmalloc:
 static __devexit int wm831x_power_remove(struct platform_device *pdev)
 {
        struct wm831x_power *wm831x_power = platform_get_drvdata(pdev);
-       struct wm831x *wm831x = wm831x_power->wm831x;
        int irq, i;
 
        for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) {
                irq = platform_get_irq_byname(pdev, wm831x_bat_irqs[i]);
-               wm831x_free_irq(wm831x, irq, wm831x_power);
+               free_irq(irq, wm831x_power);
        }
 
        irq = platform_get_irq_byname(pdev, "PWR SRC");
-       wm831x_free_irq(wm831x, irq, wm831x_power);
+       free_irq(irq, wm831x_power);
 
        irq = platform_get_irq_byname(pdev, "SYSLO");
-       wm831x_free_irq(wm831x, irq, wm831x_power);
+       free_irq(irq, wm831x_power);
 
-       power_supply_unregister(&wm831x_power->backup);
        power_supply_unregister(&wm831x_power->battery);
        power_supply_unregister(&wm831x_power->wall);
        power_supply_unregister(&wm831x_power->usb);
+       kfree(wm831x_power);
        return 0;
 }