From 7ef3b3d5e1679caca117f6640e2d07408a2edae1 Mon Sep 17 00:00:00 2001 From: xiaoyao Date: Wed, 24 May 2017 16:20:26 +0800 Subject: [PATCH] mmc: host: rk_sdmmc_ops: fix area access error Change-Id: Ibc0655d630e808d6daccbb4c0f76ffc2afa930a2 Signed-off-by: xiaoyao --- drivers/mmc/host/rk_sdmmc_ops.c | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) mode change 100755 => 100644 drivers/mmc/host/rk_sdmmc_ops.c diff --git a/drivers/mmc/host/rk_sdmmc_ops.c b/drivers/mmc/host/rk_sdmmc_ops.c old mode 100755 new mode 100644 index 8d8d01fa17b9..32b1aa437b03 --- a/drivers/mmc/host/rk_sdmmc_ops.c +++ b/drivers/mmc/host/rk_sdmmc_ops.c @@ -26,6 +26,28 @@ #define BLKSZ 512 struct mmc_card *this_card = NULL; +enum emmc_area_type { + MMC_DATA_AREA_MAIN, + MMC_DATA_AREA_BOOT1, + MMC_DATA_AREA_BOOT2, + MMC_DATA_AREA_RPMB, +}; + +static int rk_emmc_set_areatype(enum emmc_area_type areatype) +{ + int err; + u8 part_config; + + part_config = this_card->ext_csd.part_config; + part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; + part_config |= (u8)areatype; + err = mmc_switch(this_card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_PART_CONFIG, part_config, + this_card->ext_csd.part_time); + + return err; +} + /* * Fill in the mmc_request structure given a set of transfer parameters. */ @@ -108,6 +130,7 @@ static int rk_emmc_wait_busy(void) int rk_emmc_transfer(u8 *buffer, unsigned addr, unsigned blksz, int write) { int ret = 0; + enum emmc_area_type areatype; struct mmc_request mrq = {0}; struct mmc_command cmd = {0}; @@ -128,6 +151,17 @@ int rk_emmc_transfer(u8 *buffer, unsigned addr, unsigned blksz, int write) rk_emmc_prepare_mrq(&mrq, &sg, 1, addr, 1, blksz, write); mmc_claim_host(this_card->host); + + areatype = (enum emmc_area_type)this_card->ext_csd.part_config + & EXT_CSD_PART_CONFIG_ACC_MASK; + if (areatype != MMC_DATA_AREA_MAIN) { + ret = rk_emmc_set_areatype(MMC_DATA_AREA_MAIN); + if (ret) { + pr_err("rk_emmc_set_areatype error!.\n"); + goto exit; + } + } + mmc_wait_for_req(this_card->host, &mrq); if (cmd.error){ @@ -140,6 +174,13 @@ int rk_emmc_transfer(u8 *buffer, unsigned addr, unsigned blksz, int write) } ret = rk_emmc_wait_busy(); + + if (areatype != MMC_DATA_AREA_MAIN) { + ret = rk_emmc_set_areatype(areatype); + if (ret) + pr_err("rk_emmc_set_areatype error!.\n"); + } + exit: mmc_release_host(this_card->host); return ret; -- 2.34.1