Tuesday, April 10, 2012

Introduction to Real Time Clock (RTC) - Case Study: Why RTC Fails to Wake-up System from S4 in DC?

It is common to see RTC fails to wake-up on laptop systems. This blog discusses some information on RTC mechanism and probable fix for the problem that RTC fails to wake-up.

What is a "Real Time Clock" (RTC)?

A Real Time Clock (RTC) is a computer clock (in the form of integrated circuit) that keeps track
of the current time. RTC has an alternative power source (i.e. a coin-cell battery) so RTC continues to keep time when main power is removed.

Wikipedia also has very nice and clear explanations @ http://en.wikipedia.org/wiki/Real-time_clock

RTC has a very useful function called RTC Alarm. It is used to wake-up the computer from sleeping states automatically - useful when scheduled tasks are required, i.e. wake-up for recording TV-series.

However, RTC alarm needs supports from both hardware and software. Fortunately, PC has standardized hardware interface to perform (CMOS and ACPI). Most, if not all, of computers support RTC today.

I/O Ports to Access RTC 

On PC, I/O ports are used to access RTC registers. Standard I/O ports are 70h/71 pairs as below:

To access a RTC register, a program needs to output a offset of a register to Port 70h and read/write the data from Port 71. The below examples demonstrate how to read and write RTC registers.

Read from a RTC Register

Write to a RTC register

RTC Registers

RTC registers are listed here. Note offset 00h to 0Dh are used for keeping the system time and for wake-up at particular time. 

Register A to Register D are used to configure many important RTC functions including (not limited to):
1. Alarm Interrupt Enable (more below).
2. Data Mode (BCD or Binary)
3. Hour Format (12-hour or 24-hour)
and so on.

How to configure RTC wake-up

A number of RTC and ACPI register is associated to RTC wake-up.

 * RTC Registers - I/O ports 70/71 (or other mirror ports)
  * Seconds (00h), Minutes (02h), and Hours (04h)
  * Second Alarms (01h), Minutes Alarm (03h) and Hours (05h)
  * RTC_REGB[5] (Alarm Interrupt Enable - AIE)

When AIE is set and Seconds, Minutes and Hours registers matches to the corresponding Alarm registers, RTC will fire an interrupt and set RTC_STS in ACPI Registers.

 * ACPI PM registers
  * PM1_STS[10] (RTC_STS) - this is set when RTC generates an alarm
  * PM1_EN[10] (RTC_EN) - the setting of the RTC_STS bit to generate a wake event

Case Study - Why RTC fails to wake from S4 in DC mode.

Cause: EC powers off chipset to save power - this prevents RTC wakeup. The fix is therefore to prevent EC from cutting the power off; however, it is done to meet the energy requirement (usually the "Energy Star").

Solution: To fix the problem, BIOS can implement an easy fix to check RTC AIE registers and to notify EC not to remove power. The best place to add the fix is in BIOS Sleep SMI which OS hands completely control to BIOS.

No comments:

Post a Comment