]>
Commit | Line | Data |
---|---|---|
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 |
71f95118 WD |
29 | int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
30 | { | |
abb5466c | 31 | if (mmc_legacy_init (1) != 0) { |
71f95118 WD |
32 | printf ("No MMC card found\n"); |
33 | return 1; | |
34 | } | |
35 | return 0; | |
36 | } | |
37 | ||
0d498393 WD |
38 | U_BOOT_CMD( |
39 | mmcinit, 1, 0, do_mmc, | |
2fb2604d | 40 | "init mmc card", |
b0fce99b WD |
41 | NULL |
42 | ); | |
272cc70b AF |
43 | #endif /* !CONFIG_GENERIC_MMC */ |
44 | ||
45 | static void print_mmcinfo(struct mmc *mmc) | |
46 | { | |
47 | printf("Device: %s\n", mmc->name); | |
48 | printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24); | |
49 | printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff); | |
50 | printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff, | |
51 | (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff, | |
52 | (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff); | |
53 | ||
54 | printf("Tran Speed: %d\n", mmc->tran_speed); | |
55 | printf("Rd Block Len: %d\n", mmc->read_bl_len); | |
56 | ||
57 | printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC", | |
58 | (mmc->version >> 4) & 0xf, mmc->version & 0xf); | |
59 | ||
60 | printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No"); | |
61 | printf("Capacity: %lld\n", mmc->capacity); | |
62 | ||
63 | printf("Bus Width: %d-bit\n", mmc->bus_width); | |
64 | } | |
65 | ||
66 | int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) | |
67 | { | |
68 | struct mmc *mmc; | |
69 | int dev_num; | |
70 | ||
71 | if (argc < 2) | |
72 | dev_num = 0; | |
73 | else | |
74 | dev_num = simple_strtoul(argv[1], NULL, 0); | |
75 | ||
76 | mmc = find_mmc_device(dev_num); | |
77 | ||
78 | if (mmc) { | |
79 | mmc_init(mmc); | |
80 | ||
81 | print_mmcinfo(mmc); | |
82 | } | |
83 | ||
84 | return 0; | |
85 | } | |
86 | ||
87 | U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo, "mmcinfo <dev num>-- display MMC info\n", | |
88 | NULL); | |
89 | ||
90 | int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) | |
91 | { | |
92 | int rc = 0; | |
93 | ||
94 | switch (argc) { | |
95 | case 3: | |
96 | if (strcmp(argv[1], "rescan") == 0) { | |
97 | int dev = simple_strtoul(argv[2], NULL, 10); | |
98 | struct mmc *mmc = find_mmc_device(dev); | |
99 | ||
100 | mmc_init(mmc); | |
101 | ||
102 | return 0; | |
103 | } | |
104 | ||
105 | case 0: | |
106 | case 1: | |
107 | case 4: | |
108 | printf("Usage:\n%s\n", cmdtp->usage); | |
109 | return 1; | |
110 | ||
111 | case 2: | |
112 | if (!strcmp(argv[1], "list")) { | |
113 | print_mmc_devices('\n'); | |
114 | return 0; | |
115 | } | |
116 | return 1; | |
117 | default: /* at least 5 args */ | |
118 | if (strcmp(argv[1], "read") == 0) { | |
119 | int dev = simple_strtoul(argv[2], NULL, 10); | |
120 | void *addr = (void *)simple_strtoul(argv[3], NULL, 16); | |
121 | u32 cnt = simple_strtoul(argv[5], NULL, 16); | |
122 | u32 n; | |
123 | u32 blk = simple_strtoul(argv[4], NULL, 16); | |
124 | struct mmc *mmc = find_mmc_device(dev); | |
125 | ||
126 | printf("\nMMC read: dev # %d, block # %d, count %d ... ", | |
127 | dev, blk, cnt); | |
128 | ||
129 | mmc_init(mmc); | |
130 | ||
131 | n = mmc->block_dev.block_read(dev, blk, cnt, addr); | |
132 | ||
133 | /* flush cache after read */ | |
134 | flush_cache((ulong)addr, cnt * 512); //FIXME | |
135 | ||
136 | printf("%d blocks read: %s\n", | |
137 | n, (n==cnt) ? "OK" : "ERROR"); | |
138 | return (n == cnt) ? 0 : 1; | |
139 | } else if (strcmp(argv[1], "write") == 0) { | |
140 | int dev = simple_strtoul(argv[2], NULL, 10); | |
141 | void *addr = (void *)simple_strtoul(argv[3], NULL, 16); | |
142 | u32 cnt = simple_strtoul(argv[5], NULL, 16); | |
143 | u32 n; | |
144 | struct mmc *mmc = find_mmc_device(dev); | |
145 | ||
146 | int blk = simple_strtoul(argv[4], NULL, 16); | |
147 | ||
148 | printf("\nMMC write: dev # %d, block # %d, count %d ... ", | |
149 | dev, blk, cnt); | |
150 | ||
151 | mmc_init(mmc); | |
152 | ||
153 | n = mmc->block_dev.block_write(dev, blk, cnt, addr); | |
154 | ||
155 | printf("%d blocks written: %s\n", | |
156 | n, (n == cnt) ? "OK" : "ERROR"); | |
157 | return (n == cnt) ? 0 : 1; | |
158 | } else { | |
159 | printf("Usage:\n%s\n", cmdtp->usage); | |
160 | rc = 1; | |
161 | } | |
162 | ||
163 | return rc; | |
164 | } | |
165 | } | |
166 | ||
167 | U_BOOT_CMD( | |
168 | mmc, 6, 1, do_mmcops, | |
169 | "mmc - MMC sub system\n", | |
170 | "mmc read <device num> addr blk# cnt\n" | |
171 | "mmc write <device num> addr blk# cnt\n" | |
172 | "mmc rescan <device num>\n" | |
173 | "mmc list - lists available devices\n"); |