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 <cpu_func.h>
11#include <image.h>
12#include <init.h>
13#include <malloc.h>
14#include <netdev.h>
15#include <dm.h>
16#include <asm/global_data.h>
17#include <dm/platform_data/serial_sh.h>
18#include <asm/processor.h>
19#include <asm/mach-types.h>
20#include <asm/io.h>
21#include <linux/bitops.h>
22#include <linux/errno.h>
23#include <asm/arch/sys_proto.h>
24#include <asm/gpio.h>
25#include <asm/arch/gpio.h>
26#include <asm/arch/renesas.h>
27#include <asm/arch/rcar-mstp.h>
28#include <i2c.h>
29#include <mmc.h>
30
31DECLARE_GLOBAL_DATA_PTR;
32
33#define DVFS_MSTP926		BIT(26)
34#define HSUSB_MSTP704		BIT(4)	/* HSUSB */
35
36int board_early_init_f(void)
37{
38#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) && defined(CONFIG_SYS_I2C_SH)
39	/* DVFS for reset */
40	mstp_clrbits_le32(SMSTPCR9, SMSTPCR9, DVFS_MSTP926);
41#endif
42	return 0;
43}
44
45/* 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
52int board_init(void)
53{
54	/* USB1 pull-up */
55	setbits_le32(PFC_PUEN6, PUEN_USB1_OVC | PUEN_USB1_PWEN);
56
57	/* Configure the HSUSB block */
58	mstp_clrbits_le32(SMSTPCR7, SMSTPCR7, HSUSB_MSTP704);
59	/* 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
65	return 0;
66}
67
68#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) && defined(CONFIG_SYS_I2C_SH)
69void reset_cpu(void)
70{
71	i2c_reg_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x20, 0x80);
72}
73#endif
74
75#ifdef CONFIG_MULTI_DTB_FIT
76int board_fit_config_name_match(const char *name)
77{
78	/* PRR driver is not available yet */
79	u32 cpu_type = renesas_get_cpu_type();
80
81	if ((cpu_type == RENESAS_CPU_TYPE_R8A7795) &&
82	    !strcmp(name, "r8a77951-salvator-x"))
83		return 0;
84
85	if ((cpu_type == RENESAS_CPU_TYPE_R8A7796) &&
86	    !strcmp(name, "r8a77960-salvator-x"))
87		return 0;
88
89	if ((cpu_type == RENESAS_CPU_TYPE_R8A77965) &&
90	    !strcmp(name, "r8a77965-salvator-x"))
91		return 0;
92
93	return -1;
94}
95#endif
96