Merge remote-tracking branches 'regulator/fix/max8907', 'regulator/fix/max8997', 'regulator/fix/tps65910' and 'regulator/topic/mc13892' into regulator-of
···934934};935935936936#ifdef CONFIG_OF937937-static int max8997_pmic_dt_parse_dvs_gpio(struct max8997_dev *iodev,937937+static int max8997_pmic_dt_parse_dvs_gpio(struct platform_device *pdev,938938 struct max8997_platform_data *pdata,939939 struct device_node *pmic_np)940940{···944944 gpio = of_get_named_gpio(pmic_np,945945 "max8997,pmic-buck125-dvs-gpios", i);946946 if (!gpio_is_valid(gpio)) {947947- dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);947947+ dev_err(&pdev->dev, "invalid gpio[%d]: %d\n", i, gpio);948948 return -EINVAL;949949 }950950 pdata->buck125_gpios[i] = gpio;···952952 return 0;953953}954954955955-static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,955955+static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,956956 struct max8997_platform_data *pdata)957957{958958+ struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);958959 struct device_node *pmic_np, *regulators_np, *reg_np;959960 struct max8997_regulator_data *rdata;960961 unsigned int i, dvs_voltage_nr = 1, ret;961962962963 pmic_np = iodev->dev->of_node;963964 if (!pmic_np) {964964- dev_err(iodev->dev, "could not find pmic sub-node\n");965965+ dev_err(&pdev->dev, "could not find pmic sub-node\n");965966 return -ENODEV;966967 }967968968969 regulators_np = of_find_node_by_name(pmic_np, "regulators");969970 if (!regulators_np) {970970- dev_err(iodev->dev, "could not find regulators sub-node\n");971971+ dev_err(&pdev->dev, "could not find regulators sub-node\n");971972 return -EINVAL;972973 }973974···977976 for_each_child_of_node(regulators_np, reg_np)978977 pdata->num_regulators++;979978980980- rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *979979+ rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *981980 pdata->num_regulators, GFP_KERNEL);982981 if (!rdata) {983983- dev_err(iodev->dev, "could not allocate memory for "984984- "regulator data\n");982982+ dev_err(&pdev->dev, "could not allocate memory for regulator data\n");985983 return -ENOMEM;986984 }987985···991991 break;992992993993 if (i == ARRAY_SIZE(regulators)) {994994- dev_warn(iodev->dev, "don't know how to configure "995995- "regulator %s\n", reg_np->name);994994+ dev_warn(&pdev->dev, "don't know how to configure regulator %s\n",995995+ reg_np->name);996996 continue;997997 }998998999999 rdata->id = i;10001000- rdata->initdata = of_get_regulator_init_data(10011001- iodev->dev, reg_np);10001000+ rdata->initdata = of_get_regulator_init_data(&pdev->dev,10011001+ reg_np);10021002 rdata->reg_node = reg_np;10031003 rdata++;10041004 }···1014101410151015 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs ||10161016 pdata->buck5_gpiodvs) {10171017- ret = max8997_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np);10171017+ ret = max8997_pmic_dt_parse_dvs_gpio(pdev, pdata, pmic_np);10181018 if (ret)10191019 return -EINVAL;10201020···10251025 } else {10261026 if (pdata->buck125_default_idx >= 8) {10271027 pdata->buck125_default_idx = 0;10281028- dev_info(iodev->dev, "invalid value for "10291029- "default dvs index, using 0 instead\n");10281028+ dev_info(&pdev->dev, "invalid value for default dvs index, using 0 instead\n");10301029 }10311030 }10321031···10391040 if (of_property_read_u32_array(pmic_np,10401041 "max8997,pmic-buck1-dvs-voltage",10411042 pdata->buck1_voltage, dvs_voltage_nr)) {10421042- dev_err(iodev->dev, "buck1 voltages not specified\n");10431043+ dev_err(&pdev->dev, "buck1 voltages not specified\n");10431044 return -EINVAL;10441045 }1045104610461047 if (of_property_read_u32_array(pmic_np,10471048 "max8997,pmic-buck2-dvs-voltage",10481049 pdata->buck2_voltage, dvs_voltage_nr)) {10491049- dev_err(iodev->dev, "buck2 voltages not specified\n");10501050+ dev_err(&pdev->dev, "buck2 voltages not specified\n");10501051 return -EINVAL;10511052 }1052105310531054 if (of_property_read_u32_array(pmic_np,10541055 "max8997,pmic-buck5-dvs-voltage",10551056 pdata->buck5_voltage, dvs_voltage_nr)) {10561056- dev_err(iodev->dev, "buck5 voltages not specified\n");10571057+ dev_err(&pdev->dev, "buck5 voltages not specified\n");10571058 return -EINVAL;10581059 }1059106010601061 return 0;10611062}10621063#else10631063-static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,10641064+static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,10641065 struct max8997_platform_data *pdata)10651066{10661067 return 0;···10841085 }1085108610861087 if (iodev->dev->of_node) {10871087- ret = max8997_pmic_dt_parse_pdata(iodev, pdata);10881088+ ret = max8997_pmic_dt_parse_pdata(pdev, pdata);10881089 if (ret)10891090 return ret;10901091 }
+92-17
drivers/regulator/mc13892-regulator.c
···164164 1350000, 1375000165165};166166167167+/*168168+ * Note: this table is used to derive SWxVSEL by index into169169+ * the array. Offset the values by the index of 1100000uV170170+ * to get the actual register value for that voltage selector171171+ * if the HI bit is to be set as well.172172+ */173173+#define MC13892_SWxHI_SEL_OFFSET 20174174+167175static const unsigned int mc13892_sw[] = {168176 600000, 625000, 650000, 675000, 700000, 725000,169177 750000, 775000, 800000, 825000, 850000, 875000,···247239};248240249241static struct regulator_ops mc13892_gpo_regulator_ops;250250-/* sw regulators need special care due to the "hi bit" */251242static struct regulator_ops mc13892_sw_regulator_ops;252243253244···403396{404397 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);405398 int ret, id = rdev_get_id(rdev);406406- unsigned int val;399399+ unsigned int val, selector;407400408401 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);409402···414407 if (ret)415408 return ret;416409417417- val = (val & mc13892_regulators[id].vsel_mask)418418- >> mc13892_regulators[id].vsel_shift;410410+ /*411411+ * Figure out if the HI bit is set inside the switcher mode register412412+ * since this means the selector value we return is at a different413413+ * offset into the selector table.414414+ *415415+ * According to the MC13892 documentation note 59 (Table 47) the SW1416416+ * buck switcher does not support output range programming therefore417417+ * the HI bit must always remain 0. So do not do anything strange if418418+ * our register is MC13892_SWITCHERS0.419419+ */419420420420- dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);421421+ selector = val & mc13892_regulators[id].vsel_mask;421422422422- return val;423423+ if ((mc13892_regulators[id].vsel_reg != MC13892_SWITCHERS0) &&424424+ (val & MC13892_SWITCHERS0_SWxHI)) {425425+ selector += MC13892_SWxHI_SEL_OFFSET;426426+ }427427+428428+ dev_dbg(rdev_get_dev(rdev), "%s id: %d val: 0x%08x selector: %d\n",429429+ __func__, id, val, selector);430430+431431+ return selector;423432}424433425434static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,···448425449426 volt = rdev->desc->volt_table[selector];450427 mask = mc13892_regulators[id].vsel_mask;451451- reg_value = selector << mc13892_regulators[id].vsel_shift;428428+ reg_value = selector;452429453453- if (volt > 1375000) {454454- mask |= MC13892_SWITCHERS0_SWxHI;455455- reg_value |= MC13892_SWITCHERS0_SWxHI;456456- } else if (volt < 1100000) {457457- mask |= MC13892_SWITCHERS0_SWxHI;458458- reg_value &= ~MC13892_SWITCHERS0_SWxHI;430430+ /*431431+ * Don't mess with the HI bit or support HI voltage offsets for SW1.432432+ *433433+ * Since the get_voltage_sel callback has given a fudged value for434434+ * the selector offset, we need to back out that offset if HI is435435+ * to be set so we write the correct value to the register.436436+ *437437+ * The HI bit addition and selector offset handling COULD be more438438+ * complicated by shifting and masking off the voltage selector part439439+ * of the register then logical OR it back in, but since the selector440440+ * is at bits 4:0 there is very little point. This makes the whole441441+ * thing more readable and we do far less work.442442+ */443443+444444+ if (mc13892_regulators[id].vsel_reg != MC13892_SWITCHERS0) {445445+ if (volt > 1375000) {446446+ reg_value -= MC13892_SWxHI_SEL_OFFSET;447447+ reg_value |= MC13892_SWITCHERS0_SWxHI;448448+ mask |= MC13892_SWITCHERS0_SWxHI;449449+ } else if (volt < 1100000) {450450+ reg_value &= ~MC13892_SWITCHERS0_SWxHI;451451+ mask |= MC13892_SWITCHERS0_SWxHI;452452+ }459453 }460454461455 mc13xxx_lock(priv->mc13xxx);462462- ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg, mask,456456+ ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].vsel_reg, mask,463457 reg_value);464458 mc13xxx_unlock(priv->mc13xxx);465459···535495 struct mc13xxx_regulator_init_data *mc13xxx_data;536496 struct regulator_config config = { };537497 int i, ret;538538- int num_regulators = 0;498498+ int num_regulators = 0, num_parsed;539499 u32 val;540500541501 num_regulators = mc13xxx_get_num_regulators_dt(pdev);502502+542503 if (num_regulators <= 0 && pdata)543504 num_regulators = pdata->num_regulators;544505 if (num_regulators <= 0)545506 return -EINVAL;507507+508508+ num_parsed = num_regulators;546509547510 priv = devm_kzalloc(&pdev->dev, sizeof(*priv) +548511 num_regulators * sizeof(priv->regulators[0]),···563520 if (ret)564521 goto err_unlock;565522566566- /* enable switch auto mode */523523+ /* enable switch auto mode (on 2.0A silicon only) */567524 if ((val & 0x0000FFFF) == 0x45d0) {568525 ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS4,569526 MC13892_SWITCHERS4_SW1MODE_M |···589546 = mc13892_vcam_get_mode;590547591548 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,592592- ARRAY_SIZE(mc13892_regulators));549549+ ARRAY_SIZE(mc13892_regulators),550550+ &num_parsed);551551+552552+ /*553553+ * Perform a little sanity check on the regulator tree - if we found554554+ * a number of regulators from mc13xxx_get_num_regulators_dt and555555+ * then parsed a smaller number in mc13xxx_parse_regulators_dt then556556+ * there is a regulator defined in the regulators node which has557557+ * not matched any usable regulator in the driver. In this case,558558+ * there is one missing and what will happen is the first regulator559559+ * will get registered again.560560+ *561561+ * Fix this by basically making our number of registerable regulators562562+ * equal to the number of regulators we parsed. We are allocating563563+ * too much memory for priv, but this is unavoidable at this point.564564+ *565565+ * As an example of how this can happen, try making a typo in your566566+ * regulators node (vviohi {} instead of viohi {}) so that the name567567+ * does not match..568568+ *569569+ * The check will basically pass for platform data (non-DT) because570570+ * mc13xxx_parse_regulators_dt for !CONFIG_OF will not touch num_parsed.571571+ *572572+ */573573+ if (num_parsed != num_regulators) {574574+ dev_warn(&pdev->dev,575575+ "parsed %d != regulators %d - check your device tree!\n",576576+ num_parsed, num_regulators);577577+578578+ num_regulators = num_parsed;579579+ priv->num_regulators = num_regulators;580580+ }581581+593582 for (i = 0; i < num_regulators; i++) {594583 struct regulator_init_data *init_data;595584 struct regulator_desc *desc;
+8-2
drivers/regulator/mc13xxx-regulator-core.c
···181181182182struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(183183 struct platform_device *pdev, struct mc13xxx_regulator *regulators,184184- int num_regulators)184184+ int num_regulators, int *num_parsed)185185{186186 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);187187 struct mc13xxx_regulator_init_data *data, *p;188188 struct device_node *parent, *child;189189- int i;189189+ int i, parsed = 0;190190+191191+ *num_parsed = 0;190192191193 of_node_get(pdev->dev.parent->of_node);192194 parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators");···205203 for (i = 0; i < num_regulators; i++) {206204 if (!of_node_cmp(child->name,207205 regulators[i].desc.name)) {206206+208207 p->id = i;209208 p->init_data = of_get_regulator_init_data(210209 &pdev->dev, child);211210 p->node = child;212211 p++;212212+213213+ parsed++;213214 break;214215 }215216 }216217 }217218219219+ *num_parsed = parsed;218220 return data;219221}220222EXPORT_SYMBOL_GPL(mc13xxx_parse_regulators_dt);
+2-2
drivers/regulator/mc13xxx.h
···3939extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);4040extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(4141 struct platform_device *pdev, struct mc13xxx_regulator *regulators,4242- int num_regulators);4242+ int num_regulators, int *num_parsed);4343#else4444static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)4545{···48484949static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(5050 struct platform_device *pdev, struct mc13xxx_regulator *regulators,5151- int num_regulators)5151+ int num_regulators, int *num_parsed)5252{5353 return NULL;5454}
+1-1
drivers/regulator/tps65910-regulator.c
···998998 return NULL;999999 }1000100010011001- ret = of_regulator_match(pdev->dev.parent, regulators, matches, count);10011001+ ret = of_regulator_match(&pdev->dev, regulators, matches, count);10021002 if (ret < 0) {10031003 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",10041004 ret);