1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * board/renesas/salvator-x/salvator-x.c
4  *     This file is Salvator-X/Salvator-XS board support.
5  *
6  * Copyright (C) 2015-2017 Renesas Electronics Corporation
7  * Copyright (C) 2015 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
8  */
9 
10 #include <common.h>
11 #include <malloc.h>
12 #include <netdev.h>
13 #include <dm.h>
14 #include <dm/platform_data/serial_sh.h>
15 #include <asm/processor.h>
16 #include <asm/mach-types.h>
17 #include <asm/io.h>
18 #include <linux/errno.h>
19 #include <asm/arch/sys_proto.h>
20 #include <asm/gpio.h>
21 #include <asm/arch/gpio.h>
22 #include <asm/arch/rmobile.h>
23 #include <asm/arch/rcar-mstp.h>
24 #include <asm/arch/sh_sdhi.h>
25 #include <i2c.h>
26 #include <mmc.h>
27 
28 DECLARE_GLOBAL_DATA_PTR;
29 
30 void s_init(void)
31 {
32 }
33 
34 #define DVFS_MSTP926		BIT(26)
35 #define HSUSB_MSTP704		BIT(4)	/* HSUSB */
36 
37 int board_early_init_f(void)
38 {
39 #if defined(CONFIG_SYS_I2C) && defined(CONFIG_SYS_I2C_SH)
40 	/* DVFS for reset */
41 	mstp_clrbits_le32(SMSTPCR9, SMSTPCR9, DVFS_MSTP926);
42 #endif
43 	return 0;
44 }
45 
46 /* HSUSB block registers */
47 #define HSUSB_REG_LPSTS			0xE6590102
48 #define HSUSB_REG_LPSTS_SUSPM_NORMAL	BIT(14)
49 #define HSUSB_REG_UGCTRL2		0xE6590184
50 #define HSUSB_REG_UGCTRL2_USB0SEL	0x30
51 #define HSUSB_REG_UGCTRL2_USB0SEL_EHCI	0x10
52 
53 int board_init(void)
54 {
55 	/* adress of boot parameters */
56 	gd->bd->bi_boot_params = CONFIG_SYS_TEXT_BASE + 0x50000;
57 
58 	/* USB1 pull-up */
59 	setbits_le32(PFC_PUEN6, PUEN_USB1_OVC | PUEN_USB1_PWEN);
60 
61 	/* Configure the HSUSB block */
62 	mstp_clrbits_le32(SMSTPCR7, SMSTPCR7, HSUSB_MSTP704);
63 	/* Choice USB0SEL */
64 	clrsetbits_le32(HSUSB_REG_UGCTRL2, HSUSB_REG_UGCTRL2_USB0SEL,
65 			HSUSB_REG_UGCTRL2_USB0SEL_EHCI);
66 	/* low power status */
67 	setbits_le16(HSUSB_REG_LPSTS, HSUSB_REG_LPSTS_SUSPM_NORMAL);
68 
69 	return 0;
70 }
71 
72 int dram_init(void)
73 {
74 	if (fdtdec_setup_mem_size_base() != 0)
75 		return -EINVAL;
76 
77 	return 0;
78 }
79 
80 int dram_init_banksize(void)
81 {
82 	fdtdec_setup_memory_banksize();
83 
84 	return 0;
85 }
86 
87 #define RST_BASE	0xE6160000
88 #define RST_CA57RESCNT	(RST_BASE + 0x40)
89 #define RST_CA53RESCNT	(RST_BASE + 0x44)
90 #define RST_RSTOUTCR	(RST_BASE + 0x58)
91 #define RST_CODE	0xA5A5000F
92 
93 void reset_cpu(ulong addr)
94 {
95 #if defined(CONFIG_SYS_I2C) && defined(CONFIG_SYS_I2C_SH)
96 	i2c_reg_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x20, 0x80);
97 #else
98 	/* only CA57 ? */
99 	writel(RST_CODE, RST_CA57RESCNT);
100 #endif
101 }
102 
103 #ifdef CONFIG_MULTI_DTB_FIT
104 int board_fit_config_name_match(const char *name)
105 {
106 	/* PRR driver is not available yet */
107 	u32 cpu_type = rmobile_get_cpu_type();
108 
109 	if ((cpu_type == RMOBILE_CPU_TYPE_R8A7795) &&
110 	    !strcmp(name, "r8a7795-salvator-x-u-boot"))
111 		return 0;
112 
113 	if ((cpu_type == RMOBILE_CPU_TYPE_R8A7796) &&
114 	    !strcmp(name, "r8a7796-salvator-x-u-boot"))
115 		return 0;
116 
117 	if ((cpu_type == RMOBILE_CPU_TYPE_R8A77965) &&
118 	    !strcmp(name, "r8a77965-salvator-x-u-boot"))
119 		return 0;
120 
121 	return -1;
122 }
123 #endif
124