]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_mmc.c
SMDK6400: Disable LED function in start.s on the nand booting
[people/ms/u-boot.git] / common / cmd_mmc.c
CommitLineData
71f95118
WD
1/*
2 * (C) Copyright 2003
3 * Kyle Harris, kharris@nexus-tech.net
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#include <common.h>
25#include <command.h>
71f95118
WD
26#include <mmc.h>
27
272cc70b 28#ifndef CONFIG_GENERIC_MMC
02e22c2d 29static int curr_device = -1;
869f6bf4 30
54841ab5 31int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118 32{
869f6bf4
MK
33 int dev;
34
47e26b1b
WD
35 if (argc < 2)
36 return cmd_usage(cmdtp);
869f6bf4
MK
37
38 if (strcmp(argv[1], "init") == 0) {
39 if (argc == 2) {
40 if (curr_device < 0)
41 dev = 1;
42 else
43 dev = curr_device;
44 } else if (argc == 3) {
45 dev = (int)simple_strtoul(argv[2], NULL, 10);
46 } else {
47e26b1b 47 return cmd_usage(cmdtp);
869f6bf4
MK
48 }
49
50 if (mmc_legacy_init(dev) != 0) {
51 puts("No MMC card found\n");
52 return 1;
53 }
54
55 curr_device = dev;
56 printf("mmc%d is available\n", curr_device);
57 } else if (strcmp(argv[1], "device") == 0) {
58 if (argc == 2) {
59 if (curr_device < 0) {
60 puts("No MMC device available\n");
61 return 1;
62 }
63 } else if (argc == 3) {
64 dev = (int)simple_strtoul(argv[2], NULL, 10);
65
66#ifdef CONFIG_SYS_MMC_SET_DEV
67 if (mmc_set_dev(dev) != 0)
68 return 1;
69#endif
70 curr_device = dev;
71 } else {
47e26b1b 72 return cmd_usage(cmdtp);
869f6bf4
MK
73 }
74
75 printf("mmc%d is current device\n", curr_device);
76 } else {
47e26b1b 77 return cmd_usage(cmdtp);
71f95118 78 }
869f6bf4 79
71f95118
WD
80 return 0;
81}
82
0d498393 83U_BOOT_CMD(
869f6bf4
MK
84 mmc, 3, 1, do_mmc,
85 "MMC sub-system",
86 "init [dev] - init MMC sub system\n"
a89c33db 87 "mmc device [dev] - show or set current device"
b0fce99b 88);
3511b4e2 89#else /* !CONFIG_GENERIC_MMC */
272cc70b
AF
90
91static void print_mmcinfo(struct mmc *mmc)
92{
93 printf("Device: %s\n", mmc->name);
94 printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
95 printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
96 printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
97 (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
98 (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
99
100 printf("Tran Speed: %d\n", mmc->tran_speed);
101 printf("Rd Block Len: %d\n", mmc->read_bl_len);
102
103 printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
104 (mmc->version >> 4) & 0xf, mmc->version & 0xf);
105
106 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
107 printf("Capacity: %lld\n", mmc->capacity);
108
109 printf("Bus Width: %d-bit\n", mmc->bus_width);
110}
111
54841ab5 112int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
272cc70b
AF
113{
114 struct mmc *mmc;
115 int dev_num;
116
117 if (argc < 2)
118 dev_num = 0;
119 else
120 dev_num = simple_strtoul(argv[1], NULL, 0);
121
122 mmc = find_mmc_device(dev_num);
123
124 if (mmc) {
125 mmc_init(mmc);
126
127 print_mmcinfo(mmc);
128 }
129
130 return 0;
131}
132
388a29d0
FM
133U_BOOT_CMD(
134 mmcinfo, 2, 0, do_mmcinfo,
cc9f607b 135 "display MMC info",
a9804be8 136 "<dev num>\n"
2d941de9 137 " - device number of the device to dislay info of\n"
a89c33db
WD
138 ""
139);
272cc70b 140
54841ab5 141int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
272cc70b
AF
142{
143 int rc = 0;
144
145 switch (argc) {
146 case 3:
147 if (strcmp(argv[1], "rescan") == 0) {
148 int dev = simple_strtoul(argv[2], NULL, 10);
149 struct mmc *mmc = find_mmc_device(dev);
150
e85649c7
RV
151 if (!mmc)
152 return 1;
153
272cc70b
AF
154 mmc_init(mmc);
155
156 return 0;
8f3b9642
LW
157 } else if (strncmp(argv[1], "part", 4) == 0) {
158 int dev = simple_strtoul(argv[2], NULL, 10);
159 block_dev_desc_t *mmc_dev;
160 struct mmc *mmc = find_mmc_device(dev);
161
162 if (!mmc) {
163 puts("no mmc devices available\n");
164 return 1;
165 }
166 mmc_init(mmc);
167 mmc_dev = mmc_get_dev(dev);
168 if (mmc_dev != NULL &&
169 mmc_dev->type != DEV_TYPE_UNKNOWN) {
170 print_part(mmc_dev);
171 return 0;
172 }
173
174 puts("get mmc type error!\n");
175 return 1;
272cc70b
AF
176 }
177
178 case 0:
179 case 1:
180 case 4:
e2fad3fc 181 return cmd_usage(cmdtp);
272cc70b
AF
182
183 case 2:
184 if (!strcmp(argv[1], "list")) {
185 print_mmc_devices('\n');
186 return 0;
187 }
188 return 1;
189 default: /* at least 5 args */
190 if (strcmp(argv[1], "read") == 0) {
191 int dev = simple_strtoul(argv[2], NULL, 10);
192 void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
193 u32 cnt = simple_strtoul(argv[5], NULL, 16);
194 u32 n;
195 u32 blk = simple_strtoul(argv[4], NULL, 16);
196 struct mmc *mmc = find_mmc_device(dev);
197
e85649c7
RV
198 if (!mmc)
199 return 1;
200
272cc70b
AF
201 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
202 dev, blk, cnt);
203
204 mmc_init(mmc);
205
206 n = mmc->block_dev.block_read(dev, blk, cnt, addr);
207
208 /* flush cache after read */
1bba30ef 209 flush_cache((ulong)addr, cnt * 512); /* FIXME */
272cc70b
AF
210
211 printf("%d blocks read: %s\n",
212 n, (n==cnt) ? "OK" : "ERROR");
213 return (n == cnt) ? 0 : 1;
214 } else if (strcmp(argv[1], "write") == 0) {
215 int dev = simple_strtoul(argv[2], NULL, 10);
216 void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
217 u32 cnt = simple_strtoul(argv[5], NULL, 16);
218 u32 n;
219 struct mmc *mmc = find_mmc_device(dev);
220
221 int blk = simple_strtoul(argv[4], NULL, 16);
222
e85649c7
RV
223 if (!mmc)
224 return 1;
225
272cc70b
AF
226 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
227 dev, blk, cnt);
228
229 mmc_init(mmc);
230
231 n = mmc->block_dev.block_write(dev, blk, cnt, addr);
232
233 printf("%d blocks written: %s\n",
234 n, (n == cnt) ? "OK" : "ERROR");
235 return (n == cnt) ? 0 : 1;
e2fad3fc
MF
236 } else
237 rc = cmd_usage(cmdtp);
272cc70b
AF
238
239 return rc;
240 }
241}
242
243U_BOOT_CMD(
244 mmc, 6, 1, do_mmcops,
852dbfdd 245 "MMC sub system",
ac0865ff 246 "read <device num> addr blk# cnt\n"
272cc70b
AF
247 "mmc write <device num> addr blk# cnt\n"
248 "mmc rescan <device num>\n"
8f3b9642 249 "mmc part <device num> - lists available partition on mmc\n"
a89c33db 250 "mmc list - lists available devices");
3511b4e2 251#endif