Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1332463 > unrolled thread

Re: [PATCH v2 2/4] regulator: lp872x: Add enable GPIO pin support

Started by"Kim, Milo" <milo.kim@ti.com>
First post2016-02-12 01:20 +0100
Last post2016-02-15 00:40 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v2 2/4] regulator: lp872x: Add enable GPIO pin support "Kim, Milo" <milo.kim@ti.com> - 2016-02-12 01:20 +0100
    Re: [PATCH v2 2/4] regulator: lp872x: Add enable GPIO pin support Paul Kocialkowski <contact@paulk.fr> - 2016-02-12 19:30 +0100
      Re: [PATCH v2 2/4] regulator: lp872x: Add enable GPIO pin support "Kim, Milo" <milo.kim@ti.com> - 2016-02-15 00:40 +0100

#1332463 — Re: [PATCH v2 2/4] regulator: lp872x: Add enable GPIO pin support

From"Kim, Milo" <milo.kim@ti.com>
Date2016-02-12 01:20 +0100
SubjectRe: [PATCH v2 2/4] regulator: lp872x: Add enable GPIO pin support
Message-ID<r19CN-7IJ-5@gated-at.bofh.it>
Hi Paul,

Thanks for the patch. Please see my comments below.

On 2/6/2016 3:42 AM, Paul Kocialkowski wrote:
> LP872x regulators are made active via the EN pin, which might be hooked to a
> GPIO. This adds support for driving the GPIO high when the driver is in use.
>
> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> ---
>   .../devicetree/bindings/regulator/lp872x.txt       |  1 +
>   drivers/regulator/lp872x.c                         | 34 ++++++++++++++++++++++
>   include/linux/regulator/lp872x.h                   |  5 ++++
>   3 files changed, 40 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/regulator/lp872x.txt b/Documentation/devicetree/bindings/regulator/lp872x.txt
> index 7818318..ca58a68 100644
> --- a/Documentation/devicetree/bindings/regulator/lp872x.txt
> +++ b/Documentation/devicetree/bindings/regulator/lp872x.txt
> @@ -28,6 +28,7 @@ Optional properties:
>     - ti,dvs-gpio: GPIO specifier for external DVS pin control of LP872x devices.
>     - ti,dvs-vsel: DVS selector. 0 = SEL_V1, 1 = SEL_V2.
>     - ti,dvs-state: initial DVS pin state. 0 = DVS_LOW, 1 = DVS_HIGH.
> +  - enable-gpios: GPIO specifier for EN pin control of LP872x devices.
>
>     Sub nodes for regulator_init_data
>       LP8720 has maximum 6 nodes. (child name: ldo1 ~ 5 and buck)
> diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
> index 21c49d8..3899211 100644
> --- a/drivers/regulator/lp872x.c
> +++ b/drivers/regulator/lp872x.c
> @@ -15,6 +15,7 @@
>   #include <linux/regmap.h>
>   #include <linux/err.h>
>   #include <linux/gpio.h>
> +#include <linux/delay.h>
>   #include <linux/regulator/lp872x.h>
>   #include <linux/regulator/driver.h>
>   #include <linux/platform_device.h>
> @@ -757,6 +758,33 @@ set_default_dvs_mode:
>   				default_dvs_mode[lp->chipid]);
>   }
>
> +static int lp872x_hw_enable(struct lp872x *lp)
> +{
> +	int ret, gpio;
> +
> +	if (!lp->pdata)
> +		return -EINVAL;
> +
> +	gpio = lp->pdata->enable_gpio;
> +	if (!gpio_is_valid(gpio))
> +		return 0;

It seems gpio is always 0 when it starts from DT. 'enable_gpio' is 
updated in lp872x_config() but lp872x_hw_enable() is called first.

> +
> +	/* Always set enable GPIO high. */
> +	ret = devm_gpio_request_one(lp->dev, gpio, GPIOF_OUT_INIT_HIGH, "LP872X EN");
> +	if (ret) {
> +		dev_err(lp->dev, "gpio request err: %d\n", ret);
> +		return ret;
> +	}
> +
> +	/* Each chip has a different enable delay. */
> +	if (lp->chipid == LP8720)
> +		usleep_range(LP8720_ENABLE_DELAY, 1.5 * LP8720_ENABLE_DELAY);
> +	else
> +		usleep_range(LP8725_ENABLE_DELAY, 1.5 * LP8725_ENABLE_DELAY);
> +
> +	return 0;
> +}
> +
>   static int lp872x_config(struct lp872x *lp)
>   {
>   	struct lp872x_platform_data *pdata = lp->pdata;
> @@ -875,6 +903,8 @@ static struct lp872x_platform_data
>   	of_property_read_u8(np, "ti,dvs-state", &dvs_state);
>   	pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW;
>
> +	pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0);

Please move this code to lp872x_populate_pdata_from_dt().
lp872x_hw_enable() is called prior to lp872x_config(), so enable_gpio 
should be set on parsing the DT properties.

> +
>   	if (of_get_child_count(np) == 0)
>   		goto out;
>
> @@ -948,6 +978,10 @@ static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
>   	lp->chipid = id->driver_data;
>   	i2c_set_clientdata(cl, lp);
>
> +	ret = lp872x_hw_enable(lp);
> +	if (ret)
> +		return ret;
> +
>   	ret = lp872x_config(lp);
>   	if (ret)
>   		return ret;
> diff --git a/include/linux/regulator/lp872x.h b/include/linux/regulator/lp872x.h
> index 132e05c..6029279 100644
> --- a/include/linux/regulator/lp872x.h
> +++ b/include/linux/regulator/lp872x.h
> @@ -18,6 +18,9 @@
>
>   #define LP872X_MAX_REGULATORS		9
>
> +#define LP8720_ENABLE_DELAY		200
> +#define LP8725_ENABLE_DELAY		30000
> +
>   enum lp872x_regulator_id {
>   	LP8720_ID_BASE,
>   	LP8720_ID_LDO1 = LP8720_ID_BASE,
> @@ -79,12 +82,14 @@ struct lp872x_regulator_data {
>    * @update_config     : if LP872X_GENERAL_CFG register is updated, set true
>    * @regulator_data    : platform regulator id and init data
>    * @dvs               : dvs data for buck voltage control
> + * @enable_gpio       : gpio pin number for enable control
>    */
>   struct lp872x_platform_data {
>   	u8 general_config;
>   	bool update_config;
>   	struct lp872x_regulator_data regulator_data[LP872X_MAX_REGULATORS];
>   	struct lp872x_dvs *dvs;
> +	int enable_gpio;
>   };
>
>   #endif
>

Best regards,
Milo

[toc] | [next] | [standalone]


#1333006

FromPaul Kocialkowski <contact@paulk.fr>
Date2016-02-12 19:30 +0100
Message-ID<r1qDE-2aX-5@gated-at.bofh.it>
In reply to#1332463

[Multipart message — attachments visible in raw view] — view raw

Hi,
Le vendredi 12 février 2016 à 09:14 +0900, Kim, Milo a écrit :
> Thanks for the patch. Please see my comments below.

Thanks for the review!

> On 2/6/2016 3:42 AM, Paul Kocialkowski wrote:
> > LP872x regulators are made active via the EN pin, which might be hooked to a
> > GPIO. This adds support for driving the GPIO high when the driver is in use.
> >
> > Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> > ---
> >   .../devicetree/bindings/regulator/lp872x.txt       |  1 +
> >   drivers/regulator/lp872x.c                         | 34 ++++++++++++++++++++++
> >   include/linux/regulator/lp872x.h                   |  5 ++++
> >   3 files changed, 40 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/regulator/lp872x.txt b/Documentation/devicetree/bindings/regulator/lp872x.txt
> > index 7818318..ca58a68 100644
> > --- a/Documentation/devicetree/bindings/regulator/lp872x.txt
> > +++ b/Documentation/devicetree/bindings/regulator/lp872x.txt
> > @@ -28,6 +28,7 @@ Optional properties:
> >     - ti,dvs-gpio: GPIO specifier for external DVS pin control of LP872x devices.
> >     - ti,dvs-vsel: DVS selector. 0 = SEL_V1, 1 = SEL_V2.
> >     - ti,dvs-state: initial DVS pin state. 0 = DVS_LOW, 1 = DVS_HIGH.
> > +  - enable-gpios: GPIO specifier for EN pin control of LP872x devices.
> >
> >     Sub nodes for regulator_init_data
> >       LP8720 has maximum 6 nodes. (child name: ldo1 ~ 5 and buck)
> > diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
> > index 21c49d8..3899211 100644
> > --- a/drivers/regulator/lp872x.c
> > +++ b/drivers/regulator/lp872x.c
> > @@ -15,6 +15,7 @@
> >   #include <linux/regmap.h>
> >   #include <linux/err.h>
> >   #include <linux/gpio.h>
> > +#include <linux/delay.h>
> >   #include <linux/regulator/lp872x.h>
> >   #include <linux/regulator/driver.h>
> >   #include <linux/platform_device.h>
> > @@ -757,6 +758,33 @@ set_default_dvs_mode:
> >   				default_dvs_mode[lp->chipid]);
> >   }
> >
> > +static int lp872x_hw_enable(struct lp872x *lp)
> > +{
> > +	int ret, gpio;
> > +
> > +	if (!lp->pdata)
> > +		return -EINVAL;
> > +
> > +	gpio = lp->pdata->enable_gpio;
> > +	if (!gpio_is_valid(gpio))
> > +		return 0;
> 
> It seems gpio is always 0 when it starts from DT. 'enable_gpio' is 
> updated in lp872x_config() but lp872x_hw_enable() is called first.

Actually, enable_gpio is updated in lp872x_populate_pdata_from_dt.

> > +
> > +	/* Always set enable GPIO high. */
> > +	ret = devm_gpio_request_one(lp->dev, gpio, GPIOF_OUT_INIT_HIGH, "LP872X EN");
> > +	if (ret) {
> > +		dev_err(lp->dev, "gpio request err: %d\n", ret);
> > +		return ret;
> > +	}
> > +
> > +	/* Each chip has a different enable delay. */
> > +	if (lp->chipid == LP8720)
> > +		usleep_range(LP8720_ENABLE_DELAY, 1.5 * LP8720_ENABLE_DELAY);
> > +	else
> > +		usleep_range(LP8725_ENABLE_DELAY, 1.5 * LP8725_ENABLE_DELAY);
> > +
> > +	return 0;
> > +}
> > +
> >   static int lp872x_config(struct lp872x *lp)
> >   {
> >   	struct lp872x_platform_data *pdata = lp->pdata;
> > @@ -875,6 +903,8 @@ static struct lp872x_platform_data
> >   	of_property_read_u8(np, "ti,dvs-state", &dvs_state);
> >   	pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW;
> >
> > +	pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0);
> 
> Please move this code to lp872x_populate_pdata_from_dt().

This already adds it in lp872x_populate_pdata_from_dt (see the context
around the insertion).

I don't know why the diff makes it seem like it's added in
lp872x_config. It's really not.

> lp872x_hw_enable() is called prior to lp872x_config(), so enable_gpio 
> should be set on parsing the DT properties.

Of course.

> > +
> >   	if (of_get_child_count(np) == 0)
> >   		goto out;
> >
> > @@ -948,6 +978,10 @@ static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
> >   	lp->chipid = id->driver_data;
> >   	i2c_set_clientdata(cl, lp);
> >
> > +	ret = lp872x_hw_enable(lp);
> > +	if (ret)
> > +		return ret;
> > +
> >   	ret = lp872x_config(lp);
> >   	if (ret)
> >   		return ret;
> > diff --git a/include/linux/regulator/lp872x.h b/include/linux/regulator/lp872x.h
> > index 132e05c..6029279 100644
> > --- a/include/linux/regulator/lp872x.h
> > +++ b/include/linux/regulator/lp872x.h
> > @@ -18,6 +18,9 @@
> >
> >   #define LP872X_MAX_REGULATORS		9
> >
> > +#define LP8720_ENABLE_DELAY		200
> > +#define LP8725_ENABLE_DELAY		30000
> > +
> >   enum lp872x_regulator_id {
> >   	LP8720_ID_BASE,
> >   	LP8720_ID_LDO1 = LP8720_ID_BASE,
> > @@ -79,12 +82,14 @@ struct lp872x_regulator_data {
> >    * @update_config     : if LP872X_GENERAL_CFG register is updated, set true
> >    * @regulator_data    : platform regulator id and init data
> >    * @dvs               : dvs data for buck voltage control
> > + * @enable_gpio       : gpio pin number for enable control
> >    */
> >   struct lp872x_platform_data {
> >   	u8 general_config;
> >   	bool update_config;
> >   	struct lp872x_regulator_data regulator_data[LP872X_MAX_REGULATORS];
> >   	struct lp872x_dvs *dvs;
> > +	int enable_gpio;
> >   };
> >
> >   #endif
> >
> 
> Best regards,
> Milo

[toc] | [prev] | [next] | [standalone]


#1333842

From"Kim, Milo" <milo.kim@ti.com>
Date2016-02-15 00:40 +0100
Message-ID<r2eqM-1c5-65@gated-at.bofh.it>
In reply to#1333006
On 2/13/2016 3:25 AM, Paul Kocialkowski wrote:
>>> > >+
>>> > >+	/* Always set enable GPIO high. */
>>> > >+	ret = devm_gpio_request_one(lp->dev, gpio, GPIOF_OUT_INIT_HIGH, "LP872X EN");
>>> > >+	if (ret) {
>>> > >+		dev_err(lp->dev, "gpio request err: %d\n", ret);
>>> > >+		return ret;
>>> > >+	}
>>> > >+
>>> > >+	/* Each chip has a different enable delay. */
>>> > >+	if (lp->chipid == LP8720)
>>> > >+		usleep_range(LP8720_ENABLE_DELAY, 1.5 * LP8720_ENABLE_DELAY);
>>> > >+	else
>>> > >+		usleep_range(LP8725_ENABLE_DELAY, 1.5 * LP8725_ENABLE_DELAY);
>>> > >+
>>> > >+	return 0;
>>> > >+}
>>> > >+
>>> > >   static int lp872x_config(struct lp872x *lp)
>>> > >   {
>>> > >   	struct lp872x_platform_data *pdata = lp->pdata;
>>> > >@@ -875,6 +903,8 @@ static struct lp872x_platform_data
>>> > >   	of_property_read_u8(np, "ti,dvs-state", &dvs_state);
>>> > >   	pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW;
>>> > >
>>> > >+	pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0);
>> >
>> >Please move this code to lp872x_populate_pdata_from_dt().
> This already adds it in lp872x_populate_pdata_from_dt (see the context
> around the insertion).

Ah, sorry. Your patch is correct.

> I don't know why the diff makes it seem like it's added in
> lp872x_config. It's really not.

I think it was from a line break of lp872x_populate_pdata_from_dt().
Let me add my ACK to this patch. Thank you.

Best regards,
Milo

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web