ARM: rmobile: salvator-x: Add RAVB ethernet support
[platform/kernel/u-boot.git] / board / renesas / salvator-x / salvator-x.c
1 /*
2  * board/renesas/salvator-x/salvator-x.c
3  *     This file is Salvator-X board support.
4  *
5  * Copyright (C) 2015-2017 Renesas Electronics Corporation
6  * Copyright (C) 2015 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
7  *
8  * SPDX-License-Identifier: GPL-2.0+
9  */
10
11 #include <common.h>
12 #include <malloc.h>
13 #include <netdev.h>
14 #include <dm.h>
15 #include <dm/platform_data/serial_sh.h>
16 #include <asm/processor.h>
17 #include <asm/mach-types.h>
18 #include <asm/io.h>
19 #include <linux/errno.h>
20 #include <asm/arch/sys_proto.h>
21 #include <asm/gpio.h>
22 #include <asm/arch/gpio.h>
23 #include <asm/arch/rmobile.h>
24 #include <asm/arch/rcar-mstp.h>
25 #include <asm/arch/sh_sdhi.h>
26 #include <i2c.h>
27 #include <mmc.h>
28
29 DECLARE_GLOBAL_DATA_PTR;
30
31 #define CPGWPCR 0xE6150904
32 #define CPGWPR  0xE615090C
33
34 #define CLK2MHZ(clk)    (clk / 1000 / 1000)
35 void s_init(void)
36 {
37         struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
38         struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
39
40         /* Watchdog init */
41         writel(0xA5A5A500, &rwdt->rwtcsra);
42         writel(0xA5A5A500, &swdt->swtcsra);
43
44         writel(0xA5A50000, CPGWPCR);
45         writel(0xFFFFFFFF, CPGWPR);
46 }
47
48 #define GSX_MSTP112             BIT(12) /* 3DG */
49 #define TMU0_MSTP125            BIT(25) /* secure */
50 #define TMU1_MSTP124            BIT(24) /* non-secure */
51 #define SCIF2_MSTP310           BIT(10) /* SCIF2 */
52 #define ETHERAVB_MSTP812        BIT(12)
53 #define SD0_MSTP314             BIT(14)
54 #define SD1_MSTP313             BIT(13)
55 #define SD2_MSTP312             BIT(12) /* either MMC0 */
56 #define SD3_MSTP311             BIT(11) /* either MMC1 */
57
58 #define SD0CKCR                 0xE6150074
59 #define SD1CKCR                 0xE6150078
60 #define SD2CKCR                 0xE6150268
61 #define SD3CKCR                 0xE615026C
62
63 int board_early_init_f(void)
64 {
65         /* TMU0,1 */            /* which use ? */
66         mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125 | TMU1_MSTP124);
67         /* SCIF2 */
68         mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SCIF2_MSTP310);
69         /* EHTERAVB */
70         mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHERAVB_MSTP812);
71         /* eMMC */
72         mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SD1_MSTP313 | SD2_MSTP312);
73         /* SDHI0, 3 */
74         mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SD0_MSTP314 | SD3_MSTP311);
75
76         writel(0, SD0CKCR);
77         writel(0, SD1CKCR);
78         writel(0, SD2CKCR);
79         writel(0, SD3CKCR);
80
81         return 0;
82 }
83
84 /* SYSC */
85 /* R/- 32 Power status register 2(3DG) */
86 #define SYSC_PWRSR2     0xE6180100
87 /* -/W 32 Power resume control register 2 (3DG) */
88 #define SYSC_PWRONCR2   0xE618010C
89
90 int board_init(void)
91 {
92         /* adress of boot parameters */
93         gd->bd->bi_boot_params = CONFIG_SYS_TEXT_BASE + 0x50000;
94
95         /* Init PFC controller */
96         r8a7795_pinmux_init();
97
98         /* GSX: force power and clock supply */
99         writel(0x0000001F, SYSC_PWRONCR2);
100         while (readl(SYSC_PWRSR2) != 0x000003E0)
101                 mdelay(20);
102
103         mstp_clrbits_le32(MSTPSR1, SMSTPCR1, GSX_MSTP112);
104
105 #ifdef CONFIG_RAVB
106         /* EtherAVB Enable */
107         /* GPSR2 */
108         gpio_request(GPIO_GFN_AVB_AVTP_CAPTURE_A, NULL);
109         gpio_request(GPIO_GFN_AVB_AVTP_MATCH_A, NULL);
110         gpio_request(GPIO_GFN_AVB_LINK, NULL);
111         gpio_request(GPIO_GFN_AVB_PHY_INT, NULL);
112         gpio_request(GPIO_GFN_AVB_MAGIC, NULL);
113         gpio_request(GPIO_GFN_AVB_MDC, NULL);
114
115         /* IPSR0 */
116         gpio_request(GPIO_IFN_AVB_MDC, NULL);
117         gpio_request(GPIO_IFN_AVB_MAGIC, NULL);
118         gpio_request(GPIO_IFN_AVB_PHY_INT, NULL);
119         gpio_request(GPIO_IFN_AVB_LINK, NULL);
120         gpio_request(GPIO_IFN_AVB_AVTP_MATCH_A, NULL);
121         gpio_request(GPIO_IFN_AVB_AVTP_CAPTURE_A, NULL);
122         /* IPSR1 */
123         gpio_request(GPIO_FN_AVB_AVTP_PPS, NULL);
124         /* IPSR2 */
125         gpio_request(GPIO_FN_AVB_AVTP_MATCH_B, NULL);
126         /* IPSR3 */
127         gpio_request(GPIO_FN_AVB_AVTP_CAPTURE_B, NULL);
128
129         /* AVB_PHY_RST */
130         gpio_request(GPIO_GP_2_10, NULL);
131         gpio_direction_output(GPIO_GP_2_10, 0);
132         mdelay(20);
133         gpio_set_value(GPIO_GP_2_10, 1);
134         udelay(1);
135 #endif
136
137         return 0;
138 }
139
140 static struct eth_pdata salvator_x_ravb_platdata = {
141         .iobase         = 0xE6800000,
142         .phy_interface  = 0,
143         .max_speed      = 1000,
144 };
145
146 U_BOOT_DEVICE(salvator_x_ravb) = {
147         .name           = "ravb",
148         .platdata       = &salvator_x_ravb_platdata,
149 };
150
151 #ifdef CONFIG_SH_SDHI
152 int board_mmc_init(bd_t *bis)
153 {
154         int ret = -ENODEV;
155
156         /* SDHI0 */
157         gpio_request(GPIO_GFN_SD0_DAT0, NULL);
158         gpio_request(GPIO_GFN_SD0_DAT1, NULL);
159         gpio_request(GPIO_GFN_SD0_DAT2, NULL);
160         gpio_request(GPIO_GFN_SD0_DAT3, NULL);
161         gpio_request(GPIO_GFN_SD0_CLK, NULL);
162         gpio_request(GPIO_GFN_SD0_CMD, NULL);
163         gpio_request(GPIO_GFN_SD0_CD, NULL);
164         gpio_request(GPIO_GFN_SD0_WP, NULL);
165
166         gpio_request(GPIO_GP_5_2, NULL);
167         gpio_request(GPIO_GP_5_1, NULL);
168         gpio_direction_output(GPIO_GP_5_2, 1);  /* power on */
169         gpio_direction_output(GPIO_GP_5_1, 1);  /* 1: 3.3V, 0: 1.8V */
170
171         ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI0_BASE, 0,
172                            SH_SDHI_QUIRK_64BIT_BUF);
173         if (ret)
174                 return ret;
175
176         /* SDHI1/SDHI2 eMMC */
177         gpio_request(GPIO_GFN_SD1_DAT0, NULL);
178         gpio_request(GPIO_GFN_SD1_DAT1, NULL);
179         gpio_request(GPIO_GFN_SD1_DAT2, NULL);
180         gpio_request(GPIO_GFN_SD1_DAT3, NULL);
181         gpio_request(GPIO_GFN_SD2_DAT0, NULL);
182         gpio_request(GPIO_GFN_SD2_DAT1, NULL);
183         gpio_request(GPIO_GFN_SD2_DAT2, NULL);
184         gpio_request(GPIO_GFN_SD2_DAT3, NULL);
185         gpio_request(GPIO_GFN_SD2_CLK, NULL);
186         gpio_request(GPIO_GFN_SD2_CMD, NULL);
187         gpio_request(GPIO_GP_5_3, NULL);
188         gpio_request(GPIO_GP_5_9, NULL);
189         gpio_direction_output(GPIO_GP_5_3, 0);  /* 1: 3.3V, 0: 1.8V */
190         gpio_direction_output(GPIO_GP_5_9, 0);  /* 1: 3.3V, 0: 1.8V */
191
192         ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI2_BASE, 1,
193                            SH_SDHI_QUIRK_64BIT_BUF);
194         if (ret)
195                 return ret;
196
197         /* SDHI3 */
198         gpio_request(GPIO_GFN_SD3_DAT0, NULL);  /* GP_4_9 */
199         gpio_request(GPIO_GFN_SD3_DAT1, NULL);  /* GP_4_10 */
200         gpio_request(GPIO_GFN_SD3_DAT2, NULL);  /* GP_4_11 */
201         gpio_request(GPIO_GFN_SD3_DAT3, NULL);  /* GP_4_12 */
202         gpio_request(GPIO_GFN_SD3_CLK, NULL);   /* GP_4_7 */
203         gpio_request(GPIO_GFN_SD3_CMD, NULL);   /* GP_4_8 */
204         /* IPSR10 */
205         gpio_request(GPIO_FN_SD3_CD, NULL);
206         gpio_request(GPIO_FN_SD3_WP, NULL);
207
208         gpio_request(GPIO_GP_3_15, NULL);
209         gpio_request(GPIO_GP_3_14, NULL);
210         gpio_direction_output(GPIO_GP_3_15, 1); /* power on */
211         gpio_direction_output(GPIO_GP_3_14, 1); /* 1: 3.3V, 0: 1.8V */
212
213         ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI3_BASE, 2,
214                            SH_SDHI_QUIRK_64BIT_BUF);
215         return ret;
216 }
217 #endif
218
219 int dram_init(void)
220 {
221         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
222
223         return 0;
224 }
225
226 const struct rmobile_sysinfo sysinfo = {
227         CONFIG_RCAR_BOARD_STRING
228 };
229
230 #define RST_BASE        0xE6160000
231 #define RST_CA57RESCNT  (RST_BASE + 0x40)
232 #define RST_CA53RESCNT  (RST_BASE + 0x44)
233 #define RST_RSTOUTCR    (RST_BASE + 0x58)
234 #define RST_CODE        0xA5A5000F
235
236 void reset_cpu(ulong addr)
237 {
238         /* only CA57 ? */
239         writel(RST_CODE, RST_CA57RESCNT);
240 }
241
242 static const struct sh_serial_platdata serial_platdata = {
243         .base = SCIF2_BASE,
244         .type = PORT_SCIF,
245         .clk = CONFIG_SH_SCIF_CLK_FREQ,
246         .clk_mode = INT_CLK,
247 };
248
249 U_BOOT_DEVICE(salvator_x_scif2) = {
250         .name = "serial_sh",
251         .platdata = &serial_platdata,
252 };