Skip to content

Commit 9701858

Browse files
David BrownellPierre Ossman
authored andcommitted
MMC headers learn about SPI
Teach the MMC/SD/SDIO system headers that some hosts use SPI mode - New host capabilities and status bits * MMC_CAP_SPI, with mmc_host_is_spi() test * mmc_host.use_spi_crc flag - 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. - Reorder a few mmc_host fields, removing several bytes of padding None of these changes affect current code. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
1 parent 759bdc7 commit 9701858

File tree

3 files changed

+67
-13
lines changed

3 files changed

+67
-13
lines changed

include/linux/mmc/core.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ struct mmc_command {
2525
#define MMC_RSP_CRC (1 << 2) /* expect valid crc */
2626
#define MMC_RSP_BUSY (1 << 3) /* card may send busy */
2727
#define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
28-
#define MMC_CMD_MASK (3 << 5) /* command type */
28+
29+
#define MMC_CMD_MASK (3 << 5) /* non-SPI command type */
2930
#define MMC_CMD_AC (0 << 5)
3031
#define MMC_CMD_ADTC (1 << 5)
3132
#define MMC_CMD_BC (2 << 5)
3233
#define MMC_CMD_BCR (3 << 5)
3334

35+
#define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */
36+
#define MMC_RSP_SPI_S2 (1 << 8) /* second byte */
37+
#define MMC_RSP_SPI_B4 (1 << 9) /* four data bytes */
38+
#define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */
39+
3440
/*
35-
* These are the response types, and correspond to valid bit
41+
* These are the native response types, and correspond to valid bit
3642
* patterns of the above flags. One additional valid pattern
3743
* is all zeros, which means we don't expect a response.
3844
*/
@@ -48,6 +54,22 @@ struct mmc_command {
4854

4955
#define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
5056

57+
/*
58+
* These are the SPI response types for MMC, SD, and SDIO cards.
59+
* Commands return R1, with maybe more info. Zero is an error type;
60+
* callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
61+
*/
62+
#define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1)
63+
#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
64+
#define MMC_RSP_SPI_R2 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
65+
#define MMC_RSP_SPI_R3 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
66+
#define MMC_RSP_SPI_R4 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
67+
#define MMC_RSP_SPI_R5 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
68+
#define MMC_RSP_SPI_R7 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
69+
70+
#define mmc_spi_resp_type(cmd) ((cmd)->flags & \
71+
(MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
72+
5173
/*
5274
* These are the command types.
5375
*/

include/linux/mmc/host.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct mmc_host {
9191
#define MMC_CAP_MMC_HIGHSPEED (1 << 2) /* Can do MMC high-speed timing */
9292
#define MMC_CAP_SD_HIGHSPEED (1 << 3) /* Can do SD high-speed timing */
9393
#define MMC_CAP_SDIO_IRQ (1 << 4) /* Can signal pending SDIO IRQs */
94+
#define MMC_CAP_SPI (1 << 5) /* Talks only SPI protocols */
9495

9596
/* host specific block data */
9697
unsigned int max_seg_size; /* see blk_queue_max_segment_size */
@@ -107,23 +108,26 @@ struct mmc_host {
107108
struct mmc_ios ios; /* current io bus settings */
108109
u32 ocr; /* the current OCR setting */
109110

111+
/* group bitfields together to minimize padding */
112+
unsigned int use_spi_crc:1;
113+
unsigned int claimed:1; /* host exclusively claimed */
114+
unsigned int bus_dead:1; /* bus has been released */
115+
#ifdef CONFIG_MMC_DEBUG
116+
unsigned int removed:1; /* host is being removed */
117+
#endif
118+
110119
unsigned int mode; /* current card mode of host */
111120
#define MMC_MODE_MMC 0
112121
#define MMC_MODE_SD 1
113122

114123
struct mmc_card *card; /* device attached to this host */
115124

116125
wait_queue_head_t wq;
117-
unsigned int claimed:1; /* host exclusively claimed */
118126

119127
struct delayed_work detect;
120-
#ifdef CONFIG_MMC_DEBUG
121-
unsigned int removed:1; /* host is being removed */
122-
#endif
123128

124129
const struct mmc_bus_ops *bus_ops; /* current bus driver */
125130
unsigned int bus_refs; /* reference counter */
126-
unsigned int bus_dead:1; /* bus has been released */
127131

128132
unsigned int sdio_irqs;
129133
struct task_struct *sdio_irq_thread;
@@ -142,6 +146,8 @@ static inline void *mmc_priv(struct mmc_host *host)
142146
return (void *)host->private;
143147
}
144148

149+
#define mmc_host_is_spi(host) ((host)->caps & MMC_CAP_SPI)
150+
145151
#define mmc_dev(x) ((x)->parent)
146152
#define mmc_classdev(x) (&(x)->class_dev)
147153
#define mmc_hostname(x) ((x)->class_dev.bus_id)

include/linux/mmc/mmc.h

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/* Standard MMC commands (4.1) type argument response */
2929
/* class 1 */
30-
#define MMC_GO_IDLE_STATE 0 /* bc */
30+
#define MMC_GO_IDLE_STATE 0 /* bc */
3131
#define MMC_SEND_OP_COND 1 /* bcr [31:0] OCR R3 */
3232
#define MMC_ALL_SEND_CID 2 /* bcr R2 */
3333
#define MMC_SET_RELATIVE_ADDR 3 /* ac [31:16] RCA R1 */
@@ -39,8 +39,10 @@
3939
#define MMC_SEND_CID 10 /* ac [31:16] RCA R2 */
4040
#define MMC_READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */
4141
#define MMC_STOP_TRANSMISSION 12 /* ac R1b */
42-
#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */
42+
#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */
4343
#define MMC_GO_INACTIVE_STATE 15 /* ac [31:16] RCA */
44+
#define MMC_SPI_READ_OCR 58 /* spi spi_R3 */
45+
#define MMC_SPI_CRC_ON_OFF 59 /* spi [0:0] flag spi_R1 */
4446

4547
/* class 2 */
4648
#define MMC_SET_BLOCKLEN 16 /* ac [31:0] block len R1 */
@@ -90,15 +92,15 @@
9092
*/
9193

9294
/*
93-
MMC status in R1
95+
MMC status in R1, for native mode (SPI bits are different)
9496
Type
95-
e : error bit
97+
e : error bit
9698
s : status bit
9799
r : detected and set for the actual command response
98100
x : detected and set during command execution. the host must poll
99101
the card by sending status command in order to read these bits.
100102
Clear condition
101-
a : according to the card state
103+
a : according to the card state
102104
b : always related to the previous command. Reception of
103105
a valid command will clear it (with a delay of one command)
104106
c : clear by read
@@ -124,10 +126,33 @@
124126
#define R1_CARD_ECC_DISABLED (1 << 14) /* sx, a */
125127
#define R1_ERASE_RESET (1 << 13) /* sr, c */
126128
#define R1_STATUS(x) (x & 0xFFFFE000)
127-
#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */
129+
#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */
128130
#define R1_READY_FOR_DATA (1 << 8) /* sx, a */
129131
#define R1_APP_CMD (1 << 5) /* sr, c */
130132

133+
/*
134+
* MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS
135+
* R1 is the low order byte; R2 is the next highest byte, when present.
136+
*/
137+
#define R1_SPI_IDLE (1 << 0)
138+
#define R1_SPI_ERASE_RESET (1 << 1)
139+
#define R1_SPI_ILLEGAL_COMMAND (1 << 2)
140+
#define R1_SPI_COM_CRC (1 << 3)
141+
#define R1_SPI_ERASE_SEQ (1 << 4)
142+
#define R1_SPI_ADDRESS (1 << 5)
143+
#define R1_SPI_PARAMETER (1 << 6)
144+
/* R1 bit 7 is always zero */
145+
#define R2_SPI_CARD_LOCKED (1 << 8)
146+
#define R2_SPI_WP_ERASE_SKIP (1 << 9) /* or lock/unlock fail */
147+
#define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP
148+
#define R2_SPI_ERROR (1 << 10)
149+
#define R2_SPI_CC_ERROR (1 << 11)
150+
#define R2_SPI_CARD_ECC_ERROR (1 << 12)
151+
#define R2_SPI_WP_VIOLATION (1 << 13)
152+
#define R2_SPI_ERASE_PARAM (1 << 14)
153+
#define R2_SPI_OUT_OF_RANGE (1 << 15) /* or CSD overwrite */
154+
#define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE
155+
131156
/* These are unpacked versions of the actual responses */
132157

133158
struct _mmc_csd {
@@ -182,6 +207,7 @@ struct _mmc_csd {
182207
*/
183208
#define CCC_BASIC (1<<0) /* (0) Basic protocol functions */
184209
/* (CMD0,1,2,3,4,7,9,10,12,13,15) */
210+
/* (and for SPI, CMD58,59) */
185211
#define CCC_STREAM_READ (1<<1) /* (1) Stream read commands */
186212
/* (CMD11) */
187213
#define CCC_BLOCK_READ (1<<2) /* (2) Block read commands */

0 commit comments

Comments
 (0)