blob: 6c36bf93977dac7be6f95d4c379beac5df30dfa7 [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
Xu Ziyuan266c8fa2016-07-15 00:26:59 +080084#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
85#include <usb.h>
86#include <usb/dwc2_udc.h>
87
88static struct dwc2_plat_otg_data rk3288_otg_data = {
89 .rx_fifo_sz = 512,
90 .np_tx_fifo_sz = 16,
91 .tx_fifo_sz = 128,
92};
93
94int board_usb_init(int index, enum usb_init_type init)
95{
96 int node, phy_node;
97 const char *mode;
98 bool matched = false;
99 const void *blob = gd->fdt_blob;
100 u32 grf_phy_offset;
101
102 /* find the usb_otg node */
103 node = fdt_node_offset_by_compatible(blob, -1,
104 "rockchip,rk3288-usb");
105
106 while (node > 0) {
107 mode = fdt_getprop(blob, node, "dr_mode", NULL);
108 if (mode && strcmp(mode, "otg") == 0) {
109 matched = true;
110 break;
111 }
112
113 node = fdt_node_offset_by_compatible(blob, node,
114 "rockchip,rk3288-usb");
115 }
116 if (!matched) {
117 debug("Not found usb_otg device\n");
118 return -ENODEV;
119 }
120 rk3288_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
121
122 node = fdtdec_lookup_phandle(blob, node, "phys");
123 if (node <= 0) {
124 debug("Not found usb phy device\n");
125 return -ENODEV;
126 }
127
128 phy_node = fdt_parent_offset(blob, node);
129 if (phy_node <= 0) {
130 debug("Not found usb phy device\n");
131 return -ENODEV;
132 }
133
134 rk3288_otg_data.phy_of_node = phy_node;
135 grf_phy_offset = fdtdec_get_addr(blob, node, "reg");
136
137 /* find the grf node */
138 node = fdt_node_offset_by_compatible(blob, -1,
139 "rockchip,rk3288-grf");
140 if (node <= 0) {
141 debug("Not found grf device\n");
142 return -ENODEV;
143 }
144 rk3288_otg_data.regs_phy = grf_phy_offset +
145 fdtdec_get_addr(blob, node, "reg");
146
147 return dwc2_udc_probe(&rk3288_otg_data);
148}
149
150int board_usb_cleanup(int index, enum usb_init_type init)
151{
152 return 0;
153}
154#endif
155
Simon Glass74e53e02016-01-21 19:45:07 -0700156static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc,
157 char * const argv[])
158{
Stephen Warren135aa952016-06-17 09:44:00 -0600159 static const struct {
160 char *name;
161 int id;
162 } clks[] = {
163 { "osc", CLK_OSC },
164 { "apll", CLK_ARM },
165 { "dpll", CLK_DDR },
166 { "cpll", CLK_CODEC },
167 { "gpll", CLK_GENERAL },
168#ifdef CONFIG_ROCKCHIP_RK3036
169 { "mpll", CLK_NEW },
170#else
171 { "npll", CLK_NEW },
172#endif
173 };
174 int ret, i;
Simon Glass74e53e02016-01-21 19:45:07 -0700175 struct udevice *dev;
176
Simon Glassc3aad6f2016-07-17 15:23:17 -0600177 ret = rockchip_get_clk(&dev);
Stephen Warren135aa952016-06-17 09:44:00 -0600178 if (ret) {
179 printf("clk-uclass not found\n");
180 return 0;
181 }
182
183 for (i = 0; i < ARRAY_SIZE(clks); i++) {
184 struct clk clk;
Simon Glass74e53e02016-01-21 19:45:07 -0700185 ulong rate;
186
Stephen Warren135aa952016-06-17 09:44:00 -0600187 clk.id = clks[i].id;
188 ret = clk_request(dev, &clk);
189 if (ret < 0)
190 continue;
191
192 rate = clk_get_rate(&clk);
193 printf("%s: %lu\n", clks[i].name, rate);
194
195 clk_free(&clk);
Simon Glass74e53e02016-01-21 19:45:07 -0700196 }
197
198 return 0;
199}
200
201U_BOOT_CMD(
202 clock, 2, 1, do_clock,
203 "display information about clocks",
204 ""
205);