board.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * board.c
  3. *
  4. * Board functions for Phytec phyCORE-AM335x (pcm051) based boards
  5. *
  6. * Copyright (C) 2013 Lemonage Software GmbH
  7. * Author Lars Poeschel <poeschel@lemonage.de>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <common.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 <i2c.h>
  34. #include <miiphy.h>
  35. #include <cpsw.h>
  36. #include "board.h"
  37. DECLARE_GLOBAL_DATA_PTR;
  38. static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
  39. #ifdef CONFIG_SPL_BUILD
  40. static struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
  41. #endif
  42. /* MII mode defines */
  43. #define MII_MODE_ENABLE 0x0
  44. #define RGMII_MODE_ENABLE 0xA
  45. #define RMII_RGMII2_MODE_ENABLE 0x49
  46. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  47. /* UART defines */
  48. #ifdef CONFIG_SPL_BUILD
  49. #define UART_RESET (0x1 << 1)
  50. #define UART_CLK_RUNNING_MASK 0x1
  51. #define UART_SMART_IDLE_EN (0x1 << 0x3)
  52. /* DDR RAM defines */
  53. #define DDR_CLK_MHZ 303 /* DDR_DPLL_MULT value */
  54. static void rtc32k_enable(void)
  55. {
  56. struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
  57. /*
  58. * Unlock the RTC's registers. For more details please see the
  59. * RTC_SS section of the TRM. In order to unlock we need to
  60. * write these specific values (keys) in this order.
  61. */
  62. writel(0x83e70b13, &rtc->kick0r);
  63. writel(0x95a4f1e0, &rtc->kick1r);
  64. /* Enable the RTC 32K OSC by setting bits 3 and 6. */
  65. writel((1 << 3) | (1 << 6), &rtc->osc);
  66. }
  67. static const struct ddr_data ddr3_data = {
  68. .datardsratio0 = MT41J256M8HX15E_RD_DQS,
  69. .datawdsratio0 = MT41J256M8HX15E_WR_DQS,
  70. .datafwsratio0 = MT41J256M8HX15E_PHY_FIFO_WE,
  71. .datawrsratio0 = MT41J256M8HX15E_PHY_WR_DATA,
  72. .datadldiff0 = PHY_DLL_LOCK_DIFF,
  73. };
  74. static const struct cmd_control ddr3_cmd_ctrl_data = {
  75. .cmd0csratio = MT41J256M8HX15E_RATIO,
  76. .cmd0dldiff = MT41J256M8HX15E_DLL_LOCK_DIFF,
  77. .cmd0iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
  78. .cmd1csratio = MT41J256M8HX15E_RATIO,
  79. .cmd1dldiff = MT41J256M8HX15E_DLL_LOCK_DIFF,
  80. .cmd1iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
  81. .cmd2csratio = MT41J256M8HX15E_RATIO,
  82. .cmd2dldiff = MT41J256M8HX15E_DLL_LOCK_DIFF,
  83. .cmd2iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
  84. };
  85. static struct emif_regs ddr3_emif_reg_data = {
  86. .sdram_config = MT41J256M8HX15E_EMIF_SDCFG,
  87. .ref_ctrl = MT41J256M8HX15E_EMIF_SDREF,
  88. .sdram_tim1 = MT41J256M8HX15E_EMIF_TIM1,
  89. .sdram_tim2 = MT41J256M8HX15E_EMIF_TIM2,
  90. .sdram_tim3 = MT41J256M8HX15E_EMIF_TIM3,
  91. .zq_config = MT41J256M8HX15E_ZQ_CFG,
  92. .emif_ddr_phy_ctlr_1 = MT41J256M8HX15E_EMIF_READ_LATENCY,
  93. };
  94. #endif
  95. /*
  96. * early system init of muxing and clocks.
  97. */
  98. void s_init(void)
  99. {
  100. /*
  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) & UART_CLK_RUNNING_MASK)
  122. != 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. /* Initalize the board header */
  131. enable_i2c0_pin_mux();
  132. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  133. enable_board_pin_mux();
  134. config_ddr(DDR_CLK_MHZ, MT41J256M8HX15E_IOCTRL_VALUE, &ddr3_data,
  135. &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
  136. #endif
  137. }
  138. /*
  139. * Basic board specific setup. Pinmux has been handled already.
  140. */
  141. int board_init(void)
  142. {
  143. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  144. gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
  145. return 0;
  146. }
  147. #ifdef CONFIG_DRIVER_TI_CPSW
  148. static void cpsw_control(int enabled)
  149. {
  150. /* VTP can be added here */
  151. return;
  152. }
  153. static struct cpsw_slave_data cpsw_slaves[] = {
  154. {
  155. .slave_reg_ofs = 0x208,
  156. .sliver_reg_ofs = 0xd80,
  157. .phy_id = 0,
  158. .phy_if = PHY_INTERFACE_MODE_RGMII,
  159. },
  160. {
  161. .slave_reg_ofs = 0x308,
  162. .sliver_reg_ofs = 0xdc0,
  163. .phy_id = 1,
  164. .phy_if = PHY_INTERFACE_MODE_RGMII,
  165. },
  166. };
  167. static struct cpsw_platform_data cpsw_data = {
  168. .mdio_base = CPSW_MDIO_BASE,
  169. .cpsw_base = CPSW_BASE,
  170. .mdio_div = 0xff,
  171. .channels = 8,
  172. .cpdma_reg_ofs = 0x800,
  173. .slaves = 1,
  174. .slave_data = cpsw_slaves,
  175. .ale_reg_ofs = 0xd00,
  176. .ale_entries = 1024,
  177. .host_port_reg_ofs = 0x108,
  178. .hw_stats_reg_ofs = 0x900,
  179. .mac_control = (1 << 5),
  180. .control = cpsw_control,
  181. .host_port_num = 0,
  182. .version = CPSW_CTRL_VERSION_2,
  183. };
  184. #endif
  185. #if defined(CONFIG_DRIVER_TI_CPSW) || \
  186. (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
  187. int board_eth_init(bd_t *bis)
  188. {
  189. int rv, n = 0;
  190. #ifdef CONFIG_DRIVER_TI_CPSW
  191. uint8_t mac_addr[6];
  192. uint32_t mac_hi, mac_lo;
  193. if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
  194. printf("<ethaddr> not set. Reading from E-fuse\n");
  195. /* try reading mac address from efuse */
  196. mac_lo = readl(&cdev->macid0l);
  197. mac_hi = readl(&cdev->macid0h);
  198. mac_addr[0] = mac_hi & 0xFF;
  199. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  200. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  201. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  202. mac_addr[4] = mac_lo & 0xFF;
  203. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  204. if (is_valid_ether_addr(mac_addr))
  205. eth_setenv_enetaddr("ethaddr", mac_addr);
  206. else
  207. goto try_usbether;
  208. }
  209. writel(RMII_RGMII2_MODE_ENABLE, &cdev->miisel);
  210. rv = cpsw_register(&cpsw_data);
  211. if (rv < 0)
  212. printf("Error %d registering CPSW switch\n", rv);
  213. else
  214. n += rv;
  215. try_usbether:
  216. #endif
  217. #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_SPL_BUILD)
  218. rv = usb_eth_initialize(bis);
  219. if (rv < 0)
  220. printf("Error %d registering USB_ETHER\n", rv);
  221. else
  222. n += rv;
  223. #endif
  224. return n;
  225. }
  226. #endif