blob: 9c228e219dca2af64f5afc76c7e63848ff17a74a [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * Cache support: switch on or off, get status
26 */
27#include <common.h>
28#include <command.h>
Matthew McClintockd0c4c332011-05-24 10:09:05 +000029#include <linux/compiler.h>
wdenk38635852002-08-27 05:55:31 +000030
Matthew McClintockd0c4c332011-05-24 10:09:05 +000031static int parse_argv(const char *);
32
Stefan Kristiansson23498932011-10-31 18:21:12 +000033void __weak invalidate_icache_all(void)
Matthew McClintockd0c4c332011-05-24 10:09:05 +000034{
Stefan Kristiansson23498932011-10-31 18:21:12 +000035 /* please define arch specific invalidate_icache_all */
36 puts("No arch specific invalidate_icache_all available!\n");
Matthew McClintockd0c4c332011-05-24 10:09:05 +000037}
wdenk38635852002-08-27 05:55:31 +000038
Wolfgang Denk54841ab2010-06-28 22:00:46 +020039int do_icache ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000040{
41 switch (argc) {
42 case 2: /* on / off */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000043 switch (parse_argv(argv[1])) {
wdenk38635852002-08-27 05:55:31 +000044 case 0: icache_disable();
45 break;
46 case 1: icache_enable ();
47 break;
Stefan Kristiansson23498932011-10-31 18:21:12 +000048 case 2: invalidate_icache_all();
Matthew McClintockd0c4c332011-05-24 10:09:05 +000049 break;
wdenk38635852002-08-27 05:55:31 +000050 }
51 /* FALL TROUGH */
52 case 1: /* get status */
53 printf ("Instruction Cache is %s\n",
54 icache_status() ? "ON" : "OFF");
55 return 0;
56 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000057 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000058 }
59 return 0;
60}
61
Stefan Kristiansson23498932011-10-31 18:21:12 +000062void __weak flush_dcache_all(void)
Matthew McClintockd0c4c332011-05-24 10:09:05 +000063{
Stefan Kristiansson23498932011-10-31 18:21:12 +000064 puts("No arch specific flush_dcache_all available!\n");
65 /* please define arch specific flush_dcache_all */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000066}
67
Wolfgang Denk54841ab2010-06-28 22:00:46 +020068int do_dcache ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000069{
70 switch (argc) {
71 case 2: /* on / off */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000072 switch (parse_argv(argv[1])) {
wdenk38635852002-08-27 05:55:31 +000073 case 0: dcache_disable();
74 break;
75 case 1: dcache_enable ();
76 break;
Stefan Kristiansson23498932011-10-31 18:21:12 +000077 case 2: flush_dcache_all();
Matthew McClintockd0c4c332011-05-24 10:09:05 +000078 break;
wdenk38635852002-08-27 05:55:31 +000079 }
80 /* FALL TROUGH */
81 case 1: /* get status */
82 printf ("Data (writethrough) Cache is %s\n",
83 dcache_status() ? "ON" : "OFF");
84 return 0;
85 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000086 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000087 }
88 return 0;
89
90}
91
Matthew McClintockd0c4c332011-05-24 10:09:05 +000092static int parse_argv(const char *s)
wdenk38635852002-08-27 05:55:31 +000093{
Matthew McClintockd0c4c332011-05-24 10:09:05 +000094 if (strcmp(s, "flush") == 0) {
95 return (2);
96 } else if (strcmp(s, "on") == 0) {
wdenk38635852002-08-27 05:55:31 +000097 return (1);
98 } else if (strcmp(s, "off") == 0) {
99 return (0);
100 }
101 return (-1);
102}
103
wdenk8bde7f72003-06-27 21:31:46 +0000104
wdenk0d498392003-07-01 21:06:45 +0000105U_BOOT_CMD(
106 icache, 2, 1, do_icache,
Peter Tyser2fb26042009-01-27 18:03:12 -0600107 "enable or disable instruction cache",
Matthew McClintockd0c4c332011-05-24 10:09:05 +0000108 "[on, off, flush]\n"
109 " - enable, disable, or flush instruction cache"
wdenk8bde7f72003-06-27 21:31:46 +0000110);
111
wdenk0d498392003-07-01 21:06:45 +0000112U_BOOT_CMD(
113 dcache, 2, 1, do_dcache,
Peter Tyser2fb26042009-01-27 18:03:12 -0600114 "enable or disable data cache",
Matthew McClintockd0c4c332011-05-24 10:09:05 +0000115 "[on, off, flush]\n"
116 " - enable, disable, or flush data (writethrough) cache"
wdenk8bde7f72003-06-27 21:31:46 +0000117);