qos_init.c 5.74 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/*
 * Copyright (c) 2021, Renesas Electronics Corporation. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <stdint.h>

#include <common/debug.h>
#include <lib/mmio.h>

#if RCAR_LSI == RCAR_AUTO
13
#include "G2H/qos_init_g2h_v30.h"
14
15
16
#include "G2M/qos_init_g2m_v10.h"
#include "G2M/qos_init_g2m_v11.h"
#include "G2M/qos_init_g2m_v30.h"
17
#include "G2N/qos_init_g2n_v10.h"
18
19
20
21
22
23
#endif /* RCAR_LSI == RCAR_AUTO */
#if (RCAR_LSI == RZ_G2M)
#include "G2M/qos_init_g2m_v10.h"
#include "G2M/qos_init_g2m_v11.h"
#include "G2M/qos_init_g2m_v30.h"
#endif /* RCAR_LSI == RZ_G2M */
24
25
26
#if RCAR_LSI == RZ_G2H
#include "G2H/qos_init_g2h_v30.h"
#endif /* RCAR_LSI == RZ_G2H */
27
28
29
#if RCAR_LSI == RZ_G2N
#include "G2N/qos_init_g2n_v10.h"
#endif /* RCAR_LSI == RZ_G2N */
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
#include "qos_common.h"
#include "qos_init.h"
#include "qos_reg.h"
#include "rcar_def.h"

#define DRAM_CH_CNT	0x04U
uint32_t qos_init_ddr_ch;
uint8_t qos_init_ddr_phyvalid;

#define PRR_PRODUCT_ERR(reg)				\
	{						\
		ERROR("LSI Product ID(PRR=0x%x) QoS "	\
		"initialize not supported.\n", reg);	\
		panic();				\
	}

#define PRR_CUT_ERR(reg)				\
	{						\
		ERROR("LSI Cut ID(PRR=0x%x) QoS "	\
		"initialize not supported.\n", reg);	\
		panic();				\
	}

void rzg_qos_init(void)
{
	uint32_t reg;
	uint32_t i;

	qos_init_ddr_ch = 0U;
59
	qos_init_ddr_phyvalid = get_boardcnf_phyvalid();
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
	for (i = 0U; i < DRAM_CH_CNT; i++) {
		if ((qos_init_ddr_phyvalid & (1U << i))) {
			qos_init_ddr_ch++;
		}
	}

	reg = mmio_read_32(PRR);
#if (RCAR_LSI == RCAR_AUTO) || RCAR_LSI_CUT_COMPAT
	switch (reg & PRR_PRODUCT_MASK) {
	case PRR_PRODUCT_M3:
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M)
		switch (reg & PRR_CUT_MASK) {
		case PRR_PRODUCT_10:
			qos_init_g2m_v10();
			break;
		case PRR_PRODUCT_21: /* G2M Cut 13 */
			qos_init_g2m_v11();
			break;
		case PRR_PRODUCT_30: /* G2M Cut 30 */
		default:
			qos_init_g2m_v30();
			break;
		}
#else /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
		PRR_PRODUCT_ERR(reg);
#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
		break;
87
88
89
90
91
92
93
94
95
96
97
98
	case PRR_PRODUCT_H3:
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H)
		switch (reg & PRR_CUT_MASK) {
		case PRR_PRODUCT_30:
		default:
			qos_init_g2h_v30();
			break;
		}
#else
		PRR_PRODUCT_ERR(reg);
#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H) */
		break;
99
100
101
102
103
104
105
106
107
108
109
110
	case PRR_PRODUCT_M3N:
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N)
		switch (reg & PRR_CUT_MASK) {
		case PRR_PRODUCT_10:
		default:
			qos_init_g2n_v10();
			break;
		}
#else
		PRR_PRODUCT_ERR(reg);
#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N) */
		break;
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
	default:
		PRR_PRODUCT_ERR(reg);
		break;
	}
#else /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
#if (RCAR_LSI == RZ_G2M)
#if RCAR_LSI_CUT == RCAR_CUT_10
	/* G2M Cut 10 */
	if ((PRR_PRODUCT_M3 | PRR_PRODUCT_10)
	    != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
		PRR_PRODUCT_ERR(reg);
	}
	qos_init_g2m_v10();
#elif RCAR_LSI_CUT == RCAR_CUT_11
	/* G2M Cut 11 */
	if ((PRR_PRODUCT_M3 | PRR_PRODUCT_20)
	    != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
		PRR_PRODUCT_ERR(reg);
	}
	qos_init_g2m_v11();
#elif RCAR_LSI_CUT == RCAR_CUT_13
	/* G2M Cut 13 */
	if ((PRR_PRODUCT_M3 | PRR_PRODUCT_21)
	    != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
		PRR_PRODUCT_ERR(reg);
	}
	qos_init_g2m_v11();
#else
	/* G2M Cut 30 or later */
	if ((PRR_PRODUCT_M3)
	    != (reg & (PRR_PRODUCT_MASK))) {
		PRR_PRODUCT_ERR(reg);
	}
	qos_init_g2m_v30();
#endif /* RCAR_LSI_CUT == RCAR_CUT_10 */
146
147
148
149
150
151
#elif (RCAR_LSI == RZ_G2H)
	/* G2H Cut 30 or later */
	if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_H3) {
		PRR_PRODUCT_ERR(reg);
	}
	qos_init_g2h_v30();
152
153
154
155
156
157
#elif (RCAR_LSI == RZ_G2N)
	/* G2N Cut 10 or later */
	if ((reg & (PRR_PRODUCT_MASK)) != PRR_PRODUCT_M3N) {
		PRR_PRODUCT_ERR(reg);
	}
	qos_init_g2n_v10();
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
#else /* (RCAR_LSI == RZ_G2M) */
#error "Don't have QoS initialize routine(Unknown chip)."
#endif /* (RCAR_LSI == RZ_G2M) */
#endif /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
}

uint32_t get_refperiod(void)
{
	uint32_t refperiod = QOSWT_WTSET0_CYCLE;

#if (RCAR_LSI == RCAR_AUTO) || RCAR_LSI_CUT_COMPAT
	uint32_t reg;

	reg = mmio_read_32(PRR);
	switch (reg & PRR_PRODUCT_MASK) {
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M)
	case PRR_PRODUCT_M3:
		switch (reg & PRR_CUT_MASK) {
		case PRR_PRODUCT_10:
			break;
		case PRR_PRODUCT_20: /* G2M Cut 11 */
		case PRR_PRODUCT_21: /* G2M Cut 13 */
		case PRR_PRODUCT_30: /* G2M Cut 30 */
		default:
			refperiod = REFPERIOD_CYCLE;
			break;
		}
		break;
#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
187
188
189
190
191
192
193
194
195
196
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H)
	case PRR_PRODUCT_H3:
		switch (reg & PRR_CUT_MASK) {
		case PRR_PRODUCT_30:
		default:
			refperiod = REFPERIOD_CYCLE;
			break;
		}
		break;
#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H) */
197
198
199
200
201
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N)
	case PRR_PRODUCT_M3N:
		refperiod = REFPERIOD_CYCLE;
		break;
#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N) */
202
203
204
205
206
207
208
209
210
211
	default:
		break;
	}
#elif RCAR_LSI == RZ_G2M
#if RCAR_LSI_CUT == RCAR_CUT_10
	/* G2M Cut 10 */
#else /* RCAR_LSI_CUT == RCAR_CUT_10 */
	/* G2M Cut 11|13|30 or later */
	refperiod = REFPERIOD_CYCLE;
#endif /* RCAR_LSI_CUT == RCAR_CUT_10 */
212
213
#elif RCAR_LSI == RZ_G2N
	refperiod = REFPERIOD_CYCLE;
214
215
216
#elif RCAR_LSI == RZ_G2H
	/* G2H Cut 30 or later */
	refperiod = REFPERIOD_CYCLE;
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#endif /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
	return refperiod;
}

void rzg_qos_dbsc_setting(const struct rcar_gen3_dbsc_qos_settings *qos,
			  unsigned int qos_size, bool dbsc_wren)
{
	unsigned int i;

	/* Register write enable */
	if (dbsc_wren) {
		mmio_write_32(DBSC_DBSYSCNT0, 0x00001234U);
	}

	for (i = 0; i < qos_size; i++) {
		mmio_write_32(qos[i].reg, qos[i].val);
	}

	/* Register write protect */
	if (dbsc_wren) {
		mmio_write_32(DBSC_DBSYSCNT0, 0x00000000U);
	}
}