board.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*
  2. * board.c
  3. *
  4. * Board functions for TI AM335X based boards
  5. *
  6. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <errno.h>
  12. #include <libfdt.h>
  13. #include <spl.h>
  14. #include <asm/arch/cpu.h>
  15. #include <asm/arch/hardware.h>
  16. #include <asm/arch/omap.h>
  17. #include <asm/arch/ddr_defs.h>
  18. #include <asm/arch/clock.h>
  19. #include <asm/arch/gpio.h>
  20. #include <asm/arch/mmc_host_def.h>
  21. #include <asm/arch/sys_proto.h>
  22. #include <asm/arch/mem.h>
  23. #include <asm/arch/mux.h>
  24. #include <asm/io.h>
  25. #include <asm/emif.h>
  26. #include <asm/gpio.h>
  27. #include <i2c.h>
  28. #include <miiphy.h>
  29. #include <cpsw.h>
  30. #include <power/tps65217.h>
  31. #include <power/tps65910.h>
  32. #include <environment.h>
  33. #include <watchdog.h>
  34. #include "board.h"
  35. DECLARE_GLOBAL_DATA_PTR;
  36. /* GPIO that controls power to DDR on EVM-SK */
  37. #define GPIO_DDR_VTT_EN 7
  38. #define DIP_S1 44
  39. #define MPCIE_SW 100
  40. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  41. static int baltos_set_console(void)
  42. {
  43. int val, i, dips = 0;
  44. char buf[7];
  45. for (i = 0; i < 4; i++) {
  46. sprintf(buf, "dip_s%d", i + 1);
  47. if (gpio_request(DIP_S1 + i, buf)) {
  48. printf("failed to export GPIO %d\n", DIP_S1 + i);
  49. return 0;
  50. }
  51. if (gpio_direction_input(DIP_S1 + i)) {
  52. printf("failed to set GPIO %d direction\n", DIP_S1 + i);
  53. return 0;
  54. }
  55. val = gpio_get_value(DIP_S1 + i);
  56. dips |= val << i;
  57. }
  58. printf("DIPs: 0x%1x\n", (~dips) & 0xf);
  59. if ((dips & 0xf) == 0xe)
  60. setenv("console", "ttyUSB0,115200n8");
  61. return 0;
  62. }
  63. static int read_eeprom(BSP_VS_HWPARAM *header)
  64. {
  65. i2c_set_bus_num(1);
  66. /* Check if baseboard eeprom is available */
  67. if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
  68. puts("Could not probe the EEPROM; something fundamentally "
  69. "wrong on the I2C bus.\n");
  70. return -ENODEV;
  71. }
  72. /* read the eeprom using i2c */
  73. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
  74. sizeof(BSP_VS_HWPARAM))) {
  75. puts("Could not read the EEPROM; something fundamentally"
  76. " wrong on the I2C bus.\n");
  77. return -EIO;
  78. }
  79. if (header->Magic != 0xDEADBEEF) {
  80. printf("Incorrect magic number (0x%x) in EEPROM\n",
  81. header->Magic);
  82. /* fill default values */
  83. header->SystemId = 211;
  84. header->MAC1[0] = 0x00;
  85. header->MAC1[1] = 0x00;
  86. header->MAC1[2] = 0x00;
  87. header->MAC1[3] = 0x00;
  88. header->MAC1[4] = 0x00;
  89. header->MAC1[5] = 0x01;
  90. header->MAC2[0] = 0x00;
  91. header->MAC2[1] = 0x00;
  92. header->MAC2[2] = 0x00;
  93. header->MAC2[3] = 0x00;
  94. header->MAC2[4] = 0x00;
  95. header->MAC2[5] = 0x02;
  96. header->MAC3[0] = 0x00;
  97. header->MAC3[1] = 0x00;
  98. header->MAC3[2] = 0x00;
  99. header->MAC3[3] = 0x00;
  100. header->MAC3[4] = 0x00;
  101. header->MAC3[5] = 0x03;
  102. }
  103. return 0;
  104. }
  105. #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
  106. static const struct ddr_data ddr3_baltos_data = {
  107. .datardsratio0 = MT41K256M16HA125E_RD_DQS,
  108. .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
  109. .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
  110. .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
  111. };
  112. static const struct cmd_control ddr3_baltos_cmd_ctrl_data = {
  113. .cmd0csratio = MT41K256M16HA125E_RATIO,
  114. .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  115. .cmd1csratio = MT41K256M16HA125E_RATIO,
  116. .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  117. .cmd2csratio = MT41K256M16HA125E_RATIO,
  118. .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  119. };
  120. static struct emif_regs ddr3_baltos_emif_reg_data = {
  121. .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
  122. .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
  123. .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
  124. .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
  125. .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
  126. .zq_config = MT41K256M16HA125E_ZQ_CFG,
  127. .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
  128. };
  129. #ifdef CONFIG_SPL_OS_BOOT
  130. int spl_start_uboot(void)
  131. {
  132. /* break into full u-boot on 'c' */
  133. return (serial_tstc() && serial_getc() == 'c');
  134. }
  135. #endif
  136. #define OSC (V_OSCK/1000000)
  137. const struct dpll_params dpll_ddr = {
  138. 266, OSC-1, 1, -1, -1, -1, -1};
  139. const struct dpll_params dpll_ddr_evm_sk = {
  140. 303, OSC-1, 1, -1, -1, -1, -1};
  141. const struct dpll_params dpll_ddr_baltos = {
  142. 400, OSC-1, 1, -1, -1, -1, -1};
  143. void am33xx_spl_board_init(void)
  144. {
  145. int mpu_vdd;
  146. int sil_rev;
  147. /* Get the frequency */
  148. dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
  149. /*
  150. * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
  151. * MPU frequencies we support we use a CORE voltage of
  152. * 1.1375V. For MPU voltage we need to switch based on
  153. * the frequency we are running at.
  154. */
  155. i2c_set_bus_num(1);
  156. printf("I2C speed: %d Hz\n", CONFIG_SYS_OMAP24_I2C_SPEED);
  157. if (i2c_probe(TPS65910_CTRL_I2C_ADDR)) {
  158. puts("i2c: cannot access TPS65910\n");
  159. return;
  160. }
  161. /*
  162. * Depending on MPU clock and PG we will need a different
  163. * VDD to drive at that speed.
  164. */
  165. sil_rev = readl(&cdev->deviceid) >> 28;
  166. mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev,
  167. dpll_mpu_opp100.m);
  168. /* Tell the TPS65910 to use i2c */
  169. tps65910_set_i2c_control();
  170. /* First update MPU voltage. */
  171. if (tps65910_voltage_update(MPU, mpu_vdd))
  172. return;
  173. /* Second, update the CORE voltage. */
  174. if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3))
  175. return;
  176. /* Set CORE Frequencies to OPP100 */
  177. do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
  178. /* Set MPU Frequency to what we detected now that voltages are set */
  179. do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
  180. writel(0x000010ff, PRM_DEVICE_INST + 4);
  181. }
  182. const struct dpll_params *get_dpll_ddr_params(void)
  183. {
  184. enable_i2c1_pin_mux();
  185. i2c_set_bus_num(1);
  186. return &dpll_ddr_baltos;
  187. }
  188. void set_uart_mux_conf(void)
  189. {
  190. enable_uart0_pin_mux();
  191. }
  192. void set_mux_conf_regs(void)
  193. {
  194. enable_board_pin_mux();
  195. }
  196. const struct ctrl_ioregs ioregs_baltos = {
  197. .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  198. .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  199. .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  200. .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  201. .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  202. };
  203. void sdram_init(void)
  204. {
  205. gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
  206. gpio_direction_output(GPIO_DDR_VTT_EN, 1);
  207. config_ddr(400, &ioregs_baltos,
  208. &ddr3_baltos_data,
  209. &ddr3_baltos_cmd_ctrl_data,
  210. &ddr3_baltos_emif_reg_data, 0);
  211. }
  212. #endif
  213. /*
  214. * Basic board specific setup. Pinmux has been handled already.
  215. */
  216. int board_init(void)
  217. {
  218. #if defined(CONFIG_HW_WATCHDOG)
  219. hw_watchdog_init();
  220. #endif
  221. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  222. #if defined(CONFIG_NOR) || defined(CONFIG_NAND)
  223. gpmc_init();
  224. #endif
  225. return 0;
  226. }
  227. int ft_board_setup(void *blob, bd_t *bd)
  228. {
  229. int node, ret;
  230. unsigned char mac_addr[6];
  231. BSP_VS_HWPARAM header;
  232. /* get production data */
  233. if (read_eeprom(&header))
  234. return 0;
  235. /* setup MAC1 */
  236. mac_addr[0] = header.MAC1[0];
  237. mac_addr[1] = header.MAC1[1];
  238. mac_addr[2] = header.MAC1[2];
  239. mac_addr[3] = header.MAC1[3];
  240. mac_addr[4] = header.MAC1[4];
  241. mac_addr[5] = header.MAC1[5];
  242. node = fdt_path_offset(blob, "/ocp/ethernet/slave@4a100200");
  243. if (node < 0) {
  244. printf("no /soc/fman/ethernet path offset\n");
  245. return -ENODEV;
  246. }
  247. ret = fdt_setprop(blob, node, "mac-address", &mac_addr, 6);
  248. if (ret) {
  249. printf("error setting local-mac-address property\n");
  250. return -ENODEV;
  251. }
  252. /* setup MAC2 */
  253. mac_addr[0] = header.MAC2[0];
  254. mac_addr[1] = header.MAC2[1];
  255. mac_addr[2] = header.MAC2[2];
  256. mac_addr[3] = header.MAC2[3];
  257. mac_addr[4] = header.MAC2[4];
  258. mac_addr[5] = header.MAC2[5];
  259. node = fdt_path_offset(blob, "/ocp/ethernet/slave@4a100300");
  260. if (node < 0) {
  261. printf("no /soc/fman/ethernet path offset\n");
  262. return -ENODEV;
  263. }
  264. ret = fdt_setprop(blob, node, "mac-address", &mac_addr, 6);
  265. if (ret) {
  266. printf("error setting local-mac-address property\n");
  267. return -ENODEV;
  268. }
  269. printf("\nFDT was successfully setup\n");
  270. return 0;
  271. }
  272. static struct module_pin_mux pcie_sw_pin_mux[] = {
  273. {OFFSET(mii1_rxdv), (MODE(7) | PULLUDEN )}, /* GPIO3_4 */
  274. {-1},
  275. };
  276. static struct module_pin_mux dip_pin_mux[] = {
  277. {OFFSET(gpmc_ad12), (MODE(7) | RXACTIVE )}, /* GPIO1_12 */
  278. {OFFSET(gpmc_ad13), (MODE(7) | RXACTIVE )}, /* GPIO1_13 */
  279. {OFFSET(gpmc_ad14), (MODE(7) | RXACTIVE )}, /* GPIO1_14 */
  280. {OFFSET(gpmc_ad15), (MODE(7) | RXACTIVE )}, /* GPIO1_15 */
  281. {-1},
  282. };
  283. #ifdef CONFIG_BOARD_LATE_INIT
  284. int board_late_init(void)
  285. {
  286. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  287. BSP_VS_HWPARAM header;
  288. char model[4];
  289. /* get production data */
  290. if (read_eeprom(&header)) {
  291. strcpy(model, "211");
  292. } else {
  293. sprintf(model, "%d", header.SystemId);
  294. if (header.SystemId == 215) {
  295. configure_module_pin_mux(dip_pin_mux);
  296. baltos_set_console();
  297. }
  298. }
  299. /* turn power for the mPCIe slot */
  300. configure_module_pin_mux(pcie_sw_pin_mux);
  301. if (gpio_request(MPCIE_SW, "mpcie_sw")) {
  302. printf("failed to export GPIO %d\n", MPCIE_SW);
  303. return -ENODEV;
  304. }
  305. if (gpio_direction_output(MPCIE_SW, 1)) {
  306. printf("failed to set GPIO %d direction\n", MPCIE_SW);
  307. return -ENODEV;
  308. }
  309. setenv("board_name", model);
  310. #endif
  311. return 0;
  312. }
  313. #endif
  314. #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
  315. (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
  316. static void cpsw_control(int enabled)
  317. {
  318. /* VTP can be added here */
  319. return;
  320. }
  321. static struct cpsw_slave_data cpsw_slaves[] = {
  322. {
  323. .slave_reg_ofs = 0x208,
  324. .sliver_reg_ofs = 0xd80,
  325. .phy_addr = 0,
  326. },
  327. {
  328. .slave_reg_ofs = 0x308,
  329. .sliver_reg_ofs = 0xdc0,
  330. .phy_addr = 7,
  331. },
  332. };
  333. static struct cpsw_platform_data cpsw_data = {
  334. .mdio_base = CPSW_MDIO_BASE,
  335. .cpsw_base = CPSW_BASE,
  336. .mdio_div = 0xff,
  337. .channels = 8,
  338. .cpdma_reg_ofs = 0x800,
  339. .slaves = 2,
  340. .slave_data = cpsw_slaves,
  341. .active_slave = 1,
  342. .ale_reg_ofs = 0xd00,
  343. .ale_entries = 1024,
  344. .host_port_reg_ofs = 0x108,
  345. .hw_stats_reg_ofs = 0x900,
  346. .bd_ram_ofs = 0x2000,
  347. .mac_control = (1 << 5),
  348. .control = cpsw_control,
  349. .host_port_num = 0,
  350. .version = CPSW_CTRL_VERSION_2,
  351. };
  352. #endif
  353. #if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)) \
  354. && defined(CONFIG_SPL_BUILD)) || \
  355. ((defined(CONFIG_DRIVER_TI_CPSW) || \
  356. defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) && \
  357. !defined(CONFIG_SPL_BUILD))
  358. int board_eth_init(bd_t *bis)
  359. {
  360. int rv, n = 0;
  361. uint8_t mac_addr[6];
  362. uint32_t mac_hi, mac_lo;
  363. /*
  364. * Note here that we're using CPSW1 since that has a 1Gbit PHY while
  365. * CSPW0 has a 100Mbit PHY.
  366. *
  367. * On product, CPSW1 maps to port labeled WAN.
  368. */
  369. /* try reading mac address from efuse */
  370. mac_lo = readl(&cdev->macid1l);
  371. mac_hi = readl(&cdev->macid1h);
  372. mac_addr[0] = mac_hi & 0xFF;
  373. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  374. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  375. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  376. mac_addr[4] = mac_lo & 0xFF;
  377. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  378. #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
  379. (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
  380. if (!getenv("ethaddr")) {
  381. printf("<ethaddr> not set. Validating first E-fuse MAC\n");
  382. if (is_valid_ethaddr(mac_addr))
  383. eth_setenv_enetaddr("ethaddr", mac_addr);
  384. }
  385. #ifdef CONFIG_DRIVER_TI_CPSW
  386. writel((GMII1_SEL_RMII | GMII2_SEL_RGMII | RGMII2_IDMODE), &cdev->miisel);
  387. cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RGMII;
  388. rv = cpsw_register(&cpsw_data);
  389. if (rv < 0)
  390. printf("Error %d registering CPSW switch\n", rv);
  391. else
  392. n += rv;
  393. #endif
  394. /*
  395. *
  396. * CPSW RGMII Internal Delay Mode is not supported in all PVT
  397. * operating points. So we must set the TX clock delay feature
  398. * in the AR8051 PHY. Since we only support a single ethernet
  399. * device in U-Boot, we only do this for the first instance.
  400. */
  401. #define AR8051_PHY_DEBUG_ADDR_REG 0x1d
  402. #define AR8051_PHY_DEBUG_DATA_REG 0x1e
  403. #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
  404. #define AR8051_RGMII_TX_CLK_DLY 0x100
  405. const char *devname;
  406. devname = miiphy_get_current_dev();
  407. miiphy_write(devname, 0x7, AR8051_PHY_DEBUG_ADDR_REG,
  408. AR8051_DEBUG_RGMII_CLK_DLY_REG);
  409. miiphy_write(devname, 0x7, AR8051_PHY_DEBUG_DATA_REG,
  410. AR8051_RGMII_TX_CLK_DLY);
  411. #endif
  412. return n;
  413. }
  414. #endif