Commit 272cc70b211e945e4413122aa73868f6ada732a5

Authored by Andy Fleming
1 parent 1de97f9856

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers.  It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

Showing 5 changed files with 1253 additions and 9 deletions Side-by-side Diff

... ... @@ -25,6 +25,7 @@
25 25 #include <command.h>
26 26 #include <mmc.h>
27 27  
  28 +#ifndef CONFIG_GENERIC_MMC
28 29 int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
29 30 {
30 31 if (mmc_legacy_init (1) != 0) {
... ... @@ -39,4 +40,135 @@
39 40 "init mmc card",
40 41 NULL
41 42 );
  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");
drivers/mmc/Makefile
... ... @@ -25,6 +25,7 @@
25 25  
26 26 LIB := $(obj)libmmc.a
27 27  
  28 +COBJS-$(CONFIG_GENERIC_MMC) += mmc.o
28 29 COBJS-$(CONFIG_ATMEL_MCI) += atmel_mci.o
29 30 COBJS-$(CONFIG_BFIN_SDH) += bfin_sdh.o
30 31 COBJS-$(CONFIG_OMAP3_MMC) += omap3_mmc.o
  1 +/*
  2 + * Copyright 2008, Freescale Semiconductor, Inc
  3 + * Andy Fleming
  4 + *
  5 + * Based vaguely on the Linux code
  6 + *
  7 + * See file CREDITS for list of people who contributed to this
  8 + * project.
  9 + *
  10 + * This program is free software; you can redistribute it and/or
  11 + * modify it under the terms of the GNU General Public License as
  12 + * published by the Free Software Foundation; either version 2 of
  13 + * the License, or (at your option) any later version.
  14 + *
  15 + * This program is distributed in the hope that it will be useful,
  16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18 + * GNU General Public License for more details.
  19 + *
  20 + * You should have received a copy of the GNU General Public License
  21 + * along with this program; if not, write to the Free Software
  22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23 + * MA 02111-1307 USA
  24 + */
  25 +
  26 +#include <config.h>
  27 +#include <common.h>
  28 +#include <command.h>
  29 +#include <mmc.h>
  30 +#include <part.h>
  31 +#include <malloc.h>
  32 +#include <linux/list.h>
  33 +#include <mmc.h>
  34 +
  35 +static struct list_head mmc_devices;
  36 +static int cur_dev_num = -1;
  37 +
  38 +int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
  39 +{
  40 + return mmc->send_cmd(mmc, cmd, data);
  41 +}
  42 +
  43 +int mmc_set_blocklen(struct mmc *mmc, int len)
  44 +{
  45 + struct mmc_cmd cmd;
  46 +
  47 + cmd.cmdidx = MMC_CMD_SET_BLOCKLEN;
  48 + cmd.resp_type = MMC_RSP_R1;
  49 + cmd.cmdarg = len;
  50 + cmd.flags = 0;
  51 +
  52 + return mmc_send_cmd(mmc, &cmd, NULL);
  53 +}
  54 +
  55 +struct mmc *find_mmc_device(int dev_num)
  56 +{
  57 + struct mmc *m;
  58 + struct list_head *entry;
  59 +
  60 + list_for_each(entry, &mmc_devices) {
  61 + m = list_entry(entry, struct mmc, link);
  62 +
  63 + if (m->block_dev.dev == dev_num)
  64 + return m;
  65 + }
  66 +
  67 + printf("MMC Device %d not found\n", dev_num);
  68 +
  69 + return NULL;
  70 +}
  71 +
  72 +static ulong
  73 +mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
  74 +{
  75 + struct mmc_cmd cmd;
  76 + struct mmc_data data;
  77 + int err;
  78 + int stoperr = 0;
  79 + struct mmc *mmc = find_mmc_device(dev_num);
  80 + int blklen;
  81 +
  82 + if (!mmc)
  83 + return -1;
  84 +
  85 + blklen = mmc->write_bl_len;
  86 +
  87 + err = mmc_set_blocklen(mmc, mmc->write_bl_len);
  88 +
  89 + if (err) {
  90 + printf("set write bl len failed\n\r");
  91 + return err;
  92 + }
  93 +
  94 + if (blkcnt > 1)
  95 + cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK;
  96 + else
  97 + cmd.cmdidx = MMC_CMD_WRITE_SINGLE_BLOCK;
  98 +
  99 + if (mmc->high_capacity)
  100 + cmd.cmdarg = start;
  101 + else
  102 + cmd.cmdarg = start * blklen;
  103 +
  104 + cmd.resp_type = MMC_RSP_R1;
  105 + cmd.flags = 0;
  106 +
  107 + data.src = src;
  108 + data.blocks = blkcnt;
  109 + data.blocksize = blklen;
  110 + data.flags = MMC_DATA_WRITE;
  111 +
  112 + err = mmc_send_cmd(mmc, &cmd, &data);
  113 +
  114 + if (err) {
  115 + printf("mmc write failed\n\r");
  116 + return err;
  117 + }
  118 +
  119 + if (blkcnt > 1) {
  120 + cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
  121 + cmd.cmdarg = 0;
  122 + cmd.resp_type = MMC_RSP_R1b;
  123 + cmd.flags = 0;
  124 + stoperr = mmc_send_cmd(mmc, &cmd, NULL);
  125 + }
  126 +
  127 + return blkcnt;
  128 +}
  129 +
  130 +int mmc_read_block(struct mmc *mmc, void *dst, uint blocknum)
  131 +{
  132 + struct mmc_cmd cmd;
  133 + struct mmc_data data;
  134 +
  135 + cmd.cmdidx = MMC_CMD_READ_SINGLE_BLOCK;
  136 +
  137 + if (mmc->high_capacity)
  138 + cmd.cmdarg = blocknum;
  139 + else
  140 + cmd.cmdarg = blocknum * mmc->read_bl_len;
  141 +
  142 + cmd.resp_type = MMC_RSP_R1;
  143 + cmd.flags = 0;
  144 +
  145 + data.dest = dst;
  146 + data.blocks = 1;
  147 + data.blocksize = mmc->read_bl_len;
  148 + data.flags = MMC_DATA_READ;
  149 +
  150 + return mmc_send_cmd(mmc, &cmd, &data);
  151 +}
  152 +
  153 +int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size)
  154 +{
  155 + char *buffer;
  156 + int i;
  157 + int blklen = mmc->read_bl_len;
  158 + int startblock = src / blklen;
  159 + int endblock = (src + size - 1) / blklen;
  160 + int err = 0;
  161 +
  162 + /* Make a buffer big enough to hold all the blocks we might read */
  163 + buffer = malloc(blklen);
  164 +
  165 + if (!buffer) {
  166 + printf("Could not allocate buffer for MMC read!\n");
  167 + return -1;
  168 + }
  169 +
  170 + /* We always do full block reads from the card */
  171 + err = mmc_set_blocklen(mmc, mmc->read_bl_len);
  172 +
  173 + if (err)
  174 + return err;
  175 +
  176 + for (i = startblock; i <= endblock; i++) {
  177 + int segment_size;
  178 + int offset;
  179 +
  180 + err = mmc_read_block(mmc, buffer, i);
  181 +
  182 + if (err)
  183 + goto free_buffer;
  184 +
  185 + /*
  186 + * The first block may not be aligned, so we
  187 + * copy from the desired point in the block
  188 + */
  189 + offset = (src & (blklen - 1));
  190 + segment_size = MIN(blklen - offset, size);
  191 +
  192 + memcpy(dst, buffer + offset, segment_size);
  193 +
  194 + dst += segment_size;
  195 + src += segment_size;
  196 + size -= segment_size;
  197 + }
  198 +
  199 +free_buffer:
  200 + free(buffer);
  201 +
  202 + return err;
  203 +}
  204 +
  205 +static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst)
  206 +{
  207 + int err;
  208 + int i;
  209 + struct mmc *mmc = find_mmc_device(dev_num);
  210 +
  211 + if (!mmc)
  212 + return 0;
  213 +
  214 + /* We always do full block reads from the card */
  215 + err = mmc_set_blocklen(mmc, mmc->read_bl_len);
  216 +
  217 + if (err) {
  218 + return 0;
  219 + }
  220 +
  221 + for (i = start; i < start + blkcnt; i++, dst += mmc->read_bl_len) {
  222 + err = mmc_read_block(mmc, dst, i);
  223 +
  224 + if (err) {
  225 + printf("block read failed: %d\n", err);
  226 + return i - start;
  227 + }
  228 + }
  229 +
  230 + return blkcnt;
  231 +}
  232 +
  233 +int mmc_go_idle(struct mmc* mmc)
  234 +{
  235 + struct mmc_cmd cmd;
  236 + int err;
  237 +
  238 + udelay(1000);
  239 +
  240 + cmd.cmdidx = MMC_CMD_GO_IDLE_STATE;
  241 + cmd.cmdarg = 0;
  242 + cmd.resp_type = MMC_RSP_NONE;
  243 + cmd.flags = 0;
  244 +
  245 + err = mmc_send_cmd(mmc, &cmd, NULL);
  246 +
  247 + if (err)
  248 + return err;
  249 +
  250 + udelay(2000);
  251 +
  252 + return 0;
  253 +}
  254 +
  255 +int
  256 +sd_send_op_cond(struct mmc *mmc)
  257 +{
  258 + int timeout = 1000;
  259 + int err;
  260 + struct mmc_cmd cmd;
  261 +
  262 + do {
  263 + cmd.cmdidx = MMC_CMD_APP_CMD;
  264 + cmd.resp_type = MMC_RSP_R1;
  265 + cmd.cmdarg = 0;
  266 + cmd.flags = 0;
  267 +
  268 + err = mmc_send_cmd(mmc, &cmd, NULL);
  269 +
  270 + if (err)
  271 + return err;
  272 +
  273 + cmd.cmdidx = SD_CMD_APP_SEND_OP_COND;
  274 + cmd.resp_type = MMC_RSP_R3;
  275 + cmd.cmdarg = mmc->voltages;
  276 +
  277 + if (mmc->version == SD_VERSION_2)
  278 + cmd.cmdarg |= OCR_HCS;
  279 +
  280 + err = mmc_send_cmd(mmc, &cmd, NULL);
  281 +
  282 + if (err)
  283 + return err;
  284 +
  285 + udelay(1000);
  286 + } while ((!(cmd.response[0] & OCR_BUSY)) && timeout--);
  287 +
  288 + if (timeout <= 0)
  289 + return UNUSABLE_ERR;
  290 +
  291 + if (mmc->version != SD_VERSION_2)
  292 + mmc->version = SD_VERSION_1_0;
  293 +
  294 + mmc->ocr = ((uint *)(cmd.response))[0];
  295 +
  296 + mmc->high_capacity = ((mmc->ocr & OCR_HCS) == OCR_HCS);
  297 + mmc->rca = 0;
  298 +
  299 + return 0;
  300 +}
  301 +
  302 +int mmc_send_op_cond(struct mmc *mmc)
  303 +{
  304 + int timeout = 1000;
  305 + struct mmc_cmd cmd;
  306 + int err;
  307 +
  308 + /* Some cards seem to need this */
  309 + mmc_go_idle(mmc);
  310 +
  311 + do {
  312 + cmd.cmdidx = MMC_CMD_SEND_OP_COND;
  313 + cmd.resp_type = MMC_RSP_R3;
  314 + cmd.cmdarg = OCR_HCS | mmc->voltages;
  315 + cmd.flags = 0;
  316 +
  317 + err = mmc_send_cmd(mmc, &cmd, NULL);
  318 +
  319 + if (err)
  320 + return err;
  321 +
  322 + udelay(1000);
  323 + } while (!(cmd.response[0] & OCR_BUSY) && timeout--);
  324 +
  325 + if (timeout <= 0)
  326 + return UNUSABLE_ERR;
  327 +
  328 + mmc->version = MMC_VERSION_UNKNOWN;
  329 + mmc->ocr = ((uint *)(cmd.response))[0];
  330 +
  331 + mmc->high_capacity = ((mmc->ocr & OCR_HCS) == OCR_HCS);
  332 + mmc->rca = 0;
  333 +
  334 + return 0;
  335 +}
  336 +
  337 +
  338 +int mmc_send_ext_csd(struct mmc *mmc, char *ext_csd)
  339 +{
  340 + struct mmc_cmd cmd;
  341 + struct mmc_data data;
  342 + int err;
  343 +
  344 + /* Get the Card Status Register */
  345 + cmd.cmdidx = MMC_CMD_SEND_EXT_CSD;
  346 + cmd.resp_type = MMC_RSP_R1;
  347 + cmd.cmdarg = 0;
  348 + cmd.flags = 0;
  349 +
  350 + data.dest = ext_csd;
  351 + data.blocks = 1;
  352 + data.blocksize = 512;
  353 + data.flags = MMC_DATA_READ;
  354 +
  355 + err = mmc_send_cmd(mmc, &cmd, &data);
  356 +
  357 + return err;
  358 +}
  359 +
  360 +
  361 +int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
  362 +{
  363 + struct mmc_cmd cmd;
  364 +
  365 + cmd.cmdidx = MMC_CMD_SWITCH;
  366 + cmd.resp_type = MMC_RSP_R1b;
  367 + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
  368 + (index << 16) |
  369 + (value << 8);
  370 + cmd.flags = 0;
  371 +
  372 + return mmc_send_cmd(mmc, &cmd, NULL);
  373 +}
  374 +
  375 +int mmc_change_freq(struct mmc *mmc)
  376 +{
  377 + char ext_csd[512];
  378 + char cardtype;
  379 + int err;
  380 +
  381 + mmc->card_caps = 0;
  382 +
  383 + /* Only version 4 supports high-speed */
  384 + if (mmc->version < MMC_VERSION_4)
  385 + return 0;
  386 +
  387 + mmc->card_caps |= MMC_MODE_4BIT;
  388 +
  389 + err = mmc_send_ext_csd(mmc, ext_csd);
  390 +
  391 + if (err)
  392 + return err;
  393 +
  394 + if (ext_csd[212] || ext_csd[213] || ext_csd[214] || ext_csd[215])
  395 + mmc->high_capacity = 1;
  396 +
  397 + cardtype = ext_csd[196] & 0xf;
  398 +
  399 + err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
  400 +
  401 + if (err)
  402 + return err;
  403 +
  404 + /* Now check to see that it worked */
  405 + err = mmc_send_ext_csd(mmc, ext_csd);
  406 +
  407 + if (err)
  408 + return err;
  409 +
  410 + /* No high-speed support */
  411 + if (!ext_csd[185])
  412 + return 0;
  413 +
  414 + /* High Speed is set, there are two types: 52MHz and 26MHz */
  415 + if (cardtype & MMC_HS_52MHZ)
  416 + mmc->card_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
  417 + else
  418 + mmc->card_caps |= MMC_MODE_HS;
  419 +
  420 + return 0;
  421 +}
  422 +
  423 +int sd_switch(struct mmc *mmc, int mode, int group, u8 value, u8 *resp)
  424 +{
  425 + struct mmc_cmd cmd;
  426 + struct mmc_data data;
  427 +
  428 + /* Switch the frequency */
  429 + cmd.cmdidx = SD_CMD_SWITCH_FUNC;
  430 + cmd.resp_type = MMC_RSP_R1;
  431 + cmd.cmdarg = (mode << 31) | 0xffffff;
  432 + cmd.cmdarg &= ~(0xf << (group * 4));
  433 + cmd.cmdarg |= value << (group * 4);
  434 + cmd.flags = 0;
  435 +
  436 + data.dest = (char *)resp;
  437 + data.blocksize = 64;
  438 + data.blocks = 1;
  439 + data.flags = MMC_DATA_READ;
  440 +
  441 + return mmc_send_cmd(mmc, &cmd, &data);
  442 +}
  443 +
  444 +
  445 +int sd_change_freq(struct mmc *mmc)
  446 +{
  447 + int err;
  448 + struct mmc_cmd cmd;
  449 + uint scr[2];
  450 + uint switch_status[16];
  451 + struct mmc_data data;
  452 + int timeout;
  453 +
  454 + mmc->card_caps = 0;
  455 +
  456 + /* Read the SCR to find out if this card supports higher speeds */
  457 + cmd.cmdidx = MMC_CMD_APP_CMD;
  458 + cmd.resp_type = MMC_RSP_R1;
  459 + cmd.cmdarg = mmc->rca << 16;
  460 + cmd.flags = 0;
  461 +
  462 + err = mmc_send_cmd(mmc, &cmd, NULL);
  463 +
  464 + if (err)
  465 + return err;
  466 +
  467 + cmd.cmdidx = SD_CMD_APP_SEND_SCR;
  468 + cmd.resp_type = MMC_RSP_R1;
  469 + cmd.cmdarg = 0;
  470 + cmd.flags = 0;
  471 +
  472 + timeout = 3;
  473 +
  474 +retry_scr:
  475 + data.dest = (char *)&scr;
  476 + data.blocksize = 8;
  477 + data.blocks = 1;
  478 + data.flags = MMC_DATA_READ;
  479 +
  480 + err = mmc_send_cmd(mmc, &cmd, &data);
  481 +
  482 + if (err) {
  483 + if (timeout--)
  484 + goto retry_scr;
  485 +
  486 + return err;
  487 + }
  488 +
  489 + mmc->scr[0] = scr[0];
  490 + mmc->scr[1] = scr[1];
  491 +
  492 + switch ((mmc->scr[0] >> 24) & 0xf) {
  493 + case 0:
  494 + mmc->version = SD_VERSION_1_0;
  495 + break;
  496 + case 1:
  497 + mmc->version = SD_VERSION_1_10;
  498 + break;
  499 + case 2:
  500 + mmc->version = SD_VERSION_2;
  501 + break;
  502 + default:
  503 + mmc->version = SD_VERSION_1_0;
  504 + break;
  505 + }
  506 +
  507 + /* Version 1.0 doesn't support switching */
  508 + if (mmc->version == SD_VERSION_1_0)
  509 + return 0;
  510 +
  511 + timeout = 4;
  512 + while (timeout--) {
  513 + err = sd_switch(mmc, SD_SWITCH_CHECK, 0, 1,
  514 + (u8 *)&switch_status);
  515 +
  516 + if (err)
  517 + return err;
  518 +
  519 + /* The high-speed function is busy. Try again */
  520 + if (!switch_status[7] & SD_HIGHSPEED_BUSY)
  521 + break;
  522 + }
  523 +
  524 + if (mmc->scr[0] & SD_DATA_4BIT)
  525 + mmc->card_caps |= MMC_MODE_4BIT;
  526 +
  527 + /* If high-speed isn't supported, we return */
  528 + if (!(switch_status[3] & SD_HIGHSPEED_SUPPORTED))
  529 + return 0;
  530 +
  531 + err = sd_switch(mmc, SD_SWITCH_SWITCH, 0, 1, (u8 *)&switch_status);
  532 +
  533 + if (err)
  534 + return err;
  535 +
  536 + if ((switch_status[4] & 0x0f000000) == 0x01000000)
  537 + mmc->card_caps |= MMC_MODE_HS;
  538 +
  539 + return 0;
  540 +}
  541 +
  542 +/* frequency bases */
  543 +/* divided by 10 to be nice to platforms without floating point */
  544 +int fbase[] = {
  545 + 10000,
  546 + 100000,
  547 + 1000000,
  548 + 10000000,
  549 +};
  550 +
  551 +/* Multiplier values for TRAN_SPEED. Multiplied by 10 to be nice
  552 + * to platforms without floating point.
  553 + */
  554 +int multipliers[] = {
  555 + 0, /* reserved */
  556 + 10,
  557 + 12,
  558 + 13,
  559 + 15,
  560 + 20,
  561 + 25,
  562 + 30,
  563 + 35,
  564 + 40,
  565 + 45,
  566 + 50,
  567 + 55,
  568 + 60,
  569 + 70,
  570 + 80,
  571 +};
  572 +
  573 +void mmc_set_ios(struct mmc *mmc)
  574 +{
  575 + mmc->set_ios(mmc);
  576 +}
  577 +
  578 +void mmc_set_clock(struct mmc *mmc, uint clock)
  579 +{
  580 + if (clock > mmc->f_max)
  581 + clock = mmc->f_max;
  582 +
  583 + if (clock < mmc->f_min)
  584 + clock = mmc->f_min;
  585 +
  586 + mmc->clock = clock;
  587 +
  588 + mmc_set_ios(mmc);
  589 +}
  590 +
  591 +void mmc_set_bus_width(struct mmc *mmc, uint width)
  592 +{
  593 + mmc->bus_width = width;
  594 +
  595 + mmc_set_ios(mmc);
  596 +}
  597 +
  598 +int mmc_startup(struct mmc *mmc)
  599 +{
  600 + int err;
  601 + uint mult, freq;
  602 + u64 cmult, csize;
  603 + struct mmc_cmd cmd;
  604 +
  605 + /* Put the Card in Identify Mode */
  606 + cmd.cmdidx = MMC_CMD_ALL_SEND_CID;
  607 + cmd.resp_type = MMC_RSP_R2;
  608 + cmd.cmdarg = 0;
  609 + cmd.flags = 0;
  610 +
  611 + err = mmc_send_cmd(mmc, &cmd, NULL);
  612 +
  613 + if (err)
  614 + return err;
  615 +
  616 + memcpy(mmc->cid, cmd.response, 16);
  617 +
  618 + /*
  619 + * For MMC cards, set the Relative Address.
  620 + * For SD cards, get the Relatvie Address.
  621 + * This also puts the cards into Standby State
  622 + */
  623 + cmd.cmdidx = SD_CMD_SEND_RELATIVE_ADDR;
  624 + cmd.cmdarg = mmc->rca << 16;
  625 + cmd.resp_type = MMC_RSP_R6;
  626 + cmd.flags = 0;
  627 +
  628 + err = mmc_send_cmd(mmc, &cmd, NULL);
  629 +
  630 + if (err)
  631 + return err;
  632 +
  633 + if (IS_SD(mmc))
  634 + mmc->rca = (((uint *)(cmd.response))[0] >> 16) & 0xffff;
  635 +
  636 + /* Get the Card-Specific Data */
  637 + cmd.cmdidx = MMC_CMD_SEND_CSD;
  638 + cmd.resp_type = MMC_RSP_R2;
  639 + cmd.cmdarg = mmc->rca << 16;
  640 + cmd.flags = 0;
  641 +
  642 + err = mmc_send_cmd(mmc, &cmd, NULL);
  643 +
  644 + if (err)
  645 + return err;
  646 +
  647 + mmc->csd[0] = ((uint *)(cmd.response))[0];
  648 + mmc->csd[1] = ((uint *)(cmd.response))[1];
  649 + mmc->csd[2] = ((uint *)(cmd.response))[2];
  650 + mmc->csd[3] = ((uint *)(cmd.response))[3];
  651 +
  652 + if (mmc->version == MMC_VERSION_UNKNOWN) {
  653 + int version = (cmd.response[0] >> 2) & 0xf;
  654 +
  655 + switch (version) {
  656 + case 0:
  657 + mmc->version = MMC_VERSION_1_2;
  658 + break;
  659 + case 1:
  660 + mmc->version = MMC_VERSION_1_4;
  661 + break;
  662 + case 2:
  663 + mmc->version = MMC_VERSION_2_2;
  664 + break;
  665 + case 3:
  666 + mmc->version = MMC_VERSION_3;
  667 + break;
  668 + case 4:
  669 + mmc->version = MMC_VERSION_4;
  670 + break;
  671 + default:
  672 + mmc->version = MMC_VERSION_1_2;
  673 + break;
  674 + }
  675 + }
  676 +
  677 + /* divide frequency by 10, since the mults are 10x bigger */
  678 + freq = fbase[(cmd.response[3] & 0x7)];
  679 + mult = multipliers[((cmd.response[3] >> 3) & 0xf)];
  680 +
  681 + mmc->tran_speed = freq * mult;
  682 +
  683 + mmc->read_bl_len = 1 << ((((uint *)(cmd.response))[1] >> 16) & 0xf);
  684 +
  685 + if (IS_SD(mmc))
  686 + mmc->write_bl_len = mmc->read_bl_len;
  687 + else
  688 + mmc->write_bl_len = 1 << ((((uint *)(cmd.response))[3] >> 22) & 0xf);
  689 +
  690 + if (mmc->high_capacity) {
  691 + csize = (mmc->csd[1] & 0x3f) << 16
  692 + | (mmc->csd[2] & 0xffff0000) >> 16;
  693 + cmult = 8;
  694 + } else {
  695 + csize = (mmc->csd[1] & 0x3ff) << 2
  696 + | (mmc->csd[2] & 0xc0000000) >> 30;
  697 + cmult = (mmc->csd[2] & 0x00038000) >> 15;
  698 + }
  699 +
  700 + mmc->capacity = (csize + 1) << (cmult + 2);
  701 + mmc->capacity *= mmc->read_bl_len;
  702 +
  703 + if (mmc->read_bl_len > 512)
  704 + mmc->read_bl_len = 512;
  705 +
  706 + if (mmc->write_bl_len > 512)
  707 + mmc->write_bl_len = 512;
  708 +
  709 + /* Select the card, and put it into Transfer Mode */
  710 + cmd.cmdidx = MMC_CMD_SELECT_CARD;
  711 + cmd.resp_type = MMC_RSP_R1b;
  712 + cmd.cmdarg = mmc->rca << 16;
  713 + cmd.flags = 0;
  714 + err = mmc_send_cmd(mmc, &cmd, NULL);
  715 +
  716 + if (err)
  717 + return err;
  718 +
  719 + if (IS_SD(mmc))
  720 + err = sd_change_freq(mmc);
  721 + else
  722 + err = mmc_change_freq(mmc);
  723 +
  724 + if (err)
  725 + return err;
  726 +
  727 + /* Restrict card's capabilities by what the host can do */
  728 + mmc->card_caps &= mmc->host_caps;
  729 +
  730 + if (IS_SD(mmc)) {
  731 + if (mmc->card_caps & MMC_MODE_4BIT) {
  732 + cmd.cmdidx = MMC_CMD_APP_CMD;
  733 + cmd.resp_type = MMC_RSP_R1;
  734 + cmd.cmdarg = mmc->rca << 16;
  735 + cmd.flags = 0;
  736 +
  737 + err = mmc_send_cmd(mmc, &cmd, NULL);
  738 + if (err)
  739 + return err;
  740 +
  741 + cmd.cmdidx = SD_CMD_APP_SET_BUS_WIDTH;
  742 + cmd.resp_type = MMC_RSP_R1;
  743 + cmd.cmdarg = 2;
  744 + cmd.flags = 0;
  745 + err = mmc_send_cmd(mmc, &cmd, NULL);
  746 + if (err)
  747 + return err;
  748 +
  749 + mmc_set_bus_width(mmc, 4);
  750 + }
  751 +
  752 + if (mmc->card_caps & MMC_MODE_HS)
  753 + mmc_set_clock(mmc, 50000000);
  754 + else
  755 + mmc_set_clock(mmc, 25000000);
  756 + } else {
  757 + if (mmc->card_caps & MMC_MODE_4BIT) {
  758 + /* Set the card to use 4 bit*/
  759 + err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
  760 + EXT_CSD_BUS_WIDTH,
  761 + EXT_CSD_BUS_WIDTH_4);
  762 +
  763 + if (err)
  764 + return err;
  765 +
  766 + mmc_set_bus_width(mmc, 4);
  767 + } else if (mmc->card_caps & MMC_MODE_8BIT) {
  768 + /* Set the card to use 8 bit*/
  769 + err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
  770 + EXT_CSD_BUS_WIDTH,
  771 + EXT_CSD_BUS_WIDTH_8);
  772 +
  773 + if (err)
  774 + return err;
  775 +
  776 + mmc_set_bus_width(mmc, 8);
  777 + }
  778 +
  779 + if (mmc->card_caps & MMC_MODE_HS) {
  780 + if (mmc->card_caps & MMC_MODE_HS_52MHz)
  781 + mmc_set_clock(mmc, 52000000);
  782 + else
  783 + mmc_set_clock(mmc, 26000000);
  784 + } else
  785 + mmc_set_clock(mmc, 20000000);
  786 + }
  787 +
  788 + /* fill in device description */
  789 + mmc->block_dev.lun = 0;
  790 + mmc->block_dev.type = 0;
  791 + mmc->block_dev.blksz = mmc->read_bl_len;
  792 + mmc->block_dev.lba = mmc->capacity/mmc->read_bl_len;
  793 + sprintf(mmc->block_dev.vendor,"Man %02x%02x%02x Snr %02x%02x%02x%02x",
  794 + mmc->cid[0], mmc->cid[1], mmc->cid[2],
  795 + mmc->cid[9], mmc->cid[10], mmc->cid[11], mmc->cid[12]);
  796 + sprintf(mmc->block_dev.product,"%c%c%c%c%c", mmc->cid[3],
  797 + mmc->cid[4], mmc->cid[5], mmc->cid[6], mmc->cid[7]);
  798 + sprintf(mmc->block_dev.revision,"%d.%d", mmc->cid[8] >> 4,
  799 + mmc->cid[8] & 0xf);
  800 + init_part(&mmc->block_dev);
  801 +
  802 + return 0;
  803 +}
  804 +
  805 +int mmc_send_if_cond(struct mmc *mmc)
  806 +{
  807 + struct mmc_cmd cmd;
  808 + int err;
  809 +
  810 + cmd.cmdidx = SD_CMD_SEND_IF_COND;
  811 + /* We set the bit if the host supports voltages between 2.7 and 3.6 V */
  812 + cmd.cmdarg = ((mmc->voltages & 0xff8000) != 0) << 8 | 0xaa;
  813 + cmd.resp_type = MMC_RSP_R7;
  814 + cmd.flags = 0;
  815 +
  816 + err = mmc_send_cmd(mmc, &cmd, NULL);
  817 +
  818 + if (err)
  819 + return err;
  820 +
  821 + if ((((uint *)(cmd.response))[0] & 0xff) != 0xaa)
  822 + return UNUSABLE_ERR;
  823 + else
  824 + mmc->version = SD_VERSION_2;
  825 +
  826 + return 0;
  827 +}
  828 +
  829 +int mmc_register(struct mmc *mmc)
  830 +{
  831 + /* Setup the universal parts of the block interface just once */
  832 + mmc->block_dev.if_type = IF_TYPE_MMC;
  833 + mmc->block_dev.dev = cur_dev_num++;
  834 + mmc->block_dev.removable = 1;
  835 + mmc->block_dev.block_read = mmc_bread;
  836 + mmc->block_dev.block_write = mmc_bwrite;
  837 +
  838 + INIT_LIST_HEAD (&mmc->link);
  839 +
  840 + list_add_tail (&mmc->link, &mmc_devices);
  841 +
  842 + return 0;
  843 +}
  844 +
  845 +block_dev_desc_t *mmc_get_dev(int dev)
  846 +{
  847 + struct mmc *mmc = find_mmc_device(dev);
  848 +
  849 + return &mmc->block_dev;
  850 +}
  851 +
  852 +int mmc_init(struct mmc *mmc)
  853 +{
  854 + int err;
  855 +
  856 + err = mmc->init(mmc);
  857 +
  858 + if (err)
  859 + return err;
  860 +
  861 + /* Reset the Card */
  862 + err = mmc_go_idle(mmc);
  863 +
  864 + if (err)
  865 + return err;
  866 +
  867 + /* Test for SD version 2 */
  868 + err = mmc_send_if_cond(mmc);
  869 +
  870 + /* If we got an error other than timeout, we bail */
  871 + if (err && err != TIMEOUT)
  872 + return err;
  873 +
  874 + /* Now try to get the SD card's operating condition */
  875 + err = sd_send_op_cond(mmc);
  876 +
  877 + /* If the command timed out, we check for an MMC card */
  878 + if (err == TIMEOUT) {
  879 + err = mmc_send_op_cond(mmc);
  880 +
  881 + if (err) {
  882 + printf("Card did not respond to voltage select!\n");
  883 + return UNUSABLE_ERR;
  884 + }
  885 + }
  886 +
  887 + return mmc_startup(mmc);
  888 +}
  889 +
  890 +/*
  891 + * CPU and board-specific MMC initializations. Aliased function
  892 + * signals caller to move on
  893 + */
  894 +static int __def_mmc_init(bd_t *bis)
  895 +{
  896 + return -1;
  897 +}
  898 +
  899 +int cpu_mmc_init(bd_t *bis) __attribute((weak, alias("__def_mmc_init")));
  900 +int board_mmc_init(bd_t *bis) __attribute((weak, alias("__def_mmc_init")));
  901 +
  902 +void print_mmc_devices(char separator)
  903 +{
  904 + struct mmc *m;
  905 + struct list_head *entry;
  906 +
  907 + list_for_each(entry, &mmc_devices) {
  908 + m = list_entry(entry, struct mmc, link);
  909 +
  910 + printf("%s: %d", m->name, m->block_dev.dev);
  911 +
  912 + if (entry->next != &mmc_devices)
  913 + printf("%c ", separator);
  914 + }
  915 +
  916 + printf("\n");
  917 +}
  918 +
  919 +int mmc_initialize(bd_t *bis)
  920 +{
  921 + INIT_LIST_HEAD (&mmc_devices);
  922 + cur_dev_num = 0;
  923 +
  924 + if (board_mmc_init(bis) < 0)
  925 + cpu_mmc_init(bis);
  926 +
  927 + print_mmc_devices(',');
  928 +
  929 + return 0;
  930 +}
1 1 /*
2   - * (C) Copyright 2000-2003
3   - * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  2 + * Copyright 2008, Freescale Semiconductor, Inc
  3 + * Andy Fleming
4 4 *
  5 + * Based (loosely) on the Linux code
  6 + *
5 7 * See file CREDITS for list of people who contributed to this
6 8 * project.
7 9 *
8 10  
9 11  
10 12  
11 13  
12 14  
13 15  
14 16  
15 17  
16 18  
17 19  
... ... @@ -24,37 +26,150 @@
24 26 #ifndef _MMC_H_
25 27 #define _MMC_H_
26 28  
27   -/* MMC command numbers */
  29 +#include <linux/list.h>
  30 +
  31 +#define SD_VERSION_SD 0x20000
  32 +#define SD_VERSION_2 (SD_VERSION_SD | 0x20)
  33 +#define SD_VERSION_1_0 (SD_VERSION_SD | 0x10)
  34 +#define SD_VERSION_1_10 (SD_VERSION_SD | 0x1a)
  35 +#define MMC_VERSION_MMC 0x10000
  36 +#define MMC_VERSION_UNKNOWN (MMC_VERSION_MMC)
  37 +#define MMC_VERSION_1_2 (MMC_VERSION_MMC | 0x12)
  38 +#define MMC_VERSION_1_4 (MMC_VERSION_MMC | 0x14)
  39 +#define MMC_VERSION_2_2 (MMC_VERSION_MMC | 0x22)
  40 +#define MMC_VERSION_3 (MMC_VERSION_MMC | 0x30)
  41 +#define MMC_VERSION_4 (MMC_VERSION_MMC | 0x40)
  42 +
  43 +#define MMC_MODE_HS 0x001
  44 +#define MMC_MODE_HS_52MHz 0x010
  45 +#define MMC_MODE_4BIT 0x100
  46 +#define MMC_MODE_8BIT 0x200
  47 +
  48 +#define SD_DATA_4BIT 0x00040000
  49 +
  50 +#define IS_SD(x) (mmc->version & SD_VERSION_SD)
  51 +
  52 +#define MMC_DATA_READ 1
  53 +#define MMC_DATA_WRITE 2
  54 +
  55 +#define NO_CARD_ERR -16 /* No SD/MMC card inserted */
  56 +#define UNUSABLE_ERR -17 /* Unusable Card */
  57 +#define COMM_ERR -18 /* Communications Error */
  58 +#define TIMEOUT -19
  59 +
28 60 #define MMC_CMD_GO_IDLE_STATE 0
29 61 #define MMC_CMD_SEND_OP_COND 1
30 62 #define MMC_CMD_ALL_SEND_CID 2
31 63 #define MMC_CMD_SET_RELATIVE_ADDR 3
32 64 #define MMC_CMD_SET_DSR 4
  65 +#define MMC_CMD_SWITCH 6
33 66 #define MMC_CMD_SELECT_CARD 7
  67 +#define MMC_CMD_SEND_EXT_CSD 8
34 68 #define MMC_CMD_SEND_CSD 9
35 69 #define MMC_CMD_SEND_CID 10
  70 +#define MMC_CMD_STOP_TRANSMISSION 12
36 71 #define MMC_CMD_SEND_STATUS 13
37 72 #define MMC_CMD_SET_BLOCKLEN 16
38 73 #define MMC_CMD_READ_SINGLE_BLOCK 17
39 74 #define MMC_CMD_READ_MULTIPLE_BLOCK 18
40   -#define MMC_CMD_WRITE_BLOCK 24
  75 +#define MMC_CMD_WRITE_SINGLE_BLOCK 24
  76 +#define MMC_CMD_WRITE_MULTIPLE_BLOCK 25
41 77 #define MMC_CMD_APP_CMD 55
42 78  
43   -/* SD Card command numbers */
44 79 #define SD_CMD_SEND_RELATIVE_ADDR 3
45   -#define SD_CMD_SWITCH 6
  80 +#define SD_CMD_SWITCH_FUNC 6
46 81 #define SD_CMD_SEND_IF_COND 8
47 82  
48 83 #define SD_CMD_APP_SET_BUS_WIDTH 6
49 84 #define SD_CMD_APP_SEND_OP_COND 41
  85 +#define SD_CMD_APP_SEND_SCR 51
50 86  
  87 +/* SCR definitions in different words */
  88 +#define SD_HIGHSPEED_BUSY 0x00020000
  89 +#define SD_HIGHSPEED_SUPPORTED 0x00020000
  90 +
  91 +#define MMC_HS_TIMING 0x00000100
  92 +#define MMC_HS_52MHZ 0x2
  93 +
  94 +#define OCR_BUSY 0x80
  95 +#define OCR_HCS 0x40000000
  96 +
  97 +#define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
  98 +#define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */
  99 +#define MMC_VDD_21_22 0x00000200 /* VDD voltage 2.1 ~ 2.2 */
  100 +#define MMC_VDD_22_23 0x00000400 /* VDD voltage 2.2 ~ 2.3 */
  101 +#define MMC_VDD_23_24 0x00000800 /* VDD voltage 2.3 ~ 2.4 */
  102 +#define MMC_VDD_24_25 0x00001000 /* VDD voltage 2.4 ~ 2.5 */
  103 +#define MMC_VDD_25_26 0x00002000 /* VDD voltage 2.5 ~ 2.6 */
  104 +#define MMC_VDD_26_27 0x00004000 /* VDD voltage 2.6 ~ 2.7 */
  105 +#define MMC_VDD_27_28 0x00008000 /* VDD voltage 2.7 ~ 2.8 */
  106 +#define MMC_VDD_28_29 0x00010000 /* VDD voltage 2.8 ~ 2.9 */
  107 +#define MMC_VDD_29_30 0x00020000 /* VDD voltage 2.9 ~ 3.0 */
  108 +#define MMC_VDD_30_31 0x00040000 /* VDD voltage 3.0 ~ 3.1 */
  109 +#define MMC_VDD_31_32 0x00080000 /* VDD voltage 3.1 ~ 3.2 */
  110 +#define MMC_VDD_32_33 0x00100000 /* VDD voltage 3.2 ~ 3.3 */
  111 +#define MMC_VDD_33_34 0x00200000 /* VDD voltage 3.3 ~ 3.4 */
  112 +#define MMC_VDD_34_35 0x00400000 /* VDD voltage 3.4 ~ 3.5 */
  113 +#define MMC_VDD_35_36 0x00800000 /* VDD voltage 3.5 ~ 3.6 */
  114 +
  115 +#define MMC_SWITCH_MODE_CMD_SET 0x00 /* Change the command set */
  116 +#define MMC_SWITCH_MODE_SET_BITS 0x01 /* Set bits in EXT_CSD byte
  117 + addressed by index which are
  118 + 1 in value field */
  119 +#define MMC_SWITCH_MODE_CLEAR_BITS 0x02 /* Clear bits in EXT_CSD byte
  120 + addressed by index, which are
  121 + 1 in value field */
  122 +#define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target byte to value */
  123 +
  124 +#define SD_SWITCH_CHECK 0
  125 +#define SD_SWITCH_SWITCH 1
  126 +
  127 +/*
  128 + * EXT_CSD fields
  129 + */
  130 +
  131 +#define EXT_CSD_BUS_WIDTH 183 /* R/W */
  132 +#define EXT_CSD_HS_TIMING 185 /* R/W */
  133 +#define EXT_CSD_CARD_TYPE 196 /* RO */
  134 +#define EXT_CSD_REV 192 /* RO */
  135 +#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
  136 +
  137 +/*
  138 + * EXT_CSD field definitions
  139 + */
  140 +
  141 +#define EXT_CSD_CMD_SET_NORMAL (1<<0)
  142 +#define EXT_CSD_CMD_SET_SECURE (1<<1)
  143 +#define EXT_CSD_CMD_SET_CPSECURE (1<<2)
  144 +
  145 +#define EXT_CSD_CARD_TYPE_26 (1<<0) /* Card can run at 26MHz */
  146 +#define EXT_CSD_CARD_TYPE_52 (1<<1) /* Card can run at 52MHz */
  147 +
  148 +#define EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */
  149 +#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
  150 +#define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */
  151 +
51 152 #define R1_ILLEGAL_COMMAND (1 << 22)
52 153 #define R1_APP_CMD (1 << 5)
53 154  
54   -int mmc_legacy_init(int verbose);
55   -int mmc_read(ulong src, uchar *dst, int size);
56   -int mmc_write(uchar *src, ulong dst, int size);
  155 +#define MMC_RSP_PRESENT (1 << 0)
  156 +#define MMC_RSP_136 (1 << 1) /* 136 bit response */
  157 +#define MMC_RSP_CRC (1 << 2) /* expect valid crc */
  158 +#define MMC_RSP_BUSY (1 << 3) /* card may send busy */
  159 +#define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
57 160  
  161 +#define MMC_RSP_NONE (0)
  162 +#define MMC_RSP_R1 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  163 +#define MMC_RSP_R1b (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE| \
  164 + MMC_RSP_BUSY)
  165 +#define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
  166 +#define MMC_RSP_R3 (MMC_RSP_PRESENT)
  167 +#define MMC_RSP_R4 (MMC_RSP_PRESENT)
  168 +#define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  169 +#define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  170 +#define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  171 +
  172 +
58 173 struct mmc_cid {
59 174 unsigned long psn;
60 175 unsigned short oid;
... ... @@ -104,5 +219,62 @@
104 219 u8 one:1;
105 220 };
106 221  
  222 +struct mmc_cmd {
  223 + ushort cmdidx;
  224 + uint resp_type;
  225 + uint cmdarg;
  226 + char response[18];
  227 + uint flags;
  228 +};
  229 +
  230 +struct mmc_data {
  231 + union {
  232 + char *dest;
  233 + const char *src; /* src buffers don't get written to */
  234 + };
  235 + uint flags;
  236 + uint blocks;
  237 + uint blocksize;
  238 +};
  239 +
  240 +struct mmc {
  241 + struct list_head link;
  242 + char name[32];
  243 + void *priv;
  244 + uint voltages;
  245 + uint version;
  246 + uint f_min;
  247 + uint f_max;
  248 + int high_capacity;
  249 + uint bus_width;
  250 + uint clock;
  251 + uint card_caps;
  252 + uint host_caps;
  253 + uint ocr;
  254 + uint scr[2];
  255 + uint csd[4];
  256 + char cid[16];
  257 + ushort rca;
  258 + uint tran_speed;
  259 + uint read_bl_len;
  260 + uint write_bl_len;
  261 + u64 capacity;
  262 + block_dev_desc_t block_dev;
  263 + int (*send_cmd)(struct mmc *mmc,
  264 + struct mmc_cmd *cmd, struct mmc_data *data);
  265 + void (*set_ios)(struct mmc *mmc);
  266 + int (*init)(struct mmc *mmc);
  267 +};
  268 +
  269 +int mmc_register(struct mmc *mmc);
  270 +int mmc_initialize(bd_t *bis);
  271 +int mmc_init(struct mmc *mmc);
  272 +int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size);
  273 +struct mmc *find_mmc_device(int dev_num);
  274 +void print_mmc_devices(char separator);
  275 +
  276 +#ifndef CONFIG_GENERIC_MMC
  277 +int mmc_legacy_init(int verbose);
  278 +#endif
107 279 #endif /* _MMC_H_ */
... ... @@ -48,6 +48,9 @@
48 48 #include <status_led.h>
49 49 #endif
50 50 #include <net.h>
  51 +#ifdef CONFIG_GENERIC_MMC
  52 +#include <mmc.h>
  53 +#endif
51 54 #include <serial.h>
52 55 #ifdef CONFIG_SYS_ALLOC_DPRAM
53 56 #if !defined(CONFIG_CPM2)
... ... @@ -1073,6 +1076,12 @@
1073 1076 WATCHDOG_RESET ();
1074 1077 puts ("SCSI: ");
1075 1078 scsi_init ();
  1079 +#endif
  1080 +
  1081 +#ifdef CONFIG_GENERIC_MMC
  1082 + WATCHDOG_RESET ();
  1083 + puts ("MMC: ");
  1084 + mmc_initialize (bd);
1076 1085 #endif
1077 1086  
1078 1087 #if defined(CONFIG_CMD_DOC)