]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/mmc/core/core.c
mmc: at91_mci: disable handling of blocks with size not multiple of 4 bytes
[net-next-2.6.git] / drivers / mmc / core / core.c
CommitLineData
1da177e4 1/*
aaac1b47 2 * linux/drivers/mmc/core/core.c
1da177e4
LT
3 *
4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
5b4fd9ae 5 * SD support Copyright (C) 2004 Ian Molton, All Rights Reserved.
b855885e 6 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
bce40a36 7 * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved.
1da177e4
LT
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
1da177e4
LT
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>
b57c43ad
PO
21#include <asm/scatterlist.h>
22#include <linux/scatterlist.h>
1da177e4
LT
23
24#include <linux/mmc/card.h>
25#include <linux/mmc/host.h>
da7fbe58
PO
26#include <linux/mmc/mmc.h>
27#include <linux/mmc/sd.h>
1da177e4 28
aaac1b47 29#include "core.h"
ffce2e7e
PO
30#include "bus.h"
31#include "host.h"
da7fbe58
PO
32
33#include "mmc_ops.h"
34#include "sd_ops.h"
1da177e4 35
7ea239d9
PO
36extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr);
37extern int mmc_attach_sd(struct mmc_host *host, u32 ocr);
1da177e4 38
ffce2e7e
PO
39static struct workqueue_struct *workqueue;
40
41/*
42 * Internal function. Schedule delayed work in the MMC work queue.
43 */
44static int mmc_schedule_delayed_work(struct delayed_work *work,
45 unsigned long delay)
46{
47 return queue_delayed_work(workqueue, work, delay);
48}
49
50/*
51 * Internal function. Flush all scheduled work from the MMC work queue.
52 */
53static void mmc_flush_scheduled_work(void)
54{
55 flush_workqueue(workqueue);
56}
57
1da177e4 58/**
fe10c6ab
RK
59 * mmc_request_done - finish processing an MMC request
60 * @host: MMC host which completed request
61 * @mrq: MMC request which request
1da177e4
LT
62 *
63 * MMC drivers should call this function when they have completed
fe10c6ab 64 * their processing of a request.
1da177e4
LT
65 */
66void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
67{
68 struct mmc_command *cmd = mrq->cmd;
920e70c5
RK
69 int err = cmd->error;
70
1da177e4 71 if (err && cmd->retries) {
e4d21708
PO
72 pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
73 mmc_hostname(host), cmd->opcode, err);
74
1da177e4
LT
75 cmd->retries--;
76 cmd->error = 0;
77 host->ops->request(host, mrq);
e4d21708
PO
78 } else {
79 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
80 mmc_hostname(host), cmd->opcode, err,
81 cmd->resp[0], cmd->resp[1],
82 cmd->resp[2], cmd->resp[3]);
83
84 if (mrq->data) {
85 pr_debug("%s: %d bytes transferred: %d\n",
86 mmc_hostname(host),
87 mrq->data->bytes_xfered, mrq->data->error);
88 }
89
90 if (mrq->stop) {
91 pr_debug("%s: (CMD%u): %d: %08x %08x %08x %08x\n",
92 mmc_hostname(host), mrq->stop->opcode,
93 mrq->stop->error,
94 mrq->stop->resp[0], mrq->stop->resp[1],
95 mrq->stop->resp[2], mrq->stop->resp[3]);
96 }
97
98 if (mrq->done)
99 mrq->done(mrq);
1da177e4
LT
100 }
101}
102
103EXPORT_SYMBOL(mmc_request_done);
104
39361851 105static void
1da177e4
LT
106mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
107{
976d9276
PO
108#ifdef CONFIG_MMC_DEBUG
109 unsigned int i, sz;
110#endif
111
920e70c5
RK
112 pr_debug("%s: starting CMD%u arg %08x flags %08x\n",
113 mmc_hostname(host), mrq->cmd->opcode,
114 mrq->cmd->arg, mrq->cmd->flags);
1da177e4 115
e4d21708
PO
116 if (mrq->data) {
117 pr_debug("%s: blksz %d blocks %d flags %08x "
118 "tsac %d ms nsac %d\n",
119 mmc_hostname(host), mrq->data->blksz,
120 mrq->data->blocks, mrq->data->flags,
121 mrq->data->timeout_ns / 10000000,
122 mrq->data->timeout_clks);
123 }
124
125 if (mrq->stop) {
126 pr_debug("%s: CMD%u arg %08x flags %08x\n",
127 mmc_hostname(host), mrq->stop->opcode,
128 mrq->stop->arg, mrq->stop->flags);
129 }
130
f22ee4ed 131 WARN_ON(!host->claimed);
1da177e4
LT
132
133 mrq->cmd->error = 0;
134 mrq->cmd->mrq = mrq;
135 if (mrq->data) {
fe4a3c7a 136 BUG_ON(mrq->data->blksz > host->max_blk_size);
55db890a
PO
137 BUG_ON(mrq->data->blocks > host->max_blk_count);
138 BUG_ON(mrq->data->blocks * mrq->data->blksz >
139 host->max_req_size);
fe4a3c7a 140
976d9276
PO
141#ifdef CONFIG_MMC_DEBUG
142 sz = 0;
143 for (i = 0;i < mrq->data->sg_len;i++)
144 sz += mrq->data->sg[i].length;
145 BUG_ON(sz != mrq->data->blocks * mrq->data->blksz);
146#endif
147
1da177e4
LT
148 mrq->cmd->data = mrq->data;
149 mrq->data->error = 0;
150 mrq->data->mrq = mrq;
151 if (mrq->stop) {
152 mrq->data->stop = mrq->stop;
153 mrq->stop->error = 0;
154 mrq->stop->mrq = mrq;
155 }
156 }
157 host->ops->request(host, mrq);
158}
159
1da177e4
LT
160static void mmc_wait_done(struct mmc_request *mrq)
161{
162 complete(mrq->done_data);
163}
164
67a61c48
PO
165/**
166 * mmc_wait_for_req - start a request and wait for completion
167 * @host: MMC host to start command
168 * @mrq: MMC request to start
169 *
170 * Start a new MMC custom command request for a host, and wait
171 * for the command to complete. Does not attempt to parse the
172 * response.
173 */
174void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
1da177e4 175{
0afffc72 176 DECLARE_COMPLETION_ONSTACK(complete);
1da177e4
LT
177
178 mrq->done_data = &complete;
179 mrq->done = mmc_wait_done;
180
181 mmc_start_request(host, mrq);
182
183 wait_for_completion(&complete);
1da177e4
LT
184}
185
186EXPORT_SYMBOL(mmc_wait_for_req);
187
188/**
189 * mmc_wait_for_cmd - start a command and wait for completion
190 * @host: MMC host to start command
191 * @cmd: MMC command to start
192 * @retries: maximum number of retries
193 *
194 * Start a new MMC command for a host, and wait for the command
195 * to complete. Return any error that occurred while the command
196 * was executing. Do not attempt to parse the response.
197 */
198int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries)
199{
200 struct mmc_request mrq;
201
f22ee4ed 202 BUG_ON(!host->claimed);
1da177e4
LT
203
204 memset(&mrq, 0, sizeof(struct mmc_request));
205
206 memset(cmd->resp, 0, sizeof(cmd->resp));
207 cmd->retries = retries;
208
209 mrq.cmd = cmd;
210 cmd->data = NULL;
211
212 mmc_wait_for_req(host, &mrq);
213
214 return cmd->error;
215}
216
217EXPORT_SYMBOL(mmc_wait_for_cmd);
218
d773d725
RK
219/**
220 * mmc_set_data_timeout - set the timeout for a data command
221 * @data: data phase for command
222 * @card: the MMC card associated with the data transfer
67a61c48
PO
223 *
224 * Computes the data timeout parameters according to the
225 * correct algorithm given the card type.
d773d725 226 */
b146d26a 227void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
d773d725
RK
228{
229 unsigned int mult;
230
231 /*
232 * SD cards use a 100 multiplier rather than 10
233 */
234 mult = mmc_card_sd(card) ? 100 : 10;
235
236 /*
237 * Scale up the multiplier (and therefore the timeout) by
238 * the r2w factor for writes.
239 */
b146d26a 240 if (data->flags & MMC_DATA_WRITE)
d773d725
RK
241 mult <<= card->csd.r2w_factor;
242
243 data->timeout_ns = card->csd.tacc_ns * mult;
244 data->timeout_clks = card->csd.tacc_clks * mult;
245
246 /*
247 * SD cards also have an upper limit on the timeout.
248 */
249 if (mmc_card_sd(card)) {
250 unsigned int timeout_us, limit_us;
251
252 timeout_us = data->timeout_ns / 1000;
253 timeout_us += data->timeout_clks * 1000 /
254 (card->host->ios.clock / 1000);
255
b146d26a 256 if (data->flags & MMC_DATA_WRITE)
d773d725
RK
257 limit_us = 250000;
258 else
259 limit_us = 100000;
260
fba68bd2
PL
261 /*
262 * SDHC cards always use these fixed values.
263 */
264 if (timeout_us > limit_us || mmc_card_blockaddr(card)) {
d773d725
RK
265 data->timeout_ns = limit_us * 1000;
266 data->timeout_clks = 0;
267 }
268 }
269}
270EXPORT_SYMBOL(mmc_set_data_timeout);
271
1da177e4 272/**
67a61c48 273 * mmc_claim_host - exclusively claim a host
1da177e4 274 * @host: mmc host to claim
1da177e4 275 *
67a61c48 276 * Claim a host for a set of operations.
1da177e4 277 */
b855885e 278void mmc_claim_host(struct mmc_host *host)
1da177e4
LT
279{
280 DECLARE_WAITQUEUE(wait, current);
281 unsigned long flags;
1da177e4 282
cf795bfb
PO
283 might_sleep();
284
1da177e4
LT
285 add_wait_queue(&host->wq, &wait);
286 spin_lock_irqsave(&host->lock, flags);
287 while (1) {
288 set_current_state(TASK_UNINTERRUPTIBLE);
f22ee4ed 289 if (!host->claimed)
1da177e4
LT
290 break;
291 spin_unlock_irqrestore(&host->lock, flags);
292 schedule();
293 spin_lock_irqsave(&host->lock, flags);
294 }
295 set_current_state(TASK_RUNNING);
f22ee4ed 296 host->claimed = 1;
1da177e4
LT
297 spin_unlock_irqrestore(&host->lock, flags);
298 remove_wait_queue(&host->wq, &wait);
1da177e4
LT
299}
300
b855885e 301EXPORT_SYMBOL(mmc_claim_host);
1da177e4
LT
302
303/**
304 * mmc_release_host - release a host
305 * @host: mmc host to release
306 *
307 * Release a MMC host, allowing others to claim the host
308 * for their operations.
309 */
310void mmc_release_host(struct mmc_host *host)
311{
312 unsigned long flags;
313
f22ee4ed 314 BUG_ON(!host->claimed);
1da177e4
LT
315
316 spin_lock_irqsave(&host->lock, flags);
f22ee4ed 317 host->claimed = 0;
1da177e4
LT
318 spin_unlock_irqrestore(&host->lock, flags);
319
320 wake_up(&host->wq);
321}
322
323EXPORT_SYMBOL(mmc_release_host);
324
7ea239d9
PO
325/*
326 * Internal function that does the actual ios call to the host driver,
327 * optionally printing some debug output.
328 */
920e70c5
RK
329static inline void mmc_set_ios(struct mmc_host *host)
330{
331 struct mmc_ios *ios = &host->ios;
332
cd9277c0
PO
333 pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
334 "width %u timing %u\n",
920e70c5
RK
335 mmc_hostname(host), ios->clock, ios->bus_mode,
336 ios->power_mode, ios->chip_select, ios->vdd,
cd9277c0 337 ios->bus_width, ios->timing);
fba68bd2 338
920e70c5
RK
339 host->ops->set_ios(host, ios);
340}
341
7ea239d9
PO
342/*
343 * Control chip select pin on a host.
344 */
da7fbe58 345void mmc_set_chip_select(struct mmc_host *host, int mode)
1da177e4 346{
da7fbe58
PO
347 host->ios.chip_select = mode;
348 mmc_set_ios(host);
1da177e4
LT
349}
350
7ea239d9
PO
351/*
352 * Sets the host clock to the highest possible frequency that
353 * is below "hz".
354 */
355void mmc_set_clock(struct mmc_host *host, unsigned int hz)
356{
357 WARN_ON(hz < host->f_min);
358
359 if (hz > host->f_max)
360 hz = host->f_max;
361
362 host->ios.clock = hz;
363 mmc_set_ios(host);
364}
365
366/*
367 * Change the bus mode (open drain/push-pull) of a host.
368 */
369void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode)
370{
371 host->ios.bus_mode = mode;
372 mmc_set_ios(host);
373}
374
375/*
376 * Change data bus width of a host.
377 */
378void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
379{
380 host->ios.bus_width = width;
381 mmc_set_ios(host);
382}
383
1da177e4
LT
384/*
385 * Mask off any voltages we don't support and select
386 * the lowest voltage
387 */
7ea239d9 388u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
1da177e4
LT
389{
390 int bit;
391
392 ocr &= host->ocr_avail;
393
394 bit = ffs(ocr);
395 if (bit) {
396 bit -= 1;
397
63ef731a 398 ocr &= 3 << bit;
1da177e4
LT
399
400 host->ios.vdd = bit;
920e70c5 401 mmc_set_ios(host);
1da177e4
LT
402 } else {
403 ocr = 0;
404 }
405
406 return ocr;
407}
408
b57c43ad 409/*
7ea239d9 410 * Select timing parameters for host.
b57c43ad 411 */
7ea239d9 412void mmc_set_timing(struct mmc_host *host, unsigned int timing)
b57c43ad 413{
7ea239d9
PO
414 host->ios.timing = timing;
415 mmc_set_ios(host);
b57c43ad
PO
416}
417
1da177e4 418/*
45f8245b
RK
419 * Apply power to the MMC stack. This is a two-stage process.
420 * First, we enable power to the card without the clock running.
421 * We then wait a bit for the power to stabilise. Finally,
422 * enable the bus drivers and clock to the card.
423 *
424 * We must _NOT_ enable the clock prior to power stablising.
425 *
426 * If a host does all the power sequencing itself, ignore the
427 * initial MMC_POWER_UP stage.
1da177e4
LT
428 */
429static void mmc_power_up(struct mmc_host *host)
430{
431 int bit = fls(host->ocr_avail) - 1;
432
433 host->ios.vdd = bit;
434 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
865e9f13 435 host->ios.chip_select = MMC_CS_DONTCARE;
1da177e4 436 host->ios.power_mode = MMC_POWER_UP;
f218278a 437 host->ios.bus_width = MMC_BUS_WIDTH_1;
cd9277c0 438 host->ios.timing = MMC_TIMING_LEGACY;
920e70c5 439 mmc_set_ios(host);
1da177e4
LT
440
441 mmc_delay(1);
442
443 host->ios.clock = host->f_min;
444 host->ios.power_mode = MMC_POWER_ON;
920e70c5 445 mmc_set_ios(host);
1da177e4
LT
446
447 mmc_delay(2);
448}
449
450static void mmc_power_off(struct mmc_host *host)
451{
452 host->ios.clock = 0;
453 host->ios.vdd = 0;
454 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
865e9f13 455 host->ios.chip_select = MMC_CS_DONTCARE;
1da177e4 456 host->ios.power_mode = MMC_POWER_OFF;
f218278a 457 host->ios.bus_width = MMC_BUS_WIDTH_1;
cd9277c0 458 host->ios.timing = MMC_TIMING_LEGACY;
920e70c5 459 mmc_set_ios(host);
1da177e4
LT
460}
461
39361851
AB
462/*
463 * Cleanup when the last reference to the bus operator is dropped.
464 */
465void __mmc_release_bus(struct mmc_host *host)
466{
467 BUG_ON(!host);
468 BUG_ON(host->bus_refs);
469 BUG_ON(!host->bus_dead);
470
471 host->bus_ops = NULL;
472}
473
474/*
475 * Increase reference count of bus operator
476 */
477static inline void mmc_bus_get(struct mmc_host *host)
478{
479 unsigned long flags;
480
481 spin_lock_irqsave(&host->lock, flags);
482 host->bus_refs++;
483 spin_unlock_irqrestore(&host->lock, flags);
484}
485
486/*
487 * Decrease reference count of bus operator and free it if
488 * it is the last reference.
489 */
490static inline void mmc_bus_put(struct mmc_host *host)
491{
492 unsigned long flags;
493
494 spin_lock_irqsave(&host->lock, flags);
495 host->bus_refs--;
496 if ((host->bus_refs == 0) && host->bus_ops)
497 __mmc_release_bus(host);
498 spin_unlock_irqrestore(&host->lock, flags);
499}
500
1da177e4 501/*
7ea239d9
PO
502 * Assign a mmc bus handler to a host. Only one bus handler may control a
503 * host at any given time.
1da177e4 504 */
7ea239d9 505void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
1da177e4 506{
7ea239d9 507 unsigned long flags;
e45a1bd2 508
7ea239d9
PO
509 BUG_ON(!host);
510 BUG_ON(!ops);
b855885e 511
7ea239d9 512 BUG_ON(!host->claimed);
bce40a36 513
7ea239d9 514 spin_lock_irqsave(&host->lock, flags);
bce40a36 515
7ea239d9
PO
516 BUG_ON(host->bus_ops);
517 BUG_ON(host->bus_refs);
b57c43ad 518
7ea239d9
PO
519 host->bus_ops = ops;
520 host->bus_refs = 1;
521 host->bus_dead = 0;
b57c43ad 522
7ea239d9 523 spin_unlock_irqrestore(&host->lock, flags);
b57c43ad
PO
524}
525
7ea239d9
PO
526/*
527 * Remove the current bus handler from a host. Assumes that there are
528 * no interesting cards left, so the bus is powered down.
529 */
530void mmc_detach_bus(struct mmc_host *host)
7ccd266e 531{
7ea239d9 532 unsigned long flags;
7ccd266e 533
7ea239d9 534 BUG_ON(!host);
7ccd266e 535
7ea239d9
PO
536 BUG_ON(!host->claimed);
537 BUG_ON(!host->bus_ops);
cd9277c0 538
7ea239d9 539 spin_lock_irqsave(&host->lock, flags);
7ccd266e 540
7ea239d9 541 host->bus_dead = 1;
7ccd266e 542
7ea239d9 543 spin_unlock_irqrestore(&host->lock, flags);
1da177e4 544
7ea239d9 545 mmc_power_off(host);
1da177e4 546
7ea239d9 547 mmc_bus_put(host);
1da177e4
LT
548}
549
1da177e4
LT
550/**
551 * mmc_detect_change - process change of state on a MMC socket
552 * @host: host which changed state.
8dc00335 553 * @delay: optional delay to wait before detection (jiffies)
1da177e4 554 *
67a61c48
PO
555 * MMC drivers should call this when they detect a card has been
556 * inserted or removed. The MMC layer will confirm that any
557 * present card is still functional, and initialize any newly
558 * inserted.
1da177e4 559 */
8dc00335 560void mmc_detect_change(struct mmc_host *host, unsigned long delay)
1da177e4 561{
3b91e550 562#ifdef CONFIG_MMC_DEBUG
1efd48b3 563 unsigned long flags;
01f41ec7 564 spin_lock_irqsave(&host->lock, flags);
3b91e550 565 BUG_ON(host->removed);
01f41ec7 566 spin_unlock_irqrestore(&host->lock, flags);
3b91e550
PO
567#endif
568
c4028958 569 mmc_schedule_delayed_work(&host->detect, delay);
1da177e4
LT
570}
571
572EXPORT_SYMBOL(mmc_detect_change);
573
574
b93931a6 575void mmc_rescan(struct work_struct *work)
1da177e4 576{
c4028958
DH
577 struct mmc_host *host =
578 container_of(work, struct mmc_host, detect.work);
7ea239d9
PO
579 u32 ocr;
580 int err;
1da177e4 581
7ea239d9 582 mmc_bus_get(host);
b855885e 583
7ea239d9 584 if (host->bus_ops == NULL) {
1da177e4 585 /*
7ea239d9
PO
586 * Only we can add a new handler, so it's safe to
587 * release the lock here.
1da177e4 588 */
7ea239d9 589 mmc_bus_put(host);
1da177e4 590
7ea239d9 591 mmc_claim_host(host);
1da177e4 592
7ea239d9
PO
593 mmc_power_up(host);
594 mmc_go_idle(host);
1da177e4 595
7ea239d9 596 mmc_send_if_cond(host, host->ocr_avail);
1da177e4 597
7ea239d9 598 err = mmc_send_app_op_cond(host, 0, &ocr);
17b0429d 599 if (!err) {
7ea239d9
PO
600 if (mmc_attach_sd(host, ocr))
601 mmc_power_off(host);
602 } else {
603 /*
604 * If we fail to detect any SD cards then try
605 * searching for MMC cards.
606 */
607 err = mmc_send_op_cond(host, 0, &ocr);
17b0429d 608 if (!err) {
7ea239d9
PO
609 if (mmc_attach_mmc(host, ocr))
610 mmc_power_off(host);
611 } else {
612 mmc_power_off(host);
613 mmc_release_host(host);
614 }
615 }
616 } else {
617 if (host->bus_ops->detect && !host->bus_dead)
618 host->bus_ops->detect(host);
619
620 mmc_bus_put(host);
621 }
1da177e4
LT
622}
623
b93931a6 624void mmc_start_host(struct mmc_host *host)
1da177e4 625{
b93931a6
PO
626 mmc_power_off(host);
627 mmc_detect_change(host, 0);
1da177e4
LT
628}
629
b93931a6 630void mmc_stop_host(struct mmc_host *host)
1da177e4 631{
3b91e550 632#ifdef CONFIG_MMC_DEBUG
1efd48b3
PO
633 unsigned long flags;
634 spin_lock_irqsave(&host->lock, flags);
3b91e550 635 host->removed = 1;
1efd48b3 636 spin_unlock_irqrestore(&host->lock, flags);
3b91e550
PO
637#endif
638
639 mmc_flush_scheduled_work();
640
7ea239d9
PO
641 mmc_bus_get(host);
642 if (host->bus_ops && !host->bus_dead) {
643 if (host->bus_ops->remove)
644 host->bus_ops->remove(host);
645
646 mmc_claim_host(host);
647 mmc_detach_bus(host);
648 mmc_release_host(host);
1da177e4 649 }
7ea239d9
PO
650 mmc_bus_put(host);
651
652 BUG_ON(host->card);
1da177e4
LT
653
654 mmc_power_off(host);
655}
656
1da177e4
LT
657#ifdef CONFIG_PM
658
659/**
660 * mmc_suspend_host - suspend a host
661 * @host: mmc host
662 * @state: suspend mode (PM_SUSPEND_xxx)
663 */
e5378ca8 664int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
1da177e4 665{
b5af25be
PO
666 mmc_flush_scheduled_work();
667
7ea239d9
PO
668 mmc_bus_get(host);
669 if (host->bus_ops && !host->bus_dead) {
6abaa0c9
PO
670 if (host->bus_ops->suspend)
671 host->bus_ops->suspend(host);
672 if (!host->bus_ops->resume) {
673 if (host->bus_ops->remove)
674 host->bus_ops->remove(host);
675
676 mmc_claim_host(host);
677 mmc_detach_bus(host);
678 mmc_release_host(host);
679 }
b5af25be 680 }
7ea239d9
PO
681 mmc_bus_put(host);
682
1da177e4 683 mmc_power_off(host);
1da177e4
LT
684
685 return 0;
686}
687
688EXPORT_SYMBOL(mmc_suspend_host);
689
690/**
691 * mmc_resume_host - resume a previously suspended host
692 * @host: mmc host
693 */
694int mmc_resume_host(struct mmc_host *host)
695{
6abaa0c9
PO
696 mmc_bus_get(host);
697 if (host->bus_ops && !host->bus_dead) {
698 mmc_power_up(host);
699 BUG_ON(!host->bus_ops->resume);
700 host->bus_ops->resume(host);
701 }
702 mmc_bus_put(host);
703
704 /*
705 * We add a slight delay here so that resume can progress
706 * in parallel.
707 */
708 mmc_detect_change(host, 1);
1da177e4
LT
709
710 return 0;
711}
712
713EXPORT_SYMBOL(mmc_resume_host);
714
715#endif
716
ffce2e7e
PO
717static int __init mmc_init(void)
718{
719 int ret;
720
721 workqueue = create_singlethread_workqueue("kmmcd");
722 if (!workqueue)
723 return -ENOMEM;
724
725 ret = mmc_register_bus();
726 if (ret == 0) {
727 ret = mmc_register_host_class();
728 if (ret)
729 mmc_unregister_bus();
730 }
731 return ret;
732}
733
734static void __exit mmc_exit(void)
735{
736 mmc_unregister_host_class();
737 mmc_unregister_bus();
738 destroy_workqueue(workqueue);
739}
740
741module_init(mmc_init);
742module_exit(mmc_exit);
743
1da177e4 744MODULE_LICENSE("GPL");