summaryrefslogtreecommitdiffstats
path: root/sys/boot/arm
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2006-12-20 18:19:52 +0000
committerimp <imp@FreeBSD.org>2006-12-20 18:19:52 +0000
commit863d7fa98407e35057721cf03447382c4f2c11e9 (patch)
tree2ffab3476275255765d7a605b5d868cf1a23c3d3 /sys/boot/arm
parentd08a8bf72b1ca12bc84007b1b5c5f9dd2c18e5fe (diff)
downloadFreeBSD-src-863d7fa98407e35057721cf03447382c4f2c11e9.zip
FreeBSD-src-863d7fa98407e35057721cf03447382c4f2c11e9.tar.gz
MFp4: Add timeout to eeprom access for lame eeprom that go awol
Diffstat (limited to 'sys/boot/arm')
-rw-r--r--sys/boot/arm/at91/libat91/eeprom.c10
-rw-r--r--sys/boot/arm/at91/libat91/lib.h2
2 files changed, 8 insertions, 4 deletions
diff --git a/sys/boot/arm/at91/libat91/eeprom.c b/sys/boot/arm/at91/libat91/eeprom.c
index 5f5fafd..8af411b 100644
--- a/sys/boot/arm/at91/libat91/eeprom.c
+++ b/sys/boot/arm/at91/libat91/eeprom.c
@@ -82,11 +82,12 @@ InitEEPROM(void)
* This function does not utilize the page read mode to simplify the code.
* .KB_C_FN_DEFINITION_END
*/
-void
+int
ReadEEPROM(unsigned ee_off, char *data_addr, unsigned size)
{
const AT91PS_TWI twiPtr = AT91C_BASE_TWI;
unsigned int status;
+ unsigned int count;
status = twiPtr->TWI_SR;
status = twiPtr->TWI_RHR;
@@ -104,10 +105,12 @@ ReadEEPROM(unsigned ee_off, char *data_addr, unsigned size)
status = twiPtr->TWI_SR;
while (size-- > 1){
-
// Wait RHR Holding register is full
- while (!(twiPtr->TWI_SR & AT91C_TWI_RXRDY))
+ count = 1000000;
+ while (!(twiPtr->TWI_SR & AT91C_TWI_RXRDY) && --count > 0)
continue;
+ if (count <= 0)
+ return -1;
// Read byte
*(data_addr++) = twiPtr->TWI_RHR;
@@ -123,6 +126,7 @@ ReadEEPROM(unsigned ee_off, char *data_addr, unsigned size)
// Read last byte
*data_addr = twiPtr->TWI_RHR;
+ return 0;
}
diff --git a/sys/boot/arm/at91/libat91/lib.h b/sys/boot/arm/at91/libat91/lib.h
index d88b791..a0ef8ec 100644
--- a/sys/boot/arm/at91/libat91/lib.h
+++ b/sys/boot/arm/at91/libat91/lib.h
@@ -34,7 +34,7 @@ void printf(const char *fmt,...);
/* The following function write eeprom at ee_addr using data */
/* from data_add for size bytes. */
-void ReadEEPROM(unsigned eeoff, char *data_addr, unsigned size);
+int ReadEEPROM(unsigned eeoff, char *data_addr, unsigned size);
void WriteEEPROM(unsigned eeoff, char *data_addr, unsigned size);
void InitEEPROM(void);
OpenPOWER on IntegriCloud