diff options
Diffstat (limited to 'drivers/mmc')
| -rw-r--r-- | drivers/mmc/fsl_esdhc.c | 9 | ||||
| -rw-r--r-- | drivers/mmc/mmc.c | 93 | ||||
| -rw-r--r-- | drivers/mmc/sdhci.c | 6 | 
3 files changed, 83 insertions, 25 deletions
| diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c index 861f4b9d6..973b19f33 100644 --- a/drivers/mmc/fsl_esdhc.c +++ b/drivers/mmc/fsl_esdhc.c @@ -178,7 +178,7 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)  	int timeout;  	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;  	struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base; -#ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO +#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO  	uint wml_value;  	wml_value = data->blocksize/4; @@ -310,6 +310,9 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)  	/* Figure out the transfer arguments */  	xfertyp = esdhc_xfertyp(cmd, data); +	/* Mask all irqs */ +	esdhc_write32(®s->irqsigen, 0); +  	/* Send the command */  	esdhc_write32(®s->cmdarg, cmd->cmdarg);  #if defined(CONFIG_FSL_USDHC) @@ -320,15 +323,11 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)  	esdhc_write32(®s->xfertyp, xfertyp);  #endif -	/* Mask all irqs */ -	esdhc_write32(®s->irqsigen, 0); -  	/* Wait for the command to complete */  	while (!(esdhc_read32(®s->irqstat) & (IRQSTAT_CC | IRQSTAT_CTOE)))  		;  	irqstat = esdhc_read32(®s->irqstat); -	esdhc_write32(®s->irqstat, irqstat);  	/* Reset CMD and DATA portions on error */  	if (irqstat & (CMD_ERR | IRQSTAT_CTOE)) { diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index a492bbb41..73f719579 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -254,7 +254,7 @@ err_out:  }  static unsigned long -mmc_berase(int dev_num, unsigned long start, lbaint_t blkcnt) +mmc_berase(int dev_num, lbaint_t start, lbaint_t blkcnt)  {  	int err = 0;  	struct mmc *mmc = find_mmc_device(dev_num); @@ -266,7 +266,8 @@ mmc_berase(int dev_num, unsigned long start, lbaint_t blkcnt)  	if ((start % mmc->erase_grp_size) || (blkcnt % mmc->erase_grp_size))  		printf("\n\nCaution! Your devices Erase group is 0x%x\n" -			"The erase range would be change to 0x%lx~0x%lx\n\n", +		       "The erase range would be change to " +		       "0x" LBAF "~0x" LBAF "\n\n",  		       mmc->erase_grp_size, start & ~(mmc->erase_grp_size - 1),  		       ((start + blkcnt + mmc->erase_grp_size)  		       & ~(mmc->erase_grp_size - 1)) - 1); @@ -289,22 +290,24 @@ mmc_berase(int dev_num, unsigned long start, lbaint_t blkcnt)  }  static ulong -mmc_write_blocks(struct mmc *mmc, ulong start, lbaint_t blkcnt, const void*src) +mmc_write_blocks(struct mmc *mmc, lbaint_t start, lbaint_t blkcnt, const void*src)  {  	struct mmc_cmd cmd;  	struct mmc_data data;  	int timeout = 1000;  	if ((start + blkcnt) > mmc->block_dev.lba) { -		printf("MMC: block number 0x%lx exceeds max(0x%lx)\n", +		printf("MMC: block number 0x" LBAF " exceeds max(0x" LBAF ")\n",  			start + blkcnt, mmc->block_dev.lba);  		return 0;  	} -	if (blkcnt > 1) -		cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK; -	else +	if (blkcnt == 0) +		return 0; +	else if (blkcnt == 1)  		cmd.cmdidx = MMC_CMD_WRITE_SINGLE_BLOCK; +	else +		cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK;  	if (mmc->high_capacity)  		cmd.cmdarg = start; @@ -344,7 +347,7 @@ mmc_write_blocks(struct mmc *mmc, ulong start, lbaint_t blkcnt, const void*src)  }  static ulong -mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src) +mmc_bwrite(int dev_num, lbaint_t start, lbaint_t blkcnt, const void*src)  {  	lbaint_t cur, blocks_todo = blkcnt; @@ -367,7 +370,7 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)  	return blkcnt;  } -static int mmc_read_blocks(struct mmc *mmc, void *dst, ulong start, +static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,  			   lbaint_t blkcnt)  {  	struct mmc_cmd cmd; @@ -406,7 +409,7 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, ulong start,  	return blkcnt;  } -static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst) +static ulong mmc_bread(int dev_num, lbaint_t start, lbaint_t blkcnt, void *dst)  {  	lbaint_t cur, blocks_todo = blkcnt; @@ -418,7 +421,7 @@ static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst)  		return 0;  	if ((start + blkcnt) > mmc->block_dev.lba) { -		printf("MMC: block number 0x%lx exceeds max(0x%lx)\n", +		printf("MMC: block number 0x" LBAF " exceeds max(0x" LBAF ")\n",  			start + blkcnt, mmc->block_dev.lba);  		return 0;  	} @@ -700,16 +703,49 @@ static int mmc_change_freq(struct mmc *mmc)  	return 0;  } +static int mmc_set_capacity(struct mmc *mmc, int part_num) +{ +	switch (part_num) { +	case 0: +		mmc->capacity = mmc->capacity_user; +		break; +	case 1: +	case 2: +		mmc->capacity = mmc->capacity_boot; +		break; +	case 3: +		mmc->capacity = mmc->capacity_rpmb; +		break; +	case 4: +	case 5: +	case 6: +	case 7: +		mmc->capacity = mmc->capacity_gp[part_num - 4]; +		break; +	default: +		return -1; +	} + +	mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len); + +	return 0; +} +  int mmc_switch_part(int dev_num, unsigned int part_num)  {  	struct mmc *mmc = find_mmc_device(dev_num); +	int ret;  	if (!mmc)  		return -1; -	return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF, -			  (mmc->part_config & ~PART_ACCESS_MASK) -			  | (part_num & PART_ACCESS_MASK)); +	ret = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF, +			 (mmc->part_config & ~PART_ACCESS_MASK) +			 | (part_num & PART_ACCESS_MASK)); +	if (ret) +		return ret; + +	return mmc_set_capacity(mmc, part_num);  }  int mmc_getcd(struct mmc *mmc) @@ -917,7 +953,7 @@ static void mmc_set_bus_width(struct mmc *mmc, uint width)  static int mmc_startup(struct mmc *mmc)  { -	int err; +	int err, i;  	uint mult, freq;  	u64 cmult, csize, capacity;  	struct mmc_cmd cmd; @@ -1035,8 +1071,12 @@ static int mmc_startup(struct mmc *mmc)  		cmult = (mmc->csd[2] & 0x00038000) >> 15;  	} -	mmc->capacity = (csize + 1) << (cmult + 2); -	mmc->capacity *= mmc->read_bl_len; +	mmc->capacity_user = (csize + 1) << (cmult + 2); +	mmc->capacity_user *= mmc->read_bl_len; +	mmc->capacity_boot = 0; +	mmc->capacity_rpmb = 0; +	for (i = 0; i < 4; i++) +		mmc->capacity_gp[i] = 0;  	if (mmc->read_bl_len > MMC_MAX_BLOCK_LEN)  		mmc->read_bl_len = MMC_MAX_BLOCK_LEN; @@ -1075,7 +1115,7 @@ static int mmc_startup(struct mmc *mmc)  					| ext_csd[EXT_CSD_SEC_CNT + 3] << 24;  			capacity *= MMC_MAX_BLOCK_LEN;  			if ((capacity >> 20) > 2 * 1024) -				mmc->capacity = capacity; +				mmc->capacity_user = capacity;  		}  		switch (ext_csd[EXT_CSD_REV]) { @@ -1117,8 +1157,25 @@ static int mmc_startup(struct mmc *mmc)  		if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) ||  		    ext_csd[EXT_CSD_BOOT_MULT])  			mmc->part_config = ext_csd[EXT_CSD_PART_CONF]; + +		mmc->capacity_boot = ext_csd[EXT_CSD_BOOT_MULT] << 17; + +		mmc->capacity_rpmb = ext_csd[EXT_CSD_RPMB_MULT] << 17; + +		for (i = 0; i < 4; i++) { +			int idx = EXT_CSD_GP_SIZE_MULT + i * 3; +			mmc->capacity_gp[i] = (ext_csd[idx + 2] << 16) + +				(ext_csd[idx + 1] << 8) + ext_csd[idx]; +			mmc->capacity_gp[i] *= +				ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; +			mmc->capacity_gp[i] *= ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; +		}  	} +	err = mmc_set_capacity(mmc, mmc->part_num); +	if (err) +		return err; +  	if (IS_SD(mmc))  		err = sd_change_freq(mmc);  	else diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 1eaea04ad..c5631bff6 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -486,8 +486,10 @@ int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)  		mmc->voltages |= host->voltages;  	mmc->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT; -	if (caps & SDHCI_CAN_DO_8BIT) -		mmc->host_caps |= MMC_MODE_8BIT; +	if ((host->version & SDHCI_SPEC_VER_MASK) >= SDHCI_SPEC_300) { +		if (caps & SDHCI_CAN_DO_8BIT) +			mmc->host_caps |= MMC_MODE_8BIT; +	}  	if (host->host_caps)  		mmc->host_caps |= host->host_caps; |