rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 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 __SPMI_SW_H__ |
| 38 | #define __SPMI_SW_H__ |
| 39 | |
| 40 | #define SPMI_PRELOADER 0 |
| 41 | #define SPMI_LK 0 |
| 42 | #define SPMI_KERNEL 0 |
| 43 | #define SPMI_CTP 0 |
| 44 | #define SPMI_MD 1 |
| 45 | |
| 46 | /* SW ENV define */ |
| 47 | #define SPMI_DEBUG 0 |
| 48 | #define SPMI_EXTADDR_SUPPORT 0 |
| 49 | #define SPMI_MONITOR_SUPPORT 0 |
| 50 | #define SPMI_RCS_SUPPORT 0 |
| 51 | /* for evb or fpga used */ |
| 52 | #define MT63xx_EVB 1 |
| 53 | |
| 54 | /* For BringUp. if BringUp doesn't had PMIC, need open this */ |
| 55 | #if (SPMI_PRELOADER) |
| 56 | #if CFG_FPGA_PLATFORM |
| 57 | #define SPMI_NO_PMIC 1 |
| 58 | #else |
| 59 | #define SPMI_NO_PMIC 0 |
| 60 | #define SPMI_TIMEOUT 0 |
| 61 | #endif |
| 62 | #elif (SPMI_LK) |
| 63 | #if defined(MACH_FPGA) |
| 64 | #define SPMI_NO_PMIC 1 |
| 65 | #else |
| 66 | #define SPMI_NO_PMIC 0 |
| 67 | #define SPMI_TIMEOUT 0 |
| 68 | #endif |
| 69 | #elif (SPMI_CTP) |
| 70 | #if defined(CONFIG_MTK_FPGA) |
| 71 | #define SPMI_NO_PMIC 1 |
| 72 | #else |
| 73 | #define SPMI_NO_PMIC 0 |
| 74 | #define SPMI_TIMEOUT 0 |
| 75 | #endif |
| 76 | #elif (SPMI_MD) |
| 77 | #ifdef __FPGA__ |
| 78 | #define SPMI_NO_PMIC 1 |
| 79 | #else |
| 80 | #define SPMI_NO_PMIC 0 |
| 81 | #define SPMI_TIMEOUT 0 |
| 82 | #endif |
| 83 | #else |
| 84 | #define SPMI_NO_PMIC 1 |
| 85 | #define SPMI_TIMEOUT 0 |
| 86 | #endif |
| 87 | |
| 88 | /* SW ENV header define */ |
| 89 | #if (SPMI_PRELOADER) |
| 90 | #include <sync_write.h> |
| 91 | #include <typedefs.h> |
| 92 | #include <gpio.h> |
| 93 | #include <mt6885.h> |
| 94 | #include <pll.h> |
| 95 | #include <pal_log.h> |
| 96 | #elif (SPMI_LK) |
| 97 | #include <debug.h> |
| 98 | #include <platform/mt_typedefs.h> |
| 99 | #include <platform/mt_reg_base.h> |
| 100 | #include <platform/mt_gpt.h> |
| 101 | #include <platform/mt_irq.h> |
| 102 | #include <sys/types.h> |
| 103 | #include <platform/sync_write.h> |
| 104 | #include <platform/upmu_hw.h> |
| 105 | #include <pal_log.h> |
| 106 | #elif (SPMI_KERNEL) |
| 107 | #elif (SPMI_CTP) |
| 108 | #include <sync_write.h> |
| 109 | #include <typedefs.h> |
| 110 | #include <reg_base.H> |
| 111 | #include <driver_api.h> |
| 112 | #include <common.h> |
| 113 | #include <kallsyms.h> |
| 114 | #elif (SPMI_MD) |
| 115 | #include "reg_base.h" |
| 116 | #include "drv_comm.h" |
| 117 | #include "init.h" |
| 118 | #include "dcl.h" |
| 119 | #include "kal_public_api.h" |
| 120 | #include "kal_public_defs.h" |
| 121 | #include "us_timer.h" |
| 122 | #include "event_info_utility.h" // for MODEM_WARNING_MESSAGE |
| 123 | #else |
| 124 | ### Compile error, check SW ENV define |
| 125 | #endif |
| 126 | |
| 127 | /* DEBUG MARCO */ |
| 128 | #define SPMITAG "[SPMI] " |
| 129 | #if (SPMI_PRELOADER) |
| 130 | #if SPMI_DEBUG |
| 131 | #define SPMI_CRI(fmt, arg...) pal_log_err(SPMITAG fmt, ##arg) |
| 132 | #define SPMI_CRIL(fmt, arg...) pal_log_err(fmt, ##arg) |
| 133 | #define SPMI_ERR(fmt, arg...) \ |
| 134 | pal_log_err(SPMITAG "%d: "fmt, __LINE__, ##arg) |
| 135 | #define SPMI_WARN(fmt, arg...) pal_log_warn(SPMITAG fmt, ##arg) |
| 136 | #define SPMI_INFO(fmt, arg...) pal_log_info(SPMITAG fmt, ##arg) |
| 137 | #define SPMI_DBG(fmt, arg...) pal_log_debug(SPMITAG fmt, ##arg) |
| 138 | #else |
| 139 | #define SPMI_CRI(fmt, arg...) pal_log_err(SPMITAG fmt, ##arg) |
| 140 | #define SPMI_CRIL(fmt, arg...) pal_log_err(fmt, ##arg) |
| 141 | #define SPMI_ERR(fmt, arg...) \ |
| 142 | pal_log_err(SPMITAG "%d: "fmt, __LINE__, ##arg) |
| 143 | #define SPMI_WARN(fmt, arg...) pal_log_info(SPMITAG fmt, ##arg) |
| 144 | #define SPMI_INFO(fmt, arg...) do { } while(0) |
| 145 | #define SPMI_DBG(fmt, arg...) do { } while(0) |
| 146 | #endif |
| 147 | #elif (SPMI_LK) |
| 148 | #if SPMI_DEBUG |
| 149 | #define SPMI_CRI(fmt, arg...) pal_log_err(SPMITAG fmt, ##arg) |
| 150 | #define SPMI_CRIL(fmt, arg...) pal_log_err(fmt, ##arg) |
| 151 | #define SPMI_ERR(fmt, arg...) \ |
| 152 | pal_log_err(SPMITAG "%d: "fmt, __LINE__, ##arg) |
| 153 | #define SPMI_WARN(fmt, arg...) pal_log_warn(SPMITAG fmt, ##arg) |
| 154 | #define SPMI_INFO(fmt, arg...) pal_log_info(SPMITAG fmt, ##arg) |
| 155 | #define SPMI_DBG(fmt, arg...) pal_log_debug(SPMITAG fmt, ##arg) |
| 156 | #else |
| 157 | #define SPMI_CRI(fmt, arg...) pal_log_err(SPMITAG fmt, ##arg) |
| 158 | #define SPMI_CRIL(fmt, arg...) pal_log_err(fmt, ##arg) |
| 159 | #define SPMI_ERR(fmt, arg...) \ |
| 160 | pal_log_err(SPMITAG "%d: "fmt, __LINE__, ##arg) |
| 161 | #define SPMI_WARN(fmt, arg...) pal_log_info(SPMITAG fmt, ##arg) |
| 162 | #define SPMI_INFO(fmt, arg...) do { } while(0) |
| 163 | #define SPMI_DBG(fmt, arg...) do { } while(0) |
| 164 | #endif |
| 165 | #elif (SPMI_KERNEL) |
| 166 | #elif (SPMI_CTP) |
| 167 | #ifdef SPMI_DEBUG |
| 168 | #define SPMI_CRI(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 169 | #define SPMI_CRIL(fmt, arg...) dbg_print(fmt, ##arg) |
| 170 | #define SPMI_ERR(fmt, arg...) \ |
| 171 | dbg_print(SPMITAG "%d: "fmt, __LINE__, ##arg) |
| 172 | #define SPMI_WARN(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 173 | #define SPMI_INFO(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 174 | #define SPMI_DBG(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 175 | #else |
| 176 | #define SPMI_CRI(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 177 | #define SPMI_CRIL(fmt, arg...) dbg_print(fmt, ##arg) |
| 178 | #define SPMI_ERR(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 179 | #define SPMI_WARN(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 180 | #define SPMI_INFO(fmt, arg...) do { } while(0) |
| 181 | #define SPMI_DBG(fmt, arg...) do { } while(0) |
| 182 | #endif /* end of #ifdef SPMI_DEBUG */ |
| 183 | #elif (SPMI_MD) |
| 184 | #if defined(DRV_DEBUG) || defined(ATEST_DRV_ENABLE) |
| 185 | #ifdef SPMI_DEBUG |
| 186 | #define SPMI_CRI(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 187 | #define SPMI_CRIL(fmt, arg...) dbg_print(fmt, ##arg) |
| 188 | #define SPMI_ERR(fmt, arg...) \ |
| 189 | dbg_print(SPMITAG "%d: "fmt, __LINE__, ##arg) |
| 190 | #define SPMI_WARN(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 191 | #define SPMI_INFO(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 192 | #define SPMI_DBG(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 193 | #else |
| 194 | #define SPMI_CRI(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 195 | #define SPMI_CRIL(fmt, arg...) dbg_print(fmt, ##arg) |
| 196 | #define SPMI_ERR(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 197 | #define SPMI_WARN(fmt, arg...) dbg_print(SPMITAG fmt, ##arg) |
| 198 | #define SPMI_INFO(fmt, arg...) do { } while(0) |
| 199 | #define SPMI_DBG(fmt, arg...) do { } while(0) |
| 200 | #endif /* end of #ifdef SPMI_DEBUG */ |
| 201 | #else |
| 202 | #define SPMI_CRI(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__) |
| 203 | #define SPMI_CRIL(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__) |
| 204 | #define SPMI_ERR(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__) |
| 205 | #define SPMI_WARN(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__) |
| 206 | #define SPMI_INFO(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__) |
| 207 | #define SPMI_DBG(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__) |
| 208 | #endif |
| 209 | #else |
| 210 | ### Compile error, check SW ENV define |
| 211 | #endif |
| 212 | |
| 213 | #define DEFAULT_VALUE_READ_TEST (0x5a) |
| 214 | #define DEFAULT_VALUE_WRITE_TEST (0xa5) |
| 215 | |
| 216 | #define GET_REC_CMD(x) (x & 0x00000003) |
| 217 | #define GET_REC_W(x) ((x>>2) & 0x00000001) |
| 218 | #define GET_REC_OP_ST_NACK(x) ((x>>3) & 0x00000001) |
| 219 | #define GET_REC_PMIF_NACK(x) ((x>>4) & 0x00000001) |
| 220 | #define GET_REC_PMIF_PARITY_ERR(x) ((x>>5) & 0x00000001) |
| 221 | #define GET_REC_PMIF_BYTE_ERR(x) ((x>>6) & 0x00000001) |
| 222 | #define GET_REC_PMIF_GRP_RD_ERR(x) ((x>>7) & 0x00000001) |
| 223 | #define GET_REC_SLVID(x) ((x>>8) & 0x0000000f) |
| 224 | #define GET_REC_BYTECNT(x) ((x>>12) & 0x0000000f) |
| 225 | #define GET_REC_ADDR(x) ((x>>16) & 0x0000ffff) |
| 226 | |
| 227 | /* macro for spmi clock config */ |
| 228 | #define WDT_SWSYSRST2 (TOPRGU_BASE+0x090) |
| 229 | #define CLK_CFG_UPDATE2 (TOPCKGEN_BASE+0x00c) |
| 230 | #define CLK_CFG_16_CLR (TOPCKGEN_BASE+0x118) |
| 231 | |
| 232 | struct cali { |
| 233 | unsigned int dly; |
| 234 | unsigned int pol; |
| 235 | }; |
| 236 | |
| 237 | enum |
| 238 | { |
| 239 | SPMI_CK_NO_DLY = 0, |
| 240 | SPMI_CK_DLY_1T |
| 241 | }; |
| 242 | |
| 243 | enum |
| 244 | { |
| 245 | SPMI_CK_POL_NEG = 0, |
| 246 | SPMI_CK_POL_POS |
| 247 | }; |
| 248 | |
| 249 | enum |
| 250 | { |
| 251 | SPMI_OP_ST_BUSY = 1, |
| 252 | SPMI_OP_ST_ACK = 0, |
| 253 | SPMI_OP_ST_NACK = 1 |
| 254 | }; |
| 255 | |
| 256 | enum |
| 257 | { |
| 258 | SPMI_RCS_SR_BIT, |
| 259 | SPMI_RCS_A_BIT |
| 260 | }; |
| 261 | |
| 262 | enum |
| 263 | { |
| 264 | SPMI_RCS_MST_W = 1, |
| 265 | SPMI_RCS_SLV_W = 3 |
| 266 | }; |
| 267 | |
| 268 | enum |
| 269 | { |
| 270 | SPMI_RESET = 0, |
| 271 | SPMI_SLEEP, |
| 272 | SPMI_SHUTDOWN, |
| 273 | SPMI_WAKEUP |
| 274 | }; |
| 275 | |
| 276 | enum spmi_regs { |
| 277 | SPMI_OP_ST_CTRL, |
| 278 | SPMI_GRP_ID_EN, |
| 279 | SPMI_OP_ST_STA, |
| 280 | SPMI_MST_SAMPL, |
| 281 | SPMI_MST_REQ_EN, |
| 282 | /* RCS support */ |
| 283 | #if SPMI_RCS_SUPPORT |
| 284 | SPMI_RCS_CTRL, |
| 285 | SPMI_SLV_3_0_EINT, |
| 286 | SPMI_SLV_7_4_EINT, |
| 287 | SPMI_SLV_B_8_EINT, |
| 288 | SPMI_SLV_F_C_EINT, |
| 289 | #endif |
| 290 | SPMI_REC_CTRL, |
| 291 | SPMI_REC0, |
| 292 | SPMI_REC1, |
| 293 | SPMI_REC2, |
| 294 | SPMI_REC3, |
| 295 | SPMI_REC4, |
| 296 | #if SPMI_RCS_SUPPORT |
| 297 | SPMI_REC_CMD_DEC, |
| 298 | SPMI_DEC_DBG, |
| 299 | #endif |
| 300 | SPMI_MST_DBG |
| 301 | }; |
| 302 | |
| 303 | extern struct spmi_device *get_spmi_device(int mstid, unsigned int slv_type); |
| 304 | extern int spmi_init(struct pmif *pmif_arb); |
| 305 | |
| 306 | /* pmif debug API declaration */ |
| 307 | extern void spmi_dump_pmif_reg(int mstid); |
| 308 | extern void spmi_dump_pmif_record_reg(int mstid); |
| 309 | extern void spmi_dump_pmif_swinf_reg(int mstid); |
| 310 | extern void spmi_dump_pmif_busy_reg(int mstid); |
| 311 | /* spmi debug API declaration */ |
| 312 | extern void spmi_dump_spmimst_reg(int mstid); |
| 313 | /* pmic debug API declaration */ |
| 314 | extern void spmi_dump_slv_record_reg(struct spmi_device *dev); |
| 315 | |
| 316 | #endif /*__SPMI_SW_H__*/ |