Commit f0d1246ed7cb5a88522244c596d7ae7e6f161283

Authored by Haavard Skinnemoen
1 parent 448f5fea4c

atmel_mci: Use 512 byte blocksize if possible

Instead of always using the largest blocksize the card supports, check
if it can support smaller block sizes and use 512 bytes if possible.
Most cards do support this, and other parts of u-boot seem to have
trouble with block sizes different from 512 bytes.

Also enable underrun/overrun protection.

Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Acked-by: Hans-Christian Egtvedt <hcegtvedt@atmel.com>

Showing 2 changed files with 21 additions and 4 deletions Side-by-side Diff

cpu/at32ap/atmel_mci.c
... ... @@ -82,7 +82,9 @@
82 82  
83 83 blklen &= 0xfffc;
84 84 mmci_writel(MR, (MMCI_BF(CLKDIV, clkdiv)
85   - | MMCI_BF(BLKLEN, blklen)));
  85 + | MMCI_BF(BLKLEN, blklen)
  86 + | MMCI_BIT(RDPROOF)
  87 + | MMCI_BIT(WRPROOF)));
86 88 }
87 89  
88 90 #define RESP_NO_CRC 1
... ... @@ -225,7 +227,7 @@
225 227 *buffer++ = data;
226 228 wordcount++;
227 229 }
228   - } while(wordcount < (512 / 4));
  230 + } while(wordcount < (mmc_blkdev.blksz / 4));
229 231  
230 232 pr_debug("mmc: read %u words, waiting for BLKE\n", wordcount);
231 233  
... ... @@ -243,7 +245,7 @@
243 245  
244 246 fail:
245 247 mmc_cmd(MMC_CMD_SEND_STATUS, mmc_rca << 16, &card_status, R1 | NCR);
246   - printf("mmc: bread failed, card status = ", card_status);
  248 + printf("mmc: bread failed, card status = %08x\n", card_status);
247 249 goto out;
248 250 }
249 251  
... ... @@ -409,6 +411,7 @@
409 411 {
410 412 struct mmc_cid cid;
411 413 struct mmc_csd csd;
  414 + unsigned int max_blksz;
412 415 int ret;
413 416  
414 417 /* Initialize controller */
... ... @@ -444,7 +447,17 @@
444 447 sizeof(mmc_blkdev.product));
445 448 sprintf((char *)mmc_blkdev.revision, "%x %x",
446 449 cid.prv >> 4, cid.prv & 0x0f);
447   - mmc_blkdev.blksz = 1 << csd.read_bl_len;
  450 +
  451 + /*
  452 + * If we can't use 512 byte blocks, refuse to deal with the
  453 + * card. Tons of code elsewhere seems to depend on this.
  454 + */
  455 + max_blksz = 1 << csd.read_bl_len;
  456 + if (max_blksz < 512 || (max_blksz > 512 && !csd.read_bl_partial)) {
  457 + printf("Card does not support 512 byte reads, aborting.\n");
  458 + return -ENODEV;
  459 + }
  460 + mmc_blkdev.blksz = 512;
448 461 mmc_blkdev.lba = (csd.c_size + 1) * (1 << (csd.c_size_mult + 2));
449 462  
450 463 mci_set_mode(CFG_MMC_CLK_PP, mmc_blkdev.blksz);
cpu/at32ap/atmel_mci.h
... ... @@ -57,6 +57,10 @@
57 57 #define MMCI_CLKDIV_SIZE 8
58 58 #define MMCI_PWSDIV_OFFSET 8
59 59 #define MMCI_PWSDIV_SIZE 3
  60 +#define MMCI_RDPROOF_OFFSET 11
  61 +#define MMCI_RDPROOF_SIZE 1
  62 +#define MMCI_WRPROOF_OFFSET 12
  63 +#define MMCI_WRPROOF_SIZE 1
60 64 #define MMCI_PDCPADV_OFFSET 14
61 65 #define MMCI_PDCPADV_SIZE 1
62 66 #define MMCI_PDCMODE_OFFSET 15