da830evm.c 7.3 KB

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