All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Engraf <david.engraf@sysgo.com>
To: nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com,
	linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] i2c: at91: Read all available bytes at once
Date: Wed, 25 Apr 2018 17:43:09 +0200	[thread overview]
Message-ID: <cab9e509-a506-5852-6b0d-ed3e4751eeb6@sysgo.com> (raw)
In-Reply-To: <20180425150853.GU13305@rfolt0960.corp.atmel.com>

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
>>

WARNING: multiple messages have this Message-ID (diff)
From: david.engraf@sysgo.com (David Engraf)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] i2c: at91: Read all available bytes at once
Date: Wed, 25 Apr 2018 17:43:09 +0200	[thread overview]
Message-ID: <cab9e509-a506-5852-6b0d-ed3e4751eeb6@sysgo.com> (raw)
In-Reply-To: <20180425150853.GU13305@rfolt0960.corp.atmel.com>

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
>>

  reply	other threads:[~2018-04-25 15:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-18 12:40 [PATCH] i2c: at91: Read all available bytes at once David Engraf
2018-04-18 12:40 ` David Engraf
2018-04-25 15:08 ` Ludovic Desroches
2018-04-25 15:08   ` Ludovic Desroches
2018-04-25 15:08   ` Ludovic Desroches
2018-04-25 15:43   ` David Engraf [this message]
2018-04-25 15:43     ` David Engraf
2018-04-26  8:25     ` Ludovic Desroches
2018-04-26  8:25       ` Ludovic Desroches
2018-04-26  8:25       ` Ludovic Desroches
2018-04-26  9:53       ` [PATCH v2] " David Engraf
2018-04-26  9:53         ` David Engraf
2018-04-26 12:30         ` Ludovic Desroches
2018-04-26 12:30           ` Ludovic Desroches
2018-04-26 12:30           ` Ludovic Desroches
2018-04-28 12:38         ` Wolfram Sang
2018-04-28 12:38           ` Wolfram Sang
2018-04-30  6:11           ` David Engraf
2018-04-30  6:11             ` David Engraf
2018-04-26  5:52   ` [PATCH] " David Engraf
2018-04-26  5:52     ` David Engraf

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=cab9e509-a506-5852-6b0d-ed3e4751eeb6@sysgo.com \
    --to=david.engraf@sysgo.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@microchip.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.