wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 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> |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 26 | #include <mmc.h> |
| 27 | |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 28 | #ifndef CONFIG_GENERIC_MMC |
Mike Frysinger | 02e22c2 | 2009-06-14 21:35:21 -0400 | [diff] [blame] | 29 | static int curr_device = -1; |
Minkyu Kang | 869f6bf | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 30 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 31 | int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 32 | { |
Minkyu Kang | 869f6bf | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 33 | int dev; |
| 34 | |
| 35 | if (argc < 2) { |
| 36 | cmd_usage(cmdtp); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 37 | return 1; |
| 38 | } |
Minkyu Kang | 869f6bf | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 39 | |
| 40 | if (strcmp(argv[1], "init") == 0) { |
| 41 | if (argc == 2) { |
| 42 | if (curr_device < 0) |
| 43 | dev = 1; |
| 44 | else |
| 45 | dev = curr_device; |
| 46 | } else if (argc == 3) { |
| 47 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 48 | } else { |
| 49 | cmd_usage(cmdtp); |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | if (mmc_legacy_init(dev) != 0) { |
| 54 | puts("No MMC card found\n"); |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | curr_device = dev; |
| 59 | printf("mmc%d is available\n", curr_device); |
| 60 | } else if (strcmp(argv[1], "device") == 0) { |
| 61 | if (argc == 2) { |
| 62 | if (curr_device < 0) { |
| 63 | puts("No MMC device available\n"); |
| 64 | return 1; |
| 65 | } |
| 66 | } else if (argc == 3) { |
| 67 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 68 | |
| 69 | #ifdef CONFIG_SYS_MMC_SET_DEV |
| 70 | if (mmc_set_dev(dev) != 0) |
| 71 | return 1; |
| 72 | #endif |
| 73 | curr_device = dev; |
| 74 | } else { |
| 75 | cmd_usage(cmdtp); |
| 76 | return 1; |
| 77 | } |
| 78 | |
| 79 | printf("mmc%d is current device\n", curr_device); |
| 80 | } else { |
| 81 | cmd_usage(cmdtp); |
| 82 | return 1; |
| 83 | } |
| 84 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 88 | U_BOOT_CMD( |
Minkyu Kang | 869f6bf | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 89 | mmc, 3, 1, do_mmc, |
| 90 | "MMC sub-system", |
| 91 | "init [dev] - init MMC sub system\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 92 | "mmc device [dev] - show or set current device" |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 93 | ); |
Dirk Behme | 3511b4e | 2009-02-18 19:59:39 +0100 | [diff] [blame] | 94 | #else /* !CONFIG_GENERIC_MMC */ |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 95 | |
| 96 | static void print_mmcinfo(struct mmc *mmc) |
| 97 | { |
| 98 | printf("Device: %s\n", mmc->name); |
| 99 | printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24); |
| 100 | printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff); |
| 101 | printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff, |
| 102 | (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff, |
| 103 | (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff); |
| 104 | |
| 105 | printf("Tran Speed: %d\n", mmc->tran_speed); |
| 106 | printf("Rd Block Len: %d\n", mmc->read_bl_len); |
| 107 | |
| 108 | printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC", |
| 109 | (mmc->version >> 4) & 0xf, mmc->version & 0xf); |
| 110 | |
| 111 | printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No"); |
| 112 | printf("Capacity: %lld\n", mmc->capacity); |
| 113 | |
| 114 | printf("Bus Width: %d-bit\n", mmc->bus_width); |
| 115 | } |
| 116 | |
| 117 | int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 118 | { |
| 119 | struct mmc *mmc; |
| 120 | int dev_num; |
| 121 | |
| 122 | if (argc < 2) |
| 123 | dev_num = 0; |
| 124 | else |
| 125 | dev_num = simple_strtoul(argv[1], NULL, 0); |
| 126 | |
| 127 | mmc = find_mmc_device(dev_num); |
| 128 | |
| 129 | if (mmc) { |
| 130 | mmc_init(mmc); |
| 131 | |
| 132 | print_mmcinfo(mmc); |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 138 | U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo, |
| 139 | "mmcinfo <dev num>-- display MMC info\n", |
| 140 | "" |
| 141 | ); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 142 | |
| 143 | int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 144 | { |
| 145 | int rc = 0; |
| 146 | |
| 147 | switch (argc) { |
| 148 | case 3: |
| 149 | if (strcmp(argv[1], "rescan") == 0) { |
| 150 | int dev = simple_strtoul(argv[2], NULL, 10); |
| 151 | struct mmc *mmc = find_mmc_device(dev); |
| 152 | |
Rabin Vincent | e85649c | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 153 | if (!mmc) |
| 154 | return 1; |
| 155 | |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 156 | mmc_init(mmc); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | case 0: |
| 162 | case 1: |
| 163 | case 4: |
| 164 | printf("Usage:\n%s\n", cmdtp->usage); |
| 165 | return 1; |
| 166 | |
| 167 | case 2: |
| 168 | if (!strcmp(argv[1], "list")) { |
| 169 | print_mmc_devices('\n'); |
| 170 | return 0; |
| 171 | } |
| 172 | return 1; |
| 173 | default: /* at least 5 args */ |
| 174 | if (strcmp(argv[1], "read") == 0) { |
| 175 | int dev = simple_strtoul(argv[2], NULL, 10); |
| 176 | void *addr = (void *)simple_strtoul(argv[3], NULL, 16); |
| 177 | u32 cnt = simple_strtoul(argv[5], NULL, 16); |
| 178 | u32 n; |
| 179 | u32 blk = simple_strtoul(argv[4], NULL, 16); |
| 180 | struct mmc *mmc = find_mmc_device(dev); |
| 181 | |
Rabin Vincent | e85649c | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 182 | if (!mmc) |
| 183 | return 1; |
| 184 | |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 185 | printf("\nMMC read: dev # %d, block # %d, count %d ... ", |
| 186 | dev, blk, cnt); |
| 187 | |
| 188 | mmc_init(mmc); |
| 189 | |
| 190 | n = mmc->block_dev.block_read(dev, blk, cnt, addr); |
| 191 | |
| 192 | /* flush cache after read */ |
Wolfgang Denk | 1bba30e | 2009-02-19 00:41:08 +0100 | [diff] [blame] | 193 | flush_cache((ulong)addr, cnt * 512); /* FIXME */ |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 194 | |
| 195 | printf("%d blocks read: %s\n", |
| 196 | n, (n==cnt) ? "OK" : "ERROR"); |
| 197 | return (n == cnt) ? 0 : 1; |
| 198 | } else if (strcmp(argv[1], "write") == 0) { |
| 199 | int dev = simple_strtoul(argv[2], NULL, 10); |
| 200 | void *addr = (void *)simple_strtoul(argv[3], NULL, 16); |
| 201 | u32 cnt = simple_strtoul(argv[5], NULL, 16); |
| 202 | u32 n; |
| 203 | struct mmc *mmc = find_mmc_device(dev); |
| 204 | |
| 205 | int blk = simple_strtoul(argv[4], NULL, 16); |
| 206 | |
Rabin Vincent | e85649c | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 207 | if (!mmc) |
| 208 | return 1; |
| 209 | |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 210 | printf("\nMMC write: dev # %d, block # %d, count %d ... ", |
| 211 | dev, blk, cnt); |
| 212 | |
| 213 | mmc_init(mmc); |
| 214 | |
| 215 | n = mmc->block_dev.block_write(dev, blk, cnt, addr); |
| 216 | |
| 217 | printf("%d blocks written: %s\n", |
| 218 | n, (n == cnt) ? "OK" : "ERROR"); |
| 219 | return (n == cnt) ? 0 : 1; |
| 220 | } else { |
| 221 | printf("Usage:\n%s\n", cmdtp->usage); |
| 222 | rc = 1; |
| 223 | } |
| 224 | |
| 225 | return rc; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | U_BOOT_CMD( |
| 230 | mmc, 6, 1, do_mmcops, |
Mike Frysinger | 852dbfd | 2009-03-23 22:27:34 -0400 | [diff] [blame] | 231 | "MMC sub system", |
Rabin Vincent | ac0865f | 2009-04-05 13:30:52 +0530 | [diff] [blame] | 232 | "read <device num> addr blk# cnt\n" |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 233 | "mmc write <device num> addr blk# cnt\n" |
| 234 | "mmc rescan <device num>\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 235 | "mmc list - lists available devices"); |
Dirk Behme | 3511b4e | 2009-02-18 19:59:39 +0100 | [diff] [blame] | 236 | #endif |