summaryrefslogtreecommitdiff
path: root/drivers/regulator/bd718x7-regulator.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2020-12-15 15:48:30 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2020-12-15 15:48:30 -0800
commit2dda5700ef6af806e0358f63d81eb436a0d280fa (patch)
treec95ca01f50a4d0c3b3c110bb27a1720d7fa2e5ad /drivers/regulator/bd718x7-regulator.c
parenta45f1d43311d3a4f6534e48a3655ba3247a59d48 (diff)
parent5e999f10a16b90fc1d5ded8aa365e9804e894aa9 (diff)
Merge tag 'regulator-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates from Mark Brown: "This has been a quiet release for the regulator API, a few new drivers and the usual fixes and cleanup traffic but not much else going on: - Optimisations for the handling of voltage enumeration, especially with sparse selector sets, from Claudiu Beznea. - Support for several ARM SCMI regulators, Dialog DA9121, NXP PF8x00, Qualcomm PMX55, PM8350 and PM8350c The addition of the SCMI regulator driver (which controls regulators via system firmware) means that we've pulled in the support for the underlying firmware operations from the firmware tree" * tag 'regulator-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (53 commits) regulator: mc13892-regulator: convert comma to semicolon regulator: pfuze100: Convert the driver to DT-only regulator: max14577: Add proper module aliases strings regulator: da9121: Potential Oops in da9121_assign_chip_model() regulator: da9121: Fix index used for DT property regulator: da9121: Remove uninitialised string variable regulator: axp20x: Fix DLDO2 voltage control register mask for AXP22x regulator: qcom-rpmh: Add support for PM8350/PM8350c regulator: dt-bindings: Add PM8350x compatibles regulator: da9121: include linux/gpio/consumer.h regulator: da9121: Mark some symbols with static keyword regulator: da9121: Request IRQ directly and free in release function to avoid masking race regulator: da9121: add interrupt support regulator: da9121: add mode support regulator: da9121: add current support regulator: da9121: Update registration to support multiple buck variants regulator: da9121: Add support for device variants via devicetree regulator: da9121: Add device variant descriptors regulator: da9121: Add device variant regmaps regulator: da9121: Add device variants ...
Diffstat (limited to 'drivers/regulator/bd718x7-regulator.c')
-rw-r--r--drivers/regulator/bd718x7-regulator.c164
1 files changed, 157 insertions, 7 deletions
diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c
index 0774467994fb..e6d5d98c3cea 100644
--- a/drivers/regulator/bd718x7-regulator.c
+++ b/drivers/regulator/bd718x7-regulator.c
@@ -1323,13 +1323,142 @@ static void mark_hw_controlled(struct device *dev, struct device_node *np,
dev_warn(dev, "Bad regulator node\n");
}
-static int get_hw_controlled_regulators(struct device *dev,
- struct bd718xx_regulator_data *reg_data,
- unsigned int num_reg_data, int *info)
+/*
+ * Setups where regulator (especially the buck8) output voltage is scaled
+ * by adding external connection where some other regulator output is connected
+ * to feedback-pin (over suitable resistors) is getting popular amongst users
+ * of BD71837. (This allows for example scaling down the buck8 voltages to suit
+ * lover GPU voltages for projects where buck8 is (ab)used to supply power
+ * for GPU. Additionally some setups do allow DVS for buck8 but as this do
+ * produce voltage spikes the HW must be evaluated to be able to survive this
+ * - hence I keep the DVS disabled for non DVS bucks by default. I don't want
+ * to help you burn your proto board)
+ *
+ * So we allow describing this external connection from DT and scale the
+ * voltages accordingly. This is what the connection should look like:
+ *
+ * |------------|
+ * | buck 8 |-------+----->Vout
+ * | | |
+ * |------------| |
+ * | FB pin |
+ * | |
+ * +-------+--R2---+
+ * |
+ * R1
+ * |
+ * V FB-pull-up
+ *
+ * Here the buck output is sifted according to formula:
+ *
+ * Vout_o = Vo - (Vpu - Vo)*R2/R1
+ * Linear_step = step_orig*(R1+R2)/R1
+ *
+ * where:
+ * Vout_o is adjusted voltage output at vsel reg value 0
+ * Vo is original voltage output at vsel reg value 0
+ * Vpu is the pull-up voltage V FB-pull-up in the picture
+ * R1 and R2 are resistor values.
+ *
+ * As a real world example for buck8 and a specific GPU:
+ * VLDO = 1.6V (used as FB-pull-up)
+ * R1 = 1000ohms
+ * R2 = 150ohms
+ * VSEL 0x0 => 0.8V – (VLDO – 0.8) * R2 / R1 = 0.68V
+ * Linear Step = 10mV * (R1 + R2) / R1 = 11.5mV
+ */
+static int setup_feedback_loop(struct device *dev, struct device_node *np,
+ struct bd718xx_regulator_data *reg_data,
+ unsigned int num_reg_data, int fb_uv)
{
+ int i, r1, r2, ret;
+
+ /*
+ * We do adjust the values in the global desc based on DT settings.
+ * This may not be best approach as it can cause problems if more than
+ * one PMIC is controlled from same processor. I don't see such use-case
+ * for BD718x7 now - so we spare some bits.
+ *
+ * If this will point out to be a problem - then we can allocate new
+ * bd718xx_regulator_data array at probe and just use the global
+ * array as a template where we copy initial values. Then we can
+ * use allocated descs for regultor registration and do IC specific
+ * modifications to this copy while leaving other PMICs untouched. But
+ * that means allocating new array for each PMIC - and currently I see
+ * no need for that.
+ */
+
+ for (i = 0; i < num_reg_data; i++) {
+ struct regulator_desc *desc = &reg_data[i].desc;
+ int j;
+
+ if (!of_node_name_eq(np, desc->of_match))
+ continue;
+
+ pr_info("Looking at node '%s'\n", desc->of_match);
+
+ /* The feedback loop connection does not make sense for LDOs */
+ if (desc->id >= BD718XX_LDO1)
+ return -EINVAL;
+
+ ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms",
+ &r1);
+ if (ret)
+ return ret;
+
+ if (!r1)
+ return -EINVAL;
+
+ ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms",
+ &r2);
+ if (ret)
+ return ret;
+
+ if (desc->n_linear_ranges && desc->linear_ranges) {
+ struct linear_range *new;
+
+ new = devm_kzalloc(dev, desc->n_linear_ranges *
+ sizeof(struct linear_range),
+ GFP_KERNEL);
+ if (!new)
+ return -ENOMEM;
+
+ for (j = 0; j < desc->n_linear_ranges; j++) {
+ int min = desc->linear_ranges[j].min;
+ int step = desc->linear_ranges[j].step;
+
+ min -= (fb_uv - min)*r2/r1;
+ step = step * (r1 + r2);
+ step /= r1;
+
+ new[j].min = min;
+ new[j].step = step;
+
+ dev_dbg(dev, "%s: old range min %d, step %d\n",
+ desc->name, desc->linear_ranges[j].min,
+ desc->linear_ranges[j].step);
+ dev_dbg(dev, "new range min %d, step %d\n", min,
+ step);
+ }
+ desc->linear_ranges = new;
+ }
+ dev_dbg(dev, "regulator '%s' has FB pull-up configured\n",
+ desc->name);
+
+ return 0;
+ }
+
+ return -ENODEV;
+}
+
+static int get_special_regulators(struct device *dev,
+ struct bd718xx_regulator_data *reg_data,
+ unsigned int num_reg_data, int *info)
+{
+ int ret;
struct device_node *np;
struct device_node *nproot = dev->of_node;
- const char *prop = "rohm,no-regulator-enable-control";
+ int uv;
*info = 0;
@@ -1338,13 +1467,32 @@ static int get_hw_controlled_regulators(struct device *dev,
dev_err(dev, "failed to find regulators node\n");
return -ENODEV;
}
- for_each_child_of_node(nproot, np)
- if (of_property_read_bool(np, prop))
+ for_each_child_of_node(nproot, np) {
+ if (of_property_read_bool(np, "rohm,no-regulator-enable-control"))
mark_hw_controlled(dev, np, reg_data, num_reg_data,
info);
+ ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt",
+ &uv);
+ if (ret) {
+ if (ret == -EINVAL)
+ continue;
+ else
+ goto err_out;
+ }
+
+ ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv);
+ if (ret)
+ goto err_out;
+ }
of_node_put(nproot);
return 0;
+
+err_out:
+ of_node_put(np);
+ of_node_put(nproot);
+
+ return ret;
}
static int bd718xx_probe(struct platform_device *pdev)
@@ -1432,8 +1580,10 @@ static int bd718xx_probe(struct platform_device *pdev)
* be affected by PMIC state machine - Eg. regulator is likely to stay
* on even in SUSPEND
*/
- get_hw_controlled_regulators(pdev->dev.parent, reg_data, num_reg_data,
+ err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data,
&omit_enable);
+ if (err)
+ return err;
for (i = 0; i < num_reg_data; i++) {