* [PATCH] i2c: at91: Read all available bytes at once @ 2018-04-18 12:40 David Engraf 2018-04-25 15:08 ` Ludovic Desroches 0 siblings, 1 reply; 9+ messages in thread From: David Engraf @ 2018-04-18 12:40 UTC (permalink / raw) To: ludovic.desroches, nicolas.ferre, alexandre.belloni Cc: linux-i2c, linux-arm-kernel, linux-kernel, David Engraf With FIFO enabled it is possible to read multiple bytes at once in the interrupt handler as long as RXRDY is set. This may also reduce the number of interrupts. Signed-off-by: David Engraf <david.engraf@sysgo.com> --- drivers/i2c/busses/i2c-at91.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index bfd1fdff64a9..d01c2b2384bd 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c @@ -518,8 +518,12 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) * the RXRDY interrupt first in order to not keep garbage data in the * Receive Holding Register for the next transfer. */ - if (irqstatus & AT91_TWI_RXRDY) - at91_twi_read_next_byte(dev); + if (irqstatus & AT91_TWI_RXRDY) { + /* read all available bytes at once when FIFO is used */ + do { + at91_twi_read_next_byte(dev); + } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY); + } /* * When a NACK condition is detected, the I2C controller sets the NACK, -- 2.14.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] i2c: at91: Read all available bytes at once 2018-04-18 12:40 [PATCH] i2c: at91: Read all available bytes at once David Engraf @ 2018-04-25 15:08 ` Ludovic Desroches 2018-04-25 15:43 ` David Engraf 2018-04-26 5:52 ` [PATCH] " David Engraf 0 siblings, 2 replies; 9+ messages in thread From: Ludovic Desroches @ 2018-04-25 15:08 UTC (permalink / raw) To: David Engraf Cc: ludovic.desroches, nicolas.ferre, alexandre.belloni, linux-i2c, linux-arm-kernel, linux-kernel Hi David, On Wed, Apr 18, 2018 at 02:40:55PM +0200, David Engraf wrote: > With FIFO enabled it is possible to read multiple bytes > at once in the interrupt handler as long as RXRDY is > set. This may also reduce the number of interrupts. > > Signed-off-by: David Engraf <david.engraf@sysgo.com> > --- > drivers/i2c/busses/i2c-at91.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c > index bfd1fdff64a9..d01c2b2384bd 100644 > --- a/drivers/i2c/busses/i2c-at91.c > +++ b/drivers/i2c/busses/i2c-at91.c > @@ -518,8 +518,12 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) > * the RXRDY interrupt first in order to not keep garbage data in the > * Receive Holding Register for the next transfer. > */ > - if (irqstatus & AT91_TWI_RXRDY) > - at91_twi_read_next_byte(dev); > + if (irqstatus & AT91_TWI_RXRDY) { > + /* read all available bytes at once when FIFO is used */ > + do { > + at91_twi_read_next_byte(dev); > + } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY); You can avoid this check by using the RXFL field to know the number of data you can read. Did you try to use it? If yes, did you notice some issues? Regards Ludovic > + } > > /* > * When a NACK condition is detected, the I2C controller sets the NACK, > -- > 2.14.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] i2c: at91: Read all available bytes at once 2018-04-25 15:08 ` Ludovic Desroches @ 2018-04-25 15:43 ` David Engraf 2018-04-26 8:25 ` Ludovic Desroches 2018-04-26 5:52 ` [PATCH] " David Engraf 1 sibling, 1 reply; 9+ messages in thread From: David Engraf @ 2018-04-25 15:43 UTC (permalink / raw) To: nicolas.ferre, alexandre.belloni, linux-i2c, linux-arm-kernel, linux-kernel Hi Ludovic, Am 25.04.2018 um 17:08 schrieb Ludovic Desroches: > Hi David, > > On Wed, Apr 18, 2018 at 02:40:55PM +0200, David Engraf wrote: >> With FIFO enabled it is possible to read multiple bytes >> at once in the interrupt handler as long as RXRDY is >> set. This may also reduce the number of interrupts. >> >> Signed-off-by: David Engraf <david.engraf@sysgo.com> >> --- >> drivers/i2c/busses/i2c-at91.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c >> index bfd1fdff64a9..d01c2b2384bd 100644 >> --- a/drivers/i2c/busses/i2c-at91.c >> +++ b/drivers/i2c/busses/i2c-at91.c >> @@ -518,8 +518,12 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) >> * the RXRDY interrupt first in order to not keep garbage data in the >> * Receive Holding Register for the next transfer. >> */ >> - if (irqstatus & AT91_TWI_RXRDY) >> - at91_twi_read_next_byte(dev); >> + if (irqstatus & AT91_TWI_RXRDY) { >> + /* read all available bytes at once when FIFO is used */ >> + do { >> + at91_twi_read_next_byte(dev); >> + } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY); > > You can avoid this check by using the RXFL field to know the number of > data you can read. Did you try to use it? If yes, did you notice some issues? I did a quick test by reading RXFL and it worked as well but I decided to use the more readable solution by polling RXRDY. Also I don't need to check if the FIFO has been enabled. If you prefer using RXFL I can create a new patch. Best regards - David > Regards > > Ludovic > >> + } >> >> /* >> * When a NACK condition is detected, the I2C controller sets the NACK, >> -- >> 2.14.1 >> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] i2c: at91: Read all available bytes at once 2018-04-25 15:43 ` David Engraf @ 2018-04-26 8:25 ` Ludovic Desroches 2018-04-26 9:53 ` [PATCH v2] " David Engraf 0 siblings, 1 reply; 9+ messages in thread From: Ludovic Desroches @ 2018-04-26 8:25 UTC (permalink / raw) To: David Engraf Cc: nicolas.ferre, alexandre.belloni, linux-i2c, linux-arm-kernel, linux-kernel Hi David, On Wed, Apr 25, 2018 at 05:43:09PM +0200, David Engraf wrote: > Hi Ludovic, > > Am 25.04.2018 um 17:08 schrieb Ludovic Desroches: > > Hi David, > > > > On Wed, Apr 18, 2018 at 02:40:55PM +0200, David Engraf wrote: > > > With FIFO enabled it is possible to read multiple bytes > > > at once in the interrupt handler as long as RXRDY is > > > set. This may also reduce the number of interrupts. > > > > > > Signed-off-by: David Engraf <david.engraf@sysgo.com> > > > --- > > > drivers/i2c/busses/i2c-at91.c | 8 ++++++-- > > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c > > > index bfd1fdff64a9..d01c2b2384bd 100644 > > > --- a/drivers/i2c/busses/i2c-at91.c > > > +++ b/drivers/i2c/busses/i2c-at91.c > > > @@ -518,8 +518,12 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) > > > * the RXRDY interrupt first in order to not keep garbage data in the > > > * Receive Holding Register for the next transfer. > > > */ > > > - if (irqstatus & AT91_TWI_RXRDY) > > > - at91_twi_read_next_byte(dev); > > > + if (irqstatus & AT91_TWI_RXRDY) { > > > + /* read all available bytes at once when FIFO is used */ > > > + do { > > > + at91_twi_read_next_byte(dev); > > > + } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY); > > > > You can avoid this check by using the RXFL field to know the number of > > data you can read. Did you try to use it? If yes, did you notice some issues? > > I did a quick test by reading RXFL and it worked as well but I decided to > use the more readable solution by polling RXRDY. Also I don't need to check > if the FIFO has been enabled. > > If you prefer using RXFL I can create a new patch. Honestly, I have no strong opinion about it. As you said you approach is simple and easy to read. About performances, I assume that both solutions are pretty the same for small number of data. If the number increases, using the RXFL field should give better results. So I would say, maybe add a note in the commit log or in the code to keep in mind there is this solution to go further. Otherwise Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com> Regards Ludovic > > Best regards > - David > > > > Regards > > > > Ludovic > > > > > + } > > > /* > > > * When a NACK condition is detected, the I2C controller sets the NACK, > > > -- > > > 2.14.1 > > > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] i2c: at91: Read all available bytes at once 2018-04-26 8:25 ` Ludovic Desroches @ 2018-04-26 9:53 ` David Engraf 2018-04-26 12:30 ` Ludovic Desroches 2018-04-28 12:38 ` Wolfram Sang 0 siblings, 2 replies; 9+ messages in thread From: David Engraf @ 2018-04-26 9:53 UTC (permalink / raw) To: ludovic.desroches Cc: nicolas.ferre, alexandre.belloni, linux-i2c, linux-arm-kernel, linux-kernel, David Engraf With FIFO enabled it is possible to read multiple bytes at once in the interrupt handler as long as RXRDY is set. This may also reduce the number of interrupts. This patch polls RXRDY and reads all available bytes at once. Signed-off-by: David Engraf <david.engraf@sysgo.com> --- drivers/i2c/busses/i2c-at91.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index bfd1fdff64a9..9caee5b79eac 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c @@ -518,8 +518,16 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) * the RXRDY interrupt first in order to not keep garbage data in the * Receive Holding Register for the next transfer. */ - if (irqstatus & AT91_TWI_RXRDY) - at91_twi_read_next_byte(dev); + if (irqstatus & AT91_TWI_RXRDY) { + /* + * Read all available bytes at once by polling RXRDY usable w/ and w/o + * FIFO. With FIFO enabled we could also read RXFL and avoid polling + * RXRDY. + */ + do { + at91_twi_read_next_byte(dev); + } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY); + } /* * When a NACK condition is detected, the I2C controller sets the NACK, -- 2.14.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] i2c: at91: Read all available bytes at once 2018-04-26 9:53 ` [PATCH v2] " David Engraf @ 2018-04-26 12:30 ` Ludovic Desroches 2018-04-28 12:38 ` Wolfram Sang 1 sibling, 0 replies; 9+ messages in thread From: Ludovic Desroches @ 2018-04-26 12:30 UTC (permalink / raw) To: David Engraf Cc: ludovic.desroches, nicolas.ferre, alexandre.belloni, linux-i2c, linux-arm-kernel, linux-kernel On Thu, Apr 26, 2018 at 11:53:14AM +0200, David Engraf wrote: > With FIFO enabled it is possible to read multiple bytes > at once in the interrupt handler as long as RXRDY is > set. This may also reduce the number of interrupts. > > This patch polls RXRDY and reads all available bytes at > once. > > Signed-off-by: David Engraf <david.engraf@sysgo.com> Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com> Thanks a lot David. Regards Ludovic > --- > drivers/i2c/busses/i2c-at91.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c > index bfd1fdff64a9..9caee5b79eac 100644 > --- a/drivers/i2c/busses/i2c-at91.c > +++ b/drivers/i2c/busses/i2c-at91.c > @@ -518,8 +518,16 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) > * the RXRDY interrupt first in order to not keep garbage data in the > * Receive Holding Register for the next transfer. > */ > - if (irqstatus & AT91_TWI_RXRDY) > - at91_twi_read_next_byte(dev); > + if (irqstatus & AT91_TWI_RXRDY) { > + /* > + * Read all available bytes at once by polling RXRDY usable w/ and w/o > + * FIFO. With FIFO enabled we could also read RXFL and avoid polling > + * RXRDY. > + */ > + do { > + at91_twi_read_next_byte(dev); > + } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY); > + } > > /* > * When a NACK condition is detected, the I2C controller sets the NACK, > -- > 2.14.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] i2c: at91: Read all available bytes at once 2018-04-26 9:53 ` [PATCH v2] " David Engraf 2018-04-26 12:30 ` Ludovic Desroches @ 2018-04-28 12:38 ` Wolfram Sang 2018-04-30 6:11 ` David Engraf 1 sibling, 1 reply; 9+ messages in thread From: Wolfram Sang @ 2018-04-28 12:38 UTC (permalink / raw) To: David Engraf Cc: ludovic.desroches, nicolas.ferre, alexandre.belloni, linux-i2c, linux-arm-kernel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 625 bytes --] On Thu, Apr 26, 2018 at 11:53:14AM +0200, David Engraf wrote: > With FIFO enabled it is possible to read multiple bytes > at once in the interrupt handler as long as RXRDY is > set. This may also reduce the number of interrupts. > > This patch polls RXRDY and reads all available bytes at > once. > > Signed-off-by: David Engraf <david.engraf@sysgo.com> checkpatch said twice: WARNING: line over 80 characters While I am not super-strict with this limit, it makes sense here IMO. The comment stays readable, and we don't even lose a line. Fixed it this time for you. Applied to for-next, thanks! [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] i2c: at91: Read all available bytes at once 2018-04-28 12:38 ` Wolfram Sang @ 2018-04-30 6:11 ` David Engraf 0 siblings, 0 replies; 9+ messages in thread From: David Engraf @ 2018-04-30 6:11 UTC (permalink / raw) To: Wolfram Sang Cc: ludovic.desroches, nicolas.ferre, alexandre.belloni, linux-i2c, linux-arm-kernel, linux-kernel Am 28.04.2018 um 14:38 schrieb Wolfram Sang: > On Thu, Apr 26, 2018 at 11:53:14AM +0200, David Engraf wrote: >> With FIFO enabled it is possible to read multiple bytes >> at once in the interrupt handler as long as RXRDY is >> set. This may also reduce the number of interrupts. >> >> This patch polls RXRDY and reads all available bytes at >> once. >> >> Signed-off-by: David Engraf <david.engraf@sysgo.com> > > checkpatch said twice: > > WARNING: line over 80 characters > > While I am not super-strict with this limit, it makes sense here IMO. > The comment stays readable, and we don't even lose a line. Sorry for that. > Fixed it this time for you. Thanks - David > Applied to for-next, thanks! > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] i2c: at91: Read all available bytes at once 2018-04-25 15:08 ` Ludovic Desroches 2018-04-25 15:43 ` David Engraf @ 2018-04-26 5:52 ` David Engraf 1 sibling, 0 replies; 9+ messages in thread From: David Engraf @ 2018-04-26 5:52 UTC (permalink / raw) To: Ludovic Desroches Cc: nicolas.ferre, alexandre.belloni, linux-i2c, linux-arm-kernel, linux-kernel Hi Ludovic, Am 25.04.2018 um 17:08 schrieb Ludovic Desroches: > Hi David, > > On Wed, Apr 18, 2018 at 02:40:55PM +0200, David Engraf wrote: >> With FIFO enabled it is possible to read multiple bytes >> at once in the interrupt handler as long as RXRDY is >> set. This may also reduce the number of interrupts. >> >> Signed-off-by: David Engraf <david.engraf@sysgo.com> >> --- >> drivers/i2c/busses/i2c-at91.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c >> index bfd1fdff64a9..d01c2b2384bd 100644 >> --- a/drivers/i2c/busses/i2c-at91.c >> +++ b/drivers/i2c/busses/i2c-at91.c >> @@ -518,8 +518,12 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) >> * the RXRDY interrupt first in order to not keep garbage data in the >> * Receive Holding Register for the next transfer. >> */ >> - if (irqstatus & AT91_TWI_RXRDY) >> - at91_twi_read_next_byte(dev); >> + if (irqstatus & AT91_TWI_RXRDY) { >> + /* read all available bytes at once when FIFO is used */ >> + do { >> + at91_twi_read_next_byte(dev); >> + } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY); > > You can avoid this check by using the RXFL field to know the number of > data you can read. Did you try to use it? If yes, did you notice some issues? I did a quick test by reading RXFL and it worked as well but I decided to use the more readable solution by polling RXRDY. Also I don't need to check if the FIFO has been enabled. If you prefer using RXFL I can create a new patch. Best regards - David > Regards > > Ludovic > >> + } >> >> /* >> * When a NACK condition is detected, the I2C controller sets the NACK, >> -- >> 2.14.1 >> -- Mit freundlichen Grüßen/Best regards, David Engraf Product Engineer SYSGO AG Office Mainz Am Pfaffenstein 14 / D-55270 Klein-Winternheim / Germany Phone: +49-6136-9948-0 / Fax: +49-6136-9948-10 E-mail: david.engraf@sysgo.com _________________________________________________________________________________ Web: https://www.sysgo.com Blog: https://www.sysgo.com/blog Events: https://www.sysgo.com/events Newsletter: https://www.sysgo.com/newsletter _________________________________________________________________________________ Handelsregister/Commercial Registry: HRB Mainz 90 HRB 8066 Vorstand/Executive Board: Etienne Butery (CEO), Kai Sablotny (COO) Aufsichtsratsvorsitzender/Supervisory Board Chairman: Marc Darmon USt-Id-Nr./VAT-Id-No.: DE 149062328 ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-04-30 6:11 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-04-18 12:40 [PATCH] i2c: at91: Read all available bytes at once David Engraf 2018-04-25 15:08 ` Ludovic Desroches 2018-04-25 15:43 ` David Engraf 2018-04-26 8:25 ` Ludovic Desroches 2018-04-26 9:53 ` [PATCH v2] " David Engraf 2018-04-26 12:30 ` Ludovic Desroches 2018-04-28 12:38 ` Wolfram Sang 2018-04-30 6:11 ` David Engraf 2018-04-26 5:52 ` [PATCH] " David Engraf
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).