board.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * board.c
  4. *
  5. * Board functions for B&R BRXRE1 Board
  6. *
  7. * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at>
  8. * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
  9. *
  10. */
  11. #include <common.h>
  12. #include <env.h>
  13. #include <errno.h>
  14. #include <spl.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/hardware.h>
  17. #include <asm/arch/omap.h>
  18. #include <asm/arch/ddr_defs.h>
  19. #include <asm/arch/clock.h>
  20. #include <asm/arch/gpio.h>
  21. #include <asm/arch/sys_proto.h>
  22. #include <asm/arch/mem.h>
  23. #include <asm/io.h>
  24. #include <asm/emif.h>
  25. #include <asm/gpio.h>
  26. #include <dm.h>
  27. #include <power/tps65217.h>
  28. #include "../common/bur_common.h"
  29. #include "../common/br_resetc.h"
  30. /* -------------------------------------------------------------------------*/
  31. /* -- defines for used GPIO Hardware -- */
  32. #define ESC_KEY (0 + 19)
  33. #define LCD_PWR (0 + 5)
  34. #define RSTCTRL_FORCE_PWR_NEN 0x04
  35. #define RSTCTRL_CAN_STB 0x40
  36. DECLARE_GLOBAL_DATA_PTR;
  37. #if defined(CONFIG_SPL_BUILD)
  38. static const struct ddr_data ddr3_data = {
  39. .datardsratio0 = MT41K256M16HA125E_RD_DQS,
  40. .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
  41. .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
  42. .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
  43. };
  44. static const struct cmd_control ddr3_cmd_ctrl_data = {
  45. .cmd0csratio = MT41K256M16HA125E_RATIO,
  46. .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  47. .cmd1csratio = MT41K256M16HA125E_RATIO,
  48. .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  49. .cmd2csratio = MT41K256M16HA125E_RATIO,
  50. .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  51. };
  52. static struct emif_regs ddr3_emif_reg_data = {
  53. .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
  54. .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
  55. .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
  56. .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
  57. .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
  58. .zq_config = MT41K256M16HA125E_ZQ_CFG,
  59. .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
  60. };
  61. static const struct ctrl_ioregs ddr3_ioregs = {
  62. .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  63. .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  64. .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  65. .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  66. .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  67. };
  68. #define OSC (V_OSCK / 1000000)
  69. const struct dpll_params dpll_ddr3 = { 400, OSC - 1, 1, -1, -1, -1, -1};
  70. void am33xx_spl_board_init(void)
  71. {
  72. int rc;
  73. struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER;
  74. struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;
  75. /*
  76. * enable additional clocks of modules which are accessed later from
  77. * VxWorks OS
  78. */
  79. u32 *const clk_domains[] = { 0 };
  80. u32 *const clk_modules_xre1specific[] = {
  81. &cmwkup->wkup_adctscctrl,
  82. &cmper->spi1clkctrl,
  83. &cmper->dcan0clkctrl,
  84. &cmper->dcan1clkctrl,
  85. &cmper->epwmss0clkctrl,
  86. &cmper->epwmss1clkctrl,
  87. &cmper->epwmss2clkctrl,
  88. &cmper->lcdclkctrl,
  89. &cmper->lcdcclkstctrl,
  90. 0
  91. };
  92. do_enable_clocks(clk_domains, clk_modules_xre1specific, 1);
  93. /* power-OFF LCD-Display */
  94. if (gpio_request(LCD_PWR, "LCD_PWR") != 0)
  95. printf("cannot request gpio for LCD_PWR!\n");
  96. else if (gpio_direction_output(LCD_PWR, 0) != 0)
  97. printf("cannot set direction output on LCD_PWR!\n");
  98. /* setup I2C */
  99. enable_i2c_pin_mux();
  100. /* power-ON 3V3 via Resetcontroller */
  101. rc = br_resetc_regset(RSTCTRL_CTRLREG,
  102. RSTCTRL_FORCE_PWR_NEN | RSTCTRL_CAN_STB);
  103. if (rc != 0)
  104. printf("ERROR: cannot write to resetc (turn on PWR_nEN)!\n");
  105. pmicsetup(0, 0);
  106. }
  107. const struct dpll_params *get_dpll_ddr_params(void)
  108. {
  109. return &dpll_ddr3;
  110. }
  111. void sdram_init(void)
  112. {
  113. config_ddr(400, &ddr3_ioregs,
  114. &ddr3_data,
  115. &ddr3_cmd_ctrl_data,
  116. &ddr3_emif_reg_data, 0);
  117. }
  118. #endif /* CONFIG_SPL_BUILD */
  119. /*
  120. * Basic board specific setup. Pinmux has been handled already.
  121. */
  122. int board_init(void)
  123. {
  124. /* request common used gpios */
  125. gpio_request(ESC_KEY, "boot-key");
  126. if (power_tps65217_init(0))
  127. printf("WARN: cannot setup PMIC 0x24 @ bus #0, not found!.\n");
  128. return 0;
  129. }
  130. #ifdef CONFIG_BOARD_LATE_INIT
  131. int board_boot_key(void)
  132. {
  133. return gpio_get_value(ESC_KEY);
  134. }
  135. int board_late_init(void)
  136. {
  137. char othbootargs[128];
  138. br_resetc_bmode();
  139. /* setup othbootargs for bootvx-command (vxWorks bootline) */
  140. snprintf(othbootargs, sizeof(othbootargs),
  141. "u=vxWorksFTP pw=vxWorks o=0x%08x;0x%08x;0x%08x;0x%08x",
  142. (u32)gd->fb_base - 0x20,
  143. (u32)env_get_ulong("vx_memtop", 16, gd->fb_base - 0x20),
  144. (u32)env_get_ulong("vx_romfsbase", 16, 0),
  145. (u32)env_get_ulong("vx_romfssize", 16, 0));
  146. env_set("othbootargs", othbootargs);
  147. /*
  148. * reset VBAR registers to its reset location, VxWorks 6.9.3.2 does
  149. * expect that vectors are there, original u-boot moves them to _start
  150. */
  151. __asm__("ldr r0,=0x20000");
  152. __asm__("mcr p15, 0, r0, c12, c0, 0"); /* Set VBAR */
  153. return 0;
  154. }
  155. #endif /* CONFIG_BOARD_LATE_INIT */