ARM: rmobile: Move HSUSB configuration to board on ULCB
[platform/kernel/u-boot.git] / board / renesas / ulcb / ulcb.c
1 /*
2  * board/renesas/ulcb/ulcb.c
3  *     This file is ULCB board support.
4  *
5  * Copyright (C) 2017 Renesas Electronics Corporation
6  *
7  * SPDX-License-Identifier: GPL-2.0+
8  */
9
10 #include <common.h>
11 #include <malloc.h>
12 #include <netdev.h>
13 #include <dm.h>
14 #include <dm/platform_data/serial_sh.h>
15 #include <asm/processor.h>
16 #include <asm/mach-types.h>
17 #include <asm/io.h>
18 #include <linux/errno.h>
19 #include <asm/arch/sys_proto.h>
20 #include <asm/gpio.h>
21 #include <asm/arch/gpio.h>
22 #include <asm/arch/rmobile.h>
23 #include <asm/arch/rcar-mstp.h>
24 #include <asm/arch/sh_sdhi.h>
25 #include <i2c.h>
26 #include <mmc.h>
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 #define CPGWPCR 0xE6150904
31 #define CPGWPR  0xE615090C
32
33 #define CLK2MHZ(clk)    (clk / 1000 / 1000)
34 void s_init(void)
35 {
36         struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
37         struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
38
39         /* Watchdog init */
40         writel(0xA5A5A500, &rwdt->rwtcsra);
41         writel(0xA5A5A500, &swdt->swtcsra);
42
43         writel(0xA5A50000, CPGWPCR);
44         writel(0xFFFFFFFF, CPGWPR);
45 }
46
47 #define GSX_MSTP112             BIT(12) /* 3DG */
48 #define TMU0_MSTP125            BIT(25) /* secure */
49 #define TMU1_MSTP124            BIT(24) /* non-secure */
50 #define SCIF2_MSTP310           BIT(10) /* SCIF2 */
51 #define ETHERAVB_MSTP812        BIT(12)
52 #define DVFS_MSTP926            BIT(26)
53 #define SD0_MSTP314             BIT(14)
54 #define SD1_MSTP313             BIT(13)
55 #define SD2_MSTP312             BIT(12) /* either MMC0 */
56 #define HSUSB_MSTP704           BIT(4)  /* HSUSB */
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 */
74         mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SD0_MSTP314);
75
76         writel(1, SD0CKCR);
77         writel(1, SD1CKCR);
78         writel(1, SD2CKCR);
79         writel(1, SD3CKCR);
80
81 #if defined(CONFIG_SYS_I2C) && defined(CONFIG_SYS_I2C_SH)
82         /* DVFS for reset */
83         mstp_clrbits_le32(MSTPSR9, SMSTPCR9, DVFS_MSTP926);
84 #endif
85         return 0;
86 }
87
88 /* SYSC */
89 /* R/- 32 Power status register 2(3DG) */
90 #define SYSC_PWRSR2     0xE6180100
91 /* -/W 32 Power resume control register 2 (3DG) */
92 #define SYSC_PWRONCR2   0xE618010C
93
94 /* HSUSB block registers */
95 #define HSUSB_REG_LPSTS                 0xE6590102
96 #define HSUSB_REG_LPSTS_SUSPM_NORMAL    BIT(14)
97 #define HSUSB_REG_UGCTRL2               0xE6590184
98 #define HSUSB_REG_UGCTRL2_USB0SEL       0x30
99 #define HSUSB_REG_UGCTRL2_USB0SEL_EHCI  0x10
100
101 int board_init(void)
102 {
103         /* adress of boot parameters */
104         gd->bd->bi_boot_params = CONFIG_SYS_TEXT_BASE + 0x50000;
105
106         /* Init PFC controller */
107 #if defined(CONFIG_R8A7795)
108         r8a7795_pinmux_init();
109 #elif defined(CONFIG_R8A7796)
110         r8a7796_pinmux_init();
111 #endif
112
113         /* USB1 pull-up */
114         setbits_le32(PFC_PUEN6, PUEN_USB1_OVC | PUEN_USB1_PWEN);
115
116         /* Configure the HSUSB block */
117         mstp_clrbits_le32(MSTPSR7, SMSTPCR7, HSUSB_MSTP704);
118         /* Choice USB0SEL */
119         clrsetbits_le32(HSUSB_REG_UGCTRL2, HSUSB_REG_UGCTRL2_USB0SEL,
120                         HSUSB_REG_UGCTRL2_USB0SEL_EHCI);
121         /* low power status */
122         setbits_le16(HSUSB_REG_LPSTS, HSUSB_REG_LPSTS_SUSPM_NORMAL);
123
124 #ifdef CONFIG_RENESAS_RAVB
125         /* EtherAVB Enable */
126         /* GPSR2 */
127         gpio_request(GPIO_GFN_AVB_AVTP_CAPTURE_A, NULL);
128         gpio_request(GPIO_GFN_AVB_AVTP_MATCH_A, NULL);
129         gpio_request(GPIO_GFN_AVB_LINK, NULL);
130         gpio_request(GPIO_GFN_AVB_PHY_INT, NULL);
131         gpio_request(GPIO_GFN_AVB_MAGIC, NULL);
132         gpio_request(GPIO_GFN_AVB_MDC, NULL);
133
134         /* IPSR0 */
135         gpio_request(GPIO_IFN_AVB_MDC, NULL);
136         gpio_request(GPIO_IFN_AVB_MAGIC, NULL);
137         gpio_request(GPIO_IFN_AVB_PHY_INT, NULL);
138         gpio_request(GPIO_IFN_AVB_LINK, NULL);
139         gpio_request(GPIO_IFN_AVB_AVTP_MATCH_A, NULL);
140         gpio_request(GPIO_IFN_AVB_AVTP_CAPTURE_A, NULL);
141         /* IPSR1 */
142         gpio_request(GPIO_FN_AVB_AVTP_PPS, NULL);
143         /* IPSR2 */
144         gpio_request(GPIO_FN_AVB_AVTP_MATCH_B, NULL);
145         /* IPSR3 */
146         gpio_request(GPIO_FN_AVB_AVTP_CAPTURE_B, NULL);
147
148         /* AVB_PHY_RST */
149         gpio_request(GPIO_GP_2_10, NULL);
150         gpio_direction_output(GPIO_GP_2_10, 0);
151         mdelay(20);
152         gpio_set_value(GPIO_GP_2_10, 1);
153         udelay(1);
154 #endif
155
156 #ifdef CONFIG_MMC
157         /* SDHI0 */
158         gpio_request(GPIO_GFN_SD0_DAT0, NULL);
159         gpio_request(GPIO_GFN_SD0_DAT1, NULL);
160         gpio_request(GPIO_GFN_SD0_DAT2, NULL);
161         gpio_request(GPIO_GFN_SD0_DAT3, NULL);
162         gpio_request(GPIO_GFN_SD0_CLK, NULL);
163         gpio_request(GPIO_GFN_SD0_CMD, NULL);
164         gpio_request(GPIO_GFN_SD0_CD, NULL);
165         gpio_request(GPIO_GFN_SD0_WP, NULL);
166
167         gpio_request(GPIO_GP_5_2, NULL);
168         gpio_request(GPIO_GP_5_1, NULL);
169         gpio_direction_output(GPIO_GP_5_2, 1);  /* power on */
170         gpio_direction_output(GPIO_GP_5_1, 1);  /* 1: 3.3V, 0: 1.8V */
171
172         /* SDHI1/SDHI2 eMMC */
173         gpio_request(GPIO_GFN_SD1_DAT0, NULL);
174         gpio_request(GPIO_GFN_SD1_DAT1, NULL);
175         gpio_request(GPIO_GFN_SD1_DAT2, NULL);
176         gpio_request(GPIO_GFN_SD1_DAT3, NULL);
177         gpio_request(GPIO_GFN_SD2_DAT0, NULL);
178         gpio_request(GPIO_GFN_SD2_DAT1, NULL);
179         gpio_request(GPIO_GFN_SD2_DAT2, NULL);
180         gpio_request(GPIO_GFN_SD2_DAT3, NULL);
181         gpio_request(GPIO_GFN_SD2_CLK, NULL);
182 #if defined(CONFIG_R8A7795)
183         gpio_request(GPIO_GFN_SD2_CMD, NULL);
184 #elif defined(CONFIG_R8A7796)
185         gpio_request(GPIO_FN_SD2_CMD, NULL);
186 #else
187 #error Only R8A7795 and R87796 is supported
188 #endif
189         gpio_request(GPIO_GP_5_3, NULL);
190         gpio_request(GPIO_GP_5_9, NULL);
191         gpio_direction_output(GPIO_GP_5_3, 0);  /* 1: 3.3V, 0: 1.8V */
192         gpio_direction_output(GPIO_GP_5_9, 0);  /* 1: 3.3V, 0: 1.8V */
193 #endif
194
195         return 0;
196 }
197
198 int dram_init(void)
199 {
200         gd->ram_size = PHYS_SDRAM_1_SIZE;
201 #if (CONFIG_NR_DRAM_BANKS >= 2)
202         gd->ram_size += PHYS_SDRAM_2_SIZE;
203 #endif
204 #if (CONFIG_NR_DRAM_BANKS >= 3)
205         gd->ram_size += PHYS_SDRAM_3_SIZE;
206 #endif
207 #if (CONFIG_NR_DRAM_BANKS >= 4)
208         gd->ram_size += PHYS_SDRAM_4_SIZE;
209 #endif
210
211         return 0;
212 }
213
214 int dram_init_banksize(void)
215 {
216         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
217         gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
218 #if (CONFIG_NR_DRAM_BANKS >= 2)
219         gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
220         gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
221 #endif
222 #if (CONFIG_NR_DRAM_BANKS >= 3)
223         gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
224         gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
225 #endif
226 #if (CONFIG_NR_DRAM_BANKS >= 4)
227         gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
228         gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE;
229 #endif
230         return 0;
231 }
232
233 const struct rmobile_sysinfo sysinfo = {
234         CONFIG_RCAR_BOARD_STRING
235 };