[v3,04/11] serial: sc16is7xx: add post reset delay

Message ID 20230525040324.3773741-5-hugo@hugovil.com
State New
Headers
Series serial: sc16is7xx: fix GPIO regression and rs485 improvements |

Commit Message

Hugo Villeneuve May 25, 2023, 4:03 a.m. UTC
  From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

Make sure we wait at least 3us before initiating communication with
the device after reset.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 drivers/tty/serial/sc16is7xx.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Andy Shevchenko May 25, 2023, 10:30 a.m. UTC | #1
Thu, May 25, 2023 at 12:03:17AM -0400, Hugo Villeneuve kirjoitti:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> Make sure we wait at least 3us before initiating communication with
> the device after reset.

...

> +	usleep_range(3, 5);

I would put (5, 10) instead to relax a bit the scheduler.
  
Ilpo Järvinen May 25, 2023, 11:05 a.m. UTC | #2
On Thu, 25 May 2023, Hugo Villeneuve wrote:

> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> Make sure we wait at least 3us before initiating communication with
> the device after reset.
> 
> Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> ---
>  drivers/tty/serial/sc16is7xx.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
> index a7c4da3cfd2b..af7e66db54b4 100644
> --- a/drivers/tty/serial/sc16is7xx.c
> +++ b/drivers/tty/serial/sc16is7xx.c
> @@ -1428,6 +1428,12 @@ static int sc16is7xx_probe(struct device *dev,
>  	regmap_write(s->regmap, SC16IS7XX_IOCONTROL_REG << SC16IS7XX_REG_SHIFT,
>  			SC16IS7XX_IOCONTROL_SRESET_BIT);
>  
> +	/*
> +	 * After reset, the host must wait at least 3us before initializing a
> +	 * communication with the device.
> +	 */
> +	usleep_range(3, 5);
> +
>  	for (i = 0; i < devtype->nr_uart; ++i) {
>  		s->p[i].line		= i;
>  		/* Initialize port data */

Does this fix a problem? You don't have a Fixes tag nor did you describe
a problem that arises if the is not there in the changelog.
  
Hugo Villeneuve May 25, 2023, 1:18 p.m. UTC | #3
On Thu, 25 May 2023 13:30:06 +0300
andy.shevchenko@gmail.com wrote:

> Thu, May 25, 2023 at 12:03:17AM -0400, Hugo Villeneuve kirjoitti:
> > From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > 
> > Make sure we wait at least 3us before initiating communication with
> > the device after reset.
> 
> ...
> 
> > +	usleep_range(3, 5);
> 
> I would put (5, 10) instead to relax a bit the scheduler.

Hi,
Ok, done.
  
Hugo Villeneuve May 25, 2023, 2:05 p.m. UTC | #4
On Thu, 25 May 2023 14:05:35 +0300 (EEST)
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:

> On Thu, 25 May 2023, Hugo Villeneuve wrote:
> 
> > From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > 
> > Make sure we wait at least 3us before initiating communication with
> > the device after reset.
> > 
> > Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > ---
> >  drivers/tty/serial/sc16is7xx.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
> > index a7c4da3cfd2b..af7e66db54b4 100644
> > --- a/drivers/tty/serial/sc16is7xx.c
> > +++ b/drivers/tty/serial/sc16is7xx.c
> > @@ -1428,6 +1428,12 @@ static int sc16is7xx_probe(struct device *dev,
> >  	regmap_write(s->regmap, SC16IS7XX_IOCONTROL_REG << SC16IS7XX_REG_SHIFT,
> >  			SC16IS7XX_IOCONTROL_SRESET_BIT);
> >  
> > +	/*
> > +	 * After reset, the host must wait at least 3us before initializing a
> > +	 * communication with the device.
> > +	 */
> > +	usleep_range(3, 5);
> > +
> >  	for (i = 0; i < devtype->nr_uart; ++i) {
> >  		s->p[i].line		= i;
> >  		/* Initialize port data */
> 
> Does this fix a problem? You don't have a Fixes tag nor did you describe
> a problem that arises if the is not there in the changelog.

Not for the moment, that is why I didn't put a Fixes tag.

A potential problem that can arise is that on a much faster processor, there is a chance that we could reach the first instruction that request a read/write before the reset post-delay.

Hugo.
  

Patch

diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index a7c4da3cfd2b..af7e66db54b4 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -1428,6 +1428,12 @@  static int sc16is7xx_probe(struct device *dev,
 	regmap_write(s->regmap, SC16IS7XX_IOCONTROL_REG << SC16IS7XX_REG_SHIFT,
 			SC16IS7XX_IOCONTROL_SRESET_BIT);
 
+	/*
+	 * After reset, the host must wait at least 3us before initializing a
+	 * communication with the device.
+	 */
+	usleep_range(3, 5);
+
 	for (i = 0; i < devtype->nr_uart; ++i) {
 		s->p[i].line		= i;
 		/* Initialize port data */