evm.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * evm.c
  3. *
  4. * Board functions for TI814x EVM
  5. *
  6. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <common.h>
  19. #include <cpsw.h>
  20. #include <errno.h>
  21. #include <spl.h>
  22. #include <asm/arch/cpu.h>
  23. #include <asm/arch/hardware.h>
  24. #include <asm/arch/omap.h>
  25. #include <asm/arch/ddr_defs.h>
  26. #include <asm/arch/clock.h>
  27. #include <asm/arch/gpio.h>
  28. #include <asm/arch/mmc_host_def.h>
  29. #include <asm/arch/sys_proto.h>
  30. #include <asm/io.h>
  31. #include <asm/emif.h>
  32. #include <asm/gpio.h>
  33. #include "evm.h"
  34. DECLARE_GLOBAL_DATA_PTR;
  35. #ifdef CONFIG_SPL_BUILD
  36. static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
  37. static struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
  38. #endif
  39. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  40. /* UART Defines */
  41. #ifdef CONFIG_SPL_BUILD
  42. #define UART_RESET (0x1 << 1)
  43. #define UART_CLK_RUNNING_MASK 0x1
  44. #define UART_SMART_IDLE_EN (0x1 << 0x3)
  45. static void rtc32k_enable(void)
  46. {
  47. struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
  48. /*
  49. * Unlock the RTC's registers. For more details please see the
  50. * RTC_SS section of the TRM. In order to unlock we need to
  51. * write these specific values (keys) in this order.
  52. */
  53. writel(0x83e70b13, &rtc->kick0r);
  54. writel(0x95a4f1e0, &rtc->kick1r);
  55. /* Enable the RTC 32K OSC by setting bits 3 and 6. */
  56. writel((1 << 3) | (1 << 6), &rtc->osc);
  57. }
  58. static void uart_enable(void)
  59. {
  60. u32 regVal;
  61. /* UART softreset */
  62. regVal = readl(&uart_base->uartsyscfg);
  63. regVal |= UART_RESET;
  64. writel(regVal, &uart_base->uartsyscfg);
  65. while ((readl(&uart_base->uartsyssts) &
  66. UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
  67. ;
  68. /* Disable smart idle */
  69. regVal = readl(&uart_base->uartsyscfg);
  70. regVal |= UART_SMART_IDLE_EN;
  71. writel(regVal, &uart_base->uartsyscfg);
  72. }
  73. static void wdt_disable(void)
  74. {
  75. writel(0xAAAA, &wdtimer->wdtwspr);
  76. while (readl(&wdtimer->wdtwwps) != 0x0)
  77. ;
  78. writel(0x5555, &wdtimer->wdtwspr);
  79. while (readl(&wdtimer->wdtwwps) != 0x0)
  80. ;
  81. }
  82. static const struct cmd_control evm_ddr2_cctrl_data = {
  83. .cmd0csratio = 0x80,
  84. .cmd0dldiff = 0x04,
  85. .cmd0iclkout = 0x00,
  86. .cmd1csratio = 0x80,
  87. .cmd1dldiff = 0x04,
  88. .cmd1iclkout = 0x00,
  89. .cmd2csratio = 0x80,
  90. .cmd2dldiff = 0x04,
  91. .cmd2iclkout = 0x00,
  92. };
  93. static const struct emif_regs evm_ddr2_emif0_regs = {
  94. .sdram_config = 0x40801ab2,
  95. .ref_ctrl = 0x10000c30,
  96. .sdram_tim1 = 0x0aaaf552,
  97. .sdram_tim2 = 0x043631d2,
  98. .sdram_tim3 = 0x00000327,
  99. .emif_ddr_phy_ctlr_1 = 0x00000007
  100. };
  101. static const struct emif_regs evm_ddr2_emif1_regs = {
  102. .sdram_config = 0x40801ab2,
  103. .ref_ctrl = 0x10000c30,
  104. .sdram_tim1 = 0x0aaaf552,
  105. .sdram_tim2 = 0x043631d2,
  106. .sdram_tim3 = 0x00000327,
  107. .emif_ddr_phy_ctlr_1 = 0x00000007
  108. };
  109. const struct dmm_lisa_map_regs evm_lisa_map_regs = {
  110. .dmm_lisa_map_0 = 0x00000000,
  111. .dmm_lisa_map_1 = 0x00000000,
  112. .dmm_lisa_map_2 = 0x806c0300,
  113. .dmm_lisa_map_3 = 0x806c0300,
  114. };
  115. static const struct ddr_data evm_ddr2_data = {
  116. .datardsratio0 = ((0x35<<10) | (0x35<<0)),
  117. .datawdsratio0 = ((0x20<<10) | (0x20<<0)),
  118. .datawiratio0 = ((0<<10) | (0<<0)),
  119. .datagiratio0 = ((0<<10) | (0<<0)),
  120. .datafwsratio0 = ((0x90<<10) | (0x90<<0)),
  121. .datawrsratio0 = ((0x50<<10) | (0x50<<0)),
  122. .datauserank0delay = 1,
  123. .datadldiff0 = 0x4,
  124. };
  125. #endif
  126. /*
  127. * early system init of muxing and clocks.
  128. */
  129. void s_init(void)
  130. {
  131. #ifdef CONFIG_SPL_BUILD
  132. /* WDT1 is already running when the bootloader gets control
  133. * Disable it to avoid "random" resets
  134. */
  135. wdt_disable();
  136. /* Enable timer */
  137. timer_init();
  138. /* Setup the PLLs and the clocks for the peripherals */
  139. pll_init();
  140. /* Enable RTC32K clock */
  141. rtc32k_enable();
  142. /* Set UART pins */
  143. enable_uart0_pin_mux();
  144. /* Set MMC pins */
  145. enable_mmc1_pin_mux();
  146. /* Set Ethernet pins */
  147. enable_enet_pin_mux();
  148. /* Enable UART */
  149. uart_enable();
  150. gd = &gdata;
  151. preloader_console_init();
  152. config_dmm(&evm_lisa_map_regs);
  153. config_ddr(0, 0, &evm_ddr2_data, &evm_ddr2_cctrl_data,
  154. &evm_ddr2_emif0_regs, 0);
  155. config_ddr(0, 0, &evm_ddr2_data, &evm_ddr2_cctrl_data,
  156. &evm_ddr2_emif1_regs, 1);
  157. #endif
  158. }
  159. /*
  160. * Basic board specific setup. Pinmux has been handled already.
  161. */
  162. int board_init(void)
  163. {
  164. gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
  165. return 0;
  166. }
  167. #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
  168. int board_mmc_init(bd_t *bis)
  169. {
  170. omap_mmc_init(1, 0, 0, -1, -1);
  171. return 0;
  172. }
  173. #endif
  174. #ifdef CONFIG_DRIVER_TI_CPSW
  175. static void cpsw_control(int enabled)
  176. {
  177. /* VTP can be added here */
  178. return;
  179. }
  180. static struct cpsw_slave_data cpsw_slaves[] = {
  181. {
  182. .slave_reg_ofs = 0x50,
  183. .sliver_reg_ofs = 0x700,
  184. .phy_id = 1,
  185. },
  186. {
  187. .slave_reg_ofs = 0x90,
  188. .sliver_reg_ofs = 0x740,
  189. .phy_id = 0,
  190. },
  191. };
  192. static struct cpsw_platform_data cpsw_data = {
  193. .mdio_base = CPSW_MDIO_BASE,
  194. .cpsw_base = CPSW_BASE,
  195. .mdio_div = 0xff,
  196. .channels = 8,
  197. .cpdma_reg_ofs = 0x100,
  198. .slaves = 1,
  199. .slave_data = cpsw_slaves,
  200. .ale_reg_ofs = 0x600,
  201. .ale_entries = 1024,
  202. .host_port_reg_ofs = 0x28,
  203. .hw_stats_reg_ofs = 0x400,
  204. .mac_control = (1 << 5),
  205. .control = cpsw_control,
  206. .host_port_num = 0,
  207. .version = CPSW_CTRL_VERSION_1,
  208. };
  209. #endif
  210. int board_eth_init(bd_t *bis)
  211. {
  212. uint8_t mac_addr[6];
  213. uint32_t mac_hi, mac_lo;
  214. if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
  215. printf("<ethaddr> not set. Reading from E-fuse\n");
  216. /* try reading mac address from efuse */
  217. mac_lo = readl(&cdev->macid0l);
  218. mac_hi = readl(&cdev->macid0h);
  219. mac_addr[0] = mac_hi & 0xFF;
  220. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  221. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  222. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  223. mac_addr[4] = mac_lo & 0xFF;
  224. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  225. if (is_valid_ether_addr(mac_addr))
  226. eth_setenv_enetaddr("ethaddr", mac_addr);
  227. else
  228. printf("Unable to read MAC address. Set <ethaddr>\n");
  229. }
  230. return cpsw_register(&cpsw_data);
  231. }