core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. * @abort: whether or not the operation should be aborted
  234. *
  235. * Claim a host for a set of operations. If @abort is non null and
  236. * dereference a non-zero value then this will return prematurely with
  237. * that non-zero value without acquiring the lock. Returns zero
  238. * with the lock held otherwise.
  239. */
  240. int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
  241. {
  242. DECLARE_WAITQUEUE(wait, current);
  243. unsigned long flags;
  244. int stop;
  245. might_sleep();
  246. add_wait_queue(&host->wq, &wait);
  247. spin_lock_irqsave(&host->lock, flags);
  248. while (1) {
  249. set_current_state(TASK_UNINTERRUPTIBLE);
  250. stop = abort ? atomic_read(abort) : 0;
  251. if (stop || !host->claimed)
  252. break;
  253. spin_unlock_irqrestore(&host->lock, flags);
  254. schedule();
  255. spin_lock_irqsave(&host->lock, flags);
  256. }
  257. set_current_state(TASK_RUNNING);
  258. if (!stop)
  259. host->claimed = 1;
  260. else
  261. wake_up(&host->wq);
  262. spin_unlock_irqrestore(&host->lock, flags);
  263. remove_wait_queue(&host->wq, &wait);
  264. return stop;
  265. }
  266. EXPORT_SYMBOL(__mmc_claim_host);
  267. /**
  268. * mmc_release_host - release a host
  269. * @host: mmc host to release
  270. *
  271. * Release a MMC host, allowing others to claim the host
  272. * for their operations.
  273. */
  274. void mmc_release_host(struct mmc_host *host)
  275. {
  276. unsigned long flags;
  277. BUG_ON(!host->claimed);
  278. spin_lock_irqsave(&host->lock, flags);
  279. host->claimed = 0;
  280. spin_unlock_irqrestore(&host->lock, flags);
  281. wake_up(&host->wq);
  282. }
  283. EXPORT_SYMBOL(mmc_release_host);
  284. /*
  285. * Internal function that does the actual ios call to the host driver,
  286. * optionally printing some debug output.
  287. */
  288. static inline void mmc_set_ios(struct mmc_host *host)
  289. {
  290. struct mmc_ios *ios = &host->ios;
  291. pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
  292. "width %u timing %u\n",
  293. mmc_hostname(host), ios->clock, ios->bus_mode,
  294. ios->power_mode, ios->chip_select, ios->vdd,
  295. ios->bus_width, ios->timing);
  296. host->ops->set_ios(host, ios);
  297. }
  298. /*
  299. * Control chip select pin on a host.
  300. */
  301. void mmc_set_chip_select(struct mmc_host *host, int mode)
  302. {
  303. host->ios.chip_select = mode;
  304. mmc_set_ios(host);
  305. }
  306. /*
  307. * Sets the host clock to the highest possible frequency that
  308. * is below "hz".
  309. */
  310. void mmc_set_clock(struct mmc_host *host, unsigned int hz)
  311. {
  312. WARN_ON(hz < host->f_min);
  313. if (hz > host->f_max)
  314. hz = host->f_max;
  315. host->ios.clock = hz;
  316. mmc_set_ios(host);
  317. }
  318. /*
  319. * Change the bus mode (open drain/push-pull) of a host.
  320. */
  321. void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode)
  322. {
  323. host->ios.bus_mode = mode;
  324. mmc_set_ios(host);
  325. }
  326. /*
  327. * Change data bus width of a host.
  328. */
  329. void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
  330. {
  331. host->ios.bus_width = width;
  332. mmc_set_ios(host);
  333. }
  334. /*
  335. * Mask off any voltages we don't support and select
  336. * the lowest voltage
  337. */
  338. u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
  339. {
  340. int bit;
  341. ocr &= host->ocr_avail;
  342. bit = ffs(ocr);
  343. if (bit) {
  344. bit -= 1;
  345. ocr &= 3 << bit;
  346. host->ios.vdd = bit;
  347. mmc_set_ios(host);
  348. } else {
  349. ocr = 0;
  350. }
  351. return ocr;
  352. }
  353. /*
  354. * Select timing parameters for host.
  355. */
  356. void mmc_set_timing(struct mmc_host *host, unsigned int timing)
  357. {
  358. host->ios.timing = timing;
  359. mmc_set_ios(host);
  360. }
  361. /*
  362. * Apply power to the MMC stack. This is a two-stage process.
  363. * First, we enable power to the card without the clock running.
  364. * We then wait a bit for the power to stabilise. Finally,
  365. * enable the bus drivers and clock to the card.
  366. *
  367. * We must _NOT_ enable the clock prior to power stablising.
  368. *
  369. * If a host does all the power sequencing itself, ignore the
  370. * initial MMC_POWER_UP stage.
  371. */
  372. static void mmc_power_up(struct mmc_host *host)
  373. {
  374. int bit = fls(host->ocr_avail) - 1;
  375. host->ios.vdd = bit;
  376. host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
  377. host->ios.chip_select = MMC_CS_DONTCARE;
  378. host->ios.power_mode = MMC_POWER_UP;
  379. host->ios.bus_width = MMC_BUS_WIDTH_1;
  380. host->ios.timing = MMC_TIMING_LEGACY;
  381. mmc_set_ios(host);
  382. mmc_delay(1);
  383. host->ios.clock = host->f_min;
  384. host->ios.power_mode = MMC_POWER_ON;
  385. mmc_set_ios(host);
  386. mmc_delay(2);
  387. }
  388. static void mmc_power_off(struct mmc_host *host)
  389. {
  390. host->ios.clock = 0;
  391. host->ios.vdd = 0;
  392. host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
  393. host->ios.chip_select = MMC_CS_DONTCARE;
  394. host->ios.power_mode = MMC_POWER_OFF;
  395. host->ios.bus_width = MMC_BUS_WIDTH_1;
  396. host->ios.timing = MMC_TIMING_LEGACY;
  397. mmc_set_ios(host);
  398. }
  399. /*
  400. * Cleanup when the last reference to the bus operator is dropped.
  401. */
  402. void __mmc_release_bus(struct mmc_host *host)
  403. {
  404. BUG_ON(!host);
  405. BUG_ON(host->bus_refs);
  406. BUG_ON(!host->bus_dead);
  407. host->bus_ops = NULL;
  408. }
  409. /*
  410. * Increase reference count of bus operator
  411. */
  412. static inline void mmc_bus_get(struct mmc_host *host)
  413. {
  414. unsigned long flags;
  415. spin_lock_irqsave(&host->lock, flags);
  416. host->bus_refs++;
  417. spin_unlock_irqrestore(&host->lock, flags);
  418. }
  419. /*
  420. * Decrease reference count of bus operator and free it if
  421. * it is the last reference.
  422. */
  423. static inline void mmc_bus_put(struct mmc_host *host)
  424. {
  425. unsigned long flags;
  426. spin_lock_irqsave(&host->lock, flags);
  427. host->bus_refs--;
  428. if ((host->bus_refs == 0) && host->bus_ops)
  429. __mmc_release_bus(host);
  430. spin_unlock_irqrestore(&host->lock, flags);
  431. }
  432. /*
  433. * Assign a mmc bus handler to a host. Only one bus handler may control a
  434. * host at any given time.
  435. */
  436. void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
  437. {
  438. unsigned long flags;
  439. BUG_ON(!host);
  440. BUG_ON(!ops);
  441. BUG_ON(!host->claimed);
  442. spin_lock_irqsave(&host->lock, flags);
  443. BUG_ON(host->bus_ops);
  444. BUG_ON(host->bus_refs);
  445. host->bus_ops = ops;
  446. host->bus_refs = 1;
  447. host->bus_dead = 0;
  448. spin_unlock_irqrestore(&host->lock, flags);
  449. }
  450. /*
  451. * Remove the current bus handler from a host. Assumes that there are
  452. * no interesting cards left, so the bus is powered down.
  453. */
  454. void mmc_detach_bus(struct mmc_host *host)
  455. {
  456. unsigned long flags;
  457. BUG_ON(!host);
  458. BUG_ON(!host->claimed);
  459. BUG_ON(!host->bus_ops);
  460. spin_lock_irqsave(&host->lock, flags);
  461. host->bus_dead = 1;
  462. spin_unlock_irqrestore(&host->lock, flags);
  463. mmc_power_off(host);
  464. mmc_bus_put(host);
  465. }
  466. /**
  467. * mmc_detect_change - process change of state on a MMC socket
  468. * @host: host which changed state.
  469. * @delay: optional delay to wait before detection (jiffies)
  470. *
  471. * MMC drivers should call this when they detect a card has been
  472. * inserted or removed. The MMC layer will confirm that any
  473. * present card is still functional, and initialize any newly
  474. * inserted.
  475. */
  476. void mmc_detect_change(struct mmc_host *host, unsigned long delay)
  477. {
  478. #ifdef CONFIG_MMC_DEBUG
  479. unsigned long flags;
  480. spin_lock_irqsave(&host->lock, flags);
  481. BUG_ON(host->removed);
  482. spin_unlock_irqrestore(&host->lock, flags);
  483. #endif
  484. mmc_schedule_delayed_work(&host->detect, delay);
  485. }
  486. EXPORT_SYMBOL(mmc_detect_change);
  487. void mmc_rescan(struct work_struct *work)
  488. {
  489. struct mmc_host *host =
  490. container_of(work, struct mmc_host, detect.work);
  491. u32 ocr;
  492. int err;
  493. mmc_bus_get(host);
  494. if (host->bus_ops == NULL) {
  495. /*
  496. * Only we can add a new handler, so it's safe to
  497. * release the lock here.
  498. */
  499. mmc_bus_put(host);
  500. mmc_claim_host(host);
  501. mmc_power_up(host);
  502. mmc_go_idle(host);
  503. mmc_send_if_cond(host, host->ocr_avail);
  504. /*
  505. * First we search for SDIO...
  506. */
  507. err = mmc_send_io_op_cond(host, 0, &ocr);
  508. if (!err) {
  509. if (mmc_attach_sdio(host, ocr))
  510. mmc_power_off(host);
  511. return;
  512. }
  513. /*
  514. * ...then normal SD...
  515. */
  516. err = mmc_send_app_op_cond(host, 0, &ocr);
  517. if (!err) {
  518. if (mmc_attach_sd(host, ocr))
  519. mmc_power_off(host);
  520. return;
  521. }
  522. /*
  523. * ...and finally MMC.
  524. */
  525. err = mmc_send_op_cond(host, 0, &ocr);
  526. if (!err) {
  527. if (mmc_attach_mmc(host, ocr))
  528. mmc_power_off(host);
  529. return;
  530. }
  531. mmc_release_host(host);
  532. mmc_power_off(host);
  533. } else {
  534. if (host->bus_ops->detect && !host->bus_dead)
  535. host->bus_ops->detect(host);
  536. mmc_bus_put(host);
  537. }
  538. }
  539. void mmc_start_host(struct mmc_host *host)
  540. {
  541. mmc_power_off(host);
  542. mmc_detect_change(host, 0);
  543. }
  544. void mmc_stop_host(struct mmc_host *host)
  545. {
  546. #ifdef CONFIG_MMC_DEBUG
  547. unsigned long flags;
  548. spin_lock_irqsave(&host->lock, flags);
  549. host->removed = 1;
  550. spin_unlock_irqrestore(&host->lock, flags);
  551. #endif
  552. mmc_flush_scheduled_work();
  553. mmc_bus_get(host);
  554. if (host->bus_ops && !host->bus_dead) {
  555. if (host->bus_ops->remove)
  556. host->bus_ops->remove(host);
  557. mmc_claim_host(host);
  558. mmc_detach_bus(host);
  559. mmc_release_host(host);
  560. }
  561. mmc_bus_put(host);
  562. BUG_ON(host->card);
  563. mmc_power_off(host);
  564. }
  565. #ifdef CONFIG_PM
  566. /**
  567. * mmc_suspend_host - suspend a host
  568. * @host: mmc host
  569. * @state: suspend mode (PM_SUSPEND_xxx)
  570. */
  571. int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
  572. {
  573. mmc_flush_scheduled_work();
  574. mmc_bus_get(host);
  575. if (host->bus_ops && !host->bus_dead) {
  576. if (host->bus_ops->suspend)
  577. host->bus_ops->suspend(host);
  578. if (!host->bus_ops->resume) {
  579. if (host->bus_ops->remove)
  580. host->bus_ops->remove(host);
  581. mmc_claim_host(host);
  582. mmc_detach_bus(host);
  583. mmc_release_host(host);
  584. }
  585. }
  586. mmc_bus_put(host);
  587. mmc_power_off(host);
  588. return 0;
  589. }
  590. EXPORT_SYMBOL(mmc_suspend_host);
  591. /**
  592. * mmc_resume_host - resume a previously suspended host
  593. * @host: mmc host
  594. */
  595. int mmc_resume_host(struct mmc_host *host)
  596. {
  597. mmc_bus_get(host);
  598. if (host->bus_ops && !host->bus_dead) {
  599. mmc_power_up(host);
  600. BUG_ON(!host->bus_ops->resume);
  601. host->bus_ops->resume(host);
  602. }
  603. mmc_bus_put(host);
  604. /*
  605. * We add a slight delay here so that resume can progress
  606. * in parallel.
  607. */
  608. mmc_detect_change(host, 1);
  609. return 0;
  610. }
  611. EXPORT_SYMBOL(mmc_resume_host);
  612. #endif
  613. static int __init mmc_init(void)
  614. {
  615. int ret;
  616. workqueue = create_singlethread_workqueue("kmmcd");
  617. if (!workqueue)
  618. return -ENOMEM;
  619. ret = mmc_register_bus();
  620. if (ret)
  621. goto destroy_workqueue;
  622. ret = mmc_register_host_class();
  623. if (ret)
  624. goto unregister_bus;
  625. ret = sdio_register_bus();
  626. if (ret)
  627. goto unregister_host_class;
  628. return 0;
  629. unregister_host_class:
  630. mmc_unregister_host_class();
  631. unregister_bus:
  632. mmc_unregister_bus();
  633. destroy_workqueue:
  634. destroy_workqueue(workqueue);
  635. return ret;
  636. }
  637. static void __exit mmc_exit(void)
  638. {
  639. sdio_unregister_bus();
  640. mmc_unregister_host_class();
  641. mmc_unregister_bus();
  642. destroy_workqueue(workqueue);
  643. }
  644. subsys_initcall(mmc_init);
  645. module_exit(mmc_exit);
  646. MODULE_LICENSE("GPL");