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 DECLARE_COMPLETION_ONSTACK(complete);
216 mrq->done_data = &complete;
217 mrq->done = mmc_wait_done;
219 mmc_start_request(host, mrq);
221 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
222 wait_for_completion_timeout(&complete,HZ*3); //for cmd dead. Modifyed by xbw at 2011-06-02
224 wait_for_completion(&complete);
228 EXPORT_SYMBOL(mmc_wait_for_req);
231 * mmc_wait_for_cmd - start a command and wait for completion
232 * @host: MMC host to start command
233 * @cmd: MMC command to start
234 * @retries: maximum number of retries
236 * Start a new MMC command for a host, and wait for the command
237 * to complete. Return any error that occurred while the command
238 * was executing. Do not attempt to parse the response.
240 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries)
242 struct mmc_request mrq;
244 WARN_ON(!host->claimed);
246 memset(&mrq, 0, sizeof(struct mmc_request));
248 memset(cmd->resp, 0, sizeof(cmd->resp));
249 cmd->retries = retries;
254 mmc_wait_for_req(host, &mrq);
259 EXPORT_SYMBOL(mmc_wait_for_cmd);
262 * mmc_set_data_timeout - set the timeout for a data command
263 * @data: data phase for command
264 * @card: the MMC card associated with the data transfer
266 * Computes the data timeout parameters according to the
267 * correct algorithm given the card type.
269 void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
274 * SDIO cards only define an upper 1 s limit on access.
276 if (mmc_card_sdio(card)) {
277 data->timeout_ns = 1000000000;
278 data->timeout_clks = 0;
283 * SD cards use a 100 multiplier rather than 10
285 mult = mmc_card_sd(card) ? 100 : 10;
288 * Scale up the multiplier (and therefore the timeout) by
289 * the r2w factor for writes.
291 if (data->flags & MMC_DATA_WRITE)
292 mult <<= card->csd.r2w_factor;
294 data->timeout_ns = card->csd.tacc_ns * mult;
295 data->timeout_clks = card->csd.tacc_clks * mult;
298 * SD cards also have an upper limit on the timeout.
300 if (mmc_card_sd(card)) {
301 unsigned int timeout_us, limit_us;
303 timeout_us = data->timeout_ns / 1000;
304 timeout_us += data->timeout_clks * 1000 /
305 (card->host->ios.clock / 1000);
307 if (data->flags & MMC_DATA_WRITE)
309 * The limit is really 250 ms, but that is
310 * insufficient for some crappy cards.
317 * SDHC cards always use these fixed values.
319 if (timeout_us > limit_us || mmc_card_blockaddr(card)) {
320 data->timeout_ns = limit_us * 1000;
321 data->timeout_clks = 0;
325 * Some cards need very high timeouts if driven in SPI mode.
326 * The worst observed timeout was 900ms after writing a
327 * continuous stream of data until the internal logic
330 if (mmc_host_is_spi(card->host)) {
331 if (data->flags & MMC_DATA_WRITE) {
332 if (data->timeout_ns < 1000000000)
333 data->timeout_ns = 1000000000; /* 1s */
335 if (data->timeout_ns < 100000000)
336 data->timeout_ns = 100000000; /* 100ms */
340 EXPORT_SYMBOL(mmc_set_data_timeout);
343 * mmc_align_data_size - pads a transfer size to a more optimal value
344 * @card: the MMC card associated with the data transfer
345 * @sz: original transfer size
347 * Pads the original data size with a number of extra bytes in
348 * order to avoid controller bugs and/or performance hits
349 * (e.g. some controllers revert to PIO for certain sizes).
351 * Returns the improved size, which might be unmodified.
353 * Note that this function is only relevant when issuing a
354 * single scatter gather entry.
356 unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz)
359 * FIXME: We don't have a system for the controller to tell
360 * the core about its problems yet, so for now we just 32-bit
363 sz = ((sz + 3) / 4) * 4;
367 EXPORT_SYMBOL(mmc_align_data_size);
370 * mmc_host_enable - enable a host.
371 * @host: mmc host to enable
373 * Hosts that support power saving can use the 'enable' and 'disable'
374 * methods to exit and enter power saving states. For more information
375 * see comments for struct mmc_host_ops.
377 int mmc_host_enable(struct mmc_host *host)
379 if (!(host->caps & MMC_CAP_DISABLE))
382 if (host->en_dis_recurs)
385 if (host->nesting_cnt++)
388 cancel_delayed_work_sync(&host->disable);
393 if (host->ops->enable) {
396 host->en_dis_recurs = 1;
397 err = host->ops->enable(host);
398 host->en_dis_recurs = 0;
401 pr_debug("%s: enable error %d\n",
402 mmc_hostname(host), err);
409 EXPORT_SYMBOL(mmc_host_enable);
411 static int mmc_host_do_disable(struct mmc_host *host, int lazy)
413 if (host->ops->disable) {
416 host->en_dis_recurs = 1;
417 err = host->ops->disable(host, lazy);
418 host->en_dis_recurs = 0;
421 pr_debug("%s: disable error %d\n",
422 mmc_hostname(host), err);
426 unsigned long delay = msecs_to_jiffies(err);
428 mmc_schedule_delayed_work(&host->disable, delay);
436 * mmc_host_disable - disable a host.
437 * @host: mmc host to disable
439 * Hosts that support power saving can use the 'enable' and 'disable'
440 * methods to exit and enter power saving states. For more information
441 * see comments for struct mmc_host_ops.
443 int mmc_host_disable(struct mmc_host *host)
447 if (!(host->caps & MMC_CAP_DISABLE))
450 if (host->en_dis_recurs)
453 if (--host->nesting_cnt)
459 err = mmc_host_do_disable(host, 0);
462 EXPORT_SYMBOL(mmc_host_disable);
465 * __mmc_claim_host - exclusively claim a host
466 * @host: mmc host to claim
467 * @abort: whether or not the operation should be aborted
469 * Claim a host for a set of operations. If @abort is non null and
470 * dereference a non-zero value then this will return prematurely with
471 * that non-zero value without acquiring the lock. Returns zero
472 * with the lock held otherwise.
474 int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
476 DECLARE_WAITQUEUE(wait, current);
482 add_wait_queue(&host->wq, &wait);
483 spin_lock_irqsave(&host->lock, flags);
485 set_current_state(TASK_UNINTERRUPTIBLE);
486 stop = abort ? atomic_read(abort) : 0;
487 if (stop || !host->claimed || host->claimer == current)
489 spin_unlock_irqrestore(&host->lock, flags);
491 spin_lock_irqsave(&host->lock, flags);
493 set_current_state(TASK_RUNNING);
496 host->claimer = current;
497 host->claim_cnt += 1;
500 spin_unlock_irqrestore(&host->lock, flags);
501 remove_wait_queue(&host->wq, &wait);
503 mmc_host_enable(host);
507 EXPORT_SYMBOL(__mmc_claim_host);
510 * mmc_try_claim_host - try exclusively to claim a host
511 * @host: mmc host to claim
513 * Returns %1 if the host is claimed, %0 otherwise.
515 int mmc_try_claim_host(struct mmc_host *host)
517 int claimed_host = 0;
520 spin_lock_irqsave(&host->lock, flags);
521 if (!host->claimed || host->claimer == current) {
523 host->claimer = current;
524 host->claim_cnt += 1;
527 spin_unlock_irqrestore(&host->lock, flags);
530 EXPORT_SYMBOL(mmc_try_claim_host);
532 static void mmc_do_release_host(struct mmc_host *host)
536 spin_lock_irqsave(&host->lock, flags);
537 if (--host->claim_cnt) {
538 /* Release for nested claim */
539 spin_unlock_irqrestore(&host->lock, flags);
542 host->claimer = NULL;
543 spin_unlock_irqrestore(&host->lock, flags);
548 void mmc_host_deeper_disable(struct work_struct *work)
550 struct mmc_host *host =
551 container_of(work, struct mmc_host, disable.work);
553 /* If the host is claimed then we do not want to disable it anymore */
554 if (!mmc_try_claim_host(host))
556 mmc_host_do_disable(host, 1);
557 mmc_do_release_host(host);
560 wake_unlock(&mmc_delayed_work_wake_lock);
564 * mmc_host_lazy_disable - lazily disable a host.
565 * @host: mmc host to disable
567 * Hosts that support power saving can use the 'enable' and 'disable'
568 * methods to exit and enter power saving states. For more information
569 * see comments for struct mmc_host_ops.
571 int mmc_host_lazy_disable(struct mmc_host *host)
573 if (!(host->caps & MMC_CAP_DISABLE))
576 if (host->en_dis_recurs)
579 if (--host->nesting_cnt)
585 if (host->disable_delay) {
586 mmc_schedule_delayed_work(&host->disable,
587 msecs_to_jiffies(host->disable_delay));
590 return mmc_host_do_disable(host, 1);
592 EXPORT_SYMBOL(mmc_host_lazy_disable);
595 * mmc_release_host - release a host
596 * @host: mmc host to release
598 * Release a MMC host, allowing others to claim the host
599 * for their operations.
601 void mmc_release_host(struct mmc_host *host)
603 WARN_ON(!host->claimed);
605 mmc_host_lazy_disable(host);
607 mmc_do_release_host(host);
610 EXPORT_SYMBOL(mmc_release_host);
613 * Internal function that does the actual ios call to the host driver,
614 * optionally printing some debug output.
616 static inline void mmc_set_ios(struct mmc_host *host)
618 struct mmc_ios *ios = &host->ios;
620 pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
621 "width %u timing %u\n",
622 mmc_hostname(host), ios->clock, ios->bus_mode,
623 ios->power_mode, ios->chip_select, ios->vdd,
624 ios->bus_width, ios->timing);
626 host->ops->set_ios(host, ios);
630 * Control chip select pin on a host.
632 void mmc_set_chip_select(struct mmc_host *host, int mode)
634 host->ios.chip_select = mode;
639 * Sets the host clock to the highest possible frequency that
642 void mmc_set_clock(struct mmc_host *host, unsigned int hz)
644 WARN_ON(hz < host->f_min);
646 if (hz > host->f_max)
649 host->ios.clock = hz;
654 * Change the bus mode (open drain/push-pull) of a host.
656 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode)
658 host->ios.bus_mode = mode;
663 * Change data bus width of a host.
665 void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
667 host->ios.bus_width = width;
672 * mmc_vdd_to_ocrbitnum - Convert a voltage to the OCR bit number
674 * @low_bits: prefer low bits in boundary cases
676 * This function returns the OCR bit number according to the provided @vdd
677 * value. If conversion is not possible a negative errno value returned.
679 * Depending on the @low_bits flag the function prefers low or high OCR bits
680 * on boundary voltages. For example,
681 * with @low_bits = true, 3300 mV translates to ilog2(MMC_VDD_32_33);
682 * with @low_bits = false, 3300 mV translates to ilog2(MMC_VDD_33_34);
684 * Any value in the [1951:1999] range translates to the ilog2(MMC_VDD_20_21).
686 static int mmc_vdd_to_ocrbitnum(int vdd, bool low_bits)
688 const int max_bit = ilog2(MMC_VDD_35_36);
691 if (vdd < 1650 || vdd > 3600)
694 if (vdd >= 1650 && vdd <= 1950)
695 return ilog2(MMC_VDD_165_195);
700 /* Base 2000 mV, step 100 mV, bit's base 8. */
701 bit = (vdd - 2000) / 100 + 8;
708 * mmc_vddrange_to_ocrmask - Convert a voltage range to the OCR mask
709 * @vdd_min: minimum voltage value (mV)
710 * @vdd_max: maximum voltage value (mV)
712 * This function returns the OCR mask bits according to the provided @vdd_min
713 * and @vdd_max values. If conversion is not possible the function returns 0.
715 * Notes wrt boundary cases:
716 * This function sets the OCR bits for all boundary voltages, for example
717 * [3300:3400] range is translated to MMC_VDD_32_33 | MMC_VDD_33_34 |
718 * MMC_VDD_34_35 mask.
720 u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max)
724 if (vdd_max < vdd_min)
727 /* Prefer high bits for the boundary vdd_max values. */
728 vdd_max = mmc_vdd_to_ocrbitnum(vdd_max, false);
732 /* Prefer low bits for the boundary vdd_min values. */
733 vdd_min = mmc_vdd_to_ocrbitnum(vdd_min, true);
737 /* Fill the mask, from max bit to min bit. */
738 while (vdd_max >= vdd_min)
739 mask |= 1 << vdd_max--;
743 EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
745 #ifdef CONFIG_REGULATOR
748 * mmc_regulator_get_ocrmask - return mask of supported voltages
749 * @supply: regulator to use
751 * This returns either a negative errno, or a mask of voltages that
752 * can be provided to MMC/SD/SDIO devices using the specified voltage
753 * regulator. This would normally be called before registering the
756 int mmc_regulator_get_ocrmask(struct regulator *supply)
762 count = regulator_count_voltages(supply);
766 for (i = 0; i < count; i++) {
770 vdd_uV = regulator_list_voltage(supply, i);
774 vdd_mV = vdd_uV / 1000;
775 result |= mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV);
780 EXPORT_SYMBOL(mmc_regulator_get_ocrmask);
783 * mmc_regulator_set_ocr - set regulator to match host->ios voltage
784 * @vdd_bit: zero for power off, else a bit number (host->ios.vdd)
785 * @supply: regulator to use
787 * Returns zero on success, else negative errno.
789 * MMC host drivers may use this to enable or disable a regulator using
790 * a particular supply voltage. This would normally be called from the
793 int mmc_regulator_set_ocr(struct regulator *supply, unsigned short vdd_bit)
799 enabled = regulator_is_enabled(supply);
807 /* REVISIT mmc_vddrange_to_ocrmask() may have set some
808 * bits this regulator doesn't quite support ... don't
809 * be too picky, most cards and regulators are OK with
810 * a 0.1V range goof (it's a small error percentage).
812 tmp = vdd_bit - ilog2(MMC_VDD_165_195);
814 min_uV = 1650 * 1000;
815 max_uV = 1950 * 1000;
817 min_uV = 1900 * 1000 + tmp * 100 * 1000;
818 max_uV = min_uV + 100 * 1000;
821 /* avoid needless changes to this voltage; the regulator
822 * might not allow this operation
824 voltage = regulator_get_voltage(supply);
827 else if (voltage < min_uV || voltage > max_uV)
828 result = regulator_set_voltage(supply, min_uV, max_uV);
832 if (result == 0 && !enabled)
833 result = regulator_enable(supply);
834 } else if (enabled) {
835 result = regulator_disable(supply);
840 EXPORT_SYMBOL(mmc_regulator_set_ocr);
845 * Mask off any voltages we don't support and select
848 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
852 ocr &= host->ocr_avail;
863 pr_warning("%s: host doesn't support card's voltages\n",
872 * Select timing parameters for host.
874 void mmc_set_timing(struct mmc_host *host, unsigned int timing)
876 host->ios.timing = timing;
881 * Apply power to the MMC stack. This is a two-stage process.
882 * First, we enable power to the card without the clock running.
883 * We then wait a bit for the power to stabilise. Finally,
884 * enable the bus drivers and clock to the card.
886 * We must _NOT_ enable the clock prior to power stablising.
888 * If a host does all the power sequencing itself, ignore the
889 * initial MMC_POWER_UP stage.
891 static void mmc_power_up(struct mmc_host *host)
895 /* If ocr is set, we use it */
897 bit = ffs(host->ocr) - 1;
899 bit = fls(host->ocr_avail) - 1;
902 if (mmc_host_is_spi(host)) {
903 host->ios.chip_select = MMC_CS_HIGH;
904 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
906 host->ios.chip_select = MMC_CS_DONTCARE;
907 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
909 host->ios.power_mode = MMC_POWER_UP;
910 host->ios.bus_width = MMC_BUS_WIDTH_1;
911 host->ios.timing = MMC_TIMING_LEGACY;
915 * This delay should be sufficient to allow the power supply
916 * to reach the minimum voltage.
920 host->ios.clock = host->f_min;
922 host->ios.power_mode = MMC_POWER_ON;
926 * This delay must be at least 74 clock sizes, or 1 ms, or the
927 * time required to reach a stable voltage.
932 static void mmc_power_off(struct mmc_host *host)
936 if (!mmc_host_is_spi(host)) {
937 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
938 host->ios.chip_select = MMC_CS_DONTCARE;
940 host->ios.power_mode = MMC_POWER_OFF;
941 host->ios.bus_width = MMC_BUS_WIDTH_1;
942 host->ios.timing = MMC_TIMING_LEGACY;
947 * Cleanup when the last reference to the bus operator is dropped.
949 static void __mmc_release_bus(struct mmc_host *host)
952 BUG_ON(host->bus_refs);
953 BUG_ON(!host->bus_dead);
955 host->bus_ops = NULL;
959 * Increase reference count of bus operator
961 static inline void mmc_bus_get(struct mmc_host *host)
965 spin_lock_irqsave(&host->lock, flags);
967 spin_unlock_irqrestore(&host->lock, flags);
971 * Decrease reference count of bus operator and free it if
972 * it is the last reference.
974 static inline void mmc_bus_put(struct mmc_host *host)
978 spin_lock_irqsave(&host->lock, flags);
980 if ((host->bus_refs == 0) && host->bus_ops)
981 __mmc_release_bus(host);
982 spin_unlock_irqrestore(&host->lock, flags);
985 int mmc_resume_bus(struct mmc_host *host)
989 if (!mmc_bus_needs_resume(host))
992 printk("%s: Starting deferred resume\n", mmc_hostname(host));
993 spin_lock_irqsave(&host->lock, flags);
994 host->bus_resume_flags &= ~MMC_BUSRESUME_NEEDS_RESUME;
995 host->rescan_disable = 0;
996 spin_unlock_irqrestore(&host->lock, flags);
999 if (host->bus_ops && !host->bus_dead) {
1001 BUG_ON(!host->bus_ops->resume);
1002 host->bus_ops->resume(host);
1005 if (host->bus_ops->detect && !host->bus_dead)
1006 host->bus_ops->detect(host);
1009 printk("%s: Deferred resume completed\n", mmc_hostname(host));
1013 EXPORT_SYMBOL(mmc_resume_bus);
1016 * Assign a mmc bus handler to a host. Only one bus handler may control a
1017 * host at any given time.
1019 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
1021 unsigned long flags;
1026 WARN_ON(!host->claimed);
1028 spin_lock_irqsave(&host->lock, flags);
1030 BUG_ON(host->bus_ops);
1031 BUG_ON(host->bus_refs);
1033 host->bus_ops = ops;
1037 spin_unlock_irqrestore(&host->lock, flags);
1041 * Remove the current bus handler from a host. Assumes that there are
1042 * no interesting cards left, so the bus is powered down.
1044 void mmc_detach_bus(struct mmc_host *host)
1046 unsigned long flags;
1050 WARN_ON(!host->claimed);
1051 WARN_ON(!host->bus_ops);
1053 spin_lock_irqsave(&host->lock, flags);
1057 spin_unlock_irqrestore(&host->lock, flags);
1059 mmc_power_off(host);
1065 * mmc_detect_change - process change of state on a MMC socket
1066 * @host: host which changed state.
1067 * @delay: optional delay to wait before detection (jiffies)
1069 * MMC drivers should call this when they detect a card has been
1070 * inserted or removed. The MMC layer will confirm that any
1071 * present card is still functional, and initialize any newly
1074 void mmc_detect_change(struct mmc_host *host, unsigned long delay)
1076 #ifdef CONFIG_MMC_DEBUG
1077 unsigned long flags;
1078 spin_lock_irqsave(&host->lock, flags);
1079 WARN_ON(host->removed);
1080 spin_unlock_irqrestore(&host->lock, flags);
1083 mmc_schedule_delayed_work(&host->detect, delay);
1086 EXPORT_SYMBOL(mmc_detect_change);
1088 void mmc_init_erase(struct mmc_card *card)
1092 if (is_power_of_2(card->erase_size))
1093 card->erase_shift = ffs(card->erase_size) - 1;
1095 card->erase_shift = 0;
1098 * It is possible to erase an arbitrarily large area of an SD or MMC
1099 * card. That is not desirable because it can take a long time
1100 * (minutes) potentially delaying more important I/O, and also the
1101 * timeout calculations become increasingly hugely over-estimated.
1102 * Consequently, 'pref_erase' is defined as a guide to limit erases
1103 * to that size and alignment.
1105 * For SD cards that define Allocation Unit size, limit erases to one
1106 * Allocation Unit at a time. For MMC cards that define High Capacity
1107 * Erase Size, whether it is switched on or not, limit to that size.
1108 * Otherwise just have a stab at a good value. For modern cards it
1109 * will end up being 4MiB. Note that if the value is too small, it
1110 * can end up taking longer to erase.
1112 if (mmc_card_sd(card) && card->ssr.au) {
1113 card->pref_erase = card->ssr.au;
1114 card->erase_shift = ffs(card->ssr.au) - 1;
1115 } else if (card->ext_csd.hc_erase_size) {
1116 card->pref_erase = card->ext_csd.hc_erase_size;
1118 sz = (card->csd.capacity << (card->csd.read_blkbits - 9)) >> 11;
1120 card->pref_erase = 512 * 1024 / 512;
1122 card->pref_erase = 1024 * 1024 / 512;
1124 card->pref_erase = 2 * 1024 * 1024 / 512;
1126 card->pref_erase = 4 * 1024 * 1024 / 512;
1127 if (card->pref_erase < card->erase_size)
1128 card->pref_erase = card->erase_size;
1130 sz = card->pref_erase % card->erase_size;
1132 card->pref_erase += card->erase_size - sz;
1137 static void mmc_set_mmc_erase_timeout(struct mmc_card *card,
1138 struct mmc_command *cmd,
1139 unsigned int arg, unsigned int qty)
1141 unsigned int erase_timeout;
1143 if (card->ext_csd.erase_group_def & 1) {
1144 /* High Capacity Erase Group Size uses HC timeouts */
1145 if (arg == MMC_TRIM_ARG)
1146 erase_timeout = card->ext_csd.trim_timeout;
1148 erase_timeout = card->ext_csd.hc_erase_timeout;
1150 /* CSD Erase Group Size uses write timeout */
1151 unsigned int mult = (10 << card->csd.r2w_factor);
1152 unsigned int timeout_clks = card->csd.tacc_clks * mult;
1153 unsigned int timeout_us;
1155 /* Avoid overflow: e.g. tacc_ns=80000000 mult=1280 */
1156 if (card->csd.tacc_ns < 1000000)
1157 timeout_us = (card->csd.tacc_ns * mult) / 1000;
1159 timeout_us = (card->csd.tacc_ns / 1000) * mult;
1162 * ios.clock is only a target. The real clock rate might be
1163 * less but not that much less, so fudge it by multiplying by 2.
1166 timeout_us += (timeout_clks * 1000) /
1167 (card->host->ios.clock / 1000);
1169 erase_timeout = timeout_us / 1000;
1172 * Theoretically, the calculation could underflow so round up
1173 * to 1ms in that case.
1179 /* Multiplier for secure operations */
1180 if (arg & MMC_SECURE_ARGS) {
1181 if (arg == MMC_SECURE_ERASE_ARG)
1182 erase_timeout *= card->ext_csd.sec_erase_mult;
1184 erase_timeout *= card->ext_csd.sec_trim_mult;
1187 erase_timeout *= qty;
1190 * Ensure at least a 1 second timeout for SPI as per
1191 * 'mmc_set_data_timeout()'
1193 if (mmc_host_is_spi(card->host) && erase_timeout < 1000)
1194 erase_timeout = 1000;
1196 cmd->erase_timeout = erase_timeout;
1199 static void mmc_set_sd_erase_timeout(struct mmc_card *card,
1200 struct mmc_command *cmd, unsigned int arg,
1203 if (card->ssr.erase_timeout) {
1204 /* Erase timeout specified in SD Status Register (SSR) */
1205 cmd->erase_timeout = card->ssr.erase_timeout * qty +
1206 card->ssr.erase_offset;
1209 * Erase timeout not specified in SD Status Register (SSR) so
1210 * use 250ms per write block.
1212 cmd->erase_timeout = 250 * qty;
1215 /* Must not be less than 1 second */
1216 if (cmd->erase_timeout < 1000)
1217 cmd->erase_timeout = 1000;
1220 static void mmc_set_erase_timeout(struct mmc_card *card,
1221 struct mmc_command *cmd, unsigned int arg,
1224 if (mmc_card_sd(card))
1225 mmc_set_sd_erase_timeout(card, cmd, arg, qty);
1227 mmc_set_mmc_erase_timeout(card, cmd, arg, qty);
1230 static int mmc_do_erase(struct mmc_card *card, unsigned int from,
1231 unsigned int to, unsigned int arg)
1233 struct mmc_command cmd;
1234 unsigned int qty = 0;
1238 * qty is used to calculate the erase timeout which depends on how many
1239 * erase groups (or allocation units in SD terminology) are affected.
1240 * We count erasing part of an erase group as one erase group.
1241 * For SD, the allocation units are always a power of 2. For MMC, the
1242 * erase group size is almost certainly also power of 2, but it does not
1243 * seem to insist on that in the JEDEC standard, so we fall back to
1244 * division in that case. SD may not specify an allocation unit size,
1245 * in which case the timeout is based on the number of write blocks.
1247 * Note that the timeout for secure trim 2 will only be correct if the
1248 * number of erase groups specified is the same as the total of all
1249 * preceding secure trim 1 commands. Since the power may have been
1250 * lost since the secure trim 1 commands occurred, it is generally
1251 * impossible to calculate the secure trim 2 timeout correctly.
1253 if (card->erase_shift)
1254 qty += ((to >> card->erase_shift) -
1255 (from >> card->erase_shift)) + 1;
1256 else if (mmc_card_sd(card))
1257 qty += to - from + 1;
1259 qty += ((to / card->erase_size) -
1260 (from / card->erase_size)) + 1;
1262 if (!mmc_card_blockaddr(card)) {
1267 memset(&cmd, 0, sizeof(struct mmc_command));
1268 if (mmc_card_sd(card))
1269 cmd.opcode = SD_ERASE_WR_BLK_START;
1271 cmd.opcode = MMC_ERASE_GROUP_START;
1273 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1274 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1276 printk(KERN_ERR "mmc_erase: group start error %d, "
1277 "status %#x\n", err, cmd.resp[0]);
1282 memset(&cmd, 0, sizeof(struct mmc_command));
1283 if (mmc_card_sd(card))
1284 cmd.opcode = SD_ERASE_WR_BLK_END;
1286 cmd.opcode = MMC_ERASE_GROUP_END;
1288 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1289 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1291 printk(KERN_ERR "mmc_erase: group end error %d, status %#x\n",
1297 memset(&cmd, 0, sizeof(struct mmc_command));
1298 cmd.opcode = MMC_ERASE;
1300 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1301 mmc_set_erase_timeout(card, &cmd, arg, qty);
1302 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1304 printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
1310 if (mmc_host_is_spi(card->host))
1314 memset(&cmd, 0, sizeof(struct mmc_command));
1315 cmd.opcode = MMC_SEND_STATUS;
1316 cmd.arg = card->rca << 16;
1317 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
1318 /* Do not retry else we can't see errors */
1319 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1320 if (err || (cmd.resp[0] & 0xFDF92000)) {
1321 printk(KERN_ERR "error %d requesting status %#x\n",
1326 } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
1327 R1_CURRENT_STATE(cmd.resp[0]) == 7);
1333 * mmc_erase - erase sectors.
1334 * @card: card to erase
1335 * @from: first sector to erase
1336 * @nr: number of sectors to erase
1337 * @arg: erase command argument (SD supports only %MMC_ERASE_ARG)
1339 * Caller must claim host before calling this function.
1341 int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
1344 unsigned int rem, to = from + nr;
1346 if (!(card->host->caps & MMC_CAP_ERASE) ||
1347 !(card->csd.cmdclass & CCC_ERASE))
1350 if (!card->erase_size)
1353 if (mmc_card_sd(card) && arg != MMC_ERASE_ARG)
1356 if ((arg & MMC_SECURE_ARGS) &&
1357 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
1360 if ((arg & MMC_TRIM_ARGS) &&
1361 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
1364 if (arg == MMC_SECURE_ERASE_ARG) {
1365 if (from % card->erase_size || nr % card->erase_size)
1369 if (arg == MMC_ERASE_ARG) {
1370 rem = from % card->erase_size;
1372 rem = card->erase_size - rem;
1379 rem = nr % card->erase_size;
1392 /* 'from' and 'to' are inclusive */
1395 return mmc_do_erase(card, from, to, arg);
1397 EXPORT_SYMBOL(mmc_erase);
1399 int mmc_can_erase(struct mmc_card *card)
1401 if ((card->host->caps & MMC_CAP_ERASE) &&
1402 (card->csd.cmdclass & CCC_ERASE) && card->erase_size)
1406 EXPORT_SYMBOL(mmc_can_erase);
1408 int mmc_can_trim(struct mmc_card *card)
1410 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
1414 EXPORT_SYMBOL(mmc_can_trim);
1416 int mmc_can_secure_erase_trim(struct mmc_card *card)
1418 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)
1422 EXPORT_SYMBOL(mmc_can_secure_erase_trim);
1424 int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
1427 if (!card->erase_size)
1429 if (from % card->erase_size || nr % card->erase_size)
1433 EXPORT_SYMBOL(mmc_erase_group_aligned);
1435 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1436 void mmc_rescan(struct work_struct *work)
1438 struct mmc_host *host =
1439 container_of(work, struct mmc_host, detect.work);
1442 int extend_wakelock = 0;
1447 /* if there is a card registered, check whether it is still present */
1448 if ((host->bus_ops != NULL) && host->bus_ops->detect && !host->bus_dead)
1449 host->bus_ops->detect(host);
1451 /* If the card was removed the bus will be marked
1452 * as dead - extend the wakelock so userspace
1455 extend_wakelock = 1;
1462 /* if there still is a card present, stop here */
1463 if (host->bus_ops != NULL) {
1468 /* detect a newly inserted card */
1471 * Only we can add a new handler, so it's safe to
1472 * release the lock here.
1475 printk("\n%s...%d.. ===== mmc_rescan Begin....======xbw[%s]=====\n",__FILE__, __LINE__, mmc_hostname(host));
1477 if (host->ops->get_cd && host->ops->get_cd(host) == 0)
1479 printk("\n=================\n%s..%d.. ====find no SDMMC host.====xbw[%s]=====\n", \
1480 __FUNCTION__, __LINE__, mmc_hostname(host));
1485 mmc_claim_host(host);
1492 In oder to improve the initialization process in rockchip IC, I modify the following code about the the initialization process of SDIO-SD-MMC.
1493 So I deleted the CMD8 and add a conditional to distinguish between the two card type,i.e.SDMMC process and SDIO process.
1494 For detail,please refer to "RK29XX Technical Reference Manual" and "SD-MMC-SDIO Specifications".
1495 Noted by xbw@2011-04-09
1498 //mmc_send_if_cond(host, host->ocr_avail); //deleted by xbw@2011-04-09
1500 if( strncmp( mmc_hostname(host) ,"mmc0" , strlen("mmc0")) ){
1502 * First we search for SDIO...
1504 err = mmc_send_io_op_cond(host, 0, &ocr);
1506 printk("\n%s..%d.. ===== Begin to identify card as SDIO-card===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
1508 if (mmc_attach_sdio(host, ocr))
1510 printk("\n=====\n %s..%d.. ===== Initialize SDIO-card unsuccessfully!!! ===xbw[%s]===\n=====\n",\
1511 __FUNCTION__, __LINE__, mmc_hostname(host));
1513 mmc_power_off(host);
1517 printk("%s..%d.. ===== Initialize SDIO successfully. ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
1519 extend_wakelock = 1;
1526 * ...then normal SD...
1528 err = mmc_send_app_op_cond(host, 0, &ocr);
1530 printk("\n%s..%d.. ===== Begin to identify card as SD-card ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
1532 if (mmc_attach_sd(host, ocr))
1534 printk("\n=====\n%s..%d.. ===== Initialize SD-card unsuccessfully!!! ===xbw[%s]===\n====\n",\
1535 __FUNCTION__, __LINE__, mmc_hostname(host));
1537 mmc_power_off(host);
1541 printk("%s..%d.. ===== Initialize SD-card successfully. ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
1543 extend_wakelock = 1;
1548 * ...and finally MMC.
1550 err = mmc_send_op_cond(host, 0, &ocr);
1552 printk("\n%s..%d.. ===== Begin to identify card as MMC-card ===xbw[%s]===\n", __FUNCTION__, __LINE__, mmc_hostname(host));
1554 if (mmc_attach_mmc(host, ocr))
1556 printk("\n =====\n%s..%d.. ===== Initialize MMC-card unsuccessfully!!! ===xbw[%s]===\n======\n",\
1557 __FUNCTION__, __LINE__, mmc_hostname(host));
1559 mmc_power_off(host);
1563 printk("%s...%d.. ===== Initialize MMC-card successfully. ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
1565 extend_wakelock = 1;
1569 mmc_release_host(host);
1570 mmc_power_off(host);
1574 if (extend_wakelock)
1575 wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);
1577 wake_unlock(&mmc_delayed_work_wake_lock);
1579 if (host->caps & MMC_CAP_NEEDS_POLL)
1580 mmc_schedule_delayed_work(&host->detect, HZ);
1584 void mmc_rescan(struct work_struct *work)
1586 struct mmc_host *host =
1587 container_of(work, struct mmc_host, detect.work);
1590 unsigned long flags;
1591 int extend_wakelock = 0;
1593 spin_lock_irqsave(&host->lock, flags);
1595 if (host->rescan_disable) {
1596 spin_unlock_irqrestore(&host->lock, flags);
1600 spin_unlock_irqrestore(&host->lock, flags);
1605 /* if there is a card registered, check whether it is still present */
1606 if ((host->bus_ops != NULL) && host->bus_ops->detect && !host->bus_dead)
1607 host->bus_ops->detect(host);
1609 /* If the card was removed the bus will be marked
1610 * as dead - extend the wakelock so userspace
1613 extend_wakelock = 1;
1620 /* if there still is a card present, stop here */
1621 if (host->bus_ops != NULL) {
1626 /* detect a newly inserted card */
1629 * Only we can add a new handler, so it's safe to
1630 * release the lock here.
1634 if (host->ops->get_cd && host->ops->get_cd(host) == 0)
1637 mmc_claim_host(host);
1643 mmc_send_if_cond(host, host->ocr_avail);
1646 * First we search for SDIO...
1648 err = mmc_send_io_op_cond(host, 0, &ocr);
1650 if (mmc_attach_sdio(host, ocr)) {
1651 mmc_claim_host(host);
1652 /* try SDMEM (but not MMC) even if SDIO is broken */
1653 if (mmc_send_app_op_cond(host, 0, &ocr))
1656 if (mmc_attach_sd(host, ocr))
1657 mmc_power_off(host);
1658 extend_wakelock = 1;
1664 * ...then normal SD...
1666 err = mmc_send_app_op_cond(host, 0, &ocr);
1668 if (mmc_attach_sd(host, ocr))
1669 mmc_power_off(host);
1670 extend_wakelock = 1;
1675 * ...and finally MMC.
1677 err = mmc_send_op_cond(host, 0, &ocr);
1679 if (mmc_attach_mmc(host, ocr))
1680 mmc_power_off(host);
1681 extend_wakelock = 1;
1686 mmc_release_host(host);
1687 mmc_power_off(host);
1690 if (extend_wakelock)
1691 wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);
1693 wake_unlock(&mmc_delayed_work_wake_lock);
1695 if (host->caps & MMC_CAP_NEEDS_POLL)
1696 mmc_schedule_delayed_work(&host->detect, HZ);
1700 void mmc_start_host(struct mmc_host *host)
1702 mmc_power_off(host);
1703 mmc_detect_change(host, 0);
1706 void mmc_stop_host(struct mmc_host *host)
1708 #ifdef CONFIG_MMC_DEBUG
1709 unsigned long flags;
1710 spin_lock_irqsave(&host->lock, flags);
1712 spin_unlock_irqrestore(&host->lock, flags);
1715 if (host->caps & MMC_CAP_DISABLE)
1716 cancel_delayed_work(&host->disable);
1717 cancel_delayed_work_sync(&host->detect);
1718 mmc_flush_scheduled_work();
1720 /* clear pm flags now and let card drivers set them as needed */
1724 if (host->bus_ops && !host->bus_dead) {
1725 if (host->bus_ops->remove)
1726 host->bus_ops->remove(host);
1728 mmc_claim_host(host);
1729 mmc_detach_bus(host);
1730 mmc_release_host(host);
1738 mmc_power_off(host);
1741 void mmc_power_save_host(struct mmc_host *host)
1745 if (!host->bus_ops || host->bus_dead || !host->bus_ops->power_restore) {
1750 if (host->bus_ops->power_save)
1751 host->bus_ops->power_save(host);
1755 mmc_power_off(host);
1757 EXPORT_SYMBOL(mmc_power_save_host);
1759 void mmc_power_restore_host(struct mmc_host *host)
1763 if (!host->bus_ops || host->bus_dead || !host->bus_ops->power_restore) {
1769 host->bus_ops->power_restore(host);
1773 EXPORT_SYMBOL(mmc_power_restore_host);
1775 int mmc_card_awake(struct mmc_host *host)
1781 if (host->bus_ops && !host->bus_dead && host->bus_ops->awake)
1782 err = host->bus_ops->awake(host);
1788 EXPORT_SYMBOL(mmc_card_awake);
1790 int mmc_card_sleep(struct mmc_host *host)
1796 if (host->bus_ops && !host->bus_dead && host->bus_ops->awake)
1797 err = host->bus_ops->sleep(host);
1803 EXPORT_SYMBOL(mmc_card_sleep);
1805 int mmc_card_can_sleep(struct mmc_host *host)
1807 struct mmc_card *card = host->card;
1809 if (card && mmc_card_mmc(card) && card->ext_csd.rev >= 3)
1813 EXPORT_SYMBOL(mmc_card_can_sleep);
1818 * mmc_suspend_host - suspend a host
1821 int mmc_suspend_host(struct mmc_host *host)
1825 if (mmc_bus_needs_resume(host))
1828 if (host->caps & MMC_CAP_DISABLE)
1829 cancel_delayed_work(&host->disable);
1830 cancel_delayed_work(&host->detect);
1831 mmc_flush_scheduled_work();
1834 if (host->bus_ops && !host->bus_dead) {
1835 if (host->bus_ops->suspend)
1836 err = host->bus_ops->suspend(host);
1837 if (err == -ENOSYS || !host->bus_ops->resume) {
1839 * We simply "remove" the card in this case.
1840 * It will be redetected on resume.
1842 if (host->bus_ops->remove)
1843 host->bus_ops->remove(host);
1844 mmc_claim_host(host);
1845 mmc_detach_bus(host);
1846 mmc_release_host(host);
1853 if (!err && !(host->pm_flags & MMC_PM_KEEP_POWER))
1854 mmc_power_off(host);
1859 EXPORT_SYMBOL(mmc_suspend_host);
1862 * mmc_resume_host - resume a previously suspended host
1865 int mmc_resume_host(struct mmc_host *host)
1870 if (mmc_bus_manual_resume(host)) {
1871 host->bus_resume_flags |= MMC_BUSRESUME_NEEDS_RESUME;
1876 if (host->bus_ops && !host->bus_dead) {
1877 if (!(host->pm_flags & MMC_PM_KEEP_POWER)) {
1879 mmc_select_voltage(host, host->ocr);
1881 BUG_ON(!host->bus_ops->resume);
1882 #if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1883 //panic if the card is being removed during the resume, deleted by xbw at 2011-06-20
1884 host->bus_ops->resume(host);
1887 err = host->bus_ops->resume(host);
1889 printk(KERN_WARNING "%s: error %d during resume "
1890 "(card was removed?)\n",
1891 mmc_hostname(host), err);
1900 EXPORT_SYMBOL(mmc_resume_host);
1902 /* Do the card removal on suspend if card is assumed removeable
1903 * Do that in pm notifier while userspace isn't yet frozen, so we will be able
1906 int mmc_pm_notify(struct notifier_block *notify_block,
1907 unsigned long mode, void *unused)
1909 struct mmc_host *host = container_of(
1910 notify_block, struct mmc_host, pm_notify);
1911 unsigned long flags;
1915 case PM_HIBERNATION_PREPARE:
1916 case PM_SUSPEND_PREPARE:
1918 spin_lock_irqsave(&host->lock, flags);
1919 if (mmc_bus_needs_resume(host)) {
1920 spin_unlock_irqrestore(&host->lock, flags);
1923 host->rescan_disable = 1;
1924 spin_unlock_irqrestore(&host->lock, flags);
1925 cancel_delayed_work_sync(&host->detect);
1927 if (!host->bus_ops || host->bus_ops->suspend)
1930 mmc_claim_host(host);
1932 if (host->bus_ops->remove)
1933 host->bus_ops->remove(host);
1935 mmc_detach_bus(host);
1936 mmc_release_host(host);
1940 case PM_POST_SUSPEND:
1941 case PM_POST_HIBERNATION:
1942 case PM_POST_RESTORE:
1944 spin_lock_irqsave(&host->lock, flags);
1945 if (mmc_bus_manual_resume(host)) {
1946 spin_unlock_irqrestore(&host->lock, flags);
1949 host->rescan_disable = 0;
1950 spin_unlock_irqrestore(&host->lock, flags);
1951 mmc_detect_change(host, 0);
1959 #ifdef CONFIG_MMC_EMBEDDED_SDIO
1960 void mmc_set_embedded_sdio_data(struct mmc_host *host,
1961 struct sdio_cis *cis,
1962 struct sdio_cccr *cccr,
1963 struct sdio_embedded_func *funcs,
1966 host->embedded_sdio_data.cis = cis;
1967 host->embedded_sdio_data.cccr = cccr;
1968 host->embedded_sdio_data.funcs = funcs;
1969 host->embedded_sdio_data.num_funcs = num_funcs;
1972 EXPORT_SYMBOL(mmc_set_embedded_sdio_data);
1975 static int __init mmc_init(void)
1979 wake_lock_init(&mmc_delayed_work_wake_lock, WAKE_LOCK_SUSPEND, "mmc_delayed_work");
1981 workqueue = create_singlethread_workqueue("kmmcd");
1985 ret = mmc_register_bus();
1987 goto destroy_workqueue;
1989 ret = mmc_register_host_class();
1991 goto unregister_bus;
1993 ret = sdio_register_bus();
1995 goto unregister_host_class;
1999 unregister_host_class:
2000 mmc_unregister_host_class();
2002 mmc_unregister_bus();
2004 destroy_workqueue(workqueue);
2009 static void __exit mmc_exit(void)
2011 sdio_unregister_bus();
2012 mmc_unregister_host_class();
2013 mmc_unregister_bus();
2014 destroy_workqueue(workqueue);
2015 wake_lock_destroy(&mmc_delayed_work_wake_lock);
2018 subsys_initcall(mmc_init);
2019 module_exit(mmc_exit);
2021 MODULE_LICENSE("GPL");