board.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 <errno.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/sys_proto.h>
  21. #include <asm/arch/mem.h>
  22. #include <asm/io.h>
  23. #include <asm/emif.h>
  24. #include <asm/gpio.h>
  25. #include <i2c.h>
  26. #include <power/tps65217.h>
  27. #include "../common/bur_common.h"
  28. #include <lcd.h>
  29. #include <watchdog.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /* --------------------------------------------------------------------------*/
  32. /* -- defines for GPIO -- */
  33. #define REPSWITCH (0+20) /* GPIO0_20 */
  34. #if defined(CONFIG_SPL_BUILD)
  35. /* TODO: check ram-timing ! */
  36. static const struct ddr_data ddr3_data = {
  37. .datardsratio0 = MT41K256M16HA125E_RD_DQS,
  38. .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
  39. .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
  40. .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
  41. };
  42. static const struct cmd_control ddr3_cmd_ctrl_data = {
  43. .cmd0csratio = MT41K256M16HA125E_RATIO,
  44. .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  45. .cmd1csratio = MT41K256M16HA125E_RATIO,
  46. .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  47. .cmd2csratio = MT41K256M16HA125E_RATIO,
  48. .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  49. };
  50. static struct emif_regs ddr3_emif_reg_data = {
  51. .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
  52. .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
  53. .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
  54. .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
  55. .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
  56. .zq_config = MT41K256M16HA125E_ZQ_CFG,
  57. .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
  58. };
  59. static const struct ctrl_ioregs ddr3_ioregs = {
  60. .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  61. .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  62. .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  63. .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  64. .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  65. };
  66. #ifdef CONFIG_SPL_OS_BOOT
  67. /*
  68. * called from spl_nand.c
  69. * return 0 for loading linux, return 1 for loading u-boot
  70. */
  71. int spl_start_uboot(void)
  72. {
  73. if (0 == gpio_get_value(REPSWITCH)) {
  74. mdelay(1000);
  75. printf("SPL: entering u-boot instead kernel image.\n");
  76. return 1;
  77. }
  78. return 0;
  79. }
  80. #endif /* CONFIG_SPL_OS_BOOT */
  81. #define OSC (V_OSCK/1000000)
  82. static const struct dpll_params dpll_ddr3 = { 400, OSC-1, 1, -1, -1, -1, -1};
  83. void am33xx_spl_board_init(void)
  84. {
  85. struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER;
  86. /*struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;*/
  87. struct cm_dpll *const cmdpll = (struct cm_dpll *)CM_DPLL;
  88. /*
  89. * in TRM they write a reset value of 1 (=CLK_M_OSC) for the
  90. * CLKSEL_TIMER6_CLK Register, in fact reset value is 0, so we need set
  91. * the source of timer6 clk to CLK_M_OSC
  92. */
  93. writel(0x01, &cmdpll->clktimer6clk);
  94. /* enable additional clocks of modules which are accessed later */
  95. u32 *const clk_domains[] = {
  96. &cmper->lcdcclkstctrl,
  97. 0
  98. };
  99. u32 *const clk_modules_tsspecific[] = {
  100. &cmper->lcdclkctrl,
  101. &cmper->timer5clkctrl,
  102. &cmper->timer6clkctrl,
  103. 0
  104. };
  105. do_enable_clocks(clk_domains, clk_modules_tsspecific, 1);
  106. /* setup I2C */
  107. enable_i2c_pin_mux();
  108. i2c_set_bus_num(0);
  109. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
  110. pmicsetup(0);
  111. gpio_direction_output(64+29, 1); /* switch NAND_RnB to GPMC_WAIT1 */
  112. gpio_direction_output(64+28, 1); /* switch MII2_CRS to GPMC_WAIT0 */
  113. }
  114. const struct dpll_params *get_dpll_ddr_params(void)
  115. {
  116. return &dpll_ddr3;
  117. }
  118. void sdram_init(void)
  119. {
  120. config_ddr(400, &ddr3_ioregs,
  121. &ddr3_data,
  122. &ddr3_cmd_ctrl_data,
  123. &ddr3_emif_reg_data, 0);
  124. }
  125. #endif /* CONFIG_SPL_BUILD */
  126. /* Basic board specific setup. Pinmux has been handled already. */
  127. int board_init(void)
  128. {
  129. #if defined(CONFIG_HW_WATCHDOG)
  130. hw_watchdog_init();
  131. #endif
  132. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  133. #ifdef CONFIG_NAND
  134. gpmc_init();
  135. #endif
  136. return 0;
  137. }
  138. #ifdef CONFIG_BOARD_LATE_INIT
  139. int board_late_init(void)
  140. {
  141. if (0 == gpio_get_value(REPSWITCH)) {
  142. lcd_position_cursor(1, 8);
  143. lcd_puts(
  144. "switching to network-console ... ");
  145. env_set("bootcmd", "run netconsole");
  146. }
  147. return 0;
  148. }
  149. #endif /* CONFIG_BOARD_LATE_INIT */