blob: 01571625e71df3386d6dff6b250e0048e3819af2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +09002/*
3 * board/renesas/salvator-x/salvator-x.c
Marek Vasut237dadd2017-05-13 15:57:53 +02004 * This file is Salvator-X/Salvator-XS board support.
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +09005 *
Marek Vasut5abb39b2017-05-13 15:57:46 +02006 * Copyright (C) 2015-2017 Renesas Electronics Corporation
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +09007 * Copyright (C) 2015 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +09008 */
9
Simon Glassafb02152019-12-28 10:45:01 -070010#include <cpu_func.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090013#include <malloc.h>
14#include <netdev.h>
15#include <dm.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090017#include <dm/platform_data/serial_sh.h>
18#include <asm/processor.h>
19#include <asm/mach-types.h>
20#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060021#include <linux/bitops.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090022#include <linux/errno.h>
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090023#include <asm/arch/sys_proto.h>
24#include <asm/gpio.h>
25#include <asm/arch/gpio.h>
26#include <asm/arch/rmobile.h>
27#include <asm/arch/rcar-mstp.h>
28#include <i2c.h>
29#include <mmc.h>
30
31DECLARE_GLOBAL_DATA_PTR;
32
Marek Vasutc16ed0b2017-05-13 15:57:48 +020033#define DVFS_MSTP926 BIT(26)
Marek Vasut32fd3ba2017-09-12 19:07:21 +020034#define HSUSB_MSTP704 BIT(4) /* HSUSB */
Marek Vasut5abb39b2017-05-13 15:57:46 +020035
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090036int board_early_init_f(void)
37{
Tom Rini52b2e262021-08-18 23:12:24 -040038#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) && defined(CONFIG_SYS_I2C_SH)
Marek Vasutc16ed0b2017-05-13 15:57:48 +020039 /* DVFS for reset */
Hiroyuki Yokoyama7e172912018-09-26 16:00:09 +090040 mstp_clrbits_le32(SMSTPCR9, SMSTPCR9, DVFS_MSTP926);
Marek Vasutc16ed0b2017-05-13 15:57:48 +020041#endif
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090042 return 0;
43}
44
Marek Vasut32fd3ba2017-09-12 19:07:21 +020045/* HSUSB block registers */
46#define HSUSB_REG_LPSTS 0xE6590102
47#define HSUSB_REG_LPSTS_SUSPM_NORMAL BIT(14)
48#define HSUSB_REG_UGCTRL2 0xE6590184
49#define HSUSB_REG_UGCTRL2_USB0SEL 0x30
50#define HSUSB_REG_UGCTRL2_USB0SEL_EHCI 0x10
51
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090052int board_init(void)
53{
Marek Vasut4659a622017-05-13 15:57:49 +020054 /* USB1 pull-up */
55 setbits_le32(PFC_PUEN6, PUEN_USB1_OVC | PUEN_USB1_PWEN);
56
Marek Vasut32fd3ba2017-09-12 19:07:21 +020057 /* Configure the HSUSB block */
Hiroyuki Yokoyama7e172912018-09-26 16:00:09 +090058 mstp_clrbits_le32(SMSTPCR7, SMSTPCR7, HSUSB_MSTP704);
Marek Vasut32fd3ba2017-09-12 19:07:21 +020059 /* Choice USB0SEL */
60 clrsetbits_le32(HSUSB_REG_UGCTRL2, HSUSB_REG_UGCTRL2_USB0SEL,
61 HSUSB_REG_UGCTRL2_USB0SEL_EHCI);
62 /* low power status */
63 setbits_le16(HSUSB_REG_LPSTS, HSUSB_REG_LPSTS_SUSPM_NORMAL);
64
Marek Vasutc9afcf62017-08-20 17:13:47 +020065 return 0;
Marek Vasut5abb39b2017-05-13 15:57:46 +020066}
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090067
Marek Vasut78cea932023-05-31 20:10:28 +020068#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) && defined(CONFIG_SYS_I2C_SH)
Harald Seiler6f14d5f2020-12-15 16:47:52 +010069void reset_cpu(void)
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090070{
Marek Vasutc16ed0b2017-05-13 15:57:48 +020071 i2c_reg_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x20, 0x80);
Nobuhiro Iwamatsufdf7c652016-04-01 03:51:36 +090072}
Marek Vasut78cea932023-05-31 20:10:28 +020073#endif
Marek Vasut7dd7b492018-10-18 20:30:00 +020074
75#ifdef CONFIG_MULTI_DTB_FIT
76int board_fit_config_name_match(const char *name)
77{
78 /* PRR driver is not available yet */
Marek Vasut30fe98e2024-02-27 17:05:45 +010079 u32 cpu_type = renesas_get_cpu_type();
Marek Vasut7dd7b492018-10-18 20:30:00 +020080
81 if ((cpu_type == RMOBILE_CPU_TYPE_R8A7795) &&
Marek Vasutadaa0162020-04-04 16:12:48 +020082 !strcmp(name, "r8a77950-salvator-x-u-boot"))
Marek Vasut7dd7b492018-10-18 20:30:00 +020083 return 0;
84
85 if ((cpu_type == RMOBILE_CPU_TYPE_R8A7796) &&
Marek Vasutadaa0162020-04-04 16:12:48 +020086 !strcmp(name, "r8a77960-salvator-x-u-boot"))
Marek Vasut7dd7b492018-10-18 20:30:00 +020087 return 0;
88
89 if ((cpu_type == RMOBILE_CPU_TYPE_R8A77965) &&
90 !strcmp(name, "r8a77965-salvator-x-u-boot"))
91 return 0;
92
93 return -1;
94}
95#endif