board.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * board.c
  3. *
  4. * Copyright (C) 2013 Lothar Felten <lothar.felten@gmail.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/arch/cpu.h>
  10. #include <asm/arch/hardware.h>
  11. #include <asm/arch/ddr_defs.h>
  12. #include <asm/arch/clock.h>
  13. #include <asm/arch/sys_proto.h>
  14. #include <i2c.h>
  15. #include <phy.h>
  16. #include <cpsw.h>
  17. #include "board.h"
  18. DECLARE_GLOBAL_DATA_PTR;
  19. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  20. #if defined(CONFIG_SPL_BUILD)
  21. /* DDR3 RAM timings */
  22. static const struct ddr_data ddr3_data = {
  23. .datardsratio0 = MT41K128MJT187E_RD_DQS,
  24. .datawdsratio0 = MT41K128MJT187E_WR_DQS,
  25. .datafwsratio0 = MT41K128MJT187E_PHY_FIFO_WE,
  26. .datawrsratio0 = MT41K128MJT187E_PHY_WR_DATA,
  27. };
  28. static const struct cmd_control ddr3_cmd_ctrl_data = {
  29. .cmd0csratio = MT41K128MJT187E_RATIO,
  30. .cmd0iclkout = MT41K128MJT187E_INVERT_CLKOUT,
  31. .cmd1csratio = MT41K128MJT187E_RATIO,
  32. .cmd1iclkout = MT41K128MJT187E_INVERT_CLKOUT,
  33. .cmd2csratio = MT41K128MJT187E_RATIO,
  34. .cmd2iclkout = MT41K128MJT187E_INVERT_CLKOUT,
  35. };
  36. static struct emif_regs ddr3_emif_reg_data = {
  37. .sdram_config = MT41K128MJT187E_EMIF_SDCFG,
  38. .ref_ctrl = MT41K128MJT187E_EMIF_SDREF,
  39. .sdram_tim1 = MT41K128MJT187E_EMIF_TIM1,
  40. .sdram_tim2 = MT41K128MJT187E_EMIF_TIM2,
  41. .sdram_tim3 = MT41K128MJT187E_EMIF_TIM3,
  42. .zq_config = MT41K128MJT187E_ZQ_CFG,
  43. .emif_ddr_phy_ctlr_1 = MT41K128MJT187E_EMIF_READ_LATENCY |
  44. PHY_EN_DYN_PWRDN,
  45. };
  46. const struct ctrl_ioregs ddr3_ioregs = {
  47. .cm0ioctl = MT41K128MJT187E_IOCTRL_VALUE,
  48. .cm1ioctl = MT41K128MJT187E_IOCTRL_VALUE,
  49. .cm2ioctl = MT41K128MJT187E_IOCTRL_VALUE,
  50. .dt0ioctl = MT41K128MJT187E_IOCTRL_VALUE,
  51. .dt1ioctl = MT41K128MJT187E_IOCTRL_VALUE,
  52. };
  53. #ifdef CONFIG_SPL_OS_BOOT
  54. int spl_start_uboot(void)
  55. {
  56. /* break into full u-boot on 'c' */
  57. return serial_tstc() && serial_getc() == 'c';
  58. }
  59. #endif
  60. #define OSC (V_OSCK/1000000)
  61. const struct dpll_params dpll_ddr_266 = {
  62. 266, OSC-1, 1, -1, -1, -1, -1};
  63. const struct dpll_params dpll_ddr_303 = {
  64. 303, OSC-1, 1, -1, -1, -1, -1};
  65. const struct dpll_params dpll_ddr_400 = {
  66. 400, OSC-1, 1, -1, -1, -1, -1};
  67. void am33xx_spl_board_init(void)
  68. {
  69. /*
  70. * The pengwyn board uses the TPS650250 PMIC without I2C
  71. * interface and will output the following fixed voltages:
  72. * DCDC1=3V3 (IO) DCDC2=1V5 (DDR) DCDC3=1V26 (Vmpu)
  73. * VLDO1=1V8 (IO) VLDO2=1V8(IO)
  74. * Vcore=1V1 is fixed, generated by TPS62231
  75. */
  76. /* Get the frequency */
  77. dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
  78. /* Set CORE Frequencies to OPP100 */
  79. do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
  80. /* 720MHz cpu, this might change on newer board revisions */
  81. dpll_mpu_opp100.m = MPUPLL_M_720;
  82. do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
  83. }
  84. const struct dpll_params *get_dpll_ddr_params(void)
  85. {
  86. /* future configs can return other clock settings */
  87. return &dpll_ddr_303;
  88. }
  89. void set_uart_mux_conf(void)
  90. {
  91. enable_uart0_pin_mux();
  92. }
  93. void set_mux_conf_regs(void)
  94. {
  95. enable_board_pin_mux();
  96. }
  97. void sdram_init(void)
  98. {
  99. config_ddr(303, &ddr3_ioregs, &ddr3_data,
  100. &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
  101. }
  102. #endif /* if CONFIG_SPL_BUILD */
  103. /*
  104. * Basic board specific setup. Pinmux has been handled already.
  105. */
  106. int board_init(void)
  107. {
  108. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  109. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  110. gpmc_init();
  111. return 0;
  112. }
  113. #ifdef CONFIG_DRIVER_TI_CPSW
  114. static void cpsw_control(int enabled)
  115. {
  116. /* VTP can be added here */
  117. return;
  118. }
  119. static struct cpsw_slave_data cpsw_slaves[] = {
  120. {
  121. .slave_reg_ofs = 0x208,
  122. .sliver_reg_ofs = 0xd80,
  123. .phy_addr = 1,
  124. .phy_if = PHY_INTERFACE_MODE_MII,
  125. },
  126. };
  127. static struct cpsw_platform_data cpsw_data = {
  128. .mdio_base = CPSW_MDIO_BASE,
  129. .cpsw_base = CPSW_BASE,
  130. .mdio_div = 0xff,
  131. .channels = 8,
  132. .cpdma_reg_ofs = 0x800,
  133. .slaves = 1,
  134. .slave_data = cpsw_slaves,
  135. .ale_reg_ofs = 0xd00,
  136. .ale_entries = 1024,
  137. .host_port_reg_ofs = 0x108,
  138. .hw_stats_reg_ofs = 0x900,
  139. .bd_ram_ofs = 0x2000,
  140. .mac_control = (1 << 5),
  141. .control = cpsw_control,
  142. .host_port_num = 0,
  143. .version = CPSW_CTRL_VERSION_2,
  144. };
  145. int board_eth_init(bd_t *bis)
  146. {
  147. int rv, n = 0;
  148. uint8_t mac_addr[6];
  149. uint32_t mac_hi, mac_lo;
  150. if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
  151. printf("<ethaddr> not set. Reading from E-fuse\n");
  152. /* try reading mac address from efuse */
  153. mac_lo = readl(&cdev->macid0l);
  154. mac_hi = readl(&cdev->macid0h);
  155. mac_addr[0] = mac_hi & 0xFF;
  156. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  157. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  158. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  159. mac_addr[4] = mac_lo & 0xFF;
  160. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  161. if (is_valid_ethaddr(mac_addr))
  162. eth_setenv_enetaddr("ethaddr", mac_addr);
  163. else
  164. return n;
  165. }
  166. writel(MII_MODE_ENABLE, &cdev->miisel);
  167. rv = cpsw_register(&cpsw_data);
  168. if (rv < 0)
  169. printf("Error %d registering CPSW switch\n", rv);
  170. else
  171. n += rv;
  172. return n;
  173. }
  174. #endif /* if CONFIG_DRIVER_TI_CPSW */