rtc_mt6359p.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (c) 2020-2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef RTC_MT6359P_H
  7. #define RTC_MT6359P_H
  8. /* RTC registers */
  9. enum {
  10. RTC_BBPU = 0x0588,
  11. RTC_IRQ_STA = 0x058A,
  12. RTC_IRQ_EN = 0x058C,
  13. RTC_CII_EN = 0x058E
  14. };
  15. enum {
  16. RTC_AL_SEC = 0x05A0,
  17. RTC_AL_MIN = 0x05A2,
  18. RTC_AL_HOU = 0x05A4,
  19. RTC_AL_DOM = 0x05A6,
  20. RTC_AL_DOW = 0x05A8,
  21. RTC_AL_MTH = 0x05AA,
  22. RTC_AL_YEA = 0x05AC,
  23. RTC_AL_MASK = 0x0590
  24. };
  25. enum {
  26. RTC_OSC32CON = 0x05AE,
  27. RTC_CON = 0x05C4,
  28. RTC_WRTGR = 0x05C2
  29. };
  30. enum {
  31. RTC_POWERKEY1 = 0x05B0,
  32. RTC_POWERKEY2 = 0x05B2
  33. };
  34. enum {
  35. RTC_POWERKEY1_KEY = 0xA357,
  36. RTC_POWERKEY2_KEY = 0x67D2
  37. };
  38. enum {
  39. RTC_PDN1 = 0x05B4,
  40. RTC_PDN2 = 0x05B6,
  41. RTC_SPAR0 = 0x05B8,
  42. RTC_SPAR1 = 0x05BA,
  43. RTC_PROT = 0x05BC,
  44. RTC_DIFF = 0x05BE,
  45. RTC_CALI = 0x05C0
  46. };
  47. enum {
  48. RTC_OSC32CON_UNLOCK1 = 0x1A57,
  49. RTC_OSC32CON_UNLOCK2 = 0x2B68
  50. };
  51. enum {
  52. RTC_LPD_EN = 0x0406,
  53. RTC_LPD_RST = 0x040E
  54. };
  55. enum {
  56. RTC_LPD_OPT_XOSC_AND_EOSC_LPD = 0U << 13,
  57. RTC_LPD_OPT_EOSC_LPD = 1U << 13,
  58. RTC_LPD_OPT_XOSC_LPD = 2U << 13,
  59. RTC_LPD_OPT_F32K_CK_ALIVE = 3U << 13,
  60. };
  61. #define RTC_LPD_OPT_MASK (3U << 13)
  62. enum {
  63. RTC_PROT_UNLOCK1 = 0x586A,
  64. RTC_PROT_UNLOCK2 = 0x9136
  65. };
  66. enum {
  67. RTC_BBPU_PWREN = 1U << 0,
  68. RTC_BBPU_SPAR_SW = 1U << 1,
  69. RTC_BBPU_RESET_SPAR = 1U << 2,
  70. RTC_BBPU_RESET_ALARM = 1U << 3,
  71. RTC_BBPU_CLRPKY = 1U << 4,
  72. RTC_BBPU_RELOAD = 1U << 5,
  73. RTC_BBPU_CBUSY = 1U << 6
  74. };
  75. enum {
  76. RTC_AL_MASK_SEC = 1U << 0,
  77. RTC_AL_MASK_MIN = 1U << 1,
  78. RTC_AL_MASK_HOU = 1U << 2,
  79. RTC_AL_MASK_DOM = 1U << 3,
  80. RTC_AL_MASK_DOW = 1U << 4,
  81. RTC_AL_MASK_MTH = 1U << 5,
  82. RTC_AL_MASK_YEA = 1U << 6
  83. };
  84. enum {
  85. RTC_BBPU_AUTO_PDN_SEL = 1U << 6,
  86. RTC_BBPU_2SEC_CK_SEL = 1U << 7,
  87. RTC_BBPU_2SEC_EN = 1U << 8,
  88. RTC_BBPU_2SEC_MODE = 0x3 << 9,
  89. RTC_BBPU_2SEC_STAT_CLEAR = 1U << 11,
  90. RTC_BBPU_2SEC_STAT_STA = 1U << 12
  91. };
  92. enum {
  93. RTC_BBPU_KEY = 0x43 << 8
  94. };
  95. enum {
  96. RTC_EMBCK_SRC_SEL = 1 << 8,
  97. RTC_EMBCK_SEL_MODE = 3 << 6,
  98. RTC_XOSC32_ENB = 1 << 5,
  99. RTC_REG_XOSC32_ENB = 1 << 15
  100. };
  101. enum {
  102. RTC_K_EOSC_RSV_0 = 1 << 8,
  103. RTC_K_EOSC_RSV_1 = 1 << 9,
  104. RTC_K_EOSC_RSV_2 = 1 << 10
  105. };
  106. enum {
  107. RTC_RG_EOSC_CALI_TD_1SEC = 3 << 5,
  108. RTC_RG_EOSC_CALI_TD_2SEC = 4 << 5,
  109. RTC_RG_EOSC_CALI_TD_4SEC = 5 << 5,
  110. RTC_RG_EOSC_CALI_TD_8SEC = 6 << 5,
  111. RTC_RG_EOSC_CALI_TD_16SEC = 7 << 5,
  112. RTC_RG_EOSC_CALI_TD_MASK = 7 << 5
  113. };
  114. /* PMIC TOP Register Definition */
  115. enum {
  116. PMIC_RG_TOP_CON = 0x0020,
  117. PMIC_RG_TOP_CKPDN_CON1 = 0x0112,
  118. PMIC_RG_TOP_CKPDN_CON1_SET = 0x0114,
  119. PMIC_RG_TOP_CKPDN_CON1_CLR = 0x0116,
  120. PMIC_RG_TOP_CKSEL_CON0 = 0x0118,
  121. PMIC_RG_TOP_CKSEL_CON0_SET = 0x011A,
  122. PMIC_RG_TOP_CKSEL_CON0_CLR = 0x011C
  123. };
  124. /* PMIC SCK Register Definition */
  125. enum {
  126. PMIC_RG_SCK_TOP_CKPDN_CON0 = 0x0514,
  127. PMIC_RG_SCK_TOP_CKPDN_CON0_SET = 0x0516,
  128. PMIC_RG_SCK_TOP_CKPDN_CON0_CLR = 0x0518,
  129. PMIC_RG_EOSC_CALI_CON0 = 0x53A
  130. };
  131. enum {
  132. PMIC_EOSC_CALI_START_ADDR = 0x53A
  133. };
  134. enum {
  135. PMIC_EOSC_CALI_START_MASK = 0x1,
  136. PMIC_EOSC_CALI_START_SHIFT = 0
  137. };
  138. /* PMIC DCXO Register Definition */
  139. enum {
  140. PMIC_RG_DCXO_CW00 = 0x0788,
  141. PMIC_RG_DCXO_CW02 = 0x0790,
  142. PMIC_RG_DCXO_CW08 = 0x079C,
  143. PMIC_RG_DCXO_CW09 = 0x079E,
  144. PMIC_RG_DCXO_CW09_CLR = 0x07A2,
  145. PMIC_RG_DCXO_CW10 = 0x07A4,
  146. PMIC_RG_DCXO_CW12 = 0x07A8,
  147. PMIC_RG_DCXO_CW13 = 0x07AA,
  148. PMIC_RG_DCXO_CW15 = 0x07AE,
  149. PMIC_RG_DCXO_CW19 = 0x07B6,
  150. };
  151. enum {
  152. PMIC_RG_SRCLKEN_IN0_HW_MODE_MASK = 0x1,
  153. PMIC_RG_SRCLKEN_IN0_HW_MODE_SHIFT = 1,
  154. PMIC_RG_SRCLKEN_IN1_HW_MODE_MASK = 0x1,
  155. PMIC_RG_SRCLKEN_IN1_HW_MODE_SHIFT = 3,
  156. PMIC_RG_RTC_EOSC32_CK_PDN_MASK = 0x1,
  157. PMIC_RG_RTC_EOSC32_CK_PDN_SHIFT = 2,
  158. PMIC_RG_EOSC_CALI_TD_MASK = 0x7,
  159. PMIC_RG_EOSC_CALI_TD_SHIFT = 5,
  160. PMIC_RG_XO_EN32K_MAN_MASK = 0x1,
  161. PMIC_RG_XO_EN32K_MAN_SHIFT = 0
  162. };
  163. /* external API */
  164. uint16_t RTC_Read(uint32_t addr);
  165. void RTC_Write(uint32_t addr, uint16_t data);
  166. int32_t rtc_busy_wait(void);
  167. int32_t RTC_Write_Trigger(void);
  168. int32_t Writeif_unlock(void);
  169. void rtc_power_off_sequence(void);
  170. #endif /* RTC_MT6359P_H */