Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mmc/sdio_ops.c |
| 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/mmc/host.h> |
Pierre Ossman | b2bcc79 | 2007-05-22 20:25:21 +0200 | [diff] [blame^] | 13 | #include <linux/mmc/card.h> |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 14 | #include <linux/mmc/mmc.h> |
| 15 | #include <linux/mmc/sdio.h> |
| 16 | |
| 17 | #include "core.h" |
| 18 | |
| 19 | int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) |
| 20 | { |
| 21 | struct mmc_command cmd; |
| 22 | int i, err = 0; |
| 23 | |
| 24 | BUG_ON(!host); |
| 25 | |
| 26 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 27 | |
| 28 | cmd.opcode = SD_IO_SEND_OP_COND; |
| 29 | cmd.arg = ocr; |
| 30 | cmd.flags = MMC_RSP_R4 | MMC_CMD_BCR; |
| 31 | |
| 32 | for (i = 100; i; i--) { |
| 33 | err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); |
| 34 | if (err) |
| 35 | break; |
| 36 | |
| 37 | if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0) |
| 38 | break; |
| 39 | |
| 40 | err = -ETIMEDOUT; |
| 41 | |
| 42 | mmc_delay(10); |
| 43 | } |
| 44 | |
| 45 | if (rocr) |
| 46 | *rocr = cmd.resp[0]; |
| 47 | |
| 48 | return err; |
| 49 | } |
| 50 | |
Pierre Ossman | b2bcc79 | 2007-05-22 20:25:21 +0200 | [diff] [blame^] | 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 | |