blob: 7d5b17024cdd07c34b7bf304ea59400f0dce5bb7 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* 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) 2017. 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 (0x1000E000U)
44#define DEVAPC0_PD_BASE (0x10207000U)
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#define DEVAPC0_D0_APC_9 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0020))
59#define DEVAPC0_D0_APC_10 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0024))
60#define DEVAPC0_D0_APC_11 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0028))
61#define DEVAPC0_D0_APC_12 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0030))
62#define DEVAPC0_D1_APC_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0100))
63#define DEVAPC0_D1_APC_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0104))
64#define DEVAPC0_D1_APC_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0108))
65#define DEVAPC0_D1_APC_3 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x010C))
66#define DEVAPC0_D1_APC_4 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0110))
67#define DEVAPC0_D1_APC_5 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0114))
68#define DEVAPC0_D1_APC_6 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0118))
69#define DEVAPC0_D1_APC_7 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x011C))
70#define DEVAPC0_D1_APC_8 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0120))
71#define DEVAPC0_D1_APC_9 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0120))
72#define DEVAPC0_D1_APC_10 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0124))
73#define DEVAPC0_D1_APC_11 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0128))
74#define DEVAPC0_D1_APC_12 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0130))
75#define DEVAPC0_D2_APC_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0200))
76#define DEVAPC0_D2_APC_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0204))
77#define DEVAPC0_D2_APC_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0208))
78#define DEVAPC0_D2_APC_3 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x020C))
79#define DEVAPC0_D2_APC_4 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0210))
80#define DEVAPC0_D2_APC_5 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0214))
81#define DEVAPC0_D2_APC_6 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0218))
82#define DEVAPC0_D2_APC_7 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x021C))
83#define DEVAPC0_D2_APC_8 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0220))
84#define DEVAPC0_D2_APC_9 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0220))
85#define DEVAPC0_D2_APC_10 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0224))
86#define DEVAPC0_D2_APC_11 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0228))
87#define DEVAPC0_D2_APC_12 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0230))
88#define DEVAPC0_D3_APC_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0300))
89#define DEVAPC0_D3_APC_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0304))
90#define DEVAPC0_D3_APC_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0308))
91#define DEVAPC0_D3_APC_3 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x030C))
92#define DEVAPC0_D3_APC_4 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0310))
93#define DEVAPC0_D3_APC_5 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0314))
94#define DEVAPC0_D3_APC_6 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0318))
95#define DEVAPC0_D3_APC_7 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x031C))
96#define DEVAPC0_D3_APC_8 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0320))
97#define DEVAPC0_D3_APC_9 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0320))
98#define DEVAPC0_D3_APC_10 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0324))
99#define DEVAPC0_D3_APC_11 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0328))
100#define DEVAPC0_D3_APC_12 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0330))
101#define DEVAPC0_MAS_DOM_GROUP_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0400))
102#define DEVAPC0_MAS_DOM_GROUP_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0404))
103#define DEVAPC0_MAS_DOM_GROUP_2 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0408))
104#define DEVAPC0_MAS_SEC_GROUP_0 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0500))
105#define DEVAPC0_MAS_SEC_GROUP_1 ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0504))
106#define DEVAPC0_APC_CON ((volatile unsigned int*)(DEVAPC0_AO_BASE+0x0F00))
107#define DEVAPC0_PD_APC_CON ((volatile unsigned int*)(DEVAPC0_PD_BASE+0x0F00))
108#define DEVAPC_APC_CON_CTRL (0x1U)
109#define DEVAPC_APC_CON_EN (0x1U)
110#define MASTER_MSDC0 4U
111
112typedef enum {
113 NON_SECURE_TRAN = 0,
114 SECURE_TRAN,
115} E_TRANSACTION;
116
117
118///* DOMAIN_SETUP */
119#define DOMAIN_0 0U
120#define DOMAIN_1 1U
121#define DOMAIN_2 2U
122#define DOMAIN_3 3U
123#define CONN2AP (0xf << 16)//index12 DEVAPC0_MAS_DOM_1
124#define GPU (0xf << 20)//index21 DEVAPC0_MAS_DOM_2
125
126static inline unsigned int uffs(unsigned int x)
127{
128 unsigned int r = 1;
129
130 if (!x)
131 return 0;
132 if (!(x & 0xffff)) {
133 x >>= 16;
134 r += 16;
135 }
136 if (!(x & 0xff)) {
137 x >>= 8;
138 r += 8;
139 }
140 if (!(x & 0xf)) {
141 x >>= 4;
142 r += 4;
143 }
144 if (!(x & 3)) {
145 x >>= 2;
146 r += 2;
147 }
148 if (!(x & 1)) {
149 x >>= 1;
150 r += 1;
151 }
152 return r;
153}
154
155#define reg_read16(reg) __raw_readw(reg)
156#define reg_read32(reg) __raw_readl(reg)
157#define reg_write16(reg,val) __raw_writew(val,reg)
158#define reg_write32(reg,val) __raw_writel(val,reg)
159
160#define reg_set_bits(reg,bs) ((*(volatile u32*)(reg)) |= (u32)(bs))
161#define reg_clr_bits(reg,bs) ((*(volatile u32*)(reg)) &= ~((u32)(bs)))
162
163#define reg_set_field(reg,field,val) \
164 do { \
165 volatile unsigned int tv = reg_read32(reg); \
166 tv &= ~(field); \
167 tv |= ((val) << (uffs((unsigned int)field) - 1)); \
168 reg_write32(reg,tv); \
169 } while(0)
170
171#define reg_get_field(reg,field,val) \
172 do { \
173 volatile unsigned int tv = reg_read32(reg); \
174 val = ((tv & (field)) >> (uffs((unsigned int)field) - 1)); \
175 } while(0)
176
177#define DAPC_SEC_RW_NSEC_RW 0U /* read and write for both secure and non-secure access */
178#define DAPC_SEC_RW 1U /* read and write for secure access */
179#define DAPC_NSEC_RW 2U /* read and write for non-secure access */
180#define DAPC_SEC_DENY_NSEC_DENY 3U /* Any access is prohibited */
181
182#define DAPC_NS_TRANSACTION 0U /* Emit non-secure signal sideband */
183#define DAPC_S_TRANSACTION 1U /* Emit secure signal sideband */
184
185#define MASTER_NFI 0U
186#define MASTER_PWM 2U
187#define MASTER_THERMAL_CTRL 3U
188#define MASTER_MSDC0 4U
189#define MASTER_MSDC1 5U
190#define MASTER_MSDC2 6U
191#define MASTER_MSDC3 7U
192#define MASTER_SPI0 8U
193#define MASTER_SPM 9U
194#define MASTER_DEBUG_SYSTEM 11U
195#define MASTER_AUDIO_AFE 12U
196#define MASTER_APMCU 13U
197#define MASTER_MFG_M0 19U
198#define MASTER_USB30 20U
199#define MASTER_SPI1 22U
200#define MASTER_SPI2 23U
201#define MASTER_SPI3 24U
202#define MASTER_SPI4 25U
203#define MASTER_SPI5 26U
204#define MASTER_SCP 27U
205#define MASTER_USB30_2 28U
206#define MASTER_SFLASH 29U
207#define MASTER_GMAC 30U
208#define MASTER_PCIE0 31U
209#define MASTER_PCIE1 32U
210
211#define MODULE_TRANSACTION(index, is_secure) (is_secure << (index % 32))
212#define DAPC_SET_MASTER_TRANSACTION(devapc_register, is_secure) reg_write32(devapc_register, is_secure)
213
214#define MODULE_DOMAIN(index, domain) (domain << (2 * (index % 16)))
215#define DAPC_SET_MASTER_DOMAIN(devapc_register, domain) reg_write32(devapc_register, domain)
216
217#define MODULE_PERMISSION(index, permission) (permission << (2 * (index % 16)))
218#define DAPC_SET_SLAVE_PERMISSION_DOMAIN_0(devapc_register, permission) reg_write32(devapc_register, permission)
219#define DAPC_SET_SLAVE_PERMISSION_DOMAIN_1(devapc_register, permission) reg_write32(devapc_register, permission)
220#define DAPC_SET_SLAVE_PERMISSION_DOMAIN_2(devapc_register, permission) reg_write32(devapc_register, permission)
221#define DAPC_SET_SLAVE_PERMISSION_DOMAIN_3(devapc_register, permission) reg_write32(devapc_register, permission)
222
223#define INFRA_AO_TOP_LEVEL_CLOCK_GENERATOR 0U
224#define INFRA_AO_INFRASYS_CONFIG_REGS 1U
225/* #define Reserved 2U */
226#define INFRA_AO_PERISYS_CONFIG_REGS 3U
227/* #define Reserved 4U */
228#define INFRA_AO_GPIO_CONTROLLER 5U
229#define INFRA_AO_TOP_LEVEL_SLP_MANAGER 6U
230#define INFRA_AO_TOP_LEVEL_RESET_GENERATOR 7U
231#define INFRA_AO_GPT 8U
232/* #define Reserved 9U */
233#define INFRA_AO_SEJ 10U
234#define INFRA_AO_APMCU_EINT_CONTROLLER 11U
235#define SYS_TIMER_CONTROL_REG 12U
236#define IRRX_CONTROL_REG 13U
237#define INFRA_AO_DEVICE_APC_AO 14U
238#define UART5_REG 15U
239#define INFRA_AO_KPAD_CONTROL_REG 16U
240#define TOP_RTC_REG 17U
241#define SPI4_REG 18U
242#define SPI1_REG 19U
243#define INFRA_AO_GPT2 20U
244#define DRAMC_CH0_REG 21U
245#define DRAMC_CH1_REG 22U
246#define DRAMC_CH2_REG 23U
247#define DRAMC_CH3_REG 24U
248#define INFRASYS_MCUSYS_CONFIG_REG 25U
249#define INFRASYS_CONTROL_REG 26U
250#define INFRASYS_BOOTROM_SRAM 27U
251#define INFRASYS_EMI_BUS_INTERFACE 28U
252#define INFRASYS_SYSTEM_CIRQ 29U
253#define INFRASYS_M4U_CONFIGURATION 30U
254#define INFRASYS_EFUSEC 31U
255#define INFRASYS_DEVICE_APC_MONITOR 32U
256#define BUS_DEBUG_TRAKER 33U
257#define INFRASYS_AP_MIXED_CONTROL_REG 34U
258#define INFRASYS_M4U_2_CONFIGURATION 35U
259#define ANA_MIPI_DSI3 36U
260/* #define Reserved 37U */
261#define INFRASYS_MBIST_CONTROL_REG 38U
262#define INFRASYS_EMI_MPU_CONTROL_REG 39U
263#define INFRASYS_TRNG 40U
264#define INFRASYS_GCPU 41U
265#define INFRASYS_GCPU_NS 42U
266#define INFRASYS_CQ_DMA 43U
267#define INFRASYS_GCPU_M4U 44U
268#define ANA_MIPI_DSI2 45U
269#define ANA_MIPI_DSI0 46U
270#define ANA_MIPI_DSI1 47U
271#define ANA_MIPI_CSI0 48U
272#define ANA_MIPI_CSI1 49U
273/* #define Reserved 50U */
274#define DEGBUG_CORESIGHT 51U
275#define DMA 52U
276#define AUXADC 53U
277#define UART0 54U
278#define UART1 55U
279#define UART2 56U
280#define UART3 57U
281#define PWM 58U
282#define I2C0 59U
283#define I2C1 60U
284#define I2C2 61U
285#define SPI0 62U
286#define THERM_CTRL 63U
287/* #define Reserved 64U */
288#define SPI_NOR 65U
289#define NFI 66U
290#define NFI_ECC 67U
291#define I2C3 68U
292#define I2C4 69U
293/* #define Reserved 70U */
294#define I2C5 71U
295/* #define Reserved 72U */
296#define SPI2 73U
297#define SPI3 74U
298/* #define Reserved 75U */
299/* #define Reserved 76U */
300#define UART4 77U
301/* #define Reserved 78U */
302#define GMAC 79U
303/* #define Reserved 80U */
304/* #define Reserved 81U */
305#define AUDIO 82U
306#define MSDC0 83U
307#define MSDC1 84U
308#define MSDC2 85U
309#define MSDC3 86U
310#define USB3_0 87U
311#define USB3_0SIF 88U
312#define USB3_0SIF2 89U
313#define USB3_0_2 90U
314#define USB3_0SIF_2 91U
315#define USB3_0SIF2_2 92U
316#define SCPSYS_SRAM 93U
317#define PCIe0 94U
318#define PCIe1 95U
319#define G3D_CONFIG 96U
320#define MMSYS_CONFIG 97U
321#define MDP_RDMA0 98U
322#define MDP_RDMA1 99U
323#define MDP_RSZ0 100U
324#define MDP_RSZ1 101U
325#define MDP_RSZ2 102U
326#define MDP_WDMA 103U
327#define MDP_WROT0 104U
328#define MDP_WROT1 105U
329#define MDP_TDSHP0 106U
330#define MDP_TDSHP1 107U
331/* #define Reserved 108U */
332#define DISP_OVL0 109U
333#define DISP_OVL1 110U
334#define DISP_RDMA0 111U
335#define DISP_RDMA1 112U
336#define DISP_RDMA2 113U
337#define DISP_WDMA0 114U
338#define DISP_WDMA1 115U
339#define DISP_COLOR0 116U
340#define DISP_COLOR1 117U
341#define DISP_AAL 118U
342#define DISP_GAMMA 119U
343/* #define Reserved 120U */
344#define DISP_SPLIT0 121U
345/* #define Reserved 122U */
346#define DISP_UFOE 123U
347#define DSI0 124U
348#define DSI1 125U
349#define DPI 126U
350#define DISP_PWM0 127U
351#define DISP_PWM1 128U
352#define MM_MUTEX 129U
353#define SMI_LARB0 130U
354#define SMI_COMMON 131U
355#define DISP_OD 132U
356#define DPI1 133U
357/* #define Reserved 134U */
358#define LVDS 135U
359#define SMI_LARB4 136U
360#define MDP_RDMA2 137U
361#define DISP_COLOR2 138U
362#define DISP_AAL1 139U
363#define DISP_OD1 140U
364#define DISP_OVL2 141U
365#define DISP_WDMA2 142U
366#define LVDS1 143U
367#define MDP_TDSHP2 144U
368#define SMI_LARB5 145U
369#define SMI_COMMON1 146U
370#define SMI_LARB7 147U
371#define MDP_RDMA3 148U
372#define MDP_WROT2 149U
373#define DSI2 150U
374#define DSI3 151U
375/* #define Reserved 152U */
376#define DISP_MONITOR0 153U
377#define DISP_MONITOR1 154U
378#define DISP_MONITOR2 155U
379#define DISP_MONITOR3 156U
380#define DISP_PWM2 157U
381#define IMGSYS_CONFIG 158U
382#define SMI_LARB2 159U
383#define SENINF_TOP0 160U
384#define SENINF_TOP1 161U
385#define CAMSV_TOP0 162U
386#define CAMSV_TOP1 163U
387#define CAMSV_TOP2 164U
388#define CAMSV_TOP3 165U
389#define CAMSV_TOP4 166U
390#define CAMSV_TOP5 167U
391/* #define Reserved 168U */
392/* #define Reserved 169U */
393/* #define Reserved 170U */
394/* #define Reserved 171U */
395/* #define Reserved 172U */
396/* #define Reserved 173U */
397#define BDP_DISPSYS_CONFIG 174U
398#define BDP_DISPFMT 175U
399#define BDP_VDO 176U
400#define BDP_NR 177U
401#define BDP_NR2 178U
402#define BDP_TVD 179U
403#define BDP_WR_CHANNEL_DI 180U
404#define BDP_WR_CHANNEL_VDI 181U
405#define BDP_LARB 182U
406#define BDP_LARB_RT 183U
407#define BDP_DRAM2AXI_BRIDGE 184U
408#define VDECSYS_CONFIGURATION 185U
409#define VDECSYS_SMI_LARB1 186U
410#define VDEC_FULL_TOP 187U
411#define IMGRZ 188U
412#define VDEC_MBIST 189U
413#define JPGDEC_CONFIGURATION 190U
414#define JPDEC 191U
415#define JPDGDEC1 192U
416/* #define Reserved 193U */
417#define VENC_CONFIGURATION 194U
418#define VENC_SMI_LARB3 195U
419#define VENC_SMI_LARB6 196U
420#define SMI_COMMON_2 197U
421#define VENC 198U
422/* #define Reserved 199U */
423#define SFLASH 200U
424
425extern void device_APC_dom_setup(void);
426extern void tz_dapc_sec_setting(void);
427#endif