ARM: rmobile: Remove SD clock configuration from board files
[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/Salvator-XS 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 DVFS_MSTP926            BIT(26)
54 #define HSUSB_MSTP704           BIT(4)  /* HSUSB */
55
56 int board_early_init_f(void)
57 {
58         /* TMU0,1 */            /* which use ? */
59         mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125 | TMU1_MSTP124);
60         /* SCIF2 */
61         mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SCIF2_MSTP310);
62         /* EHTERAVB */
63         mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHERAVB_MSTP812);
64
65 #if defined(CONFIG_SYS_I2C) && defined(CONFIG_SYS_I2C_SH)
66         /* DVFS for reset */
67         mstp_clrbits_le32(MSTPSR9, SMSTPCR9, DVFS_MSTP926);
68 #endif
69         return 0;
70 }
71
72 /* SYSC */
73 /* R/- 32 Power status register 2(3DG) */
74 #define SYSC_PWRSR2     0xE6180100
75 /* -/W 32 Power resume control register 2 (3DG) */
76 #define SYSC_PWRONCR2   0xE618010C
77
78 /* HSUSB block registers */
79 #define HSUSB_REG_LPSTS                 0xE6590102
80 #define HSUSB_REG_LPSTS_SUSPM_NORMAL    BIT(14)
81 #define HSUSB_REG_UGCTRL2               0xE6590184
82 #define HSUSB_REG_UGCTRL2_USB0SEL       0x30
83 #define HSUSB_REG_UGCTRL2_USB0SEL_EHCI  0x10
84
85 int board_init(void)
86 {
87         /* adress of boot parameters */
88         gd->bd->bi_boot_params = CONFIG_SYS_TEXT_BASE + 0x50000;
89
90         /* Init PFC controller */
91 #if defined(CONFIG_R8A7795)
92         r8a7795_pinmux_init();
93 #elif defined(CONFIG_R8A7796)
94         r8a7796_pinmux_init();
95 #endif
96
97 #if defined(CONFIG_R8A7795)
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 #endif
105
106         /* USB1 pull-up */
107         setbits_le32(PFC_PUEN6, PUEN_USB1_OVC | PUEN_USB1_PWEN);
108
109         /* Configure the HSUSB block */
110         mstp_clrbits_le32(MSTPSR7, SMSTPCR7, HSUSB_MSTP704);
111         /* Choice USB0SEL */
112         clrsetbits_le32(HSUSB_REG_UGCTRL2, HSUSB_REG_UGCTRL2_USB0SEL,
113                         HSUSB_REG_UGCTRL2_USB0SEL_EHCI);
114         /* low power status */
115         setbits_le16(HSUSB_REG_LPSTS, HSUSB_REG_LPSTS_SUSPM_NORMAL);
116
117 #ifdef CONFIG_RENESAS_RAVB
118         /* EtherAVB Enable */
119         /* GPSR2 */
120         gpio_request(GPIO_GFN_AVB_AVTP_CAPTURE_A, NULL);
121         gpio_request(GPIO_GFN_AVB_AVTP_MATCH_A, NULL);
122         gpio_request(GPIO_GFN_AVB_LINK, NULL);
123         gpio_request(GPIO_GFN_AVB_PHY_INT, NULL);
124         gpio_request(GPIO_GFN_AVB_MAGIC, NULL);
125         gpio_request(GPIO_GFN_AVB_MDC, NULL);
126
127         /* IPSR0 */
128         gpio_request(GPIO_IFN_AVB_MDC, NULL);
129         gpio_request(GPIO_IFN_AVB_MAGIC, NULL);
130         gpio_request(GPIO_IFN_AVB_PHY_INT, NULL);
131         gpio_request(GPIO_IFN_AVB_LINK, NULL);
132         gpio_request(GPIO_IFN_AVB_AVTP_MATCH_A, NULL);
133         gpio_request(GPIO_IFN_AVB_AVTP_CAPTURE_A, NULL);
134         /* IPSR1 */
135         gpio_request(GPIO_FN_AVB_AVTP_PPS, NULL);
136         /* IPSR2 */
137         gpio_request(GPIO_FN_AVB_AVTP_MATCH_B, NULL);
138         /* IPSR3 */
139         gpio_request(GPIO_FN_AVB_AVTP_CAPTURE_B, NULL);
140
141 #if defined(CONFIG_R8A7795)
142         /* USB2_OVC */
143         gpio_request(GPIO_GP_6_15, NULL);
144         gpio_direction_input(GPIO_GP_6_15);
145
146         /* USB2_PWEN */
147         gpio_request(GPIO_GP_6_14, NULL);
148         gpio_direction_output(GPIO_GP_6_14, 1);
149         gpio_set_value(GPIO_GP_6_14, 1);
150 #endif
151         /* AVB_PHY_RST */
152         gpio_request(GPIO_GP_2_10, NULL);
153         gpio_direction_output(GPIO_GP_2_10, 0);
154         mdelay(20);
155         gpio_set_value(GPIO_GP_2_10, 1);
156         udelay(1);
157 #endif
158
159 #ifdef CONFIG_MMC
160         /* SDHI0 */
161         gpio_request(GPIO_GFN_SD0_DAT0, NULL);
162         gpio_request(GPIO_GFN_SD0_DAT1, NULL);
163         gpio_request(GPIO_GFN_SD0_DAT2, NULL);
164         gpio_request(GPIO_GFN_SD0_DAT3, NULL);
165         gpio_request(GPIO_GFN_SD0_CLK, NULL);
166         gpio_request(GPIO_GFN_SD0_CMD, NULL);
167         gpio_request(GPIO_GFN_SD0_CD, NULL);
168         gpio_request(GPIO_GFN_SD0_WP, NULL);
169
170         gpio_request(GPIO_GP_5_2, NULL);
171         gpio_request(GPIO_GP_5_1, NULL);
172         gpio_direction_output(GPIO_GP_5_2, 1);  /* power on */
173         gpio_direction_output(GPIO_GP_5_1, 1);  /* 1: 3.3V, 0: 1.8V */
174
175         /* SDHI1/SDHI2 eMMC */
176         gpio_request(GPIO_GFN_SD1_DAT0, NULL);
177         gpio_request(GPIO_GFN_SD1_DAT1, NULL);
178         gpio_request(GPIO_GFN_SD1_DAT2, NULL);
179         gpio_request(GPIO_GFN_SD1_DAT3, NULL);
180         gpio_request(GPIO_GFN_SD2_DAT0, NULL);
181         gpio_request(GPIO_GFN_SD2_DAT1, NULL);
182         gpio_request(GPIO_GFN_SD2_DAT2, NULL);
183         gpio_request(GPIO_GFN_SD2_DAT3, NULL);
184         gpio_request(GPIO_GFN_SD2_CLK, NULL);
185 #if defined(CONFIG_R8A7795)
186         gpio_request(GPIO_GFN_SD2_CMD, NULL);
187 #elif defined(CONFIG_R8A7796)
188         gpio_request(GPIO_FN_SD2_CMD, NULL);
189 #else
190 #error Only R8A7795 and R87796 is supported
191 #endif
192         gpio_request(GPIO_GP_5_3, NULL);
193         gpio_request(GPIO_GP_5_9, NULL);
194         gpio_direction_output(GPIO_GP_5_3, 0);  /* 1: 3.3V, 0: 1.8V */
195         gpio_direction_output(GPIO_GP_5_9, 0);  /* 1: 3.3V, 0: 1.8V */
196
197 #if defined(CONFIG_R8A7795)
198         /* SDHI3 */
199         gpio_request(GPIO_GFN_SD3_DAT0, NULL);  /* GP_4_9 */
200         gpio_request(GPIO_GFN_SD3_DAT1, NULL);  /* GP_4_10 */
201         gpio_request(GPIO_GFN_SD3_DAT2, NULL);  /* GP_4_11 */
202         gpio_request(GPIO_GFN_SD3_DAT3, NULL);  /* GP_4_12 */
203         gpio_request(GPIO_GFN_SD3_CLK, NULL);   /* GP_4_7 */
204         gpio_request(GPIO_GFN_SD3_CMD, NULL);   /* GP_4_8 */
205 #elif defined(CONFIG_R8A7796)
206         gpio_request(GPIO_FN_SD3_DAT0, NULL);   /* GP_4_9 */
207         gpio_request(GPIO_FN_SD3_DAT1, NULL);   /* GP_4_10 */
208         gpio_request(GPIO_FN_SD3_DAT2, NULL);   /* GP_4_11 */
209         gpio_request(GPIO_FN_SD3_DAT3, NULL);   /* GP_4_12 */
210         gpio_request(GPIO_FN_SD3_CLK, NULL);    /* GP_4_7 */
211         gpio_request(GPIO_FN_SD3_CMD, NULL);    /* GP_4_8 */
212 #else
213 #error Only R8A7795 and R87796 is supported
214 #endif
215         /* IPSR10 */
216         gpio_request(GPIO_FN_SD3_CD, NULL);
217         gpio_request(GPIO_FN_SD3_WP, NULL);
218
219         gpio_request(GPIO_GP_3_15, NULL);
220         gpio_request(GPIO_GP_3_14, NULL);
221         gpio_direction_output(GPIO_GP_3_15, 1); /* power on */
222         gpio_direction_output(GPIO_GP_3_14, 1); /* 1: 3.3V, 0: 1.8V */
223 #endif
224
225         return 0;
226 }
227
228 int dram_init(void)
229 {
230         gd->ram_size = PHYS_SDRAM_1_SIZE;
231 #if (CONFIG_NR_DRAM_BANKS >= 2)
232         gd->ram_size += PHYS_SDRAM_2_SIZE;
233 #endif
234 #if (CONFIG_NR_DRAM_BANKS >= 3)
235         gd->ram_size += PHYS_SDRAM_3_SIZE;
236 #endif
237 #if (CONFIG_NR_DRAM_BANKS >= 4)
238         gd->ram_size += PHYS_SDRAM_4_SIZE;
239 #endif
240
241         return 0;
242 }
243
244 int dram_init_banksize(void)
245 {
246         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
247         gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
248 #if (CONFIG_NR_DRAM_BANKS >= 2)
249         gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
250         gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
251 #endif
252 #if (CONFIG_NR_DRAM_BANKS >= 3)
253         gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
254         gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
255 #endif
256 #if (CONFIG_NR_DRAM_BANKS >= 4)
257         gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
258         gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE;
259 #endif
260         return 0;
261 }
262
263 const struct rmobile_sysinfo sysinfo = {
264         CONFIG_RCAR_BOARD_STRING
265 };
266
267 #define RST_BASE        0xE6160000
268 #define RST_CA57RESCNT  (RST_BASE + 0x40)
269 #define RST_CA53RESCNT  (RST_BASE + 0x44)
270 #define RST_RSTOUTCR    (RST_BASE + 0x58)
271 #define RST_CODE        0xA5A5000F
272
273 void reset_cpu(ulong addr)
274 {
275 #if defined(CONFIG_SYS_I2C) && defined(CONFIG_SYS_I2C_SH)
276         i2c_reg_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x20, 0x80);
277 #else
278         /* only CA57 ? */
279         writel(RST_CODE, RST_CA57RESCNT);
280 #endif
281 }