linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Cc: mazziesaccount@gmail.com, Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, linux-power@fi.rohmeurope.com
Subject: Re: [PATCH 11/15] regulator: rohm-regulator: SNVS dvs and linear voltage support
Date: Fri, 15 Jan 2021 08:26:36 +0000	[thread overview]
Message-ID: <20210115082636.GF3975472@dell> (raw)
In-Reply-To: <f0af653b3d3d56bd1852468502518a54b31b1f10.1610110144.git.matti.vaittinen@fi.rohmeurope.com>

On Fri, 08 Jan 2021, Matti Vaittinen wrote:

> The helper for obtaining HW-state based DVS voltage levels currently only
> works for regulators using linear-ranges. Extend support to regulators with
> simple linear mappings and add also proper error path if pickable-ranges
> regulators call this.
> 
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> ---
>  drivers/regulator/rohm-regulator.c | 23 +++++++++++++++++++++--
>  include/linux/mfd/rohm-generic.h   |  6 +++++-
>  2 files changed, 26 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/regulator/rohm-regulator.c b/drivers/regulator/rohm-regulator.c
> index 399002383b28..9248bd63afa9 100644
> --- a/drivers/regulator/rohm-regulator.c
> +++ b/drivers/regulator/rohm-regulator.c
> @@ -22,13 +22,26 @@ static int set_dvs_level(const struct regulator_desc *desc,
>  			return ret;
>  		return 0;
>  	}
> -
> +	/* If voltage is set to 0 => disable */
>  	if (uv == 0) {
>  		if (omask)
>  			return regmap_update_bits(regmap, oreg, omask, 0);
>  	}
> +	/* Some setups don't allow setting own voltage but do allow enabling */
> +	if (!mask) {
> +		if (omask)
> +			return regmap_update_bits(regmap, oreg, omask, omask);
> +
> +		return -EINVAL;
> +	}
>  	for (i = 0; i < desc->n_voltages; i++) {
> -		ret = regulator_desc_list_voltage_linear_range(desc, i);
> +		/* NOTE to next hacker - Does not support pickable ranges */
> +		if (desc->linear_range_selectors)
> +			return -EINVAL;
> +		if (desc->n_linear_ranges)
> +			ret = regulator_desc_list_voltage_linear_range(desc, i);
> +		else
> +			ret = regulator_desc_list_voltage_linear(desc, i);
>  		if (ret < 0)
>  			continue;
>  		if (ret == uv) {
> @@ -79,6 +92,12 @@ int rohm_regulator_set_dvs_levels(const struct rohm_dvs_config *dvs,
>  				mask = dvs->lpsr_mask;
>  				omask = dvs->lpsr_on_mask;
>  				break;
> +			case ROHM_DVS_LEVEL_SNVS:
> +				prop = "rohm,dvs-snvs-voltage";
> +				reg = dvs->snvs_reg;
> +				mask = dvs->snvs_mask;
> +				omask = dvs->snvs_on_mask;
> +				break;
>  			default:
>  				return -EINVAL;
>  			}
> diff --git a/include/linux/mfd/rohm-generic.h b/include/linux/mfd/rohm-generic.h
> index e99e569d3cc1..2f5fbfd0c6b3 100644
> --- a/include/linux/mfd/rohm-generic.h
> +++ b/include/linux/mfd/rohm-generic.h
> @@ -27,7 +27,8 @@ enum {
>  	ROHM_DVS_LEVEL_IDLE,
>  	ROHM_DVS_LEVEL_SUSPEND,
>  	ROHM_DVS_LEVEL_LPSR,
> -	ROHM_DVS_LEVEL_MAX = ROHM_DVS_LEVEL_LPSR,
> +	ROHM_DVS_LEVEL_SNVS,
> +	ROHM_DVS_LEVEL_MAX = ROHM_DVS_LEVEL_SNVS,
>  };

Does this actually work?

The code that consumes it looks like:

    for (i = 0; i < ROHM_DVS_LEVEL_MAX && !ret; i++)

So it will loop through like:

0 (ROHM_DVS_LEVEL_IDLE)
1 (ROHM_DVS_LEVEL_SUSPEND)
2 (ROHM_DVS_LEVEL_LPSR)
3 (ROHM_DVS_LEVEL_SNVS)

Then break, since 'i' will be (== 4) not (< 4).

So the following will never be used:

4 (ROHM_DVS_LEVEL_MAX = ROHM_DVS_LEVEL_SNVS)

Unless I'm missing something, I think MAX should be the last entry.

>  /**
> @@ -66,6 +67,9 @@ struct rohm_dvs_config {
>  	unsigned int lpsr_reg;
>  	unsigned int lpsr_mask;
>  	unsigned int lpsr_on_mask;
> +	unsigned int snvs_reg;
> +	unsigned int snvs_mask;
> +	unsigned int snvs_on_mask;
>  };
>  
>  #if IS_ENABLED(CONFIG_REGULATOR_ROHM)

-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

  reply	other threads:[~2021-01-15  8:27 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08 13:27 [PATCH 00/15] Support ROHM BD71815 PMIC Matti Vaittinen
2021-01-08 13:29 ` [PATCH 01/15] rtc: bd70528: Do not require parent data Matti Vaittinen
2021-01-08 13:31 ` [PATCH 02/15] clk: BD718x7: Do not depend on parent driver data Matti Vaittinen
2021-01-08 13:32 ` [PATCH 03/15] mfd: bd718x7: simplify by cleaning unnecessary device data Matti Vaittinen
2021-01-08 13:34 ` [PATCH 04/15] dt_bindings: bd71828: Add clock output mode Matti Vaittinen
2021-01-13 13:52   ` Rob Herring
2021-01-13 14:52     ` Matti Vaittinen
2021-01-13 15:52       ` Rob Herring
2021-01-08 13:34 ` [PATCH 05/15] dt_bindings: mfd: Add ROHM BD71815 PMIC Matti Vaittinen
2021-01-11 19:06   ` Rob Herring
2021-01-12  6:14     ` Vaittinen, Matti
2021-01-08 13:36 ` [PATCH 06/15] dt_bindings: regulator: Add ROHM BD71815 PMIC regulators Matti Vaittinen
2021-01-11 19:09   ` Rob Herring
2021-01-12  6:10     ` Matti Vaittinen
2021-01-13 13:53       ` Rob Herring
2021-01-13 14:23         ` Vaittinen, Matti
2021-01-13 15:47           ` Rob Herring
2021-01-08 13:37 ` [PATCH 07/15] mfd: Add ROHM BD71815 ID Matti Vaittinen
2021-01-08 13:37 ` [PATCH 08/15] mfd: Support for ROHM BD71815 PMIC core Matti Vaittinen
2021-01-08 13:39 ` [PATCH 09/15] gpio: support ROHM BD71815 GPOs Matti Vaittinen
2021-01-08 19:28   ` kernel test robot
2021-01-09  0:45   ` Linus Walleij
2021-01-11  6:15     ` Vaittinen, Matti
2021-01-11  7:26       ` Vaittinen, Matti
2021-01-08 13:41 ` [PATCH 10/15] regulator: helpers: Export helper voltage listing Matti Vaittinen
2021-01-08 13:42 ` [PATCH 11/15] regulator: rohm-regulator: SNVS dvs and linear voltage support Matti Vaittinen
2021-01-15  8:26   ` Lee Jones [this message]
2021-01-15  9:10     ` Vaittinen, Matti
2021-01-15  9:48     ` Matti Vaittinen
2021-01-08 13:43 ` [PATCH 12/15] regulator: Support ROHM BD71815 regulators Matti Vaittinen
2021-01-08 22:30   ` kernel test robot
2021-01-08 13:45 ` [PATCH 13/15] clk: bd718x7: Add support for clk gate on ROHM BD71815 PMIC Matti Vaittinen
2021-01-08 13:46 ` [PATCH 14/15] rtc: bd70528: Support RTC on ROHM BD71815 Matti Vaittinen
2021-01-08 13:46 ` [PATCH 15/15] MAINTAINERS: Add ROHM BD71815AGW Matti Vaittinen

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=20210115082636.GF3975472@dell \
    --to=lee.jones@linaro.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-power@fi.rohmeurope.com \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@gmail.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).