2 * linux/drivers/mmc/host/omap.c
4 * Copyright (C) 2004 Nokia Corporation
5 * Written by Tuukka Tikkanen and Juha Yrjölä<juha.yrjola@nokia.com>
6 * Misc hacks here and there by Tony Lindgren <tony@atomide.com>
7 * Other hacks (DMA, SD, etc) by David Brownell
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.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/ioport.h>
18 #include <linux/platform_device.h>
19 #include <linux/interrupt.h>
20 #include <linux/dmaengine.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/delay.h>
23 #include <linux/spinlock.h>
24 #include <linux/timer.h>
25 #include <linux/omap-dma.h>
26 #include <linux/mmc/host.h>
27 #include <linux/mmc/card.h>
28 #include <linux/clk.h>
29 #include <linux/scatterlist.h>
30 #include <linux/slab.h>
31 #include <linux/platform_data/mmc-omap.h>
34 #define OMAP_MMC_REG_CMD 0x00
35 #define OMAP_MMC_REG_ARGL 0x01
36 #define OMAP_MMC_REG_ARGH 0x02
37 #define OMAP_MMC_REG_CON 0x03
38 #define OMAP_MMC_REG_STAT 0x04
39 #define OMAP_MMC_REG_IE 0x05
40 #define OMAP_MMC_REG_CTO 0x06
41 #define OMAP_MMC_REG_DTO 0x07
42 #define OMAP_MMC_REG_DATA 0x08
43 #define OMAP_MMC_REG_BLEN 0x09
44 #define OMAP_MMC_REG_NBLK 0x0a
45 #define OMAP_MMC_REG_BUF 0x0b
46 #define OMAP_MMC_REG_SDIO 0x0d
47 #define OMAP_MMC_REG_REV 0x0f
48 #define OMAP_MMC_REG_RSP0 0x10
49 #define OMAP_MMC_REG_RSP1 0x11
50 #define OMAP_MMC_REG_RSP2 0x12
51 #define OMAP_MMC_REG_RSP3 0x13
52 #define OMAP_MMC_REG_RSP4 0x14
53 #define OMAP_MMC_REG_RSP5 0x15
54 #define OMAP_MMC_REG_RSP6 0x16
55 #define OMAP_MMC_REG_RSP7 0x17
56 #define OMAP_MMC_REG_IOSR 0x18
57 #define OMAP_MMC_REG_SYSC 0x19
58 #define OMAP_MMC_REG_SYSS 0x1a
60 #define OMAP_MMC_STAT_CARD_ERR (1 << 14)
61 #define OMAP_MMC_STAT_CARD_IRQ (1 << 13)
62 #define OMAP_MMC_STAT_OCR_BUSY (1 << 12)
63 #define OMAP_MMC_STAT_A_EMPTY (1 << 11)
64 #define OMAP_MMC_STAT_A_FULL (1 << 10)
65 #define OMAP_MMC_STAT_CMD_CRC (1 << 8)
66 #define OMAP_MMC_STAT_CMD_TOUT (1 << 7)
67 #define OMAP_MMC_STAT_DATA_CRC (1 << 6)
68 #define OMAP_MMC_STAT_DATA_TOUT (1 << 5)
69 #define OMAP_MMC_STAT_END_BUSY (1 << 4)
70 #define OMAP_MMC_STAT_END_OF_DATA (1 << 3)
71 #define OMAP_MMC_STAT_CARD_BUSY (1 << 2)
72 #define OMAP_MMC_STAT_END_OF_CMD (1 << 0)
74 #define mmc_omap7xx() (host->features & MMC_OMAP7XX)
75 #define mmc_omap15xx() (host->features & MMC_OMAP15XX)
76 #define mmc_omap16xx() (host->features & MMC_OMAP16XX)
77 #define MMC_OMAP1_MASK (MMC_OMAP7XX | MMC_OMAP15XX | MMC_OMAP16XX)
78 #define mmc_omap1() (host->features & MMC_OMAP1_MASK)
79 #define mmc_omap2() (!mmc_omap1())
81 #define OMAP_MMC_REG(host, reg) (OMAP_MMC_REG_##reg << (host)->reg_shift)
82 #define OMAP_MMC_READ(host, reg) __raw_readw((host)->virt_base + OMAP_MMC_REG(host, reg))
83 #define OMAP_MMC_WRITE(host, reg, val) __raw_writew((val), (host)->virt_base + OMAP_MMC_REG(host, reg))
88 #define OMAP_MMC_CMDTYPE_BC 0
89 #define OMAP_MMC_CMDTYPE_BCR 1
90 #define OMAP_MMC_CMDTYPE_AC 2
91 #define OMAP_MMC_CMDTYPE_ADTC 3
93 #define OMAP_DMA_MMC_TX 21
94 #define OMAP_DMA_MMC_RX 22
95 #define OMAP_DMA_MMC2_TX 54
96 #define OMAP_DMA_MMC2_RX 55
98 #define OMAP24XX_DMA_MMC2_TX 47
99 #define OMAP24XX_DMA_MMC2_RX 48
100 #define OMAP24XX_DMA_MMC1_TX 61
101 #define OMAP24XX_DMA_MMC1_RX 62
104 #define DRIVER_NAME "mmci-omap"
106 /* Specifies how often in millisecs to poll for card status changes
107 * when the cover switch is open */
108 #define OMAP_MMC_COVER_POLL_DELAY 500
110 struct mmc_omap_host
;
112 struct mmc_omap_slot
{
117 unsigned int fclk_freq
;
119 struct tasklet_struct cover_tasklet
;
120 struct timer_list cover_timer
;
123 struct mmc_request
*mrq
;
124 struct mmc_omap_host
*host
;
125 struct mmc_host
*mmc
;
126 struct omap_mmc_slot_data
*pdata
;
129 struct mmc_omap_host
{
132 struct mmc_request
* mrq
;
133 struct mmc_command
* cmd
;
134 struct mmc_data
* data
;
135 struct mmc_host
* mmc
;
137 unsigned char id
; /* 16xx chips have 2 MMC blocks */
140 struct dma_chan
*dma_rx
;
142 struct dma_chan
*dma_tx
;
144 struct resource
*mem_res
;
145 void __iomem
*virt_base
;
146 unsigned int phys_base
;
148 unsigned char bus_mode
;
149 unsigned int reg_shift
;
151 struct work_struct cmd_abort_work
;
153 struct timer_list cmd_abort_timer
;
155 struct work_struct slot_release_work
;
156 struct mmc_omap_slot
*next_slot
;
157 struct work_struct send_stop_work
;
158 struct mmc_data
*stop_data
;
163 u32 buffer_bytes_left
;
164 u32 total_bytes_left
;
168 unsigned brs_received
:1, dma_done
:1;
169 unsigned dma_in_use
:1;
172 struct mmc_omap_slot
*slots
[OMAP_MMC_MAX_SLOTS
];
173 struct mmc_omap_slot
*current_slot
;
174 spinlock_t slot_lock
;
175 wait_queue_head_t slot_wq
;
178 struct timer_list clk_timer
;
179 spinlock_t clk_lock
; /* for changing enabled state */
180 unsigned int fclk_enabled
:1;
181 struct workqueue_struct
*mmc_omap_wq
;
183 struct omap_mmc_platform_data
*pdata
;
187 static void mmc_omap_fclk_offdelay(struct mmc_omap_slot
*slot
)
189 unsigned long tick_ns
;
191 if (slot
!= NULL
&& slot
->host
->fclk_enabled
&& slot
->fclk_freq
> 0) {
192 tick_ns
= (1000000000 + slot
->fclk_freq
- 1) / slot
->fclk_freq
;
197 static void mmc_omap_fclk_enable(struct mmc_omap_host
*host
, unsigned int enable
)
201 spin_lock_irqsave(&host
->clk_lock
, flags
);
202 if (host
->fclk_enabled
!= enable
) {
203 host
->fclk_enabled
= enable
;
205 clk_enable(host
->fclk
);
207 clk_disable(host
->fclk
);
209 spin_unlock_irqrestore(&host
->clk_lock
, flags
);
212 static void mmc_omap_select_slot(struct mmc_omap_slot
*slot
, int claimed
)
214 struct mmc_omap_host
*host
= slot
->host
;
219 spin_lock_irqsave(&host
->slot_lock
, flags
);
220 while (host
->mmc
!= NULL
) {
221 spin_unlock_irqrestore(&host
->slot_lock
, flags
);
222 wait_event(host
->slot_wq
, host
->mmc
== NULL
);
223 spin_lock_irqsave(&host
->slot_lock
, flags
);
225 host
->mmc
= slot
->mmc
;
226 spin_unlock_irqrestore(&host
->slot_lock
, flags
);
228 del_timer(&host
->clk_timer
);
229 if (host
->current_slot
!= slot
|| !claimed
)
230 mmc_omap_fclk_offdelay(host
->current_slot
);
232 if (host
->current_slot
!= slot
) {
233 OMAP_MMC_WRITE(host
, CON
, slot
->saved_con
& 0xFC00);
234 if (host
->pdata
->switch_slot
!= NULL
)
235 host
->pdata
->switch_slot(mmc_dev(slot
->mmc
), slot
->id
);
236 host
->current_slot
= slot
;
240 mmc_omap_fclk_enable(host
, 1);
242 /* Doing the dummy read here seems to work around some bug
243 * at least in OMAP24xx silicon where the command would not
244 * start after writing the CMD register. Sigh. */
245 OMAP_MMC_READ(host
, CON
);
247 OMAP_MMC_WRITE(host
, CON
, slot
->saved_con
);
249 mmc_omap_fclk_enable(host
, 0);
252 static void mmc_omap_start_request(struct mmc_omap_host
*host
,
253 struct mmc_request
*req
);
255 static void mmc_omap_slot_release_work(struct work_struct
*work
)
257 struct mmc_omap_host
*host
= container_of(work
, struct mmc_omap_host
,
259 struct mmc_omap_slot
*next_slot
= host
->next_slot
;
260 struct mmc_request
*rq
;
262 host
->next_slot
= NULL
;
263 mmc_omap_select_slot(next_slot
, 1);
266 next_slot
->mrq
= NULL
;
267 mmc_omap_start_request(host
, rq
);
270 static void mmc_omap_release_slot(struct mmc_omap_slot
*slot
, int clk_enabled
)
272 struct mmc_omap_host
*host
= slot
->host
;
276 BUG_ON(slot
== NULL
|| host
->mmc
== NULL
);
279 /* Keeps clock running for at least 8 cycles on valid freq */
280 mod_timer(&host
->clk_timer
, jiffies
+ HZ
/10);
282 del_timer(&host
->clk_timer
);
283 mmc_omap_fclk_offdelay(slot
);
284 mmc_omap_fclk_enable(host
, 0);
287 spin_lock_irqsave(&host
->slot_lock
, flags
);
288 /* Check for any pending requests */
289 for (i
= 0; i
< host
->nr_slots
; i
++) {
290 struct mmc_omap_slot
*new_slot
;
292 if (host
->slots
[i
] == NULL
|| host
->slots
[i
]->mrq
== NULL
)
295 BUG_ON(host
->next_slot
!= NULL
);
296 new_slot
= host
->slots
[i
];
297 /* The current slot should not have a request in queue */
298 BUG_ON(new_slot
== host
->current_slot
);
300 host
->next_slot
= new_slot
;
301 host
->mmc
= new_slot
->mmc
;
302 spin_unlock_irqrestore(&host
->slot_lock
, flags
);
303 queue_work(host
->mmc_omap_wq
, &host
->slot_release_work
);
308 wake_up(&host
->slot_wq
);
309 spin_unlock_irqrestore(&host
->slot_lock
, flags
);
313 int mmc_omap_cover_is_open(struct mmc_omap_slot
*slot
)
315 if (slot
->pdata
->get_cover_state
)
316 return slot
->pdata
->get_cover_state(mmc_dev(slot
->mmc
),
322 mmc_omap_show_cover_switch(struct device
*dev
, struct device_attribute
*attr
,
325 struct mmc_host
*mmc
= container_of(dev
, struct mmc_host
, class_dev
);
326 struct mmc_omap_slot
*slot
= mmc_priv(mmc
);
328 return sprintf(buf
, "%s\n", mmc_omap_cover_is_open(slot
) ? "open" :
332 static DEVICE_ATTR(cover_switch
, S_IRUGO
, mmc_omap_show_cover_switch
, NULL
);
335 mmc_omap_show_slot_name(struct device
*dev
, struct device_attribute
*attr
,
338 struct mmc_host
*mmc
= container_of(dev
, struct mmc_host
, class_dev
);
339 struct mmc_omap_slot
*slot
= mmc_priv(mmc
);
341 return sprintf(buf
, "%s\n", slot
->pdata
->name
);
344 static DEVICE_ATTR(slot_name
, S_IRUGO
, mmc_omap_show_slot_name
, NULL
);
347 mmc_omap_start_command(struct mmc_omap_host
*host
, struct mmc_command
*cmd
)
358 /* Our hardware needs to know exact type */
359 switch (mmc_resp_type(cmd
)) {
364 /* resp 1, 1b, 6, 7 */
374 dev_err(mmc_dev(host
->mmc
), "Invalid response type: %04x\n", mmc_resp_type(cmd
));
378 if (mmc_cmd_type(cmd
) == MMC_CMD_ADTC
) {
379 cmdtype
= OMAP_MMC_CMDTYPE_ADTC
;
380 } else if (mmc_cmd_type(cmd
) == MMC_CMD_BC
) {
381 cmdtype
= OMAP_MMC_CMDTYPE_BC
;
382 } else if (mmc_cmd_type(cmd
) == MMC_CMD_BCR
) {
383 cmdtype
= OMAP_MMC_CMDTYPE_BCR
;
385 cmdtype
= OMAP_MMC_CMDTYPE_AC
;
388 cmdreg
= cmd
->opcode
| (resptype
<< 8) | (cmdtype
<< 12);
390 if (host
->current_slot
->bus_mode
== MMC_BUSMODE_OPENDRAIN
)
393 if (cmd
->flags
& MMC_RSP_BUSY
)
396 if (host
->data
&& !(host
->data
->flags
& MMC_DATA_WRITE
))
399 mod_timer(&host
->cmd_abort_timer
, jiffies
+ HZ
/2);
401 OMAP_MMC_WRITE(host
, CTO
, 200);
402 OMAP_MMC_WRITE(host
, ARGL
, cmd
->arg
& 0xffff);
403 OMAP_MMC_WRITE(host
, ARGH
, cmd
->arg
>> 16);
404 OMAP_MMC_WRITE(host
, IE
,
405 OMAP_MMC_STAT_A_EMPTY
| OMAP_MMC_STAT_A_FULL
|
406 OMAP_MMC_STAT_CMD_CRC
| OMAP_MMC_STAT_CMD_TOUT
|
407 OMAP_MMC_STAT_DATA_CRC
| OMAP_MMC_STAT_DATA_TOUT
|
408 OMAP_MMC_STAT_END_OF_CMD
| OMAP_MMC_STAT_CARD_ERR
|
409 OMAP_MMC_STAT_END_OF_DATA
);
410 OMAP_MMC_WRITE(host
, CMD
, cmdreg
);
414 mmc_omap_release_dma(struct mmc_omap_host
*host
, struct mmc_data
*data
,
417 enum dma_data_direction dma_data_dir
;
418 struct device
*dev
= mmc_dev(host
->mmc
);
421 if (data
->flags
& MMC_DATA_WRITE
) {
422 dma_data_dir
= DMA_TO_DEVICE
;
425 dma_data_dir
= DMA_FROM_DEVICE
;
430 dmaengine_terminate_all(c
);
431 /* Claim nothing transferred on error... */
432 data
->bytes_xfered
= 0;
434 dev
= c
->device
->dev
;
436 dma_unmap_sg(dev
, data
->sg
, host
->sg_len
, dma_data_dir
);
439 static void mmc_omap_send_stop_work(struct work_struct
*work
)
441 struct mmc_omap_host
*host
= container_of(work
, struct mmc_omap_host
,
443 struct mmc_omap_slot
*slot
= host
->current_slot
;
444 struct mmc_data
*data
= host
->stop_data
;
445 unsigned long tick_ns
;
447 tick_ns
= (1000000000 + slot
->fclk_freq
- 1)/slot
->fclk_freq
;
450 mmc_omap_start_command(host
, data
->stop
);
454 mmc_omap_xfer_done(struct mmc_omap_host
*host
, struct mmc_data
*data
)
456 if (host
->dma_in_use
)
457 mmc_omap_release_dma(host
, data
, data
->error
);
462 /* NOTE: MMC layer will sometimes poll-wait CMD13 next, issuing
463 * dozens of requests until the card finishes writing data.
464 * It'd be cheaper to just wait till an EOFB interrupt arrives...
468 struct mmc_host
*mmc
;
472 mmc_omap_release_slot(host
->current_slot
, 1);
473 mmc_request_done(mmc
, data
->mrq
);
477 host
->stop_data
= data
;
478 queue_work(host
->mmc_omap_wq
, &host
->send_stop_work
);
482 mmc_omap_send_abort(struct mmc_omap_host
*host
, int maxloops
)
484 struct mmc_omap_slot
*slot
= host
->current_slot
;
485 unsigned int restarts
, passes
, timeout
;
488 /* Sending abort takes 80 clocks. Have some extra and round up */
489 timeout
= (120*1000000 + slot
->fclk_freq
- 1)/slot
->fclk_freq
;
491 while (restarts
< maxloops
) {
492 OMAP_MMC_WRITE(host
, STAT
, 0xFFFF);
493 OMAP_MMC_WRITE(host
, CMD
, (3 << 12) | (1 << 7));
496 while (passes
< timeout
) {
497 stat
= OMAP_MMC_READ(host
, STAT
);
498 if (stat
& OMAP_MMC_STAT_END_OF_CMD
)
507 OMAP_MMC_WRITE(host
, STAT
, stat
);
511 mmc_omap_abort_xfer(struct mmc_omap_host
*host
, struct mmc_data
*data
)
513 if (host
->dma_in_use
)
514 mmc_omap_release_dma(host
, data
, 1);
519 mmc_omap_send_abort(host
, 10000);
523 mmc_omap_end_of_data(struct mmc_omap_host
*host
, struct mmc_data
*data
)
528 if (!host
->dma_in_use
) {
529 mmc_omap_xfer_done(host
, data
);
533 spin_lock_irqsave(&host
->dma_lock
, flags
);
537 host
->brs_received
= 1;
538 spin_unlock_irqrestore(&host
->dma_lock
, flags
);
540 mmc_omap_xfer_done(host
, data
);
544 mmc_omap_dma_done(struct mmc_omap_host
*host
, struct mmc_data
*data
)
550 spin_lock_irqsave(&host
->dma_lock
, flags
);
551 if (host
->brs_received
)
555 spin_unlock_irqrestore(&host
->dma_lock
, flags
);
557 mmc_omap_xfer_done(host
, data
);
561 mmc_omap_cmd_done(struct mmc_omap_host
*host
, struct mmc_command
*cmd
)
565 del_timer(&host
->cmd_abort_timer
);
567 if (cmd
->flags
& MMC_RSP_PRESENT
) {
568 if (cmd
->flags
& MMC_RSP_136
) {
569 /* response type 2 */
571 OMAP_MMC_READ(host
, RSP0
) |
572 (OMAP_MMC_READ(host
, RSP1
) << 16);
574 OMAP_MMC_READ(host
, RSP2
) |
575 (OMAP_MMC_READ(host
, RSP3
) << 16);
577 OMAP_MMC_READ(host
, RSP4
) |
578 (OMAP_MMC_READ(host
, RSP5
) << 16);
580 OMAP_MMC_READ(host
, RSP6
) |
581 (OMAP_MMC_READ(host
, RSP7
) << 16);
583 /* response types 1, 1b, 3, 4, 5, 6 */
585 OMAP_MMC_READ(host
, RSP6
) |
586 (OMAP_MMC_READ(host
, RSP7
) << 16);
590 if (host
->data
== NULL
|| cmd
->error
) {
591 struct mmc_host
*mmc
;
593 if (host
->data
!= NULL
)
594 mmc_omap_abort_xfer(host
, host
->data
);
597 mmc_omap_release_slot(host
->current_slot
, 1);
598 mmc_request_done(mmc
, cmd
->mrq
);
603 * Abort stuck command. Can occur when card is removed while it is being
606 static void mmc_omap_abort_command(struct work_struct
*work
)
608 struct mmc_omap_host
*host
= container_of(work
, struct mmc_omap_host
,
612 dev_dbg(mmc_dev(host
->mmc
), "Aborting stuck command CMD%d\n",
615 if (host
->cmd
->error
== 0)
616 host
->cmd
->error
= -ETIMEDOUT
;
618 if (host
->data
== NULL
) {
619 struct mmc_command
*cmd
;
620 struct mmc_host
*mmc
;
624 mmc_omap_send_abort(host
, 10000);
628 mmc_omap_release_slot(host
->current_slot
, 1);
629 mmc_request_done(mmc
, cmd
->mrq
);
631 mmc_omap_cmd_done(host
, host
->cmd
);
634 enable_irq(host
->irq
);
638 mmc_omap_cmd_timer(unsigned long data
)
640 struct mmc_omap_host
*host
= (struct mmc_omap_host
*) data
;
643 spin_lock_irqsave(&host
->slot_lock
, flags
);
644 if (host
->cmd
!= NULL
&& !host
->abort
) {
645 OMAP_MMC_WRITE(host
, IE
, 0);
646 disable_irq(host
->irq
);
648 queue_work(host
->mmc_omap_wq
, &host
->cmd_abort_work
);
650 spin_unlock_irqrestore(&host
->slot_lock
, flags
);
655 mmc_omap_sg_to_buf(struct mmc_omap_host
*host
)
657 struct scatterlist
*sg
;
659 sg
= host
->data
->sg
+ host
->sg_idx
;
660 host
->buffer_bytes_left
= sg
->length
;
661 host
->buffer
= sg_virt(sg
);
662 if (host
->buffer_bytes_left
> host
->total_bytes_left
)
663 host
->buffer_bytes_left
= host
->total_bytes_left
;
667 mmc_omap_clk_timer(unsigned long data
)
669 struct mmc_omap_host
*host
= (struct mmc_omap_host
*) data
;
671 mmc_omap_fclk_enable(host
, 0);
676 mmc_omap_xfer_data(struct mmc_omap_host
*host
, int write
)
680 if (host
->buffer_bytes_left
== 0) {
682 BUG_ON(host
->sg_idx
== host
->sg_len
);
683 mmc_omap_sg_to_buf(host
);
686 if (n
> host
->buffer_bytes_left
)
687 n
= host
->buffer_bytes_left
;
690 nwords
+= n
& 1; /* handle odd number of bytes to transfer */
692 host
->buffer_bytes_left
-= n
;
693 host
->total_bytes_left
-= n
;
694 host
->data
->bytes_xfered
+= n
;
697 __raw_writesw(host
->virt_base
+ OMAP_MMC_REG(host
, DATA
),
698 host
->buffer
, nwords
);
700 __raw_readsw(host
->virt_base
+ OMAP_MMC_REG(host
, DATA
),
701 host
->buffer
, nwords
);
704 host
->buffer
+= nwords
;
707 #ifdef CONFIG_MMC_DEBUG
708 static void mmc_omap_report_irq(struct mmc_omap_host
*host
, u16 status
)
710 static const char *mmc_omap_status_bits
[] = {
711 "EOC", "CD", "CB", "BRS", "EOFB", "DTO", "DCRC", "CTO",
712 "CCRC", "CRW", "AF", "AE", "OCRB", "CIRQ", "CERR"
715 char res
[64], *buf
= res
;
717 buf
+= sprintf(buf
, "MMC IRQ 0x%x:", status
);
719 for (i
= 0; i
< ARRAY_SIZE(mmc_omap_status_bits
); i
++)
720 if (status
& (1 << i
))
721 buf
+= sprintf(buf
, " %s", mmc_omap_status_bits
[i
]);
722 dev_vdbg(mmc_dev(host
->mmc
), "%s\n", res
);
725 static void mmc_omap_report_irq(struct mmc_omap_host
*host
, u16 status
)
731 static irqreturn_t
mmc_omap_irq(int irq
, void *dev_id
)
733 struct mmc_omap_host
* host
= (struct mmc_omap_host
*)dev_id
;
737 int transfer_error
, cmd_error
;
739 if (host
->cmd
== NULL
&& host
->data
== NULL
) {
740 status
= OMAP_MMC_READ(host
, STAT
);
741 dev_info(mmc_dev(host
->slots
[0]->mmc
),
742 "Spurious IRQ 0x%04x\n", status
);
744 OMAP_MMC_WRITE(host
, STAT
, status
);
745 OMAP_MMC_WRITE(host
, IE
, 0);
755 while ((status
= OMAP_MMC_READ(host
, STAT
)) != 0) {
758 OMAP_MMC_WRITE(host
, STAT
, status
);
759 if (host
->cmd
!= NULL
)
760 cmd
= host
->cmd
->opcode
;
763 dev_dbg(mmc_dev(host
->mmc
), "MMC IRQ %04x (CMD %d): ",
765 mmc_omap_report_irq(host
, status
);
767 if (host
->total_bytes_left
) {
768 if ((status
& OMAP_MMC_STAT_A_FULL
) ||
769 (status
& OMAP_MMC_STAT_END_OF_DATA
))
770 mmc_omap_xfer_data(host
, 0);
771 if (status
& OMAP_MMC_STAT_A_EMPTY
)
772 mmc_omap_xfer_data(host
, 1);
775 if (status
& OMAP_MMC_STAT_END_OF_DATA
)
778 if (status
& OMAP_MMC_STAT_DATA_TOUT
) {
779 dev_dbg(mmc_dev(host
->mmc
), "data timeout (CMD%d)\n",
782 host
->data
->error
= -ETIMEDOUT
;
787 if (status
& OMAP_MMC_STAT_DATA_CRC
) {
789 host
->data
->error
= -EILSEQ
;
790 dev_dbg(mmc_dev(host
->mmc
),
791 "data CRC error, bytes left %d\n",
792 host
->total_bytes_left
);
795 dev_dbg(mmc_dev(host
->mmc
), "data CRC error\n");
799 if (status
& OMAP_MMC_STAT_CMD_TOUT
) {
800 /* Timeouts are routine with some commands */
802 struct mmc_omap_slot
*slot
=
805 !mmc_omap_cover_is_open(slot
))
806 dev_err(mmc_dev(host
->mmc
),
807 "command timeout (CMD%d)\n",
809 host
->cmd
->error
= -ETIMEDOUT
;
815 if (status
& OMAP_MMC_STAT_CMD_CRC
) {
817 dev_err(mmc_dev(host
->mmc
),
818 "command CRC error (CMD%d, arg 0x%08x)\n",
819 cmd
, host
->cmd
->arg
);
820 host
->cmd
->error
= -EILSEQ
;
824 dev_err(mmc_dev(host
->mmc
),
825 "command CRC error without cmd?\n");
828 if (status
& OMAP_MMC_STAT_CARD_ERR
) {
829 dev_dbg(mmc_dev(host
->mmc
),
830 "ignoring card status error (CMD%d)\n",
836 * NOTE: On 1610 the END_OF_CMD may come too early when
839 if ((status
& OMAP_MMC_STAT_END_OF_CMD
) &&
840 (!(status
& OMAP_MMC_STAT_A_EMPTY
))) {
845 if (cmd_error
&& host
->data
) {
846 del_timer(&host
->cmd_abort_timer
);
848 OMAP_MMC_WRITE(host
, IE
, 0);
849 disable_irq_nosync(host
->irq
);
850 queue_work(host
->mmc_omap_wq
, &host
->cmd_abort_work
);
854 if (end_command
&& host
->cmd
)
855 mmc_omap_cmd_done(host
, host
->cmd
);
856 if (host
->data
!= NULL
) {
858 mmc_omap_xfer_done(host
, host
->data
);
859 else if (end_transfer
)
860 mmc_omap_end_of_data(host
, host
->data
);
866 void omap_mmc_notify_cover_event(struct device
*dev
, int num
, int is_closed
)
869 struct mmc_omap_host
*host
= dev_get_drvdata(dev
);
870 struct mmc_omap_slot
*slot
= host
->slots
[num
];
872 BUG_ON(num
>= host
->nr_slots
);
874 /* Other subsystems can call in here before we're initialised. */
875 if (host
->nr_slots
== 0 || !host
->slots
[num
])
878 cover_open
= mmc_omap_cover_is_open(slot
);
879 if (cover_open
!= slot
->cover_open
) {
880 slot
->cover_open
= cover_open
;
881 sysfs_notify(&slot
->mmc
->class_dev
.kobj
, NULL
, "cover_switch");
884 tasklet_hi_schedule(&slot
->cover_tasklet
);
887 static void mmc_omap_cover_timer(unsigned long arg
)
889 struct mmc_omap_slot
*slot
= (struct mmc_omap_slot
*) arg
;
890 tasklet_schedule(&slot
->cover_tasklet
);
893 static void mmc_omap_cover_handler(unsigned long param
)
895 struct mmc_omap_slot
*slot
= (struct mmc_omap_slot
*)param
;
896 int cover_open
= mmc_omap_cover_is_open(slot
);
898 mmc_detect_change(slot
->mmc
, 0);
903 * If no card is inserted, we postpone polling until
904 * the cover has been closed.
906 if (slot
->mmc
->card
== NULL
|| !mmc_card_present(slot
->mmc
->card
))
909 mod_timer(&slot
->cover_timer
,
910 jiffies
+ msecs_to_jiffies(OMAP_MMC_COVER_POLL_DELAY
));
913 static void mmc_omap_dma_callback(void *priv
)
915 struct mmc_omap_host
*host
= priv
;
916 struct mmc_data
*data
= host
->data
;
918 /* If we got to the end of DMA, assume everything went well */
919 data
->bytes_xfered
+= data
->blocks
* data
->blksz
;
921 mmc_omap_dma_done(host
, data
);
924 static inline void set_cmd_timeout(struct mmc_omap_host
*host
, struct mmc_request
*req
)
928 reg
= OMAP_MMC_READ(host
, SDIO
);
930 OMAP_MMC_WRITE(host
, SDIO
, reg
);
931 /* Set maximum timeout */
932 OMAP_MMC_WRITE(host
, CTO
, 0xff);
935 static inline void set_data_timeout(struct mmc_omap_host
*host
, struct mmc_request
*req
)
937 unsigned int timeout
, cycle_ns
;
940 cycle_ns
= 1000000000 / host
->current_slot
->fclk_freq
;
941 timeout
= req
->data
->timeout_ns
/ cycle_ns
;
942 timeout
+= req
->data
->timeout_clks
;
944 /* Check if we need to use timeout multiplier register */
945 reg
= OMAP_MMC_READ(host
, SDIO
);
946 if (timeout
> 0xffff) {
951 OMAP_MMC_WRITE(host
, SDIO
, reg
);
952 OMAP_MMC_WRITE(host
, DTO
, timeout
);
956 mmc_omap_prepare_data(struct mmc_omap_host
*host
, struct mmc_request
*req
)
958 struct mmc_data
*data
= req
->data
;
959 int i
, use_dma
, block_size
;
964 OMAP_MMC_WRITE(host
, BLEN
, 0);
965 OMAP_MMC_WRITE(host
, NBLK
, 0);
966 OMAP_MMC_WRITE(host
, BUF
, 0);
967 host
->dma_in_use
= 0;
968 set_cmd_timeout(host
, req
);
972 block_size
= data
->blksz
;
974 OMAP_MMC_WRITE(host
, NBLK
, data
->blocks
- 1);
975 OMAP_MMC_WRITE(host
, BLEN
, block_size
- 1);
976 set_data_timeout(host
, req
);
978 /* cope with calling layer confusion; it issues "single
979 * block" writes using multi-block scatterlists.
981 sg_len
= (data
->blocks
== 1) ? 1 : data
->sg_len
;
983 /* Only do DMA for entire blocks */
984 use_dma
= host
->use_dma
;
986 for (i
= 0; i
< sg_len
; i
++) {
987 if ((data
->sg
[i
].length
% block_size
) != 0) {
996 enum dma_data_direction dma_data_dir
;
997 struct dma_async_tx_descriptor
*tx
;
1003 * FIFO is 16x2 bytes on 15xx, and 32x2 bytes on 16xx
1004 * and 24xx. Use 16 or 32 word frames when the
1005 * blocksize is at least that large. Blocksize is
1006 * usually 512 bytes; but not for some SD reads.
1008 burst
= mmc_omap15xx() ? 32 : 64;
1009 if (burst
> data
->blksz
)
1010 burst
= data
->blksz
;
1014 if (data
->flags
& MMC_DATA_WRITE
) {
1016 bp
= &host
->dma_tx_burst
;
1017 buf
= 0x0f80 | (burst
- 1) << 0;
1018 dma_data_dir
= DMA_TO_DEVICE
;
1021 bp
= &host
->dma_rx_burst
;
1022 buf
= 0x800f | (burst
- 1) << 8;
1023 dma_data_dir
= DMA_FROM_DEVICE
;
1029 /* Only reconfigure if we have a different burst size */
1031 struct dma_slave_config cfg
;
1033 cfg
.src_addr
= host
->phys_base
+ OMAP_MMC_REG(host
, DATA
);
1034 cfg
.dst_addr
= host
->phys_base
+ OMAP_MMC_REG(host
, DATA
);
1035 cfg
.src_addr_width
= DMA_SLAVE_BUSWIDTH_2_BYTES
;
1036 cfg
.dst_addr_width
= DMA_SLAVE_BUSWIDTH_2_BYTES
;
1037 cfg
.src_maxburst
= burst
;
1038 cfg
.dst_maxburst
= burst
;
1040 if (dmaengine_slave_config(c
, &cfg
))
1046 host
->sg_len
= dma_map_sg(c
->device
->dev
, data
->sg
, sg_len
,
1048 if (host
->sg_len
== 0)
1051 tx
= dmaengine_prep_slave_sg(c
, data
->sg
, host
->sg_len
,
1052 data
->flags
& MMC_DATA_WRITE
? DMA_MEM_TO_DEV
: DMA_DEV_TO_MEM
,
1053 DMA_PREP_INTERRUPT
| DMA_CTRL_ACK
);
1057 OMAP_MMC_WRITE(host
, BUF
, buf
);
1059 tx
->callback
= mmc_omap_dma_callback
;
1060 tx
->callback_param
= host
;
1061 dmaengine_submit(tx
);
1062 host
->brs_received
= 0;
1064 host
->dma_in_use
= 1;
1069 /* Revert to PIO? */
1070 OMAP_MMC_WRITE(host
, BUF
, 0x1f1f);
1071 host
->total_bytes_left
= data
->blocks
* block_size
;
1072 host
->sg_len
= sg_len
;
1073 mmc_omap_sg_to_buf(host
);
1074 host
->dma_in_use
= 0;
1077 static void mmc_omap_start_request(struct mmc_omap_host
*host
,
1078 struct mmc_request
*req
)
1080 BUG_ON(host
->mrq
!= NULL
);
1084 /* only touch fifo AFTER the controller readies it */
1085 mmc_omap_prepare_data(host
, req
);
1086 mmc_omap_start_command(host
, req
->cmd
);
1087 if (host
->dma_in_use
) {
1088 struct dma_chan
*c
= host
->data
->flags
& MMC_DATA_WRITE
?
1089 host
->dma_tx
: host
->dma_rx
;
1091 dma_async_issue_pending(c
);
1095 static void mmc_omap_request(struct mmc_host
*mmc
, struct mmc_request
*req
)
1097 struct mmc_omap_slot
*slot
= mmc_priv(mmc
);
1098 struct mmc_omap_host
*host
= slot
->host
;
1099 unsigned long flags
;
1101 spin_lock_irqsave(&host
->slot_lock
, flags
);
1102 if (host
->mmc
!= NULL
) {
1103 BUG_ON(slot
->mrq
!= NULL
);
1105 spin_unlock_irqrestore(&host
->slot_lock
, flags
);
1109 spin_unlock_irqrestore(&host
->slot_lock
, flags
);
1110 mmc_omap_select_slot(slot
, 1);
1111 mmc_omap_start_request(host
, req
);
1114 static void mmc_omap_set_power(struct mmc_omap_slot
*slot
, int power_on
,
1117 struct mmc_omap_host
*host
;
1121 if (slot
->pdata
->set_power
!= NULL
)
1122 slot
->pdata
->set_power(mmc_dev(slot
->mmc
), slot
->id
, power_on
,
1128 w
= OMAP_MMC_READ(host
, CON
);
1129 OMAP_MMC_WRITE(host
, CON
, w
| (1 << 11));
1131 w
= OMAP_MMC_READ(host
, CON
);
1132 OMAP_MMC_WRITE(host
, CON
, w
& ~(1 << 11));
1137 static int mmc_omap_calc_divisor(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
1139 struct mmc_omap_slot
*slot
= mmc_priv(mmc
);
1140 struct mmc_omap_host
*host
= slot
->host
;
1141 int func_clk_rate
= clk_get_rate(host
->fclk
);
1144 if (ios
->clock
== 0)
1147 dsor
= func_clk_rate
/ ios
->clock
;
1151 if (func_clk_rate
/ dsor
> ios
->clock
)
1157 slot
->fclk_freq
= func_clk_rate
/ dsor
;
1159 if (ios
->bus_width
== MMC_BUS_WIDTH_4
)
1165 static void mmc_omap_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
1167 struct mmc_omap_slot
*slot
= mmc_priv(mmc
);
1168 struct mmc_omap_host
*host
= slot
->host
;
1172 mmc_omap_select_slot(slot
, 0);
1174 dsor
= mmc_omap_calc_divisor(mmc
, ios
);
1176 if (ios
->vdd
!= slot
->vdd
)
1177 slot
->vdd
= ios
->vdd
;
1180 switch (ios
->power_mode
) {
1182 mmc_omap_set_power(slot
, 0, ios
->vdd
);
1185 /* Cannot touch dsor yet, just power up MMC */
1186 mmc_omap_set_power(slot
, 1, ios
->vdd
);
1189 mmc_omap_fclk_enable(host
, 1);
1195 if (slot
->bus_mode
!= ios
->bus_mode
) {
1196 if (slot
->pdata
->set_bus_mode
!= NULL
)
1197 slot
->pdata
->set_bus_mode(mmc_dev(mmc
), slot
->id
,
1199 slot
->bus_mode
= ios
->bus_mode
;
1202 /* On insanely high arm_per frequencies something sometimes
1203 * goes somehow out of sync, and the POW bit is not being set,
1204 * which results in the while loop below getting stuck.
1205 * Writing to the CON register twice seems to do the trick. */
1206 for (i
= 0; i
< 2; i
++)
1207 OMAP_MMC_WRITE(host
, CON
, dsor
);
1208 slot
->saved_con
= dsor
;
1209 if (ios
->power_mode
== MMC_POWER_ON
) {
1210 /* worst case at 400kHz, 80 cycles makes 200 microsecs */
1213 /* Send clock cycles, poll completion */
1214 OMAP_MMC_WRITE(host
, IE
, 0);
1215 OMAP_MMC_WRITE(host
, STAT
, 0xffff);
1216 OMAP_MMC_WRITE(host
, CMD
, 1 << 7);
1217 while (usecs
> 0 && (OMAP_MMC_READ(host
, STAT
) & 1) == 0) {
1221 OMAP_MMC_WRITE(host
, STAT
, 1);
1225 mmc_omap_release_slot(slot
, clk_enabled
);
1228 static const struct mmc_host_ops mmc_omap_ops
= {
1229 .request
= mmc_omap_request
,
1230 .set_ios
= mmc_omap_set_ios
,
1233 static int mmc_omap_new_slot(struct mmc_omap_host
*host
, int id
)
1235 struct mmc_omap_slot
*slot
= NULL
;
1236 struct mmc_host
*mmc
;
1239 mmc
= mmc_alloc_host(sizeof(struct mmc_omap_slot
), host
->dev
);
1243 slot
= mmc_priv(mmc
);
1247 slot
->pdata
= &host
->pdata
->slots
[id
];
1249 host
->slots
[id
] = slot
;
1252 if (host
->pdata
->slots
[id
].wires
>= 4)
1253 mmc
->caps
|= MMC_CAP_4_BIT_DATA
;
1255 mmc
->ops
= &mmc_omap_ops
;
1256 mmc
->f_min
= 400000;
1259 mmc
->f_max
= 48000000;
1261 mmc
->f_max
= 24000000;
1262 if (host
->pdata
->max_freq
)
1263 mmc
->f_max
= min(host
->pdata
->max_freq
, mmc
->f_max
);
1264 mmc
->ocr_avail
= slot
->pdata
->ocr_mask
;
1266 /* Use scatterlist DMA to reduce per-transfer costs.
1267 * NOTE max_seg_size assumption that small blocks aren't
1268 * normally used (except e.g. for reading SD registers).
1271 mmc
->max_blk_size
= 2048; /* BLEN is 11 bits (+1) */
1272 mmc
->max_blk_count
= 2048; /* NBLK is 11 bits (+1) */
1273 mmc
->max_req_size
= mmc
->max_blk_size
* mmc
->max_blk_count
;
1274 mmc
->max_seg_size
= mmc
->max_req_size
;
1276 r
= mmc_add_host(mmc
);
1278 goto err_remove_host
;
1280 if (slot
->pdata
->name
!= NULL
) {
1281 r
= device_create_file(&mmc
->class_dev
,
1282 &dev_attr_slot_name
);
1284 goto err_remove_host
;
1287 if (slot
->pdata
->get_cover_state
!= NULL
) {
1288 r
= device_create_file(&mmc
->class_dev
,
1289 &dev_attr_cover_switch
);
1291 goto err_remove_slot_name
;
1293 setup_timer(&slot
->cover_timer
, mmc_omap_cover_timer
,
1294 (unsigned long)slot
);
1295 tasklet_init(&slot
->cover_tasklet
, mmc_omap_cover_handler
,
1296 (unsigned long)slot
);
1297 tasklet_schedule(&slot
->cover_tasklet
);
1302 err_remove_slot_name
:
1303 if (slot
->pdata
->name
!= NULL
)
1304 device_remove_file(&mmc
->class_dev
, &dev_attr_slot_name
);
1306 mmc_remove_host(mmc
);
1311 static void mmc_omap_remove_slot(struct mmc_omap_slot
*slot
)
1313 struct mmc_host
*mmc
= slot
->mmc
;
1315 if (slot
->pdata
->name
!= NULL
)
1316 device_remove_file(&mmc
->class_dev
, &dev_attr_slot_name
);
1317 if (slot
->pdata
->get_cover_state
!= NULL
)
1318 device_remove_file(&mmc
->class_dev
, &dev_attr_cover_switch
);
1320 tasklet_kill(&slot
->cover_tasklet
);
1321 del_timer_sync(&slot
->cover_timer
);
1322 flush_workqueue(slot
->host
->mmc_omap_wq
);
1324 mmc_remove_host(mmc
);
1328 static int mmc_omap_probe(struct platform_device
*pdev
)
1330 struct omap_mmc_platform_data
*pdata
= pdev
->dev
.platform_data
;
1331 struct mmc_omap_host
*host
= NULL
;
1332 struct resource
*res
;
1333 dma_cap_mask_t mask
;
1338 if (pdata
== NULL
) {
1339 dev_err(&pdev
->dev
, "platform data missing\n");
1342 if (pdata
->nr_slots
== 0) {
1343 dev_err(&pdev
->dev
, "no slots\n");
1347 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1348 irq
= platform_get_irq(pdev
, 0);
1349 if (res
== NULL
|| irq
< 0)
1352 res
= request_mem_region(res
->start
, resource_size(res
),
1357 host
= kzalloc(sizeof(struct mmc_omap_host
), GFP_KERNEL
);
1360 goto err_free_mem_region
;
1363 INIT_WORK(&host
->slot_release_work
, mmc_omap_slot_release_work
);
1364 INIT_WORK(&host
->send_stop_work
, mmc_omap_send_stop_work
);
1366 INIT_WORK(&host
->cmd_abort_work
, mmc_omap_abort_command
);
1367 setup_timer(&host
->cmd_abort_timer
, mmc_omap_cmd_timer
,
1368 (unsigned long) host
);
1370 spin_lock_init(&host
->clk_lock
);
1371 setup_timer(&host
->clk_timer
, mmc_omap_clk_timer
, (unsigned long) host
);
1373 spin_lock_init(&host
->dma_lock
);
1374 spin_lock_init(&host
->slot_lock
);
1375 init_waitqueue_head(&host
->slot_wq
);
1377 host
->pdata
= pdata
;
1378 host
->features
= host
->pdata
->slots
[0].features
;
1379 host
->dev
= &pdev
->dev
;
1380 platform_set_drvdata(pdev
, host
);
1382 host
->id
= pdev
->id
;
1383 host
->mem_res
= res
;
1387 host
->phys_base
= host
->mem_res
->start
;
1388 host
->virt_base
= ioremap(res
->start
, resource_size(res
));
1389 if (!host
->virt_base
)
1392 host
->iclk
= clk_get(&pdev
->dev
, "ick");
1393 if (IS_ERR(host
->iclk
)) {
1394 ret
= PTR_ERR(host
->iclk
);
1395 goto err_free_mmc_host
;
1397 clk_enable(host
->iclk
);
1399 host
->fclk
= clk_get(&pdev
->dev
, "fck");
1400 if (IS_ERR(host
->fclk
)) {
1401 ret
= PTR_ERR(host
->fclk
);
1406 dma_cap_set(DMA_SLAVE
, mask
);
1408 host
->dma_tx_burst
= -1;
1409 host
->dma_rx_burst
= -1;
1412 sig
= host
->id
== 0 ? OMAP24XX_DMA_MMC1_TX
: OMAP24XX_DMA_MMC2_TX
;
1414 sig
= host
->id
== 0 ? OMAP_DMA_MMC_TX
: OMAP_DMA_MMC2_TX
;
1415 host
->dma_tx
= dma_request_channel(mask
, omap_dma_filter_fn
, &sig
);
1417 dev_warn(host
->dev
, "unable to obtain TX DMA engine channel %u\n",
1420 sig
= host
->id
== 0 ? OMAP24XX_DMA_MMC1_RX
: OMAP24XX_DMA_MMC2_RX
;
1422 sig
= host
->id
== 0 ? OMAP_DMA_MMC_RX
: OMAP_DMA_MMC2_RX
;
1423 host
->dma_rx
= dma_request_channel(mask
, omap_dma_filter_fn
, &sig
);
1425 dev_warn(host
->dev
, "unable to obtain RX DMA engine channel %u\n",
1428 ret
= request_irq(host
->irq
, mmc_omap_irq
, 0, DRIVER_NAME
, host
);
1432 if (pdata
->init
!= NULL
) {
1433 ret
= pdata
->init(&pdev
->dev
);
1438 host
->nr_slots
= pdata
->nr_slots
;
1439 host
->reg_shift
= (mmc_omap7xx() ? 1 : 2);
1441 host
->mmc_omap_wq
= alloc_workqueue("mmc_omap", 0, 0);
1442 if (!host
->mmc_omap_wq
)
1443 goto err_plat_cleanup
;
1445 for (i
= 0; i
< pdata
->nr_slots
; i
++) {
1446 ret
= mmc_omap_new_slot(host
, i
);
1449 mmc_omap_remove_slot(host
->slots
[i
]);
1451 goto err_destroy_wq
;
1458 destroy_workqueue(host
->mmc_omap_wq
);
1461 pdata
->cleanup(&pdev
->dev
);
1463 free_irq(host
->irq
, host
);
1466 dma_release_channel(host
->dma_tx
);
1468 dma_release_channel(host
->dma_rx
);
1469 clk_put(host
->fclk
);
1471 clk_disable(host
->iclk
);
1472 clk_put(host
->iclk
);
1474 iounmap(host
->virt_base
);
1477 err_free_mem_region
:
1478 release_mem_region(res
->start
, resource_size(res
));
1482 static int mmc_omap_remove(struct platform_device
*pdev
)
1484 struct mmc_omap_host
*host
= platform_get_drvdata(pdev
);
1487 BUG_ON(host
== NULL
);
1489 for (i
= 0; i
< host
->nr_slots
; i
++)
1490 mmc_omap_remove_slot(host
->slots
[i
]);
1492 if (host
->pdata
->cleanup
)
1493 host
->pdata
->cleanup(&pdev
->dev
);
1495 mmc_omap_fclk_enable(host
, 0);
1496 free_irq(host
->irq
, host
);
1497 clk_put(host
->fclk
);
1498 clk_disable(host
->iclk
);
1499 clk_put(host
->iclk
);
1502 dma_release_channel(host
->dma_tx
);
1504 dma_release_channel(host
->dma_rx
);
1506 iounmap(host
->virt_base
);
1507 release_mem_region(pdev
->resource
[0].start
,
1508 pdev
->resource
[0].end
- pdev
->resource
[0].start
+ 1);
1509 destroy_workqueue(host
->mmc_omap_wq
);
1517 static int mmc_omap_suspend(struct platform_device
*pdev
, pm_message_t mesg
)
1520 struct mmc_omap_host
*host
= platform_get_drvdata(pdev
);
1522 if (host
== NULL
|| host
->suspended
)
1525 for (i
= 0; i
< host
->nr_slots
; i
++) {
1526 struct mmc_omap_slot
*slot
;
1528 slot
= host
->slots
[i
];
1529 ret
= mmc_suspend_host(slot
->mmc
);
1532 slot
= host
->slots
[i
];
1533 mmc_resume_host(slot
->mmc
);
1538 host
->suspended
= 1;
1542 static int mmc_omap_resume(struct platform_device
*pdev
)
1545 struct mmc_omap_host
*host
= platform_get_drvdata(pdev
);
1547 if (host
== NULL
|| !host
->suspended
)
1550 for (i
= 0; i
< host
->nr_slots
; i
++) {
1551 struct mmc_omap_slot
*slot
;
1552 slot
= host
->slots
[i
];
1553 ret
= mmc_resume_host(slot
->mmc
);
1557 host
->suspended
= 0;
1562 #define mmc_omap_suspend NULL
1563 #define mmc_omap_resume NULL
1566 static struct platform_driver mmc_omap_driver
= {
1567 .probe
= mmc_omap_probe
,
1568 .remove
= mmc_omap_remove
,
1569 .suspend
= mmc_omap_suspend
,
1570 .resume
= mmc_omap_resume
,
1572 .name
= DRIVER_NAME
,
1573 .owner
= THIS_MODULE
,
1577 module_platform_driver(mmc_omap_driver
);
1578 MODULE_DESCRIPTION("OMAP Multimedia Card driver");
1579 MODULE_LICENSE("GPL");
1580 MODULE_ALIAS("platform:" DRIVER_NAME
);
1581 MODULE_AUTHOR("Juha Yrjölä");