1 // SPDX-License-Identifier: GPL-2.0+
4 * (C) Copyright 2012 Renesas Solutions Corp.
12 #include <asm/arch/sys_proto.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 #define CS0BCR_D (0x06C00400)
20 #define CS4BCR_D (0x16c90400)
21 #define CS0WCR_D (0x55062C42)
22 #define CS4WCR_D (0x1e071dc3)
24 #define CMNCR_BROMMD0 (1 << 21)
25 #define CMNCR_BROMMD1 (1 << 22)
26 #define CMNCR_BROMMD (CMNCR_BROMMD0|CMNCR_BROMMD1)
27 #define VCLKCR1_D (0x27)
29 #define SMSTPCR1_CMT0 (1 << 24)
30 #define SMSTPCR1_I2C0 (1 << 16)
31 #define SMSTPCR3_USB (1 << 22)
32 #define SMSTPCR3_I2C1 (1 << 23)
34 #define PORT32CR (0xE6051020)
35 #define PORT33CR (0xE6051021)
36 #define PORT34CR (0xE6051022)
37 #define PORT35CR (0xE6051023)
39 static int cmp_loop(u32 *addr, u32 data, u32 cmp)
47 if ((value & data) == cmp) {
57 /* SBSC Init function */
58 static void sbsc_init(struct sh73a0_sbsc *sbsc)
60 writel(readl(&sbsc->dllcnt0)|0x2, &sbsc->dllcnt0);
61 writel(0x5, &sbsc->sdgencnt);
62 cmp_loop(&sbsc->sdgencnt, 0xffffffff, 0x0);
64 writel(0xacc90159, &sbsc->sdcr0);
65 writel(0x00010059, &sbsc->sdcr1);
66 writel(0x50874114, &sbsc->sdwcrc0);
67 writel(0x33199b37, &sbsc->sdwcrc1);
68 writel(0x008f2313, &sbsc->sdwcrc2);
69 writel(0x31020707, &sbsc->sdwcr00);
70 writel(0x0017040a, &sbsc->sdwcr01);
71 writel(0x31020707, &sbsc->sdwcr10);
72 writel(0x0017040a, &sbsc->sdwcr11);
73 writel(0x055557ff, &sbsc->sddrvcr0); /* Enlarge drivability of LPDQS0-3, LPCLK */
74 writel(0x30000000, &sbsc->sdwcr2);
76 writel(readl(&sbsc->sdpcr) | 0x80, &sbsc->sdpcr);
77 cmp_loop(&sbsc->sdpcr, 0x80, 0x80);
79 writel(0x00002710, &sbsc->sdgencnt);
80 cmp_loop(&sbsc->sdgencnt, 0xffffffff, 0x0);
82 writel(0x0000003f, &sbsc->sdmracr0);
84 writel(0x000001f4, &sbsc->sdgencnt);
85 cmp_loop(&sbsc->sdgencnt, 0xffffffff, 0x0);
87 writel(0x0000ff0a, &sbsc->sdmracr0);
88 if (sbsc == (struct sh73a0_sbsc *)SBSC1_BASE)
93 writel(0x00000032, &sbsc->sdgencnt);
94 cmp_loop(&sbsc->sdgencnt, 0xffffffff, 0x0);
96 if (sbsc == (struct sh73a0_sbsc *)SBSC1_BASE) {
97 writel(0x00002201, &sbsc->sdmracr0);
99 writel(0x00000402, &sbsc->sdmracr0);
100 writel(0x0, SDMRA1A);
101 writel(0x00000203, &sbsc->sdmracr0); /* MR3 register DS=2 */
102 writel(0x0, SDMRA1A);
103 writel(0x0, SDMRA2A);
105 writel(0x00002201, &sbsc->sdmracr0);
106 writel(0x0, SDMRA1B);
107 writel(0x00000402, &sbsc->sdmracr0);
108 writel(0x0, SDMRA1B);
109 writel(0x00000203, &sbsc->sdmracr0); /* MR3 register DS=2 */
110 writel(0x0, SDMRA1B);
111 writel(0x0, SDMRA2B);
114 writel(0x88800004, &sbsc->sdmrtmpcr);
115 writel(0x00000004, &sbsc->sdmrtmpmsk);
116 writel(0xa55a0032, &sbsc->rtcor);
117 writel(0xa55a000c, &sbsc->rtcorh);
118 writel(0xa55a2048, &sbsc->rtcsr);
119 writel(readl(&sbsc->sdcr0)|0x800, &sbsc->sdcr0);
120 writel(readl(&sbsc->sdcr1)|0x400, &sbsc->sdcr1);
121 writel(0xfff20000, &sbsc->zqccr);
124 if (sbsc == (struct sh73a0_sbsc *)SBSC2_BASE) {
125 writel(readl(&sbsc->sdpdcr0)|0x00030000, &sbsc->sdpdcr0);
126 writel(0xa5390000, &sbsc->dphycnt1);
127 writel(0x00001200, &sbsc->dphycnt0);
128 writel(0x07ce0000, &sbsc->dphycnt1);
129 writel(0x00001247, &sbsc->dphycnt0);
130 cmp_loop(&sbsc->dphycnt2, 0xffffffff, 0x07ce0000);
131 writel(readl(&sbsc->sdpdcr0) & 0xfffcffff, &sbsc->sdpdcr0);
137 struct sh73a0_rwdt *rwdt = (struct sh73a0_rwdt *)RWDT_BASE;
138 struct sh73a0_sbsc_cpg *cpg = (struct sh73a0_sbsc_cpg *)CPG_BASE;
139 struct sh73a0_sbsc_cpg_srcr *cpg_srcr =
140 (struct sh73a0_sbsc_cpg_srcr *)CPG_SRCR_BASE;
141 struct sh73a0_sbsc *sbsc1 = (struct sh73a0_sbsc *)SBSC1_BASE;
142 struct sh73a0_sbsc *sbsc2 = (struct sh73a0_sbsc *)SBSC2_BASE;
143 struct sh73a0_hpb *hpb = (struct sh73a0_hpb *)HPB_BASE;
144 struct sh73a0_hpb_bscr *hpb_bscr =
145 (struct sh73a0_hpb_bscr *)HPBSCR_BASE;
148 writew(0xA507, &rwdt->rwtcsra0);
150 /* Secure control register Init */
151 #define LIFEC_SEC_SRC_BIT (1 << 15)
152 writel(readl(LIFEC_SEC_SRC) & ~LIFEC_SEC_SRC_BIT, LIFEC_SEC_SRC);
154 clrbits_le32(&cpg->smstpcr3, (1 << 15));
155 clrbits_le32(&cpg_srcr->srcr3, (1 << 15));
156 clrbits_le32(&cpg->smstpcr2, (1 << 18));
157 clrbits_le32(&cpg_srcr->srcr2, (1 << 18));
158 writel(0x0, &cpg->pllecr);
160 cmp_loop(&cpg->pllecr, 0x00000F00, 0x0);
161 cmp_loop(&cpg->frqcrb, 0x80000000, 0x0);
163 writel(0x2D000000, &cpg->pll0cr);
164 writel(0x17100000, &cpg->pll1cr);
165 writel(0x96235880, &cpg->frqcrb);
166 cmp_loop(&cpg->frqcrb, 0x80000000, 0x0);
168 writel(0xB, &cpg->flckcr);
169 clrbits_le32(&cpg->smstpcr0, (1 << 1));
171 clrbits_le32(&cpg_srcr->srcr0, (1 << 1));
172 writel(0x0514, &hpb_bscr->smgpiotime);
173 writel(0x0514, &hpb_bscr->smcmt2time);
174 writel(0x0514, &hpb_bscr->smcpgtime);
175 writel(0x0514, &hpb_bscr->smsysctime);
177 writel(0x00092000, &cpg->dvfscr4);
178 writel(0x000000DC, &cpg->dvfscr5);
179 writel(0x0, &cpg->pllecr);
180 cmp_loop(&cpg->pllecr, 0x00000F00, 0x0);
183 writel(0x0012453C, &cpg->frqcra);
184 writel(0x80431350, &cpg->frqcrb); /* ETM TRCLK 78MHz */
185 cmp_loop(&cpg->frqcrb, 0x80000000, 0x0);
186 writel(0x00000B0B, &cpg->frqcrd);
187 cmp_loop(&cpg->frqcrd, 0x80000000, 0x0);
190 writel(0x00000003, PCLKCR);
191 writel(0x0000012F, &cpg->vclkcr1);
192 writel(0x00000119, &cpg->vclkcr2);
193 writel(0x00000119, &cpg->vclkcr3);
194 writel(0x00000002, &cpg->zbckcr);
195 writel(0x00000005, &cpg->flckcr);
196 writel(0x00000080, &cpg->sd0ckcr);
197 writel(0x00000080, &cpg->sd1ckcr);
198 writel(0x00000080, &cpg->sd2ckcr);
199 writel(0x0000003F, &cpg->fsiackcr);
200 writel(0x0000003F, &cpg->fsibckcr);
201 writel(0x00000080, &cpg->subckcr);
202 writel(0x0000000B, &cpg->spuackcr);
203 writel(0x0000000B, &cpg->spuvckcr);
204 writel(0x0000013F, &cpg->msuckcr);
205 writel(0x00000080, &cpg->hsickcr);
206 writel(0x0000003F, &cpg->mfck1cr);
207 writel(0x0000003F, &cpg->mfck2cr);
208 writel(0x00000107, &cpg->dsitckcr);
209 writel(0x00000313, &cpg->dsi0pckcr);
210 writel(0x0000130D, &cpg->dsi1pckcr);
211 writel(0x2A800E0E, &cpg->dsi0phycr);
212 writel(0x1E000000, &cpg->pll0cr);
213 writel(0x2D000000, &cpg->pll0cr);
214 writel(0x17100000, &cpg->pll1cr);
215 writel(0x27000080, &cpg->pll2cr);
216 writel(0x1D000000, &cpg->pll3cr);
217 writel(0x00080000, &cpg->pll0stpcr);
218 writel(0x000120C0, &cpg->pll1stpcr);
219 writel(0x00012000, &cpg->pll2stpcr);
220 writel(0x00000030, &cpg->pll3stpcr);
222 writel(0x0000000B, &cpg->pllecr);
223 cmp_loop(&cpg->pllecr, 0x00000B00, 0x00000B00);
225 writel(0x000120F0, &cpg->dvfscr3);
226 writel(0x00000020, &cpg->mpmode);
227 writel(0x0000028A, &cpg->vrefcr);
228 writel(0xE4628087, &cpg->rmstpcr0);
229 writel(0xFFFFFFFF, &cpg->rmstpcr1);
230 writel(0x53FFFFFF, &cpg->rmstpcr2);
231 writel(0xFFFFFFFF, &cpg->rmstpcr3);
232 writel(0x00800D3D, &cpg->rmstpcr4);
233 writel(0xFFFFF3FF, &cpg->rmstpcr5);
234 writel(0x00000000, &cpg->smstpcr2);
235 writel(0x00040000, &cpg_srcr->srcr2);
237 clrbits_le32(&cpg->pllecr, (1 << 3));
238 cmp_loop(&cpg->pllecr, 0x00000800, 0x0);
240 writel(0x00000001, &hpb->hpbctrl6);
241 cmp_loop(&hpb->hpbctrl6, 0x1, 0x1);
243 writel(0x00001414, &cpg->frqcrd);
244 cmp_loop(&cpg->frqcrd, 0x80000000, 0x0);
246 writel(0x1d000000, &cpg->pll3cr);
247 setbits_le32(&cpg->pllecr, (1 << 3));
248 cmp_loop(&cpg->pllecr, 0x800, 0x800);
256 writel(0x00000b0b, &cpg->frqcrd);
257 cmp_loop(&cpg->frqcrd, 0x80000000, 0x0);
258 writel(0xfffffffc, &cpg->cpgxxcs4);
261 int board_early_init_f(void)
263 struct sh73a0_sbsc_cpg *cpg = (struct sh73a0_sbsc_cpg *)CPG_BASE;
264 struct sh73a0_bsc *bsc = (struct sh73a0_bsc *)BSC_BASE;
265 struct sh73a0_sbsc_cpg_srcr *cpg_srcr =
266 (struct sh73a0_sbsc_cpg_srcr *)CPG_SRCR_BASE;
268 writel(CS0BCR_D, &bsc->cs0bcr);
269 writel(CS4BCR_D, &bsc->cs4bcr);
270 writel(CS0WCR_D, &bsc->cs0wcr);
271 writel(CS4WCR_D, &bsc->cs4wcr);
273 clrsetbits_le32(&bsc->cmncr, ~CMNCR_BROMMD, CMNCR_BROMMD);
275 clrbits_le32(&cpg->smstpcr1, (SMSTPCR1_CMT0|SMSTPCR1_I2C0));
276 clrbits_le32(&cpg_srcr->srcr1, (SMSTPCR1_CMT0|SMSTPCR1_I2C0));
277 clrbits_le32(&cpg->smstpcr3, (SMSTPCR3_USB|SMSTPCR3_I2C1));
278 clrbits_le32(&cpg_srcr->srcr3, (SMSTPCR3_USB|SMSTPCR3_I2C1));
279 writel(VCLKCR1_D, &cpg->vclkcr1);
281 /* Setup SCIF4 / workaround */
282 writeb(0x12, PORT32CR);
283 writeb(0x22, PORT33CR);
284 writeb(0x12, PORT34CR);
285 writeb(0x22, PORT35CR);
290 void adjust_core_voltage(void)
296 i2c_write(0x40, 3, 1, &data, 1);
301 adjust_core_voltage();
302 sh73a0_pinmux_init();
305 gpio_request(GPIO_FN_SCIFA4_TXD, NULL);
306 gpio_request(GPIO_FN_SCIFA4_RXD, NULL);
307 gpio_request(GPIO_FN_SCIFA4_RTS_, NULL);
308 gpio_request(GPIO_FN_SCIFA4_CTS_, NULL);
311 gpio_request(GPIO_PORT224, NULL);
312 gpio_direction_input(GPIO_PORT224);
315 gpio_request(GPIO_FN_CS4_, NULL);
318 gpio_request(GPIO_FN_MMCCLK0, NULL);
319 gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
320 gpio_request(GPIO_FN_MMCD0_0_PU, NULL);
321 gpio_request(GPIO_FN_MMCD0_1_PU, NULL);
322 gpio_request(GPIO_FN_MMCD0_2_PU, NULL);
323 gpio_request(GPIO_FN_MMCD0_3_PU, NULL);
324 gpio_request(GPIO_FN_MMCD0_4_PU, NULL);
325 gpio_request(GPIO_FN_MMCD0_5_PU, NULL);
326 gpio_request(GPIO_FN_MMCD0_6_PU, NULL);
327 gpio_request(GPIO_FN_MMCD0_7_PU, NULL);
330 gpio_request(GPIO_FN_SDHIWP0, NULL);
331 gpio_request(GPIO_FN_SDHICD0, NULL);
332 gpio_request(GPIO_FN_SDHICMD0, NULL);
333 gpio_request(GPIO_FN_SDHICLK0, NULL);
334 gpio_request(GPIO_FN_SDHID0_3, NULL);
335 gpio_request(GPIO_FN_SDHID0_2, NULL);
336 gpio_request(GPIO_FN_SDHID0_1, NULL);
337 gpio_request(GPIO_FN_SDHID0_0, NULL);
338 gpio_request(GPIO_FN_SDHI0_VCCQ_MC0_ON, NULL);
339 gpio_request(GPIO_PORT15, NULL);
340 gpio_direction_output(GPIO_PORT15, 1);
343 gpio_request(GPIO_FN_PORT237_I2C_SCL2, NULL);
344 gpio_request(GPIO_FN_PORT236_I2C_SDA2, NULL);
345 gpio_request(GPIO_FN_PORT27_I2C_SCL3, NULL);
346 gpio_request(GPIO_FN_PORT28_I2C_SDA3, NULL);
348 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
355 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
359 int board_eth_init(bd_t *bis)
362 #ifdef CONFIG_SMC911X
363 ret = smc911x_initialize(0, CONFIG_SMC911X_BASE);
368 void reset_cpu(ulong addr)
370 /* Soft Power On Reset */
371 writel((1 << 31), RESCNT2);