Sekhar Nori | a9ada86 | 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 | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 37 | #include <net.h> |
| 38 | #include <netdev.h> |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 39 | #include <asm/arch/hardware.h> |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 40 | #include <asm/arch/emif_defs.h> |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 41 | #include <asm/arch/emac_defs.h> |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 42 | #include <asm/io.h> |
Manjunath Hadli | 5a8864a | 2011-10-07 23:38:39 +0000 | [diff] [blame] | 43 | #include <nand.h> |
| 44 | #include <asm/arch/nand_defs.h> |
Sughosh Ganu | 80995f9 | 2010-11-28 20:21:27 -0500 | [diff] [blame] | 45 | #include <asm/arch/davinci_misc.h> |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 46 | |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame^] | 47 | #ifdef CONFIG_DAVINCI_MMC |
| 48 | #include <mmc.h> |
| 49 | #include <asm/arch/sdmmc_defs.h> |
| 50 | #endif |
| 51 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 52 | DECLARE_GLOBAL_DATA_PTR; |
| 53 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 54 | /* SPI0 pin muxer settings */ |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 55 | static const struct pinmux_config spi0_pins[] = { |
Prakash PM | ba8f78f | 2010-07-15 16:08:35 -0400 | [diff] [blame] | 56 | { pinmux(7), 1, 3 }, |
| 57 | { pinmux(7), 1, 4 }, |
| 58 | { pinmux(7), 1, 5 }, |
| 59 | { pinmux(7), 1, 6 }, |
| 60 | { pinmux(7), 1, 7 } |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 61 | }; |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 62 | |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 63 | /* EMIF-A bus pins for 8-bit NAND support on CS3 */ |
| 64 | static const struct pinmux_config emifa_nand_pins[] = { |
Prakash PM | ba8f78f | 2010-07-15 16:08:35 -0400 | [diff] [blame] | 65 | { pinmux(13), 1, 6 }, |
| 66 | { pinmux(13), 1, 7 }, |
| 67 | { pinmux(14), 1, 0 }, |
| 68 | { pinmux(14), 1, 1 }, |
| 69 | { pinmux(14), 1, 2 }, |
| 70 | { pinmux(14), 1, 3 }, |
| 71 | { pinmux(14), 1, 4 }, |
| 72 | { pinmux(14), 1, 5 }, |
| 73 | { pinmux(15), 1, 7 }, |
| 74 | { pinmux(16), 1, 0 }, |
| 75 | { pinmux(18), 1, 1 }, |
| 76 | { pinmux(18), 1, 4 }, |
| 77 | { pinmux(18), 1, 5 }, |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 80 | /* EMAC PHY interface pins */ |
| 81 | static const struct pinmux_config emac_pins[] = { |
Prakash PM | ba8f78f | 2010-07-15 16:08:35 -0400 | [diff] [blame] | 82 | { pinmux(9), 0, 5 }, |
| 83 | { pinmux(10), 2, 1 }, |
| 84 | { pinmux(10), 2, 2 }, |
| 85 | { pinmux(10), 2, 3 }, |
| 86 | { pinmux(10), 2, 4 }, |
| 87 | { pinmux(10), 2, 5 }, |
| 88 | { pinmux(10), 2, 6 }, |
| 89 | { pinmux(10), 2, 7 }, |
| 90 | { pinmux(11), 2, 0 }, |
| 91 | { pinmux(11), 2, 1 }, |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 92 | }; |
| 93 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 94 | /* UART pin muxer settings */ |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 95 | static const struct pinmux_config uart_pins[] = { |
Prakash PM | ba8f78f | 2010-07-15 16:08:35 -0400 | [diff] [blame] | 96 | { pinmux(8), 2, 7 }, |
| 97 | { pinmux(9), 2, 0 } |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /* I2C pin muxer settings */ |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 101 | static const struct pinmux_config i2c_pins[] = { |
Prakash PM | ba8f78f | 2010-07-15 16:08:35 -0400 | [diff] [blame] | 102 | { pinmux(8), 2, 3 }, |
| 103 | { pinmux(8), 2, 4 } |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 104 | }; |
| 105 | |
Manjunath Hadli | 5a8864a | 2011-10-07 23:38:39 +0000 | [diff] [blame] | 106 | #ifdef CONFIG_USE_NAND |
| 107 | /* NAND pin muxer settings */ |
| 108 | const struct pinmux_config aemif_pins[] = { |
| 109 | { pinmux(13), 1, 6 }, |
| 110 | { pinmux(13), 1, 7 }, |
| 111 | { pinmux(14), 1, 0 }, |
| 112 | { pinmux(14), 1, 1 }, |
| 113 | { pinmux(14), 1, 2 }, |
| 114 | { pinmux(14), 1, 3 }, |
| 115 | { pinmux(14), 1, 4 }, |
| 116 | { pinmux(14), 1, 5 }, |
| 117 | { pinmux(14), 1, 6 }, |
| 118 | { pinmux(14), 1, 7 }, |
| 119 | { pinmux(15), 1, 0 }, |
| 120 | { pinmux(15), 1, 1 }, |
| 121 | { pinmux(15), 1, 2 }, |
| 122 | { pinmux(15), 1, 3 }, |
| 123 | { pinmux(15), 1, 4 }, |
| 124 | { pinmux(15), 1, 5 }, |
| 125 | { pinmux(15), 1, 6 }, |
| 126 | { pinmux(15), 1, 7 }, |
| 127 | { pinmux(16), 1, 0 }, |
| 128 | { pinmux(16), 1, 1 }, |
| 129 | { pinmux(16), 1, 2 }, |
| 130 | { pinmux(16), 1, 3 }, |
| 131 | { pinmux(16), 1, 4 }, |
| 132 | { pinmux(16), 1, 5 }, |
| 133 | { pinmux(16), 1, 6 }, |
| 134 | { pinmux(16), 1, 7 }, |
| 135 | { pinmux(17), 1, 0 }, |
| 136 | { pinmux(17), 1, 1 }, |
| 137 | { pinmux(17), 1, 2 }, |
| 138 | { pinmux(17), 1, 3 }, |
| 139 | { pinmux(17), 1, 4 }, |
| 140 | { pinmux(17), 1, 5 }, |
| 141 | { pinmux(17), 1, 6 }, |
| 142 | { pinmux(17), 1, 7 }, |
| 143 | { pinmux(18), 1, 0 }, |
| 144 | { pinmux(18), 1, 1 }, |
| 145 | { pinmux(18), 1, 2 }, |
| 146 | { pinmux(18), 1, 3 }, |
| 147 | { pinmux(18), 1, 4 }, |
| 148 | { pinmux(18), 1, 5 }, |
| 149 | { pinmux(18), 1, 6 }, |
| 150 | { pinmux(18), 1, 7 }, |
| 151 | { pinmux(10), 1, 0 } |
| 152 | }; |
| 153 | #endif |
| 154 | |
| 155 | |
Ajay Kumar Gupta | e94491d | 2009-12-22 10:56:11 +0530 | [diff] [blame] | 156 | /* USB0_DRVVBUS pin muxer settings */ |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 157 | static const struct pinmux_config usb_pins[] = { |
Prakash PM | ba8f78f | 2010-07-15 16:08:35 -0400 | [diff] [blame] | 158 | { pinmux(9), 1, 1 } |
Ajay Kumar Gupta | e94491d | 2009-12-22 10:56:11 +0530 | [diff] [blame] | 159 | }; |
| 160 | |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame^] | 161 | #ifdef CONFIG_DAVINCI_MMC |
| 162 | /* MMC0 pin muxer settings */ |
| 163 | const struct pinmux_config mmc0_pins[] = { |
| 164 | { pinmux(15), 2, 7 }, /* MMCSD0_CLK */ |
| 165 | { pinmux(16), 2, 0 }, /* MMCSD0_CMD */ |
| 166 | { pinmux(13), 2, 6 }, /* MMCSD0_DAT_0 */ |
| 167 | { pinmux(13), 2, 7 }, /* MMCSD0_DAT_1 */ |
| 168 | { pinmux(14), 2, 0 }, /* MMCSD0_DAT_2 */ |
| 169 | { pinmux(14), 2, 1 }, /* MMCSD0_DAT_3 */ |
| 170 | { pinmux(14), 2, 2 }, /* MMCSD0_DAT_4 */ |
| 171 | { pinmux(14), 2, 3 }, /* MMCSD0_DAT_5 */ |
| 172 | { pinmux(14), 2, 4 }, /* MMCSD0_DAT_6 */ |
| 173 | { pinmux(14), 2, 5 }, /* MMCSD0_DAT_7 */ |
| 174 | /* DA830 supports 8-bit mode */ |
| 175 | }; |
| 176 | #endif |
| 177 | |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 178 | static const struct pinmux_resource pinmuxes[] = { |
| 179 | #ifdef CONFIG_SPI_FLASH |
| 180 | PINMUX_ITEM(spi0_pins), |
| 181 | #endif |
| 182 | PINMUX_ITEM(uart_pins), |
| 183 | PINMUX_ITEM(i2c_pins), |
| 184 | #ifdef CONFIG_USB_DA8XX |
| 185 | PINMUX_ITEM(usb_pins), |
| 186 | #endif |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 187 | #ifdef CONFIG_USE_NAND |
| 188 | PINMUX_ITEM(emifa_nand_pins), |
Manjunath Hadli | 5a8864a | 2011-10-07 23:38:39 +0000 | [diff] [blame] | 189 | PINMUX_ITEM(aemif_pins), |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 190 | #endif |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 191 | #if defined(CONFIG_DRIVER_TI_EMAC) |
| 192 | PINMUX_ITEM(emac_pins), |
| 193 | #endif |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame^] | 194 | #ifdef CONFIG_DAVINCI_MMC |
| 195 | PINMUX_ITEM(mmc0_pins), |
| 196 | #endif |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 197 | }; |
| 198 | |
Sudhakar Rajashekhara | 66ba294 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 199 | static const struct lpsc_resource lpsc[] = { |
| 200 | { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */ |
| 201 | { DAVINCI_LPSC_SPI0 }, /* Serial Flash */ |
| 202 | { DAVINCI_LPSC_EMAC }, /* image download */ |
| 203 | { DAVINCI_LPSC_UART2 }, /* console */ |
| 204 | { DAVINCI_LPSC_GPIO }, |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame^] | 205 | #ifdef CONFIG_DAVINCI_MMC |
| 206 | { DAVINCI_LPSC_MMC_SD }, |
| 207 | #endif |
| 208 | |
| 209 | }; |
| 210 | |
| 211 | #ifdef CONFIG_DAVINCI_MMC |
| 212 | static struct davinci_mmc mmc_sd0 = { |
| 213 | .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE, |
| 214 | .host_caps = MMC_MODE_8BIT, |
| 215 | .voltages = MMC_VDD_32_33 | MMC_VDD_33_34, |
| 216 | .version = MMC_CTLR_VERSION_2, |
Sudhakar Rajashekhara | 66ba294 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 217 | }; |
| 218 | |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame^] | 219 | int board_mmc_init(bd_t *bis) |
| 220 | { |
| 221 | mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID); |
| 222 | |
| 223 | printf("%x\n", mmc_sd0.input_clk); |
| 224 | |
| 225 | /* Add slot-0 to mmc subsystem */ |
| 226 | return davinci_mmc_init(bis, &mmc_sd0); |
| 227 | } |
| 228 | #endif |
| 229 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 230 | int board_init(void) |
| 231 | { |
| 232 | #ifndef CONFIG_USE_IRQ |
Sudhakar Rajashekhara | 66ba294 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 233 | irq_init(); |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 234 | #endif |
| 235 | |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 236 | #ifdef CONFIG_NAND_DAVINCI |
| 237 | /* EMIFA 100MHz clock select */ |
| 238 | writel(readl(&davinci_syscfg_regs->cfgchip3) & ~2, |
| 239 | &davinci_syscfg_regs->cfgchip3); |
| 240 | /* NAND CS setup */ |
| 241 | writel((DAVINCI_ABCR_WSETUP(0) | |
| 242 | DAVINCI_ABCR_WSTROBE(2) | |
| 243 | DAVINCI_ABCR_WHOLD(0) | |
| 244 | DAVINCI_ABCR_RSETUP(0) | |
| 245 | DAVINCI_ABCR_RSTROBE(2) | |
| 246 | DAVINCI_ABCR_RHOLD(0) | |
| 247 | DAVINCI_ABCR_TA(2) | |
| 248 | DAVINCI_ABCR_ASIZE_8BIT), |
Cyril Chemparathy | c4e7224 | 2010-03-17 10:03:10 -0400 | [diff] [blame] | 249 | &davinci_emif_regs->ab2cr); |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 250 | #endif |
| 251 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 252 | /* arch number of the board */ |
| 253 | gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM; |
| 254 | |
| 255 | /* address of boot parameters */ |
| 256 | gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; |
| 257 | |
| 258 | /* |
| 259 | * Power on required peripherals |
| 260 | * ARM does not have access by default to PSC0 and PSC1 |
| 261 | * assuming here that the DSP bootloader has set the IOPU |
| 262 | * such that PSC access is available to ARM |
| 263 | */ |
Sudhakar Rajashekhara | 66ba294 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 264 | if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) |
| 265 | return 1; |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 266 | |
| 267 | /* setup the SUSPSRC for ARM to control emulation suspend */ |
| 268 | writel(readl(&davinci_syscfg_regs->suspsrc) & |
| 269 | ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | |
| 270 | DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | |
| 271 | DAVINCI_SYSCFG_SUSPSRC_UART2), |
| 272 | &davinci_syscfg_regs->suspsrc); |
| 273 | |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 274 | /* configure pinmux settings */ |
| 275 | if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) |
Ajay Kumar Gupta | e94491d | 2009-12-22 10:56:11 +0530 | [diff] [blame] | 276 | return 1; |
| 277 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 278 | /* enable the console UART */ |
| 279 | writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | |
| 280 | DAVINCI_UART_PWREMU_MGMT_UTRST), |
| 281 | &davinci_uart2_ctrl_regs->pwremu_mgmt); |
| 282 | |
| 283 | return(0); |
| 284 | } |
Manjunath Hadli | 5a8864a | 2011-10-07 23:38:39 +0000 | [diff] [blame] | 285 | |
| 286 | |
| 287 | #ifdef CONFIG_NAND_DAVINCI |
| 288 | int board_nand_init(struct nand_chip *nand) |
| 289 | { |
| 290 | davinci_nand_init(nand); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | #endif |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 295 | |
| 296 | #if defined(CONFIG_DRIVER_TI_EMAC) |
| 297 | |
| 298 | #define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */ |
| 299 | |
| 300 | /* |
| 301 | * Initializes on-board ethernet controllers. |
| 302 | */ |
| 303 | int board_eth_init(bd_t *bis) |
| 304 | { |
| 305 | u_int8_t mac_addr[6]; |
| 306 | u_int8_t switch_start_cmd[2] = { 0x01, 0x23 }; |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 307 | struct eth_device *dev; |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 308 | |
| 309 | /* Read Ethernet MAC address from EEPROM */ |
| 310 | if (dvevm_read_mac_address(mac_addr)) |
| 311 | /* set address env if not already set */ |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 312 | davinci_sync_env_enetaddr(mac_addr); |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 313 | |
| 314 | /* read the address back from env */ |
| 315 | if (!eth_getenv_enetaddr("ethaddr", mac_addr)) |
| 316 | return -1; |
| 317 | |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 318 | /* enable the Ethernet switch in the 3 port PHY */ |
| 319 | if (i2c_write(PHY_SW_I2C_ADDR, 0, 0, |
| 320 | switch_start_cmd, sizeof(switch_start_cmd))) { |
| 321 | printf("Ethernet switch start failed!\n"); |
| 322 | return -1; |
| 323 | } |
| 324 | |
| 325 | /* finally, initialise the driver */ |
| 326 | if (!davinci_emac_initialize()) { |
| 327 | printf("Error: Ethernet init failed!\n"); |
| 328 | return -1; |
| 329 | } |
| 330 | |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 331 | dev = eth_get_dev(); |
| 332 | |
| 333 | /* provide the resulting addr to the driver */ |
| 334 | memcpy(dev->enetaddr, mac_addr, 6); |
| 335 | dev->write_hwaddr(dev); |
| 336 | |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 337 | return 0; |
| 338 | } |
| 339 | #endif /* CONFIG_DRIVER_TI_EMAC */ |