blob: 2021e7324298dd0a41728d47b02ba5ce4bbc72e2 [file] [log] [blame]
Sekhar Noribdc9c6c2009-11-12 11:08:39 -05001/*
2 * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
3 *
4 * Base on code from TI. Original Notices follow:
5 *
6 * (C) Copyright 2008, Texas Instruments, Inc. http://www.ti.com/
7 *
8 * Modified for DA8xx EVM.
9 *
10 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
11 *
12 * Parts are shamelessly stolen from various TI sources, original copyright
13 * follows:
14 * -----------------------------------------------------------------
15 *
16 * Copyright (C) 2004 Texas Instruments.
17 *
18 * ----------------------------------------------------------------------------
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 * ----------------------------------------------------------------------------
33 */
34
35#include <common.h>
36#include <i2c.h>
Nick Thompson37cffda2010-02-17 20:37:24 -050037#include <net.h>
38#include <netdev.h>
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050039#include <asm/arch/hardware.h>
Nick Thompson3a4e4392010-02-08 11:36:16 -050040#include <asm/arch/emif_defs.h>
Nick Thompson37cffda2010-02-17 20:37:24 -050041#include <asm/arch/emac_defs.h>
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050042#include <asm/io.h>
Manjunath Hadli28375eb2011-10-07 23:38:39 +000043#include <nand.h>
44#include <asm/arch/nand_defs.h>
Sughosh Ganud7f9b502010-11-28 20:21:27 -050045#include <asm/arch/davinci_misc.h>
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050046
47DECLARE_GLOBAL_DATA_PTR;
48
Prakash PMb9f34ce2010-07-15 16:08:35 -040049#define pinmux(x) (&davinci_syscfg_regs->pinmux[x])
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050050
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050051/* SPI0 pin muxer settings */
Nick Thompson63a47df2010-01-27 11:11:28 -050052static const struct pinmux_config spi0_pins[] = {
Prakash PMb9f34ce2010-07-15 16:08:35 -040053 { pinmux(7), 1, 3 },
54 { pinmux(7), 1, 4 },
55 { pinmux(7), 1, 5 },
56 { pinmux(7), 1, 6 },
57 { pinmux(7), 1, 7 }
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050058};
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050059
Nick Thompson3a4e4392010-02-08 11:36:16 -050060/* EMIF-A bus pins for 8-bit NAND support on CS3 */
61static const struct pinmux_config emifa_nand_pins[] = {
Prakash PMb9f34ce2010-07-15 16:08:35 -040062 { pinmux(13), 1, 6 },
63 { pinmux(13), 1, 7 },
64 { pinmux(14), 1, 0 },
65 { pinmux(14), 1, 1 },
66 { pinmux(14), 1, 2 },
67 { pinmux(14), 1, 3 },
68 { pinmux(14), 1, 4 },
69 { pinmux(14), 1, 5 },
70 { pinmux(15), 1, 7 },
71 { pinmux(16), 1, 0 },
72 { pinmux(18), 1, 1 },
73 { pinmux(18), 1, 4 },
74 { pinmux(18), 1, 5 },
Nick Thompson3a4e4392010-02-08 11:36:16 -050075};
76
Nick Thompson37cffda2010-02-17 20:37:24 -050077/* EMAC PHY interface pins */
78static const struct pinmux_config emac_pins[] = {
Prakash PMb9f34ce2010-07-15 16:08:35 -040079 { pinmux(9), 0, 5 },
80 { pinmux(10), 2, 1 },
81 { pinmux(10), 2, 2 },
82 { pinmux(10), 2, 3 },
83 { pinmux(10), 2, 4 },
84 { pinmux(10), 2, 5 },
85 { pinmux(10), 2, 6 },
86 { pinmux(10), 2, 7 },
87 { pinmux(11), 2, 0 },
88 { pinmux(11), 2, 1 },
Nick Thompson37cffda2010-02-17 20:37:24 -050089};
90
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050091/* UART pin muxer settings */
Nick Thompson63a47df2010-01-27 11:11:28 -050092static const struct pinmux_config uart_pins[] = {
Prakash PMb9f34ce2010-07-15 16:08:35 -040093 { pinmux(8), 2, 7 },
94 { pinmux(9), 2, 0 }
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050095};
96
97/* I2C pin muxer settings */
Nick Thompson63a47df2010-01-27 11:11:28 -050098static const struct pinmux_config i2c_pins[] = {
Prakash PMb9f34ce2010-07-15 16:08:35 -040099 { pinmux(8), 2, 3 },
100 { pinmux(8), 2, 4 }
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500101};
102
Manjunath Hadli28375eb2011-10-07 23:38:39 +0000103#ifdef CONFIG_USE_NAND
104/* NAND pin muxer settings */
105const struct pinmux_config aemif_pins[] = {
106 { pinmux(13), 1, 6 },
107 { pinmux(13), 1, 7 },
108 { pinmux(14), 1, 0 },
109 { pinmux(14), 1, 1 },
110 { pinmux(14), 1, 2 },
111 { pinmux(14), 1, 3 },
112 { pinmux(14), 1, 4 },
113 { pinmux(14), 1, 5 },
114 { pinmux(14), 1, 6 },
115 { pinmux(14), 1, 7 },
116 { pinmux(15), 1, 0 },
117 { pinmux(15), 1, 1 },
118 { pinmux(15), 1, 2 },
119 { pinmux(15), 1, 3 },
120 { pinmux(15), 1, 4 },
121 { pinmux(15), 1, 5 },
122 { pinmux(15), 1, 6 },
123 { pinmux(15), 1, 7 },
124 { pinmux(16), 1, 0 },
125 { pinmux(16), 1, 1 },
126 { pinmux(16), 1, 2 },
127 { pinmux(16), 1, 3 },
128 { pinmux(16), 1, 4 },
129 { pinmux(16), 1, 5 },
130 { pinmux(16), 1, 6 },
131 { pinmux(16), 1, 7 },
132 { pinmux(17), 1, 0 },
133 { pinmux(17), 1, 1 },
134 { pinmux(17), 1, 2 },
135 { pinmux(17), 1, 3 },
136 { pinmux(17), 1, 4 },
137 { pinmux(17), 1, 5 },
138 { pinmux(17), 1, 6 },
139 { pinmux(17), 1, 7 },
140 { pinmux(18), 1, 0 },
141 { pinmux(18), 1, 1 },
142 { pinmux(18), 1, 2 },
143 { pinmux(18), 1, 3 },
144 { pinmux(18), 1, 4 },
145 { pinmux(18), 1, 5 },
146 { pinmux(18), 1, 6 },
147 { pinmux(18), 1, 7 },
148 { pinmux(10), 1, 0 }
149};
150#endif
151
152
Ajay Kumar Gupta82a821f2009-12-22 10:56:11 +0530153/* USB0_DRVVBUS pin muxer settings */
Nick Thompson63a47df2010-01-27 11:11:28 -0500154static const struct pinmux_config usb_pins[] = {
Prakash PMb9f34ce2010-07-15 16:08:35 -0400155 { pinmux(9), 1, 1 }
Ajay Kumar Gupta82a821f2009-12-22 10:56:11 +0530156};
157
Nick Thompson63a47df2010-01-27 11:11:28 -0500158static const struct pinmux_resource pinmuxes[] = {
159#ifdef CONFIG_SPI_FLASH
160 PINMUX_ITEM(spi0_pins),
161#endif
162 PINMUX_ITEM(uart_pins),
163 PINMUX_ITEM(i2c_pins),
164#ifdef CONFIG_USB_DA8XX
165 PINMUX_ITEM(usb_pins),
166#endif
Nick Thompson3a4e4392010-02-08 11:36:16 -0500167#ifdef CONFIG_USE_NAND
168 PINMUX_ITEM(emifa_nand_pins),
Manjunath Hadli28375eb2011-10-07 23:38:39 +0000169 PINMUX_ITEM(aemif_pins),
Nick Thompson3a4e4392010-02-08 11:36:16 -0500170#endif
Nick Thompson37cffda2010-02-17 20:37:24 -0500171#if defined(CONFIG_DRIVER_TI_EMAC)
172 PINMUX_ITEM(emac_pins),
173#endif
Nick Thompson63a47df2010-01-27 11:11:28 -0500174};
175
Sudhakar Rajashekhara9d799562010-06-07 12:39:59 +0530176static const struct lpsc_resource lpsc[] = {
177 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
178 { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
179 { DAVINCI_LPSC_EMAC }, /* image download */
180 { DAVINCI_LPSC_UART2 }, /* console */
181 { DAVINCI_LPSC_GPIO },
182};
183
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500184int board_init(void)
185{
186#ifndef CONFIG_USE_IRQ
Sudhakar Rajashekhara9d799562010-06-07 12:39:59 +0530187 irq_init();
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500188#endif
189
Nick Thompson3a4e4392010-02-08 11:36:16 -0500190#ifdef CONFIG_NAND_DAVINCI
191 /* EMIFA 100MHz clock select */
192 writel(readl(&davinci_syscfg_regs->cfgchip3) & ~2,
193 &davinci_syscfg_regs->cfgchip3);
194 /* NAND CS setup */
195 writel((DAVINCI_ABCR_WSETUP(0) |
196 DAVINCI_ABCR_WSTROBE(2) |
197 DAVINCI_ABCR_WHOLD(0) |
198 DAVINCI_ABCR_RSETUP(0) |
199 DAVINCI_ABCR_RSTROBE(2) |
200 DAVINCI_ABCR_RHOLD(0) |
201 DAVINCI_ABCR_TA(2) |
202 DAVINCI_ABCR_ASIZE_8BIT),
Cyril Chemparathycc41a592010-03-17 10:03:10 -0400203 &davinci_emif_regs->ab2cr);
Nick Thompson3a4e4392010-02-08 11:36:16 -0500204#endif
205
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500206 /* arch number of the board */
207 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM;
208
209 /* address of boot parameters */
210 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
211
212 /*
213 * Power on required peripherals
214 * ARM does not have access by default to PSC0 and PSC1
215 * assuming here that the DSP bootloader has set the IOPU
216 * such that PSC access is available to ARM
217 */
Sudhakar Rajashekhara9d799562010-06-07 12:39:59 +0530218 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
219 return 1;
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500220
221 /* setup the SUSPSRC for ARM to control emulation suspend */
222 writel(readl(&davinci_syscfg_regs->suspsrc) &
223 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
224 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
225 DAVINCI_SYSCFG_SUSPSRC_UART2),
226 &davinci_syscfg_regs->suspsrc);
227
Nick Thompson63a47df2010-01-27 11:11:28 -0500228 /* configure pinmux settings */
229 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
Ajay Kumar Gupta82a821f2009-12-22 10:56:11 +0530230 return 1;
231
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500232 /* enable the console UART */
233 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
234 DAVINCI_UART_PWREMU_MGMT_UTRST),
235 &davinci_uart2_ctrl_regs->pwremu_mgmt);
236
237 return(0);
238}
Nick Thompson37cffda2010-02-17 20:37:24 -0500239
Manjunath Hadli28375eb2011-10-07 23:38:39 +0000240
241#ifdef CONFIG_NAND_DAVINCI
242int board_nand_init(struct nand_chip *nand)
243{
244 davinci_nand_init(nand);
245
246 return 0;
247}
248#endif
249
Nick Thompson37cffda2010-02-17 20:37:24 -0500250#if defined(CONFIG_DRIVER_TI_EMAC)
251
252#define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */
253
254/*
255 * Initializes on-board ethernet controllers.
256 */
257int board_eth_init(bd_t *bis)
258{
259 u_int8_t mac_addr[6];
260 u_int8_t switch_start_cmd[2] = { 0x01, 0x23 };
Ben Gardiner7b37a272010-09-23 09:58:43 -0400261 struct eth_device *dev;
Nick Thompson37cffda2010-02-17 20:37:24 -0500262
263 /* Read Ethernet MAC address from EEPROM */
264 if (dvevm_read_mac_address(mac_addr))
265 /* set address env if not already set */
Ben Gardiner7b37a272010-09-23 09:58:43 -0400266 davinci_sync_env_enetaddr(mac_addr);
Nick Thompson37cffda2010-02-17 20:37:24 -0500267
268 /* read the address back from env */
269 if (!eth_getenv_enetaddr("ethaddr", mac_addr))
270 return -1;
271
Nick Thompson37cffda2010-02-17 20:37:24 -0500272 /* enable the Ethernet switch in the 3 port PHY */
273 if (i2c_write(PHY_SW_I2C_ADDR, 0, 0,
274 switch_start_cmd, sizeof(switch_start_cmd))) {
275 printf("Ethernet switch start failed!\n");
276 return -1;
277 }
278
279 /* finally, initialise the driver */
280 if (!davinci_emac_initialize()) {
281 printf("Error: Ethernet init failed!\n");
282 return -1;
283 }
284
Ben Gardiner7b37a272010-09-23 09:58:43 -0400285 dev = eth_get_dev();
286
287 /* provide the resulting addr to the driver */
288 memcpy(dev->enetaddr, mac_addr, 6);
289 dev->write_hwaddr(dev);
290
Nick Thompson37cffda2010-02-17 20:37:24 -0500291 return 0;
292}
293#endif /* CONFIG_DRIVER_TI_EMAC */