From 5a043fe08d84490356888d236ee7d190aa195217 Mon Sep 17 00:00:00 2001 From: Marshall Dawson Date: Sat, 5 Nov 2016 18:31:33 -0600 Subject: rtc: Check update-in-progress bit While the real-time clock updates its count, values may not be correctly read or written. On reads, ensure the UIP bit is clear which guarantees a minimum of 244 microseconds exists before the update begins. Writes already avoid the problem by disabling the RTC count via the SET bit. Change-Id: I39e34493113015d32582f1c280fafa9e97f43a40 Signed-off-by: Marshall Dawson Reviewed-on: https://review.coreboot.org/17369 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin Reviewed-by: Paul Menzel --- src/include/pc80/mc146818rtc.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/include/pc80/mc146818rtc.h') diff --git a/src/include/pc80/mc146818rtc.h b/src/include/pc80/mc146818rtc.h index effc03d2ae..66d5edb4b9 100644 --- a/src/include/pc80/mc146818rtc.h +++ b/src/include/pc80/mc146818rtc.h @@ -112,6 +112,16 @@ static inline unsigned char cmos_read(unsigned char addr) return inb(RTC_BASE_PORT + offs + 1); } +/* Upon return the caller is guaranteed 244 microseconds to complete any + * RTC operations. wait_uip may be called a single time prior to multiple + * accesses, but sequences requiring more time should call wait_uip again. + */ +static inline void wait_uip(void) +{ + while (cmos_read(RTC_REG_A) & RTC_UIP) + ; +} + static inline void cmos_write_inner(unsigned char val, unsigned char addr) { int offs = 0; -- cgit v1.2.3