blob: bec756d7ac0bad6aed9324254909b2d675a85fc9 [file] [log] [blame]
Simon Glass2444dae2015-08-30 16:55:38 -06001/*
2 * (C) Copyright 2015 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Simon Glass74e53e02016-01-21 19:45:07 -07008#include <clk.h>
Simon Glass2444dae2015-08-30 16:55:38 -06009#include <dm.h>
10#include <ram.h>
huang linbe1d5e02015-11-17 14:20:27 +080011#include <asm/io.h>
Stephen Warren135aa952016-06-17 09:44:00 -060012#include <asm/arch/clock.h>
Xu Ziyuanb47ea792016-07-12 19:09:49 +080013#include <asm/arch/periph.h>
14#include <asm/gpio.h>
15#include <dm/pinctrl.h>
Simon Glass2444dae2015-08-30 16:55:38 -060016
17DECLARE_GLOBAL_DATA_PTR;
18
19int board_init(void)
20{
Xu Ziyuanb47ea792016-07-12 19:09:49 +080021#ifdef CONFIG_ROCKCHIP_SPL_BACK_TO_BROM
22 struct udevice *pinctrl;
23 int ret;
24
25 /*
26 * We need to implement sdcard iomux here for the further
27 * initlization, otherwise, it'll hit sdcard command sending
28 * timeout exception.
29 */
30 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
31 if (ret) {
32 debug("%s: Cannot find pinctrl device\n", __func__);
33 goto err;
34 }
35 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
36 if (ret) {
37 debug("%s: Failed to set up SD card\n", __func__);
38 goto err;
39 }
40
Simon Glass2444dae2015-08-30 16:55:38 -060041 return 0;
Xu Ziyuanb47ea792016-07-12 19:09:49 +080042err:
43 printf("board_init: Error %d\n", ret);
44
45 /* No way to report error here */
46 hang();
47
48 return -1;
49#else
50 return 0;
51#endif
Simon Glass2444dae2015-08-30 16:55:38 -060052}
53
54int dram_init(void)
55{
56 struct ram_info ram;
57 struct udevice *dev;
58 int ret;
59
60 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
61 if (ret) {
62 debug("DRAM init failed: %d\n", ret);
63 return ret;
64 }
65 ret = ram_get_info(dev, &ram);
66 if (ret) {
67 debug("Cannot get DRAM size: %d\n", ret);
68 return ret;
69 }
70 debug("SDRAM base=%lx, size=%x\n", ram.base, ram.size);
71 gd->ram_size = ram.size;
72
73 return 0;
74}
75
76#ifndef CONFIG_SYS_DCACHE_OFF
77void enable_caches(void)
78{
79 /* Enable D-cache. I-cache is already enabled in start.S */
80 dcache_enable();
81}
82#endif
Simon Glassad443b72016-01-21 19:45:06 -070083
84void lowlevel_init(void)
85{
86}
Simon Glass74e53e02016-01-21 19:45:07 -070087
Xu Ziyuan266c8fa2016-07-15 00:26:59 +080088#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
89#include <usb.h>
90#include <usb/dwc2_udc.h>
91
92static struct dwc2_plat_otg_data rk3288_otg_data = {
93 .rx_fifo_sz = 512,
94 .np_tx_fifo_sz = 16,
95 .tx_fifo_sz = 128,
96};
97
98int board_usb_init(int index, enum usb_init_type init)
99{
100 int node, phy_node;
101 const char *mode;
102 bool matched = false;
103 const void *blob = gd->fdt_blob;
104 u32 grf_phy_offset;
105
106 /* find the usb_otg node */
107 node = fdt_node_offset_by_compatible(blob, -1,
108 "rockchip,rk3288-usb");
109
110 while (node > 0) {
111 mode = fdt_getprop(blob, node, "dr_mode", NULL);
112 if (mode && strcmp(mode, "otg") == 0) {
113 matched = true;
114 break;
115 }
116
117 node = fdt_node_offset_by_compatible(blob, node,
118 "rockchip,rk3288-usb");
119 }
120 if (!matched) {
121 debug("Not found usb_otg device\n");
122 return -ENODEV;
123 }
124 rk3288_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
125
126 node = fdtdec_lookup_phandle(blob, node, "phys");
127 if (node <= 0) {
128 debug("Not found usb phy device\n");
129 return -ENODEV;
130 }
131
132 phy_node = fdt_parent_offset(blob, node);
133 if (phy_node <= 0) {
134 debug("Not found usb phy device\n");
135 return -ENODEV;
136 }
137
138 rk3288_otg_data.phy_of_node = phy_node;
139 grf_phy_offset = fdtdec_get_addr(blob, node, "reg");
140
141 /* find the grf node */
142 node = fdt_node_offset_by_compatible(blob, -1,
143 "rockchip,rk3288-grf");
144 if (node <= 0) {
145 debug("Not found grf device\n");
146 return -ENODEV;
147 }
148 rk3288_otg_data.regs_phy = grf_phy_offset +
149 fdtdec_get_addr(blob, node, "reg");
150
151 return dwc2_udc_probe(&rk3288_otg_data);
152}
153
154int board_usb_cleanup(int index, enum usb_init_type init)
155{
156 return 0;
157}
158#endif
159
Simon Glass74e53e02016-01-21 19:45:07 -0700160static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc,
161 char * const argv[])
162{
Stephen Warren135aa952016-06-17 09:44:00 -0600163 static const struct {
164 char *name;
165 int id;
166 } clks[] = {
167 { "osc", CLK_OSC },
168 { "apll", CLK_ARM },
169 { "dpll", CLK_DDR },
170 { "cpll", CLK_CODEC },
171 { "gpll", CLK_GENERAL },
172#ifdef CONFIG_ROCKCHIP_RK3036
173 { "mpll", CLK_NEW },
174#else
175 { "npll", CLK_NEW },
176#endif
177 };
178 int ret, i;
Simon Glass74e53e02016-01-21 19:45:07 -0700179 struct udevice *dev;
180
Simon Glassc3aad6f2016-07-17 15:23:17 -0600181 ret = rockchip_get_clk(&dev);
Stephen Warren135aa952016-06-17 09:44:00 -0600182 if (ret) {
183 printf("clk-uclass not found\n");
184 return 0;
185 }
186
187 for (i = 0; i < ARRAY_SIZE(clks); i++) {
188 struct clk clk;
Simon Glass74e53e02016-01-21 19:45:07 -0700189 ulong rate;
190
Stephen Warren135aa952016-06-17 09:44:00 -0600191 clk.id = clks[i].id;
192 ret = clk_request(dev, &clk);
193 if (ret < 0)
194 continue;
195
196 rate = clk_get_rate(&clk);
197 printf("%s: %lu\n", clks[i].name, rate);
198
199 clk_free(&clk);
Simon Glass74e53e02016-01-21 19:45:07 -0700200 }
201
202 return 0;
203}
204
205U_BOOT_CMD(
206 clock, 2, 1, do_clock,
207 "display information about clocks",
208 ""
209);