From: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
To: Krzysztof Kozlowski <k.kozlowski@samsung.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
linux-kernel@vger.kernel.org, Ben Dooks <ben-linux@fluff.org>,
Kukjin Kim <kgene.kim@samsung.com>,
Russell King <linux@arm.linux.org.uk>,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org
Cc: Kyungmin Park <kyungmin.park@samsung.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>
Subject: Re: [PATCH v4 2/3] regulator: max77686: Implement suspend disable for some LDOs
Date: Mon, 27 Oct 2014 11:08:36 +0100 [thread overview]
Message-ID: <544E19A4.6040603@collabora.co.uk> (raw)
In-Reply-To: <1414403066-7872-3-git-send-email-k.kozlowski@samsung.com>
Hello Krzysztof,
On 10/27/2014 10:44 AM, Krzysztof Kozlowski wrote:
> Some LDOs of Maxim 77686 PMIC support disabling during system suspend
> (LDO{2,6,7,8,10,11,12,14,15,16}). This was already implemented as part
> of set_suspend_mode function. In that case the mode was one of:
> - disable,
> - normal mode,
> - low power mode.
> However there are no bindings for setting the mode during suspend.
>
> Add suspend disable for LDO regulators supporting this to the existing
> max77686_buck_set_suspend_disable() function. This helps reducing
> energy consumption during system sleep.
>
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> ---
> drivers/regulator/max77686.c | 75 ++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 66 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
> index 3d0922051488..4b35c19c9286 100644
> --- a/drivers/regulator/max77686.c
> +++ b/drivers/regulator/max77686.c
> @@ -87,18 +87,31 @@ struct max77686_data {
> unsigned int opmode[MAX77686_REGULATORS];
> };
>
> -/* Some BUCKS supports Normal[ON/OFF] mode during suspend */
> -static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev)
> +/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
> +static int max77686_set_suspend_disable(struct regulator_dev *rdev)
> {
> unsigned int val;
> struct max77686_data *max77686 = rdev_get_drvdata(rdev);
> int ret, id = rdev_get_id(rdev);
>
> - if (id == MAX77686_BUCK1)
> + switch (id) {
> + case MAX77686_BUCK1:
> val = MAX77686_BUCK_OFF_PWRREQ;
> - else
> - val = MAX77686_BUCK_OFF_PWRREQ
> - << MAX77686_OPMODE_BUCK234_SHIFT;
> + break;
> + case MAX77686_BUCK2 ... MAX77686_BUCK4:
> + val = MAX77686_BUCK_OFF_PWRREQ << MAX77686_OPMODE_BUCK234_SHIFT;
> + break;
> + case MAX77686_LDO2:
> + case MAX77686_LDO6 ... MAX77686_LDO8:
> + case MAX77686_LDO10 ... MAX77686_LDO12:
> + case MAX77686_LDO14 ... MAX77686_LDO16:
> + val = MAX77686_LDO_OFF_PWRREQ << MAX77686_OPMODE_SHIFT;
> + break;
> + default:
> + pr_warn("%s: regulator_suspend_disable not supported\n",
> + rdev->desc->name);
> + return -EINVAL;
> + }
>
> ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
> rdev->desc->enable_mask, val);
> @@ -176,13 +189,53 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
> return 0;
> }
>
> +/*
> + * For regulators supporting disabled in suspend it checks if opmode
> + * is 'off_pwrreq' mode (disabled in suspend) and changes it to 'enable'.
> + * For other regulators does nothing.
> + */
> +static void max77686_set_opmode_enable(struct max77686_data *max77686, int id)
> +{
> + unsigned int opmode_shift;
> +
> + /*
> + * Same enable function is used for LDO and bucks. Assuming
> + * the same values are used for enable registers.
> + */
> + BUILD_BUG_ON(MAX77686_LDO_OFF_PWRREQ != MAX77686_BUCK_OFF_PWRREQ);
> + BUILD_BUG_ON(MAX77686_LDO_NORMAL != MAX77686_BUCK_NORMAL);
> +
> + switch (id) {
> + case MAX77686_BUCK1:
> + opmode_shift = 0;
> + break;
> + case MAX77686_BUCK2 ... MAX77686_BUCK4:
> + opmode_shift = MAX77686_OPMODE_BUCK234_SHIFT;
> + break;
> + case MAX77686_LDO2:
> + case MAX77686_LDO6 ... MAX77686_LDO8:
> + case MAX77686_LDO10 ... MAX77686_LDO12:
> + case MAX77686_LDO14 ... MAX77686_LDO16:
> + opmode_shift = MAX77686_OPMODE_SHIFT;
> + break;
> + default:
> + return;
> + }
> +
> + if (max77686->opmode[id] == (MAX77686_LDO_OFF_PWRREQ << opmode_shift))
> + max77686->opmode[id] = MAX77686_LDO_NORMAL << opmode_shift;
> +}
> +
> static int max77686_enable(struct regulator_dev *rdev)
> {
> struct max77686_data *max77686 = rdev_get_drvdata(rdev);
> + int id = rdev_get_id(rdev);
> +
> + max77686_set_opmode_enable(max77686, id);
>
> return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
> rdev->desc->enable_mask,
> - max77686->opmode[rdev_get_id(rdev)]);
> + max77686->opmode[id]);
> }
the max77802 driver handles this slightly differently. It stores in opmode[id]
just the value without the shift and there is a max77802_get_opmode_shift() to
obtain the shift that is used before updating the register, e.g:
int shift = max77802_get_opmode_shift(id);
return regmap_update_bits(..., max77802->opmode[id] << shift);
I think the max77802 driver approach is better since it avoids duplicating the
switch statement to get the shift for each regulator. Just look how the max77802
enable and disable functions are easier to read. Looking at the max77686 driver,
I see that there are assumptions that opmode[id] has the value shifted so your
changes are consistent with the rest of the driver but I would consider changing
this.
Best regards,
Javier
next prev parent reply other threads:[~2014-10-27 10:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-27 9:44 [PATCH v4 0/3] regulator: max77686/trats2: Disable some regulators in suspend Krzysztof Kozlowski
2014-10-27 9:44 ` [PATCH v4 1/3] regulator: max77686: Replace hard-coded opmode values with defines Krzysztof Kozlowski
2014-10-27 9:44 ` [PATCH v4 2/3] regulator: max77686: Implement suspend disable for some LDOs Krzysztof Kozlowski
2014-10-27 10:08 ` Javier Martinez Canillas [this message]
2014-10-27 10:27 ` Krzysztof Kozlowski
2014-10-27 10:32 ` Javier Martinez Canillas
2014-10-27 10:35 ` Krzysztof Kozlowski
2014-10-27 9:44 ` [PATCH v4 3/3] ARM: dts: exynos4412-trats: Add suspend configuration for max77686 regulators Krzysztof Kozlowski
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=544E19A4.6040603@collabora.co.uk \
--to=javier.martinez@collabora.co.uk \
--cc=b.zolnierkie@samsung.com \
--cc=ben-linux@fluff.org \
--cc=broonie@kernel.org \
--cc=cw00.choi@samsung.com \
--cc=devicetree@vger.kernel.org \
--cc=k.kozlowski@samsung.com \
--cc=kgene.kim@samsung.com \
--cc=kyungmin.park@samsung.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=m.szyprowski@samsung.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