blob: c15387366c756c6489ff9185e9aa3e6e26f030e0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +09002/*
3 * board/renesas/blanche/blanche.c
4 * This file is blanche board support.
5 *
6 * Copyright (C) 2016 Renesas Electronics Corporation
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +09007 */
8
9#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -070010#include <cpu_func.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020011#include <asm/arch/mmc.h>
12#include <asm/arch/rcar-mstp.h>
13#include <asm/arch/rmobile.h>
14#include <asm/arch/sh_sdhi.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/gpio.h>
17#include <asm/io.h>
18#include <asm/mach-types.h>
19#include <asm/processor.h>
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090020#include <dm.h>
21#include <dm/platform_data/serial_sh.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060022#include <env.h>
Marek Vasut24700a22020-03-21 16:57:58 +010023#include <hang.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020024#include <i2c.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090025#include <linux/errno.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020026#include <malloc.h>
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090027#include <miiphy.h>
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090028#include <mmc.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020029#include <netdev.h>
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090030#include "qos.h"
31
32DECLARE_GLOBAL_DATA_PTR;
33
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090034#define CPG_PLL1CR 0xE6150028
35#define CPG_PLL3CR 0xE61500DC
36
Marek Vasut927b1e32018-04-30 14:10:36 +020037#define TMU0_MSTP125 BIT(25)
38#define QSPI_MSTP917 BIT(17)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090039
Marek Vasut927b1e32018-04-30 14:10:36 +020040struct reg_config {
41 u16 off;
42 u32 val;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090043};
44
Marek Vasut927b1e32018-04-30 14:10:36 +020045static void blanche_init_sys(void)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090046{
47 struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
48 struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
49 u32 cpu_type;
50
51 cpu_type = rmobile_get_cpu_type();
52 if (cpu_type == 0x4A) {
53 writel(0x4D000000, CPG_PLL1CR);
54 writel(0x4F000000, CPG_PLL3CR);
55 }
56
57 /* Watchdog init */
58 writel(0xA5A5A500, &rwdt->rwtcsra);
59 writel(0xA5A5A500, &swdt->swtcsra);
Marek Vasut927b1e32018-04-30 14:10:36 +020060}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090061
Marek Vasut927b1e32018-04-30 14:10:36 +020062static void blanche_init_pfc(void)
63{
64 static const struct reg_config pfc_with_unlock[] = {
65 { 0x0004, 0x0bffffff },
66 { 0x0008, 0x002fffff },
67 { 0x0014, 0x00000fff },
68 { 0x0018, 0x00010fff },
69 { 0x001c, 0x00010fff },
70 { 0x0020, 0x00010fff },
71 { 0x0024, 0x00010fff },
72 { 0x0028, 0x00010fff },
73 { 0x002c, 0x04006000 },
74 { 0x0030, 0x303fefe0 },
75 { 0x0058, 0x0002000e },
76 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090077
Marek Vasut927b1e32018-04-30 14:10:36 +020078 static const struct reg_config pfc_without_unlock[] = {
79 { 0x0108, 0x00000000 },
80 { 0x010c, 0x0803FF40 },
81 { 0x0110, 0x0000FFFF },
82 { 0x0114, 0x00010FFF },
83 { 0x011c, 0x0001AFFF },
84 { 0x0124, 0x0001CFFF },
85 { 0x0128, 0xC0438001 },
86 { 0x012c, 0x0FC00007 },
87 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090088
Marek Vasut927b1e32018-04-30 14:10:36 +020089 static const u32 pfc_base = 0xe6060000;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090090
Marek Vasut927b1e32018-04-30 14:10:36 +020091 unsigned int i;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090092
Marek Vasut927b1e32018-04-30 14:10:36 +020093 for (i = 0; i < ARRAY_SIZE(pfc_with_unlock); i++) {
94 writel(~pfc_with_unlock[i].val, pfc_base);
95 writel(pfc_with_unlock[i].val,
96 pfc_base | pfc_with_unlock[i].off);
97 }
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090098
Marek Vasut927b1e32018-04-30 14:10:36 +020099 for (i = 0; i < ARRAY_SIZE(pfc_without_unlock); i++)
100 writel(pfc_without_unlock[i].val,
101 pfc_base | pfc_without_unlock[i].off);
102}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900103
Marek Vasut927b1e32018-04-30 14:10:36 +0200104static void blanche_init_lbsc(void)
105{
106 static const struct reg_config lbsc_config[] = {
107 { 0x00, 0x00000020 },
108 { 0x08, 0x00002020 },
109 { 0x30, 0x2a103320 },
110 { 0x38, 0x19102110 },
111 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900112
Marek Vasut927b1e32018-04-30 14:10:36 +0200113 static const u32 lbsc_base = 0xfec00200;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900114
Marek Vasut927b1e32018-04-30 14:10:36 +0200115 unsigned int i;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900116
Marek Vasut927b1e32018-04-30 14:10:36 +0200117 for (i = 0; i < ARRAY_SIZE(lbsc_config); i++) {
118 writel(lbsc_config[i].val,
119 lbsc_base | lbsc_config[i].off);
120 writel(lbsc_config[i].val,
121 lbsc_base | (lbsc_config[i].off + 4));
122 }
123}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900124
Marek Vasut927b1e32018-04-30 14:10:36 +0200125#if defined(CONFIG_MTD_NOR_FLASH)
126static void dbsc_wait(u16 reg)
127{
128 static const u32 dbsc3_0_base = DBSC3_0_BASE;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900129
Marek Vasut927b1e32018-04-30 14:10:36 +0200130 while (!(readl(dbsc3_0_base + reg) & BIT(0)))
131 ;
132}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900133
Marek Vasut927b1e32018-04-30 14:10:36 +0200134static void blanche_init_dbsc(void)
135{
136 static const struct reg_config dbsc_config1[] = {
137 { 0x0280, 0x0000a55a },
138 { 0x0018, 0x21000000 },
139 { 0x0018, 0x11000000 },
140 { 0x0018, 0x10000000 },
141 { 0x0290, 0x00000001 },
142 { 0x02a0, 0x80000000 },
143 { 0x0290, 0x00000004 },
144 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900145
Marek Vasut927b1e32018-04-30 14:10:36 +0200146 static const struct reg_config dbsc_config2[] = {
147 { 0x0290, 0x00000006 },
148 { 0x02a0, 0x0001c000 },
149 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900150
Marek Vasut927b1e32018-04-30 14:10:36 +0200151 static const struct reg_config dbsc_config4[] = {
152 { 0x0290, 0x0000000f },
153 { 0x02a0, 0x00181ee4 },
154 { 0x0290, 0x00000010 },
155 { 0x02a0, 0xf00464db },
156 { 0x0290, 0x00000061 },
157 { 0x02a0, 0x0000008d },
158 { 0x0290, 0x00000001 },
159 { 0x02a0, 0x00000073 },
160 { 0x0020, 0x00000007 },
161 { 0x0024, 0x0f030a02 },
162 { 0x0030, 0x00000001 },
163 { 0x00b0, 0x00000000 },
164 { 0x0040, 0x0000000b },
165 { 0x0044, 0x00000008 },
166 { 0x0048, 0x00000000 },
167 { 0x0050, 0x0000000b },
168 { 0x0054, 0x000c000b },
169 { 0x0058, 0x00000027 },
170 { 0x005c, 0x0000001c },
171 { 0x0060, 0x00000006 },
172 { 0x0064, 0x00000020 },
173 { 0x0068, 0x00000008 },
174 { 0x006c, 0x0000000c },
175 { 0x0070, 0x00000009 },
176 { 0x0074, 0x00000012 },
177 { 0x0078, 0x000000d0 },
178 { 0x007c, 0x00140005 },
179 { 0x0080, 0x00050004 },
180 { 0x0084, 0x70233005 },
181 { 0x0088, 0x000c0000 },
182 { 0x008c, 0x00000300 },
183 { 0x0090, 0x00000040 },
184 { 0x0100, 0x00000001 },
185 { 0x00c0, 0x00020001 },
186 { 0x00c8, 0x20082004 },
187 { 0x0380, 0x00020002 },
188 { 0x0390, 0x0000001f },
189 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900190
Marek Vasut927b1e32018-04-30 14:10:36 +0200191 static const struct reg_config dbsc_config5[] = {
192 { 0x0244, 0x00000011 },
193 { 0x0290, 0x00000003 },
194 { 0x02a0, 0x0300c4e1 },
195 { 0x0290, 0x00000023 },
196 { 0x02a0, 0x00fcdb60 },
197 { 0x0290, 0x00000011 },
198 { 0x02a0, 0x1000040b },
199 { 0x0290, 0x00000012 },
200 { 0x02a0, 0x9d9cbb66 },
201 { 0x0290, 0x00000013 },
202 { 0x02a0, 0x1a868400 },
203 { 0x0290, 0x00000014 },
204 { 0x02a0, 0x300214d8 },
205 { 0x0290, 0x00000015 },
206 { 0x02a0, 0x00000d70 },
207 { 0x0290, 0x00000016 },
208 { 0x02a0, 0x00000004 },
209 { 0x0290, 0x00000017 },
210 { 0x02a0, 0x00000018 },
211 { 0x0290, 0x0000001a },
212 { 0x02a0, 0x910035c7 },
213 { 0x0290, 0x00000004 },
214 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900215
Marek Vasut927b1e32018-04-30 14:10:36 +0200216 static const struct reg_config dbsc_config6[] = {
217 { 0x0290, 0x00000001 },
218 { 0x02a0, 0x00000181 },
219 { 0x0018, 0x11000000 },
220 { 0x0290, 0x00000004 },
221 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900222
Marek Vasut927b1e32018-04-30 14:10:36 +0200223 static const struct reg_config dbsc_config7[] = {
224 { 0x0290, 0x00000001 },
225 { 0x02a0, 0x0000fe01 },
226 { 0x0304, 0x00000000 },
227 { 0x00f4, 0x01004c20 },
228 { 0x00f8, 0x014000aa },
229 { 0x00e0, 0x00000140 },
230 { 0x00e4, 0x00081860 },
231 { 0x00e8, 0x00010000 },
232 { 0x0290, 0x00000004 },
233 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900234
Marek Vasut927b1e32018-04-30 14:10:36 +0200235 static const struct reg_config dbsc_config8[] = {
236 { 0x0014, 0x00000001 },
237 { 0x0010, 0x00000001 },
238 { 0x0280, 0x00000000 },
239 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900240
Marek Vasut927b1e32018-04-30 14:10:36 +0200241 static const u32 dbsc3_0_base = DBSC3_0_BASE;
242 unsigned int i;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900243
Marek Vasut927b1e32018-04-30 14:10:36 +0200244 for (i = 0; i < ARRAY_SIZE(dbsc_config1); i++)
245 writel(dbsc_config1[i].val, dbsc3_0_base | dbsc_config1[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900246
Marek Vasut927b1e32018-04-30 14:10:36 +0200247 dbsc_wait(0x2a0);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900248
Marek Vasut927b1e32018-04-30 14:10:36 +0200249 for (i = 0; i < ARRAY_SIZE(dbsc_config2); i++)
250 writel(dbsc_config2[i].val, dbsc3_0_base | dbsc_config2[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900251
Marek Vasut927b1e32018-04-30 14:10:36 +0200252 for (i = 0; i < ARRAY_SIZE(dbsc_config4); i++)
253 writel(dbsc_config4[i].val, dbsc3_0_base | dbsc_config4[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900254
Marek Vasut927b1e32018-04-30 14:10:36 +0200255 dbsc_wait(0x240);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900256
Marek Vasut927b1e32018-04-30 14:10:36 +0200257 for (i = 0; i < ARRAY_SIZE(dbsc_config5); i++)
258 writel(dbsc_config5[i].val, dbsc3_0_base | dbsc_config5[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900259
Marek Vasut927b1e32018-04-30 14:10:36 +0200260 dbsc_wait(0x2a0);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900261
Marek Vasut927b1e32018-04-30 14:10:36 +0200262 for (i = 0; i < ARRAY_SIZE(dbsc_config6); i++)
263 writel(dbsc_config6[i].val, dbsc3_0_base | dbsc_config6[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900264
Marek Vasut927b1e32018-04-30 14:10:36 +0200265 dbsc_wait(0x2a0);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900266
Marek Vasut927b1e32018-04-30 14:10:36 +0200267 for (i = 0; i < ARRAY_SIZE(dbsc_config7); i++)
268 writel(dbsc_config7[i].val, dbsc3_0_base | dbsc_config7[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900269
Marek Vasut927b1e32018-04-30 14:10:36 +0200270 dbsc_wait(0x2a0);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900271
Marek Vasut927b1e32018-04-30 14:10:36 +0200272 for (i = 0; i < ARRAY_SIZE(dbsc_config8); i++)
273 writel(dbsc_config8[i].val, dbsc3_0_base | dbsc_config8[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900274
Marek Vasut927b1e32018-04-30 14:10:36 +0200275}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900276
Marek Vasut927b1e32018-04-30 14:10:36 +0200277static void s_init_wait(volatile unsigned int cnt)
278{
279 volatile u32 i = cnt * 0x10000;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900280
Marek Vasut927b1e32018-04-30 14:10:36 +0200281 while (i-- > 0)
282 ;
283}
284#endif
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900285
Marek Vasut927b1e32018-04-30 14:10:36 +0200286void s_init(void)
287{
288 blanche_init_sys();
289 qos_init();
290 blanche_init_pfc();
291 blanche_init_lbsc();
292#if defined(CONFIG_MTD_NOR_FLASH)
293 s_init_wait(10);
294 blanche_init_dbsc();
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900295#endif /* CONFIG_MTD_NOR_FLASH */
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900296}
297
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900298int board_early_init_f(void)
299{
300 /* TMU0 */
301 mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900302 /* QSPI */
303 mstp_clrbits_le32(MSTPSR9, SMSTPCR9, QSPI_MSTP917);
304
305 return 0;
306}
307
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900308int board_init(void)
309{
310 /* adress of boot parameters */
311 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
312
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900313 return 0;
314}
315
Marek Vasut927b1e32018-04-30 14:10:36 +0200316/* Added for BLANCHE(R-CarV2H board) */
Marek Vasut91691452020-03-21 17:38:57 +0100317#ifndef CONFIG_DM_ETH
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900318int board_eth_init(bd_t *bis)
319{
320 int rc = 0;
321
322#ifdef CONFIG_SMC911X
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900323 struct eth_device *dev;
324 uchar eth_addr[6];
325
326 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
327
Marek Vasut927b1e32018-04-30 14:10:36 +0200328 if (!eth_env_get_enetaddr("ethaddr", eth_addr)) {
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900329 dev = eth_get_dev_by_index(0);
330 if (dev) {
Marek Vasut927b1e32018-04-30 14:10:36 +0200331 eth_env_set_enetaddr("ethaddr", dev->enetaddr);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900332 } else {
333 printf("blanche: Couldn't get eth device\n");
334 rc = -1;
335 }
336 }
337
338#endif
339
340 return rc;
341}
Marek Vasut91691452020-03-21 17:38:57 +0100342#endif
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900343
Marek Vasut927b1e32018-04-30 14:10:36 +0200344int dram_init(void)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900345{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530346 if (fdtdec_setup_mem_size_base() != 0)
Marek Vasut927b1e32018-04-30 14:10:36 +0200347 return -EINVAL;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900348
Marek Vasut927b1e32018-04-30 14:10:36 +0200349 return 0;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900350}
351
Marek Vasut927b1e32018-04-30 14:10:36 +0200352int dram_init_banksize(void)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900353{
Marek Vasut927b1e32018-04-30 14:10:36 +0200354 fdtdec_setup_memory_banksize();
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900355
356 return 0;
357}
358
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900359void reset_cpu(ulong addr)
360{
Marek Vasut24700a22020-03-21 16:57:58 +0100361 struct udevice *dev;
362 const u8 pmic_bus = 6;
363 const u8 pmic_addr = 0x58;
364 u8 data;
365 int ret;
366
367 ret = i2c_get_chip_for_busnum(pmic_bus, pmic_addr, 1, &dev);
368 if (ret)
369 hang();
370
371 ret = dm_i2c_read(dev, 0x13, &data, 1);
372 if (ret)
373 hang();
374
375 data |= BIT(1);
376
377 ret = dm_i2c_write(dev, 0x13, &data, 1);
378 if (ret)
379 hang();
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900380}