blob: 57506d647adac4c592dfd474de4efb1a41e8a2e3 [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"
Sudhakar Rajashekhara66ba2942010-06-07 12:39:59 +053044#include "common.h"
Sekhar Noria9ada862009-11-12 11:08:39 -050045
46DECLARE_GLOBAL_DATA_PTR;
47
48#define pinmux &davinci_syscfg_regs->pinmux
49
Sekhar Noria9ada862009-11-12 11:08:39 -050050/* SPI0 pin muxer settings */
Nick Thompson1d300d82010-01-27 11:11:28 -050051static const struct pinmux_config spi0_pins[] = {
Sekhar Noria9ada862009-11-12 11:08:39 -050052 { pinmux[7], 1, 3 },
53 { pinmux[7], 1, 4 },
54 { pinmux[7], 1, 5 },
55 { pinmux[7], 1, 6 },
56 { pinmux[7], 1, 7 }
57};
Sekhar Noria9ada862009-11-12 11:08:39 -050058
Nick Thompson60b19942010-02-08 11:36:16 -050059/* EMIF-A bus pins for 8-bit NAND support on CS3 */
60static const struct pinmux_config emifa_nand_pins[] = {
61 { pinmux[13], 1, 6 },
62 { pinmux[13], 1, 7 },
63 { pinmux[14], 1, 0 },
64 { pinmux[14], 1, 1 },
65 { pinmux[14], 1, 2 },
66 { pinmux[14], 1, 3 },
67 { pinmux[14], 1, 4 },
68 { pinmux[14], 1, 5 },
69 { pinmux[15], 1, 7 },
70 { pinmux[16], 1, 0 },
71 { pinmux[18], 1, 1 },
72 { pinmux[18], 1, 4 },
73 { pinmux[18], 1, 5 },
74};
75
Nick Thompson10a24f22010-02-17 20:37:24 -050076/* EMAC PHY interface pins */
77static const struct pinmux_config emac_pins[] = {
78 { pinmux[9], 0, 5 },
79 { pinmux[10], 2, 1 },
80 { pinmux[10], 2, 2 },
81 { pinmux[10], 2, 3 },
82 { pinmux[10], 2, 4 },
83 { pinmux[10], 2, 5 },
84 { pinmux[10], 2, 6 },
85 { pinmux[10], 2, 7 },
86 { pinmux[11], 2, 0 },
87 { pinmux[11], 2, 1 },
88};
89
Sekhar Noria9ada862009-11-12 11:08:39 -050090/* UART pin muxer settings */
Nick Thompson1d300d82010-01-27 11:11:28 -050091static const struct pinmux_config uart_pins[] = {
Sekhar Noria9ada862009-11-12 11:08:39 -050092 { pinmux[8], 2, 7 },
93 { pinmux[9], 2, 0 }
94};
95
96/* I2C pin muxer settings */
Nick Thompson1d300d82010-01-27 11:11:28 -050097static const struct pinmux_config i2c_pins[] = {
Nick Thompson10a24f22010-02-17 20:37:24 -050098 { pinmux[8], 2, 3 },
99 { pinmux[8], 2, 4 }
Sekhar Noria9ada862009-11-12 11:08:39 -0500100};
101
Ajay Kumar Guptae94491d2009-12-22 10:56:11 +0530102/* USB0_DRVVBUS pin muxer settings */
Nick Thompson1d300d82010-01-27 11:11:28 -0500103static const struct pinmux_config usb_pins[] = {
Ajay Kumar Guptae94491d2009-12-22 10:56:11 +0530104 { pinmux[9], 1, 1 }
105};
106
Nick Thompson1d300d82010-01-27 11:11:28 -0500107static const struct pinmux_resource pinmuxes[] = {
108#ifdef CONFIG_SPI_FLASH
109 PINMUX_ITEM(spi0_pins),
110#endif
111 PINMUX_ITEM(uart_pins),
112 PINMUX_ITEM(i2c_pins),
113#ifdef CONFIG_USB_DA8XX
114 PINMUX_ITEM(usb_pins),
115#endif
Nick Thompson60b19942010-02-08 11:36:16 -0500116#ifdef CONFIG_USE_NAND
117 PINMUX_ITEM(emifa_nand_pins),
118#endif
Nick Thompson10a24f22010-02-17 20:37:24 -0500119#if defined(CONFIG_DRIVER_TI_EMAC)
120 PINMUX_ITEM(emac_pins),
121#endif
Nick Thompson1d300d82010-01-27 11:11:28 -0500122};
123
Sudhakar Rajashekhara66ba2942010-06-07 12:39:59 +0530124static const struct lpsc_resource lpsc[] = {
125 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
126 { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
127 { DAVINCI_LPSC_EMAC }, /* image download */
128 { DAVINCI_LPSC_UART2 }, /* console */
129 { DAVINCI_LPSC_GPIO },
130};
131
Sekhar Noria9ada862009-11-12 11:08:39 -0500132int board_init(void)
133{
134#ifndef CONFIG_USE_IRQ
Sudhakar Rajashekhara66ba2942010-06-07 12:39:59 +0530135 irq_init();
Sekhar Noria9ada862009-11-12 11:08:39 -0500136#endif
137
Nick Thompson60b19942010-02-08 11:36:16 -0500138#ifdef CONFIG_NAND_DAVINCI
139 /* EMIFA 100MHz clock select */
140 writel(readl(&davinci_syscfg_regs->cfgchip3) & ~2,
141 &davinci_syscfg_regs->cfgchip3);
142 /* NAND CS setup */
143 writel((DAVINCI_ABCR_WSETUP(0) |
144 DAVINCI_ABCR_WSTROBE(2) |
145 DAVINCI_ABCR_WHOLD(0) |
146 DAVINCI_ABCR_RSETUP(0) |
147 DAVINCI_ABCR_RSTROBE(2) |
148 DAVINCI_ABCR_RHOLD(0) |
149 DAVINCI_ABCR_TA(2) |
150 DAVINCI_ABCR_ASIZE_8BIT),
Cyril Chemparathyc4e72242010-03-17 10:03:10 -0400151 &davinci_emif_regs->ab2cr);
Nick Thompson60b19942010-02-08 11:36:16 -0500152#endif
153
Sekhar Noria9ada862009-11-12 11:08:39 -0500154 /* arch number of the board */
155 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM;
156
157 /* address of boot parameters */
158 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
159
160 /*
161 * Power on required peripherals
162 * ARM does not have access by default to PSC0 and PSC1
163 * assuming here that the DSP bootloader has set the IOPU
164 * such that PSC access is available to ARM
165 */
Sudhakar Rajashekhara66ba2942010-06-07 12:39:59 +0530166 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
167 return 1;
Sekhar Noria9ada862009-11-12 11:08:39 -0500168
169 /* setup the SUSPSRC for ARM to control emulation suspend */
170 writel(readl(&davinci_syscfg_regs->suspsrc) &
171 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
172 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
173 DAVINCI_SYSCFG_SUSPSRC_UART2),
174 &davinci_syscfg_regs->suspsrc);
175
Nick Thompson1d300d82010-01-27 11:11:28 -0500176 /* configure pinmux settings */
177 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
Ajay Kumar Guptae94491d2009-12-22 10:56:11 +0530178 return 1;
179
Sekhar Noria9ada862009-11-12 11:08:39 -0500180 /* enable the console UART */
181 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
182 DAVINCI_UART_PWREMU_MGMT_UTRST),
183 &davinci_uart2_ctrl_regs->pwremu_mgmt);
184
185 return(0);
186}
Nick Thompson10a24f22010-02-17 20:37:24 -0500187
188#if defined(CONFIG_DRIVER_TI_EMAC)
189
190#define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */
191
192/*
193 * Initializes on-board ethernet controllers.
194 */
195int board_eth_init(bd_t *bis)
196{
197 u_int8_t mac_addr[6];
198 u_int8_t switch_start_cmd[2] = { 0x01, 0x23 };
199
200 /* Read Ethernet MAC address from EEPROM */
201 if (dvevm_read_mac_address(mac_addr))
202 /* set address env if not already set */
203 dv_configure_mac_address(mac_addr);
204
205 /* read the address back from env */
206 if (!eth_getenv_enetaddr("ethaddr", mac_addr))
207 return -1;
208
209 /* provide the resulting addr to the driver */
210 davinci_eth_set_mac_addr(mac_addr);
211
212 /* enable the Ethernet switch in the 3 port PHY */
213 if (i2c_write(PHY_SW_I2C_ADDR, 0, 0,
214 switch_start_cmd, sizeof(switch_start_cmd))) {
215 printf("Ethernet switch start failed!\n");
216 return -1;
217 }
218
219 /* finally, initialise the driver */
220 if (!davinci_emac_initialize()) {
221 printf("Error: Ethernet init failed!\n");
222 return -1;
223 }
224
225 return 0;
226}
227#endif /* CONFIG_DRIVER_TI_EMAC */