blob: f040c1b74639c4d81a4d5fb5a441a529e241be3f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yang168eef72017-06-23 17:17:52 +08002/*
3 * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
Kever Yang168eef72017-06-23 17:17:52 +08004 */
5#include <common.h>
6#include <clk.h>
7#include <dm.h>
8#include <ram.h>
Kever Yangc964a0d2017-08-09 19:28:03 +08009#include <syscon.h>
Kever Yang168eef72017-06-23 17:17:52 +080010#include <asm/io.h>
Kever Yang15f09a12019-03-28 11:01:23 +080011#include <asm/arch-rockchip/boot_mode.h>
12#include <asm/arch-rockchip/clock.h>
13#include <asm/arch-rockchip/periph.h>
14#include <asm/arch-rockchip/grf_rk322x.h>
Kever Yang168eef72017-06-23 17:17:52 +080015
16DECLARE_GLOBAL_DATA_PTR;
17
Kever Yang168eef72017-06-23 17:17:52 +080018__weak int rk_board_late_init(void)
19{
20 return 0;
21}
22
23int board_late_init(void)
24{
25 setup_boot_mode();
26
27 return rk_board_late_init();
28}
29
30int board_init(void)
31{
Kever Yang15f09a12019-03-28 11:01:23 +080032#include <asm/arch-rockchip/grf_rk322x.h>
Kever Yang168eef72017-06-23 17:17:52 +080033 /* Enable early UART2 channel 1 on the RK322x */
34#define GRF_BASE 0x11000000
35 struct rk322x_grf * const grf = (void *)GRF_BASE;
David Wu424324d2018-01-13 14:04:26 +080036 enum {
37 GPIO1B2_SHIFT = 4,
38 GPIO1B2_MASK = 3 << GPIO1B2_SHIFT,
39 GPIO1B2_GPIO = 0,
40 GPIO1B2_UART21_SIN,
41
42 GPIO1B1_SHIFT = 2,
43 GPIO1B1_MASK = 3 << GPIO1B1_SHIFT,
44 GPIO1B1_GPIO = 0,
45 GPIO1B1_UART1_SOUT,
46 GPIO1B1_UART21_SOUT,
47 };
48 enum {
49 CON_IOMUX_UART2SEL_SHIFT= 8,
50 CON_IOMUX_UART2SEL_MASK = 1 << CON_IOMUX_UART2SEL_SHIFT,
51 CON_IOMUX_UART2SEL_2 = 0,
52 CON_IOMUX_UART2SEL_21,
53 };
Kever Yang168eef72017-06-23 17:17:52 +080054
55 rk_clrsetreg(&grf->gpio1b_iomux,
56 GPIO1B1_MASK | GPIO1B2_MASK,
57 GPIO1B2_UART21_SIN << GPIO1B2_SHIFT |
58 GPIO1B1_UART21_SOUT << GPIO1B1_SHIFT);
59 /* Set channel C as UART2 input */
60 rk_clrsetreg(&grf->con_iomux,
61 CON_IOMUX_UART2SEL_MASK,
62 CON_IOMUX_UART2SEL_21 << CON_IOMUX_UART2SEL_SHIFT);
63
David Wu4c94aac2017-08-14 15:04:28 +080064 /*
65 * The integrated macphy is enabled by default, disable it
66 * for saving power consuming.
67 */
68 rk_clrsetreg(&grf->macphy_con[0],
69 MACPHY_CFG_ENABLE_MASK,
70 0 << MACPHY_CFG_ENABLE_SHIFT);
71
Kever Yang168eef72017-06-23 17:17:52 +080072 return 0;
73}
74
75int dram_init_banksize(void)
76{
Kever Yang44c5ba52017-07-21 18:21:07 +080077 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
Kever Yang168eef72017-06-23 17:17:52 +080078 gd->bd->bi_dram[0].size = 0x8400000;
Kever Yang44c5ba52017-07-21 18:21:07 +080079 /* Reserve 0x200000 for OPTEE */
80 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE
81 + gd->bd->bi_dram[0].size + 0x200000;
82 gd->bd->bi_dram[1].size = gd->bd->bi_dram[0].start
83 + gd->ram_size - gd->bd->bi_dram[1].start;
Kever Yang168eef72017-06-23 17:17:52 +080084
85 return 0;
86}
87
88#ifndef CONFIG_SYS_DCACHE_OFF
89void enable_caches(void)
90{
91 /* Enable D-cache. I-cache is already enabled in start.S */
92 dcache_enable();
93}
94#endif
95
96#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
97#include <usb.h>
98#include <usb/dwc2_udc.h>
99
100static struct dwc2_plat_otg_data rk322x_otg_data = {
101 .rx_fifo_sz = 512,
102 .np_tx_fifo_sz = 16,
103 .tx_fifo_sz = 128,
104};
105
106int board_usb_init(int index, enum usb_init_type init)
107{
108 int node;
109 const char *mode;
110 bool matched = false;
111 const void *blob = gd->fdt_blob;
112
113 /* find the usb_otg node */
114 node = fdt_node_offset_by_compatible(blob, -1,
115 "rockchip,rk3288-usb");
116
117 while (node > 0) {
118 mode = fdt_getprop(blob, node, "dr_mode", NULL);
119 if (mode && strcmp(mode, "otg") == 0) {
120 matched = true;
121 break;
122 }
123
124 node = fdt_node_offset_by_compatible(blob, node,
125 "rockchip,rk3288-usb");
126 }
127 if (!matched) {
128 debug("Not found usb_otg device\n");
129 return -ENODEV;
130 }
131 rk322x_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
132
133 return dwc2_udc_probe(&rk322x_otg_data);
134}
135
136int board_usb_cleanup(int index, enum usb_init_type init)
137{
138 return 0;
139}
140#endif
Kever Yangc964a0d2017-08-09 19:28:03 +0800141
Alex Kiernan8a65bd62018-05-29 15:30:46 +0000142#if CONFIG_IS_ENABLED(FASTBOOT)
143int fastboot_set_reboot_flag(void)
Kever Yangc964a0d2017-08-09 19:28:03 +0800144{
145 struct rk322x_grf *grf;
146
147 printf("Setting reboot to fastboot flag ...\n");
148 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
149 /* Set boot mode to fastboot */
150 writel(BOOT_FASTBOOT, &grf->os_reg[0]);
151
152 return 0;
153}
154#endif