board.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. /* WDT1 is already running when the bootloader gets control
  94. * Disable it to avoid "random" resets
  95. */
  96. writel(0xAAAA, &wdtimer->wdtwspr);
  97. while (readl(&wdtimer->wdtwwps) != 0x0)
  98. ;
  99. writel(0x5555, &wdtimer->wdtwspr);
  100. while (readl(&wdtimer->wdtwwps) != 0x0)
  101. ;
  102. #ifdef CONFIG_SPL_BUILD
  103. /* Setup the PLLs and the clocks for the peripherals */
  104. pll_init();
  105. /* Enable RTC32K clock */
  106. rtc32k_enable();
  107. /* UART softreset */
  108. u32 regval;
  109. enable_uart0_pin_mux();
  110. regval = readl(&uart_base->uartsyscfg);
  111. regval |= UART_RESET;
  112. writel(regval, &uart_base->uartsyscfg);
  113. while ((readl(&uart_base->uartsyssts) &
  114. UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
  115. ;
  116. /* Disable smart idle */
  117. regval = readl(&uart_base->uartsyscfg);
  118. regval |= UART_SMART_IDLE_EN;
  119. writel(regval, &uart_base->uartsyscfg);
  120. gd = &gdata;
  121. preloader_console_init();
  122. /* Configure board pin mux */
  123. enable_board_pin_mux();
  124. config_ddr(303, K4B2G1646EBIH9_IOCTRL_VALUE, &ddr3_data,
  125. &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
  126. #endif
  127. }
  128. /*
  129. * Basic board specific setup. Pinmux has been handled already.
  130. */
  131. int board_init(void)
  132. {
  133. gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
  134. gpmc_init();
  135. return 0;
  136. }
  137. #if defined(CONFIG_DRIVER_TI_CPSW)
  138. static void cpsw_control(int enabled)
  139. {
  140. /* VTP can be added here */
  141. return;
  142. }
  143. static struct cpsw_slave_data cpsw_slaves[] = {
  144. {
  145. .slave_reg_ofs = 0x208,
  146. .sliver_reg_ofs = 0xd80,
  147. .phy_id = 0,
  148. .phy_if = PHY_INTERFACE_MODE_RMII,
  149. },
  150. };
  151. static struct cpsw_platform_data cpsw_data = {
  152. .mdio_base = CPSW_MDIO_BASE,
  153. .cpsw_base = CPSW_BASE,
  154. .mdio_div = 0xff,
  155. .channels = 8,
  156. .cpdma_reg_ofs = 0x800,
  157. .slaves = 1,
  158. .slave_data = cpsw_slaves,
  159. .ale_reg_ofs = 0xd00,
  160. .ale_entries = 1024,
  161. .host_port_reg_ofs = 0x108,
  162. .hw_stats_reg_ofs = 0x900,
  163. .mac_control = (1 << 5),
  164. .control = cpsw_control,
  165. .host_port_num = 0,
  166. .version = CPSW_CTRL_VERSION_2,
  167. };
  168. int board_eth_init(bd_t *bis)
  169. {
  170. int rv, ret = 0;
  171. uint8_t mac_addr[6];
  172. uint32_t mac_hi, mac_lo;
  173. if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
  174. /* try reading mac address from efuse */
  175. mac_lo = readl(&cdev->macid0l);
  176. mac_hi = readl(&cdev->macid0h);
  177. mac_addr[0] = mac_hi & 0xFF;
  178. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  179. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  180. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  181. mac_addr[4] = mac_lo & 0xFF;
  182. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  183. if (is_valid_ether_addr(mac_addr))
  184. eth_setenv_enetaddr("ethaddr", mac_addr);
  185. }
  186. writel(RMII_MODE_ENABLE, &cdev->miisel);
  187. rv = cpsw_register(&cpsw_data);
  188. if (rv < 0)
  189. printf("Error %d registering CPSW switch\n", rv);
  190. else
  191. ret += rv;
  192. return ret;
  193. }
  194. #endif