xref: /OK3568_Linux_fs/kernel/drivers/soc/mediatek/mtk-pmic-wrap.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2014 MediaTek Inc.
4*4882a593Smuzhiyun  * Author: Flora Fu, MediaTek
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #include <linux/clk.h>
7*4882a593Smuzhiyun #include <linux/interrupt.h>
8*4882a593Smuzhiyun #include <linux/io.h>
9*4882a593Smuzhiyun #include <linux/kernel.h>
10*4882a593Smuzhiyun #include <linux/module.h>
11*4882a593Smuzhiyun #include <linux/of_device.h>
12*4882a593Smuzhiyun #include <linux/platform_device.h>
13*4882a593Smuzhiyun #include <linux/regmap.h>
14*4882a593Smuzhiyun #include <linux/reset.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_IORD_ARB_EN		0x4
17*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_WACS3_EN		0x10
18*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_INIT_DONE3		0x14
19*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_WACS4_EN		0x24
20*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_INIT_DONE4		0x28
21*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_INT_EN		0x38
22*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_TIMER_EN		0x48
23*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_WDT_UNIT		0x50
24*4882a593Smuzhiyun #define PWRAP_MT8135_BRIDGE_WDT_SRC_EN		0x54
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /* macro for wrapper status */
27*4882a593Smuzhiyun #define PWRAP_GET_WACS_RDATA(x)		(((x) >> 0) & 0x0000ffff)
28*4882a593Smuzhiyun #define PWRAP_GET_WACS_FSM(x)		(((x) >> 16) & 0x00000007)
29*4882a593Smuzhiyun #define PWRAP_GET_WACS_REQ(x)		(((x) >> 19) & 0x00000001)
30*4882a593Smuzhiyun #define PWRAP_STATE_SYNC_IDLE0		(1 << 20)
31*4882a593Smuzhiyun #define PWRAP_STATE_INIT_DONE0		(1 << 21)
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /* macro for WACS FSM */
34*4882a593Smuzhiyun #define PWRAP_WACS_FSM_IDLE		0x00
35*4882a593Smuzhiyun #define PWRAP_WACS_FSM_REQ		0x02
36*4882a593Smuzhiyun #define PWRAP_WACS_FSM_WFDLE		0x04
37*4882a593Smuzhiyun #define PWRAP_WACS_FSM_WFVLDCLR		0x06
38*4882a593Smuzhiyun #define PWRAP_WACS_INIT_DONE		0x01
39*4882a593Smuzhiyun #define PWRAP_WACS_WACS_SYNC_IDLE	0x01
40*4882a593Smuzhiyun #define PWRAP_WACS_SYNC_BUSY		0x00
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /* macro for device wrapper default value */
43*4882a593Smuzhiyun #define PWRAP_DEW_READ_TEST_VAL		0x5aa5
44*4882a593Smuzhiyun #define PWRAP_DEW_WRITE_TEST_VAL	0xa55a
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* macro for manual command */
47*4882a593Smuzhiyun #define PWRAP_MAN_CMD_SPI_WRITE_NEW	(1 << 14)
48*4882a593Smuzhiyun #define PWRAP_MAN_CMD_SPI_WRITE		(1 << 13)
49*4882a593Smuzhiyun #define PWRAP_MAN_CMD_OP_CSH		(0x0 << 8)
50*4882a593Smuzhiyun #define PWRAP_MAN_CMD_OP_CSL		(0x1 << 8)
51*4882a593Smuzhiyun #define PWRAP_MAN_CMD_OP_CK		(0x2 << 8)
52*4882a593Smuzhiyun #define PWRAP_MAN_CMD_OP_OUTS		(0x8 << 8)
53*4882a593Smuzhiyun #define PWRAP_MAN_CMD_OP_OUTD		(0x9 << 8)
54*4882a593Smuzhiyun #define PWRAP_MAN_CMD_OP_OUTQ		(0xa << 8)
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /* macro for Watch Dog Timer Source */
57*4882a593Smuzhiyun #define PWRAP_WDT_SRC_EN_STAUPD_TRIG		(1 << 25)
58*4882a593Smuzhiyun #define PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE	(1 << 20)
59*4882a593Smuzhiyun #define PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE	(1 << 6)
60*4882a593Smuzhiyun #define PWRAP_WDT_SRC_MASK_ALL			0xffffffff
61*4882a593Smuzhiyun #define PWRAP_WDT_SRC_MASK_NO_STAUPD	~(PWRAP_WDT_SRC_EN_STAUPD_TRIG | \
62*4882a593Smuzhiyun 					  PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE | \
63*4882a593Smuzhiyun 					  PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE)
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun /* Group of bits used for shown slave capability */
66*4882a593Smuzhiyun #define PWRAP_SLV_CAP_SPI	BIT(0)
67*4882a593Smuzhiyun #define PWRAP_SLV_CAP_DUALIO	BIT(1)
68*4882a593Smuzhiyun #define PWRAP_SLV_CAP_SECURITY	BIT(2)
69*4882a593Smuzhiyun #define HAS_CAP(_c, _x)	(((_c) & (_x)) == (_x))
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun /* Group of bits used for shown pwrap capability */
72*4882a593Smuzhiyun #define PWRAP_CAP_BRIDGE	BIT(0)
73*4882a593Smuzhiyun #define PWRAP_CAP_RESET		BIT(1)
74*4882a593Smuzhiyun #define PWRAP_CAP_DCM		BIT(2)
75*4882a593Smuzhiyun #define PWRAP_CAP_INT1_EN	BIT(3)
76*4882a593Smuzhiyun #define PWRAP_CAP_WDT_SRC1	BIT(4)
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /* defines for slave device wrapper registers */
79*4882a593Smuzhiyun enum dew_regs {
80*4882a593Smuzhiyun 	PWRAP_DEW_BASE,
81*4882a593Smuzhiyun 	PWRAP_DEW_DIO_EN,
82*4882a593Smuzhiyun 	PWRAP_DEW_READ_TEST,
83*4882a593Smuzhiyun 	PWRAP_DEW_WRITE_TEST,
84*4882a593Smuzhiyun 	PWRAP_DEW_CRC_EN,
85*4882a593Smuzhiyun 	PWRAP_DEW_CRC_VAL,
86*4882a593Smuzhiyun 	PWRAP_DEW_MON_GRP_SEL,
87*4882a593Smuzhiyun 	PWRAP_DEW_CIPHER_KEY_SEL,
88*4882a593Smuzhiyun 	PWRAP_DEW_CIPHER_IV_SEL,
89*4882a593Smuzhiyun 	PWRAP_DEW_CIPHER_RDY,
90*4882a593Smuzhiyun 	PWRAP_DEW_CIPHER_MODE,
91*4882a593Smuzhiyun 	PWRAP_DEW_CIPHER_SWRST,
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	/* MT6323 only regs */
94*4882a593Smuzhiyun 	PWRAP_DEW_CIPHER_EN,
95*4882a593Smuzhiyun 	PWRAP_DEW_RDDMY_NO,
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun 	/* MT6358 only regs */
98*4882a593Smuzhiyun 	PWRAP_SMT_CON1,
99*4882a593Smuzhiyun 	PWRAP_DRV_CON1,
100*4882a593Smuzhiyun 	PWRAP_FILTER_CON0,
101*4882a593Smuzhiyun 	PWRAP_GPIO_PULLEN0_CLR,
102*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON0,
103*4882a593Smuzhiyun 	PWRAP_RG_SPI_RECORD0,
104*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON2,
105*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON3,
106*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON4,
107*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON5,
108*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON6,
109*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON7,
110*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON8,
111*4882a593Smuzhiyun 	PWRAP_RG_SPI_CON13,
112*4882a593Smuzhiyun 	PWRAP_SPISLV_KEY,
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun 	/* MT6359 only regs */
115*4882a593Smuzhiyun 	PWRAP_DEW_CRC_SWRST,
116*4882a593Smuzhiyun 	PWRAP_DEW_RG_EN_RECORD,
117*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_CMD0,
118*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_CMD1,
119*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_CMD2,
120*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_CMD3,
121*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_CMD4,
122*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_CMD5,
123*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_WDATA0,
124*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_WDATA1,
125*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_WDATA2,
126*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_WDATA3,
127*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_WDATA4,
128*4882a593Smuzhiyun 	PWRAP_DEW_RECORD_WDATA5,
129*4882a593Smuzhiyun 	PWRAP_DEW_RG_ADDR_TARGET,
130*4882a593Smuzhiyun 	PWRAP_DEW_RG_ADDR_MASK,
131*4882a593Smuzhiyun 	PWRAP_DEW_RG_WDATA_TARGET,
132*4882a593Smuzhiyun 	PWRAP_DEW_RG_WDATA_MASK,
133*4882a593Smuzhiyun 	PWRAP_DEW_RG_SPI_RECORD_CLR,
134*4882a593Smuzhiyun 	PWRAP_DEW_RG_CMD_ALERT_CLR,
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	/* MT6397 only regs */
137*4882a593Smuzhiyun 	PWRAP_DEW_EVENT_OUT_EN,
138*4882a593Smuzhiyun 	PWRAP_DEW_EVENT_SRC_EN,
139*4882a593Smuzhiyun 	PWRAP_DEW_EVENT_SRC,
140*4882a593Smuzhiyun 	PWRAP_DEW_EVENT_FLAG,
141*4882a593Smuzhiyun 	PWRAP_DEW_MON_FLAG_SEL,
142*4882a593Smuzhiyun 	PWRAP_DEW_EVENT_TEST,
143*4882a593Smuzhiyun 	PWRAP_DEW_CIPHER_LOAD,
144*4882a593Smuzhiyun 	PWRAP_DEW_CIPHER_START,
145*4882a593Smuzhiyun };
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun static const u32 mt6323_regs[] = {
148*4882a593Smuzhiyun 	[PWRAP_DEW_BASE] =		0x0000,
149*4882a593Smuzhiyun 	[PWRAP_DEW_DIO_EN] =		0x018a,
150*4882a593Smuzhiyun 	[PWRAP_DEW_READ_TEST] =		0x018c,
151*4882a593Smuzhiyun 	[PWRAP_DEW_WRITE_TEST] =	0x018e,
152*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_EN] =		0x0192,
153*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_VAL] =		0x0194,
154*4882a593Smuzhiyun 	[PWRAP_DEW_MON_GRP_SEL] =	0x0196,
155*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_KEY_SEL] =	0x0198,
156*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_IV_SEL] =	0x019a,
157*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_EN] =		0x019c,
158*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_RDY] =	0x019e,
159*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_MODE] =	0x01a0,
160*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_SWRST] =	0x01a2,
161*4882a593Smuzhiyun 	[PWRAP_DEW_RDDMY_NO] =		0x01a4,
162*4882a593Smuzhiyun };
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun static const u32 mt6351_regs[] = {
165*4882a593Smuzhiyun 	[PWRAP_DEW_DIO_EN] =		0x02F2,
166*4882a593Smuzhiyun 	[PWRAP_DEW_READ_TEST] =		0x02F4,
167*4882a593Smuzhiyun 	[PWRAP_DEW_WRITE_TEST] =	0x02F6,
168*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_EN] =		0x02FA,
169*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_VAL] =		0x02FC,
170*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_KEY_SEL] =	0x0300,
171*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_IV_SEL] =	0x0302,
172*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_EN] =		0x0304,
173*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_RDY] =	0x0306,
174*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_MODE] =	0x0308,
175*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_SWRST] =	0x030A,
176*4882a593Smuzhiyun 	[PWRAP_DEW_RDDMY_NO] =		0x030C,
177*4882a593Smuzhiyun };
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun static const u32 mt6357_regs[] = {
180*4882a593Smuzhiyun 	[PWRAP_DEW_DIO_EN] =            0x040A,
181*4882a593Smuzhiyun 	[PWRAP_DEW_READ_TEST] =         0x040C,
182*4882a593Smuzhiyun 	[PWRAP_DEW_WRITE_TEST] =        0x040E,
183*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_EN] =            0x0412,
184*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_VAL] =           0x0414,
185*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_KEY_SEL] =    0x0418,
186*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_IV_SEL] =     0x041A,
187*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_EN] =         0x041C,
188*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_RDY] =        0x041E,
189*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_MODE] =       0x0420,
190*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_SWRST] =      0x0422,
191*4882a593Smuzhiyun 	[PWRAP_DEW_RDDMY_NO] =          0x0424,
192*4882a593Smuzhiyun };
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun static const u32 mt6358_regs[] = {
195*4882a593Smuzhiyun 	[PWRAP_SMT_CON1] =		0x0030,
196*4882a593Smuzhiyun 	[PWRAP_DRV_CON1] =		0x0038,
197*4882a593Smuzhiyun 	[PWRAP_FILTER_CON0] =		0x0040,
198*4882a593Smuzhiyun 	[PWRAP_GPIO_PULLEN0_CLR] =	0x0098,
199*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON0] =		0x0408,
200*4882a593Smuzhiyun 	[PWRAP_RG_SPI_RECORD0] =	0x040a,
201*4882a593Smuzhiyun 	[PWRAP_DEW_DIO_EN] =		0x040c,
202*4882a593Smuzhiyun 	[PWRAP_DEW_READ_TEST]	=	0x040e,
203*4882a593Smuzhiyun 	[PWRAP_DEW_WRITE_TEST]	=	0x0410,
204*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_EN] =		0x0414,
205*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_KEY_SEL] =	0x041a,
206*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_IV_SEL] =	0x041c,
207*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_EN]	=	0x041e,
208*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_RDY] =	0x0420,
209*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_MODE] =	0x0422,
210*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_SWRST] =	0x0424,
211*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON2] =		0x0432,
212*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON3] =		0x0434,
213*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON4] =		0x0436,
214*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON5] =		0x0438,
215*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON6] =		0x043a,
216*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON7] =		0x043c,
217*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON8] =		0x043e,
218*4882a593Smuzhiyun 	[PWRAP_RG_SPI_CON13] =		0x0448,
219*4882a593Smuzhiyun 	[PWRAP_SPISLV_KEY] =		0x044a,
220*4882a593Smuzhiyun };
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun static const u32 mt6359_regs[] = {
223*4882a593Smuzhiyun 	[PWRAP_DEW_RG_EN_RECORD] =	0x040a,
224*4882a593Smuzhiyun 	[PWRAP_DEW_DIO_EN] =		0x040c,
225*4882a593Smuzhiyun 	[PWRAP_DEW_READ_TEST] =		0x040e,
226*4882a593Smuzhiyun 	[PWRAP_DEW_WRITE_TEST] =	0x0410,
227*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_SWRST] =		0x0412,
228*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_EN] =		0x0414,
229*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_VAL] =		0x0416,
230*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_KEY_SEL] =	0x0418,
231*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_IV_SEL] =	0x041a,
232*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_EN] =		0x041c,
233*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_RDY] =	0x041e,
234*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_MODE] =	0x0420,
235*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_SWRST] =	0x0422,
236*4882a593Smuzhiyun 	[PWRAP_DEW_RDDMY_NO] =		0x0424,
237*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_CMD0] =	0x0428,
238*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_CMD1] =	0x042a,
239*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_CMD2] =	0x042c,
240*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_CMD3] =	0x042e,
241*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_CMD4] =	0x0430,
242*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_CMD5] =	0x0432,
243*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_WDATA0] =	0x0434,
244*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_WDATA1] =	0x0436,
245*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_WDATA2] =	0x0438,
246*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_WDATA3] =	0x043a,
247*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_WDATA4] =	0x043c,
248*4882a593Smuzhiyun 	[PWRAP_DEW_RECORD_WDATA5] =	0x043e,
249*4882a593Smuzhiyun 	[PWRAP_DEW_RG_ADDR_TARGET] =	0x0440,
250*4882a593Smuzhiyun 	[PWRAP_DEW_RG_ADDR_MASK] =	0x0442,
251*4882a593Smuzhiyun 	[PWRAP_DEW_RG_WDATA_TARGET] =	0x0444,
252*4882a593Smuzhiyun 	[PWRAP_DEW_RG_WDATA_MASK] =	0x0446,
253*4882a593Smuzhiyun 	[PWRAP_DEW_RG_SPI_RECORD_CLR] =	0x0448,
254*4882a593Smuzhiyun 	[PWRAP_DEW_RG_CMD_ALERT_CLR] =	0x0448,
255*4882a593Smuzhiyun 	[PWRAP_SPISLV_KEY] =		0x044a,
256*4882a593Smuzhiyun };
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun static const u32 mt6397_regs[] = {
259*4882a593Smuzhiyun 	[PWRAP_DEW_BASE] =		0xbc00,
260*4882a593Smuzhiyun 	[PWRAP_DEW_EVENT_OUT_EN] =	0xbc00,
261*4882a593Smuzhiyun 	[PWRAP_DEW_DIO_EN] =		0xbc02,
262*4882a593Smuzhiyun 	[PWRAP_DEW_EVENT_SRC_EN] =	0xbc04,
263*4882a593Smuzhiyun 	[PWRAP_DEW_EVENT_SRC] =		0xbc06,
264*4882a593Smuzhiyun 	[PWRAP_DEW_EVENT_FLAG] =	0xbc08,
265*4882a593Smuzhiyun 	[PWRAP_DEW_READ_TEST] =		0xbc0a,
266*4882a593Smuzhiyun 	[PWRAP_DEW_WRITE_TEST] =	0xbc0c,
267*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_EN] =		0xbc0e,
268*4882a593Smuzhiyun 	[PWRAP_DEW_CRC_VAL] =		0xbc10,
269*4882a593Smuzhiyun 	[PWRAP_DEW_MON_GRP_SEL] =	0xbc12,
270*4882a593Smuzhiyun 	[PWRAP_DEW_MON_FLAG_SEL] =	0xbc14,
271*4882a593Smuzhiyun 	[PWRAP_DEW_EVENT_TEST] =	0xbc16,
272*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_KEY_SEL] =	0xbc18,
273*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_IV_SEL] =	0xbc1a,
274*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_LOAD] =	0xbc1c,
275*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_START] =	0xbc1e,
276*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_RDY] =	0xbc20,
277*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_MODE] =	0xbc22,
278*4882a593Smuzhiyun 	[PWRAP_DEW_CIPHER_SWRST] =	0xbc24,
279*4882a593Smuzhiyun };
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun enum pwrap_regs {
282*4882a593Smuzhiyun 	PWRAP_MUX_SEL,
283*4882a593Smuzhiyun 	PWRAP_WRAP_EN,
284*4882a593Smuzhiyun 	PWRAP_DIO_EN,
285*4882a593Smuzhiyun 	PWRAP_SIDLY,
286*4882a593Smuzhiyun 	PWRAP_CSHEXT_WRITE,
287*4882a593Smuzhiyun 	PWRAP_CSHEXT_READ,
288*4882a593Smuzhiyun 	PWRAP_CSLEXT_START,
289*4882a593Smuzhiyun 	PWRAP_CSLEXT_END,
290*4882a593Smuzhiyun 	PWRAP_STAUPD_PRD,
291*4882a593Smuzhiyun 	PWRAP_STAUPD_GRPEN,
292*4882a593Smuzhiyun 	PWRAP_STAUPD_MAN_TRIG,
293*4882a593Smuzhiyun 	PWRAP_STAUPD_STA,
294*4882a593Smuzhiyun 	PWRAP_WRAP_STA,
295*4882a593Smuzhiyun 	PWRAP_HARB_INIT,
296*4882a593Smuzhiyun 	PWRAP_HARB_HPRIO,
297*4882a593Smuzhiyun 	PWRAP_HIPRIO_ARB_EN,
298*4882a593Smuzhiyun 	PWRAP_HARB_STA0,
299*4882a593Smuzhiyun 	PWRAP_HARB_STA1,
300*4882a593Smuzhiyun 	PWRAP_MAN_EN,
301*4882a593Smuzhiyun 	PWRAP_MAN_CMD,
302*4882a593Smuzhiyun 	PWRAP_MAN_RDATA,
303*4882a593Smuzhiyun 	PWRAP_MAN_VLDCLR,
304*4882a593Smuzhiyun 	PWRAP_WACS0_EN,
305*4882a593Smuzhiyun 	PWRAP_INIT_DONE0,
306*4882a593Smuzhiyun 	PWRAP_WACS0_CMD,
307*4882a593Smuzhiyun 	PWRAP_WACS0_RDATA,
308*4882a593Smuzhiyun 	PWRAP_WACS0_VLDCLR,
309*4882a593Smuzhiyun 	PWRAP_WACS1_EN,
310*4882a593Smuzhiyun 	PWRAP_INIT_DONE1,
311*4882a593Smuzhiyun 	PWRAP_WACS1_CMD,
312*4882a593Smuzhiyun 	PWRAP_WACS1_RDATA,
313*4882a593Smuzhiyun 	PWRAP_WACS1_VLDCLR,
314*4882a593Smuzhiyun 	PWRAP_WACS2_EN,
315*4882a593Smuzhiyun 	PWRAP_INIT_DONE2,
316*4882a593Smuzhiyun 	PWRAP_WACS2_CMD,
317*4882a593Smuzhiyun 	PWRAP_WACS2_RDATA,
318*4882a593Smuzhiyun 	PWRAP_WACS2_VLDCLR,
319*4882a593Smuzhiyun 	PWRAP_INT_EN,
320*4882a593Smuzhiyun 	PWRAP_INT_FLG_RAW,
321*4882a593Smuzhiyun 	PWRAP_INT_FLG,
322*4882a593Smuzhiyun 	PWRAP_INT_CLR,
323*4882a593Smuzhiyun 	PWRAP_SIG_ADR,
324*4882a593Smuzhiyun 	PWRAP_SIG_MODE,
325*4882a593Smuzhiyun 	PWRAP_SIG_VALUE,
326*4882a593Smuzhiyun 	PWRAP_SIG_ERRVAL,
327*4882a593Smuzhiyun 	PWRAP_CRC_EN,
328*4882a593Smuzhiyun 	PWRAP_TIMER_EN,
329*4882a593Smuzhiyun 	PWRAP_TIMER_STA,
330*4882a593Smuzhiyun 	PWRAP_WDT_UNIT,
331*4882a593Smuzhiyun 	PWRAP_WDT_SRC_EN,
332*4882a593Smuzhiyun 	PWRAP_WDT_FLG,
333*4882a593Smuzhiyun 	PWRAP_DEBUG_INT_SEL,
334*4882a593Smuzhiyun 	PWRAP_CIPHER_KEY_SEL,
335*4882a593Smuzhiyun 	PWRAP_CIPHER_IV_SEL,
336*4882a593Smuzhiyun 	PWRAP_CIPHER_RDY,
337*4882a593Smuzhiyun 	PWRAP_CIPHER_MODE,
338*4882a593Smuzhiyun 	PWRAP_CIPHER_SWRST,
339*4882a593Smuzhiyun 	PWRAP_DCM_EN,
340*4882a593Smuzhiyun 	PWRAP_DCM_DBC_PRD,
341*4882a593Smuzhiyun 	PWRAP_EINT_STA0_ADR,
342*4882a593Smuzhiyun 	PWRAP_EINT_STA1_ADR,
343*4882a593Smuzhiyun 
344*4882a593Smuzhiyun 	/* MT2701 only regs */
345*4882a593Smuzhiyun 	PWRAP_ADC_CMD_ADDR,
346*4882a593Smuzhiyun 	PWRAP_PWRAP_ADC_CMD,
347*4882a593Smuzhiyun 	PWRAP_ADC_RDY_ADDR,
348*4882a593Smuzhiyun 	PWRAP_ADC_RDATA_ADDR1,
349*4882a593Smuzhiyun 	PWRAP_ADC_RDATA_ADDR2,
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	/* MT7622 only regs */
352*4882a593Smuzhiyun 	PWRAP_STA,
353*4882a593Smuzhiyun 	PWRAP_CLR,
354*4882a593Smuzhiyun 	PWRAP_DVFS_ADR8,
355*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA8,
356*4882a593Smuzhiyun 	PWRAP_DVFS_ADR9,
357*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA9,
358*4882a593Smuzhiyun 	PWRAP_DVFS_ADR10,
359*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA10,
360*4882a593Smuzhiyun 	PWRAP_DVFS_ADR11,
361*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA11,
362*4882a593Smuzhiyun 	PWRAP_DVFS_ADR12,
363*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA12,
364*4882a593Smuzhiyun 	PWRAP_DVFS_ADR13,
365*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA13,
366*4882a593Smuzhiyun 	PWRAP_DVFS_ADR14,
367*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA14,
368*4882a593Smuzhiyun 	PWRAP_DVFS_ADR15,
369*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA15,
370*4882a593Smuzhiyun 	PWRAP_EXT_CK,
371*4882a593Smuzhiyun 	PWRAP_ADC_RDATA_ADDR,
372*4882a593Smuzhiyun 	PWRAP_GPS_STA,
373*4882a593Smuzhiyun 	PWRAP_SW_RST,
374*4882a593Smuzhiyun 	PWRAP_DVFS_STEP_CTRL0,
375*4882a593Smuzhiyun 	PWRAP_DVFS_STEP_CTRL1,
376*4882a593Smuzhiyun 	PWRAP_DVFS_STEP_CTRL2,
377*4882a593Smuzhiyun 	PWRAP_SPI2_CTRL,
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun 	/* MT8135 only regs */
380*4882a593Smuzhiyun 	PWRAP_CSHEXT,
381*4882a593Smuzhiyun 	PWRAP_EVENT_IN_EN,
382*4882a593Smuzhiyun 	PWRAP_EVENT_DST_EN,
383*4882a593Smuzhiyun 	PWRAP_RRARB_INIT,
384*4882a593Smuzhiyun 	PWRAP_RRARB_EN,
385*4882a593Smuzhiyun 	PWRAP_RRARB_STA0,
386*4882a593Smuzhiyun 	PWRAP_RRARB_STA1,
387*4882a593Smuzhiyun 	PWRAP_EVENT_STA,
388*4882a593Smuzhiyun 	PWRAP_EVENT_STACLR,
389*4882a593Smuzhiyun 	PWRAP_CIPHER_LOAD,
390*4882a593Smuzhiyun 	PWRAP_CIPHER_START,
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun 	/* MT8173 only regs */
393*4882a593Smuzhiyun 	PWRAP_RDDMY,
394*4882a593Smuzhiyun 	PWRAP_SI_CK_CON,
395*4882a593Smuzhiyun 	PWRAP_DVFS_ADR0,
396*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA0,
397*4882a593Smuzhiyun 	PWRAP_DVFS_ADR1,
398*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA1,
399*4882a593Smuzhiyun 	PWRAP_DVFS_ADR2,
400*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA2,
401*4882a593Smuzhiyun 	PWRAP_DVFS_ADR3,
402*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA3,
403*4882a593Smuzhiyun 	PWRAP_DVFS_ADR4,
404*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA4,
405*4882a593Smuzhiyun 	PWRAP_DVFS_ADR5,
406*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA5,
407*4882a593Smuzhiyun 	PWRAP_DVFS_ADR6,
408*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA6,
409*4882a593Smuzhiyun 	PWRAP_DVFS_ADR7,
410*4882a593Smuzhiyun 	PWRAP_DVFS_WDATA7,
411*4882a593Smuzhiyun 	PWRAP_SPMINF_STA,
412*4882a593Smuzhiyun 	PWRAP_CIPHER_EN,
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun 	/* MT8183 only regs */
415*4882a593Smuzhiyun 	PWRAP_SI_SAMPLE_CTRL,
416*4882a593Smuzhiyun 	PWRAP_CSLEXT_WRITE,
417*4882a593Smuzhiyun 	PWRAP_CSLEXT_READ,
418*4882a593Smuzhiyun 	PWRAP_EXT_CK_WRITE,
419*4882a593Smuzhiyun 	PWRAP_STAUPD_CTRL,
420*4882a593Smuzhiyun 	PWRAP_WACS_P2P_EN,
421*4882a593Smuzhiyun 	PWRAP_INIT_DONE_P2P,
422*4882a593Smuzhiyun 	PWRAP_WACS_MD32_EN,
423*4882a593Smuzhiyun 	PWRAP_INIT_DONE_MD32,
424*4882a593Smuzhiyun 	PWRAP_INT1_EN,
425*4882a593Smuzhiyun 	PWRAP_INT1_FLG,
426*4882a593Smuzhiyun 	PWRAP_INT1_CLR,
427*4882a593Smuzhiyun 	PWRAP_WDT_SRC_EN_1,
428*4882a593Smuzhiyun 	PWRAP_INT_GPS_AUXADC_CMD_ADDR,
429*4882a593Smuzhiyun 	PWRAP_INT_GPS_AUXADC_CMD,
430*4882a593Smuzhiyun 	PWRAP_INT_GPS_AUXADC_RDATA_ADDR,
431*4882a593Smuzhiyun 	PWRAP_EXT_GPS_AUXADC_RDATA_ADDR,
432*4882a593Smuzhiyun 	PWRAP_GPSINF_0_STA,
433*4882a593Smuzhiyun 	PWRAP_GPSINF_1_STA,
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun 	/* MT8516 only regs */
436*4882a593Smuzhiyun 	PWRAP_OP_TYPE,
437*4882a593Smuzhiyun 	PWRAP_MSB_FIRST,
438*4882a593Smuzhiyun };
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun static int mt2701_regs[] = {
441*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =		0x0,
442*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =		0x4,
443*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =		0x8,
444*4882a593Smuzhiyun 	[PWRAP_SIDLY] =			0xc,
445*4882a593Smuzhiyun 	[PWRAP_RDDMY] =			0x18,
446*4882a593Smuzhiyun 	[PWRAP_SI_CK_CON] =		0x1c,
447*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =		0x20,
448*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =		0x24,
449*4882a593Smuzhiyun 	[PWRAP_CSLEXT_START] =		0x28,
450*4882a593Smuzhiyun 	[PWRAP_CSLEXT_END] =		0x2c,
451*4882a593Smuzhiyun 	[PWRAP_STAUPD_PRD] =		0x30,
452*4882a593Smuzhiyun 	[PWRAP_STAUPD_GRPEN] =		0x34,
453*4882a593Smuzhiyun 	[PWRAP_STAUPD_MAN_TRIG] =	0x38,
454*4882a593Smuzhiyun 	[PWRAP_STAUPD_STA] =		0x3c,
455*4882a593Smuzhiyun 	[PWRAP_WRAP_STA] =		0x44,
456*4882a593Smuzhiyun 	[PWRAP_HARB_INIT] =		0x48,
457*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =		0x4c,
458*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =		0x50,
459*4882a593Smuzhiyun 	[PWRAP_HARB_STA0] =		0x54,
460*4882a593Smuzhiyun 	[PWRAP_HARB_STA1] =		0x58,
461*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =		0x5c,
462*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =		0x60,
463*4882a593Smuzhiyun 	[PWRAP_MAN_RDATA] =		0x64,
464*4882a593Smuzhiyun 	[PWRAP_MAN_VLDCLR] =		0x68,
465*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =		0x6c,
466*4882a593Smuzhiyun 	[PWRAP_INIT_DONE0] =		0x70,
467*4882a593Smuzhiyun 	[PWRAP_WACS0_CMD] =		0x74,
468*4882a593Smuzhiyun 	[PWRAP_WACS0_RDATA] =		0x78,
469*4882a593Smuzhiyun 	[PWRAP_WACS0_VLDCLR] =		0x7c,
470*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =		0x80,
471*4882a593Smuzhiyun 	[PWRAP_INIT_DONE1] =		0x84,
472*4882a593Smuzhiyun 	[PWRAP_WACS1_CMD] =		0x88,
473*4882a593Smuzhiyun 	[PWRAP_WACS1_RDATA] =		0x8c,
474*4882a593Smuzhiyun 	[PWRAP_WACS1_VLDCLR] =		0x90,
475*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =		0x94,
476*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =		0x98,
477*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =		0x9c,
478*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =		0xa0,
479*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =		0xa4,
480*4882a593Smuzhiyun 	[PWRAP_INT_EN] =		0xa8,
481*4882a593Smuzhiyun 	[PWRAP_INT_FLG_RAW] =		0xac,
482*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =		0xb0,
483*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =		0xb4,
484*4882a593Smuzhiyun 	[PWRAP_SIG_ADR] =		0xb8,
485*4882a593Smuzhiyun 	[PWRAP_SIG_MODE] =		0xbc,
486*4882a593Smuzhiyun 	[PWRAP_SIG_VALUE] =		0xc0,
487*4882a593Smuzhiyun 	[PWRAP_SIG_ERRVAL] =		0xc4,
488*4882a593Smuzhiyun 	[PWRAP_CRC_EN] =		0xc8,
489*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =		0xcc,
490*4882a593Smuzhiyun 	[PWRAP_TIMER_STA] =		0xd0,
491*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =		0xd4,
492*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =		0xd8,
493*4882a593Smuzhiyun 	[PWRAP_WDT_FLG] =		0xdc,
494*4882a593Smuzhiyun 	[PWRAP_DEBUG_INT_SEL] =		0xe0,
495*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR0] =		0xe4,
496*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA0] =		0xe8,
497*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR1] =		0xec,
498*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA1] =		0xf0,
499*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR2] =		0xf4,
500*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA2] =		0xf8,
501*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR3] =		0xfc,
502*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA3] =		0x100,
503*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR4] =		0x104,
504*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA4] =		0x108,
505*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR5] =		0x10c,
506*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA5] =		0x110,
507*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR6] =		0x114,
508*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA6] =		0x118,
509*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR7] =		0x11c,
510*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA7] =		0x120,
511*4882a593Smuzhiyun 	[PWRAP_CIPHER_KEY_SEL] =	0x124,
512*4882a593Smuzhiyun 	[PWRAP_CIPHER_IV_SEL] =		0x128,
513*4882a593Smuzhiyun 	[PWRAP_CIPHER_EN] =		0x12c,
514*4882a593Smuzhiyun 	[PWRAP_CIPHER_RDY] =		0x130,
515*4882a593Smuzhiyun 	[PWRAP_CIPHER_MODE] =		0x134,
516*4882a593Smuzhiyun 	[PWRAP_CIPHER_SWRST] =		0x138,
517*4882a593Smuzhiyun 	[PWRAP_DCM_EN] =		0x13c,
518*4882a593Smuzhiyun 	[PWRAP_DCM_DBC_PRD] =		0x140,
519*4882a593Smuzhiyun 	[PWRAP_ADC_CMD_ADDR] =		0x144,
520*4882a593Smuzhiyun 	[PWRAP_PWRAP_ADC_CMD] =		0x148,
521*4882a593Smuzhiyun 	[PWRAP_ADC_RDY_ADDR] =		0x14c,
522*4882a593Smuzhiyun 	[PWRAP_ADC_RDATA_ADDR1] =	0x150,
523*4882a593Smuzhiyun 	[PWRAP_ADC_RDATA_ADDR2] =	0x154,
524*4882a593Smuzhiyun };
525*4882a593Smuzhiyun 
526*4882a593Smuzhiyun static int mt6765_regs[] = {
527*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =		0x0,
528*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =		0x4,
529*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =		0x8,
530*4882a593Smuzhiyun 	[PWRAP_RDDMY] =			0x20,
531*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =		0x24,
532*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =		0x28,
533*4882a593Smuzhiyun 	[PWRAP_CSLEXT_START] =		0x2C,
534*4882a593Smuzhiyun 	[PWRAP_CSLEXT_END] =		0x30,
535*4882a593Smuzhiyun 	[PWRAP_STAUPD_PRD] =		0x3C,
536*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =		0x68,
537*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =		0x6C,
538*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =		0x7C,
539*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =		0x80,
540*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =		0x8C,
541*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =		0x94,
542*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =		0x9C,
543*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =		0xA0,
544*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =		0xC20,
545*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =		0xC24,
546*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =		0xC28,
547*4882a593Smuzhiyun 	[PWRAP_INT_EN] =		0xB4,
548*4882a593Smuzhiyun 	[PWRAP_INT_FLG_RAW] =		0xB8,
549*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =		0xBC,
550*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =		0xC0,
551*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =		0xE8,
552*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =		0xF0,
553*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =		0xF4,
554*4882a593Smuzhiyun 	[PWRAP_DCM_EN] =		0x1DC,
555*4882a593Smuzhiyun 	[PWRAP_DCM_DBC_PRD] =		0x1E0,
556*4882a593Smuzhiyun };
557*4882a593Smuzhiyun 
558*4882a593Smuzhiyun static int mt6779_regs[] = {
559*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =		0x0,
560*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =		0x4,
561*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =		0x8,
562*4882a593Smuzhiyun 	[PWRAP_RDDMY] =			0x20,
563*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =		0x24,
564*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =		0x28,
565*4882a593Smuzhiyun 	[PWRAP_CSLEXT_WRITE] =		0x2C,
566*4882a593Smuzhiyun 	[PWRAP_CSLEXT_READ] =		0x30,
567*4882a593Smuzhiyun 	[PWRAP_EXT_CK_WRITE] =		0x34,
568*4882a593Smuzhiyun 	[PWRAP_STAUPD_CTRL] =		0x3C,
569*4882a593Smuzhiyun 	[PWRAP_STAUPD_GRPEN] =		0x40,
570*4882a593Smuzhiyun 	[PWRAP_EINT_STA0_ADR] =		0x44,
571*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =		0x68,
572*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =		0x6C,
573*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =		0x7C,
574*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =		0x80,
575*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =		0x8C,
576*4882a593Smuzhiyun 	[PWRAP_INIT_DONE0] =		0x90,
577*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =		0x94,
578*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =		0x9C,
579*4882a593Smuzhiyun 	[PWRAP_INIT_DONE1] =		0x98,
580*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =		0xA0,
581*4882a593Smuzhiyun 	[PWRAP_INT_EN] =		0xBC,
582*4882a593Smuzhiyun 	[PWRAP_INT_FLG_RAW] =		0xC0,
583*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =		0xC4,
584*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =		0xC8,
585*4882a593Smuzhiyun 	[PWRAP_INT1_EN] =		0xCC,
586*4882a593Smuzhiyun 	[PWRAP_INT1_FLG] =		0xD4,
587*4882a593Smuzhiyun 	[PWRAP_INT1_CLR] =		0xD8,
588*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =		0xF0,
589*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =		0xF8,
590*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =		0xFC,
591*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN_1] =		0x100,
592*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =		0xC20,
593*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =		0xC24,
594*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =		0xC28,
595*4882a593Smuzhiyun };
596*4882a593Smuzhiyun 
597*4882a593Smuzhiyun static int mt6797_regs[] = {
598*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =		0x0,
599*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =		0x4,
600*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =		0x8,
601*4882a593Smuzhiyun 	[PWRAP_SIDLY] =			0xC,
602*4882a593Smuzhiyun 	[PWRAP_RDDMY] =			0x10,
603*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =		0x18,
604*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =		0x1C,
605*4882a593Smuzhiyun 	[PWRAP_CSLEXT_START] =		0x20,
606*4882a593Smuzhiyun 	[PWRAP_CSLEXT_END] =		0x24,
607*4882a593Smuzhiyun 	[PWRAP_STAUPD_PRD] =		0x28,
608*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =		0x50,
609*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =		0x54,
610*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =		0x60,
611*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =		0x64,
612*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =		0x70,
613*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =		0x84,
614*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =		0x98,
615*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =		0x9C,
616*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =		0xA0,
617*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =		0xA4,
618*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =		0xA8,
619*4882a593Smuzhiyun 	[PWRAP_INT_EN] =		0xC0,
620*4882a593Smuzhiyun 	[PWRAP_INT_FLG_RAW] =		0xC4,
621*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =		0xC8,
622*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =		0xCC,
623*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =		0xF4,
624*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =		0xFC,
625*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =		0x100,
626*4882a593Smuzhiyun 	[PWRAP_DCM_EN] =		0x1CC,
627*4882a593Smuzhiyun 	[PWRAP_DCM_DBC_PRD] =		0x1D4,
628*4882a593Smuzhiyun };
629*4882a593Smuzhiyun 
630*4882a593Smuzhiyun static int mt7622_regs[] = {
631*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =		0x0,
632*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =		0x4,
633*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =		0x8,
634*4882a593Smuzhiyun 	[PWRAP_SIDLY] =			0xC,
635*4882a593Smuzhiyun 	[PWRAP_RDDMY] =			0x10,
636*4882a593Smuzhiyun 	[PWRAP_SI_CK_CON] =		0x14,
637*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =		0x18,
638*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =		0x1C,
639*4882a593Smuzhiyun 	[PWRAP_CSLEXT_START] =		0x20,
640*4882a593Smuzhiyun 	[PWRAP_CSLEXT_END] =		0x24,
641*4882a593Smuzhiyun 	[PWRAP_STAUPD_PRD] =		0x28,
642*4882a593Smuzhiyun 	[PWRAP_STAUPD_GRPEN] =		0x2C,
643*4882a593Smuzhiyun 	[PWRAP_EINT_STA0_ADR] =		0x30,
644*4882a593Smuzhiyun 	[PWRAP_EINT_STA1_ADR] =		0x34,
645*4882a593Smuzhiyun 	[PWRAP_STA] =			0x38,
646*4882a593Smuzhiyun 	[PWRAP_CLR] =			0x3C,
647*4882a593Smuzhiyun 	[PWRAP_STAUPD_MAN_TRIG] =	0x40,
648*4882a593Smuzhiyun 	[PWRAP_STAUPD_STA] =		0x44,
649*4882a593Smuzhiyun 	[PWRAP_WRAP_STA] =		0x48,
650*4882a593Smuzhiyun 	[PWRAP_HARB_INIT] =		0x4C,
651*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =		0x50,
652*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =		0x54,
653*4882a593Smuzhiyun 	[PWRAP_HARB_STA0] =		0x58,
654*4882a593Smuzhiyun 	[PWRAP_HARB_STA1] =		0x5C,
655*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =		0x60,
656*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =		0x64,
657*4882a593Smuzhiyun 	[PWRAP_MAN_RDATA] =		0x68,
658*4882a593Smuzhiyun 	[PWRAP_MAN_VLDCLR] =		0x6C,
659*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =		0x70,
660*4882a593Smuzhiyun 	[PWRAP_INIT_DONE0] =		0x74,
661*4882a593Smuzhiyun 	[PWRAP_WACS0_CMD] =		0x78,
662*4882a593Smuzhiyun 	[PWRAP_WACS0_RDATA] =		0x7C,
663*4882a593Smuzhiyun 	[PWRAP_WACS0_VLDCLR] =		0x80,
664*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =		0x84,
665*4882a593Smuzhiyun 	[PWRAP_INIT_DONE1] =		0x88,
666*4882a593Smuzhiyun 	[PWRAP_WACS1_CMD] =		0x8C,
667*4882a593Smuzhiyun 	[PWRAP_WACS1_RDATA] =		0x90,
668*4882a593Smuzhiyun 	[PWRAP_WACS1_VLDCLR] =		0x94,
669*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =		0x98,
670*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =		0x9C,
671*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =		0xA0,
672*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =		0xA4,
673*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =		0xA8,
674*4882a593Smuzhiyun 	[PWRAP_INT_EN] =		0xAC,
675*4882a593Smuzhiyun 	[PWRAP_INT_FLG_RAW] =		0xB0,
676*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =		0xB4,
677*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =		0xB8,
678*4882a593Smuzhiyun 	[PWRAP_SIG_ADR] =		0xBC,
679*4882a593Smuzhiyun 	[PWRAP_SIG_MODE] =		0xC0,
680*4882a593Smuzhiyun 	[PWRAP_SIG_VALUE] =		0xC4,
681*4882a593Smuzhiyun 	[PWRAP_SIG_ERRVAL] =		0xC8,
682*4882a593Smuzhiyun 	[PWRAP_CRC_EN] =		0xCC,
683*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =		0xD0,
684*4882a593Smuzhiyun 	[PWRAP_TIMER_STA] =		0xD4,
685*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =		0xD8,
686*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =		0xDC,
687*4882a593Smuzhiyun 	[PWRAP_WDT_FLG] =		0xE0,
688*4882a593Smuzhiyun 	[PWRAP_DEBUG_INT_SEL] =		0xE4,
689*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR0] =		0xE8,
690*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA0] =		0xEC,
691*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR1] =		0xF0,
692*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA1] =		0xF4,
693*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR2] =		0xF8,
694*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA2] =		0xFC,
695*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR3] =		0x100,
696*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA3] =		0x104,
697*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR4] =		0x108,
698*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA4] =		0x10C,
699*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR5] =		0x110,
700*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA5] =		0x114,
701*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR6] =		0x118,
702*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA6] =		0x11C,
703*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR7] =		0x120,
704*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA7] =		0x124,
705*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR8] =		0x128,
706*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA8] =		0x12C,
707*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR9] =		0x130,
708*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA9] =		0x134,
709*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR10] =		0x138,
710*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA10] =		0x13C,
711*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR11] =		0x140,
712*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA11] =		0x144,
713*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR12] =		0x148,
714*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA12] =		0x14C,
715*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR13] =		0x150,
716*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA13] =		0x154,
717*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR14] =		0x158,
718*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA14] =		0x15C,
719*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR15] =		0x160,
720*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA15] =		0x164,
721*4882a593Smuzhiyun 	[PWRAP_SPMINF_STA] =		0x168,
722*4882a593Smuzhiyun 	[PWRAP_CIPHER_KEY_SEL] =	0x16C,
723*4882a593Smuzhiyun 	[PWRAP_CIPHER_IV_SEL] =		0x170,
724*4882a593Smuzhiyun 	[PWRAP_CIPHER_EN] =		0x174,
725*4882a593Smuzhiyun 	[PWRAP_CIPHER_RDY] =		0x178,
726*4882a593Smuzhiyun 	[PWRAP_CIPHER_MODE] =		0x17C,
727*4882a593Smuzhiyun 	[PWRAP_CIPHER_SWRST] =		0x180,
728*4882a593Smuzhiyun 	[PWRAP_DCM_EN] =		0x184,
729*4882a593Smuzhiyun 	[PWRAP_DCM_DBC_PRD] =		0x188,
730*4882a593Smuzhiyun 	[PWRAP_EXT_CK] =		0x18C,
731*4882a593Smuzhiyun 	[PWRAP_ADC_CMD_ADDR] =		0x190,
732*4882a593Smuzhiyun 	[PWRAP_PWRAP_ADC_CMD] =		0x194,
733*4882a593Smuzhiyun 	[PWRAP_ADC_RDATA_ADDR] =	0x198,
734*4882a593Smuzhiyun 	[PWRAP_GPS_STA] =		0x19C,
735*4882a593Smuzhiyun 	[PWRAP_SW_RST] =		0x1A0,
736*4882a593Smuzhiyun 	[PWRAP_DVFS_STEP_CTRL0] =	0x238,
737*4882a593Smuzhiyun 	[PWRAP_DVFS_STEP_CTRL1] =	0x23C,
738*4882a593Smuzhiyun 	[PWRAP_DVFS_STEP_CTRL2] =	0x240,
739*4882a593Smuzhiyun 	[PWRAP_SPI2_CTRL] =		0x244,
740*4882a593Smuzhiyun };
741*4882a593Smuzhiyun 
742*4882a593Smuzhiyun static int mt8135_regs[] = {
743*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =		0x0,
744*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =		0x4,
745*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =		0x8,
746*4882a593Smuzhiyun 	[PWRAP_SIDLY] =			0xc,
747*4882a593Smuzhiyun 	[PWRAP_CSHEXT] =		0x10,
748*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =		0x14,
749*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =		0x18,
750*4882a593Smuzhiyun 	[PWRAP_CSLEXT_START] =		0x1c,
751*4882a593Smuzhiyun 	[PWRAP_CSLEXT_END] =		0x20,
752*4882a593Smuzhiyun 	[PWRAP_STAUPD_PRD] =		0x24,
753*4882a593Smuzhiyun 	[PWRAP_STAUPD_GRPEN] =		0x28,
754*4882a593Smuzhiyun 	[PWRAP_STAUPD_MAN_TRIG] =	0x2c,
755*4882a593Smuzhiyun 	[PWRAP_STAUPD_STA] =		0x30,
756*4882a593Smuzhiyun 	[PWRAP_EVENT_IN_EN] =		0x34,
757*4882a593Smuzhiyun 	[PWRAP_EVENT_DST_EN] =		0x38,
758*4882a593Smuzhiyun 	[PWRAP_WRAP_STA] =		0x3c,
759*4882a593Smuzhiyun 	[PWRAP_RRARB_INIT] =		0x40,
760*4882a593Smuzhiyun 	[PWRAP_RRARB_EN] =		0x44,
761*4882a593Smuzhiyun 	[PWRAP_RRARB_STA0] =		0x48,
762*4882a593Smuzhiyun 	[PWRAP_RRARB_STA1] =		0x4c,
763*4882a593Smuzhiyun 	[PWRAP_HARB_INIT] =		0x50,
764*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =		0x54,
765*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =		0x58,
766*4882a593Smuzhiyun 	[PWRAP_HARB_STA0] =		0x5c,
767*4882a593Smuzhiyun 	[PWRAP_HARB_STA1] =		0x60,
768*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =		0x64,
769*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =		0x68,
770*4882a593Smuzhiyun 	[PWRAP_MAN_RDATA] =		0x6c,
771*4882a593Smuzhiyun 	[PWRAP_MAN_VLDCLR] =		0x70,
772*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =		0x74,
773*4882a593Smuzhiyun 	[PWRAP_INIT_DONE0] =		0x78,
774*4882a593Smuzhiyun 	[PWRAP_WACS0_CMD] =		0x7c,
775*4882a593Smuzhiyun 	[PWRAP_WACS0_RDATA] =		0x80,
776*4882a593Smuzhiyun 	[PWRAP_WACS0_VLDCLR] =		0x84,
777*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =		0x88,
778*4882a593Smuzhiyun 	[PWRAP_INIT_DONE1] =		0x8c,
779*4882a593Smuzhiyun 	[PWRAP_WACS1_CMD] =		0x90,
780*4882a593Smuzhiyun 	[PWRAP_WACS1_RDATA] =		0x94,
781*4882a593Smuzhiyun 	[PWRAP_WACS1_VLDCLR] =		0x98,
782*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =		0x9c,
783*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =		0xa0,
784*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =		0xa4,
785*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =		0xa8,
786*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =		0xac,
787*4882a593Smuzhiyun 	[PWRAP_INT_EN] =		0xb0,
788*4882a593Smuzhiyun 	[PWRAP_INT_FLG_RAW] =		0xb4,
789*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =		0xb8,
790*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =		0xbc,
791*4882a593Smuzhiyun 	[PWRAP_SIG_ADR] =		0xc0,
792*4882a593Smuzhiyun 	[PWRAP_SIG_MODE] =		0xc4,
793*4882a593Smuzhiyun 	[PWRAP_SIG_VALUE] =		0xc8,
794*4882a593Smuzhiyun 	[PWRAP_SIG_ERRVAL] =		0xcc,
795*4882a593Smuzhiyun 	[PWRAP_CRC_EN] =		0xd0,
796*4882a593Smuzhiyun 	[PWRAP_EVENT_STA] =		0xd4,
797*4882a593Smuzhiyun 	[PWRAP_EVENT_STACLR] =		0xd8,
798*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =		0xdc,
799*4882a593Smuzhiyun 	[PWRAP_TIMER_STA] =		0xe0,
800*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =		0xe4,
801*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =		0xe8,
802*4882a593Smuzhiyun 	[PWRAP_WDT_FLG] =		0xec,
803*4882a593Smuzhiyun 	[PWRAP_DEBUG_INT_SEL] =		0xf0,
804*4882a593Smuzhiyun 	[PWRAP_CIPHER_KEY_SEL] =	0x134,
805*4882a593Smuzhiyun 	[PWRAP_CIPHER_IV_SEL] =		0x138,
806*4882a593Smuzhiyun 	[PWRAP_CIPHER_LOAD] =		0x13c,
807*4882a593Smuzhiyun 	[PWRAP_CIPHER_START] =		0x140,
808*4882a593Smuzhiyun 	[PWRAP_CIPHER_RDY] =		0x144,
809*4882a593Smuzhiyun 	[PWRAP_CIPHER_MODE] =		0x148,
810*4882a593Smuzhiyun 	[PWRAP_CIPHER_SWRST] =		0x14c,
811*4882a593Smuzhiyun 	[PWRAP_DCM_EN] =		0x15c,
812*4882a593Smuzhiyun 	[PWRAP_DCM_DBC_PRD] =		0x160,
813*4882a593Smuzhiyun };
814*4882a593Smuzhiyun 
815*4882a593Smuzhiyun static int mt8173_regs[] = {
816*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =		0x0,
817*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =		0x4,
818*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =		0x8,
819*4882a593Smuzhiyun 	[PWRAP_SIDLY] =			0xc,
820*4882a593Smuzhiyun 	[PWRAP_RDDMY] =			0x10,
821*4882a593Smuzhiyun 	[PWRAP_SI_CK_CON] =		0x14,
822*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =		0x18,
823*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =		0x1c,
824*4882a593Smuzhiyun 	[PWRAP_CSLEXT_START] =		0x20,
825*4882a593Smuzhiyun 	[PWRAP_CSLEXT_END] =		0x24,
826*4882a593Smuzhiyun 	[PWRAP_STAUPD_PRD] =		0x28,
827*4882a593Smuzhiyun 	[PWRAP_STAUPD_GRPEN] =		0x2c,
828*4882a593Smuzhiyun 	[PWRAP_STAUPD_MAN_TRIG] =	0x40,
829*4882a593Smuzhiyun 	[PWRAP_STAUPD_STA] =		0x44,
830*4882a593Smuzhiyun 	[PWRAP_WRAP_STA] =		0x48,
831*4882a593Smuzhiyun 	[PWRAP_HARB_INIT] =		0x4c,
832*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =		0x50,
833*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =		0x54,
834*4882a593Smuzhiyun 	[PWRAP_HARB_STA0] =		0x58,
835*4882a593Smuzhiyun 	[PWRAP_HARB_STA1] =		0x5c,
836*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =		0x60,
837*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =		0x64,
838*4882a593Smuzhiyun 	[PWRAP_MAN_RDATA] =		0x68,
839*4882a593Smuzhiyun 	[PWRAP_MAN_VLDCLR] =		0x6c,
840*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =		0x70,
841*4882a593Smuzhiyun 	[PWRAP_INIT_DONE0] =		0x74,
842*4882a593Smuzhiyun 	[PWRAP_WACS0_CMD] =		0x78,
843*4882a593Smuzhiyun 	[PWRAP_WACS0_RDATA] =		0x7c,
844*4882a593Smuzhiyun 	[PWRAP_WACS0_VLDCLR] =		0x80,
845*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =		0x84,
846*4882a593Smuzhiyun 	[PWRAP_INIT_DONE1] =		0x88,
847*4882a593Smuzhiyun 	[PWRAP_WACS1_CMD] =		0x8c,
848*4882a593Smuzhiyun 	[PWRAP_WACS1_RDATA] =		0x90,
849*4882a593Smuzhiyun 	[PWRAP_WACS1_VLDCLR] =		0x94,
850*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =		0x98,
851*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =		0x9c,
852*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =		0xa0,
853*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =		0xa4,
854*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =		0xa8,
855*4882a593Smuzhiyun 	[PWRAP_INT_EN] =		0xac,
856*4882a593Smuzhiyun 	[PWRAP_INT_FLG_RAW] =		0xb0,
857*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =		0xb4,
858*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =		0xb8,
859*4882a593Smuzhiyun 	[PWRAP_SIG_ADR] =		0xbc,
860*4882a593Smuzhiyun 	[PWRAP_SIG_MODE] =		0xc0,
861*4882a593Smuzhiyun 	[PWRAP_SIG_VALUE] =		0xc4,
862*4882a593Smuzhiyun 	[PWRAP_SIG_ERRVAL] =		0xc8,
863*4882a593Smuzhiyun 	[PWRAP_CRC_EN] =		0xcc,
864*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =		0xd0,
865*4882a593Smuzhiyun 	[PWRAP_TIMER_STA] =		0xd4,
866*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =		0xd8,
867*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =		0xdc,
868*4882a593Smuzhiyun 	[PWRAP_WDT_FLG] =		0xe0,
869*4882a593Smuzhiyun 	[PWRAP_DEBUG_INT_SEL] =		0xe4,
870*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR0] =		0xe8,
871*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA0] =		0xec,
872*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR1] =		0xf0,
873*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA1] =		0xf4,
874*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR2] =		0xf8,
875*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA2] =		0xfc,
876*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR3] =		0x100,
877*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA3] =		0x104,
878*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR4] =		0x108,
879*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA4] =		0x10c,
880*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR5] =		0x110,
881*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA5] =		0x114,
882*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR6] =		0x118,
883*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA6] =		0x11c,
884*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR7] =		0x120,
885*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA7] =		0x124,
886*4882a593Smuzhiyun 	[PWRAP_SPMINF_STA] =		0x128,
887*4882a593Smuzhiyun 	[PWRAP_CIPHER_KEY_SEL] =	0x12c,
888*4882a593Smuzhiyun 	[PWRAP_CIPHER_IV_SEL] =		0x130,
889*4882a593Smuzhiyun 	[PWRAP_CIPHER_EN] =		0x134,
890*4882a593Smuzhiyun 	[PWRAP_CIPHER_RDY] =		0x138,
891*4882a593Smuzhiyun 	[PWRAP_CIPHER_MODE] =		0x13c,
892*4882a593Smuzhiyun 	[PWRAP_CIPHER_SWRST] =		0x140,
893*4882a593Smuzhiyun 	[PWRAP_DCM_EN] =		0x144,
894*4882a593Smuzhiyun 	[PWRAP_DCM_DBC_PRD] =		0x148,
895*4882a593Smuzhiyun };
896*4882a593Smuzhiyun 
897*4882a593Smuzhiyun static int mt8183_regs[] = {
898*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =			0x0,
899*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =			0x4,
900*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =			0x8,
901*4882a593Smuzhiyun 	[PWRAP_SI_SAMPLE_CTRL] =		0xC,
902*4882a593Smuzhiyun 	[PWRAP_RDDMY] =				0x14,
903*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =			0x18,
904*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =			0x1C,
905*4882a593Smuzhiyun 	[PWRAP_CSLEXT_WRITE] =			0x20,
906*4882a593Smuzhiyun 	[PWRAP_CSLEXT_READ] =			0x24,
907*4882a593Smuzhiyun 	[PWRAP_EXT_CK_WRITE] =			0x28,
908*4882a593Smuzhiyun 	[PWRAP_STAUPD_CTRL] =			0x30,
909*4882a593Smuzhiyun 	[PWRAP_STAUPD_GRPEN] =			0x34,
910*4882a593Smuzhiyun 	[PWRAP_EINT_STA0_ADR] =			0x38,
911*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =			0x5C,
912*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =			0x60,
913*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =			0x70,
914*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =			0x74,
915*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =			0x80,
916*4882a593Smuzhiyun 	[PWRAP_INIT_DONE0] =			0x84,
917*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =			0x88,
918*4882a593Smuzhiyun 	[PWRAP_INIT_DONE1] =			0x8C,
919*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =			0x90,
920*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =			0x94,
921*4882a593Smuzhiyun 	[PWRAP_WACS_P2P_EN] =			0xA0,
922*4882a593Smuzhiyun 	[PWRAP_INIT_DONE_P2P] =			0xA4,
923*4882a593Smuzhiyun 	[PWRAP_WACS_MD32_EN] =			0xA8,
924*4882a593Smuzhiyun 	[PWRAP_INIT_DONE_MD32] =		0xAC,
925*4882a593Smuzhiyun 	[PWRAP_INT_EN] =			0xB0,
926*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =			0xB8,
927*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =			0xBC,
928*4882a593Smuzhiyun 	[PWRAP_INT1_EN] =			0xC0,
929*4882a593Smuzhiyun 	[PWRAP_INT1_FLG] =			0xC8,
930*4882a593Smuzhiyun 	[PWRAP_INT1_CLR] =			0xCC,
931*4882a593Smuzhiyun 	[PWRAP_SIG_ADR] =			0xD0,
932*4882a593Smuzhiyun 	[PWRAP_CRC_EN] =			0xE0,
933*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =			0xE4,
934*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =			0xEC,
935*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =			0xF0,
936*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN_1] =			0xF4,
937*4882a593Smuzhiyun 	[PWRAP_INT_GPS_AUXADC_CMD_ADDR] =	0x1DC,
938*4882a593Smuzhiyun 	[PWRAP_INT_GPS_AUXADC_CMD] =		0x1E0,
939*4882a593Smuzhiyun 	[PWRAP_INT_GPS_AUXADC_RDATA_ADDR] =	0x1E4,
940*4882a593Smuzhiyun 	[PWRAP_EXT_GPS_AUXADC_RDATA_ADDR] =	0x1E8,
941*4882a593Smuzhiyun 	[PWRAP_GPSINF_0_STA] =			0x1EC,
942*4882a593Smuzhiyun 	[PWRAP_GPSINF_1_STA] =			0x1F0,
943*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =			0xC20,
944*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =			0xC24,
945*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =			0xC28,
946*4882a593Smuzhiyun };
947*4882a593Smuzhiyun 
948*4882a593Smuzhiyun static int mt8516_regs[] = {
949*4882a593Smuzhiyun 	[PWRAP_MUX_SEL] =		0x0,
950*4882a593Smuzhiyun 	[PWRAP_WRAP_EN] =		0x4,
951*4882a593Smuzhiyun 	[PWRAP_DIO_EN] =		0x8,
952*4882a593Smuzhiyun 	[PWRAP_SIDLY] =			0xc,
953*4882a593Smuzhiyun 	[PWRAP_RDDMY] =			0x10,
954*4882a593Smuzhiyun 	[PWRAP_SI_CK_CON] =		0x14,
955*4882a593Smuzhiyun 	[PWRAP_CSHEXT_WRITE] =		0x18,
956*4882a593Smuzhiyun 	[PWRAP_CSHEXT_READ] =		0x1c,
957*4882a593Smuzhiyun 	[PWRAP_CSLEXT_START] =		0x20,
958*4882a593Smuzhiyun 	[PWRAP_CSLEXT_END] =		0x24,
959*4882a593Smuzhiyun 	[PWRAP_STAUPD_PRD] =		0x28,
960*4882a593Smuzhiyun 	[PWRAP_STAUPD_GRPEN] =		0x2c,
961*4882a593Smuzhiyun 	[PWRAP_STAUPD_MAN_TRIG] =	0x40,
962*4882a593Smuzhiyun 	[PWRAP_STAUPD_STA] =		0x44,
963*4882a593Smuzhiyun 	[PWRAP_WRAP_STA] =		0x48,
964*4882a593Smuzhiyun 	[PWRAP_HARB_INIT] =		0x4c,
965*4882a593Smuzhiyun 	[PWRAP_HARB_HPRIO] =		0x50,
966*4882a593Smuzhiyun 	[PWRAP_HIPRIO_ARB_EN] =		0x54,
967*4882a593Smuzhiyun 	[PWRAP_HARB_STA0] =		0x58,
968*4882a593Smuzhiyun 	[PWRAP_HARB_STA1] =		0x5c,
969*4882a593Smuzhiyun 	[PWRAP_MAN_EN] =		0x60,
970*4882a593Smuzhiyun 	[PWRAP_MAN_CMD] =		0x64,
971*4882a593Smuzhiyun 	[PWRAP_MAN_RDATA] =		0x68,
972*4882a593Smuzhiyun 	[PWRAP_MAN_VLDCLR] =		0x6c,
973*4882a593Smuzhiyun 	[PWRAP_WACS0_EN] =		0x70,
974*4882a593Smuzhiyun 	[PWRAP_INIT_DONE0] =		0x74,
975*4882a593Smuzhiyun 	[PWRAP_WACS0_CMD] =		0x78,
976*4882a593Smuzhiyun 	[PWRAP_WACS0_RDATA] =		0x7c,
977*4882a593Smuzhiyun 	[PWRAP_WACS0_VLDCLR] =		0x80,
978*4882a593Smuzhiyun 	[PWRAP_WACS1_EN] =		0x84,
979*4882a593Smuzhiyun 	[PWRAP_INIT_DONE1] =		0x88,
980*4882a593Smuzhiyun 	[PWRAP_WACS1_CMD] =		0x8c,
981*4882a593Smuzhiyun 	[PWRAP_WACS1_RDATA] =		0x90,
982*4882a593Smuzhiyun 	[PWRAP_WACS1_VLDCLR] =		0x94,
983*4882a593Smuzhiyun 	[PWRAP_WACS2_EN] =		0x98,
984*4882a593Smuzhiyun 	[PWRAP_INIT_DONE2] =		0x9c,
985*4882a593Smuzhiyun 	[PWRAP_WACS2_CMD] =		0xa0,
986*4882a593Smuzhiyun 	[PWRAP_WACS2_RDATA] =		0xa4,
987*4882a593Smuzhiyun 	[PWRAP_WACS2_VLDCLR] =		0xa8,
988*4882a593Smuzhiyun 	[PWRAP_INT_EN] =		0xac,
989*4882a593Smuzhiyun 	[PWRAP_INT_FLG_RAW] =		0xb0,
990*4882a593Smuzhiyun 	[PWRAP_INT_FLG] =		0xb4,
991*4882a593Smuzhiyun 	[PWRAP_INT_CLR] =		0xb8,
992*4882a593Smuzhiyun 	[PWRAP_SIG_ADR] =		0xbc,
993*4882a593Smuzhiyun 	[PWRAP_SIG_MODE] =		0xc0,
994*4882a593Smuzhiyun 	[PWRAP_SIG_VALUE] =		0xc4,
995*4882a593Smuzhiyun 	[PWRAP_SIG_ERRVAL] =		0xc8,
996*4882a593Smuzhiyun 	[PWRAP_CRC_EN] =		0xcc,
997*4882a593Smuzhiyun 	[PWRAP_TIMER_EN] =		0xd0,
998*4882a593Smuzhiyun 	[PWRAP_TIMER_STA] =		0xd4,
999*4882a593Smuzhiyun 	[PWRAP_WDT_UNIT] =		0xd8,
1000*4882a593Smuzhiyun 	[PWRAP_WDT_SRC_EN] =		0xdc,
1001*4882a593Smuzhiyun 	[PWRAP_WDT_FLG] =		0xe0,
1002*4882a593Smuzhiyun 	[PWRAP_DEBUG_INT_SEL] =		0xe4,
1003*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR0] =		0xe8,
1004*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA0] =		0xec,
1005*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR1] =		0xf0,
1006*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA1] =		0xf4,
1007*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR2] =		0xf8,
1008*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA2] =		0xfc,
1009*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR3] =		0x100,
1010*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA3] =		0x104,
1011*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR4] =		0x108,
1012*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA4] =		0x10c,
1013*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR5] =		0x110,
1014*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA5] =		0x114,
1015*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR6] =		0x118,
1016*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA6] =		0x11c,
1017*4882a593Smuzhiyun 	[PWRAP_DVFS_ADR7] =		0x120,
1018*4882a593Smuzhiyun 	[PWRAP_DVFS_WDATA7] =		0x124,
1019*4882a593Smuzhiyun 	[PWRAP_SPMINF_STA] =		0x128,
1020*4882a593Smuzhiyun 	[PWRAP_CIPHER_KEY_SEL] =	0x12c,
1021*4882a593Smuzhiyun 	[PWRAP_CIPHER_IV_SEL] =		0x130,
1022*4882a593Smuzhiyun 	[PWRAP_CIPHER_EN] =		0x134,
1023*4882a593Smuzhiyun 	[PWRAP_CIPHER_RDY] =		0x138,
1024*4882a593Smuzhiyun 	[PWRAP_CIPHER_MODE] =		0x13c,
1025*4882a593Smuzhiyun 	[PWRAP_CIPHER_SWRST] =		0x140,
1026*4882a593Smuzhiyun 	[PWRAP_DCM_EN] =		0x144,
1027*4882a593Smuzhiyun 	[PWRAP_DCM_DBC_PRD] =		0x148,
1028*4882a593Smuzhiyun 	[PWRAP_SW_RST] =		0x168,
1029*4882a593Smuzhiyun 	[PWRAP_OP_TYPE] =		0x16c,
1030*4882a593Smuzhiyun 	[PWRAP_MSB_FIRST] =		0x170,
1031*4882a593Smuzhiyun };
1032*4882a593Smuzhiyun 
1033*4882a593Smuzhiyun enum pmic_type {
1034*4882a593Smuzhiyun 	PMIC_MT6323,
1035*4882a593Smuzhiyun 	PMIC_MT6351,
1036*4882a593Smuzhiyun 	PMIC_MT6357,
1037*4882a593Smuzhiyun 	PMIC_MT6358,
1038*4882a593Smuzhiyun 	PMIC_MT6359,
1039*4882a593Smuzhiyun 	PMIC_MT6380,
1040*4882a593Smuzhiyun 	PMIC_MT6397,
1041*4882a593Smuzhiyun };
1042*4882a593Smuzhiyun 
1043*4882a593Smuzhiyun enum pwrap_type {
1044*4882a593Smuzhiyun 	PWRAP_MT2701,
1045*4882a593Smuzhiyun 	PWRAP_MT6765,
1046*4882a593Smuzhiyun 	PWRAP_MT6779,
1047*4882a593Smuzhiyun 	PWRAP_MT6797,
1048*4882a593Smuzhiyun 	PWRAP_MT7622,
1049*4882a593Smuzhiyun 	PWRAP_MT8135,
1050*4882a593Smuzhiyun 	PWRAP_MT8173,
1051*4882a593Smuzhiyun 	PWRAP_MT8183,
1052*4882a593Smuzhiyun 	PWRAP_MT8516,
1053*4882a593Smuzhiyun };
1054*4882a593Smuzhiyun 
1055*4882a593Smuzhiyun struct pmic_wrapper;
1056*4882a593Smuzhiyun struct pwrap_slv_type {
1057*4882a593Smuzhiyun 	const u32 *dew_regs;
1058*4882a593Smuzhiyun 	enum pmic_type type;
1059*4882a593Smuzhiyun 	const struct regmap_config *regmap;
1060*4882a593Smuzhiyun 	/* Flags indicating the capability for the target slave */
1061*4882a593Smuzhiyun 	u32 caps;
1062*4882a593Smuzhiyun 	/*
1063*4882a593Smuzhiyun 	 * pwrap operations are highly associated with the PMIC types,
1064*4882a593Smuzhiyun 	 * so the pointers added increases flexibility allowing determination
1065*4882a593Smuzhiyun 	 * which type is used by the detection through device tree.
1066*4882a593Smuzhiyun 	 */
1067*4882a593Smuzhiyun 	int (*pwrap_read)(struct pmic_wrapper *wrp, u32 adr, u32 *rdata);
1068*4882a593Smuzhiyun 	int (*pwrap_write)(struct pmic_wrapper *wrp, u32 adr, u32 wdata);
1069*4882a593Smuzhiyun };
1070*4882a593Smuzhiyun 
1071*4882a593Smuzhiyun struct pmic_wrapper {
1072*4882a593Smuzhiyun 	struct device *dev;
1073*4882a593Smuzhiyun 	void __iomem *base;
1074*4882a593Smuzhiyun 	struct regmap *regmap;
1075*4882a593Smuzhiyun 	const struct pmic_wrapper_type *master;
1076*4882a593Smuzhiyun 	const struct pwrap_slv_type *slave;
1077*4882a593Smuzhiyun 	struct clk *clk_spi;
1078*4882a593Smuzhiyun 	struct clk *clk_wrap;
1079*4882a593Smuzhiyun 	struct reset_control *rstc;
1080*4882a593Smuzhiyun 
1081*4882a593Smuzhiyun 	struct reset_control *rstc_bridge;
1082*4882a593Smuzhiyun 	void __iomem *bridge_base;
1083*4882a593Smuzhiyun };
1084*4882a593Smuzhiyun 
1085*4882a593Smuzhiyun struct pmic_wrapper_type {
1086*4882a593Smuzhiyun 	int *regs;
1087*4882a593Smuzhiyun 	enum pwrap_type type;
1088*4882a593Smuzhiyun 	u32 arb_en_all;
1089*4882a593Smuzhiyun 	u32 int_en_all;
1090*4882a593Smuzhiyun 	u32 int1_en_all;
1091*4882a593Smuzhiyun 	u32 spi_w;
1092*4882a593Smuzhiyun 	u32 wdt_src;
1093*4882a593Smuzhiyun 	/* Flags indicating the capability for the target pwrap */
1094*4882a593Smuzhiyun 	u32 caps;
1095*4882a593Smuzhiyun 	int (*init_reg_clock)(struct pmic_wrapper *wrp);
1096*4882a593Smuzhiyun 	int (*init_soc_specific)(struct pmic_wrapper *wrp);
1097*4882a593Smuzhiyun };
1098*4882a593Smuzhiyun 
pwrap_readl(struct pmic_wrapper * wrp,enum pwrap_regs reg)1099*4882a593Smuzhiyun static u32 pwrap_readl(struct pmic_wrapper *wrp, enum pwrap_regs reg)
1100*4882a593Smuzhiyun {
1101*4882a593Smuzhiyun 	return readl(wrp->base + wrp->master->regs[reg]);
1102*4882a593Smuzhiyun }
1103*4882a593Smuzhiyun 
pwrap_writel(struct pmic_wrapper * wrp,u32 val,enum pwrap_regs reg)1104*4882a593Smuzhiyun static void pwrap_writel(struct pmic_wrapper *wrp, u32 val, enum pwrap_regs reg)
1105*4882a593Smuzhiyun {
1106*4882a593Smuzhiyun 	writel(val, wrp->base + wrp->master->regs[reg]);
1107*4882a593Smuzhiyun }
1108*4882a593Smuzhiyun 
pwrap_is_fsm_idle(struct pmic_wrapper * wrp)1109*4882a593Smuzhiyun static bool pwrap_is_fsm_idle(struct pmic_wrapper *wrp)
1110*4882a593Smuzhiyun {
1111*4882a593Smuzhiyun 	u32 val = pwrap_readl(wrp, PWRAP_WACS2_RDATA);
1112*4882a593Smuzhiyun 
1113*4882a593Smuzhiyun 	return PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_IDLE;
1114*4882a593Smuzhiyun }
1115*4882a593Smuzhiyun 
pwrap_is_fsm_vldclr(struct pmic_wrapper * wrp)1116*4882a593Smuzhiyun static bool pwrap_is_fsm_vldclr(struct pmic_wrapper *wrp)
1117*4882a593Smuzhiyun {
1118*4882a593Smuzhiyun 	u32 val = pwrap_readl(wrp, PWRAP_WACS2_RDATA);
1119*4882a593Smuzhiyun 
1120*4882a593Smuzhiyun 	return PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_WFVLDCLR;
1121*4882a593Smuzhiyun }
1122*4882a593Smuzhiyun 
1123*4882a593Smuzhiyun /*
1124*4882a593Smuzhiyun  * Timeout issue sometimes caused by the last read command
1125*4882a593Smuzhiyun  * failed because pmic wrap could not got the FSM_VLDCLR
1126*4882a593Smuzhiyun  * in time after finishing WACS2_CMD. It made state machine
1127*4882a593Smuzhiyun  * still on FSM_VLDCLR and timeout next time.
1128*4882a593Smuzhiyun  * Check the status of FSM and clear the vldclr to recovery the
1129*4882a593Smuzhiyun  * error.
1130*4882a593Smuzhiyun  */
pwrap_leave_fsm_vldclr(struct pmic_wrapper * wrp)1131*4882a593Smuzhiyun static inline void pwrap_leave_fsm_vldclr(struct pmic_wrapper *wrp)
1132*4882a593Smuzhiyun {
1133*4882a593Smuzhiyun 	if (pwrap_is_fsm_vldclr(wrp))
1134*4882a593Smuzhiyun 		pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
1135*4882a593Smuzhiyun }
1136*4882a593Smuzhiyun 
pwrap_is_sync_idle(struct pmic_wrapper * wrp)1137*4882a593Smuzhiyun static bool pwrap_is_sync_idle(struct pmic_wrapper *wrp)
1138*4882a593Smuzhiyun {
1139*4882a593Smuzhiyun 	return pwrap_readl(wrp, PWRAP_WACS2_RDATA) & PWRAP_STATE_SYNC_IDLE0;
1140*4882a593Smuzhiyun }
1141*4882a593Smuzhiyun 
pwrap_is_fsm_idle_and_sync_idle(struct pmic_wrapper * wrp)1142*4882a593Smuzhiyun static bool pwrap_is_fsm_idle_and_sync_idle(struct pmic_wrapper *wrp)
1143*4882a593Smuzhiyun {
1144*4882a593Smuzhiyun 	u32 val = pwrap_readl(wrp, PWRAP_WACS2_RDATA);
1145*4882a593Smuzhiyun 
1146*4882a593Smuzhiyun 	return (PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_IDLE) &&
1147*4882a593Smuzhiyun 		(val & PWRAP_STATE_SYNC_IDLE0);
1148*4882a593Smuzhiyun }
1149*4882a593Smuzhiyun 
pwrap_wait_for_state(struct pmic_wrapper * wrp,bool (* fp)(struct pmic_wrapper *))1150*4882a593Smuzhiyun static int pwrap_wait_for_state(struct pmic_wrapper *wrp,
1151*4882a593Smuzhiyun 		bool (*fp)(struct pmic_wrapper *))
1152*4882a593Smuzhiyun {
1153*4882a593Smuzhiyun 	unsigned long timeout;
1154*4882a593Smuzhiyun 
1155*4882a593Smuzhiyun 	timeout = jiffies + usecs_to_jiffies(10000);
1156*4882a593Smuzhiyun 
1157*4882a593Smuzhiyun 	do {
1158*4882a593Smuzhiyun 		if (time_after(jiffies, timeout))
1159*4882a593Smuzhiyun 			return fp(wrp) ? 0 : -ETIMEDOUT;
1160*4882a593Smuzhiyun 		if (fp(wrp))
1161*4882a593Smuzhiyun 			return 0;
1162*4882a593Smuzhiyun 	} while (1);
1163*4882a593Smuzhiyun }
1164*4882a593Smuzhiyun 
pwrap_read16(struct pmic_wrapper * wrp,u32 adr,u32 * rdata)1165*4882a593Smuzhiyun static int pwrap_read16(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
1166*4882a593Smuzhiyun {
1167*4882a593Smuzhiyun 	int ret;
1168*4882a593Smuzhiyun 
1169*4882a593Smuzhiyun 	ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
1170*4882a593Smuzhiyun 	if (ret) {
1171*4882a593Smuzhiyun 		pwrap_leave_fsm_vldclr(wrp);
1172*4882a593Smuzhiyun 		return ret;
1173*4882a593Smuzhiyun 	}
1174*4882a593Smuzhiyun 
1175*4882a593Smuzhiyun 	pwrap_writel(wrp, (adr >> 1) << 16, PWRAP_WACS2_CMD);
1176*4882a593Smuzhiyun 
1177*4882a593Smuzhiyun 	ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_vldclr);
1178*4882a593Smuzhiyun 	if (ret)
1179*4882a593Smuzhiyun 		return ret;
1180*4882a593Smuzhiyun 
1181*4882a593Smuzhiyun 	*rdata = PWRAP_GET_WACS_RDATA(pwrap_readl(wrp, PWRAP_WACS2_RDATA));
1182*4882a593Smuzhiyun 
1183*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
1184*4882a593Smuzhiyun 
1185*4882a593Smuzhiyun 	return 0;
1186*4882a593Smuzhiyun }
1187*4882a593Smuzhiyun 
pwrap_read32(struct pmic_wrapper * wrp,u32 adr,u32 * rdata)1188*4882a593Smuzhiyun static int pwrap_read32(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
1189*4882a593Smuzhiyun {
1190*4882a593Smuzhiyun 	int ret, msb;
1191*4882a593Smuzhiyun 
1192*4882a593Smuzhiyun 	*rdata = 0;
1193*4882a593Smuzhiyun 	for (msb = 0; msb < 2; msb++) {
1194*4882a593Smuzhiyun 		ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
1195*4882a593Smuzhiyun 		if (ret) {
1196*4882a593Smuzhiyun 			pwrap_leave_fsm_vldclr(wrp);
1197*4882a593Smuzhiyun 			return ret;
1198*4882a593Smuzhiyun 		}
1199*4882a593Smuzhiyun 
1200*4882a593Smuzhiyun 		pwrap_writel(wrp, ((msb << 30) | (adr << 16)),
1201*4882a593Smuzhiyun 			     PWRAP_WACS2_CMD);
1202*4882a593Smuzhiyun 
1203*4882a593Smuzhiyun 		ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_vldclr);
1204*4882a593Smuzhiyun 		if (ret)
1205*4882a593Smuzhiyun 			return ret;
1206*4882a593Smuzhiyun 
1207*4882a593Smuzhiyun 		*rdata += (PWRAP_GET_WACS_RDATA(pwrap_readl(wrp,
1208*4882a593Smuzhiyun 			   PWRAP_WACS2_RDATA)) << (16 * msb));
1209*4882a593Smuzhiyun 
1210*4882a593Smuzhiyun 		pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
1211*4882a593Smuzhiyun 	}
1212*4882a593Smuzhiyun 
1213*4882a593Smuzhiyun 	return 0;
1214*4882a593Smuzhiyun }
1215*4882a593Smuzhiyun 
pwrap_read(struct pmic_wrapper * wrp,u32 adr,u32 * rdata)1216*4882a593Smuzhiyun static int pwrap_read(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
1217*4882a593Smuzhiyun {
1218*4882a593Smuzhiyun 	return wrp->slave->pwrap_read(wrp, adr, rdata);
1219*4882a593Smuzhiyun }
1220*4882a593Smuzhiyun 
pwrap_write16(struct pmic_wrapper * wrp,u32 adr,u32 wdata)1221*4882a593Smuzhiyun static int pwrap_write16(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
1222*4882a593Smuzhiyun {
1223*4882a593Smuzhiyun 	int ret;
1224*4882a593Smuzhiyun 
1225*4882a593Smuzhiyun 	ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
1226*4882a593Smuzhiyun 	if (ret) {
1227*4882a593Smuzhiyun 		pwrap_leave_fsm_vldclr(wrp);
1228*4882a593Smuzhiyun 		return ret;
1229*4882a593Smuzhiyun 	}
1230*4882a593Smuzhiyun 
1231*4882a593Smuzhiyun 	pwrap_writel(wrp, (1 << 31) | ((adr >> 1) << 16) | wdata,
1232*4882a593Smuzhiyun 		     PWRAP_WACS2_CMD);
1233*4882a593Smuzhiyun 
1234*4882a593Smuzhiyun 	return 0;
1235*4882a593Smuzhiyun }
1236*4882a593Smuzhiyun 
pwrap_write32(struct pmic_wrapper * wrp,u32 adr,u32 wdata)1237*4882a593Smuzhiyun static int pwrap_write32(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
1238*4882a593Smuzhiyun {
1239*4882a593Smuzhiyun 	int ret, msb, rdata;
1240*4882a593Smuzhiyun 
1241*4882a593Smuzhiyun 	for (msb = 0; msb < 2; msb++) {
1242*4882a593Smuzhiyun 		ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
1243*4882a593Smuzhiyun 		if (ret) {
1244*4882a593Smuzhiyun 			pwrap_leave_fsm_vldclr(wrp);
1245*4882a593Smuzhiyun 			return ret;
1246*4882a593Smuzhiyun 		}
1247*4882a593Smuzhiyun 
1248*4882a593Smuzhiyun 		pwrap_writel(wrp, (1 << 31) | (msb << 30) | (adr << 16) |
1249*4882a593Smuzhiyun 			     ((wdata >> (msb * 16)) & 0xffff),
1250*4882a593Smuzhiyun 			     PWRAP_WACS2_CMD);
1251*4882a593Smuzhiyun 
1252*4882a593Smuzhiyun 		/*
1253*4882a593Smuzhiyun 		 * The pwrap_read operation is the requirement of hardware used
1254*4882a593Smuzhiyun 		 * for the synchronization between two successive 16-bit
1255*4882a593Smuzhiyun 		 * pwrap_writel operations composing one 32-bit bus writing.
1256*4882a593Smuzhiyun 		 * Otherwise, we'll find the result fails on the lower 16-bit
1257*4882a593Smuzhiyun 		 * pwrap writing.
1258*4882a593Smuzhiyun 		 */
1259*4882a593Smuzhiyun 		if (!msb)
1260*4882a593Smuzhiyun 			pwrap_read(wrp, adr, &rdata);
1261*4882a593Smuzhiyun 	}
1262*4882a593Smuzhiyun 
1263*4882a593Smuzhiyun 	return 0;
1264*4882a593Smuzhiyun }
1265*4882a593Smuzhiyun 
pwrap_write(struct pmic_wrapper * wrp,u32 adr,u32 wdata)1266*4882a593Smuzhiyun static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
1267*4882a593Smuzhiyun {
1268*4882a593Smuzhiyun 	return wrp->slave->pwrap_write(wrp, adr, wdata);
1269*4882a593Smuzhiyun }
1270*4882a593Smuzhiyun 
pwrap_regmap_read(void * context,u32 adr,u32 * rdata)1271*4882a593Smuzhiyun static int pwrap_regmap_read(void *context, u32 adr, u32 *rdata)
1272*4882a593Smuzhiyun {
1273*4882a593Smuzhiyun 	return pwrap_read(context, adr, rdata);
1274*4882a593Smuzhiyun }
1275*4882a593Smuzhiyun 
pwrap_regmap_write(void * context,u32 adr,u32 wdata)1276*4882a593Smuzhiyun static int pwrap_regmap_write(void *context, u32 adr, u32 wdata)
1277*4882a593Smuzhiyun {
1278*4882a593Smuzhiyun 	return pwrap_write(context, adr, wdata);
1279*4882a593Smuzhiyun }
1280*4882a593Smuzhiyun 
pwrap_reset_spislave(struct pmic_wrapper * wrp)1281*4882a593Smuzhiyun static int pwrap_reset_spislave(struct pmic_wrapper *wrp)
1282*4882a593Smuzhiyun {
1283*4882a593Smuzhiyun 	int ret, i;
1284*4882a593Smuzhiyun 
1285*4882a593Smuzhiyun 	pwrap_writel(wrp, 0, PWRAP_HIPRIO_ARB_EN);
1286*4882a593Smuzhiyun 	pwrap_writel(wrp, 0, PWRAP_WRAP_EN);
1287*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_MUX_SEL);
1288*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_MAN_EN);
1289*4882a593Smuzhiyun 	pwrap_writel(wrp, 0, PWRAP_DIO_EN);
1290*4882a593Smuzhiyun 
1291*4882a593Smuzhiyun 	pwrap_writel(wrp, wrp->master->spi_w | PWRAP_MAN_CMD_OP_CSL,
1292*4882a593Smuzhiyun 			PWRAP_MAN_CMD);
1293*4882a593Smuzhiyun 	pwrap_writel(wrp, wrp->master->spi_w | PWRAP_MAN_CMD_OP_OUTS,
1294*4882a593Smuzhiyun 			PWRAP_MAN_CMD);
1295*4882a593Smuzhiyun 	pwrap_writel(wrp, wrp->master->spi_w | PWRAP_MAN_CMD_OP_CSH,
1296*4882a593Smuzhiyun 			PWRAP_MAN_CMD);
1297*4882a593Smuzhiyun 
1298*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
1299*4882a593Smuzhiyun 		pwrap_writel(wrp, wrp->master->spi_w | PWRAP_MAN_CMD_OP_OUTS,
1300*4882a593Smuzhiyun 				PWRAP_MAN_CMD);
1301*4882a593Smuzhiyun 
1302*4882a593Smuzhiyun 	ret = pwrap_wait_for_state(wrp, pwrap_is_sync_idle);
1303*4882a593Smuzhiyun 	if (ret) {
1304*4882a593Smuzhiyun 		dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
1305*4882a593Smuzhiyun 		return ret;
1306*4882a593Smuzhiyun 	}
1307*4882a593Smuzhiyun 
1308*4882a593Smuzhiyun 	pwrap_writel(wrp, 0, PWRAP_MAN_EN);
1309*4882a593Smuzhiyun 	pwrap_writel(wrp, 0, PWRAP_MUX_SEL);
1310*4882a593Smuzhiyun 
1311*4882a593Smuzhiyun 	return 0;
1312*4882a593Smuzhiyun }
1313*4882a593Smuzhiyun 
1314*4882a593Smuzhiyun /*
1315*4882a593Smuzhiyun  * pwrap_init_sidly - configure serial input delay
1316*4882a593Smuzhiyun  *
1317*4882a593Smuzhiyun  * This configures the serial input delay. We can configure 0, 2, 4 or 6ns
1318*4882a593Smuzhiyun  * delay. Do a read test with all possible values and chose the best delay.
1319*4882a593Smuzhiyun  */
pwrap_init_sidly(struct pmic_wrapper * wrp)1320*4882a593Smuzhiyun static int pwrap_init_sidly(struct pmic_wrapper *wrp)
1321*4882a593Smuzhiyun {
1322*4882a593Smuzhiyun 	u32 rdata;
1323*4882a593Smuzhiyun 	u32 i;
1324*4882a593Smuzhiyun 	u32 pass = 0;
1325*4882a593Smuzhiyun 	signed char dly[16] = {
1326*4882a593Smuzhiyun 		-1, 0, 1, 0, 2, -1, 1, 1, 3, -1, -1, -1, 3, -1, 2, 1
1327*4882a593Smuzhiyun 	};
1328*4882a593Smuzhiyun 
1329*4882a593Smuzhiyun 	for (i = 0; i < 4; i++) {
1330*4882a593Smuzhiyun 		pwrap_writel(wrp, i, PWRAP_SIDLY);
1331*4882a593Smuzhiyun 		pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_READ_TEST],
1332*4882a593Smuzhiyun 			   &rdata);
1333*4882a593Smuzhiyun 		if (rdata == PWRAP_DEW_READ_TEST_VAL) {
1334*4882a593Smuzhiyun 			dev_dbg(wrp->dev, "[Read Test] pass, SIDLY=%x\n", i);
1335*4882a593Smuzhiyun 			pass |= 1 << i;
1336*4882a593Smuzhiyun 		}
1337*4882a593Smuzhiyun 	}
1338*4882a593Smuzhiyun 
1339*4882a593Smuzhiyun 	if (dly[pass] < 0) {
1340*4882a593Smuzhiyun 		dev_err(wrp->dev, "sidly pass range 0x%x not continuous\n",
1341*4882a593Smuzhiyun 				pass);
1342*4882a593Smuzhiyun 		return -EIO;
1343*4882a593Smuzhiyun 	}
1344*4882a593Smuzhiyun 
1345*4882a593Smuzhiyun 	pwrap_writel(wrp, dly[pass], PWRAP_SIDLY);
1346*4882a593Smuzhiyun 
1347*4882a593Smuzhiyun 	return 0;
1348*4882a593Smuzhiyun }
1349*4882a593Smuzhiyun 
pwrap_init_dual_io(struct pmic_wrapper * wrp)1350*4882a593Smuzhiyun static int pwrap_init_dual_io(struct pmic_wrapper *wrp)
1351*4882a593Smuzhiyun {
1352*4882a593Smuzhiyun 	int ret;
1353*4882a593Smuzhiyun 	u32 rdata;
1354*4882a593Smuzhiyun 
1355*4882a593Smuzhiyun 	/* Enable dual IO mode */
1356*4882a593Smuzhiyun 	pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_DIO_EN], 1);
1357*4882a593Smuzhiyun 
1358*4882a593Smuzhiyun 	/* Check IDLE & INIT_DONE in advance */
1359*4882a593Smuzhiyun 	ret = pwrap_wait_for_state(wrp,
1360*4882a593Smuzhiyun 				   pwrap_is_fsm_idle_and_sync_idle);
1361*4882a593Smuzhiyun 	if (ret) {
1362*4882a593Smuzhiyun 		dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
1363*4882a593Smuzhiyun 		return ret;
1364*4882a593Smuzhiyun 	}
1365*4882a593Smuzhiyun 
1366*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_DIO_EN);
1367*4882a593Smuzhiyun 
1368*4882a593Smuzhiyun 	/* Read Test */
1369*4882a593Smuzhiyun 	pwrap_read(wrp,
1370*4882a593Smuzhiyun 		   wrp->slave->dew_regs[PWRAP_DEW_READ_TEST], &rdata);
1371*4882a593Smuzhiyun 	if (rdata != PWRAP_DEW_READ_TEST_VAL) {
1372*4882a593Smuzhiyun 		dev_err(wrp->dev,
1373*4882a593Smuzhiyun 			"Read failed on DIO mode: 0x%04x!=0x%04x\n",
1374*4882a593Smuzhiyun 			PWRAP_DEW_READ_TEST_VAL, rdata);
1375*4882a593Smuzhiyun 		return -EFAULT;
1376*4882a593Smuzhiyun 	}
1377*4882a593Smuzhiyun 
1378*4882a593Smuzhiyun 	return 0;
1379*4882a593Smuzhiyun }
1380*4882a593Smuzhiyun 
1381*4882a593Smuzhiyun /*
1382*4882a593Smuzhiyun  * pwrap_init_chip_select_ext is used to configure CS extension time for each
1383*4882a593Smuzhiyun  * phase during data transactions on the pwrap bus.
1384*4882a593Smuzhiyun  */
pwrap_init_chip_select_ext(struct pmic_wrapper * wrp,u8 hext_write,u8 hext_read,u8 lext_start,u8 lext_end)1385*4882a593Smuzhiyun static void pwrap_init_chip_select_ext(struct pmic_wrapper *wrp, u8 hext_write,
1386*4882a593Smuzhiyun 				       u8 hext_read, u8 lext_start,
1387*4882a593Smuzhiyun 				       u8 lext_end)
1388*4882a593Smuzhiyun {
1389*4882a593Smuzhiyun 	/*
1390*4882a593Smuzhiyun 	 * After finishing a write and read transaction, extends CS high time
1391*4882a593Smuzhiyun 	 * to be at least xT of BUS CLK as hext_write and hext_read specifies
1392*4882a593Smuzhiyun 	 * respectively.
1393*4882a593Smuzhiyun 	 */
1394*4882a593Smuzhiyun 	pwrap_writel(wrp, hext_write, PWRAP_CSHEXT_WRITE);
1395*4882a593Smuzhiyun 	pwrap_writel(wrp, hext_read, PWRAP_CSHEXT_READ);
1396*4882a593Smuzhiyun 
1397*4882a593Smuzhiyun 	/*
1398*4882a593Smuzhiyun 	 * Extends CS low time after CSL and before CSH command to be at
1399*4882a593Smuzhiyun 	 * least xT of BUS CLK as lext_start and lext_end specifies
1400*4882a593Smuzhiyun 	 * respectively.
1401*4882a593Smuzhiyun 	 */
1402*4882a593Smuzhiyun 	pwrap_writel(wrp, lext_start, PWRAP_CSLEXT_START);
1403*4882a593Smuzhiyun 	pwrap_writel(wrp, lext_end, PWRAP_CSLEXT_END);
1404*4882a593Smuzhiyun }
1405*4882a593Smuzhiyun 
pwrap_common_init_reg_clock(struct pmic_wrapper * wrp)1406*4882a593Smuzhiyun static int pwrap_common_init_reg_clock(struct pmic_wrapper *wrp)
1407*4882a593Smuzhiyun {
1408*4882a593Smuzhiyun 	switch (wrp->master->type) {
1409*4882a593Smuzhiyun 	case PWRAP_MT8173:
1410*4882a593Smuzhiyun 		pwrap_init_chip_select_ext(wrp, 0, 4, 2, 2);
1411*4882a593Smuzhiyun 		break;
1412*4882a593Smuzhiyun 	case PWRAP_MT8135:
1413*4882a593Smuzhiyun 		pwrap_writel(wrp, 0x4, PWRAP_CSHEXT);
1414*4882a593Smuzhiyun 		pwrap_init_chip_select_ext(wrp, 0, 4, 0, 0);
1415*4882a593Smuzhiyun 		break;
1416*4882a593Smuzhiyun 	default:
1417*4882a593Smuzhiyun 		break;
1418*4882a593Smuzhiyun 	}
1419*4882a593Smuzhiyun 
1420*4882a593Smuzhiyun 	return 0;
1421*4882a593Smuzhiyun }
1422*4882a593Smuzhiyun 
pwrap_mt2701_init_reg_clock(struct pmic_wrapper * wrp)1423*4882a593Smuzhiyun static int pwrap_mt2701_init_reg_clock(struct pmic_wrapper *wrp)
1424*4882a593Smuzhiyun {
1425*4882a593Smuzhiyun 	switch (wrp->slave->type) {
1426*4882a593Smuzhiyun 	case PMIC_MT6397:
1427*4882a593Smuzhiyun 		pwrap_writel(wrp, 0xc, PWRAP_RDDMY);
1428*4882a593Smuzhiyun 		pwrap_init_chip_select_ext(wrp, 4, 0, 2, 2);
1429*4882a593Smuzhiyun 		break;
1430*4882a593Smuzhiyun 
1431*4882a593Smuzhiyun 	case PMIC_MT6323:
1432*4882a593Smuzhiyun 		pwrap_writel(wrp, 0x8, PWRAP_RDDMY);
1433*4882a593Smuzhiyun 		pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_RDDMY_NO],
1434*4882a593Smuzhiyun 			    0x8);
1435*4882a593Smuzhiyun 		pwrap_init_chip_select_ext(wrp, 5, 0, 2, 2);
1436*4882a593Smuzhiyun 		break;
1437*4882a593Smuzhiyun 	default:
1438*4882a593Smuzhiyun 		break;
1439*4882a593Smuzhiyun 	}
1440*4882a593Smuzhiyun 
1441*4882a593Smuzhiyun 	return 0;
1442*4882a593Smuzhiyun }
1443*4882a593Smuzhiyun 
pwrap_is_cipher_ready(struct pmic_wrapper * wrp)1444*4882a593Smuzhiyun static bool pwrap_is_cipher_ready(struct pmic_wrapper *wrp)
1445*4882a593Smuzhiyun {
1446*4882a593Smuzhiyun 	return pwrap_readl(wrp, PWRAP_CIPHER_RDY) & 1;
1447*4882a593Smuzhiyun }
1448*4882a593Smuzhiyun 
pwrap_is_pmic_cipher_ready(struct pmic_wrapper * wrp)1449*4882a593Smuzhiyun static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper *wrp)
1450*4882a593Smuzhiyun {
1451*4882a593Smuzhiyun 	u32 rdata;
1452*4882a593Smuzhiyun 	int ret;
1453*4882a593Smuzhiyun 
1454*4882a593Smuzhiyun 	ret = pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_RDY],
1455*4882a593Smuzhiyun 			 &rdata);
1456*4882a593Smuzhiyun 	if (ret)
1457*4882a593Smuzhiyun 		return false;
1458*4882a593Smuzhiyun 
1459*4882a593Smuzhiyun 	return rdata == 1;
1460*4882a593Smuzhiyun }
1461*4882a593Smuzhiyun 
pwrap_init_cipher(struct pmic_wrapper * wrp)1462*4882a593Smuzhiyun static int pwrap_init_cipher(struct pmic_wrapper *wrp)
1463*4882a593Smuzhiyun {
1464*4882a593Smuzhiyun 	int ret;
1465*4882a593Smuzhiyun 	u32 rdata = 0;
1466*4882a593Smuzhiyun 
1467*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x1, PWRAP_CIPHER_SWRST);
1468*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x0, PWRAP_CIPHER_SWRST);
1469*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x1, PWRAP_CIPHER_KEY_SEL);
1470*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x2, PWRAP_CIPHER_IV_SEL);
1471*4882a593Smuzhiyun 
1472*4882a593Smuzhiyun 	switch (wrp->master->type) {
1473*4882a593Smuzhiyun 	case PWRAP_MT8135:
1474*4882a593Smuzhiyun 		pwrap_writel(wrp, 1, PWRAP_CIPHER_LOAD);
1475*4882a593Smuzhiyun 		pwrap_writel(wrp, 1, PWRAP_CIPHER_START);
1476*4882a593Smuzhiyun 		break;
1477*4882a593Smuzhiyun 	case PWRAP_MT2701:
1478*4882a593Smuzhiyun 	case PWRAP_MT6765:
1479*4882a593Smuzhiyun 	case PWRAP_MT6779:
1480*4882a593Smuzhiyun 	case PWRAP_MT6797:
1481*4882a593Smuzhiyun 	case PWRAP_MT8173:
1482*4882a593Smuzhiyun 	case PWRAP_MT8516:
1483*4882a593Smuzhiyun 		pwrap_writel(wrp, 1, PWRAP_CIPHER_EN);
1484*4882a593Smuzhiyun 		break;
1485*4882a593Smuzhiyun 	case PWRAP_MT7622:
1486*4882a593Smuzhiyun 		pwrap_writel(wrp, 0, PWRAP_CIPHER_EN);
1487*4882a593Smuzhiyun 		break;
1488*4882a593Smuzhiyun 	case PWRAP_MT8183:
1489*4882a593Smuzhiyun 		break;
1490*4882a593Smuzhiyun 	}
1491*4882a593Smuzhiyun 
1492*4882a593Smuzhiyun 	/* Config cipher mode @PMIC */
1493*4882a593Smuzhiyun 	pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_SWRST], 0x1);
1494*4882a593Smuzhiyun 	pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_SWRST], 0x0);
1495*4882a593Smuzhiyun 	pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_KEY_SEL], 0x1);
1496*4882a593Smuzhiyun 	pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_IV_SEL], 0x2);
1497*4882a593Smuzhiyun 
1498*4882a593Smuzhiyun 	switch (wrp->slave->type) {
1499*4882a593Smuzhiyun 	case PMIC_MT6397:
1500*4882a593Smuzhiyun 		pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_LOAD],
1501*4882a593Smuzhiyun 			    0x1);
1502*4882a593Smuzhiyun 		pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_START],
1503*4882a593Smuzhiyun 			    0x1);
1504*4882a593Smuzhiyun 		break;
1505*4882a593Smuzhiyun 	case PMIC_MT6323:
1506*4882a593Smuzhiyun 	case PMIC_MT6351:
1507*4882a593Smuzhiyun 	case PMIC_MT6357:
1508*4882a593Smuzhiyun 		pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_EN],
1509*4882a593Smuzhiyun 			    0x1);
1510*4882a593Smuzhiyun 		break;
1511*4882a593Smuzhiyun 	default:
1512*4882a593Smuzhiyun 		break;
1513*4882a593Smuzhiyun 	}
1514*4882a593Smuzhiyun 
1515*4882a593Smuzhiyun 	/* wait for cipher data ready@AP */
1516*4882a593Smuzhiyun 	ret = pwrap_wait_for_state(wrp, pwrap_is_cipher_ready);
1517*4882a593Smuzhiyun 	if (ret) {
1518*4882a593Smuzhiyun 		dev_err(wrp->dev, "cipher data ready@AP fail, ret=%d\n", ret);
1519*4882a593Smuzhiyun 		return ret;
1520*4882a593Smuzhiyun 	}
1521*4882a593Smuzhiyun 
1522*4882a593Smuzhiyun 	/* wait for cipher data ready@PMIC */
1523*4882a593Smuzhiyun 	ret = pwrap_wait_for_state(wrp, pwrap_is_pmic_cipher_ready);
1524*4882a593Smuzhiyun 	if (ret) {
1525*4882a593Smuzhiyun 		dev_err(wrp->dev,
1526*4882a593Smuzhiyun 			"timeout waiting for cipher data ready@PMIC\n");
1527*4882a593Smuzhiyun 		return ret;
1528*4882a593Smuzhiyun 	}
1529*4882a593Smuzhiyun 
1530*4882a593Smuzhiyun 	/* wait for cipher mode idle */
1531*4882a593Smuzhiyun 	pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_MODE], 0x1);
1532*4882a593Smuzhiyun 	ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle_and_sync_idle);
1533*4882a593Smuzhiyun 	if (ret) {
1534*4882a593Smuzhiyun 		dev_err(wrp->dev, "cipher mode idle fail, ret=%d\n", ret);
1535*4882a593Smuzhiyun 		return ret;
1536*4882a593Smuzhiyun 	}
1537*4882a593Smuzhiyun 
1538*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_CIPHER_MODE);
1539*4882a593Smuzhiyun 
1540*4882a593Smuzhiyun 	/* Write Test */
1541*4882a593Smuzhiyun 	if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_WRITE_TEST],
1542*4882a593Smuzhiyun 			PWRAP_DEW_WRITE_TEST_VAL) ||
1543*4882a593Smuzhiyun 	    pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_WRITE_TEST],
1544*4882a593Smuzhiyun 		       &rdata) ||
1545*4882a593Smuzhiyun 	    (rdata != PWRAP_DEW_WRITE_TEST_VAL)) {
1546*4882a593Smuzhiyun 		dev_err(wrp->dev, "rdata=0x%04X\n", rdata);
1547*4882a593Smuzhiyun 		return -EFAULT;
1548*4882a593Smuzhiyun 	}
1549*4882a593Smuzhiyun 
1550*4882a593Smuzhiyun 	return 0;
1551*4882a593Smuzhiyun }
1552*4882a593Smuzhiyun 
pwrap_init_security(struct pmic_wrapper * wrp)1553*4882a593Smuzhiyun static int pwrap_init_security(struct pmic_wrapper *wrp)
1554*4882a593Smuzhiyun {
1555*4882a593Smuzhiyun 	int ret;
1556*4882a593Smuzhiyun 
1557*4882a593Smuzhiyun 	/* Enable encryption */
1558*4882a593Smuzhiyun 	ret = pwrap_init_cipher(wrp);
1559*4882a593Smuzhiyun 	if (ret)
1560*4882a593Smuzhiyun 		return ret;
1561*4882a593Smuzhiyun 
1562*4882a593Smuzhiyun 	/* Signature checking - using CRC */
1563*4882a593Smuzhiyun 	if (pwrap_write(wrp,
1564*4882a593Smuzhiyun 			wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1))
1565*4882a593Smuzhiyun 		return -EFAULT;
1566*4882a593Smuzhiyun 
1567*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x1, PWRAP_CRC_EN);
1568*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x0, PWRAP_SIG_MODE);
1569*4882a593Smuzhiyun 	pwrap_writel(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_VAL],
1570*4882a593Smuzhiyun 		     PWRAP_SIG_ADR);
1571*4882a593Smuzhiyun 	pwrap_writel(wrp,
1572*4882a593Smuzhiyun 		     wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
1573*4882a593Smuzhiyun 
1574*4882a593Smuzhiyun 	return 0;
1575*4882a593Smuzhiyun }
1576*4882a593Smuzhiyun 
pwrap_mt8135_init_soc_specific(struct pmic_wrapper * wrp)1577*4882a593Smuzhiyun static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
1578*4882a593Smuzhiyun {
1579*4882a593Smuzhiyun 	/* enable pwrap events and pwrap bridge in AP side */
1580*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
1581*4882a593Smuzhiyun 	pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
1582*4882a593Smuzhiyun 	writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
1583*4882a593Smuzhiyun 	writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
1584*4882a593Smuzhiyun 	writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
1585*4882a593Smuzhiyun 	writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
1586*4882a593Smuzhiyun 	writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
1587*4882a593Smuzhiyun 	writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
1588*4882a593Smuzhiyun 	writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
1589*4882a593Smuzhiyun 
1590*4882a593Smuzhiyun 	/* enable PMIC event out and sources */
1591*4882a593Smuzhiyun 	if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_EVENT_OUT_EN],
1592*4882a593Smuzhiyun 			0x1) ||
1593*4882a593Smuzhiyun 	    pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_EVENT_SRC_EN],
1594*4882a593Smuzhiyun 			0xffff)) {
1595*4882a593Smuzhiyun 		dev_err(wrp->dev, "enable dewrap fail\n");
1596*4882a593Smuzhiyun 		return -EFAULT;
1597*4882a593Smuzhiyun 	}
1598*4882a593Smuzhiyun 
1599*4882a593Smuzhiyun 	return 0;
1600*4882a593Smuzhiyun }
1601*4882a593Smuzhiyun 
pwrap_mt8173_init_soc_specific(struct pmic_wrapper * wrp)1602*4882a593Smuzhiyun static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper *wrp)
1603*4882a593Smuzhiyun {
1604*4882a593Smuzhiyun 	/* PMIC_DEWRAP enables */
1605*4882a593Smuzhiyun 	if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_EVENT_OUT_EN],
1606*4882a593Smuzhiyun 			0x1) ||
1607*4882a593Smuzhiyun 	    pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_EVENT_SRC_EN],
1608*4882a593Smuzhiyun 			0xffff)) {
1609*4882a593Smuzhiyun 		dev_err(wrp->dev, "enable dewrap fail\n");
1610*4882a593Smuzhiyun 		return -EFAULT;
1611*4882a593Smuzhiyun 	}
1612*4882a593Smuzhiyun 
1613*4882a593Smuzhiyun 	return 0;
1614*4882a593Smuzhiyun }
1615*4882a593Smuzhiyun 
pwrap_mt2701_init_soc_specific(struct pmic_wrapper * wrp)1616*4882a593Smuzhiyun static int pwrap_mt2701_init_soc_specific(struct pmic_wrapper *wrp)
1617*4882a593Smuzhiyun {
1618*4882a593Smuzhiyun 	/* GPS_INTF initialization */
1619*4882a593Smuzhiyun 	switch (wrp->slave->type) {
1620*4882a593Smuzhiyun 	case PMIC_MT6323:
1621*4882a593Smuzhiyun 		pwrap_writel(wrp, 0x076c, PWRAP_ADC_CMD_ADDR);
1622*4882a593Smuzhiyun 		pwrap_writel(wrp, 0x8000, PWRAP_PWRAP_ADC_CMD);
1623*4882a593Smuzhiyun 		pwrap_writel(wrp, 0x072c, PWRAP_ADC_RDY_ADDR);
1624*4882a593Smuzhiyun 		pwrap_writel(wrp, 0x072e, PWRAP_ADC_RDATA_ADDR1);
1625*4882a593Smuzhiyun 		pwrap_writel(wrp, 0x0730, PWRAP_ADC_RDATA_ADDR2);
1626*4882a593Smuzhiyun 		break;
1627*4882a593Smuzhiyun 	default:
1628*4882a593Smuzhiyun 		break;
1629*4882a593Smuzhiyun 	}
1630*4882a593Smuzhiyun 
1631*4882a593Smuzhiyun 	return 0;
1632*4882a593Smuzhiyun }
1633*4882a593Smuzhiyun 
pwrap_mt7622_init_soc_specific(struct pmic_wrapper * wrp)1634*4882a593Smuzhiyun static int pwrap_mt7622_init_soc_specific(struct pmic_wrapper *wrp)
1635*4882a593Smuzhiyun {
1636*4882a593Smuzhiyun 	pwrap_writel(wrp, 0, PWRAP_STAUPD_PRD);
1637*4882a593Smuzhiyun 	/* enable 2wire SPI master */
1638*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x8000000, PWRAP_SPI2_CTRL);
1639*4882a593Smuzhiyun 
1640*4882a593Smuzhiyun 	return 0;
1641*4882a593Smuzhiyun }
1642*4882a593Smuzhiyun 
pwrap_mt8183_init_soc_specific(struct pmic_wrapper * wrp)1643*4882a593Smuzhiyun static int pwrap_mt8183_init_soc_specific(struct pmic_wrapper *wrp)
1644*4882a593Smuzhiyun {
1645*4882a593Smuzhiyun 	pwrap_writel(wrp, 0xf5, PWRAP_STAUPD_GRPEN);
1646*4882a593Smuzhiyun 
1647*4882a593Smuzhiyun 	pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1);
1648*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_CRC_EN);
1649*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x416, PWRAP_SIG_ADR);
1650*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x42e, PWRAP_EINT_STA0_ADR);
1651*4882a593Smuzhiyun 
1652*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_WACS_P2P_EN);
1653*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_WACS_MD32_EN);
1654*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_INIT_DONE_P2P);
1655*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_INIT_DONE_MD32);
1656*4882a593Smuzhiyun 
1657*4882a593Smuzhiyun 	return 0;
1658*4882a593Smuzhiyun }
1659*4882a593Smuzhiyun 
pwrap_init(struct pmic_wrapper * wrp)1660*4882a593Smuzhiyun static int pwrap_init(struct pmic_wrapper *wrp)
1661*4882a593Smuzhiyun {
1662*4882a593Smuzhiyun 	int ret;
1663*4882a593Smuzhiyun 
1664*4882a593Smuzhiyun 	if (wrp->rstc)
1665*4882a593Smuzhiyun 		reset_control_reset(wrp->rstc);
1666*4882a593Smuzhiyun 	if (wrp->rstc_bridge)
1667*4882a593Smuzhiyun 		reset_control_reset(wrp->rstc_bridge);
1668*4882a593Smuzhiyun 
1669*4882a593Smuzhiyun 	if (wrp->master->type == PWRAP_MT8173) {
1670*4882a593Smuzhiyun 		/* Enable DCM */
1671*4882a593Smuzhiyun 		pwrap_writel(wrp, 3, PWRAP_DCM_EN);
1672*4882a593Smuzhiyun 		pwrap_writel(wrp, 0, PWRAP_DCM_DBC_PRD);
1673*4882a593Smuzhiyun 	}
1674*4882a593Smuzhiyun 
1675*4882a593Smuzhiyun 	if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
1676*4882a593Smuzhiyun 		/* Reset SPI slave */
1677*4882a593Smuzhiyun 		ret = pwrap_reset_spislave(wrp);
1678*4882a593Smuzhiyun 		if (ret)
1679*4882a593Smuzhiyun 			return ret;
1680*4882a593Smuzhiyun 	}
1681*4882a593Smuzhiyun 
1682*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_WRAP_EN);
1683*4882a593Smuzhiyun 
1684*4882a593Smuzhiyun 	pwrap_writel(wrp, wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
1685*4882a593Smuzhiyun 
1686*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_WACS2_EN);
1687*4882a593Smuzhiyun 
1688*4882a593Smuzhiyun 	ret = wrp->master->init_reg_clock(wrp);
1689*4882a593Smuzhiyun 	if (ret)
1690*4882a593Smuzhiyun 		return ret;
1691*4882a593Smuzhiyun 
1692*4882a593Smuzhiyun 	if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
1693*4882a593Smuzhiyun 		/* Setup serial input delay */
1694*4882a593Smuzhiyun 		ret = pwrap_init_sidly(wrp);
1695*4882a593Smuzhiyun 		if (ret)
1696*4882a593Smuzhiyun 			return ret;
1697*4882a593Smuzhiyun 	}
1698*4882a593Smuzhiyun 
1699*4882a593Smuzhiyun 	if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_DUALIO)) {
1700*4882a593Smuzhiyun 		/* Enable dual I/O mode */
1701*4882a593Smuzhiyun 		ret = pwrap_init_dual_io(wrp);
1702*4882a593Smuzhiyun 		if (ret)
1703*4882a593Smuzhiyun 			return ret;
1704*4882a593Smuzhiyun 	}
1705*4882a593Smuzhiyun 
1706*4882a593Smuzhiyun 	if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SECURITY)) {
1707*4882a593Smuzhiyun 		/* Enable security on bus */
1708*4882a593Smuzhiyun 		ret = pwrap_init_security(wrp);
1709*4882a593Smuzhiyun 		if (ret)
1710*4882a593Smuzhiyun 			return ret;
1711*4882a593Smuzhiyun 	}
1712*4882a593Smuzhiyun 
1713*4882a593Smuzhiyun 	if (wrp->master->type == PWRAP_MT8135)
1714*4882a593Smuzhiyun 		pwrap_writel(wrp, 0x7, PWRAP_RRARB_EN);
1715*4882a593Smuzhiyun 
1716*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x1, PWRAP_WACS0_EN);
1717*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x1, PWRAP_WACS1_EN);
1718*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x1, PWRAP_WACS2_EN);
1719*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x5, PWRAP_STAUPD_PRD);
1720*4882a593Smuzhiyun 	pwrap_writel(wrp, 0xff, PWRAP_STAUPD_GRPEN);
1721*4882a593Smuzhiyun 
1722*4882a593Smuzhiyun 	if (wrp->master->init_soc_specific) {
1723*4882a593Smuzhiyun 		ret = wrp->master->init_soc_specific(wrp);
1724*4882a593Smuzhiyun 		if (ret)
1725*4882a593Smuzhiyun 			return ret;
1726*4882a593Smuzhiyun 	}
1727*4882a593Smuzhiyun 
1728*4882a593Smuzhiyun 	/* Setup the init done registers */
1729*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_INIT_DONE2);
1730*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_INIT_DONE0);
1731*4882a593Smuzhiyun 	pwrap_writel(wrp, 1, PWRAP_INIT_DONE1);
1732*4882a593Smuzhiyun 
1733*4882a593Smuzhiyun 	if (HAS_CAP(wrp->master->caps, PWRAP_CAP_BRIDGE)) {
1734*4882a593Smuzhiyun 		writel(1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INIT_DONE3);
1735*4882a593Smuzhiyun 		writel(1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INIT_DONE4);
1736*4882a593Smuzhiyun 	}
1737*4882a593Smuzhiyun 
1738*4882a593Smuzhiyun 	return 0;
1739*4882a593Smuzhiyun }
1740*4882a593Smuzhiyun 
pwrap_interrupt(int irqno,void * dev_id)1741*4882a593Smuzhiyun static irqreturn_t pwrap_interrupt(int irqno, void *dev_id)
1742*4882a593Smuzhiyun {
1743*4882a593Smuzhiyun 	u32 rdata;
1744*4882a593Smuzhiyun 	struct pmic_wrapper *wrp = dev_id;
1745*4882a593Smuzhiyun 
1746*4882a593Smuzhiyun 	rdata = pwrap_readl(wrp, PWRAP_INT_FLG);
1747*4882a593Smuzhiyun 	dev_err(wrp->dev, "unexpected interrupt int=0x%x\n", rdata);
1748*4882a593Smuzhiyun 	pwrap_writel(wrp, 0xffffffff, PWRAP_INT_CLR);
1749*4882a593Smuzhiyun 
1750*4882a593Smuzhiyun 	if (HAS_CAP(wrp->master->caps, PWRAP_CAP_INT1_EN)) {
1751*4882a593Smuzhiyun 		rdata = pwrap_readl(wrp, PWRAP_INT1_FLG);
1752*4882a593Smuzhiyun 		dev_err(wrp->dev, "unexpected interrupt int1=0x%x\n", rdata);
1753*4882a593Smuzhiyun 		pwrap_writel(wrp, 0xffffffff, PWRAP_INT1_CLR);
1754*4882a593Smuzhiyun 	}
1755*4882a593Smuzhiyun 
1756*4882a593Smuzhiyun 	return IRQ_HANDLED;
1757*4882a593Smuzhiyun }
1758*4882a593Smuzhiyun 
1759*4882a593Smuzhiyun static const struct regmap_config pwrap_regmap_config16 = {
1760*4882a593Smuzhiyun 	.reg_bits = 16,
1761*4882a593Smuzhiyun 	.val_bits = 16,
1762*4882a593Smuzhiyun 	.reg_stride = 2,
1763*4882a593Smuzhiyun 	.reg_read = pwrap_regmap_read,
1764*4882a593Smuzhiyun 	.reg_write = pwrap_regmap_write,
1765*4882a593Smuzhiyun 	.max_register = 0xffff,
1766*4882a593Smuzhiyun };
1767*4882a593Smuzhiyun 
1768*4882a593Smuzhiyun static const struct regmap_config pwrap_regmap_config32 = {
1769*4882a593Smuzhiyun 	.reg_bits = 32,
1770*4882a593Smuzhiyun 	.val_bits = 32,
1771*4882a593Smuzhiyun 	.reg_stride = 4,
1772*4882a593Smuzhiyun 	.reg_read = pwrap_regmap_read,
1773*4882a593Smuzhiyun 	.reg_write = pwrap_regmap_write,
1774*4882a593Smuzhiyun 	.max_register = 0xffff,
1775*4882a593Smuzhiyun };
1776*4882a593Smuzhiyun 
1777*4882a593Smuzhiyun static const struct pwrap_slv_type pmic_mt6323 = {
1778*4882a593Smuzhiyun 	.dew_regs = mt6323_regs,
1779*4882a593Smuzhiyun 	.type = PMIC_MT6323,
1780*4882a593Smuzhiyun 	.regmap = &pwrap_regmap_config16,
1781*4882a593Smuzhiyun 	.caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO |
1782*4882a593Smuzhiyun 		PWRAP_SLV_CAP_SECURITY,
1783*4882a593Smuzhiyun 	.pwrap_read = pwrap_read16,
1784*4882a593Smuzhiyun 	.pwrap_write = pwrap_write16,
1785*4882a593Smuzhiyun };
1786*4882a593Smuzhiyun 
1787*4882a593Smuzhiyun static const struct pwrap_slv_type pmic_mt6351 = {
1788*4882a593Smuzhiyun 	.dew_regs = mt6351_regs,
1789*4882a593Smuzhiyun 	.type = PMIC_MT6351,
1790*4882a593Smuzhiyun 	.regmap = &pwrap_regmap_config16,
1791*4882a593Smuzhiyun 	.caps = 0,
1792*4882a593Smuzhiyun 	.pwrap_read = pwrap_read16,
1793*4882a593Smuzhiyun 	.pwrap_write = pwrap_write16,
1794*4882a593Smuzhiyun };
1795*4882a593Smuzhiyun 
1796*4882a593Smuzhiyun static const struct pwrap_slv_type pmic_mt6357 = {
1797*4882a593Smuzhiyun 	.dew_regs = mt6357_regs,
1798*4882a593Smuzhiyun 	.type = PMIC_MT6357,
1799*4882a593Smuzhiyun 	.regmap = &pwrap_regmap_config16,
1800*4882a593Smuzhiyun 	.caps = 0,
1801*4882a593Smuzhiyun 	.pwrap_read = pwrap_read16,
1802*4882a593Smuzhiyun 	.pwrap_write = pwrap_write16,
1803*4882a593Smuzhiyun };
1804*4882a593Smuzhiyun 
1805*4882a593Smuzhiyun static const struct pwrap_slv_type pmic_mt6358 = {
1806*4882a593Smuzhiyun 	.dew_regs = mt6358_regs,
1807*4882a593Smuzhiyun 	.type = PMIC_MT6358,
1808*4882a593Smuzhiyun 	.regmap = &pwrap_regmap_config16,
1809*4882a593Smuzhiyun 	.caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO,
1810*4882a593Smuzhiyun 	.pwrap_read = pwrap_read16,
1811*4882a593Smuzhiyun 	.pwrap_write = pwrap_write16,
1812*4882a593Smuzhiyun };
1813*4882a593Smuzhiyun 
1814*4882a593Smuzhiyun static const struct pwrap_slv_type pmic_mt6359 = {
1815*4882a593Smuzhiyun 	.dew_regs = mt6359_regs,
1816*4882a593Smuzhiyun 	.type = PMIC_MT6359,
1817*4882a593Smuzhiyun 	.regmap = &pwrap_regmap_config16,
1818*4882a593Smuzhiyun 	.caps = PWRAP_SLV_CAP_DUALIO,
1819*4882a593Smuzhiyun 	.pwrap_read = pwrap_read16,
1820*4882a593Smuzhiyun 	.pwrap_write = pwrap_write16,
1821*4882a593Smuzhiyun };
1822*4882a593Smuzhiyun 
1823*4882a593Smuzhiyun static const struct pwrap_slv_type pmic_mt6380 = {
1824*4882a593Smuzhiyun 	.dew_regs = NULL,
1825*4882a593Smuzhiyun 	.type = PMIC_MT6380,
1826*4882a593Smuzhiyun 	.regmap = &pwrap_regmap_config32,
1827*4882a593Smuzhiyun 	.caps = 0,
1828*4882a593Smuzhiyun 	.pwrap_read = pwrap_read32,
1829*4882a593Smuzhiyun 	.pwrap_write = pwrap_write32,
1830*4882a593Smuzhiyun };
1831*4882a593Smuzhiyun 
1832*4882a593Smuzhiyun static const struct pwrap_slv_type pmic_mt6397 = {
1833*4882a593Smuzhiyun 	.dew_regs = mt6397_regs,
1834*4882a593Smuzhiyun 	.type = PMIC_MT6397,
1835*4882a593Smuzhiyun 	.regmap = &pwrap_regmap_config16,
1836*4882a593Smuzhiyun 	.caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO |
1837*4882a593Smuzhiyun 		PWRAP_SLV_CAP_SECURITY,
1838*4882a593Smuzhiyun 	.pwrap_read = pwrap_read16,
1839*4882a593Smuzhiyun 	.pwrap_write = pwrap_write16,
1840*4882a593Smuzhiyun };
1841*4882a593Smuzhiyun 
1842*4882a593Smuzhiyun static const struct of_device_id of_slave_match_tbl[] = {
1843*4882a593Smuzhiyun 	{
1844*4882a593Smuzhiyun 		.compatible = "mediatek,mt6323",
1845*4882a593Smuzhiyun 		.data = &pmic_mt6323,
1846*4882a593Smuzhiyun 	}, {
1847*4882a593Smuzhiyun 		.compatible = "mediatek,mt6351",
1848*4882a593Smuzhiyun 		.data = &pmic_mt6351,
1849*4882a593Smuzhiyun 	}, {
1850*4882a593Smuzhiyun 		.compatible = "mediatek,mt6357",
1851*4882a593Smuzhiyun 		.data = &pmic_mt6357,
1852*4882a593Smuzhiyun 	}, {
1853*4882a593Smuzhiyun 		.compatible = "mediatek,mt6358",
1854*4882a593Smuzhiyun 		.data = &pmic_mt6358,
1855*4882a593Smuzhiyun 	}, {
1856*4882a593Smuzhiyun 		.compatible = "mediatek,mt6359",
1857*4882a593Smuzhiyun 		.data = &pmic_mt6359,
1858*4882a593Smuzhiyun 	}, {
1859*4882a593Smuzhiyun 		/* The MT6380 PMIC only implements a regulator, so we bind it
1860*4882a593Smuzhiyun 		 * directly instead of using a MFD.
1861*4882a593Smuzhiyun 		 */
1862*4882a593Smuzhiyun 		.compatible = "mediatek,mt6380-regulator",
1863*4882a593Smuzhiyun 		.data = &pmic_mt6380,
1864*4882a593Smuzhiyun 	}, {
1865*4882a593Smuzhiyun 		.compatible = "mediatek,mt6397",
1866*4882a593Smuzhiyun 		.data = &pmic_mt6397,
1867*4882a593Smuzhiyun 	}, {
1868*4882a593Smuzhiyun 		/* sentinel */
1869*4882a593Smuzhiyun 	}
1870*4882a593Smuzhiyun };
1871*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, of_slave_match_tbl);
1872*4882a593Smuzhiyun 
1873*4882a593Smuzhiyun static const struct pmic_wrapper_type pwrap_mt2701 = {
1874*4882a593Smuzhiyun 	.regs = mt2701_regs,
1875*4882a593Smuzhiyun 	.type = PWRAP_MT2701,
1876*4882a593Smuzhiyun 	.arb_en_all = 0x3f,
1877*4882a593Smuzhiyun 	.int_en_all = ~(u32)(BIT(31) | BIT(2)),
1878*4882a593Smuzhiyun 	.int1_en_all = 0,
1879*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE_NEW,
1880*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_ALL,
1881*4882a593Smuzhiyun 	.caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
1882*4882a593Smuzhiyun 	.init_reg_clock = pwrap_mt2701_init_reg_clock,
1883*4882a593Smuzhiyun 	.init_soc_specific = pwrap_mt2701_init_soc_specific,
1884*4882a593Smuzhiyun };
1885*4882a593Smuzhiyun 
1886*4882a593Smuzhiyun static const struct pmic_wrapper_type pwrap_mt6765 = {
1887*4882a593Smuzhiyun 	.regs = mt6765_regs,
1888*4882a593Smuzhiyun 	.type = PWRAP_MT6765,
1889*4882a593Smuzhiyun 	.arb_en_all = 0x3fd35,
1890*4882a593Smuzhiyun 	.int_en_all = 0xffffffff,
1891*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE,
1892*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_ALL,
1893*4882a593Smuzhiyun 	.caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
1894*4882a593Smuzhiyun 	.init_reg_clock = pwrap_common_init_reg_clock,
1895*4882a593Smuzhiyun 	.init_soc_specific = NULL,
1896*4882a593Smuzhiyun };
1897*4882a593Smuzhiyun 
1898*4882a593Smuzhiyun static const struct pmic_wrapper_type pwrap_mt6779 = {
1899*4882a593Smuzhiyun 	.regs = mt6779_regs,
1900*4882a593Smuzhiyun 	.type = PWRAP_MT6779,
1901*4882a593Smuzhiyun 	.arb_en_all = 0xfbb7f,
1902*4882a593Smuzhiyun 	.int_en_all = 0xfffffffe,
1903*4882a593Smuzhiyun 	.int1_en_all = 0,
1904*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE,
1905*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_ALL,
1906*4882a593Smuzhiyun 	.caps = 0,
1907*4882a593Smuzhiyun 	.init_reg_clock = pwrap_common_init_reg_clock,
1908*4882a593Smuzhiyun 	.init_soc_specific = NULL,
1909*4882a593Smuzhiyun };
1910*4882a593Smuzhiyun 
1911*4882a593Smuzhiyun static const struct pmic_wrapper_type pwrap_mt6797 = {
1912*4882a593Smuzhiyun 	.regs = mt6797_regs,
1913*4882a593Smuzhiyun 	.type = PWRAP_MT6797,
1914*4882a593Smuzhiyun 	.arb_en_all = 0x01fff,
1915*4882a593Smuzhiyun 	.int_en_all = 0xffffffc6,
1916*4882a593Smuzhiyun 	.int1_en_all = 0,
1917*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE,
1918*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_ALL,
1919*4882a593Smuzhiyun 	.caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
1920*4882a593Smuzhiyun 	.init_reg_clock = pwrap_common_init_reg_clock,
1921*4882a593Smuzhiyun 	.init_soc_specific = NULL,
1922*4882a593Smuzhiyun };
1923*4882a593Smuzhiyun 
1924*4882a593Smuzhiyun static const struct pmic_wrapper_type pwrap_mt7622 = {
1925*4882a593Smuzhiyun 	.regs = mt7622_regs,
1926*4882a593Smuzhiyun 	.type = PWRAP_MT7622,
1927*4882a593Smuzhiyun 	.arb_en_all = 0xff,
1928*4882a593Smuzhiyun 	.int_en_all = ~(u32)BIT(31),
1929*4882a593Smuzhiyun 	.int1_en_all = 0,
1930*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE,
1931*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_ALL,
1932*4882a593Smuzhiyun 	.caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
1933*4882a593Smuzhiyun 	.init_reg_clock = pwrap_common_init_reg_clock,
1934*4882a593Smuzhiyun 	.init_soc_specific = pwrap_mt7622_init_soc_specific,
1935*4882a593Smuzhiyun };
1936*4882a593Smuzhiyun 
1937*4882a593Smuzhiyun static const struct pmic_wrapper_type pwrap_mt8135 = {
1938*4882a593Smuzhiyun 	.regs = mt8135_regs,
1939*4882a593Smuzhiyun 	.type = PWRAP_MT8135,
1940*4882a593Smuzhiyun 	.arb_en_all = 0x1ff,
1941*4882a593Smuzhiyun 	.int_en_all = ~(u32)(BIT(31) | BIT(1)),
1942*4882a593Smuzhiyun 	.int1_en_all = 0,
1943*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE,
1944*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_ALL,
1945*4882a593Smuzhiyun 	.caps = PWRAP_CAP_BRIDGE | PWRAP_CAP_RESET | PWRAP_CAP_DCM,
1946*4882a593Smuzhiyun 	.init_reg_clock = pwrap_common_init_reg_clock,
1947*4882a593Smuzhiyun 	.init_soc_specific = pwrap_mt8135_init_soc_specific,
1948*4882a593Smuzhiyun };
1949*4882a593Smuzhiyun 
1950*4882a593Smuzhiyun static const struct pmic_wrapper_type pwrap_mt8173 = {
1951*4882a593Smuzhiyun 	.regs = mt8173_regs,
1952*4882a593Smuzhiyun 	.type = PWRAP_MT8173,
1953*4882a593Smuzhiyun 	.arb_en_all = 0x3f,
1954*4882a593Smuzhiyun 	.int_en_all = ~(u32)(BIT(31) | BIT(1)),
1955*4882a593Smuzhiyun 	.int1_en_all = 0,
1956*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE,
1957*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_NO_STAUPD,
1958*4882a593Smuzhiyun 	.caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
1959*4882a593Smuzhiyun 	.init_reg_clock = pwrap_common_init_reg_clock,
1960*4882a593Smuzhiyun 	.init_soc_specific = pwrap_mt8173_init_soc_specific,
1961*4882a593Smuzhiyun };
1962*4882a593Smuzhiyun 
1963*4882a593Smuzhiyun static const struct pmic_wrapper_type pwrap_mt8183 = {
1964*4882a593Smuzhiyun 	.regs = mt8183_regs,
1965*4882a593Smuzhiyun 	.type = PWRAP_MT8183,
1966*4882a593Smuzhiyun 	.arb_en_all = 0x3fa75,
1967*4882a593Smuzhiyun 	.int_en_all = 0xffffffff,
1968*4882a593Smuzhiyun 	.int1_en_all = 0xeef7ffff,
1969*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE,
1970*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_ALL,
1971*4882a593Smuzhiyun 	.caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1,
1972*4882a593Smuzhiyun 	.init_reg_clock = pwrap_common_init_reg_clock,
1973*4882a593Smuzhiyun 	.init_soc_specific = pwrap_mt8183_init_soc_specific,
1974*4882a593Smuzhiyun };
1975*4882a593Smuzhiyun 
1976*4882a593Smuzhiyun static struct pmic_wrapper_type pwrap_mt8516 = {
1977*4882a593Smuzhiyun 	.regs = mt8516_regs,
1978*4882a593Smuzhiyun 	.type = PWRAP_MT8516,
1979*4882a593Smuzhiyun 	.arb_en_all = 0xff,
1980*4882a593Smuzhiyun 	.int_en_all = ~(u32)(BIT(31) | BIT(2)),
1981*4882a593Smuzhiyun 	.spi_w = PWRAP_MAN_CMD_SPI_WRITE,
1982*4882a593Smuzhiyun 	.wdt_src = PWRAP_WDT_SRC_MASK_ALL,
1983*4882a593Smuzhiyun 	.caps = PWRAP_CAP_DCM,
1984*4882a593Smuzhiyun 	.init_reg_clock = pwrap_mt2701_init_reg_clock,
1985*4882a593Smuzhiyun 	.init_soc_specific = NULL,
1986*4882a593Smuzhiyun };
1987*4882a593Smuzhiyun 
1988*4882a593Smuzhiyun static const struct of_device_id of_pwrap_match_tbl[] = {
1989*4882a593Smuzhiyun 	{
1990*4882a593Smuzhiyun 		.compatible = "mediatek,mt2701-pwrap",
1991*4882a593Smuzhiyun 		.data = &pwrap_mt2701,
1992*4882a593Smuzhiyun 	}, {
1993*4882a593Smuzhiyun 		.compatible = "mediatek,mt6765-pwrap",
1994*4882a593Smuzhiyun 		.data = &pwrap_mt6765,
1995*4882a593Smuzhiyun 	}, {
1996*4882a593Smuzhiyun 		.compatible = "mediatek,mt6779-pwrap",
1997*4882a593Smuzhiyun 		.data = &pwrap_mt6779,
1998*4882a593Smuzhiyun 	}, {
1999*4882a593Smuzhiyun 		.compatible = "mediatek,mt6797-pwrap",
2000*4882a593Smuzhiyun 		.data = &pwrap_mt6797,
2001*4882a593Smuzhiyun 	}, {
2002*4882a593Smuzhiyun 		.compatible = "mediatek,mt7622-pwrap",
2003*4882a593Smuzhiyun 		.data = &pwrap_mt7622,
2004*4882a593Smuzhiyun 	}, {
2005*4882a593Smuzhiyun 		.compatible = "mediatek,mt8135-pwrap",
2006*4882a593Smuzhiyun 		.data = &pwrap_mt8135,
2007*4882a593Smuzhiyun 	}, {
2008*4882a593Smuzhiyun 		.compatible = "mediatek,mt8173-pwrap",
2009*4882a593Smuzhiyun 		.data = &pwrap_mt8173,
2010*4882a593Smuzhiyun 	}, {
2011*4882a593Smuzhiyun 		.compatible = "mediatek,mt8183-pwrap",
2012*4882a593Smuzhiyun 		.data = &pwrap_mt8183,
2013*4882a593Smuzhiyun 	}, {
2014*4882a593Smuzhiyun 		.compatible = "mediatek,mt8516-pwrap",
2015*4882a593Smuzhiyun 		.data = &pwrap_mt8516,
2016*4882a593Smuzhiyun 	}, {
2017*4882a593Smuzhiyun 		/* sentinel */
2018*4882a593Smuzhiyun 	}
2019*4882a593Smuzhiyun };
2020*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, of_pwrap_match_tbl);
2021*4882a593Smuzhiyun 
pwrap_probe(struct platform_device * pdev)2022*4882a593Smuzhiyun static int pwrap_probe(struct platform_device *pdev)
2023*4882a593Smuzhiyun {
2024*4882a593Smuzhiyun 	int ret, irq;
2025*4882a593Smuzhiyun 	struct pmic_wrapper *wrp;
2026*4882a593Smuzhiyun 	struct device_node *np = pdev->dev.of_node;
2027*4882a593Smuzhiyun 	const struct of_device_id *of_slave_id = NULL;
2028*4882a593Smuzhiyun 	struct resource *res;
2029*4882a593Smuzhiyun 
2030*4882a593Smuzhiyun 	if (np->child)
2031*4882a593Smuzhiyun 		of_slave_id = of_match_node(of_slave_match_tbl, np->child);
2032*4882a593Smuzhiyun 
2033*4882a593Smuzhiyun 	if (!of_slave_id) {
2034*4882a593Smuzhiyun 		dev_dbg(&pdev->dev, "slave pmic should be defined in dts\n");
2035*4882a593Smuzhiyun 		return -EINVAL;
2036*4882a593Smuzhiyun 	}
2037*4882a593Smuzhiyun 
2038*4882a593Smuzhiyun 	wrp = devm_kzalloc(&pdev->dev, sizeof(*wrp), GFP_KERNEL);
2039*4882a593Smuzhiyun 	if (!wrp)
2040*4882a593Smuzhiyun 		return -ENOMEM;
2041*4882a593Smuzhiyun 
2042*4882a593Smuzhiyun 	platform_set_drvdata(pdev, wrp);
2043*4882a593Smuzhiyun 
2044*4882a593Smuzhiyun 	wrp->master = of_device_get_match_data(&pdev->dev);
2045*4882a593Smuzhiyun 	wrp->slave = of_slave_id->data;
2046*4882a593Smuzhiyun 	wrp->dev = &pdev->dev;
2047*4882a593Smuzhiyun 
2048*4882a593Smuzhiyun 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwrap");
2049*4882a593Smuzhiyun 	wrp->base = devm_ioremap_resource(wrp->dev, res);
2050*4882a593Smuzhiyun 	if (IS_ERR(wrp->base))
2051*4882a593Smuzhiyun 		return PTR_ERR(wrp->base);
2052*4882a593Smuzhiyun 
2053*4882a593Smuzhiyun 	if (HAS_CAP(wrp->master->caps, PWRAP_CAP_RESET)) {
2054*4882a593Smuzhiyun 		wrp->rstc = devm_reset_control_get(wrp->dev, "pwrap");
2055*4882a593Smuzhiyun 		if (IS_ERR(wrp->rstc)) {
2056*4882a593Smuzhiyun 			ret = PTR_ERR(wrp->rstc);
2057*4882a593Smuzhiyun 			dev_dbg(wrp->dev, "cannot get pwrap reset: %d\n", ret);
2058*4882a593Smuzhiyun 			return ret;
2059*4882a593Smuzhiyun 		}
2060*4882a593Smuzhiyun 	}
2061*4882a593Smuzhiyun 
2062*4882a593Smuzhiyun 	if (HAS_CAP(wrp->master->caps, PWRAP_CAP_BRIDGE)) {
2063*4882a593Smuzhiyun 		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2064*4882a593Smuzhiyun 				"pwrap-bridge");
2065*4882a593Smuzhiyun 		wrp->bridge_base = devm_ioremap_resource(wrp->dev, res);
2066*4882a593Smuzhiyun 		if (IS_ERR(wrp->bridge_base))
2067*4882a593Smuzhiyun 			return PTR_ERR(wrp->bridge_base);
2068*4882a593Smuzhiyun 
2069*4882a593Smuzhiyun 		wrp->rstc_bridge = devm_reset_control_get(wrp->dev,
2070*4882a593Smuzhiyun 							  "pwrap-bridge");
2071*4882a593Smuzhiyun 		if (IS_ERR(wrp->rstc_bridge)) {
2072*4882a593Smuzhiyun 			ret = PTR_ERR(wrp->rstc_bridge);
2073*4882a593Smuzhiyun 			dev_dbg(wrp->dev,
2074*4882a593Smuzhiyun 				"cannot get pwrap-bridge reset: %d\n", ret);
2075*4882a593Smuzhiyun 			return ret;
2076*4882a593Smuzhiyun 		}
2077*4882a593Smuzhiyun 	}
2078*4882a593Smuzhiyun 
2079*4882a593Smuzhiyun 	wrp->clk_spi = devm_clk_get(wrp->dev, "spi");
2080*4882a593Smuzhiyun 	if (IS_ERR(wrp->clk_spi)) {
2081*4882a593Smuzhiyun 		dev_dbg(wrp->dev, "failed to get clock: %ld\n",
2082*4882a593Smuzhiyun 			PTR_ERR(wrp->clk_spi));
2083*4882a593Smuzhiyun 		return PTR_ERR(wrp->clk_spi);
2084*4882a593Smuzhiyun 	}
2085*4882a593Smuzhiyun 
2086*4882a593Smuzhiyun 	wrp->clk_wrap = devm_clk_get(wrp->dev, "wrap");
2087*4882a593Smuzhiyun 	if (IS_ERR(wrp->clk_wrap)) {
2088*4882a593Smuzhiyun 		dev_dbg(wrp->dev, "failed to get clock: %ld\n",
2089*4882a593Smuzhiyun 			PTR_ERR(wrp->clk_wrap));
2090*4882a593Smuzhiyun 		return PTR_ERR(wrp->clk_wrap);
2091*4882a593Smuzhiyun 	}
2092*4882a593Smuzhiyun 
2093*4882a593Smuzhiyun 	ret = clk_prepare_enable(wrp->clk_spi);
2094*4882a593Smuzhiyun 	if (ret)
2095*4882a593Smuzhiyun 		return ret;
2096*4882a593Smuzhiyun 
2097*4882a593Smuzhiyun 	ret = clk_prepare_enable(wrp->clk_wrap);
2098*4882a593Smuzhiyun 	if (ret)
2099*4882a593Smuzhiyun 		goto err_out1;
2100*4882a593Smuzhiyun 
2101*4882a593Smuzhiyun 	/* Enable internal dynamic clock */
2102*4882a593Smuzhiyun 	if (HAS_CAP(wrp->master->caps, PWRAP_CAP_DCM)) {
2103*4882a593Smuzhiyun 		pwrap_writel(wrp, 1, PWRAP_DCM_EN);
2104*4882a593Smuzhiyun 		pwrap_writel(wrp, 0, PWRAP_DCM_DBC_PRD);
2105*4882a593Smuzhiyun 	}
2106*4882a593Smuzhiyun 
2107*4882a593Smuzhiyun 	/*
2108*4882a593Smuzhiyun 	 * The PMIC could already be initialized by the bootloader.
2109*4882a593Smuzhiyun 	 * Skip initialization here in this case.
2110*4882a593Smuzhiyun 	 */
2111*4882a593Smuzhiyun 	if (!pwrap_readl(wrp, PWRAP_INIT_DONE2)) {
2112*4882a593Smuzhiyun 		ret = pwrap_init(wrp);
2113*4882a593Smuzhiyun 		if (ret) {
2114*4882a593Smuzhiyun 			dev_dbg(wrp->dev, "init failed with %d\n", ret);
2115*4882a593Smuzhiyun 			goto err_out2;
2116*4882a593Smuzhiyun 		}
2117*4882a593Smuzhiyun 	}
2118*4882a593Smuzhiyun 
2119*4882a593Smuzhiyun 	if (!(pwrap_readl(wrp, PWRAP_WACS2_RDATA) & PWRAP_STATE_INIT_DONE0)) {
2120*4882a593Smuzhiyun 		dev_dbg(wrp->dev, "initialization isn't finished\n");
2121*4882a593Smuzhiyun 		ret = -ENODEV;
2122*4882a593Smuzhiyun 		goto err_out2;
2123*4882a593Smuzhiyun 	}
2124*4882a593Smuzhiyun 
2125*4882a593Smuzhiyun 	/* Initialize watchdog, may not be done by the bootloader */
2126*4882a593Smuzhiyun 	pwrap_writel(wrp, 0xf, PWRAP_WDT_UNIT);
2127*4882a593Smuzhiyun 	/*
2128*4882a593Smuzhiyun 	 * Since STAUPD was not used on mt8173 platform,
2129*4882a593Smuzhiyun 	 * so STAUPD of WDT_SRC which should be turned off
2130*4882a593Smuzhiyun 	 */
2131*4882a593Smuzhiyun 	pwrap_writel(wrp, wrp->master->wdt_src, PWRAP_WDT_SRC_EN);
2132*4882a593Smuzhiyun 	if (HAS_CAP(wrp->master->caps, PWRAP_CAP_WDT_SRC1))
2133*4882a593Smuzhiyun 		pwrap_writel(wrp, wrp->master->wdt_src, PWRAP_WDT_SRC_EN_1);
2134*4882a593Smuzhiyun 
2135*4882a593Smuzhiyun 	pwrap_writel(wrp, 0x1, PWRAP_TIMER_EN);
2136*4882a593Smuzhiyun 	pwrap_writel(wrp, wrp->master->int_en_all, PWRAP_INT_EN);
2137*4882a593Smuzhiyun 	/*
2138*4882a593Smuzhiyun 	 * We add INT1 interrupt to handle starvation and request exception
2139*4882a593Smuzhiyun 	 * If we support it, we should enable it here.
2140*4882a593Smuzhiyun 	 */
2141*4882a593Smuzhiyun 	if (HAS_CAP(wrp->master->caps, PWRAP_CAP_INT1_EN))
2142*4882a593Smuzhiyun 		pwrap_writel(wrp, wrp->master->int1_en_all, PWRAP_INT1_EN);
2143*4882a593Smuzhiyun 
2144*4882a593Smuzhiyun 	irq = platform_get_irq(pdev, 0);
2145*4882a593Smuzhiyun 	ret = devm_request_irq(wrp->dev, irq, pwrap_interrupt,
2146*4882a593Smuzhiyun 			       IRQF_TRIGGER_HIGH,
2147*4882a593Smuzhiyun 			       "mt-pmic-pwrap", wrp);
2148*4882a593Smuzhiyun 	if (ret)
2149*4882a593Smuzhiyun 		goto err_out2;
2150*4882a593Smuzhiyun 
2151*4882a593Smuzhiyun 	wrp->regmap = devm_regmap_init(wrp->dev, NULL, wrp, wrp->slave->regmap);
2152*4882a593Smuzhiyun 	if (IS_ERR(wrp->regmap)) {
2153*4882a593Smuzhiyun 		ret = PTR_ERR(wrp->regmap);
2154*4882a593Smuzhiyun 		goto err_out2;
2155*4882a593Smuzhiyun 	}
2156*4882a593Smuzhiyun 
2157*4882a593Smuzhiyun 	ret = of_platform_populate(np, NULL, NULL, wrp->dev);
2158*4882a593Smuzhiyun 	if (ret) {
2159*4882a593Smuzhiyun 		dev_dbg(wrp->dev, "failed to create child devices at %pOF\n",
2160*4882a593Smuzhiyun 				np);
2161*4882a593Smuzhiyun 		goto err_out2;
2162*4882a593Smuzhiyun 	}
2163*4882a593Smuzhiyun 
2164*4882a593Smuzhiyun 	return 0;
2165*4882a593Smuzhiyun 
2166*4882a593Smuzhiyun err_out2:
2167*4882a593Smuzhiyun 	clk_disable_unprepare(wrp->clk_wrap);
2168*4882a593Smuzhiyun err_out1:
2169*4882a593Smuzhiyun 	clk_disable_unprepare(wrp->clk_spi);
2170*4882a593Smuzhiyun 
2171*4882a593Smuzhiyun 	return ret;
2172*4882a593Smuzhiyun }
2173*4882a593Smuzhiyun 
2174*4882a593Smuzhiyun static struct platform_driver pwrap_drv = {
2175*4882a593Smuzhiyun 	.driver = {
2176*4882a593Smuzhiyun 		.name = "mt-pmic-pwrap",
2177*4882a593Smuzhiyun 		.of_match_table = of_match_ptr(of_pwrap_match_tbl),
2178*4882a593Smuzhiyun 	},
2179*4882a593Smuzhiyun 	.probe = pwrap_probe,
2180*4882a593Smuzhiyun };
2181*4882a593Smuzhiyun 
2182*4882a593Smuzhiyun module_platform_driver(pwrap_drv);
2183*4882a593Smuzhiyun 
2184*4882a593Smuzhiyun MODULE_AUTHOR("Flora Fu, MediaTek");
2185*4882a593Smuzhiyun MODULE_DESCRIPTION("MediaTek MT8135 PMIC Wrapper Driver");
2186*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
2187