core.c 17 KB

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