rk3368.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2016 Rockchip Electronics Co., Ltd
  4. * Copyright (c) 2016 Andreas Färber
  5. */
  6. #include <common.h>
  7. #include <asm/armv8/mmu.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/clock.h>
  10. #include <asm/arch/cru_rk3368.h>
  11. #include <asm/arch/grf_rk3368.h>
  12. #include <syscon.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. #define IMEM_BASE 0xFF8C0000
  15. /* Max MCU's SRAM value is 8K, begin at (IMEM_BASE + 4K) */
  16. #define MCU_SRAM_BASE (IMEM_BASE + 1024 * 4)
  17. #define MCU_SRAM_BASE_BIT31_BIT28 ((MCU_SRAM_BASE & GENMASK(31, 28)) >> 28)
  18. #define MCU_SRAM_BASE_BIT27_BIT12 ((MCU_SRAM_BASE & GENMASK(27, 12)) >> 12)
  19. /* exsram may using by mcu to accessing dram(0x0-0x20000000) */
  20. #define MCU_EXSRAM_BASE (0)
  21. #define MCU_EXSRAM_BASE_BIT31_BIT28 ((MCU_EXSRAM_BASE & GENMASK(31, 28)) >> 28)
  22. #define MCU_EXSRAM_BASE_BIT27_BIT12 ((MCU_EXSRAM_BASE & GENMASK(27, 12)) >> 12)
  23. /* experi no used, reserved value = 0 */
  24. #define MCU_EXPERI_BASE (0)
  25. #define MCU_EXPERI_BASE_BIT31_BIT28 ((MCU_EXPERI_BASE & GENMASK(31, 28)) >> 28)
  26. #define MCU_EXPERI_BASE_BIT27_BIT12 ((MCU_EXPERI_BASE & GENMASK(27, 12)) >> 12)
  27. static struct mm_region rk3368_mem_map[] = {
  28. {
  29. .virt = 0x0UL,
  30. .phys = 0x0UL,
  31. .size = 0x80000000UL,
  32. .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  33. PTE_BLOCK_INNER_SHARE
  34. }, {
  35. .virt = 0xf0000000UL,
  36. .phys = 0xf0000000UL,
  37. .size = 0x10000000UL,
  38. .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
  39. PTE_BLOCK_NON_SHARE |
  40. PTE_BLOCK_PXN | PTE_BLOCK_UXN
  41. }, {
  42. /* List terminator */
  43. 0,
  44. }
  45. };
  46. struct mm_region *mem_map = rk3368_mem_map;
  47. int dram_init_banksize(void)
  48. {
  49. size_t max_size = min((unsigned long)gd->ram_size, gd->ram_top);
  50. /* Reserve 0x200000 for ATF bl31 */
  51. gd->bd->bi_dram[0].start = 0x200000;
  52. gd->bd->bi_dram[0].size = max_size - gd->bd->bi_dram[0].start;
  53. return 0;
  54. }
  55. #ifdef CONFIG_ARCH_EARLY_INIT_R
  56. static int mcu_init(void)
  57. {
  58. struct rk3368_grf *grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
  59. struct rk3368_cru *cru = rockchip_get_cru();
  60. rk_clrsetreg(&grf->soc_con14, MCU_SRAM_BASE_BIT31_BIT28_MASK,
  61. MCU_SRAM_BASE_BIT31_BIT28 << MCU_SRAM_BASE_BIT31_BIT28_SHIFT);
  62. rk_clrsetreg(&grf->soc_con11, MCU_SRAM_BASE_BIT27_BIT12_MASK,
  63. MCU_SRAM_BASE_BIT27_BIT12 << MCU_SRAM_BASE_BIT27_BIT12_SHIFT);
  64. rk_clrsetreg(&grf->soc_con14, MCU_EXSRAM_BASE_BIT31_BIT28_MASK,
  65. MCU_EXSRAM_BASE_BIT31_BIT28 << MCU_EXSRAM_BASE_BIT31_BIT28_SHIFT);
  66. rk_clrsetreg(&grf->soc_con12, MCU_EXSRAM_BASE_BIT27_BIT12_MASK,
  67. MCU_EXSRAM_BASE_BIT27_BIT12 << MCU_EXSRAM_BASE_BIT27_BIT12_SHIFT);
  68. rk_clrsetreg(&grf->soc_con14, MCU_EXPERI_BASE_BIT31_BIT28_MASK,
  69. MCU_EXPERI_BASE_BIT31_BIT28 << MCU_EXPERI_BASE_BIT31_BIT28_SHIFT);
  70. rk_clrsetreg(&grf->soc_con13, MCU_EXPERI_BASE_BIT27_BIT12_MASK,
  71. MCU_EXPERI_BASE_BIT27_BIT12 << MCU_EXPERI_BASE_BIT27_BIT12_SHIFT);
  72. rk_clrsetreg(&cru->clksel_con[12], MCU_PLL_SEL_MASK | MCU_CLK_DIV_MASK,
  73. (MCU_PLL_SEL_GPLL << MCU_PLL_SEL_SHIFT) |
  74. (5 << MCU_CLK_DIV_SHIFT));
  75. /* mcu dereset, for start running */
  76. rk_clrreg(&cru->softrst_con[1], MCU_PO_SRST_MASK | MCU_SYS_SRST_MASK);
  77. return 0;
  78. }
  79. int arch_early_init_r(void)
  80. {
  81. return mcu_init();
  82. }
  83. #endif