blob: ed668afccc87c32ad0df034b19a9912b67257264 [file] [log] [blame]
Sekhar Noria9ada862009-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 Thompson10a24f22010-02-17 20:37:24 -050037#include <net.h>
38#include <netdev.h>
Sekhar Noria9ada862009-11-12 11:08:39 -050039#include <asm/arch/hardware.h>
Nick Thompson60b19942010-02-08 11:36:16 -050040#include <asm/arch/emif_defs.h>
Nick Thompson10a24f22010-02-17 20:37:24 -050041#include <asm/arch/emac_defs.h>
Sekhar Noria9ada862009-11-12 11:08:39 -050042#include <asm/io.h>
43#include "../common/misc.h"
44
45DECLARE_GLOBAL_DATA_PTR;
46
47#define pinmux &davinci_syscfg_regs->pinmux
48
Sekhar Noria9ada862009-11-12 11:08:39 -050049/* SPI0 pin muxer settings */
Nick Thompson1d300d82010-01-27 11:11:28 -050050static const struct pinmux_config spi0_pins[] = {
Sekhar Noria9ada862009-11-12 11:08:39 -050051 { pinmux[7], 1, 3 },
52 { pinmux[7], 1, 4 },
53 { pinmux[7], 1, 5 },
54 { pinmux[7], 1, 6 },
55 { pinmux[7], 1, 7 }
56};
Sekhar Noria9ada862009-11-12 11:08:39 -050057
Nick Thompson60b19942010-02-08 11:36:16 -050058/* EMIF-A bus pins for 8-bit NAND support on CS3 */
59static const struct pinmux_config emifa_nand_pins[] = {
60 { pinmux[13], 1, 6 },
61 { pinmux[13], 1, 7 },
62 { pinmux[14], 1, 0 },
63 { pinmux[14], 1, 1 },
64 { pinmux[14], 1, 2 },
65 { pinmux[14], 1, 3 },
66 { pinmux[14], 1, 4 },
67 { pinmux[14], 1, 5 },
68 { pinmux[15], 1, 7 },
69 { pinmux[16], 1, 0 },
70 { pinmux[18], 1, 1 },
71 { pinmux[18], 1, 4 },
72 { pinmux[18], 1, 5 },
73};
74
Nick Thompson10a24f22010-02-17 20:37:24 -050075/* EMAC PHY interface pins */
76static const struct pinmux_config emac_pins[] = {
77 { pinmux[9], 0, 5 },
78 { pinmux[10], 2, 1 },
79 { pinmux[10], 2, 2 },
80 { pinmux[10], 2, 3 },
81 { pinmux[10], 2, 4 },
82 { pinmux[10], 2, 5 },
83 { pinmux[10], 2, 6 },
84 { pinmux[10], 2, 7 },
85 { pinmux[11], 2, 0 },
86 { pinmux[11], 2, 1 },
87};
88
Sekhar Noria9ada862009-11-12 11:08:39 -050089/* UART pin muxer settings */
Nick Thompson1d300d82010-01-27 11:11:28 -050090static const struct pinmux_config uart_pins[] = {
Sekhar Noria9ada862009-11-12 11:08:39 -050091 { pinmux[8], 2, 7 },
92 { pinmux[9], 2, 0 }
93};
94
95/* I2C pin muxer settings */
Nick Thompson1d300d82010-01-27 11:11:28 -050096static const struct pinmux_config i2c_pins[] = {
Nick Thompson10a24f22010-02-17 20:37:24 -050097 { pinmux[8], 2, 3 },
98 { pinmux[8], 2, 4 }
Sekhar Noria9ada862009-11-12 11:08:39 -050099};
100
Ajay Kumar Guptae94491d2009-12-22 10:56:11 +0530101/* USB0_DRVVBUS pin muxer settings */
Nick Thompson1d300d82010-01-27 11:11:28 -0500102static const struct pinmux_config usb_pins[] = {
Ajay Kumar Guptae94491d2009-12-22 10:56:11 +0530103 { pinmux[9], 1, 1 }
104};
105
Nick Thompson1d300d82010-01-27 11:11:28 -0500106static const struct pinmux_resource pinmuxes[] = {
107#ifdef CONFIG_SPI_FLASH
108 PINMUX_ITEM(spi0_pins),
109#endif
110 PINMUX_ITEM(uart_pins),
111 PINMUX_ITEM(i2c_pins),
112#ifdef CONFIG_USB_DA8XX
113 PINMUX_ITEM(usb_pins),
114#endif
Nick Thompson60b19942010-02-08 11:36:16 -0500115#ifdef CONFIG_USE_NAND
116 PINMUX_ITEM(emifa_nand_pins),
117#endif
Nick Thompson10a24f22010-02-17 20:37:24 -0500118#if defined(CONFIG_DRIVER_TI_EMAC)
119 PINMUX_ITEM(emac_pins),
120#endif
Nick Thompson1d300d82010-01-27 11:11:28 -0500121};
122
Sekhar Noria9ada862009-11-12 11:08:39 -0500123int board_init(void)
124{
125#ifndef CONFIG_USE_IRQ
126 /*
127 * Mask all IRQs by clearing the global enable and setting
128 * the enable clear for all the 90 interrupts.
129 */
130
131 writel(0, &davinci_aintc_regs->ger);
132
133 writel(0, &davinci_aintc_regs->hier);
134
135 writel(0xffffffff, &davinci_aintc_regs->ecr1);
136 writel(0xffffffff, &davinci_aintc_regs->ecr2);
137 writel(0xffffffff, &davinci_aintc_regs->ecr3);
138#endif
139
Nick Thompson60b19942010-02-08 11:36:16 -0500140#ifdef CONFIG_NAND_DAVINCI
141 /* EMIFA 100MHz clock select */
142 writel(readl(&davinci_syscfg_regs->cfgchip3) & ~2,
143 &davinci_syscfg_regs->cfgchip3);
144 /* NAND CS setup */
145 writel((DAVINCI_ABCR_WSETUP(0) |
146 DAVINCI_ABCR_WSTROBE(2) |
147 DAVINCI_ABCR_WHOLD(0) |
148 DAVINCI_ABCR_RSETUP(0) |
149 DAVINCI_ABCR_RSTROBE(2) |
150 DAVINCI_ABCR_RHOLD(0) |
151 DAVINCI_ABCR_TA(2) |
152 DAVINCI_ABCR_ASIZE_8BIT),
153 &davinci_emif_regs->AB2CR);
154#endif
155
Sekhar Noria9ada862009-11-12 11:08:39 -0500156 /* arch number of the board */
157 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM;
158
159 /* address of boot parameters */
160 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
161
162 /*
163 * Power on required peripherals
164 * ARM does not have access by default to PSC0 and PSC1
165 * assuming here that the DSP bootloader has set the IOPU
166 * such that PSC access is available to ARM
167 */
168 lpsc_on(DAVINCI_LPSC_AEMIF); /* NAND, NOR */
169 lpsc_on(DAVINCI_LPSC_SPI0); /* Serial Flash */
170 lpsc_on(DAVINCI_LPSC_EMAC); /* image download */
171 lpsc_on(DAVINCI_LPSC_UART2); /* console */
172 lpsc_on(DAVINCI_LPSC_GPIO);
173
174 /* setup the SUSPSRC for ARM to control emulation suspend */
175 writel(readl(&davinci_syscfg_regs->suspsrc) &
176 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
177 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
178 DAVINCI_SYSCFG_SUSPSRC_UART2),
179 &davinci_syscfg_regs->suspsrc);
180
Nick Thompson1d300d82010-01-27 11:11:28 -0500181 /* configure pinmux settings */
182 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
Ajay Kumar Guptae94491d2009-12-22 10:56:11 +0530183 return 1;
184
Sekhar Noria9ada862009-11-12 11:08:39 -0500185 /* enable the console UART */
186 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
187 DAVINCI_UART_PWREMU_MGMT_UTRST),
188 &davinci_uart2_ctrl_regs->pwremu_mgmt);
189
190 return(0);
191}
Nick Thompson10a24f22010-02-17 20:37:24 -0500192
193#if defined(CONFIG_DRIVER_TI_EMAC)
194
195#define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */
196
197/*
198 * Initializes on-board ethernet controllers.
199 */
200int board_eth_init(bd_t *bis)
201{
202 u_int8_t mac_addr[6];
203 u_int8_t switch_start_cmd[2] = { 0x01, 0x23 };
204
205 /* Read Ethernet MAC address from EEPROM */
206 if (dvevm_read_mac_address(mac_addr))
207 /* set address env if not already set */
208 dv_configure_mac_address(mac_addr);
209
210 /* read the address back from env */
211 if (!eth_getenv_enetaddr("ethaddr", mac_addr))
212 return -1;
213
214 /* provide the resulting addr to the driver */
215 davinci_eth_set_mac_addr(mac_addr);
216
217 /* enable the Ethernet switch in the 3 port PHY */
218 if (i2c_write(PHY_SW_I2C_ADDR, 0, 0,
219 switch_start_cmd, sizeof(switch_start_cmd))) {
220 printf("Ethernet switch start failed!\n");
221 return -1;
222 }
223
224 /* finally, initialise the driver */
225 if (!davinci_emac_initialize()) {
226 printf("Error: Ethernet init failed!\n");
227 return -1;
228 }
229
230 return 0;
231}
232#endif /* CONFIG_DRIVER_TI_EMAC */