2 * linux/drivers/mmc/sdio_ops.c
4 * Copyright 2006-2007 Pierre Ossman
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
12 #include <linux/scatterlist.h>
14 #include <linux/mmc/host.h>
15 #include <linux/mmc/card.h>
16 #include <linux/mmc/mmc.h>
17 #include <linux/mmc/sdio.h>
22 int mmc_send_io_op_cond(struct mmc_host
*host
, u32 ocr
, u32
*rocr
)
24 struct mmc_command cmd
;
29 memset(&cmd
, 0, sizeof(struct mmc_command
));
31 cmd
.opcode
= SD_IO_SEND_OP_COND
;
33 cmd
.flags
= MMC_RSP_SPI_R4
| MMC_RSP_R4
| MMC_CMD_BCR
;
35 for (i
= 100; i
; i
--) {
36 err
= mmc_wait_for_cmd(host
, &cmd
, MMC_CMD_RETRIES
);
40 /* if we're just probing, do a single pass */
44 /* otherwise wait until reset completes */
45 if (mmc_host_is_spi(host
)) {
47 * Both R1_SPI_IDLE and MMC_CARD_BUSY indicate
48 * an initialized card under SPI, but some cards
49 * (Marvell's) only behave when looking at this
52 if (cmd
.resp
[1] & MMC_CARD_BUSY
)
55 if (cmd
.resp
[0] & MMC_CARD_BUSY
)
65 *rocr
= cmd
.resp
[mmc_host_is_spi(host
) ? 1 : 0];
70 int mmc_io_rw_direct(struct mmc_card
*card
, int write
, unsigned fn
,
71 unsigned addr
, u8 in
, u8
* out
)
73 struct mmc_command cmd
;
83 memset(&cmd
, 0, sizeof(struct mmc_command
));
85 cmd
.opcode
= SD_IO_RW_DIRECT
;
86 cmd
.arg
= write
? 0x80000000 : 0x00000000;
88 cmd
.arg
|= (write
&& out
) ? 0x08000000 : 0x00000000;
91 cmd
.flags
= MMC_RSP_SPI_R5
| MMC_RSP_R5
| MMC_CMD_AC
;
93 err
= mmc_wait_for_cmd(card
->host
, &cmd
, 0);
97 if (mmc_host_is_spi(card
->host
)) {
98 /* host driver already reported errors */
100 if (cmd
.resp
[0] & R5_ERROR
)
102 if (cmd
.resp
[0] & R5_FUNCTION_NUMBER
)
104 if (cmd
.resp
[0] & R5_OUT_OF_RANGE
)
109 if (mmc_host_is_spi(card
->host
))
110 *out
= (cmd
.resp
[0] >> 8) & 0xFF;
112 *out
= cmd
.resp
[0] & 0xFF;
118 int mmc_io_rw_extended(struct mmc_card
*card
, int write
, unsigned fn
,
119 unsigned addr
, int incr_addr
, u8
*buf
, unsigned blocks
, unsigned blksz
)
121 struct mmc_request mrq
;
122 struct mmc_command cmd
;
123 struct mmc_data data
;
124 struct scatterlist sg
;
128 BUG_ON(blocks
== 1 && blksz
> 512);
129 WARN_ON(blocks
== 0);
136 memset(&mrq
, 0, sizeof(struct mmc_request
));
137 memset(&cmd
, 0, sizeof(struct mmc_command
));
138 memset(&data
, 0, sizeof(struct mmc_data
));
143 cmd
.opcode
= SD_IO_RW_EXTENDED
;
144 cmd
.arg
= write
? 0x80000000 : 0x00000000;
146 cmd
.arg
|= incr_addr
? 0x04000000 : 0x00000000;
147 cmd
.arg
|= addr
<< 9;
148 if (blocks
== 1 && blksz
<= 512)
149 cmd
.arg
|= (blksz
== 512) ? 0 : blksz
; /* byte mode */
151 cmd
.arg
|= 0x08000000 | blocks
; /* block mode */
152 cmd
.flags
= MMC_RSP_SPI_R5
| MMC_RSP_R5
| MMC_CMD_ADTC
;
155 data
.blocks
= blocks
;
156 data
.flags
= write
? MMC_DATA_WRITE
: MMC_DATA_READ
;
160 sg_init_one(&sg
, buf
, blksz
* blocks
);
162 mmc_set_data_timeout(&data
, card
);
164 mmc_wait_for_req(card
->host
, &mrq
);
171 if (mmc_host_is_spi(card
->host
)) {
172 /* host driver already reported errors */
174 if (cmd
.resp
[0] & R5_ERROR
)
176 if (cmd
.resp
[0] & R5_FUNCTION_NUMBER
)
178 if (cmd
.resp
[0] & R5_OUT_OF_RANGE
)