da830evm.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. #include <common.h>
  35. #include <i2c.h>
  36. #include <net.h>
  37. #include <netdev.h>
  38. #include <asm/arch/hardware.h>
  39. #include <asm/arch/emif_defs.h>
  40. #include <asm/arch/emac_defs.h>
  41. #include <asm/arch/pinmux_defs.h>
  42. #include <asm/io.h>
  43. #include <nand.h>
  44. #include <asm/arch/nand_defs.h>
  45. #include <asm/arch/davinci_misc.h>
  46. #ifdef CONFIG_DAVINCI_MMC
  47. #include <mmc.h>
  48. #include <asm/arch/sdmmc_defs.h>
  49. #endif
  50. DECLARE_GLOBAL_DATA_PTR;
  51. static const struct pinmux_resource pinmuxes[] = {
  52. #ifdef CONFIG_SPI_FLASH
  53. PINMUX_ITEM(spi0_pins_base),
  54. PINMUX_ITEM(spi0_pins_scs0),
  55. PINMUX_ITEM(spi0_pins_ena),
  56. #endif
  57. PINMUX_ITEM(uart2_pins_txrx),
  58. PINMUX_ITEM(i2c0_pins),
  59. #ifdef CONFIG_USB_DA8XX
  60. PINMUX_ITEM(usb_pins),
  61. #endif
  62. #ifdef CONFIG_USE_NAND
  63. PINMUX_ITEM(emifa_pins),
  64. PINMUX_ITEM(emifa_pins_cs0),
  65. PINMUX_ITEM(emifa_pins_cs2),
  66. PINMUX_ITEM(emifa_pins_cs3),
  67. #endif
  68. #if defined(CONFIG_DRIVER_TI_EMAC)
  69. PINMUX_ITEM(emac_pins_rmii),
  70. PINMUX_ITEM(emac_pins_mdio),
  71. PINMUX_ITEM(emac_pins_rmii_clk_source),
  72. #endif
  73. #ifdef CONFIG_DAVINCI_MMC
  74. PINMUX_ITEM(mmc0_pins_8bit)
  75. #endif
  76. };
  77. static const struct lpsc_resource lpsc[] = {
  78. { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
  79. { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
  80. { DAVINCI_LPSC_EMAC }, /* image download */
  81. { DAVINCI_LPSC_UART2 }, /* console */
  82. { DAVINCI_LPSC_GPIO },
  83. #ifdef CONFIG_DAVINCI_MMC
  84. { DAVINCI_LPSC_MMC_SD },
  85. #endif
  86. };
  87. #ifdef CONFIG_DAVINCI_MMC
  88. static struct davinci_mmc mmc_sd0 = {
  89. .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
  90. .host_caps = MMC_MODE_8BIT,
  91. .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
  92. .version = MMC_CTLR_VERSION_2,
  93. };
  94. int board_mmc_init(bd_t *bis)
  95. {
  96. mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
  97. printf("%x\n", mmc_sd0.input_clk);
  98. /* Add slot-0 to mmc subsystem */
  99. return davinci_mmc_init(bis, &mmc_sd0);
  100. }
  101. #endif
  102. int board_init(void)
  103. {
  104. #ifndef CONFIG_USE_IRQ
  105. irq_init();
  106. #endif
  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),
  120. &davinci_emif_regs->ab2cr);
  121. #endif
  122. /* arch number of the board */
  123. gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM;
  124. /* address of boot parameters */
  125. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  126. /*
  127. * Power on required peripherals
  128. * ARM does not have access by default to PSC0 and PSC1
  129. * assuming here that the DSP bootloader has set the IOPU
  130. * such that PSC access is available to ARM
  131. */
  132. if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
  133. return 1;
  134. /* setup the SUSPSRC for ARM to control emulation suspend */
  135. writel(readl(&davinci_syscfg_regs->suspsrc) &
  136. ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
  137. DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
  138. DAVINCI_SYSCFG_SUSPSRC_UART2),
  139. &davinci_syscfg_regs->suspsrc);
  140. /* configure pinmux settings */
  141. if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
  142. return 1;
  143. /* enable the console UART */
  144. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  145. DAVINCI_UART_PWREMU_MGMT_UTRST),
  146. &davinci_uart2_ctrl_regs->pwremu_mgmt);
  147. return(0);
  148. }
  149. #ifdef CONFIG_NAND_DAVINCI
  150. int board_nand_init(struct nand_chip *nand)
  151. {
  152. davinci_nand_init(nand);
  153. return 0;
  154. }
  155. #endif
  156. #if defined(CONFIG_DRIVER_TI_EMAC)
  157. #define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */
  158. /*
  159. * Initializes on-board ethernet controllers.
  160. */
  161. int board_eth_init(bd_t *bis)
  162. {
  163. u_int8_t mac_addr[6];
  164. u_int8_t switch_start_cmd[2] = { 0x01, 0x23 };
  165. struct eth_device *dev;
  166. /* Read Ethernet MAC address from EEPROM */
  167. if (dvevm_read_mac_address(mac_addr))
  168. /* set address env if not already set */
  169. davinci_sync_env_enetaddr(mac_addr);
  170. /* read the address back from env */
  171. if (!eth_getenv_enetaddr("ethaddr", mac_addr))
  172. return -1;
  173. /* enable the Ethernet switch in the 3 port PHY */
  174. if (i2c_write(PHY_SW_I2C_ADDR, 0, 0,
  175. switch_start_cmd, sizeof(switch_start_cmd))) {
  176. printf("Ethernet switch start failed!\n");
  177. return -1;
  178. }
  179. /* finally, initialise the driver */
  180. if (!davinci_emac_initialize()) {
  181. printf("Error: Ethernet init failed!\n");
  182. return -1;
  183. }
  184. dev = eth_get_dev();
  185. /* provide the resulting addr to the driver */
  186. memcpy(dev->enetaddr, mac_addr, 6);
  187. dev->write_hwaddr(dev);
  188. return 0;
  189. }
  190. #endif /* CONFIG_DRIVER_TI_EMAC */