blob: e527a61764da14d7b8a1a9d89792b7b6b47e1a2c [file] [log] [blame]
Biju Das21615422020-11-09 09:38:51 +00001/*
2 * Copyright (c) 2021, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdint.h>
8
9#include <common/debug.h>
10#include <lib/mmio.h>
11
12#if RCAR_LSI == RCAR_AUTO
Lad Prabhakar84e942d2020-12-21 11:33:16 +000013#include "G2E/qos_init_g2e_v10.h"
Lad Prabhakaref124a22020-12-11 20:06:59 +000014#include "G2H/qos_init_g2h_v30.h"
Biju Das21615422020-11-09 09:38:51 +000015#include "G2M/qos_init_g2m_v10.h"
16#include "G2M/qos_init_g2m_v11.h"
17#include "G2M/qos_init_g2m_v30.h"
Lad Prabhakar964fcb22021-03-18 18:54:15 +000018#include "G2N/qos_init_g2n_v10.h"
Biju Das21615422020-11-09 09:38:51 +000019#endif /* RCAR_LSI == RCAR_AUTO */
20#if (RCAR_LSI == RZ_G2M)
21#include "G2M/qos_init_g2m_v10.h"
22#include "G2M/qos_init_g2m_v11.h"
23#include "G2M/qos_init_g2m_v30.h"
24#endif /* RCAR_LSI == RZ_G2M */
Lad Prabhakaref124a22020-12-11 20:06:59 +000025#if RCAR_LSI == RZ_G2H
26#include "G2H/qos_init_g2h_v30.h"
27#endif /* RCAR_LSI == RZ_G2H */
Lad Prabhakar964fcb22021-03-18 18:54:15 +000028#if RCAR_LSI == RZ_G2N
29#include "G2N/qos_init_g2n_v10.h"
30#endif /* RCAR_LSI == RZ_G2N */
Lad Prabhakar84e942d2020-12-21 11:33:16 +000031#if RCAR_LSI == RZ_G2E
32#include "G2E/qos_init_g2e_v10.h"
33#endif /* RCAR_LSI == RZ_G2E */
Biju Das21615422020-11-09 09:38:51 +000034#include "qos_common.h"
35#include "qos_init.h"
36#include "qos_reg.h"
37#include "rcar_def.h"
38
Lad Prabhakar84e942d2020-12-21 11:33:16 +000039#if (RCAR_LSI != RZ_G2E)
Biju Das21615422020-11-09 09:38:51 +000040#define DRAM_CH_CNT 0x04U
41uint32_t qos_init_ddr_ch;
42uint8_t qos_init_ddr_phyvalid;
Lad Prabhakar84e942d2020-12-21 11:33:16 +000043#endif /* RCAR_LSI != RZ_G2E */
Biju Das21615422020-11-09 09:38:51 +000044
45#define PRR_PRODUCT_ERR(reg) \
46 { \
47 ERROR("LSI Product ID(PRR=0x%x) QoS " \
48 "initialize not supported.\n", reg); \
49 panic(); \
50 }
51
52#define PRR_CUT_ERR(reg) \
53 { \
54 ERROR("LSI Cut ID(PRR=0x%x) QoS " \
55 "initialize not supported.\n", reg); \
56 panic(); \
57 }
58
59void rzg_qos_init(void)
60{
61 uint32_t reg;
Lad Prabhakar84e942d2020-12-21 11:33:16 +000062#if (RCAR_LSI != RZ_G2E)
Biju Das21615422020-11-09 09:38:51 +000063 uint32_t i;
64
65 qos_init_ddr_ch = 0U;
Lad Prabhakar9f2b5792021-03-10 14:30:20 +000066 qos_init_ddr_phyvalid = get_boardcnf_phyvalid();
Biju Das21615422020-11-09 09:38:51 +000067 for (i = 0U; i < DRAM_CH_CNT; i++) {
68 if ((qos_init_ddr_phyvalid & (1U << i))) {
69 qos_init_ddr_ch++;
70 }
71 }
Lad Prabhakar84e942d2020-12-21 11:33:16 +000072#endif /* RCAR_LSI != RZ_G2E */
Biju Das21615422020-11-09 09:38:51 +000073
74 reg = mmio_read_32(PRR);
75#if (RCAR_LSI == RCAR_AUTO) || RCAR_LSI_CUT_COMPAT
76 switch (reg & PRR_PRODUCT_MASK) {
77 case PRR_PRODUCT_M3:
78#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M)
79 switch (reg & PRR_CUT_MASK) {
80 case PRR_PRODUCT_10:
81 qos_init_g2m_v10();
82 break;
83 case PRR_PRODUCT_21: /* G2M Cut 13 */
84 qos_init_g2m_v11();
85 break;
86 case PRR_PRODUCT_30: /* G2M Cut 30 */
87 default:
88 qos_init_g2m_v30();
89 break;
90 }
91#else /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
92 PRR_PRODUCT_ERR(reg);
93#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
94 break;
Lad Prabhakaref124a22020-12-11 20:06:59 +000095 case PRR_PRODUCT_H3:
96#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H)
97 switch (reg & PRR_CUT_MASK) {
98 case PRR_PRODUCT_30:
99 default:
100 qos_init_g2h_v30();
101 break;
102 }
103#else
104 PRR_PRODUCT_ERR(reg);
105#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H) */
106 break;
Lad Prabhakar964fcb22021-03-18 18:54:15 +0000107 case PRR_PRODUCT_M3N:
108#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N)
109 switch (reg & PRR_CUT_MASK) {
110 case PRR_PRODUCT_10:
111 default:
112 qos_init_g2n_v10();
113 break;
114 }
115#else
116 PRR_PRODUCT_ERR(reg);
117#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N) */
118 break;
Lad Prabhakar84e942d2020-12-21 11:33:16 +0000119 case PRR_PRODUCT_E3:
120#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2E)
121 switch (reg & PRR_CUT_MASK) {
122 case PRR_PRODUCT_10:
123 default:
124 qos_init_g2e_v10();
125 break;
126 }
127#else
128 PRR_PRODUCT_ERR(reg);
129#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2E) */
130 break;
Biju Das21615422020-11-09 09:38:51 +0000131 default:
132 PRR_PRODUCT_ERR(reg);
133 break;
134 }
135#else /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
136#if (RCAR_LSI == RZ_G2M)
137#if RCAR_LSI_CUT == RCAR_CUT_10
138 /* G2M Cut 10 */
139 if ((PRR_PRODUCT_M3 | PRR_PRODUCT_10)
140 != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
141 PRR_PRODUCT_ERR(reg);
142 }
143 qos_init_g2m_v10();
144#elif RCAR_LSI_CUT == RCAR_CUT_11
145 /* G2M Cut 11 */
146 if ((PRR_PRODUCT_M3 | PRR_PRODUCT_20)
147 != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
148 PRR_PRODUCT_ERR(reg);
149 }
150 qos_init_g2m_v11();
151#elif RCAR_LSI_CUT == RCAR_CUT_13
152 /* G2M Cut 13 */
153 if ((PRR_PRODUCT_M3 | PRR_PRODUCT_21)
154 != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
155 PRR_PRODUCT_ERR(reg);
156 }
157 qos_init_g2m_v11();
158#else
159 /* G2M Cut 30 or later */
160 if ((PRR_PRODUCT_M3)
161 != (reg & (PRR_PRODUCT_MASK))) {
162 PRR_PRODUCT_ERR(reg);
163 }
164 qos_init_g2m_v30();
165#endif /* RCAR_LSI_CUT == RCAR_CUT_10 */
Lad Prabhakaref124a22020-12-11 20:06:59 +0000166#elif (RCAR_LSI == RZ_G2H)
167 /* G2H Cut 30 or later */
168 if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_H3) {
169 PRR_PRODUCT_ERR(reg);
170 }
171 qos_init_g2h_v30();
Lad Prabhakar964fcb22021-03-18 18:54:15 +0000172#elif (RCAR_LSI == RZ_G2N)
173 /* G2N Cut 10 or later */
174 if ((reg & (PRR_PRODUCT_MASK)) != PRR_PRODUCT_M3N) {
175 PRR_PRODUCT_ERR(reg);
176 }
177 qos_init_g2n_v10();
Lad Prabhakar84e942d2020-12-21 11:33:16 +0000178#elif RCAR_LSI == RZ_G2E
179 /* G2E Cut 10 or later */
180 if ((reg & (PRR_PRODUCT_MASK)) != PRR_PRODUCT_E3) {
181 PRR_PRODUCT_ERR(reg);
182 }
183 qos_init_g2e_v10();
Biju Das21615422020-11-09 09:38:51 +0000184#else /* (RCAR_LSI == RZ_G2M) */
185#error "Don't have QoS initialize routine(Unknown chip)."
186#endif /* (RCAR_LSI == RZ_G2M) */
187#endif /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
188}
189
Lad Prabhakar84e942d2020-12-21 11:33:16 +0000190#if (RCAR_LSI != RZ_G2E)
Biju Das21615422020-11-09 09:38:51 +0000191uint32_t get_refperiod(void)
192{
193 uint32_t refperiod = QOSWT_WTSET0_CYCLE;
194
195#if (RCAR_LSI == RCAR_AUTO) || RCAR_LSI_CUT_COMPAT
196 uint32_t reg;
197
198 reg = mmio_read_32(PRR);
199 switch (reg & PRR_PRODUCT_MASK) {
200#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M)
201 case PRR_PRODUCT_M3:
202 switch (reg & PRR_CUT_MASK) {
203 case PRR_PRODUCT_10:
204 break;
205 case PRR_PRODUCT_20: /* G2M Cut 11 */
206 case PRR_PRODUCT_21: /* G2M Cut 13 */
207 case PRR_PRODUCT_30: /* G2M Cut 30 */
208 default:
209 refperiod = REFPERIOD_CYCLE;
210 break;
211 }
212 break;
213#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
Lad Prabhakaref124a22020-12-11 20:06:59 +0000214#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H)
215 case PRR_PRODUCT_H3:
216 switch (reg & PRR_CUT_MASK) {
217 case PRR_PRODUCT_30:
218 default:
219 refperiod = REFPERIOD_CYCLE;
220 break;
221 }
222 break;
223#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H) */
Lad Prabhakar964fcb22021-03-18 18:54:15 +0000224#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N)
225 case PRR_PRODUCT_M3N:
226 refperiod = REFPERIOD_CYCLE;
227 break;
228#endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N) */
Biju Das21615422020-11-09 09:38:51 +0000229 default:
230 break;
231 }
232#elif RCAR_LSI == RZ_G2M
233#if RCAR_LSI_CUT == RCAR_CUT_10
234 /* G2M Cut 10 */
235#else /* RCAR_LSI_CUT == RCAR_CUT_10 */
236 /* G2M Cut 11|13|30 or later */
237 refperiod = REFPERIOD_CYCLE;
238#endif /* RCAR_LSI_CUT == RCAR_CUT_10 */
Lad Prabhakar964fcb22021-03-18 18:54:15 +0000239#elif RCAR_LSI == RZ_G2N
240 refperiod = REFPERIOD_CYCLE;
Lad Prabhakaref124a22020-12-11 20:06:59 +0000241#elif RCAR_LSI == RZ_G2H
242 /* G2H Cut 30 or later */
243 refperiod = REFPERIOD_CYCLE;
Biju Das21615422020-11-09 09:38:51 +0000244#endif /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
245 return refperiod;
246}
Lad Prabhakar84e942d2020-12-21 11:33:16 +0000247#endif /* RCAR_LSI != RZ_G2E */
Biju Das21615422020-11-09 09:38:51 +0000248
249void rzg_qos_dbsc_setting(const struct rcar_gen3_dbsc_qos_settings *qos,
250 unsigned int qos_size, bool dbsc_wren)
251{
252 unsigned int i;
253
254 /* Register write enable */
255 if (dbsc_wren) {
256 mmio_write_32(DBSC_DBSYSCNT0, 0x00001234U);
257 }
258
259 for (i = 0; i < qos_size; i++) {
260 mmio_write_32(qos[i].reg, qos[i].val);
261 }
262
263 /* Register write protect */
264 if (dbsc_wren) {
265 mmio_write_32(DBSC_DBSYSCNT0, 0x00000000U);
266 }
267}