summaryrefslogtreecommitdiff
path: root/drivers/regulator
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/Kconfig12
-rw-r--r--drivers/regulator/Makefile1
-rw-r--r--drivers/regulator/bd718x7-regulator.c164
-rw-r--r--drivers/regulator/core.c2
-rw-r--r--drivers/regulator/da9121-regulator.c108
-rw-r--r--drivers/regulator/fixed.c63
-rw-r--r--drivers/regulator/lp872x.c2
7 files changed, 337 insertions, 15 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 020a00d6696b..005a6036dd38 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -303,6 +303,18 @@ config REGULATOR_DA9063
This driver can also be built as a module. If so, the module
will be called da9063-regulator.
+config REGULATOR_DA9121
+ tristate "Dialog Semiconductor DA9121 regulator"
+ depends on I2C && OF
+ select REGMAP_I2C
+ help
+ Say y here to support for the Dialog Semiconductor DA9121. The
+ DA9210 is a dual-phase buck converter controlled through an I2C
+ interface.
+
+ This driver can also be built as a module. If so, the module
+ will be called da9121-regulator.
+
config REGULATOR_DA9210
tristate "Dialog Semiconductor DA9210 regulator"
depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 6ebae516258e..6096862a1d60 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
obj-$(CONFIG_REGULATOR_DA9062) += da9062-regulator.o
obj-$(CONFIG_REGULATOR_DA9063) += da9063-regulator.o
+obj-$(CONFIG_REGULATOR_DA9121) += da9121-regulator.o
obj-$(CONFIG_REGULATOR_DA9210) += da9210-regulator.o
obj-$(CONFIG_REGULATOR_DA9211) += da9211-regulator.o
obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
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++) {
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 70168f2a53ed..2e1ea18221ef 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -5531,7 +5531,7 @@ void regulator_set_drvdata(struct regulator *regulator, void *data)
EXPORT_SYMBOL_GPL(regulator_set_drvdata);
/**
- * regulator_get_id - get regulator ID
+ * rdev_get_id - get regulator ID
* @rdev: regulator
*/
int rdev_get_id(struct regulator_dev *rdev)
diff --git a/drivers/regulator/da9121-regulator.c b/drivers/regulator/da9121-regulator.c
new file mode 100644
index 000000000000..66bdfd1979c0
--- /dev/null
+++ b/drivers/regulator/da9121-regulator.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2020 Axis Communications AB */
+
+#include <linux/of_device.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/driver.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+
+#define DA9121_BUCK_BUCK1_0 0x20
+#define DA9121_BUCK_BUCK1_0_CH1_EN BIT(0)
+
+#define DA9121_BUCK_BUCK1_5 0x25
+#define DA9121_BUCK_BUCK1_5_CH1_A_VOUT GENMASK(7, 0)
+
+#define DA9121_MIN_MV 300
+#define DA9121_MAX_MV 1900
+#define DA9121_STEP_MV 10
+#define DA9121_MIN_SEL (DA9121_MIN_MV / DA9121_STEP_MV)
+#define DA9121_N_VOLTAGES (((DA9121_MAX_MV - DA9121_MIN_MV) / DA9121_STEP_MV) \
+ + 1 + DA9121_MIN_SEL)
+
+static const struct regmap_config da9121_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+};
+
+static const struct regulator_ops da9121_buck_ops = {
+ .enable = regulator_enable_regmap,
+ .disable = regulator_disable_regmap,
+ .is_enabled = regulator_is_enabled_regmap,
+ .set_voltage_sel = regulator_set_voltage_sel_regmap,
+ .get_voltage_sel = regulator_get_voltage_sel_regmap,
+ .list_voltage = regulator_list_voltage_linear,
+};
+
+static const struct regulator_desc da9121_reg = {
+ .name = "da9121",
+ .of_match = "buck1",
+ .owner = THIS_MODULE,
+ .ops = &da9121_buck_ops,
+ .type = REGULATOR_VOLTAGE,
+ .n_voltages = DA9121_N_VOLTAGES,
+ .min_uV = DA9121_MIN_MV * 1000,
+ .uV_step = DA9121_STEP_MV * 1000,
+ .linear_min_sel = DA9121_MIN_SEL,
+ .vsel_reg = DA9121_BUCK_BUCK1_5,
+ .vsel_mask = DA9121_BUCK_BUCK1_5_CH1_A_VOUT,
+ .enable_reg = DA9121_BUCK_BUCK1_0,
+ .enable_mask = DA9121_BUCK_BUCK1_0_CH1_EN,
+ /* Default value of BUCK_BUCK1_0.CH1_SRC_DVC_UP */
+ .ramp_delay = 20000,
+ /* tBUCK_EN */
+ .enable_time = 20,
+};
+
+static const struct of_device_id da9121_dt_ids[] = {
+ { .compatible = "dlg,da9121", },
+ { }
+};
+MODULE_DEVICE_TABLE(of, da9121_dt_ids);
+
+static int da9121_i2c_probe(struct i2c_client *i2c,
+ const struct i2c_device_id *id)
+{
+ struct device *dev = &i2c->dev;
+ struct regulator_config config = {};
+ struct regulator_dev *rdev;
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_i2c(i2c, &da9121_regmap_config);
+ if (IS_ERR(regmap))
+ return PTR_ERR(regmap);
+
+ config.dev = &i2c->dev;
+ config.of_node = dev->of_node;
+ config.regmap = regmap;
+
+ rdev = devm_regulator_register(&i2c->dev, &da9121_reg, &config);
+ if (IS_ERR(rdev)) {
+ dev_err(&i2c->dev, "Failed to register da9121 regulator\n");
+ return PTR_ERR(rdev);
+ }
+
+ return 0;
+}
+
+static const struct i2c_device_id da9121_i2c_id[] = {
+ { "da9121", 0 },
+ {},
+};
+MODULE_DEVICE_TABLE(i2c, da9121_i2c_id);
+
+static struct i2c_driver da9121_regulator_driver = {
+ .driver = {
+ .name = "da9121",
+ .of_match_table = of_match_ptr(da9121_dt_ids),
+ },
+ .probe = da9121_i2c_probe,
+ .id_table = da9121_i2c_id,
+};
+
+module_i2c_driver(da9121_regulator_driver);
+
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 3de7709bdcd4..02ad83153e19 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -18,6 +18,8 @@
#include <linux/mutex.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <linux/pm_opp.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/fixed.h>
#include <linux/gpio/consumer.h>
@@ -34,11 +36,13 @@ struct fixed_voltage_data {
struct regulator_dev *dev;
struct clk *enable_clock;
- unsigned int clk_enable_counter;
+ unsigned int enable_counter;
+ int performance_state;
};
struct fixed_dev_type {
bool has_enable_clock;
+ bool has_performance_state;
};
static int reg_clock_enable(struct regulator_dev *rdev)
@@ -50,7 +54,7 @@ static int reg_clock_enable(struct regulator_dev *rdev)
if (ret)
return ret;
- priv->clk_enable_counter++;
+ priv->enable_counter++;
return ret;
}
@@ -60,16 +64,41 @@ static int reg_clock_disable(struct regulator_dev *rdev)
struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
clk_disable_unprepare(priv->enable_clock);
- priv->clk_enable_counter--;
+ priv->enable_counter--;
return 0;
}
-static int reg_clock_is_enabled(struct regulator_dev *rdev)
+static int reg_domain_enable(struct regulator_dev *rdev)
{
struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
+ struct device *dev = rdev->dev.parent;
+ int ret;
+
+ ret = dev_pm_genpd_set_performance_state(dev, priv->performance_state);
+ if (ret)
+ return ret;
- return priv->clk_enable_counter > 0;
+ priv->enable_counter++;
+
+ return ret;
+}
+
+static int reg_domain_disable(struct regulator_dev *rdev)
+{
+ struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
+ struct device *dev = rdev->dev.parent;
+
+ priv->enable_counter--;
+
+ return dev_pm_genpd_set_performance_state(dev, 0);
+}
+
+static int reg_is_enabled(struct regulator_dev *rdev)
+{
+ struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
+
+ return priv->enable_counter > 0;
}
@@ -129,7 +158,13 @@ static const struct regulator_ops fixed_voltage_ops = {
static const struct regulator_ops fixed_voltage_clkenabled_ops = {
.enable = reg_clock_enable,
.disable = reg_clock_disable,
- .is_enabled = reg_clock_is_enabled,
+ .is_enabled = reg_is_enabled,
+};
+
+static const struct regulator_ops fixed_voltage_domain_ops = {
+ .enable = reg_domain_enable,
+ .disable = reg_domain_disable,
+ .is_enabled = reg_is_enabled,
};
static int reg_fixed_voltage_probe(struct platform_device *pdev)
@@ -177,6 +212,14 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
dev_err(dev, "Can't get enable-clock from devicetree\n");
return -ENOENT;
}
+ } else if (drvtype && drvtype->has_performance_state) {
+ drvdata->desc.ops = &fixed_voltage_domain_ops;
+
+ drvdata->performance_state = of_get_required_opp_performance_state(dev->of_node, 0);
+ if (drvdata->performance_state < 0) {
+ dev_err(dev, "Can't get performance state from devicetree\n");
+ return drvdata->performance_state;
+ }
} else {
drvdata->desc.ops = &fixed_voltage_ops;
}
@@ -260,6 +303,10 @@ static const struct fixed_dev_type fixed_clkenable_data = {
.has_enable_clock = true,
};
+static const struct fixed_dev_type fixed_domain_data = {
+ .has_performance_state = true,
+};
+
static const struct of_device_id fixed_of_match[] = {
{
.compatible = "regulator-fixed",
@@ -270,6 +317,10 @@ static const struct of_device_id fixed_of_match[] = {
.data = &fixed_clkenable_data,
},
{
+ .compatible = "regulator-fixed-domain",
+ .data = &fixed_domain_data,
+ },
+ {
},
};
MODULE_DEVICE_TABLE(of, fixed_of_match);
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
index 303d7e2dc838..e84be29533f4 100644
--- a/drivers/regulator/lp872x.c
+++ b/drivers/regulator/lp872x.c
@@ -892,7 +892,7 @@ static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
struct lp872x *lp;
struct lp872x_platform_data *pdata;
int ret;
- const int lp872x_num_regulators[] = {
+ static const int lp872x_num_regulators[] = {
[LP8720] = LP8720_NUM_REGULATORS,
[LP8725] = LP8725_NUM_REGULATORS,
};