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 | * ---------------------------------------------------------------------------- |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 19 | * SPDX-License-Identifier: GPL-2.0+ |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 20 | * ---------------------------------------------------------------------------- |
| 21 | */ |
| 22 | |
| 23 | #include <common.h> |
| 24 | #include <i2c.h> |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 25 | #include <net.h> |
| 26 | #include <netdev.h> |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 27 | #include <asm/arch/hardware.h> |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 28 | #include <asm/arch/emif_defs.h> |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 29 | #include <asm/arch/emac_defs.h> |
Vishwanathrao Badarkhe, Manish | 213c0eb | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 30 | #include <asm/arch/pinmux_defs.h> |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 31 | #include <asm/io.h> |
Manjunath Hadli | 5a8864a | 2011-10-07 23:38:39 +0000 | [diff] [blame] | 32 | #include <nand.h> |
| 33 | #include <asm/arch/nand_defs.h> |
Sughosh Ganu | 80995f9 | 2010-11-28 20:21:27 -0500 | [diff] [blame] | 34 | #include <asm/arch/davinci_misc.h> |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 35 | |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 36 | #ifdef CONFIG_DAVINCI_MMC |
| 37 | #include <mmc.h> |
| 38 | #include <asm/arch/sdmmc_defs.h> |
| 39 | #endif |
| 40 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 43 | static const struct pinmux_resource pinmuxes[] = { |
| 44 | #ifdef CONFIG_SPI_FLASH |
Vishwanathrao Badarkhe, Manish | 213c0eb | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 45 | PINMUX_ITEM(spi0_pins_base), |
| 46 | PINMUX_ITEM(spi0_pins_scs0), |
| 47 | PINMUX_ITEM(spi0_pins_ena), |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 48 | #endif |
Vishwanathrao Badarkhe, Manish | 213c0eb | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 49 | PINMUX_ITEM(uart2_pins_txrx), |
| 50 | PINMUX_ITEM(i2c0_pins), |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 51 | #ifdef CONFIG_USB_DA8XX |
| 52 | PINMUX_ITEM(usb_pins), |
| 53 | #endif |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 54 | #ifdef CONFIG_USE_NAND |
Vishwanathrao Badarkhe, Manish | 213c0eb | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 55 | PINMUX_ITEM(emifa_pins), |
| 56 | PINMUX_ITEM(emifa_pins_cs0), |
| 57 | PINMUX_ITEM(emifa_pins_cs2), |
| 58 | PINMUX_ITEM(emifa_pins_cs3), |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 59 | #endif |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 60 | #if defined(CONFIG_DRIVER_TI_EMAC) |
Vishwanathrao Badarkhe, Manish | 213c0eb | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 61 | PINMUX_ITEM(emac_pins_rmii), |
| 62 | PINMUX_ITEM(emac_pins_mdio), |
| 63 | PINMUX_ITEM(emac_pins_rmii_clk_source), |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 64 | #endif |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 65 | #ifdef CONFIG_DAVINCI_MMC |
Vishwanathrao Badarkhe, Manish | 213c0eb | 2013-05-29 21:55:11 +0000 | [diff] [blame] | 66 | PINMUX_ITEM(mmc0_pins_8bit) |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 67 | #endif |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 68 | }; |
| 69 | |
Sudhakar Rajashekhara | 66ba294 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 70 | static const struct lpsc_resource lpsc[] = { |
| 71 | { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */ |
| 72 | { DAVINCI_LPSC_SPI0 }, /* Serial Flash */ |
| 73 | { DAVINCI_LPSC_EMAC }, /* image download */ |
| 74 | { DAVINCI_LPSC_UART2 }, /* console */ |
| 75 | { DAVINCI_LPSC_GPIO }, |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 76 | #ifdef CONFIG_DAVINCI_MMC |
| 77 | { DAVINCI_LPSC_MMC_SD }, |
| 78 | #endif |
| 79 | |
| 80 | }; |
| 81 | |
| 82 | #ifdef CONFIG_DAVINCI_MMC |
| 83 | static struct davinci_mmc mmc_sd0 = { |
| 84 | .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE, |
| 85 | .host_caps = MMC_MODE_8BIT, |
| 86 | .voltages = MMC_VDD_32_33 | MMC_VDD_33_34, |
| 87 | .version = MMC_CTLR_VERSION_2, |
Sudhakar Rajashekhara | 66ba294 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 88 | }; |
| 89 | |
Vishwanathrao Badarkhe, Manish | 69a4345 | 2013-05-22 03:38:48 +0000 | [diff] [blame] | 90 | int board_mmc_init(bd_t *bis) |
| 91 | { |
| 92 | mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID); |
| 93 | |
| 94 | printf("%x\n", mmc_sd0.input_clk); |
| 95 | |
| 96 | /* Add slot-0 to mmc subsystem */ |
| 97 | return davinci_mmc_init(bis, &mmc_sd0); |
| 98 | } |
| 99 | #endif |
| 100 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 101 | int board_init(void) |
| 102 | { |
| 103 | #ifndef CONFIG_USE_IRQ |
Sudhakar Rajashekhara | 66ba294 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 104 | irq_init(); |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 105 | #endif |
| 106 | |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 107 | #ifdef CONFIG_NAND_DAVINCI |
| 108 | /* EMIFA 100MHz clock select */ |
| 109 | writel(readl(&davinci_syscfg_regs->cfgchip3) & ~2, |
| 110 | &davinci_syscfg_regs->cfgchip3); |
| 111 | /* NAND CS setup */ |
| 112 | writel((DAVINCI_ABCR_WSETUP(0) | |
| 113 | DAVINCI_ABCR_WSTROBE(2) | |
| 114 | DAVINCI_ABCR_WHOLD(0) | |
| 115 | DAVINCI_ABCR_RSETUP(0) | |
| 116 | DAVINCI_ABCR_RSTROBE(2) | |
| 117 | DAVINCI_ABCR_RHOLD(0) | |
| 118 | DAVINCI_ABCR_TA(2) | |
| 119 | DAVINCI_ABCR_ASIZE_8BIT), |
Cyril Chemparathy | c4e7224 | 2010-03-17 10:03:10 -0400 | [diff] [blame] | 120 | &davinci_emif_regs->ab2cr); |
Nick Thompson | 60b1994 | 2010-02-08 11:36:16 -0500 | [diff] [blame] | 121 | #endif |
| 122 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 123 | /* arch number of the board */ |
| 124 | gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM; |
| 125 | |
| 126 | /* address of boot parameters */ |
| 127 | gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; |
| 128 | |
| 129 | /* |
| 130 | * Power on required peripherals |
| 131 | * ARM does not have access by default to PSC0 and PSC1 |
| 132 | * assuming here that the DSP bootloader has set the IOPU |
| 133 | * such that PSC access is available to ARM |
| 134 | */ |
Sudhakar Rajashekhara | 66ba294 | 2010-06-07 12:39:59 +0530 | [diff] [blame] | 135 | if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) |
| 136 | return 1; |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 137 | |
| 138 | /* setup the SUSPSRC for ARM to control emulation suspend */ |
| 139 | writel(readl(&davinci_syscfg_regs->suspsrc) & |
| 140 | ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | |
| 141 | DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | |
| 142 | DAVINCI_SYSCFG_SUSPSRC_UART2), |
| 143 | &davinci_syscfg_regs->suspsrc); |
| 144 | |
Nick Thompson | 1d300d8 | 2010-01-27 11:11:28 -0500 | [diff] [blame] | 145 | /* configure pinmux settings */ |
| 146 | if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) |
Ajay Kumar Gupta | e94491d | 2009-12-22 10:56:11 +0530 | [diff] [blame] | 147 | return 1; |
| 148 | |
Sekhar Nori | a9ada86 | 2009-11-12 11:08:39 -0500 | [diff] [blame] | 149 | /* enable the console UART */ |
| 150 | writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | |
| 151 | DAVINCI_UART_PWREMU_MGMT_UTRST), |
| 152 | &davinci_uart2_ctrl_regs->pwremu_mgmt); |
| 153 | |
| 154 | return(0); |
| 155 | } |
Manjunath Hadli | 5a8864a | 2011-10-07 23:38:39 +0000 | [diff] [blame] | 156 | |
| 157 | |
| 158 | #ifdef CONFIG_NAND_DAVINCI |
| 159 | int board_nand_init(struct nand_chip *nand) |
| 160 | { |
| 161 | davinci_nand_init(nand); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | #endif |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 166 | |
| 167 | #if defined(CONFIG_DRIVER_TI_EMAC) |
| 168 | |
| 169 | #define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */ |
| 170 | |
| 171 | /* |
| 172 | * Initializes on-board ethernet controllers. |
| 173 | */ |
| 174 | int board_eth_init(bd_t *bis) |
| 175 | { |
| 176 | u_int8_t mac_addr[6]; |
| 177 | u_int8_t switch_start_cmd[2] = { 0x01, 0x23 }; |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 178 | struct eth_device *dev; |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 179 | |
| 180 | /* Read Ethernet MAC address from EEPROM */ |
| 181 | if (dvevm_read_mac_address(mac_addr)) |
| 182 | /* set address env if not already set */ |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 183 | davinci_sync_env_enetaddr(mac_addr); |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 184 | |
| 185 | /* read the address back from env */ |
| 186 | if (!eth_getenv_enetaddr("ethaddr", mac_addr)) |
| 187 | return -1; |
| 188 | |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 189 | /* enable the Ethernet switch in the 3 port PHY */ |
| 190 | if (i2c_write(PHY_SW_I2C_ADDR, 0, 0, |
| 191 | switch_start_cmd, sizeof(switch_start_cmd))) { |
| 192 | printf("Ethernet switch start failed!\n"); |
| 193 | return -1; |
| 194 | } |
| 195 | |
| 196 | /* finally, initialise the driver */ |
| 197 | if (!davinci_emac_initialize()) { |
| 198 | printf("Error: Ethernet init failed!\n"); |
| 199 | return -1; |
| 200 | } |
| 201 | |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 202 | dev = eth_get_dev(); |
| 203 | |
| 204 | /* provide the resulting addr to the driver */ |
| 205 | memcpy(dev->enetaddr, mac_addr, 6); |
| 206 | dev->write_hwaddr(dev); |
| 207 | |
Nick Thompson | 10a24f2 | 2010-02-17 20:37:24 -0500 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | #endif /* CONFIG_DRIVER_TI_EMAC */ |