rk322x-board-spl.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2017 Rockchip Electronics Co., Ltd
  4. */
  5. #include <common.h>
  6. #include <debug_uart.h>
  7. #include <dm.h>
  8. #include <ram.h>
  9. #include <spl.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/bootrom.h>
  12. #include <asm/arch/cru_rk322x.h>
  13. #include <asm/arch/grf_rk322x.h>
  14. #include <asm/arch/hardware.h>
  15. #include <asm/arch/timer.h>
  16. #include <asm/arch/uart.h>
  17. u32 spl_boot_device(void)
  18. {
  19. return BOOT_DEVICE_MMC1;
  20. }
  21. #define GRF_BASE 0x11000000
  22. #define SGRF_BASE 0x10140000
  23. #define DEBUG_UART_BASE 0x11030000
  24. void board_debug_uart_init(void)
  25. {
  26. static struct rk322x_grf * const grf = (void *)GRF_BASE;
  27. enum {
  28. GPIO1B2_SHIFT = 4,
  29. GPIO1B2_MASK = 3 << GPIO1B2_SHIFT,
  30. GPIO1B2_GPIO = 0,
  31. GPIO1B2_UART1_SIN,
  32. GPIO1B2_UART21_SIN,
  33. GPIO1B1_SHIFT = 2,
  34. GPIO1B1_MASK = 3 << GPIO1B1_SHIFT,
  35. GPIO1B1_GPIO = 0,
  36. GPIO1B1_UART1_SOUT,
  37. GPIO1B1_UART21_SOUT,
  38. };
  39. enum {
  40. CON_IOMUX_UART2SEL_SHIFT= 8,
  41. CON_IOMUX_UART2SEL_MASK = 1 << CON_IOMUX_UART2SEL_SHIFT,
  42. CON_IOMUX_UART2SEL_2 = 0,
  43. CON_IOMUX_UART2SEL_21,
  44. };
  45. /* Enable early UART2 channel 1 on the RK322x */
  46. rk_clrsetreg(&grf->gpio1b_iomux,
  47. GPIO1B1_MASK | GPIO1B2_MASK,
  48. GPIO1B2_UART21_SIN << GPIO1B2_SHIFT |
  49. GPIO1B1_UART21_SOUT << GPIO1B1_SHIFT);
  50. /* Set channel C as UART2 input */
  51. rk_clrsetreg(&grf->con_iomux,
  52. CON_IOMUX_UART2SEL_MASK,
  53. CON_IOMUX_UART2SEL_21 << CON_IOMUX_UART2SEL_SHIFT);
  54. }
  55. #define SGRF_DDR_CON0 0x10150000
  56. void board_init_f(ulong dummy)
  57. {
  58. struct udevice *dev;
  59. int ret;
  60. /*
  61. * Debug UART can be used from here if required:
  62. *
  63. * debug_uart_init();
  64. * printch('a');
  65. * printhex8(0x1234);
  66. * printascii("string");
  67. */
  68. debug_uart_init();
  69. printascii("SPL Init");
  70. ret = spl_early_init();
  71. if (ret) {
  72. debug("spl_early_init() failed: %d\n", ret);
  73. hang();
  74. }
  75. rockchip_timer_init();
  76. printf("timer init done\n");
  77. ret = uclass_get_device(UCLASS_RAM, 0, &dev);
  78. if (ret) {
  79. printf("DRAM init failed: %d\n", ret);
  80. return;
  81. }
  82. /* Disable the ddr secure region setting to make it non-secure */
  83. rk_clrreg(SGRF_DDR_CON0, 0x4000);
  84. #if defined(CONFIG_SPL_ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
  85. back_to_bootrom(BROM_BOOT_NEXTSTAGE);
  86. #endif
  87. }