2 * Copyright (C) 2012-2014 Panasonic Corporation
3 * Copyright (C) 2015 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/armv7.h>
12 #include <mach/ssc-regs.h>
14 #ifdef CONFIG_UNIPHIER_L2CACHE_ON
15 static void uniphier_cache_maint_all(u32 operation)
17 /* try until the command is successfully set */
19 writel(SSCOQM_S_ALL | SSCOQM_CE | operation, SSCOQM);
20 } while (readl(SSCOPPQSEF) & (SSCOPPQSEF_FE | SSCOPPQSEF_OE));
22 /* wait until the operation is completed */
23 while (readl(SSCOLPQS) != SSCOLPQS_EF)
26 /* clear the complete notification flag */
27 writel(SSCOLPQS_EF, SSCOLPQS);
29 writel(SSCOPE_CM_SYNC, SSCOPE); /* drain internal buffers */
30 readl(SSCOPE); /* need a read back to confirm */
33 void v7_outer_cache_flush_all(void)
35 uniphier_cache_maint_all(SSCOQM_CM_WB_INV);
38 void v7_outer_cache_inval_all(void)
40 uniphier_cache_maint_all(SSCOQM_CM_INV);
43 static void __uniphier_cache_maint_range(u32 start, u32 size, u32 operation)
45 /* try until the command is successfully set */
47 writel(SSCOQM_S_ADDRESS | SSCOQM_CE | operation, SSCOQM);
48 writel(start, SSCOQAD);
49 writel(size, SSCOQSZ);
51 } while (readl(SSCOPPQSEF) & (SSCOPPQSEF_FE | SSCOPPQSEF_OE));
53 /* wait until the operation is completed */
54 while (readl(SSCOLPQS) != SSCOLPQS_EF)
57 /* clear the complete notification flag */
58 writel(SSCOLPQS_EF, SSCOLPQS);
61 static void uniphier_cache_maint_range(u32 start, u32 end, u32 operation)
66 * If start address is not aligned to cache-line,
67 * do cache operation for the first cache-line
69 start = start & ~(SSC_LINE_SIZE - 1);
71 if (start == 0 && end >= (u32)(-SSC_LINE_SIZE)) {
72 /* this means cache operation for all range */
73 uniphier_cache_maint_all(operation);
78 * If end address is not aligned to cache-line,
79 * do cache operation for the last cache-line
81 size = (end - start + SSC_LINE_SIZE - 1) & ~(SSC_LINE_SIZE - 1);
84 u32 chunk_size = size > SSC_RANGE_OP_MAX_SIZE ?
85 SSC_RANGE_OP_MAX_SIZE : size;
86 __uniphier_cache_maint_range(start, chunk_size, operation);
92 writel(SSCOPE_CM_SYNC, SSCOPE); /* drain internal buffers */
93 readl(SSCOPE); /* need a read back to confirm */
96 void v7_outer_cache_flush_range(u32 start, u32 end)
98 uniphier_cache_maint_range(start, end, SSCOQM_CM_WB_INV);
101 void v7_outer_cache_inval_range(u32 start, u32 end)
103 uniphier_cache_maint_range(start, end, SSCOQM_CM_INV);
106 void v7_outer_cache_enable(void)
115 void v7_outer_cache_disable(void)
123 void enable_caches(void)