tpl.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2019 Rockchip Electronics Co., Ltd
  4. */
  5. #include <common.h>
  6. #include <debug_uart.h>
  7. #include <dm.h>
  8. #include <hang.h>
  9. #include <ram.h>
  10. #include <spl.h>
  11. #include <version.h>
  12. #include <asm/io.h>
  13. #include <asm/arch-rockchip/bootrom.h>
  14. #define TIMER_LOAD_COUNT_L 0x00
  15. #define TIMER_LOAD_COUNT_H 0x04
  16. #define TIMER_CONTROL_REG 0x10
  17. #define TIMER_EN 0x1
  18. #define TIMER_FMODE BIT(0)
  19. #define TIMER_RMODE BIT(1)
  20. __weak void rockchip_stimer_init(void)
  21. {
  22. /* If Timer already enabled, don't re-init it */
  23. u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
  24. if (reg & TIMER_EN)
  25. return;
  26. #ifndef CONFIG_ARM64
  27. asm volatile("mcr p15, 0, %0, c14, c0, 0"
  28. : : "r"(COUNTER_FREQUENCY));
  29. #endif
  30. writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
  31. writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
  32. writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
  33. writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
  34. TIMER_CONTROL_REG);
  35. }
  36. void board_init_f(ulong dummy)
  37. {
  38. struct udevice *dev;
  39. int ret;
  40. #if defined(CONFIG_DEBUG_UART) && defined(CONFIG_TPL_SERIAL_SUPPORT)
  41. /*
  42. * Debug UART can be used from here if required:
  43. *
  44. * debug_uart_init();
  45. * printch('a');
  46. * printhex8(0x1234);
  47. * printascii("string");
  48. */
  49. debug_uart_init();
  50. #ifdef CONFIG_TPL_BANNER_PRINT
  51. printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
  52. U_BOOT_TIME ")\n");
  53. #endif
  54. #endif
  55. ret = spl_early_init();
  56. if (ret) {
  57. debug("spl_early_init() failed: %d\n", ret);
  58. hang();
  59. }
  60. /* Init secure timer */
  61. rockchip_stimer_init();
  62. /* Init ARM arch timer in arch/arm/cpu/ */
  63. timer_init();
  64. ret = uclass_get_device(UCLASS_RAM, 0, &dev);
  65. if (ret) {
  66. printf("DRAM init failed: %d\n", ret);
  67. return;
  68. }
  69. }
  70. int board_return_to_bootrom(struct spl_image_info *spl_image,
  71. struct spl_boot_device *bootdev)
  72. {
  73. back_to_bootrom(BROM_BOOT_NEXTSTAGE);
  74. return 0;
  75. }
  76. u32 spl_boot_device(void)
  77. {
  78. return BOOT_DEVICE_BOOTROM;
  79. }