rjw | 1f88458 | 2022-01-06 17:20:42 +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) 2016. 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 | |
| 38 | #ifndef __DEVICE_APC_H__ |
| 39 | #define __DEVICE_APC_H__ |
| 40 | |
| 41 | #include "typedefs.h" |
| 42 | |
| 43 | #define DEVAPC0_AO_BASE 0x10007000 // for AP |
| 44 | #define DEVAPC0_PD_BASE 0x10207000 // for AP |
| 45 | |
| 46 | /******************************************************************************* |
| 47 | * REGISTER ADDRESS DEFINATION |
| 48 | ******************************************************************************/ |
| 49 | #define DEVAPC0_D0_APC_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0000)) |
| 50 | #define DEVAPC0_D0_APC_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0004)) |
| 51 | #define DEVAPC0_D0_APC_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0008)) |
| 52 | #define DEVAPC0_D0_APC_3 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x000C)) |
| 53 | #define DEVAPC0_D0_APC_4 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0010)) |
| 54 | #define DEVAPC0_D0_APC_5 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0014)) |
| 55 | #define DEVAPC0_D0_APC_6 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0018)) |
| 56 | #define DEVAPC0_D0_APC_7 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x001C)) |
| 57 | #define DEVAPC0_D0_APC_8 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0020)) |
| 58 | |
| 59 | #define DEVAPC0_D1_APC_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0100)) |
| 60 | #define DEVAPC0_D1_APC_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0104)) |
| 61 | #define DEVAPC0_D1_APC_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0108)) |
| 62 | #define DEVAPC0_D1_APC_3 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x010C)) |
| 63 | #define DEVAPC0_D1_APC_4 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0110)) |
| 64 | #define DEVAPC0_D1_APC_5 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0114)) |
| 65 | #define DEVAPC0_D1_APC_6 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0118)) |
| 66 | #define DEVAPC0_D1_APC_7 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x011C)) |
| 67 | #define DEVAPC0_D1_APC_8 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0120)) |
| 68 | |
| 69 | #define DEVAPC0_D2_APC_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0200)) |
| 70 | #define DEVAPC0_D2_APC_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0204)) |
| 71 | #define DEVAPC0_D2_APC_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0208)) |
| 72 | #define DEVAPC0_D2_APC_3 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x020C)) |
| 73 | #define DEVAPC0_D2_APC_4 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0210)) |
| 74 | #define DEVAPC0_D2_APC_5 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0214)) |
| 75 | #define DEVAPC0_D2_APC_6 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0218)) |
| 76 | #define DEVAPC0_D2_APC_7 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x021C)) |
| 77 | #define DEVAPC0_D2_APC_8 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0220)) |
| 78 | |
| 79 | #define DEVAPC0_D3_APC_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0300)) |
| 80 | #define DEVAPC0_D3_APC_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0304)) |
| 81 | #define DEVAPC0_D3_APC_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0308)) |
| 82 | #define DEVAPC0_D3_APC_3 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x030C)) |
| 83 | #define DEVAPC0_D3_APC_4 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0310)) |
| 84 | #define DEVAPC0_D3_APC_5 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0314)) |
| 85 | #define DEVAPC0_D3_APC_6 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0318)) |
| 86 | #define DEVAPC0_D3_APC_7 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x031C)) |
| 87 | #define DEVAPC0_D3_APC_8 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0320)) |
| 88 | |
| 89 | #if defined(MACH_TYPE_MT6735) |
| 90 | |
| 91 | #define DEVAPC0_MAS_DOM_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0A00)) |
| 92 | #define DEVAPC0_MAS_DOM_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0A04)) |
| 93 | #define DEVAPC0_MAS_DOM_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0A08)) |
| 94 | #define DEVAPC0_MAS_SEC ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0B00)) |
| 95 | |
| 96 | #else |
| 97 | |
| 98 | #error "Wrong MACH type" |
| 99 | |
| 100 | #endif |
| 101 | |
| 102 | #define DEVAPC0_APC_CON ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0F00)) |
| 103 | #define DEVAPC0_APC_LOCK_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0F04)) |
| 104 | #define DEVAPC0_APC_LOCK_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0F08)) |
| 105 | #define DEVAPC0_APC_LOCK_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0F0C)) |
| 106 | #define DEVAPC0_APC_LOCK_3 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0F10)) |
| 107 | #define DEVAPC0_APC_LOCK_4 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0F14)) |
| 108 | |
| 109 | #define DEVAPC0_PD_APC_CON ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0F00)) |
| 110 | #define DEVAPC0_D0_VIO_MASK_0 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0000)) |
| 111 | #define DEVAPC0_D0_VIO_MASK_1 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0004)) |
| 112 | #define DEVAPC0_D0_VIO_MASK_2 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0008)) |
| 113 | #define DEVAPC0_D0_VIO_MASK_3 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x000C)) |
| 114 | #define DEVAPC0_D0_VIO_MASK_4 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0010)) |
| 115 | #define DEVAPC0_D0_VIO_STA_0 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0400)) |
| 116 | #define DEVAPC0_D0_VIO_STA_1 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0404)) |
| 117 | #define DEVAPC0_D0_VIO_STA_2 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0408)) |
| 118 | #define DEVAPC0_D0_VIO_STA_3 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x040C)) |
| 119 | #define DEVAPC0_D0_VIO_STA_4 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0410)) |
| 120 | #define DEVAPC0_VIO_DBG0 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0900)) |
| 121 | #define DEVAPC0_VIO_DBG1 ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0904)) |
| 122 | |
| 123 | #define DEVAPC0_DEC_ERR_CON ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0F80)) |
| 124 | #define DEVAPC0_DEC_ERR_ADDR ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0F84)) |
| 125 | #define DEVAPC0_DEC_ERR_ID ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0F88)) |
| 126 | |
| 127 | |
| 128 | #define DEVAPC_APC_CON_CTRL (0x1 << 0) |
| 129 | #define DEVAPC_APC_CON_EN 0x1 |
| 130 | #define MASTER_MSDC0 4 |
| 131 | #define MASTER_SPI0 7 |
| 132 | |
| 133 | typedef enum { |
| 134 | NON_SECURE_TRAN = 0, |
| 135 | SECURE_TRAN, |
| 136 | } E_TRANSACTION; |
| 137 | |
| 138 | |
| 139 | ///* DOMAIN_SETUP */ |
| 140 | |
| 141 | |
| 142 | #define DOMAIN_0 0 |
| 143 | #define DOMAIN_1 1 |
| 144 | #define DOMAIN_2 2 |
| 145 | #define DOMAIN_3 3 |
| 146 | |
| 147 | #if defined(MACH_TYPE_MT6735) |
| 148 | |
| 149 | #define DOMAIN_4 4 |
| 150 | #define DOMAIN_5 5 |
| 151 | #define DOMAIN_6 6 |
| 152 | |
| 153 | #define CONN2AP (0xf << 16)//index12 DEVAPC0_MAS_DOM_1 |
| 154 | #define MD1_DOMAIN (0xf << 24)//index14 DEVAPC0_MAS_DOM_1 |
| 155 | #define MD3_DOMAIN (0xf << 8)//index18 DEVAPC0_MAS_DOM_2 |
| 156 | #define GPU (0xf << 20)//index21 DEVAPC0_MAS_DOM_2 |
| 157 | |
| 158 | #else |
| 159 | |
| 160 | #error "Wrong MACH type" |
| 161 | |
| 162 | #endif |
| 163 | |
| 164 | static inline unsigned int uffs(unsigned int x) |
| 165 | { |
| 166 | unsigned int r = 1; |
| 167 | |
| 168 | if (!x) |
| 169 | return 0; |
| 170 | if (!(x & 0xffff)) { |
| 171 | x >>= 16; |
| 172 | r += 16; |
| 173 | } |
| 174 | if (!(x & 0xff)) { |
| 175 | x >>= 8; |
| 176 | r += 8; |
| 177 | } |
| 178 | if (!(x & 0xf)) { |
| 179 | x >>= 4; |
| 180 | r += 4; |
| 181 | } |
| 182 | if (!(x & 3)) { |
| 183 | x >>= 2; |
| 184 | r += 2; |
| 185 | } |
| 186 | if (!(x & 1)) { |
| 187 | x >>= 1; |
| 188 | r += 1; |
| 189 | } |
| 190 | return r; |
| 191 | } |
| 192 | |
| 193 | #define reg_read16(reg) __raw_readw(reg) |
| 194 | #define reg_read32(reg) __raw_readl(reg) |
| 195 | #define reg_write16(reg,val) __raw_writew(val,reg) |
| 196 | #define reg_write32(reg,val) __raw_writel(val,reg) |
| 197 | |
| 198 | #define reg_set_bits(reg,bs) ((*(volatile u32*)(reg)) |= (u32)(bs)) |
| 199 | #define reg_clr_bits(reg,bs) ((*(volatile u32*)(reg)) &= ~((u32)(bs))) |
| 200 | |
| 201 | #define reg_set_field(reg,field,val) \ |
| 202 | do { \ |
| 203 | volatile unsigned int tv = reg_read32(reg); \ |
| 204 | tv &= ~(field); \ |
| 205 | tv |= ((val) << (uffs((unsigned int)field) - 1)); \ |
| 206 | reg_write32(reg,tv); \ |
| 207 | } while(0) |
| 208 | |
| 209 | #define reg_get_field(reg,field,val) \ |
| 210 | do { \ |
| 211 | volatile unsigned int tv = reg_read32(reg); \ |
| 212 | val = ((tv & (field)) >> (uffs((unsigned int)field) - 1)); \ |
| 213 | } while(0) |
| 214 | |
| 215 | extern void device_APC_dom_setup(void); |
| 216 | |
| 217 | #endif |