cache.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * Set bit 22 in the auxiliary control register. If this bit
  40. * is cleared, PL310 treats Normal Shared Non-cacheable
  41. * accesses as Cacheable no-allocate.
  42. */
  43. setbits_le32(&pl310->pl310_aux_ctrl, L310_SHARED_ATT_OVERRIDE_ENABLE);
  44. #if defined CONFIG_MX6SL
  45. struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
  46. val = readl(&iomux->gpr[11]);
  47. if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) {
  48. /* L2 cache configured as OCRAM, reset it */
  49. val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM;
  50. writel(val, &iomux->gpr[11]);
  51. }
  52. #endif
  53. /* Must disable the L2 before changing the latency parameters */
  54. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  55. writel(0x132, &pl310->pl310_tag_latency_ctrl);
  56. writel(0x132, &pl310->pl310_data_latency_ctrl);
  57. val = readl(&pl310->pl310_prefetch_ctrl);
  58. /* Turn on the L2 I/D prefetch */
  59. val |= 0x30000000;
  60. /*
  61. * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
  62. * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL is r3p2
  63. * But according to ARM PL310 errata: 752271
  64. * ID: 752271: Double linefill feature can cause data corruption
  65. * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
  66. * Workaround: The only workaround to this erratum is to disable the
  67. * double linefill feature. This is the default behavior.
  68. */
  69. #ifndef CONFIG_MX6Q
  70. val |= 0x40800000;
  71. #endif
  72. writel(val, &pl310->pl310_prefetch_ctrl);
  73. val = readl(&pl310->pl310_power_ctrl);
  74. val |= L2X0_DYNAMIC_CLK_GATING_EN;
  75. val |= L2X0_STNDBY_MODE_EN;
  76. writel(val, &pl310->pl310_power_ctrl);
  77. setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  78. }
  79. void v7_outer_cache_disable(void)
  80. {
  81. struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
  82. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  83. }
  84. #endif /* !CONFIG_SYS_L2_PL310 */
  85. #endif /* !CONFIG_SYS_L2CACHE_OFF */