devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy@kernel.org>
To: Hui Wang <hui.wang@canonical.com>
Cc: linux-serial@vger.kernel.org, devicetree@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org,
	hvilleneuve@dimonoff.com, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, lech.perczak@camlingroup.com
Subject: Re: [PATCH v2 2/2] serial: sc16is7xx: hard reset the chip if reset-gpios is defined in dt
Date: Tue, 4 Jun 2024 16:42:33 +0300	[thread overview]
Message-ID: <Zl8ZyZ6ftvNTusFi@smile.fi.intel.com> (raw)
In-Reply-To: <20240604132726.1272475-2-hui.wang@canonical.com>

On Tue, Jun 04, 2024 at 09:27:26PM +0800, Hui Wang wrote:
> Certain designs connect a gpio to the reset pin, and the reset pin

GPIO

> needs to be setup correctly before accessing the chip.
> 
> Here adding a function to handle the chip reset. If the reset-gpios is
> defined in the dt, do the hard reset through this gpio, othwerwise do

DT

> the soft reset as before.

...

> +static int sc16is7xx_reset(struct device *dev, struct regmap *regmaps[])
> +{
> +	struct gpio_desc *reset_gpiod;

> +	reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> +	if (!reset_gpiod)
> +		/* soft reset device, purging any pending irq / data */
> +		regmap_write(regmaps[0], SC16IS7XX_IOCONTROL_REG,
> +			     SC16IS7XX_IOCONTROL_SRESET_BIT);
> +	else if (!IS_ERR(reset_gpiod)) {
> +		/* delay 5 us (at least 3 us) and deassert the gpio to exit the hard reset */
> +		udelay(5);
> +		gpiod_set_value_cansleep(reset_gpiod, 0);
> +	} else
> +		return PTR_ERR(reset_gpiod);

You can do better here.

	reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(reset_gpiod))
		return PTR_ERR(reset_gpiod);

	if (reset_gpiod) {
		/* delay 5 us (at least 3 us) and deassert the GPIO to exit the hard reset */
		fsleep(5);
		gpiod_set_value_cansleep(reset_gpiod, 0);
	} else {
		/* soft reset device, purging any pending IRQ / data */
		regmap_write(regmaps[0], SC16IS7XX_IOCONTROL_REG,
			     SC16IS7XX_IOCONTROL_SRESET_BIT);
	}

> +	return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2024-06-04 13:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04 13:27 [PATCH v2 1/2] dt-bindings: serial: sc16is7xx: add reset-gpios Hui Wang
2024-06-04 13:27 ` [PATCH v2 2/2] serial: sc16is7xx: hard reset the chip if reset-gpios is defined in dt Hui Wang
2024-06-04 13:30   ` Krzysztof Kozlowski
2024-06-04 13:42   ` Andy Shevchenko [this message]
2024-06-05  6:36     ` Hui Wang
2024-06-04 14:23   ` Hugo Villeneuve
2024-06-05  6:39     ` Hui Wang
2024-06-05 10:30     ` Maarten Brock
2024-06-05 10:55       ` Hui Wang
2024-06-05 11:19         ` Maarten Brock
2024-06-05 11:21           ` Andy Shevchenko
2024-06-05 11:24           ` Krzysztof Kozlowski
2024-06-05 13:01             ` Hui Wang
2024-06-05 11:19         ` Andy Shevchenko
     [not found]           ` <1d5c49ea-c021-42cf-b878-83c625e17caa@canonical.com>
2024-06-05 15:32             ` Hugo Villeneuve
2024-06-06  2:04               ` Hui Wang
2024-06-04 14:34   ` Hugo Villeneuve
2024-06-05  6:42     ` Hui Wang
2024-06-04 13:29 ` [PATCH v2 1/2] dt-bindings: serial: sc16is7xx: add reset-gpios Krzysztof Kozlowski
2024-06-05  6:07   ` Hui Wang
2024-06-04 13:37 ` Andy Shevchenko
2024-06-05  6:33   ` Hui Wang
2024-06-04 14:35 ` Hugo Villeneuve
2024-06-05  6:34   ` Hui Wang

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=Zl8ZyZ6ftvNTusFi@smile.fi.intel.com \
    --to=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hui.wang@canonical.com \
    --cc=hvilleneuve@dimonoff.com \
    --cc=jirislaby@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lech.perczak@camlingroup.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=robh@kernel.org \
    /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).