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