block.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * Block driver for media (i.e., flash cards)
  3. *
  4. * Copyright 2002 Hewlett-Packard Company
  5. * Copyright 2005-2008 Pierre Ossman
  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. #include <linux/kernel.h>
  24. #include <linux/fs.h>
  25. #include <linux/slab.h>
  26. #include <linux/errno.h>
  27. #include <linux/hdreg.h>
  28. #include <linux/kdev_t.h>
  29. #include <linux/blkdev.h>
  30. #include <linux/mutex.h>
  31. #include <linux/scatterlist.h>
  32. #include <linux/string_helpers.h>
  33. #include <linux/mmc/card.h>
  34. #include <linux/mmc/host.h>
  35. #include <linux/mmc/mmc.h>
  36. #include <linux/mmc/sd.h>
  37. #include <asm/system.h>
  38. #include <asm/uaccess.h>
  39. #include "queue.h"
  40. MODULE_ALIAS("mmc:block");
  41. /*
  42. * max 8 partitions per card
  43. */
  44. #define MMC_SHIFT 3
  45. #define MMC_NUM_MINORS (256 >> MMC_SHIFT)
  46. static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS);
  47. /*
  48. * There is one mmc_blk_data per slot.
  49. */
  50. struct mmc_blk_data {
  51. spinlock_t lock;
  52. struct gendisk *disk;
  53. struct mmc_queue queue;
  54. unsigned int usage;
  55. unsigned int read_only;
  56. };
  57. static DEFINE_MUTEX(open_lock);
  58. static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
  59. {
  60. struct mmc_blk_data *md;
  61. mutex_lock(&open_lock);
  62. md = disk->private_data;
  63. if (md && md->usage == 0)
  64. md = NULL;
  65. if (md)
  66. md->usage++;
  67. mutex_unlock(&open_lock);
  68. return md;
  69. }
  70. static void mmc_blk_put(struct mmc_blk_data *md)
  71. {
  72. mutex_lock(&open_lock);
  73. md->usage--;
  74. if (md->usage == 0) {
  75. int devmaj = MAJOR(disk_devt(md->disk));
  76. int devidx = MINOR(disk_devt(md->disk)) >> MMC_SHIFT;
  77. if (!devmaj)
  78. devidx = md->disk->first_minor >> MMC_SHIFT;
  79. blk_cleanup_queue(md->queue.queue);
  80. __clear_bit(devidx, dev_use);
  81. put_disk(md->disk);
  82. kfree(md);
  83. }
  84. mutex_unlock(&open_lock);
  85. }
  86. static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
  87. {
  88. struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
  89. int ret = -ENXIO;
  90. if (md) {
  91. if (md->usage == 2)
  92. check_disk_change(bdev);
  93. ret = 0;
  94. if ((mode & FMODE_WRITE) && md->read_only) {
  95. mmc_blk_put(md);
  96. ret = -EROFS;
  97. }
  98. }
  99. return ret;
  100. }
  101. static int mmc_blk_release(struct gendisk *disk, fmode_t mode)
  102. {
  103. struct mmc_blk_data *md = disk->private_data;
  104. mmc_blk_put(md);
  105. return 0;
  106. }
  107. static int
  108. mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  109. {
  110. geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16);
  111. geo->heads = 4;
  112. geo->sectors = 16;
  113. return 0;
  114. }
  115. static const struct block_device_operations mmc_bdops = {
  116. .open = mmc_blk_open,
  117. .release = mmc_blk_release,
  118. .getgeo = mmc_blk_getgeo,
  119. .owner = THIS_MODULE,
  120. };
  121. struct mmc_blk_request {
  122. struct mmc_request mrq;
  123. struct mmc_command cmd;
  124. struct mmc_command stop;
  125. struct mmc_data data;
  126. };
  127. static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
  128. {
  129. int err;
  130. u32 result;
  131. __be32 *blocks;
  132. struct mmc_request mrq;
  133. struct mmc_command cmd;
  134. struct mmc_data data;
  135. unsigned int timeout_us;
  136. struct scatterlist sg;
  137. memset(&cmd, 0, sizeof(struct mmc_command));
  138. cmd.opcode = MMC_APP_CMD;
  139. cmd.arg = card->rca << 16;
  140. cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
  141. err = mmc_wait_for_cmd(card->host, &cmd, 0);
  142. if (err)
  143. return (u32)-1;
  144. if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
  145. return (u32)-1;
  146. memset(&cmd, 0, sizeof(struct mmc_command));
  147. cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
  148. cmd.arg = 0;
  149. cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
  150. memset(&data, 0, sizeof(struct mmc_data));
  151. data.timeout_ns = card->csd.tacc_ns * 100;
  152. data.timeout_clks = card->csd.tacc_clks * 100;
  153. timeout_us = data.timeout_ns / 1000;
  154. timeout_us += data.timeout_clks * 1000 /
  155. (card->host->ios.clock / 1000);
  156. if (timeout_us > 100000) {
  157. data.timeout_ns = 100000000;
  158. data.timeout_clks = 0;
  159. }
  160. data.blksz = 4;
  161. data.blocks = 1;
  162. data.flags = MMC_DATA_READ;
  163. data.sg = &sg;
  164. data.sg_len = 1;
  165. memset(&mrq, 0, sizeof(struct mmc_request));
  166. mrq.cmd = &cmd;
  167. mrq.data = &data;
  168. blocks = kmalloc(4, GFP_KERNEL);
  169. if (!blocks)
  170. return (u32)-1;
  171. sg_init_one(&sg, blocks, 4);
  172. mmc_wait_for_req(card->host, &mrq);
  173. result = ntohl(*blocks);
  174. kfree(blocks);
  175. if (cmd.error || data.error)
  176. result = (u32)-1;
  177. return result;
  178. }
  179. static u32 get_card_status(struct mmc_card *card, struct request *req)
  180. {
  181. struct mmc_command cmd;
  182. int err;
  183. memset(&cmd, 0, sizeof(struct mmc_command));
  184. cmd.opcode = MMC_SEND_STATUS;
  185. if (!mmc_host_is_spi(card->host))
  186. cmd.arg = card->rca << 16;
  187. cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
  188. err = mmc_wait_for_cmd(card->host, &cmd, 0);
  189. if (err)
  190. printk(KERN_ERR "%s: error %d sending status comand",
  191. req->rq_disk->disk_name, err);
  192. return cmd.resp[0];
  193. }
  194. static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
  195. {
  196. struct mmc_blk_data *md = mq->data;
  197. struct mmc_card *card = md->queue.card;
  198. struct mmc_blk_request brq;
  199. int ret = 1, disable_multi = 0;
  200. mmc_claim_host(card->host);
  201. do {
  202. struct mmc_command cmd;
  203. u32 readcmd, writecmd, status = 0;
  204. memset(&brq, 0, sizeof(struct mmc_blk_request));
  205. brq.mrq.cmd = &brq.cmd;
  206. brq.mrq.data = &brq.data;
  207. brq.cmd.arg = blk_rq_pos(req);
  208. if (!mmc_card_blockaddr(card))
  209. brq.cmd.arg <<= 9;
  210. brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
  211. brq.data.blksz = 512;
  212. brq.stop.opcode = MMC_STOP_TRANSMISSION;
  213. brq.stop.arg = 0;
  214. brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
  215. brq.data.blocks = blk_rq_sectors(req);
  216. /*
  217. * The block layer doesn't support all sector count
  218. * restrictions, so we need to be prepared for too big
  219. * requests.
  220. */
  221. if (brq.data.blocks > card->host->max_blk_count)
  222. brq.data.blocks = card->host->max_blk_count;
  223. /*
  224. * After a read error, we redo the request one sector at a time
  225. * in order to accurately determine which sectors can be read
  226. * successfully.
  227. */
  228. if (disable_multi && brq.data.blocks > 1)
  229. brq.data.blocks = 1;
  230. if (brq.data.blocks > 1) {
  231. /* SPI multiblock writes terminate using a special
  232. * token, not a STOP_TRANSMISSION request.
  233. */
  234. if (!mmc_host_is_spi(card->host)
  235. || rq_data_dir(req) == READ)
  236. brq.mrq.stop = &brq.stop;
  237. readcmd = MMC_READ_MULTIPLE_BLOCK;
  238. writecmd = MMC_WRITE_MULTIPLE_BLOCK;
  239. } else {
  240. brq.mrq.stop = NULL;
  241. readcmd = MMC_READ_SINGLE_BLOCK;
  242. writecmd = MMC_WRITE_BLOCK;
  243. }
  244. if (rq_data_dir(req) == READ) {
  245. brq.cmd.opcode = readcmd;
  246. brq.data.flags |= MMC_DATA_READ;
  247. } else {
  248. brq.cmd.opcode = writecmd;
  249. brq.data.flags |= MMC_DATA_WRITE;
  250. }
  251. mmc_set_data_timeout(&brq.data, card);
  252. brq.data.sg = mq->sg;
  253. brq.data.sg_len = mmc_queue_map_sg(mq);
  254. /*
  255. * Adjust the sg list so it is the same size as the
  256. * request.
  257. */
  258. if (brq.data.blocks != blk_rq_sectors(req)) {
  259. int i, data_size = brq.data.blocks << 9;
  260. struct scatterlist *sg;
  261. for_each_sg(brq.data.sg, sg, brq.data.sg_len, i) {
  262. data_size -= sg->length;
  263. if (data_size <= 0) {
  264. sg->length += data_size;
  265. i++;
  266. break;
  267. }
  268. }
  269. brq.data.sg_len = i;
  270. }
  271. mmc_queue_bounce_pre(mq);
  272. mmc_wait_for_req(card->host, &brq.mrq);
  273. mmc_queue_bounce_post(mq);
  274. /*
  275. * Check for errors here, but don't jump to cmd_err
  276. * until later as we need to wait for the card to leave
  277. * programming mode even when things go wrong.
  278. */
  279. if (brq.cmd.error || brq.data.error || brq.stop.error) {
  280. if (brq.data.blocks > 1 && rq_data_dir(req) == READ) {
  281. /* Redo read one sector at a time */
  282. printk(KERN_WARNING "%s: retrying using single "
  283. "block read\n", req->rq_disk->disk_name);
  284. disable_multi = 1;
  285. continue;
  286. }
  287. status = get_card_status(card, req);
  288. }
  289. if (brq.cmd.error) {
  290. printk(KERN_ERR "%s: error %d sending read/write "
  291. "command, response %#x, card status %#x\n",
  292. req->rq_disk->disk_name, brq.cmd.error,
  293. brq.cmd.resp[0], status);
  294. }
  295. if (brq.data.error) {
  296. if (brq.data.error == -ETIMEDOUT && brq.mrq.stop)
  297. /* 'Stop' response contains card status */
  298. status = brq.mrq.stop->resp[0];
  299. printk(KERN_ERR "%s: error %d transferring data,"
  300. " sector %u, nr %u, card status %#x\n",
  301. req->rq_disk->disk_name, brq.data.error,
  302. (unsigned)blk_rq_pos(req),
  303. (unsigned)blk_rq_sectors(req), status);
  304. }
  305. if (brq.stop.error) {
  306. printk(KERN_ERR "%s: error %d sending stop command, "
  307. "response %#x, card status %#x\n",
  308. req->rq_disk->disk_name, brq.stop.error,
  309. brq.stop.resp[0], status);
  310. }
  311. if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
  312. do {
  313. int err;
  314. cmd.opcode = MMC_SEND_STATUS;
  315. cmd.arg = card->rca << 16;
  316. cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
  317. err = mmc_wait_for_cmd(card->host, &cmd, 5);
  318. if (err) {
  319. printk(KERN_ERR "%s: error %d requesting status\n",
  320. req->rq_disk->disk_name, err);
  321. goto cmd_err;
  322. }
  323. /*
  324. * Some cards mishandle the status bits,
  325. * so make sure to check both the busy
  326. * indication and the card state.
  327. */
  328. } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
  329. (R1_CURRENT_STATE(cmd.resp[0]) == 7));
  330. #if 0
  331. if (cmd.resp[0] & ~0x00000900)
  332. printk(KERN_ERR "%s: status = %08x\n",
  333. req->rq_disk->disk_name, cmd.resp[0]);
  334. if (mmc_decode_status(cmd.resp))
  335. goto cmd_err;
  336. #endif
  337. }
  338. if (brq.cmd.error || brq.stop.error || brq.data.error) {
  339. if (rq_data_dir(req) == READ) {
  340. /*
  341. * After an error, we redo I/O one sector at a
  342. * time, so we only reach here after trying to
  343. * read a single sector.
  344. */
  345. spin_lock_irq(&md->lock);
  346. ret = __blk_end_request(req, -EIO, brq.data.blksz);
  347. spin_unlock_irq(&md->lock);
  348. continue;
  349. }
  350. goto cmd_err;
  351. }
  352. /*
  353. * A block was successfully transferred.
  354. */
  355. spin_lock_irq(&md->lock);
  356. ret = __blk_end_request(req, 0, brq.data.bytes_xfered);
  357. spin_unlock_irq(&md->lock);
  358. } while (ret);
  359. mmc_release_host(card->host);
  360. return 1;
  361. cmd_err:
  362. /*
  363. * If this is an SD card and we're writing, we can first
  364. * mark the known good sectors as ok.
  365. *
  366. * If the card is not SD, we can still ok written sectors
  367. * as reported by the controller (which might be less than
  368. * the real number of written sectors, but never more).
  369. */
  370. if (mmc_card_sd(card)) {
  371. u32 blocks;
  372. blocks = mmc_sd_num_wr_blocks(card);
  373. if (blocks != (u32)-1) {
  374. spin_lock_irq(&md->lock);
  375. ret = __blk_end_request(req, 0, blocks << 9);
  376. spin_unlock_irq(&md->lock);
  377. }
  378. } else {
  379. spin_lock_irq(&md->lock);
  380. ret = __blk_end_request(req, 0, brq.data.bytes_xfered);
  381. spin_unlock_irq(&md->lock);
  382. }
  383. mmc_release_host(card->host);
  384. spin_lock_irq(&md->lock);
  385. while (ret)
  386. ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req));
  387. spin_unlock_irq(&md->lock);
  388. return 0;
  389. }
  390. static inline int mmc_blk_readonly(struct mmc_card *card)
  391. {
  392. return mmc_card_readonly(card) ||
  393. !(card->csd.cmdclass & CCC_BLOCK_WRITE);
  394. }
  395. static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
  396. {
  397. struct mmc_blk_data *md;
  398. int devidx, ret;
  399. devidx = find_first_zero_bit(dev_use, MMC_NUM_MINORS);
  400. if (devidx >= MMC_NUM_MINORS)
  401. return ERR_PTR(-ENOSPC);
  402. __set_bit(devidx, dev_use);
  403. md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
  404. if (!md) {
  405. ret = -ENOMEM;
  406. goto out;
  407. }
  408. /*
  409. * Set the read-only status based on the supported commands
  410. * and the write protect switch.
  411. */
  412. md->read_only = mmc_blk_readonly(card);
  413. md->disk = alloc_disk(1 << MMC_SHIFT);
  414. if (md->disk == NULL) {
  415. ret = -ENOMEM;
  416. goto err_kfree;
  417. }
  418. spin_lock_init(&md->lock);
  419. md->usage = 1;
  420. ret = mmc_init_queue(&md->queue, card, &md->lock);
  421. if (ret)
  422. goto err_putdisk;
  423. md->queue.issue_fn = mmc_blk_issue_rq;
  424. md->queue.data = md;
  425. md->disk->major = MMC_BLOCK_MAJOR;
  426. md->disk->first_minor = devidx << MMC_SHIFT;
  427. md->disk->fops = &mmc_bdops;
  428. md->disk->private_data = md;
  429. md->disk->queue = md->queue.queue;
  430. md->disk->driverfs_dev = &card->dev;
  431. /*
  432. * As discussed on lkml, GENHD_FL_REMOVABLE should:
  433. *
  434. * - be set for removable media with permanent block devices
  435. * - be unset for removable block devices with permanent media
  436. *
  437. * Since MMC block devices clearly fall under the second
  438. * case, we do not set GENHD_FL_REMOVABLE. Userspace
  439. * should use the block device creation/destruction hotplug
  440. * messages to tell when the card is present.
  441. */
  442. sprintf(md->disk->disk_name, "mmcblk%d", devidx);
  443. blk_queue_logical_block_size(md->queue.queue, 512);
  444. if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
  445. /*
  446. * The EXT_CSD sector count is in number or 512 byte
  447. * sectors.
  448. */
  449. set_capacity(md->disk, card->ext_csd.sectors);
  450. } else {
  451. /*
  452. * The CSD capacity field is in units of read_blkbits.
  453. * set_capacity takes units of 512 bytes.
  454. */
  455. set_capacity(md->disk,
  456. card->csd.capacity << (card->csd.read_blkbits - 9));
  457. }
  458. return md;
  459. err_putdisk:
  460. put_disk(md->disk);
  461. err_kfree:
  462. kfree(md);
  463. out:
  464. return ERR_PTR(ret);
  465. }
  466. static int
  467. mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
  468. {
  469. struct mmc_command cmd;
  470. int err;
  471. /* Block-addressed cards ignore MMC_SET_BLOCKLEN. */
  472. if (mmc_card_blockaddr(card))
  473. return 0;
  474. mmc_claim_host(card->host);
  475. cmd.opcode = MMC_SET_BLOCKLEN;
  476. cmd.arg = 512;
  477. cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
  478. err = mmc_wait_for_cmd(card->host, &cmd, 5);
  479. mmc_release_host(card->host);
  480. if (err) {
  481. printk(KERN_ERR "%s: unable to set block size to %d: %d\n",
  482. md->disk->disk_name, cmd.arg, err);
  483. return -EINVAL;
  484. }
  485. return 0;
  486. }
  487. static int mmc_blk_probe(struct mmc_card *card)
  488. {
  489. struct mmc_blk_data *md;
  490. int err;
  491. char cap_str[10];
  492. /*
  493. * Check that the card supports the command class(es) we need.
  494. */
  495. if (!(card->csd.cmdclass & CCC_BLOCK_READ))
  496. return -ENODEV;
  497. md = mmc_blk_alloc(card);
  498. if (IS_ERR(md))
  499. return PTR_ERR(md);
  500. err = mmc_blk_set_blksize(md, card);
  501. if (err)
  502. goto out;
  503. string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2,
  504. cap_str, sizeof(cap_str));
  505. printk(KERN_INFO "%s: %s %s %s %s\n",
  506. md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
  507. cap_str, md->read_only ? "(ro)" : "");
  508. mmc_set_drvdata(card, md);
  509. add_disk(md->disk);
  510. return 0;
  511. out:
  512. mmc_cleanup_queue(&md->queue);
  513. mmc_blk_put(md);
  514. return err;
  515. }
  516. static void mmc_blk_remove(struct mmc_card *card)
  517. {
  518. struct mmc_blk_data *md = mmc_get_drvdata(card);
  519. if (md) {
  520. /* Stop new requests from getting into the queue */
  521. del_gendisk(md->disk);
  522. /* Then flush out any already in there */
  523. mmc_cleanup_queue(&md->queue);
  524. mmc_blk_put(md);
  525. }
  526. mmc_set_drvdata(card, NULL);
  527. }
  528. #ifdef CONFIG_PM
  529. static int mmc_blk_suspend(struct mmc_card *card, pm_message_t state)
  530. {
  531. struct mmc_blk_data *md = mmc_get_drvdata(card);
  532. if (md) {
  533. mmc_queue_suspend(&md->queue);
  534. }
  535. return 0;
  536. }
  537. static int mmc_blk_resume(struct mmc_card *card)
  538. {
  539. struct mmc_blk_data *md = mmc_get_drvdata(card);
  540. if (md) {
  541. mmc_blk_set_blksize(md, card);
  542. mmc_queue_resume(&md->queue);
  543. }
  544. return 0;
  545. }
  546. #else
  547. #define mmc_blk_suspend NULL
  548. #define mmc_blk_resume NULL
  549. #endif
  550. static struct mmc_driver mmc_driver = {
  551. .drv = {
  552. .name = "mmcblk",
  553. },
  554. .probe = mmc_blk_probe,
  555. .remove = mmc_blk_remove,
  556. .suspend = mmc_blk_suspend,
  557. .resume = mmc_blk_resume,
  558. };
  559. static int __init mmc_blk_init(void)
  560. {
  561. int res;
  562. res = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
  563. if (res)
  564. goto out;
  565. res = mmc_register_driver(&mmc_driver);
  566. if (res)
  567. goto out2;
  568. return 0;
  569. out2:
  570. unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
  571. out:
  572. return res;
  573. }
  574. static void __exit mmc_blk_exit(void)
  575. {
  576. mmc_unregister_driver(&mmc_driver);
  577. unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
  578. }
  579. module_init(mmc_blk_init);
  580. module_exit(mmc_blk_exit);
  581. MODULE_LICENSE("GPL");
  582. MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver");