diff options
| author | Tom Rini <trini@ti.com> | 2013-06-22 07:38:12 -0400 | 
|---|---|---|
| committer | Tom Rini <trini@ti.com> | 2013-06-22 07:38:12 -0400 | 
| commit | 348e47f766ac228fb02d1af562b2e9a4c69355db (patch) | |
| tree | 778ffb90bb670f45fa7a0dae78010c8128c4d84d /drivers/mmc | |
| parent | 5707233880090f785c33df32c04549ea1aeef61e (diff) | |
| parent | fbf87b1823dd5ebc2a384711ea2c677543019ece (diff) | |
| download | olio-uboot-2014.01-348e47f766ac228fb02d1af562b2e9a4c69355db.tar.xz olio-uboot-2014.01-348e47f766ac228fb02d1af562b2e9a4c69355db.zip | |
Merge branch 'master' of git://git.denx.de/u-boot-arm
Diffstat (limited to 'drivers/mmc')
| -rw-r--r-- | drivers/mmc/dw_mmc.c | 27 | ||||
| -rw-r--r-- | drivers/mmc/exynos_dw_mmc.c | 127 | ||||
| -rw-r--r-- | drivers/mmc/mmc.c | 134 | 
3 files changed, 265 insertions, 23 deletions
| diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index 4070d4ea5..5da20eda5 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -129,13 +129,13 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,  	unsigned int timeout = 100000;  	u32 retry = 10000;  	u32 mask, ctrl; +	ulong start = get_timer(0);  	while (dwmci_readl(host, DWMCI_STATUS) & DWMCI_BUSY) { -		if (timeout == 0) { +		if (get_timer(start) > timeout) {  			printf("Timeout on data busy\n");  			return TIMEOUT;  		} -		timeout--;  	}  	dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_ALL); @@ -143,7 +143,6 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,  	if (data)  		dwmci_prepare_data(host, data); -  	dwmci_writel(host, DWMCI_CMDARG, cmd->cmdarg);  	if (data) @@ -231,9 +230,8 @@ static int dwmci_setup_bus(struct dwmci_host *host, u32 freq)  	int timeout = 10000;  	unsigned long sclk; -	if (freq == host->clock) +	if ((freq == host->clock) || (freq == 0))  		return 0; -  	/*  	 * If host->mmc_clk didn't define,  	 * then assume that host->bus_hz is source clock value. @@ -314,7 +312,7 @@ static void dwmci_set_ios(struct mmc *mmc)  static int dwmci_init(struct mmc *mmc)  {  	struct dwmci_host *host = (struct dwmci_host *)mmc->priv; -	u32 fifo_size, fifoth_val; +	u32 fifo_size;  	dwmci_writel(host, DWMCI_PWREN, 1); @@ -323,6 +321,9 @@ static int dwmci_init(struct mmc *mmc)  		return -1;  	} +	/* Enumerate at 400KHz */ +	dwmci_setup_bus(host, mmc->f_min); +  	dwmci_writel(host, DWMCI_RINTSTS, 0xFFFFFFFF);  	dwmci_writel(host, DWMCI_INTMASK, 0); @@ -331,13 +332,13 @@ static int dwmci_init(struct mmc *mmc)  	dwmci_writel(host, DWMCI_IDINTEN, 0);  	dwmci_writel(host, DWMCI_BMOD, 1); -	fifo_size = dwmci_readl(host, DWMCI_FIFOTH); -	if (host->fifoth_val) -		fifoth_val = host->fifoth_val; -	else -		fifoth_val = MSIZE(0x2) | RX_WMARK(fifo_size/2 -1) | -			TX_WMARK(fifo_size/2); -	dwmci_writel(host, DWMCI_FIFOTH, fifoth_val); +	if (!host->fifoth_val) { +		fifo_size = dwmci_readl(host, DWMCI_FIFOTH); +		fifo_size = ((fifo_size & RX_WMARK_MASK) >> RX_WMARK_SHIFT) + 1; +		host->fifoth_val = MSIZE(0x2) | RX_WMARK(fifo_size / 2 - 1) | +			TX_WMARK(fifo_size / 2); +	} +	dwmci_writel(host, DWMCI_FIFOTH, host->fifoth_val);  	dwmci_writel(host, DWMCI_CLKENA, 0);  	dwmci_writel(host, DWMCI_CLKSRC, 0); diff --git a/drivers/mmc/exynos_dw_mmc.c b/drivers/mmc/exynos_dw_mmc.c index 72a31b73f..4238dd933 100644 --- a/drivers/mmc/exynos_dw_mmc.c +++ b/drivers/mmc/exynos_dw_mmc.c @@ -19,39 +19,146 @@   */  #include <common.h> -#include <malloc.h>  #include <dwmmc.h> +#include <fdtdec.h> +#include <libfdt.h> +#include <malloc.h>  #include <asm/arch/dwmmc.h>  #include <asm/arch/clk.h> +#include <asm/arch/pinmux.h> -static char *EXYNOS_NAME = "EXYNOS DWMMC"; +#define	DWMMC_MAX_CH_NUM		4 +#define	DWMMC_MAX_FREQ			52000000 +#define	DWMMC_MIN_FREQ			400000 +#define	DWMMC_MMC0_CLKSEL_VAL		0x03030001 +#define	DWMMC_MMC2_CLKSEL_VAL		0x03020001 +/* + * Function used as callback function to initialise the + * CLKSEL register for every mmc channel. + */  static void exynos_dwmci_clksel(struct dwmci_host *host)  { -	u32 val; -	val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) | -		DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(0); +	dwmci_writel(host, DWMCI_CLKSEL, host->clksel_val); +} -	dwmci_writel(host, DWMCI_CLKSEL, val); +unsigned int exynos_dwmci_get_clk(int dev_index) +{ +	return get_mmc_clk(dev_index);  } -int exynos_dwmci_init(u32 regbase, int bus_width, int index) +/* + * This function adds the mmc channel to be registered with mmc core. + * index -	mmc channel number. + * regbase -	register base address of mmc channel specified in 'index'. + * bus_width -	operating bus width of mmc channel specified in 'index'. + * clksel -	value to be written into CLKSEL register in case of FDT. + *		NULL in case od non-FDT. + */ +int exynos_dwmci_add_port(int index, u32 regbase, int bus_width, u32 clksel)  {  	struct dwmci_host *host = NULL; +	unsigned int div; +	unsigned long freq, sclk;  	host = malloc(sizeof(struct dwmci_host));  	if (!host) {  		printf("dwmci_host malloc fail!\n");  		return 1;  	} +	/* request mmc clock vlaue of 52MHz.  */ +	freq = 52000000; +	sclk = get_mmc_clk(index); +	div = DIV_ROUND_UP(sclk, freq); +	/* set the clock divisor for mmc */ +	set_mmc_clk(index, div); -	host->name = EXYNOS_NAME; +	host->name = "EXYNOS DWMMC";  	host->ioaddr = (void *)regbase;  	host->buswidth = bus_width; + +	if (clksel) { +		host->clksel_val = clksel; +	} else { +		if (0 == index) +			host->clksel_val = DWMMC_MMC0_CLKSEL_VAL; +		if (2 == index) +			host->clksel_val = DWMMC_MMC2_CLKSEL_VAL; +	} +  	host->clksel = exynos_dwmci_clksel;  	host->dev_index = index; +	host->mmc_clk = exynos_dwmci_get_clk; +	/* Add the mmc channel to be registered with mmc core */ +	if (add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ)) { +		debug("dwmmc%d registration failed\n", index); +		return -1; +	} +	return 0; +} + +#ifdef CONFIG_OF_CONTROL +int exynos_dwmmc_init(const void *blob) +{ +	int index, bus_width; +	int node_list[DWMMC_MAX_CH_NUM]; +	int err = 0, dev_id, flag, count, i; +	u32 clksel_val, base, timing[3]; + +	count = fdtdec_find_aliases_for_id(blob, "mmc", +				COMPAT_SAMSUNG_EXYNOS5_DWMMC, node_list, +				DWMMC_MAX_CH_NUM); + +	for (i = 0; i < count; i++) { +		int node = node_list[i]; + +		if (node <= 0) +			continue; -	add_dwmci(host, 52000000, 400000); +		/* Extract device id for each mmc channel */ +		dev_id = pinmux_decode_periph_id(blob, node); +		/* Get the bus width from the device node */ +		bus_width = fdtdec_get_int(blob, node, "samsung,bus-width", 0); +		if (bus_width <= 0) { +			debug("DWMMC: Can't get bus-width\n"); +			return -1; +		} +		if (8 == bus_width) +			flag = PINMUX_FLAG_8BIT_MODE; +		else +			flag = PINMUX_FLAG_NONE; + +		/* config pinmux for each mmc channel */ +		err = exynos_pinmux_config(dev_id, flag); +		if (err) { +			debug("DWMMC not configured\n"); +			return err; +		} + +		index = dev_id - PERIPH_ID_SDMMC0; + +		/* Get the base address from the device node */ +		base = fdtdec_get_addr(blob, node, "reg"); +		if (!base) { +			debug("DWMMC: Can't get base address\n"); +			return -1; +		} +		/* Extract the timing info from the node */ +		err = fdtdec_get_int_array(blob, node, "samsung,timing", +					timing, 3); +		if (err) { +			debug("Can't get sdr-timings for divider\n"); +			return -1; +		} + +		clksel_val = (DWMCI_SET_SAMPLE_CLK(timing[0]) | +				DWMCI_SET_DRV_CLK(timing[1]) | +				DWMCI_SET_DIV_RATIO(timing[2])); +		/* Initialise each mmc channel */ +		err = exynos_dwmci_add_port(index, base, bus_width, clksel_val); +		if (err) +			debug("dwmmc Channel-%d init failed\n", index); +	}  	return 0;  } - +#endif diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index e6a296a57..83d2df774 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1503,3 +1503,137 @@ int mmc_initialize(bd_t *bis)  	do_preinit();  	return 0;  } + +#ifdef CONFIG_SUPPORT_EMMC_BOOT +/* + * This function changes the size of boot partition and the size of rpmb + * partition present on EMMC devices. + * + * Input Parameters: + * struct *mmc: pointer for the mmc device strcuture + * bootsize: size of boot partition + * rpmbsize: size of rpmb partition + * + * Returns 0 on success. + */ + +int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize, +				unsigned long rpmbsize) +{ +	int err; +	struct mmc_cmd cmd; + +	/* Only use this command for raw EMMC moviNAND. Enter backdoor mode */ +	cmd.cmdidx = MMC_CMD_RES_MAN; +	cmd.resp_type = MMC_RSP_R1b; +	cmd.cmdarg = MMC_CMD62_ARG1; + +	err = mmc_send_cmd(mmc, &cmd, NULL); +	if (err) { +		debug("mmc_boot_partition_size_change: Error1 = %d\n", err); +		return err; +	} + +	/* Boot partition changing mode */ +	cmd.cmdidx = MMC_CMD_RES_MAN; +	cmd.resp_type = MMC_RSP_R1b; +	cmd.cmdarg = MMC_CMD62_ARG2; + +	err = mmc_send_cmd(mmc, &cmd, NULL); +	if (err) { +		debug("mmc_boot_partition_size_change: Error2 = %d\n", err); +		return err; +	} +	/* boot partition size is multiple of 128KB */ +	bootsize = (bootsize * 1024) / 128; + +	/* Arg: boot partition size */ +	cmd.cmdidx = MMC_CMD_RES_MAN; +	cmd.resp_type = MMC_RSP_R1b; +	cmd.cmdarg = bootsize; + +	err = mmc_send_cmd(mmc, &cmd, NULL); +	if (err) { +		debug("mmc_boot_partition_size_change: Error3 = %d\n", err); +		return err; +	} +	/* RPMB partition size is multiple of 128KB */ +	rpmbsize = (rpmbsize * 1024) / 128; +	/* Arg: RPMB partition size */ +	cmd.cmdidx = MMC_CMD_RES_MAN; +	cmd.resp_type = MMC_RSP_R1b; +	cmd.cmdarg = rpmbsize; + +	err = mmc_send_cmd(mmc, &cmd, NULL); +	if (err) { +		debug("mmc_boot_partition_size_change: Error4 = %d\n", err); +		return err; +	} +	return 0; +} + +/* + * This function shall form and send the commands to open / close the + * boot partition specified by user. + * + * Input Parameters: + * ack: 0x0 - No boot acknowledge sent (default) + *	0x1 - Boot acknowledge sent during boot operation + * part_num: User selects boot data that will be sent to master + *	0x0 - Device not boot enabled (default) + *	0x1 - Boot partition 1 enabled for boot + *	0x2 - Boot partition 2 enabled for boot + * access: User selects partitions to access + *	0x0 : No access to boot partition (default) + *	0x1 : R/W boot partition 1 + *	0x2 : R/W boot partition 2 + *	0x3 : R/W Replay Protected Memory Block (RPMB) + * + * Returns 0 on success. + */ +int mmc_boot_part_access(struct mmc *mmc, u8 ack, u8 part_num, u8 access) +{ +	int err; +	struct mmc_cmd cmd; + +	/* Boot ack enable, boot partition enable , boot partition access */ +	cmd.cmdidx = MMC_CMD_SWITCH; +	cmd.resp_type = MMC_RSP_R1b; + +	cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | +			(EXT_CSD_PART_CONF << 16) | +			((EXT_CSD_BOOT_ACK(ack) | +			EXT_CSD_BOOT_PART_NUM(part_num) | +			EXT_CSD_PARTITION_ACCESS(access)) << 8); + +	err = mmc_send_cmd(mmc, &cmd, NULL); +	if (err) { +		if (access) { +			debug("mmc boot partition#%d open fail:Error1 = %d\n", +			      part_num, err); +		} else { +			debug("mmc boot partition#%d close fail:Error = %d\n", +			      part_num, err); +		} +		return err; +	} + +	if (access) { +		/* 4bit transfer mode at booting time. */ +		cmd.cmdidx = MMC_CMD_SWITCH; +		cmd.resp_type = MMC_RSP_R1b; + +		cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | +				(EXT_CSD_BOOT_BUS_WIDTH << 16) | +				((1 << 0) << 8); + +		err = mmc_send_cmd(mmc, &cmd, NULL); +		if (err) { +			debug("mmc boot partition#%d open fail:Error2 = %d\n", +			      part_num, err); +			return err; +		} +	} +	return 0; +} +#endif |