MLK-16188-1 mmc: add mmc_send_tuning function
authorPeng Fan <peng.fan@nxp.com>
Sat, 12 Aug 2017 05:00:10 +0000 (13:00 +0800)
committerJason Liu <jason.hui.liu@nxp.com>
Thu, 2 Nov 2017 18:37:12 +0000 (02:37 +0800)
Add mmc_send_tuning function. tuning_blk_patter imported from Linux Kernel.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/mmc/mmc.c
include/mmc.h

index 49edf52..daf128a 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright 2008, Freescale Semiconductor, Inc
  * Andy Fleming
+ * Copyright 2017 NXP
  *
  * Based vaguely on the Linux code
  *
@@ -293,6 +294,75 @@ int mmc_set_blocklen(struct mmc *mmc, int len)
        return err;
 }
 
+static const u8 tuning_blk_pattern_4bit[] = {
+       0xff, 0x0f, 0xff, 0x00, 0xff, 0xcc, 0xc3, 0xcc,
+       0xc3, 0x3c, 0xcc, 0xff, 0xfe, 0xff, 0xfe, 0xef,
+       0xff, 0xdf, 0xff, 0xdd, 0xff, 0xfb, 0xff, 0xfb,
+       0xbf, 0xff, 0x7f, 0xff, 0x77, 0xf7, 0xbd, 0xef,
+       0xff, 0xf0, 0xff, 0xf0, 0x0f, 0xfc, 0xcc, 0x3c,
+       0xcc, 0x33, 0xcc, 0xcf, 0xff, 0xef, 0xff, 0xee,
+       0xff, 0xfd, 0xff, 0xfd, 0xdf, 0xff, 0xbf, 0xff,
+       0xbb, 0xff, 0xf7, 0xff, 0xf7, 0x7f, 0x7b, 0xde,
+};
+
+static const u8 tuning_blk_pattern_8bit[] = {
+       0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
+       0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc, 0xcc,
+       0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff, 0xff,
+       0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, 0xff,
+       0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd, 0xdd,
+       0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb,
+       0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff, 0xff,
+       0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, 0xff,
+       0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
+       0x00, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc,
+       0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff,
+       0xff, 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee,
+       0xff, 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd,
+       0xdd, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff,
+       0xbb, 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff,
+       0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee,
+};
+
+int mmc_send_tuning(struct mmc *mmc, u32 opcode, int *cmd_error)
+{
+       struct mmc_cmd cmd;
+       struct mmc_data data;
+       const u8 *tuning_block_pattern;
+       int size, err;
+
+       if (mmc->bus_width == 8) {
+               tuning_block_pattern = tuning_blk_pattern_8bit;
+               size = sizeof(tuning_blk_pattern_8bit);
+       } else if (mmc->bus_width == 4) {
+               tuning_block_pattern = tuning_blk_pattern_4bit;
+               size = sizeof(tuning_blk_pattern_4bit);
+       } else {
+               return -EINVAL;
+       }
+
+       ALLOC_CACHE_ALIGN_BUFFER(u8, data_buf, size);
+
+       cmd.cmdidx = opcode;
+       cmd.cmdarg = 0;
+       cmd.resp_type = MMC_RSP_R1;
+
+       data.dest = (void *)data_buf;
+       data.blocks = 1;
+       data.blocksize = size;
+       data.flags = MMC_DATA_READ;
+
+       err = mmc_send_cmd(mmc, &cmd, &data);
+       if (err)
+               return err;
+
+       if (memcmp(data_buf, tuning_block_pattern, size))
+               return -EIO;
+
+       return 0;
+}
+
+
 static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
                           lbaint_t blkcnt)
 {
index 4dd42c4..7336498 100644 (file)
@@ -623,6 +623,7 @@ void mmc_destroy(struct mmc *mmc);
 int mmc_unbind(struct udevice *dev);
 int mmc_initialize(bd_t *bis);
 int mmc_init(struct mmc *mmc);
+int mmc_send_tuning(struct mmc *mmc, u32 opcode, int *cmd_error);
 int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size);
 int mmc_set_clock(struct mmc *mmc, uint clock, u8 disable);
 struct mmc *find_mmc_device(int dev_num);