Skip to content

Commit b2bcc79

Browse files
author
Pierre Ossman
committed
mmc: implement SDIO IO_RW_DIRECT operation
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
1 parent 5c4e6f1 commit b2bcc79

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

‎drivers/mmc/core/sdio_ops.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <linux/mmc/host.h>
13+
#include <linux/mmc/card.h>
1314
#include <linux/mmc/mmc.h>
1415
#include <linux/mmc/sdio.h>
1516

@@ -47,3 +48,39 @@ int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
4748
return err;
4849
}
4950

51+
int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
52+
unsigned addr, u8 in, u8* out)
53+
{
54+
struct mmc_command cmd;
55+
int err;
56+
57+
BUG_ON(!card);
58+
BUG_ON(fn > 7);
59+
60+
memset(&cmd, 0, sizeof(struct mmc_command));
61+
62+
cmd.opcode = SD_IO_RW_DIRECT;
63+
cmd.arg = write ? 0x80000000 : 0x00000000;
64+
cmd.arg |= fn << 28;
65+
cmd.arg |= (write && out) ? 0x08000000 : 0x00000000;
66+
cmd.arg |= addr << 9;
67+
cmd.arg |= in;
68+
cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
69+
70+
err = mmc_wait_for_cmd(card->host, &cmd, 0);
71+
if (err)
72+
return err;
73+
74+
if (cmd.resp[0] & R5_ERROR)
75+
return -EIO;
76+
if (cmd.resp[0] & R5_FUNCTION_NUMBER)
77+
return -EINVAL;
78+
if (cmd.resp[0] & R5_OUT_OF_RANGE)
79+
return -ERANGE;
80+
81+
if (out)
82+
*out = cmd.resp[0] & 0xFF;
83+
84+
return 0;
85+
}
86+

‎drivers/mmc/core/sdio_ops.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#define _MMC_SDIO_OPS_H
1414

1515
int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
16+
int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
17+
unsigned addr, u8 in, u8* out);
1618

1719
#endif
1820

‎include/linux/mmc/core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct mmc_command {
4242
#define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
4343
#define MMC_RSP_R3 (MMC_RSP_PRESENT)
4444
#define MMC_RSP_R4 (MMC_RSP_PRESENT)
45+
#define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
4546
#define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
4647
#define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
4748

‎include/linux/mmc/sdio.h‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,40 @@
1414

1515
/* SDIO commands type argument response */
1616
#define SD_IO_SEND_OP_COND 5 /* bcr [23:0] OCR R4 */
17+
#define SD_IO_RW_DIRECT 52 /* ac [31:0] See below R5 */
18+
19+
/*
20+
* SD_IO_RW_DIRECT argument format:
21+
*
22+
* [31] R/W flag
23+
* [30:28] Function number
24+
* [27] RAW flag
25+
* [25:9] Register address
26+
* [7:0] Data
27+
*/
28+
29+
/*
30+
SDIO status in R5
31+
Type
32+
e : error bit
33+
s : status bit
34+
r : detected and set for the actual command response
35+
x : detected and set during command execution. the host must poll
36+
the card by sending status command in order to read these bits.
37+
Clear condition
38+
a : according to the card state
39+
b : always related to the previous command. Reception of
40+
a valid command will clear it (with a delay of one command)
41+
c : clear by read
42+
*/
43+
44+
#define R5_COM_CRC_ERROR (1 << 15) /* er, b */
45+
#define R5_ILLEGAL_COMMAND (1 << 14) /* er, b */
46+
#define R5_ERROR (1 << 11) /* erx, c */
47+
#define R5_FUNCTION_NUMBER (1 << 9) /* er, c */
48+
#define R5_OUT_OF_RANGE (1 << 8) /* er, c */
49+
#define R5_STATUS(x) (x & 0xCB00)
50+
#define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12) /* s, b */
1751

1852
#endif
1953

0 commit comments

Comments
 (0)