]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
Merge remote-tracking branch 'regulator/topic/palmas' into regulator-next
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 10 Dec 2012 03:43:17 +0000 (12:43 +0900)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 10 Dec 2012 03:43:17 +0000 (12:43 +0900)
1  2 
drivers/regulator/palmas-regulator.c

index fd27a43a9fbcfef96504ffe34103b8907925a513,f4142b4c971b914435a06a747c040b6e4573c9ce..e915629a25cf64ed660e9ac9f2b2112b1ea228e9
@@@ -309,68 -309,22 +309,22 @@@ static int palmas_list_voltage_smps(str
        int id = rdev_get_id(dev);
        int mult = 1;
  
-       if (!selector)
-               return 0;
        /* Read the multiplier set in VSEL register to return
         * the correct voltage.
         */
        if (pmic->range[id])
                mult = 2;
  
-       /* Voltage is (0.49V + (selector * 0.01V)) * RANGE
-        * as defined in data sheet. RANGE is either x1 or x2
-        */
-       return  (490000 + (selector * 10000)) * mult;
- }
- static int palmas_get_voltage_smps_sel(struct regulator_dev *dev)
- {
-       struct palmas_pmic *pmic = rdev_get_drvdata(dev);
-       int id = rdev_get_id(dev);
-       int selector;
-       unsigned int reg;
-       unsigned int addr;
-       addr = palmas_regs_info[id].vsel_addr;
-       palmas_smps_read(pmic->palmas, addr, &reg);
-       selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
-       /* Adjust selector to match list_voltage ranges */
-       if ((selector > 0) && (selector < 6))
-               selector = 6;
-       if (!selector)
-               selector = 5;
-       if (selector > 121)
-               selector = 121;
-       selector -= 5;
-       return selector;
- }
- static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,
-               unsigned selector)
- {
-       struct palmas_pmic *pmic = rdev_get_drvdata(dev);
-       int id = rdev_get_id(dev);
-       unsigned int reg = 0;
-       unsigned int addr;
-       addr = palmas_regs_info[id].vsel_addr;
-       /* Make sure we don't change the value of RANGE */
-       if (pmic->range[id])
-               reg |= PALMAS_SMPS12_VOLTAGE_RANGE;
-       /* Adjust the linux selector into range used in VSEL register */
-       if (selector)
-               reg |= selector + 5;
-       palmas_smps_write(pmic->palmas, addr, reg);
-       return 0;
+       if (selector == 0)
+               return 0;
+       else if (selector < 6)
+               return 500000 * mult;
+       else
+               /* Voltage is linear mapping starting from selector 6,
+                * volt = (0.49V + ((selector - 5) * 0.01V)) * RANGE
+                * RANGE is either x1 or x2
+                */
+               return (490000 + ((selector - 5) * 10000)) * mult;
  }
  
  static int palmas_map_voltage_smps(struct regulator_dev *rdev,
        if (pmic->range[id]) { /* RANGE is x2 */
                if (min_uV < 1000000)
                        min_uV = 1000000;
-               ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1;
+               ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 6;
        } else {                /* RANGE is x1 */
                if (min_uV < 500000)
                        min_uV = 500000;
-               ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1;
+               ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 6;
        }
  
        /* Map back into a voltage to verify we're still in bounds */
@@@ -407,8 -361,8 +361,8 @@@ static struct regulator_ops palmas_ops_
        .disable                = palmas_disable_smps,
        .set_mode               = palmas_set_mode_smps,
        .get_mode               = palmas_get_mode_smps,
-       .get_voltage_sel        = palmas_get_voltage_smps_sel,
-       .set_voltage_sel        = palmas_set_voltage_smps_sel,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
        .list_voltage           = palmas_list_voltage_smps,
        .map_voltage            = palmas_map_voltage_smps,
  };
@@@ -436,14 -390,44 +390,14 @@@ static int palmas_is_enabled_ldo(struc
        return !!(reg);
  }
  
 -static int palmas_list_voltage_ldo(struct regulator_dev *dev,
 -                                      unsigned selector)
 -{
 -      if (!selector)
 -              return 0;
 -
 -      /* voltage is 0.85V + (selector * 0.05v) */
 -      return  850000 + (selector * 50000);
 -}
 -
 -static int palmas_map_voltage_ldo(struct regulator_dev *rdev,
 -              int min_uV, int max_uV)
 -{
 -      int ret, voltage;
 -
 -      if (min_uV == 0)
 -              return 0;
 -
 -      if (min_uV < 900000)
 -              min_uV = 900000;
 -      ret = DIV_ROUND_UP(min_uV - 900000, 50000) + 1;
 -
 -      /* Map back into a voltage to verify we're still in bounds */
 -      voltage = palmas_list_voltage_ldo(rdev, ret);
 -      if (voltage < min_uV || voltage > max_uV)
 -              return -EINVAL;
 -
 -      return ret;
 -}
 -
  static struct regulator_ops palmas_ops_ldo = {
        .is_enabled             = palmas_is_enabled_ldo,
        .enable                 = regulator_enable_regmap,
        .disable                = regulator_disable_regmap,
        .get_voltage_sel        = regulator_get_voltage_sel_regmap,
        .set_voltage_sel        = regulator_set_voltage_sel_regmap,
 -      .list_voltage           = palmas_list_voltage_ldo,
 -      .map_voltage            = palmas_map_voltage_ldo,
 +      .list_voltage           = regulator_list_voltage_linear,
 +      .map_voltage            = regulator_map_voltage_linear,
  };
  
  /*
@@@ -565,7 -549,7 +519,7 @@@ static struct of_regulator_match palmas
        { .name = "ldousb", },
  };
  
 -static void __devinit palmas_dt_to_pdata(struct device *dev,
 +static void palmas_dt_to_pdata(struct device *dev,
                struct device_node *node,
                struct palmas_pmic_platform_data *pdata)
  {
  }
  
  
 -static __devinit int palmas_probe(struct platform_device *pdev)
 +static int palmas_probe(struct platform_device *pdev)
  {
        struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
        struct palmas_pmic_platform_data *pdata = pdev->dev.platform_data;
                                continue;
                }
  
+               /* Initialise sleep/init values from platform data */
+               if (pdata && pdata->reg_init[id]) {
+                       reg_init = pdata->reg_init[id];
+                       ret = palmas_smps_init(palmas, id, reg_init);
+                       if (ret)
+                               goto err_unregister_regulator;
+               }
                /* Register the regulators */
                pmic->desc[id].name = palmas_regs_info[id].name;
                pmic->desc[id].id = id;
                        pmic->desc[id].uV_step = 1250000;
                        break;
                default:
-                       pmic->desc[id].ops = &palmas_ops_smps;
-                       pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
-               }
-               pmic->desc[id].type = REGULATOR_VOLTAGE;
-               pmic->desc[id].owner = THIS_MODULE;
-               /* Initialise sleep/init values from platform data */
-               if (pdata) {
-                       reg_init = pdata->reg_init[id];
-                       if (reg_init) {
-                               ret = palmas_smps_init(palmas, id, reg_init);
-                               if (ret)
-                                       goto err_unregister_regulator;
-                       }
-               }
-               /*
-                * read and store the RANGE bit for later use
-                * This must be done before regulator is probed otherwise
-                * we error in probe with unsuportable ranges.
-                */
-               if (id != PALMAS_REG_SMPS10) {
+                       /*
+                        * Read and store the RANGE bit for later use
+                        * This must be done before regulator is probed,
+                        * otherwise we error in probe with unsupportable ranges.
+                        */
                        addr = palmas_regs_info[id].vsel_addr;
  
                        ret = palmas_smps_read(pmic->palmas, addr, &reg);
                                goto err_unregister_regulator;
                        if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
                                pmic->range[id] = 1;
+                       pmic->desc[id].ops = &palmas_ops_smps;
+                       pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
+                       pmic->desc[id].vsel_reg =
+                                       PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
+                                               palmas_regs_info[id].vsel_addr);
+                       pmic->desc[id].vsel_mask =
+                                       PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
                }
  
+               pmic->desc[id].type = REGULATOR_VOLTAGE;
+               pmic->desc[id].owner = THIS_MODULE;
                if (pdata)
                        config.init_data = pdata->reg_data[id];
                else
  
                pmic->desc[id].type = REGULATOR_VOLTAGE;
                pmic->desc[id].owner = THIS_MODULE;
 +              pmic->desc[id].min_uV = 900000;
 +              pmic->desc[id].uV_step = 50000;
 +              pmic->desc[id].linear_min_sel = 1;
                pmic->desc[id].vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
                                                palmas_regs_info[id].vsel_addr);
                pmic->desc[id].vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK;
@@@ -841,7 -823,7 +796,7 @@@ err_unregister_regulator
        return ret;
  }
  
 -static int __devexit palmas_remove(struct platform_device *pdev)
 +static int palmas_remove(struct platform_device *pdev)
  {
        struct palmas_pmic *pmic = platform_get_drvdata(pdev);
        int id;
@@@ -863,7 -845,7 +818,7 @@@ static struct platform_driver palmas_dr
                .owner = THIS_MODULE,
        },
        .probe = palmas_probe,
 -      .remove = __devexit_p(palmas_remove),
 +      .remove = palmas_remove,
  };
  
  static int __init palmas_init(void)