starfive_visionfive2.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2022 StarFive Technology Co., Ltd.
  4. * Author: Yanhong Wang<yanhong.wang@starfivetech.com>
  5. */
  6. #include <common.h>
  7. #include <cpu_func.h>
  8. #include <dm.h>
  9. #include <fdt_support.h>
  10. #include <env.h>
  11. #include <asm/arch/eeprom.h>
  12. #include <asm/io.h>
  13. #include <asm/sections.h>
  14. #include <linux/bitops.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. #define JH7110_L2_PREFETCHER_BASE_ADDR 0x2030000
  17. #define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000
  18. #define FDTFILE_VISIONFIVE2_1_2A \
  19. "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb"
  20. #define FDTFILE_VISIONFIVE2_1_3B \
  21. "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb"
  22. /* enable U74-mc hart1~hart4 prefetcher */
  23. static void enable_prefetcher(void)
  24. {
  25. u8 hart;
  26. u32 *reg;
  27. /* JH7110 use U74MC CORE IP, it include five cores(one S7 and four U7),
  28. * but only U7 cores support prefetcher configuration
  29. */
  30. for (hart = 1; hart < 5; hart++) {
  31. reg = (void *)(u64)(JH7110_L2_PREFETCHER_BASE_ADDR
  32. + hart * JH7110_L2_PREFETCHER_HART_OFFSET);
  33. mb(); /* memory barrier */
  34. setbits_le32(reg, 0x1);
  35. mb(); /* memory barrier */
  36. }
  37. }
  38. /**
  39. * set_fdtfile() - set the $fdtfile variable based on the board revision
  40. */
  41. static void set_fdtfile(void)
  42. {
  43. u8 version;
  44. const char *fdtfile;
  45. version = get_pcb_revision_from_eeprom();
  46. switch (version) {
  47. case 'a':
  48. case 'A':
  49. fdtfile = FDTFILE_VISIONFIVE2_1_2A;
  50. break;
  51. case 'b':
  52. case 'B':
  53. default:
  54. fdtfile = FDTFILE_VISIONFIVE2_1_3B;
  55. break;
  56. };
  57. env_set("fdtfile", fdtfile);
  58. }
  59. int board_init(void)
  60. {
  61. enable_caches();
  62. enable_prefetcher();
  63. return 0;
  64. }
  65. int board_late_init(void)
  66. {
  67. if (CONFIG_IS_ENABLED(ID_EEPROM))
  68. set_fdtfile();
  69. return 0;
  70. }
  71. void *board_fdt_blob_setup(int *err)
  72. {
  73. *err = 0;
  74. if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
  75. if (gd->arch.firmware_fdt_addr)
  76. return (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr;
  77. }
  78. return (ulong *)&_end;
  79. }
  80. int ft_board_setup(void *blob, struct bd_info *bd)
  81. {
  82. return fdt_fixup_memory(blob, 0x40000000, gd->ram_size);
  83. }