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>
26 #include <linux/mmc/card.h>
27 #include <linux/mmc/host.h>
28 #include <linux/mmc/mmc.h>
29 #include <linux/mmc/sd.h>
40 static struct workqueue_struct
*workqueue
;
43 * Enabling software CRCs on the data blocks can be a significant (30%)
44 * performance cost, and for other reasons may not always be desired.
45 * So we allow it it to be disabled.
48 module_param(use_spi_crc
, bool, 0);
51 * We normally treat cards as removed during suspend if they are not
52 * known to be on a non-removable bus, to avoid the risk of writing
53 * back data to a different card after resume. Allow this to be
54 * overridden if necessary.
56 #ifdef CONFIG_MMC_UNSAFE_RESUME
57 int mmc_assume_removable
;
59 int mmc_assume_removable
= 1;
61 EXPORT_SYMBOL(mmc_assume_removable
);
62 module_param_named(removable
, mmc_assume_removable
, bool, 0644);
65 "MMC/SD cards are removable and may be removed during suspend");
68 * Internal function. Schedule delayed work in the MMC work queue.
70 static int mmc_schedule_delayed_work(struct delayed_work
*work
,
73 return queue_delayed_work(workqueue
, work
, delay
);
77 * Internal function. Flush all scheduled work from the MMC work queue.
79 static void mmc_flush_scheduled_work(void)
81 flush_workqueue(workqueue
);
85 * mmc_request_done - finish processing an MMC request
86 * @host: MMC host which completed request
87 * @mrq: MMC request which request
89 * MMC drivers should call this function when they have completed
90 * their processing of a request.
92 void mmc_request_done(struct mmc_host
*host
, struct mmc_request
*mrq
)
94 struct mmc_command
*cmd
= mrq
->cmd
;
97 if (err
&& cmd
->retries
&& mmc_host_is_spi(host
)) {
98 if (cmd
->resp
[0] & R1_SPI_ILLEGAL_COMMAND
)
102 if (err
&& cmd
->retries
) {
103 pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
104 mmc_hostname(host
), cmd
->opcode
, err
);
108 host
->ops
->request(host
, mrq
);
110 led_trigger_event(host
->led
, LED_OFF
);
112 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
113 mmc_hostname(host
), cmd
->opcode
, err
,
114 cmd
->resp
[0], cmd
->resp
[1],
115 cmd
->resp
[2], cmd
->resp
[3]);
118 pr_debug("%s: %d bytes transferred: %d\n",
120 mrq
->data
->bytes_xfered
, mrq
->data
->error
);
124 pr_debug("%s: (CMD%u): %d: %08x %08x %08x %08x\n",
125 mmc_hostname(host
), mrq
->stop
->opcode
,
127 mrq
->stop
->resp
[0], mrq
->stop
->resp
[1],
128 mrq
->stop
->resp
[2], mrq
->stop
->resp
[3]);
136 EXPORT_SYMBOL(mmc_request_done
);
139 mmc_start_request(struct mmc_host
*host
, struct mmc_request
*mrq
)
141 #ifdef CONFIG_MMC_DEBUG
143 struct scatterlist
*sg
;
146 pr_debug("%s: starting CMD%u arg %08x flags %08x\n",
147 mmc_hostname(host
), mrq
->cmd
->opcode
,
148 mrq
->cmd
->arg
, mrq
->cmd
->flags
);
151 pr_debug("%s: blksz %d blocks %d flags %08x "
152 "tsac %d ms nsac %d\n",
153 mmc_hostname(host
), mrq
->data
->blksz
,
154 mrq
->data
->blocks
, mrq
->data
->flags
,
155 mrq
->data
->timeout_ns
/ 1000000,
156 mrq
->data
->timeout_clks
);
160 pr_debug("%s: CMD%u arg %08x flags %08x\n",
161 mmc_hostname(host
), mrq
->stop
->opcode
,
162 mrq
->stop
->arg
, mrq
->stop
->flags
);
165 WARN_ON(!host
->claimed
);
167 led_trigger_event(host
->led
, LED_FULL
);
172 BUG_ON(mrq
->data
->blksz
> host
->max_blk_size
);
173 BUG_ON(mrq
->data
->blocks
> host
->max_blk_count
);
174 BUG_ON(mrq
->data
->blocks
* mrq
->data
->blksz
>
177 #ifdef CONFIG_MMC_DEBUG
179 for_each_sg(mrq
->data
->sg
, sg
, mrq
->data
->sg_len
, i
)
181 BUG_ON(sz
!= mrq
->data
->blocks
* mrq
->data
->blksz
);
184 mrq
->cmd
->data
= mrq
->data
;
185 mrq
->data
->error
= 0;
186 mrq
->data
->mrq
= mrq
;
188 mrq
->data
->stop
= mrq
->stop
;
189 mrq
->stop
->error
= 0;
190 mrq
->stop
->mrq
= mrq
;
193 host
->ops
->request(host
, mrq
);
196 static void mmc_wait_done(struct mmc_request
*mrq
)
198 complete(mrq
->done_data
);
202 * mmc_wait_for_req - start a request and wait for completion
203 * @host: MMC host to start command
204 * @mrq: MMC request to start
206 * Start a new MMC custom command request for a host, and wait
207 * for the command to complete. Does not attempt to parse the
210 void mmc_wait_for_req(struct mmc_host
*host
, struct mmc_request
*mrq
)
212 DECLARE_COMPLETION_ONSTACK(complete
);
214 mrq
->done_data
= &complete
;
215 mrq
->done
= mmc_wait_done
;
217 mmc_start_request(host
, mrq
);
219 wait_for_completion(&complete
);
222 EXPORT_SYMBOL(mmc_wait_for_req
);
225 * mmc_wait_for_cmd - start a command and wait for completion
226 * @host: MMC host to start command
227 * @cmd: MMC command to start
228 * @retries: maximum number of retries
230 * Start a new MMC command for a host, and wait for the command
231 * to complete. Return any error that occurred while the command
232 * was executing. Do not attempt to parse the response.
234 int mmc_wait_for_cmd(struct mmc_host
*host
, struct mmc_command
*cmd
, int retries
)
236 struct mmc_request mrq
;
238 WARN_ON(!host
->claimed
);
240 memset(&mrq
, 0, sizeof(struct mmc_request
));
242 memset(cmd
->resp
, 0, sizeof(cmd
->resp
));
243 cmd
->retries
= retries
;
248 mmc_wait_for_req(host
, &mrq
);
253 EXPORT_SYMBOL(mmc_wait_for_cmd
);
256 * mmc_set_data_timeout - set the timeout for a data command
257 * @data: data phase for command
258 * @card: the MMC card associated with the data transfer
260 * Computes the data timeout parameters according to the
261 * correct algorithm given the card type.
263 void mmc_set_data_timeout(struct mmc_data
*data
, const struct mmc_card
*card
)
268 * SDIO cards only define an upper 1 s limit on access.
270 if (mmc_card_sdio(card
)) {
271 data
->timeout_ns
= 1000000000;
272 data
->timeout_clks
= 0;
277 * SD cards use a 100 multiplier rather than 10
279 mult
= mmc_card_sd(card
) ? 100 : 10;
282 * Scale up the multiplier (and therefore the timeout) by
283 * the r2w factor for writes.
285 if (data
->flags
& MMC_DATA_WRITE
)
286 mult
<<= card
->csd
.r2w_factor
;
288 data
->timeout_ns
= card
->csd
.tacc_ns
* mult
;
289 data
->timeout_clks
= card
->csd
.tacc_clks
* mult
;
292 * SD cards also have an upper limit on the timeout.
294 if (mmc_card_sd(card
)) {
295 unsigned int timeout_us
, limit_us
;
297 timeout_us
= data
->timeout_ns
/ 1000;
298 timeout_us
+= data
->timeout_clks
* 1000 /
299 (card
->host
->ios
.clock
/ 1000);
301 if (data
->flags
& MMC_DATA_WRITE
)
303 * The limit is really 250 ms, but that is
304 * insufficient for some crappy cards.
311 * SDHC cards always use these fixed values.
313 if (timeout_us
> limit_us
|| mmc_card_blockaddr(card
)) {
314 data
->timeout_ns
= limit_us
* 1000;
315 data
->timeout_clks
= 0;
319 * Some cards need very high timeouts if driven in SPI mode.
320 * The worst observed timeout was 900ms after writing a
321 * continuous stream of data until the internal logic
324 if (mmc_host_is_spi(card
->host
)) {
325 if (data
->flags
& MMC_DATA_WRITE
) {
326 if (data
->timeout_ns
< 1000000000)
327 data
->timeout_ns
= 1000000000; /* 1s */
329 if (data
->timeout_ns
< 100000000)
330 data
->timeout_ns
= 100000000; /* 100ms */
334 EXPORT_SYMBOL(mmc_set_data_timeout
);
337 * mmc_align_data_size - pads a transfer size to a more optimal value
338 * @card: the MMC card associated with the data transfer
339 * @sz: original transfer size
341 * Pads the original data size with a number of extra bytes in
342 * order to avoid controller bugs and/or performance hits
343 * (e.g. some controllers revert to PIO for certain sizes).
345 * Returns the improved size, which might be unmodified.
347 * Note that this function is only relevant when issuing a
348 * single scatter gather entry.
350 unsigned int mmc_align_data_size(struct mmc_card
*card
, unsigned int sz
)
353 * FIXME: We don't have a system for the controller to tell
354 * the core about its problems yet, so for now we just 32-bit
357 sz
= ((sz
+ 3) / 4) * 4;
361 EXPORT_SYMBOL(mmc_align_data_size
);
364 * mmc_host_enable - enable a host.
365 * @host: mmc host to enable
367 * Hosts that support power saving can use the 'enable' and 'disable'
368 * methods to exit and enter power saving states. For more information
369 * see comments for struct mmc_host_ops.
371 int mmc_host_enable(struct mmc_host
*host
)
373 if (!(host
->caps
& MMC_CAP_DISABLE
))
376 if (host
->en_dis_recurs
)
379 if (host
->nesting_cnt
++)
382 cancel_delayed_work_sync(&host
->disable
);
387 if (host
->ops
->enable
) {
390 host
->en_dis_recurs
= 1;
391 err
= host
->ops
->enable(host
);
392 host
->en_dis_recurs
= 0;
395 pr_debug("%s: enable error %d\n",
396 mmc_hostname(host
), err
);
403 EXPORT_SYMBOL(mmc_host_enable
);
405 static int mmc_host_do_disable(struct mmc_host
*host
, int lazy
)
407 if (host
->ops
->disable
) {
410 host
->en_dis_recurs
= 1;
411 err
= host
->ops
->disable(host
, lazy
);
412 host
->en_dis_recurs
= 0;
415 pr_debug("%s: disable error %d\n",
416 mmc_hostname(host
), err
);
420 unsigned long delay
= msecs_to_jiffies(err
);
422 mmc_schedule_delayed_work(&host
->disable
, delay
);
430 * mmc_host_disable - disable a host.
431 * @host: mmc host to disable
433 * Hosts that support power saving can use the 'enable' and 'disable'
434 * methods to exit and enter power saving states. For more information
435 * see comments for struct mmc_host_ops.
437 int mmc_host_disable(struct mmc_host
*host
)
441 if (!(host
->caps
& MMC_CAP_DISABLE
))
444 if (host
->en_dis_recurs
)
447 if (--host
->nesting_cnt
)
453 err
= mmc_host_do_disable(host
, 0);
456 EXPORT_SYMBOL(mmc_host_disable
);
459 * __mmc_claim_host - exclusively claim a host
460 * @host: mmc host to claim
461 * @abort: whether or not the operation should be aborted
463 * Claim a host for a set of operations. If @abort is non null and
464 * dereference a non-zero value then this will return prematurely with
465 * that non-zero value without acquiring the lock. Returns zero
466 * with the lock held otherwise.
468 int __mmc_claim_host(struct mmc_host
*host
, atomic_t
*abort
)
470 DECLARE_WAITQUEUE(wait
, current
);
476 add_wait_queue(&host
->wq
, &wait
);
477 spin_lock_irqsave(&host
->lock
, flags
);
479 set_current_state(TASK_UNINTERRUPTIBLE
);
480 stop
= abort
? atomic_read(abort
) : 0;
481 if (stop
|| !host
->claimed
|| host
->claimer
== current
)
483 spin_unlock_irqrestore(&host
->lock
, flags
);
485 spin_lock_irqsave(&host
->lock
, flags
);
487 set_current_state(TASK_RUNNING
);
490 host
->claimer
= current
;
491 host
->claim_cnt
+= 1;
494 spin_unlock_irqrestore(&host
->lock
, flags
);
495 remove_wait_queue(&host
->wq
, &wait
);
497 mmc_host_enable(host
);
501 EXPORT_SYMBOL(__mmc_claim_host
);
504 * mmc_try_claim_host - try exclusively to claim a host
505 * @host: mmc host to claim
507 * Returns %1 if the host is claimed, %0 otherwise.
509 int mmc_try_claim_host(struct mmc_host
*host
)
511 int claimed_host
= 0;
514 spin_lock_irqsave(&host
->lock
, flags
);
515 if (!host
->claimed
|| host
->claimer
== current
) {
517 host
->claimer
= current
;
518 host
->claim_cnt
+= 1;
521 spin_unlock_irqrestore(&host
->lock
, flags
);
524 EXPORT_SYMBOL(mmc_try_claim_host
);
526 static void mmc_do_release_host(struct mmc_host
*host
)
530 spin_lock_irqsave(&host
->lock
, flags
);
531 if (--host
->claim_cnt
) {
532 /* Release for nested claim */
533 spin_unlock_irqrestore(&host
->lock
, flags
);
536 host
->claimer
= NULL
;
537 spin_unlock_irqrestore(&host
->lock
, flags
);
542 void mmc_host_deeper_disable(struct work_struct
*work
)
544 struct mmc_host
*host
=
545 container_of(work
, struct mmc_host
, disable
.work
);
547 /* If the host is claimed then we do not want to disable it anymore */
548 if (!mmc_try_claim_host(host
))
550 mmc_host_do_disable(host
, 1);
551 mmc_do_release_host(host
);
555 * mmc_host_lazy_disable - lazily disable a host.
556 * @host: mmc host to disable
558 * Hosts that support power saving can use the 'enable' and 'disable'
559 * methods to exit and enter power saving states. For more information
560 * see comments for struct mmc_host_ops.
562 int mmc_host_lazy_disable(struct mmc_host
*host
)
564 if (!(host
->caps
& MMC_CAP_DISABLE
))
567 if (host
->en_dis_recurs
)
570 if (--host
->nesting_cnt
)
576 if (host
->disable_delay
) {
577 mmc_schedule_delayed_work(&host
->disable
,
578 msecs_to_jiffies(host
->disable_delay
));
581 return mmc_host_do_disable(host
, 1);
583 EXPORT_SYMBOL(mmc_host_lazy_disable
);
586 * mmc_release_host - release a host
587 * @host: mmc host to release
589 * Release a MMC host, allowing others to claim the host
590 * for their operations.
592 void mmc_release_host(struct mmc_host
*host
)
594 WARN_ON(!host
->claimed
);
596 mmc_host_lazy_disable(host
);
598 mmc_do_release_host(host
);
601 EXPORT_SYMBOL(mmc_release_host
);
604 * Internal function that does the actual ios call to the host driver,
605 * optionally printing some debug output.
607 static inline void mmc_set_ios(struct mmc_host
*host
)
609 struct mmc_ios
*ios
= &host
->ios
;
611 pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
612 "width %u timing %u\n",
613 mmc_hostname(host
), ios
->clock
, ios
->bus_mode
,
614 ios
->power_mode
, ios
->chip_select
, ios
->vdd
,
615 ios
->bus_width
, ios
->timing
);
617 host
->ops
->set_ios(host
, ios
);
621 * Control chip select pin on a host.
623 void mmc_set_chip_select(struct mmc_host
*host
, int mode
)
625 host
->ios
.chip_select
= mode
;
630 * Sets the host clock to the highest possible frequency that
633 void mmc_set_clock(struct mmc_host
*host
, unsigned int hz
)
635 WARN_ON(hz
< host
->f_min
);
637 if (hz
> host
->f_max
)
640 host
->ios
.clock
= hz
;
645 * Change the bus mode (open drain/push-pull) of a host.
647 void mmc_set_bus_mode(struct mmc_host
*host
, unsigned int mode
)
649 host
->ios
.bus_mode
= mode
;
654 * Change data bus width and DDR mode of a host.
656 void mmc_set_bus_width_ddr(struct mmc_host
*host
, unsigned int width
,
659 host
->ios
.bus_width
= width
;
665 * Change data bus width of a host.
667 void mmc_set_bus_width(struct mmc_host
*host
, unsigned int width
)
669 mmc_set_bus_width_ddr(host
, width
, MMC_SDR_MODE
);
673 * mmc_vdd_to_ocrbitnum - Convert a voltage to the OCR bit number
675 * @low_bits: prefer low bits in boundary cases
677 * This function returns the OCR bit number according to the provided @vdd
678 * value. If conversion is not possible a negative errno value returned.
680 * Depending on the @low_bits flag the function prefers low or high OCR bits
681 * on boundary voltages. For example,
682 * with @low_bits = true, 3300 mV translates to ilog2(MMC_VDD_32_33);
683 * with @low_bits = false, 3300 mV translates to ilog2(MMC_VDD_33_34);
685 * Any value in the [1951:1999] range translates to the ilog2(MMC_VDD_20_21).
687 static int mmc_vdd_to_ocrbitnum(int vdd
, bool low_bits
)
689 const int max_bit
= ilog2(MMC_VDD_35_36
);
692 if (vdd
< 1650 || vdd
> 3600)
695 if (vdd
>= 1650 && vdd
<= 1950)
696 return ilog2(MMC_VDD_165_195
);
701 /* Base 2000 mV, step 100 mV, bit's base 8. */
702 bit
= (vdd
- 2000) / 100 + 8;
709 * mmc_vddrange_to_ocrmask - Convert a voltage range to the OCR mask
710 * @vdd_min: minimum voltage value (mV)
711 * @vdd_max: maximum voltage value (mV)
713 * This function returns the OCR mask bits according to the provided @vdd_min
714 * and @vdd_max values. If conversion is not possible the function returns 0.
716 * Notes wrt boundary cases:
717 * This function sets the OCR bits for all boundary voltages, for example
718 * [3300:3400] range is translated to MMC_VDD_32_33 | MMC_VDD_33_34 |
719 * MMC_VDD_34_35 mask.
721 u32
mmc_vddrange_to_ocrmask(int vdd_min
, int vdd_max
)
725 if (vdd_max
< vdd_min
)
728 /* Prefer high bits for the boundary vdd_max values. */
729 vdd_max
= mmc_vdd_to_ocrbitnum(vdd_max
, false);
733 /* Prefer low bits for the boundary vdd_min values. */
734 vdd_min
= mmc_vdd_to_ocrbitnum(vdd_min
, true);
738 /* Fill the mask, from max bit to min bit. */
739 while (vdd_max
>= vdd_min
)
740 mask
|= 1 << vdd_max
--;
744 EXPORT_SYMBOL(mmc_vddrange_to_ocrmask
);
746 #ifdef CONFIG_REGULATOR
749 * mmc_regulator_get_ocrmask - return mask of supported voltages
750 * @supply: regulator to use
752 * This returns either a negative errno, or a mask of voltages that
753 * can be provided to MMC/SD/SDIO devices using the specified voltage
754 * regulator. This would normally be called before registering the
757 int mmc_regulator_get_ocrmask(struct regulator
*supply
)
763 count
= regulator_count_voltages(supply
);
767 for (i
= 0; i
< count
; i
++) {
771 vdd_uV
= regulator_list_voltage(supply
, i
);
775 vdd_mV
= vdd_uV
/ 1000;
776 result
|= mmc_vddrange_to_ocrmask(vdd_mV
, vdd_mV
);
781 EXPORT_SYMBOL(mmc_regulator_get_ocrmask
);
784 * mmc_regulator_set_ocr - set regulator to match host->ios voltage
785 * @mmc: the host to regulate
786 * @supply: regulator to use
787 * @vdd_bit: zero for power off, else a bit number (host->ios.vdd)
789 * Returns zero on success, else negative errno.
791 * MMC host drivers may use this to enable or disable a regulator using
792 * a particular supply voltage. This would normally be called from the
795 int mmc_regulator_set_ocr(struct mmc_host
*mmc
,
796 struct regulator
*supply
,
797 unsigned short vdd_bit
)
806 /* REVISIT mmc_vddrange_to_ocrmask() may have set some
807 * bits this regulator doesn't quite support ... don't
808 * be too picky, most cards and regulators are OK with
809 * a 0.1V range goof (it's a small error percentage).
811 tmp
= vdd_bit
- ilog2(MMC_VDD_165_195
);
813 min_uV
= 1650 * 1000;
814 max_uV
= 1950 * 1000;
816 min_uV
= 1900 * 1000 + tmp
* 100 * 1000;
817 max_uV
= min_uV
+ 100 * 1000;
820 /* avoid needless changes to this voltage; the regulator
821 * might not allow this operation
823 voltage
= regulator_get_voltage(supply
);
826 else if (voltage
< min_uV
|| voltage
> max_uV
)
827 result
= regulator_set_voltage(supply
, min_uV
, max_uV
);
831 if (result
== 0 && !mmc
->regulator_enabled
) {
832 result
= regulator_enable(supply
);
834 mmc
->regulator_enabled
= true;
836 } else if (mmc
->regulator_enabled
) {
837 result
= regulator_disable(supply
);
839 mmc
->regulator_enabled
= false;
843 dev_err(mmc_dev(mmc
),
844 "could not set regulator OCR (%d)\n", result
);
847 EXPORT_SYMBOL(mmc_regulator_set_ocr
);
849 #endif /* CONFIG_REGULATOR */
852 * Mask off any voltages we don't support and select
855 u32
mmc_select_voltage(struct mmc_host
*host
, u32 ocr
)
859 ocr
&= host
->ocr_avail
;
870 pr_warning("%s: host doesn't support card's voltages\n",
879 * Select timing parameters for host.
881 void mmc_set_timing(struct mmc_host
*host
, unsigned int timing
)
883 host
->ios
.timing
= timing
;
888 * Apply power to the MMC stack. This is a two-stage process.
889 * First, we enable power to the card without the clock running.
890 * We then wait a bit for the power to stabilise. Finally,
891 * enable the bus drivers and clock to the card.
893 * We must _NOT_ enable the clock prior to power stablising.
895 * If a host does all the power sequencing itself, ignore the
896 * initial MMC_POWER_UP stage.
898 static void mmc_power_up(struct mmc_host
*host
)
902 /* If ocr is set, we use it */
904 bit
= ffs(host
->ocr
) - 1;
906 bit
= fls(host
->ocr_avail
) - 1;
909 if (mmc_host_is_spi(host
)) {
910 host
->ios
.chip_select
= MMC_CS_HIGH
;
911 host
->ios
.bus_mode
= MMC_BUSMODE_PUSHPULL
;
913 host
->ios
.chip_select
= MMC_CS_DONTCARE
;
914 host
->ios
.bus_mode
= MMC_BUSMODE_OPENDRAIN
;
916 host
->ios
.power_mode
= MMC_POWER_UP
;
917 host
->ios
.bus_width
= MMC_BUS_WIDTH_1
;
918 host
->ios
.timing
= MMC_TIMING_LEGACY
;
922 * This delay should be sufficient to allow the power supply
923 * to reach the minimum voltage.
927 host
->ios
.clock
= host
->f_init
;
929 host
->ios
.power_mode
= MMC_POWER_ON
;
933 * This delay must be at least 74 clock sizes, or 1 ms, or the
934 * time required to reach a stable voltage.
939 static void mmc_power_off(struct mmc_host
*host
)
943 if (!mmc_host_is_spi(host
)) {
944 host
->ios
.bus_mode
= MMC_BUSMODE_OPENDRAIN
;
945 host
->ios
.chip_select
= MMC_CS_DONTCARE
;
947 host
->ios
.power_mode
= MMC_POWER_OFF
;
948 host
->ios
.bus_width
= MMC_BUS_WIDTH_1
;
949 host
->ios
.timing
= MMC_TIMING_LEGACY
;
954 * Cleanup when the last reference to the bus operator is dropped.
956 static void __mmc_release_bus(struct mmc_host
*host
)
959 BUG_ON(host
->bus_refs
);
960 BUG_ON(!host
->bus_dead
);
962 host
->bus_ops
= NULL
;
966 * Increase reference count of bus operator
968 static inline void mmc_bus_get(struct mmc_host
*host
)
972 spin_lock_irqsave(&host
->lock
, flags
);
974 spin_unlock_irqrestore(&host
->lock
, flags
);
978 * Decrease reference count of bus operator and free it if
979 * it is the last reference.
981 static inline void mmc_bus_put(struct mmc_host
*host
)
985 spin_lock_irqsave(&host
->lock
, flags
);
987 if ((host
->bus_refs
== 0) && host
->bus_ops
)
988 __mmc_release_bus(host
);
989 spin_unlock_irqrestore(&host
->lock
, flags
);
993 * Assign a mmc bus handler to a host. Only one bus handler may control a
994 * host at any given time.
996 void mmc_attach_bus(struct mmc_host
*host
, const struct mmc_bus_ops
*ops
)
1003 WARN_ON(!host
->claimed
);
1005 spin_lock_irqsave(&host
->lock
, flags
);
1007 BUG_ON(host
->bus_ops
);
1008 BUG_ON(host
->bus_refs
);
1010 host
->bus_ops
= ops
;
1014 spin_unlock_irqrestore(&host
->lock
, flags
);
1018 * Remove the current bus handler from a host. Assumes that there are
1019 * no interesting cards left, so the bus is powered down.
1021 void mmc_detach_bus(struct mmc_host
*host
)
1023 unsigned long flags
;
1027 WARN_ON(!host
->claimed
);
1028 WARN_ON(!host
->bus_ops
);
1030 spin_lock_irqsave(&host
->lock
, flags
);
1034 spin_unlock_irqrestore(&host
->lock
, flags
);
1036 mmc_power_off(host
);
1042 * mmc_detect_change - process change of state on a MMC socket
1043 * @host: host which changed state.
1044 * @delay: optional delay to wait before detection (jiffies)
1046 * MMC drivers should call this when they detect a card has been
1047 * inserted or removed. The MMC layer will confirm that any
1048 * present card is still functional, and initialize any newly
1051 void mmc_detect_change(struct mmc_host
*host
, unsigned long delay
)
1053 #ifdef CONFIG_MMC_DEBUG
1054 unsigned long flags
;
1055 spin_lock_irqsave(&host
->lock
, flags
);
1056 WARN_ON(host
->removed
);
1057 spin_unlock_irqrestore(&host
->lock
, flags
);
1060 mmc_schedule_delayed_work(&host
->detect
, delay
);
1063 EXPORT_SYMBOL(mmc_detect_change
);
1065 void mmc_init_erase(struct mmc_card
*card
)
1069 if (is_power_of_2(card
->erase_size
))
1070 card
->erase_shift
= ffs(card
->erase_size
) - 1;
1072 card
->erase_shift
= 0;
1075 * It is possible to erase an arbitrarily large area of an SD or MMC
1076 * card. That is not desirable because it can take a long time
1077 * (minutes) potentially delaying more important I/O, and also the
1078 * timeout calculations become increasingly hugely over-estimated.
1079 * Consequently, 'pref_erase' is defined as a guide to limit erases
1080 * to that size and alignment.
1082 * For SD cards that define Allocation Unit size, limit erases to one
1083 * Allocation Unit at a time. For MMC cards that define High Capacity
1084 * Erase Size, whether it is switched on or not, limit to that size.
1085 * Otherwise just have a stab at a good value. For modern cards it
1086 * will end up being 4MiB. Note that if the value is too small, it
1087 * can end up taking longer to erase.
1089 if (mmc_card_sd(card
) && card
->ssr
.au
) {
1090 card
->pref_erase
= card
->ssr
.au
;
1091 card
->erase_shift
= ffs(card
->ssr
.au
) - 1;
1092 } else if (card
->ext_csd
.hc_erase_size
) {
1093 card
->pref_erase
= card
->ext_csd
.hc_erase_size
;
1095 sz
= (card
->csd
.capacity
<< (card
->csd
.read_blkbits
- 9)) >> 11;
1097 card
->pref_erase
= 512 * 1024 / 512;
1099 card
->pref_erase
= 1024 * 1024 / 512;
1101 card
->pref_erase
= 2 * 1024 * 1024 / 512;
1103 card
->pref_erase
= 4 * 1024 * 1024 / 512;
1104 if (card
->pref_erase
< card
->erase_size
)
1105 card
->pref_erase
= card
->erase_size
;
1107 sz
= card
->pref_erase
% card
->erase_size
;
1109 card
->pref_erase
+= card
->erase_size
- sz
;
1114 static void mmc_set_mmc_erase_timeout(struct mmc_card
*card
,
1115 struct mmc_command
*cmd
,
1116 unsigned int arg
, unsigned int qty
)
1118 unsigned int erase_timeout
;
1120 if (card
->ext_csd
.erase_group_def
& 1) {
1121 /* High Capacity Erase Group Size uses HC timeouts */
1122 if (arg
== MMC_TRIM_ARG
)
1123 erase_timeout
= card
->ext_csd
.trim_timeout
;
1125 erase_timeout
= card
->ext_csd
.hc_erase_timeout
;
1127 /* CSD Erase Group Size uses write timeout */
1128 unsigned int mult
= (10 << card
->csd
.r2w_factor
);
1129 unsigned int timeout_clks
= card
->csd
.tacc_clks
* mult
;
1130 unsigned int timeout_us
;
1132 /* Avoid overflow: e.g. tacc_ns=80000000 mult=1280 */
1133 if (card
->csd
.tacc_ns
< 1000000)
1134 timeout_us
= (card
->csd
.tacc_ns
* mult
) / 1000;
1136 timeout_us
= (card
->csd
.tacc_ns
/ 1000) * mult
;
1139 * ios.clock is only a target. The real clock rate might be
1140 * less but not that much less, so fudge it by multiplying by 2.
1143 timeout_us
+= (timeout_clks
* 1000) /
1144 (card
->host
->ios
.clock
/ 1000);
1146 erase_timeout
= timeout_us
/ 1000;
1149 * Theoretically, the calculation could underflow so round up
1150 * to 1ms in that case.
1156 /* Multiplier for secure operations */
1157 if (arg
& MMC_SECURE_ARGS
) {
1158 if (arg
== MMC_SECURE_ERASE_ARG
)
1159 erase_timeout
*= card
->ext_csd
.sec_erase_mult
;
1161 erase_timeout
*= card
->ext_csd
.sec_trim_mult
;
1164 erase_timeout
*= qty
;
1167 * Ensure at least a 1 second timeout for SPI as per
1168 * 'mmc_set_data_timeout()'
1170 if (mmc_host_is_spi(card
->host
) && erase_timeout
< 1000)
1171 erase_timeout
= 1000;
1173 cmd
->erase_timeout
= erase_timeout
;
1176 static void mmc_set_sd_erase_timeout(struct mmc_card
*card
,
1177 struct mmc_command
*cmd
, unsigned int arg
,
1180 if (card
->ssr
.erase_timeout
) {
1181 /* Erase timeout specified in SD Status Register (SSR) */
1182 cmd
->erase_timeout
= card
->ssr
.erase_timeout
* qty
+
1183 card
->ssr
.erase_offset
;
1186 * Erase timeout not specified in SD Status Register (SSR) so
1187 * use 250ms per write block.
1189 cmd
->erase_timeout
= 250 * qty
;
1192 /* Must not be less than 1 second */
1193 if (cmd
->erase_timeout
< 1000)
1194 cmd
->erase_timeout
= 1000;
1197 static void mmc_set_erase_timeout(struct mmc_card
*card
,
1198 struct mmc_command
*cmd
, unsigned int arg
,
1201 if (mmc_card_sd(card
))
1202 mmc_set_sd_erase_timeout(card
, cmd
, arg
, qty
);
1204 mmc_set_mmc_erase_timeout(card
, cmd
, arg
, qty
);
1207 static int mmc_do_erase(struct mmc_card
*card
, unsigned int from
,
1208 unsigned int to
, unsigned int arg
)
1210 struct mmc_command cmd
;
1211 unsigned int qty
= 0;
1215 * qty is used to calculate the erase timeout which depends on how many
1216 * erase groups (or allocation units in SD terminology) are affected.
1217 * We count erasing part of an erase group as one erase group.
1218 * For SD, the allocation units are always a power of 2. For MMC, the
1219 * erase group size is almost certainly also power of 2, but it does not
1220 * seem to insist on that in the JEDEC standard, so we fall back to
1221 * division in that case. SD may not specify an allocation unit size,
1222 * in which case the timeout is based on the number of write blocks.
1224 * Note that the timeout for secure trim 2 will only be correct if the
1225 * number of erase groups specified is the same as the total of all
1226 * preceding secure trim 1 commands. Since the power may have been
1227 * lost since the secure trim 1 commands occurred, it is generally
1228 * impossible to calculate the secure trim 2 timeout correctly.
1230 if (card
->erase_shift
)
1231 qty
+= ((to
>> card
->erase_shift
) -
1232 (from
>> card
->erase_shift
)) + 1;
1233 else if (mmc_card_sd(card
))
1234 qty
+= to
- from
+ 1;
1236 qty
+= ((to
/ card
->erase_size
) -
1237 (from
/ card
->erase_size
)) + 1;
1239 if (!mmc_card_blockaddr(card
)) {
1244 memset(&cmd
, 0, sizeof(struct mmc_command
));
1245 if (mmc_card_sd(card
))
1246 cmd
.opcode
= SD_ERASE_WR_BLK_START
;
1248 cmd
.opcode
= MMC_ERASE_GROUP_START
;
1250 cmd
.flags
= MMC_RSP_SPI_R1
| MMC_RSP_R1
| MMC_CMD_AC
;
1251 err
= mmc_wait_for_cmd(card
->host
, &cmd
, 0);
1253 printk(KERN_ERR
"mmc_erase: group start error %d, "
1254 "status %#x\n", err
, cmd
.resp
[0]);
1259 memset(&cmd
, 0, sizeof(struct mmc_command
));
1260 if (mmc_card_sd(card
))
1261 cmd
.opcode
= SD_ERASE_WR_BLK_END
;
1263 cmd
.opcode
= MMC_ERASE_GROUP_END
;
1265 cmd
.flags
= MMC_RSP_SPI_R1
| MMC_RSP_R1
| MMC_CMD_AC
;
1266 err
= mmc_wait_for_cmd(card
->host
, &cmd
, 0);
1268 printk(KERN_ERR
"mmc_erase: group end error %d, status %#x\n",
1274 memset(&cmd
, 0, sizeof(struct mmc_command
));
1275 cmd
.opcode
= MMC_ERASE
;
1277 cmd
.flags
= MMC_RSP_SPI_R1B
| MMC_RSP_R1B
| MMC_CMD_AC
;
1278 mmc_set_erase_timeout(card
, &cmd
, arg
, qty
);
1279 err
= mmc_wait_for_cmd(card
->host
, &cmd
, 0);
1281 printk(KERN_ERR
"mmc_erase: erase error %d, status %#x\n",
1287 if (mmc_host_is_spi(card
->host
))
1291 memset(&cmd
, 0, sizeof(struct mmc_command
));
1292 cmd
.opcode
= MMC_SEND_STATUS
;
1293 cmd
.arg
= card
->rca
<< 16;
1294 cmd
.flags
= MMC_RSP_R1
| MMC_CMD_AC
;
1295 /* Do not retry else we can't see errors */
1296 err
= mmc_wait_for_cmd(card
->host
, &cmd
, 0);
1297 if (err
|| (cmd
.resp
[0] & 0xFDF92000)) {
1298 printk(KERN_ERR
"error %d requesting status %#x\n",
1303 } while (!(cmd
.resp
[0] & R1_READY_FOR_DATA
) ||
1304 R1_CURRENT_STATE(cmd
.resp
[0]) == 7);
1310 * mmc_erase - erase sectors.
1311 * @card: card to erase
1312 * @from: first sector to erase
1313 * @nr: number of sectors to erase
1314 * @arg: erase command argument (SD supports only %MMC_ERASE_ARG)
1316 * Caller must claim host before calling this function.
1318 int mmc_erase(struct mmc_card
*card
, unsigned int from
, unsigned int nr
,
1321 unsigned int rem
, to
= from
+ nr
;
1323 if (!(card
->host
->caps
& MMC_CAP_ERASE
) ||
1324 !(card
->csd
.cmdclass
& CCC_ERASE
))
1327 if (!card
->erase_size
)
1330 if (mmc_card_sd(card
) && arg
!= MMC_ERASE_ARG
)
1333 if ((arg
& MMC_SECURE_ARGS
) &&
1334 !(card
->ext_csd
.sec_feature_support
& EXT_CSD_SEC_ER_EN
))
1337 if ((arg
& MMC_TRIM_ARGS
) &&
1338 !(card
->ext_csd
.sec_feature_support
& EXT_CSD_SEC_GB_CL_EN
))
1341 if (arg
== MMC_SECURE_ERASE_ARG
) {
1342 if (from
% card
->erase_size
|| nr
% card
->erase_size
)
1346 if (arg
== MMC_ERASE_ARG
) {
1347 rem
= from
% card
->erase_size
;
1349 rem
= card
->erase_size
- rem
;
1356 rem
= nr
% card
->erase_size
;
1369 /* 'from' and 'to' are inclusive */
1372 return mmc_do_erase(card
, from
, to
, arg
);
1374 EXPORT_SYMBOL(mmc_erase
);
1376 int mmc_can_erase(struct mmc_card
*card
)
1378 if ((card
->host
->caps
& MMC_CAP_ERASE
) &&
1379 (card
->csd
.cmdclass
& CCC_ERASE
) && card
->erase_size
)
1383 EXPORT_SYMBOL(mmc_can_erase
);
1385 int mmc_can_trim(struct mmc_card
*card
)
1387 if (card
->ext_csd
.sec_feature_support
& EXT_CSD_SEC_GB_CL_EN
)
1391 EXPORT_SYMBOL(mmc_can_trim
);
1393 int mmc_can_secure_erase_trim(struct mmc_card
*card
)
1395 if (card
->ext_csd
.sec_feature_support
& EXT_CSD_SEC_ER_EN
)
1399 EXPORT_SYMBOL(mmc_can_secure_erase_trim
);
1401 int mmc_erase_group_aligned(struct mmc_card
*card
, unsigned int from
,
1404 if (!card
->erase_size
)
1406 if (from
% card
->erase_size
|| nr
% card
->erase_size
)
1410 EXPORT_SYMBOL(mmc_erase_group_aligned
);
1412 int mmc_set_blocklen(struct mmc_card
*card
, unsigned int blocklen
)
1414 struct mmc_command cmd
;
1416 if (mmc_card_blockaddr(card
) || mmc_card_ddr_mode(card
))
1419 memset(&cmd
, 0, sizeof(struct mmc_command
));
1420 cmd
.opcode
= MMC_SET_BLOCKLEN
;
1422 cmd
.flags
= MMC_RSP_SPI_R1
| MMC_RSP_R1
| MMC_CMD_AC
;
1423 return mmc_wait_for_cmd(card
->host
, &cmd
, 5);
1425 EXPORT_SYMBOL(mmc_set_blocklen
);
1427 void mmc_rescan(struct work_struct
*work
)
1429 struct mmc_host
*host
=
1430 container_of(work
, struct mmc_host
, detect
.work
);
1433 unsigned long flags
;
1435 const unsigned freqs
[] = { 400000, 300000, 200000, 100000 };
1437 spin_lock_irqsave(&host
->lock
, flags
);
1439 if (host
->rescan_disable
) {
1440 spin_unlock_irqrestore(&host
->lock
, flags
);
1444 spin_unlock_irqrestore(&host
->lock
, flags
);
1449 /* if there is a card registered, check whether it is still present */
1450 if ((host
->bus_ops
!= NULL
) && host
->bus_ops
->detect
&& !host
->bus_dead
)
1451 host
->bus_ops
->detect(host
);
1458 /* if there still is a card present, stop here */
1459 if (host
->bus_ops
!= NULL
) {
1464 /* detect a newly inserted card */
1467 * Only we can add a new handler, so it's safe to
1468 * release the lock here.
1472 if (host
->ops
->get_cd
&& host
->ops
->get_cd(host
) == 0)
1475 for (i
= 0; i
< ARRAY_SIZE(freqs
); i
++) {
1476 mmc_claim_host(host
);
1478 if (freqs
[i
] >= host
->f_min
)
1479 host
->f_init
= freqs
[i
];
1480 else if (!i
|| freqs
[i
-1] > host
->f_min
)
1481 host
->f_init
= host
->f_min
;
1483 mmc_release_host(host
);
1486 #ifdef CONFIG_MMC_DEBUG
1487 pr_info("%s: %s: trying to init card at %u Hz\n",
1488 mmc_hostname(host
), __func__
, host
->f_init
);
1494 mmc_send_if_cond(host
, host
->ocr_avail
);
1497 * First we search for SDIO...
1499 err
= mmc_send_io_op_cond(host
, 0, &ocr
);
1501 if (mmc_attach_sdio(host
, ocr
)) {
1502 mmc_claim_host(host
);
1504 * Try SDMEM (but not MMC) even if SDIO
1507 if (mmc_send_app_op_cond(host
, 0, &ocr
))
1510 if (mmc_attach_sd(host
, ocr
))
1511 mmc_power_off(host
);
1517 * ...then normal SD...
1519 err
= mmc_send_app_op_cond(host
, 0, &ocr
);
1521 if (mmc_attach_sd(host
, ocr
))
1522 mmc_power_off(host
);
1527 * ...and finally MMC.
1529 err
= mmc_send_op_cond(host
, 0, &ocr
);
1531 if (mmc_attach_mmc(host
, ocr
))
1532 mmc_power_off(host
);
1537 mmc_release_host(host
);
1538 mmc_power_off(host
);
1541 if (host
->caps
& MMC_CAP_NEEDS_POLL
)
1542 mmc_schedule_delayed_work(&host
->detect
, HZ
);
1545 void mmc_start_host(struct mmc_host
*host
)
1547 mmc_power_off(host
);
1548 mmc_detect_change(host
, 0);
1551 void mmc_stop_host(struct mmc_host
*host
)
1553 #ifdef CONFIG_MMC_DEBUG
1554 unsigned long flags
;
1555 spin_lock_irqsave(&host
->lock
, flags
);
1557 spin_unlock_irqrestore(&host
->lock
, flags
);
1560 if (host
->caps
& MMC_CAP_DISABLE
)
1561 cancel_delayed_work(&host
->disable
);
1562 cancel_delayed_work_sync(&host
->detect
);
1563 mmc_flush_scheduled_work();
1565 /* clear pm flags now and let card drivers set them as needed */
1569 if (host
->bus_ops
&& !host
->bus_dead
) {
1570 if (host
->bus_ops
->remove
)
1571 host
->bus_ops
->remove(host
);
1573 mmc_claim_host(host
);
1574 mmc_detach_bus(host
);
1575 mmc_release_host(host
);
1583 mmc_power_off(host
);
1586 int mmc_power_save_host(struct mmc_host
*host
)
1592 if (!host
->bus_ops
|| host
->bus_dead
|| !host
->bus_ops
->power_restore
) {
1597 if (host
->bus_ops
->power_save
)
1598 ret
= host
->bus_ops
->power_save(host
);
1602 mmc_power_off(host
);
1606 EXPORT_SYMBOL(mmc_power_save_host
);
1608 int mmc_power_restore_host(struct mmc_host
*host
)
1614 if (!host
->bus_ops
|| host
->bus_dead
|| !host
->bus_ops
->power_restore
) {
1620 ret
= host
->bus_ops
->power_restore(host
);
1626 EXPORT_SYMBOL(mmc_power_restore_host
);
1628 int mmc_card_awake(struct mmc_host
*host
)
1634 if (host
->bus_ops
&& !host
->bus_dead
&& host
->bus_ops
->awake
)
1635 err
= host
->bus_ops
->awake(host
);
1641 EXPORT_SYMBOL(mmc_card_awake
);
1643 int mmc_card_sleep(struct mmc_host
*host
)
1649 if (host
->bus_ops
&& !host
->bus_dead
&& host
->bus_ops
->awake
)
1650 err
= host
->bus_ops
->sleep(host
);
1656 EXPORT_SYMBOL(mmc_card_sleep
);
1658 int mmc_card_can_sleep(struct mmc_host
*host
)
1660 struct mmc_card
*card
= host
->card
;
1662 if (card
&& mmc_card_mmc(card
) && card
->ext_csd
.rev
>= 3)
1666 EXPORT_SYMBOL(mmc_card_can_sleep
);
1671 * mmc_suspend_host - suspend a host
1674 int mmc_suspend_host(struct mmc_host
*host
)
1678 if (host
->caps
& MMC_CAP_DISABLE
)
1679 cancel_delayed_work(&host
->disable
);
1680 cancel_delayed_work(&host
->detect
);
1681 mmc_flush_scheduled_work();
1684 if (host
->bus_ops
&& !host
->bus_dead
) {
1685 if (host
->bus_ops
->suspend
)
1686 err
= host
->bus_ops
->suspend(host
);
1687 if (err
== -ENOSYS
|| !host
->bus_ops
->resume
) {
1689 * We simply "remove" the card in this case.
1690 * It will be redetected on resume.
1692 if (host
->bus_ops
->remove
)
1693 host
->bus_ops
->remove(host
);
1694 mmc_claim_host(host
);
1695 mmc_detach_bus(host
);
1696 mmc_release_host(host
);
1703 if (!err
&& !(host
->pm_flags
& MMC_PM_KEEP_POWER
))
1704 mmc_power_off(host
);
1709 EXPORT_SYMBOL(mmc_suspend_host
);
1712 * mmc_resume_host - resume a previously suspended host
1715 int mmc_resume_host(struct mmc_host
*host
)
1720 if (host
->bus_ops
&& !host
->bus_dead
) {
1721 if (!(host
->pm_flags
& MMC_PM_KEEP_POWER
)) {
1723 mmc_select_voltage(host
, host
->ocr
);
1725 BUG_ON(!host
->bus_ops
->resume
);
1726 err
= host
->bus_ops
->resume(host
);
1728 printk(KERN_WARNING
"%s: error %d during resume "
1729 "(card was removed?)\n",
1730 mmc_hostname(host
), err
);
1738 EXPORT_SYMBOL(mmc_resume_host
);
1740 /* Do the card removal on suspend if card is assumed removeable
1741 * Do that in pm notifier while userspace isn't yet frozen, so we will be able
1744 int mmc_pm_notify(struct notifier_block
*notify_block
,
1745 unsigned long mode
, void *unused
)
1747 struct mmc_host
*host
= container_of(
1748 notify_block
, struct mmc_host
, pm_notify
);
1749 unsigned long flags
;
1753 case PM_HIBERNATION_PREPARE
:
1754 case PM_SUSPEND_PREPARE
:
1756 spin_lock_irqsave(&host
->lock
, flags
);
1757 host
->rescan_disable
= 1;
1758 spin_unlock_irqrestore(&host
->lock
, flags
);
1759 cancel_delayed_work_sync(&host
->detect
);
1761 if (!host
->bus_ops
|| host
->bus_ops
->suspend
)
1764 mmc_claim_host(host
);
1766 if (host
->bus_ops
->remove
)
1767 host
->bus_ops
->remove(host
);
1769 mmc_detach_bus(host
);
1770 mmc_release_host(host
);
1774 case PM_POST_SUSPEND
:
1775 case PM_POST_HIBERNATION
:
1777 spin_lock_irqsave(&host
->lock
, flags
);
1778 host
->rescan_disable
= 0;
1779 spin_unlock_irqrestore(&host
->lock
, flags
);
1780 mmc_detect_change(host
, 0);
1788 static int __init
mmc_init(void)
1792 workqueue
= create_singlethread_workqueue("kmmcd");
1796 ret
= mmc_register_bus();
1798 goto destroy_workqueue
;
1800 ret
= mmc_register_host_class();
1802 goto unregister_bus
;
1804 ret
= sdio_register_bus();
1806 goto unregister_host_class
;
1810 unregister_host_class
:
1811 mmc_unregister_host_class();
1813 mmc_unregister_bus();
1815 destroy_workqueue(workqueue
);
1820 static void __exit
mmc_exit(void)
1822 sdio_unregister_bus();
1823 mmc_unregister_host_class();
1824 mmc_unregister_bus();
1825 destroy_workqueue(workqueue
);
1828 subsys_initcall(mmc_init
);
1829 module_exit(mmc_exit
);
1831 MODULE_LICENSE("GPL");