mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 17:11:42 +00:00
stm32f0/i2c: Return error if we see a NACK
i2cdetect -q was broken on the AP. The way it works is by sending a 0 length
write request and checking for NACK. The stm32f0 driver had to be fixed to
actually return non-success if there was a NACK. i2cdetect -r worked so far
because it relied on a 1-length read and we indirectly detected NACKs by the
lack of data.
The error catching also had to be moved(in both drivers) before the success
returns, because it is possible to transmit something successfully(buffer got
emptied) without getting an ACK. We want this to be an error.
BUG=None
BRANCH=None
TEST=veyron: i2cdetect -y -r 20 0x09 0x0b should display -- on the 0x0a spot
since there's no device there. i2cdetect -y -{r,q} 20 should display the same
thing.
Change-Id: Id6cadb798e4d972dea089f15742e5b30888a038b
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220185
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
458d39c1a8
commit
c83db9a119
@@ -50,14 +50,15 @@ static int wait_isr(int port, int mask)
|
||||
while (get_time().val < timeout) {
|
||||
int isr = STM32_I2C_ISR(port);
|
||||
|
||||
/* Check for errors */
|
||||
if (isr & (STM32_I2C_ISR_ARLO | STM32_I2C_ISR_BERR |
|
||||
STM32_I2C_ISR_NACK))
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
/* Check for desired mask */
|
||||
if ((isr & mask) == mask)
|
||||
return EC_SUCCESS;
|
||||
|
||||
/* Check for errors */
|
||||
if (isr & (STM32_I2C_ISR_ARLO | STM32_I2C_ISR_BERR))
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
/* I2C is slow, so let other things run while we wait */
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
@@ -73,10 +73,6 @@ static int wait_sr1(int port, int mask)
|
||||
while (get_time().val < timeout) {
|
||||
int sr1 = STM32_I2C_SR1(port);
|
||||
|
||||
/* Check for desired mask */
|
||||
if ((sr1 & mask) == mask)
|
||||
return EC_SUCCESS;
|
||||
|
||||
/* Check for errors */
|
||||
if (sr1 & (STM32_I2C_SR1_ARLO | STM32_I2C_SR1_BERR |
|
||||
STM32_I2C_SR1_AF)) {
|
||||
@@ -84,6 +80,10 @@ static int wait_sr1(int port, int mask)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
/* Check for desired mask */
|
||||
if ((sr1 & mask) == mask)
|
||||
return EC_SUCCESS;
|
||||
|
||||
/* I2C is slow, so let other things run while we wait */
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user