diff options
| author | Thomas Chou <thomas@wytron.com.tw> | 2010-12-24 13:12:21 +0000 | 
|---|---|---|
| committer | Andy Fleming <afleming@freescale.com> | 2011-04-13 06:35:22 -0500 | 
| commit | d52ebf102209cc1ad460c79b9498b2c8936ba413 (patch) | |
| tree | 843fc83bf6b7d92f49177bc0c585a56b20662bb2 /common/cmd_mmc_spi.c | |
| parent | 5f837c2c0ebda8f22474d26f85857993fb81ad7c (diff) | |
| download | olio-uboot-2014.01-d52ebf102209cc1ad460c79b9498b2c8936ba413.tar.xz olio-uboot-2014.01-d52ebf102209cc1ad460c79b9498b2c8936ba413.zip | |
mmc: add generic mmc spi driver
This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.
The crc checksum on data packet is enabled with the def,
There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Diffstat (limited to 'common/cmd_mmc_spi.c')
| -rw-r--r-- | common/cmd_mmc_spi.c | 88 | 
1 files changed, 88 insertions, 0 deletions
| diff --git a/common/cmd_mmc_spi.c b/common/cmd_mmc_spi.c new file mode 100644 index 000000000..63fe31337 --- /dev/null +++ b/common/cmd_mmc_spi.c @@ -0,0 +1,88 @@ +/* + * Command for mmc_spi setup. + * + * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw> + * Licensed under the GPL-2 or later. + */ + +#include <common.h> +#include <mmc.h> +#include <spi.h> + +#ifndef CONFIG_MMC_SPI_BUS +# define CONFIG_MMC_SPI_BUS 0 +#endif +#ifndef CONFIG_MMC_SPI_CS +# define CONFIG_MMC_SPI_CS 1 +#endif +/* in SPI mode, MMC speed limit is 20MHz, while SD speed limit is 25MHz */ +#ifndef CONFIG_MMC_SPI_SPEED +# define CONFIG_MMC_SPI_SPEED 25000000 +#endif +/* MMC and SD specs only seem to care that sampling is on the + * rising edge ... meaning SPI modes 0 or 3.  So either SPI mode + * should be legit.  We'll use mode 0 since the steady state is 0, + * which is appropriate for hotplugging, unless the platform data + * specify mode 3 (if hardware is not compatible to mode 0). + */ +#ifndef CONFIG_MMC_SPI_MODE +# define CONFIG_MMC_SPI_MODE SPI_MODE_0 +#endif + +static int do_mmc_spi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ +	uint bus = CONFIG_MMC_SPI_BUS; +	uint cs = CONFIG_MMC_SPI_CS; +	uint speed = CONFIG_MMC_SPI_SPEED; +	uint mode = CONFIG_MMC_SPI_MODE; +	char *endp; +	struct mmc *mmc; + +	if (argc < 2) +		goto usage; + +	cs = simple_strtoul(argv[1], &endp, 0); +	if (*argv[1] == 0 || (*endp != 0 && *endp != ':')) +		goto usage; +	if (*endp == ':') { +		if (endp[1] == 0) +			goto usage; +		bus = cs; +		cs = simple_strtoul(endp + 1, &endp, 0); +		if (*endp != 0) +			goto usage; +	} +	if (argc >= 3) { +		speed = simple_strtoul(argv[2], &endp, 0); +		if (*argv[2] == 0 || *endp != 0) +			goto usage; +	} +	if (argc >= 4) { +		mode = simple_strtoul(argv[3], &endp, 16); +		if (*argv[3] == 0 || *endp != 0) +			goto usage; +	} +	if (!spi_cs_is_valid(bus, cs)) { +		printf("Invalid SPI bus %u cs %u\n", bus, cs); +		return 1; +	} + +	mmc = mmc_spi_init(bus, cs, speed, mode); +	if (!mmc) { +		printf("Failed to create MMC Device\n"); +		return 1; +	} +	printf("%s: %d at %u:%u hz %u mode %u\n", mmc->name, mmc->block_dev.dev, +	       bus, cs, speed, mode); +	return 0; + +usage: +	cmd_usage(cmdtp); +	return 1; +} + +U_BOOT_CMD( +	mmc_spi,	4,	0,	do_mmc_spi, +	"mmc_spi setup", +	"[bus:]cs [hz] [mode]	- setup mmc_spi device" +); |