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 <asm/scatterlist.h>
13 #include <linux/scatterlist.h>
15 #include <linux/mmc/host.h>
16 #include <linux/mmc/card.h>
17 #include <linux/mmc/mmc.h>
18 #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_R4 | MMC_CMD_BCR;
35 for (i = 100; i; i--) {
36 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
40 if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
54 int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
55 unsigned addr, u8 in, u8* out)
57 struct mmc_command cmd;
63 memset(&cmd, 0, sizeof(struct mmc_command));
65 cmd.opcode = SD_IO_RW_DIRECT;
66 cmd.arg = write ? 0x80000000 : 0x00000000;
68 cmd.arg |= (write && out) ? 0x08000000 : 0x00000000;
71 cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
73 err = mmc_wait_for_cmd(card->host, &cmd, 0);
77 if (cmd.resp[0] & R5_ERROR)
79 if (cmd.resp[0] & R5_FUNCTION_NUMBER)
81 if (cmd.resp[0] & R5_OUT_OF_RANGE)
85 *out = cmd.resp[0] & 0xFF;
90 int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
91 unsigned addr, int bang, u8 *buf, unsigned size)
93 struct mmc_request mrq;
94 struct mmc_command cmd;
96 struct scatterlist sg;
102 memset(&mrq, 0, sizeof(struct mmc_request));
103 memset(&cmd, 0, sizeof(struct mmc_command));
104 memset(&data, 0, sizeof(struct mmc_data));
109 cmd.opcode = SD_IO_RW_EXTENDED;
110 cmd.arg = write ? 0x80000000 : 0x00000000;
112 cmd.arg |= bang ? 0x00000000 : 0x04000000;
113 cmd.arg |= addr << 9;
114 cmd.arg |= (size == 512) ? 0 : size;
115 cmd.flags = MMC_RSP_R5 | MMC_CMD_ADTC;
119 data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
123 sg_init_one(&sg, buf, size);
125 mmc_set_data_timeout(&data, card);
127 mmc_wait_for_req(card->host, &mrq);
134 if (cmd.resp[0] & R5_ERROR)
136 if (cmd.resp[0] & R5_FUNCTION_NUMBER)
138 if (cmd.resp[0] & R5_OUT_OF_RANGE)