linux-stable/drivers/i2c
Cyrille Pitchen 93563a6a71 i2c: at91: fix a race condition when using the DMA controller
For TX transactions, the TXCOMP bit in the Status Register is cleared
when the first data is written into the Transmit Holding Register.

In the lines from at91_do_twi_transfer():
at91_twi_write_data_dma(dev);
at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP);

the TXCOMP interrupt may be enabled before the DMA controller has
actually started to write into the THR. In such a case, the TXCOMP bit
is still set into the Status Register so the interrupt is triggered
immediately. The driver understands that a transaction completion has
occurred but this transaction hasn't started yet. Hence the TXCOMP
interrupt is no longer enabled by at91_do_twi_transfer() but instead
by at91_twi_write_data_dma_callback().

Also, the TXCOMP bit in the Status Register in not a clear on read flag
but a snapshot of the transmission state at the time the Status
Register is read.
When a NACK error is dectected by the I2C controller, the TXCOMP, NACK
and TXRDY bits are set together to 1 in the SR. If enabled, the TXCOMP
interrupt is triggered at the same time. Also setting the TXRDY to 1
triggers the DMA controller to write the next data into the THR. Such
a write resets the TXCOMP bit to 0 in the SR. So depending on when the
interrupt handler reads the SR, it may fail to detect the NACK error
if it relies on the TXCOMP bit. The NACK bit and its interrupt should
be used instead.

For RX transactions, the TXCOMP bit in the Status Register is cleared
when the START bit is set into the Control Register. However to unify
the management of the TXCOMP bit when the DMA controller is used, the
TXCOMP interrupt is now enabled by the DMA callbacks for both TX and
RX transfers.

Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
Cc: stable@vger.kernel.org #3.10 and later
Acked-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
2015-06-10 21:51:49 +09:00
..
algos i2c: algo-pca: fix typo in comment 2015-06-01 08:41:19 +09:00
busses i2c: at91: fix a race condition when using the DMA controller 2015-06-10 21:51:49 +09:00
muxes i2c: Allow compile test of GPIO consumers if !GPIOLIB 2015-05-12 15:22:52 +02:00
i2c-boardinfo.c i2c: remove FSF address 2014-11-07 18:35:33 +01:00
i2c-core.c i2c: core: Reduce stack size of acpi_i2c_space_handler() 2015-06-03 00:28:40 +09:00
i2c-core.h i2c: remove FSF address 2014-11-07 18:35:33 +01:00
i2c-dev.c i2c: remove FSF address 2014-11-07 18:35:33 +01:00
i2c-mux.c i2c: mux: use proper dev when removing "channel-X" symlinks 2015-04-23 19:35:33 +02:00
i2c-slave-eeprom.c i2c: slave-eeprom: add more info when to increase the pointer 2015-03-27 16:53:40 +01:00
i2c-smbus.c i2c: smbus: fix typo in commet 2015-06-01 08:41:26 +09:00
i2c-stub.c i2c: remove FSF address 2014-11-07 18:35:33 +01:00
Kconfig kconfig: use bool instead of boolean for type definition attributes 2015-01-07 13:08:04 +01:00
Makefile i2c: slave-eeprom: add eeprom simulator driver 2014-12-11 22:25:54 +01:00