xref: /openbmc/u-boot/board/renesas/draak/draak.c (revision 6f565821)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * board/renesas/draak/draak.c
4  *     This file is Draak board support.
5  *
6  * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
7  */
8 
9 #include <common.h>
10 #include <malloc.h>
11 #include <netdev.h>
12 #include <dm.h>
13 #include <dm/platform_data/serial_sh.h>
14 #include <asm/processor.h>
15 #include <asm/mach-types.h>
16 #include <asm/io.h>
17 #include <linux/errno.h>
18 #include <asm/arch/sys_proto.h>
19 #include <asm/gpio.h>
20 #include <asm/arch/gpio.h>
21 #include <asm/arch/rmobile.h>
22 #include <asm/arch/rcar-mstp.h>
23 #include <asm/arch/sh_sdhi.h>
24 #include <i2c.h>
25 #include <mmc.h>
26 
27 DECLARE_GLOBAL_DATA_PTR;
28 
29 #define CPGWPCR	0xE6150904
30 #define CPGWPR  0xE6150900
31 
32 #define CLK2MHZ(clk)	(clk / 1000 / 1000)
33 void s_init(void)
34 {
35 	struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
36 	struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
37 
38 	/* Watchdog init */
39 	writel(0xA5A5A500, &rwdt->rwtcsra);
40 	writel(0xA5A5A500, &swdt->swtcsra);
41 
42 	writel(0x5A5AFFFF, CPGWPR);
43 	writel(0xA5A50000, CPGWPCR);
44 }
45 
46 #define GSX_MSTP112		BIT(12)	/* 3DG */
47 #define SCIF2_MSTP310		BIT(10)	/* SCIF2 */
48 #define DVFS_MSTP926		BIT(26)
49 #define HSUSB_MSTP704		BIT(4)	/* HSUSB */
50 
51 int board_early_init_f(void)
52 {
53 #if defined(CONFIG_SYS_I2C) && defined(CONFIG_SYS_I2C_SH)
54 	/* DVFS for reset */
55 	mstp_clrbits_le32(MSTPSR9, SMSTPCR9, DVFS_MSTP926);
56 #endif
57 	return 0;
58 }
59 
60 /* SYSC */
61 /* R/- 32 Power status register 2(3DG) */
62 #define	SYSC_PWRSR2	0xE6180100
63 /* -/W 32 Power resume control register 2 (3DG) */
64 #define	SYSC_PWRONCR2	0xE618010C
65 
66 /* HSUSB block registers */
67 #define HSUSB_REG_LPSTS			0xE6590102
68 #define HSUSB_REG_LPSTS_SUSPM_NORMAL	BIT(14)
69 #define HSUSB_REG_UGCTRL2		0xE6590184
70 #define HSUSB_REG_UGCTRL2_USB0SEL	0x30
71 #define HSUSB_REG_UGCTRL2_USB0SEL_EHCI	0x10
72 
73 int board_init(void)
74 {
75 	/* adress of boot parameters */
76 	gd->bd->bi_boot_params = CONFIG_SYS_TEXT_BASE + 0x50000;
77 
78 	/* USB1 pull-up */
79 	setbits_le32(PFC_PUEN6, PUEN_USB1_OVC | PUEN_USB1_PWEN);
80 
81 	/* Configure the HSUSB block */
82 	mstp_clrbits_le32(MSTPSR7, SMSTPCR7, HSUSB_MSTP704);
83 	/* Choice USB0SEL */
84 	clrsetbits_le32(HSUSB_REG_UGCTRL2, HSUSB_REG_UGCTRL2_USB0SEL,
85 			HSUSB_REG_UGCTRL2_USB0SEL_EHCI);
86 	/* low power status */
87 	setbits_le16(HSUSB_REG_LPSTS, HSUSB_REG_LPSTS_SUSPM_NORMAL);
88 
89 	return 0;
90 }
91 
92 int dram_init(void)
93 {
94 	if (fdtdec_setup_mem_size_base() != 0)
95 		return -EINVAL;
96 
97 	return 0;
98 }
99 
100 int dram_init_banksize(void)
101 {
102 	fdtdec_setup_memory_banksize();
103 
104 	return 0;
105 }
106 
107 #define RST_BASE	0xE6160000
108 #define RST_CA57RESCNT	(RST_BASE + 0x40)
109 #define RST_CA53RESCNT	(RST_BASE + 0x44)
110 #define RST_RSTOUTCR	(RST_BASE + 0x58)
111 #define RST_CA57_CODE	0xA5A5000F
112 #define RST_CA53_CODE	0x5A5A000F
113 
114 void reset_cpu(ulong addr)
115 {
116 	unsigned long midr, cputype;
117 
118 	asm volatile("mrs %0, midr_el1" : "=r" (midr));
119 	cputype = (midr >> 4) & 0xfff;
120 
121 	if (cputype == 0xd03)
122 		writel(RST_CA53_CODE, RST_CA53RESCNT);
123 	else if (cputype == 0xd07)
124 		writel(RST_CA57_CODE, RST_CA57RESCNT);
125 	else
126 		hang();
127 }
128