Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 1 | /* |
Pierre Ossman | 70f1048 | 2007-07-11 20:04:50 +0200 | [diff] [blame] | 2 | * linux/drivers/mmc/core/mmc_ops.h |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2006-2007 Pierre Ossman |
| 5 | * |
| 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. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/types.h> |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 13 | #include <linux/scatterlist.h> |
| 14 | |
| 15 | #include <linux/mmc/host.h> |
| 16 | #include <linux/mmc/card.h> |
| 17 | #include <linux/mmc/mmc.h> |
| 18 | |
| 19 | #include "core.h" |
| 20 | #include "mmc_ops.h" |
| 21 | |
| 22 | static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card) |
| 23 | { |
| 24 | int err; |
| 25 | struct mmc_command cmd; |
| 26 | |
| 27 | BUG_ON(!host); |
| 28 | |
| 29 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 30 | |
| 31 | cmd.opcode = MMC_SELECT_CARD; |
| 32 | |
| 33 | if (card) { |
| 34 | cmd.arg = card->rca << 16; |
| 35 | cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; |
| 36 | } else { |
| 37 | cmd.arg = 0; |
| 38 | cmd.flags = MMC_RSP_NONE | MMC_CMD_AC; |
| 39 | } |
| 40 | |
| 41 | err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 42 | if (err) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 43 | return err; |
| 44 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 45 | return 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | int mmc_select_card(struct mmc_card *card) |
| 49 | { |
| 50 | BUG_ON(!card); |
| 51 | |
| 52 | return _mmc_select_card(card->host, card); |
| 53 | } |
| 54 | |
| 55 | int mmc_deselect_cards(struct mmc_host *host) |
| 56 | { |
| 57 | return _mmc_select_card(host, NULL); |
| 58 | } |
| 59 | |
Jarkko Lavinen | b1ebe38 | 2009-09-22 16:44:34 -0700 | [diff] [blame^] | 60 | int mmc_card_sleepawake(struct mmc_host *host, int sleep) |
| 61 | { |
| 62 | struct mmc_command cmd; |
| 63 | struct mmc_card *card = host->card; |
| 64 | int err; |
| 65 | |
| 66 | if (sleep) |
| 67 | mmc_deselect_cards(host); |
| 68 | |
| 69 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 70 | |
| 71 | cmd.opcode = MMC_SLEEP_AWAKE; |
| 72 | cmd.arg = card->rca << 16; |
| 73 | if (sleep) |
| 74 | cmd.arg |= 1 << 15; |
| 75 | |
| 76 | cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; |
| 77 | err = mmc_wait_for_cmd(host, &cmd, 0); |
| 78 | if (err) |
| 79 | return err; |
| 80 | |
| 81 | /* |
| 82 | * If the host does not wait while the card signals busy, then we will |
| 83 | * will have to wait the sleep/awake timeout. Note, we cannot use the |
| 84 | * SEND_STATUS command to poll the status because that command (and most |
| 85 | * others) is invalid while the card sleeps. |
| 86 | */ |
| 87 | if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) |
| 88 | mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); |
| 89 | |
| 90 | if (!sleep) |
| 91 | err = mmc_select_card(card); |
| 92 | |
| 93 | return err; |
| 94 | } |
| 95 | |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 96 | int mmc_go_idle(struct mmc_host *host) |
| 97 | { |
| 98 | int err; |
| 99 | struct mmc_command cmd; |
| 100 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 101 | /* |
| 102 | * Non-SPI hosts need to prevent chipselect going active during |
| 103 | * GO_IDLE; that would put chips into SPI mode. Remind them of |
| 104 | * that in case of hardware that won't pull up DAT3/nCS otherwise. |
| 105 | * |
| 106 | * SPI hosts ignore ios.chip_select; it's managed according to |
| 107 | * rules that must accomodate non-MMC slaves which this layer |
| 108 | * won't even know about. |
| 109 | */ |
| 110 | if (!mmc_host_is_spi(host)) { |
| 111 | mmc_set_chip_select(host, MMC_CS_HIGH); |
| 112 | mmc_delay(1); |
| 113 | } |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 114 | |
| 115 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 116 | |
| 117 | cmd.opcode = MMC_GO_IDLE_STATE; |
| 118 | cmd.arg = 0; |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 119 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_NONE | MMC_CMD_BC; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 120 | |
| 121 | err = mmc_wait_for_cmd(host, &cmd, 0); |
| 122 | |
| 123 | mmc_delay(1); |
| 124 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 125 | if (!mmc_host_is_spi(host)) { |
| 126 | mmc_set_chip_select(host, MMC_CS_DONTCARE); |
| 127 | mmc_delay(1); |
| 128 | } |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 129 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 130 | host->use_spi_crc = 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 131 | |
| 132 | return err; |
| 133 | } |
| 134 | |
| 135 | int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) |
| 136 | { |
| 137 | struct mmc_command cmd; |
| 138 | int i, err = 0; |
| 139 | |
| 140 | BUG_ON(!host); |
| 141 | |
| 142 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 143 | |
| 144 | cmd.opcode = MMC_SEND_OP_COND; |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 145 | cmd.arg = mmc_host_is_spi(host) ? 0 : ocr; |
| 146 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 147 | |
| 148 | for (i = 100; i; i--) { |
| 149 | err = mmc_wait_for_cmd(host, &cmd, 0); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 150 | if (err) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 151 | break; |
| 152 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 153 | /* if we're just probing, do a single pass */ |
| 154 | if (ocr == 0) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 155 | break; |
| 156 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 157 | /* otherwise wait until reset completes */ |
| 158 | if (mmc_host_is_spi(host)) { |
| 159 | if (!(cmd.resp[0] & R1_SPI_IDLE)) |
| 160 | break; |
| 161 | } else { |
| 162 | if (cmd.resp[0] & MMC_CARD_BUSY) |
| 163 | break; |
| 164 | } |
| 165 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 166 | err = -ETIMEDOUT; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 167 | |
| 168 | mmc_delay(10); |
| 169 | } |
| 170 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 171 | if (rocr && !mmc_host_is_spi(host)) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 172 | *rocr = cmd.resp[0]; |
| 173 | |
| 174 | return err; |
| 175 | } |
| 176 | |
| 177 | int mmc_all_send_cid(struct mmc_host *host, u32 *cid) |
| 178 | { |
| 179 | int err; |
| 180 | struct mmc_command cmd; |
| 181 | |
| 182 | BUG_ON(!host); |
| 183 | BUG_ON(!cid); |
| 184 | |
| 185 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 186 | |
| 187 | cmd.opcode = MMC_ALL_SEND_CID; |
| 188 | cmd.arg = 0; |
| 189 | cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR; |
| 190 | |
| 191 | err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 192 | if (err) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 193 | return err; |
| 194 | |
| 195 | memcpy(cid, cmd.resp, sizeof(u32) * 4); |
| 196 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 197 | return 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | int mmc_set_relative_addr(struct mmc_card *card) |
| 201 | { |
| 202 | int err; |
| 203 | struct mmc_command cmd; |
| 204 | |
| 205 | BUG_ON(!card); |
| 206 | BUG_ON(!card->host); |
| 207 | |
| 208 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 209 | |
| 210 | cmd.opcode = MMC_SET_RELATIVE_ADDR; |
| 211 | cmd.arg = card->rca << 16; |
| 212 | cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; |
| 213 | |
| 214 | err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 215 | if (err) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 216 | return err; |
| 217 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 218 | return 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 219 | } |
| 220 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 221 | static int |
| 222 | mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 223 | { |
| 224 | int err; |
| 225 | struct mmc_command cmd; |
| 226 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 227 | BUG_ON(!host); |
| 228 | BUG_ON(!cxd); |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 229 | |
| 230 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 231 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 232 | cmd.opcode = opcode; |
| 233 | cmd.arg = arg; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 234 | cmd.flags = MMC_RSP_R2 | MMC_CMD_AC; |
| 235 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 236 | err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 237 | if (err) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 238 | return err; |
| 239 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 240 | memcpy(cxd, cmd.resp, sizeof(u32) * 4); |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 241 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 242 | return 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 243 | } |
| 244 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 245 | static int |
| 246 | mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host, |
| 247 | u32 opcode, void *buf, unsigned len) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 248 | { |
| 249 | struct mmc_request mrq; |
| 250 | struct mmc_command cmd; |
| 251 | struct mmc_data data; |
| 252 | struct scatterlist sg; |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 253 | void *data_buf; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 254 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 255 | /* dma onto stack is unsafe/nonportable, but callers to this |
| 256 | * routine normally provide temporary on-stack buffers ... |
| 257 | */ |
| 258 | data_buf = kmalloc(len, GFP_KERNEL); |
| 259 | if (data_buf == NULL) |
| 260 | return -ENOMEM; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 261 | |
| 262 | memset(&mrq, 0, sizeof(struct mmc_request)); |
| 263 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 264 | memset(&data, 0, sizeof(struct mmc_data)); |
| 265 | |
| 266 | mrq.cmd = &cmd; |
| 267 | mrq.data = &data; |
| 268 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 269 | cmd.opcode = opcode; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 270 | cmd.arg = 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 271 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 272 | /* NOTE HACK: the MMC_RSP_SPI_R1 is always correct here, but we |
| 273 | * rely on callers to never use this with "native" calls for reading |
| 274 | * CSD or CID. Native versions of those commands use the R2 type, |
| 275 | * not R1 plus a data block. |
| 276 | */ |
| 277 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
| 278 | |
| 279 | data.blksz = len; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 280 | data.blocks = 1; |
| 281 | data.flags = MMC_DATA_READ; |
| 282 | data.sg = &sg; |
| 283 | data.sg_len = 1; |
| 284 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 285 | sg_init_one(&sg, data_buf, len); |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 286 | |
Adrian Hunter | cda56ac | 2009-02-10 16:32:33 +0200 | [diff] [blame] | 287 | if (opcode == MMC_SEND_CSD || opcode == MMC_SEND_CID) { |
| 288 | /* |
| 289 | * The spec states that CSR and CID accesses have a timeout |
| 290 | * of 64 clock cycles. |
| 291 | */ |
| 292 | data.timeout_ns = 0; |
| 293 | data.timeout_clks = 64; |
| 294 | } else |
| 295 | mmc_set_data_timeout(&data, card); |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 296 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 297 | mmc_wait_for_req(host, &mrq); |
| 298 | |
| 299 | memcpy(buf, data_buf, len); |
| 300 | kfree(data_buf); |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 301 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 302 | if (cmd.error) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 303 | return cmd.error; |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 304 | if (data.error) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 305 | return data.error; |
| 306 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 307 | return 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 308 | } |
| 309 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 310 | int mmc_send_csd(struct mmc_card *card, u32 *csd) |
| 311 | { |
Pierre Ossman | 78e4807 | 2007-10-27 14:14:23 +0200 | [diff] [blame] | 312 | int ret, i; |
| 313 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 314 | if (!mmc_host_is_spi(card->host)) |
| 315 | return mmc_send_cxd_native(card->host, card->rca << 16, |
| 316 | csd, MMC_SEND_CSD); |
| 317 | |
Pierre Ossman | 78e4807 | 2007-10-27 14:14:23 +0200 | [diff] [blame] | 318 | ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16); |
| 319 | if (ret) |
| 320 | return ret; |
| 321 | |
| 322 | for (i = 0;i < 4;i++) |
| 323 | csd[i] = be32_to_cpu(csd[i]); |
| 324 | |
| 325 | return 0; |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | int mmc_send_cid(struct mmc_host *host, u32 *cid) |
| 329 | { |
Pierre Ossman | 78e4807 | 2007-10-27 14:14:23 +0200 | [diff] [blame] | 330 | int ret, i; |
| 331 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 332 | if (!mmc_host_is_spi(host)) { |
| 333 | if (!host->card) |
| 334 | return -EINVAL; |
| 335 | return mmc_send_cxd_native(host, host->card->rca << 16, |
| 336 | cid, MMC_SEND_CID); |
| 337 | } |
| 338 | |
Pierre Ossman | 78e4807 | 2007-10-27 14:14:23 +0200 | [diff] [blame] | 339 | ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16); |
| 340 | if (ret) |
| 341 | return ret; |
| 342 | |
| 343 | for (i = 0;i < 4;i++) |
| 344 | cid[i] = be32_to_cpu(cid[i]); |
| 345 | |
| 346 | return 0; |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd) |
| 350 | { |
| 351 | return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD, |
| 352 | ext_csd, 512); |
| 353 | } |
| 354 | |
| 355 | int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp) |
| 356 | { |
| 357 | struct mmc_command cmd; |
| 358 | int err; |
| 359 | |
| 360 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 361 | |
| 362 | cmd.opcode = MMC_SPI_READ_OCR; |
| 363 | cmd.arg = highcap ? (1 << 30) : 0; |
| 364 | cmd.flags = MMC_RSP_SPI_R3; |
| 365 | |
| 366 | err = mmc_wait_for_cmd(host, &cmd, 0); |
| 367 | |
| 368 | *ocrp = cmd.resp[1]; |
| 369 | return err; |
| 370 | } |
| 371 | |
| 372 | int mmc_spi_set_crc(struct mmc_host *host, int use_crc) |
| 373 | { |
| 374 | struct mmc_command cmd; |
| 375 | int err; |
| 376 | |
| 377 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 378 | |
| 379 | cmd.opcode = MMC_SPI_CRC_ON_OFF; |
| 380 | cmd.flags = MMC_RSP_SPI_R1; |
| 381 | cmd.arg = use_crc; |
| 382 | |
| 383 | err = mmc_wait_for_cmd(host, &cmd, 0); |
| 384 | if (!err) |
| 385 | host->use_spi_crc = use_crc; |
| 386 | return err; |
| 387 | } |
| 388 | |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 389 | int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value) |
| 390 | { |
| 391 | int err; |
| 392 | struct mmc_command cmd; |
| 393 | |
| 394 | BUG_ON(!card); |
| 395 | BUG_ON(!card->host); |
| 396 | |
| 397 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 398 | |
| 399 | cmd.opcode = MMC_SWITCH; |
| 400 | cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | |
| 401 | (index << 16) | |
| 402 | (value << 8) | |
| 403 | set; |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 404 | cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 405 | |
| 406 | err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 407 | if (err) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 408 | return err; |
| 409 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 410 | return 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | int mmc_send_status(struct mmc_card *card, u32 *status) |
| 414 | { |
| 415 | int err; |
| 416 | struct mmc_command cmd; |
| 417 | |
| 418 | BUG_ON(!card); |
| 419 | BUG_ON(!card->host); |
| 420 | |
| 421 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 422 | |
| 423 | cmd.opcode = MMC_SEND_STATUS; |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 424 | if (!mmc_host_is_spi(card->host)) |
| 425 | cmd.arg = card->rca << 16; |
| 426 | cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 427 | |
| 428 | err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 429 | if (err) |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 430 | return err; |
| 431 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 432 | /* NOTE: callers are required to understand the difference |
| 433 | * between "native" and SPI format status words! |
| 434 | */ |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 435 | if (status) |
| 436 | *status = cmd.resp[0]; |
| 437 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 438 | return 0; |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 439 | } |
| 440 | |