diff mbox series

[1/2] spi: Add call to spi_slave_abort() function when spidev driver is released

Message ID 20190924110547.14770-2-lukma@denx.de (mailing list archive)
State Superseded
Commit bf390d25e03b38248a0a4f7d0002bbb495a82fe9
Headers show
Series spi: Fix problem with interrupted slave transmission | expand

Commit Message

Lukasz Majewski Sept. 24, 2019, 11:05 a.m. UTC
This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
in the slave mode (like NXP's dspi driver for Vybrid SoC).

When SPI HW works in this mode - the master is responsible for providing
CS and CLK signals. However, when some fault happens - like for example
distortion on SPI lines - the SPI Linux driver needs a chance to recover
from this abnormal situation and prepare itself for next (correct)
transmission.

This change doesn't pose any threat on drivers working in master mode as
spi_slave_abort() function checks if SPI slave mode is supported.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
---
 drivers/spi/spidev.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Geert Uytterhoeven Sept. 26, 2019, 6:52 a.m. UTC | #1
Hi Lukasz,

On Thu, Sep 26, 2019 at 3:33 AM Lukasz Majewski <lukma@denx.de> wrote:
> This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
> in the slave mode (like NXP's dspi driver for Vybrid SoC).
>
> When SPI HW works in this mode - the master is responsible for providing
> CS and CLK signals. However, when some fault happens - like for example
> distortion on SPI lines - the SPI Linux driver needs a chance to recover
> from this abnormal situation and prepare itself for next (correct)
> transmission.
>
> This change doesn't pose any threat on drivers working in master mode as
> spi_slave_abort() function checks if SPI slave mode is supported.
>
> Signed-off-by: Lukasz Majewski <lukma@denx.de>

Thanks for your patch!

Yesterday I saw this appear on spi/for-next, but I couldn't find the
email in my mbox.  Today it has arrived. Looks like gmail had some troubles
("Delivered after 138401 seconds", ugh).

> --- a/drivers/spi/spidev.c
> +++ b/drivers/spi/spidev.c
> @@ -627,6 +627,7 @@ static int spidev_release(struct inode *inode, struct file *filp)
>                 if (dofree)
>                         kfree(spidev);
>         }
> +       spi_slave_abort(spidev->spi);

Looks good to me.  Just wondering if this should be done for the last user only,
i.e. in the "if" block above, like resetting speed_hz?

>         mutex_unlock(&device_list_lock);
>
>         return 0;

Gr{oetje,eeting}s,

                        Geert
Lukasz Majewski Sept. 26, 2019, 7:59 a.m. UTC | #2
Hi Geert,

> Hi Lukasz,
> 
> On Thu, Sep 26, 2019 at 3:33 AM Lukasz Majewski <lukma@denx.de> wrote:
> > This change is necessary for spidev devices (e.g. /dev/spidev3.0)
> > working in the slave mode (like NXP's dspi driver for Vybrid SoC).
> >
> > When SPI HW works in this mode - the master is responsible for
> > providing CS and CLK signals. However, when some fault happens -
> > like for example distortion on SPI lines - the SPI Linux driver
> > needs a chance to recover from this abnormal situation and prepare
> > itself for next (correct) transmission.
> >
> > This change doesn't pose any threat on drivers working in master
> > mode as spi_slave_abort() function checks if SPI slave mode is
> > supported.
> >
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>  
> 
> Thanks for your patch!
> 
> Yesterday I saw this appear on spi/for-next, but I couldn't find the
> email in my mbox.  Today it has arrived. Looks like gmail had some
> troubles ("Delivered after 138401 seconds", ugh).

I've already sent v2 of this patch, as Intel Linux test setup spot the
error with lack of #define guards.

> 
> > --- a/drivers/spi/spidev.c
> > +++ b/drivers/spi/spidev.c
> > @@ -627,6 +627,7 @@ static int spidev_release(struct inode *inode,
> > struct file *filp) if (dofree)
> >                         kfree(spidev);
> >         }
> > +       spi_slave_abort(spidev->spi);  
> 
> Looks good to me.  Just wondering if this should be done for the last
> user only, i.e. in the "if" block above, like resetting speed_hz?

I also thought about this. However, from my use case the user must end
the transmission with CTRL+C on his user space program, which in turn
communicate via SPI with /dev/spidev3.0.

There might be many (potential) programs using the /dev/spidev3.0 at the
same time, so the usage count may be not one.

For the above reason I've moved it outside the above if().

> 
> >         mutex_unlock(&device_list_lock);
> >
> >         return 0;  
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
diff mbox series

Patch

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 255786f2e844..fe9ea7e55e5b 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -627,6 +627,7 @@  static int spidev_release(struct inode *inode, struct file *filp)
 		if (dofree)
 			kfree(spidev);
 	}
+	spi_slave_abort(spidev->spi);
 	mutex_unlock(&device_list_lock);
 
 	return 0;