diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2020-01-04 17:38:17 +0200 |
---|---|---|
committer | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2020-01-07 18:39:35 +0000 |
commit | 1a9b7b50c74b028a7be49b870aefafd221bad1cf (patch) | |
tree | 8f9eb7df9bf0b1f189f7b995ab8b48085ad97a9d /src/include/pc80 | |
parent | a0259b427345824abf6b7d80fe66415b47b1cc73 (diff) | |
download | coreboot-1a9b7b50c74b028a7be49b870aefafd221bad1cf.tar.xz |
drivers/pc80/rtc: Clean up some inlined functions
Change-Id: Ie73797b4e9a09605a0685f0b03cb85e9a3be93ad
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/38179
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Diffstat (limited to 'src/include/pc80')
-rw-r--r-- | src/include/pc80/mc146818rtc.h | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/src/include/pc80/mc146818rtc.h b/src/include/pc80/mc146818rtc.h index a8221c7259..e2f44941d3 100644 --- a/src/include/pc80/mc146818rtc.h +++ b/src/include/pc80/mc146818rtc.h @@ -114,16 +114,6 @@ 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; @@ -135,31 +125,34 @@ static inline void cmos_write_inner(unsigned char val, unsigned char addr) outb(val, RTC_BASE_PORT + offs + 1); } -static inline void cmos_write(unsigned char val, unsigned char addr) +static inline u8 cmos_disable_rtc(void) { u8 control_state = cmos_read(RTC_CONTROL); - /* There are various places where RTC bits might be hiding, - * eg. the Century / AltCentury byte. So to be safe, disable - * RTC before changing any value. - */ - if ((addr != RTC_CONTROL) && !(control_state & RTC_SET)) + if (!(control_state & RTC_SET)) cmos_write_inner(control_state | RTC_SET, RTC_CONTROL); - cmos_write_inner(val, addr); - /* reset to prior configuration */ - if ((addr != RTC_CONTROL) && !(control_state & RTC_SET)) - cmos_write_inner(control_state, RTC_CONTROL); + return control_state; } -static inline void cmos_disable_rtc(void) +static inline void cmos_restore_rtc(u8 control_state) { - u8 control_state = cmos_read(RTC_CONTROL); - cmos_write(control_state | RTC_SET, RTC_CONTROL); + if (!(control_state & RTC_SET)) + cmos_write_inner(control_state, RTC_CONTROL); } -static inline void cmos_enable_rtc(void) +static inline void cmos_write(unsigned char val, unsigned char addr) { - u8 control_state = cmos_read(RTC_CONTROL); - cmos_write(control_state & ~RTC_SET, RTC_CONTROL); + u8 control_state; + + /* + * There are various places where RTC bits might be hiding, + * eg. the Century / AltCentury byte. So to be safe, disable + * RTC before changing any value. + */ + if (addr != RTC_CONTROL) + control_state = cmos_disable_rtc(); + cmos_write_inner(val, addr); + if (addr != RTC_CONTROL) + cmos_restore_rtc(control_state); } static inline u32 cmos_read32(u8 offset) |