latest MMC-over-SPI patchset
Subsystems (6)
cover latest MMC-over-SPI patchset
It's been a while since the mmc-over-spi host driver has been updated, and I think it's time to do so ... and start getting it mergeable. Hence the following series of patches.
Kudos to Mike Lavender, original author; Hans-Peter Nilsson, who got this version to really work; Jan Nikitenko, who made more rough edges vanish and added CRC support; and Pierre Ossman, who has supported the notion of a bit more surgery on mmc-core to help keep some crap out of the host driver!
The first few patches are pretty separable:
- CRC7 support (already in MM)
- SD 4wire bugfix (submitted to Pierre)
- SPI "exclusive mode" patch ... experimental, optional
The rest are the guts of the MMC-over-SPI support, following Pierre's suggestion to teach the mmc core about SPI so that the host adapter doesn't have so much work to do.
- MMC headers expose SPI constants; add mmc_host_is_spi()
- MMC core uses those to support MMC or SD enumeration
- MMC block needed tweaks too
- Last but not least ... mmc_spi host adapter.
This is distributed for testing and comments. I believe that Pierre will have a few issues with the core patches. The SPI "exclusive mode" patch will remain experimental for some time.
I'd also like to see someone sign up as mmc_spi maintainer; ideally that person would start sheparding this the rest of the way upstream.
- Dave
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 1/7 CRC7 support
In reply to a message not in the archiveFrom: Jan Nikitenko <[email protected]>
Add CRC7 routines, used for example in MMC over SPI communication. Kerneldoc updates
---
NOTE: this is already in the MM tree.
Documentation/DocBook/kernel-api.tmpl | 4 +- include/linux/crc7.h | 14 +++++++ lib/Kconfig | 8 ++++ lib/Makefile | 1 lib/crc7.c | 68 ++++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 1 deletion(-)
Documentation/DocBook/kernel-api.tmpl +3 -1
@@ -139,8 +139,10 @@ X!Ilib/string.c !Elib/cmdline.c </sect1> - <sect1><title>CRC Functions</title> + <sect1 id="crc"><title>CRC Functions</title> +!Elib/crc7.c !Elib/crc16.c +!Elib/crc-itu-t.c !Elib/crc32.c !Elib/crc-ccitt.c </sect1>
lib/Kconfig +8 -0
@@ -41,6 +41,14 @@ config CRC32 kernel tree does. Such modules that use library CRC32 functions require M here. +config CRC7 + tristate "CRC7 functions" + help + This option is provided for the case where no in-kernel-tree + modules require CRC7 functions, but a module built outside + the kernel tree does. Such modules that use library CRC7 + functions require M here. + config LIBCRC32C tristate "CRC32c (Castagnoli, et al) Cyclic Redundancy-Check" help
lib/Makefile +1 -0
@@ -43,6 +43,7 @@ obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o obj-$(CONFIG_CRC16) += crc16.o obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o obj-$(CONFIG_CRC32) += crc32.o +obj-$(CONFIG_CRC7) += crc7.o obj-$(CONFIG_LIBCRC32C) += libcrc32c.o obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o
include/linux/crc7.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _LINUX_CRC7_H +#define _LINUX_CRC7_H +#include <linux/types.h> + +extern const u8 crc7_syndrome_table[256 ]; + +static inline u8 crc7_byte (u8 crc,const u8 data) +{ +return crc7_syndrome_table[(crc <<1 ) ^ data]; +} + +extern u8 crc7 (u8 crc,const u8 *buffer,size_t len); + +#endif
lib/crc7.c new file +68 -0
68 lines not on this page · raw message
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 2/7 SD 4wire bugfix
In reply to a message not in the archiveOnce upon a debug dreary, while I pondered weak and weary, Over many a quaint and curious volume of forgotten lore-- While I nodded, nearly napping, suddenly there came a trapping, As of some code gently thrashing, thrashing at a chip once more. "'Tis some bugginess," I muttered, "trapping MMC_CAP_4
Only this, and nothing more."
---
Sent already to Pierre ... this should get into 2.6.22-rc5!
drivers/mmc/core/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/sd.c +1 -1
@@ -402,7 +402,7 @@ static int mmc_sd_init_card(struct mmc_h/* * Switch to wider bus (if supported). */ -if ((host->caps &&MMC_CAP_4_BIT_DATA ) && +if ((host->caps &MMC_CAP_4_BIT_DATA ) && (card->scr.bus_widths &SD_SCR_BUS_WIDTH_4 )) { err =mmc_app_set_bus_width (card,MMC_BUS_WIDTH_4 );if (err !=MMC_ERR_NONE )
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 3/7 SPI "exclusive access" (experimental)
In reply to a message not in the archiveThis is a draft API and reference implementation for a new SPI protocol tweaking option, which supports more complex protocol stacks over SPI.
Examples: MMC/SD-over-SPI, wireless network chips, and hardware tools at the JTAG/ISP level.
- A new SPI protocol tweaking interface, giving one driver exclusive access to a SPI bus for transfer sequences too complex to fit into one spi_message.
- An initial implementation of that, for the "bitbang" core. I'm sure someone can come up with a much better implementation for this, which I'd expect to feed back to improve that interface.
It behaves in light testing without contention for the bus lock.
Includes secondary queue code from Jan Nikitenko <[email protected]> to make submissions to other devices act "normally"; they're executed
when the exclusion is released.
NOT YET READY for prime time. An alternate scheme has recently been suggested, more amenable to IRQ-driven code that needs to start and sustain "exclusion" in contexts that can't sleep.
--- drivers/spi/spi_bitbang.c | 92 +++++++++++++++++++++++++++++++++++++--- include/linux/spi/spi.h | 58 +++++++++++++++++++++++++ include/linux/spi/spi_bitbang.h | 3 + 3 files changed, 148 insertions(+), 5 deletions(-)
include/linux/spi/spi.h +58 -0
@@ -182,6 +182,9 @@ static inline void spi_unregister_driver* the device whose settings are being modified. * @transfer: adds a message to the controller's transfer queue. * @cleanup: frees controller-specific state +* @get_exclusive: Waits until the message queue is empty, then reserves +* the bus for exclusive use with that devices. +* @put_exclusive: Reverses the effect of @get_exclusive. * * Each SPI master controller can communicate with one or more @spi_device * children. These make a small bus, sharing MOSI, MISO and SCK signals
@@ -237,6 +240,12 @@ struct spi_master {/* called on release() to free memory provided by spi_master */ void (*cleanup)(struct spi_device *spi); + +/* Some protocols, like MMC or SD over SPI, need to lock a device's +* chipselect for an extended period of time. +*/ +int (*get_exclusive)(struct spi_device *spi); +void (*put_exclusive)(struct spi_device *spi); };static inline void *spi_master_get_devdata (struct spi_master *master)
@@ -538,6 +547,55 @@ spi_async(struct spi_device *spi, structreturn spi->master->transfer (spi, message); } + +#define SPI_HAS_EXCLUSIVE + +/** +* spi_get_exclusive - temporarily acquire exclusive access to a SPI bus +* @spi: device which will have exclusive access to the SPI bus. +* Context: can sleep +* +* Some SPI protocols, such as those for MMC and SD cards, involve keeping +* a given device's chipselect active for more complex sequences of transfers +* than the known-in-advance contents of one spi_message. Drivers for such +* protocols should use this method and its sibling spi_put_exclusive(). +* +* When spi_get_exclusive() returns success, any pending transfers on that +* bus will have completed, and that device's chipselect will be active. +* From that point until spi_put_exclusive() is called, only spi_message +* transfers to that device will be acted on, and the device will only be +* (briefly) deselected mid-message, according to by spi_transfer.cs_change. +* +* Message being sent to other devices on this bus are queued for processing +* after the matching put_exclusive() call. +* +* This call may only be from contexts which can sleep. It returns zero +* on success, else a negative error number. +*/ +static inline int spi_get_exclusive (struct spi_device *spi) +{ +if (!spi->master->get_exclusive) +return -EIO ; +return spi->master->get_exclusive (spi); +} + +/** +* spi_put_exclusive - release exclusive access to a SPI bus +* @spi: device which has been granted that access +* Context: can sleep +* +* This reverses the effect of a successful spi_get_exclusive(), and +* deselects the device. +* +* This call may only be from contexts which can sleep. It is an error to +* call this when messages are still queued to the specified device, or +* from code that doesn't hold the exclusive access. +*/ +static inline void spi_put_exclusive (struct spi_device *spi) +{ + spi->master->put_exclusive (spi); +} +/*---------------------------------------------------------------------------*/ /* All these synchronous SPI transfer routines are utilities layered
include/linux/spi/spi_bitbang.h +3 -0
@@ -29,6 +29,9 @@ struct spi_bitbang {u8 flags;/* extra spi->mode support */ struct spi_master *master; +struct spi_device *exclusive; +wait_queue_head_t xwait; +struct list_head xqueue;/* setup_transfer() changes clock and/or wordsize to match settings * for this transfer; zeroes restore defaults from spi_device.
drivers/spi/spi_bitbang.c +87 -5
149 lines not on this page · raw message
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 4/7 MMC headers understand SPI
In reply to a message not in the archiveTeach the MMC/SD/SDIO system headers that some hosts use SPI mode
- New host capabilities bits
* MMC_CAP_SPI, with mmc_host_is_spi() test
* MMC_CAP_SPI_CRC, if it's ready to use CRCs
- SPI-specific declarations:
* Response types, MMC_RSP_SPI_R*
* Two SPI-only commands
* Status bits used native to SPI: R1_SPI_*, R2_SPI_*
- Fix a few (unrelated) whitespace bugs in the headers.
None of these changes affects current code.
--- include/linux/mmc/core.h | 25 ++++++++++++++++++++++-- include/linux/mmc/host.h | 4 +++ include/linux/mmc/mmc.h | 48 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 68 insertions(+), 9 deletions(-)
include/linux/mmc/host.h +4 -0
@@ -90,6 +90,8 @@ struct mmc_host {#define MMC_CAP_BYTEBLOCK (1 << 2)/* Can do non-log2 block sizes */ #define MMC_CAP_MMC_HIGHSPEED (1 << 3)/* Can do MMC high-speed timing */ #define MMC_CAP_SD_HIGHSPEED (1 << 4)/* Can do SD high-speed timing */ +#define MMC_CAP_SPI (1 << 5)/* Talks only SPI protocols */ +#define MMC_CAP_SPI_CRC (1 << 6)/* Handles CRC option in SPI */ /* host specific block data */ unsigned int max_seg_size;/* see blk_queue_max_segment_size */
@@ -137,6 +139,8 @@ static inline void *mmc_priv(struct mmc_return (void *)host->private; } +#define mmc_host_is_spi (host) ((host)->caps & MMC_CAP_SPI) +#define mmc_dev (x) ((x)->parent)#define mmc_classdev (x) (&(x)->class_dev)#define mmc_hostname (x) ((x)->class_dev.bus_id)
include/linux/mmc/core.h +23 -2
@@ -25,14 +25,19 @@ struct mmc_command {#define MMC_RSP_CRC (1 << 2)/* expect valid crc */ #define MMC_RSP_BUSY (1 << 3)/* card may send busy */ #define MMC_RSP_OPCODE (1 << 4)/* response contains opcode */ -#define MMC_CMD_MASK (3 << 5)/* command type */ + +#define MMC_CMD_MASK (3 << 5)/* non-SPI command type */ #define MMC_CMD_AC (0 << 5)#define MMC_CMD_ADTC (1 << 5)#define MMC_CMD_BC (2 << 5)#define MMC_CMD_BCR (3 << 5) +#define MMC_RSP_SPI_S1 (1 << 7)/* one status byte */ +#define MMC_RSP_SPI_S2 (1 << 8)/* second status byte */ +#define MMC_RSP_SPI_OCR (1 << 9)/* OCR */ +/* -* These are the response types, and correspond to valid bit +* These are the native response types, and correspond to valid bit * patterns of the above flags. One additional valid pattern * is all zeros, which means we don't expect a response. */
@@ -47,6 +52,22 @@ struct mmc_command {#define mmc_resp_type (cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))/* +* These are the SPI response types. Commands return R1, with maybe +* more info. Commands like SEND_CSD return a data block too, which +* we call 'R1D'. Zero is an invalid type, meaning that the caller +* forgot to say which response type applies to this command. +* +* FIXME remove R1D; update SEND_CxD in the core. +*/ +#define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1) +#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_BUSY) +#define MMC_RSP_SPI_R2 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2) +#define MMC_RSP_SPI_R3 (MMC_RSP_SPI_S1|MMC_RSP_SPI_OCR) +#define MMC_RSP_SPI_R1D (MMC_RSP_SPI_S1|MMC_RSP_136) + +#define mmc_spi_resp_type (cmd) ((cmd)->flags & (MMC_RSP_SPI_S1|MMC_RSP_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_OCR|MMC_RSP_136)) + +/* * These are the command types. */ #define mmc_cmd_type (cmd) ((cmd)->flags & MMC_CMD_MASK)
include/linux/mmc/mmc.h +41 -7
88 lines not on this page · raw message
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 5/7 MMC core understands SPI
In reply to a message not in the archiveTeach the MMC/SD/SDIO core about using SPI mode.
- Provide utilities to access two SPI-only requests, and one request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only
* mmc_spi_send_cid() ... works without broadcast mode
- Use mmc_host_is_spi() so enumeration works through SPI protocols, not just the native (and sometimes parallel) ones
- Provide the SPI response type flags with each request issued. The model is that if no such flags are provided, it will be rejected by the MMC-over-SPI host. (Some requests are invalid over SPI.)
- Understand that some commands act a bit differently ... notably the OP_COND command doesn't return the OCR, and does status differently.
The current assumption is that nobody will want a controller driver to handle both SPI *and* the faster "native" MMC/SD protocols ... even though some MMC controllers could do that.
Evidently the very newest MMC cards (like v4.2) differ from older ones in how they handle things like CMD8 ... lacking specs, much less one of the high capacity cards, this doesn't attempt to handle those cases.
--- drivers/mmc/core/core.c | 38 ++++++++++++++--- drivers/mmc/core/mmc.c | 28 ++++++++---- drivers/mmc/core/mmc_ops.c | 97 +++++++++++++++++++++++++++++++++++---------- drivers/mmc/core/mmc_ops.h | 4 + drivers/mmc/core/sd.c | 36 +++++++++++----- drivers/mmc/core/sd_ops.c | 17 +++++-- 6 files changed, 166 insertions(+), 54 deletions(-)
drivers/mmc/core/mmc_ops.h +4 -0
@@ -23,5 +23,9 @@ int mmc_send_ext_csd(struct mmc_card *caint mmc_switch (struct mmc_card *card,u8 set,u8 index,u8 value);int mmc_send_status (struct mmc_card *card,u32 *status); +int mmc_spi_send_cid (struct mmc_host *host,u32 *cid); +int mmc_spi_read_ocr (struct mmc_host *host,u32 *ocrp); +int mmc_spi_set_crc (struct mmc_host *host); +#endif
drivers/mmc/core/core.c +31 -7
@@ -400,8 +400,13 @@ static void mmc_power_up(struct mmc_hostint bit =fls (host->ocr_avail) -1 ; host->ios.vdd = bit; - host->ios.bus_mode =MMC_BUSMODE_OPENDRAIN ; - host->ios.chip_select =MMC_CS_DONTCARE ; +if (mmc_host_is_spi (host)) { + host->ios.chip_select =MMC_CS_HIGH ; + host->ios.bus_mode =MMC_BUSMODE_PUSHPULL ; + }else { + host->ios.chip_select =MMC_CS_DONTCARE ; + host->ios.bus_mode =MMC_BUSMODE_OPENDRAIN ; + } host->ios.power_mode =MMC_POWER_UP ; host->ios.bus_width =MMC_BUS_WIDTH_1 ; host->ios.timing =MMC_TIMING_LEGACY ;
@@ -420,8 +425,10 @@ static void mmc_power_off(struct mmc_hos { host->ios.clock =0 ; host->ios.vdd =0 ; - host->ios.bus_mode =MMC_BUSMODE_OPENDRAIN ; - host->ios.chip_select =MMC_CS_DONTCARE ; +if (!mmc_host_is_spi (host)) { + host->ios.bus_mode =MMC_BUSMODE_OPENDRAIN ; + host->ios.chip_select =MMC_CS_DONTCARE ; + } host->ios.power_mode =MMC_POWER_OFF ; host->ios.bus_width =MMC_BUS_WIDTH_1 ; host->ios.timing =MMC_TIMING_LEGACY ;
@@ -512,6 +519,19 @@ void mmc_detect_change(struct mmc_host *EXPORT_SYMBOL (mmc_detect_change); +static int mmc_spi_fixup (struct mmc_host *host,u32 *ocrp) +{ +int err; + +if (!mmc_host_is_spi (host)) +return MMC_ERR_NONE ; + + err =mmc_spi_read_ocr (host, ocrp); +if (err ==MMC_ERR_NONE ); + err =mmc_spi_set_crc (host); +return err; +} +static void mmc_rescan (struct work_struct *work) { struct mmc_host *host =
@@ -533,11 +553,13 @@ static void mmc_rescan(struct work_strucmmc_power_up (host);mmc_go_idle (host); -mmc_send_if_cond (host, host->ocr_avail); +if (!mmc_host_is_spi (host)) +mmc_send_if_cond (host, host->ocr_avail); err =mmc_send_app_op_cond (host,0 , &ocr);if (err ==MMC_ERR_NONE ) { -if (mmc_attach_sd (host, ocr)) + err =mmc_spi_fixup (host, &ocr); +if (err !=MMC_ERR_NONE ||mmc_attach_sd (host, ocr))mmc_power_off (host); }else {/*
@@ -546,7 +568,9 @@ static void mmc_rescan(struct work_struc*/ err =mmc_send_op_cond (host,0 , &ocr);if (err ==MMC_ERR_NONE ) { -if (mmc_attach_mmc (host, ocr)) + err =mmc_spi_fixup (host, &ocr); +if (err !=MMC_ERR_NONE + ||mmc_attach_mmc (host, ocr))mmc_power_off (host); }else {mmc_power_off (host);
drivers/mmc/core/mmc_ops.c +76 -21
164 lines not on this page · raw message
drivers/mmc/core/mmc.c +18 -10
@@ -263,9 +263,15 @@ static int mmc_sd_init_card(struct mmc_h/* * Fetch CID from card. */ - err =mmc_all_send_cid (host, cid); -if (err !=MMC_ERR_NONE ) - goto err; +if (mmc_host_is_spi (host)) { + err =mmc_spi_send_cid (host, cid); +if (err !=MMC_ERR_NONE ) + goto err; + }else { + err =mmc_all_send_cid (host, cid); +if (err !=MMC_ERR_NONE ) + goto err; + }if (oldcard) {if (memcmp (cid, oldcard->raw_cid,sizeof (cid)) !=0 )
@@ -286,13 +292,15 @@ static int mmc_sd_init_card(struct mmc_h }/* -* Set card RCA. +* For native busses: set card RCA and leave open drain mode. */ - err =mmc_set_relative_addr (card); -if (err !=MMC_ERR_NONE ) - goto free_card; +if (!mmc_host_is_spi (host)) { + err =mmc_set_relative_addr (card); +if (err !=MMC_ERR_NONE ) + goto free_card; -mmc_set_bus_mode (host,MMC_BUSMODE_PUSHPULL ); +mmc_set_bus_mode (host,MMC_BUSMODE_PUSHPULL ); + }if (!oldcard) {/*
@@ -317,9 +325,9 @@ static int mmc_sd_init_card(struct mmc_hif (err !=MMC_ERR_NONE ) goto free_card; -if (!oldcard) { +if (!oldcard && !mmc_host_is_spi (host)) {/* -* Fetch and process extened CSD. +* Fetch and process extended CSD. */ err =mmc_read_ext_csd (card);if (err !=MMC_ERR_NONE )
drivers/mmc/core/sd.c +25 -11
@@ -306,9 +306,19 @@ static int mmc_sd_init_card(struct mmc_h/* * Fetch CID from card. */ - err =mmc_all_send_cid (host, cid); -if (err !=MMC_ERR_NONE ) - goto err; +if (mmc_host_is_spi (host)) { + err =mmc_spi_set_crc (host); +if (err !=MMC_ERR_NONE ) + goto err; + err =mmc_spi_send_cid (host, cid); +if (err !=MMC_ERR_NONE ) + goto err; + }else { + err =mmc_all_send_cid (host, cid); +if (err !=MMC_ERR_NONE ) + goto err; + } +if (oldcard) {if (memcmp (cid, oldcard->raw_cid,sizeof (cid)) !=0 )
@@ -328,13 +338,15 @@ static int mmc_sd_init_card(struct mmc_h }/* -* Set card RCA. +* For native busses: set card RCA and leave open drain mode. */ - err =mmc_send_relative_addr (host, &card->rca); -if (err !=MMC_ERR_NONE ) - goto free_card; +if (!mmc_host_is_spi (host)) { + err =mmc_send_relative_addr (host, &card->rca); +if (err !=MMC_ERR_NONE ) + goto free_card; -mmc_set_bus_mode (host,MMC_BUSMODE_PUSHPULL ); +mmc_set_bus_mode (host,MMC_BUSMODE_PUSHPULL ); + }if (!oldcard) {/*
@@ -373,9 +385,11 @@ static int mmc_sd_init_card(struct mmc_h/* * Fetch switch information from card. */ - err =mmc_read_switch (card); -if (err !=MMC_ERR_NONE ) - goto free_card; +if (!mmc_host_is_spi (host)) { + err =mmc_read_switch (card); +if (err !=MMC_ERR_NONE ) + goto free_card; + } }/*
drivers/mmc/core/sd_ops.c +12 -5
@@ -89,10 +89,10 @@ int mmc_app_cmd(struct mmc_host *host, sif (card) { cmd.arg = card->rca <<16 ; - cmd.flags =MMC_RSP_R1 |MMC_CMD_AC ; + cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_AC ; }else { cmd.arg =0 ; - cmd.flags =MMC_RSP_R1 |MMC_CMD_BCR ; + cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_BCR ; } err =mmc_wait_for_cmd (host, &cmd,0 );
@@ -148,14 +148,18 @@ int mmc_send_app_op_cond(struct mmc_host cmd.opcode =SD_APP_OP_COND ; cmd.arg = ocr; - cmd.flags =MMC_RSP_R3 |MMC_CMD_BCR ; + cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R3 |MMC_CMD_BCR ;for (i =100 ; i; i--) { err =mmc_wait_for_app_cmd (host,NULL , &cmd,MMC_CMD_RETRIES );if (err !=MMC_ERR_NONE )break ; -if (cmd.resp[0 ] &MMC_CARD_BUSY || ocr ==0 ) +if (mmc_host_is_spi (host)) { +/* wait until reset completes */ +if (!(cmd.resp[2 ] &R1_SPI_IDLE )) +break ; + }else if (cmd.resp[0 ] &MMC_CARD_BUSY || ocr ==0 )break ; err =MMC_ERR_TIMEOUT ;
@@ -175,6 +179,9 @@ int mmc_send_if_cond(struct mmc_host *hoint err;static const u8 test_pattern =0xAA ; +if (mmc_host_is_spi (host)) +return MMC_ERR_FAILED ; +/* * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND * before SD_APP_OP_COND. This command will harmlessly fail for
@@ -242,7 +249,7 @@ int mmc_app_send_scr(struct mmc_card *ca cmd.opcode =SD_APP_SEND_SCR ; cmd.arg =0 ; - cmd.flags =MMC_RSP_R1 |MMC_CMD_ADTC ; + cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; data.blksz =8 ; data.blocks =1 ;
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 6/7 MMC block understands SPI
In reply to a message not in the archiveTeach the MMC/SD block card driver about SPI.
- Provide the SPI response type flags with each request issued. The model is that if no such flags are provided, it will be rejected by the MMC-over-SPI host.
- Understand that multiblock SPI writes don't use STOP_TRANSMISSION.
--- drivers/mmc/card/block.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/mmc/card/block.c +13 -7
@@ -151,7 +151,7 @@ static u32 mmc_sd_num_wr_blocks(struct m cmd.opcode =MMC_APP_CMD ; cmd.arg = card->rca <<16 ; - cmd.flags =MMC_RSP_R1 |MMC_CMD_AC ; + cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_AC ; err =mmc_wait_for_cmd (card->host, &cmd,0 );if ((err !=MMC_ERR_NONE ) || !(cmd.resp[0 ] &R1_APP_CMD ))
@@ -161,7 +161,7 @@ static u32 mmc_sd_num_wr_blocks(struct m cmd.opcode =SD_APP_SEND_NUM_WR_BLKS ; cmd.arg =0 ; - cmd.flags =MMC_RSP_R1 |MMC_CMD_ADTC ; + cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ;memset (&data,0 ,sizeof (struct mmc_data ));
@@ -220,11 +220,11 @@ static int mmc_blk_issue_rq(struct mmc_q brq.cmd.arg = req->sector;if (!mmc_card_blockaddr (card)) brq.cmd.arg <<=9 ; - brq.cmd.flags =MMC_RSP_R1 |MMC_CMD_ADTC ; + brq.cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; brq.data.blksz =1 << md->block_bits; brq.stop.opcode =MMC_STOP_TRANSMISSION ; brq.stop.arg =0 ; - brq.stop.flags =MMC_RSP_R1B |MMC_CMD_AC ; + brq.stop.flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; brq.data.blocks = req->nr_sectors >> (md->block_bits -9 );if (brq.data.blocks > card->host->max_blk_count) brq.data.blocks = card->host->max_blk_count;
@@ -244,7 +244,12 @@ static int mmc_blk_issue_rq(struct mmc_qif (brq.data.blocks >1 ) { brq.data.flags |=MMC_DATA_MULTI ; - brq.mrq.stop = &brq.stop; +/* SPI multiblock writes terminate using a special +* token, not a STOP_TRANSMISSION request. +*/ +if (!mmc_host_is_spi (card->host) + ||rq_data_dir (req) ==READ ) + brq.mrq.stop = &brq.stop; readcmd =MMC_READ_MULTIPLE_BLOCK ; writecmd =MMC_WRITE_MULTIPLE_BLOCK ; }else {
@@ -303,7 +308,8 @@ static int mmc_blk_issue_rq(struct mmc_q cmd.opcode =MMC_SEND_STATUS ; cmd.arg = card->rca <<16 ; - cmd.flags =MMC_RSP_R1 |MMC_CMD_AC ; + cmd.flags =MMC_RSP_SPI_R2 |MMC_RSP_R1 + |MMC_CMD_AC ; err =mmc_wait_for_cmd (card->host, &cmd,5 );if (err) { printk(KERN_ERR "%s: error %d requesting status\n",
@@ -506,7 +512,7 @@ mmc_blk_set_blksize(struct mmc_blk_datammc_claim_host (card->host); cmd.opcode =MMC_SET_BLOCKLEN ; cmd.arg =1 << md->block_bits; - cmd.flags =MMC_RSP_R1 |MMC_CMD_AC ; + cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_AC ; err =mmc_wait_for_cmd (card->host, &cmd,5 );mmc_release_host (card->host);
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 7/7 mmc_spi host driver
In reply to a message not in the archiveThis is the latest version of the MMC-over-SPI support. It works on 2.6.22-rc4, along with several preceding patches which teach the rest of the MMC stack about SPI (so this host driver can focus on doing only the lowlevel stuff).
It's been lightly tested on MMC and SD cards, both reading and writing ext3 filesystems (including fsck). I didn't test the CRC mode, and suspect that's been broken in the CSD and CID reading code.
---
I'm not expecting this to merge in quite this form. The CRC should be verified to work again, and the "R1D" response type should go away (in conjunction with MMC core updates). The "exclusive" hooks will likely need to be removed; they can be added when the SPI stack gets such primitives. In general, this version marks a big cleanup/change from the previous monolithic code.
drivers/mmc/host/Kconfig | 13 drivers/mmc/host/Makefile | 1 drivers/mmc/host/mmc_spi.c | 1462 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/spi/mmc_spi.h | 32 4 files changed, 1508 insertions(+)
drivers/mmc/host/Kconfig +13 -0
@@ -100,3 +100,16 @@ config MMC_TIFM_SD To compile this driver as a module, choose M here: the module will be called tifm_sd. +config MMC_SPI + tristate "MMC/SD over SPI" + depends on MMC && SPI_MASTER && EXPERIMENTAL + select CRC7 + select CRC_ITU_T + help + Some systems accss MMC/SD cards using the SPI protocol instead of + using an MMC/SD controller. The disadvantage of using SPI is that + it's often not as fast; its compensating advantage is that SPI is + available on many systems without MMC/SD controllers. + + If unsure, or if your system has no SPI controller driver, say N. +
drivers/mmc/host/Makefile +1 -0
@@ -15,4 +15,5 @@ obj-$(CONFIG_MMC_AU1X) += au1xmmc.o obj-$(CONFIG_MMC_OMAP) += omap.o obj-$(CONFIG_MMC_AT91) += at91_mci.o obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o +obj-$(CONFIG_MMC_SPI) += mmc_spi.o
include/linux/spi/mmc_spi.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef __LINUX_SPI_MMC_SPI_H +#define __LINUX_SPI_MMC_SPI_H + +struct device ; +struct mmc_host ; + +/* Put this in platform_data of a device being used to manage an MMC/SD +* card slot. (Modeled after PXA mmc glue; see that for usage examples.) +* +* REVISIT This is not a spi-specific notion. Any card slot should be +* able to handle it. If the MMC core doesn't adopt this kind of notion, +* switch the "struct device *" parameters over to "struct spi_device *". +*/ +struct mmc_spi_platform_data { +/* driver activation and (optional) card detect irq hookup */ +int (*init)(struct device *, +irqreturn_t (*)(int ,void *), +void *); +void (*exit)(struct device *,void *); + +/* how long to debounce card detect, in msecs */ +unsigned detect_delay; + +/* sense switch on sd cards */ +int (*get_ro)(struct device *); + +/* power management */ +unsigned int ocr_mask;/* available voltages */ +void (*setpower)(struct device *,unsigned int maskval); +}; + +#endif /* __LINUX_SPI_MMC_SPI_H */
drivers/mmc/host/mmc_spi.c new file +1462 -0
1,462 lines not on this page · raw message
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
[patch 2.6.22-rc4 8/7] mmc_spi cid/csd/ext_csd updates, CRCs on
In reply to a message not in the archiveFix some of the "register"/descriptor access glitches in the preceding patches:
- Updated internal routines:
* previous mmc_send_cxd() renamed to mmc_send_cxd_native(); it uses native "R2" responses, which include 16 bytes of data.
* previous mmc_send_ext_csd() becomes new mmc_send_cxd_data() helper for command-and-data access
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- New mmc_send_csd() and mmc_spi_send_cid() routines now use one
of those helper routines based on whether they're native or SPI;
- Remove ugly "R1D" response pseudo-type for SPI
- Make it OK for MMC cards to try SEND_EXT_CSD; v4+ needs that
- Turn CRCs back on by default with the SPI protocol
So this resolves most of the technical issues I know about, leaving nontechnical ones like "is this code clean enough" or "is this how we want to solve that problem".
--- drivers/mmc/core/mmc.c | 2 drivers/mmc/core/mmc_ops.c | 93 +++++++++++++++++++++++++++++++++------------ drivers/mmc/host/mmc_spi.c | 59 ---------------------------- include/linux/mmc/core.h | 8 --- 4 files changed, 72 insertions(+), 90 deletions(-)
drivers/mmc/core/mmc_ops.c +69 -24
@@ -175,7 +175,7 @@ int mmc_set_relative_addr(struct mmc_car }static int -mmc_send_cxd (struct mmc_host *host,unsigned rca,u32 *cxd,int opcode) +mmc_send_cxd_native (struct mmc_host *host,unsigned rca,u32 *cxd,int opcode) {int err;struct mmc_command cmd;
@@ -187,7 +187,7 @@ mmc_send_cxd(struct mmc_host *host, unsi cmd.opcode = opcode; cmd.arg = rca <<16 ; - cmd.flags =MMC_RSP_SPI_R1D |MMC_RSP_R2 |MMC_CMD_AC ; + cmd.flags =MMC_RSP_R2 |MMC_CMD_AC ; err =mmc_wait_for_cmd (host, &cmd,MMC_CMD_RETRIES );if (err !=MMC_ERR_NONE )
@@ -198,16 +198,6 @@ mmc_send_cxd(struct mmc_host *host, unsireturn MMC_ERR_NONE ; } -int mmc_send_csd (struct mmc_card *card,u32 *csd) -{ -return mmc_send_cxd (card->host, card->rca, csd,MMC_SEND_CSD ); -} - -int mmc_spi_send_cid (struct mmc_host *host,u32 *cid) -{ -return mmc_send_cxd (host,0 , cid,MMC_SEND_CID ); -} -int mmc_spi_read_ocr (struct mmc_host *host,u32 *ocrp) {struct mmc_command cmd;
@@ -238,17 +228,22 @@ int mmc_spi_set_crc(struct mmc_host *hosreturn mmc_wait_for_cmd (host, &cmd,0 ); } -int mmc_send_ext_csd (struct mmc_card *card,u8 *ext_csd) +struct mmc_cxd { +struct mmc_card *card;/* optional */ +void *buf; +unsigned len; +u32 opcode; +u32 arg; +unsigned flags; +}; + +static int mmc_send_cxd_data (struct mmc_host *host,struct mmc_cxd *cxd) {struct mmc_request mrq;struct mmc_command cmd;struct mmc_data data;struct scatterlist sg; -BUG_ON (!card); -BUG_ON (!card->host); -BUG_ON (!ext_csd); -memset (&mrq,0 ,sizeof (struct mmc_request ));memset (&cmd,0 ,sizeof (struct mmc_command ));memset (&data,0 ,sizeof (struct mmc_data ));
@@ -256,21 +251,22 @@ int mmc_send_ext_csd(struct mmc_card *ca mrq.cmd = &cmd; mrq.data = &data; - cmd.opcode =MMC_SEND_EXT_CSD ; - cmd.arg =0 ; - cmd.flags =MMC_RSP_R1 |MMC_CMD_ADTC ; + cmd.opcode = cxd->opcode; + cmd.arg = cxd->arg; + cmd.flags = cxd->flags; - data.blksz =512 ; + data.blksz = cxd->len; data.blocks =1 ; data.flags =MMC_DATA_READ ; data.sg = &sg; data.sg_len =1 ; -sg_init_one (&sg, ext_csd,512 ); +sg_init_one (&sg, cxd->buf, cxd->len); -mmc_set_data_timeout (&data, card,0 ); +if (cxd->card) +mmc_set_data_timeout (&data, cxd->card,0 ); -mmc_wait_for_req (card->host, &mrq); +mmc_wait_for_req (host, &mrq);if (cmd.error !=MMC_ERR_NONE )return cmd.error;
@@ -280,6 +276,55 @@ int mmc_send_ext_csd(struct mmc_card *careturn MMC_ERR_NONE ; } +int mmc_send_csd (struct mmc_card *card,u32 *csd) +{ +struct mmc_cxd cxd; + +if (!mmc_host_is_spi (card->host)) +return mmc_send_cxd_native (card->host, card->rca, + csd,MMC_SEND_CSD ); + + cxd.card = card; + cxd.buf = csd; + cxd.len =16 ; + cxd.opcode =MMC_SEND_CSD ; + cxd.arg =0 ; + cxd.flags =MMC_RSP_SPI_R1 ; + +return mmc_send_cxd_data (card->host, &cxd); +} + +int mmc_spi_send_cid (struct mmc_host *host,u32 *cid) +{ +struct mmc_cxd cxd; + +if (!mmc_host_is_spi (host)) +return mmc_send_cxd_native (host,0 , cid,MMC_SEND_CID ); + + cxd.card =NULL ; + cxd.buf = cid; + cxd.len =16 ; + cxd.opcode =MMC_SEND_CID ; + cxd.arg =0 ; + cxd.flags =MMC_RSP_SPI_R1 ; + +return mmc_send_cxd_data (host, &cxd); +} + +int mmc_send_ext_csd (struct mmc_card *card,u8 *ext_csd) +{ +struct mmc_cxd cxd; + + cxd.card = card; + cxd.buf = ext_csd; + cxd.len =512 ; + cxd.opcode =MMC_SEND_EXT_CSD ; + cxd.arg =0 ; + cxd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; + +return mmc_send_cxd_data (card->host, &cxd); +} +int mmc_switch (struct mmc_card *card,u8 set,u8 index,u8 value) {int err;
drivers/mmc/host/mmc_spi.c +0 -59
82 lines not on this page · raw message
include/linux/mmc/core.h +2 -6
@@ -53,19 +53,15 @@ struct mmc_command {/* * These are the SPI response types. Commands return R1, with maybe -* more info. Commands like SEND_CSD return a data block too, which -* we call 'R1D'. Zero is an invalid type, meaning that the caller +* more info. Zero is an invalid type, meaning that the caller * forgot to say which response type applies to this command. -* -* FIXME remove R1D; update SEND_CxD in the core. */ #define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1)#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_BUSY)#define MMC_RSP_SPI_R2 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)#define MMC_RSP_SPI_R3 (MMC_RSP_SPI_S1|MMC_RSP_SPI_OCR) -#define MMC_RSP_SPI_R1D (MMC_RSP_SPI_S1|MMC_RSP_136) -#define mmc_spi_resp_type (cmd) ((cmd)->flags & (MMC_RSP_SPI_S1|MMC_RSP_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_OCR|MMC_RSP_136)) +#define mmc_spi_resp_type (cmd) ((cmd)->flags & (MMC_RSP_SPI_S1|MMC_RSP_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_OCR))/* * These are the command types.
drivers/mmc/core/mmc.c +1 -1
@@ -325,7 +325,7 @@ static int mmc_sd_init_card(struct mmc_hif (err !=MMC_ERR_NONE ) goto free_card; -if (!oldcard && !mmc_host_is_spi (host)) { +if (!oldcard) {/* * Fetch and process extended CSD. */
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Re: [patch 2.6.22-rc4 8/7] mmc_spi cid/csd/ext_csd updates, CRCs on
In reply to a message not in the archiveQuoted 18 lines · David Brownell
Fix some of the "register"/descriptor access glitches in the preceding patches:
- Updated internal routines:
* previousmmc_send_cxd()renamed tommc_send_cxd_native(); it uses native "R2" responses, which include 16 bytes of data.
* previousmmc_send_ext_csd()becomes newmmc_send_cxd_data()helper for command-and-data access- Modified
mmc_send_ext_csd()now usesmmc_send_cxd_data()helper- New
mmc_send_csd()andmmc_spi_send_cid()routines now use oneof those helper routines based on whether they're native or SPI;- Remove ugly "R1D" response pseudo-type for SPI
- Make it OK for MMC cards to try
SEND_EXT_CSD; v4+ needs that
Quoted 7 lines
- Turn CRCs back on by default with the SPI protocol
So this resolves most of the technical issues I know about, leaving nontechnical ones like "is this code clean enough" or "is this how we want to solve that problem".
Signed-off-by David Brownell <[email protected]>
Instead of me reviewing the broken set of patches, can you merge these fixes in and resend the set?
Rgds
Signature · 11 lines
-- Pierre Ossman Linux kernel, MMC maintainer http://www.kernel.org PulseAudio, core developer http://pulseaudio.org rdesktop, core developer http://www.rdesktop.org ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Re: [patch 2.6.22-rc4 8/7] mmc_spi cid/csd/ext_csd updates, CRCs on
In reply to a message not in the archiveQuoted 2 lines · Pierre Ossman
Instead of me reviewing the broken set of patches, can you merge these fixes in and resend the set?
Well, "broken" is a bit excessive. :)
But I'll send an update against rc4 plus two patches now found in the MM tree: git-mmc (notable change, the card lock/unlock facility), and the crc7 patch.
- Dave
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/