1 /*
2  * Copyright (c) 2020-2021, Renesas Electronics Corporation. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 #include <stdint.h>
7 
8 #include <common/debug.h>
9 #include <lib/mmio.h>
10 
11 #if RCAR_LSI == RCAR_AUTO
12 #include "G2E/pfc_init_g2e.h"
13 #include "G2H/pfc_init_g2h.h"
14 #include "G2M/pfc_init_g2m.h"
15 #include "G2N/pfc_init_g2n.h"
16 #endif /* RCAR_LSI == RCAR_AUTO */
17 #if (RCAR_LSI == RZ_G2E)
18 #include "G2E/pfc_init_g2e.h"
19 #endif /* RCAR_LSI == RZ_G2N */
20 #if (RCAR_LSI == RZ_G2H)
21 #include "G2H/pfc_init_g2h.h"
22 #endif /* RCAR_LSI == RZ_G2H */
23 #if (RCAR_LSI == RZ_G2M)
24 #include "G2M/pfc_init_g2m.h"
25 #endif /* RCAR_LSI == RZ_G2M */
26 #if (RCAR_LSI == RZ_G2N)
27 #include "G2N/pfc_init_g2n.h"
28 #endif /* RCAR_LSI == RZ_G2N */
29 #include "rcar_def.h"
30 
31 #define PRR_PRODUCT_ERR(reg)				\
32 	do {						\
33 		ERROR("LSI Product ID(PRR=0x%x) PFC init not supported.\n", \
34 			reg);				\
35 		panic();				\
36 	} while (0)
37 
38 #define PRR_CUT_ERR(reg)				\
39 	do {						\
40 		ERROR("LSI Cut ID(PRR=0x%x) PFC init not supported.\n", \
41 			reg);				\
42 		panic();\
43 	} while (0)
44 
rzg_pfc_init(void)45 void rzg_pfc_init(void)
46 {
47 	uint32_t reg;
48 
49 	reg = mmio_read_32(RCAR_PRR);
50 #if RCAR_LSI == RCAR_AUTO
51 	switch (reg & PRR_PRODUCT_MASK) {
52 	case PRR_PRODUCT_M3:
53 		pfc_init_g2m();
54 		break;
55 	case PRR_PRODUCT_H3:
56 		pfc_init_g2h();
57 		break;
58 	case PRR_PRODUCT_M3N:
59 		pfc_init_g2n();
60 		break;
61 	case PRR_PRODUCT_E3:
62 		pfc_init_g2e();
63 		break;
64 	default:
65 		PRR_PRODUCT_ERR(reg);
66 		break;
67 	}
68 
69 #elif RCAR_LSI_CUT_COMPAT /* RCAR_LSI == RCAR_AUTO */
70 	switch (reg & PRR_PRODUCT_MASK) {
71 	case PRR_PRODUCT_M3:
72 #if RCAR_LSI != RZ_G2M
73 		PRR_PRODUCT_ERR(reg);
74 #else /* RCAR_LSI != RZ_G2M */
75 		pfc_init_g2m();
76 #endif /* RCAR_LSI != RZ_G2M */
77 		break;
78 	case PRR_PRODUCT_H3:
79 #if (RCAR_LSI != RZ_G2H)
80 		PRR_PRODUCT_ERR(reg);
81 #else /* RCAR_LSI != RZ_G2H */
82 		pfc_init_g2h();
83 #endif /* RCAR_LSI != RZ_G2H */
84 		break;
85 	case PRR_PRODUCT_M3N:
86 #if RCAR_LSI != RZ_G2N
87 		PRR_PRODUCT_ERR(reg);
88 #else
89 		pfc_init_g2n();
90 #endif /* RCAR_LSI != RZ_G2N */
91 		break;
92 	case PRR_PRODUCT_E3:
93 #if RCAR_LSI != RZ_G2E
94 		PRR_PRODUCT_ERR(reg);
95 #else
96 		pfc_init_g2e();
97 #endif
98 		break;
99 	default:
100 		PRR_PRODUCT_ERR(reg);
101 		break;
102 	}
103 
104 #else /* RCAR_LSI == RCAR_AUTO */
105 #if (RCAR_LSI == RZ_G2M)
106 	if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_M3) {
107 		PRR_PRODUCT_ERR(reg);
108 	}
109 	pfc_init_m3();
110 #elif (RCAR_LSI == RZ_G2H)
111 	if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_H3) {
112 		PRR_PRODUCT_ERR(reg);
113 	}
114 	pfc_init_g2h();
115 #elif (RCAR_LSI == RZ_G2N)	/* G2N */
116 	if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_M3N) {
117 		PRR_PRODUCT_ERR(reg);
118 	}
119 	pfc_init_g2n();
120 #elif (RCAR_LSI == RZ_G2E)
121 	if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_E3) {
122 		PRR_PRODUCT_ERR(reg);
123 	}
124 	pfc_init_g2e();
125 #else /* RCAR_LSI == RZ_G2M */
126 #error "Don't have PFC initialize routine(unknown)."
127 #endif /* RCAR_LSI == RZ_G2M */
128 #endif /* RCAR_LSI == RCAR_AUTO */
129 }
130