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