2 * linux/drivers/mmc/core/mmc_ops.h
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/types.h>
13 #if 1 // add by VIctor Yu. 12-02-2008
14 #include <linux/pagemap.h>
16 #include <asm/scatterlist.h>
17 #include <linux/scatterlist.h>
19 #include <linux/mmc/host.h>
20 #include <linux/mmc/card.h>
21 #include <linux/mmc/mmc.h>
26 static int _mmc_select_card(struct mmc_host
*host
, struct mmc_card
*card
)
29 struct mmc_command cmd
;
33 memset(&cmd
, 0, sizeof(struct mmc_command
));
35 cmd
.opcode
= MMC_SELECT_CARD
;
38 cmd
.arg
= card
->rca
<< 16;
39 cmd
.flags
= MMC_RSP_R1
| MMC_CMD_AC
;
42 cmd
.flags
= MMC_RSP_NONE
| MMC_CMD_AC
;
45 err
= mmc_wait_for_cmd(host
, &cmd
, MMC_CMD_RETRIES
);
46 if (err
!= MMC_ERR_NONE
)
52 int mmc_select_card(struct mmc_card
*card
)
56 return _mmc_select_card(card
->host
, card
);
59 int mmc_deselect_cards(struct mmc_host
*host
)
61 return _mmc_select_card(host
, NULL
);
64 int mmc_go_idle(struct mmc_host
*host
)
67 struct mmc_command cmd
;
69 mmc_set_chip_select(host
, MMC_CS_HIGH
);
73 memset(&cmd
, 0, sizeof(struct mmc_command
));
75 cmd
.opcode
= MMC_GO_IDLE_STATE
;
77 cmd
.flags
= MMC_RSP_NONE
| MMC_CMD_BC
;
79 err
= mmc_wait_for_cmd(host
, &cmd
, 0);
83 mmc_set_chip_select(host
, MMC_CS_DONTCARE
);
90 int mmc_send_op_cond(struct mmc_host
*host
, u32 ocr
, u32
*rocr
)
92 struct mmc_command cmd
;
97 memset(&cmd
, 0, sizeof(struct mmc_command
));
99 cmd
.opcode
= MMC_SEND_OP_COND
;
101 cmd
.flags
= MMC_RSP_R3
| MMC_CMD_BCR
;
103 for (i
= 100; i
; i
--) {
104 err
= mmc_wait_for_cmd(host
, &cmd
, 0);
105 if (err
!= MMC_ERR_NONE
)
108 if (cmd
.resp
[0] & MMC_CARD_BUSY
|| ocr
== 0)
111 err
= MMC_ERR_TIMEOUT
;
122 int mmc_all_send_cid(struct mmc_host
*host
, u32
*cid
)
125 struct mmc_command cmd
;
130 memset(&cmd
, 0, sizeof(struct mmc_command
));
132 cmd
.opcode
= MMC_ALL_SEND_CID
;
134 cmd
.flags
= MMC_RSP_R2
| MMC_CMD_BCR
;
136 err
= mmc_wait_for_cmd(host
, &cmd
, MMC_CMD_RETRIES
);
137 if (err
!= MMC_ERR_NONE
)
140 memcpy(cid
, cmd
.resp
, sizeof(u32
) * 4);
145 int mmc_set_relative_addr(struct mmc_card
*card
)
148 struct mmc_command cmd
;
153 memset(&cmd
, 0, sizeof(struct mmc_command
));
155 cmd
.opcode
= MMC_SET_RELATIVE_ADDR
;
156 cmd
.arg
= card
->rca
<< 16;
157 cmd
.flags
= MMC_RSP_R1
| MMC_CMD_AC
;
159 err
= mmc_wait_for_cmd(card
->host
, &cmd
, MMC_CMD_RETRIES
);
160 if (err
!= MMC_ERR_NONE
)
166 int mmc_send_csd(struct mmc_card
*card
, u32
*csd
)
169 struct mmc_command cmd
;
175 memset(&cmd
, 0, sizeof(struct mmc_command
));
177 cmd
.opcode
= MMC_SEND_CSD
;
178 cmd
.arg
= card
->rca
<< 16;
179 cmd
.flags
= MMC_RSP_R2
| MMC_CMD_AC
;
181 err
= mmc_wait_for_cmd(card
->host
, &cmd
, MMC_CMD_RETRIES
);
182 if (err
!= MMC_ERR_NONE
)
185 memcpy(csd
, cmd
.resp
, sizeof(u32
) * 4);
190 int mmc_send_ext_csd(struct mmc_card
*card
, u8
*ext_csd
)
192 struct mmc_request mrq
;
193 struct mmc_command cmd
;
194 struct mmc_data data
;
195 struct scatterlist sg
;
201 memset(&mrq
, 0, sizeof(struct mmc_request
));
202 memset(&cmd
, 0, sizeof(struct mmc_command
));
203 memset(&data
, 0, sizeof(struct mmc_data
));
208 cmd
.opcode
= MMC_SEND_EXT_CSD
;
210 cmd
.flags
= MMC_RSP_R1
| MMC_CMD_ADTC
;
214 data
.flags
= MMC_DATA_READ
;
218 sg_init_one(&sg
, ext_csd
, 512);
220 mmc_set_data_timeout(&data
, card
, 0);
222 mmc_wait_for_req(card
->host
, &mrq
);
224 if (cmd
.error
!= MMC_ERR_NONE
)
226 if (data
.error
!= MMC_ERR_NONE
)
232 int mmc_switch(struct mmc_card
*card
, u8 set
, u8 index
, u8 value
)
235 struct mmc_command cmd
;
240 memset(&cmd
, 0, sizeof(struct mmc_command
));
242 cmd
.opcode
= MMC_SWITCH
;
243 cmd
.arg
= (MMC_SWITCH_MODE_WRITE_BYTE
<< 24) |
247 cmd
.flags
= MMC_RSP_R1B
| MMC_CMD_AC
;
249 err
= mmc_wait_for_cmd(card
->host
, &cmd
, MMC_CMD_RETRIES
);
250 if (err
!= MMC_ERR_NONE
)
256 int mmc_send_status(struct mmc_card
*card
, u32
*status
)
259 struct mmc_command cmd
;
264 memset(&cmd
, 0, sizeof(struct mmc_command
));
266 cmd
.opcode
= MMC_SEND_STATUS
;
267 cmd
.arg
= card
->rca
<< 16;
268 cmd
.flags
= MMC_RSP_R1
| MMC_CMD_AC
;
270 err
= mmc_wait_for_cmd(card
->host
, &cmd
, MMC_CMD_RETRIES
);
271 if (err
!= MMC_ERR_NONE
)
275 *status
= cmd
.resp
[0];