board.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * board.c
  4. *
  5. * Board functions for B&R BRPPT1
  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 <bootcount.h>
  13. #include <env.h>
  14. #include <errno.h>
  15. #include <init.h>
  16. #include <spl.h>
  17. #include <asm/arch/cpu.h>
  18. #include <asm/arch/hardware.h>
  19. #include <asm/arch/omap.h>
  20. #include <asm/arch/ddr_defs.h>
  21. #include <asm/arch/clock.h>
  22. #include <asm/arch/gpio.h>
  23. #include <asm/arch/sys_proto.h>
  24. #include <asm/arch/mem.h>
  25. #include <asm/io.h>
  26. #include <asm/emif.h>
  27. #include <asm/gpio.h>
  28. #include <i2c.h>
  29. #include <power/tps65217.h>
  30. #include "../common/bur_common.h"
  31. #include <watchdog.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. /* --------------------------------------------------------------------------*/
  34. /* -- defines for GPIO -- */
  35. #define REPSWITCH (0+20) /* GPIO0_20 */
  36. #if defined(CONFIG_SPL_BUILD)
  37. /* TODO: check ram-timing ! */
  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. static 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. struct cm_dpll *const cmdpll = (struct cm_dpll *)CM_DPLL;
  76. /*
  77. * in TRM they write a reset value of 1 (=CLK_M_OSC) for the
  78. * CLKSEL_TIMER6_CLK Register, in fact reset value is 0, so we need set
  79. * the source of timer6 clk to CLK_M_OSC
  80. */
  81. writel(0x01, &cmdpll->clktimer6clk);
  82. /* enable additional clocks of modules which are accessed later */
  83. u32 *const clk_domains[] = {
  84. &cmper->lcdcclkstctrl,
  85. 0
  86. };
  87. u32 *const clk_modules_tsspecific[] = {
  88. &cmper->lcdclkctrl,
  89. &cmper->timer5clkctrl,
  90. &cmper->timer6clkctrl,
  91. 0
  92. };
  93. do_enable_clocks(clk_domains, clk_modules_tsspecific, 1);
  94. /* setup I2C */
  95. enable_i2c_pin_mux();
  96. pmicsetup(0, 0);
  97. /* peripheral reset */
  98. rc = gpio_request(64 + 29, "GPMC_WAIT1");
  99. if (rc != 0)
  100. printf("cannot request GPMC_WAIT1 GPIO!\n");
  101. rc = gpio_direction_output(64 + 29, 1);
  102. if (rc != 0)
  103. printf("cannot set GPMC_WAIT1 GPIO!\n");
  104. rc = gpio_request(64 + 28, "GPMC_WAIT0");
  105. if (rc != 0)
  106. printf("cannot request GPMC_WAIT0 GPIO!\n");
  107. rc = gpio_direction_output(64 + 28, 1);
  108. if (rc != 0)
  109. printf("cannot set GPMC_WAIT0 GPIO!\n");
  110. }
  111. const struct dpll_params *get_dpll_ddr_params(void)
  112. {
  113. return &dpll_ddr3;
  114. }
  115. void sdram_init(void)
  116. {
  117. config_ddr(400, &ddr3_ioregs,
  118. &ddr3_data,
  119. &ddr3_cmd_ctrl_data,
  120. &ddr3_emif_reg_data, 0);
  121. }
  122. #endif /* CONFIG_SPL_BUILD */
  123. /* Basic board specific setup. Pinmux has been handled already. */
  124. int board_init(void)
  125. {
  126. #if defined(CONFIG_HW_WATCHDOG)
  127. hw_watchdog_init();
  128. #endif
  129. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  130. #ifdef CONFIG_NAND
  131. gpmc_init();
  132. #endif
  133. return 0;
  134. }
  135. #ifdef CONFIG_BOARD_LATE_INIT
  136. static char *bootmodeascii[16] = {
  137. "BOOT", "reserved", "reserved", "reserved",
  138. "RUN", "reserved", "reserved", "reserved",
  139. "reserved", "reserved", "reserved", "reserved",
  140. "PME", "reserved", "reserved", "DIAG",
  141. };
  142. int board_late_init(void)
  143. {
  144. unsigned char bmode = 0;
  145. ulong bootcount = 0;
  146. int rc;
  147. bootcount = bootcount_load() & 0xF;
  148. rc = gpio_request(REPSWITCH, "REPSWITCH");
  149. if (rc != 0 || gpio_get_value(REPSWITCH) == 0 || bootcount == 12)
  150. bmode = 12;
  151. else if (bootcount > 0)
  152. bmode = 0;
  153. else
  154. bmode = 4;
  155. printf("Mode: %s\n", bootmodeascii[bmode & 0x0F]);
  156. env_set_ulong("b_mode", bmode);
  157. /* get sure that bootcmd isn't affected by any bootcount value */
  158. env_set_ulong("bootlimit", 0);
  159. return 0;
  160. }
  161. #endif /* CONFIG_BOARD_LATE_INIT */