| Linux kernel & device driver programming |
| [ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] |
1 /* 1
2 * linux/drivers/mmc/core/core.c
3 *
4 * Copyright (C) 2003-2004 Russell King, All
5 * SD support Copyright (C) 2004 Ian Molton,
6 * Copyright (C) 2005-2008 Pierre Ossman, All
7 * MMCv4 support Copyright (C) 2006 Philip La
8 *
9 * This program is free software; you can redi
10 * it under the terms of the GNU General Publi
11 * published by the Free Software Foundation.
12 */
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/completion.h>
17 #include <linux/device.h>
18 #include <linux/delay.h>
19 #include <linux/pagemap.h>
20 #include <linux/err.h>
21 #include <linux/leds.h>
22 #include <linux/scatterlist.h>
23 #include <linux/log2.h>
24 #include <linux/regulator/consumer.h>
25
26 #include <linux/mmc/card.h>
27 #include <linux/mmc/host.h>
28 #include <linux/mmc/mmc.h>
29 #include <linux/mmc/sd.h>
30
31 #include "core.h"
32 #include "bus.h"
33 #include "host.h"
34 #include "sdio_bus.h"
35
36 #include "mmc_ops.h"
37 #include "sd_ops.h"
38 #include "sdio_ops.h"
39
40 static struct workqueue_struct *workqueue;
41
42 /*
43 * Enabling software CRCs on the data blocks c
44 * performance cost, and for other reasons may
45 * So we allow it it to be disabled.
46 */
47 int use_spi_crc = 1;
48 module_param(use_spi_crc, bool, 0);
49
50 /*
51 * Internal function. Schedule delayed work in
52 */
53 static int mmc_schedule_delayed_work(struct de
54 unsigned
55 {
56 return queue_delayed_work(workqueue, w
57 }
58
59 /*
60 * Internal function. Flush all scheduled work
61 */
62 static void mmc_flush_scheduled_work(void)
63 {
64 flush_workqueue(workqueue);
65 }
66
67 /**
68 * mmc_request_done - finish processing a
69 * @host: MMC host which completed reques
70 * @mrq: MMC request which request
71 *
72 * MMC drivers should call this function
73 * their processing of a request.
74 */
75 void mmc_request_done(struct mmc_host *host, s
76 {
77 struct mmc_command *cmd = mrq->cmd;
78 int err = cmd->error;
79
80 if (err && cmd->retries && mmc_host_is
81 if (cmd->resp[0] & R1_SPI_ILLE
82 cmd->retries = 0;
83 }
84
85 if (err && cmd->retries) {
86 pr_debug("%s: req failed (CMD%
87 mmc_hostname(host), cm
88
89 cmd->retries--;
90 cmd->error = 0;
91 host->ops->request(host, mrq);
92 } else {
93 led_trigger_event(host->led, L
94
95 pr_debug("%s: req done (CMD%u)
96 mmc_hostname(host), cm
97 cmd->resp[0], cmd->res
98 cmd->resp[2], cmd->res
99
100 if (mrq->data) {
101 pr_debug("%s: %d b
102 mmc_hostname(h
103 mrq->data->byt
104 }
105
106 if (mrq->stop) {
107 pr_debug("%s: (CMD
108 mmc_hostname(h
109 mrq->stop->err
110 mrq->stop->res
111 mrq->stop->res
112 }
113
114 if (mrq->done)
115 mrq->done(mrq);
116 }
117 }
118
119 EXPORT_SYMBOL(mmc_request_done);
120
121 static void
122 mmc_start_request(struct mmc_host *host, struc
123 {
124 #ifdef CONFIG_MMC_DEBUG
125 unsigned int i, sz;
126 struct scatterlist *sg;
127 #endif
128
129 pr_debug("%s: starting CMD%u arg %08x
130 mmc_hostname(host), mrq->cmd-
131 mrq->cmd->arg, mrq->cmd->flag
132
133 if (mrq->data) {
134 pr_debug("%s: blksz %d blo
135 "tsac %d ms nsac %d\n"
136 mmc_hostname(host), mr
137 mrq->data->blocks, mrq
138 mrq->data->timeout_ns
139 mrq->data->timeout_clk
140 }
141
142 if (mrq->stop) {
143 pr_debug("%s: CMD%u arg %0
144 mmc_hostname(host), m
145 mrq->stop->arg, mrq->
146 }
147
148 WARN_ON(!host->claimed);
149
150 led_trigger_event(host->led, LED_FULL)
151
152 mrq->cmd->error = 0;
153 mrq->cmd->mrq = mrq;
154 if (mrq->data) {
155 BUG_ON(mrq->data->blksz > host
156 BUG_ON(mrq->data->blocks > hos
157 BUG_ON(mrq->data->blocks * mrq
158 host->max_req_size);
159
160 #ifdef CONFIG_MMC_DEBUG
161 sz = 0;
162 for_each_sg(mrq->data->sg, sg,
163 sz += sg->length;
164 BUG_ON(sz != mrq->data->blocks
165 #endif
166
167 mrq->cmd->data = mrq->data;
168 mrq->data->error = 0;
169 mrq->data->mrq = mrq;
170 if (mrq->stop) {
171 mrq->data->stop = mrq-
172 mrq->stop->error = 0;
173 mrq->stop->mrq = mrq;
174 }
175 }
176 host->ops->request(host, mrq);
177 }
178
179 static void mmc_wait_done(struct mmc_request *
180 {
181 complete(mrq->done_data);
182 }
183
184 /**
185 * mmc_wait_for_req - start a request and
186 * @host: MMC host to start command
187 * @mrq: MMC request to start
188 *
189 * Start a new MMC custom command request
190 * for the command to complete. Does not
191 * response.
192 */
193 void mmc_wait_for_req(struct mmc_host *host, s
194 {
195 DECLARE_COMPLETION_ONSTACK(complete);
196
197 mrq->done_data = &complete;
198 mrq->done = mmc_wait_done;
199
200 mmc_start_request(host, mrq);
201
202 wait_for_completion(&complete);
203 }
204
205 EXPORT_SYMBOL(mmc_wait_for_req);
206
207 /**
208 * mmc_wait_for_cmd - start a command and
209 * @host: MMC host to start command
210 * @cmd: MMC command to start
211 * @retries: maximum number of retries
212 *
213 * Start a new MMC command for a host, an
214 * to complete. Return any error that oc
215 * was executing. Do not attempt to pars
216 */
217 int mmc_wait_for_cmd(struct mmc_host *host, st
218 {
219 struct mmc_request mrq;
220
221 WARN_ON(!host->claimed);
222
223 memset(&mrq, 0, sizeof(struct mmc_requ
224
225 memset(cmd->resp, 0, sizeof(cmd->resp)
226 cmd->retries = retries;
227
228 mrq.cmd = cmd;
229 cmd->data = NULL;
230
231 mmc_wait_for_req(host, &mrq);
232
233 return cmd->error;
234 }
235
236 EXPORT_SYMBOL(mmc_wait_for_cmd);
237
238 /**
239 * mmc_set_data_timeout - set the timeout
240 * @data: data phase for command
241 * @card: the MMC card associated with th
242 *
243 * Computes the data timeout parameters a
244 * correct algorithm given the card type.
245 */
246 void mmc_set_data_timeout(struct mmc_data *dat
247 {
248 unsigned int mult;
249
250 /*
251 * SDIO cards only define an upper 1 s
252 */
253 if (mmc_card_sdio(card)) {
254 data->timeout_ns = 1000000000;
255 data->timeout_clks = 0;
256 return;
257 }
258
259 /*
260 * SD cards use a 100 multiplier rathe
261 */
262 mult = mmc_card_sd(card) ? 100 : 10;
263
264 /*
265 * Scale up the multiplier (and theref
266 * the r2w factor for writes.
267 */
268 if (data->flags & MMC_DATA_WRITE)
269 mult <<= card->csd.r2w_factor;
270
271 data->timeout_ns = card->csd.tacc_ns *
272 data->timeout_clks = card->csd.tacc_cl
273
274 /*
275 * SD cards also have an upper limit o
276 */
277 if (mmc_card_sd(card)) {
278 unsigned int timeout_us, limit
279
280 timeout_us = data->timeout_ns
281 timeout_us += data->timeout_cl
282 (card->host->ios.clock
283
284 if (data->flags & MMC_DATA_WRI
285 /*
286 * The limit is really
287 * insufficient for so
288 */
289 limit_us = 300000;
290 else
291 limit_us = 100000;
292
293 /*
294 * SDHC cards always use these
295 */
296 if (timeout_us > limit_us || m
297 data->timeout_ns = lim
298 data->timeout_clks = 0
299 }
300 }
301 /*
302 * Some cards need very high timeouts
303 * The worst observed timeout was 900m
304 * continuous stream of data until the
305 * overflowed.
306 */
307 if (mmc_host_is_spi(card->host)) {
308 if (data->flags & MMC_DATA_WRI
309 if (data->timeout_ns <
310 data->timeout_
311 } else {
312 if (data->timeout_ns <
313 data->timeout_
314 }
315 }
316 }
317 EXPORT_SYMBOL(mmc_set_data_timeout);
318
319 /**
320 * mmc_align_data_size - pads a transfer
321 * @card: the MMC card associated with th
322 * @sz: original transfer size
323 *
324 * Pads the original data size with a num
325 * order to avoid controller bugs and/or
326 * (e.g. some controllers revert to PIO f
327 *
328 * Returns the improved size, which might
329 *
330 * Note that this function is only releva
331 * single scatter gather entry.
332 */
333 unsigned int mmc_align_data_size(struct mmc_ca
334 {
335 /*
336 * FIXME: We don't have a system for t
337 * the core about its problems yet, so
338 * align the size.
339 */
340 sz = ((sz + 3) / 4) * 4;
341
342 return sz;
343 }
344 EXPORT_SYMBOL(mmc_align_data_size);
345
346 /**
347 * __mmc_claim_host - exclusively claim a
348 * @host: mmc host to claim
349 * @abort: whether or not the operation s
350 *
351 * Claim a host for a set of operations.
352 * dereference a non-zero value then this
353 * that non-zero value without acquiring
354 * with the lock held otherwise.
355 */
356 int __mmc_claim_host(struct mmc_host *host, at
357 {
358 DECLARE_WAITQUEUE(wait, current);
359 unsigned long flags;
360 int stop;
361
362 might_sleep();
363
364 add_wait_queue(&host->wq, &wait);
365 spin_lock_irqsave(&host->lock, flags);
366 while (1) {
367 set_current_state(TASK_UNINTER
368 stop = abort ? atomic_read(abo
369 if (stop || !host->claimed)
370 break;
371 spin_unlock_irqrestore(&host->
372 schedule();
373 spin_lock_irqsave(&host->lock,
374 }
375 set_current_state(TASK_RUNNING);
376 if (!stop)
377 host->claimed = 1;
378 else
379 wake_up(&host->wq);
380 spin_unlock_irqrestore(&host->lock, fl
381 remove_wait_queue(&host->wq, &wait);
382 return stop;
383 }
384
385 EXPORT_SYMBOL(__mmc_claim_host);
386
387 /**
388 * mmc_release_host - release a host
389 * @host: mmc host to release
390 *
391 * Release a MMC host, allowing others to
392 * for their operations.
393 */
394 void mmc_release_host(struct mmc_host *host)
395 {
396 unsigned long flags;
397
398 WARN_ON(!host->claimed);
399
400 spin_lock_irqsave(&host->lock, flags);
401 host->claimed = 0;
402 spin_unlock_irqrestore(&host->lock, fl
403
404 wake_up(&host->wq);
405 }
406
407 EXPORT_SYMBOL(mmc_release_host);
408
409 /*
410 * Internal function that does the actual ios
411 * optionally printing some debug output.
412 */
413 static inline void mmc_set_ios(struct mmc_host
414 {
415 struct mmc_ios *ios = &host->ios;
416
417 pr_debug("%s: clock %uHz busmode %u po
418 "width %u timing %u\n",
419 mmc_hostname(host), ios->cloc
420 ios->power_mode, ios->chip_se
421 ios->bus_width, ios->timing);
422
423 host->ops->set_ios(host, ios);
424 }
425
426 /*
427 * Control chip select pin on a host.
428 */
429 void mmc_set_chip_select(struct mmc_host *host
430 {
431 host->ios.chip_select = mode;
432 mmc_set_ios(host);
433 }
434
435 /*
436 * Sets the host clock to the highest possible
437 * is below "hz".
438 */
439 void mmc_set_clock(struct mmc_host *host, unsi
440 {
441 WARN_ON(hz < host->f_min);
442
443 if (hz > host->f_max)
444 hz = host->f_max;
445
446 host->ios.clock = hz;
447 mmc_set_ios(host);
448 }
449
450 /*
451 * Change the bus mode (open drain/push-pull)
452 */
453 void mmc_set_bus_mode(struct mmc_host *host, u
454 {
455 host->ios.bus_mode = mode;
456 mmc_set_ios(host);
457 }
458
459 /*
460 * Change data bus width of a host.
461 */
462 void mmc_set_bus_width(struct mmc_host *host,
463 {
464 host->ios.bus_width = width;
465 mmc_set_ios(host);
466 }
467
468 /**
469 * mmc_vdd_to_ocrbitnum - Convert a voltage to
470 * @vdd: voltage (mV)
471 * @low_bits: prefer low bits in boundary ca
472 *
473 * This function returns the OCR bit number ac
474 * value. If conversion is not possible a nega
475 *
476 * Depending on the @low_bits flag the functio
477 * on boundary voltages. For example,
478 * with @low_bits = true, 3300 mV translates t
479 * with @low_bits = false, 3300 mV translates
480 *
481 * Any value in the [1951:1999] range translat
482 */
483 static int mmc_vdd_to_ocrbitnum(int vdd, bool
484 {
485 const int max_bit = ilog2(MMC_VDD_35_3
486 int bit;
487
488 if (vdd < 1650 || vdd > 3600)
489 return -EINVAL;
490
491 if (vdd >= 1650 && vdd <= 1950)
492 return ilog2(MMC_VDD_165_195);
493
494 if (low_bits)
495 vdd -= 1;
496
497 /* Base 2000 mV, step 100 mV, bit's ba
498 bit = (vdd - 2000) / 100 + 8;
499 if (bit > max_bit)
500 return max_bit;
501 return bit;
502 }
503
504 /**
505 * mmc_vddrange_to_ocrmask - Convert a voltage
506 * @vdd_min: minimum voltage value (mV)
507 * @vdd_max: maximum voltage value (mV)
508 *
509 * This function returns the OCR mask bits acc
510 * and @vdd_max values. If conversion is not p
511 *
512 * Notes wrt boundary cases:
513 * This function sets the OCR bits for all bou
514 * [3300:3400] range is translated to MMC_VDD_
515 * MMC_VDD_34_35 mask.
516 */
517 u32 mmc_vddrange_to_ocrmask(int vdd_min, int v
518 {
519 u32 mask = 0;
520
521 if (vdd_max < vdd_min)
522 return 0;
523
524 /* Prefer high bits for the boundary v
525 vdd_max = mmc_vdd_to_ocrbitnum(vdd_max
526 if (vdd_max < 0)
527 return 0;
528
529 /* Prefer low bits for the boundary vd
530 vdd_min = mmc_vdd_to_ocrbitnum(vdd_min
531 if (vdd_min < 0)
532 return 0;
533
534 /* Fill the mask, from max bit to min
535 while (vdd_max >= vdd_min)
536 mask |= 1 << vdd_max--;
537
538 return mask;
539 }
540 EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
541
542 #ifdef CONFIG_REGULATOR
543
544 /**
545 * mmc_regulator_get_ocrmask - return mask of
546 * @supply: regulator to use
547 *
548 * This returns either a negative errno, or a
549 * can be provided to MMC/SD/SDIO devices usin
550 * regulator. This would normally be called b
551 * MMC host adapter.
552 */
553 int mmc_regulator_get_ocrmask(struct regulator
554 {
555 int result = 0;
556 int count;
557 int i;
558
559 count = regulator_count_voltages(suppl
560 if (count < 0)
561 return count;
562
563 for (i = 0; i < count; i++) {
564 int vdd_uV;
565 int vdd_mV;
566
567 vdd_uV = regulator_list_voltag
568 if (vdd_uV <= 0)
569 continue;
570
571 vdd_mV = vdd_uV / 1000;
572 result |= mmc_vddrange_to_ocrm
573 }
574
575 return result;
576 }
577 EXPORT_SYMBOL(mmc_regulator_get_ocrmask);
578
579 /**
580 * mmc_regulator_set_ocr - set regulator to ma
581 * @vdd_bit: zero for power off, else a bit nu
582 * @supply: regulator to use
583 *
584 * Returns zero on success, else negative errn
585 *
586 * MMC host drivers may use this to enable or
587 * a particular supply voltage. This would no
588 * set_ios() method.
589 */
590 int mmc_regulator_set_ocr(struct regulator *su
591 {
592 int result = 0;
593 int min_uV, max_uV
594 int enabled;
595
596 enabled = regulator_is_enabled(supply)
597 if (enabled < 0)
598 return enabled;
599
600 if (vdd_bit) {
601 int tmp;
602 int voltage;
603
604 /* REVISIT mmc_vddrange_to_ocr
605 * bits this regulator doesn't
606 * be too picky, most cards an
607 * a 0.1V range goof (it's a s
608 */
609 tmp = vdd_bit - ilog2(MMC_VDD_
610 if (tmp == 0) {
611 min_uV = 1650 * 1000;
612 max_uV = 1950 * 1000;
613 } else {
614 min_uV = 1900 * 1000 +
615 max_uV = min_uV + 100
616 }
617
618 /* avoid needless changes to t
619 * might not allow this operat
620 */
621 voltage = regulator_get_voltag
622 if (voltage < 0)
623 result = voltage;
624 else if (voltage < min_uV || v
625 result = regulator_set
626 else
627 result = 0;
628
629 if (result == 0 && !enabled)
630 result = regulator_ena
631 } else if (enabled) {
632 result = regulator_disable(sup
633 }
634
635 return result;
636 }
637 EXPORT_SYMBOL(mmc_regulator_set_ocr);
638
639 #endif
640
641 /*
642 * Mask off any voltages we don't support and
643 * the lowest voltage
644 */
645 u32 mmc_select_voltage(struct mmc_host *host,
646 {
647 int bit;
648
649 ocr &= host->ocr_avail;
650
651 bit = ffs(ocr);
652 if (bit) {
653 bit -= 1;
654
655 ocr &= 3 << bit;
656
657 host->ios.vdd = bit;
658 mmc_set_ios(host);
659 } else {
660 pr_warning("%s: host doesn't s
661 mmc_hostname(h
662 ocr = 0;
663 }
664
665 return ocr;
666 }
667
668 /*
669 * Select timing parameters for host.
670 */
671 void mmc_set_timing(struct mmc_host *host, uns
672 {
673 host->ios.timing = timing;
674 mmc_set_ios(host);
675 }
676
677 /*
678 * Apply power to the MMC stack. This is a tw
679 * First, we enable power to the card without
680 * We then wait a bit for the power to stabili
681 * enable the bus drivers and clock to the car
682 *
683 * We must _NOT_ enable the clock prior to pow
684 *
685 * If a host does all the power sequencing its
686 * initial MMC_POWER_UP stage.
687 */
688 static void mmc_power_up(struct mmc_host *host
689 {
690 int bit = fls(host->ocr_avail) - 1;
691
692 host->ios.vdd = bit;
693 if (mmc_host_is_spi(host)) {
694 host->ios.chip_select = MMC_CS
695 host->ios.bus_mode = MMC_BUSMO
696 } else {
697 host->ios.chip_select = MMC_CS
698 host->ios.bus_mode = MMC_BUSMO
699 }
700 host->ios.power_mode = MMC_POWER_UP;
701 host->ios.bus_width = MMC_BUS_WIDTH_1;
702 host->ios.timing = MMC_TIMING_LEGACY;
703 mmc_set_ios(host);
704
705 /*
706 * This delay should be sufficient to
707 * to reach the minimum voltage.
708 */
709 mmc_delay(10);
710
711 if (host->f_min > 400000) {
712 pr_warning("%s: Minimum clock
713 "identificatio
714 host->ios.clock = host->f_min;
715 } else
716 host->ios.clock = 400000;
717
718 host->ios.power_mode = MMC_POWER_ON;
719 mmc_set_ios(host);
720
721 /*
722 * This delay must be at least 74 cloc
723 * time required to reach a stable vol
724 */
725 mmc_delay(10);
726 }
727
728 static void mmc_power_off(struct mmc_host *hos
729 {
730 host->ios.clock = 0;
731 host->ios.vdd = 0;
732 if (!mmc_host_is_spi(host)) {
733 host->ios.bus_mode = MMC_BUSMO
734 host->ios.chip_select = MMC_CS
735 }
736 host->ios.power_mode = MMC_POWER_OFF;
737 host->ios.bus_width = MMC_BUS_WIDTH_1;
738 host->ios.timing = MMC_TIMING_LEGACY;
739 mmc_set_ios(host);
740 }
741
742 /*
743 * Cleanup when the last reference to the bus
744 */
745 static void __mmc_release_bus(struct mmc_host
746 {
747 BUG_ON(!host);
748 BUG_ON(host->bus_refs);
749 BUG_ON(!host->bus_dead);
750
751 host->bus_ops = NULL;
752 }
753
754 /*
755 * Increase reference count of bus operator
756 */
757 static inline void mmc_bus_get(struct mmc_host
758 {
759 unsigned long flags;
760
761 spin_lock_irqsave(&host->lock, flags);
762 host->bus_refs++;
763 spin_unlock_irqrestore(&host->lock, fl
764 }
765
766 /*
767 * Decrease reference count of bus operator an
768 * it is the last reference.
769 */
770 static inline void mmc_bus_put(struct mmc_host
771 {
772 unsigned long flags;
773
774 spin_lock_irqsave(&host->lock, flags);
775 host->bus_refs--;
776 if ((host->bus_refs == 0) && host->bus
777 __mmc_release_bus(host);
778 spin_unlock_irqrestore(&host->lock, fl
779 }
780
781 /*
782 * Assign a mmc bus handler to a host. Only on
783 * host at any given time.
784 */
785 void mmc_attach_bus(struct mmc_host *host, con
786 {
787 unsigned long flags;
788
789 BUG_ON(!host);
790 BUG_ON(!ops);
791
792 WARN_ON(!host->claimed);
793
794 spin_lock_irqsave(&host->lock, flags);
795
796 BUG_ON(host->bus_ops);
797 BUG_ON(host->bus_refs);
798
799 host->bus_ops = ops;
800 host->bus_refs = 1;
801 host->bus_dead = 0;
802
803 spin_unlock_irqrestore(&host->lock, fl
804 }
805
806 /*
807 * Remove the current bus handler from a host.
808 * no interesting cards left, so the bus is po
809 */
810 void mmc_detach_bus(struct mmc_host *host)
811 {
812 unsigned long flags;
813
814 BUG_ON(!host);
815
816 WARN_ON(!host->claimed);
817 WARN_ON(!host->bus_ops);
818
819 spin_lock_irqsave(&host->lock, flags);
820
821 host->bus_dead = 1;
822
823 spin_unlock_irqrestore(&host->lock, fl
824
825 mmc_power_off(host);
826
827 mmc_bus_put(host);
828 }
829
830 /**
831 * mmc_detect_change - process change of
832 * @host: host which changed state.
833 * @delay: optional delay to wait before
834 *
835 * MMC drivers should call this when they
836 * inserted or removed. The MMC layer wil
837 * present card is still functional, and
838 * inserted.
839 */
840 void mmc_detect_change(struct mmc_host *host,
841 {
842 #ifdef CONFIG_MMC_DEBUG
843 unsigned long flags;
844 spin_lock_irqsave(&host->lock, flags);
845 WARN_ON(host->removed);
846 spin_unlock_irqrestore(&host->lock, fl
847 #endif
848
849 mmc_schedule_delayed_work(&host->detec
850 }
851
852 EXPORT_SYMBOL(mmc_detect_change);
853
854
855 void mmc_rescan(struct work_struct *work)
856 {
857 struct mmc_host *host =
858 container_of(work, struct mmc_
859 u32 ocr;
860 int err;
861
862 mmc_bus_get(host);
863
864 /* if there is a card registered, chec
865 if ((host->bus_ops != NULL) && host->b
866 host->bus_ops->detect(host);
867
868 mmc_bus_put(host);
869
870
871 mmc_bus_get(host);
872
873 /* if there still is a card present, s
874 if (host->bus_ops != NULL) {
875 mmc_bus_put(host);
876 goto out;
877 }
878
879 /* detect a newly inserted card */
880
881 /*
882 * Only we can add a new handler, so i
883 * release the lock here.
884 */
885 mmc_bus_put(host);
886
887 if (host->ops->get_cd && host->ops->ge
888 goto out;
889
890 mmc_claim_host(host);
891
892 mmc_power_up(host);
893 mmc_go_idle(host);
894
895 mmc_send_if_cond(host, host->ocr_avail
896
897 /*
898 * First we search for SDIO...
899 */
900 err = mmc_send_io_op_cond(host, 0, &oc
901 if (!err) {
902 if (mmc_attach_sdio(host, ocr)
903 mmc_power_off(host);
904 goto out;
905 }
906
907 /*
908 * ...then normal SD...
909 */
910 err = mmc_send_app_op_cond(host, 0, &o
911 if (!err) {
912 if (mmc_attach_sd(host, ocr))
913 mmc_power_off(host);
914 goto out;
915 }
916
917 /*
918 * ...and finally MMC.
919 */
920 err = mmc_send_op_cond(host, 0, &ocr);
921 if (!err) {
922 if (mmc_attach_mmc(host, ocr))
923 mmc_power_off(host);
924 goto out;
925 }
926
927 mmc_release_host(host);
928 mmc_power_off(host);
929
930 out:
931 if (host->caps & MMC_CAP_NEEDS_POLL)
932 mmc_schedule_delayed_work(&hos
933 }
934
935 void mmc_start_host(struct mmc_host *host)
936 {
937 mmc_power_off(host);
938 mmc_detect_change(host, 0);
939 }
940
941 void mmc_stop_host(struct mmc_host *host)
942 {
943 #ifdef CONFIG_MMC_DEBUG
944 unsigned long flags;
945 spin_lock_irqsave(&host->lock, flags);
946 host->removed = 1;
947 spin_unlock_irqrestore(&host->lock, fl
948 #endif
949
950 cancel_delayed_work(&host->detect);
951 mmc_flush_scheduled_work();
952
953 mmc_bus_get(host);
954 if (host->bus_ops && !host->bus_dead)
955 if (host->bus_ops->remove)
956 host->bus_ops->remove(
957
958 mmc_claim_host(host);
959 mmc_detach_bus(host);
960 mmc_release_host(host);
961 }
962 mmc_bus_put(host);
963
964 BUG_ON(host->card);
965
966 mmc_power_off(host);
967 }
968
969 #ifdef CONFIG_PM
970
971 /**
972 * mmc_suspend_host - suspend a host
973 * @host: mmc host
974 * @state: suspend mode (PM_SUSPEND_xxx)
975 */
976 int mmc_suspend_host(struct mmc_host *host, pm
977 {
978 cancel_delayed_work(&host->detect);
979 mmc_flush_scheduled_work();
980
981 mmc_bus_get(host);
982 if (host->bus_ops && !host->bus_dead)
983 if (host->bus_ops->suspend)
984 host->bus_ops->suspend
985 if (!host->bus_ops->resume) {
986 if (host->bus_ops->rem
987 host->bus_ops-
988
989 mmc_claim_host(host);
990 mmc_detach_bus(host);
991 mmc_release_host(host)
992 }
993 }
994 mmc_bus_put(host);
995
996 mmc_power_off(host);
997
998 return 0;
999 }
1000
1001 EXPORT_SYMBOL(mmc_suspend_host);
1002
1003 /**
1004 * mmc_resume_host - resume a previously
1005 * @host: mmc host
1006 */
1007 int mmc_resume_host(struct mmc_host *host)
1008 {
1009 mmc_bus_get(host);
1010 if (host->bus_ops && !host->bus_dead)
1011 mmc_power_up(host);
1012 mmc_select_voltage(host, host
1013 BUG_ON(!host->bus_ops->resume
1014 host->bus_ops->resume(host);
1015 }
1016 mmc_bus_put(host);
1017
1018 /*
1019 * We add a slight delay here so that
1020 * in parallel.
1021 */
1022 mmc_detect_change(host, 1);
1023
1024 return 0;
1025 }
1026
1027 EXPORT_SYMBOL(mmc_resume_host);
1028
1029 #endif
1030
1031 static int __init mmc_init(void)
1032 {
1033 int ret;
1034
1035 workqueue = create_singlethread_workq
1036 if (!workqueue)
1037 return -ENOMEM;
1038
1039 ret = mmc_register_bus();
1040 if (ret)
1041 goto destroy_workqueue;
1042
1043 ret = mmc_register_host_class();
1044 if (ret)
1045 goto unregister_bus;
1046
1047 ret = sdio_register_bus();
1048 if (ret)
1049 goto unregister_host_class;
1050
1051 return 0;
1052
1053 unregister_host_class:
1054 mmc_unregister_host_class();
1055 unregister_bus:
1056 mmc_unregister_bus();
1057 destroy_workqueue:
1058 destroy_workqueue(workqueue);
1059
1060 return ret;
1061 }
1062
1063 static void __exit mmc_exit(void)
1064 {
1065 sdio_unregister_bus();
1066 mmc_unregister_host_class();
1067 mmc_unregister_bus();
1068 destroy_workqueue(workqueue);
1069 }
1070
1071 subsys_initcall(mmc_init);
1072 module_exit(mmc_exit);
1073
1074 MODULE_LICENSE("GPL");
1075
| This page was automatically generated by the LXR engine. |