diff mbox series

Input: edt-ft5x06 - add vdd supply

Message ID 20190514212111.21742-1-martijn@brixit.nl (mailing list archive)
State Superseded
Headers show
Series Input: edt-ft5x06 - add vdd supply | expand

Commit Message

Martijn Braam May 14, 2019, 9:21 p.m. UTC
Add a regulator supply request for the controller power

Signed-off-by: Martijn Braam <martijn@brixit.nl>
---
 drivers/input/touchscreen/edt-ft5x06.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Marco Felsch May 15, 2019, 4:41 a.m. UTC | #1
Hi Martijn,

On 19-05-14 23:21, Martijn Braam wrote:
> Add a regulator supply request for the controller power
> 
> Signed-off-by: Martijn Braam <martijn@brixit.nl>
> ---
>  drivers/input/touchscreen/edt-ft5x06.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> index 702bfda7ee77..226c623f8d46 100644
> --- a/drivers/input/touchscreen/edt-ft5x06.c
> +++ b/drivers/input/touchscreen/edt-ft5x06.c
> @@ -29,6 +29,7 @@
>  #include <linux/ratelimit.h>
>  #include <linux/irq.h>
>  #include <linux/interrupt.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/input.h>
>  #include <linux/i2c.h>
>  #include <linux/kernel.h>
> @@ -103,6 +104,7 @@ struct edt_ft5x06_ts_data {
>  
>  	struct gpio_desc *reset_gpio;
>  	struct gpio_desc *wake_gpio;
> +	struct regulator *vdd;
>  
>  #if defined(CONFIG_DEBUG_FS)
>  	struct dentry *debug_dir;
> @@ -1092,6 +1094,22 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
>  		return error;
>  	}
>  
> +	tsdata->vdd = devm_regulator_get(&client->dev, "vdd");
> +	if (IS_ERR(tsdata->vdd)) {
> +		error = PTR_ERR(tsdata->vdd);
> +		if (error != -EPROBE_DEFER)
> +			dev_err(&client->dev,
> +				"Failed to get vdd regulator: %d\n", error);
> +		return error;

This will break current device tree's and this should never happen. So
we need to make this regulator optional.
BTW:
Did you changed the bindings too?

Regards,
  Marco

> +	}
> +
> +	/* power the controller */
> +	error = regulator_enable(tsdata->vdd);
> +	if (error) {
> +		dev_err(&client->dev, "Controller fail to enable vdd\n");
> +		return error;
> +	}
> +
>  	tsdata->wake_gpio = devm_gpiod_get_optional(&client->dev,
>  						    "wake", GPIOD_OUT_LOW);
>  	if (IS_ERR(tsdata->wake_gpio)) {
> @@ -1204,6 +1222,7 @@ static int edt_ft5x06_ts_remove(struct i2c_client *client)
>  {
>  	struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
>  
> +	regulator_disable(tsdata->vdd);
>  	edt_ft5x06_ts_teardown_debugfs(tsdata);
>  
>  	return 0;
> -- 
> 2.21.0
> 
>
Martijn Braam May 15, 2019, 10:36 p.m. UTC | #2
Hi Marco,

The regulator seems to be optional this way, it gets a dummy regulator
if none is specified so it shouldn't break existing devices. '
I think I managed to do the git send-email thing correctly to add the bindings.

Greetings,
Martijn Braam

Op wo 15 mei 2019 om 06:41 schreef Marco Felsch <m.felsch@pengutronix.de>:

>
> Hi Martijn,
>
> On 19-05-14 23:21, Martijn Braam wrote:
> > Add a regulator supply request for the controller power
> >
> > Signed-off-by: Martijn Braam <martijn@brixit.nl>
> > ---
> >  drivers/input/touchscreen/edt-ft5x06.c | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> >
> > diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> > index 702bfda7ee77..226c623f8d46 100644
> > --- a/drivers/input/touchscreen/edt-ft5x06.c
> > +++ b/drivers/input/touchscreen/edt-ft5x06.c
> > @@ -29,6 +29,7 @@
> >  #include <linux/ratelimit.h>
> >  #include <linux/irq.h>
> >  #include <linux/interrupt.h>
> > +#include <linux/regulator/consumer.h>
> >  #include <linux/input.h>
> >  #include <linux/i2c.h>
> >  #include <linux/kernel.h>
> > @@ -103,6 +104,7 @@ struct edt_ft5x06_ts_data {
> >
> >       struct gpio_desc *reset_gpio;
> >       struct gpio_desc *wake_gpio;
> > +     struct regulator *vdd;
> >
> >  #if defined(CONFIG_DEBUG_FS)
> >       struct dentry *debug_dir;
> > @@ -1092,6 +1094,22 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
> >               return error;
> >       }
> >
> > +     tsdata->vdd = devm_regulator_get(&client->dev, "vdd");
> > +     if (IS_ERR(tsdata->vdd)) {
> > +             error = PTR_ERR(tsdata->vdd);
> > +             if (error != -EPROBE_DEFER)
> > +                     dev_err(&client->dev,
> > +                             "Failed to get vdd regulator: %d\n", error);
> > +             return error;
>
> This will break current device tree's and this should never happen. So
> we need to make this regulator optional.
> BTW:
> Did you changed the bindings too?
>
> Regards,
>   Marco
>
> > +     }
> > +
> > +     /* power the controller */
> > +     error = regulator_enable(tsdata->vdd);
> > +     if (error) {
> > +             dev_err(&client->dev, "Controller fail to enable vdd\n");
> > +             return error;
> > +     }
> > +
> >       tsdata->wake_gpio = devm_gpiod_get_optional(&client->dev,
> >                                                   "wake", GPIOD_OUT_LOW);
> >       if (IS_ERR(tsdata->wake_gpio)) {
> > @@ -1204,6 +1222,7 @@ static int edt_ft5x06_ts_remove(struct i2c_client *client)
> >  {
> >       struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
> >
> > +     regulator_disable(tsdata->vdd);
> >       edt_ft5x06_ts_teardown_debugfs(tsdata);
> >
> >       return 0;
> > --
> > 2.21.0
> >
> >
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Marco Felsch May 16, 2019, 10:12 a.m. UTC | #3
Hi Martijn,

On 19-05-16 00:36, Martijn Braam wrote:
> Hi Marco,
> 
> The regulator seems to be optional this way, it gets a dummy regulator
> if none is specified so it shouldn't break existing devices. '

You're right I didn't covered that.

> I think I managed to do the git send-email thing correctly to add the bindings.

Seems to be okay :)

Regards,
  Marco

> Greetings,
> Martijn Braam
> 
> Op wo 15 mei 2019 om 06:41 schreef Marco Felsch <m.felsch@pengutronix.de>:
> 
> >
> > Hi Martijn,
> >
> > On 19-05-14 23:21, Martijn Braam wrote:
> > > Add a regulator supply request for the controller power
> > >
> > > Signed-off-by: Martijn Braam <martijn@brixit.nl>
> > > ---
> > >  drivers/input/touchscreen/edt-ft5x06.c | 19 +++++++++++++++++++
> > >  1 file changed, 19 insertions(+)
> > >
> > > diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> > > index 702bfda7ee77..226c623f8d46 100644
> > > --- a/drivers/input/touchscreen/edt-ft5x06.c
> > > +++ b/drivers/input/touchscreen/edt-ft5x06.c
> > > @@ -29,6 +29,7 @@
> > >  #include <linux/ratelimit.h>
> > >  #include <linux/irq.h>
> > >  #include <linux/interrupt.h>
> > > +#include <linux/regulator/consumer.h>
> > >  #include <linux/input.h>
> > >  #include <linux/i2c.h>
> > >  #include <linux/kernel.h>
> > > @@ -103,6 +104,7 @@ struct edt_ft5x06_ts_data {
> > >
> > >       struct gpio_desc *reset_gpio;
> > >       struct gpio_desc *wake_gpio;
> > > +     struct regulator *vdd;
> > >
> > >  #if defined(CONFIG_DEBUG_FS)
> > >       struct dentry *debug_dir;
> > > @@ -1092,6 +1094,22 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
> > >               return error;
> > >       }
> > >
> > > +     tsdata->vdd = devm_regulator_get(&client->dev, "vdd");
> > > +     if (IS_ERR(tsdata->vdd)) {
> > > +             error = PTR_ERR(tsdata->vdd);
> > > +             if (error != -EPROBE_DEFER)
> > > +                     dev_err(&client->dev,
> > > +                             "Failed to get vdd regulator: %d\n", error);
> > > +             return error;
> >
> > This will break current device tree's and this should never happen. So
> > we need to make this regulator optional.
> > BTW:
> > Did you changed the bindings too?
> >
> > Regards,
> >   Marco
> >
> > > +     }
> > > +
> > > +     /* power the controller */
> > > +     error = regulator_enable(tsdata->vdd);
> > > +     if (error) {
> > > +             dev_err(&client->dev, "Controller fail to enable vdd\n");
> > > +             return error;
> > > +     }
> > > +
> > >       tsdata->wake_gpio = devm_gpiod_get_optional(&client->dev,
> > >                                                   "wake", GPIOD_OUT_LOW);
> > >       if (IS_ERR(tsdata->wake_gpio)) {
> > > @@ -1204,6 +1222,7 @@ static int edt_ft5x06_ts_remove(struct i2c_client *client)
> > >  {
> > >       struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
> > >
> > > +     regulator_disable(tsdata->vdd);
> > >       edt_ft5x06_ts_teardown_debugfs(tsdata);
> > >
> > >       return 0;
> > > --
> > > 2.21.0
> > >
> > >
> >
> > --
> > Pengutronix e.K.                           |                             |
> > Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>
Dmitry Torokhov June 30, 2019, 7:12 a.m. UTC | #4
Hi Martijn,

On Tue, May 14, 2019 at 11:21:11PM +0200, Martijn Braam wrote:
> Add a regulator supply request for the controller power
> 
> Signed-off-by: Martijn Braam <martijn@brixit.nl>
> ---
>  drivers/input/touchscreen/edt-ft5x06.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> index 702bfda7ee77..226c623f8d46 100644
> --- a/drivers/input/touchscreen/edt-ft5x06.c
> +++ b/drivers/input/touchscreen/edt-ft5x06.c
> @@ -29,6 +29,7 @@
>  #include <linux/ratelimit.h>
>  #include <linux/irq.h>
>  #include <linux/interrupt.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/input.h>
>  #include <linux/i2c.h>
>  #include <linux/kernel.h>
> @@ -103,6 +104,7 @@ struct edt_ft5x06_ts_data {
>  
>  	struct gpio_desc *reset_gpio;
>  	struct gpio_desc *wake_gpio;
> +	struct regulator *vdd;
>  
>  #if defined(CONFIG_DEBUG_FS)
>  	struct dentry *debug_dir;
> @@ -1092,6 +1094,22 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
>  		return error;
>  	}
>  
> +	tsdata->vdd = devm_regulator_get(&client->dev, "vdd");
> +	if (IS_ERR(tsdata->vdd)) {
> +		error = PTR_ERR(tsdata->vdd);
> +		if (error != -EPROBE_DEFER)
> +			dev_err(&client->dev,
> +				"Failed to get vdd regulator: %d\n", error);
> +		return error;
> +	}
> +
> +	/* power the controller */
> +	error = regulator_enable(tsdata->vdd);
> +	if (error) {
> +		dev_err(&client->dev, "Controller fail to enable vdd\n");
> +		return error;
> +	}
> +
>  	tsdata->wake_gpio = devm_gpiod_get_optional(&client->dev,
>  						    "wake", GPIOD_OUT_LOW);
>  	if (IS_ERR(tsdata->wake_gpio)) {
> @@ -1204,6 +1222,7 @@ static int edt_ft5x06_ts_remove(struct i2c_client *client)
>  {
>  	struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
>  
> +	regulator_disable(tsdata->vdd);

This is too early. You are powering down the chip while it may still
generate interrupts and we'll get errors if we try to access it then.
Please use devm_add_action_or_reset() to include turning off the
regulator into devm handling of the rest of the resources.

>  	edt_ft5x06_ts_teardown_debugfs(tsdata);
>  
>  	return 0;
> -- 
> 2.21.0
> 

Thanks.
Dmitry Torokhov July 1, 2019, 7:34 a.m. UTC | #5
On Sun, Jun 30, 2019 at 12:12:13AM -0700, Dmitry Torokhov wrote:
> Hi Martijn,
> 
> On Tue, May 14, 2019 at 11:21:11PM +0200, Martijn Braam wrote:
> > Add a regulator supply request for the controller power
> > 
> > Signed-off-by: Martijn Braam <martijn@brixit.nl>
> > ---
> >  drivers/input/touchscreen/edt-ft5x06.c | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> > 
> > diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> > index 702bfda7ee77..226c623f8d46 100644
> > --- a/drivers/input/touchscreen/edt-ft5x06.c
> > +++ b/drivers/input/touchscreen/edt-ft5x06.c
> > @@ -29,6 +29,7 @@
> >  #include <linux/ratelimit.h>
> >  #include <linux/irq.h>
> >  #include <linux/interrupt.h>
> > +#include <linux/regulator/consumer.h>
> >  #include <linux/input.h>
> >  #include <linux/i2c.h>
> >  #include <linux/kernel.h>
> > @@ -103,6 +104,7 @@ struct edt_ft5x06_ts_data {
> >  
> >  	struct gpio_desc *reset_gpio;
> >  	struct gpio_desc *wake_gpio;
> > +	struct regulator *vdd;
> >  
> >  #if defined(CONFIG_DEBUG_FS)
> >  	struct dentry *debug_dir;
> > @@ -1092,6 +1094,22 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
> >  		return error;
> >  	}
> >  
> > +	tsdata->vdd = devm_regulator_get(&client->dev, "vdd");
> > +	if (IS_ERR(tsdata->vdd)) {
> > +		error = PTR_ERR(tsdata->vdd);
> > +		if (error != -EPROBE_DEFER)
> > +			dev_err(&client->dev,
> > +				"Failed to get vdd regulator: %d\n", error);
> > +		return error;
> > +	}
> > +
> > +	/* power the controller */
> > +	error = regulator_enable(tsdata->vdd);
> > +	if (error) {
> > +		dev_err(&client->dev, "Controller fail to enable vdd\n");
> > +		return error;
> > +	}
> > +
> >  	tsdata->wake_gpio = devm_gpiod_get_optional(&client->dev,
> >  						    "wake", GPIOD_OUT_LOW);
> >  	if (IS_ERR(tsdata->wake_gpio)) {
> > @@ -1204,6 +1222,7 @@ static int edt_ft5x06_ts_remove(struct i2c_client *client)
> >  {
> >  	struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
> >  
> > +	regulator_disable(tsdata->vdd);
> 
> This is too early. You are powering down the chip while it may still
> generate interrupts and we'll get errors if we try to access it then.
> Please use devm_add_action_or_reset() to include turning off the
> regulator into devm handling of the rest of the resources.

Also, I just recalled that Mylène Josserand was also working on adding
regulator handling for this driver, you want to check their work to make
sure it is compatible.

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index 702bfda7ee77..226c623f8d46 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -29,6 +29,7 @@ 
 #include <linux/ratelimit.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
+#include <linux/regulator/consumer.h>
 #include <linux/input.h>
 #include <linux/i2c.h>
 #include <linux/kernel.h>
@@ -103,6 +104,7 @@  struct edt_ft5x06_ts_data {
 
 	struct gpio_desc *reset_gpio;
 	struct gpio_desc *wake_gpio;
+	struct regulator *vdd;
 
 #if defined(CONFIG_DEBUG_FS)
 	struct dentry *debug_dir;
@@ -1092,6 +1094,22 @@  static int edt_ft5x06_ts_probe(struct i2c_client *client,
 		return error;
 	}
 
+	tsdata->vdd = devm_regulator_get(&client->dev, "vdd");
+	if (IS_ERR(tsdata->vdd)) {
+		error = PTR_ERR(tsdata->vdd);
+		if (error != -EPROBE_DEFER)
+			dev_err(&client->dev,
+				"Failed to get vdd regulator: %d\n", error);
+		return error;
+	}
+
+	/* power the controller */
+	error = regulator_enable(tsdata->vdd);
+	if (error) {
+		dev_err(&client->dev, "Controller fail to enable vdd\n");
+		return error;
+	}
+
 	tsdata->wake_gpio = devm_gpiod_get_optional(&client->dev,
 						    "wake", GPIOD_OUT_LOW);
 	if (IS_ERR(tsdata->wake_gpio)) {
@@ -1204,6 +1222,7 @@  static int edt_ft5x06_ts_remove(struct i2c_client *client)
 {
 	struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
 
+	regulator_disable(tsdata->vdd);
 	edt_ft5x06_ts_teardown_debugfs(tsdata);
 
 	return 0;