core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * linux/drivers/mmc/core/core.c
  3. *
  4. * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
  5. * SD support Copyright (C) 2004 Ian Molton, All Rights Reserved.
  6. * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
  7. * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/completion.h>
  17. #include <linux/device.h>
  18. #include <linux/delay.h>
  19. #include <linux/pagemap.h>
  20. #include <linux/err.h>
  21. #include <asm/scatterlist.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/mmc/card.h>
  24. #include <linux/mmc/host.h>
  25. #include <linux/mmc/mmc.h>
  26. #include <linux/mmc/sd.h>
  27. #include "core.h"
  28. #include "bus.h"
  29. #include "host.h"
  30. #include "sdio_bus.h"
  31. #include "mmc_ops.h"
  32. #include "sd_ops.h"
  33. #include "sdio_ops.h"
  34. extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr);
  35. extern int mmc_attach_sd(struct mmc_host *host, u32 ocr);
  36. extern int mmc_attach_sdio(struct mmc_host *host, u32 ocr);
  37. static struct workqueue_struct *workqueue;
  38. /*
  39. * Internal function. Schedule delayed work in the MMC work queue.
  40. */
  41. static int mmc_schedule_delayed_work(struct delayed_work *work,
  42. unsigned long delay)
  43. {
  44. return queue_delayed_work(workqueue, work, delay);
  45. }
  46. /*
  47. * Internal function. Flush all scheduled work from the MMC work queue.
  48. */
  49. static void mmc_flush_scheduled_work(void)
  50. {
  51. flush_workqueue(workqueue);
  52. }
  53. /**
  54. * mmc_request_done - finish processing an MMC request
  55. * @host: MMC host which completed request
  56. * @mrq: MMC request which request
  57. *
  58. * MMC drivers should call this function when they have completed
  59. * their processing of a request.
  60. */
  61. void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
  62. {
  63. struct mmc_command *cmd = mrq->cmd;
  64. int err = cmd->error;
  65. if (err && cmd->retries) {
  66. pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
  67. mmc_hostname(host), cmd->opcode, err);
  68. cmd->retries--;
  69. cmd->error = 0;
  70. host->ops->request(host, mrq);
  71. } else {
  72. pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
  73. mmc_hostname(host), cmd->opcode, err,
  74. cmd->resp[0], cmd->resp[1],
  75. cmd->resp[2], cmd->resp[3]);
  76. if (mrq->data) {
  77. pr_debug("%s: %d bytes transferred: %d\n",
  78. mmc_hostname(host),
  79. mrq->data->bytes_xfered, mrq->data->error);
  80. }
  81. if (mrq->stop) {
  82. pr_debug("%s: (CMD%u): %d: %08x %08x %08x %08x\n",
  83. mmc_hostname(host), mrq->stop->opcode,
  84. mrq->stop->error,
  85. mrq->stop->resp[0], mrq->stop->resp[1],
  86. mrq->stop->resp[2], mrq->stop->resp[3]);
  87. }
  88. if (mrq->done)
  89. mrq->done(mrq);
  90. }
  91. }
  92. EXPORT_SYMBOL(mmc_request_done);
  93. static void
  94. mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
  95. {
  96. #ifdef CONFIG_MMC_DEBUG
  97. unsigned int i, sz;
  98. #endif
  99. pr_debug("%s: starting CMD%u arg %08x flags %08x\n",
  100. mmc_hostname(host), mrq->cmd->opcode,
  101. mrq->cmd->arg, mrq->cmd->flags);
  102. if (mrq->data) {
  103. pr_debug("%s: blksz %d blocks %d flags %08x "
  104. "tsac %d ms nsac %d\n",
  105. mmc_hostname(host), mrq->data->blksz,
  106. mrq->data->blocks, mrq->data->flags,
  107. mrq->data->timeout_ns / 10000000,
  108. mrq->data->timeout_clks);
  109. }
  110. if (mrq->stop) {
  111. pr_debug("%s: CMD%u arg %08x flags %08x\n",
  112. mmc_hostname(host), mrq->stop->opcode,
  113. mrq->stop->arg, mrq->stop->flags);
  114. }
  115. WARN_ON(!host->claimed);
  116. mrq->cmd->error = 0;
  117. mrq->cmd->mrq = mrq;
  118. if (mrq->data) {
  119. BUG_ON(mrq->data->blksz > host->max_blk_size);
  120. BUG_ON(mrq->data->blocks > host->max_blk_count);
  121. BUG_ON(mrq->data->blocks * mrq->data->blksz >
  122. host->max_req_size);
  123. #ifdef CONFIG_MMC_DEBUG
  124. sz = 0;
  125. for (i = 0;i < mrq->data->sg_len;i++)
  126. sz += mrq->data->sg[i].length;
  127. BUG_ON(sz != mrq->data->blocks * mrq->data->blksz);
  128. #endif
  129. mrq->cmd->data = mrq->data;
  130. mrq->data->error = 0;
  131. mrq->data->mrq = mrq;
  132. if (mrq->stop) {
  133. mrq->data->stop = mrq->stop;
  134. mrq->stop->error = 0;
  135. mrq->stop->mrq = mrq;
  136. }
  137. }
  138. host->ops->request(host, mrq);
  139. }
  140. static void mmc_wait_done(struct mmc_request *mrq)
  141. {
  142. complete(mrq->done_data);
  143. }
  144. /**
  145. * mmc_wait_for_req - start a request and wait for completion
  146. * @host: MMC host to start command
  147. * @mrq: MMC request to start
  148. *
  149. * Start a new MMC custom command request for a host, and wait
  150. * for the command to complete. Does not attempt to parse the
  151. * response.
  152. */
  153. void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
  154. {
  155. DECLARE_COMPLETION_ONSTACK(complete);
  156. mrq->done_data = &complete;
  157. mrq->done = mmc_wait_done;
  158. mmc_start_request(host, mrq);
  159. wait_for_completion(&complete);
  160. }
  161. EXPORT_SYMBOL(mmc_wait_for_req);
  162. /**
  163. * mmc_wait_for_cmd - start a command and wait for completion
  164. * @host: MMC host to start command
  165. * @cmd: MMC command to start
  166. * @retries: maximum number of retries
  167. *
  168. * Start a new MMC command for a host, and wait for the command
  169. * to complete. Return any error that occurred while the command
  170. * was executing. Do not attempt to parse the response.
  171. */
  172. int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries)
  173. {
  174. struct mmc_request mrq;
  175. BUG_ON(!host->claimed);
  176. memset(&mrq, 0, sizeof(struct mmc_request));
  177. memset(cmd->resp, 0, sizeof(cmd->resp));
  178. cmd->retries = retries;
  179. mrq.cmd = cmd;
  180. cmd->data = NULL;
  181. mmc_wait_for_req(host, &mrq);
  182. return cmd->error;
  183. }
  184. EXPORT_SYMBOL(mmc_wait_for_cmd);
  185. /**
  186. * mmc_set_data_timeout - set the timeout for a data command
  187. * @data: data phase for command
  188. * @card: the MMC card associated with the data transfer
  189. *
  190. * Computes the data timeout parameters according to the
  191. * correct algorithm given the card type.
  192. */
  193. void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
  194. {
  195. unsigned int mult;
  196. /*
  197. * SD cards use a 100 multiplier rather than 10
  198. */
  199. mult = mmc_card_sd(card) ? 100 : 10;
  200. /*
  201. * Scale up the multiplier (and therefore the timeout) by
  202. * the r2w factor for writes.
  203. */
  204. if (data->flags & MMC_DATA_WRITE)
  205. mult <<= card->csd.r2w_factor;
  206. data->timeout_ns = card->csd.tacc_ns * mult;
  207. data->timeout_clks = card->csd.tacc_clks * mult;
  208. /*
  209. * SD cards also have an upper limit on the timeout.
  210. */
  211. if (mmc_card_sd(card)) {
  212. unsigned int timeout_us, limit_us;
  213. timeout_us = data->timeout_ns / 1000;
  214. timeout_us += data->timeout_clks * 1000 /
  215. (card->host->ios.clock / 1000);
  216. if (data->flags & MMC_DATA_WRITE)
  217. limit_us = 250000;
  218. else
  219. limit_us = 100000;
  220. /*
  221. * SDHC cards always use these fixed values.
  222. */
  223. if (timeout_us > limit_us || mmc_card_blockaddr(card)) {
  224. data->timeout_ns = limit_us * 1000;
  225. data->timeout_clks = 0;
  226. }
  227. }
  228. }
  229. EXPORT_SYMBOL(mmc_set_data_timeout);
  230. /**
  231. * mmc_claim_host - exclusively claim a host
  232. * @host: mmc host to claim
  233. *
  234. * Claim a host for a set of operations.
  235. */
  236. void mmc_claim_host(struct mmc_host *host)
  237. {
  238. DECLARE_WAITQUEUE(wait, current);
  239. unsigned long flags;
  240. might_sleep();
  241. add_wait_queue(&host->wq, &wait);
  242. spin_lock_irqsave(&host->lock, flags);
  243. while (1) {
  244. set_current_state(TASK_UNINTERRUPTIBLE);
  245. if (!host->claimed)
  246. break;
  247. spin_unlock_irqrestore(&host->lock, flags);
  248. schedule();
  249. spin_lock_irqsave(&host->lock, flags);
  250. }
  251. set_current_state(TASK_RUNNING);
  252. host->claimed = 1;
  253. spin_unlock_irqrestore(&host->lock, flags);
  254. remove_wait_queue(&host->wq, &wait);
  255. }
  256. EXPORT_SYMBOL(mmc_claim_host);
  257. /**
  258. * mmc_release_host - release a host
  259. * @host: mmc host to release
  260. *
  261. * Release a MMC host, allowing others to claim the host
  262. * for their operations.
  263. */
  264. void mmc_release_host(struct mmc_host *host)
  265. {
  266. unsigned long flags;
  267. BUG_ON(!host->claimed);
  268. spin_lock_irqsave(&host->lock, flags);
  269. host->claimed = 0;
  270. spin_unlock_irqrestore(&host->lock, flags);
  271. wake_up(&host->wq);
  272. }
  273. EXPORT_SYMBOL(mmc_release_host);
  274. /*
  275. * Internal function that does the actual ios call to the host driver,
  276. * optionally printing some debug output.
  277. */
  278. static inline void mmc_set_ios(struct mmc_host *host)
  279. {
  280. struct mmc_ios *ios = &host->ios;
  281. pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
  282. "width %u timing %u\n",
  283. mmc_hostname(host), ios->clock, ios->bus_mode,
  284. ios->power_mode, ios->chip_select, ios->vdd,
  285. ios->bus_width, ios->timing);
  286. host->ops->set_ios(host, ios);
  287. }
  288. /*
  289. * Control chip select pin on a host.
  290. */
  291. void mmc_set_chip_select(struct mmc_host *host, int mode)
  292. {
  293. host->ios.chip_select = mode;
  294. mmc_set_ios(host);
  295. }
  296. /*
  297. * Sets the host clock to the highest possible frequency that
  298. * is below "hz".
  299. */
  300. void mmc_set_clock(struct mmc_host *host, unsigned int hz)
  301. {
  302. WARN_ON(hz < host->f_min);
  303. if (hz > host->f_max)
  304. hz = host->f_max;
  305. host->ios.clock = hz;
  306. mmc_set_ios(host);
  307. }
  308. /*
  309. * Change the bus mode (open drain/push-pull) of a host.
  310. */
  311. void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode)
  312. {
  313. host->ios.bus_mode = mode;
  314. mmc_set_ios(host);
  315. }
  316. /*
  317. * Change data bus width of a host.
  318. */
  319. void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
  320. {
  321. host->ios.bus_width = width;
  322. mmc_set_ios(host);
  323. }
  324. /*
  325. * Mask off any voltages we don't support and select
  326. * the lowest voltage
  327. */
  328. u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
  329. {
  330. int bit;
  331. ocr &= host->ocr_avail;
  332. bit = ffs(ocr);
  333. if (bit) {
  334. bit -= 1;
  335. ocr &= 3 << bit;
  336. host->ios.vdd = bit;
  337. mmc_set_ios(host);
  338. } else {
  339. ocr = 0;
  340. }
  341. return ocr;
  342. }
  343. /*
  344. * Select timing parameters for host.
  345. */
  346. void mmc_set_timing(struct mmc_host *host, unsigned int timing)
  347. {
  348. host->ios.timing = timing;
  349. mmc_set_ios(host);
  350. }
  351. /*
  352. * Apply power to the MMC stack. This is a two-stage process.
  353. * First, we enable power to the card without the clock running.
  354. * We then wait a bit for the power to stabilise. Finally,
  355. * enable the bus drivers and clock to the card.
  356. *
  357. * We must _NOT_ enable the clock prior to power stablising.
  358. *
  359. * If a host does all the power sequencing itself, ignore the
  360. * initial MMC_POWER_UP stage.
  361. */
  362. static void mmc_power_up(struct mmc_host *host)
  363. {
  364. int bit = fls(host->ocr_avail) - 1;
  365. host->ios.vdd = bit;
  366. host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
  367. host->ios.chip_select = MMC_CS_DONTCARE;
  368. host->ios.power_mode = MMC_POWER_UP;
  369. host->ios.bus_width = MMC_BUS_WIDTH_1;
  370. host->ios.timing = MMC_TIMING_LEGACY;
  371. mmc_set_ios(host);
  372. mmc_delay(1);
  373. host->ios.clock = host->f_min;
  374. host->ios.power_mode = MMC_POWER_ON;
  375. mmc_set_ios(host);
  376. mmc_delay(2);
  377. }
  378. static void mmc_power_off(struct mmc_host *host)
  379. {
  380. host->ios.clock = 0;
  381. host->ios.vdd = 0;
  382. host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
  383. host->ios.chip_select = MMC_CS_DONTCARE;
  384. host->ios.power_mode = MMC_POWER_OFF;
  385. host->ios.bus_width = MMC_BUS_WIDTH_1;
  386. host->ios.timing = MMC_TIMING_LEGACY;
  387. mmc_set_ios(host);
  388. }
  389. /*
  390. * Cleanup when the last reference to the bus operator is dropped.
  391. */
  392. void __mmc_release_bus(struct mmc_host *host)
  393. {
  394. BUG_ON(!host);
  395. BUG_ON(host->bus_refs);
  396. BUG_ON(!host->bus_dead);
  397. host->bus_ops = NULL;
  398. }
  399. /*
  400. * Increase reference count of bus operator
  401. */
  402. static inline void mmc_bus_get(struct mmc_host *host)
  403. {
  404. unsigned long flags;
  405. spin_lock_irqsave(&host->lock, flags);
  406. host->bus_refs++;
  407. spin_unlock_irqrestore(&host->lock, flags);
  408. }
  409. /*
  410. * Decrease reference count of bus operator and free it if
  411. * it is the last reference.
  412. */
  413. static inline void mmc_bus_put(struct mmc_host *host)
  414. {
  415. unsigned long flags;
  416. spin_lock_irqsave(&host->lock, flags);
  417. host->bus_refs--;
  418. if ((host->bus_refs == 0) && host->bus_ops)
  419. __mmc_release_bus(host);
  420. spin_unlock_irqrestore(&host->lock, flags);
  421. }
  422. /*
  423. * Assign a mmc bus handler to a host. Only one bus handler may control a
  424. * host at any given time.
  425. */
  426. void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
  427. {
  428. unsigned long flags;
  429. BUG_ON(!host);
  430. BUG_ON(!ops);
  431. BUG_ON(!host->claimed);
  432. spin_lock_irqsave(&host->lock, flags);
  433. BUG_ON(host->bus_ops);
  434. BUG_ON(host->bus_refs);
  435. host->bus_ops = ops;
  436. host->bus_refs = 1;
  437. host->bus_dead = 0;
  438. spin_unlock_irqrestore(&host->lock, flags);
  439. }
  440. /*
  441. * Remove the current bus handler from a host. Assumes that there are
  442. * no interesting cards left, so the bus is powered down.
  443. */
  444. void mmc_detach_bus(struct mmc_host *host)
  445. {
  446. unsigned long flags;
  447. BUG_ON(!host);
  448. BUG_ON(!host->claimed);
  449. BUG_ON(!host->bus_ops);
  450. spin_lock_irqsave(&host->lock, flags);
  451. host->bus_dead = 1;
  452. spin_unlock_irqrestore(&host->lock, flags);
  453. mmc_power_off(host);
  454. mmc_bus_put(host);
  455. }
  456. /**
  457. * mmc_detect_change - process change of state on a MMC socket
  458. * @host: host which changed state.
  459. * @delay: optional delay to wait before detection (jiffies)
  460. *
  461. * MMC drivers should call this when they detect a card has been
  462. * inserted or removed. The MMC layer will confirm that any
  463. * present card is still functional, and initialize any newly
  464. * inserted.
  465. */
  466. void mmc_detect_change(struct mmc_host *host, unsigned long delay)
  467. {
  468. #ifdef CONFIG_MMC_DEBUG
  469. unsigned long flags;
  470. spin_lock_irqsave(&host->lock, flags);
  471. BUG_ON(host->removed);
  472. spin_unlock_irqrestore(&host->lock, flags);
  473. #endif
  474. mmc_schedule_delayed_work(&host->detect, delay);
  475. }
  476. EXPORT_SYMBOL(mmc_detect_change);
  477. void mmc_rescan(struct work_struct *work)
  478. {
  479. struct mmc_host *host =
  480. container_of(work, struct mmc_host, detect.work);
  481. u32 ocr;
  482. int err;
  483. mmc_bus_get(host);
  484. if (host->bus_ops == NULL) {
  485. /*
  486. * Only we can add a new handler, so it's safe to
  487. * release the lock here.
  488. */
  489. mmc_bus_put(host);
  490. mmc_claim_host(host);
  491. mmc_power_up(host);
  492. mmc_go_idle(host);
  493. mmc_send_if_cond(host, host->ocr_avail);
  494. /*
  495. * First we search for SDIO...
  496. */
  497. err = mmc_send_io_op_cond(host, 0, &ocr);
  498. if (!err) {
  499. if (mmc_attach_sdio(host, ocr))
  500. mmc_power_off(host);
  501. return;
  502. }
  503. /*
  504. * ...then normal SD...
  505. */
  506. err = mmc_send_app_op_cond(host, 0, &ocr);
  507. if (!err) {
  508. if (mmc_attach_sd(host, ocr))
  509. mmc_power_off(host);
  510. return;
  511. }
  512. /*
  513. * ...and finally MMC.
  514. */
  515. err = mmc_send_op_cond(host, 0, &ocr);
  516. if (!err) {
  517. if (mmc_attach_mmc(host, ocr))
  518. mmc_power_off(host);
  519. return;
  520. }
  521. mmc_release_host(host);
  522. mmc_power_off(host);
  523. } else {
  524. if (host->bus_ops->detect && !host->bus_dead)
  525. host->bus_ops->detect(host);
  526. mmc_bus_put(host);
  527. }
  528. }
  529. void mmc_start_host(struct mmc_host *host)
  530. {
  531. mmc_power_off(host);
  532. mmc_detect_change(host, 0);
  533. }
  534. void mmc_stop_host(struct mmc_host *host)
  535. {
  536. #ifdef CONFIG_MMC_DEBUG
  537. unsigned long flags;
  538. spin_lock_irqsave(&host->lock, flags);
  539. host->removed = 1;
  540. spin_unlock_irqrestore(&host->lock, flags);
  541. #endif
  542. mmc_flush_scheduled_work();
  543. mmc_bus_get(host);
  544. if (host->bus_ops && !host->bus_dead) {
  545. if (host->bus_ops->remove)
  546. host->bus_ops->remove(host);
  547. mmc_claim_host(host);
  548. mmc_detach_bus(host);
  549. mmc_release_host(host);
  550. }
  551. mmc_bus_put(host);
  552. BUG_ON(host->card);
  553. mmc_power_off(host);
  554. }
  555. #ifdef CONFIG_PM
  556. /**
  557. * mmc_suspend_host - suspend a host
  558. * @host: mmc host
  559. * @state: suspend mode (PM_SUSPEND_xxx)
  560. */
  561. int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
  562. {
  563. mmc_flush_scheduled_work();
  564. mmc_bus_get(host);
  565. if (host->bus_ops && !host->bus_dead) {
  566. if (host->bus_ops->suspend)
  567. host->bus_ops->suspend(host);
  568. if (!host->bus_ops->resume) {
  569. if (host->bus_ops->remove)
  570. host->bus_ops->remove(host);
  571. mmc_claim_host(host);
  572. mmc_detach_bus(host);
  573. mmc_release_host(host);
  574. }
  575. }
  576. mmc_bus_put(host);
  577. mmc_power_off(host);
  578. return 0;
  579. }
  580. EXPORT_SYMBOL(mmc_suspend_host);
  581. /**
  582. * mmc_resume_host - resume a previously suspended host
  583. * @host: mmc host
  584. */
  585. int mmc_resume_host(struct mmc_host *host)
  586. {
  587. mmc_bus_get(host);
  588. if (host->bus_ops && !host->bus_dead) {
  589. mmc_power_up(host);
  590. BUG_ON(!host->bus_ops->resume);
  591. host->bus_ops->resume(host);
  592. }
  593. mmc_bus_put(host);
  594. /*
  595. * We add a slight delay here so that resume can progress
  596. * in parallel.
  597. */
  598. mmc_detect_change(host, 1);
  599. return 0;
  600. }
  601. EXPORT_SYMBOL(mmc_resume_host);
  602. #endif
  603. static int __init mmc_init(void)
  604. {
  605. int ret;
  606. workqueue = create_singlethread_workqueue("kmmcd");
  607. if (!workqueue)
  608. return -ENOMEM;
  609. ret = mmc_register_bus();
  610. if (ret)
  611. goto destroy_workqueue;
  612. ret = mmc_register_host_class();
  613. if (ret)
  614. goto unregister_bus;
  615. ret = sdio_register_bus();
  616. if (ret)
  617. goto unregister_host_class;
  618. return 0;
  619. unregister_host_class:
  620. mmc_unregister_host_class();
  621. unregister_bus:
  622. mmc_unregister_bus();
  623. destroy_workqueue:
  624. destroy_workqueue(workqueue);
  625. return ret;
  626. }
  627. static void __exit mmc_exit(void)
  628. {
  629. sdio_unregister_bus();
  630. mmc_unregister_host_class();
  631. mmc_unregister_bus();
  632. destroy_workqueue(workqueue);
  633. }
  634. module_init(mmc_init);
  635. module_exit(mmc_exit);
  636. MODULE_LICENSE("GPL");