pmif_sw.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 __PMIF_SW_H__
  38. #define __PMIF_SW_H__
  39. #define PMIF_PRELOADER 0
  40. #define PMIF_LK 1
  41. #define PMIF_KERNEL 0
  42. #define PMIF_CTP 0
  43. /* SW ENV define */
  44. #define PMIF_DEBUG 0
  45. /* Read/write byte limitation, by project */
  46. #define PMIF_BYTECNT_MAX 1
  47. #define PMIF_SRCLKEN_RC_EN 0
  48. /* For BringUp. if BringUp doesn't had PMIC, need open this */
  49. #if (PMIF_PRELOADER)
  50. #if CFG_FPGA_PLATFORM
  51. #define PMIF_NO_PMIC 1
  52. #else
  53. #define PMIF_NO_PMIC 0
  54. #define PMIF_TIMEOUT 0
  55. #endif
  56. #define PMIF_NORMAL_BOOT 1
  57. #elif (PMIF_LK)
  58. #if defined(MACH_FPGA)
  59. #define PMIF_NO_PMIC 1
  60. #else
  61. #define PMIF_NO_PMIC 0
  62. #define PMIF_TIMEOUT 0
  63. #endif
  64. #define PMIF_NORMAL_BOOT 1
  65. #elif (PMIF_CTP)
  66. #if defined(CONFIG_MTK_FPGA)
  67. #define PMIF_NO_PMIC 1
  68. #else
  69. #define PMIF_NO_PMIC 0
  70. #define PMIF_TIMEOUT 0
  71. #endif
  72. #define PMIF_NORMAL_BOOT 0
  73. #else
  74. #define PMIF_NO_PMIC 1
  75. #define PMIF_TIMEOUT 0
  76. #endif
  77. /* SW ENV header define */
  78. #if (PMIF_PRELOADER)
  79. #include <sync_write.h>
  80. #include <typedefs.h>
  81. #include <gpio.h>
  82. #include <mt6885.h>
  83. #include <pll.h>
  84. #include <pal_log.h>
  85. #define INIT_CRITICAL()
  86. #define ENTER_CRITICAL()
  87. #define EXIT_CRITICAL()
  88. #elif (PMIF_LK)
  89. #include <debug.h>
  90. #include <platform/mt_typedefs.h>
  91. #include <platform/mt_reg_base.h>
  92. #include <platform/mt_gpt.h>
  93. #include <platform/mt_irq.h>
  94. #include <sys/types.h>
  95. #include <platform/sync_write.h>
  96. #include <platform/upmu_hw.h>
  97. #include <pal_log.h>
  98. #include <kernel/thread.h>
  99. #include <string.h>
  100. #define INIT_CRITICAL()
  101. #define ENTER_CRITICAL() enter_critical_section();
  102. #define EXIT_CRITICAL() exit_critical_section();
  103. #elif (PMIF_KERNEL)
  104. #elif (PMIF_CTP)
  105. #include <sync_write.h>
  106. #include <typedefs.h>
  107. #include <reg_base.H>
  108. #include <driver_api.h>
  109. #define INIT_CRITICAL()
  110. #define ENTER_CRITICAL()
  111. #define EXIT_CRITICAL()
  112. #else
  113. ### Compile error, check SW ENV define
  114. #endif
  115. /* DEBUG MARCO */
  116. #define PMIFTAG "[PMIF] "
  117. #if (PMIF_PRELOADER)
  118. #if PMIF_DEBUG
  119. #define PMIF_CRI(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
  120. #define PMIF_CRIL(fmt, arg...) pal_log_err(fmt, ##arg)
  121. #define PMIF_ERR(fmt, arg...) \
  122. pal_log_err(PMIFTAG "%d: "fmt, __LINE__, ##arg)
  123. #define PMIF_WARN(fmt, arg...) pal_log_warn(PMIFTAG fmt, ##arg)
  124. #define PMIF_INFO(fmt, arg...) pal_log_info(PMIFTAG fmt, ##arg)
  125. #define PMIF_DBG(fmt, arg...) pal_log_debug(PMIFTAG fmt, ##arg)
  126. #else
  127. #define PMIF_CRI(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
  128. #define PMIF_CRIL(fmt, arg...) pal_log_err(fmt, ##arg)
  129. #define PMIF_ERR(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
  130. #define PMIF_WARN(fmt, arg...) pal_log_info(PMIFTAG fmt, ##arg)
  131. #define PMIF_INFO(fmt, arg...) do { } while(0)
  132. #define PMIF_DBG(fmt, arg...) do { } while(0)
  133. #endif
  134. #elif (PMIF_LK)
  135. #if PMIF_DEBUG
  136. #define PMIF_CRI(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
  137. #define PMIF_CRIL(fmt, arg...) pal_log_err(fmt, ##arg)
  138. #define PMIF_ERR(fmt, arg...) \
  139. pal_log_err(PMIFTAG "%d: "fmt, __LINE__, ##arg)
  140. #define PMIF_WARN(fmt, arg...) pal_log_warn(PMIFTAG fmt, ##arg)
  141. #define PMIF_INFO(fmt, arg...) pal_log_info(PMIFTAG fmt, ##arg)
  142. #define PMIF_DBG(fmt, arg...) pal_log_debug(PMIFTAG fmt, ##arg)
  143. #else
  144. #define PMIF_CRI(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
  145. #define PMIF_CRIL(fmt, arg...) pal_log_err(fmt, ##arg)
  146. #define PMIF_ERR(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
  147. #define PMIF_WARN(fmt, arg...) pal_log_info(PMIFTAG fmt, ##arg)
  148. #define PMIF_INFO(fmt, arg...) do { } while(0)
  149. #define PMIF_DBG(fmt, arg...) do { } while(0)
  150. #endif
  151. #elif (PMIF_KERNEL)
  152. #elif (PMIF_CTP)
  153. #ifdef PMIF_DEBUG
  154. #define PMIF_CRI(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
  155. #define PMIF_CRIL(fmt, arg...) dbg_print(fmt, ##arg)
  156. #define PMIF_ERR(fmt, arg...) \
  157. dbg_print(PMIFTAG "%d: "fmt, __LINE__, ##arg)
  158. #define PMIF_WARN(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
  159. #define PMIF_INFO(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
  160. #define PMIF_DBG(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
  161. #else
  162. #define PMIF_CRI(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
  163. #define PMIF_CRIL(fmt, arg...) dbg_print(fmt, ##arg)
  164. #define PMIF_ERR(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
  165. #define PMIF_WARN(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
  166. #define PMIF_INFO(fmt, arg...) do { } while(0)
  167. #define PMIF_DBG(fmt, arg...) do { } while(0)
  168. #endif /* end of #ifdef PMIF_DEBUG */
  169. #else
  170. ### Compile error, check SW ENV define
  171. #endif
  172. /* macro for SWINF_FSM */
  173. #define SWINF_FSM_IDLE (0x00)
  174. #define SWINF_FSM_REQ (0x02)
  175. #define SWINF_FSM_WFDLE (0x04)
  176. #define SWINF_FSM_WFVLDCLR (0x06)
  177. #define SWINF_INIT_DONE (0x01)
  178. /* indicate which number SW channel start, by project */
  179. #define PMIF_SWINF_0_CHAN_NO 4
  180. /* MD: 0, security domain: 1, AP: 2 */
  181. #define PMIF_AP_SWINF_NO 2
  182. /* 0: SPI, 1: SPMI */
  183. #define PMIF_PMIFID 1
  184. #ifndef EIO
  185. #define EIO 5 /* I/O error */
  186. #endif
  187. #ifndef EBUSY
  188. #define EBUSY 16 /* Device or resource busy */
  189. #endif
  190. #ifndef ENODEV
  191. #define ENODEV 19 /* No such device */
  192. #endif
  193. #ifndef EINVAL
  194. #define EINVAL 22 /* Invalid argument */
  195. #endif
  196. #ifndef EOPNOTSUPP
  197. #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
  198. #endif
  199. #ifndef ETIMEDOUT
  200. #define ETIMEDOUT 110 /* Connection timed out */
  201. #endif
  202. extern int spmi_pmif_dbg_init(struct pmif *arb);
  203. #endif /*__PMIF_SW_H__*/