cache.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/armv7.h>
  8. #include <asm/pl310.h>
  9. #include <asm/io.h>
  10. #ifndef CONFIG_SYS_DCACHE_OFF
  11. void enable_caches(void)
  12. {
  13. #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
  14. enum dcache_option option = DCACHE_WRITETHROUGH;
  15. #else
  16. enum dcache_option option = DCACHE_WRITEBACK;
  17. #endif
  18. /* Avoid random hang when download by usb */
  19. invalidate_dcache_all();
  20. /* Enable D-cache. I-cache is already enabled in start.S */
  21. dcache_enable();
  22. /* Enable caching on OCRAM and ROM */
  23. mmu_set_region_dcache_behaviour(ROMCP_ARB_BASE_ADDR,
  24. ROMCP_ARB_END_ADDR,
  25. option);
  26. mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR,
  27. IRAM_SIZE,
  28. option);
  29. }
  30. #endif
  31. #ifndef CONFIG_SYS_L2CACHE_OFF
  32. #ifdef CONFIG_SYS_L2_PL310
  33. #define IOMUXC_GPR11_L2CACHE_AS_OCRAM 0x00000002
  34. void v7_outer_cache_enable(void)
  35. {
  36. struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
  37. unsigned int val;
  38. /*
  39. * Must disable the L2 before changing the latency parameters
  40. * and auxiliary control register.
  41. */
  42. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  43. /*
  44. * Set bit 22 in the auxiliary control register. If this bit
  45. * is cleared, PL310 treats Normal Shared Non-cacheable
  46. * accesses as Cacheable no-allocate.
  47. */
  48. setbits_le32(&pl310->pl310_aux_ctrl, L310_SHARED_ATT_OVERRIDE_ENABLE);
  49. #if defined CONFIG_MX6SL
  50. struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
  51. val = readl(&iomux->gpr[11]);
  52. if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) {
  53. /* L2 cache configured as OCRAM, reset it */
  54. val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM;
  55. writel(val, &iomux->gpr[11]);
  56. }
  57. #endif
  58. writel(0x132, &pl310->pl310_tag_latency_ctrl);
  59. writel(0x132, &pl310->pl310_data_latency_ctrl);
  60. val = readl(&pl310->pl310_prefetch_ctrl);
  61. /* Turn on the L2 I/D prefetch */
  62. val |= 0x30000000;
  63. /*
  64. * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
  65. * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL is r3p2
  66. * But according to ARM PL310 errata: 752271
  67. * ID: 752271: Double linefill feature can cause data corruption
  68. * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
  69. * Workaround: The only workaround to this erratum is to disable the
  70. * double linefill feature. This is the default behavior.
  71. */
  72. #ifndef CONFIG_MX6Q
  73. val |= 0x40800000;
  74. #endif
  75. writel(val, &pl310->pl310_prefetch_ctrl);
  76. val = readl(&pl310->pl310_power_ctrl);
  77. val |= L2X0_DYNAMIC_CLK_GATING_EN;
  78. val |= L2X0_STNDBY_MODE_EN;
  79. writel(val, &pl310->pl310_power_ctrl);
  80. setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  81. }
  82. void v7_outer_cache_disable(void)
  83. {
  84. struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
  85. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  86. }
  87. #endif /* !CONFIG_SYS_L2_PL310 */
  88. #endif /* !CONFIG_SYS_L2CACHE_OFF */