blob: a4e92541578bd70535594957ce256a1ce6439005 [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>
Vishwanathrao Badarkhe, Manish213c0eb2013-05-29 21:55:11 +000042#include <asm/arch/pinmux_defs.h>
Sekhar Noria9ada862009-11-12 11:08:39 -050043#include <asm/io.h>
Manjunath Hadli5a8864a2011-10-07 23:38:39 +000044#include <nand.h>
45#include <asm/arch/nand_defs.h>
Sughosh Ganu80995f92010-11-28 20:21:27 -050046#include <asm/arch/davinci_misc.h>
Sekhar Noria9ada862009-11-12 11:08:39 -050047
Vishwanathrao Badarkhe, Manish69a43452013-05-22 03:38:48 +000048#ifdef CONFIG_DAVINCI_MMC
49#include <mmc.h>
50#include <asm/arch/sdmmc_defs.h>
51#endif
52
Sekhar Noria9ada862009-11-12 11:08:39 -050053DECLARE_GLOBAL_DATA_PTR;
54
Nick Thompson1d300d82010-01-27 11:11:28 -050055static const struct pinmux_resource pinmuxes[] = {
56#ifdef CONFIG_SPI_FLASH
Vishwanathrao Badarkhe, Manish213c0eb2013-05-29 21:55:11 +000057 PINMUX_ITEM(spi0_pins_base),
58 PINMUX_ITEM(spi0_pins_scs0),
59 PINMUX_ITEM(spi0_pins_ena),
Nick Thompson1d300d82010-01-27 11:11:28 -050060#endif
Vishwanathrao Badarkhe, Manish213c0eb2013-05-29 21:55:11 +000061 PINMUX_ITEM(uart2_pins_txrx),
62 PINMUX_ITEM(i2c0_pins),
Nick Thompson1d300d82010-01-27 11:11:28 -050063#ifdef CONFIG_USB_DA8XX
64 PINMUX_ITEM(usb_pins),
65#endif
Nick Thompson60b19942010-02-08 11:36:16 -050066#ifdef CONFIG_USE_NAND
Vishwanathrao Badarkhe, Manish213c0eb2013-05-29 21:55:11 +000067 PINMUX_ITEM(emifa_pins),
68 PINMUX_ITEM(emifa_pins_cs0),
69 PINMUX_ITEM(emifa_pins_cs2),
70 PINMUX_ITEM(emifa_pins_cs3),
Nick Thompson60b19942010-02-08 11:36:16 -050071#endif
Nick Thompson10a24f22010-02-17 20:37:24 -050072#if defined(CONFIG_DRIVER_TI_EMAC)
Vishwanathrao Badarkhe, Manish213c0eb2013-05-29 21:55:11 +000073 PINMUX_ITEM(emac_pins_rmii),
74 PINMUX_ITEM(emac_pins_mdio),
75 PINMUX_ITEM(emac_pins_rmii_clk_source),
Nick Thompson10a24f22010-02-17 20:37:24 -050076#endif
Vishwanathrao Badarkhe, Manish69a43452013-05-22 03:38:48 +000077#ifdef CONFIG_DAVINCI_MMC
Vishwanathrao Badarkhe, Manish213c0eb2013-05-29 21:55:11 +000078 PINMUX_ITEM(mmc0_pins_8bit)
Vishwanathrao Badarkhe, Manish69a43452013-05-22 03:38:48 +000079#endif
Nick Thompson1d300d82010-01-27 11:11:28 -050080};
81
Sudhakar Rajashekhara66ba2942010-06-07 12:39:59 +053082static const struct lpsc_resource lpsc[] = {
83 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
84 { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
85 { DAVINCI_LPSC_EMAC }, /* image download */
86 { DAVINCI_LPSC_UART2 }, /* console */
87 { DAVINCI_LPSC_GPIO },
Vishwanathrao Badarkhe, Manish69a43452013-05-22 03:38:48 +000088#ifdef CONFIG_DAVINCI_MMC
89 { DAVINCI_LPSC_MMC_SD },
90#endif
91
92};
93
94#ifdef CONFIG_DAVINCI_MMC
95static struct davinci_mmc mmc_sd0 = {
96 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
97 .host_caps = MMC_MODE_8BIT,
98 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
99 .version = MMC_CTLR_VERSION_2,
Sudhakar Rajashekhara66ba2942010-06-07 12:39:59 +0530100};
101
Vishwanathrao Badarkhe, Manish69a43452013-05-22 03:38:48 +0000102int board_mmc_init(bd_t *bis)
103{
104 mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
105
106 printf("%x\n", mmc_sd0.input_clk);
107
108 /* Add slot-0 to mmc subsystem */
109 return davinci_mmc_init(bis, &mmc_sd0);
110}
111#endif
112
Sekhar Noria9ada862009-11-12 11:08:39 -0500113int board_init(void)
114{
115#ifndef CONFIG_USE_IRQ
Sudhakar Rajashekhara66ba2942010-06-07 12:39:59 +0530116 irq_init();
Sekhar Noria9ada862009-11-12 11:08:39 -0500117#endif
118
Nick Thompson60b19942010-02-08 11:36:16 -0500119#ifdef CONFIG_NAND_DAVINCI
120 /* EMIFA 100MHz clock select */
121 writel(readl(&davinci_syscfg_regs->cfgchip3) & ~2,
122 &davinci_syscfg_regs->cfgchip3);
123 /* NAND CS setup */
124 writel((DAVINCI_ABCR_WSETUP(0) |
125 DAVINCI_ABCR_WSTROBE(2) |
126 DAVINCI_ABCR_WHOLD(0) |
127 DAVINCI_ABCR_RSETUP(0) |
128 DAVINCI_ABCR_RSTROBE(2) |
129 DAVINCI_ABCR_RHOLD(0) |
130 DAVINCI_ABCR_TA(2) |
131 DAVINCI_ABCR_ASIZE_8BIT),
Cyril Chemparathyc4e72242010-03-17 10:03:10 -0400132 &davinci_emif_regs->ab2cr);
Nick Thompson60b19942010-02-08 11:36:16 -0500133#endif
134
Sekhar Noria9ada862009-11-12 11:08:39 -0500135 /* arch number of the board */
136 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM;
137
138 /* address of boot parameters */
139 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
140
141 /*
142 * Power on required peripherals
143 * ARM does not have access by default to PSC0 and PSC1
144 * assuming here that the DSP bootloader has set the IOPU
145 * such that PSC access is available to ARM
146 */
Sudhakar Rajashekhara66ba2942010-06-07 12:39:59 +0530147 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
148 return 1;
Sekhar Noria9ada862009-11-12 11:08:39 -0500149
150 /* setup the SUSPSRC for ARM to control emulation suspend */
151 writel(readl(&davinci_syscfg_regs->suspsrc) &
152 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
153 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
154 DAVINCI_SYSCFG_SUSPSRC_UART2),
155 &davinci_syscfg_regs->suspsrc);
156
Nick Thompson1d300d82010-01-27 11:11:28 -0500157 /* configure pinmux settings */
158 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
Ajay Kumar Guptae94491d2009-12-22 10:56:11 +0530159 return 1;
160
Sekhar Noria9ada862009-11-12 11:08:39 -0500161 /* enable the console UART */
162 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
163 DAVINCI_UART_PWREMU_MGMT_UTRST),
164 &davinci_uart2_ctrl_regs->pwremu_mgmt);
165
166 return(0);
167}
Manjunath Hadli5a8864a2011-10-07 23:38:39 +0000168
169
170#ifdef CONFIG_NAND_DAVINCI
171int board_nand_init(struct nand_chip *nand)
172{
173 davinci_nand_init(nand);
174
175 return 0;
176}
177#endif
Nick Thompson10a24f22010-02-17 20:37:24 -0500178
179#if defined(CONFIG_DRIVER_TI_EMAC)
180
181#define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */
182
183/*
184 * Initializes on-board ethernet controllers.
185 */
186int board_eth_init(bd_t *bis)
187{
188 u_int8_t mac_addr[6];
189 u_int8_t switch_start_cmd[2] = { 0x01, 0x23 };
Ben Gardiner1fb49e32010-09-23 09:58:43 -0400190 struct eth_device *dev;
Nick Thompson10a24f22010-02-17 20:37:24 -0500191
192 /* Read Ethernet MAC address from EEPROM */
193 if (dvevm_read_mac_address(mac_addr))
194 /* set address env if not already set */
Ben Gardiner1fb49e32010-09-23 09:58:43 -0400195 davinci_sync_env_enetaddr(mac_addr);
Nick Thompson10a24f22010-02-17 20:37:24 -0500196
197 /* read the address back from env */
198 if (!eth_getenv_enetaddr("ethaddr", mac_addr))
199 return -1;
200
Nick Thompson10a24f22010-02-17 20:37:24 -0500201 /* enable the Ethernet switch in the 3 port PHY */
202 if (i2c_write(PHY_SW_I2C_ADDR, 0, 0,
203 switch_start_cmd, sizeof(switch_start_cmd))) {
204 printf("Ethernet switch start failed!\n");
205 return -1;
206 }
207
208 /* finally, initialise the driver */
209 if (!davinci_emac_initialize()) {
210 printf("Error: Ethernet init failed!\n");
211 return -1;
212 }
213
Ben Gardiner1fb49e32010-09-23 09:58:43 -0400214 dev = eth_get_dev();
215
216 /* provide the resulting addr to the driver */
217 memcpy(dev->enetaddr, mac_addr, 6);
218 dev->write_hwaddr(dev);
219
Nick Thompson10a24f22010-02-17 20:37:24 -0500220 return 0;
221}
222#endif /* CONFIG_DRIVER_TI_EMAC */