block.c 16 KB

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