spm_md_mtcmos.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. if (state == STA_POWER_DOWN) {
  36. /* TINFO="Start to turn off MD1" */
  37. /* TINFO="Set bus protect" */
  38. spm_write(INFRA_TOPAXI_PROTECTEN_SET, MD1_PROT_BIT_MASK);
  39. #ifndef IGNORE_MTCMOS_CHECK
  40. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA0) & MD1_PROT_BIT_ACK_MASK) != MD1_PROT_BIT_ACK_MASK) {
  41. /* */
  42. /* */
  43. }
  44. #endif
  45. /* TINFO="Set bus protect" */
  46. spm_write(INFRA_TOPAXI_PROTECTEN_1_SET, MD1_PROT_BIT_2ND_MASK);
  47. #ifndef IGNORE_MTCMOS_CHECK
  48. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA0_1) & MD1_PROT_BIT_ACK_2ND_MASK) !=
  49. MD1_PROT_BIT_ACK_2ND_MASK) {
  50. /* */
  51. /* */
  52. }
  53. #endif
  54. /* TINFO="MD_EXTRA_PWR_CON[0]=1"*/
  55. spm_write(MD_EXTRA_PWR_CON, spm_read(MD_EXTRA_PWR_CON) | (0x1 << 0));
  56. /* TINFO="Set MD_PWR_CLK_DIS = 1" */
  57. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | MD_PWR_CLK_DIS);
  58. /* TINFO="Set PWR_ISO = 1" */
  59. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_ISO);
  60. /* TINFO="MD_SRAM_ISO_CON[0]=0"*/
  61. spm_write(MD_SRAM_ISO_CON, spm_read(MD_SRAM_ISO_CON) & ~(0x1 << 0));
  62. /* TINFO="Set SRAM_PDN = 1" */
  63. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | MD1_SRAM_PDN);
  64. #ifndef IGNORE_MTCMOS_CHECK
  65. #endif
  66. /* TINFO="Set PWR_ON = 0" */
  67. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_ON);
  68. /* TINFO="Set PWR_ON_2ND = 0" */
  69. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_ON_2ND);
  70. #ifndef IGNORE_MTCMOS_CHECK
  71. /* TINFO="Wait until PWR_STATUS = 0 and PWR_STATUS_2ND = 0" */
  72. while ((spm_read(PWR_STATUS) & MD1_PWR_STA_MASK)
  73. || (spm_read(PWR_STATUS_2ND) & MD1_PWR_STA_MASK)) {
  74. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  75. }
  76. #endif
  77. /* TINFO="Set PWR_RST_B = 0" */
  78. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_RST_B);
  79. /* TINFO="Finish to turn off MD1" */
  80. } else { /* STA_POWER_ON */
  81. /* TINFO="Start to turn on MD1" */
  82. /* TINFO="Set PWR_RST_B = 0" */
  83. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_RST_B);
  84. /* TINFO="Set PWR_ON = 1" */
  85. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_ON);
  86. /* TINFO="Set PWR_ON_2ND = 1" */
  87. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_ON_2ND);
  88. #ifndef IGNORE_MTCMOS_CHECK
  89. /* TINFO="Wait until PWR_STATUS = 1 and PWR_STATUS_2ND = 1" */
  90. while (((spm_read(PWR_STATUS) & MD1_PWR_STA_MASK) != MD1_PWR_STA_MASK)
  91. || ((spm_read(PWR_STATUS_2ND) & MD1_PWR_STA_MASK) != MD1_PWR_STA_MASK)) {
  92. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  93. /* */
  94. /* */
  95. }
  96. #endif
  97. /* TINFO="Set SRAM_PDN = 0" */
  98. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~(0x1 << 6));
  99. /* TINFO="MD_SRAM_ISO_CON[0]=1"*/
  100. spm_write(MD_SRAM_ISO_CON, spm_read(MD_SRAM_ISO_CON) | (0x1 << 0));
  101. /* TINFO="Set PWR_ISO = 0" */
  102. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~PWR_ISO);
  103. /* TINFO="Set MD_PWR_CLK_DIS = 0" */
  104. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) & ~MD_PWR_CLK_DIS);
  105. /* TINFO="Set PWR_RST_B = 1" */
  106. spm_write(MD1_PWR_CON, spm_read(MD1_PWR_CON) | PWR_RST_B);
  107. /* TINFO="MD_EXTRA_PWR_CON[0]=0"*/
  108. spm_write(MD_EXTRA_PWR_CON, spm_read(MD_EXTRA_PWR_CON) & ~(0x1 << 0));
  109. /* TINFO="Release bus protect" */
  110. spm_write(INFRA_TOPAXI_PROTECTEN_1_CLR, MD1_PROT_BIT_2ND_MASK);
  111. #ifndef IGNORE_MTCMOS_CHECK
  112. /* Note that this protect ack check after releasing protect has been ignored */
  113. #endif
  114. /* TINFO="Release bus protect" */
  115. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, MD1_PROT_BIT_MASK);
  116. #ifndef IGNORE_MTCMOS_CHECK
  117. udelay(250);
  118. /* Note that this protect ack check after releasing protect has been ignored */
  119. #endif
  120. /* TINFO="Finish to turn on MD1" */
  121. }
  122. return err;
  123. }
  124. int spm_mtcmos_ctrl_dis(int state)
  125. {
  126. int err = 0;
  127. if (state == STA_POWER_DOWN) {
  128. /* TINFO="Start to turn off DIS" */
  129. /* TINFO="Set bus protect" */
  130. spm_write(INFRA_TOPAXI_PROTECTEN_SET, DIS_PROT_BIT_MASK);
  131. #ifndef IGNORE_MTCMOS_CHECK
  132. while ((spm_read(INFRA_TOPAXI_PROTECTEN_STA1) & DIS_PROT_BIT_ACK_MASK) != DIS_PROT_BIT_ACK_MASK) {
  133. /* */
  134. /* */
  135. }
  136. #endif
  137. /* TINFO="Set SRAM_PDN = 1" */
  138. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | DIS_SRAM_PDN);
  139. #ifndef IGNORE_MTCMOS_CHECK
  140. /* TINFO="Wait until DIS_SRAM_PDN_ACK = 1" */
  141. while ((spm_read(DIS_PWR_CON) & DIS_SRAM_PDN_ACK) != DIS_SRAM_PDN_ACK) {
  142. /* Need hf_fmm_ck for SRAM PDN delay IP. */
  143. /* */
  144. }
  145. #endif
  146. /* TINFO="Set PWR_ISO = 1" */
  147. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ISO);
  148. /* TINFO="Set PWR_CLK_DIS = 1" */
  149. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_CLK_DIS);
  150. /* TINFO="Set PWR_RST_B = 0" */
  151. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_RST_B);
  152. /* TINFO="Set PWR_ON = 0" */
  153. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ON);
  154. /* TINFO="Set PWR_ON_2ND = 0" */
  155. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ON_2ND);
  156. #ifndef IGNORE_MTCMOS_CHECK
  157. /* TINFO="Wait until PWR_STATUS = 0 and PWR_STATUS_2ND = 0" */
  158. while ((spm_read(PWR_STATUS) & DIS_PWR_STA_MASK)
  159. || (spm_read(PWR_STATUS_2ND) & DIS_PWR_STA_MASK)) {
  160. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  161. /* */
  162. /* */
  163. }
  164. #endif
  165. /* TINFO="Finish to turn off DIS" */
  166. } else { /* STA_POWER_ON */
  167. if (((spm_read(PWR_STATUS) & DIS_PWR_STA_MASK) == DIS_PWR_STA_MASK)
  168. & ((spm_read(PWR_STATUS_2ND) & DIS_PWR_STA_MASK) == DIS_PWR_STA_MASK))
  169. return err;
  170. /* TINFO="Start to turn on DIS" */
  171. /* TINFO="Set PWR_ON = 1" */
  172. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ON);
  173. /* TINFO="Set PWR_ON_2ND = 1" */
  174. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_ON_2ND);
  175. #ifndef IGNORE_MTCMOS_CHECK
  176. /* TINFO="Wait until PWR_STATUS = 1 and PWR_STATUS_2ND = 1" */
  177. while (((spm_read(PWR_STATUS) & DIS_PWR_STA_MASK) != DIS_PWR_STA_MASK)
  178. || ((spm_read(PWR_STATUS_2ND) & DIS_PWR_STA_MASK) != DIS_PWR_STA_MASK)) {
  179. /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */
  180. /* */
  181. /* */
  182. }
  183. #endif
  184. /* TINFO="Set PWR_CLK_DIS = 0" */
  185. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_CLK_DIS);
  186. /* TINFO="Set PWR_ISO = 0" */
  187. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~PWR_ISO);
  188. /* TINFO="Set PWR_RST_B = 1" */
  189. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) | PWR_RST_B);
  190. /* TINFO="Set SRAM_PDN = 0" */
  191. spm_write(DIS_PWR_CON, spm_read(DIS_PWR_CON) & ~(0x1 << 5));
  192. #ifndef IGNORE_MTCMOS_CHECK
  193. /* TINFO="Wait until DIS_SRAM_PDN_ACK_BIT0 = 0" */
  194. while (spm_read(DIS_PWR_CON) & DIS_SRAM_PDN_ACK_BIT0) {
  195. /* Need hf_fmm_ck for SRAM PDN delay IP. */
  196. /* */
  197. /* */
  198. }
  199. #endif
  200. /* TINFO="Release bus protect" */
  201. spm_write(INFRA_TOPAXI_PROTECTEN_CLR, DIS_PROT_BIT_MASK);
  202. #ifndef IGNORE_MTCMOS_CHECK
  203. /* Note that this protect ack check after releasing protect has been ignored */
  204. #endif
  205. /* TINFO="Finish to turn on DIS" */
  206. }
  207. return err;
  208. }