da830evm.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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/io.h>
  42. #include <nand.h>
  43. #include <asm/arch/nand_defs.h>
  44. #include <asm/arch/davinci_misc.h>
  45. DECLARE_GLOBAL_DATA_PTR;
  46. /* SPI0 pin muxer settings */
  47. static const struct pinmux_config spi0_pins[] = {
  48. { pinmux(7), 1, 3 },
  49. { pinmux(7), 1, 4 },
  50. { pinmux(7), 1, 5 },
  51. { pinmux(7), 1, 6 },
  52. { pinmux(7), 1, 7 }
  53. };
  54. /* EMIF-A bus pins for 8-bit NAND support on CS3 */
  55. static const struct pinmux_config emifa_nand_pins[] = {
  56. { pinmux(13), 1, 6 },
  57. { pinmux(13), 1, 7 },
  58. { pinmux(14), 1, 0 },
  59. { pinmux(14), 1, 1 },
  60. { pinmux(14), 1, 2 },
  61. { pinmux(14), 1, 3 },
  62. { pinmux(14), 1, 4 },
  63. { pinmux(14), 1, 5 },
  64. { pinmux(15), 1, 7 },
  65. { pinmux(16), 1, 0 },
  66. { pinmux(18), 1, 1 },
  67. { pinmux(18), 1, 4 },
  68. { pinmux(18), 1, 5 },
  69. };
  70. /* EMAC PHY interface pins */
  71. static const struct pinmux_config emac_pins[] = {
  72. { pinmux(9), 0, 5 },
  73. { pinmux(10), 2, 1 },
  74. { pinmux(10), 2, 2 },
  75. { pinmux(10), 2, 3 },
  76. { pinmux(10), 2, 4 },
  77. { pinmux(10), 2, 5 },
  78. { pinmux(10), 2, 6 },
  79. { pinmux(10), 2, 7 },
  80. { pinmux(11), 2, 0 },
  81. { pinmux(11), 2, 1 },
  82. };
  83. /* UART pin muxer settings */
  84. static const struct pinmux_config uart_pins[] = {
  85. { pinmux(8), 2, 7 },
  86. { pinmux(9), 2, 0 }
  87. };
  88. /* I2C pin muxer settings */
  89. static const struct pinmux_config i2c_pins[] = {
  90. { pinmux(8), 2, 3 },
  91. { pinmux(8), 2, 4 }
  92. };
  93. #ifdef CONFIG_USE_NAND
  94. /* NAND pin muxer settings */
  95. const struct pinmux_config aemif_pins[] = {
  96. { pinmux(13), 1, 6 },
  97. { pinmux(13), 1, 7 },
  98. { pinmux(14), 1, 0 },
  99. { pinmux(14), 1, 1 },
  100. { pinmux(14), 1, 2 },
  101. { pinmux(14), 1, 3 },
  102. { pinmux(14), 1, 4 },
  103. { pinmux(14), 1, 5 },
  104. { pinmux(14), 1, 6 },
  105. { pinmux(14), 1, 7 },
  106. { pinmux(15), 1, 0 },
  107. { pinmux(15), 1, 1 },
  108. { pinmux(15), 1, 2 },
  109. { pinmux(15), 1, 3 },
  110. { pinmux(15), 1, 4 },
  111. { pinmux(15), 1, 5 },
  112. { pinmux(15), 1, 6 },
  113. { pinmux(15), 1, 7 },
  114. { pinmux(16), 1, 0 },
  115. { pinmux(16), 1, 1 },
  116. { pinmux(16), 1, 2 },
  117. { pinmux(16), 1, 3 },
  118. { pinmux(16), 1, 4 },
  119. { pinmux(16), 1, 5 },
  120. { pinmux(16), 1, 6 },
  121. { pinmux(16), 1, 7 },
  122. { pinmux(17), 1, 0 },
  123. { pinmux(17), 1, 1 },
  124. { pinmux(17), 1, 2 },
  125. { pinmux(17), 1, 3 },
  126. { pinmux(17), 1, 4 },
  127. { pinmux(17), 1, 5 },
  128. { pinmux(17), 1, 6 },
  129. { pinmux(17), 1, 7 },
  130. { pinmux(18), 1, 0 },
  131. { pinmux(18), 1, 1 },
  132. { pinmux(18), 1, 2 },
  133. { pinmux(18), 1, 3 },
  134. { pinmux(18), 1, 4 },
  135. { pinmux(18), 1, 5 },
  136. { pinmux(18), 1, 6 },
  137. { pinmux(18), 1, 7 },
  138. { pinmux(10), 1, 0 }
  139. };
  140. #endif
  141. /* USB0_DRVVBUS pin muxer settings */
  142. static const struct pinmux_config usb_pins[] = {
  143. { pinmux(9), 1, 1 }
  144. };
  145. static const struct pinmux_resource pinmuxes[] = {
  146. #ifdef CONFIG_SPI_FLASH
  147. PINMUX_ITEM(spi0_pins),
  148. #endif
  149. PINMUX_ITEM(uart_pins),
  150. PINMUX_ITEM(i2c_pins),
  151. #ifdef CONFIG_USB_DA8XX
  152. PINMUX_ITEM(usb_pins),
  153. #endif
  154. #ifdef CONFIG_USE_NAND
  155. PINMUX_ITEM(emifa_nand_pins),
  156. PINMUX_ITEM(aemif_pins),
  157. #endif
  158. #if defined(CONFIG_DRIVER_TI_EMAC)
  159. PINMUX_ITEM(emac_pins),
  160. #endif
  161. };
  162. static const struct lpsc_resource lpsc[] = {
  163. { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
  164. { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
  165. { DAVINCI_LPSC_EMAC }, /* image download */
  166. { DAVINCI_LPSC_UART2 }, /* console */
  167. { DAVINCI_LPSC_GPIO },
  168. };
  169. int board_init(void)
  170. {
  171. #ifndef CONFIG_USE_IRQ
  172. irq_init();
  173. #endif
  174. #ifdef CONFIG_NAND_DAVINCI
  175. /* EMIFA 100MHz clock select */
  176. writel(readl(&davinci_syscfg_regs->cfgchip3) & ~2,
  177. &davinci_syscfg_regs->cfgchip3);
  178. /* NAND CS setup */
  179. writel((DAVINCI_ABCR_WSETUP(0) |
  180. DAVINCI_ABCR_WSTROBE(2) |
  181. DAVINCI_ABCR_WHOLD(0) |
  182. DAVINCI_ABCR_RSETUP(0) |
  183. DAVINCI_ABCR_RSTROBE(2) |
  184. DAVINCI_ABCR_RHOLD(0) |
  185. DAVINCI_ABCR_TA(2) |
  186. DAVINCI_ABCR_ASIZE_8BIT),
  187. &davinci_emif_regs->ab2cr);
  188. #endif
  189. /* arch number of the board */
  190. gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA830_EVM;
  191. /* address of boot parameters */
  192. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  193. /*
  194. * Power on required peripherals
  195. * ARM does not have access by default to PSC0 and PSC1
  196. * assuming here that the DSP bootloader has set the IOPU
  197. * such that PSC access is available to ARM
  198. */
  199. if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
  200. return 1;
  201. /* setup the SUSPSRC for ARM to control emulation suspend */
  202. writel(readl(&davinci_syscfg_regs->suspsrc) &
  203. ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
  204. DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
  205. DAVINCI_SYSCFG_SUSPSRC_UART2),
  206. &davinci_syscfg_regs->suspsrc);
  207. /* configure pinmux settings */
  208. if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
  209. return 1;
  210. /* enable the console UART */
  211. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  212. DAVINCI_UART_PWREMU_MGMT_UTRST),
  213. &davinci_uart2_ctrl_regs->pwremu_mgmt);
  214. return(0);
  215. }
  216. #ifdef CONFIG_NAND_DAVINCI
  217. int board_nand_init(struct nand_chip *nand)
  218. {
  219. davinci_nand_init(nand);
  220. return 0;
  221. }
  222. #endif
  223. #if defined(CONFIG_DRIVER_TI_EMAC)
  224. #define PHY_SW_I2C_ADDR 0x5f /* Address of PHY on i2c bus */
  225. /*
  226. * Initializes on-board ethernet controllers.
  227. */
  228. int board_eth_init(bd_t *bis)
  229. {
  230. u_int8_t mac_addr[6];
  231. u_int8_t switch_start_cmd[2] = { 0x01, 0x23 };
  232. struct eth_device *dev;
  233. /* Read Ethernet MAC address from EEPROM */
  234. if (dvevm_read_mac_address(mac_addr))
  235. /* set address env if not already set */
  236. davinci_sync_env_enetaddr(mac_addr);
  237. /* read the address back from env */
  238. if (!eth_getenv_enetaddr("ethaddr", mac_addr))
  239. return -1;
  240. /* enable the Ethernet switch in the 3 port PHY */
  241. if (i2c_write(PHY_SW_I2C_ADDR, 0, 0,
  242. switch_start_cmd, sizeof(switch_start_cmd))) {
  243. printf("Ethernet switch start failed!\n");
  244. return -1;
  245. }
  246. /* finally, initialise the driver */
  247. if (!davinci_emac_initialize()) {
  248. printf("Error: Ethernet init failed!\n");
  249. return -1;
  250. }
  251. dev = eth_get_dev();
  252. /* provide the resulting addr to the driver */
  253. memcpy(dev->enetaddr, mac_addr, 6);
  254. dev->write_hwaddr(dev);
  255. return 0;
  256. }
  257. #endif /* CONFIG_DRIVER_TI_EMAC */