Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 1 | /* |
| 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 Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 37 | #include <net.h> |
| 38 | #include <netdev.h> |
Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 39 | #include <asm/arch/hardware.h> |
Nick Thompson | 3a4e439 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 40 | #include <asm/arch/emif_defs.h> |
Nick Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 41 | #include <asm/arch/emac_defs.h> |
Vishwanathrao Badarkhe, Manish | 68cd4a4 | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 42 | #include <asm/arch/pinmux_defs.h> |
Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 43 | #include <asm/io.h> |
Manjunath Hadli | 28375eb | 2011-10-07 23:38:39 +0000 | [diff] [blame] | 44 | #include <nand.h> |
| 45 | #include <asm/arch/nand_defs.h> |
Sughosh Ganu | d7f9b50 | 2010-11-28 20:21:27 -0500 | [diff] [blame] | 46 | #include <asm/arch/davinci_misc.h> |
Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 47 | |
Vishwanathrao Badarkhe, Manish | 03e08d7 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_DAVINCI_MMC |
| 49 | #include <mmc.h> |
| 50 | #include <asm/arch/sdmmc_defs.h> |
| 51 | #endif |
| 52 | |
Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 53 | DECLARE_GLOBAL_DATA_PTR; |
| 54 | |
Nick Thompson | 63a47df | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 55 | static const struct pinmux_resource pinmuxes[] = { |
| 56 | #ifdef CONFIG_SPI_FLASH |
Vishwanathrao Badarkhe, Manish | 68cd4a4 | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 57 | PINMUX_ITEM(spi0_pins_base), |
| 58 | PINMUX_ITEM(spi0_pins_scs0), |
| 59 | PINMUX_ITEM(spi0_pins_ena), |
Nick Thompson | 63a47df | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 60 | #endif |
Vishwanathrao Badarkhe, Manish | 68cd4a4 | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 61 | PINMUX_ITEM(uart2_pins_txrx), |
| 62 | PINMUX_ITEM(i2c0_pins), |
Nick Thompson | 63a47df | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 63 | #ifdef CONFIG_USB_DA8XX |
| 64 | PINMUX_ITEM(usb_pins), |
| 65 | #endif |
Nick Thompson | 3a4e439 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 66 | #ifdef CONFIG_USE_NAND |
Vishwanathrao Badarkhe, Manish | 68cd4a4 | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 67 | PINMUX_ITEM(emifa_pins), |
| 68 | PINMUX_ITEM(emifa_pins_cs0), |
| 69 | PINMUX_ITEM(emifa_pins_cs2), |
| 70 | PINMUX_ITEM(emifa_pins_cs3), |
Nick Thompson | 3a4e439 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 71 | #endif |
Nick Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 72 | #if defined(CONFIG_DRIVER_TI_EMAC) |
Vishwanathrao Badarkhe, Manish | 68cd4a4 | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 73 | PINMUX_ITEM(emac_pins_rmii), |
| 74 | PINMUX_ITEM(emac_pins_mdio), |
| 75 | PINMUX_ITEM(emac_pins_rmii_clk_source), |
Nick Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 76 | #endif |
Vishwanathrao Badarkhe, Manish | 03e08d7 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 77 | #ifdef CONFIG_DAVINCI_MMC |
Vishwanathrao Badarkhe, Manish | 68cd4a4 | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 78 | PINMUX_ITEM(mmc0_pins_8bit) |
Vishwanathrao Badarkhe, Manish | 03e08d7 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 79 | #endif |
Nick Thompson | 63a47df | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 80 | }; |
| 81 | |
Sudhakar Rajashekhara | 9d79956 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 82 | static 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, Manish | 03e08d7 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 88 | #ifdef CONFIG_DAVINCI_MMC |
| 89 | { DAVINCI_LPSC_MMC_SD }, |
| 90 | #endif |
| 91 | |
Sudhakar Rajashekhara | 9d79956 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 92 | }; |
| 93 | |
Vishwanathrao Badarkhe, Manish | 03e08d7 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 94 | #ifdef CONFIG_DAVINCI_MMC |
| 95 | static 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, |
| 100 | }; |
| 101 | |
| 102 | int 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 Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 113 | int board_init(void) |
| 114 | { |
| 115 | #ifndef CONFIG_USE_IRQ |
Sudhakar Rajashekhara | 9d79956 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 116 | irq_init(); |
Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 117 | #endif |
| 118 | |
Nick Thompson | 3a4e439 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 119 | #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 Chemparathy | cc41a59 | 2010-03-17 10:03:10 -0400 | [diff] [blame] | 132 | &davinci_emif_regs->ab2cr); |
Nick Thompson | 3a4e439 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 133 | #endif |
| 134 | |
Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 135 | /* 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 Rajashekhara | 9d79956 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 147 | if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) |
| 148 | return 1; |
Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 149 | |
| 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 Thompson | 63a47df | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 157 | /* configure pinmux settings */ |
| 158 | if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) |
Ajay Kumar Gupta | 82a821f | 2009-12-22 10:56:11 +0530 | [diff] [blame] | 159 | return 1; |
| 160 | |
Sekhar Nori | bdc9c6c | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 161 | /* 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 | } |
Nick Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 168 | |
Manjunath Hadli | 28375eb | 2011-10-07 23:38:39 +0000 | [diff] [blame] | 169 | |
| 170 | #ifdef CONFIG_NAND_DAVINCI |
| 171 | int board_nand_init(struct nand_chip *nand) |
| 172 | { |
| 173 | davinci_nand_init(nand); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | #endif |
| 178 | |
Nick Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 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 | */ |
| 186 | int 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 Gardiner | 7b37a27 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 190 | struct eth_device *dev; |
Nick Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 191 | |
| 192 | /* Read Ethernet MAC address from EEPROM */ |
| 193 | if (dvevm_read_mac_address(mac_addr)) |
| 194 | /* set address env if not already set */ |
Ben Gardiner | 7b37a27 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 195 | davinci_sync_env_enetaddr(mac_addr); |
Nick Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 196 | |
| 197 | /* read the address back from env */ |
| 198 | if (!eth_getenv_enetaddr("ethaddr", mac_addr)) |
| 199 | return -1; |
| 200 | |
Nick Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 201 | /* 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 Gardiner | 7b37a27 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 214 | 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 Thompson | 37cffda | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 220 | return 0; |
| 221 | } |
| 222 | #endif /* CONFIG_DRIVER_TI_EMAC */ |