spm_md_mtcmos.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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="MD_EXTRA_PWR_CON[0]=1"*/
  58. spm_write(MD_EXTRA_PWR_CON, spm_read(MD_EXTRA_PWR_CON) | (0x1 << 0));
  59. /* TINFO="Set PWR_CLK_DIS = 1" */
  60. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_CLK_DIS);
  61. /* TINFO="Set PWR_ISO = 1" */
  62. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_ISO);
  63. /* TINFO="MD_SRAM_ISO_CON[0]=0"*/
  64. spm_write(MD_SRAM_ISO_CON, spm_read(MD_SRAM_ISO_CON) & ~(0x1 << 0));
  65. /* TINFO="Set SRAM_PDN = 1" */
  66. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | MD1_SRAM_PDN);
  67. #ifndef IGNORE_MTCMOS_CHECK
  68. #endif
  69. /* TINFO="Set PWR_ON = 0" */
  70. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_ON);
  71. /* TINFO="Set PWR_ON_2ND = 0" */
  72. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_ON_2ND);
  73. #ifndef IGNORE_MTCMOS_CHECK
  74. /* TINFO="Wait until PWR_STATUS = 0 and PWR_STATUS_2ND = 0" */
  75. while ((spm_read(PWR_STATUS) & MD1_PWR_STA_MASK)
  76. || (spm_read(PWR_STATUS_2ND) & MD1_PWR_STA_MASK)) {
  77. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  78. }
  79. #endif
  80. /* TINFO="Finish to turn off MD1" */
  81. } else { /* STA_POWER_ON */
  82. /* TINFO="Start to turn on MD1" */
  83. /* TINFO="Set PWR_RST_B = 0" */
  84. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_RST_B);
  85. /* TINFO="Set PWR_ON = 1" */
  86. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_ON);
  87. /* TINFO="Set PWR_ON_2ND = 1" */
  88. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_ON_2ND);
  89. #ifndef IGNORE_MTCMOS_CHECK
  90. /* TINFO="Wait until PWR_STATUS = 1 and PWR_STATUS_2ND = 1" */
  91. while (((spm_read(PWR_STATUS) & MD1_PWR_STA_MASK) != MD1_PWR_STA_MASK)
  92. || ((spm_read(PWR_STATUS_2ND) & MD1_PWR_STA_MASK) != MD1_PWR_STA_MASK)) {
  93. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  94. }
  95. #endif
  96. /* TINFO="Set SRAM_PDN = 0" */
  97. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~(0x1 << 8));
  98. #ifndef IGNORE_MTCMOS_CHECK
  99. #endif
  100. /* TINFO="MD_SRAM_ISO_CON[0]=1"*/
  101. spm_write(MD_SRAM_ISO_CON, spm_read(MD_SRAM_ISO_CON) | (0x1 << 0));
  102. /* TINFO="Set PWR_ISO = 0" */
  103. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_ISO);
  104. /* TINFO="Set PWR_CLK_DIS = 0" */
  105. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_CLK_DIS);
  106. /* TINFO="Set PWR_RST_B = 1" */
  107. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_RST_B);
  108. /* TINFO="MD_EXTRA_PWR_CON[0]=0"*/
  109. spm_write(MD_EXTRA_PWR_CON, spm_read(MD_EXTRA_PWR_CON) & ~(0x1 << 0));
  110. /* TINFO="Release bus protect - step2 : 0" */
  111. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, MD1_PROT_STEP2_0_MASK);
  112. #ifndef IGNORE_MTCMOS_CHECK
  113. /* Note that this protect ack check after releasing protect has been ignored */
  114. #endif
  115. /* TINFO="Release bus protect - step2 : 1" */
  116. spm_write(INFRA_TOPAXI_PROTECTEN_1_CLR, MD1_PROT_STEP2_1_MASK);
  117. #ifndef IGNORE_MTCMOS_CHECK
  118. /* Note that this protect ack check after releasing protect has been ignored */
  119. #endif
  120. /* TINFO="Release bus protect - step1 : 0" */
  121. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, MD1_PROT_STEP1_0_MASK);
  122. #ifndef IGNORE_MTCMOS_CHECK
  123. /* Note that this protect ack check after releasing protect has been ignored */
  124. #endif
  125. /* TINFO="Finish to turn on MD1" */
  126. }
  127. return err;
  128. }
  129. int spm_mtcmos_ctrl_dis(int state)
  130. {
  131. int err = 0;
  132. /* TINFO="enable SPM register control" */
  133. spm_write(POWERON_CONFIG_EN, (SPM_PROJECT_CODE << 16) | (0x1 << 0));
  134. if (state == STA_POWER_DOWN) {
  135. /* TINFO="Start to turn off DIS" */
  136. /* TINFO="Set bus protect - step1 : 0" */
  137. spm_write(INFRA_TOPAXI_PROTECTEN_1_SET, DIS_PROT_STEP1_0_MASK);
  138. #ifndef IGNORE_MTCMOS_CHECK
  139. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1_1) & DIS_PROT_STEP1_0_ACK_MASK) != DIS_PROT_STEP1_0_ACK_MASK) {
  140. }
  141. #endif
  142. /* TINFO="Set bus protect - step2 : 0" */
  143. spm_write(INFRA_TOPAXI_PROTECTEN_1_SET, DIS_PROT_STEP2_0_MASK);
  144. #ifndef IGNORE_MTCMOS_CHECK
  145. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1_1) & DIS_PROT_STEP2_0_ACK_MASK) != DIS_PROT_STEP2_0_ACK_MASK) {
  146. }
  147. #endif
  148. /* TINFO="Set bus protect - step3 : 0" */
  149. spm_write(INFRA_TOPAXI_PROTECTEN_SET, DIS_PROT_STEP3_0_MASK);
  150. #ifndef IGNORE_MTCMOS_CHECK
  151. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1) & DIS_PROT_STEP3_0_ACK_MASK) != DIS_PROT_STEP3_0_ACK_MASK) {
  152. }
  153. #endif
  154. /* TINFO="Set bus protect - step4 : 0" */
  155. spm_write(INFRA_TOPAXI_PROTECTEN_SET, DIS_PROT_STEP4_0_MASK);
  156. #ifndef IGNORE_MTCMOS_CHECK
  157. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1) & DIS_PROT_STEP4_0_ACK_MASK) != DIS_PROT_STEP4_0_ACK_MASK) {
  158. }
  159. #endif
  160. /* TINFO="Set SRAM_PDN = 1" */
  161. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | DIS_SRAM_PDN);
  162. #ifndef IGNORE_MTCMOS_CHECK
  163. /* TINFO="Wait until DIS_SRAM_PDN_ACK = 1" */
  164. while ((spm_read(DIS_PWR_CON) & DIS_SRAM_PDN_ACK) != DIS_SRAM_PDN_ACK) {
  165. /* n/a */
  166. }
  167. #endif
  168. /* TINFO="Set PWR_ISO = 1" */
  169. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ISO);
  170. /* TINFO="Set PWR_CLK_DIS = 1" */
  171. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_CLK_DIS);
  172. /* TINFO="Set PWR_RST_B = 0" */
  173. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_RST_B);
  174. /* TINFO="Set PWR_ON = 0" */
  175. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ON);
  176. /* TINFO="Set PWR_ON_2ND = 0" */
  177. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ON_2ND);
  178. #ifndef IGNORE_MTCMOS_CHECK
  179. /* TINFO="Wait until PWR_STATUS = 0 and PWR_STATUS_2ND = 0" */
  180. while ((spm_read(PWR_STATUS) & DIS_PWR_STA_MASK)
  181. || (spm_read(PWR_STATUS_2ND) & DIS_PWR_STA_MASK)) {
  182. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  183. }
  184. #endif
  185. /* TINFO="Finish to turn off DIS" */
  186. } else { /* STA_POWER_ON */
  187. /* TINFO="Start to turn on DIS" */
  188. /* TINFO="Set PWR_ON = 1" */
  189. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ON);
  190. /* TINFO="Set PWR_ON_2ND = 1" */
  191. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ON_2ND);
  192. #ifndef IGNORE_MTCMOS_CHECK
  193. /* TINFO="Wait until PWR_STATUS = 1 and PWR_STATUS_2ND = 1" */
  194. while (((spm_read(PWR_STATUS) & DIS_PWR_STA_MASK) != DIS_PWR_STA_MASK)
  195. || ((spm_read(PWR_STATUS_2ND) & DIS_PWR_STA_MASK) != DIS_PWR_STA_MASK)) {
  196. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  197. }
  198. #endif
  199. /* TINFO="Set PWR_CLK_DIS = 0" */
  200. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_CLK_DIS);
  201. /* TINFO="Set PWR_ISO = 0" */
  202. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ISO);
  203. /* TINFO="Set PWR_RST_B = 1" */
  204. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_RST_B);
  205. /* TINFO="Set SRAM_PDN = 0" */
  206. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~(0x1 << 8));
  207. #ifndef IGNORE_MTCMOS_CHECK
  208. /* TINFO="Wait until DIS_SRAM_PDN_ACK_BIT0 = 0" */
  209. while (spm_read(DIS_PWR_CON) & DIS_SRAM_PDN_ACK_BIT0) {
  210. /* n/a */
  211. }
  212. #endif
  213. /* TINFO="Release bus protect - step4 : 0" */
  214. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, DIS_PROT_STEP4_0_MASK);
  215. #ifndef IGNORE_MTCMOS_CHECK
  216. /* Note that this protect ack check after releasing protect has been ignored */
  217. #endif
  218. /* TINFO="Release bus protect - step3 : 0" */
  219. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, DIS_PROT_STEP3_0_MASK);
  220. #ifndef IGNORE_MTCMOS_CHECK
  221. /* Note that this protect ack check after releasing protect has been ignored */
  222. #endif
  223. /* TINFO="Release bus protect - step2 : 0" */
  224. spm_write(INFRA_TOPAXI_PROTECTEN_1_CLR, DIS_PROT_STEP2_0_MASK);
  225. #ifndef IGNORE_MTCMOS_CHECK
  226. /* Note that this protect ack check after releasing protect has been ignored */
  227. #endif
  228. /* TINFO="Release bus protect - step1 : 0" */
  229. spm_write(INFRA_TOPAXI_PROTECTEN_1_CLR, DIS_PROT_STEP1_0_MASK);
  230. #ifndef IGNORE_MTCMOS_CHECK
  231. /* Note that this protect ack check after releasing protect has been ignored */
  232. #endif
  233. /* TINFO="Finish to turn on DIS" */
  234. }
  235. return err;
  236. }
  237. int spm_mtcmos_ctrl_audio(int state)
  238. {
  239. return 0;
  240. }