Merge remote-tracking branch 'regulator/topic/max8997' into regulator-next
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 19 Feb 2013 12:42:49 +0000 (12:42 +0000)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 19 Feb 2013 12:42:49 +0000 (12:42 +0000)
1  2 
drivers/regulator/max8997.c

@@@ -54,6 -54,13 +54,13 @@@ struct max8997_data 
        u8 saved_states[MAX8997_REG_MAX];
  };
  
+ static const unsigned int safeoutvolt[] = {
+       4850000,
+       4900000,
+       4950000,
+       3300000,
+ };
  static inline void max8997_set_gpio(struct max8997_data *max8997)
  {
        int set3 = (max8997->buck125_gpioindex) & 0x1;
@@@ -71,26 -78,26 +78,26 @@@ struct voltage_map_desc 
        int step;
  };
  
 -/* Voltage maps in mV */
 +/* Voltage maps in uV */
  static const struct voltage_map_desc ldo_voltage_map_desc = {
 -      .min = 800,     .max = 3950,    .step = 50,
 +      .min = 800000,  .max = 3950000, .step = 50000,
  }; /* LDO1 ~ 18, 21 all */
  
  static const struct voltage_map_desc buck1245_voltage_map_desc = {
 -      .min = 650,     .max = 2225,    .step = 25,
 +      .min = 650000,  .max = 2225000, .step = 25000,
  }; /* Buck1, 2, 4, 5 */
  
  static const struct voltage_map_desc buck37_voltage_map_desc = {
 -      .min = 750,     .max = 3900,    .step = 50,
 +      .min = 750000,  .max = 3900000, .step = 50000,
  }; /* Buck3, 7 */
  
 -/* current map in mA */
 +/* current map in uA */
  static const struct voltage_map_desc charger_current_map_desc = {
 -      .min = 200,     .max = 950,     .step = 50,
 +      .min = 200000,  .max = 950000,  .step = 50000,
  };
  
  static const struct voltage_map_desc topoff_current_map_desc = {
 -      .min = 50,      .max = 200,     .step = 10,
 +      .min = 50000,   .max = 200000,  .step = 10000,
  };
  
  static const struct voltage_map_desc *reg_voltage_map[] = {
        [MAX8997_CHARGER_TOPOFF] = &topoff_current_map_desc,
  };
  
- static int max8997_list_voltage_safeout(struct regulator_dev *rdev,
-               unsigned int selector)
- {
-       int rid = rdev_get_id(rdev);
-       if (rid == MAX8997_ESAFEOUT1 || rid == MAX8997_ESAFEOUT2) {
-               switch (selector) {
-               case 0:
-                       return 4850000;
-               case 1:
-                       return 4900000;
-               case 2:
-                       return 4950000;
-               case 3:
-                       return 3300000;
-               default:
-                       return -EINVAL;
-               }
-       }
-       return -EINVAL;
- }
  static int max8997_list_voltage_charger_cv(struct regulator_dev *rdev,
                unsigned int selector)
  {
@@@ -194,7 -178,7 +178,7 @@@ static int max8997_list_voltage(struct 
        if (val > desc->max)
                return -EINVAL;
  
 -      return val * 1000;
 +      return val;
  }
  
  static int max8997_get_enable_register(struct regulator_dev *rdev,
@@@ -485,6 -469,7 +469,6 @@@ static int max8997_set_voltage_ldobuck(
  {
        struct max8997_data *max8997 = rdev_get_drvdata(rdev);
        struct i2c_client *i2c = max8997->iodev->i2c;
 -      int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
        const struct voltage_map_desc *desc;
        int rid = rdev_get_id(rdev);
        int i, reg, shift, mask, ret;
  
        desc = reg_voltage_map[rid];
  
 -      i = max8997_get_voltage_proper_val(desc, min_vol, max_vol);
 +      i = max8997_get_voltage_proper_val(desc, min_uV, max_uV);
        if (i < 0)
                return i;
  
        return ret;
  }
  
- static int max8997_set_voltage_ldobuck_time_sel(struct regulator_dev *rdev,
+ static int max8997_set_voltage_buck_time_sel(struct regulator_dev *rdev,
                                                unsigned int old_selector,
                                                unsigned int new_selector)
  {
        case MAX8997_BUCK4:
        case MAX8997_BUCK5:
                return DIV_ROUND_UP(desc->step * (new_selector - old_selector),
 -                                  max8997->ramp_delay);
 +                                  max8997->ramp_delay * 1000);
        }
  
        return 0;
@@@ -655,6 -640,7 +639,6 @@@ static int max8997_set_voltage_buck(str
        const struct voltage_map_desc *desc;
        int new_val, new_idx, damage, tmp_val, tmp_idx, tmp_dmg;
        bool gpio_dvs_mode = false;
 -      int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
  
        if (rid < MAX8997_BUCK1 || rid > MAX8997_BUCK7)
                return -EINVAL;
                                                selector);
  
        desc = reg_voltage_map[rid];
 -      new_val = max8997_get_voltage_proper_val(desc, min_vol, max_vol);
 +      new_val = max8997_get_voltage_proper_val(desc, min_uV, max_uV);
        if (new_val < 0)
                return new_val;
  
@@@ -720,49 -706,23 +704,23 @@@ out
        return 0;
  }
  
- static const int safeoutvolt[] = {
-       3300000,
-       4850000,
-       4900000,
-       4950000,
- };
  /* For SAFEOUT1 and SAFEOUT2 */
- static int max8997_set_voltage_safeout(struct regulator_dev *rdev,
-               int min_uV, int max_uV, unsigned *selector)
+ static int max8997_set_voltage_safeout_sel(struct regulator_dev *rdev,
+                                          unsigned selector)
  {
        struct max8997_data *max8997 = rdev_get_drvdata(rdev);
        struct i2c_client *i2c = max8997->iodev->i2c;
        int rid = rdev_get_id(rdev);
        int reg, shift = 0, mask, ret;
-       int i = 0;
-       u8 val;
  
        if (rid != MAX8997_ESAFEOUT1 && rid != MAX8997_ESAFEOUT2)
                return -EINVAL;
  
-       for (i = 0; i < ARRAY_SIZE(safeoutvolt); i++) {
-               if (min_uV <= safeoutvolt[i] &&
-                               max_uV >= safeoutvolt[i])
-                       break;
-       }
-       if (i >= ARRAY_SIZE(safeoutvolt))
-               return -EINVAL;
-       if (i == 0)
-               val = 0x3;
-       else
-               val = i - 1;
        ret = max8997_get_voltage_register(rdev, &reg, &shift, &mask);
        if (ret)
                return ret;
  
-       ret = max8997_update_reg(i2c, reg, val << shift, mask << shift);
-       *selector = val;
-       return ret;
+       return max8997_update_reg(i2c, reg, selector << shift, mask << shift);
  }
  
  static int max8997_reg_disable_suspend(struct regulator_dev *rdev)
@@@ -799,7 -759,6 +757,6 @@@ static struct regulator_ops max8997_ldo
        .disable                = max8997_reg_disable,
        .get_voltage_sel        = max8997_get_voltage_sel,
        .set_voltage            = max8997_set_voltage_ldobuck,
-       .set_voltage_time_sel   = max8997_set_voltage_ldobuck_time_sel,
        .set_suspend_disable    = max8997_reg_disable_suspend,
  };
  
@@@ -810,7 -769,7 +767,7 @@@ static struct regulator_ops max8997_buc
        .disable                = max8997_reg_disable,
        .get_voltage_sel        = max8997_get_voltage_sel,
        .set_voltage            = max8997_set_voltage_buck,
-       .set_voltage_time_sel   = max8997_set_voltage_ldobuck_time_sel,
+       .set_voltage_time_sel   = max8997_set_voltage_buck_time_sel,
        .set_suspend_disable    = max8997_reg_disable_suspend,
  };
  
@@@ -823,12 -782,12 +780,12 @@@ static struct regulator_ops max8997_fix
  };
  
  static struct regulator_ops max8997_safeout_ops = {
-       .list_voltage           = max8997_list_voltage_safeout,
+       .list_voltage           = regulator_list_voltage_table,
        .is_enabled             = max8997_reg_is_enabled,
        .enable                 = max8997_reg_enable,
        .disable                = max8997_reg_disable,
        .get_voltage_sel        = max8997_get_voltage_sel,
-       .set_voltage            = max8997_set_voltage_safeout,
+       .set_voltage_sel        = max8997_set_voltage_safeout_sel,
        .set_suspend_disable    = max8997_reg_disable_suspend,
  };
  
@@@ -934,7 -893,7 +891,7 @@@ static struct regulator_desc regulators
  };
  
  #ifdef CONFIG_OF
 -static int max8997_pmic_dt_parse_dvs_gpio(struct max8997_dev *iodev,
 +static int max8997_pmic_dt_parse_dvs_gpio(struct platform_device *pdev,
                        struct max8997_platform_data *pdata,
                        struct device_node *pmic_np)
  {
                gpio = of_get_named_gpio(pmic_np,
                                        "max8997,pmic-buck125-dvs-gpios", i);
                if (!gpio_is_valid(gpio)) {
 -                      dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
 +                      dev_err(&pdev->dev, "invalid gpio[%d]: %d\n", i, gpio);
                        return -EINVAL;
                }
                pdata->buck125_gpios[i] = gpio;
        return 0;
  }
  
 -static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
 +static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
                                        struct max8997_platform_data *pdata)
  {
 +      struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
        struct device_node *pmic_np, *regulators_np, *reg_np;
        struct max8997_regulator_data *rdata;
        unsigned int i, dvs_voltage_nr = 1, ret;
  
        pmic_np = iodev->dev->of_node;
        if (!pmic_np) {
 -              dev_err(iodev->dev, "could not find pmic sub-node\n");
 +              dev_err(&pdev->dev, "could not find pmic sub-node\n");
                return -ENODEV;
        }
  
        regulators_np = of_find_node_by_name(pmic_np, "regulators");
        if (!regulators_np) {
 -              dev_err(iodev->dev, "could not find regulators sub-node\n");
 +              dev_err(&pdev->dev, "could not find regulators sub-node\n");
                return -EINVAL;
        }
  
        for_each_child_of_node(regulators_np, reg_np)
                pdata->num_regulators++;
  
 -      rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
 +      rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *
                                pdata->num_regulators, GFP_KERNEL);
        if (!rdata) {
 -              dev_err(iodev->dev, "could not allocate memory for "
 -                                              "regulator data\n");
 +              dev_err(&pdev->dev, "could not allocate memory for regulator data\n");
                return -ENOMEM;
        }
  
                                break;
  
                if (i == ARRAY_SIZE(regulators)) {
 -                      dev_warn(iodev->dev, "don't know how to configure "
 -                              "regulator %s\n", reg_np->name);
 +                      dev_warn(&pdev->dev, "don't know how to configure regulator %s\n",
 +                               reg_np->name);
                        continue;
                }
  
                rdata->id = i;
 -              rdata->initdata = of_get_regulator_init_data(
 -                                              iodev->dev, reg_np);
 +              rdata->initdata = of_get_regulator_init_data(&pdev->dev,
 +                                                           reg_np);
                rdata->reg_node = reg_np;
                rdata++;
        }
  
        if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs ||
                                                pdata->buck5_gpiodvs) {
 -              ret = max8997_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np);
 +              ret = max8997_pmic_dt_parse_dvs_gpio(pdev, pdata, pmic_np);
                if (ret)
                        return -EINVAL;
  
                } else {
                        if (pdata->buck125_default_idx >= 8) {
                                pdata->buck125_default_idx = 0;
 -                              dev_info(iodev->dev, "invalid value for "
 -                              "default dvs index, using 0 instead\n");
 +                              dev_info(&pdev->dev, "invalid value for default dvs index, using 0 instead\n");
                        }
                }
  
        if (of_property_read_u32_array(pmic_np,
                                "max8997,pmic-buck1-dvs-voltage",
                                pdata->buck1_voltage, dvs_voltage_nr)) {
 -              dev_err(iodev->dev, "buck1 voltages not specified\n");
 +              dev_err(&pdev->dev, "buck1 voltages not specified\n");
                return -EINVAL;
        }
  
        if (of_property_read_u32_array(pmic_np,
                                "max8997,pmic-buck2-dvs-voltage",
                                pdata->buck2_voltage, dvs_voltage_nr)) {
 -              dev_err(iodev->dev, "buck2 voltages not specified\n");
 +              dev_err(&pdev->dev, "buck2 voltages not specified\n");
                return -EINVAL;
        }
  
        if (of_property_read_u32_array(pmic_np,
                                "max8997,pmic-buck5-dvs-voltage",
                                pdata->buck5_voltage, dvs_voltage_nr)) {
 -              dev_err(iodev->dev, "buck5 voltages not specified\n");
 +              dev_err(&pdev->dev, "buck5 voltages not specified\n");
                return -EINVAL;
        }
  
        return 0;
  }
  #else
 -static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
 +static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
                                        struct max8997_platform_data *pdata)
  {
        return 0;
@@@ -1084,7 -1044,7 +1041,7 @@@ static int max8997_pmic_probe(struct pl
        }
  
        if (iodev->dev->of_node) {
 -              ret = max8997_pmic_dt_parse_pdata(iodev, pdata);
 +              ret = max8997_pmic_dt_parse_pdata(pdev, pdata);
                if (ret)
                        return ret;
        }
                max8997->buck1_vol[i] = ret =
                        max8997_get_voltage_proper_val(
                                        &buck1245_voltage_map_desc,
 -                                      pdata->buck1_voltage[i] / 1000,
 -                                      pdata->buck1_voltage[i] / 1000 +
 +                                      pdata->buck1_voltage[i],
 +                                      pdata->buck1_voltage[i] +
                                        buck1245_voltage_map_desc.step);
                if (ret < 0)
                        goto err_out;
                max8997->buck2_vol[i] = ret =
                        max8997_get_voltage_proper_val(
                                        &buck1245_voltage_map_desc,
 -                                      pdata->buck2_voltage[i] / 1000,
 -                                      pdata->buck2_voltage[i] / 1000 +
 +                                      pdata->buck2_voltage[i],
 +                                      pdata->buck2_voltage[i] +
                                        buck1245_voltage_map_desc.step);
                if (ret < 0)
                        goto err_out;
                max8997->buck5_vol[i] = ret =
                        max8997_get_voltage_proper_val(
                                        &buck1245_voltage_map_desc,
 -                                      pdata->buck5_voltage[i] / 1000,
 -                                      pdata->buck5_voltage[i] / 1000 +
 +                                      pdata->buck5_voltage[i],
 +                                      pdata->buck5_voltage[i] +
                                        buck1245_voltage_map_desc.step);
                if (ret < 0)
                        goto err_out;
                int id = pdata->regulators[i].id;
  
                desc = reg_voltage_map[id];
-               if (desc)
+               if (desc) {
                        regulators[id].n_voltages =
                                (desc->max - desc->min) / desc->step + 1;
-               else if (id == MAX8997_ESAFEOUT1 || id == MAX8997_ESAFEOUT2)
-                       regulators[id].n_voltages = 4;
-               else if (id == MAX8997_CHARGER_CV)
+               } else if (id == MAX8997_ESAFEOUT1 || id == MAX8997_ESAFEOUT2) {
+                       regulators[id].volt_table = safeoutvolt;
+                       regulators[id].n_voltages = ARRAY_SIZE(safeoutvolt);
+               } else if (id == MAX8997_CHARGER_CV) {
                        regulators[id].n_voltages = 16;
+               }
  
                config.dev = max8997->dev;
                config.init_data = pdata->regulators[i].initdata;