blob: c40587ff0981d0b6fc2cce785c465976fe7b36e8 [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 * ----------------------------------------------------------------------------
Wolfgang Denk1a459662013-07-08 09:37:19 +020019 * SPDX-License-Identifier: GPL-2.0+
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050020 * ----------------------------------------------------------------------------
21 */
22
23#include <common.h>
24#include <i2c.h>
Nick Thompson37cffda2010-02-17 20:37:24 -050025#include <net.h>
26#include <netdev.h>
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050027#include <asm/arch/hardware.h>
Nick Thompson37cffda2010-02-17 20:37:24 -050028#include <asm/arch/emac_defs.h>
Vishwanathrao Badarkhe, Manish68cd4a42013-05-29 21:55:11 +000029#include <asm/arch/pinmux_defs.h>
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050030#include <asm/io.h>
Manjunath Hadli28375eb2011-10-07 23:38:39 +000031#include <nand.h>
Khoronzhuk, Ivan3e01ed02014-06-07 04:22:52 +030032#include <asm/ti-common/davinci_nand.h>
Sughosh Ganud7f9b502010-11-28 20:21:27 -050033#include <asm/arch/davinci_misc.h>
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050034
Vishwanathrao Badarkhe, Manish03e08d72013-05-22 03:38:48 +000035#ifdef CONFIG_DAVINCI_MMC
36#include <mmc.h>
37#include <asm/arch/sdmmc_defs.h>
38#endif
39
Sekhar Noribdc9c6c2009-11-12 11:08:39 -050040DECLARE_GLOBAL_DATA_PTR;
41
Nick Thompson63a47df2010-01-27 11:11:28 -050042static const struct pinmux_resource pinmuxes[] = {
43#ifdef CONFIG_SPI_FLASH
Vishwanathrao Badarkhe, Manish68cd4a42013-05-29 21:55:11 +000044 PINMUX_ITEM(spi0_pins_base),
45 PINMUX_ITEM(spi0_pins_scs0),
46 PINMUX_ITEM(spi0_pins_ena),
Nick Thompson63a47df2010-01-27 11:11:28 -050047#endif
Vishwanathrao Badarkhe, Manish68cd4a42013-05-29 21:55:11 +000048 PINMUX_ITEM(uart2_pins_txrx),
49 PINMUX_ITEM(i2c0_pins),
Nick Thompson63a47df2010-01-27 11:11:28 -050050#ifdef CONFIG_USB_DA8XX
51 PINMUX_ITEM(usb_pins),
52#endif
Nick Thompson3a4e4392010-02-08 11:36:16 -050053#ifdef CONFIG_USE_NAND
Vishwanathrao Badarkhe, Manish68cd4a42013-05-29 21:55:11 +000054 PINMUX_ITEM(emifa_pins),
55 PINMUX_ITEM(emifa_pins_cs0),
56 PINMUX_ITEM(emifa_pins_cs2),
57 PINMUX_ITEM(emifa_pins_cs3),
Nick Thompson3a4e4392010-02-08 11:36:16 -050058#endif
Nick Thompson37cffda2010-02-17 20:37:24 -050059#if defined(CONFIG_DRIVER_TI_EMAC)
Vishwanathrao Badarkhe, Manish68cd4a42013-05-29 21:55:11 +000060 PINMUX_ITEM(emac_pins_rmii),
61 PINMUX_ITEM(emac_pins_mdio),
62 PINMUX_ITEM(emac_pins_rmii_clk_source),
Nick Thompson37cffda2010-02-17 20:37:24 -050063#endif
Vishwanathrao Badarkhe, Manish03e08d72013-05-22 03:38:48 +000064#ifdef CONFIG_DAVINCI_MMC
Vishwanathrao Badarkhe, Manish68cd4a42013-05-29 21:55:11 +000065 PINMUX_ITEM(mmc0_pins_8bit)
Vishwanathrao Badarkhe, Manish03e08d72013-05-22 03:38:48 +000066#endif
Nick Thompson63a47df2010-01-27 11:11:28 -050067};
68
Sudhakar Rajashekhara9d799562010-06-07 12:39:59 +053069static const struct lpsc_resource lpsc[] = {
70 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
71 { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
72 { DAVINCI_LPSC_EMAC }, /* image download */
73 { DAVINCI_LPSC_UART2 }, /* console */
74 { DAVINCI_LPSC_GPIO },
Vishwanathrao Badarkhe, Manish03e08d72013-05-22 03:38:48 +000075#ifdef CONFIG_DAVINCI_MMC
76 { DAVINCI_LPSC_MMC_SD },
77#endif
78
Sudhakar Rajashekhara9d799562010-06-07 12:39:59 +053079};
80
Vishwanathrao Badarkhe, Manish03e08d72013-05-22 03:38:48 +000081#ifdef CONFIG_DAVINCI_MMC
82static struct davinci_mmc mmc_sd0 = {
83 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
84 .host_caps = MMC_MODE_8BIT,
85 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
86 .version = MMC_CTLR_VERSION_2,
87};
88
89int board_mmc_init(bd_t *bis)
90{
91 mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
92
93 printf("%x\n", mmc_sd0.input_clk);
94
95 /* Add slot-0 to mmc subsystem */
96 return davinci_mmc_init(bis, &mmc_sd0);
97}
98#endif
99
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500100int board_init(void)
101{
102#ifndef CONFIG_USE_IRQ
Sudhakar Rajashekhara9d799562010-06-07 12:39:59 +0530103 irq_init();
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500104#endif
105
Nick Thompson3a4e4392010-02-08 11:36:16 -0500106#ifdef CONFIG_NAND_DAVINCI
107 /* EMIFA 100MHz clock select */
108 writel(readl(&davinci_syscfg_regs->cfgchip3) & ~2,
109 &davinci_syscfg_regs->cfgchip3);
110 /* NAND CS setup */
111 writel((DAVINCI_ABCR_WSETUP(0) |
112 DAVINCI_ABCR_WSTROBE(2) |
113 DAVINCI_ABCR_WHOLD(0) |
114 DAVINCI_ABCR_RSETUP(0) |
115 DAVINCI_ABCR_RSTROBE(2) |
116 DAVINCI_ABCR_RHOLD(0) |
117 DAVINCI_ABCR_TA(2) |
118 DAVINCI_ABCR_ASIZE_8BIT),
Cyril Chemparathycc41a592010-03-17 10:03:10 -0400119 &davinci_emif_regs->ab2cr);
Nick Thompson3a4e4392010-02-08 11:36:16 -0500120#endif
121
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500122 /* arch number of the board */
123 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM;
124
125 /* address of boot parameters */
126 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
127
128 /*
129 * Power on required peripherals
130 * ARM does not have access by default to PSC0 and PSC1
131 * assuming here that the DSP bootloader has set the IOPU
132 * such that PSC access is available to ARM
133 */
Sudhakar Rajashekhara9d799562010-06-07 12:39:59 +0530134 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
135 return 1;
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500136
137 /* setup the SUSPSRC for ARM to control emulation suspend */
138 writel(readl(&davinci_syscfg_regs->suspsrc) &
139 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
140 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
141 DAVINCI_SYSCFG_SUSPSRC_UART2),
142 &davinci_syscfg_regs->suspsrc);
143
Nick Thompson63a47df2010-01-27 11:11:28 -0500144 /* configure pinmux settings */
145 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
Ajay Kumar Gupta82a821f2009-12-22 10:56:11 +0530146 return 1;
147
Sekhar Noribdc9c6c2009-11-12 11:08:39 -0500148 /* enable the console UART */
149 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
150 DAVINCI_UART_PWREMU_MGMT_UTRST),
151 &davinci_uart2_ctrl_regs->pwremu_mgmt);
152
153 return(0);
154}
Nick Thompson37cffda2010-02-17 20:37:24 -0500155
Manjunath Hadli28375eb2011-10-07 23:38:39 +0000156
157#ifdef CONFIG_NAND_DAVINCI
158int board_nand_init(struct nand_chip *nand)
159{
160 davinci_nand_init(nand);
161
162 return 0;
163}
164#endif
165
Nick Thompson37cffda2010-02-17 20:37:24 -0500166#if defined(CONFIG_DRIVER_TI_EMAC)
167
168#define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */
169
170/*
171 * Initializes on-board ethernet controllers.
172 */
173int board_eth_init(bd_t *bis)
174{
175 u_int8_t mac_addr[6];
176 u_int8_t switch_start_cmd[2] = { 0x01, 0x23 };
Ben Gardiner7b37a272010-09-23 09:58:43 -0400177 struct eth_device *dev;
Nick Thompson37cffda2010-02-17 20:37:24 -0500178
179 /* Read Ethernet MAC address from EEPROM */
180 if (dvevm_read_mac_address(mac_addr))
181 /* set address env if not already set */
Ben Gardiner7b37a272010-09-23 09:58:43 -0400182 davinci_sync_env_enetaddr(mac_addr);
Nick Thompson37cffda2010-02-17 20:37:24 -0500183
184 /* read the address back from env */
185 if (!eth_getenv_enetaddr("ethaddr", mac_addr))
186 return -1;
187
Nick Thompson37cffda2010-02-17 20:37:24 -0500188 /* enable the Ethernet switch in the 3 port PHY */
189 if (i2c_write(PHY_SW_I2C_ADDR, 0, 0,
190 switch_start_cmd, sizeof(switch_start_cmd))) {
191 printf("Ethernet switch start failed!\n");
192 return -1;
193 }
194
195 /* finally, initialise the driver */
196 if (!davinci_emac_initialize()) {
197 printf("Error: Ethernet init failed!\n");
198 return -1;
199 }
200
Ben Gardiner7b37a272010-09-23 09:58:43 -0400201 dev = eth_get_dev();
202
203 /* provide the resulting addr to the driver */
204 memcpy(dev->enetaddr, mac_addr, 6);
205 dev->write_hwaddr(dev);
206
Nick Thompson37cffda2010-02-17 20:37:24 -0500207 return 0;
208}
209#endif /* CONFIG_DRIVER_TI_EMAC */