From: Marco Felsch <m.felsch@pengutronix.de>
To: support.opensource@diasemi.com, lee.jones@linaro.org,
robh+dt@kernel.org, lgirdwood@gmail.com, broonie@kernel.org,
stwiss.opensource@diasemi.com
Cc: kernel@pengutronix.de, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] regulator: da9062: add gpio based regulator dis-/enable support
Date: Tue, 17 Sep 2019 14:42:46 +0200 [thread overview]
Message-ID: <20190917124246.11732-6-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20190917124246.11732-1-m.felsch@pengutronix.de>
Each regulator can be enabeld/disabled by the internal pmic state
machine or by a gpio input signal. Typically the OTP configures the
regulators to be enabled/disabled on a specific sequence number which is
most the time fine. Sometimes we need to reconfigure that due to a PCB
bug. This patch adds the support to disable/enable the regulator based
on a gpio input signal.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/regulator/da9062-regulator.c | 84 +++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 2 deletions(-)
diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-regulator.c
index 9d6eb7625948..1fd15c6c654f 100644
--- a/drivers/regulator/da9062-regulator.c
+++ b/drivers/regulator/da9062-regulator.c
@@ -53,6 +53,7 @@ struct da9062_regulator_info {
struct reg_field suspend_sleep;
unsigned int suspend_vsel_reg;
struct reg_field vsel_gpi;
+ struct reg_field ena_gpi;
/* Event detection bit */
struct reg_field oc_event;
};
@@ -69,6 +70,7 @@ struct da9062_regulator {
struct regmap_field *sleep;
struct regmap_field *suspend_sleep;
struct regmap_field *vsel_gpi;
+ struct regmap_field *ena_gpi;
};
/* Encapsulates all information for the regulators driver */
@@ -398,7 +400,10 @@ static int da9062_config_gpi(struct device_node *np,
goto free;
}
- ret = regmap_field_write(regl->vsel_gpi, nr);
+ if (!strncmp(gpi_id, "ena", 3))
+ ret = regmap_field_write(regl->ena_gpi, nr);
+ else
+ ret = regmap_field_write(regl->vsel_gpi, nr);
free:
kfree(prop);
@@ -411,7 +416,13 @@ static int da9062_parse_dt(struct device_node *np,
const struct regulator_desc *desc,
struct regulator_config *cfg)
{
- return da9062_config_gpi(np, desc, cfg, "vsel");
+ int error;
+
+ error = da9062_config_gpi(np, desc, cfg, "vsel");
+ if (error)
+ return error;
+
+ return da9062_config_gpi(np, desc, cfg, "ena");
}
/* DA9061 Regulator information */
@@ -456,6 +467,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VBUCK1_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VBUCK1_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_BUCK1_CONT,
+ __builtin_ffs((int)DA9062AA_BUCK1_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_BUCK1_GPI_MASK) - 1),
},
{
.desc.id = DA9061_ID_BUCK2,
@@ -497,6 +512,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VBUCK3_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VBUCK3_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_BUCK3_CONT,
+ __builtin_ffs((int)DA9062AA_BUCK3_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_BUCK3_GPI_MASK) - 1),
},
{
.desc.id = DA9061_ID_BUCK3,
@@ -538,6 +557,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VBUCK4_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VBUCK4_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_BUCK4_CONT,
+ __builtin_ffs((int)DA9062AA_BUCK4_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_BUCK4_GPI_MASK) - 1),
},
{
.desc.id = DA9061_ID_LDO1,
@@ -572,6 +595,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VLDO1_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VLDO1_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_LDO1_CONT,
+ __builtin_ffs((int)DA9062AA_LDO1_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_LDO1_GPI_MASK) - 1),
.oc_event = REG_FIELD(DA9062AA_STATUS_D,
__builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
sizeof(unsigned int) * 8 -
@@ -610,6 +637,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VLDO2_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VLDO2_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_LDO2_CONT,
+ __builtin_ffs((int)DA9062AA_LDO2_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_LDO2_GPI_MASK) - 1),
.oc_event = REG_FIELD(DA9062AA_STATUS_D,
__builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
sizeof(unsigned int) * 8 -
@@ -648,6 +679,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VLDO3_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VLDO3_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_LDO3_CONT,
+ __builtin_ffs((int)DA9062AA_LDO3_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_LDO3_GPI_MASK) - 1),
.oc_event = REG_FIELD(DA9062AA_STATUS_D,
__builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
sizeof(unsigned int) * 8 -
@@ -686,6 +721,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VLDO4_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VLDO4_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_LDO4_CONT,
+ __builtin_ffs((int)DA9062AA_LDO4_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_LDO4_GPI_MASK) - 1),
.oc_event = REG_FIELD(DA9062AA_STATUS_D,
__builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
sizeof(unsigned int) * 8 -
@@ -735,6 +774,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VBUCK1_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VBUCK1_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_BUCK1_CONT,
+ __builtin_ffs((int)DA9062AA_BUCK1_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_BUCK1_GPI_MASK) - 1),
},
{
.desc.id = DA9062_ID_BUCK2,
@@ -776,6 +819,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VBUCK2_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VBUCK2_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_BUCK2_CONT,
+ __builtin_ffs((int)DA9062AA_BUCK2_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_BUCK2_GPI_MASK) - 1),
},
{
.desc.id = DA9062_ID_BUCK3,
@@ -817,6 +864,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VBUCK3_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VBUCK3_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_BUCK3_CONT,
+ __builtin_ffs((int)DA9062AA_BUCK3_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_BUCK3_GPI_MASK) - 1),
},
{
.desc.id = DA9062_ID_BUCK4,
@@ -858,6 +909,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VBUCK4_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VBUCK4_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_BUCK4_CONT,
+ __builtin_ffs((int)DA9062AA_BUCK4_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_BUCK4_GPI_MASK) - 1),
},
{
.desc.id = DA9062_ID_LDO1,
@@ -892,6 +947,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VLDO1_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VLDO1_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_LDO1_CONT,
+ __builtin_ffs((int)DA9062AA_LDO1_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_LDO1_GPI_MASK) - 1),
.oc_event = REG_FIELD(DA9062AA_STATUS_D,
__builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
sizeof(unsigned int) * 8 -
@@ -930,6 +989,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VLDO2_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VLDO2_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_LDO2_CONT,
+ __builtin_ffs((int)DA9062AA_LDO2_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_LDO2_GPI_MASK) - 1),
.oc_event = REG_FIELD(DA9062AA_STATUS_D,
__builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
sizeof(unsigned int) * 8 -
@@ -968,6 +1031,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VLDO3_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VLDO3_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_LDO3_CONT,
+ __builtin_ffs((int)DA9062AA_LDO3_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_LDO3_GPI_MASK) - 1),
.oc_event = REG_FIELD(DA9062AA_STATUS_D,
__builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
sizeof(unsigned int) * 8 -
@@ -1006,6 +1073,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
__builtin_ffs((int)DA9062AA_VLDO4_GPI_MASK) - 1,
sizeof(unsigned int) * 8 -
__builtin_clz(DA9062AA_VLDO4_GPI_MASK) - 1),
+ .ena_gpi = REG_FIELD(DA9062AA_LDO4_CONT,
+ __builtin_ffs((int)DA9062AA_LDO4_GPI_MASK) - 1,
+ sizeof(unsigned int) * 8 -
+ __builtin_clz(DA9062AA_LDO4_GPI_MASK) - 1),
.oc_event = REG_FIELD(DA9062AA_STATUS_D,
__builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
sizeof(unsigned int) * 8 -
@@ -1135,6 +1206,15 @@ static int da9062_regulator_probe(struct platform_device *pdev)
return PTR_ERR(regl->vsel_gpi);
}
+ if (regl->info->ena_gpi.reg) {
+ regl->ena_gpi = devm_regmap_field_alloc(
+ &pdev->dev,
+ chip->regmap,
+ regl->info->ena_gpi);
+ if (IS_ERR(regl->ena_gpi))
+ return PTR_ERR(regl->ena_gpi);
+ }
+
/* Register regulator */
memset(&config, 0, sizeof(config));
config.dev = chip->dev;
--
2.20.1
prev parent reply other threads:[~2019-09-17 12:42 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-17 12:42 [PATCH 0/5] DA9062 PMIC fixes and features Marco Felsch
2019-09-17 12:42 ` [PATCH 1/5] regulator: da9062: fix suspend_enable/disable preparation Marco Felsch
2019-09-18 12:41 ` Adam Thomson
2019-09-18 15:05 ` Marco Felsch
2019-09-23 16:03 ` Adam Thomson
2019-09-23 22:02 ` Marco Felsch
2019-09-24 8:58 ` Adam Thomson
2019-09-23 21:23 ` Applied "regulator: da9062: fix suspend_enable/disable preparation" to the regulator tree Mark Brown
2019-09-17 12:42 ` [PATCH 2/5] dt-bindings: mfd: da9062: add regulator voltage selection documentation Marco Felsch
2019-09-24 9:23 ` Adam Thomson
2019-09-25 15:51 ` Marco Felsch
2019-09-25 16:18 ` Adam Thomson
2019-09-26 8:09 ` Marco Felsch
2019-09-26 10:17 ` Adam Thomson
2019-09-26 11:43 ` Marco Felsch
2019-09-26 14:04 ` Adam Thomson
2019-09-26 14:38 ` Marco Felsch
2019-09-30 9:53 ` Adam Thomson
2019-10-02 13:45 ` Marco Felsch
2019-10-22 10:22 ` Marco Felsch
2019-09-17 12:42 ` [PATCH 3/5] regulator: da9062: add voltage selection gpio support Marco Felsch
2019-09-17 14:22 ` kbuild test robot
2019-09-17 14:34 ` Marco Felsch
2019-09-24 9:48 ` Adam Thomson
2019-09-25 15:59 ` Marco Felsch
2019-10-04 19:41 ` Linus Walleij
2019-10-07 8:59 ` Marco Felsch
2019-09-17 12:42 ` [PATCH 4/5] dt-bindings: mfd: da9062: add regulator gpio enable/disable documentation Marco Felsch
2019-09-17 12:42 ` Marco Felsch [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190917124246.11732-6-m.felsch@pengutronix.de \
--to=m.felsch@pengutronix.de \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kernel@pengutronix.de \
--cc=lee.jones@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=stwiss.opensource@diasemi.com \
--cc=support.opensource@diasemi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).