mt_pmic_wrap_init.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein is
  5. * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
  6. * the prior written permission of MediaTek inc. and/or its licensors, any
  7. * reproduction, modification, use or disclosure of MediaTek Software, and
  8. * information contained herein, in whole or in part, shall be strictly
  9. * prohibited.
  10. *
  11. * MediaTek Inc. (C) 2019. All rights reserved.
  12. *
  13. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  14. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  15. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
  16. * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
  17. * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  19. * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
  20. * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
  21. * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
  22. * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
  23. * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
  24. * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
  25. * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
  26. * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  27. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
  28. * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
  29. * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
  30. * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
  31. * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  32. *
  33. * The following software/firmware and/or related documentation ("MediaTek
  34. * Software") have been modified by MediaTek Inc. All revisions are subject to
  35. * any receiver's applicable license agreements with MediaTek Inc.
  36. */
  37. #ifndef __PMIC_WRAP_INIT_H__
  38. #define __PMIC_WRAP_INIT_H__
  39. /****** SW ENV define *************************************/
  40. #define PMIC_WRAP_PRELOADER 0
  41. #define PMIC_WRAP_LK 1
  42. #define PMIC_WRAP_KERNEL 0
  43. #define PMIC_WRAP_SCP 0
  44. #define PMIC_WRAP_CTP 0
  45. #define PMIC_WRAP_DEBUG
  46. #define PMIC_WRAP_SUPPORT
  47. #define PMIC_WRAP_CRC_SUPPORT
  48. /* #define PMIC_WRAP_RESET_UT */
  49. /****** For BringUp. if BringUp doesn't had PMIC, need open this ***********/
  50. #if (PMIC_WRAP_PRELOADER)
  51. #if CFG_FPGA_PLATFORM
  52. #define PMIC_WRAP_NO_PMIC
  53. #else
  54. /* #define PWRAP_TIMEOUT */
  55. #endif
  56. #elif (PMIC_WRAP_LK)
  57. #if defined(MACH_FPGA)
  58. #define PMIC_WRAP_NO_PMIC
  59. #else
  60. #define PWRAP_TIMEOUT
  61. #endif
  62. #elif (PMIC_WRAP_KERNEL)
  63. #if defined(CONFIG_MTK_FPGA) || defined(CONFIG_FPGA_EARLY_PORTING)
  64. #define PMIC_WRAP_NO_PMIC
  65. #else
  66. /* #define PWRAP_TIMEOUT */
  67. #endif
  68. #elif (PMIC_WRAP_CTP)
  69. #if defined(CONFIG_MTK_FPGA)
  70. #define PMIC_WRAP_NO_PMIC
  71. #else
  72. /* #define PWRAP_TIMEOUT */
  73. #endif
  74. #else
  75. #define PWRAP_TIMEOUT
  76. #endif
  77. #define MTK_PLATFORM_MT6359 1
  78. /****** SW ENV header define *****************************/
  79. #if (PMIC_WRAP_PRELOADER)
  80. #include <sync_write.h>
  81. #include <typedefs.h>
  82. #include <gpio.h>
  83. #include <mt6785.h>
  84. #elif (PMIC_WRAP_LK)
  85. #include <debug.h>
  86. #include <platform/mt_typedefs.h>
  87. #include <platform/mt_reg_base.h>
  88. #include <platform/mt_gpt.h>
  89. #include <platform/mt_irq.h>
  90. #include <sys/types.h>
  91. #include <platform/sync_write.h>
  92. #include <platform/upmu_hw.h>
  93. #elif (PMIC_WRAP_KERNEL)
  94. #elif (PMIC_WRAP_SCP)
  95. #include "stdio.h"
  96. #include <string.h>
  97. #include "FreeRTOS.h"
  98. #elif (PMIC_WRAP_CTP)
  99. #include <sync_write.h>
  100. #include <typedefs.h>
  101. #include <reg_base.H>
  102. #else
  103. ### Compile error, check SW ENV define
  104. #endif
  105. /*****************************************************************/
  106. #include <reg_PMIC_WRAP.h>
  107. #include <reg_PMIC_WRAP_mac.h>
  108. /*******************macro for regsister@PMIC *******************************/
  109. #if !defined(MACH_FPGA)
  110. #include <upmu_hw.h>
  111. #else
  112. #include <upmu_hw.h>
  113. #endif
  114. /*******************start ---external API********************************/
  115. extern signed int pwrap_read(unsigned int adr, unsigned int *rdata);
  116. extern signed int pwrap_write(unsigned int adr, unsigned int wdata);
  117. extern signed int pwrap_write_nochk(unsigned int adr, unsigned int wdata);
  118. extern signed int pwrap_read_nochk(unsigned int adr, unsigned int *rdata);
  119. extern signed int pwrap_wacs2(unsigned int write, unsigned int adr, unsigned int wdata, unsigned int *rdata);
  120. extern void pwrap_dump_all_register(void);
  121. extern signed int pwrap_init_preloader(void);
  122. extern signed int pwrap_init_lk(void);
  123. extern signed int pwrap_init_scp(void);
  124. extern signed int pwrap_init(void);
  125. /****** DEBUG marco define *******************************/
  126. #define PWRAPTAG "[PWRAP] "
  127. #if (PMIC_WRAP_PRELOADER)
  128. #ifdef PMIC_WRAP_DEBUG
  129. #define PWRAPFUC(fmt, arg...) print(PWRAPTAG "%s\n", __func__)
  130. #define PWRAPLOG(fmt, arg...) print(PWRAPTAG fmt, ##arg)
  131. #else
  132. #define PWRAPFUC(fmt, arg...)
  133. #define PWRAPLOG(fmt, arg...)
  134. #endif /* end of #ifdef PMIC_WRAP_DEBUG */
  135. #define PWRAPCRI(fmt, arg...) print(PWRAPTAG fmt, ##arg)
  136. #define PWRAPERR(fmt, arg...) print(PWRAPTAG "ERR " fmt, ##arg)
  137. #elif (PMIC_WRAP_LK)
  138. #ifdef PMIC_WRAP_DEBUG
  139. #define PWRAPFUC(fmt, arg...) \
  140. dprintf(CRITICAL, PWRAPTAG "%s\n", __func__)
  141. #define PWRAPLOG(fmt, arg...) \
  142. dprintf(CRITICAL, PWRAPTAG fmt, ##arg)
  143. #else
  144. #define PWRAPFUC(fmt, arg...)
  145. #define PWRAPLOG(fmt, arg...)
  146. #endif /* end of #ifdef PMIC_WRAP_DEBUG */
  147. #define PWRAPERR(fmt, arg...) \
  148. dprintf(CRITICAL, PWRAPTAG "ERR,line=%d " fmt, __LINE__, ##arg)
  149. #elif (PMIC_WRAP_KERNEL)
  150. #ifdef PMIC_WRAP_DEBUG
  151. #define PWRAPDEB(fmt, arg...)
  152. #define PWRAPLOG(fmt, arg...) pr_err(PWRAPTAG fmt, ##arg)
  153. #define PWRAPFUC(fmt, arg...)
  154. #define PWRAPREG(fmt, arg...) pr_err(PWRAPTAG fmt, ##arg)
  155. #else
  156. #define PWRAPDEB(fmt, arg...)
  157. #define PWRAPLOG(fmt, arg...)
  158. #define PWRAPFUC(fmt, arg...)
  159. #define PWRAPREG(fmt, arg...)
  160. #endif /* end of #ifdef PMIC_WRAP_DEBUG */
  161. #define PWRAP_PR_ERR(fmt, arg...) \
  162. pr_err(PWRAPTAG "ERROR,line=%d " fmt, __LINE__, ##arg)
  163. #elif (PMIC_WRAP_SCP)
  164. #ifdef PMIC_WRAP_DEBUG
  165. #define PWRAPFUC(fmt, arg...) \
  166. PRINTF_D(PWRAPTAG "%s\n", __func__)
  167. #define PWRAPLOG(fmt, arg...) \
  168. PRINTF_D(PWRAPTAG fmt, ##arg)
  169. #else
  170. #define PWRAPFUC(fmt, arg...)
  171. #define PWRAPLOG(fmt, arg...)
  172. #endif /* end of #ifdef PMIC_WRAP_DEBUG */
  173. #define PWRAPERR(fmt, arg...) \
  174. PRINTF_E(PWRAPTAG "ERR, line=%d " fmt, __LINE__, ##arg)
  175. #elif (PMIC_WRAP_CTP)
  176. #ifdef PMIC_WRAP_DEBUG
  177. #define PWRAPFUC(fmt, arg...) \
  178. dbg_print(PWRAPTAG "%s\n", __func__)
  179. #define PWRAPLOG(fmt, arg...) \
  180. dbg_print(PWRAPTAG fmt, ##arg)
  181. #else
  182. #define PWRAPFUC(fmt, arg...) \
  183. dbg_print(PWRAPTAG "%s\n", __func__)
  184. #define PWRAPLOG(fmt, arg...) \
  185. dbg_print(PWRAPTAG fmt, ##arg)
  186. #endif /* end of #ifdef PMIC_WRAP_DEBUG */
  187. #define PWRAPERR(fmt, arg...) \
  188. dbg_print(PWRAPTAG "ERR,line=%d " fmt, __LINE__, ##arg)
  189. #else
  190. ### Compile error, check SW ENV define
  191. #endif
  192. /**********************************************************/
  193. /*********** platform info, PMIC info ********************/
  194. #define PMIC_WRAP_BASE (PWRAP_BASE)
  195. #define PMIC_WRAP_REG_RANGE (250)
  196. #define DEFAULT_VALUE_READ_TEST (0x5aa5)
  197. #define DEFAULT_VALUE_WRITE_TEST (0xa55a)
  198. #define PWRAP_WRITE_TEST_VALUE (0x1234)
  199. #define PWRAP_EXT_WRITE_TEST_VALUE (0x4321)
  200. /**********************************************************/
  201. #define DISABLE_ALL (0)
  202. /* HIPRIS_ARB */
  203. /*
  204. * #define MDINF (1 << 0)
  205. * #define WACS0 (1 << 1)
  206. * #define WACS1 (1 << 2)
  207. * #define WACS2 (1 << 4)
  208. * #define DVFSINF (1 << 3)
  209. * #define STAUPD (1 << 5)
  210. * #define GPSINF (1 << 6)
  211. */
  212. /* MUX SEL */
  213. #define WRAPPER_MODE (0)
  214. #define MANUAL_MODE (1)
  215. /* macro for MAN_RDATA FSM */
  216. #define MAN_FSM_NO_REQ (0x00)
  217. #define MAN_FSM_IDLE (0x00)
  218. #define MAN_FSM_REQ (0x02)
  219. #define MAN_FSM_WFDLE (0x04)
  220. #define MAN_FSM_WFVLDCLR (0x06)
  221. /* macro for WACS_FSM */
  222. #define WACS_FSM_IDLE (0x00)
  223. #define WACS_FSM_REQ (0x02) /* request in process */
  224. #define WACS_FSM_WFDLE (0x04)
  225. #define WACS_FSM_WFVLDCLR (0x06)
  226. #define WACS_INIT_DONE (0x01)
  227. #define WACS_SYNC_IDLE (0x01)
  228. #define WACS_SYNC_BUSY (0x00)
  229. /**** timeout time, unit :us ***********/
  230. #define TIMEOUT_RESET (0x2710) /* 10000us */
  231. #define TIMEOUT_READ (0x2710) /* 10000us */
  232. #define TIMEOUT_WAIT_IDLE (0x2710) /* 10000us */
  233. /*-----macro for manual commnd ---------------------------------*/
  234. #define OP_WR (0x1)
  235. #define OP_RD (0x0)
  236. #define OP_CSH (0x0)
  237. #define OP_CSL (0x1)
  238. #define OP_CK (0x2)
  239. #define OP_OUTS (0x8)
  240. #define OP_OUTD (0x9)
  241. #define OP_OUTQ (0xA)
  242. #define OP_INS (0xC)
  243. #define OP_INS0 (0xD)
  244. #define OP_IND (0xE)
  245. #define OP_INQ (0xF)
  246. #define OP_OS2IS (0x10)
  247. #define OP_OS2ID (0x11)
  248. #define OP_OS2IQ (0x12)
  249. #define OP_OD2IS (0x13)
  250. #define OP_OD2ID (0x14)
  251. #define OP_OD2IQ (0x15)
  252. #define OP_OQ2IS (0x16)
  253. #define OP_OQ2ID (0x17)
  254. #define OP_OQ2IQ (0x18)
  255. #define OP_OSNIS (0x19)
  256. #define OP_ODNID (0x1A)
  257. /******************Error handle *****************************/
  258. #define E_PWR_INVALID_ARG (1)
  259. #define E_PWR_INVALID_RW (2)
  260. #define E_PWR_INVALID_ADDR (3)
  261. #define E_PWR_INVALID_WDAT (4)
  262. #define E_PWR_INVALID_OP_MANUAL (5)
  263. #define E_PWR_NOT_IDLE_STATE (6)
  264. #define E_PWR_NOT_INIT_DONE (7)
  265. #define E_PWR_NOT_INIT_DONE_READ (8)
  266. #define E_PWR_WAIT_IDLE_TIMEOUT (9)
  267. #define E_PWR_WAIT_IDLE_TIMEOUT_READ (10)
  268. #define E_PWR_INIT_SIDLY_FAIL (11)
  269. #define E_PWR_RESET_TIMEOUT (12)
  270. #define E_PWR_TIMEOUT (13)
  271. #define E_PWR_INIT_RESET_SPI (20)
  272. #define E_PWR_INIT_SIDLY (21)
  273. #define E_PWR_INIT_REG_CLOCK (22)
  274. #define E_PWR_INIT_ENABLE_PMIC (23)
  275. #define E_PWR_INIT_DIO (24)
  276. #define E_PWR_INIT_CIPHER (25)
  277. #define E_PWR_INIT_WRITE_TEST (26)
  278. #define E_PWR_INIT_ENABLE_CRC (27)
  279. #define E_PWR_INIT_ENABLE_DEWRAP (28)
  280. #define E_PWR_READ_TEST_FAIL (30)
  281. #define E_PWR_WRITE_TEST_FAIL (31)
  282. #define E_PWR_SWITCH_DIO (32)
  283. /*-----macro for read/write register -------------------------------------*/
  284. #define WRAP_RD32(addr) (*(volatile unsigned int *)(addr))
  285. #define WRAP_WR32(addr,data) ((*(volatile unsigned int *)(addr)) = (unsigned int)data)
  286. #define WRAP_SET_BIT(BS,REG) ((*(volatile unsigned int*)(REG)) |= (unsigned int)(BS))
  287. #define WRAP_CLR_BIT(BS,REG) ((*(volatile unsigned int*)(REG)) &= ~((unsigned int)(BS)))
  288. /**************** end ---external API***********************************/
  289. /************* macro for spi clock config ******************************/
  290. #define CLK_CFG_UPDATE (TOPCKGEN_BASE+0x004)
  291. #define CLK_CFG_4_SET (TOPCKGEN_BASE+0x084)
  292. #define CLK_CFG_4_CLR (TOPCKGEN_BASE+0x088)
  293. #define CLK_CFG_5_SET (TOPCKGEN_BASE+0x094)
  294. #define CLK_CFG_5_CLR (TOPCKGEN_BASE+0x098)
  295. #define CLK_SPI_CK_26M 0x1
  296. #define INFRA_GLOBALCON_RST0 (INFRACFG_AO_BASE+0x140)
  297. #define INFRA_GLOBALCON_RST1 (INFRACFG_AO_BASE+0x144)
  298. #define PMIC_CLOCK_DCM (INFRACFG_AO_BASE+0x074)
  299. /* APB Module infracfg_ao */
  300. #define MODULE_SW_CG_0_SET (INFRACFG_AO_BASE+0x080)
  301. #define MODULE_SW_CG_0_CLR (INFRACFG_AO_BASE+0x084)
  302. #define MODULE_CLK_SEL (INFRACFG_AO_BASE+0x098)
  303. #define PMICW_CLOCK_CTRL (INFRACFG_AO_BASE+0x108)
  304. #define PMICW_CLOCK_CTRL_SET (INFRACFG_AO_BASE+0x3A8)
  305. #define PMICW_CLOCK_CTRL_CLR (INFRACFG_AO_BASE+0x3AC)
  306. #define MODULE_SW_CG_2_SET (INFRACFG_AO_BASE+0x0A4)
  307. #define MODULE_SW_CG_2_CLR (INFRACFG_AO_BASE+0x0A8)
  308. #define INFRA_GLOBALCON_RST2_SET (INFRACFG_AO_BASE+0x140)
  309. #define INFRA_GLOBALCON_RST2_CLR (INFRACFG_AO_BASE+0x144)
  310. #define APB_CLOCK_GATING (INFRACFG_AO_BASE+0xF0C)
  311. /************* macro for spi io config ******************************/
  312. #define IO_CFG_LT_DRV_CFG1 (IOCFG_LT_BASE+0x010)
  313. #define IO_CFG_LT_DRV_CFG1_SET (IOCFG_LT_BASE+0x014)
  314. #define IO_CFG_LT_DRV_CFG1_CLR (IOCFG_LT_BASE+0x018)
  315. #define IO_CFG_LM_PD_CFG0_SET (IOCFG_LM_BASE+0x034)
  316. #define IO_CFG_LM_PD_CFG0_CLR (IOCFG_LM_BASE+0x038)
  317. #define IO_CFG_LM_PU_CFG0_SET (IOCFG_LM_BASE+0x044)
  318. #define IO_CFG_LM_PU_CFG0_CLR (IOCFG_LM_BASE+0x048)
  319. #define IO_CFG_RM_DRV_CFG0_SET (IOCFG_RM_BASE+0x004)
  320. #define IO_CFG_RM_DRV_CFG0_CLR (IOCFG_RM_BASE+0x008)
  321. /************* macro for APB Module modem_temp_share ****************/
  322. #define MODEM_TEMP_SHARE_BASE (TOPCKGEN_BASE+0x18000)
  323. #define MODEM_TEMP_SHARE_CTRL (MODEM_TEMP_SHARE_BASE+0x00)
  324. #endif /*__PMIC_WRAP_INIT_H__*/