board.c 4.4 KB

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