board.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Board functions for IGEP COM AQUILA/CYGNUS based boards
  3. *
  4. * Copyright (C) 2013, ISEE 2007 SL - http://www.isee.biz/
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <common.h>
  17. #include <errno.h>
  18. #include <spl.h>
  19. #include <asm/arch/cpu.h>
  20. #include <asm/arch/hardware.h>
  21. #include <asm/arch/omap.h>
  22. #include <asm/arch/ddr_defs.h>
  23. #include <asm/arch/clock.h>
  24. #include <asm/arch/gpio.h>
  25. #include <asm/arch/mmc_host_def.h>
  26. #include <asm/arch/sys_proto.h>
  27. #include <asm/io.h>
  28. #include <asm/emif.h>
  29. #include <asm/gpio.h>
  30. #include <i2c.h>
  31. #include <miiphy.h>
  32. #include <cpsw.h>
  33. #include "board.h"
  34. DECLARE_GLOBAL_DATA_PTR;
  35. static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
  36. #ifdef CONFIG_SPL_BUILD
  37. static struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
  38. #endif
  39. /* MII mode defines */
  40. #define RMII_MODE_ENABLE 0x4D
  41. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  42. /* UART Defines */
  43. #ifdef CONFIG_SPL_BUILD
  44. #define UART_RESET (0x1 << 1)
  45. #define UART_CLK_RUNNING_MASK 0x1
  46. #define UART_SMART_IDLE_EN (0x1 << 0x3)
  47. static void rtc32k_enable(void)
  48. {
  49. struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
  50. /*
  51. * Unlock the RTC's registers. For more details please see the
  52. * RTC_SS section of the TRM. In order to unlock we need to
  53. * write these specific values (keys) in this order.
  54. */
  55. writel(0x83e70b13, &rtc->kick0r);
  56. writel(0x95a4f1e0, &rtc->kick1r);
  57. /* Enable the RTC 32K OSC by setting bits 3 and 6. */
  58. writel((1 << 3) | (1 << 6), &rtc->osc);
  59. }
  60. static const struct ddr_data ddr3_data = {
  61. .datardsratio0 = K4B2G1646EBIH9_RD_DQS,
  62. .datawdsratio0 = K4B2G1646EBIH9_WR_DQS,
  63. .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE,
  64. .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA,
  65. .datadldiff0 = PHY_DLL_LOCK_DIFF,
  66. };
  67. static const struct cmd_control ddr3_cmd_ctrl_data = {
  68. .cmd0csratio = K4B2G1646EBIH9_RATIO,
  69. .cmd0dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF,
  70. .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
  71. .cmd1csratio = K4B2G1646EBIH9_RATIO,
  72. .cmd1dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF,
  73. .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
  74. .cmd2csratio = K4B2G1646EBIH9_RATIO,
  75. .cmd2dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF,
  76. .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
  77. };
  78. static struct emif_regs ddr3_emif_reg_data = {
  79. .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG,
  80. .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF,
  81. .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1,
  82. .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2,
  83. .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3,
  84. .zq_config = K4B2G1646EBIH9_ZQ_CFG,
  85. .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY,
  86. };
  87. #endif
  88. /*
  89. * Early system init of muxing and clocks.
  90. */
  91. void s_init(void)
  92. {
  93. /*
  94. * Save the boot parameters passed from romcode.
  95. * We cannot delay the saving further than this,
  96. * to prevent overwrites.
  97. */
  98. #ifdef CONFIG_SPL_BUILD
  99. save_omap_boot_params();
  100. #endif
  101. /* WDT1 is already running when the bootloader gets control
  102. * Disable it to avoid "random" resets
  103. */
  104. writel(0xAAAA, &wdtimer->wdtwspr);
  105. while (readl(&wdtimer->wdtwwps) != 0x0)
  106. ;
  107. writel(0x5555, &wdtimer->wdtwspr);
  108. while (readl(&wdtimer->wdtwwps) != 0x0)
  109. ;
  110. #ifdef CONFIG_SPL_BUILD
  111. /* Setup the PLLs and the clocks for the peripherals */
  112. pll_init();
  113. /* Enable RTC32K clock */
  114. rtc32k_enable();
  115. /* UART softreset */
  116. u32 regval;
  117. enable_uart0_pin_mux();
  118. regval = readl(&uart_base->uartsyscfg);
  119. regval |= UART_RESET;
  120. writel(regval, &uart_base->uartsyscfg);
  121. while ((readl(&uart_base->uartsyssts) &
  122. UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
  123. ;
  124. /* Disable smart idle */
  125. regval = readl(&uart_base->uartsyscfg);
  126. regval |= UART_SMART_IDLE_EN;
  127. writel(regval, &uart_base->uartsyscfg);
  128. gd = &gdata;
  129. preloader_console_init();
  130. /* Configure board pin mux */
  131. enable_board_pin_mux();
  132. config_ddr(303, K4B2G1646EBIH9_IOCTRL_VALUE, &ddr3_data,
  133. &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
  134. #endif
  135. }
  136. /*
  137. * Basic board specific setup. Pinmux has been handled already.
  138. */
  139. int board_init(void)
  140. {
  141. gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
  142. gpmc_init();
  143. return 0;
  144. }
  145. #if defined(CONFIG_DRIVER_TI_CPSW)
  146. static void cpsw_control(int enabled)
  147. {
  148. /* VTP can be added here */
  149. return;
  150. }
  151. static struct cpsw_slave_data cpsw_slaves[] = {
  152. {
  153. .slave_reg_ofs = 0x208,
  154. .sliver_reg_ofs = 0xd80,
  155. .phy_id = 0,
  156. .phy_if = PHY_INTERFACE_MODE_RMII,
  157. },
  158. };
  159. static struct cpsw_platform_data cpsw_data = {
  160. .mdio_base = CPSW_MDIO_BASE,
  161. .cpsw_base = CPSW_BASE,
  162. .mdio_div = 0xff,
  163. .channels = 8,
  164. .cpdma_reg_ofs = 0x800,
  165. .slaves = 1,
  166. .slave_data = cpsw_slaves,
  167. .ale_reg_ofs = 0xd00,
  168. .ale_entries = 1024,
  169. .host_port_reg_ofs = 0x108,
  170. .hw_stats_reg_ofs = 0x900,
  171. .mac_control = (1 << 5),
  172. .control = cpsw_control,
  173. .host_port_num = 0,
  174. .version = CPSW_CTRL_VERSION_2,
  175. };
  176. int board_eth_init(bd_t *bis)
  177. {
  178. int rv, ret = 0;
  179. uint8_t mac_addr[6];
  180. uint32_t mac_hi, mac_lo;
  181. if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
  182. /* try reading mac address from efuse */
  183. mac_lo = readl(&cdev->macid0l);
  184. mac_hi = readl(&cdev->macid0h);
  185. mac_addr[0] = mac_hi & 0xFF;
  186. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  187. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  188. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  189. mac_addr[4] = mac_lo & 0xFF;
  190. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  191. if (is_valid_ether_addr(mac_addr))
  192. eth_setenv_enetaddr("ethaddr", mac_addr);
  193. }
  194. writel(RMII_MODE_ENABLE, &cdev->miisel);
  195. rv = cpsw_register(&cpsw_data);
  196. if (rv < 0)
  197. printf("Error %d registering CPSW switch\n", rv);
  198. else
  199. ret += rv;
  200. return ret;
  201. }
  202. #endif