blob: 8e1ae29e2219ec30cdd38224766f309995574938 [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>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <net.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020013#include <asm/arch/mmc.h>
14#include <asm/arch/rcar-mstp.h>
15#include <asm/arch/rmobile.h>
16#include <asm/arch/sh_sdhi.h>
17#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020019#include <asm/gpio.h>
20#include <asm/io.h>
21#include <asm/mach-types.h>
22#include <asm/processor.h>
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090023#include <dm.h>
24#include <dm/platform_data/serial_sh.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060025#include <env.h>
Marek Vasut24700a22020-03-21 16:57:58 +010026#include <hang.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020027#include <i2c.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060028#include <linux/bitops.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090029#include <linux/errno.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020030#include <malloc.h>
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090031#include <miiphy.h>
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090032#include <mmc.h>
Marek Vasut927b1e32018-04-30 14:10:36 +020033#include <netdev.h>
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090034#include "qos.h"
35
36DECLARE_GLOBAL_DATA_PTR;
37
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090038#define CPG_PLL1CR 0xE6150028
39#define CPG_PLL3CR 0xE61500DC
40
Marek Vasut927b1e32018-04-30 14:10:36 +020041#define TMU0_MSTP125 BIT(25)
42#define QSPI_MSTP917 BIT(17)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090043
Marek Vasut927b1e32018-04-30 14:10:36 +020044struct reg_config {
45 u16 off;
46 u32 val;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090047};
48
Marek Vasut927b1e32018-04-30 14:10:36 +020049static void blanche_init_sys(void)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090050{
51 struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
52 struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
53 u32 cpu_type;
54
55 cpu_type = rmobile_get_cpu_type();
56 if (cpu_type == 0x4A) {
57 writel(0x4D000000, CPG_PLL1CR);
58 writel(0x4F000000, CPG_PLL3CR);
59 }
60
61 /* Watchdog init */
62 writel(0xA5A5A500, &rwdt->rwtcsra);
63 writel(0xA5A5A500, &swdt->swtcsra);
Marek Vasut927b1e32018-04-30 14:10:36 +020064}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090065
Marek Vasut927b1e32018-04-30 14:10:36 +020066static void blanche_init_pfc(void)
67{
68 static const struct reg_config pfc_with_unlock[] = {
69 { 0x0004, 0x0bffffff },
70 { 0x0008, 0x002fffff },
71 { 0x0014, 0x00000fff },
72 { 0x0018, 0x00010fff },
73 { 0x001c, 0x00010fff },
74 { 0x0020, 0x00010fff },
75 { 0x0024, 0x00010fff },
76 { 0x0028, 0x00010fff },
77 { 0x002c, 0x04006000 },
78 { 0x0030, 0x303fefe0 },
79 { 0x0058, 0x0002000e },
80 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090081
Marek Vasut927b1e32018-04-30 14:10:36 +020082 static const struct reg_config pfc_without_unlock[] = {
83 { 0x0108, 0x00000000 },
84 { 0x010c, 0x0803FF40 },
85 { 0x0110, 0x0000FFFF },
86 { 0x0114, 0x00010FFF },
87 { 0x011c, 0x0001AFFF },
88 { 0x0124, 0x0001CFFF },
89 { 0x0128, 0xC0438001 },
90 { 0x012c, 0x0FC00007 },
91 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090092
Marek Vasut927b1e32018-04-30 14:10:36 +020093 static const u32 pfc_base = 0xe6060000;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090094
Marek Vasut927b1e32018-04-30 14:10:36 +020095 unsigned int i;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +090096
Marek Vasut927b1e32018-04-30 14:10:36 +020097 for (i = 0; i < ARRAY_SIZE(pfc_with_unlock); i++) {
98 writel(~pfc_with_unlock[i].val, pfc_base);
99 writel(pfc_with_unlock[i].val,
100 pfc_base | pfc_with_unlock[i].off);
101 }
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900102
Marek Vasut927b1e32018-04-30 14:10:36 +0200103 for (i = 0; i < ARRAY_SIZE(pfc_without_unlock); i++)
104 writel(pfc_without_unlock[i].val,
105 pfc_base | pfc_without_unlock[i].off);
106}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900107
Marek Vasut927b1e32018-04-30 14:10:36 +0200108static void blanche_init_lbsc(void)
109{
110 static const struct reg_config lbsc_config[] = {
111 { 0x00, 0x00000020 },
112 { 0x08, 0x00002020 },
113 { 0x30, 0x2a103320 },
114 { 0x38, 0x19102110 },
115 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900116
Marek Vasut927b1e32018-04-30 14:10:36 +0200117 static const u32 lbsc_base = 0xfec00200;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900118
Marek Vasut927b1e32018-04-30 14:10:36 +0200119 unsigned int i;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900120
Marek Vasut927b1e32018-04-30 14:10:36 +0200121 for (i = 0; i < ARRAY_SIZE(lbsc_config); i++) {
122 writel(lbsc_config[i].val,
123 lbsc_base | lbsc_config[i].off);
124 writel(lbsc_config[i].val,
125 lbsc_base | (lbsc_config[i].off + 4));
126 }
127}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900128
Marek Vasut927b1e32018-04-30 14:10:36 +0200129#if defined(CONFIG_MTD_NOR_FLASH)
130static void dbsc_wait(u16 reg)
131{
132 static const u32 dbsc3_0_base = DBSC3_0_BASE;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900133
Marek Vasut927b1e32018-04-30 14:10:36 +0200134 while (!(readl(dbsc3_0_base + reg) & BIT(0)))
135 ;
136}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900137
Marek Vasut927b1e32018-04-30 14:10:36 +0200138static void blanche_init_dbsc(void)
139{
140 static const struct reg_config dbsc_config1[] = {
141 { 0x0280, 0x0000a55a },
142 { 0x0018, 0x21000000 },
143 { 0x0018, 0x11000000 },
144 { 0x0018, 0x10000000 },
145 { 0x0290, 0x00000001 },
146 { 0x02a0, 0x80000000 },
147 { 0x0290, 0x00000004 },
148 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900149
Marek Vasut927b1e32018-04-30 14:10:36 +0200150 static const struct reg_config dbsc_config2[] = {
151 { 0x0290, 0x00000006 },
152 { 0x02a0, 0x0001c000 },
153 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900154
Marek Vasut927b1e32018-04-30 14:10:36 +0200155 static const struct reg_config dbsc_config4[] = {
156 { 0x0290, 0x0000000f },
157 { 0x02a0, 0x00181ee4 },
158 { 0x0290, 0x00000010 },
159 { 0x02a0, 0xf00464db },
160 { 0x0290, 0x00000061 },
161 { 0x02a0, 0x0000008d },
162 { 0x0290, 0x00000001 },
163 { 0x02a0, 0x00000073 },
164 { 0x0020, 0x00000007 },
165 { 0x0024, 0x0f030a02 },
166 { 0x0030, 0x00000001 },
167 { 0x00b0, 0x00000000 },
168 { 0x0040, 0x0000000b },
169 { 0x0044, 0x00000008 },
170 { 0x0048, 0x00000000 },
171 { 0x0050, 0x0000000b },
172 { 0x0054, 0x000c000b },
173 { 0x0058, 0x00000027 },
174 { 0x005c, 0x0000001c },
175 { 0x0060, 0x00000006 },
176 { 0x0064, 0x00000020 },
177 { 0x0068, 0x00000008 },
178 { 0x006c, 0x0000000c },
179 { 0x0070, 0x00000009 },
180 { 0x0074, 0x00000012 },
181 { 0x0078, 0x000000d0 },
182 { 0x007c, 0x00140005 },
183 { 0x0080, 0x00050004 },
184 { 0x0084, 0x70233005 },
185 { 0x0088, 0x000c0000 },
186 { 0x008c, 0x00000300 },
187 { 0x0090, 0x00000040 },
188 { 0x0100, 0x00000001 },
189 { 0x00c0, 0x00020001 },
190 { 0x00c8, 0x20082004 },
191 { 0x0380, 0x00020002 },
192 { 0x0390, 0x0000001f },
193 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900194
Marek Vasut927b1e32018-04-30 14:10:36 +0200195 static const struct reg_config dbsc_config5[] = {
196 { 0x0244, 0x00000011 },
197 { 0x0290, 0x00000003 },
198 { 0x02a0, 0x0300c4e1 },
199 { 0x0290, 0x00000023 },
200 { 0x02a0, 0x00fcdb60 },
201 { 0x0290, 0x00000011 },
202 { 0x02a0, 0x1000040b },
203 { 0x0290, 0x00000012 },
204 { 0x02a0, 0x9d9cbb66 },
205 { 0x0290, 0x00000013 },
206 { 0x02a0, 0x1a868400 },
207 { 0x0290, 0x00000014 },
208 { 0x02a0, 0x300214d8 },
209 { 0x0290, 0x00000015 },
210 { 0x02a0, 0x00000d70 },
211 { 0x0290, 0x00000016 },
212 { 0x02a0, 0x00000004 },
213 { 0x0290, 0x00000017 },
214 { 0x02a0, 0x00000018 },
215 { 0x0290, 0x0000001a },
216 { 0x02a0, 0x910035c7 },
217 { 0x0290, 0x00000004 },
218 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900219
Marek Vasut927b1e32018-04-30 14:10:36 +0200220 static const struct reg_config dbsc_config6[] = {
221 { 0x0290, 0x00000001 },
222 { 0x02a0, 0x00000181 },
223 { 0x0018, 0x11000000 },
224 { 0x0290, 0x00000004 },
225 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900226
Marek Vasut927b1e32018-04-30 14:10:36 +0200227 static const struct reg_config dbsc_config7[] = {
228 { 0x0290, 0x00000001 },
229 { 0x02a0, 0x0000fe01 },
230 { 0x0304, 0x00000000 },
231 { 0x00f4, 0x01004c20 },
232 { 0x00f8, 0x014000aa },
233 { 0x00e0, 0x00000140 },
234 { 0x00e4, 0x00081860 },
235 { 0x00e8, 0x00010000 },
236 { 0x0290, 0x00000004 },
237 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900238
Marek Vasut927b1e32018-04-30 14:10:36 +0200239 static const struct reg_config dbsc_config8[] = {
240 { 0x0014, 0x00000001 },
241 { 0x0010, 0x00000001 },
242 { 0x0280, 0x00000000 },
243 };
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900244
Marek Vasut927b1e32018-04-30 14:10:36 +0200245 static const u32 dbsc3_0_base = DBSC3_0_BASE;
246 unsigned int i;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900247
Marek Vasut927b1e32018-04-30 14:10:36 +0200248 for (i = 0; i < ARRAY_SIZE(dbsc_config1); i++)
249 writel(dbsc_config1[i].val, dbsc3_0_base | dbsc_config1[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900250
Marek Vasut927b1e32018-04-30 14:10:36 +0200251 dbsc_wait(0x2a0);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900252
Marek Vasut927b1e32018-04-30 14:10:36 +0200253 for (i = 0; i < ARRAY_SIZE(dbsc_config2); i++)
254 writel(dbsc_config2[i].val, dbsc3_0_base | dbsc_config2[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900255
Marek Vasut927b1e32018-04-30 14:10:36 +0200256 for (i = 0; i < ARRAY_SIZE(dbsc_config4); i++)
257 writel(dbsc_config4[i].val, dbsc3_0_base | dbsc_config4[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900258
Marek Vasut927b1e32018-04-30 14:10:36 +0200259 dbsc_wait(0x240);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900260
Marek Vasut927b1e32018-04-30 14:10:36 +0200261 for (i = 0; i < ARRAY_SIZE(dbsc_config5); i++)
262 writel(dbsc_config5[i].val, dbsc3_0_base | dbsc_config5[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900263
Marek Vasut927b1e32018-04-30 14:10:36 +0200264 dbsc_wait(0x2a0);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900265
Marek Vasut927b1e32018-04-30 14:10:36 +0200266 for (i = 0; i < ARRAY_SIZE(dbsc_config6); i++)
267 writel(dbsc_config6[i].val, dbsc3_0_base | dbsc_config6[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900268
Marek Vasut927b1e32018-04-30 14:10:36 +0200269 dbsc_wait(0x2a0);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900270
Marek Vasut927b1e32018-04-30 14:10:36 +0200271 for (i = 0; i < ARRAY_SIZE(dbsc_config7); i++)
272 writel(dbsc_config7[i].val, dbsc3_0_base | dbsc_config7[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900273
Marek Vasut927b1e32018-04-30 14:10:36 +0200274 dbsc_wait(0x2a0);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900275
Marek Vasut927b1e32018-04-30 14:10:36 +0200276 for (i = 0; i < ARRAY_SIZE(dbsc_config8); i++)
277 writel(dbsc_config8[i].val, dbsc3_0_base | dbsc_config8[i].off);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900278
Marek Vasut927b1e32018-04-30 14:10:36 +0200279}
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900280
Marek Vasut927b1e32018-04-30 14:10:36 +0200281static void s_init_wait(volatile unsigned int cnt)
282{
283 volatile u32 i = cnt * 0x10000;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900284
Marek Vasut927b1e32018-04-30 14:10:36 +0200285 while (i-- > 0)
286 ;
287}
288#endif
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900289
Marek Vasut927b1e32018-04-30 14:10:36 +0200290void s_init(void)
291{
292 blanche_init_sys();
293 qos_init();
294 blanche_init_pfc();
295 blanche_init_lbsc();
296#if defined(CONFIG_MTD_NOR_FLASH)
297 s_init_wait(10);
298 blanche_init_dbsc();
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900299#endif /* CONFIG_MTD_NOR_FLASH */
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900300}
301
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900302int board_early_init_f(void)
303{
304 /* TMU0 */
305 mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900306 /* QSPI */
307 mstp_clrbits_le32(MSTPSR9, SMSTPCR9, QSPI_MSTP917);
308
309 return 0;
310}
311
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900312int board_init(void)
313{
314 /* adress of boot parameters */
Tom Rinibb4dd962022-11-16 13:10:37 -0500315 gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900316
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900317 return 0;
318}
319
Marek Vasut927b1e32018-04-30 14:10:36 +0200320/* Added for BLANCHE(R-CarV2H board) */
Marek Vasut91691452020-03-21 17:38:57 +0100321#ifndef CONFIG_DM_ETH
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900322int board_eth_init(struct bd_info *bis)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900323{
324 int rc = 0;
325
326#ifdef CONFIG_SMC911X
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900327 struct eth_device *dev;
328 uchar eth_addr[6];
329
Tom Rini364d0022023-01-10 11:19:45 -0500330 rc = smc911x_initialize(0, CFG_SMC911X_BASE);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900331
Marek Vasut927b1e32018-04-30 14:10:36 +0200332 if (!eth_env_get_enetaddr("ethaddr", eth_addr)) {
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900333 dev = eth_get_dev_by_index(0);
334 if (dev) {
Marek Vasut927b1e32018-04-30 14:10:36 +0200335 eth_env_set_enetaddr("ethaddr", dev->enetaddr);
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900336 } else {
337 printf("blanche: Couldn't get eth device\n");
338 rc = -1;
339 }
340 }
341
342#endif
343
344 return rc;
345}
Marek Vasut91691452020-03-21 17:38:57 +0100346#endif
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900347
Marek Vasut927b1e32018-04-30 14:10:36 +0200348int dram_init(void)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900349{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530350 if (fdtdec_setup_mem_size_base() != 0)
Marek Vasut927b1e32018-04-30 14:10:36 +0200351 return -EINVAL;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900352
Marek Vasut927b1e32018-04-30 14:10:36 +0200353 return 0;
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900354}
355
Marek Vasut927b1e32018-04-30 14:10:36 +0200356int dram_init_banksize(void)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900357{
Marek Vasut927b1e32018-04-30 14:10:36 +0200358 fdtdec_setup_memory_banksize();
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900359
360 return 0;
361}
362
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100363void reset_cpu(void)
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900364{
Marek Vasut24700a22020-03-21 16:57:58 +0100365 struct udevice *dev;
366 const u8 pmic_bus = 6;
367 const u8 pmic_addr = 0x58;
368 u8 data;
369 int ret;
370
371 ret = i2c_get_chip_for_busnum(pmic_bus, pmic_addr, 1, &dev);
372 if (ret)
373 hang();
374
375 ret = dm_i2c_read(dev, 0x13, &data, 1);
376 if (ret)
377 hang();
378
379 data |= BIT(1);
380
381 ret = dm_i2c_write(dev, 0x13, &data, 1);
382 if (ret)
383 hang();
masakazu.mochizuki.wd@hitachi.com9d0e9372016-04-12 17:11:41 +0900384}