1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014 MediaTek Inc.
4 * Author: Flora Fu, MediaTek
7 #include <linux/interrupt.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/of_device.h>
12 #include <linux/platform_device.h>
13 #include <linux/regmap.h>
14 #include <linux/reset.h>
16 #define PWRAP_MT8135_BRIDGE_IORD_ARB_EN 0x4
17 #define PWRAP_MT8135_BRIDGE_WACS3_EN 0x10
18 #define PWRAP_MT8135_BRIDGE_INIT_DONE3 0x14
19 #define PWRAP_MT8135_BRIDGE_WACS4_EN 0x24
20 #define PWRAP_MT8135_BRIDGE_INIT_DONE4 0x28
21 #define PWRAP_MT8135_BRIDGE_INT_EN 0x38
22 #define PWRAP_MT8135_BRIDGE_TIMER_EN 0x48
23 #define PWRAP_MT8135_BRIDGE_WDT_UNIT 0x50
24 #define PWRAP_MT8135_BRIDGE_WDT_SRC_EN 0x54
26 /* macro for wrapper status */
27 #define PWRAP_GET_WACS_RDATA(x) (((x) >> 0) & 0x0000ffff)
28 #define PWRAP_GET_WACS_FSM(x) (((x) >> 16) & 0x00000007)
29 #define PWRAP_GET_WACS_REQ(x) (((x) >> 19) & 0x00000001)
30 #define PWRAP_STATE_SYNC_IDLE0 (1 << 20)
31 #define PWRAP_STATE_INIT_DONE0 (1 << 21)
33 /* macro for WACS FSM */
34 #define PWRAP_WACS_FSM_IDLE 0x00
35 #define PWRAP_WACS_FSM_REQ 0x02
36 #define PWRAP_WACS_FSM_WFDLE 0x04
37 #define PWRAP_WACS_FSM_WFVLDCLR 0x06
38 #define PWRAP_WACS_INIT_DONE 0x01
39 #define PWRAP_WACS_WACS_SYNC_IDLE 0x01
40 #define PWRAP_WACS_SYNC_BUSY 0x00
42 /* macro for device wrapper default value */
43 #define PWRAP_DEW_READ_TEST_VAL 0x5aa5
44 #define PWRAP_DEW_WRITE_TEST_VAL 0xa55a
46 /* macro for manual command */
47 #define PWRAP_MAN_CMD_SPI_WRITE_NEW (1 << 14)
48 #define PWRAP_MAN_CMD_SPI_WRITE (1 << 13)
49 #define PWRAP_MAN_CMD_OP_CSH (0x0 << 8)
50 #define PWRAP_MAN_CMD_OP_CSL (0x1 << 8)
51 #define PWRAP_MAN_CMD_OP_CK (0x2 << 8)
52 #define PWRAP_MAN_CMD_OP_OUTS (0x8 << 8)
53 #define PWRAP_MAN_CMD_OP_OUTD (0x9 << 8)
54 #define PWRAP_MAN_CMD_OP_OUTQ (0xa << 8)
56 /* macro for Watch Dog Timer Source */
57 #define PWRAP_WDT_SRC_EN_STAUPD_TRIG (1 << 25)
58 #define PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE (1 << 20)
59 #define PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE (1 << 6)
60 #define PWRAP_WDT_SRC_MASK_ALL 0xffffffff
61 #define PWRAP_WDT_SRC_MASK_NO_STAUPD ~(PWRAP_WDT_SRC_EN_STAUPD_TRIG | \
62 PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE | \
63 PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE)
65 /* Group of bits used for shown slave capability */
66 #define PWRAP_SLV_CAP_SPI BIT(0)
67 #define PWRAP_SLV_CAP_DUALIO BIT(1)
68 #define PWRAP_SLV_CAP_SECURITY BIT(2)
69 #define HAS_CAP(_c, _x) (((_c) & (_x)) == (_x))
71 /* Group of bits used for shown pwrap capability */
72 #define PWRAP_CAP_BRIDGE BIT(0)
73 #define PWRAP_CAP_RESET BIT(1)
74 #define PWRAP_CAP_DCM BIT(2)
75 #define PWRAP_CAP_INT1_EN BIT(3)
76 #define PWRAP_CAP_WDT_SRC1 BIT(4)
78 /* defines for slave device wrapper registers */
86 PWRAP_DEW_MON_GRP_SEL
,
87 PWRAP_DEW_CIPHER_KEY_SEL
,
88 PWRAP_DEW_CIPHER_IV_SEL
,
90 PWRAP_DEW_CIPHER_MODE
,
91 PWRAP_DEW_CIPHER_SWRST
,
93 /* MT6323 only regs */
97 /* MT6358 only regs */
101 PWRAP_GPIO_PULLEN0_CLR
,
103 PWRAP_RG_SPI_RECORD0
,
114 /* MT6397 only regs */
115 PWRAP_DEW_EVENT_OUT_EN
,
116 PWRAP_DEW_EVENT_SRC_EN
,
118 PWRAP_DEW_EVENT_FLAG
,
119 PWRAP_DEW_MON_FLAG_SEL
,
120 PWRAP_DEW_EVENT_TEST
,
121 PWRAP_DEW_CIPHER_LOAD
,
122 PWRAP_DEW_CIPHER_START
,
125 static const u32 mt6323_regs
[] = {
126 [PWRAP_DEW_BASE
] = 0x0000,
127 [PWRAP_DEW_DIO_EN
] = 0x018a,
128 [PWRAP_DEW_READ_TEST
] = 0x018c,
129 [PWRAP_DEW_WRITE_TEST
] = 0x018e,
130 [PWRAP_DEW_CRC_EN
] = 0x0192,
131 [PWRAP_DEW_CRC_VAL
] = 0x0194,
132 [PWRAP_DEW_MON_GRP_SEL
] = 0x0196,
133 [PWRAP_DEW_CIPHER_KEY_SEL
] = 0x0198,
134 [PWRAP_DEW_CIPHER_IV_SEL
] = 0x019a,
135 [PWRAP_DEW_CIPHER_EN
] = 0x019c,
136 [PWRAP_DEW_CIPHER_RDY
] = 0x019e,
137 [PWRAP_DEW_CIPHER_MODE
] = 0x01a0,
138 [PWRAP_DEW_CIPHER_SWRST
] = 0x01a2,
139 [PWRAP_DEW_RDDMY_NO
] = 0x01a4,
142 static const u32 mt6351_regs
[] = {
143 [PWRAP_DEW_DIO_EN
] = 0x02F2,
144 [PWRAP_DEW_READ_TEST
] = 0x02F4,
145 [PWRAP_DEW_WRITE_TEST
] = 0x02F6,
146 [PWRAP_DEW_CRC_EN
] = 0x02FA,
147 [PWRAP_DEW_CRC_VAL
] = 0x02FC,
148 [PWRAP_DEW_CIPHER_KEY_SEL
] = 0x0300,
149 [PWRAP_DEW_CIPHER_IV_SEL
] = 0x0302,
150 [PWRAP_DEW_CIPHER_EN
] = 0x0304,
151 [PWRAP_DEW_CIPHER_RDY
] = 0x0306,
152 [PWRAP_DEW_CIPHER_MODE
] = 0x0308,
153 [PWRAP_DEW_CIPHER_SWRST
] = 0x030A,
154 [PWRAP_DEW_RDDMY_NO
] = 0x030C,
157 static const u32 mt6357_regs
[] = {
158 [PWRAP_DEW_DIO_EN
] = 0x040A,
159 [PWRAP_DEW_READ_TEST
] = 0x040C,
160 [PWRAP_DEW_WRITE_TEST
] = 0x040E,
161 [PWRAP_DEW_CRC_EN
] = 0x0412,
162 [PWRAP_DEW_CRC_VAL
] = 0x0414,
163 [PWRAP_DEW_CIPHER_KEY_SEL
] = 0x0418,
164 [PWRAP_DEW_CIPHER_IV_SEL
] = 0x041A,
165 [PWRAP_DEW_CIPHER_EN
] = 0x041C,
166 [PWRAP_DEW_CIPHER_RDY
] = 0x041E,
167 [PWRAP_DEW_CIPHER_MODE
] = 0x0420,
168 [PWRAP_DEW_CIPHER_SWRST
] = 0x0422,
169 [PWRAP_DEW_RDDMY_NO
] = 0x0424,
172 static const u32 mt6358_regs
[] = {
173 [PWRAP_SMT_CON1
] = 0x0030,
174 [PWRAP_DRV_CON1
] = 0x0038,
175 [PWRAP_FILTER_CON0
] = 0x0040,
176 [PWRAP_GPIO_PULLEN0_CLR
] = 0x0098,
177 [PWRAP_RG_SPI_CON0
] = 0x0408,
178 [PWRAP_RG_SPI_RECORD0
] = 0x040a,
179 [PWRAP_DEW_DIO_EN
] = 0x040c,
180 [PWRAP_DEW_READ_TEST
] = 0x040e,
181 [PWRAP_DEW_WRITE_TEST
] = 0x0410,
182 [PWRAP_DEW_CRC_EN
] = 0x0414,
183 [PWRAP_DEW_CIPHER_KEY_SEL
] = 0x041a,
184 [PWRAP_DEW_CIPHER_IV_SEL
] = 0x041c,
185 [PWRAP_DEW_CIPHER_EN
] = 0x041e,
186 [PWRAP_DEW_CIPHER_RDY
] = 0x0420,
187 [PWRAP_DEW_CIPHER_MODE
] = 0x0422,
188 [PWRAP_DEW_CIPHER_SWRST
] = 0x0424,
189 [PWRAP_RG_SPI_CON2
] = 0x0432,
190 [PWRAP_RG_SPI_CON3
] = 0x0434,
191 [PWRAP_RG_SPI_CON4
] = 0x0436,
192 [PWRAP_RG_SPI_CON5
] = 0x0438,
193 [PWRAP_RG_SPI_CON6
] = 0x043a,
194 [PWRAP_RG_SPI_CON7
] = 0x043c,
195 [PWRAP_RG_SPI_CON8
] = 0x043e,
196 [PWRAP_RG_SPI_CON13
] = 0x0448,
197 [PWRAP_SPISLV_KEY
] = 0x044a,
200 static const u32 mt6397_regs
[] = {
201 [PWRAP_DEW_BASE
] = 0xbc00,
202 [PWRAP_DEW_EVENT_OUT_EN
] = 0xbc00,
203 [PWRAP_DEW_DIO_EN
] = 0xbc02,
204 [PWRAP_DEW_EVENT_SRC_EN
] = 0xbc04,
205 [PWRAP_DEW_EVENT_SRC
] = 0xbc06,
206 [PWRAP_DEW_EVENT_FLAG
] = 0xbc08,
207 [PWRAP_DEW_READ_TEST
] = 0xbc0a,
208 [PWRAP_DEW_WRITE_TEST
] = 0xbc0c,
209 [PWRAP_DEW_CRC_EN
] = 0xbc0e,
210 [PWRAP_DEW_CRC_VAL
] = 0xbc10,
211 [PWRAP_DEW_MON_GRP_SEL
] = 0xbc12,
212 [PWRAP_DEW_MON_FLAG_SEL
] = 0xbc14,
213 [PWRAP_DEW_EVENT_TEST
] = 0xbc16,
214 [PWRAP_DEW_CIPHER_KEY_SEL
] = 0xbc18,
215 [PWRAP_DEW_CIPHER_IV_SEL
] = 0xbc1a,
216 [PWRAP_DEW_CIPHER_LOAD
] = 0xbc1c,
217 [PWRAP_DEW_CIPHER_START
] = 0xbc1e,
218 [PWRAP_DEW_CIPHER_RDY
] = 0xbc20,
219 [PWRAP_DEW_CIPHER_MODE
] = 0xbc22,
220 [PWRAP_DEW_CIPHER_SWRST
] = 0xbc24,
234 PWRAP_STAUPD_MAN_TRIG
,
276 PWRAP_CIPHER_KEY_SEL
,
286 /* MT2701 only regs */
290 PWRAP_ADC_RDATA_ADDR1
,
291 PWRAP_ADC_RDATA_ADDR2
,
293 /* MT7622 only regs */
313 PWRAP_ADC_RDATA_ADDR
,
316 PWRAP_DVFS_STEP_CTRL0
,
317 PWRAP_DVFS_STEP_CTRL1
,
318 PWRAP_DVFS_STEP_CTRL2
,
321 /* MT8135 only regs */
334 /* MT8173 only regs */
356 /* MT8183 only regs */
357 PWRAP_SI_SAMPLE_CTRL
,
365 PWRAP_INIT_DONE_MD32
,
370 PWRAP_INT_GPS_AUXADC_CMD_ADDR
,
371 PWRAP_INT_GPS_AUXADC_CMD
,
372 PWRAP_INT_GPS_AUXADC_RDATA_ADDR
,
373 PWRAP_EXT_GPS_AUXADC_RDATA_ADDR
,
377 /* MT8516 only regs */
382 static int mt2701_regs
[] = {
383 [PWRAP_MUX_SEL
] = 0x0,
384 [PWRAP_WRAP_EN
] = 0x4,
385 [PWRAP_DIO_EN
] = 0x8,
387 [PWRAP_RDDMY
] = 0x18,
388 [PWRAP_SI_CK_CON
] = 0x1c,
389 [PWRAP_CSHEXT_WRITE
] = 0x20,
390 [PWRAP_CSHEXT_READ
] = 0x24,
391 [PWRAP_CSLEXT_START
] = 0x28,
392 [PWRAP_CSLEXT_END
] = 0x2c,
393 [PWRAP_STAUPD_PRD
] = 0x30,
394 [PWRAP_STAUPD_GRPEN
] = 0x34,
395 [PWRAP_STAUPD_MAN_TRIG
] = 0x38,
396 [PWRAP_STAUPD_STA
] = 0x3c,
397 [PWRAP_WRAP_STA
] = 0x44,
398 [PWRAP_HARB_INIT
] = 0x48,
399 [PWRAP_HARB_HPRIO
] = 0x4c,
400 [PWRAP_HIPRIO_ARB_EN
] = 0x50,
401 [PWRAP_HARB_STA0
] = 0x54,
402 [PWRAP_HARB_STA1
] = 0x58,
403 [PWRAP_MAN_EN
] = 0x5c,
404 [PWRAP_MAN_CMD
] = 0x60,
405 [PWRAP_MAN_RDATA
] = 0x64,
406 [PWRAP_MAN_VLDCLR
] = 0x68,
407 [PWRAP_WACS0_EN
] = 0x6c,
408 [PWRAP_INIT_DONE0
] = 0x70,
409 [PWRAP_WACS0_CMD
] = 0x74,
410 [PWRAP_WACS0_RDATA
] = 0x78,
411 [PWRAP_WACS0_VLDCLR
] = 0x7c,
412 [PWRAP_WACS1_EN
] = 0x80,
413 [PWRAP_INIT_DONE1
] = 0x84,
414 [PWRAP_WACS1_CMD
] = 0x88,
415 [PWRAP_WACS1_RDATA
] = 0x8c,
416 [PWRAP_WACS1_VLDCLR
] = 0x90,
417 [PWRAP_WACS2_EN
] = 0x94,
418 [PWRAP_INIT_DONE2
] = 0x98,
419 [PWRAP_WACS2_CMD
] = 0x9c,
420 [PWRAP_WACS2_RDATA
] = 0xa0,
421 [PWRAP_WACS2_VLDCLR
] = 0xa4,
422 [PWRAP_INT_EN
] = 0xa8,
423 [PWRAP_INT_FLG_RAW
] = 0xac,
424 [PWRAP_INT_FLG
] = 0xb0,
425 [PWRAP_INT_CLR
] = 0xb4,
426 [PWRAP_SIG_ADR
] = 0xb8,
427 [PWRAP_SIG_MODE
] = 0xbc,
428 [PWRAP_SIG_VALUE
] = 0xc0,
429 [PWRAP_SIG_ERRVAL
] = 0xc4,
430 [PWRAP_CRC_EN
] = 0xc8,
431 [PWRAP_TIMER_EN
] = 0xcc,
432 [PWRAP_TIMER_STA
] = 0xd0,
433 [PWRAP_WDT_UNIT
] = 0xd4,
434 [PWRAP_WDT_SRC_EN
] = 0xd8,
435 [PWRAP_WDT_FLG
] = 0xdc,
436 [PWRAP_DEBUG_INT_SEL
] = 0xe0,
437 [PWRAP_DVFS_ADR0
] = 0xe4,
438 [PWRAP_DVFS_WDATA0
] = 0xe8,
439 [PWRAP_DVFS_ADR1
] = 0xec,
440 [PWRAP_DVFS_WDATA1
] = 0xf0,
441 [PWRAP_DVFS_ADR2
] = 0xf4,
442 [PWRAP_DVFS_WDATA2
] = 0xf8,
443 [PWRAP_DVFS_ADR3
] = 0xfc,
444 [PWRAP_DVFS_WDATA3
] = 0x100,
445 [PWRAP_DVFS_ADR4
] = 0x104,
446 [PWRAP_DVFS_WDATA4
] = 0x108,
447 [PWRAP_DVFS_ADR5
] = 0x10c,
448 [PWRAP_DVFS_WDATA5
] = 0x110,
449 [PWRAP_DVFS_ADR6
] = 0x114,
450 [PWRAP_DVFS_WDATA6
] = 0x118,
451 [PWRAP_DVFS_ADR7
] = 0x11c,
452 [PWRAP_DVFS_WDATA7
] = 0x120,
453 [PWRAP_CIPHER_KEY_SEL
] = 0x124,
454 [PWRAP_CIPHER_IV_SEL
] = 0x128,
455 [PWRAP_CIPHER_EN
] = 0x12c,
456 [PWRAP_CIPHER_RDY
] = 0x130,
457 [PWRAP_CIPHER_MODE
] = 0x134,
458 [PWRAP_CIPHER_SWRST
] = 0x138,
459 [PWRAP_DCM_EN
] = 0x13c,
460 [PWRAP_DCM_DBC_PRD
] = 0x140,
461 [PWRAP_ADC_CMD_ADDR
] = 0x144,
462 [PWRAP_PWRAP_ADC_CMD
] = 0x148,
463 [PWRAP_ADC_RDY_ADDR
] = 0x14c,
464 [PWRAP_ADC_RDATA_ADDR1
] = 0x150,
465 [PWRAP_ADC_RDATA_ADDR2
] = 0x154,
468 static int mt6765_regs
[] = {
469 [PWRAP_MUX_SEL
] = 0x0,
470 [PWRAP_WRAP_EN
] = 0x4,
471 [PWRAP_DIO_EN
] = 0x8,
472 [PWRAP_RDDMY
] = 0x20,
473 [PWRAP_CSHEXT_WRITE
] = 0x24,
474 [PWRAP_CSHEXT_READ
] = 0x28,
475 [PWRAP_CSLEXT_START
] = 0x2C,
476 [PWRAP_CSLEXT_END
] = 0x30,
477 [PWRAP_STAUPD_PRD
] = 0x3C,
478 [PWRAP_HARB_HPRIO
] = 0x68,
479 [PWRAP_HIPRIO_ARB_EN
] = 0x6C,
480 [PWRAP_MAN_EN
] = 0x7C,
481 [PWRAP_MAN_CMD
] = 0x80,
482 [PWRAP_WACS0_EN
] = 0x8C,
483 [PWRAP_WACS1_EN
] = 0x94,
484 [PWRAP_WACS2_EN
] = 0x9C,
485 [PWRAP_INIT_DONE2
] = 0xA0,
486 [PWRAP_WACS2_CMD
] = 0xC20,
487 [PWRAP_WACS2_RDATA
] = 0xC24,
488 [PWRAP_WACS2_VLDCLR
] = 0xC28,
489 [PWRAP_INT_EN
] = 0xB4,
490 [PWRAP_INT_FLG_RAW
] = 0xB8,
491 [PWRAP_INT_FLG
] = 0xBC,
492 [PWRAP_INT_CLR
] = 0xC0,
493 [PWRAP_TIMER_EN
] = 0xE8,
494 [PWRAP_WDT_UNIT
] = 0xF0,
495 [PWRAP_WDT_SRC_EN
] = 0xF4,
496 [PWRAP_DCM_EN
] = 0x1DC,
497 [PWRAP_DCM_DBC_PRD
] = 0x1E0,
500 static int mt6797_regs
[] = {
501 [PWRAP_MUX_SEL
] = 0x0,
502 [PWRAP_WRAP_EN
] = 0x4,
503 [PWRAP_DIO_EN
] = 0x8,
505 [PWRAP_RDDMY
] = 0x10,
506 [PWRAP_CSHEXT_WRITE
] = 0x18,
507 [PWRAP_CSHEXT_READ
] = 0x1C,
508 [PWRAP_CSLEXT_START
] = 0x20,
509 [PWRAP_CSLEXT_END
] = 0x24,
510 [PWRAP_STAUPD_PRD
] = 0x28,
511 [PWRAP_HARB_HPRIO
] = 0x50,
512 [PWRAP_HIPRIO_ARB_EN
] = 0x54,
513 [PWRAP_MAN_EN
] = 0x60,
514 [PWRAP_MAN_CMD
] = 0x64,
515 [PWRAP_WACS0_EN
] = 0x70,
516 [PWRAP_WACS1_EN
] = 0x84,
517 [PWRAP_WACS2_EN
] = 0x98,
518 [PWRAP_INIT_DONE2
] = 0x9C,
519 [PWRAP_WACS2_CMD
] = 0xA0,
520 [PWRAP_WACS2_RDATA
] = 0xA4,
521 [PWRAP_WACS2_VLDCLR
] = 0xA8,
522 [PWRAP_INT_EN
] = 0xC0,
523 [PWRAP_INT_FLG_RAW
] = 0xC4,
524 [PWRAP_INT_FLG
] = 0xC8,
525 [PWRAP_INT_CLR
] = 0xCC,
526 [PWRAP_TIMER_EN
] = 0xF4,
527 [PWRAP_WDT_UNIT
] = 0xFC,
528 [PWRAP_WDT_SRC_EN
] = 0x100,
529 [PWRAP_DCM_EN
] = 0x1CC,
530 [PWRAP_DCM_DBC_PRD
] = 0x1D4,
533 static int mt7622_regs
[] = {
534 [PWRAP_MUX_SEL
] = 0x0,
535 [PWRAP_WRAP_EN
] = 0x4,
536 [PWRAP_DIO_EN
] = 0x8,
538 [PWRAP_RDDMY
] = 0x10,
539 [PWRAP_SI_CK_CON
] = 0x14,
540 [PWRAP_CSHEXT_WRITE
] = 0x18,
541 [PWRAP_CSHEXT_READ
] = 0x1C,
542 [PWRAP_CSLEXT_START
] = 0x20,
543 [PWRAP_CSLEXT_END
] = 0x24,
544 [PWRAP_STAUPD_PRD
] = 0x28,
545 [PWRAP_STAUPD_GRPEN
] = 0x2C,
546 [PWRAP_EINT_STA0_ADR
] = 0x30,
547 [PWRAP_EINT_STA1_ADR
] = 0x34,
550 [PWRAP_STAUPD_MAN_TRIG
] = 0x40,
551 [PWRAP_STAUPD_STA
] = 0x44,
552 [PWRAP_WRAP_STA
] = 0x48,
553 [PWRAP_HARB_INIT
] = 0x4C,
554 [PWRAP_HARB_HPRIO
] = 0x50,
555 [PWRAP_HIPRIO_ARB_EN
] = 0x54,
556 [PWRAP_HARB_STA0
] = 0x58,
557 [PWRAP_HARB_STA1
] = 0x5C,
558 [PWRAP_MAN_EN
] = 0x60,
559 [PWRAP_MAN_CMD
] = 0x64,
560 [PWRAP_MAN_RDATA
] = 0x68,
561 [PWRAP_MAN_VLDCLR
] = 0x6C,
562 [PWRAP_WACS0_EN
] = 0x70,
563 [PWRAP_INIT_DONE0
] = 0x74,
564 [PWRAP_WACS0_CMD
] = 0x78,
565 [PWRAP_WACS0_RDATA
] = 0x7C,
566 [PWRAP_WACS0_VLDCLR
] = 0x80,
567 [PWRAP_WACS1_EN
] = 0x84,
568 [PWRAP_INIT_DONE1
] = 0x88,
569 [PWRAP_WACS1_CMD
] = 0x8C,
570 [PWRAP_WACS1_RDATA
] = 0x90,
571 [PWRAP_WACS1_VLDCLR
] = 0x94,
572 [PWRAP_WACS2_EN
] = 0x98,
573 [PWRAP_INIT_DONE2
] = 0x9C,
574 [PWRAP_WACS2_CMD
] = 0xA0,
575 [PWRAP_WACS2_RDATA
] = 0xA4,
576 [PWRAP_WACS2_VLDCLR
] = 0xA8,
577 [PWRAP_INT_EN
] = 0xAC,
578 [PWRAP_INT_FLG_RAW
] = 0xB0,
579 [PWRAP_INT_FLG
] = 0xB4,
580 [PWRAP_INT_CLR
] = 0xB8,
581 [PWRAP_SIG_ADR
] = 0xBC,
582 [PWRAP_SIG_MODE
] = 0xC0,
583 [PWRAP_SIG_VALUE
] = 0xC4,
584 [PWRAP_SIG_ERRVAL
] = 0xC8,
585 [PWRAP_CRC_EN
] = 0xCC,
586 [PWRAP_TIMER_EN
] = 0xD0,
587 [PWRAP_TIMER_STA
] = 0xD4,
588 [PWRAP_WDT_UNIT
] = 0xD8,
589 [PWRAP_WDT_SRC_EN
] = 0xDC,
590 [PWRAP_WDT_FLG
] = 0xE0,
591 [PWRAP_DEBUG_INT_SEL
] = 0xE4,
592 [PWRAP_DVFS_ADR0
] = 0xE8,
593 [PWRAP_DVFS_WDATA0
] = 0xEC,
594 [PWRAP_DVFS_ADR1
] = 0xF0,
595 [PWRAP_DVFS_WDATA1
] = 0xF4,
596 [PWRAP_DVFS_ADR2
] = 0xF8,
597 [PWRAP_DVFS_WDATA2
] = 0xFC,
598 [PWRAP_DVFS_ADR3
] = 0x100,
599 [PWRAP_DVFS_WDATA3
] = 0x104,
600 [PWRAP_DVFS_ADR4
] = 0x108,
601 [PWRAP_DVFS_WDATA4
] = 0x10C,
602 [PWRAP_DVFS_ADR5
] = 0x110,
603 [PWRAP_DVFS_WDATA5
] = 0x114,
604 [PWRAP_DVFS_ADR6
] = 0x118,
605 [PWRAP_DVFS_WDATA6
] = 0x11C,
606 [PWRAP_DVFS_ADR7
] = 0x120,
607 [PWRAP_DVFS_WDATA7
] = 0x124,
608 [PWRAP_DVFS_ADR8
] = 0x128,
609 [PWRAP_DVFS_WDATA8
] = 0x12C,
610 [PWRAP_DVFS_ADR9
] = 0x130,
611 [PWRAP_DVFS_WDATA9
] = 0x134,
612 [PWRAP_DVFS_ADR10
] = 0x138,
613 [PWRAP_DVFS_WDATA10
] = 0x13C,
614 [PWRAP_DVFS_ADR11
] = 0x140,
615 [PWRAP_DVFS_WDATA11
] = 0x144,
616 [PWRAP_DVFS_ADR12
] = 0x148,
617 [PWRAP_DVFS_WDATA12
] = 0x14C,
618 [PWRAP_DVFS_ADR13
] = 0x150,
619 [PWRAP_DVFS_WDATA13
] = 0x154,
620 [PWRAP_DVFS_ADR14
] = 0x158,
621 [PWRAP_DVFS_WDATA14
] = 0x15C,
622 [PWRAP_DVFS_ADR15
] = 0x160,
623 [PWRAP_DVFS_WDATA15
] = 0x164,
624 [PWRAP_SPMINF_STA
] = 0x168,
625 [PWRAP_CIPHER_KEY_SEL
] = 0x16C,
626 [PWRAP_CIPHER_IV_SEL
] = 0x170,
627 [PWRAP_CIPHER_EN
] = 0x174,
628 [PWRAP_CIPHER_RDY
] = 0x178,
629 [PWRAP_CIPHER_MODE
] = 0x17C,
630 [PWRAP_CIPHER_SWRST
] = 0x180,
631 [PWRAP_DCM_EN
] = 0x184,
632 [PWRAP_DCM_DBC_PRD
] = 0x188,
633 [PWRAP_EXT_CK
] = 0x18C,
634 [PWRAP_ADC_CMD_ADDR
] = 0x190,
635 [PWRAP_PWRAP_ADC_CMD
] = 0x194,
636 [PWRAP_ADC_RDATA_ADDR
] = 0x198,
637 [PWRAP_GPS_STA
] = 0x19C,
638 [PWRAP_SW_RST
] = 0x1A0,
639 [PWRAP_DVFS_STEP_CTRL0
] = 0x238,
640 [PWRAP_DVFS_STEP_CTRL1
] = 0x23C,
641 [PWRAP_DVFS_STEP_CTRL2
] = 0x240,
642 [PWRAP_SPI2_CTRL
] = 0x244,
645 static int mt8135_regs
[] = {
646 [PWRAP_MUX_SEL
] = 0x0,
647 [PWRAP_WRAP_EN
] = 0x4,
648 [PWRAP_DIO_EN
] = 0x8,
650 [PWRAP_CSHEXT
] = 0x10,
651 [PWRAP_CSHEXT_WRITE
] = 0x14,
652 [PWRAP_CSHEXT_READ
] = 0x18,
653 [PWRAP_CSLEXT_START
] = 0x1c,
654 [PWRAP_CSLEXT_END
] = 0x20,
655 [PWRAP_STAUPD_PRD
] = 0x24,
656 [PWRAP_STAUPD_GRPEN
] = 0x28,
657 [PWRAP_STAUPD_MAN_TRIG
] = 0x2c,
658 [PWRAP_STAUPD_STA
] = 0x30,
659 [PWRAP_EVENT_IN_EN
] = 0x34,
660 [PWRAP_EVENT_DST_EN
] = 0x38,
661 [PWRAP_WRAP_STA
] = 0x3c,
662 [PWRAP_RRARB_INIT
] = 0x40,
663 [PWRAP_RRARB_EN
] = 0x44,
664 [PWRAP_RRARB_STA0
] = 0x48,
665 [PWRAP_RRARB_STA1
] = 0x4c,
666 [PWRAP_HARB_INIT
] = 0x50,
667 [PWRAP_HARB_HPRIO
] = 0x54,
668 [PWRAP_HIPRIO_ARB_EN
] = 0x58,
669 [PWRAP_HARB_STA0
] = 0x5c,
670 [PWRAP_HARB_STA1
] = 0x60,
671 [PWRAP_MAN_EN
] = 0x64,
672 [PWRAP_MAN_CMD
] = 0x68,
673 [PWRAP_MAN_RDATA
] = 0x6c,
674 [PWRAP_MAN_VLDCLR
] = 0x70,
675 [PWRAP_WACS0_EN
] = 0x74,
676 [PWRAP_INIT_DONE0
] = 0x78,
677 [PWRAP_WACS0_CMD
] = 0x7c,
678 [PWRAP_WACS0_RDATA
] = 0x80,
679 [PWRAP_WACS0_VLDCLR
] = 0x84,
680 [PWRAP_WACS1_EN
] = 0x88,
681 [PWRAP_INIT_DONE1
] = 0x8c,
682 [PWRAP_WACS1_CMD
] = 0x90,
683 [PWRAP_WACS1_RDATA
] = 0x94,
684 [PWRAP_WACS1_VLDCLR
] = 0x98,
685 [PWRAP_WACS2_EN
] = 0x9c,
686 [PWRAP_INIT_DONE2
] = 0xa0,
687 [PWRAP_WACS2_CMD
] = 0xa4,
688 [PWRAP_WACS2_RDATA
] = 0xa8,
689 [PWRAP_WACS2_VLDCLR
] = 0xac,
690 [PWRAP_INT_EN
] = 0xb0,
691 [PWRAP_INT_FLG_RAW
] = 0xb4,
692 [PWRAP_INT_FLG
] = 0xb8,
693 [PWRAP_INT_CLR
] = 0xbc,
694 [PWRAP_SIG_ADR
] = 0xc0,
695 [PWRAP_SIG_MODE
] = 0xc4,
696 [PWRAP_SIG_VALUE
] = 0xc8,
697 [PWRAP_SIG_ERRVAL
] = 0xcc,
698 [PWRAP_CRC_EN
] = 0xd0,
699 [PWRAP_EVENT_STA
] = 0xd4,
700 [PWRAP_EVENT_STACLR
] = 0xd8,
701 [PWRAP_TIMER_EN
] = 0xdc,
702 [PWRAP_TIMER_STA
] = 0xe0,
703 [PWRAP_WDT_UNIT
] = 0xe4,
704 [PWRAP_WDT_SRC_EN
] = 0xe8,
705 [PWRAP_WDT_FLG
] = 0xec,
706 [PWRAP_DEBUG_INT_SEL
] = 0xf0,
707 [PWRAP_CIPHER_KEY_SEL
] = 0x134,
708 [PWRAP_CIPHER_IV_SEL
] = 0x138,
709 [PWRAP_CIPHER_LOAD
] = 0x13c,
710 [PWRAP_CIPHER_START
] = 0x140,
711 [PWRAP_CIPHER_RDY
] = 0x144,
712 [PWRAP_CIPHER_MODE
] = 0x148,
713 [PWRAP_CIPHER_SWRST
] = 0x14c,
714 [PWRAP_DCM_EN
] = 0x15c,
715 [PWRAP_DCM_DBC_PRD
] = 0x160,
718 static int mt8173_regs
[] = {
719 [PWRAP_MUX_SEL
] = 0x0,
720 [PWRAP_WRAP_EN
] = 0x4,
721 [PWRAP_DIO_EN
] = 0x8,
723 [PWRAP_RDDMY
] = 0x10,
724 [PWRAP_SI_CK_CON
] = 0x14,
725 [PWRAP_CSHEXT_WRITE
] = 0x18,
726 [PWRAP_CSHEXT_READ
] = 0x1c,
727 [PWRAP_CSLEXT_START
] = 0x20,
728 [PWRAP_CSLEXT_END
] = 0x24,
729 [PWRAP_STAUPD_PRD
] = 0x28,
730 [PWRAP_STAUPD_GRPEN
] = 0x2c,
731 [PWRAP_STAUPD_MAN_TRIG
] = 0x40,
732 [PWRAP_STAUPD_STA
] = 0x44,
733 [PWRAP_WRAP_STA
] = 0x48,
734 [PWRAP_HARB_INIT
] = 0x4c,
735 [PWRAP_HARB_HPRIO
] = 0x50,
736 [PWRAP_HIPRIO_ARB_EN
] = 0x54,
737 [PWRAP_HARB_STA0
] = 0x58,
738 [PWRAP_HARB_STA1
] = 0x5c,
739 [PWRAP_MAN_EN
] = 0x60,
740 [PWRAP_MAN_CMD
] = 0x64,
741 [PWRAP_MAN_RDATA
] = 0x68,
742 [PWRAP_MAN_VLDCLR
] = 0x6c,
743 [PWRAP_WACS0_EN
] = 0x70,
744 [PWRAP_INIT_DONE0
] = 0x74,
745 [PWRAP_WACS0_CMD
] = 0x78,
746 [PWRAP_WACS0_RDATA
] = 0x7c,
747 [PWRAP_WACS0_VLDCLR
] = 0x80,
748 [PWRAP_WACS1_EN
] = 0x84,
749 [PWRAP_INIT_DONE1
] = 0x88,
750 [PWRAP_WACS1_CMD
] = 0x8c,
751 [PWRAP_WACS1_RDATA
] = 0x90,
752 [PWRAP_WACS1_VLDCLR
] = 0x94,
753 [PWRAP_WACS2_EN
] = 0x98,
754 [PWRAP_INIT_DONE2
] = 0x9c,
755 [PWRAP_WACS2_CMD
] = 0xa0,
756 [PWRAP_WACS2_RDATA
] = 0xa4,
757 [PWRAP_WACS2_VLDCLR
] = 0xa8,
758 [PWRAP_INT_EN
] = 0xac,
759 [PWRAP_INT_FLG_RAW
] = 0xb0,
760 [PWRAP_INT_FLG
] = 0xb4,
761 [PWRAP_INT_CLR
] = 0xb8,
762 [PWRAP_SIG_ADR
] = 0xbc,
763 [PWRAP_SIG_MODE
] = 0xc0,
764 [PWRAP_SIG_VALUE
] = 0xc4,
765 [PWRAP_SIG_ERRVAL
] = 0xc8,
766 [PWRAP_CRC_EN
] = 0xcc,
767 [PWRAP_TIMER_EN
] = 0xd0,
768 [PWRAP_TIMER_STA
] = 0xd4,
769 [PWRAP_WDT_UNIT
] = 0xd8,
770 [PWRAP_WDT_SRC_EN
] = 0xdc,
771 [PWRAP_WDT_FLG
] = 0xe0,
772 [PWRAP_DEBUG_INT_SEL
] = 0xe4,
773 [PWRAP_DVFS_ADR0
] = 0xe8,
774 [PWRAP_DVFS_WDATA0
] = 0xec,
775 [PWRAP_DVFS_ADR1
] = 0xf0,
776 [PWRAP_DVFS_WDATA1
] = 0xf4,
777 [PWRAP_DVFS_ADR2
] = 0xf8,
778 [PWRAP_DVFS_WDATA2
] = 0xfc,
779 [PWRAP_DVFS_ADR3
] = 0x100,
780 [PWRAP_DVFS_WDATA3
] = 0x104,
781 [PWRAP_DVFS_ADR4
] = 0x108,
782 [PWRAP_DVFS_WDATA4
] = 0x10c,
783 [PWRAP_DVFS_ADR5
] = 0x110,
784 [PWRAP_DVFS_WDATA5
] = 0x114,
785 [PWRAP_DVFS_ADR6
] = 0x118,
786 [PWRAP_DVFS_WDATA6
] = 0x11c,
787 [PWRAP_DVFS_ADR7
] = 0x120,
788 [PWRAP_DVFS_WDATA7
] = 0x124,
789 [PWRAP_SPMINF_STA
] = 0x128,
790 [PWRAP_CIPHER_KEY_SEL
] = 0x12c,
791 [PWRAP_CIPHER_IV_SEL
] = 0x130,
792 [PWRAP_CIPHER_EN
] = 0x134,
793 [PWRAP_CIPHER_RDY
] = 0x138,
794 [PWRAP_CIPHER_MODE
] = 0x13c,
795 [PWRAP_CIPHER_SWRST
] = 0x140,
796 [PWRAP_DCM_EN
] = 0x144,
797 [PWRAP_DCM_DBC_PRD
] = 0x148,
800 static int mt8183_regs
[] = {
801 [PWRAP_MUX_SEL
] = 0x0,
802 [PWRAP_WRAP_EN
] = 0x4,
803 [PWRAP_DIO_EN
] = 0x8,
804 [PWRAP_SI_SAMPLE_CTRL
] = 0xC,
805 [PWRAP_RDDMY
] = 0x14,
806 [PWRAP_CSHEXT_WRITE
] = 0x18,
807 [PWRAP_CSHEXT_READ
] = 0x1C,
808 [PWRAP_CSLEXT_WRITE
] = 0x20,
809 [PWRAP_CSLEXT_READ
] = 0x24,
810 [PWRAP_EXT_CK_WRITE
] = 0x28,
811 [PWRAP_STAUPD_CTRL
] = 0x30,
812 [PWRAP_STAUPD_GRPEN
] = 0x34,
813 [PWRAP_EINT_STA0_ADR
] = 0x38,
814 [PWRAP_HARB_HPRIO
] = 0x5C,
815 [PWRAP_HIPRIO_ARB_EN
] = 0x60,
816 [PWRAP_MAN_EN
] = 0x70,
817 [PWRAP_MAN_CMD
] = 0x74,
818 [PWRAP_WACS0_EN
] = 0x80,
819 [PWRAP_INIT_DONE0
] = 0x84,
820 [PWRAP_WACS1_EN
] = 0x88,
821 [PWRAP_INIT_DONE1
] = 0x8C,
822 [PWRAP_WACS2_EN
] = 0x90,
823 [PWRAP_INIT_DONE2
] = 0x94,
824 [PWRAP_WACS_P2P_EN
] = 0xA0,
825 [PWRAP_INIT_DONE_P2P
] = 0xA4,
826 [PWRAP_WACS_MD32_EN
] = 0xA8,
827 [PWRAP_INIT_DONE_MD32
] = 0xAC,
828 [PWRAP_INT_EN
] = 0xB0,
829 [PWRAP_INT_FLG
] = 0xB8,
830 [PWRAP_INT_CLR
] = 0xBC,
831 [PWRAP_INT1_EN
] = 0xC0,
832 [PWRAP_INT1_FLG
] = 0xC8,
833 [PWRAP_INT1_CLR
] = 0xCC,
834 [PWRAP_SIG_ADR
] = 0xD0,
835 [PWRAP_CRC_EN
] = 0xE0,
836 [PWRAP_TIMER_EN
] = 0xE4,
837 [PWRAP_WDT_UNIT
] = 0xEC,
838 [PWRAP_WDT_SRC_EN
] = 0xF0,
839 [PWRAP_WDT_SRC_EN_1
] = 0xF4,
840 [PWRAP_INT_GPS_AUXADC_CMD_ADDR
] = 0x1DC,
841 [PWRAP_INT_GPS_AUXADC_CMD
] = 0x1E0,
842 [PWRAP_INT_GPS_AUXADC_RDATA_ADDR
] = 0x1E4,
843 [PWRAP_EXT_GPS_AUXADC_RDATA_ADDR
] = 0x1E8,
844 [PWRAP_GPSINF_0_STA
] = 0x1EC,
845 [PWRAP_GPSINF_1_STA
] = 0x1F0,
846 [PWRAP_WACS2_CMD
] = 0xC20,
847 [PWRAP_WACS2_RDATA
] = 0xC24,
848 [PWRAP_WACS2_VLDCLR
] = 0xC28,
851 static int mt8516_regs
[] = {
852 [PWRAP_MUX_SEL
] = 0x0,
853 [PWRAP_WRAP_EN
] = 0x4,
854 [PWRAP_DIO_EN
] = 0x8,
856 [PWRAP_RDDMY
] = 0x10,
857 [PWRAP_SI_CK_CON
] = 0x14,
858 [PWRAP_CSHEXT_WRITE
] = 0x18,
859 [PWRAP_CSHEXT_READ
] = 0x1c,
860 [PWRAP_CSLEXT_START
] = 0x20,
861 [PWRAP_CSLEXT_END
] = 0x24,
862 [PWRAP_STAUPD_PRD
] = 0x28,
863 [PWRAP_STAUPD_GRPEN
] = 0x2c,
864 [PWRAP_STAUPD_MAN_TRIG
] = 0x40,
865 [PWRAP_STAUPD_STA
] = 0x44,
866 [PWRAP_WRAP_STA
] = 0x48,
867 [PWRAP_HARB_INIT
] = 0x4c,
868 [PWRAP_HARB_HPRIO
] = 0x50,
869 [PWRAP_HIPRIO_ARB_EN
] = 0x54,
870 [PWRAP_HARB_STA0
] = 0x58,
871 [PWRAP_HARB_STA1
] = 0x5c,
872 [PWRAP_MAN_EN
] = 0x60,
873 [PWRAP_MAN_CMD
] = 0x64,
874 [PWRAP_MAN_RDATA
] = 0x68,
875 [PWRAP_MAN_VLDCLR
] = 0x6c,
876 [PWRAP_WACS0_EN
] = 0x70,
877 [PWRAP_INIT_DONE0
] = 0x74,
878 [PWRAP_WACS0_CMD
] = 0x78,
879 [PWRAP_WACS0_RDATA
] = 0x7c,
880 [PWRAP_WACS0_VLDCLR
] = 0x80,
881 [PWRAP_WACS1_EN
] = 0x84,
882 [PWRAP_INIT_DONE1
] = 0x88,
883 [PWRAP_WACS1_CMD
] = 0x8c,
884 [PWRAP_WACS1_RDATA
] = 0x90,
885 [PWRAP_WACS1_VLDCLR
] = 0x94,
886 [PWRAP_WACS2_EN
] = 0x98,
887 [PWRAP_INIT_DONE2
] = 0x9c,
888 [PWRAP_WACS2_CMD
] = 0xa0,
889 [PWRAP_WACS2_RDATA
] = 0xa4,
890 [PWRAP_WACS2_VLDCLR
] = 0xa8,
891 [PWRAP_INT_EN
] = 0xac,
892 [PWRAP_INT_FLG_RAW
] = 0xb0,
893 [PWRAP_INT_FLG
] = 0xb4,
894 [PWRAP_INT_CLR
] = 0xb8,
895 [PWRAP_SIG_ADR
] = 0xbc,
896 [PWRAP_SIG_MODE
] = 0xc0,
897 [PWRAP_SIG_VALUE
] = 0xc4,
898 [PWRAP_SIG_ERRVAL
] = 0xc8,
899 [PWRAP_CRC_EN
] = 0xcc,
900 [PWRAP_TIMER_EN
] = 0xd0,
901 [PWRAP_TIMER_STA
] = 0xd4,
902 [PWRAP_WDT_UNIT
] = 0xd8,
903 [PWRAP_WDT_SRC_EN
] = 0xdc,
904 [PWRAP_WDT_FLG
] = 0xe0,
905 [PWRAP_DEBUG_INT_SEL
] = 0xe4,
906 [PWRAP_DVFS_ADR0
] = 0xe8,
907 [PWRAP_DVFS_WDATA0
] = 0xec,
908 [PWRAP_DVFS_ADR1
] = 0xf0,
909 [PWRAP_DVFS_WDATA1
] = 0xf4,
910 [PWRAP_DVFS_ADR2
] = 0xf8,
911 [PWRAP_DVFS_WDATA2
] = 0xfc,
912 [PWRAP_DVFS_ADR3
] = 0x100,
913 [PWRAP_DVFS_WDATA3
] = 0x104,
914 [PWRAP_DVFS_ADR4
] = 0x108,
915 [PWRAP_DVFS_WDATA4
] = 0x10c,
916 [PWRAP_DVFS_ADR5
] = 0x110,
917 [PWRAP_DVFS_WDATA5
] = 0x114,
918 [PWRAP_DVFS_ADR6
] = 0x118,
919 [PWRAP_DVFS_WDATA6
] = 0x11c,
920 [PWRAP_DVFS_ADR7
] = 0x120,
921 [PWRAP_DVFS_WDATA7
] = 0x124,
922 [PWRAP_SPMINF_STA
] = 0x128,
923 [PWRAP_CIPHER_KEY_SEL
] = 0x12c,
924 [PWRAP_CIPHER_IV_SEL
] = 0x130,
925 [PWRAP_CIPHER_EN
] = 0x134,
926 [PWRAP_CIPHER_RDY
] = 0x138,
927 [PWRAP_CIPHER_MODE
] = 0x13c,
928 [PWRAP_CIPHER_SWRST
] = 0x140,
929 [PWRAP_DCM_EN
] = 0x144,
930 [PWRAP_DCM_DBC_PRD
] = 0x148,
931 [PWRAP_SW_RST
] = 0x168,
932 [PWRAP_OP_TYPE
] = 0x16c,
933 [PWRAP_MSB_FIRST
] = 0x170,
957 struct pwrap_slv_type
{
960 const struct regmap_config
*regmap
;
961 /* Flags indicating the capability for the target slave */
964 * pwrap operations are highly associated with the PMIC types,
965 * so the pointers added increases flexibility allowing determination
966 * which type is used by the detection through device tree.
968 int (*pwrap_read
)(struct pmic_wrapper
*wrp
, u32 adr
, u32
*rdata
);
969 int (*pwrap_write
)(struct pmic_wrapper
*wrp
, u32 adr
, u32 wdata
);
972 struct pmic_wrapper
{
975 struct regmap
*regmap
;
976 const struct pmic_wrapper_type
*master
;
977 const struct pwrap_slv_type
*slave
;
979 struct clk
*clk_wrap
;
980 struct reset_control
*rstc
;
982 struct reset_control
*rstc_bridge
;
983 void __iomem
*bridge_base
;
986 struct pmic_wrapper_type
{
988 enum pwrap_type type
;
994 /* Flags indicating the capability for the target pwrap */
996 int (*init_reg_clock
)(struct pmic_wrapper
*wrp
);
997 int (*init_soc_specific
)(struct pmic_wrapper
*wrp
);
1000 static u32
pwrap_readl(struct pmic_wrapper
*wrp
, enum pwrap_regs reg
)
1002 return readl(wrp
->base
+ wrp
->master
->regs
[reg
]);
1005 static void pwrap_writel(struct pmic_wrapper
*wrp
, u32 val
, enum pwrap_regs reg
)
1007 writel(val
, wrp
->base
+ wrp
->master
->regs
[reg
]);
1010 static bool pwrap_is_fsm_idle(struct pmic_wrapper
*wrp
)
1012 u32 val
= pwrap_readl(wrp
, PWRAP_WACS2_RDATA
);
1014 return PWRAP_GET_WACS_FSM(val
) == PWRAP_WACS_FSM_IDLE
;
1017 static bool pwrap_is_fsm_vldclr(struct pmic_wrapper
*wrp
)
1019 u32 val
= pwrap_readl(wrp
, PWRAP_WACS2_RDATA
);
1021 return PWRAP_GET_WACS_FSM(val
) == PWRAP_WACS_FSM_WFVLDCLR
;
1025 * Timeout issue sometimes caused by the last read command
1026 * failed because pmic wrap could not got the FSM_VLDCLR
1027 * in time after finishing WACS2_CMD. It made state machine
1028 * still on FSM_VLDCLR and timeout next time.
1029 * Check the status of FSM and clear the vldclr to recovery the
1032 static inline void pwrap_leave_fsm_vldclr(struct pmic_wrapper
*wrp
)
1034 if (pwrap_is_fsm_vldclr(wrp
))
1035 pwrap_writel(wrp
, 1, PWRAP_WACS2_VLDCLR
);
1038 static bool pwrap_is_sync_idle(struct pmic_wrapper
*wrp
)
1040 return pwrap_readl(wrp
, PWRAP_WACS2_RDATA
) & PWRAP_STATE_SYNC_IDLE0
;
1043 static bool pwrap_is_fsm_idle_and_sync_idle(struct pmic_wrapper
*wrp
)
1045 u32 val
= pwrap_readl(wrp
, PWRAP_WACS2_RDATA
);
1047 return (PWRAP_GET_WACS_FSM(val
) == PWRAP_WACS_FSM_IDLE
) &&
1048 (val
& PWRAP_STATE_SYNC_IDLE0
);
1051 static int pwrap_wait_for_state(struct pmic_wrapper
*wrp
,
1052 bool (*fp
)(struct pmic_wrapper
*))
1054 unsigned long timeout
;
1056 timeout
= jiffies
+ usecs_to_jiffies(10000);
1059 if (time_after(jiffies
, timeout
))
1060 return fp(wrp
) ? 0 : -ETIMEDOUT
;
1066 static int pwrap_read16(struct pmic_wrapper
*wrp
, u32 adr
, u32
*rdata
)
1070 ret
= pwrap_wait_for_state(wrp
, pwrap_is_fsm_idle
);
1072 pwrap_leave_fsm_vldclr(wrp
);
1076 pwrap_writel(wrp
, (adr
>> 1) << 16, PWRAP_WACS2_CMD
);
1078 ret
= pwrap_wait_for_state(wrp
, pwrap_is_fsm_vldclr
);
1082 *rdata
= PWRAP_GET_WACS_RDATA(pwrap_readl(wrp
, PWRAP_WACS2_RDATA
));
1084 pwrap_writel(wrp
, 1, PWRAP_WACS2_VLDCLR
);
1089 static int pwrap_read32(struct pmic_wrapper
*wrp
, u32 adr
, u32
*rdata
)
1094 for (msb
= 0; msb
< 2; msb
++) {
1095 ret
= pwrap_wait_for_state(wrp
, pwrap_is_fsm_idle
);
1097 pwrap_leave_fsm_vldclr(wrp
);
1101 pwrap_writel(wrp
, ((msb
<< 30) | (adr
<< 16)),
1104 ret
= pwrap_wait_for_state(wrp
, pwrap_is_fsm_vldclr
);
1108 *rdata
+= (PWRAP_GET_WACS_RDATA(pwrap_readl(wrp
,
1109 PWRAP_WACS2_RDATA
)) << (16 * msb
));
1111 pwrap_writel(wrp
, 1, PWRAP_WACS2_VLDCLR
);
1117 static int pwrap_read(struct pmic_wrapper
*wrp
, u32 adr
, u32
*rdata
)
1119 return wrp
->slave
->pwrap_read(wrp
, adr
, rdata
);
1122 static int pwrap_write16(struct pmic_wrapper
*wrp
, u32 adr
, u32 wdata
)
1126 ret
= pwrap_wait_for_state(wrp
, pwrap_is_fsm_idle
);
1128 pwrap_leave_fsm_vldclr(wrp
);
1132 pwrap_writel(wrp
, (1 << 31) | ((adr
>> 1) << 16) | wdata
,
1138 static int pwrap_write32(struct pmic_wrapper
*wrp
, u32 adr
, u32 wdata
)
1140 int ret
, msb
, rdata
;
1142 for (msb
= 0; msb
< 2; msb
++) {
1143 ret
= pwrap_wait_for_state(wrp
, pwrap_is_fsm_idle
);
1145 pwrap_leave_fsm_vldclr(wrp
);
1149 pwrap_writel(wrp
, (1 << 31) | (msb
<< 30) | (adr
<< 16) |
1150 ((wdata
>> (msb
* 16)) & 0xffff),
1154 * The pwrap_read operation is the requirement of hardware used
1155 * for the synchronization between two successive 16-bit
1156 * pwrap_writel operations composing one 32-bit bus writing.
1157 * Otherwise, we'll find the result fails on the lower 16-bit
1161 pwrap_read(wrp
, adr
, &rdata
);
1167 static int pwrap_write(struct pmic_wrapper
*wrp
, u32 adr
, u32 wdata
)
1169 return wrp
->slave
->pwrap_write(wrp
, adr
, wdata
);
1172 static int pwrap_regmap_read(void *context
, u32 adr
, u32
*rdata
)
1174 return pwrap_read(context
, adr
, rdata
);
1177 static int pwrap_regmap_write(void *context
, u32 adr
, u32 wdata
)
1179 return pwrap_write(context
, adr
, wdata
);
1182 static int pwrap_reset_spislave(struct pmic_wrapper
*wrp
)
1186 pwrap_writel(wrp
, 0, PWRAP_HIPRIO_ARB_EN
);
1187 pwrap_writel(wrp
, 0, PWRAP_WRAP_EN
);
1188 pwrap_writel(wrp
, 1, PWRAP_MUX_SEL
);
1189 pwrap_writel(wrp
, 1, PWRAP_MAN_EN
);
1190 pwrap_writel(wrp
, 0, PWRAP_DIO_EN
);
1192 pwrap_writel(wrp
, wrp
->master
->spi_w
| PWRAP_MAN_CMD_OP_CSL
,
1194 pwrap_writel(wrp
, wrp
->master
->spi_w
| PWRAP_MAN_CMD_OP_OUTS
,
1196 pwrap_writel(wrp
, wrp
->master
->spi_w
| PWRAP_MAN_CMD_OP_CSH
,
1199 for (i
= 0; i
< 4; i
++)
1200 pwrap_writel(wrp
, wrp
->master
->spi_w
| PWRAP_MAN_CMD_OP_OUTS
,
1203 ret
= pwrap_wait_for_state(wrp
, pwrap_is_sync_idle
);
1205 dev_err(wrp
->dev
, "%s fail, ret=%d\n", __func__
, ret
);
1209 pwrap_writel(wrp
, 0, PWRAP_MAN_EN
);
1210 pwrap_writel(wrp
, 0, PWRAP_MUX_SEL
);
1216 * pwrap_init_sidly - configure serial input delay
1218 * This configures the serial input delay. We can configure 0, 2, 4 or 6ns
1219 * delay. Do a read test with all possible values and chose the best delay.
1221 static int pwrap_init_sidly(struct pmic_wrapper
*wrp
)
1226 signed char dly
[16] = {
1227 -1, 0, 1, 0, 2, -1, 1, 1, 3, -1, -1, -1, 3, -1, 2, 1
1230 for (i
= 0; i
< 4; i
++) {
1231 pwrap_writel(wrp
, i
, PWRAP_SIDLY
);
1232 pwrap_read(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_READ_TEST
],
1234 if (rdata
== PWRAP_DEW_READ_TEST_VAL
) {
1235 dev_dbg(wrp
->dev
, "[Read Test] pass, SIDLY=%x\n", i
);
1240 if (dly
[pass
] < 0) {
1241 dev_err(wrp
->dev
, "sidly pass range 0x%x not continuous\n",
1246 pwrap_writel(wrp
, dly
[pass
], PWRAP_SIDLY
);
1251 static int pwrap_init_dual_io(struct pmic_wrapper
*wrp
)
1256 /* Enable dual IO mode */
1257 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_DIO_EN
], 1);
1259 /* Check IDLE & INIT_DONE in advance */
1260 ret
= pwrap_wait_for_state(wrp
,
1261 pwrap_is_fsm_idle_and_sync_idle
);
1263 dev_err(wrp
->dev
, "%s fail, ret=%d\n", __func__
, ret
);
1267 pwrap_writel(wrp
, 1, PWRAP_DIO_EN
);
1271 wrp
->slave
->dew_regs
[PWRAP_DEW_READ_TEST
], &rdata
);
1272 if (rdata
!= PWRAP_DEW_READ_TEST_VAL
) {
1274 "Read failed on DIO mode: 0x%04x!=0x%04x\n",
1275 PWRAP_DEW_READ_TEST_VAL
, rdata
);
1283 * pwrap_init_chip_select_ext is used to configure CS extension time for each
1284 * phase during data transactions on the pwrap bus.
1286 static void pwrap_init_chip_select_ext(struct pmic_wrapper
*wrp
, u8 hext_write
,
1287 u8 hext_read
, u8 lext_start
,
1291 * After finishing a write and read transaction, extends CS high time
1292 * to be at least xT of BUS CLK as hext_write and hext_read specifies
1295 pwrap_writel(wrp
, hext_write
, PWRAP_CSHEXT_WRITE
);
1296 pwrap_writel(wrp
, hext_read
, PWRAP_CSHEXT_READ
);
1299 * Extends CS low time after CSL and before CSH command to be at
1300 * least xT of BUS CLK as lext_start and lext_end specifies
1303 pwrap_writel(wrp
, lext_start
, PWRAP_CSLEXT_START
);
1304 pwrap_writel(wrp
, lext_end
, PWRAP_CSLEXT_END
);
1307 static int pwrap_common_init_reg_clock(struct pmic_wrapper
*wrp
)
1309 switch (wrp
->master
->type
) {
1311 pwrap_init_chip_select_ext(wrp
, 0, 4, 2, 2);
1314 pwrap_writel(wrp
, 0x4, PWRAP_CSHEXT
);
1315 pwrap_init_chip_select_ext(wrp
, 0, 4, 0, 0);
1324 static int pwrap_mt2701_init_reg_clock(struct pmic_wrapper
*wrp
)
1326 switch (wrp
->slave
->type
) {
1328 pwrap_writel(wrp
, 0xc, PWRAP_RDDMY
);
1329 pwrap_init_chip_select_ext(wrp
, 4, 0, 2, 2);
1333 pwrap_writel(wrp
, 0x8, PWRAP_RDDMY
);
1334 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_RDDMY_NO
],
1336 pwrap_init_chip_select_ext(wrp
, 5, 0, 2, 2);
1345 static bool pwrap_is_cipher_ready(struct pmic_wrapper
*wrp
)
1347 return pwrap_readl(wrp
, PWRAP_CIPHER_RDY
) & 1;
1350 static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper
*wrp
)
1355 ret
= pwrap_read(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_RDY
],
1363 static int pwrap_init_cipher(struct pmic_wrapper
*wrp
)
1368 pwrap_writel(wrp
, 0x1, PWRAP_CIPHER_SWRST
);
1369 pwrap_writel(wrp
, 0x0, PWRAP_CIPHER_SWRST
);
1370 pwrap_writel(wrp
, 0x1, PWRAP_CIPHER_KEY_SEL
);
1371 pwrap_writel(wrp
, 0x2, PWRAP_CIPHER_IV_SEL
);
1373 switch (wrp
->master
->type
) {
1375 pwrap_writel(wrp
, 1, PWRAP_CIPHER_LOAD
);
1376 pwrap_writel(wrp
, 1, PWRAP_CIPHER_START
);
1383 pwrap_writel(wrp
, 1, PWRAP_CIPHER_EN
);
1386 pwrap_writel(wrp
, 0, PWRAP_CIPHER_EN
);
1392 /* Config cipher mode @PMIC */
1393 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_SWRST
], 0x1);
1394 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_SWRST
], 0x0);
1395 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_KEY_SEL
], 0x1);
1396 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_IV_SEL
], 0x2);
1398 switch (wrp
->slave
->type
) {
1400 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_LOAD
],
1402 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_START
],
1408 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_EN
],
1415 /* wait for cipher data ready@AP */
1416 ret
= pwrap_wait_for_state(wrp
, pwrap_is_cipher_ready
);
1418 dev_err(wrp
->dev
, "cipher data ready@AP fail, ret=%d\n", ret
);
1422 /* wait for cipher data ready@PMIC */
1423 ret
= pwrap_wait_for_state(wrp
, pwrap_is_pmic_cipher_ready
);
1426 "timeout waiting for cipher data ready@PMIC\n");
1430 /* wait for cipher mode idle */
1431 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CIPHER_MODE
], 0x1);
1432 ret
= pwrap_wait_for_state(wrp
, pwrap_is_fsm_idle_and_sync_idle
);
1434 dev_err(wrp
->dev
, "cipher mode idle fail, ret=%d\n", ret
);
1438 pwrap_writel(wrp
, 1, PWRAP_CIPHER_MODE
);
1441 if (pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_WRITE_TEST
],
1442 PWRAP_DEW_WRITE_TEST_VAL
) ||
1443 pwrap_read(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_WRITE_TEST
],
1445 (rdata
!= PWRAP_DEW_WRITE_TEST_VAL
)) {
1446 dev_err(wrp
->dev
, "rdata=0x%04X\n", rdata
);
1453 static int pwrap_init_security(struct pmic_wrapper
*wrp
)
1457 /* Enable encryption */
1458 ret
= pwrap_init_cipher(wrp
);
1462 /* Signature checking - using CRC */
1463 if (pwrap_write(wrp
,
1464 wrp
->slave
->dew_regs
[PWRAP_DEW_CRC_EN
], 0x1))
1467 pwrap_writel(wrp
, 0x1, PWRAP_CRC_EN
);
1468 pwrap_writel(wrp
, 0x0, PWRAP_SIG_MODE
);
1469 pwrap_writel(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CRC_VAL
],
1472 wrp
->master
->arb_en_all
, PWRAP_HIPRIO_ARB_EN
);
1477 static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper
*wrp
)
1479 /* enable pwrap events and pwrap bridge in AP side */
1480 pwrap_writel(wrp
, 0x1, PWRAP_EVENT_IN_EN
);
1481 pwrap_writel(wrp
, 0xffff, PWRAP_EVENT_DST_EN
);
1482 writel(0x7f, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_IORD_ARB_EN
);
1483 writel(0x1, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_WACS3_EN
);
1484 writel(0x1, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_WACS4_EN
);
1485 writel(0x1, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_WDT_UNIT
);
1486 writel(0xffff, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_WDT_SRC_EN
);
1487 writel(0x1, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_TIMER_EN
);
1488 writel(0x7ff, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_INT_EN
);
1490 /* enable PMIC event out and sources */
1491 if (pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_EVENT_OUT_EN
],
1493 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_EVENT_SRC_EN
],
1495 dev_err(wrp
->dev
, "enable dewrap fail\n");
1502 static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper
*wrp
)
1504 /* PMIC_DEWRAP enables */
1505 if (pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_EVENT_OUT_EN
],
1507 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_EVENT_SRC_EN
],
1509 dev_err(wrp
->dev
, "enable dewrap fail\n");
1516 static int pwrap_mt2701_init_soc_specific(struct pmic_wrapper
*wrp
)
1518 /* GPS_INTF initialization */
1519 switch (wrp
->slave
->type
) {
1521 pwrap_writel(wrp
, 0x076c, PWRAP_ADC_CMD_ADDR
);
1522 pwrap_writel(wrp
, 0x8000, PWRAP_PWRAP_ADC_CMD
);
1523 pwrap_writel(wrp
, 0x072c, PWRAP_ADC_RDY_ADDR
);
1524 pwrap_writel(wrp
, 0x072e, PWRAP_ADC_RDATA_ADDR1
);
1525 pwrap_writel(wrp
, 0x0730, PWRAP_ADC_RDATA_ADDR2
);
1534 static int pwrap_mt7622_init_soc_specific(struct pmic_wrapper
*wrp
)
1536 pwrap_writel(wrp
, 0, PWRAP_STAUPD_PRD
);
1537 /* enable 2wire SPI master */
1538 pwrap_writel(wrp
, 0x8000000, PWRAP_SPI2_CTRL
);
1543 static int pwrap_mt8183_init_soc_specific(struct pmic_wrapper
*wrp
)
1545 pwrap_writel(wrp
, 0xf5, PWRAP_STAUPD_GRPEN
);
1547 pwrap_write(wrp
, wrp
->slave
->dew_regs
[PWRAP_DEW_CRC_EN
], 0x1);
1548 pwrap_writel(wrp
, 1, PWRAP_CRC_EN
);
1549 pwrap_writel(wrp
, 0x416, PWRAP_SIG_ADR
);
1550 pwrap_writel(wrp
, 0x42e, PWRAP_EINT_STA0_ADR
);
1552 pwrap_writel(wrp
, 1, PWRAP_WACS_P2P_EN
);
1553 pwrap_writel(wrp
, 1, PWRAP_WACS_MD32_EN
);
1554 pwrap_writel(wrp
, 1, PWRAP_INIT_DONE_P2P
);
1555 pwrap_writel(wrp
, 1, PWRAP_INIT_DONE_MD32
);
1560 static int pwrap_init(struct pmic_wrapper
*wrp
)
1565 reset_control_reset(wrp
->rstc
);
1566 if (wrp
->rstc_bridge
)
1567 reset_control_reset(wrp
->rstc_bridge
);
1569 if (wrp
->master
->type
== PWRAP_MT8173
) {
1571 pwrap_writel(wrp
, 3, PWRAP_DCM_EN
);
1572 pwrap_writel(wrp
, 0, PWRAP_DCM_DBC_PRD
);
1575 if (HAS_CAP(wrp
->slave
->caps
, PWRAP_SLV_CAP_SPI
)) {
1576 /* Reset SPI slave */
1577 ret
= pwrap_reset_spislave(wrp
);
1582 pwrap_writel(wrp
, 1, PWRAP_WRAP_EN
);
1584 pwrap_writel(wrp
, wrp
->master
->arb_en_all
, PWRAP_HIPRIO_ARB_EN
);
1586 pwrap_writel(wrp
, 1, PWRAP_WACS2_EN
);
1588 ret
= wrp
->master
->init_reg_clock(wrp
);
1592 if (HAS_CAP(wrp
->slave
->caps
, PWRAP_SLV_CAP_SPI
)) {
1593 /* Setup serial input delay */
1594 ret
= pwrap_init_sidly(wrp
);
1599 if (HAS_CAP(wrp
->slave
->caps
, PWRAP_SLV_CAP_DUALIO
)) {
1600 /* Enable dual I/O mode */
1601 ret
= pwrap_init_dual_io(wrp
);
1606 if (HAS_CAP(wrp
->slave
->caps
, PWRAP_SLV_CAP_SECURITY
)) {
1607 /* Enable security on bus */
1608 ret
= pwrap_init_security(wrp
);
1613 if (wrp
->master
->type
== PWRAP_MT8135
)
1614 pwrap_writel(wrp
, 0x7, PWRAP_RRARB_EN
);
1616 pwrap_writel(wrp
, 0x1, PWRAP_WACS0_EN
);
1617 pwrap_writel(wrp
, 0x1, PWRAP_WACS1_EN
);
1618 pwrap_writel(wrp
, 0x1, PWRAP_WACS2_EN
);
1619 pwrap_writel(wrp
, 0x5, PWRAP_STAUPD_PRD
);
1620 pwrap_writel(wrp
, 0xff, PWRAP_STAUPD_GRPEN
);
1622 if (wrp
->master
->init_soc_specific
) {
1623 ret
= wrp
->master
->init_soc_specific(wrp
);
1628 /* Setup the init done registers */
1629 pwrap_writel(wrp
, 1, PWRAP_INIT_DONE2
);
1630 pwrap_writel(wrp
, 1, PWRAP_INIT_DONE0
);
1631 pwrap_writel(wrp
, 1, PWRAP_INIT_DONE1
);
1633 if (HAS_CAP(wrp
->master
->caps
, PWRAP_CAP_BRIDGE
)) {
1634 writel(1, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_INIT_DONE3
);
1635 writel(1, wrp
->bridge_base
+ PWRAP_MT8135_BRIDGE_INIT_DONE4
);
1641 static irqreturn_t
pwrap_interrupt(int irqno
, void *dev_id
)
1644 struct pmic_wrapper
*wrp
= dev_id
;
1646 rdata
= pwrap_readl(wrp
, PWRAP_INT_FLG
);
1647 dev_err(wrp
->dev
, "unexpected interrupt int=0x%x\n", rdata
);
1648 pwrap_writel(wrp
, 0xffffffff, PWRAP_INT_CLR
);
1650 if (HAS_CAP(wrp
->master
->caps
, PWRAP_CAP_INT1_EN
)) {
1651 rdata
= pwrap_readl(wrp
, PWRAP_INT1_FLG
);
1652 dev_err(wrp
->dev
, "unexpected interrupt int1=0x%x\n", rdata
);
1653 pwrap_writel(wrp
, 0xffffffff, PWRAP_INT1_CLR
);
1659 static const struct regmap_config pwrap_regmap_config16
= {
1663 .reg_read
= pwrap_regmap_read
,
1664 .reg_write
= pwrap_regmap_write
,
1665 .max_register
= 0xffff,
1668 static const struct regmap_config pwrap_regmap_config32
= {
1672 .reg_read
= pwrap_regmap_read
,
1673 .reg_write
= pwrap_regmap_write
,
1674 .max_register
= 0xffff,
1677 static const struct pwrap_slv_type pmic_mt6323
= {
1678 .dew_regs
= mt6323_regs
,
1679 .type
= PMIC_MT6323
,
1680 .regmap
= &pwrap_regmap_config16
,
1681 .caps
= PWRAP_SLV_CAP_SPI
| PWRAP_SLV_CAP_DUALIO
|
1682 PWRAP_SLV_CAP_SECURITY
,
1683 .pwrap_read
= pwrap_read16
,
1684 .pwrap_write
= pwrap_write16
,
1687 static const struct pwrap_slv_type pmic_mt6351
= {
1688 .dew_regs
= mt6351_regs
,
1689 .type
= PMIC_MT6351
,
1690 .regmap
= &pwrap_regmap_config16
,
1692 .pwrap_read
= pwrap_read16
,
1693 .pwrap_write
= pwrap_write16
,
1696 static const struct pwrap_slv_type pmic_mt6357
= {
1697 .dew_regs
= mt6357_regs
,
1698 .type
= PMIC_MT6357
,
1699 .regmap
= &pwrap_regmap_config16
,
1701 .pwrap_read
= pwrap_read16
,
1702 .pwrap_write
= pwrap_write16
,
1705 static const struct pwrap_slv_type pmic_mt6358
= {
1706 .dew_regs
= mt6358_regs
,
1707 .type
= PMIC_MT6358
,
1708 .regmap
= &pwrap_regmap_config16
,
1709 .caps
= PWRAP_SLV_CAP_SPI
| PWRAP_SLV_CAP_DUALIO
,
1710 .pwrap_read
= pwrap_read16
,
1711 .pwrap_write
= pwrap_write16
,
1714 static const struct pwrap_slv_type pmic_mt6380
= {
1716 .type
= PMIC_MT6380
,
1717 .regmap
= &pwrap_regmap_config32
,
1719 .pwrap_read
= pwrap_read32
,
1720 .pwrap_write
= pwrap_write32
,
1723 static const struct pwrap_slv_type pmic_mt6397
= {
1724 .dew_regs
= mt6397_regs
,
1725 .type
= PMIC_MT6397
,
1726 .regmap
= &pwrap_regmap_config16
,
1727 .caps
= PWRAP_SLV_CAP_SPI
| PWRAP_SLV_CAP_DUALIO
|
1728 PWRAP_SLV_CAP_SECURITY
,
1729 .pwrap_read
= pwrap_read16
,
1730 .pwrap_write
= pwrap_write16
,
1733 static const struct of_device_id of_slave_match_tbl
[] = {
1735 .compatible
= "mediatek,mt6323",
1736 .data
= &pmic_mt6323
,
1738 .compatible
= "mediatek,mt6351",
1739 .data
= &pmic_mt6351
,
1741 .compatible
= "mediatek,mt6357",
1742 .data
= &pmic_mt6357
,
1744 .compatible
= "mediatek,mt6358",
1745 .data
= &pmic_mt6358
,
1747 /* The MT6380 PMIC only implements a regulator, so we bind it
1748 * directly instead of using a MFD.
1750 .compatible
= "mediatek,mt6380-regulator",
1751 .data
= &pmic_mt6380
,
1753 .compatible
= "mediatek,mt6397",
1754 .data
= &pmic_mt6397
,
1759 MODULE_DEVICE_TABLE(of
, of_slave_match_tbl
);
1761 static const struct pmic_wrapper_type pwrap_mt2701
= {
1762 .regs
= mt2701_regs
,
1763 .type
= PWRAP_MT2701
,
1765 .int_en_all
= ~(u32
)(BIT(31) | BIT(2)),
1767 .spi_w
= PWRAP_MAN_CMD_SPI_WRITE_NEW
,
1768 .wdt_src
= PWRAP_WDT_SRC_MASK_ALL
,
1769 .caps
= PWRAP_CAP_RESET
| PWRAP_CAP_DCM
,
1770 .init_reg_clock
= pwrap_mt2701_init_reg_clock
,
1771 .init_soc_specific
= pwrap_mt2701_init_soc_specific
,
1774 static const struct pmic_wrapper_type pwrap_mt6765
= {
1775 .regs
= mt6765_regs
,
1776 .type
= PWRAP_MT6765
,
1777 .arb_en_all
= 0x3fd35,
1778 .int_en_all
= 0xffffffff,
1779 .spi_w
= PWRAP_MAN_CMD_SPI_WRITE
,
1780 .wdt_src
= PWRAP_WDT_SRC_MASK_ALL
,
1781 .caps
= PWRAP_CAP_RESET
| PWRAP_CAP_DCM
,
1782 .init_reg_clock
= pwrap_common_init_reg_clock
,
1783 .init_soc_specific
= NULL
,
1786 static const struct pmic_wrapper_type pwrap_mt6797
= {
1787 .regs
= mt6797_regs
,
1788 .type
= PWRAP_MT6797
,
1789 .arb_en_all
= 0x01fff,
1790 .int_en_all
= 0xffffffc6,
1792 .spi_w
= PWRAP_MAN_CMD_SPI_WRITE
,
1793 .wdt_src
= PWRAP_WDT_SRC_MASK_ALL
,
1794 .caps
= PWRAP_CAP_RESET
| PWRAP_CAP_DCM
,
1795 .init_reg_clock
= pwrap_common_init_reg_clock
,
1796 .init_soc_specific
= NULL
,
1799 static const struct pmic_wrapper_type pwrap_mt7622
= {
1800 .regs
= mt7622_regs
,
1801 .type
= PWRAP_MT7622
,
1803 .int_en_all
= ~(u32
)BIT(31),
1805 .spi_w
= PWRAP_MAN_CMD_SPI_WRITE
,
1806 .wdt_src
= PWRAP_WDT_SRC_MASK_ALL
,
1807 .caps
= PWRAP_CAP_RESET
| PWRAP_CAP_DCM
,
1808 .init_reg_clock
= pwrap_common_init_reg_clock
,
1809 .init_soc_specific
= pwrap_mt7622_init_soc_specific
,
1812 static const struct pmic_wrapper_type pwrap_mt8135
= {
1813 .regs
= mt8135_regs
,
1814 .type
= PWRAP_MT8135
,
1815 .arb_en_all
= 0x1ff,
1816 .int_en_all
= ~(u32
)(BIT(31) | BIT(1)),
1818 .spi_w
= PWRAP_MAN_CMD_SPI_WRITE
,
1819 .wdt_src
= PWRAP_WDT_SRC_MASK_ALL
,
1820 .caps
= PWRAP_CAP_BRIDGE
| PWRAP_CAP_RESET
| PWRAP_CAP_DCM
,
1821 .init_reg_clock
= pwrap_common_init_reg_clock
,
1822 .init_soc_specific
= pwrap_mt8135_init_soc_specific
,
1825 static const struct pmic_wrapper_type pwrap_mt8173
= {
1826 .regs
= mt8173_regs
,
1827 .type
= PWRAP_MT8173
,
1829 .int_en_all
= ~(u32
)(BIT(31) | BIT(1)),
1831 .spi_w
= PWRAP_MAN_CMD_SPI_WRITE
,
1832 .wdt_src
= PWRAP_WDT_SRC_MASK_NO_STAUPD
,
1833 .caps
= PWRAP_CAP_RESET
| PWRAP_CAP_DCM
,
1834 .init_reg_clock
= pwrap_common_init_reg_clock
,
1835 .init_soc_specific
= pwrap_mt8173_init_soc_specific
,
1838 static const struct pmic_wrapper_type pwrap_mt8183
= {
1839 .regs
= mt8183_regs
,
1840 .type
= PWRAP_MT8183
,
1841 .arb_en_all
= 0x3fa75,
1842 .int_en_all
= 0xffffffff,
1843 .int1_en_all
= 0xeef7ffff,
1844 .spi_w
= PWRAP_MAN_CMD_SPI_WRITE
,
1845 .wdt_src
= PWRAP_WDT_SRC_MASK_ALL
,
1846 .caps
= PWRAP_CAP_INT1_EN
| PWRAP_CAP_WDT_SRC1
,
1847 .init_reg_clock
= pwrap_common_init_reg_clock
,
1848 .init_soc_specific
= pwrap_mt8183_init_soc_specific
,
1851 static struct pmic_wrapper_type pwrap_mt8516
= {
1852 .regs
= mt8516_regs
,
1853 .type
= PWRAP_MT8516
,
1855 .int_en_all
= ~(u32
)(BIT(31) | BIT(2)),
1856 .spi_w
= PWRAP_MAN_CMD_SPI_WRITE
,
1857 .wdt_src
= PWRAP_WDT_SRC_MASK_ALL
,
1858 .caps
= PWRAP_CAP_DCM
,
1859 .init_reg_clock
= pwrap_mt2701_init_reg_clock
,
1860 .init_soc_specific
= NULL
,
1863 static const struct of_device_id of_pwrap_match_tbl
[] = {
1865 .compatible
= "mediatek,mt2701-pwrap",
1866 .data
= &pwrap_mt2701
,
1868 .compatible
= "mediatek,mt6765-pwrap",
1869 .data
= &pwrap_mt6765
,
1871 .compatible
= "mediatek,mt6797-pwrap",
1872 .data
= &pwrap_mt6797
,
1874 .compatible
= "mediatek,mt7622-pwrap",
1875 .data
= &pwrap_mt7622
,
1877 .compatible
= "mediatek,mt8135-pwrap",
1878 .data
= &pwrap_mt8135
,
1880 .compatible
= "mediatek,mt8173-pwrap",
1881 .data
= &pwrap_mt8173
,
1883 .compatible
= "mediatek,mt8183-pwrap",
1884 .data
= &pwrap_mt8183
,
1886 .compatible
= "mediatek,mt8516-pwrap",
1887 .data
= &pwrap_mt8516
,
1892 MODULE_DEVICE_TABLE(of
, of_pwrap_match_tbl
);
1894 static int pwrap_probe(struct platform_device
*pdev
)
1897 struct pmic_wrapper
*wrp
;
1898 struct device_node
*np
= pdev
->dev
.of_node
;
1899 const struct of_device_id
*of_slave_id
= NULL
;
1900 struct resource
*res
;
1903 of_slave_id
= of_match_node(of_slave_match_tbl
, np
->child
);
1906 dev_dbg(&pdev
->dev
, "slave pmic should be defined in dts\n");
1910 wrp
= devm_kzalloc(&pdev
->dev
, sizeof(*wrp
), GFP_KERNEL
);
1914 platform_set_drvdata(pdev
, wrp
);
1916 wrp
->master
= of_device_get_match_data(&pdev
->dev
);
1917 wrp
->slave
= of_slave_id
->data
;
1918 wrp
->dev
= &pdev
->dev
;
1920 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "pwrap");
1921 wrp
->base
= devm_ioremap_resource(wrp
->dev
, res
);
1922 if (IS_ERR(wrp
->base
))
1923 return PTR_ERR(wrp
->base
);
1925 if (HAS_CAP(wrp
->master
->caps
, PWRAP_CAP_RESET
)) {
1926 wrp
->rstc
= devm_reset_control_get(wrp
->dev
, "pwrap");
1927 if (IS_ERR(wrp
->rstc
)) {
1928 ret
= PTR_ERR(wrp
->rstc
);
1929 dev_dbg(wrp
->dev
, "cannot get pwrap reset: %d\n", ret
);
1934 if (HAS_CAP(wrp
->master
->caps
, PWRAP_CAP_BRIDGE
)) {
1935 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
1937 wrp
->bridge_base
= devm_ioremap_resource(wrp
->dev
, res
);
1938 if (IS_ERR(wrp
->bridge_base
))
1939 return PTR_ERR(wrp
->bridge_base
);
1941 wrp
->rstc_bridge
= devm_reset_control_get(wrp
->dev
,
1943 if (IS_ERR(wrp
->rstc_bridge
)) {
1944 ret
= PTR_ERR(wrp
->rstc_bridge
);
1946 "cannot get pwrap-bridge reset: %d\n", ret
);
1951 wrp
->clk_spi
= devm_clk_get(wrp
->dev
, "spi");
1952 if (IS_ERR(wrp
->clk_spi
)) {
1953 dev_dbg(wrp
->dev
, "failed to get clock: %ld\n",
1954 PTR_ERR(wrp
->clk_spi
));
1955 return PTR_ERR(wrp
->clk_spi
);
1958 wrp
->clk_wrap
= devm_clk_get(wrp
->dev
, "wrap");
1959 if (IS_ERR(wrp
->clk_wrap
)) {
1960 dev_dbg(wrp
->dev
, "failed to get clock: %ld\n",
1961 PTR_ERR(wrp
->clk_wrap
));
1962 return PTR_ERR(wrp
->clk_wrap
);
1965 ret
= clk_prepare_enable(wrp
->clk_spi
);
1969 ret
= clk_prepare_enable(wrp
->clk_wrap
);
1973 /* Enable internal dynamic clock */
1974 if (HAS_CAP(wrp
->master
->caps
, PWRAP_CAP_DCM
)) {
1975 pwrap_writel(wrp
, 1, PWRAP_DCM_EN
);
1976 pwrap_writel(wrp
, 0, PWRAP_DCM_DBC_PRD
);
1980 * The PMIC could already be initialized by the bootloader.
1981 * Skip initialization here in this case.
1983 if (!pwrap_readl(wrp
, PWRAP_INIT_DONE2
)) {
1984 ret
= pwrap_init(wrp
);
1986 dev_dbg(wrp
->dev
, "init failed with %d\n", ret
);
1991 if (!(pwrap_readl(wrp
, PWRAP_WACS2_RDATA
) & PWRAP_STATE_INIT_DONE0
)) {
1992 dev_dbg(wrp
->dev
, "initialization isn't finished\n");
1997 /* Initialize watchdog, may not be done by the bootloader */
1998 pwrap_writel(wrp
, 0xf, PWRAP_WDT_UNIT
);
2000 * Since STAUPD was not used on mt8173 platform,
2001 * so STAUPD of WDT_SRC which should be turned off
2003 pwrap_writel(wrp
, wrp
->master
->wdt_src
, PWRAP_WDT_SRC_EN
);
2004 if (HAS_CAP(wrp
->master
->caps
, PWRAP_CAP_WDT_SRC1
))
2005 pwrap_writel(wrp
, wrp
->master
->wdt_src
, PWRAP_WDT_SRC_EN_1
);
2007 pwrap_writel(wrp
, 0x1, PWRAP_TIMER_EN
);
2008 pwrap_writel(wrp
, wrp
->master
->int_en_all
, PWRAP_INT_EN
);
2010 * We add INT1 interrupt to handle starvation and request exception
2011 * If we support it, we should enable it here.
2013 if (HAS_CAP(wrp
->master
->caps
, PWRAP_CAP_INT1_EN
))
2014 pwrap_writel(wrp
, wrp
->master
->int1_en_all
, PWRAP_INT1_EN
);
2016 irq
= platform_get_irq(pdev
, 0);
2017 ret
= devm_request_irq(wrp
->dev
, irq
, pwrap_interrupt
,
2019 "mt-pmic-pwrap", wrp
);
2023 wrp
->regmap
= devm_regmap_init(wrp
->dev
, NULL
, wrp
, wrp
->slave
->regmap
);
2024 if (IS_ERR(wrp
->regmap
)) {
2025 ret
= PTR_ERR(wrp
->regmap
);
2029 ret
= of_platform_populate(np
, NULL
, NULL
, wrp
->dev
);
2031 dev_dbg(wrp
->dev
, "failed to create child devices at %pOF\n",
2039 clk_disable_unprepare(wrp
->clk_wrap
);
2041 clk_disable_unprepare(wrp
->clk_spi
);
2046 static struct platform_driver pwrap_drv
= {
2048 .name
= "mt-pmic-pwrap",
2049 .of_match_table
= of_match_ptr(of_pwrap_match_tbl
),
2051 .probe
= pwrap_probe
,
2054 module_platform_driver(pwrap_drv
);
2056 MODULE_AUTHOR("Flora Fu, MediaTek");
2057 MODULE_DESCRIPTION("MediaTek MT8135 PMIC Wrapper Driver");
2058 MODULE_LICENSE("GPL v2");