1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <common.h>
17#include <i2c.h>
18#include <net.h>
19#include <netdev.h>
20#include <spi.h>
21#include <spi_flash.h>
22#include <asm/arch/hardware.h>
23#include <asm/ti-common/davinci_nand.h>
24#include <asm/arch/emac_defs.h>
25#include <asm/arch/pinmux_defs.h>
26#include <asm/io.h>
27#include <asm/arch/davinci_misc.h>
28#include <linux/errno.h>
29#include <asm/gpio.h>
30#include <hwconfig.h>
31#include <bootstage.h>
32
33DECLARE_GLOBAL_DATA_PTR;
34
35#ifdef CONFIG_DRIVER_TI_EMAC
36#ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
37#define HAS_RMII 1
38#else
39#define HAS_RMII 0
40#endif
41#endif
42
43void dsp_lpsc_on(unsigned domain, unsigned int id)
44{
45 dv_reg_p mdstat, mdctl, ptstat, ptcmd;
46 struct davinci_psc_regs *psc_regs;
47
48 psc_regs = davinci_psc0_regs;
49 mdstat = &psc_regs->psc0.mdstat[id];
50 mdctl = &psc_regs->psc0.mdctl[id];
51 ptstat = &psc_regs->ptstat;
52 ptcmd = &psc_regs->ptcmd;
53
54 while (*ptstat & (0x1 << domain))
55 ;
56
57 if ((*mdstat & 0x1f) == 0x03)
58 return;
59
60 *mdctl |= 0x03;
61
62 *ptcmd = 0x1 << domain;
63
64 while (*ptstat & (0x1 << domain))
65 ;
66 while ((*mdstat & 0x1f) != 0x03)
67 ;
68}
69
70static void dspwake(void)
71{
72 unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
73 u32 val;
74
75
76 if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
77 return;
78
79 if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
80 return;
81
82 *resetvect++ = 0x1E000;
83
84 memset(resetvect, 0, sizeof(unsigned) * 10);
85
86
87 writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
88
89 dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
90 val = readl(PSC0_MDCTL + (15 * 4));
91 val |= 0x100;
92 writel(val, (PSC0_MDCTL + (15 * 4)));
93}
94
95int misc_init_r(void)
96{
97 dspwake();
98 return 0;
99}
100
101static const struct pinmux_config gpio_pins[] = {
102
103 { pinmux(16), 8, 3 },
104};
105
106const struct pinmux_resource pinmuxes[] = {
107#ifdef CONFIG_DRIVER_TI_EMAC
108 PINMUX_ITEM(emac_pins_mdio),
109#ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
110 PINMUX_ITEM(emac_pins_rmii),
111#else
112 PINMUX_ITEM(emac_pins_mii),
113#endif
114#endif
115 PINMUX_ITEM(uart2_pins_txrx),
116 PINMUX_ITEM(uart2_pins_rtscts),
117 PINMUX_ITEM(uart0_pins_txrx),
118 PINMUX_ITEM(uart0_pins_rtscts),
119#ifdef CONFIG_NAND_DAVINCI
120 PINMUX_ITEM(emifa_pins_cs3),
121 PINMUX_ITEM(emifa_pins_nand),
122#endif
123 PINMUX_ITEM(gpio_pins),
124};
125
126const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
127
128const struct lpsc_resource lpsc[] = {
129 { DAVINCI_LPSC_AEMIF },
130 { DAVINCI_LPSC_EMAC },
131 { DAVINCI_LPSC_UART2 },
132 { DAVINCI_LPSC_UART0 },
133 { DAVINCI_LPSC_GPIO },
134};
135
136const int lpsc_size = ARRAY_SIZE(lpsc);
137
138#ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
139#define CONFIG_DA850_EVM_MAX_CPU_CLK 300000000
140#endif
141
142#define REV_AM18X_EVM 0x100
143
144
145
146
147
148
149
150
151
152
153u32 get_board_rev(void)
154{
155 char *s;
156 u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
157 u32 rev = 0;
158
159 s = getenv("maxcpuclk");
160 if (s)
161 maxcpuclk = simple_strtoul(s, NULL, 10);
162
163 if (maxcpuclk >= 456000000)
164 rev = 3;
165 else if (maxcpuclk >= 408000000)
166 rev = 2;
167 else if (maxcpuclk >= 372000000)
168 rev = 1;
169#ifdef CONFIG_DA850_AM18X_EVM
170 rev |= REV_AM18X_EVM;
171#endif
172 return rev;
173}
174
175int board_early_init_f(void)
176{
177
178
179
180
181
182
183 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
184 return 1;
185
186 return 0;
187}
188
189int board_init(void)
190{
191#ifndef CONFIG_USE_IRQ
192 irq_init();
193#endif
194
195
196 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
197
198
199 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
200
201
202 writel(readl(&davinci_syscfg_regs->suspsrc) &
203 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
204 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
205 DAVINCI_SYSCFG_SUSPSRC_UART0),
206 &davinci_syscfg_regs->suspsrc);
207
208
209 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
210 return 1;
211
212#ifdef CONFIG_DRIVER_TI_EMAC
213 davinci_emac_mii_mode_sel(HAS_RMII);
214#endif
215
216
217 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
218 DAVINCI_UART_PWREMU_MGMT_UTRST),
219#if (CONFIG_SYS_NS16550_COM1 == DAVINCI_UART0_BASE)
220 &davinci_uart0_ctrl_regs->pwremu_mgmt);
221#else
222 &davinci_uart2_ctrl_regs->pwremu_mgmt);
223#endif
224 return 0;
225}
226
227#ifdef CONFIG_DRIVER_TI_EMAC
228
229
230
231int board_eth_init(bd_t *bis)
232{
233 if (!davinci_emac_initialize()) {
234 printf("Error: Ethernet init failed!\n");
235 return -1;
236 }
237
238 return 0;
239}
240#endif
241
242static int init_led(int gpio, char *name, int val)
243{
244 int ret;
245
246 ret = gpio_request(gpio, name);
247 if (ret)
248 return -1;
249 ret = gpio_direction_output(gpio, val);
250 if (ret)
251 return -1;
252
253 return gpio;
254}
255
256#define LED_ON 0
257#define LED_OFF 1
258
259#if !defined(CONFIG_SPL_BUILD)
260#ifdef CONFIG_SHOW_BOOT_PROGRESS
261void show_boot_progress(int status)
262{
263 static int red;
264 static int green;
265
266 if (red == 0)
267 red = init_led(CONFIG_IPAM390_GPIO_LED_RED, "red", LED_ON);
268 if (red != CONFIG_IPAM390_GPIO_LED_RED)
269 return;
270 if (green == 0)
271 green = init_led(CONFIG_IPAM390_GPIO_LED_GREEN, "green",
272 LED_OFF);
273 if (green != CONFIG_IPAM390_GPIO_LED_GREEN)
274 return;
275
276 switch (status) {
277 case BOOTSTAGE_ID_RUN_OS:
278
279
280
281
282
283 gpio_set_value(red, LED_ON);
284 gpio_set_value(green, LED_OFF);
285 break;
286 case BOOTSTAGE_ID_MAIN_LOOP:
287
288
289
290
291
292 gpio_set_value(red, LED_ON);
293 gpio_set_value(green, LED_ON);
294 break;
295 }
296}
297#endif
298#endif
299
300#ifdef CONFIG_SPL_OS_BOOT
301int spl_start_uboot(void)
302{
303 int ret;
304 int bootmode = 0;
305
306
307
308
309
310
311
312
313
314
315
316 ret = gpio_request(CONFIG_IPAM390_GPIO_BOOTMODE , "bootmode");
317 if (ret)
318 bootmode = 1;
319 if (!bootmode) {
320 ret = gpio_direction_input(CONFIG_IPAM390_GPIO_BOOTMODE);
321 if (ret)
322 bootmode = 1;
323 }
324 if (!bootmode)
325 ret = gpio_get_value(CONFIG_IPAM390_GPIO_BOOTMODE);
326 if (!bootmode)
327 if (ret == 0)
328 bootmode = 1;
329
330
331
332
333 init_led(CONFIG_IPAM390_GPIO_LED_RED, "red", LED_ON);
334 init_led(CONFIG_IPAM390_GPIO_LED_GREEN, "green", LED_OFF);
335 return bootmode;
336}
337#endif
338