spm_md_mtcmos.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #include <platform/spm.h>
  32. int spm_mtcmos_ctrl_md1(int state)
  33. {
  34. int err = 0;
  35. /* TINFO="enable SPM register control" */
  36. spm_write(POWERON_CONFIG_EN, (SPM_PROJECT_CODE << 16) | (0x1 << 0));
  37. if (state == STA_POWER_DOWN) {
  38. /* TINFO="Start to turn off MD1" */
  39. /* TINFO="Set bus protect - step1 : 0" */
  40. spm_write(INFRA_TOPAXI_PROTECTEN_SET, MD1_PROT_STEP1_0_MASK);
  41. #ifndef IGNORE_MTCMOS_CHECK
  42. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1) & MD1_PROT_STEP1_0_ACK_MASK) != MD1_PROT_STEP1_0_ACK_MASK) {
  43. }
  44. #endif
  45. /* TINFO="Set bus protect - step2 : 0" */
  46. spm_write(INFRA_TOPAXI_PROTECTEN_SET, MD1_PROT_STEP2_0_MASK);
  47. #ifndef IGNORE_MTCMOS_CHECK
  48. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1) & MD1_PROT_STEP2_0_ACK_MASK) != MD1_PROT_STEP2_0_ACK_MASK) {
  49. }
  50. #endif
  51. /* TINFO="Set bus protect - step2 : 1" */
  52. spm_write(INFRA_TOPAXI_PROTECTEN_1_SET, MD1_PROT_STEP2_1_MASK);
  53. #ifndef IGNORE_MTCMOS_CHECK
  54. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1_1) & MD1_PROT_STEP2_1_ACK_MASK) != MD1_PROT_STEP2_1_ACK_MASK) {
  55. }
  56. #endif
  57. /* TINFO="Set PWR_ON = 0" */
  58. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_ON);
  59. #ifndef IGNORE_MTCMOS_CHECK
  60. /* TINFO="Wait until MD1_PWR_STA_MASK = 0" */
  61. while (spm_read(PWR_STATUS) & MD1_PWR_STA_MASK) {
  62. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  63. }
  64. #endif
  65. /* TINFO="MD_EXT_BUCK_ISO_CON[0]=1"*/
  66. spm_write(MD_EXT_BUCK_ISO_CON, spm_read(MD_EXT_BUCK_ISO_CON) | (0x1 << 0));
  67. /* TINFO="MD_EXT_BUCK_ISO_CON[1]=1"*/
  68. spm_write(MD_EXT_BUCK_ISO_CON, spm_read(MD_EXT_BUCK_ISO_CON) | (0x1 << 1));
  69. /* TINFO="Set PWR_RST_B = 0" */
  70. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_RST_B);
  71. /* TINFO="Finish to turn off MD1" */
  72. } else { /* STA_POWER_ON */
  73. /* TINFO="Start to turn on MD1" */
  74. /* TINFO="MD_EXT_BUCK_ISO_CON[0]=0"*/
  75. spm_write(MD_EXT_BUCK_ISO_CON, spm_read(MD_EXT_BUCK_ISO_CON) & ~(0x1 << 0));
  76. /* TINFO="MD_EXT_BUCK_ISO_CON[1]=0"*/
  77. spm_write(MD_EXT_BUCK_ISO_CON, spm_read(MD_EXT_BUCK_ISO_CON) & ~(0x1 << 1));
  78. /* TINFO="Set PWR_RST_B = 1" */
  79. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_RST_B);
  80. /* TINFO="Set PWR_ON = 1" */
  81. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_ON);
  82. #ifndef IGNORE_MTCMOS_CHECK
  83. /* TINFO="Wait until MD1_PWR_STA_MASK = 1" */
  84. while ((spm_read(PWR_STATUS) & MD1_PWR_STA_MASK) != MD1_PWR_STA_MASK) {
  85. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  86. }
  87. #endif
  88. /* TINFO="Release bus protect - step2 : 0" */
  89. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, MD1_PROT_STEP2_0_MASK);
  90. #ifndef IGNORE_MTCMOS_CHECK
  91. /* Note that this protect ack check after releasing protect has been ignored */
  92. #endif
  93. /* TINFO="Release bus protect - step2 : 1" */
  94. spm_write(INFRA_TOPAXI_PROTECTEN_1_CLR, MD1_PROT_STEP2_1_MASK);
  95. #ifndef IGNORE_MTCMOS_CHECK
  96. /* Note that this protect ack check after releasing protect has been ignored */
  97. #endif
  98. /* TINFO="Release bus protect - step1 : 0" */
  99. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, MD1_PROT_STEP1_0_MASK);
  100. #ifndef IGNORE_MTCMOS_CHECK
  101. /* Note that this protect ack check after releasing protect has been ignored */
  102. #endif
  103. /* TINFO="Finish to turn on MD1" */
  104. }
  105. return err;
  106. }
  107. int spm_mtcmos_ctrl_dis(int state)
  108. {
  109. int err = 0;
  110. /* TINFO="enable SPM register control" */
  111. spm_write(POWERON_CONFIG_EN, (SPM_PROJECT_CODE << 16) | (0x1 << 0));
  112. if (state == STA_POWER_DOWN) {
  113. /* TINFO="Start to turn off DIS" */
  114. /* TINFO="Set bus protect - step1 : 0" */
  115. spm_write(INFRA_TOPAXI_PROTECTEN_MM_SET, DIS_PROT_STEP1_0_MASK);
  116. #ifndef IGNORE_MTCMOS_CHECK
  117. while ((spm_read(INFRA_TOPAXI_PROTECTEN_MM_STA1) & DIS_PROT_STEP1_0_ACK_MASK) != DIS_PROT_STEP1_0_ACK_MASK) {
  118. }
  119. #endif
  120. /* TINFO="Set bus protect - step2 : 0" */
  121. spm_write(SMI_COMMON_SMI_CLAMP_SET, DIS_PROT_STEP2_0_MASK);
  122. #ifndef IGNORE_MTCMOS_CHECK
  123. while ((spm_read(SMI_COMMON_SMI_CLAMP) & DIS_PROT_STEP2_0_ACK_MASK) != DIS_PROT_STEP2_0_ACK_MASK) {
  124. }
  125. #endif
  126. /* TINFO="Set bus protect - step3 : 0" */
  127. spm_write(INFRA_TOPAXI_PROTECTEN_1_SET, DIS_PROT_STEP3_0_MASK);
  128. #ifndef IGNORE_MTCMOS_CHECK
  129. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1_1) & DIS_PROT_STEP3_0_ACK_MASK) != DIS_PROT_STEP3_0_ACK_MASK) {
  130. }
  131. #endif
  132. /* TINFO="Set bus protect - step4 : 0" */
  133. spm_write(INFRA_TOPAXI_PROTECTEN_SET, DIS_PROT_STEP4_0_MASK);
  134. #ifndef IGNORE_MTCMOS_CHECK
  135. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1) & DIS_PROT_STEP4_0_ACK_MASK) != DIS_PROT_STEP4_0_ACK_MASK) {
  136. }
  137. #endif
  138. /* TINFO="Set bus protect - way_en : 0" */
  139. spm_write(INFRA_TOPAXI_SI0_CTL_CLR, 0x1 << 6);
  140. #ifndef IGNORE_MTCMOS_CHECK
  141. while ((spm_read(INFRA_TOPAXI_SI0_STA) & (0x1 << 24)) != (0x1 << 24)) {
  142. }
  143. #endif
  144. /* TINFO="Set bus protect - way_en : 0" */
  145. //*INFRA_TOPAXI_SI2_CTL = *INFRA_TOPAXI_SI2_CTL & (~(0x1 << 5));
  146. spm_write(INFRA_TOPAXI_SI2_CTL,
  147. spm_read(INFRA_TOPAXI_SI2_CTL) & (~(0x1 << 5)));
  148. #ifndef IGNORE_MTCMOS_CHECK
  149. while ((spm_read(INFRA_TOPAXI_SI2_STA) & (0x1 << 14)) != (0x1 << 14)) {
  150. }
  151. #endif
  152. /* TINFO="Set bus protect - step5 : 0" */
  153. spm_write(INFRA_TOPAXI_PROTECTEN_SET, DIS_PROT_STEP5_0_MASK);
  154. #ifndef IGNORE_MTCMOS_CHECK
  155. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1) & DIS_PROT_STEP5_0_ACK_MASK) != DIS_PROT_STEP5_0_ACK_MASK) {
  156. }
  157. #endif
  158. /* TINFO="Set SRAM_PDN = 1" */
  159. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | DIS_SRAM_PDN);
  160. #ifndef IGNORE_MTCMOS_CHECK
  161. /* TINFO="Wait until DIS_SRAM_PDN_ACK = 1" */
  162. while ((spm_read(DIS_PWR_CON) & DIS_SRAM_PDN_ACK) != DIS_SRAM_PDN_ACK) {
  163. /* Need hf_fmm_ck for SRAM PDN delay IP. */
  164. }
  165. #endif
  166. /* TINFO="Set PWR_ISO = 1" */
  167. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ISO);
  168. /* TINFO="Set PWR_CLK_DIS = 1" */
  169. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_CLK_DIS);
  170. /* TINFO="Set PWR_RST_B = 0" */
  171. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_RST_B);
  172. /* TINFO="Set PWR_ON = 0" */
  173. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ON);
  174. /* TINFO="Set PWR_ON_2ND = 0" */
  175. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ON_2ND);
  176. #ifndef IGNORE_MTCMOS_CHECK
  177. /* TINFO="Wait until PWR_STATUS = 0 and PWR_STATUS_2ND = 0" */
  178. while ((spm_read(PWR_STATUS) & DIS_PWR_STA_MASK)
  179. || (spm_read(PWR_STATUS_2ND) & DIS_PWR_STA_MASK)) {
  180. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  181. }
  182. #endif
  183. /* TINFO="Finish to turn off DIS" */
  184. } else { /* STA_POWER_ON */
  185. /* TINFO="Start to turn on DIS" */
  186. /* TINFO="Set PWR_ON = 1" */
  187. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ON);
  188. /* TINFO="Set PWR_ON_2ND = 1" */
  189. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ON_2ND);
  190. #ifndef IGNORE_MTCMOS_CHECK
  191. /* TINFO="Wait until PWR_STATUS = 1 and PWR_STATUS_2ND = 1" */
  192. while (((spm_read(PWR_STATUS) & DIS_PWR_STA_MASK) != DIS_PWR_STA_MASK)
  193. || ((spm_read(PWR_STATUS_2ND) & DIS_PWR_STA_MASK) != DIS_PWR_STA_MASK)) {
  194. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  195. }
  196. #endif
  197. /* TINFO="Set PWR_CLK_DIS = 0" */
  198. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_CLK_DIS);
  199. /* TINFO="Set PWR_ISO = 0" */
  200. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ISO);
  201. /* TINFO="Set PWR_RST_B = 1" */
  202. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_RST_B);
  203. /* TINFO="Set SRAM_PDN = 0" */
  204. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~(0x1 << 8));
  205. #ifndef IGNORE_MTCMOS_CHECK
  206. /* TINFO="Wait until DIS_SRAM_PDN_ACK_BIT0 = 0" */
  207. while (spm_read(DIS_PWR_CON) & DIS_SRAM_PDN_ACK_BIT0) {
  208. /* Need hf_fmm_ck for SRAM PDN delay IP. */
  209. }
  210. #endif
  211. /* TINFO="Release bus protect - step5 : 0" */
  212. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, DIS_PROT_STEP5_0_MASK);
  213. #ifndef IGNORE_MTCMOS_CHECK
  214. /* Note that this protect ack check after releasing protect has been ignored */
  215. #endif
  216. /* TINFO="Release bus protect - way_en : 0" */
  217. //*INFRA_TOPAXI_SI2_CTL = *INFRA_TOPAXI_SI2_CTL | (0x1 << 5);
  218. spm_write(INFRA_TOPAXI_SI2_CTL,
  219. spm_read(INFRA_TOPAXI_SI2_CTL) | (0x1 << 5));
  220. #ifndef IGNORE_MTCMOS_CHECK
  221. while ((spm_read(INFRA_TOPAXI_SI2_STA) & (0x1 << 14)) != (0x1 << 14)) {
  222. }
  223. #endif
  224. /* TINFO="Release bus protect - way_en : 0" */
  225. spm_write(INFRA_TOPAXI_SI0_CTL_SET, 0x1 << 6);
  226. #ifndef IGNORE_MTCMOS_CHECK
  227. while ((spm_read(INFRA_TOPAXI_SI0_STA) & (0x1 << 24)) != (0x1 << 24)) {
  228. }
  229. #endif
  230. /* TINFO="Release bus protect - step4 : 0" */
  231. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, DIS_PROT_STEP4_0_MASK);
  232. #ifndef IGNORE_MTCMOS_CHECK
  233. /* Note that this protect ack check after releasing protect has been ignored */
  234. #endif
  235. /* TINFO="Release bus protect - step3 : 0" */
  236. spm_write(INFRA_TOPAXI_PROTECTEN_1_CLR, DIS_PROT_STEP3_0_MASK);
  237. #ifndef IGNORE_MTCMOS_CHECK
  238. /* Note that this protect ack check after releasing protect has been ignored */
  239. #endif
  240. /* TINFO="Release bus protect - step2 : 0" */
  241. spm_write(SMI_COMMON_SMI_CLAMP_CLR, DIS_PROT_STEP2_0_MASK);
  242. #ifndef IGNORE_MTCMOS_CHECK
  243. /* Note that this protect ack check after releasing protect has been ignored */
  244. #endif
  245. /* TINFO="Release bus protect - step1 : 0" */
  246. spm_write(INFRA_TOPAXI_PROTECTEN_MM_CLR, DIS_PROT_STEP1_0_MASK);
  247. #ifndef IGNORE_MTCMOS_CHECK
  248. /* Note that this protect ack check after releasing protect has been ignored */
  249. #endif
  250. /* TINFO="Finish to turn on DIS" */
  251. }
  252. return err;
  253. }