cpu.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012 Michal Simek <monstr@monstr.eu>
  4. * Copyright (C) 2012 Xilinx, Inc. All rights reserved.
  5. */
  6. #include <common.h>
  7. #include <cpu_func.h>
  8. #include <init.h>
  9. #include <zynqpl.h>
  10. #include <asm/cache.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/clk.h>
  13. #include <asm/arch/hardware.h>
  14. #include <asm/arch/ps7_init_gpl.h>
  15. #include <asm/arch/sys_proto.h>
  16. #define ZYNQ_SILICON_VER_MASK 0xF0000000
  17. #define ZYNQ_SILICON_VER_SHIFT 28
  18. #if CONFIG_IS_ENABLED(FPGA)
  19. xilinx_desc fpga = {
  20. .family = xilinx_zynq,
  21. .iface = devcfg,
  22. .operations = &zynq_op,
  23. };
  24. #endif
  25. static const struct {
  26. u8 idcode;
  27. #if defined(CONFIG_FPGA)
  28. u32 fpga_size;
  29. #endif
  30. char *devicename;
  31. } zynq_fpga_descs[] = {
  32. ZYNQ_DESC(7Z007S),
  33. ZYNQ_DESC(7Z010),
  34. ZYNQ_DESC(7Z012S),
  35. ZYNQ_DESC(7Z014S),
  36. ZYNQ_DESC(7Z015),
  37. ZYNQ_DESC(7Z020),
  38. ZYNQ_DESC(7Z030),
  39. ZYNQ_DESC(7Z035),
  40. ZYNQ_DESC(7Z045),
  41. ZYNQ_DESC(7Z100),
  42. { /* Sentinel */ },
  43. };
  44. int arch_cpu_init(void)
  45. {
  46. zynq_slcr_unlock();
  47. #ifndef CONFIG_SPL_BUILD
  48. /* Device config APB, unlock the PCAP */
  49. writel(0x757BDF0D, &devcfg_base->unlock);
  50. writel(0xFFFFFFFF, &devcfg_base->rom_shadow);
  51. #if (CONFIG_SYS_SDRAM_BASE == 0)
  52. /* remap DDR to zero, FILTERSTART */
  53. writel(0, &scu_base->filter_start);
  54. /* OCM_CFG, Mask out the ROM, map ram into upper addresses */
  55. writel(0x1F, &slcr_base->ocm_cfg);
  56. /* FPGA_RST_CTRL, clear resets on AXI fabric ports */
  57. writel(0x0, &slcr_base->fpga_rst_ctrl);
  58. /* Set urgent bits with register */
  59. writel(0x0, &slcr_base->ddr_urgent_sel);
  60. /* Urgent write, ports S2/S3 */
  61. writel(0xC, &slcr_base->ddr_urgent);
  62. #endif
  63. #endif
  64. zynq_slcr_lock();
  65. return 0;
  66. }
  67. unsigned int zynq_get_silicon_version(void)
  68. {
  69. return (readl(&devcfg_base->mctrl) & ZYNQ_SILICON_VER_MASK)
  70. >> ZYNQ_SILICON_VER_SHIFT;
  71. }
  72. void reset_cpu(ulong addr)
  73. {
  74. zynq_slcr_cpu_reset();
  75. while (1)
  76. ;
  77. }
  78. #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  79. void enable_caches(void)
  80. {
  81. /* Enable D-cache. I-cache is already enabled in start.S */
  82. dcache_enable();
  83. }
  84. #endif
  85. static int __maybe_unused cpu_desc_id(void)
  86. {
  87. u32 idcode;
  88. u8 i;
  89. idcode = zynq_slcr_get_idcode();
  90. for (i = 0; zynq_fpga_descs[i].idcode; i++) {
  91. if (zynq_fpga_descs[i].idcode == idcode)
  92. return i;
  93. }
  94. return -ENODEV;
  95. }
  96. #if defined(CONFIG_ARCH_EARLY_INIT_R)
  97. int arch_early_init_r(void)
  98. {
  99. #if CONFIG_IS_ENABLED(FPGA)
  100. int cpu_id = cpu_desc_id();
  101. if (cpu_id < 0)
  102. return 0;
  103. fpga.size = zynq_fpga_descs[cpu_id].fpga_size;
  104. fpga.name = zynq_fpga_descs[cpu_id].devicename;
  105. fpga_init();
  106. fpga_add(fpga_xilinx, &fpga);
  107. #endif
  108. return 0;
  109. }
  110. #endif
  111. #ifdef CONFIG_DISPLAY_CPUINFO
  112. int print_cpuinfo(void)
  113. {
  114. u32 version;
  115. int cpu_id = cpu_desc_id();
  116. if (cpu_id < 0)
  117. return 0;
  118. version = zynq_get_silicon_version() << 1;
  119. if (version > (PCW_SILICON_VERSION_3 << 1))
  120. version += 1;
  121. printf("CPU: Zynq %s\n", zynq_fpga_descs[cpu_id].devicename);
  122. printf("Silicon: v%d.%d\n", version >> 1, version & 1);
  123. return 0;
  124. }
  125. #endif