2 * linux/drivers/mmc/core/core.c
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-2008 Pierre Ossman, All Rights Reserved.
7 * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved.
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.
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 <linux/leds.h>
22 #include <linux/scatterlist.h>
23 #include <linux/log2.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/wakelock.h>
27 #include <linux/mmc/card.h>
28 #include <linux/mmc/host.h>
29 #include <linux/mmc/mmc.h>
30 #include <linux/mmc/sd.h>
41 static struct workqueue_struct *workqueue;
42 static struct wake_lock mmc_delayed_work_wake_lock;
45 * Enabling software CRCs on the data blocks can be a significant (30%)
46 * performance cost, and for other reasons may not always be desired.
47 * So we allow it it to be disabled.
50 module_param(use_spi_crc, bool, 0);
53 * We normally treat cards as removed during suspend if they are not
54 * known to be on a non-removable bus, to avoid the risk of writing
55 * back data to a different card after resume. Allow this to be
56 * overridden if necessary.
58 #ifdef CONFIG_MMC_UNSAFE_RESUME
59 int mmc_assume_removable;
61 int mmc_assume_removable = 1;
63 module_param_named(removable, mmc_assume_removable, bool, 0644);
66 "MMC/SD cards are removable and may be removed during suspend");
69 * Internal function. Schedule delayed work in the MMC work queue.
71 static int mmc_schedule_delayed_work(struct delayed_work *work,
74 wake_lock(&mmc_delayed_work_wake_lock);
75 return queue_delayed_work(workqueue, work, delay);
79 * Internal function. Flush all scheduled work from the MMC work queue.
81 static void mmc_flush_scheduled_work(void)
83 flush_workqueue(workqueue);
87 * mmc_request_done - finish processing an MMC request
88 * @host: MMC host which completed request
89 * @mrq: MMC request which request
91 * MMC drivers should call this function when they have completed
92 * their processing of a request.
94 void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
96 struct mmc_command *cmd = mrq->cmd;
99 if (err && cmd->retries && mmc_host_is_spi(host)) {
100 if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
104 if (err && cmd->retries) {
105 pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
106 mmc_hostname(host), cmd->opcode, err);
110 host->ops->request(host, mrq);
112 led_trigger_event(host->led, LED_OFF);
114 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
115 mmc_hostname(host), cmd->opcode, err,
116 cmd->resp[0], cmd->resp[1],
117 cmd->resp[2], cmd->resp[3]);
120 pr_debug("%s: %d bytes transferred: %d\n",
122 mrq->data->bytes_xfered, mrq->data->error);
126 pr_debug("%s: (CMD%u): %d: %08x %08x %08x %08x\n",
127 mmc_hostname(host), mrq->stop->opcode,
129 mrq->stop->resp[0], mrq->stop->resp[1],
130 mrq->stop->resp[2], mrq->stop->resp[3]);
138 EXPORT_SYMBOL(mmc_request_done);
141 mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
143 #ifdef CONFIG_MMC_DEBUG
145 struct scatterlist *sg;
148 pr_debug("%s: starting CMD%u arg %08x flags %08x\n",
149 mmc_hostname(host), mrq->cmd->opcode,
150 mrq->cmd->arg, mrq->cmd->flags);
153 pr_debug("%s: blksz %d blocks %d flags %08x "
154 "tsac %d ms nsac %d\n",
155 mmc_hostname(host), mrq->data->blksz,
156 mrq->data->blocks, mrq->data->flags,
157 mrq->data->timeout_ns / 1000000,
158 mrq->data->timeout_clks);
162 pr_debug("%s: CMD%u arg %08x flags %08x\n",
163 mmc_hostname(host), mrq->stop->opcode,
164 mrq->stop->arg, mrq->stop->flags);
167 WARN_ON(!host->claimed);
169 led_trigger_event(host->led, LED_FULL);
174 BUG_ON(mrq->data->blksz > host->max_blk_size);
175 BUG_ON(mrq->data->blocks > host->max_blk_count);
176 BUG_ON(mrq->data->blocks * mrq->data->blksz >
179 #ifdef CONFIG_MMC_DEBUG
181 for_each_sg(mrq->data->sg, sg, mrq->data->sg_len, i)
183 BUG_ON(sz != mrq->data->blocks * mrq->data->blksz);
186 mrq->cmd->data = mrq->data;
187 mrq->data->error = 0;
188 mrq->data->mrq = mrq;
190 mrq->data->stop = mrq->stop;
191 mrq->stop->error = 0;
192 mrq->stop->mrq = mrq;
195 host->ops->request(host, mrq);
198 static void mmc_wait_done(struct mmc_request *mrq)
200 complete(mrq->done_data);
204 * mmc_wait_for_req - start a request and wait for completion
205 * @host: MMC host to start command
206 * @mrq: MMC request to start
208 * Start a new MMC custom command request for a host, and wait
209 * for the command to complete. Does not attempt to parse the
212 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
214 unsigned long waittime;
215 DECLARE_COMPLETION_ONSTACK(complete);
217 mrq->done_data = &complete;
218 mrq->done = mmc_wait_done;
220 mmc_start_request(host, mrq);
222 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
223 waittime = wait_for_completion_timeout(&complete,HZ*7); //for cmd dead. Modifyed by xbw at 2011-06-02
227 printk("%s...%d.. =====!!!!!!!!!CMD%d timeout ===xbw===\n",__FUNCTION__, __LINE__, mrq->cmd->opcode);
230 wait_for_completion(&complete);
234 EXPORT_SYMBOL(mmc_wait_for_req);
237 * mmc_wait_for_cmd - start a command and wait for completion
238 * @host: MMC host to start command
239 * @cmd: MMC command to start
240 * @retries: maximum number of retries
242 * Start a new MMC command for a host, and wait for the command
243 * to complete. Return any error that occurred while the command
244 * was executing. Do not attempt to parse the response.
246 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries)
248 struct mmc_request mrq;
250 WARN_ON(!host->claimed);
252 memset(&mrq, 0, sizeof(struct mmc_request));
254 memset(cmd->resp, 0, sizeof(cmd->resp));
255 cmd->retries = retries;
260 mmc_wait_for_req(host, &mrq);
265 EXPORT_SYMBOL(mmc_wait_for_cmd);
268 * mmc_set_data_timeout - set the timeout for a data command
269 * @data: data phase for command
270 * @card: the MMC card associated with the data transfer
272 * Computes the data timeout parameters according to the
273 * correct algorithm given the card type.
275 void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
280 * SDIO cards only define an upper 1 s limit on access.
282 if (mmc_card_sdio(card)) {
283 data->timeout_ns = 1000000000;
284 data->timeout_clks = 0;
289 * SD cards use a 100 multiplier rather than 10
291 mult = mmc_card_sd(card) ? 100 : 10;
294 * Scale up the multiplier (and therefore the timeout) by
295 * the r2w factor for writes.
297 if (data->flags & MMC_DATA_WRITE)
298 mult <<= card->csd.r2w_factor;
300 data->timeout_ns = card->csd.tacc_ns * mult;
301 data->timeout_clks = card->csd.tacc_clks * mult;
304 * SD cards also have an upper limit on the timeout.
306 if (mmc_card_sd(card)) {
307 unsigned int timeout_us, limit_us;
309 timeout_us = data->timeout_ns / 1000;
310 timeout_us += data->timeout_clks * 1000 /
311 (card->host->ios.clock / 1000);
313 if (data->flags & MMC_DATA_WRITE)
315 * The limit is really 250 ms, but that is
316 * insufficient for some crappy cards.
323 * SDHC cards always use these fixed values.
325 if (timeout_us > limit_us || mmc_card_blockaddr(card)) {
326 data->timeout_ns = limit_us * 1000;
327 data->timeout_clks = 0;
331 * Some cards need very high timeouts if driven in SPI mode.
332 * The worst observed timeout was 900ms after writing a
333 * continuous stream of data until the internal logic
336 if (mmc_host_is_spi(card->host)) {
337 if (data->flags & MMC_DATA_WRITE) {
338 if (data->timeout_ns < 1000000000)
339 data->timeout_ns = 1000000000; /* 1s */
341 if (data->timeout_ns < 100000000)
342 data->timeout_ns = 100000000; /* 100ms */
346 EXPORT_SYMBOL(mmc_set_data_timeout);
349 * mmc_align_data_size - pads a transfer size to a more optimal value
350 * @card: the MMC card associated with the data transfer
351 * @sz: original transfer size
353 * Pads the original data size with a number of extra bytes in
354 * order to avoid controller bugs and/or performance hits
355 * (e.g. some controllers revert to PIO for certain sizes).
357 * Returns the improved size, which might be unmodified.
359 * Note that this function is only relevant when issuing a
360 * single scatter gather entry.
362 unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz)
365 * FIXME: We don't have a system for the controller to tell
366 * the core about its problems yet, so for now we just 32-bit
369 sz = ((sz + 3) / 4) * 4;
373 EXPORT_SYMBOL(mmc_align_data_size);
376 * mmc_host_enable - enable a host.
377 * @host: mmc host to enable
379 * Hosts that support power saving can use the 'enable' and 'disable'
380 * methods to exit and enter power saving states. For more information
381 * see comments for struct mmc_host_ops.
383 int mmc_host_enable(struct mmc_host *host)
385 if (!(host->caps & MMC_CAP_DISABLE))
388 if (host->en_dis_recurs)
391 if (host->nesting_cnt++)
394 cancel_delayed_work_sync(&host->disable);
399 if (host->ops->enable) {
402 host->en_dis_recurs = 1;
403 err = host->ops->enable(host);
404 host->en_dis_recurs = 0;
407 pr_debug("%s: enable error %d\n",
408 mmc_hostname(host), err);
415 EXPORT_SYMBOL(mmc_host_enable);
417 static int mmc_host_do_disable(struct mmc_host *host, int lazy)
419 if (host->ops->disable) {
422 host->en_dis_recurs = 1;
423 err = host->ops->disable(host, lazy);
424 host->en_dis_recurs = 0;
427 pr_debug("%s: disable error %d\n",
428 mmc_hostname(host), err);
432 unsigned long delay = msecs_to_jiffies(err);
434 mmc_schedule_delayed_work(&host->disable, delay);
442 * mmc_host_disable - disable a host.
443 * @host: mmc host to disable
445 * Hosts that support power saving can use the 'enable' and 'disable'
446 * methods to exit and enter power saving states. For more information
447 * see comments for struct mmc_host_ops.
449 int mmc_host_disable(struct mmc_host *host)
453 if (!(host->caps & MMC_CAP_DISABLE))
456 if (host->en_dis_recurs)
459 if (--host->nesting_cnt)
465 err = mmc_host_do_disable(host, 0);
468 EXPORT_SYMBOL(mmc_host_disable);
471 * __mmc_claim_host - exclusively claim a host
472 * @host: mmc host to claim
473 * @abort: whether or not the operation should be aborted
475 * Claim a host for a set of operations. If @abort is non null and
476 * dereference a non-zero value then this will return prematurely with
477 * that non-zero value without acquiring the lock. Returns zero
478 * with the lock held otherwise.
480 int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
482 DECLARE_WAITQUEUE(wait, current);
488 add_wait_queue(&host->wq, &wait);
489 spin_lock_irqsave(&host->lock, flags);
491 set_current_state(TASK_UNINTERRUPTIBLE);
492 stop = abort ? atomic_read(abort) : 0;
493 if (stop || !host->claimed || host->claimer == current)
495 spin_unlock_irqrestore(&host->lock, flags);
497 spin_lock_irqsave(&host->lock, flags);
499 set_current_state(TASK_RUNNING);
502 host->claimer = current;
503 host->claim_cnt += 1;
506 spin_unlock_irqrestore(&host->lock, flags);
507 remove_wait_queue(&host->wq, &wait);
509 mmc_host_enable(host);
513 EXPORT_SYMBOL(__mmc_claim_host);
516 * mmc_try_claim_host - try exclusively to claim a host
517 * @host: mmc host to claim
519 * Returns %1 if the host is claimed, %0 otherwise.
521 int mmc_try_claim_host(struct mmc_host *host)
523 int claimed_host = 0;
526 spin_lock_irqsave(&host->lock, flags);
527 if (!host->claimed || host->claimer == current) {
529 host->claimer = current;
530 host->claim_cnt += 1;
533 spin_unlock_irqrestore(&host->lock, flags);
536 EXPORT_SYMBOL(mmc_try_claim_host);
538 static void mmc_do_release_host(struct mmc_host *host)
542 spin_lock_irqsave(&host->lock, flags);
543 if (--host->claim_cnt) {
544 /* Release for nested claim */
545 spin_unlock_irqrestore(&host->lock, flags);
548 host->claimer = NULL;
549 spin_unlock_irqrestore(&host->lock, flags);
554 void mmc_host_deeper_disable(struct work_struct *work)
556 struct mmc_host *host =
557 container_of(work, struct mmc_host, disable.work);
559 /* If the host is claimed then we do not want to disable it anymore */
560 if (!mmc_try_claim_host(host))
562 mmc_host_do_disable(host, 1);
563 mmc_do_release_host(host);
566 wake_unlock(&mmc_delayed_work_wake_lock);
570 * mmc_host_lazy_disable - lazily disable a host.
571 * @host: mmc host to disable
573 * Hosts that support power saving can use the 'enable' and 'disable'
574 * methods to exit and enter power saving states. For more information
575 * see comments for struct mmc_host_ops.
577 int mmc_host_lazy_disable(struct mmc_host *host)
579 if (!(host->caps & MMC_CAP_DISABLE))
582 if (host->en_dis_recurs)
585 if (--host->nesting_cnt)
591 if (host->disable_delay) {
592 mmc_schedule_delayed_work(&host->disable,
593 msecs_to_jiffies(host->disable_delay));
596 return mmc_host_do_disable(host, 1);
598 EXPORT_SYMBOL(mmc_host_lazy_disable);
601 * mmc_release_host - release a host
602 * @host: mmc host to release
604 * Release a MMC host, allowing others to claim the host
605 * for their operations.
607 void mmc_release_host(struct mmc_host *host)
609 WARN_ON(!host->claimed);
611 mmc_host_lazy_disable(host);
613 mmc_do_release_host(host);
616 EXPORT_SYMBOL(mmc_release_host);
619 * Internal function that does the actual ios call to the host driver,
620 * optionally printing some debug output.
622 static inline void mmc_set_ios(struct mmc_host *host)
624 struct mmc_ios *ios = &host->ios;
626 pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
627 "width %u timing %u\n",
628 mmc_hostname(host), ios->clock, ios->bus_mode,
629 ios->power_mode, ios->chip_select, ios->vdd,
630 ios->bus_width, ios->timing);
632 host->ops->set_ios(host, ios);
636 * Control chip select pin on a host.
638 void mmc_set_chip_select(struct mmc_host *host, int mode)
640 host->ios.chip_select = mode;
645 * Sets the host clock to the highest possible frequency that
648 void mmc_set_clock(struct mmc_host *host, unsigned int hz)
650 WARN_ON(hz < host->f_min);
652 if (hz > host->f_max)
655 host->ios.clock = hz;
660 * Change the bus mode (open drain/push-pull) of a host.
662 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode)
664 host->ios.bus_mode = mode;
669 * Change data bus width of a host.
671 void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
673 host->ios.bus_width = width;
678 * mmc_vdd_to_ocrbitnum - Convert a voltage to the OCR bit number
680 * @low_bits: prefer low bits in boundary cases
682 * This function returns the OCR bit number according to the provided @vdd
683 * value. If conversion is not possible a negative errno value returned.
685 * Depending on the @low_bits flag the function prefers low or high OCR bits
686 * on boundary voltages. For example,
687 * with @low_bits = true, 3300 mV translates to ilog2(MMC_VDD_32_33);
688 * with @low_bits = false, 3300 mV translates to ilog2(MMC_VDD_33_34);
690 * Any value in the [1951:1999] range translates to the ilog2(MMC_VDD_20_21).
692 static int mmc_vdd_to_ocrbitnum(int vdd, bool low_bits)
694 const int max_bit = ilog2(MMC_VDD_35_36);
697 if (vdd < 1650 || vdd > 3600)
700 if (vdd >= 1650 && vdd <= 1950)
701 return ilog2(MMC_VDD_165_195);
706 /* Base 2000 mV, step 100 mV, bit's base 8. */
707 bit = (vdd - 2000) / 100 + 8;
714 * mmc_vddrange_to_ocrmask - Convert a voltage range to the OCR mask
715 * @vdd_min: minimum voltage value (mV)
716 * @vdd_max: maximum voltage value (mV)
718 * This function returns the OCR mask bits according to the provided @vdd_min
719 * and @vdd_max values. If conversion is not possible the function returns 0.
721 * Notes wrt boundary cases:
722 * This function sets the OCR bits for all boundary voltages, for example
723 * [3300:3400] range is translated to MMC_VDD_32_33 | MMC_VDD_33_34 |
724 * MMC_VDD_34_35 mask.
726 u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max)
730 if (vdd_max < vdd_min)
733 /* Prefer high bits for the boundary vdd_max values. */
734 vdd_max = mmc_vdd_to_ocrbitnum(vdd_max, false);
738 /* Prefer low bits for the boundary vdd_min values. */
739 vdd_min = mmc_vdd_to_ocrbitnum(vdd_min, true);
743 /* Fill the mask, from max bit to min bit. */
744 while (vdd_max >= vdd_min)
745 mask |= 1 << vdd_max--;
749 EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
751 #ifdef CONFIG_REGULATOR
754 * mmc_regulator_get_ocrmask - return mask of supported voltages
755 * @supply: regulator to use
757 * This returns either a negative errno, or a mask of voltages that
758 * can be provided to MMC/SD/SDIO devices using the specified voltage
759 * regulator. This would normally be called before registering the
762 int mmc_regulator_get_ocrmask(struct regulator *supply)
768 count = regulator_count_voltages(supply);
772 for (i = 0; i < count; i++) {
776 vdd_uV = regulator_list_voltage(supply, i);
780 vdd_mV = vdd_uV / 1000;
781 result |= mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV);
786 EXPORT_SYMBOL(mmc_regulator_get_ocrmask);
789 * mmc_regulator_set_ocr - set regulator to match host->ios voltage
790 * @vdd_bit: zero for power off, else a bit number (host->ios.vdd)
791 * @supply: regulator to use
793 * Returns zero on success, else negative errno.
795 * MMC host drivers may use this to enable or disable a regulator using
796 * a particular supply voltage. This would normally be called from the
799 int mmc_regulator_set_ocr(struct regulator *supply, unsigned short vdd_bit)
805 enabled = regulator_is_enabled(supply);
813 /* REVISIT mmc_vddrange_to_ocrmask() may have set some
814 * bits this regulator doesn't quite support ... don't
815 * be too picky, most cards and regulators are OK with
816 * a 0.1V range goof (it's a small error percentage).
818 tmp = vdd_bit - ilog2(MMC_VDD_165_195);
820 min_uV = 1650 * 1000;
821 max_uV = 1950 * 1000;
823 min_uV = 1900 * 1000 + tmp * 100 * 1000;
824 max_uV = min_uV + 100 * 1000;
827 /* avoid needless changes to this voltage; the regulator
828 * might not allow this operation
830 voltage = regulator_get_voltage(supply);
833 else if (voltage < min_uV || voltage > max_uV)
834 result = regulator_set_voltage(supply, min_uV, max_uV);
838 if (result == 0 && !enabled)
839 result = regulator_enable(supply);
840 } else if (enabled) {
841 result = regulator_disable(supply);
846 EXPORT_SYMBOL(mmc_regulator_set_ocr);
851 * Mask off any voltages we don't support and select
854 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
858 ocr &= host->ocr_avail;
869 pr_warning("%s: host doesn't support card's voltages\n",
878 * Select timing parameters for host.
880 void mmc_set_timing(struct mmc_host *host, unsigned int timing)
882 host->ios.timing = timing;
887 * Apply power to the MMC stack. This is a two-stage process.
888 * First, we enable power to the card without the clock running.
889 * We then wait a bit for the power to stabilise. Finally,
890 * enable the bus drivers and clock to the card.
892 * We must _NOT_ enable the clock prior to power stablising.
894 * If a host does all the power sequencing itself, ignore the
895 * initial MMC_POWER_UP stage.
897 static void mmc_power_up(struct mmc_host *host)
901 /* If ocr is set, we use it */
903 bit = ffs(host->ocr) - 1;
905 bit = fls(host->ocr_avail) - 1;
908 if (mmc_host_is_spi(host)) {
909 host->ios.chip_select = MMC_CS_HIGH;
910 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
912 host->ios.chip_select = MMC_CS_DONTCARE;
913 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
915 host->ios.power_mode = MMC_POWER_UP;
916 host->ios.bus_width = MMC_BUS_WIDTH_1;
917 host->ios.timing = MMC_TIMING_LEGACY;
921 * This delay should be sufficient to allow the power supply
922 * to reach the minimum voltage.
926 host->ios.clock = host->f_min;
928 host->ios.power_mode = MMC_POWER_ON;
932 * This delay must be at least 74 clock sizes, or 1 ms, or the
933 * time required to reach a stable voltage.
938 static void mmc_power_off(struct mmc_host *host)
942 if (!mmc_host_is_spi(host)) {
943 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
944 host->ios.chip_select = MMC_CS_DONTCARE;
946 host->ios.power_mode = MMC_POWER_OFF;
947 host->ios.bus_width = MMC_BUS_WIDTH_1;
948 host->ios.timing = MMC_TIMING_LEGACY;
953 * Cleanup when the last reference to the bus operator is dropped.
955 static void __mmc_release_bus(struct mmc_host *host)
958 BUG_ON(host->bus_refs);
959 BUG_ON(!host->bus_dead);
961 host->bus_ops = NULL;
965 * Increase reference count of bus operator
967 static inline void mmc_bus_get(struct mmc_host *host)
971 spin_lock_irqsave(&host->lock, flags);
973 spin_unlock_irqrestore(&host->lock, flags);
977 * Decrease reference count of bus operator and free it if
978 * it is the last reference.
980 static inline void mmc_bus_put(struct mmc_host *host)
984 spin_lock_irqsave(&host->lock, flags);
986 if ((host->bus_refs == 0) && host->bus_ops)
987 __mmc_release_bus(host);
988 spin_unlock_irqrestore(&host->lock, flags);
991 int mmc_resume_bus(struct mmc_host *host)
995 if (!mmc_bus_needs_resume(host))
998 printk("%s: Starting deferred resume\n", mmc_hostname(host));
999 spin_lock_irqsave(&host->lock, flags);
1000 host->bus_resume_flags &= ~MMC_BUSRESUME_NEEDS_RESUME;
1001 host->rescan_disable = 0;
1002 spin_unlock_irqrestore(&host->lock, flags);
1005 if (host->bus_ops && !host->bus_dead) {
1007 BUG_ON(!host->bus_ops->resume);
1008 host->bus_ops->resume(host);
1011 if (host->bus_ops->detect && !host->bus_dead)
1012 host->bus_ops->detect(host);
1015 printk("%s: Deferred resume completed\n", mmc_hostname(host));
1019 EXPORT_SYMBOL(mmc_resume_bus);
1022 * Assign a mmc bus handler to a host. Only one bus handler may control a
1023 * host at any given time.
1025 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
1027 unsigned long flags;
1032 WARN_ON(!host->claimed);
1034 spin_lock_irqsave(&host->lock, flags);
1036 BUG_ON(host->bus_ops);
1037 BUG_ON(host->bus_refs);
1039 host->bus_ops = ops;
1043 spin_unlock_irqrestore(&host->lock, flags);
1047 * Remove the current bus handler from a host. Assumes that there are
1048 * no interesting cards left, so the bus is powered down.
1050 void mmc_detach_bus(struct mmc_host *host)
1052 unsigned long flags;
1056 WARN_ON(!host->claimed);
1057 WARN_ON(!host->bus_ops);
1059 spin_lock_irqsave(&host->lock, flags);
1063 spin_unlock_irqrestore(&host->lock, flags);
1065 mmc_power_off(host);
1071 * mmc_detect_change - process change of state on a MMC socket
1072 * @host: host which changed state.
1073 * @delay: optional delay to wait before detection (jiffies)
1075 * MMC drivers should call this when they detect a card has been
1076 * inserted or removed. The MMC layer will confirm that any
1077 * present card is still functional, and initialize any newly
1080 void mmc_detect_change(struct mmc_host *host, unsigned long delay)
1082 #ifdef CONFIG_MMC_DEBUG
1083 unsigned long flags;
1084 spin_lock_irqsave(&host->lock, flags);
1085 WARN_ON(host->removed);
1086 spin_unlock_irqrestore(&host->lock, flags);
1089 mmc_schedule_delayed_work(&host->detect, delay);
1092 EXPORT_SYMBOL(mmc_detect_change);
1094 void mmc_init_erase(struct mmc_card *card)
1098 if (is_power_of_2(card->erase_size))
1099 card->erase_shift = ffs(card->erase_size) - 1;
1101 card->erase_shift = 0;
1104 * It is possible to erase an arbitrarily large area of an SD or MMC
1105 * card. That is not desirable because it can take a long time
1106 * (minutes) potentially delaying more important I/O, and also the
1107 * timeout calculations become increasingly hugely over-estimated.
1108 * Consequently, 'pref_erase' is defined as a guide to limit erases
1109 * to that size and alignment.
1111 * For SD cards that define Allocation Unit size, limit erases to one
1112 * Allocation Unit at a time. For MMC cards that define High Capacity
1113 * Erase Size, whether it is switched on or not, limit to that size.
1114 * Otherwise just have a stab at a good value. For modern cards it
1115 * will end up being 4MiB. Note that if the value is too small, it
1116 * can end up taking longer to erase.
1118 if (mmc_card_sd(card) && card->ssr.au) {
1119 card->pref_erase = card->ssr.au;
1120 card->erase_shift = ffs(card->ssr.au) - 1;
1121 } else if (card->ext_csd.hc_erase_size) {
1122 card->pref_erase = card->ext_csd.hc_erase_size;
1124 sz = (card->csd.capacity << (card->csd.read_blkbits - 9)) >> 11;
1126 card->pref_erase = 512 * 1024 / 512;
1128 card->pref_erase = 1024 * 1024 / 512;
1130 card->pref_erase = 2 * 1024 * 1024 / 512;
1132 card->pref_erase = 4 * 1024 * 1024 / 512;
1133 if (card->pref_erase < card->erase_size)
1134 card->pref_erase = card->erase_size;
1136 sz = card->pref_erase % card->erase_size;
1138 card->pref_erase += card->erase_size - sz;
1143 static void mmc_set_mmc_erase_timeout(struct mmc_card *card,
1144 struct mmc_command *cmd,
1145 unsigned int arg, unsigned int qty)
1147 unsigned int erase_timeout;
1149 if (card->ext_csd.erase_group_def & 1) {
1150 /* High Capacity Erase Group Size uses HC timeouts */
1151 if (arg == MMC_TRIM_ARG)
1152 erase_timeout = card->ext_csd.trim_timeout;
1154 erase_timeout = card->ext_csd.hc_erase_timeout;
1156 /* CSD Erase Group Size uses write timeout */
1157 unsigned int mult = (10 << card->csd.r2w_factor);
1158 unsigned int timeout_clks = card->csd.tacc_clks * mult;
1159 unsigned int timeout_us;
1161 /* Avoid overflow: e.g. tacc_ns=80000000 mult=1280 */
1162 if (card->csd.tacc_ns < 1000000)
1163 timeout_us = (card->csd.tacc_ns * mult) / 1000;
1165 timeout_us = (card->csd.tacc_ns / 1000) * mult;
1168 * ios.clock is only a target. The real clock rate might be
1169 * less but not that much less, so fudge it by multiplying by 2.
1172 timeout_us += (timeout_clks * 1000) /
1173 (card->host->ios.clock / 1000);
1175 erase_timeout = timeout_us / 1000;
1178 * Theoretically, the calculation could underflow so round up
1179 * to 1ms in that case.
1185 /* Multiplier for secure operations */
1186 if (arg & MMC_SECURE_ARGS) {
1187 if (arg == MMC_SECURE_ERASE_ARG)
1188 erase_timeout *= card->ext_csd.sec_erase_mult;
1190 erase_timeout *= card->ext_csd.sec_trim_mult;
1193 erase_timeout *= qty;
1196 * Ensure at least a 1 second timeout for SPI as per
1197 * 'mmc_set_data_timeout()'
1199 if (mmc_host_is_spi(card->host) && erase_timeout < 1000)
1200 erase_timeout = 1000;
1202 cmd->erase_timeout = erase_timeout;
1205 static void mmc_set_sd_erase_timeout(struct mmc_card *card,
1206 struct mmc_command *cmd, unsigned int arg,
1209 if (card->ssr.erase_timeout) {
1210 /* Erase timeout specified in SD Status Register (SSR) */
1211 cmd->erase_timeout = card->ssr.erase_timeout * qty +
1212 card->ssr.erase_offset;
1215 * Erase timeout not specified in SD Status Register (SSR) so
1216 * use 250ms per write block.
1218 cmd->erase_timeout = 250 * qty;
1221 /* Must not be less than 1 second */
1222 if (cmd->erase_timeout < 1000)
1223 cmd->erase_timeout = 1000;
1226 static void mmc_set_erase_timeout(struct mmc_card *card,
1227 struct mmc_command *cmd, unsigned int arg,
1230 if (mmc_card_sd(card))
1231 mmc_set_sd_erase_timeout(card, cmd, arg, qty);
1233 mmc_set_mmc_erase_timeout(card, cmd, arg, qty);
1236 static int mmc_do_erase(struct mmc_card *card, unsigned int from,
1237 unsigned int to, unsigned int arg)
1239 struct mmc_command cmd;
1240 unsigned int qty = 0;
1244 * qty is used to calculate the erase timeout which depends on how many
1245 * erase groups (or allocation units in SD terminology) are affected.
1246 * We count erasing part of an erase group as one erase group.
1247 * For SD, the allocation units are always a power of 2. For MMC, the
1248 * erase group size is almost certainly also power of 2, but it does not
1249 * seem to insist on that in the JEDEC standard, so we fall back to
1250 * division in that case. SD may not specify an allocation unit size,
1251 * in which case the timeout is based on the number of write blocks.
1253 * Note that the timeout for secure trim 2 will only be correct if the
1254 * number of erase groups specified is the same as the total of all
1255 * preceding secure trim 1 commands. Since the power may have been
1256 * lost since the secure trim 1 commands occurred, it is generally
1257 * impossible to calculate the secure trim 2 timeout correctly.
1259 if (card->erase_shift)
1260 qty += ((to >> card->erase_shift) -
1261 (from >> card->erase_shift)) + 1;
1262 else if (mmc_card_sd(card))
1263 qty += to - from + 1;
1265 qty += ((to / card->erase_size) -
1266 (from / card->erase_size)) + 1;
1268 if (!mmc_card_blockaddr(card)) {
1273 memset(&cmd, 0, sizeof(struct mmc_command));
1274 if (mmc_card_sd(card))
1275 cmd.opcode = SD_ERASE_WR_BLK_START;
1277 cmd.opcode = MMC_ERASE_GROUP_START;
1279 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1280 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1282 printk(KERN_ERR "mmc_erase: group start error %d, "
1283 "status %#x\n", err, cmd.resp[0]);
1288 memset(&cmd, 0, sizeof(struct mmc_command));
1289 if (mmc_card_sd(card))
1290 cmd.opcode = SD_ERASE_WR_BLK_END;
1292 cmd.opcode = MMC_ERASE_GROUP_END;
1294 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1295 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1297 printk(KERN_ERR "mmc_erase: group end error %d, status %#x\n",
1303 memset(&cmd, 0, sizeof(struct mmc_command));
1304 cmd.opcode = MMC_ERASE;
1306 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1307 mmc_set_erase_timeout(card, &cmd, arg, qty);
1308 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1310 printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
1316 if (mmc_host_is_spi(card->host))
1320 memset(&cmd, 0, sizeof(struct mmc_command));
1321 cmd.opcode = MMC_SEND_STATUS;
1322 cmd.arg = card->rca << 16;
1323 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
1324 /* Do not retry else we can't see errors */
1325 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1326 if (err || (cmd.resp[0] & 0xFDF92000)) {
1327 printk(KERN_ERR "error %d requesting status %#x\n",
1332 } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
1333 R1_CURRENT_STATE(cmd.resp[0]) == 7);
1339 * mmc_erase - erase sectors.
1340 * @card: card to erase
1341 * @from: first sector to erase
1342 * @nr: number of sectors to erase
1343 * @arg: erase command argument (SD supports only %MMC_ERASE_ARG)
1345 * Caller must claim host before calling this function.
1347 int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
1350 unsigned int rem, to = from + nr;
1352 if (!(card->host->caps & MMC_CAP_ERASE) ||
1353 !(card->csd.cmdclass & CCC_ERASE))
1356 if (!card->erase_size)
1359 if (mmc_card_sd(card) && arg != MMC_ERASE_ARG)
1362 if ((arg & MMC_SECURE_ARGS) &&
1363 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
1366 if ((arg & MMC_TRIM_ARGS) &&
1367 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
1370 if (arg == MMC_SECURE_ERASE_ARG) {
1371 if (from % card->erase_size || nr % card->erase_size)
1375 if (arg == MMC_ERASE_ARG) {
1376 rem = from % card->erase_size;
1378 rem = card->erase_size - rem;
1385 rem = nr % card->erase_size;
1398 /* 'from' and 'to' are inclusive */
1401 return mmc_do_erase(card, from, to, arg);
1403 EXPORT_SYMBOL(mmc_erase);
1405 int mmc_can_erase(struct mmc_card *card)
1407 if ((card->host->caps & MMC_CAP_ERASE) &&
1408 (card->csd.cmdclass & CCC_ERASE) && card->erase_size)
1412 EXPORT_SYMBOL(mmc_can_erase);
1414 int mmc_can_trim(struct mmc_card *card)
1416 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
1420 EXPORT_SYMBOL(mmc_can_trim);
1422 int mmc_can_secure_erase_trim(struct mmc_card *card)
1424 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)
1428 EXPORT_SYMBOL(mmc_can_secure_erase_trim);
1430 int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
1433 if (!card->erase_size)
1435 if (from % card->erase_size || nr % card->erase_size)
1439 EXPORT_SYMBOL(mmc_erase_group_aligned);
1441 void mmc_rescan(struct work_struct *work)
1443 struct mmc_host *host =
1444 container_of(work, struct mmc_host, detect.work);
1447 unsigned long flags;
1448 int extend_wakelock = 0;
1450 spin_lock_irqsave(&host->lock, flags);
1452 if (host->rescan_disable) {
1453 spin_unlock_irqrestore(&host->lock, flags);
1457 spin_unlock_irqrestore(&host->lock, flags);
1462 /* if there is a card registered, check whether it is still present */
1463 if ((host->bus_ops != NULL) && host->bus_ops->detect && !host->bus_dead)
1464 host->bus_ops->detect(host);
1466 /* If the card was removed the bus will be marked
1467 * as dead - extend the wakelock so userspace
1470 extend_wakelock = 1;
1477 /* if there still is a card present, stop here */
1478 if (host->bus_ops != NULL) {
1483 /* detect a newly inserted card */
1486 * Only we can add a new handler, so it's safe to
1487 * release the lock here.
1491 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1492 printk("\n%s...%d.. ===== mmc_rescan Begin....======xbw[%s]=====\n",__FILE__, __LINE__, mmc_hostname(host));
1495 if (host->ops->get_cd && host->ops->get_cd(host) == 0)
1497 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1498 printk("\n=================\n%s..%d.. ====find no SDMMC host.====xbw[%s]=====\n", \
1499 __FUNCTION__, __LINE__, mmc_hostname(host));
1504 mmc_claim_host(host);
1508 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1509 //sdio_reset(host); //This does not make sense , deleted by xbw at 2011-08-08
1516 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1517 //mmc_send_if_cond(host, host->ocr_avail); //This does not make sense, deleted by xbw at 2011-08-08
1519 if( strncmp( mmc_hostname(host) ,"mmc0" , strlen("mmc0")) ){
1521 * First we search for SDIO...
1523 err = mmc_send_io_op_cond(host, 0, &ocr);
1525 printk("\n%s..%d.. ===== Begin to identify card as SDIO-card===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
1527 if (mmc_attach_sdio(host, ocr))
1529 printk("\n=====\n %s..%d.. ===== Initialize SDIO-card unsuccessfully!!! ===xbw[%s]===\n=====\n",\
1530 __FUNCTION__, __LINE__, mmc_hostname(host));
1532 mmc_power_off(host);
1536 printk("%s..%d.. ===== Initialize SDIO successfully. ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
1538 extend_wakelock = 1;
1544 mmc_send_if_cond(host, host->ocr_avail);
1547 * First we search for SDIO...
1549 err = mmc_send_io_op_cond(host, 0, &ocr);
1551 if (mmc_attach_sdio(host, ocr)) {
1552 mmc_claim_host(host);
1553 /* try SDMEM (but not MMC) even if SDIO is broken */
1554 if (mmc_send_app_op_cond(host, 0, &ocr))
1557 if (mmc_attach_sd(host, ocr))
1558 mmc_power_off(host);
1559 extend_wakelock = 1;
1566 * ...then normal SD...
1568 err = mmc_send_app_op_cond(host, 0, &ocr);
1570 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1571 printk("\n%s..%d.. ===== Begin to identify card as SD-card ===xbw[%s]===\n",\
1572 __FUNCTION__, __LINE__, mmc_hostname(host));
1574 if (mmc_attach_sd(host, ocr))
1576 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1577 printk("\n=====\n%s..%d.. ===== Initialize SD-card unsuccessfully!!! ===xbw[%s]===\n====\n",\
1578 __FUNCTION__, __LINE__, mmc_hostname(host));
1580 mmc_power_off(host);
1582 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1585 printk("%s..%d.. ===== Initialize SD-card successfully. ===xbw[%s]===\n",\
1586 __FUNCTION__, __LINE__, mmc_hostname(host));
1589 extend_wakelock = 1;
1594 * ...and finally MMC.
1596 err = mmc_send_op_cond(host, 0, &ocr);
1598 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1599 printk("\n%s..%d.. ===== Begin to identify card as MMC-card ===xbw[%s]===\n",\
1600 __FUNCTION__, __LINE__, mmc_hostname(host));
1602 if (mmc_attach_mmc(host, ocr))
1604 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1605 printk("\n =====\n%s..%d.. ===== Initialize MMC-card unsuccessfully!!! ===xbw[%s]===\n======\n",\
1606 __FUNCTION__, __LINE__, mmc_hostname(host));
1608 mmc_power_off(host);
1610 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1613 printk("%s...%d.. ===== Initialize MMC-card successfully. ===xbw[%s]===\n",\
1614 __FUNCTION__, __LINE__, mmc_hostname(host));
1617 extend_wakelock = 1;
1622 mmc_release_host(host);
1623 mmc_power_off(host);
1626 if (extend_wakelock)
1627 wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);
1629 wake_unlock(&mmc_delayed_work_wake_lock);
1631 if (host->caps & MMC_CAP_NEEDS_POLL)
1632 mmc_schedule_delayed_work(&host->detect, HZ);
1635 void mmc_start_host(struct mmc_host *host)
1637 mmc_power_off(host);
1638 mmc_detect_change(host, 0);
1641 void mmc_stop_host(struct mmc_host *host)
1643 #ifdef CONFIG_MMC_DEBUG
1644 unsigned long flags;
1645 spin_lock_irqsave(&host->lock, flags);
1647 spin_unlock_irqrestore(&host->lock, flags);
1650 if (host->caps & MMC_CAP_DISABLE)
1651 cancel_delayed_work(&host->disable);
1652 cancel_delayed_work_sync(&host->detect);
1653 mmc_flush_scheduled_work();
1655 /* clear pm flags now and let card drivers set them as needed */
1659 if (host->bus_ops && !host->bus_dead) {
1660 if (host->bus_ops->remove)
1661 host->bus_ops->remove(host);
1663 mmc_claim_host(host);
1664 mmc_detach_bus(host);
1665 mmc_release_host(host);
1673 mmc_power_off(host);
1676 void mmc_power_save_host(struct mmc_host *host)
1680 if (!host->bus_ops || host->bus_dead || !host->bus_ops->power_restore) {
1685 if (host->bus_ops->power_save)
1686 host->bus_ops->power_save(host);
1690 mmc_power_off(host);
1692 EXPORT_SYMBOL(mmc_power_save_host);
1694 void mmc_power_restore_host(struct mmc_host *host)
1698 if (!host->bus_ops || host->bus_dead || !host->bus_ops->power_restore) {
1704 host->bus_ops->power_restore(host);
1708 EXPORT_SYMBOL(mmc_power_restore_host);
1710 int mmc_card_awake(struct mmc_host *host)
1716 if (host->bus_ops && !host->bus_dead && host->bus_ops->awake)
1717 err = host->bus_ops->awake(host);
1723 EXPORT_SYMBOL(mmc_card_awake);
1725 int mmc_card_sleep(struct mmc_host *host)
1731 if (host->bus_ops && !host->bus_dead && host->bus_ops->awake)
1732 err = host->bus_ops->sleep(host);
1738 EXPORT_SYMBOL(mmc_card_sleep);
1740 int mmc_card_can_sleep(struct mmc_host *host)
1742 struct mmc_card *card = host->card;
1744 if (card && mmc_card_mmc(card) && card->ext_csd.rev >= 3)
1748 EXPORT_SYMBOL(mmc_card_can_sleep);
1753 * mmc_suspend_host - suspend a host
1756 int mmc_suspend_host(struct mmc_host *host)
1760 if (mmc_bus_needs_resume(host))
1763 if (host->caps & MMC_CAP_DISABLE)
1764 cancel_delayed_work(&host->disable);
1765 cancel_delayed_work(&host->detect);
1766 mmc_flush_scheduled_work();
1769 if (host->bus_ops && !host->bus_dead) {
1770 if (host->bus_ops->suspend)
1771 err = host->bus_ops->suspend(host);
1772 if (err == -ENOSYS || !host->bus_ops->resume) {
1774 * We simply "remove" the card in this case.
1775 * It will be redetected on resume.
1777 if (host->bus_ops->remove)
1778 host->bus_ops->remove(host);
1779 mmc_claim_host(host);
1780 mmc_detach_bus(host);
1781 mmc_release_host(host);
1788 if (!err && !(host->pm_flags & MMC_PM_KEEP_POWER))
1789 mmc_power_off(host);
1794 EXPORT_SYMBOL(mmc_suspend_host);
1797 * mmc_resume_host - resume a previously suspended host
1800 int mmc_resume_host(struct mmc_host *host)
1805 if (mmc_bus_manual_resume(host)) {
1806 host->bus_resume_flags |= MMC_BUSRESUME_NEEDS_RESUME;
1811 if (host->bus_ops && !host->bus_dead) {
1812 if (!(host->pm_flags & MMC_PM_KEEP_POWER)) {
1814 mmc_select_voltage(host, host->ocr);
1816 BUG_ON(!host->bus_ops->resume);
1817 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1818 //panic if the card is being removed during the resume, deleted by xbw at 2011-06-20
1819 host->bus_ops->resume(host);
1822 err = host->bus_ops->resume(host);
1824 printk(KERN_WARNING "%s: error %d during resume "
1825 "(card was removed?)\n",
1826 mmc_hostname(host), err);
1835 EXPORT_SYMBOL(mmc_resume_host);
1837 /* Do the card removal on suspend if card is assumed removeable
1838 * Do that in pm notifier while userspace isn't yet frozen, so we will be able
1841 int mmc_pm_notify(struct notifier_block *notify_block,
1842 unsigned long mode, void *unused)
1844 struct mmc_host *host = container_of(
1845 notify_block, struct mmc_host, pm_notify);
1846 unsigned long flags;
1850 case PM_HIBERNATION_PREPARE:
1851 case PM_SUSPEND_PREPARE:
1853 spin_lock_irqsave(&host->lock, flags);
1854 if (mmc_bus_needs_resume(host)) {
1855 spin_unlock_irqrestore(&host->lock, flags);
1858 host->rescan_disable = 1;
1859 spin_unlock_irqrestore(&host->lock, flags);
1860 cancel_delayed_work_sync(&host->detect);
1862 if (!host->bus_ops || host->bus_ops->suspend)
1865 mmc_claim_host(host);
1867 if (host->bus_ops->remove)
1868 host->bus_ops->remove(host);
1870 mmc_detach_bus(host);
1871 mmc_release_host(host);
1875 case PM_POST_SUSPEND:
1876 case PM_POST_HIBERNATION:
1877 case PM_POST_RESTORE:
1879 spin_lock_irqsave(&host->lock, flags);
1880 if (mmc_bus_manual_resume(host)) {
1881 spin_unlock_irqrestore(&host->lock, flags);
1884 host->rescan_disable = 0;
1885 spin_unlock_irqrestore(&host->lock, flags);
1886 mmc_detect_change(host, 0);
1894 #ifdef CONFIG_MMC_EMBEDDED_SDIO
1895 void mmc_set_embedded_sdio_data(struct mmc_host *host,
1896 struct sdio_cis *cis,
1897 struct sdio_cccr *cccr,
1898 struct sdio_embedded_func *funcs,
1901 host->embedded_sdio_data.cis = cis;
1902 host->embedded_sdio_data.cccr = cccr;
1903 host->embedded_sdio_data.funcs = funcs;
1904 host->embedded_sdio_data.num_funcs = num_funcs;
1907 EXPORT_SYMBOL(mmc_set_embedded_sdio_data);
1910 static int __init mmc_init(void)
1914 wake_lock_init(&mmc_delayed_work_wake_lock, WAKE_LOCK_SUSPEND, "mmc_delayed_work");
1916 workqueue = create_singlethread_workqueue("kmmcd");
1920 ret = mmc_register_bus();
1922 goto destroy_workqueue;
1924 ret = mmc_register_host_class();
1926 goto unregister_bus;
1928 ret = sdio_register_bus();
1930 goto unregister_host_class;
1934 unregister_host_class:
1935 mmc_unregister_host_class();
1937 mmc_unregister_bus();
1939 destroy_workqueue(workqueue);
1944 static void __exit mmc_exit(void)
1946 sdio_unregister_bus();
1947 mmc_unregister_host_class();
1948 mmc_unregister_bus();
1949 destroy_workqueue(workqueue);
1950 wake_lock_destroy(&mmc_delayed_work_wake_lock);
1953 subsys_initcall(mmc_init);
1954 module_exit(mmc_exit);
1956 MODULE_LICENSE("GPL");