2015-02-12 03:35:41

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH 0/5] Rename regulator_set_optimum_mode

Changing the name of the regulator_set_optimum_mode() to
regulator_set_load() better reflects that the API is doing.

This series does the name change and move the current consumers
over.

Bjorn Andersson (5):
regulator: s/regulator_set_optimum_mode/regulator_set_load/
ufs: Rename of regulator_set_optimum_mode
usb: phy: ab8500-usb: Rename regulator_set_optimum_mode
usb: phy: phy-msm-usb: Rename regulator_set_optimum_mode
regulator: Drop temporary regulator_set_optimum_mode wrapper

Documentation/power/regulator/consumer.txt | 2 +-
drivers/regulator/core.c | 8 ++++----
drivers/scsi/ufs/ufshcd.c | 27 +++++++--------------------
drivers/usb/phy/phy-ab8500-usb.c | 4 ++--
drivers/usb/phy/phy-msm-usb.c | 15 +++++----------
include/linux/regulator/consumer.h | 5 ++---
6 files changed, 21 insertions(+), 40 deletions(-)

--
1.8.2.2


2015-02-12 03:37:41

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH 1/5] regulator: Rename regulator_set_optimum_mode

Rename the regulator_set_optimum_mode() function regulator_set_load() to
better represent what's going on.

Signed-off-by: Bjorn Andersson <[email protected]>
---
Documentation/power/regulator/consumer.txt | 2 +-
drivers/regulator/core.c | 8 ++++----
include/linux/regulator/consumer.h | 12 +++++++++---
3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/Documentation/power/regulator/consumer.txt b/Documentation/power/regulator/consumer.txt
index 8afb236c..e51564c 100644
--- a/Documentation/power/regulator/consumer.txt
+++ b/Documentation/power/regulator/consumer.txt
@@ -137,7 +137,7 @@ Indirect operating mode control.
Consumer drivers can request a change in their supply regulator operating mode
by calling :-

-int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
+int regulator_set_load(struct regulator *regulator, int load_uA);

This will cause the core to recalculate the total load on the regulator (based
on all its consumers) and change operating mode (if necessary and permitted)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 27fb349..b137578 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3018,7 +3018,7 @@ unsigned int regulator_get_mode(struct regulator *regulator)
EXPORT_SYMBOL_GPL(regulator_get_mode);

/**
- * regulator_set_optimum_mode - set regulator optimum operating mode
+ * regulator_set_load - set regulator load
* @regulator: regulator source
* @uA_load: load current
*
@@ -3041,9 +3041,9 @@ EXPORT_SYMBOL_GPL(regulator_get_mode);
* DRMS will sum the total requested load on the regulator and change
* to the most efficient operating mode if platform constraints allow.
*
- * Returns the new regulator mode or error.
+ * On error a negative errno is returned.
*/
-int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
+int regulator_set_load(struct regulator *regulator, int uA_load)
{
struct regulator_dev *rdev = regulator->rdev;
int ret;
@@ -3055,7 +3055,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)

return ret;
}
-EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
+EXPORT_SYMBOL_GPL(regulator_set_load);

/**
* regulator_allow_bypass - allow the regulator to go into bypass mode
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index d17e1ff..6d4e9d2 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -238,7 +238,7 @@ int regulator_get_current_limit(struct regulator *regulator);

int regulator_set_mode(struct regulator *regulator, unsigned int mode);
unsigned int regulator_get_mode(struct regulator *regulator);
-int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
+int regulator_set_load(struct regulator *regulator, int load_uA);

int regulator_allow_bypass(struct regulator *regulator, bool allow);

@@ -479,8 +479,7 @@ static inline unsigned int regulator_get_mode(struct regulator *regulator)
return REGULATOR_MODE_NORMAL;
}

-static inline int regulator_set_optimum_mode(struct regulator *regulator,
- int load_uA)
+static inline int regulator_set_load(struct regulator *regulator, int load_uA)
{
return REGULATOR_MODE_NORMAL;
}
@@ -555,4 +554,11 @@ static inline int regulator_is_supported_voltage_tol(struct regulator *regulator
target_uV + tol_uV);
}

+/* TEMP: Wrapper to keep bisectability */
+static inline int regulator_set_optimum_mode(struct regulator *regulator,
+ int load_uA)
+{
+ return regulator_set_load(regulator, load_uA);
+}
+
#endif
--
1.8.2.2

2015-02-12 03:36:43

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH 2/5] ufs: Rename of regulator_set_optimum_mode

The function regulator_set_optimum_mode() is changing name to
regulator_set_load(), so update the code accordingly. Also cleaned up
ufshcd_config_vreg_load() while touching the code.

Signed-off-by: Bjorn Andersson <[email protected]>
---
drivers/scsi/ufs/ufshcd.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 2e4614b..4b73b94 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -4225,22 +4225,15 @@ static struct scsi_host_template ufshcd_driver_template = {
static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
int ua)
{
- int ret = 0;
- struct regulator *reg = vreg->reg;
- const char *name = vreg->name;
+ int ret;

- BUG_ON(!vreg);
+ if (!vreg)
+ return 0;

- ret = regulator_set_optimum_mode(reg, ua);
- if (ret >= 0) {
- /*
- * regulator_set_optimum_mode() returns new regulator
- * mode upon success.
- */
- ret = 0;
- } else {
- dev_err(dev, "%s: %s set optimum mode(ua=%d) failed, err=%d\n",
- __func__, name, ua, ret);
+ ret = regulator_set_load(vreg->reg, ua);
+ if (ret < 0) {
+ dev_err(dev, "%s: %s set load (ua=%d) failed, err=%d\n",
+ __func__, vreg->name, ua, ret);
}

return ret;
@@ -4249,18 +4242,12 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
static inline int ufshcd_config_vreg_lpm(struct ufs_hba *hba,
struct ufs_vreg *vreg)
{
- if (!vreg)
- return 0;
-
return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA);
}

static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
struct ufs_vreg *vreg)
{
- if (!vreg)
- return 0;
-
return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA);
}

--
1.8.2.2

2015-02-12 03:35:46

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH 3/5] usb: phy: ab8500-usb: Rename regulator_set_optimum_mode

The function regulator_set_optimum_mode() is changing name to
regulator_set_load(), so update the code accordingly.

Signed-off-by: Bjorn Andersson <[email protected]>
---
drivers/usb/phy/phy-ab8500-usb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c
index 0b1bd23..f5b3b92 100644
--- a/drivers/usb/phy/phy-ab8500-usb.c
+++ b/drivers/usb/phy/phy-ab8500-usb.c
@@ -277,7 +277,7 @@ static void ab8500_usb_regulator_enable(struct ab8500_usb *ab)
dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n",
ret);

- ret = regulator_set_optimum_mode(ab->v_ulpi, 28000);
+ ret = regulator_set_load(ab->v_ulpi, 28000);
if (ret < 0)
dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
ret);
@@ -317,7 +317,7 @@ static void ab8500_usb_regulator_disable(struct ab8500_usb *ab)
ab->saved_v_ulpi, ret);
}

- ret = regulator_set_optimum_mode(ab->v_ulpi, 0);
+ ret = regulator_set_load(ab->v_ulpi, 0);
if (ret < 0)
dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
ret);
--
1.8.2.2

2015-02-12 03:36:11

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH 4/5] usb: phy: phy-msm-usb: Rename regulator_set_optimum_mode

The function regulator_set_optimum_mode() is changing name to
regulator_set_load(), so update the code accordingly.

Signed-off-by: Bjorn Andersson <[email protected]>
---
drivers/usb/phy/phy-msm-usb.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 000fd89..6ed67ea 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -142,27 +142,22 @@ static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, int on)
int ret = 0;

if (on) {
- ret = regulator_set_optimum_mode(motg->v1p8,
- USB_PHY_1P8_HPM_LOAD);
+ ret = regulator_set_load(motg->v1p8, USB_PHY_1P8_HPM_LOAD);
if (ret < 0) {
pr_err("Could not set HPM for v1p8\n");
return ret;
}
- ret = regulator_set_optimum_mode(motg->v3p3,
- USB_PHY_3P3_HPM_LOAD);
+ ret = regulator_set_load(motg->v3p3, USB_PHY_3P3_HPM_LOAD);
if (ret < 0) {
pr_err("Could not set HPM for v3p3\n");
- regulator_set_optimum_mode(motg->v1p8,
- USB_PHY_1P8_LPM_LOAD);
+ regulator_set_load(motg->v1p8, USB_PHY_1P8_LPM_LOAD);
return ret;
}
} else {
- ret = regulator_set_optimum_mode(motg->v1p8,
- USB_PHY_1P8_LPM_LOAD);
+ ret = regulator_set_load(motg->v1p8, USB_PHY_1P8_LPM_LOAD);
if (ret < 0)
pr_err("Could not set LPM for v1p8\n");
- ret = regulator_set_optimum_mode(motg->v3p3,
- USB_PHY_3P3_LPM_LOAD);
+ ret = regulator_set_load(motg->v3p3, USB_PHY_3P3_LPM_LOAD);
if (ret < 0)
pr_err("Could not set LPM for v3p3\n");
}
--
1.8.2.2

2015-02-12 03:35:49

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH 5/5] regulator: Drop temporary regulator_set_optimum_mode wrapper

Signed-off-by: Bjorn Andersson <[email protected]>
---
include/linux/regulator/consumer.h | 7 -------
1 file changed, 7 deletions(-)

diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 6d4e9d2..d8944f5 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -554,11 +554,4 @@ static inline int regulator_is_supported_voltage_tol(struct regulator *regulator
target_uV + tol_uV);
}

-/* TEMP: Wrapper to keep bisectability */
-static inline int regulator_set_optimum_mode(struct regulator *regulator,
- int load_uA)
-{
- return regulator_set_load(regulator, load_uA);
-}
-
#endif
--
1.8.2.2

2015-02-25 23:40:36

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH 0/5] Rename regulator_set_optimum_mode

On Wed, Feb 11, 2015 at 7:35 PM, Bjorn Andersson
<[email protected]> wrote:
> Changing the name of the regulator_set_optimum_mode() to
> regulator_set_load() better reflects that the API is doing.
>

Any comments on this?

I'm going to propose a patch to the mmc framework calling this api, so
it would be good to know before I add another consumer of the api.

Regards,
Bjorn

2015-02-27 15:30:33

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH 3/5] usb: phy: ab8500-usb: Rename regulator_set_optimum_mode

On Wed, Feb 11, 2015 at 07:35:29PM -0800, Bjorn Andersson wrote:
> The function regulator_set_optimum_mode() is changing name to
> regulator_set_load(), so update the code accordingly.
>
> Signed-off-by: Bjorn Andersson <[email protected]>

since this depends on the rest of the series:

Acked-by: Felipe Balbi <[email protected]>

> ---
> drivers/usb/phy/phy-ab8500-usb.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c
> index 0b1bd23..f5b3b92 100644
> --- a/drivers/usb/phy/phy-ab8500-usb.c
> +++ b/drivers/usb/phy/phy-ab8500-usb.c
> @@ -277,7 +277,7 @@ static void ab8500_usb_regulator_enable(struct ab8500_usb *ab)
> dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n",
> ret);
>
> - ret = regulator_set_optimum_mode(ab->v_ulpi, 28000);
> + ret = regulator_set_load(ab->v_ulpi, 28000);
> if (ret < 0)
> dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
> ret);
> @@ -317,7 +317,7 @@ static void ab8500_usb_regulator_disable(struct ab8500_usb *ab)
> ab->saved_v_ulpi, ret);
> }
>
> - ret = regulator_set_optimum_mode(ab->v_ulpi, 0);
> + ret = regulator_set_load(ab->v_ulpi, 0);
> if (ret < 0)
> dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
> ret);
> --
> 1.8.2.2
>

--
balbi


Attachments:
(No filename) (1.34 kB)
signature.asc (819.00 B)
Digital signature
Download all attachments

2015-02-27 15:30:36

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH 4/5] usb: phy: phy-msm-usb: Rename regulator_set_optimum_mode

On Wed, Feb 11, 2015 at 07:35:30PM -0800, Bjorn Andersson wrote:
> The function regulator_set_optimum_mode() is changing name to
> regulator_set_load(), so update the code accordingly.
>
> Signed-off-by: Bjorn Andersson <[email protected]>

since this depends on the rest of the series:

Acked-by: Felipe Balbi <[email protected]>

> ---
> drivers/usb/phy/phy-msm-usb.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
> index 000fd89..6ed67ea 100644
> --- a/drivers/usb/phy/phy-msm-usb.c
> +++ b/drivers/usb/phy/phy-msm-usb.c
> @@ -142,27 +142,22 @@ static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, int on)
> int ret = 0;
>
> if (on) {
> - ret = regulator_set_optimum_mode(motg->v1p8,
> - USB_PHY_1P8_HPM_LOAD);
> + ret = regulator_set_load(motg->v1p8, USB_PHY_1P8_HPM_LOAD);
> if (ret < 0) {
> pr_err("Could not set HPM for v1p8\n");
> return ret;
> }
> - ret = regulator_set_optimum_mode(motg->v3p3,
> - USB_PHY_3P3_HPM_LOAD);
> + ret = regulator_set_load(motg->v3p3, USB_PHY_3P3_HPM_LOAD);
> if (ret < 0) {
> pr_err("Could not set HPM for v3p3\n");
> - regulator_set_optimum_mode(motg->v1p8,
> - USB_PHY_1P8_LPM_LOAD);
> + regulator_set_load(motg->v1p8, USB_PHY_1P8_LPM_LOAD);
> return ret;
> }
> } else {
> - ret = regulator_set_optimum_mode(motg->v1p8,
> - USB_PHY_1P8_LPM_LOAD);
> + ret = regulator_set_load(motg->v1p8, USB_PHY_1P8_LPM_LOAD);
> if (ret < 0)
> pr_err("Could not set LPM for v1p8\n");
> - ret = regulator_set_optimum_mode(motg->v3p3,
> - USB_PHY_3P3_LPM_LOAD);
> + ret = regulator_set_load(motg->v3p3, USB_PHY_3P3_LPM_LOAD);
> if (ret < 0)
> pr_err("Could not set LPM for v3p3\n");
> }
> --
> 1.8.2.2
>

--
balbi


Attachments:
(No filename) (1.79 kB)
signature.asc (819.00 B)
Digital signature
Download all attachments

2015-04-14 12:12:10

by Akinobu Mita

[permalink] [raw]
Subject: Re: [PATCH 2/5] ufs: Rename of regulator_set_optimum_mode

2015-02-12 12:35 GMT+09:00 Bjorn Andersson <[email protected]>:
> The function regulator_set_optimum_mode() is changing name to
> regulator_set_load(), so update the code accordingly. Also cleaned up
> ufshcd_config_vreg_load() while touching the code.
>
> Signed-off-by: Bjorn Andersson <[email protected]>
> ---
> drivers/scsi/ufs/ufshcd.c | 27 +++++++--------------------
> 1 file changed, 7 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 2e4614b..4b73b94 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -4225,22 +4225,15 @@ static struct scsi_host_template ufshcd_driver_template = {
> static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
> int ua)
> {
> - int ret = 0;
> - struct regulator *reg = vreg->reg;
> - const char *name = vreg->name;
> + int ret;
>
> - BUG_ON(!vreg);
> + if (!vreg)
> + return 0;
>
> - ret = regulator_set_optimum_mode(reg, ua);
> - if (ret >= 0) {
> - /*
> - * regulator_set_optimum_mode() returns new regulator
> - * mode upon success.
> - */
> - ret = 0;
> - } else {
> - dev_err(dev, "%s: %s set optimum mode(ua=%d) failed, err=%d\n",
> - __func__, name, ua, ret);
> + ret = regulator_set_load(vreg->reg, ua);
> + if (ret < 0) {
> + dev_err(dev, "%s: %s set load (ua=%d) failed, err=%d\n",
> + __func__, vreg->name, ua, ret);
> }
>
> return ret;
> @@ -4249,18 +4242,12 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
> static inline int ufshcd_config_vreg_lpm(struct ufs_hba *hba,
> struct ufs_vreg *vreg)
> {
> - if (!vreg)
> - return 0;
> -
> return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA);
> }
>
> static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
> struct ufs_vreg *vreg)
> {
> - if (!vreg)
> - return 0;
> -
> return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA);
> }

I tried this patch and it caused kernel null pointer dereference with
'verg->max_uA' when vreg == NULL. So you can't simply move !vreg check here
into ufshcd_config_vreg_load().

2015-04-15 18:35:26

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH 2/5] ufs: Rename of regulator_set_optimum_mode

On Tue 14 Apr 05:11 PDT 2015, Akinobu Mita wrote:

> 2015-02-12 12:35 GMT+09:00 Bjorn Andersson <[email protected]>:
> > The function regulator_set_optimum_mode() is changing name to
> > regulator_set_load(), so update the code accordingly. Also cleaned up
> > ufshcd_config_vreg_load() while touching the code.
> >
> > Signed-off-by: Bjorn Andersson <[email protected]>

[..]

> > static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
> > struct ufs_vreg *vreg)
> > {
> > - if (!vreg)
> > - return 0;
> > -
> > return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA);
> > }
>
> I tried this patch and it caused kernel null pointer dereference with
> 'verg->max_uA' when vreg == NULL. So you can't simply move !vreg check here
> into ufshcd_config_vreg_load().

Akinobu-san, you're correct, sorry for missing that (and in essence
reverting your commit).

Looks like Linus merged the fix on master, so I will send out a fixup.

Regards,
Bjorn