Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Block driver for media (i.e., flash cards) |
| 3 | * |
| 4 | * Copyright 2002 Hewlett-Packard Company |
Pierre Ossman | 979ce72 | 2008-06-29 12:19:47 +0200 | [diff] [blame] | 5 | * Copyright 2005-2008 Pierre Ossman |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Use consistent with the GNU GPL is permitted, |
| 8 | * provided that this copyright notice is |
| 9 | * preserved in its entirety in all copies and derived works. |
| 10 | * |
| 11 | * HEWLETT-PACKARD COMPANY MAKES NO WARRANTIES, EXPRESSED OR IMPLIED, |
| 12 | * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS |
| 13 | * FITNESS FOR ANY PARTICULAR PURPOSE. |
| 14 | * |
| 15 | * Many thanks to Alessandro Rubini and Jonathan Corbet! |
| 16 | * |
| 17 | * Author: Andrew Christian |
| 18 | * 28 May 2002 |
| 19 | */ |
| 20 | #include <linux/moduleparam.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/init.h> |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/fs.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/hdreg.h> |
| 28 | #include <linux/kdev_t.h> |
| 29 | #include <linux/blkdev.h> |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 30 | #include <linux/mutex.h> |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 31 | #include <linux/scatterlist.h> |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 32 | #include <linux/string_helpers.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include <linux/mmc/card.h> |
Pierre Ossman | 385e3227 | 2006-06-18 14:34:37 +0200 | [diff] [blame] | 35 | #include <linux/mmc/host.h> |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 36 | #include <linux/mmc/mmc.h> |
| 37 | #include <linux/mmc/sd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include <asm/system.h> |
| 40 | #include <asm/uaccess.h> |
| 41 | |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 42 | #include "queue.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Andy Whitcroft | 6b0b628 | 2009-02-23 12:38:41 +0000 | [diff] [blame] | 44 | MODULE_ALIAS("mmc:block"); |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* |
| 47 | * max 8 partitions per card |
| 48 | */ |
| 49 | #define MMC_SHIFT 3 |
David Woodhouse | 1dff314 | 2007-11-21 18:45:12 +0100 | [diff] [blame] | 50 | #define MMC_NUM_MINORS (256 >> MMC_SHIFT) |
| 51 | |
Ben Collins | 203c801 | 2008-06-05 19:10:21 -0400 | [diff] [blame] | 52 | static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* |
| 55 | * There is one mmc_blk_data per slot. |
| 56 | */ |
| 57 | struct mmc_blk_data { |
| 58 | spinlock_t lock; |
| 59 | struct gendisk *disk; |
| 60 | struct mmc_queue queue; |
| 61 | |
| 62 | unsigned int usage; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 63 | unsigned int read_only; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 66 | static DEFINE_MUTEX(open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) |
| 69 | { |
| 70 | struct mmc_blk_data *md; |
| 71 | |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 72 | mutex_lock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | md = disk->private_data; |
| 74 | if (md && md->usage == 0) |
| 75 | md = NULL; |
| 76 | if (md) |
| 77 | md->usage++; |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 78 | mutex_unlock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | return md; |
| 81 | } |
| 82 | |
| 83 | static void mmc_blk_put(struct mmc_blk_data *md) |
| 84 | { |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 85 | mutex_lock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | md->usage--; |
| 87 | if (md->usage == 0) { |
Anna Lemehova | 7d92df6 | 2010-01-08 14:42:58 -0800 | [diff] [blame] | 88 | int devmaj = MAJOR(disk_devt(md->disk)); |
Tejun Heo | f331c02 | 2008-09-03 09:01:48 +0200 | [diff] [blame] | 89 | int devidx = MINOR(disk_devt(md->disk)) >> MMC_SHIFT; |
Anna Lemehova | 7d92df6 | 2010-01-08 14:42:58 -0800 | [diff] [blame] | 90 | |
| 91 | if (!devmaj) |
| 92 | devidx = md->disk->first_minor >> MMC_SHIFT; |
| 93 | |
David Woodhouse | 1dff314 | 2007-11-21 18:45:12 +0100 | [diff] [blame] | 94 | __clear_bit(devidx, dev_use); |
| 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | put_disk(md->disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | kfree(md); |
| 98 | } |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 99 | mutex_unlock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 102 | static int mmc_blk_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 104 | struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | int ret = -ENXIO; |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | if (md) { |
| 108 | if (md->usage == 2) |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 109 | check_disk_change(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | ret = 0; |
Pierre Ossman | a00fc09 | 2005-09-06 15:18:52 -0700 | [diff] [blame] | 111 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 112 | if ((mode & FMODE_WRITE) && md->read_only) { |
Andrew Morton | 70bb089 | 2008-09-05 14:00:24 -0700 | [diff] [blame] | 113 | mmc_blk_put(md); |
Pierre Ossman | a00fc09 | 2005-09-06 15:18:52 -0700 | [diff] [blame] | 114 | ret = -EROFS; |
Andrew Morton | 70bb089 | 2008-09-05 14:00:24 -0700 | [diff] [blame] | 115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | return ret; |
| 119 | } |
| 120 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 121 | static int mmc_blk_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 123 | struct mmc_blk_data *md = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | mmc_blk_put(md); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static int |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 130 | mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 132 | geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16); |
| 133 | geo->heads = 4; |
| 134 | geo->sectors = 16; |
| 135 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 138 | static const struct block_device_operations mmc_bdops = { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 139 | .open = mmc_blk_open, |
| 140 | .release = mmc_blk_release, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 141 | .getgeo = mmc_blk_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | .owner = THIS_MODULE, |
| 143 | }; |
| 144 | |
| 145 | struct mmc_blk_request { |
| 146 | struct mmc_request mrq; |
| 147 | struct mmc_command cmd; |
| 148 | struct mmc_command stop; |
| 149 | struct mmc_data data; |
| 150 | }; |
| 151 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 152 | static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) |
| 153 | { |
| 154 | int err; |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 155 | u32 result; |
| 156 | __be32 *blocks; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 157 | |
| 158 | struct mmc_request mrq; |
| 159 | struct mmc_command cmd; |
| 160 | struct mmc_data data; |
| 161 | unsigned int timeout_us; |
| 162 | |
| 163 | struct scatterlist sg; |
| 164 | |
| 165 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 166 | |
| 167 | cmd.opcode = MMC_APP_CMD; |
| 168 | cmd.arg = card->rca << 16; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 169 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 170 | |
| 171 | err = mmc_wait_for_cmd(card->host, &cmd, 0); |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 172 | if (err) |
| 173 | return (u32)-1; |
| 174 | if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD)) |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 175 | return (u32)-1; |
| 176 | |
| 177 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 178 | |
| 179 | cmd.opcode = SD_APP_SEND_NUM_WR_BLKS; |
| 180 | cmd.arg = 0; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 181 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 182 | |
| 183 | memset(&data, 0, sizeof(struct mmc_data)); |
| 184 | |
| 185 | data.timeout_ns = card->csd.tacc_ns * 100; |
| 186 | data.timeout_clks = card->csd.tacc_clks * 100; |
| 187 | |
| 188 | timeout_us = data.timeout_ns / 1000; |
| 189 | timeout_us += data.timeout_clks * 1000 / |
| 190 | (card->host->ios.clock / 1000); |
| 191 | |
| 192 | if (timeout_us > 100000) { |
| 193 | data.timeout_ns = 100000000; |
| 194 | data.timeout_clks = 0; |
| 195 | } |
| 196 | |
| 197 | data.blksz = 4; |
| 198 | data.blocks = 1; |
| 199 | data.flags = MMC_DATA_READ; |
| 200 | data.sg = &sg; |
| 201 | data.sg_len = 1; |
| 202 | |
| 203 | memset(&mrq, 0, sizeof(struct mmc_request)); |
| 204 | |
| 205 | mrq.cmd = &cmd; |
| 206 | mrq.data = &data; |
| 207 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 208 | blocks = kmalloc(4, GFP_KERNEL); |
| 209 | if (!blocks) |
| 210 | return (u32)-1; |
| 211 | |
| 212 | sg_init_one(&sg, blocks, 4); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 213 | |
| 214 | mmc_wait_for_req(card->host, &mrq); |
| 215 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 216 | result = ntohl(*blocks); |
| 217 | kfree(blocks); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 218 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 219 | if (cmd.error || data.error) |
| 220 | result = (u32)-1; |
| 221 | |
| 222 | return result; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 225 | static u32 get_card_status(struct mmc_card *card, struct request *req) |
| 226 | { |
| 227 | struct mmc_command cmd; |
| 228 | int err; |
| 229 | |
| 230 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 231 | cmd.opcode = MMC_SEND_STATUS; |
| 232 | if (!mmc_host_is_spi(card->host)) |
| 233 | cmd.arg = card->rca << 16; |
| 234 | cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC; |
| 235 | err = mmc_wait_for_cmd(card->host, &cmd, 0); |
| 236 | if (err) |
| 237 | printk(KERN_ERR "%s: error %d sending status comand", |
| 238 | req->rq_disk->disk_name, err); |
| 239 | return cmd.resp[0]; |
| 240 | } |
| 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) |
| 243 | { |
| 244 | struct mmc_blk_data *md = mq->data; |
| 245 | struct mmc_card *card = md->queue.card; |
Pierre Ossman | 176f00f | 2006-10-04 02:15:41 -0700 | [diff] [blame] | 246 | struct mmc_blk_request brq; |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 247 | int ret = 1, disable_multi = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 249 | mmc_claim_host(card->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | struct mmc_command cmd; |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 253 | u32 readcmd, writecmd, status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | memset(&brq, 0, sizeof(struct mmc_blk_request)); |
| 256 | brq.mrq.cmd = &brq.cmd; |
| 257 | brq.mrq.data = &brq.data; |
| 258 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 259 | brq.cmd.arg = blk_rq_pos(req); |
Philip Langdale | fba68bd | 2007-01-04 06:57:32 -0800 | [diff] [blame] | 260 | if (!mmc_card_blockaddr(card)) |
| 261 | brq.cmd.arg <<= 9; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 262 | brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
Pierre Ossman | 0884669 | 2008-08-31 14:10:08 +0200 | [diff] [blame] | 263 | brq.data.blksz = 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | brq.stop.opcode = MMC_STOP_TRANSMISSION; |
| 265 | brq.stop.arg = 0; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 266 | brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 267 | brq.data.blocks = blk_rq_sectors(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 269 | /* |
Pierre Ossman | 548d2de | 2009-04-10 17:52:57 +0200 | [diff] [blame] | 270 | * The block layer doesn't support all sector count |
| 271 | * restrictions, so we need to be prepared for too big |
| 272 | * requests. |
| 273 | */ |
| 274 | if (brq.data.blocks > card->host->max_blk_count) |
| 275 | brq.data.blocks = card->host->max_blk_count; |
| 276 | |
| 277 | /* |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 278 | * After a read error, we redo the request one sector at a time |
| 279 | * in order to accurately determine which sectors can be read |
| 280 | * successfully. |
| 281 | */ |
| 282 | if (disable_multi && brq.data.blocks > 1) |
| 283 | brq.data.blocks = 1; |
| 284 | |
Russell King | 788ee7b | 2006-01-09 21:12:17 +0000 | [diff] [blame] | 285 | if (brq.data.blocks > 1) { |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 286 | /* SPI multiblock writes terminate using a special |
| 287 | * token, not a STOP_TRANSMISSION request. |
| 288 | */ |
| 289 | if (!mmc_host_is_spi(card->host) |
| 290 | || rq_data_dir(req) == READ) |
| 291 | brq.mrq.stop = &brq.stop; |
Russell King | db53f28 | 2006-08-30 15:14:56 +0100 | [diff] [blame] | 292 | readcmd = MMC_READ_MULTIPLE_BLOCK; |
| 293 | writecmd = MMC_WRITE_MULTIPLE_BLOCK; |
Russell King | 788ee7b | 2006-01-09 21:12:17 +0000 | [diff] [blame] | 294 | } else { |
| 295 | brq.mrq.stop = NULL; |
Russell King | db53f28 | 2006-08-30 15:14:56 +0100 | [diff] [blame] | 296 | readcmd = MMC_READ_SINGLE_BLOCK; |
| 297 | writecmd = MMC_WRITE_BLOCK; |
| 298 | } |
| 299 | |
| 300 | if (rq_data_dir(req) == READ) { |
| 301 | brq.cmd.opcode = readcmd; |
| 302 | brq.data.flags |= MMC_DATA_READ; |
| 303 | } else { |
| 304 | brq.cmd.opcode = writecmd; |
| 305 | brq.data.flags |= MMC_DATA_WRITE; |
Russell King | 788ee7b | 2006-01-09 21:12:17 +0000 | [diff] [blame] | 306 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Pierre Ossman | b146d26 | 2007-07-24 19:16:54 +0200 | [diff] [blame] | 308 | mmc_set_data_timeout(&brq.data, card); |
| 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | brq.data.sg = mq->sg; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 311 | brq.data.sg_len = mmc_queue_map_sg(mq); |
| 312 | |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 313 | /* |
| 314 | * Adjust the sg list so it is the same size as the |
| 315 | * request. |
| 316 | */ |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 317 | if (brq.data.blocks != blk_rq_sectors(req)) { |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 318 | int i, data_size = brq.data.blocks << 9; |
| 319 | struct scatterlist *sg; |
| 320 | |
| 321 | for_each_sg(brq.data.sg, sg, brq.data.sg_len, i) { |
| 322 | data_size -= sg->length; |
| 323 | if (data_size <= 0) { |
| 324 | sg->length += data_size; |
| 325 | i++; |
| 326 | break; |
| 327 | } |
| 328 | } |
| 329 | brq.data.sg_len = i; |
| 330 | } |
| 331 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 332 | mmc_queue_bounce_pre(mq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
| 334 | mmc_wait_for_req(card->host, &brq.mrq); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 335 | |
| 336 | mmc_queue_bounce_post(mq); |
| 337 | |
Pierre Ossman | 979ce72 | 2008-06-29 12:19:47 +0200 | [diff] [blame] | 338 | /* |
| 339 | * Check for errors here, but don't jump to cmd_err |
| 340 | * until later as we need to wait for the card to leave |
| 341 | * programming mode even when things go wrong. |
| 342 | */ |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 343 | if (brq.cmd.error || brq.data.error || brq.stop.error) { |
| 344 | if (brq.data.blocks > 1 && rq_data_dir(req) == READ) { |
| 345 | /* Redo read one sector at a time */ |
| 346 | printk(KERN_WARNING "%s: retrying using single " |
| 347 | "block read\n", req->rq_disk->disk_name); |
| 348 | disable_multi = 1; |
| 349 | continue; |
| 350 | } |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 351 | status = get_card_status(card, req); |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 352 | } |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | if (brq.cmd.error) { |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 355 | printk(KERN_ERR "%s: error %d sending read/write " |
| 356 | "command, response %#x, card status %#x\n", |
| 357 | req->rq_disk->disk_name, brq.cmd.error, |
| 358 | brq.cmd.resp[0], status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | if (brq.data.error) { |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 362 | if (brq.data.error == -ETIMEDOUT && brq.mrq.stop) |
| 363 | /* 'Stop' response contains card status */ |
| 364 | status = brq.mrq.stop->resp[0]; |
| 365 | printk(KERN_ERR "%s: error %d transferring data," |
| 366 | " sector %u, nr %u, card status %#x\n", |
| 367 | req->rq_disk->disk_name, brq.data.error, |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 368 | (unsigned)blk_rq_pos(req), |
| 369 | (unsigned)blk_rq_sectors(req), status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | if (brq.stop.error) { |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 373 | printk(KERN_ERR "%s: error %d sending stop command, " |
| 374 | "response %#x, card status %#x\n", |
| 375 | req->rq_disk->disk_name, brq.stop.error, |
| 376 | brq.stop.resp[0], status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 379 | if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { |
Russell King | 2ed6d22 | 2006-09-24 10:46:43 +0100 | [diff] [blame] | 380 | do { |
| 381 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Russell King | 2ed6d22 | 2006-09-24 10:46:43 +0100 | [diff] [blame] | 383 | cmd.opcode = MMC_SEND_STATUS; |
| 384 | cmd.arg = card->rca << 16; |
| 385 | cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; |
| 386 | err = mmc_wait_for_cmd(card->host, &cmd, 5); |
| 387 | if (err) { |
| 388 | printk(KERN_ERR "%s: error %d requesting status\n", |
| 389 | req->rq_disk->disk_name, err); |
| 390 | goto cmd_err; |
| 391 | } |
Pierre Ossman | d198f10 | 2007-11-02 18:21:13 +0100 | [diff] [blame] | 392 | /* |
| 393 | * Some cards mishandle the status bits, |
| 394 | * so make sure to check both the busy |
| 395 | * indication and the card state. |
| 396 | */ |
| 397 | } while (!(cmd.resp[0] & R1_READY_FOR_DATA) || |
| 398 | (R1_CURRENT_STATE(cmd.resp[0]) == 7)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | #if 0 |
Russell King | 2ed6d22 | 2006-09-24 10:46:43 +0100 | [diff] [blame] | 401 | if (cmd.resp[0] & ~0x00000900) |
| 402 | printk(KERN_ERR "%s: status = %08x\n", |
| 403 | req->rq_disk->disk_name, cmd.resp[0]); |
| 404 | if (mmc_decode_status(cmd.resp)) |
| 405 | goto cmd_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | #endif |
Russell King | 2ed6d22 | 2006-09-24 10:46:43 +0100 | [diff] [blame] | 407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 409 | if (brq.cmd.error || brq.stop.error || brq.data.error) { |
| 410 | if (rq_data_dir(req) == READ) { |
| 411 | /* |
| 412 | * After an error, we redo I/O one sector at a |
| 413 | * time, so we only reach here after trying to |
| 414 | * read a single sector. |
| 415 | */ |
| 416 | spin_lock_irq(&md->lock); |
| 417 | ret = __blk_end_request(req, -EIO, brq.data.blksz); |
| 418 | spin_unlock_irq(&md->lock); |
| 419 | continue; |
| 420 | } |
Pierre Ossman | 979ce72 | 2008-06-29 12:19:47 +0200 | [diff] [blame] | 421 | goto cmd_err; |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 422 | } |
Pierre Ossman | 979ce72 | 2008-06-29 12:19:47 +0200 | [diff] [blame] | 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /* |
| 425 | * A block was successfully transferred. |
| 426 | */ |
| 427 | spin_lock_irq(&md->lock); |
Kiyoshi Ueda | fd53983 | 2007-12-11 17:48:29 -0500 | [diff] [blame] | 428 | ret = __blk_end_request(req, 0, brq.data.bytes_xfered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | spin_unlock_irq(&md->lock); |
| 430 | } while (ret); |
| 431 | |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 432 | mmc_release_host(card->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | return 1; |
| 435 | |
| 436 | cmd_err: |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 437 | /* |
| 438 | * If this is an SD card and we're writing, we can first |
| 439 | * mark the known good sectors as ok. |
| 440 | * |
| 441 | * If the card is not SD, we can still ok written sectors |
Pierre Ossman | 23af603 | 2008-07-06 01:10:27 +0200 | [diff] [blame] | 442 | * as reported by the controller (which might be less than |
| 443 | * the real number of written sectors, but never more). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | */ |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 445 | if (mmc_card_sd(card)) { |
| 446 | u32 blocks; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 447 | |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 448 | blocks = mmc_sd_num_wr_blocks(card); |
| 449 | if (blocks != (u32)-1) { |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 450 | spin_lock_irq(&md->lock); |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 451 | ret = __blk_end_request(req, 0, blocks << 9); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 452 | spin_unlock_irq(&md->lock); |
| 453 | } |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 454 | } else { |
| 455 | spin_lock_irq(&md->lock); |
| 456 | ret = __blk_end_request(req, 0, brq.data.bytes_xfered); |
| 457 | spin_unlock_irq(&md->lock); |
Pierre Ossman | 176f00f | 2006-10-04 02:15:41 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 460 | mmc_release_host(card->host); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | spin_lock_irq(&md->lock); |
Kiyoshi Ueda | fd53983 | 2007-12-11 17:48:29 -0500 | [diff] [blame] | 463 | while (ret) |
| 464 | ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | spin_unlock_irq(&md->lock); |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 471 | static inline int mmc_blk_readonly(struct mmc_card *card) |
| 472 | { |
| 473 | return mmc_card_readonly(card) || |
| 474 | !(card->csd.cmdclass & CCC_BLOCK_WRITE); |
| 475 | } |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card) |
| 478 | { |
| 479 | struct mmc_blk_data *md; |
| 480 | int devidx, ret; |
| 481 | |
| 482 | devidx = find_first_zero_bit(dev_use, MMC_NUM_MINORS); |
| 483 | if (devidx >= MMC_NUM_MINORS) |
| 484 | return ERR_PTR(-ENOSPC); |
| 485 | __set_bit(devidx, dev_use); |
| 486 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 487 | md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 488 | if (!md) { |
| 489 | ret = -ENOMEM; |
| 490 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 492 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 493 | |
| 494 | /* |
| 495 | * Set the read-only status based on the supported commands |
| 496 | * and the write protect switch. |
| 497 | */ |
| 498 | md->read_only = mmc_blk_readonly(card); |
| 499 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 500 | md->disk = alloc_disk(1 << MMC_SHIFT); |
| 501 | if (md->disk == NULL) { |
| 502 | ret = -ENOMEM; |
| 503 | goto err_kfree; |
| 504 | } |
| 505 | |
| 506 | spin_lock_init(&md->lock); |
| 507 | md->usage = 1; |
| 508 | |
| 509 | ret = mmc_init_queue(&md->queue, card, &md->lock); |
| 510 | if (ret) |
| 511 | goto err_putdisk; |
| 512 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 513 | md->queue.issue_fn = mmc_blk_issue_rq; |
| 514 | md->queue.data = md; |
| 515 | |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 516 | md->disk->major = MMC_BLOCK_MAJOR; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 517 | md->disk->first_minor = devidx << MMC_SHIFT; |
| 518 | md->disk->fops = &mmc_bdops; |
| 519 | md->disk->private_data = md; |
| 520 | md->disk->queue = md->queue.queue; |
| 521 | md->disk->driverfs_dev = &card->dev; |
| 522 | |
| 523 | /* |
| 524 | * As discussed on lkml, GENHD_FL_REMOVABLE should: |
| 525 | * |
| 526 | * - be set for removable media with permanent block devices |
| 527 | * - be unset for removable block devices with permanent media |
| 528 | * |
| 529 | * Since MMC block devices clearly fall under the second |
| 530 | * case, we do not set GENHD_FL_REMOVABLE. Userspace |
| 531 | * should use the block device creation/destruction hotplug |
| 532 | * messages to tell when the card is present. |
| 533 | */ |
| 534 | |
| 535 | sprintf(md->disk->disk_name, "mmcblk%d", devidx); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 536 | |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 537 | blk_queue_logical_block_size(md->queue.queue, 512); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 538 | |
Pierre Ossman | 85a18ad | 2007-02-17 22:15:27 +0100 | [diff] [blame] | 539 | if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) { |
| 540 | /* |
| 541 | * The EXT_CSD sector count is in number or 512 byte |
| 542 | * sectors. |
| 543 | */ |
| 544 | set_capacity(md->disk, card->ext_csd.sectors); |
| 545 | } else { |
| 546 | /* |
| 547 | * The CSD capacity field is in units of read_blkbits. |
| 548 | * set_capacity takes units of 512 bytes. |
| 549 | */ |
| 550 | set_capacity(md->disk, |
| 551 | card->csd.capacity << (card->csd.read_blkbits - 9)); |
| 552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | return md; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 554 | |
| 555 | err_putdisk: |
| 556 | put_disk(md->disk); |
| 557 | err_kfree: |
| 558 | kfree(md); |
| 559 | out: |
| 560 | return ERR_PTR(ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static int |
| 564 | mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card) |
| 565 | { |
| 566 | struct mmc_command cmd; |
| 567 | int err; |
| 568 | |
Philip Langdale | fba68bd | 2007-01-04 06:57:32 -0800 | [diff] [blame] | 569 | /* Block-addressed cards ignore MMC_SET_BLOCKLEN. */ |
| 570 | if (mmc_card_blockaddr(card)) |
| 571 | return 0; |
| 572 | |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 573 | mmc_claim_host(card->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | cmd.opcode = MMC_SET_BLOCKLEN; |
Pierre Ossman | 0884669 | 2008-08-31 14:10:08 +0200 | [diff] [blame] | 575 | cmd.arg = 512; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 576 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | err = mmc_wait_for_cmd(card->host, &cmd, 5); |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 578 | mmc_release_host(card->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
| 580 | if (err) { |
| 581 | printk(KERN_ERR "%s: unable to set block size to %d: %d\n", |
| 582 | md->disk->disk_name, cmd.arg, err); |
| 583 | return -EINVAL; |
| 584 | } |
| 585 | |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | static int mmc_blk_probe(struct mmc_card *card) |
| 590 | { |
| 591 | struct mmc_blk_data *md; |
| 592 | int err; |
| 593 | |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 594 | char cap_str[10]; |
| 595 | |
Pierre Ossman | 912490d | 2005-05-21 10:27:02 +0100 | [diff] [blame] | 596 | /* |
| 597 | * Check that the card supports the command class(es) we need. |
| 598 | */ |
| 599 | if (!(card->csd.cmdclass & CCC_BLOCK_READ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | return -ENODEV; |
| 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | md = mmc_blk_alloc(card); |
| 603 | if (IS_ERR(md)) |
| 604 | return PTR_ERR(md); |
| 605 | |
| 606 | err = mmc_blk_set_blksize(md, card); |
| 607 | if (err) |
| 608 | goto out; |
| 609 | |
Yi Li | 444122f | 2009-02-05 15:31:57 +0800 | [diff] [blame] | 610 | string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2, |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 611 | cap_str, sizeof(cap_str)); |
| 612 | printk(KERN_INFO "%s: %s %s %s %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | md->disk->disk_name, mmc_card_id(card), mmc_card_name(card), |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 614 | cap_str, md->read_only ? "(ro)" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | mmc_set_drvdata(card, md); |
| 617 | add_disk(md->disk); |
| 618 | return 0; |
| 619 | |
| 620 | out: |
Jarkko Lavinen | 0a74ff2 | 2010-01-08 14:42:59 -0800 | [diff] [blame^] | 621 | mmc_cleanup_queue(&md->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | mmc_blk_put(md); |
| 623 | |
| 624 | return err; |
| 625 | } |
| 626 | |
| 627 | static void mmc_blk_remove(struct mmc_card *card) |
| 628 | { |
| 629 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 630 | |
| 631 | if (md) { |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 632 | /* Stop new requests from getting into the queue */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | del_gendisk(md->disk); |
| 634 | |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 635 | /* Then flush out any already in there */ |
| 636 | mmc_cleanup_queue(&md->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | mmc_blk_put(md); |
| 639 | } |
| 640 | mmc_set_drvdata(card, NULL); |
| 641 | } |
| 642 | |
| 643 | #ifdef CONFIG_PM |
| 644 | static int mmc_blk_suspend(struct mmc_card *card, pm_message_t state) |
| 645 | { |
| 646 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 647 | |
| 648 | if (md) { |
| 649 | mmc_queue_suspend(&md->queue); |
| 650 | } |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static int mmc_blk_resume(struct mmc_card *card) |
| 655 | { |
| 656 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 657 | |
| 658 | if (md) { |
| 659 | mmc_blk_set_blksize(md, card); |
| 660 | mmc_queue_resume(&md->queue); |
| 661 | } |
| 662 | return 0; |
| 663 | } |
| 664 | #else |
| 665 | #define mmc_blk_suspend NULL |
| 666 | #define mmc_blk_resume NULL |
| 667 | #endif |
| 668 | |
| 669 | static struct mmc_driver mmc_driver = { |
| 670 | .drv = { |
| 671 | .name = "mmcblk", |
| 672 | }, |
| 673 | .probe = mmc_blk_probe, |
| 674 | .remove = mmc_blk_remove, |
| 675 | .suspend = mmc_blk_suspend, |
| 676 | .resume = mmc_blk_resume, |
| 677 | }; |
| 678 | |
| 679 | static int __init mmc_blk_init(void) |
| 680 | { |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 681 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 683 | res = register_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
| 684 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 687 | res = mmc_register_driver(&mmc_driver); |
| 688 | if (res) |
| 689 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 691 | return 0; |
| 692 | out2: |
| 693 | unregister_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | out: |
| 695 | return res; |
| 696 | } |
| 697 | |
| 698 | static void __exit mmc_blk_exit(void) |
| 699 | { |
| 700 | mmc_unregister_driver(&mmc_driver); |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 701 | unregister_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | module_init(mmc_blk_init); |
| 705 | module_exit(mmc_blk_exit); |
| 706 | |
| 707 | MODULE_LICENSE("GPL"); |
| 708 | MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver"); |
| 709 | |