linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Stefan Eichenberger <eichest@gmail.com>
Cc: nick@shmanahar.org, robh@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
	nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com,
	claudiu.beznea@tuxon.dev, linus.walleij@linaro.org,
	linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Stefan Eichenberger <stefan.eichenberger@toradex.com>
Subject: Re: [PATCH v4 1/4] Input: atmel_mxt_ts - add power off and power on functions
Date: Mon, 8 Jul 2024 21:55:37 -0700	[thread overview]
Message-ID: <ZozCyQ-deK8A2uOe@google.com> (raw)
In-Reply-To: <ZnWQYc1IunNyhmD4@eichest-laptop>

Hi Stefan,

On Fri, Jun 21, 2024 at 04:38:25PM +0200, Stefan Eichenberger wrote:
> Hi Dmitry
> 
> On Thu, Jun 20, 2024 at 08:37:40AM -0700, Dmitry Torokhov wrote:
> > Hi Stefan,
> > 
> > On Wed, Apr 17, 2024 at 11:05:24AM +0200, Stefan Eichenberger wrote:
> > > @@ -3374,8 +3390,7 @@ static void mxt_remove(struct i2c_client *client)
> > >  	sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
> > >  	mxt_free_input_device(data);
> > >  	mxt_free_object_table(data);
> > > -	regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> > > -			       data->regulators);
> > > +	mxt_power_off(data);
> > 
> > This change means that on unbind we will leave with GPIO line asserted.
> > Won't this potentially cause some current leakage? Why do we need to
> > have reset asserted here?
> 
> This is correct, but I checked the datasheet of three different maxTouch
> models and all of them have the reset line low active. This means we had
> a current leakage before this patch.

No, the reset line would be either set or pulled high, which is the
normal state for the device.

> Now it is fixed because we assert
> the reset line, which sets the pin to 0. I also think it makes sense if
> we look at the power on sequence. There we first power on the controller
> before we release the reset line. Without asserting it on unbind this
> would never trigger a reset after a power on.

Please see that in mxt_probe() we do:

	/* Request the RESET line as asserted so we go into reset */
	data->reset_gpio = devm_gpiod_get_optional(&client->dev,
						   "reset", GPIOD_OUT_HIGH);

If the reset GPIO is annotated as "active low" (as it should unless
there are inverters on the line) this will cause the line
be driven to 0, putting the chip into the reset state. Then we enable
regulators and deassert the reset GPIO with this bit of code:

	if (data->reset_gpio) {
		/* Wait a while and then de-assert the RESET GPIO line */
		msleep(MXT_RESET_GPIO_TIME);
		gpiod_set_value(data->reset_gpio, 0);
		msleep(MXT_RESET_INVALID_CHG);
	}

So the line here will be left at "1" state (logical off). It should stay
this way until we need to go through the reset sequence again.

I can see that you need the power on sequence to be executed again after
probing is done. I recommend you make it something like this:

static int mxt_power_on()
{
	int error;

	if (data->reset_gpio)
		gpiod_set_value_cansleep(data->reset_gpio, 1);


	error = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
				      data->regulators);
	if (error) {
		dev_err(&client->dev, "failed to enable regulators: %d\n",
			error);
		return error;
	}

	/*
	 * The device takes 40ms to come up after power-on according
	 * to the mXT224 datasheet, page 13.
	 */
	msleep(MXT_BACKUP_TIME);

	if (data->reset_gpio) {
		/* Wait a while and then de-assert the RESET GPIO line */
		msleep(MXT_RESET_GPIO_TIME);
		gpiod_set_value(data->reset_gpio, 0);
		msleep(MXT_RESET_INVALID_CHG);
	}

	return 0;
}

And then mxt_power_off() should only disable regulators, and leave the
reset line alone. This way first time around the first
"piod_set_value_cansleep(data->reset_gpio, 1)" will be effectively a
noop, but on subsequent calls it will ensure that you have the
transition inactive->active->inactive for the reset line.

I wonder if we need both MXT_BACKUP_TIME and MXT_RESET_GPIO_TIME
though...

Thanks.

-- 
Dmitry

  reply	other threads:[~2024-07-09  4:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17  9:05 [PATCH v4 0/4] Add a property to turn off the max touch controller if not used Stefan Eichenberger
2024-04-17  9:05 ` [PATCH v4 1/4] Input: atmel_mxt_ts - add power off and power on functions Stefan Eichenberger
2024-06-20 15:37   ` Dmitry Torokhov
2024-06-21 14:38     ` Stefan Eichenberger
2024-07-09  4:55       ` Dmitry Torokhov [this message]
2024-04-17  9:05 ` [PATCH v4 2/4] Input: atmel_mxt_ts - move calls to register the input device to separate function Stefan Eichenberger
2024-04-17  9:05 ` [PATCH v4 3/4] dt-bindings: input: atmel,maxtouch: add poweroff-sleep property Stefan Eichenberger
2024-04-17  9:05 ` [PATCH v4 4/4] Input: atmel_mxt_ts - add support for poweroff-sleep Stefan Eichenberger
2024-06-20  1:12   ` Dmitry Torokhov
2024-06-21 14:31     ` Stefan Eichenberger
2024-04-17 11:12 ` [PATCH v4 0/4] Add a property to turn off the max touch controller if not used Joao Paulo Goncalves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZozCyQ-deK8A2uOe@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=eichest@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nick@shmanahar.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=robh@kernel.org \
    --cc=stefan.eichenberger@toradex.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).