core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  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. /*
  391. * This delay should be sufficient to allow the power supply
  392. * to reach the minimum voltage.
  393. */
  394. mmc_delay(2);
  395. host->ios.clock = host->f_min;
  396. host->ios.power_mode = MMC_POWER_ON;
  397. mmc_set_ios(host);
  398. /*
  399. * This delay must be at least 74 clock sizes, or 1 ms, or the
  400. * time required to reach a stable voltage.
  401. */
  402. mmc_delay(2);
  403. }
  404. static void mmc_power_off(struct mmc_host *host)
  405. {
  406. host->ios.clock = 0;
  407. host->ios.vdd = 0;
  408. host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
  409. host->ios.chip_select = MMC_CS_DONTCARE;
  410. host->ios.power_mode = MMC_POWER_OFF;
  411. host->ios.bus_width = MMC_BUS_WIDTH_1;
  412. host->ios.timing = MMC_TIMING_LEGACY;
  413. mmc_set_ios(host);
  414. }
  415. /*
  416. * Cleanup when the last reference to the bus operator is dropped.
  417. */
  418. void __mmc_release_bus(struct mmc_host *host)
  419. {
  420. BUG_ON(!host);
  421. BUG_ON(host->bus_refs);
  422. BUG_ON(!host->bus_dead);
  423. host->bus_ops = NULL;
  424. }
  425. /*
  426. * Increase reference count of bus operator
  427. */
  428. static inline void mmc_bus_get(struct mmc_host *host)
  429. {
  430. unsigned long flags;
  431. spin_lock_irqsave(&host->lock, flags);
  432. host->bus_refs++;
  433. spin_unlock_irqrestore(&host->lock, flags);
  434. }
  435. /*
  436. * Decrease reference count of bus operator and free it if
  437. * it is the last reference.
  438. */
  439. static inline void mmc_bus_put(struct mmc_host *host)
  440. {
  441. unsigned long flags;
  442. spin_lock_irqsave(&host->lock, flags);
  443. host->bus_refs--;
  444. if ((host->bus_refs == 0) && host->bus_ops)
  445. __mmc_release_bus(host);
  446. spin_unlock_irqrestore(&host->lock, flags);
  447. }
  448. /*
  449. * Assign a mmc bus handler to a host. Only one bus handler may control a
  450. * host at any given time.
  451. */
  452. void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
  453. {
  454. unsigned long flags;
  455. BUG_ON(!host);
  456. BUG_ON(!ops);
  457. WARN_ON(!host->claimed);
  458. spin_lock_irqsave(&host->lock, flags);
  459. BUG_ON(host->bus_ops);
  460. BUG_ON(host->bus_refs);
  461. host->bus_ops = ops;
  462. host->bus_refs = 1;
  463. host->bus_dead = 0;
  464. spin_unlock_irqrestore(&host->lock, flags);
  465. }
  466. /*
  467. * Remove the current bus handler from a host. Assumes that there are
  468. * no interesting cards left, so the bus is powered down.
  469. */
  470. void mmc_detach_bus(struct mmc_host *host)
  471. {
  472. unsigned long flags;
  473. BUG_ON(!host);
  474. WARN_ON(!host->claimed);
  475. WARN_ON(!host->bus_ops);
  476. spin_lock_irqsave(&host->lock, flags);
  477. host->bus_dead = 1;
  478. spin_unlock_irqrestore(&host->lock, flags);
  479. mmc_power_off(host);
  480. mmc_bus_put(host);
  481. }
  482. /**
  483. * mmc_detect_change - process change of state on a MMC socket
  484. * @host: host which changed state.
  485. * @delay: optional delay to wait before detection (jiffies)
  486. *
  487. * MMC drivers should call this when they detect a card has been
  488. * inserted or removed. The MMC layer will confirm that any
  489. * present card is still functional, and initialize any newly
  490. * inserted.
  491. */
  492. void mmc_detect_change(struct mmc_host *host, unsigned long delay)
  493. {
  494. #ifdef CONFIG_MMC_DEBUG
  495. unsigned long flags;
  496. spin_lock_irqsave(&host->lock, flags);
  497. WARN_ON(host->removed);
  498. spin_unlock_irqrestore(&host->lock, flags);
  499. #endif
  500. mmc_schedule_delayed_work(&host->detect, delay);
  501. }
  502. EXPORT_SYMBOL(mmc_detect_change);
  503. void mmc_rescan(struct work_struct *work)
  504. {
  505. struct mmc_host *host =
  506. container_of(work, struct mmc_host, detect.work);
  507. u32 ocr;
  508. int err;
  509. mmc_bus_get(host);
  510. if (host->bus_ops == NULL) {
  511. /*
  512. * Only we can add a new handler, so it's safe to
  513. * release the lock here.
  514. */
  515. mmc_bus_put(host);
  516. mmc_claim_host(host);
  517. mmc_power_up(host);
  518. mmc_go_idle(host);
  519. mmc_send_if_cond(host, host->ocr_avail);
  520. /*
  521. * First we search for SDIO...
  522. */
  523. err = mmc_send_io_op_cond(host, 0, &ocr);
  524. if (!err) {
  525. if (mmc_attach_sdio(host, ocr))
  526. mmc_power_off(host);
  527. return;
  528. }
  529. /*
  530. * ...then normal SD...
  531. */
  532. err = mmc_send_app_op_cond(host, 0, &ocr);
  533. if (!err) {
  534. if (mmc_attach_sd(host, ocr))
  535. mmc_power_off(host);
  536. return;
  537. }
  538. /*
  539. * ...and finally MMC.
  540. */
  541. err = mmc_send_op_cond(host, 0, &ocr);
  542. if (!err) {
  543. if (mmc_attach_mmc(host, ocr))
  544. mmc_power_off(host);
  545. return;
  546. }
  547. mmc_release_host(host);
  548. mmc_power_off(host);
  549. } else {
  550. if (host->bus_ops->detect && !host->bus_dead)
  551. host->bus_ops->detect(host);
  552. mmc_bus_put(host);
  553. }
  554. }
  555. void mmc_start_host(struct mmc_host *host)
  556. {
  557. mmc_power_off(host);
  558. mmc_detect_change(host, 0);
  559. }
  560. void mmc_stop_host(struct mmc_host *host)
  561. {
  562. #ifdef CONFIG_MMC_DEBUG
  563. unsigned long flags;
  564. spin_lock_irqsave(&host->lock, flags);
  565. host->removed = 1;
  566. spin_unlock_irqrestore(&host->lock, flags);
  567. #endif
  568. mmc_flush_scheduled_work();
  569. mmc_bus_get(host);
  570. if (host->bus_ops && !host->bus_dead) {
  571. if (host->bus_ops->remove)
  572. host->bus_ops->remove(host);
  573. mmc_claim_host(host);
  574. mmc_detach_bus(host);
  575. mmc_release_host(host);
  576. }
  577. mmc_bus_put(host);
  578. BUG_ON(host->card);
  579. mmc_power_off(host);
  580. }
  581. #ifdef CONFIG_PM
  582. /**
  583. * mmc_suspend_host - suspend a host
  584. * @host: mmc host
  585. * @state: suspend mode (PM_SUSPEND_xxx)
  586. */
  587. int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
  588. {
  589. mmc_flush_scheduled_work();
  590. mmc_bus_get(host);
  591. if (host->bus_ops && !host->bus_dead) {
  592. if (host->bus_ops->suspend)
  593. host->bus_ops->suspend(host);
  594. if (!host->bus_ops->resume) {
  595. if (host->bus_ops->remove)
  596. host->bus_ops->remove(host);
  597. mmc_claim_host(host);
  598. mmc_detach_bus(host);
  599. mmc_release_host(host);
  600. }
  601. }
  602. mmc_bus_put(host);
  603. mmc_power_off(host);
  604. return 0;
  605. }
  606. EXPORT_SYMBOL(mmc_suspend_host);
  607. /**
  608. * mmc_resume_host - resume a previously suspended host
  609. * @host: mmc host
  610. */
  611. int mmc_resume_host(struct mmc_host *host)
  612. {
  613. mmc_bus_get(host);
  614. if (host->bus_ops && !host->bus_dead) {
  615. mmc_power_up(host);
  616. BUG_ON(!host->bus_ops->resume);
  617. host->bus_ops->resume(host);
  618. }
  619. mmc_bus_put(host);
  620. /*
  621. * We add a slight delay here so that resume can progress
  622. * in parallel.
  623. */
  624. mmc_detect_change(host, 1);
  625. return 0;
  626. }
  627. EXPORT_SYMBOL(mmc_resume_host);
  628. #endif
  629. static int __init mmc_init(void)
  630. {
  631. int ret;
  632. workqueue = create_singlethread_workqueue("kmmcd");
  633. if (!workqueue)
  634. return -ENOMEM;
  635. ret = mmc_register_bus();
  636. if (ret)
  637. goto destroy_workqueue;
  638. ret = mmc_register_host_class();
  639. if (ret)
  640. goto unregister_bus;
  641. ret = sdio_register_bus();
  642. if (ret)
  643. goto unregister_host_class;
  644. return 0;
  645. unregister_host_class:
  646. mmc_unregister_host_class();
  647. unregister_bus:
  648. mmc_unregister_bus();
  649. destroy_workqueue:
  650. destroy_workqueue(workqueue);
  651. return ret;
  652. }
  653. static void __exit mmc_exit(void)
  654. {
  655. sdio_unregister_bus();
  656. mmc_unregister_host_class();
  657. mmc_unregister_bus();
  658. destroy_workqueue(workqueue);
  659. }
  660. subsys_initcall(mmc_init);
  661. module_exit(mmc_exit);
  662. MODULE_LICENSE("GPL");