summaryrefslogtreecommitdiff
path: root/drivers/reset/reset-th1520.c
blob: fd32e991c4cbc79506a750169957efbe05974d53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
 * Author: Michal Wilczynski <m.wilczynski@samsung.com>
 */

#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/reset-controller.h>
#include <linux/regmap.h>

#include <dt-bindings/reset/thead,th1520-reset.h>

 /* register offset in RSTGEN_R */
#define TH1520_BROM_RST_CFG		0x0
#define TH1520_C910_RST_CFG		0x4
#define TH1520_CHIP_DBG_RST_CFG		0xc
#define TH1520_AXI4_CPUSYS2_RST_CFG	0x10
#define TH1520_X2H_CPUSYS_RST_CFG	0x18
#define TH1520_AHB2_CPUSYS_RST_CFG	0x1c
#define TH1520_APB3_CPUSYS_RST_CFG	0x20
#define TH1520_MBOX0_RST_CFG		0x24
#define TH1520_MBOX1_RST_CFG		0x28
#define TH1520_MBOX2_RST_CFG		0x2c
#define TH1520_MBOX3_RST_CFG		0x30
#define TH1520_WDT0_RST_CFG		0x34
#define TH1520_WDT1_RST_CFG		0x38
#define TH1520_TIMER0_RST_CFG		0x3c
#define TH1520_TIMER1_RST_CFG		0x40
#define TH1520_PERISYS_AHB_RST_CFG	0x44
#define TH1520_PERISYS_APB1_RST_CFG	0x48
#define TH1520_PERISYS_APB2_RST_CFG	0x4c
#define TH1520_GMAC0_RST_CFG		0x68
#define TH1520_UART0_RST_CFG		0x70
#define TH1520_UART1_RST_CFG		0x74
#define TH1520_UART2_RST_CFG		0x78
#define TH1520_UART3_RST_CFG		0x7c
#define TH1520_UART4_RST_CFG		0x80
#define TH1520_UART5_RST_CFG		0x84
#define TH1520_QSPI0_RST_CFG		0x8c
#define TH1520_QSPI1_RST_CFG		0x90
#define TH1520_SPI_RST_CFG		0x94
#define TH1520_I2C0_RST_CFG		0x98
#define TH1520_I2C1_RST_CFG		0x9c
#define TH1520_I2C2_RST_CFG		0xa0
#define TH1520_I2C3_RST_CFG		0xa4
#define TH1520_I2C4_RST_CFG		0xa8
#define TH1520_I2C5_RST_CFG		0xac
#define TH1520_GPIO0_RST_CFG		0xb0
#define TH1520_GPIO1_RST_CFG		0xb4
#define TH1520_GPIO2_RST_CFG		0xb8
#define TH1520_PWM_RST_CFG		0xc0
#define TH1520_PADCTRL0_APSYS_RST_CFG	0xc4
#define TH1520_CPU2PERI_X2H_RST_CFG	0xcc
#define TH1520_CPU2AON_X2H_RST_CFG	0xe4
#define TH1520_AON2CPU_A2X_RST_CFG	0xfc
#define TH1520_NPUSYS_AXI_RST_CFG	0x128
#define TH1520_CPU2VP_X2P_RST_CFG	0x12c
#define TH1520_CPU2VI_X2H_RST_CFG	0x138
#define TH1520_BMU_C910_RST_CFG		0x148
#define TH1520_DMAC_CPUSYS_RST_CFG	0x14c
#define TH1520_SPINLOCK_RST_CFG		0x178
#define TH1520_CFG2TEE_X2H_RST_CFG	0x188
#define TH1520_DSMART_RST_CFG		0x18c
#define TH1520_GPIO3_RST_CFG		0x1a8
#define TH1520_I2S_RST_CFG		0x1ac
#define TH1520_IMG_NNA_RST_CFG		0x1b0
#define TH1520_PERI_APB3_RST_CFG	0x1dc
#define TH1520_VP_SUBSYS_RST_CFG	0x1ec
#define TH1520_PERISYS_APB4_RST_CFG	0x1f8
#define TH1520_GMAC1_RST_CFG		0x204
#define TH1520_GMAC_AXI_RST_CFG		0x208
#define TH1520_PADCTRL1_APSYS_RST_CFG	0x20c
#define TH1520_VOSYS_AXI_RST_CFG	0x210
#define TH1520_VOSYS_X2X_RST_CFG	0x214
#define TH1520_MISC2VP_X2X_RST_CFG	0x218
#define TH1520_SUBSYS_RST_CFG		0x220

 /* register offset in DSP_REGMAP */
#define TH1520_DSPSYS_RST_CFG		0x0

 /* register offset in MISCSYS_REGMAP */
#define TH1520_EMMC_RST_CFG		0x0
#define TH1520_MISCSYS_AXI_RST_CFG	0x8
#define TH1520_SDIO0_RST_CFG		0xc
#define TH1520_SDIO1_RST_CFG		0x10
#define TH1520_USB3_DRD_RST_CFG		0x14

 /* register offset in VISYS_REGMAP */
#define TH1520_VISYS_RST_CFG		0x0
#define TH1520_VISYS_2_RST_CFG		0x4

 /* register offset in VOSYS_REGMAP */
#define TH1520_GPU_RST_CFG		0x0
#define TH1520_GPU_RST_CFG_MASK		GENMASK(1, 0)
#define TH1520_DPU_RST_CFG		0x4
#define TH1520_DSI0_RST_CFG		0x8
#define TH1520_DSI1_RST_CFG		0xc
#define TH1520_HDMI_RST_CFG		0x14
#define TH1520_AXI4_VO_DW_AXI_RST_CFG	0x18
#define TH1520_X2H_X4_VOSYS_DW_RST_CFG	0x20

/* register values */
#define TH1520_GPU_SW_GPU_RST		BIT(0)
#define TH1520_GPU_SW_CLKGEN_RST	BIT(1)
#define TH1520_DPU_SW_DPU_HRST		BIT(0)
#define TH1520_DPU_SW_DPU_ARST		BIT(1)
#define TH1520_DPU_SW_DPU_CRST		BIT(2)
#define TH1520_DSI_SW_DSI_PRST		BIT(0)
#define TH1520_HDMI_SW_MAIN_RST		BIT(0)
#define TH1520_HDMI_SW_PRST		BIT(1)

 /* register offset in VPSYS_REGMAP */
#define TH1520_AXIBUS_RST_CFG		0x0
#define TH1520_FCE_RST_CFG		0x4
#define TH1520_G2D_RST_CFG		0x8
#define TH1520_VDEC_RST_CFG		0xc
#define TH1520_VENC_RST_CFG		0x10

struct th1520_reset_map {
	u32 bit;
	u32 reg;
};

struct th1520_reset_priv {
	struct reset_controller_dev rcdev;
	struct regmap *map;
	const struct th1520_reset_map *resets;
};

struct th1520_reset_data {
	const struct th1520_reset_map *resets;
	size_t num;
};

static const struct th1520_reset_map th1520_resets[] = {
	[TH1520_RESET_ID_GPU] = {
		.bit = TH1520_GPU_SW_GPU_RST,
		.reg = TH1520_GPU_RST_CFG,
	},
	[TH1520_RESET_ID_GPU_CLKGEN] = {
		.bit = TH1520_GPU_SW_CLKGEN_RST,
		.reg = TH1520_GPU_RST_CFG,
	},
	[TH1520_RESET_ID_DPU_AHB] = {
		.bit = TH1520_DPU_SW_DPU_HRST,
		.reg = TH1520_DPU_RST_CFG,
	},
	[TH1520_RESET_ID_DPU_AXI] = {
		.bit = TH1520_DPU_SW_DPU_ARST,
		.reg = TH1520_DPU_RST_CFG,
	},
	[TH1520_RESET_ID_DPU_CORE] = {
		.bit = TH1520_DPU_SW_DPU_CRST,
		.reg = TH1520_DPU_RST_CFG,
	},
	[TH1520_RESET_ID_DSI0_APB] = {
		.bit = TH1520_DSI_SW_DSI_PRST,
		.reg = TH1520_DSI0_RST_CFG,
	},
	[TH1520_RESET_ID_DSI1_APB] = {
		.bit = TH1520_DSI_SW_DSI_PRST,
		.reg = TH1520_DSI1_RST_CFG,
	},
	[TH1520_RESET_ID_HDMI] = {
		.bit = TH1520_HDMI_SW_MAIN_RST,
		.reg = TH1520_HDMI_RST_CFG,
	},
	[TH1520_RESET_ID_HDMI_APB] = {
		.bit = TH1520_HDMI_SW_PRST,
		.reg = TH1520_HDMI_RST_CFG,
	},
	[TH1520_RESET_ID_VOAXI] = {
		.bit = BIT(0),
		.reg = TH1520_AXI4_VO_DW_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_VOAXI_APB] = {
		.bit = BIT(1),
		.reg = TH1520_AXI4_VO_DW_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_X2H_DPU_AXI] = {
		.bit = BIT(0),
		.reg = TH1520_X2H_X4_VOSYS_DW_RST_CFG,
	},
	[TH1520_RESET_ID_X2H_DPU_AHB] = {
		.bit = BIT(1),
		.reg = TH1520_X2H_X4_VOSYS_DW_RST_CFG,
	},
	[TH1520_RESET_ID_X2H_DPU1_AXI] = {
		.bit = BIT(2),
		.reg = TH1520_X2H_X4_VOSYS_DW_RST_CFG,
	},
	[TH1520_RESET_ID_X2H_DPU1_AHB] = {
		.bit = BIT(3),
		.reg = TH1520_X2H_X4_VOSYS_DW_RST_CFG,
	},
};

static const struct th1520_reset_map th1520_ap_resets[] = {
	[TH1520_RESET_ID_BROM] = {
		.bit = BIT(0),
		.reg = TH1520_BROM_RST_CFG,
	},
	[TH1520_RESET_ID_C910_TOP] = {
		.bit = BIT(0),
		.reg = TH1520_C910_RST_CFG,
	},
	[TH1520_RESET_ID_NPU] =  {
		.bit = BIT(0),
		.reg = TH1520_IMG_NNA_RST_CFG,
	},
	[TH1520_RESET_ID_WDT0] = {
		.bit = BIT(0),
		.reg = TH1520_WDT0_RST_CFG,
	},
	[TH1520_RESET_ID_WDT1] = {
		.bit = BIT(0),
		.reg = TH1520_WDT1_RST_CFG,
	},
	[TH1520_RESET_ID_C910_C0] = {
		.bit = BIT(1),
		.reg = TH1520_C910_RST_CFG,
	},
	[TH1520_RESET_ID_C910_C1] = {
		.bit = BIT(2),
		.reg = TH1520_C910_RST_CFG,
	},
	[TH1520_RESET_ID_C910_C2] = {
		.bit = BIT(3),
		.reg = TH1520_C910_RST_CFG,
	},
	[TH1520_RESET_ID_C910_C3] = {
		.bit = BIT(4),
		.reg = TH1520_C910_RST_CFG,
	},
	[TH1520_RESET_ID_CHIP_DBG_CORE] = {
		.bit = BIT(0),
		.reg = TH1520_CHIP_DBG_RST_CFG,
	},
	[TH1520_RESET_ID_CHIP_DBG_AXI] = {
		.bit = BIT(1),
		.reg = TH1520_CHIP_DBG_RST_CFG,
	},
	[TH1520_RESET_ID_AXI4_CPUSYS2_AXI] = {
		.bit = BIT(0),
		.reg = TH1520_AXI4_CPUSYS2_RST_CFG,
	},
	[TH1520_RESET_ID_AXI4_CPUSYS2_APB] = {
		.bit = BIT(1),
		.reg = TH1520_AXI4_CPUSYS2_RST_CFG,
	},
	[TH1520_RESET_ID_X2H_CPUSYS] = {
		.bit = BIT(0),
		.reg = TH1520_X2H_CPUSYS_RST_CFG,
	},
	[TH1520_RESET_ID_AHB2_CPUSYS] = {
		.bit = BIT(0),
		.reg = TH1520_AHB2_CPUSYS_RST_CFG,
	},
	[TH1520_RESET_ID_APB3_CPUSYS] = {
		.bit = BIT(0),
		.reg = TH1520_APB3_CPUSYS_RST_CFG,
	},
	[TH1520_RESET_ID_MBOX0_APB] = {
		.bit = BIT(0),
		.reg = TH1520_MBOX0_RST_CFG,
	},
	[TH1520_RESET_ID_MBOX1_APB] = {
		.bit = BIT(0),
		.reg = TH1520_MBOX1_RST_CFG,
	},
	[TH1520_RESET_ID_MBOX2_APB] = {
		.bit = BIT(0),
		.reg = TH1520_MBOX2_RST_CFG,
	},
	[TH1520_RESET_ID_MBOX3_APB] = {
		.bit = BIT(0),
		.reg = TH1520_MBOX3_RST_CFG,
	},
	[TH1520_RESET_ID_TIMER0_APB] = {
		.bit = BIT(0),
		.reg = TH1520_TIMER0_RST_CFG,
	},
	[TH1520_RESET_ID_TIMER0_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_TIMER0_RST_CFG,
	},
	[TH1520_RESET_ID_TIMER1_APB] = {
		.bit = BIT(0),
		.reg = TH1520_TIMER1_RST_CFG,
	},
	[TH1520_RESET_ID_TIMER1_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_TIMER1_RST_CFG,
	},
	[TH1520_RESET_ID_PERISYS_AHB] = {
		.bit = BIT(0),
		.reg = TH1520_PERISYS_AHB_RST_CFG,
	},
	[TH1520_RESET_ID_PERISYS_APB1] = {
		.bit = BIT(0),
		.reg = TH1520_PERISYS_APB1_RST_CFG,
	},
	[TH1520_RESET_ID_PERISYS_APB2] = {
		.bit = BIT(0),
		.reg = TH1520_PERISYS_APB2_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC0_APB] = {
		.bit = BIT(0),
		.reg = TH1520_GMAC0_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC0_AHB] = {
		.bit = BIT(1),
		.reg = TH1520_GMAC0_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC0_CLKGEN] = {
		.bit = BIT(2),
		.reg = TH1520_GMAC0_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC0_AXI] = {
		.bit = BIT(3),
		.reg = TH1520_GMAC0_RST_CFG,
	},
	[TH1520_RESET_ID_UART0_APB] = {
		.bit = BIT(0),
		.reg = TH1520_UART0_RST_CFG,
	},
	[TH1520_RESET_ID_UART0_IF] = {
		.bit = BIT(1),
		.reg = TH1520_UART0_RST_CFG,
	},
	[TH1520_RESET_ID_UART1_APB] = {
		.bit = BIT(0),
		.reg = TH1520_UART1_RST_CFG,
	},
	[TH1520_RESET_ID_UART1_IF] = {
		.bit = BIT(1),
		.reg = TH1520_UART1_RST_CFG,
	},
	[TH1520_RESET_ID_UART2_APB] = {
		.bit = BIT(0),
		.reg = TH1520_UART2_RST_CFG,
	},
	[TH1520_RESET_ID_UART2_IF] = {
		.bit = BIT(1),
		.reg = TH1520_UART2_RST_CFG,
	},
	[TH1520_RESET_ID_UART3_APB] = {
		.bit = BIT(0),
		.reg = TH1520_UART3_RST_CFG,
	},
	[TH1520_RESET_ID_UART3_IF] = {
		.bit = BIT(1),
		.reg = TH1520_UART3_RST_CFG,
	},
	[TH1520_RESET_ID_UART4_APB] = {
		.bit = BIT(0),
		.reg = TH1520_UART4_RST_CFG,
	},
	[TH1520_RESET_ID_UART4_IF] = {
		.bit = BIT(1),
		.reg = TH1520_UART4_RST_CFG,
	},
	[TH1520_RESET_ID_UART5_APB] = {
		.bit = BIT(0),
		.reg = TH1520_UART5_RST_CFG,
	},
	[TH1520_RESET_ID_UART5_IF] = {
		.bit = BIT(1),
		.reg = TH1520_UART5_RST_CFG,
	},
	[TH1520_RESET_ID_QSPI0_IF] = {
		.bit = BIT(0),
		.reg = TH1520_QSPI0_RST_CFG,
	},
	[TH1520_RESET_ID_QSPI0_APB] = {
		.bit = BIT(1),
		.reg = TH1520_QSPI0_RST_CFG,
	},
	[TH1520_RESET_ID_QSPI1_IF] = {
		.bit = BIT(0),
		.reg = TH1520_QSPI1_RST_CFG,
	},
	[TH1520_RESET_ID_QSPI1_APB] = {
		.bit = BIT(1),
		.reg = TH1520_QSPI1_RST_CFG,
	},
	[TH1520_RESET_ID_SPI_IF] = {
		.bit = BIT(0),
		.reg = TH1520_SPI_RST_CFG,
	},
	[TH1520_RESET_ID_SPI_APB] = {
		.bit = BIT(1),
		.reg = TH1520_SPI_RST_CFG,
	},
	[TH1520_RESET_ID_I2C0_APB] = {
		.bit = BIT(0),
		.reg = TH1520_I2C0_RST_CFG,
	},
	[TH1520_RESET_ID_I2C0_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_I2C0_RST_CFG,
	},
	[TH1520_RESET_ID_I2C1_APB] = {
		.bit = BIT(0),
		.reg = TH1520_I2C1_RST_CFG,
	},
	[TH1520_RESET_ID_I2C1_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_I2C1_RST_CFG,
	},
	[TH1520_RESET_ID_I2C2_APB] = {
		.bit = BIT(0),
		.reg = TH1520_I2C2_RST_CFG,
	},
	[TH1520_RESET_ID_I2C2_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_I2C2_RST_CFG,
	},
	[TH1520_RESET_ID_I2C3_APB] = {
		.bit = BIT(0),
		.reg = TH1520_I2C3_RST_CFG,
	},
	[TH1520_RESET_ID_I2C3_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_I2C3_RST_CFG,
	},
	[TH1520_RESET_ID_I2C4_APB] = {
		.bit = BIT(0),
		.reg = TH1520_I2C4_RST_CFG,
	},
	[TH1520_RESET_ID_I2C4_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_I2C4_RST_CFG,
	},
	[TH1520_RESET_ID_I2C5_APB] = {
		.bit = BIT(0),
		.reg = TH1520_I2C5_RST_CFG,
	},
	[TH1520_RESET_ID_I2C5_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_I2C5_RST_CFG,
	},
	[TH1520_RESET_ID_GPIO0_DB] = {
		.bit = BIT(0),
		.reg = TH1520_GPIO0_RST_CFG,
	},
	[TH1520_RESET_ID_GPIO0_APB] = {
		.bit = BIT(1),
		.reg = TH1520_GPIO0_RST_CFG,
	},
	[TH1520_RESET_ID_GPIO1_DB] = {
		.bit = BIT(0),
		.reg = TH1520_GPIO1_RST_CFG,
	},
	[TH1520_RESET_ID_GPIO1_APB] = {
		.bit = BIT(1),
		.reg = TH1520_GPIO1_RST_CFG,
	},
	[TH1520_RESET_ID_GPIO2_DB] = {
		.bit = BIT(0),
		.reg = TH1520_GPIO2_RST_CFG,
	},
	[TH1520_RESET_ID_GPIO2_APB] = {
		.bit = BIT(1),
		.reg = TH1520_GPIO2_RST_CFG,
	},
	[TH1520_RESET_ID_PWM_COUNTER] = {
		.bit = BIT(0),
		.reg = TH1520_PWM_RST_CFG,
	},
	[TH1520_RESET_ID_PWM_APB] = {
		.bit = BIT(1),
		.reg = TH1520_PWM_RST_CFG,
	},
	[TH1520_RESET_ID_PADCTRL0_APB] = {
		.bit = BIT(0),
		.reg = TH1520_PADCTRL0_APSYS_RST_CFG,
	},
	[TH1520_RESET_ID_CPU2PERI_X2H] = {
		.bit = BIT(1),
		.reg = TH1520_CPU2PERI_X2H_RST_CFG,
	},
	[TH1520_RESET_ID_CPU2AON_X2H] = {
		.bit = BIT(0),
		.reg = TH1520_CPU2AON_X2H_RST_CFG,
	},
	[TH1520_RESET_ID_AON2CPU_A2X] = {
		.bit = BIT(0),
		.reg = TH1520_AON2CPU_A2X_RST_CFG,
	},
	[TH1520_RESET_ID_NPUSYS_AXI] = {
		.bit = BIT(0),
		.reg = TH1520_NPUSYS_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_NPUSYS_AXI_APB] = {
		.bit = BIT(1),
		.reg = TH1520_NPUSYS_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_CPU2VP_X2P] = {
		.bit = BIT(0),
		.reg = TH1520_CPU2VP_X2P_RST_CFG,
	},
	[TH1520_RESET_ID_CPU2VI_X2H] = {
		.bit = BIT(0),
		.reg = TH1520_CPU2VI_X2H_RST_CFG,
	},
	[TH1520_RESET_ID_BMU_AXI] = {
		.bit = BIT(0),
		.reg = TH1520_BMU_C910_RST_CFG,
	},
	[TH1520_RESET_ID_BMU_APB] = {
		.bit = BIT(1),
		.reg = TH1520_BMU_C910_RST_CFG,
	},
	[TH1520_RESET_ID_DMAC_CPUSYS_AXI] = {
		.bit = BIT(0),
		.reg = TH1520_DMAC_CPUSYS_RST_CFG,
	},
	[TH1520_RESET_ID_DMAC_CPUSYS_AHB] = {
		.bit = BIT(1),
		.reg = TH1520_DMAC_CPUSYS_RST_CFG,
	},
	[TH1520_RESET_ID_SPINLOCK] = {
		.bit = BIT(0),
		.reg = TH1520_SPINLOCK_RST_CFG,
	},
	[TH1520_RESET_ID_CFG2TEE] = {
		.bit = BIT(0),
		.reg = TH1520_CFG2TEE_X2H_RST_CFG,
	},
	[TH1520_RESET_ID_DSMART] = {
		.bit = BIT(0),
		.reg = TH1520_DSMART_RST_CFG,
	},
	[TH1520_RESET_ID_GPIO3_DB] = {
		.bit = BIT(0),
		.reg = TH1520_GPIO3_RST_CFG,
	},
	[TH1520_RESET_ID_GPIO3_APB] = {
		.bit = BIT(1),
		.reg = TH1520_GPIO3_RST_CFG,
	},
	[TH1520_RESET_ID_PERI_I2S] = {
		.bit = BIT(0),
		.reg = TH1520_I2S_RST_CFG,
	},
	[TH1520_RESET_ID_PERI_APB3] = {
		.bit = BIT(0),
		.reg = TH1520_PERI_APB3_RST_CFG,
	},
	[TH1520_RESET_ID_PERI2PERI1_APB] = {
		.bit = BIT(1),
		.reg = TH1520_PERI_APB3_RST_CFG,
	},
	[TH1520_RESET_ID_VPSYS_APB] = {
		.bit = BIT(0),
		.reg = TH1520_VP_SUBSYS_RST_CFG,
	},
	[TH1520_RESET_ID_PERISYS_APB4] = {
		.bit = BIT(0),
		.reg = TH1520_PERISYS_APB4_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC1_APB] = {
		.bit = BIT(0),
		.reg = TH1520_GMAC1_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC1_AHB] = {
		.bit = BIT(1),
		.reg = TH1520_GMAC1_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC1_CLKGEN] = {
		.bit = BIT(2),
		.reg = TH1520_GMAC1_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC1_AXI] = {
		.bit = BIT(3),
		.reg = TH1520_GMAC1_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC_AXI] = {
		.bit = BIT(0),
		.reg = TH1520_GMAC_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_GMAC_AXI_APB] = {
		.bit = BIT(1),
		.reg = TH1520_GMAC_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_PADCTRL1_APB] = {
		.bit = BIT(0),
		.reg = TH1520_PADCTRL1_APSYS_RST_CFG,
	},
	[TH1520_RESET_ID_VOSYS_AXI] = {
		.bit = BIT(0),
		.reg = TH1520_VOSYS_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_VOSYS_AXI_APB] = {
		.bit = BIT(1),
		.reg = TH1520_VOSYS_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_VOSYS_AXI_X2X] = {
		.bit = BIT(0),
		.reg = TH1520_VOSYS_X2X_RST_CFG,
	},
	[TH1520_RESET_ID_MISC2VP_X2X] = {
		.bit = BIT(0),
		.reg = TH1520_MISC2VP_X2X_RST_CFG,
	},
	[TH1520_RESET_ID_DSPSYS] = {
		.bit = BIT(0),
		.reg = TH1520_SUBSYS_RST_CFG,
	},
	[TH1520_RESET_ID_VISYS] = {
		.bit = BIT(1),
		.reg = TH1520_SUBSYS_RST_CFG,
	},
	[TH1520_RESET_ID_VOSYS] = {
		.bit = BIT(2),
		.reg = TH1520_SUBSYS_RST_CFG,
	},
	[TH1520_RESET_ID_VPSYS] = {
		.bit = BIT(3),
		.reg = TH1520_SUBSYS_RST_CFG,
	},
};

static const struct th1520_reset_map th1520_dsp_resets[] = {
	[TH1520_RESET_ID_X2X_DSP1] = {
		.bit = BIT(0),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_X2X_DSP0] = {
		.bit = BIT(1),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_X2X_SLAVE_DSP1] = {
		.bit = BIT(2),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_X2X_SLAVE_DSP0] = {
		.bit = BIT(3),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_DSP0_CORE] = {
		.bit = BIT(8),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_DSP0_DEBUG] = {
		.bit = BIT(9),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_DSP0_APB] = {
		.bit = BIT(10),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_DSP1_CORE] = {
		.bit = BIT(12),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_DSP1_DEBUG] = {
		.bit = BIT(13),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_DSP1_APB] = {
		.bit = BIT(14),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_DSPSYS_APB] = {
		.bit = BIT(16),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_AXI4_DSPSYS_SLV] = {
		.bit = BIT(20),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_AXI4_DSPSYS] = {
		.bit = BIT(24),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
	[TH1520_RESET_ID_AXI4_DSP_RS] = {
		.bit = BIT(26),
		.reg = TH1520_DSPSYS_RST_CFG,
	},
};

static const struct th1520_reset_map th1520_misc_resets[] = {
	[TH1520_RESET_ID_EMMC_SDIO_CLKGEN] = {
		.bit = BIT(0),
		.reg = TH1520_EMMC_RST_CFG,
	},
	[TH1520_RESET_ID_EMMC] = {
		.bit = BIT(1),
		.reg = TH1520_EMMC_RST_CFG,
	},
	[TH1520_RESET_ID_MISCSYS_AXI] = {
		.bit = BIT(0),
		.reg = TH1520_MISCSYS_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_MISCSYS_AXI_APB] = {
		.bit = BIT(1),
		.reg = TH1520_MISCSYS_AXI_RST_CFG,
	},
	[TH1520_RESET_ID_SDIO0] = {
		.bit = BIT(0),
		.reg = TH1520_SDIO0_RST_CFG,
	},
	[TH1520_RESET_ID_SDIO1] = {
		.bit = BIT(1),
		.reg = TH1520_SDIO1_RST_CFG,
	},
	[TH1520_RESET_ID_USB3_APB] = {
		.bit = BIT(0),
		.reg = TH1520_USB3_DRD_RST_CFG,
	},
	[TH1520_RESET_ID_USB3_PHY] = {
		.bit = BIT(1),
		.reg = TH1520_USB3_DRD_RST_CFG,
	},
	[TH1520_RESET_ID_USB3_VCC] = {
		.bit = BIT(2),
		.reg = TH1520_USB3_DRD_RST_CFG,
	},
};

static const struct th1520_reset_map th1520_vi_resets[] = {
	[TH1520_RESET_ID_ISP0] = {
		.bit = BIT(0),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_ISP1] = {
		.bit = BIT(4),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_CSI0_APB] = {
		.bit = BIT(16),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_CSI1_APB] = {
		.bit = BIT(17),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_CSI2_APB] = {
		.bit = BIT(18),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_MIPI_FIFO] = {
		.bit = BIT(20),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_ISP_VENC_APB] = {
		.bit = BIT(24),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_VIPRE_APB] = {
		.bit = BIT(28),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_VIPRE_AXI] = {
		.bit = BIT(29),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_DW200_APB] = {
		.bit = BIT(31),
		.reg = TH1520_VISYS_RST_CFG,
	},
	[TH1520_RESET_ID_VISYS3_AXI] = {
		.bit = BIT(8),
		.reg = TH1520_VISYS_2_RST_CFG,
	},
	[TH1520_RESET_ID_VISYS2_AXI] = {
		.bit = BIT(9),
		.reg = TH1520_VISYS_2_RST_CFG,
	},
	[TH1520_RESET_ID_VISYS1_AXI] = {
		.bit = BIT(10),
		.reg = TH1520_VISYS_2_RST_CFG,
	},
	[TH1520_RESET_ID_VISYS_AXI] = {
		.bit = BIT(12),
		.reg = TH1520_VISYS_2_RST_CFG,
	},
	[TH1520_RESET_ID_VISYS_APB] = {
		.bit = BIT(16),
		.reg = TH1520_VISYS_2_RST_CFG,
	},
	[TH1520_RESET_ID_ISP_VENC_AXI] = {
		.bit = BIT(20),
		.reg = TH1520_VISYS_2_RST_CFG,
	},
};

static const struct th1520_reset_map th1520_vp_resets[] = {
	[TH1520_RESET_ID_VPSYS_AXI_APB] = {
		.bit = BIT(0),
		.reg = TH1520_AXIBUS_RST_CFG,
	},
	[TH1520_RESET_ID_VPSYS_AXI] = {
		.bit = BIT(1),
		.reg = TH1520_AXIBUS_RST_CFG,
	},
	[TH1520_RESET_ID_FCE_APB] = {
		.bit = BIT(0),
		.reg = TH1520_FCE_RST_CFG,
	},
	[TH1520_RESET_ID_FCE_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_FCE_RST_CFG,
	},
	[TH1520_RESET_ID_FCE_X2X_MASTER] = {
		.bit = BIT(4),
		.reg = TH1520_FCE_RST_CFG,
	},
	[TH1520_RESET_ID_FCE_X2X_SLAVE] = {
		.bit = BIT(5),
		.reg = TH1520_FCE_RST_CFG,
	},
	[TH1520_RESET_ID_G2D_APB] = {
		.bit = BIT(0),
		.reg = TH1520_G2D_RST_CFG,
	},
	[TH1520_RESET_ID_G2D_ACLK] = {
		.bit = BIT(1),
		.reg = TH1520_G2D_RST_CFG,
	},
	[TH1520_RESET_ID_G2D_CORE] = {
		.bit = BIT(2),
		.reg = TH1520_G2D_RST_CFG,
	},
	[TH1520_RESET_ID_VDEC_APB] = {
		.bit = BIT(0),
		.reg = TH1520_VDEC_RST_CFG,
	},
	[TH1520_RESET_ID_VDEC_ACLK] = {
		.bit = BIT(1),
		.reg = TH1520_VDEC_RST_CFG,
	},
	[TH1520_RESET_ID_VDEC_CORE] = {
		.bit = BIT(2),
		.reg = TH1520_VDEC_RST_CFG,
	},
	[TH1520_RESET_ID_VENC_APB] = {
		.bit = BIT(0),
		.reg = TH1520_VENC_RST_CFG,
	},
	[TH1520_RESET_ID_VENC_CORE] = {
		.bit = BIT(1),
		.reg = TH1520_VENC_RST_CFG,
	},
};

static inline struct th1520_reset_priv *
to_th1520_reset(struct reset_controller_dev *rcdev)
{
	return container_of(rcdev, struct th1520_reset_priv, rcdev);
}

static int th1520_reset_assert(struct reset_controller_dev *rcdev,
			       unsigned long id)
{
	struct th1520_reset_priv *priv = to_th1520_reset(rcdev);
	const struct th1520_reset_map *reset;

	reset = &priv->resets[id];

	return regmap_update_bits(priv->map, reset->reg, reset->bit, 0);
}

static int th1520_reset_deassert(struct reset_controller_dev *rcdev,
				 unsigned long id)
{
	struct th1520_reset_priv *priv = to_th1520_reset(rcdev);
	const struct th1520_reset_map *reset;

	reset = &priv->resets[id];

	return regmap_update_bits(priv->map, reset->reg, reset->bit,
				  reset->bit);
}

static const struct reset_control_ops th1520_reset_ops = {
	.assert	= th1520_reset_assert,
	.deassert = th1520_reset_deassert,
};

static const struct regmap_config th1520_reset_regmap_config = {
	.reg_bits = 32,
	.val_bits = 32,
	.reg_stride = 4,
};

static int th1520_reset_probe(struct platform_device *pdev)
{
	const struct th1520_reset_data *data;
	struct device *dev = &pdev->dev;
	struct th1520_reset_priv *priv;
	void __iomem *base;
	int ret;

	data = device_get_match_data(dev);

	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	base = devm_platform_ioremap_resource(pdev, 0);
	if (IS_ERR(base))
		return PTR_ERR(base);

	priv->map = devm_regmap_init_mmio(dev, base,
					  &th1520_reset_regmap_config);
	if (IS_ERR(priv->map))
		return PTR_ERR(priv->map);

	if (of_device_is_compatible(dev->of_node, "thead,th1520-reset")) {
		/* Initialize GPU resets to asserted state */
		ret = regmap_update_bits(priv->map, TH1520_GPU_RST_CFG,
					 TH1520_GPU_RST_CFG_MASK, 0);
		if (ret)
			return ret;
	}

	priv->rcdev.owner = THIS_MODULE;
	priv->rcdev.nr_resets = data->num;
	priv->rcdev.ops = &th1520_reset_ops;
	priv->rcdev.of_node = dev->of_node;

	priv->resets = data->resets;

	return devm_reset_controller_register(dev, &priv->rcdev);
}

static const struct th1520_reset_data th1520_reset_data = {
	.resets = th1520_resets,
	.num = ARRAY_SIZE(th1520_resets),
};

static const struct th1520_reset_data th1520_ap_reset_data = {
	.resets = th1520_ap_resets,
	.num = ARRAY_SIZE(th1520_ap_resets),
};

static const struct th1520_reset_data th1520_dsp_reset_data = {
	.resets = th1520_dsp_resets,
	.num = ARRAY_SIZE(th1520_dsp_resets),
};

static const struct th1520_reset_data th1520_misc_reset_data = {
	.resets = th1520_misc_resets,
	.num = ARRAY_SIZE(th1520_misc_resets),
};

static const struct th1520_reset_data th1520_vi_reset_data = {
	.resets = th1520_vi_resets,
	.num = ARRAY_SIZE(th1520_vi_resets),
};

static const struct th1520_reset_data th1520_vp_reset_data = {
	.resets = th1520_vp_resets,
	.num = ARRAY_SIZE(th1520_vp_resets),
};

static const struct of_device_id th1520_reset_match[] = {
	{ .compatible = "thead,th1520-reset", .data = &th1520_reset_data },
	{ .compatible = "thead,th1520-reset-ap", .data = &th1520_ap_reset_data },
	{ .compatible = "thead,th1520-reset-dsp", .data = &th1520_dsp_reset_data },
	{ .compatible = "thead,th1520-reset-misc", .data = &th1520_misc_reset_data },
	{ .compatible = "thead,th1520-reset-vi", .data = &th1520_vi_reset_data },
	{ .compatible = "thead,th1520-reset-vp", .data = &th1520_vp_reset_data },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, th1520_reset_match);

static struct platform_driver th1520_reset_driver = {
	.driver = {
		.name = "th1520-reset",
		.of_match_table = th1520_reset_match,
	},
	.probe = th1520_reset_probe,
};
module_platform_driver(th1520_reset_driver);

MODULE_AUTHOR("Michal Wilczynski <m.wilczynski@samsung.com>");
MODULE_DESCRIPTION("T-HEAD TH1520 SoC reset controller");
MODULE_LICENSE("GPL");