215 102 251KB
English Pages 13 Year 2011
LY M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
YuSu RTC Customer Document
Version: Release date:
0.3 2011-04-12
© 2008 - 2011 MediaTek Inc. This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
FO
Specifications are subject to change without notice.
LY
MT6573 YuSu Confidential B
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
Document Revision History
Date
Author
0.1
2010-06-18
Terry Chang
Initial Draft
0.2
2010-10-30
Terry Chang
1. Add one Note in 2.2.1 and update Figure 5 2. Remove day-of-week customization
0.3
2011-04-12
Terry Chang
Update the partial content for MT6573
FO
Revision
MediaTek Confidential
Description
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 2 of 13
LY
MT6573 YuSu Confidential B
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
Table of Contents
Document Revision History .................................................................................................................. 2 Table of Contents................................................................................................................................... 3 1
Introduction................................................................................................................................... 4 1.1
1.2 1.3 1.4
2
Design............................................................................................................................................ 6 2.1 2.2
3
Data Structures................................................................................................................... 10 Functions ............................................................................................................................ 10 3.2.1 rtc_mark_recovery.............................................................................................. 10 3.2.2 rtc_mark_swreset ............................................................................................... 10 3.2.3 rtc_bbpu_power_down ....................................................................................... 11 3.2.4 rtc_gpio_enable_32k .......................................................................................... 11 3.2.5 rtc_gpio_disable_32k ......................................................................................... 11
Customization............................................................................................................................. 12 4.1
5
Architecture........................................................................................................................... 6 Procedure & Flow ................................................................................................................. 6
Interface....................................................................................................................................... 10 3.1 3.2
4
Software/Hardware Environment.......................................................................................... 4 1.1.1 Software Environment .......................................................................................... 4 1.1.2 Hardware Environment......................................................................................... 4 Functionality.......................................................................................................................... 4 Hardware Background.......................................................................................................... 4 Hardware Component Used in This Driver........................................................................... 4
Compile Options ................................................................................................................. 12
Build............................................................................................................................................. 13
FO
5.1 5.2
Source Code Structure & File Description.......................................................................... 13 Build Option ........................................................................................................................ 13
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 3 of 13
LY
MT6573 YuSu Confidential B
Introduction
1.1
Software/Hardware Environment
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
1
1.1.1
Software Environment
RTC driver discussed in this document is designed based on Linux Kernel 2.6.35 and Android 2.3.
1.1.2
Hardware Environment
RTC driver discussed in this document can run on the devices with MT6573.
1.2
Functionality
RTC driver’s main functionality: (1) Provide interfaces to read time from RTC and set time into RTC. (2) Provide interfaces to read alarm time from RTC and set alarm/power-on time into RTC. (3) Control BBPU to power down the phone. (4) Provide RTC spare bits to store some information which must be kept when the phone is powered down. (5) Provide interfaces to let other module drivers be able to control 32K export on RTC_GPIO.
1.3
Hardware Background
When the phone is powered down, RTC still keeps running since there is a small battery dedicated to RTC. Therefore, the values in RTC registers can be retained even if the phone is in power-off state. Like other HW, RTC still needs to be initialized. There are two special registers: RTC_POWERKEY1 and RTC_POWERKEY2. They are used to check whether SW has programmed and initialized RTC. After SW programs the values pre-defined by HW into POWERKEY registers, these two registers do not need to be updated and it means RTC completes initialization.
1.4
Hardware Component Used in This Driver
FO
The Real Time Clock (RTC) module provides time and date information. The clock is based on a 32.768KHz oscillator with an independent power supply. When the mobile handset is powered off, a dedicated regulator supplies the RTC block. If the main battery is not present, a backup supply such as a small mercury cell battery or a large capacitor is used. In addition to providing time and date information, an alarm can be set and the interrupt is issued when the alarm time is up. The alarm interrupt can be used to power up the baseband core via the BBWAKEUP pin. We can use this HW feature to achieve the function which can power-on the phone at the scheduled time. The year span is from 2000 to 2127, but SW can remap this year span. The maximum day-of-month values, which MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 4 of 13
LY
MT6573 YuSu Confidential B
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
depend on the leap year condition, are stored in the RTC block. Figure 1 shows the range of each HW time counter compared to Linux definition.
Figure 1: The Range of Each Time Counter
The RTC write interface is protected by RTC_PROT register. When the values in RTC_POWERKEY1 and RTC_POWERKEY2 registers are not equal to the HW pre-defined values, the RTC write interface is always enabled. However, when they match, SW has to perform an unlock flow to enable the RTC write interface. Once the normal writing is completed, do not modify the RTC_PROT content to lock RTC write interface.
FO
Unlock Flow
MediaTek Confidential
Step 1: *RTC_PROT = 0x586a; Step 2: *RTC_WRTGR = 1; Step 3: while (*RTC_BBPU & 0x40); Step 4: *RTC_PROT = 0x9136; Step 5: *RTC_WRTGR = 1; Step 6: while (*RTC_BBPU & 0x40);
/* timeout period: 120usec */ /* timeout period: 120usec */
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 5 of 13
Design
2.1
Architecture
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
2
LY
MT6573 YuSu Confidential B
The architecture of RTC driver is shown in Figure 2. There are five main tasks in RTC driver: 1. Provide callback functions to read time from RTC time counters or set time into RTC time counters. 2. Provide callback functions to read alarm time or set alarm/power-on time. 3. Control BBPU to power down the phone. 4. Provide RTC spare bits to store some information which must be kept when the phone is powered down. 5. Provide two APIs to let other module drivers be able to control 32K export on RTC_GPIO.
Figure 2: RTC Driver Architecture
Note: RTC interface and rtc_dev interface belong to Linux RTC subsystem. RTC driver will register callback functions and itself into Linux RTC subsystem so that Android Alarm driver can use RTC interface to read/set time and set alarm time.
2.2
Procedure & Flow
FO
(1) The year span defined by HW is from 2000 (leap year) to 2127. But in Linux, the base year is 1970. Since 1970 is not a leap year, we remap the base year to 1968. On the other hand, dayof-week defined by HW is from 1 to 7. We map 1 ~ 6 to Monday ~ Saturday and map 7 to Sunday so that the difference to Linux definition is only on Sunday. We have to take care of these mappings when reading and setting time. For another example, month defined by HW is from 1 to 12 but from 0 to 11 in Linux definition. Hence, we have to subtract one from the value read from RTC month counter before passing the time to Linux RTC subsystem.
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 6 of 13
LY
MT6573 YuSu Confidential B
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
Note: Currently, day-of-week will be calculated by using date and time when reading RTC time. Day-of-week time counter is no more to be used.
(2) In Android, there is an Alarm driver to control the alarm and time setting. However, the alarm implementation in Alarm driver uses Linux’ high resolution timer. The high resolution timer cannot work when the system is in suspend state, so we have to set the alarm time into RTC before the system goes to sleep. When the alarm time is up, RTC will wake up the system. The overall RTC operation path in Android is shown in Figure 3.
Figure 3: RTC Operation Path
(3) The block diagram of Schedule Power-On is shown in Figure 4. The left part is power-on time setting flow. When the power-on time is up at the power-off state, RTC will alarm the phone and Preloader will load the U-boot to boot the system. The booting flow is shown in the right part.
FO
Note: The power-on time in RTC alarm registers may be covered by the normal alarm time since there is only one set of alarm registers. To solve this issue, we use the RTC spare bits to store the power-on time and let the normal alarm time also alarm the phone, but we will compare the current time with the power-on time stored in the RTC spare bits to make sure this alarm is indeed for the phone power-on.
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 7 of 13
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
LY
MT6573 YuSu Confidential B
Figure 4: Schedule Power-On Flow
FO
(4) There are totally 48 spare bits in RTC registers. The current usage is shown in Figure 5.
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 8 of 13
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
LY
MT6573 YuSu Confidential B
Figure 5: The Usage of RTC Spare Bits
FO
Note: RTC spare bits will affect the system running state. Do not modify the current usage of RTC spare bits unless you really understand what you do.
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 9 of 13
Interface
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
3
LY
MT6573 YuSu Confidential B
This section discusses the data structures and functions used by other kernel modules.
3.1
Data Structures
None.
3.2
Functions
3.2.1
rtc_mark_recovery
Prototype
void rtc_mark_recovery(void) Parameters None
Return Value None
This function is used to mark that next booting will enter Recovery mode which performs Factory Data Reset.
3.2.2
rtc_mark_swreset
Prototype
void rtc_mark_swreset(void) Parameters
None
Return Value None
FO
The function is used to mark that SW reset and next booting will enter Normal mode.
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 10 of 13
rtc_bbpu_power_down
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
3.2.3
LY
MT6573 YuSu Confidential B
Prototype
void rtc_bbpu_power_down(void) Parameters
None
Return Value None
The function is used to power down the phone.
3.2.4
rtc_gpio_enable_32k
Prototype
void rtc_gpio_enable_32k(rtc_gpio_user_t user) Parameters
user
rtc_gpio_user_t
RTC_GPIO_USER_WIFI, RTC_GPIO_USER_GPS, RTC_GPIO_USER_BT, RTC_GPIO_USER_FM
Return Value None
The function is used to enable 32K export on RTC_GPIO.
Note: RTC_GPIO always exports 32K enabled by some user even if the phone is powered off.
3.2.5
rtc_gpio_disable_32k
Prototype
void rtc_gpio_disable_32k(rtc_gpio_user_t user) Parameters
user
rtc_gpio_user_t
RTC_GPIO_USER_WIFI, RTC_GPIO_USER_GPS, RTC_GPIO_USER_BT, RTC_GPIO_USER_FM
Return Value None
FO
The function is used to disable 32K export on RTC_GPIO.
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 11 of 13
Customization
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
4
LY
MT6573 YuSu Confidential B
This section discusses how to customize RTC driver.
4.1
Compile Options
There is rtc-mt6573.h in RTC driver to centralize compile options for customization. We can use this header file to enable/disable some functionality in RTC driver. 1. RTC_OVER_TIME_RESET The time in 32-bit Linux will overflow at 2038/01/19 03:14:07. However, RTC time counters still keep running. If the user does not reset the system time, there may be abnormal exceptions occurred, especially after rebooting the system. To avoid that, we can enable this compile option which will reset RTC time counters when Kernel reads RTC time and RTC time is over 2038/01/19 03:14:07. Therefore, if the user reboots the system, the system time will be the normal state, not overflow state. Sub-Options: /* * Reset to default date if RTC time is over 2038/1/19 3:14:7 * Year (YEA) : 1970 ~ 2037 * Month (MTH) : 1 ~ 12 * Day of Month (DOM) : 1 ~ 31 */ #define RTC_DEFAULT_YEA 2010 #define RTC_DEFAULT_MTH 1 #define RTC_DEFAULT_DOM 1
FO
Note: When initialize RTC HW, we will initialize RTC time counters by using a set of time. This set of time belongs to Preloader’s customization but the format is the same as above.
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 12 of 13
LY
MT6573 YuSu Confidential B
Build
5.1
Source Code Structure & File Description
M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N
5
File
Description
mediatek/custom/{project name}/kernel/rtc/rtc/ rtc-mt6573.h
The header file used to customize RTC driver
mediatek/platform/mt6573/kernel/core/include/mach/ mtk_rtc.h
The header file including exported APIs
mediatek/platform/mt6573/kernel/drivers/rtc/ mtk_rtc.c
5.2
The core of RTC driver
Build Option
FO
In Kernel configuration, CONFIG_MTK_RTC must be “y”.
MediaTek Confidential
© 2008 - 2011 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Page 13 of 13