xref: /rk3399_ARM-atf/drivers/renesas/rzg/pfc/pfc_init.c (revision 618522eb22a8cc06124576360ce2618eca750f3a)
1*618522ebSBiju Das /*
2*618522ebSBiju Das  * Copyright (c) 2020, Renesas Electronics Corporation. All rights reserved.
3*618522ebSBiju Das  *
4*618522ebSBiju Das  * SPDX-License-Identifier: BSD-3-Clause
5*618522ebSBiju Das  */
6*618522ebSBiju Das #include <stdint.h>
7*618522ebSBiju Das 
8*618522ebSBiju Das #include <common/debug.h>
9*618522ebSBiju Das #include <lib/mmio.h>
10*618522ebSBiju Das 
11*618522ebSBiju Das #if RCAR_LSI == RCAR_AUTO
12*618522ebSBiju Das #include "G2M/pfc_init_g2m.h"
13*618522ebSBiju Das #endif /* RCAR_LSI == RCAR_AUTO */
14*618522ebSBiju Das #if (RCAR_LSI == RZ_G2M)
15*618522ebSBiju Das #include "G2M/pfc_init_g2m.h"
16*618522ebSBiju Das #endif /* RCAR_LSI == RZ_G2M */
17*618522ebSBiju Das #include "rcar_def.h"
18*618522ebSBiju Das 
19*618522ebSBiju Das #define PRR_PRODUCT_ERR(reg)				\
20*618522ebSBiju Das 	do {						\
21*618522ebSBiju Das 		ERROR("LSI Product ID(PRR=0x%x) PFC init not supported.\n", \
22*618522ebSBiju Das 			reg);				\
23*618522ebSBiju Das 		panic();				\
24*618522ebSBiju Das 	} while (0)
25*618522ebSBiju Das 
26*618522ebSBiju Das #define PRR_CUT_ERR(reg)				\
27*618522ebSBiju Das 	do {						\
28*618522ebSBiju Das 		ERROR("LSI Cut ID(PRR=0x%x) PFC init not supported.\n", \
29*618522ebSBiju Das 			reg);				\
30*618522ebSBiju Das 		panic();\
31*618522ebSBiju Das 	} while (0)
32*618522ebSBiju Das 
33*618522ebSBiju Das void rzg_pfc_init(void)
34*618522ebSBiju Das {
35*618522ebSBiju Das 	uint32_t reg;
36*618522ebSBiju Das 
37*618522ebSBiju Das 	reg = mmio_read_32(RCAR_PRR);
38*618522ebSBiju Das #if RCAR_LSI == RCAR_AUTO
39*618522ebSBiju Das 	switch (reg & PRR_PRODUCT_MASK) {
40*618522ebSBiju Das 	case PRR_PRODUCT_M3:
41*618522ebSBiju Das 		pfc_init_g2m();
42*618522ebSBiju Das 		break;
43*618522ebSBiju Das 	default:
44*618522ebSBiju Das 		PRR_PRODUCT_ERR(reg);
45*618522ebSBiju Das 		break;
46*618522ebSBiju Das 	}
47*618522ebSBiju Das 
48*618522ebSBiju Das #elif RCAR_LSI_CUT_COMPAT /* RCAR_LSI == RCAR_AUTO */
49*618522ebSBiju Das 	switch (reg & PRR_PRODUCT_MASK) {
50*618522ebSBiju Das 	case PRR_PRODUCT_M3:
51*618522ebSBiju Das #if RCAR_LSI != RZ_G2M
52*618522ebSBiju Das 		PRR_PRODUCT_ERR(reg);
53*618522ebSBiju Das #else /* RCAR_LSI != RZ_G2M */
54*618522ebSBiju Das 		pfc_init_g2m();
55*618522ebSBiju Das #endif /* RCAR_LSI != RZ_G2M */
56*618522ebSBiju Das 		break;
57*618522ebSBiju Das 	default:
58*618522ebSBiju Das 		PRR_PRODUCT_ERR(reg);
59*618522ebSBiju Das 		break;
60*618522ebSBiju Das 	}
61*618522ebSBiju Das 
62*618522ebSBiju Das #else /* RCAR_LSI == RCAR_AUTO */
63*618522ebSBiju Das #if (RCAR_LSI == RZ_G2M)
64*618522ebSBiju Das 	if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_M3) {
65*618522ebSBiju Das 		PRR_PRODUCT_ERR(reg);
66*618522ebSBiju Das 	}
67*618522ebSBiju Das 	pfc_init_m3();
68*618522ebSBiju Das #else /* RCAR_LSI == RZ_G2M */
69*618522ebSBiju Das #error "Don't have PFC initialize routine(unknown)."
70*618522ebSBiju Das #endif /* RCAR_LSI == RZ_G2M */
71*618522ebSBiju Das #endif /* RCAR_LSI == RCAR_AUTO */
72*618522ebSBiju Das }
73