2018-07-17 18:17:24

by Paweł Chmiel

[permalink] [raw]
Subject: [PATCH v2 0/2] Input: atmel_mxt_ts: Add support for optional regulators

This two patches add optional regulator support to atmel_mxt_ts.
First patch adds regulators to driver.
Second patch updates documentation.

Changes from v1:
- Enable regulators only if reset_gpio is present.
- Switch from devm_regulator_get_optional to devm_regulator_get.

Paweł Chmiel (2):
Input: atmel_mxt_ts: Add support for optional regulators.
Input: atmel_mxt_ts: Document optional voltage regulators

.../devicetree/bindings/input/atmel,maxtouch.txt | 8 ++++
drivers/input/touchscreen/atmel_mxt_ts.c | 46 +++++++++++++++++++++-
2 files changed, 52 insertions(+), 2 deletions(-)

--
2.7.4



2018-07-17 18:17:31

by Paweł Chmiel

[permalink] [raw]
Subject: [PATCH v2 2/2] Input: atmel_mxt_ts: Document optional voltage regulators

Document new optional voltage regulators, which can be used
to power down/up touchscreen.

Signed-off-by: Paweł Chmiel <[email protected]>
---
Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
index c88919480d37..17930ecadad3 100644
--- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
+++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
@@ -31,6 +31,12 @@ Optional properties for main touchpad device:

- reset-gpios: GPIO specifier for the touchscreen's reset pin (active low)

+- avdd-supply: Analog power supply. It powers up the analog channel block
+ of the controller to detect the touches.
+
+- vdd-supply: Digital power supply. It powers up the digital block
+ of the controller to enable i2c communication.
+
Example:

touch@4b {
@@ -38,4 +44,6 @@ Example:
reg = <0x4b>;
interrupt-parent = <&gpio>;
interrupts = <TEGRA_GPIO(W, 3) IRQ_TYPE_LEVEL_LOW>;
+ avdd-supply = <&atsp_reg>;
+ vdd-supply = <&tsp_reg>;
};
--
2.7.4


2018-07-17 18:17:50

by Paweł Chmiel

[permalink] [raw]
Subject: [PATCH v2 1/2] Input: atmel_mxt_ts: Add support for optional regulators.

This patch adds optional regulators, which can be used to power
up touchscreen. After enabling regulators, we need to wait 150msec.
This value is taken from official driver.

It was tested on Samsung Galaxy i9000 (based on Samsung S5PV210 SOC).

Signed-off-by: Paweł Chmiel <[email protected]>
---
Changes from v1:
- Enable regulators only if reset_gpio is present.
- Switch from devm_regulator_get_optional to devm_regulator_get
---
drivers/input/touchscreen/atmel_mxt_ts.c | 46 ++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 54fe190fd4bc..005f0fee9fc8 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -27,6 +27,7 @@
#include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/property.h>
+#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/gpio/consumer.h>
#include <linux/property.h>
@@ -194,10 +195,10 @@ enum t100_type {

/* Delay times */
#define MXT_BACKUP_TIME 50 /* msec */
-#define MXT_RESET_GPIO_TIME 20 /* msec */
#define MXT_RESET_INVALID_CHG 100 /* msec */
#define MXT_RESET_TIME 200 /* msec */
#define MXT_RESET_TIMEOUT 3000 /* msec */
+#define MXT_REGULATOR_DELAY 150 /* msec */
#define MXT_CRC_TIMEOUT 1000 /* msec */
#define MXT_FW_RESET_TIME 3000 /* msec */
#define MXT_FW_CHG_TIMEOUT 300 /* msec */
@@ -310,6 +311,8 @@ struct mxt_data {
struct t7_config t7_cfg;
struct mxt_dbg dbg;
struct gpio_desc *reset_gpio;
+ struct regulator *vdd_reg;
+ struct regulator *avdd_reg;

/* Cached parameters from object table */
u16 T5_address;
@@ -3076,6 +3079,22 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
return error;
}

+ data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
+ if (IS_ERR(data->vdd_reg)) {
+ error = PTR_ERR(data->vdd_reg);
+ dev_err(&client->dev, "Failed to get vdd regulator: %d\n",
+ error);
+ return error;
+ }
+
+ data->avdd_reg = devm_regulator_get(&client->dev, "avdd");
+ if (IS_ERR(data->avdd_reg)) {
+ error = PTR_ERR(data->avdd_reg);
+ dev_err(&client->dev, "Failed to get avdd regulator: %d\n",
+ error);
+ return error;
+ }
+
error = devm_request_threaded_irq(&client->dev, client->irq,
NULL, mxt_interrupt, IRQF_ONESHOT,
client->name, data);
@@ -3087,7 +3106,26 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
disable_irq(client->irq);

if (data->reset_gpio) {
- msleep(MXT_RESET_GPIO_TIME);
+ error = regulator_enable(data->vdd_reg);
+ if (error) {
+ dev_err(&client->dev, "Failed to enable vdd regulator: %d\n",
+ error);
+ return error;
+ }
+
+ error = regulator_enable(data->avdd_reg);
+ if (error) {
+ dev_err(&client->dev, "Failed to enable avdd regulator: %d\n",
+ error);
+ return error;
+ }
+
+ /*
+ * According to maXTouch power sequencing specification, RESET line
+ * must be kept low until some time after regulators come up to
+ * voltage
+ */
+ msleep(MXT_REGULATOR_DELAY);
gpiod_set_value(data->reset_gpio, 1);
msleep(MXT_RESET_INVALID_CHG);
}
@@ -3116,6 +3154,10 @@ static int mxt_remove(struct i2c_client *client)
struct mxt_data *data = i2c_get_clientdata(client);

disable_irq(data->irq);
+ if (data->reset_gpio) {
+ regulator_disable(data->avdd_reg);
+ regulator_disable(data->vdd_reg);
+ }
sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
mxt_free_input_device(data);
mxt_free_object_table(data);
--
2.7.4


2018-07-17 21:02:18

by Nick Dyer

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] Input: atmel_mxt_ts: Add support for optional regulators.

On Tue, Jul 17, 2018 at 08:16:25PM +0200, Paweł Chmiel wrote:
> This patch adds optional regulators, which can be used to power
> up touchscreen. After enabling regulators, we need to wait 150msec.
> This value is taken from official driver.
>
> It was tested on Samsung Galaxy i9000 (based on Samsung S5PV210 SOC).
>
> Signed-off-by: Paweł Chmiel <[email protected]>
> ---
> Changes from v1:
> - Enable regulators only if reset_gpio is present.
> - Switch from devm_regulator_get_optional to devm_regulator_get
> ---
> drivers/input/touchscreen/atmel_mxt_ts.c | 46 ++++++++++++++++++++++++++++++--
> 1 file changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> index 54fe190fd4bc..005f0fee9fc8 100644
> --- a/drivers/input/touchscreen/atmel_mxt_ts.c
> +++ b/drivers/input/touchscreen/atmel_mxt_ts.c
> @@ -27,6 +27,7 @@
> #include <linux/interrupt.h>
> #include <linux/of.h>
> #include <linux/property.h>
> +#include <linux/regulator/consumer.h>
> #include <linux/slab.h>
> #include <linux/gpio/consumer.h>
> #include <linux/property.h>
> @@ -194,10 +195,10 @@ enum t100_type {
>
> /* Delay times */
> #define MXT_BACKUP_TIME 50 /* msec */
> -#define MXT_RESET_GPIO_TIME 20 /* msec */
> #define MXT_RESET_INVALID_CHG 100 /* msec */
> #define MXT_RESET_TIME 200 /* msec */
> #define MXT_RESET_TIMEOUT 3000 /* msec */
> +#define MXT_REGULATOR_DELAY 150 /* msec */
> #define MXT_CRC_TIMEOUT 1000 /* msec */
> #define MXT_FW_RESET_TIME 3000 /* msec */
> #define MXT_FW_CHG_TIMEOUT 300 /* msec */
> @@ -310,6 +311,8 @@ struct mxt_data {
> struct t7_config t7_cfg;
> struct mxt_dbg dbg;
> struct gpio_desc *reset_gpio;
> + struct regulator *vdd_reg;
> + struct regulator *avdd_reg;
>
> /* Cached parameters from object table */
> u16 T5_address;
> @@ -3076,6 +3079,22 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
> return error;
> }
>
> + data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
> + if (IS_ERR(data->vdd_reg)) {
> + error = PTR_ERR(data->vdd_reg);
> + dev_err(&client->dev, "Failed to get vdd regulator: %d\n",
> + error);
> + return error;
> + }
> +
> + data->avdd_reg = devm_regulator_get(&client->dev, "avdd");
> + if (IS_ERR(data->avdd_reg)) {
> + error = PTR_ERR(data->avdd_reg);
> + dev_err(&client->dev, "Failed to get avdd regulator: %d\n",
> + error);
> + return error;
> + }
> +
> error = devm_request_threaded_irq(&client->dev, client->irq,
> NULL, mxt_interrupt, IRQF_ONESHOT,
> client->name, data);
> @@ -3087,7 +3106,26 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
> disable_irq(client->irq);
>
> if (data->reset_gpio) {
> - msleep(MXT_RESET_GPIO_TIME);
> + error = regulator_enable(data->vdd_reg);
> + if (error) {
> + dev_err(&client->dev, "Failed to enable vdd regulator: %d\n",
> + error);
> + return error;
> + }
> +
> + error = regulator_enable(data->avdd_reg);
> + if (error) {
> + dev_err(&client->dev, "Failed to enable avdd regulator: %d\n",
> + error);
> + return error;
> + }
> +
> + /*
> + * According to maXTouch power sequencing specification, RESET line
> + * must be kept low until some time after regulators come up to
> + * voltage
> + */
> + msleep(MXT_REGULATOR_DELAY);
> gpiod_set_value(data->reset_gpio, 1);
> msleep(MXT_RESET_INVALID_CHG);

Hi Pawel-

I see you've borrowed some of the logic from the patch I wrote a while
back (see https://github.com/ndyer/linux/commit/8e9687e41ed062 )

The correct behaviour according to Atmel should be:

* Make RESET zero
* Bring up regulators
* Wait for a period to settle (150 msec)
* Release RESET
* Wait for 100 msec whilst device gets through bootloader
* Wait for CHG line assert before reading info block

I can't see the first and last steps in your patch at present.

The only downside with this approach is that there are a lot of
delays during driver probe, but I believe the asynchronous probe stuff
that's landed since I wrote the original patch should address that.

cheers

Nick

> }
> @@ -3116,6 +3154,10 @@ static int mxt_remove(struct i2c_client *client)
> struct mxt_data *data = i2c_get_clientdata(client);
>
> disable_irq(data->irq);
> + if (data->reset_gpio) {
> + regulator_disable(data->avdd_reg);
> + regulator_disable(data->vdd_reg);
> + }
> sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
> mxt_free_input_device(data);
> mxt_free_object_table(data);
> --
> 2.7.4
>

2018-07-18 16:23:33

by Paweł Chmiel

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] Input: atmel_mxt_ts: Add support for optional regulators.

On Tuesday, July 17, 2018 10:00:05 PM CEST Nick Dyer wrote:
> On Tue, Jul 17, 2018 at 08:16:25PM +0200, Paweł Chmiel wrote:
> > This patch adds optional regulators, which can be used to power
> > up touchscreen. After enabling regulators, we need to wait 150msec.
> > This value is taken from official driver.
> >
> > It was tested on Samsung Galaxy i9000 (based on Samsung S5PV210 SOC).
> >
> > Signed-off-by: Paweł Chmiel <[email protected]>
> > ---
> > Changes from v1:
> > - Enable regulators only if reset_gpio is present.
> > - Switch from devm_regulator_get_optional to devm_regulator_get
> > ---
> > drivers/input/touchscreen/atmel_mxt_ts.c | 46 ++++++++++++++++++++++++++++++--
> > 1 file changed, 44 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> > index 54fe190fd4bc..005f0fee9fc8 100644
> > --- a/drivers/input/touchscreen/atmel_mxt_ts.c
> > +++ b/drivers/input/touchscreen/atmel_mxt_ts.c
> > @@ -27,6 +27,7 @@
> > #include <linux/interrupt.h>
> > #include <linux/of.h>
> > #include <linux/property.h>
> > +#include <linux/regulator/consumer.h>
> > #include <linux/slab.h>
> > #include <linux/gpio/consumer.h>
> > #include <linux/property.h>
> > @@ -194,10 +195,10 @@ enum t100_type {
> >
> > /* Delay times */
> > #define MXT_BACKUP_TIME 50 /* msec */
> > -#define MXT_RESET_GPIO_TIME 20 /* msec */
> > #define MXT_RESET_INVALID_CHG 100 /* msec */
> > #define MXT_RESET_TIME 200 /* msec */
> > #define MXT_RESET_TIMEOUT 3000 /* msec */
> > +#define MXT_REGULATOR_DELAY 150 /* msec */
> > #define MXT_CRC_TIMEOUT 1000 /* msec */
> > #define MXT_FW_RESET_TIME 3000 /* msec */
> > #define MXT_FW_CHG_TIMEOUT 300 /* msec */
> > @@ -310,6 +311,8 @@ struct mxt_data {
> > struct t7_config t7_cfg;
> > struct mxt_dbg dbg;
> > struct gpio_desc *reset_gpio;
> > + struct regulator *vdd_reg;
> > + struct regulator *avdd_reg;
> >
> > /* Cached parameters from object table */
> > u16 T5_address;
> > @@ -3076,6 +3079,22 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
> > return error;
> > }
> >
> > + data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
> > + if (IS_ERR(data->vdd_reg)) {
> > + error = PTR_ERR(data->vdd_reg);
> > + dev_err(&client->dev, "Failed to get vdd regulator: %d\n",
> > + error);
> > + return error;
> > + }
> > +
> > + data->avdd_reg = devm_regulator_get(&client->dev, "avdd");
> > + if (IS_ERR(data->avdd_reg)) {
> > + error = PTR_ERR(data->avdd_reg);
> > + dev_err(&client->dev, "Failed to get avdd regulator: %d\n",
> > + error);
> > + return error;
> > + }
> > +
> > error = devm_request_threaded_irq(&client->dev, client->irq,
> > NULL, mxt_interrupt, IRQF_ONESHOT,
> > client->name, data);
> > @@ -3087,7 +3106,26 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
> > disable_irq(client->irq);
> >
> > if (data->reset_gpio) {
> > - msleep(MXT_RESET_GPIO_TIME);
> > + error = regulator_enable(data->vdd_reg);
> > + if (error) {
> > + dev_err(&client->dev, "Failed to enable vdd regulator: %d\n",
> > + error);
> > + return error;
> > + }
> > +
> > + error = regulator_enable(data->avdd_reg);
> > + if (error) {
> > + dev_err(&client->dev, "Failed to enable avdd regulator: %d\n",
> > + error);
> > + return error;
> > + }
> > +
> > + /*
> > + * According to maXTouch power sequencing specification, RESET line
> > + * must be kept low until some time after regulators come up to
> > + * voltage
> > + */
> > + msleep(MXT_REGULATOR_DELAY);
> > gpiod_set_value(data->reset_gpio, 1);
> > msleep(MXT_RESET_INVALID_CHG);
>
> Hi Pawel-
>
> I see you've borrowed some of the logic from the patch I wrote a while
> back (see https://github.com/ndyer/linux/commit/8e9687e41ed062 )
Actually, i was looking at https://github.com/atmel-maxtouch/linux/blob/maxtouch-v3.14/drivers/input/touchscreen/atmel_mxt_ts.c (and didn't saw Your patch till now).
Are You going to submit it? (it has more functionalities - for example suspend mode read from device tree).
>
> The correct behaviour according to Atmel should be:
>
> * Make RESET zero
> * Bring up regulators
> * Wait for a period to settle (150 msec)
> * Release RESET
> * Wait for 100 msec whilst device gets through bootloader
> * Wait for CHG line assert before reading info block
>
> I can't see the first and last steps in your patch at present.
About first step - reset_gpio is readed by using devm_gpiod_get_optional with GPIOD_OUT_LOW flag, so i think (but might be wrong) that we don't need to set this gpio value again to 0 before enabling regulators,
since currently only place where reset_gpio is used is in driver probe (in Your patch it is used in other cases/places - for example in mxt_start/stop, when we enable regulators).
About missing wait after releasing reset, shouldn't this be separate patch (since currently driver is not doing it)? I can prepare it and send with other in next version.

Thanks for feedback
>
> The only downside with this approach is that there are a lot of
> delays during driver probe, but I believe the asynchronous probe stuff
> that's landed since I wrote the original patch should address that.
>
> cheers
>
> Nick
>
> > }
> > @@ -3116,6 +3154,10 @@ static int mxt_remove(struct i2c_client *client)
> > struct mxt_data *data = i2c_get_clientdata(client);
> >
> > disable_irq(data->irq);
> > + if (data->reset_gpio) {
> > + regulator_disable(data->avdd_reg);
> > + regulator_disable(data->vdd_reg);
> > + }
> > sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
> > mxt_free_input_device(data);
> > mxt_free_object_table(data);
>



2018-07-19 20:55:33

by Nick Dyer

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] Input: atmel_mxt_ts: Add support for optional regulators.

On Wed, Jul 18, 2018 at 06:21:30PM +0200, Paweł Chmiel wrote:
> On Tuesday, July 17, 2018 10:00:05 PM CEST Nick Dyer wrote:
> > On Tue, Jul 17, 2018 at 08:16:25PM +0200, Paweł Chmiel wrote:
> > > This patch adds optional regulators, which can be used to power
> > > up touchscreen. After enabling regulators, we need to wait 150msec.
> > > This value is taken from official driver.
> > >
> > > It was tested on Samsung Galaxy i9000 (based on Samsung S5PV210 SOC).
> > >
> > > Signed-off-by: Paweł Chmiel <[email protected]>
> > > ---
> > > Changes from v1:
> > > - Enable regulators only if reset_gpio is present.
> > > - Switch from devm_regulator_get_optional to devm_regulator_get
> > > ---
> > > drivers/input/touchscreen/atmel_mxt_ts.c | 46 ++++++++++++++++++++++++++++++--
> > > 1 file changed, 44 insertions(+), 2 deletions(-)
> >
> > Hi Pawel-
> >
> > I see you've borrowed some of the logic from the patch I wrote a while
> > back (see https://github.com/ndyer/linux/commit/8e9687e41ed062 )
> Actually, i was looking at https://github.com/atmel-maxtouch/linux/blob/maxtouch-v3.14/drivers/input/touchscreen/atmel_mxt_ts.c (and didn't saw Your patch till now).
> Are You going to submit it? (it has more functionalities - for example
> suspend mode read from device tree).

Getting that work upstream has stalled for a couple of years because I
changed jobs. I have actually started recently to dust it off again, it
was later on in my queue but if you have the time to work on it that is
great.

> > The correct behaviour according to Atmel should be:
> >
> > * Make RESET zero
> > * Bring up regulators
> > * Wait for a period to settle (150 msec)
> > * Release RESET
> > * Wait for 100 msec whilst device gets through bootloader
> > * Wait for CHG line assert before reading info block
> >
> > I can't see the first and last steps in your patch at present.
> About first step - reset_gpio is readed by using
> devm_gpiod_get_optional with GPIOD_OUT_LOW flag, so i think (but might
> be wrong) that we don't need to set this gpio value again to 0 before
> enabling regulators,

I see what you mean - that is fair enough.

> since currently only place where reset_gpio is used is in driver probe
> (in Your patch it is used in other cases/places - for example in
> mxt_start/stop, when we enable regulators).
> About missing wait after releasing reset, shouldn't this be separate
> patch (since currently driver is not doing it)? I can prepare it and
> send with other in next version.

According to the maxtouch documentation, it isn't ready for comms until
the firmware asserts the CHG line. I've seen a bunch of devices that get
by without an explicit wait because the board file does the power on,
and by the time the driver gets to probe it's a few hundred ms later
anyway, so it doesn't matter. But if we put it all in the driver, it
will attempt to read the info block straight after the 100 msec delay
without waiting for CHG, and I suspect we'll end up with occasional
probe failures. It'll depend on the maxtouch device, though: they have a
range of different power on timings.

Which platform are you doing this for? Is it a Chromebook?

> Thanks for feedback
> >
> > The only downside with this approach is that there are a lot of
> > delays during driver probe, but I believe the asynchronous probe stuff
> > that's landed since I wrote the original patch should address that.
> >
> > cheers
> >
> > Nick
> >
> > > }
> > > @@ -3116,6 +3154,10 @@ static int mxt_remove(struct i2c_client *client)
> > > struct mxt_data *data = i2c_get_clientdata(client);
> > >
> > > disable_irq(data->irq);
> > > + if (data->reset_gpio) {
> > > + regulator_disable(data->avdd_reg);
> > > + regulator_disable(data->vdd_reg);
> > > + }
> > > sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
> > > mxt_free_input_device(data);
> > > mxt_free_object_table(data);
> >
>
>

2018-07-25 16:03:55

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] Input: atmel_mxt_ts: Document optional voltage regulators

On Tue, Jul 17, 2018 at 08:16:26PM +0200, Paweł Chmiel wrote:
> Document new optional voltage regulators, which can be used
> to power down/up touchscreen.
>
> Signed-off-by: Paweł Chmiel <[email protected]>
> ---
> Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 8 ++++++++
> 1 file changed, 8 insertions(+)

Reviewed-by: Rob Herring <[email protected]>

2018-07-28 13:17:55

by Paweł Chmiel

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] Input: atmel_mxt_ts: Add support for optional regulators.

On Thursday, July 19, 2018 9:54:04 PM CEST Nick Dyer wrote:
> On Wed, Jul 18, 2018 at 06:21:30PM +0200, Paweł Chmiel wrote:
> > On Tuesday, July 17, 2018 10:00:05 PM CEST Nick Dyer wrote:
> > > On Tue, Jul 17, 2018 at 08:16:25PM +0200, Paweł Chmiel wrote:
> > > > This patch adds optional regulators, which can be used to power
> > > > up touchscreen. After enabling regulators, we need to wait 150msec.
> > > > This value is taken from official driver.
> > > >
> > > > It was tested on Samsung Galaxy i9000 (based on Samsung S5PV210 SOC).
> > > >
> > > > Signed-off-by: Paweł Chmiel <[email protected]>
> > > > ---
> > > > Changes from v1:
> > > > - Enable regulators only if reset_gpio is present.
> > > > - Switch from devm_regulator_get_optional to devm_regulator_get
> > > > ---
> > > > drivers/input/touchscreen/atmel_mxt_ts.c | 46 ++++++++++++++++++++++++++++++--
> > > > 1 file changed, 44 insertions(+), 2 deletions(-)
> > >
> > > Hi Pawel-
> > >
> > > I see you've borrowed some of the logic from the patch I wrote a while
> > > back (see https://github.com/ndyer/linux/commit/8e9687e41ed062 )
> > Actually, i was looking at https://github.com/atmel-maxtouch/linux/blob/maxtouch-v3.14/drivers/input/touchscreen/atmel_mxt_ts.c (and didn't saw Your patch till now).
> > Are You going to submit it? (it has more functionalities - for example
> > suspend mode read from device tree).
>
> Getting that work upstream has stalled for a couple of years because I
> changed jobs. I have actually started recently to dust it off again, it
> was later on in my queue but if you have the time to work on it that is
> great.
>
> > > The correct behaviour according to Atmel should be:
> > >
> > > * Make RESET zero
> > > * Bring up regulators
> > > * Wait for a period to settle (150 msec)
> > > * Release RESET
> > > * Wait for 100 msec whilst device gets through bootloader
> > > * Wait for CHG line assert before reading info block
> > >
> > > I can't see the first and last steps in your patch at present.
> > About first step - reset_gpio is readed by using
> > devm_gpiod_get_optional with GPIOD_OUT_LOW flag, so i think (but might
> > be wrong) that we don't need to set this gpio value again to 0 before
> > enabling regulators,
>
> I see what you mean - that is fair enough.
>
> > since currently only place where reset_gpio is used is in driver probe
> > (in Your patch it is used in other cases/places - for example in
> > mxt_start/stop, when we enable regulators).
> > About missing wait after releasing reset, shouldn't this be separate
> > patch (since currently driver is not doing it)? I can prepare it and
> > send with other in next version.
>
> According to the maxtouch documentation, it isn't ready for comms until
> the firmware asserts the CHG line. I've seen a bunch of devices that get
> by without an explicit wait because the board file does the power on,
> and by the time the driver gets to probe it's a few hundred ms later
> anyway, so it doesn't matter. But if we put it all in the driver, it
> will attempt to read the info block straight after the 100 msec delay
> without waiting for CHG, and I suspect we'll end up with occasional
> probe failures. It'll depend on the maxtouch device, though: they have a
> range of different power on timings.
>
> Which platform are you doing this for? Is it a Chromebook?
No, it's Samsung Galaxy S (i9000) phone with S5PV210 Samsung Soc.
I'm preparing v3 version with separate patch adding this wait/delay.
>
> > Thanks for feedback
> > >
> > > The only downside with this approach is that there are a lot of
> > > delays during driver probe, but I believe the asynchronous probe stuff
> > > that's landed since I wrote the original patch should address that.
> > >
> > > cheers
> > >
> > > Nick
> > >
> > > > }
> > > > @@ -3116,6 +3154,10 @@ static int mxt_remove(struct i2c_client *client)
> > > > struct mxt_data *data = i2c_get_clientdata(client);
> > > >
> > > > disable_irq(data->irq);
> > > > + if (data->reset_gpio) {
> > > > + regulator_disable(data->avdd_reg);
> > > > + regulator_disable(data->vdd_reg);
> > > > + }
> > > > sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
> > > > mxt_free_input_device(data);
> > > > mxt_free_object_table(data);
> > >
> >
> >
>



2018-08-22 22:54:52

by George G. Davis

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] Input: atmel_mxt_ts: Add support for optional regulators.

Hello Nick,

On Tue, Jul 17, 2018 at 10:00:05PM +0100, Nick Dyer wrote:
> On Tue, Jul 17, 2018 at 08:16:25PM +0200, Paweł Chmiel wrote:
> > This patch adds optional regulators, which can be used to power
> > up touchscreen. After enabling regulators, we need to wait 150msec.
> > This value is taken from official driver.
> >
> > It was tested on Samsung Galaxy i9000 (based on Samsung S5PV210 SOC).
> >
> > Signed-off-by: Paweł Chmiel <[email protected]>
> > ---
> > Changes from v1:
> > - Enable regulators only if reset_gpio is present.
> > - Switch from devm_regulator_get_optional to devm_regulator_get
> > ---
> > drivers/input/touchscreen/atmel_mxt_ts.c | 46 ++++++++++++++++++++++++++++++--
> > 1 file changed, 44 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> > index 54fe190fd4bc..005f0fee9fc8 100644
> > --- a/drivers/input/touchscreen/atmel_mxt_ts.c
> > +++ b/drivers/input/touchscreen/atmel_mxt_ts.c
> > @@ -27,6 +27,7 @@
> > #include <linux/interrupt.h>
> > #include <linux/of.h>
> > #include <linux/property.h>
> > +#include <linux/regulator/consumer.h>
> > #include <linux/slab.h>
> > #include <linux/gpio/consumer.h>
> > #include <linux/property.h>
> > @@ -194,10 +195,10 @@ enum t100_type {
> >
> > /* Delay times */
> > #define MXT_BACKUP_TIME 50 /* msec */
> > -#define MXT_RESET_GPIO_TIME 20 /* msec */
> > #define MXT_RESET_INVALID_CHG 100 /* msec */
> > #define MXT_RESET_TIME 200 /* msec */
> > #define MXT_RESET_TIMEOUT 3000 /* msec */
> > +#define MXT_REGULATOR_DELAY 150 /* msec */
> > #define MXT_CRC_TIMEOUT 1000 /* msec */
> > #define MXT_FW_RESET_TIME 3000 /* msec */
> > #define MXT_FW_CHG_TIMEOUT 300 /* msec */
> > @@ -310,6 +311,8 @@ struct mxt_data {
> > struct t7_config t7_cfg;
> > struct mxt_dbg dbg;
> > struct gpio_desc *reset_gpio;
> > + struct regulator *vdd_reg;
> > + struct regulator *avdd_reg;
> >
> > /* Cached parameters from object table */
> > u16 T5_address;
> > @@ -3076,6 +3079,22 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
> > return error;
> > }
> >
> > + data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
> > + if (IS_ERR(data->vdd_reg)) {
> > + error = PTR_ERR(data->vdd_reg);
> > + dev_err(&client->dev, "Failed to get vdd regulator: %d\n",
> > + error);
> > + return error;
> > + }
> > +
> > + data->avdd_reg = devm_regulator_get(&client->dev, "avdd");
> > + if (IS_ERR(data->avdd_reg)) {
> > + error = PTR_ERR(data->avdd_reg);
> > + dev_err(&client->dev, "Failed to get avdd regulator: %d\n",
> > + error);
> > + return error;
> > + }
> > +
> > error = devm_request_threaded_irq(&client->dev, client->irq,
> > NULL, mxt_interrupt, IRQF_ONESHOT,
> > client->name, data);
> > @@ -3087,7 +3106,26 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
> > disable_irq(client->irq);
> >
> > if (data->reset_gpio) {
> > - msleep(MXT_RESET_GPIO_TIME);
> > + error = regulator_enable(data->vdd_reg);
> > + if (error) {
> > + dev_err(&client->dev, "Failed to enable vdd regulator: %d\n",
> > + error);
> > + return error;
> > + }
> > +
> > + error = regulator_enable(data->avdd_reg);
> > + if (error) {
> > + dev_err(&client->dev, "Failed to enable avdd regulator: %d\n",
> > + error);
> > + return error;
> > + }
> > +
> > + /*
> > + * According to maXTouch power sequencing specification, RESET line
> > + * must be kept low until some time after regulators come up to
> > + * voltage
> > + */
> > + msleep(MXT_REGULATOR_DELAY);
> > gpiod_set_value(data->reset_gpio, 1);
> > msleep(MXT_RESET_INVALID_CHG);
>
> Hi Pawel-
>
> I see you've borrowed some of the logic from the patch I wrote a while
> back (see https://github.com/ndyer/linux/commit/8e9687e41ed062 )

I'm actually quite interested in your work and notice that it has
languished for some time now. If you have rebased any of your earlier
work to more recent kernel versions, I'd be happy to assist with testing
and review.

--
Regards,
George

> The correct behaviour according to Atmel should be:
>
> * Make RESET zero
> * Bring up regulators
> * Wait for a period to settle (150 msec)
> * Release RESET
> * Wait for 100 msec whilst device gets through bootloader
> * Wait for CHG line assert before reading info block
>
> I can't see the first and last steps in your patch at present.
>
> The only downside with this approach is that there are a lot of
> delays during driver probe, but I believe the asynchronous probe stuff
> that's landed since I wrote the original patch should address that.
>
> cheers
>
> Nick
>
> > }
> > @@ -3116,6 +3154,10 @@ static int mxt_remove(struct i2c_client *client)
> > struct mxt_data *data = i2c_get_clientdata(client);
> >
> > disable_irq(data->irq);
> > + if (data->reset_gpio) {
> > + regulator_disable(data->avdd_reg);
> > + regulator_disable(data->vdd_reg);
> > + }
> > sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
> > mxt_free_input_device(data);
> > mxt_free_object_table(data);
> > --
> > 2.7.4
> >
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel