mxs_nand: Update compatible string for i.MX6SX
[oweals/u-boot.git] / cmd / cache.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2000
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6
7 /*
8  * Cache support: switch on or off, get status
9  */
10 #include <common.h>
11 #include <command.h>
12 #include <cpu_func.h>
13 #include <linux/compiler.h>
14
15 static int parse_argv(const char *);
16
17 void __weak invalidate_icache_all(void)
18 {
19         /* please define arch specific invalidate_icache_all */
20         puts("No arch specific invalidate_icache_all available!\n");
21 }
22
23 __weak void noncached_set_region(void)
24 {
25 }
26
27 static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
28 {
29         switch (argc) {
30         case 2:                 /* on / off / flush */
31                 switch (parse_argv(argv[1])) {
32                 case 0:
33                         icache_disable();
34                         break;
35                 case 1:
36                         icache_enable();
37                         break;
38                 case 2:
39                         invalidate_icache_all();
40                         break;
41                 default:
42                         return CMD_RET_USAGE;
43                 }
44                 break;
45         case 1:                 /* get status */
46                 printf("Instruction Cache is %s\n",
47                         icache_status() ? "ON" : "OFF");
48                 return 0;
49         default:
50                 return CMD_RET_USAGE;
51         }
52         return 0;
53 }
54
55 void __weak flush_dcache_all(void)
56 {
57         puts("No arch specific flush_dcache_all available!\n");
58         /* please define arch specific flush_dcache_all */
59 }
60
61 static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
62 {
63         switch (argc) {
64         case 2:                 /* on / off / flush */
65                 switch (parse_argv(argv[1])) {
66                 case 0:
67                         dcache_disable();
68                         break;
69                 case 1:
70                         dcache_enable();
71                         noncached_set_region();
72                         break;
73                 case 2:
74                         flush_dcache_all();
75                         break;
76                 default:
77                         return CMD_RET_USAGE;
78                 }
79                 break;
80         case 1:                 /* get status */
81                 printf("Data (writethrough) Cache is %s\n",
82                         dcache_status() ? "ON" : "OFF");
83                 return 0;
84         default:
85                 return CMD_RET_USAGE;
86         }
87         return 0;
88 }
89
90 static int parse_argv(const char *s)
91 {
92         if (strcmp(s, "flush") == 0)
93                 return 2;
94         else if (strcmp(s, "on") == 0)
95                 return 1;
96         else if (strcmp(s, "off") == 0)
97                 return 0;
98
99         return -1;
100 }
101
102
103 U_BOOT_CMD(
104         icache,   2,   1,     do_icache,
105         "enable or disable instruction cache",
106         "[on, off, flush]\n"
107         "    - enable, disable, or flush instruction cache"
108 );
109
110 U_BOOT_CMD(
111         dcache,   2,   1,     do_dcache,
112         "enable or disable data cache",
113         "[on, off, flush]\n"
114         "    - enable, disable, or flush data (writethrough) cache"
115 );