cache.c 2.9 KB

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