diff mbox series

[2/2] Input: edt-ft5x06 - add support for iovcc-supply

Message ID 20210108192337.563679-2-stephan@gerhold.net (mailing list archive)
State New
Headers show
Series [1/2] dt-bindings: input: touchscreen: edt-ft5x06: add iovcc-supply | expand

Commit Message

Stephan Gerhold Jan. 8, 2021, 7:23 p.m. UTC
At the moment, the edt-ft5x06 driver can control a single regulator
("vcc"). However, some FocalTech touch controllers have an additional
IOVCC pin that should be supplied with the digital I/O voltage.

The I/O voltage might be provided by another regulator that should also
be kept on. Otherwise, the touchscreen can randomly stop functioning if
the regulator is turned off because no other components still require it.

Implement (optional) support for also enabling an "iovcc-supply".
IOVCC is needed whenever VCC is needed, so switch to the regulator bulk
APIs to request/enable/disable both when appropriate.

Cc: Ondrej Jirman <megous@megous.com>
Cc: Marco Felsch <m.felsch@pengutronix.de>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
 drivers/input/touchscreen/edt-ft5x06.c | 35 ++++++++++++++------------
 1 file changed, 19 insertions(+), 16 deletions(-)

Comments

Marco Felsch Jan. 11, 2021, 8:36 a.m. UTC | #1
Hi Stephan,

thanks for the patch :) Please see my inline comments.

On 21-01-08 20:23, Stephan Gerhold wrote:
> At the moment, the edt-ft5x06 driver can control a single regulator
> ("vcc"). However, some FocalTech touch controllers have an additional
> IOVCC pin that should be supplied with the digital I/O voltage.
> 
> The I/O voltage might be provided by another regulator that should also
> be kept on. Otherwise, the touchscreen can randomly stop functioning if
> the regulator is turned off because no other components still require it.
> 
> Implement (optional) support for also enabling an "iovcc-supply".
> IOVCC is needed whenever VCC is needed, so switch to the regulator bulk
> APIs to request/enable/disable both when appropriate.
> 
> Cc: Ondrej Jirman <megous@megous.com>
> Cc: Marco Felsch <m.felsch@pengutronix.de>
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
> ---
>  drivers/input/touchscreen/edt-ft5x06.c | 35 ++++++++++++++------------
>  1 file changed, 19 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> index 2eefbc2485bc..bf2e208112fe 100644
> --- a/drivers/input/touchscreen/edt-ft5x06.c
> +++ b/drivers/input/touchscreen/edt-ft5x06.c
> @@ -103,7 +103,7 @@ struct edt_ft5x06_ts_data {
>  	struct touchscreen_properties prop;
>  	u16 num_x;
>  	u16 num_y;
> -	struct regulator *vcc;
> +	struct regulator_bulk_data regulators[2];

Is there an enabling order we must follow?

>  	struct gpio_desc *reset_gpio;
>  	struct gpio_desc *wake_gpio;
> @@ -1066,7 +1066,7 @@ static void edt_ft5x06_disable_regulator(void *arg)
>  {
>  	struct edt_ft5x06_ts_data *data = arg;
>  
> -	regulator_disable(data->vcc);
> +	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
>  }
>  
>  static int edt_ft5x06_ts_probe(struct i2c_client *client,
> @@ -1098,18 +1098,19 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
>  
>  	tsdata->max_support_points = chip_data->max_support_points;
>  
> -	tsdata->vcc = devm_regulator_get(&client->dev, "vcc");
> -	if (IS_ERR(tsdata->vcc)) {
> -		error = PTR_ERR(tsdata->vcc);
> -		if (error != -EPROBE_DEFER)
> -			dev_err(&client->dev,
> -				"failed to request regulator: %d\n", error);
> -		return error;
> -	}
> +	tsdata->regulators[0].supply = "vcc";
> +	tsdata->regulators[1].supply = "iovcc";
> +	error = devm_regulator_bulk_get(&client->dev,
> +					ARRAY_SIZE(tsdata->regulators),
> +					tsdata->regulators);
> +	if (error)
> +		return dev_err_probe(&client->dev, error,
> +				     "failed to request regulators\n");

It would be nice to have a patch in front of this one which handles the
support for dev_err_probe().

Regards,
  Marco

>  
> -	error = regulator_enable(tsdata->vcc);
> +	error = regulator_bulk_enable(ARRAY_SIZE(tsdata->regulators),
> +				      tsdata->regulators);
>  	if (error < 0) {
> -		dev_err(&client->dev, "failed to enable vcc: %d\n", error);
> +		dev_err(&client->dev, "failed to enable regulators: %d\n", error);
>  		return error;
>  	}
>  
> @@ -1286,9 +1287,10 @@ static int __maybe_unused edt_ft5x06_ts_suspend(struct device *dev)
>  	gpiod_set_value_cansleep(reset_gpio, 1);
>  	usleep_range(1000, 2000);
>  
> -	ret = regulator_disable(tsdata->vcc);
> +	ret = regulator_bulk_disable(ARRAY_SIZE(tsdata->regulators),
> +				     tsdata->regulators);
>  	if (ret)
> -		dev_warn(dev, "Failed to disable vcc\n");
> +		dev_warn(dev, "Failed to disable regulators\n");
>  
>  	return 0;
>  }
> @@ -1319,9 +1321,10 @@ static int __maybe_unused edt_ft5x06_ts_resume(struct device *dev)
>  		gpiod_set_value_cansleep(reset_gpio, 1);
>  		usleep_range(5000, 6000);
>  
> -		ret = regulator_enable(tsdata->vcc);
> +		ret = regulator_bulk_enable(ARRAY_SIZE(tsdata->regulators),
> +					    tsdata->regulators);
>  		if (ret) {
> -			dev_err(dev, "Failed to enable vcc\n");
> +			dev_err(dev, "Failed to enable regulators\n");
>  			return ret;
>  		}
>  
> -- 
> 2.30.0
> 
>
Stephan Gerhold Jan. 11, 2021, 9:26 a.m. UTC | #2
Hi Marco,

thanks for the review!

On Mon, Jan 11, 2021 at 09:36:12AM +0100, Marco Felsch wrote:
> Hi Stephan,
> 
> thanks for the patch :) Please see my inline comments.
> 
> On 21-01-08 20:23, Stephan Gerhold wrote:
> > At the moment, the edt-ft5x06 driver can control a single regulator
> > ("vcc"). However, some FocalTech touch controllers have an additional
> > IOVCC pin that should be supplied with the digital I/O voltage.
> > 
> > The I/O voltage might be provided by another regulator that should also
> > be kept on. Otherwise, the touchscreen can randomly stop functioning if
> > the regulator is turned off because no other components still require it.
> > 
> > Implement (optional) support for also enabling an "iovcc-supply".
> > IOVCC is needed whenever VCC is needed, so switch to the regulator bulk
> > APIs to request/enable/disable both when appropriate.
> > 
> > Cc: Ondrej Jirman <megous@megous.com>
> > Cc: Marco Felsch <m.felsch@pengutronix.de>
> > Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
> > ---
> >  drivers/input/touchscreen/edt-ft5x06.c | 35 ++++++++++++++------------
> >  1 file changed, 19 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> > index 2eefbc2485bc..bf2e208112fe 100644
> > --- a/drivers/input/touchscreen/edt-ft5x06.c
> > +++ b/drivers/input/touchscreen/edt-ft5x06.c
> > @@ -103,7 +103,7 @@ struct edt_ft5x06_ts_data {
> >  	struct touchscreen_properties prop;
> >  	u16 num_x;
> >  	u16 num_y;
> > -	struct regulator *vcc;
> > +	struct regulator_bulk_data regulators[2];
> 
> Is there an enabling order we must follow?
> 

I don't know, sadly. The datasheets I was able to find do not mention
anything about this; the power-on sequence only includes the VDD line.

I tried several suspend/resume cycles with both regulators set up and it
worked fine, which could mean that I was lucky or that the order does
not matter. :)

What do you think?

> >  	struct gpio_desc *reset_gpio;
> >  	struct gpio_desc *wake_gpio;
> > @@ -1066,7 +1066,7 @@ static void edt_ft5x06_disable_regulator(void *arg)
> >  {
> >  	struct edt_ft5x06_ts_data *data = arg;
> >  
> > -	regulator_disable(data->vcc);
> > +	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
> >  }
> >  
> >  static int edt_ft5x06_ts_probe(struct i2c_client *client,
> > @@ -1098,18 +1098,19 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
> >  
> >  	tsdata->max_support_points = chip_data->max_support_points;
> >  
> > -	tsdata->vcc = devm_regulator_get(&client->dev, "vcc");
> > -	if (IS_ERR(tsdata->vcc)) {
> > -		error = PTR_ERR(tsdata->vcc);
> > -		if (error != -EPROBE_DEFER)
> > -			dev_err(&client->dev,
> > -				"failed to request regulator: %d\n", error);
> > -		return error;
> > -	}
> > +	tsdata->regulators[0].supply = "vcc";
> > +	tsdata->regulators[1].supply = "iovcc";
> > +	error = devm_regulator_bulk_get(&client->dev,
> > +					ARRAY_SIZE(tsdata->regulators),
> > +					tsdata->regulators);
> > +	if (error)
> > +		return dev_err_probe(&client->dev, error,
> > +				     "failed to request regulators\n");
> 
> It would be nice to have a patch in front of this one which handles the
> support for dev_err_probe().
> 

OK, I can send a v2 with the dev_err_probe() change separated into an
extra patch.

Thanks!
Stephan

> 
> >  
> > -	error = regulator_enable(tsdata->vcc);
> > +	error = regulator_bulk_enable(ARRAY_SIZE(tsdata->regulators),
> > +				      tsdata->regulators);
> >  	if (error < 0) {
> > -		dev_err(&client->dev, "failed to enable vcc: %d\n", error);
> > +		dev_err(&client->dev, "failed to enable regulators: %d\n", error);
> >  		return error;
> >  	}
> >  
> > @@ -1286,9 +1287,10 @@ static int __maybe_unused edt_ft5x06_ts_suspend(struct device *dev)
> >  	gpiod_set_value_cansleep(reset_gpio, 1);
> >  	usleep_range(1000, 2000);
> >  
> > -	ret = regulator_disable(tsdata->vcc);
> > +	ret = regulator_bulk_disable(ARRAY_SIZE(tsdata->regulators),
> > +				     tsdata->regulators);
> >  	if (ret)
> > -		dev_warn(dev, "Failed to disable vcc\n");
> > +		dev_warn(dev, "Failed to disable regulators\n");
> >  
> >  	return 0;
> >  }
> > @@ -1319,9 +1321,10 @@ static int __maybe_unused edt_ft5x06_ts_resume(struct device *dev)
> >  		gpiod_set_value_cansleep(reset_gpio, 1);
> >  		usleep_range(5000, 6000);
> >  
> > -		ret = regulator_enable(tsdata->vcc);
> > +		ret = regulator_bulk_enable(ARRAY_SIZE(tsdata->regulators),
> > +					    tsdata->regulators);
> >  		if (ret) {
> > -			dev_err(dev, "Failed to enable vcc\n");
> > +			dev_err(dev, "Failed to enable regulators\n");
> >  			return ret;
> >  		}
> >  
> > -- 
> > 2.30.0
> > 
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Marco Felsch Jan. 11, 2021, 9:45 a.m. UTC | #3
On 21-01-11 10:26, Stephan Gerhold wrote:
> Hi Marco,
> 
> thanks for the review!
> 
> On Mon, Jan 11, 2021 at 09:36:12AM +0100, Marco Felsch wrote:
> > Hi Stephan,
> > 
> > thanks for the patch :) Please see my inline comments.
> > 
> > On 21-01-08 20:23, Stephan Gerhold wrote:
> > > At the moment, the edt-ft5x06 driver can control a single regulator
> > > ("vcc"). However, some FocalTech touch controllers have an additional
> > > IOVCC pin that should be supplied with the digital I/O voltage.
> > > 
> > > The I/O voltage might be provided by another regulator that should also
> > > be kept on. Otherwise, the touchscreen can randomly stop functioning if
> > > the regulator is turned off because no other components still require it.
> > > 
> > > Implement (optional) support for also enabling an "iovcc-supply".
> > > IOVCC is needed whenever VCC is needed, so switch to the regulator bulk
> > > APIs to request/enable/disable both when appropriate.
> > > 
> > > Cc: Ondrej Jirman <megous@megous.com>
> > > Cc: Marco Felsch <m.felsch@pengutronix.de>
> > > Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
> > > ---
> > >  drivers/input/touchscreen/edt-ft5x06.c | 35 ++++++++++++++------------
> > >  1 file changed, 19 insertions(+), 16 deletions(-)
> > > 
> > > diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> > > index 2eefbc2485bc..bf2e208112fe 100644
> > > --- a/drivers/input/touchscreen/edt-ft5x06.c
> > > +++ b/drivers/input/touchscreen/edt-ft5x06.c
> > > @@ -103,7 +103,7 @@ struct edt_ft5x06_ts_data {
> > >  	struct touchscreen_properties prop;
> > >  	u16 num_x;
> > >  	u16 num_y;
> > > -	struct regulator *vcc;
> > > +	struct regulator_bulk_data regulators[2];
> > 
> > Is there an enabling order we must follow?
> > 
> 
> I don't know, sadly. The datasheets I was able to find do not mention
> anything about this; the power-on sequence only includes the VDD line.

I've goolged a bit :)

Check this: https://focuslcds.com/content/FT5X26.pdf, page 12 of 32

There it is mentioned that we need to enable it first and add a 10us
delay till we can enable the vdd line. So unfortunately the bulk_api
can't be used as it is today. Another solution could be to extended the
bulk api to respect on/off delays.

Regards,
  Marco

> I tried several suspend/resume cycles with both regulators set up and it
> worked fine, which could mean that I was lucky or that the order does
> not matter. :)
> 
> What do you think?
> 
> > >  	struct gpio_desc *reset_gpio;
> > >  	struct gpio_desc *wake_gpio;
> > > @@ -1066,7 +1066,7 @@ static void edt_ft5x06_disable_regulator(void *arg)
> > >  {
> > >  	struct edt_ft5x06_ts_data *data = arg;
> > >  
> > > -	regulator_disable(data->vcc);
> > > +	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
> > >  }
> > >  
> > >  static int edt_ft5x06_ts_probe(struct i2c_client *client,
> > > @@ -1098,18 +1098,19 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
> > >  
> > >  	tsdata->max_support_points = chip_data->max_support_points;
> > >  
> > > -	tsdata->vcc = devm_regulator_get(&client->dev, "vcc");
> > > -	if (IS_ERR(tsdata->vcc)) {
> > > -		error = PTR_ERR(tsdata->vcc);
> > > -		if (error != -EPROBE_DEFER)
> > > -			dev_err(&client->dev,
> > > -				"failed to request regulator: %d\n", error);
> > > -		return error;
> > > -	}
> > > +	tsdata->regulators[0].supply = "vcc";
> > > +	tsdata->regulators[1].supply = "iovcc";
> > > +	error = devm_regulator_bulk_get(&client->dev,
> > > +					ARRAY_SIZE(tsdata->regulators),
> > > +					tsdata->regulators);
> > > +	if (error)
> > > +		return dev_err_probe(&client->dev, error,
> > > +				     "failed to request regulators\n");
> > 
> > It would be nice to have a patch in front of this one which handles the
> > support for dev_err_probe().
> > 
> 
> OK, I can send a v2 with the dev_err_probe() change separated into an
> extra patch.
> 
> Thanks!
> Stephan
> 
> > 
> > >  
> > > -	error = regulator_enable(tsdata->vcc);
> > > +	error = regulator_bulk_enable(ARRAY_SIZE(tsdata->regulators),
> > > +				      tsdata->regulators);
> > >  	if (error < 0) {
> > > -		dev_err(&client->dev, "failed to enable vcc: %d\n", error);
> > > +		dev_err(&client->dev, "failed to enable regulators: %d\n", error);
> > >  		return error;
> > >  	}
> > >  
> > > @@ -1286,9 +1287,10 @@ static int __maybe_unused edt_ft5x06_ts_suspend(struct device *dev)
> > >  	gpiod_set_value_cansleep(reset_gpio, 1);
> > >  	usleep_range(1000, 2000);
> > >  
> > > -	ret = regulator_disable(tsdata->vcc);
> > > +	ret = regulator_bulk_disable(ARRAY_SIZE(tsdata->regulators),
> > > +				     tsdata->regulators);
> > >  	if (ret)
> > > -		dev_warn(dev, "Failed to disable vcc\n");
> > > +		dev_warn(dev, "Failed to disable regulators\n");
> > >  
> > >  	return 0;
> > >  }
> > > @@ -1319,9 +1321,10 @@ static int __maybe_unused edt_ft5x06_ts_resume(struct device *dev)
> > >  		gpiod_set_value_cansleep(reset_gpio, 1);
> > >  		usleep_range(5000, 6000);
> > >  
> > > -		ret = regulator_enable(tsdata->vcc);
> > > +		ret = regulator_bulk_enable(ARRAY_SIZE(tsdata->regulators),
> > > +					    tsdata->regulators);
> > >  		if (ret) {
> > > -			dev_err(dev, "Failed to enable vcc\n");
> > > +			dev_err(dev, "Failed to enable regulators\n");
> > >  			return ret;
> > >  		}
> > >  
> > > -- 
> > > 2.30.0
> > > 
> > > 
> > 
> > -- 
> > Pengutronix e.K.                           |                             |
> > Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> > 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>
Stephan Gerhold Jan. 11, 2021, 10:10 a.m. UTC | #4
On Mon, Jan 11, 2021 at 10:45:38AM +0100, Marco Felsch wrote:
> On 21-01-11 10:26, Stephan Gerhold wrote:
> > On Mon, Jan 11, 2021 at 09:36:12AM +0100, Marco Felsch wrote:
> > > On 21-01-08 20:23, Stephan Gerhold wrote:
> > > > diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> > > > index 2eefbc2485bc..bf2e208112fe 100644
> > > > --- a/drivers/input/touchscreen/edt-ft5x06.c
> > > > +++ b/drivers/input/touchscreen/edt-ft5x06.c
> > > > @@ -103,7 +103,7 @@ struct edt_ft5x06_ts_data {
> > > >  	struct touchscreen_properties prop;
> > > >  	u16 num_x;
> > > >  	u16 num_y;
> > > > -	struct regulator *vcc;
> > > > +	struct regulator_bulk_data regulators[2];
> > > 
> > > Is there an enabling order we must follow?
> > > 
> > 
> > I don't know, sadly. The datasheets I was able to find do not mention
> > anything about this; the power-on sequence only includes the VDD line.
> 
> I've goolged a bit :)
> 
> Check this: https://focuslcds.com/content/FT5X26.pdf, page 12 of 32
> 

Thanks! I looked at several datasheets, that's probably one of the few I
did not look at. :(

> There it is mentioned that we need to enable it first and add a 10us
> delay till we can enable the vdd line. So unfortunately the bulk_api
> can't be used as it is today. Another solution could be to extended the
> bulk api to respect on/off delays.
> 

I think for two regulators like here it's still manageable to
get/enable/disable/put them separately, so I will just revert the bulk
API change in v2.

Thanks again!
Stephan
Andy Shevchenko Jan. 11, 2021, 10:22 a.m. UTC | #5
On Mon, Jan 11, 2021 at 10:26:25AM +0100, Stephan Gerhold wrote:
> On Mon, Jan 11, 2021 at 09:36:12AM +0100, Marco Felsch wrote:
> > On 21-01-08 20:23, Stephan Gerhold wrote:

...

> > > +	if (error)
> > > +		return dev_err_probe(&client->dev, error,
> > > +				     "failed to request regulators\n");
> > 
> > It would be nice to have a patch in front of this one which handles the
> > support for dev_err_probe().
> > 
> 
> OK, I can send a v2 with the dev_err_probe() change separated into an
> extra patch.

AFAIR Dmitry has strong opinion against dev_err_probe(). But I might be
mistaken.
Stephan Gerhold Jan. 11, 2021, 10:43 a.m. UTC | #6
On Mon, Jan 11, 2021 at 12:22:36PM +0200, Andy Shevchenko wrote:
> On Mon, Jan 11, 2021 at 10:26:25AM +0100, Stephan Gerhold wrote:
> > On Mon, Jan 11, 2021 at 09:36:12AM +0100, Marco Felsch wrote:
> > > On 21-01-08 20:23, Stephan Gerhold wrote:
> 
> ...
> 
> > > > +	if (error)
> > > > +		return dev_err_probe(&client->dev, error,
> > > > +				     "failed to request regulators\n");
> > > 
> > > It would be nice to have a patch in front of this one which handles the
> > > support for dev_err_probe().
> > > 
> > 
> > OK, I can send a v2 with the dev_err_probe() change separated into an
> > extra patch.
> 
> AFAIR Dmitry has strong opinion against dev_err_probe(). But I might be
> mistaken.
> 

Hmm, yeah actually it seems like there was a patch for this already:
https://lore.kernel.org/linux-input/20200827185829.30096-12-krzk@kernel.org/

I guess it's better to not include this here then...

Thanks,
Stephan
Stephan Gerhold Jan. 11, 2021, 3:46 p.m. UTC | #7
Hi,

On Mon, Jan 11, 2021 at 11:10:16AM +0100, Stephan Gerhold wrote:
> On Mon, Jan 11, 2021 at 10:45:38AM +0100, Marco Felsch wrote:
> > On 21-01-11 10:26, Stephan Gerhold wrote:
> > > On Mon, Jan 11, 2021 at 09:36:12AM +0100, Marco Felsch wrote:
> > > > On 21-01-08 20:23, Stephan Gerhold wrote:
> > > > > diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> > > > > index 2eefbc2485bc..bf2e208112fe 100644
> > > > > --- a/drivers/input/touchscreen/edt-ft5x06.c
> > > > > +++ b/drivers/input/touchscreen/edt-ft5x06.c
> > > > > @@ -103,7 +103,7 @@ struct edt_ft5x06_ts_data {
> > > > >  	struct touchscreen_properties prop;
> > > > >  	u16 num_x;
> > > > >  	u16 num_y;
> > > > > -	struct regulator *vcc;
> > > > > +	struct regulator_bulk_data regulators[2];
> > > > 
> > > > Is there an enabling order we must follow?
> > > > 
> > > 
> > > I don't know, sadly. The datasheets I was able to find do not mention
> > > anything about this; the power-on sequence only includes the VDD line.
> > 
> > I've goolged a bit :)
> > 
> > Check this: https://focuslcds.com/content/FT5X26.pdf, page 12 of 32
> > 
> 
> Thanks! I looked at several datasheets, that's probably one of the few I
> did not look at. :(
> 
> > There it is mentioned that we need to enable it first and add a 10us
> > delay till we can enable the vdd line. So unfortunately the bulk_api
> > can't be used as it is today. Another solution could be to extended the
> > bulk api to respect on/off delays.
> > 
> 
> I think for two regulators like here it's still manageable to
> get/enable/disable/put them separately, so I will just revert the bulk
> API change in v2.
> 

While implementing this I noticed that the power-up sequence in probe()
does not quite seem right. The power-up sequence implemented by Marco in
edt_ft5x06_ts_resume() seems to match the datasheet(s) but in probe() we
enable VCC before doing anything with the reset line.

So before I add the IOVCC regulator I will try to refactor the code a
bit to make this consistent. :)

Thanks,
Stephan
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index 2eefbc2485bc..bf2e208112fe 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -103,7 +103,7 @@  struct edt_ft5x06_ts_data {
 	struct touchscreen_properties prop;
 	u16 num_x;
 	u16 num_y;
-	struct regulator *vcc;
+	struct regulator_bulk_data regulators[2];
 
 	struct gpio_desc *reset_gpio;
 	struct gpio_desc *wake_gpio;
@@ -1066,7 +1066,7 @@  static void edt_ft5x06_disable_regulator(void *arg)
 {
 	struct edt_ft5x06_ts_data *data = arg;
 
-	regulator_disable(data->vcc);
+	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
 }
 
 static int edt_ft5x06_ts_probe(struct i2c_client *client,
@@ -1098,18 +1098,19 @@  static int edt_ft5x06_ts_probe(struct i2c_client *client,
 
 	tsdata->max_support_points = chip_data->max_support_points;
 
-	tsdata->vcc = devm_regulator_get(&client->dev, "vcc");
-	if (IS_ERR(tsdata->vcc)) {
-		error = PTR_ERR(tsdata->vcc);
-		if (error != -EPROBE_DEFER)
-			dev_err(&client->dev,
-				"failed to request regulator: %d\n", error);
-		return error;
-	}
+	tsdata->regulators[0].supply = "vcc";
+	tsdata->regulators[1].supply = "iovcc";
+	error = devm_regulator_bulk_get(&client->dev,
+					ARRAY_SIZE(tsdata->regulators),
+					tsdata->regulators);
+	if (error)
+		return dev_err_probe(&client->dev, error,
+				     "failed to request regulators\n");
 
-	error = regulator_enable(tsdata->vcc);
+	error = regulator_bulk_enable(ARRAY_SIZE(tsdata->regulators),
+				      tsdata->regulators);
 	if (error < 0) {
-		dev_err(&client->dev, "failed to enable vcc: %d\n", error);
+		dev_err(&client->dev, "failed to enable regulators: %d\n", error);
 		return error;
 	}
 
@@ -1286,9 +1287,10 @@  static int __maybe_unused edt_ft5x06_ts_suspend(struct device *dev)
 	gpiod_set_value_cansleep(reset_gpio, 1);
 	usleep_range(1000, 2000);
 
-	ret = regulator_disable(tsdata->vcc);
+	ret = regulator_bulk_disable(ARRAY_SIZE(tsdata->regulators),
+				     tsdata->regulators);
 	if (ret)
-		dev_warn(dev, "Failed to disable vcc\n");
+		dev_warn(dev, "Failed to disable regulators\n");
 
 	return 0;
 }
@@ -1319,9 +1321,10 @@  static int __maybe_unused edt_ft5x06_ts_resume(struct device *dev)
 		gpiod_set_value_cansleep(reset_gpio, 1);
 		usleep_range(5000, 6000);
 
-		ret = regulator_enable(tsdata->vcc);
+		ret = regulator_bulk_enable(ARRAY_SIZE(tsdata->regulators),
+					    tsdata->regulators);
 		if (ret) {
-			dev_err(dev, "Failed to enable vcc\n");
+			dev_err(dev, "Failed to enable regulators\n");
 			return ret;
 		}