]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - cmd/mmc_spi.c
2 * Command for mmc_spi setup.
4 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
5 * Licensed under the GPL-2 or later.
12 #ifndef CONFIG_MMC_SPI_BUS
13 # define CONFIG_MMC_SPI_BUS 0
15 #ifndef CONFIG_MMC_SPI_CS
16 # define CONFIG_MMC_SPI_CS 1
18 /* in SPI mode, MMC speed limit is 20MHz, while SD speed limit is 25MHz */
19 #ifndef CONFIG_MMC_SPI_SPEED
20 # define CONFIG_MMC_SPI_SPEED 25000000
22 /* MMC and SD specs only seem to care that sampling is on the
23 * rising edge ... meaning SPI modes 0 or 3. So either SPI mode
24 * should be legit. We'll use mode 0 since the steady state is 0,
25 * which is appropriate for hotplugging, unless the platform data
26 * specify mode 3 (if hardware is not compatible to mode 0).
28 #ifndef CONFIG_MMC_SPI_MODE
29 # define CONFIG_MMC_SPI_MODE SPI_MODE_0
32 static int do_mmc_spi(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
34 uint bus
= CONFIG_MMC_SPI_BUS
;
35 uint cs
= CONFIG_MMC_SPI_CS
;
36 uint speed
= CONFIG_MMC_SPI_SPEED
;
37 uint mode
= CONFIG_MMC_SPI_MODE
;
44 cs
= simple_strtoul(argv
[1], &endp
, 0);
45 if (*argv
[1] == 0 || (*endp
!= 0 && *endp
!= ':'))
51 cs
= simple_strtoul(endp
+ 1, &endp
, 0);
56 speed
= simple_strtoul(argv
[2], &endp
, 0);
57 if (*argv
[2] == 0 || *endp
!= 0)
61 mode
= simple_strtoul(argv
[3], &endp
, 16);
62 if (*argv
[3] == 0 || *endp
!= 0)
65 if (!spi_cs_is_valid(bus
, cs
)) {
66 printf("Invalid SPI bus %u cs %u\n", bus
, cs
);
70 mmc
= mmc_spi_init(bus
, cs
, speed
, mode
);
72 printf("Failed to create MMC Device\n");
75 printf("%s: %d at %u:%u hz %u mode %u\n", mmc
->cfg
->name
,
76 mmc
->block_dev
.devnum
, bus
, cs
, speed
, mode
);
85 mmc_spi
, 4, 0, do_mmc_spi
,
87 "[bus:]cs [hz] [mode] - setup mmc_spi device"