2 * Atmel MultiMedia Card Interface driver
4 * Copyright (C) 2004-2008 Atmel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/blkdev.h>
11 #include <linux/clk.h>
12 #include <linux/debugfs.h>
13 #include <linux/device.h>
14 #include <linux/dmaengine.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/err.h>
17 #include <linux/gpio.h>
18 #include <linux/init.h>
19 #include <linux/interrupt.h>
20 #include <linux/ioport.h>
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <linux/scatterlist.h>
24 #include <linux/seq_file.h>
25 #include <linux/slab.h>
26 #include <linux/stat.h>
27 #include <linux/types.h>
29 #include <linux/mmc/host.h>
30 #include <linux/mmc/sdio.h>
32 #include <mach/atmel-mci.h>
33 #include <linux/atmel-mci.h>
34 #include <linux/atmel_pdc.h>
37 #include <asm/unaligned.h>
40 #include <mach/board.h>
42 #include "atmel-mci-regs.h"
44 #define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE)
45 #define ATMCI_DMA_THRESHOLD 16
48 EVENT_CMD_COMPLETE
= 0,
54 enum atmel_mci_state
{
73 struct atmel_mci_caps
{
83 struct atmel_mci_dma
{
84 struct dma_chan
*chan
;
85 struct dma_async_tx_descriptor
*data_desc
;
89 * struct atmel_mci - MMC controller state shared between all slots
90 * @lock: Spinlock protecting the queue and associated data.
91 * @regs: Pointer to MMIO registers.
92 * @sg: Scatterlist entry currently being processed by PIO or PDC code.
93 * @pio_offset: Offset into the current scatterlist entry.
94 * @cur_slot: The slot which is currently using the controller.
95 * @mrq: The request currently being processed on @cur_slot,
96 * or NULL if the controller is idle.
97 * @cmd: The command currently being sent to the card, or NULL.
98 * @data: The data currently being transferred, or NULL if no data
99 * transfer is in progress.
100 * @data_size: just data->blocks * data->blksz.
101 * @dma: DMA client state.
102 * @data_chan: DMA channel being used for the current data transfer.
103 * @cmd_status: Snapshot of SR taken upon completion of the current
104 * command. Only valid when EVENT_CMD_COMPLETE is pending.
105 * @data_status: Snapshot of SR taken upon completion of the current
106 * data transfer. Only valid when EVENT_DATA_COMPLETE or
107 * EVENT_DATA_ERROR is pending.
108 * @stop_cmdr: Value to be loaded into CMDR when the stop command is
110 * @tasklet: Tasklet running the request state machine.
111 * @pending_events: Bitmask of events flagged by the interrupt handler
112 * to be processed by the tasklet.
113 * @completed_events: Bitmask of events which the state machine has
115 * @state: Tasklet state.
116 * @queue: List of slots waiting for access to the controller.
117 * @need_clock_update: Update the clock rate before the next request.
118 * @need_reset: Reset controller before next request.
119 * @mode_reg: Value of the MR register.
120 * @cfg_reg: Value of the CFG register.
121 * @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus
122 * rate and timeout calculations.
123 * @mapbase: Physical address of the MMIO registers.
124 * @mck: The peripheral bus clock hooked up to the MMC controller.
125 * @pdev: Platform device associated with the MMC controller.
126 * @slot: Slots sharing this MMC controller.
127 * @caps: MCI capabilities depending on MCI version.
128 * @prepare_data: function to setup MCI before data transfer which
129 * depends on MCI capabilities.
130 * @submit_data: function to start data transfer which depends on MCI
132 * @stop_transfer: function to stop data transfer which depends on MCI
138 * @lock is a softirq-safe spinlock protecting @queue as well as
139 * @cur_slot, @mrq and @state. These must always be updated
140 * at the same time while holding @lock.
142 * @lock also protects mode_reg and need_clock_update since these are
143 * used to synchronize mode register updates with the queue
146 * The @mrq field of struct atmel_mci_slot is also protected by @lock,
147 * and must always be written at the same time as the slot is added to
150 * @pending_events and @completed_events are accessed using atomic bit
151 * operations, so they don't need any locking.
153 * None of the fields touched by the interrupt handler need any
154 * locking. However, ordering is important: Before EVENT_DATA_ERROR or
155 * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
156 * interrupts must be disabled and @data_status updated with a
157 * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
158 * CMDRDY interrupt must be disabled and @cmd_status updated with a
159 * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
160 * bytes_xfered field of @data must be written. This is ensured by
167 struct scatterlist
*sg
;
169 unsigned int pio_offset
;
171 struct atmel_mci_slot
*cur_slot
;
172 struct mmc_request
*mrq
;
173 struct mmc_command
*cmd
;
174 struct mmc_data
*data
;
175 unsigned int data_size
;
177 struct atmel_mci_dma dma
;
178 struct dma_chan
*data_chan
;
179 struct dma_slave_config dma_conf
;
185 struct tasklet_struct tasklet
;
186 unsigned long pending_events
;
187 unsigned long completed_events
;
188 enum atmel_mci_state state
;
189 struct list_head queue
;
191 bool need_clock_update
;
195 unsigned long bus_hz
;
196 unsigned long mapbase
;
198 struct platform_device
*pdev
;
200 struct atmel_mci_slot
*slot
[ATMCI_MAX_NR_SLOTS
];
202 struct atmel_mci_caps caps
;
204 u32 (*prepare_data
)(struct atmel_mci
*host
, struct mmc_data
*data
);
205 void (*submit_data
)(struct atmel_mci
*host
, struct mmc_data
*data
);
206 void (*stop_transfer
)(struct atmel_mci
*host
);
210 * struct atmel_mci_slot - MMC slot state
211 * @mmc: The mmc_host representing this slot.
212 * @host: The MMC controller this slot is using.
213 * @sdc_reg: Value of SDCR to be written before using this slot.
214 * @sdio_irq: SDIO irq mask for this slot.
215 * @mrq: mmc_request currently being processed or waiting to be
216 * processed, or NULL when the slot is idle.
217 * @queue_node: List node for placing this node in the @queue list of
219 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
220 * @flags: Random state bits associated with the slot.
221 * @detect_pin: GPIO pin used for card detection, or negative if not
223 * @wp_pin: GPIO pin used for card write protect sending, or negative
225 * @detect_is_active_high: The state of the detect pin when it is active.
226 * @detect_timer: Timer used for debouncing @detect_pin interrupts.
228 struct atmel_mci_slot
{
229 struct mmc_host
*mmc
;
230 struct atmel_mci
*host
;
235 struct mmc_request
*mrq
;
236 struct list_head queue_node
;
240 #define ATMCI_CARD_PRESENT 0
241 #define ATMCI_CARD_NEED_INIT 1
242 #define ATMCI_SHUTDOWN 2
243 #define ATMCI_SUSPENDED 3
247 bool detect_is_active_high
;
249 struct timer_list detect_timer
;
252 #define atmci_test_and_clear_pending(host, event) \
253 test_and_clear_bit(event, &host->pending_events)
254 #define atmci_set_completed(host, event) \
255 set_bit(event, &host->completed_events)
256 #define atmci_set_pending(host, event) \
257 set_bit(event, &host->pending_events)
260 * The debugfs stuff below is mostly optimized away when
261 * CONFIG_DEBUG_FS is not set.
263 static int atmci_req_show(struct seq_file
*s
, void *v
)
265 struct atmel_mci_slot
*slot
= s
->private;
266 struct mmc_request
*mrq
;
267 struct mmc_command
*cmd
;
268 struct mmc_command
*stop
;
269 struct mmc_data
*data
;
271 /* Make sure we get a consistent snapshot */
272 spin_lock_bh(&slot
->host
->lock
);
282 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
283 cmd
->opcode
, cmd
->arg
, cmd
->flags
,
284 cmd
->resp
[0], cmd
->resp
[1], cmd
->resp
[2],
285 cmd
->resp
[3], cmd
->error
);
287 seq_printf(s
, "DATA %u / %u * %u flg %x err %d\n",
288 data
->bytes_xfered
, data
->blocks
,
289 data
->blksz
, data
->flags
, data
->error
);
292 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
293 stop
->opcode
, stop
->arg
, stop
->flags
,
294 stop
->resp
[0], stop
->resp
[1], stop
->resp
[2],
295 stop
->resp
[3], stop
->error
);
298 spin_unlock_bh(&slot
->host
->lock
);
303 static int atmci_req_open(struct inode
*inode
, struct file
*file
)
305 return single_open(file
, atmci_req_show
, inode
->i_private
);
308 static const struct file_operations atmci_req_fops
= {
309 .owner
= THIS_MODULE
,
310 .open
= atmci_req_open
,
313 .release
= single_release
,
316 static void atmci_show_status_reg(struct seq_file
*s
,
317 const char *regname
, u32 value
)
319 static const char *sr_bit
[] = {
350 seq_printf(s
, "%s:\t0x%08x", regname
, value
);
351 for (i
= 0; i
< ARRAY_SIZE(sr_bit
); i
++) {
352 if (value
& (1 << i
)) {
354 seq_printf(s
, " %s", sr_bit
[i
]);
356 seq_puts(s
, " UNKNOWN");
362 static int atmci_regs_show(struct seq_file
*s
, void *v
)
364 struct atmel_mci
*host
= s
->private;
367 buf
= kmalloc(ATMCI_REGS_SIZE
, GFP_KERNEL
);
372 * Grab a more or less consistent snapshot. Note that we're
373 * not disabling interrupts, so IMR and SR may not be
376 spin_lock_bh(&host
->lock
);
377 clk_enable(host
->mck
);
378 memcpy_fromio(buf
, host
->regs
, ATMCI_REGS_SIZE
);
379 clk_disable(host
->mck
);
380 spin_unlock_bh(&host
->lock
);
382 seq_printf(s
, "MR:\t0x%08x%s%s CLKDIV=%u\n",
384 buf
[ATMCI_MR
/ 4] & ATMCI_MR_RDPROOF
? " RDPROOF" : "",
385 buf
[ATMCI_MR
/ 4] & ATMCI_MR_WRPROOF
? " WRPROOF" : "",
386 buf
[ATMCI_MR
/ 4] & 0xff);
387 seq_printf(s
, "DTOR:\t0x%08x\n", buf
[ATMCI_DTOR
/ 4]);
388 seq_printf(s
, "SDCR:\t0x%08x\n", buf
[ATMCI_SDCR
/ 4]);
389 seq_printf(s
, "ARGR:\t0x%08x\n", buf
[ATMCI_ARGR
/ 4]);
390 seq_printf(s
, "BLKR:\t0x%08x BCNT=%u BLKLEN=%u\n",
392 buf
[ATMCI_BLKR
/ 4] & 0xffff,
393 (buf
[ATMCI_BLKR
/ 4] >> 16) & 0xffff);
394 if (host
->caps
.has_cstor_reg
)
395 seq_printf(s
, "CSTOR:\t0x%08x\n", buf
[ATMCI_CSTOR
/ 4]);
397 /* Don't read RSPR and RDR; it will consume the data there */
399 atmci_show_status_reg(s
, "SR", buf
[ATMCI_SR
/ 4]);
400 atmci_show_status_reg(s
, "IMR", buf
[ATMCI_IMR
/ 4]);
402 if (host
->caps
.has_dma
) {
405 val
= buf
[ATMCI_DMA
/ 4];
406 seq_printf(s
, "DMA:\t0x%08x OFFSET=%u CHKSIZE=%u%s\n",
409 1 << (((val
>> 4) & 3) + 1) : 1,
410 val
& ATMCI_DMAEN
? " DMAEN" : "");
412 if (host
->caps
.has_cfg_reg
) {
415 val
= buf
[ATMCI_CFG
/ 4];
416 seq_printf(s
, "CFG:\t0x%08x%s%s%s%s\n",
418 val
& ATMCI_CFG_FIFOMODE_1DATA
? " FIFOMODE_ONE_DATA" : "",
419 val
& ATMCI_CFG_FERRCTRL_COR
? " FERRCTRL_CLEAR_ON_READ" : "",
420 val
& ATMCI_CFG_HSMODE
? " HSMODE" : "",
421 val
& ATMCI_CFG_LSYNC
? " LSYNC" : "");
429 static int atmci_regs_open(struct inode
*inode
, struct file
*file
)
431 return single_open(file
, atmci_regs_show
, inode
->i_private
);
434 static const struct file_operations atmci_regs_fops
= {
435 .owner
= THIS_MODULE
,
436 .open
= atmci_regs_open
,
439 .release
= single_release
,
442 static void atmci_init_debugfs(struct atmel_mci_slot
*slot
)
444 struct mmc_host
*mmc
= slot
->mmc
;
445 struct atmel_mci
*host
= slot
->host
;
449 root
= mmc
->debugfs_root
;
453 node
= debugfs_create_file("regs", S_IRUSR
, root
, host
,
460 node
= debugfs_create_file("req", S_IRUSR
, root
, slot
, &atmci_req_fops
);
464 node
= debugfs_create_u32("state", S_IRUSR
, root
, (u32
*)&host
->state
);
468 node
= debugfs_create_x32("pending_events", S_IRUSR
, root
,
469 (u32
*)&host
->pending_events
);
473 node
= debugfs_create_x32("completed_events", S_IRUSR
, root
,
474 (u32
*)&host
->completed_events
);
481 dev_err(&mmc
->class_dev
, "failed to initialize debugfs for slot\n");
484 static inline unsigned int atmci_ns_to_clocks(struct atmel_mci
*host
,
488 * It is easier here to use us instead of ns for the timeout,
489 * it prevents from overflows during calculation.
491 unsigned int us
= DIV_ROUND_UP(ns
, 1000);
493 /* Maximum clock frequency is host->bus_hz/2 */
494 return us
* (DIV_ROUND_UP(host
->bus_hz
, 2000000));
497 static void atmci_set_timeout(struct atmel_mci
*host
,
498 struct atmel_mci_slot
*slot
, struct mmc_data
*data
)
500 static unsigned dtomul_to_shift
[] = {
501 0, 4, 7, 8, 10, 12, 16, 20
507 timeout
= atmci_ns_to_clocks(host
, data
->timeout_ns
)
508 + data
->timeout_clks
;
510 for (dtomul
= 0; dtomul
< 8; dtomul
++) {
511 unsigned shift
= dtomul_to_shift
[dtomul
];
512 dtocyc
= (timeout
+ (1 << shift
) - 1) >> shift
;
522 dev_vdbg(&slot
->mmc
->class_dev
, "setting timeout to %u cycles\n",
523 dtocyc
<< dtomul_to_shift
[dtomul
]);
524 atmci_writel(host
, ATMCI_DTOR
, (ATMCI_DTOMUL(dtomul
) | ATMCI_DTOCYC(dtocyc
)));
528 * Return mask with command flags to be enabled for this command.
530 static u32
atmci_prepare_command(struct mmc_host
*mmc
,
531 struct mmc_command
*cmd
)
533 struct mmc_data
*data
;
536 cmd
->error
= -EINPROGRESS
;
538 cmdr
= ATMCI_CMDR_CMDNB(cmd
->opcode
);
540 if (cmd
->flags
& MMC_RSP_PRESENT
) {
541 if (cmd
->flags
& MMC_RSP_136
)
542 cmdr
|= ATMCI_CMDR_RSPTYP_136BIT
;
544 cmdr
|= ATMCI_CMDR_RSPTYP_48BIT
;
548 * This should really be MAXLAT_5 for CMD2 and ACMD41, but
549 * it's too difficult to determine whether this is an ACMD or
550 * not. Better make it 64.
552 cmdr
|= ATMCI_CMDR_MAXLAT_64CYC
;
554 if (mmc
->ios
.bus_mode
== MMC_BUSMODE_OPENDRAIN
)
555 cmdr
|= ATMCI_CMDR_OPDCMD
;
559 cmdr
|= ATMCI_CMDR_START_XFER
;
561 if (cmd
->opcode
== SD_IO_RW_EXTENDED
) {
562 cmdr
|= ATMCI_CMDR_SDIO_BLOCK
;
564 if (data
->flags
& MMC_DATA_STREAM
)
565 cmdr
|= ATMCI_CMDR_STREAM
;
566 else if (data
->blocks
> 1)
567 cmdr
|= ATMCI_CMDR_MULTI_BLOCK
;
569 cmdr
|= ATMCI_CMDR_BLOCK
;
572 if (data
->flags
& MMC_DATA_READ
)
573 cmdr
|= ATMCI_CMDR_TRDIR_READ
;
579 static void atmci_send_command(struct atmel_mci
*host
,
580 struct mmc_command
*cmd
, u32 cmd_flags
)
585 dev_vdbg(&host
->pdev
->dev
,
586 "start command: ARGR=0x%08x CMDR=0x%08x\n",
587 cmd
->arg
, cmd_flags
);
589 atmci_writel(host
, ATMCI_ARGR
, cmd
->arg
);
590 atmci_writel(host
, ATMCI_CMDR
, cmd_flags
);
593 static void atmci_send_stop_cmd(struct atmel_mci
*host
, struct mmc_data
*data
)
595 atmci_send_command(host
, data
->stop
, host
->stop_cmdr
);
596 atmci_writel(host
, ATMCI_IER
, ATMCI_CMDRDY
);
600 * Configure given PDC buffer taking care of alignement issues.
601 * Update host->data_size and host->sg.
603 static void atmci_pdc_set_single_buf(struct atmel_mci
*host
,
604 enum atmci_xfer_dir dir
, enum atmci_pdc_buf buf_nb
)
606 u32 pointer_reg
, counter_reg
;
608 if (dir
== XFER_RECEIVE
) {
609 pointer_reg
= ATMEL_PDC_RPR
;
610 counter_reg
= ATMEL_PDC_RCR
;
612 pointer_reg
= ATMEL_PDC_TPR
;
613 counter_reg
= ATMEL_PDC_TCR
;
616 if (buf_nb
== PDC_SECOND_BUF
) {
617 pointer_reg
+= ATMEL_PDC_SCND_BUF_OFF
;
618 counter_reg
+= ATMEL_PDC_SCND_BUF_OFF
;
621 atmci_writel(host
, pointer_reg
, sg_dma_address(host
->sg
));
622 if (host
->data_size
<= sg_dma_len(host
->sg
)) {
623 if (host
->data_size
& 0x3) {
624 /* If size is different from modulo 4, transfer bytes */
625 atmci_writel(host
, counter_reg
, host
->data_size
);
626 atmci_writel(host
, ATMCI_MR
, host
->mode_reg
| ATMCI_MR_PDCFBYTE
);
628 /* Else transfer 32-bits words */
629 atmci_writel(host
, counter_reg
, host
->data_size
/ 4);
633 /* We assume the size of a page is 32-bits aligned */
634 atmci_writel(host
, counter_reg
, sg_dma_len(host
->sg
) / 4);
635 host
->data_size
-= sg_dma_len(host
->sg
);
637 host
->sg
= sg_next(host
->sg
);
642 * Configure PDC buffer according to the data size ie configuring one or two
643 * buffers. Don't use this function if you want to configure only the second
644 * buffer. In this case, use atmci_pdc_set_single_buf.
646 static void atmci_pdc_set_both_buf(struct atmel_mci
*host
, int dir
)
648 atmci_pdc_set_single_buf(host
, dir
, PDC_FIRST_BUF
);
650 atmci_pdc_set_single_buf(host
, dir
, PDC_SECOND_BUF
);
654 * Unmap sg lists, called when transfer is finished.
656 static void atmci_pdc_cleanup(struct atmel_mci
*host
)
658 struct mmc_data
*data
= host
->data
;
661 dma_unmap_sg(&host
->pdev
->dev
,
662 data
->sg
, data
->sg_len
,
663 ((data
->flags
& MMC_DATA_WRITE
)
664 ? DMA_TO_DEVICE
: DMA_FROM_DEVICE
));
668 * Disable PDC transfers. Update pending flags to EVENT_XFER_COMPLETE after
669 * having received ATMCI_TXBUFE or ATMCI_RXBUFF interrupt. Enable ATMCI_NOTBUSY
670 * interrupt needed for both transfer directions.
672 static void atmci_pdc_complete(struct atmel_mci
*host
)
674 atmci_writel(host
, ATMEL_PDC_PTCR
, ATMEL_PDC_RXTDIS
| ATMEL_PDC_TXTDIS
);
675 atmci_pdc_cleanup(host
);
678 * If the card was removed, data will be NULL. No point trying
679 * to send the stop command or waiting for NBUSY in this case.
682 atmci_set_pending(host
, EVENT_XFER_COMPLETE
);
683 tasklet_schedule(&host
->tasklet
);
684 atmci_writel(host
, ATMCI_IER
, ATMCI_NOTBUSY
);
688 static void atmci_dma_cleanup(struct atmel_mci
*host
)
690 struct mmc_data
*data
= host
->data
;
693 dma_unmap_sg(host
->dma
.chan
->device
->dev
,
694 data
->sg
, data
->sg_len
,
695 ((data
->flags
& MMC_DATA_WRITE
)
696 ? DMA_TO_DEVICE
: DMA_FROM_DEVICE
));
700 * This function is called by the DMA driver from tasklet context.
702 static void atmci_dma_complete(void *arg
)
704 struct atmel_mci
*host
= arg
;
705 struct mmc_data
*data
= host
->data
;
707 dev_vdbg(&host
->pdev
->dev
, "DMA complete\n");
709 if (host
->caps
.has_dma
)
710 /* Disable DMA hardware handshaking on MCI */
711 atmci_writel(host
, ATMCI_DMA
, atmci_readl(host
, ATMCI_DMA
) & ~ATMCI_DMAEN
);
713 atmci_dma_cleanup(host
);
716 * If the card was removed, data will be NULL. No point trying
717 * to send the stop command or waiting for NBUSY in this case.
720 atmci_set_pending(host
, EVENT_XFER_COMPLETE
);
721 tasklet_schedule(&host
->tasklet
);
724 * Regardless of what the documentation says, we have
725 * to wait for NOTBUSY even after block read
728 * When the DMA transfer is complete, the controller
729 * may still be reading the CRC from the card, i.e.
730 * the data transfer is still in progress and we
731 * haven't seen all the potential error bits yet.
733 * The interrupt handler will schedule a different
734 * tasklet to finish things up when the data transfer
735 * is completely done.
737 * We may not complete the mmc request here anyway
738 * because the mmc layer may call back and cause us to
739 * violate the "don't submit new operations from the
740 * completion callback" rule of the dma engine
743 atmci_writel(host
, ATMCI_IER
, ATMCI_NOTBUSY
);
748 * Returns a mask of interrupt flags to be enabled after the whole
749 * request has been prepared.
751 static u32
atmci_prepare_data(struct atmel_mci
*host
, struct mmc_data
*data
)
755 data
->error
= -EINPROGRESS
;
758 host
->sg_len
= data
->sg_len
;
760 host
->data_chan
= NULL
;
762 iflags
= ATMCI_DATA_ERROR_FLAGS
;
765 * Errata: MMC data write operation with less than 12
766 * bytes is impossible.
768 * Errata: MCI Transmit Data Register (TDR) FIFO
769 * corruption when length is not multiple of 4.
771 if (data
->blocks
* data
->blksz
< 12
772 || (data
->blocks
* data
->blksz
) & 3)
773 host
->need_reset
= true;
775 host
->pio_offset
= 0;
776 if (data
->flags
& MMC_DATA_READ
)
777 iflags
|= ATMCI_RXRDY
;
779 iflags
|= ATMCI_TXRDY
;
785 * Set interrupt flags and set block length into the MCI mode register even
786 * if this value is also accessible in the MCI block register. It seems to be
787 * necessary before the High Speed MCI version. It also map sg and configure
791 atmci_prepare_data_pdc(struct atmel_mci
*host
, struct mmc_data
*data
)
795 enum dma_data_direction dir
;
797 data
->error
= -EINPROGRESS
;
801 iflags
= ATMCI_DATA_ERROR_FLAGS
;
803 /* Enable pdc mode */
804 atmci_writel(host
, ATMCI_MR
, host
->mode_reg
| ATMCI_MR_PDCMODE
);
806 if (data
->flags
& MMC_DATA_READ
) {
807 dir
= DMA_FROM_DEVICE
;
808 iflags
|= ATMCI_ENDRX
| ATMCI_RXBUFF
;
811 iflags
|= ATMCI_ENDTX
| ATMCI_TXBUFE
;
815 tmp
= atmci_readl(host
, ATMCI_MR
);
817 tmp
|= ATMCI_BLKLEN(data
->blksz
);
818 atmci_writel(host
, ATMCI_MR
, tmp
);
821 host
->data_size
= data
->blocks
* data
->blksz
;
822 sg_len
= dma_map_sg(&host
->pdev
->dev
, data
->sg
, data
->sg_len
, dir
);
824 atmci_pdc_set_both_buf(host
,
825 ((dir
== DMA_FROM_DEVICE
) ? XFER_RECEIVE
: XFER_TRANSMIT
));
831 atmci_prepare_data_dma(struct atmel_mci
*host
, struct mmc_data
*data
)
833 struct dma_chan
*chan
;
834 struct dma_async_tx_descriptor
*desc
;
835 struct scatterlist
*sg
;
837 enum dma_data_direction direction
;
838 enum dma_transfer_direction slave_dirn
;
842 data
->error
= -EINPROGRESS
;
848 iflags
= ATMCI_DATA_ERROR_FLAGS
;
851 * We don't do DMA on "complex" transfers, i.e. with
852 * non-word-aligned buffers or lengths. Also, we don't bother
853 * with all the DMA setup overhead for short transfers.
855 if (data
->blocks
* data
->blksz
< ATMCI_DMA_THRESHOLD
)
856 return atmci_prepare_data(host
, data
);
858 return atmci_prepare_data(host
, data
);
860 for_each_sg(data
->sg
, sg
, data
->sg_len
, i
) {
861 if (sg
->offset
& 3 || sg
->length
& 3)
862 return atmci_prepare_data(host
, data
);
865 /* If we don't have a channel, we can't do DMA */
866 chan
= host
->dma
.chan
;
868 host
->data_chan
= chan
;
873 if (host
->caps
.has_dma
)
874 atmci_writel(host
, ATMCI_DMA
, ATMCI_DMA_CHKSIZE(3) | ATMCI_DMAEN
);
876 if (data
->flags
& MMC_DATA_READ
) {
877 direction
= DMA_FROM_DEVICE
;
878 host
->dma_conf
.direction
= slave_dirn
= DMA_DEV_TO_MEM
;
880 direction
= DMA_TO_DEVICE
;
881 host
->dma_conf
.direction
= slave_dirn
= DMA_MEM_TO_DEV
;
884 sglen
= dma_map_sg(chan
->device
->dev
, data
->sg
,
885 data
->sg_len
, direction
);
887 dmaengine_slave_config(chan
, &host
->dma_conf
);
888 desc
= dmaengine_prep_slave_sg(chan
,
889 data
->sg
, sglen
, slave_dirn
,
890 DMA_PREP_INTERRUPT
| DMA_CTRL_ACK
);
894 host
->dma
.data_desc
= desc
;
895 desc
->callback
= atmci_dma_complete
;
896 desc
->callback_param
= host
;
900 dma_unmap_sg(chan
->device
->dev
, data
->sg
, data
->sg_len
, direction
);
905 atmci_submit_data(struct atmel_mci
*host
, struct mmc_data
*data
)
911 * Start PDC according to transfer direction.
914 atmci_submit_data_pdc(struct atmel_mci
*host
, struct mmc_data
*data
)
916 if (data
->flags
& MMC_DATA_READ
)
917 atmci_writel(host
, ATMEL_PDC_PTCR
, ATMEL_PDC_RXTEN
);
919 atmci_writel(host
, ATMEL_PDC_PTCR
, ATMEL_PDC_TXTEN
);
923 atmci_submit_data_dma(struct atmel_mci
*host
, struct mmc_data
*data
)
925 struct dma_chan
*chan
= host
->data_chan
;
926 struct dma_async_tx_descriptor
*desc
= host
->dma
.data_desc
;
929 dmaengine_submit(desc
);
930 dma_async_issue_pending(chan
);
934 static void atmci_stop_transfer(struct atmel_mci
*host
)
936 atmci_set_pending(host
, EVENT_XFER_COMPLETE
);
937 atmci_writel(host
, ATMCI_IER
, ATMCI_NOTBUSY
);
941 * Stop data transfer because error(s) occured.
943 static void atmci_stop_transfer_pdc(struct atmel_mci
*host
)
945 atmci_set_pending(host
, EVENT_XFER_COMPLETE
);
946 atmci_writel(host
, ATMCI_IER
, ATMCI_NOTBUSY
);
949 static void atmci_stop_transfer_dma(struct atmel_mci
*host
)
951 struct dma_chan
*chan
= host
->data_chan
;
954 dmaengine_terminate_all(chan
);
955 atmci_dma_cleanup(host
);
957 /* Data transfer was stopped by the interrupt handler */
958 atmci_set_pending(host
, EVENT_XFER_COMPLETE
);
959 atmci_writel(host
, ATMCI_IER
, ATMCI_NOTBUSY
);
964 * Start a request: prepare data if needed, prepare the command and activate
967 static void atmci_start_request(struct atmel_mci
*host
,
968 struct atmel_mci_slot
*slot
)
970 struct mmc_request
*mrq
;
971 struct mmc_command
*cmd
;
972 struct mmc_data
*data
;
977 host
->cur_slot
= slot
;
980 host
->pending_events
= 0;
981 host
->completed_events
= 0;
982 host
->data_status
= 0;
984 if (host
->need_reset
) {
985 iflags
= atmci_readl(host
, ATMCI_IMR
);
986 iflags
&= (ATMCI_SDIOIRQA
| ATMCI_SDIOIRQB
);
987 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_SWRST
);
988 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_MCIEN
);
989 atmci_writel(host
, ATMCI_MR
, host
->mode_reg
);
990 if (host
->caps
.has_cfg_reg
)
991 atmci_writel(host
, ATMCI_CFG
, host
->cfg_reg
);
992 atmci_writel(host
, ATMCI_IER
, iflags
);
993 host
->need_reset
= false;
995 atmci_writel(host
, ATMCI_SDCR
, slot
->sdc_reg
);
997 iflags
= atmci_readl(host
, ATMCI_IMR
);
998 if (iflags
& ~(ATMCI_SDIOIRQA
| ATMCI_SDIOIRQB
))
999 dev_warn(&slot
->mmc
->class_dev
, "WARNING: IMR=0x%08x\n",
1002 if (unlikely(test_and_clear_bit(ATMCI_CARD_NEED_INIT
, &slot
->flags
))) {
1003 /* Send init sequence (74 clock cycles) */
1004 atmci_writel(host
, ATMCI_CMDR
, ATMCI_CMDR_SPCMD_INIT
);
1005 while (!(atmci_readl(host
, ATMCI_SR
) & ATMCI_CMDRDY
))
1011 atmci_set_timeout(host
, slot
, data
);
1013 /* Must set block count/size before sending command */
1014 atmci_writel(host
, ATMCI_BLKR
, ATMCI_BCNT(data
->blocks
)
1015 | ATMCI_BLKLEN(data
->blksz
));
1016 dev_vdbg(&slot
->mmc
->class_dev
, "BLKR=0x%08x\n",
1017 ATMCI_BCNT(data
->blocks
) | ATMCI_BLKLEN(data
->blksz
));
1019 iflags
|= host
->prepare_data(host
, data
);
1022 iflags
|= ATMCI_CMDRDY
;
1024 cmdflags
= atmci_prepare_command(slot
->mmc
, cmd
);
1027 * DMA transfer should be started before sending the command to avoid
1028 * unexpected errors especially for read operations in SDIO mode.
1029 * Unfortunately, in PDC mode, command has to be sent before starting
1032 if (host
->submit_data
!= &atmci_submit_data_dma
)
1033 atmci_send_command(host
, cmd
, cmdflags
);
1036 host
->submit_data(host
, data
);
1038 if (host
->submit_data
== &atmci_submit_data_dma
)
1039 atmci_send_command(host
, cmd
, cmdflags
);
1042 host
->stop_cmdr
= atmci_prepare_command(slot
->mmc
, mrq
->stop
);
1043 host
->stop_cmdr
|= ATMCI_CMDR_STOP_XFER
;
1044 if (!(data
->flags
& MMC_DATA_WRITE
))
1045 host
->stop_cmdr
|= ATMCI_CMDR_TRDIR_READ
;
1046 if (data
->flags
& MMC_DATA_STREAM
)
1047 host
->stop_cmdr
|= ATMCI_CMDR_STREAM
;
1049 host
->stop_cmdr
|= ATMCI_CMDR_MULTI_BLOCK
;
1053 * We could have enabled interrupts earlier, but I suspect
1054 * that would open up a nice can of interesting race
1055 * conditions (e.g. command and data complete, but stop not
1058 atmci_writel(host
, ATMCI_IER
, iflags
);
1061 static void atmci_queue_request(struct atmel_mci
*host
,
1062 struct atmel_mci_slot
*slot
, struct mmc_request
*mrq
)
1064 dev_vdbg(&slot
->mmc
->class_dev
, "queue request: state=%d\n",
1067 spin_lock_bh(&host
->lock
);
1069 if (host
->state
== STATE_IDLE
) {
1070 host
->state
= STATE_SENDING_CMD
;
1071 atmci_start_request(host
, slot
);
1073 list_add_tail(&slot
->queue_node
, &host
->queue
);
1075 spin_unlock_bh(&host
->lock
);
1078 static void atmci_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
1080 struct atmel_mci_slot
*slot
= mmc_priv(mmc
);
1081 struct atmel_mci
*host
= slot
->host
;
1082 struct mmc_data
*data
;
1087 * We may "know" the card is gone even though there's still an
1088 * electrical connection. If so, we really need to communicate
1089 * this to the MMC core since there won't be any more
1090 * interrupts as the card is completely removed. Otherwise,
1091 * the MMC core might believe the card is still there even
1092 * though the card was just removed very slowly.
1094 if (!test_bit(ATMCI_CARD_PRESENT
, &slot
->flags
)) {
1095 mrq
->cmd
->error
= -ENOMEDIUM
;
1096 mmc_request_done(mmc
, mrq
);
1100 /* We don't support multiple blocks of weird lengths. */
1102 if (data
&& data
->blocks
> 1 && data
->blksz
& 3) {
1103 mrq
->cmd
->error
= -EINVAL
;
1104 mmc_request_done(mmc
, mrq
);
1107 atmci_queue_request(host
, slot
, mrq
);
1110 static void atmci_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
1112 struct atmel_mci_slot
*slot
= mmc_priv(mmc
);
1113 struct atmel_mci
*host
= slot
->host
;
1116 slot
->sdc_reg
&= ~ATMCI_SDCBUS_MASK
;
1117 switch (ios
->bus_width
) {
1118 case MMC_BUS_WIDTH_1
:
1119 slot
->sdc_reg
|= ATMCI_SDCBUS_1BIT
;
1121 case MMC_BUS_WIDTH_4
:
1122 slot
->sdc_reg
|= ATMCI_SDCBUS_4BIT
;
1127 unsigned int clock_min
= ~0U;
1130 spin_lock_bh(&host
->lock
);
1131 if (!host
->mode_reg
) {
1132 clk_enable(host
->mck
);
1133 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_SWRST
);
1134 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_MCIEN
);
1135 if (host
->caps
.has_cfg_reg
)
1136 atmci_writel(host
, ATMCI_CFG
, host
->cfg_reg
);
1140 * Use mirror of ios->clock to prevent race with mmc
1141 * core ios update when finding the minimum.
1143 slot
->clock
= ios
->clock
;
1144 for (i
= 0; i
< ATMCI_MAX_NR_SLOTS
; i
++) {
1145 if (host
->slot
[i
] && host
->slot
[i
]->clock
1146 && host
->slot
[i
]->clock
< clock_min
)
1147 clock_min
= host
->slot
[i
]->clock
;
1150 /* Calculate clock divider */
1151 if (host
->caps
.has_odd_clk_div
) {
1152 clkdiv
= DIV_ROUND_UP(host
->bus_hz
, clock_min
) - 2;
1154 dev_warn(&mmc
->class_dev
,
1155 "clock %u too slow; using %lu\n",
1156 clock_min
, host
->bus_hz
/ (511 + 2));
1159 host
->mode_reg
= ATMCI_MR_CLKDIV(clkdiv
>> 1)
1160 | ATMCI_MR_CLKODD(clkdiv
& 1);
1162 clkdiv
= DIV_ROUND_UP(host
->bus_hz
, 2 * clock_min
) - 1;
1164 dev_warn(&mmc
->class_dev
,
1165 "clock %u too slow; using %lu\n",
1166 clock_min
, host
->bus_hz
/ (2 * 256));
1169 host
->mode_reg
= ATMCI_MR_CLKDIV(clkdiv
);
1173 * WRPROOF and RDPROOF prevent overruns/underruns by
1174 * stopping the clock when the FIFO is full/empty.
1175 * This state is not expected to last for long.
1177 if (host
->caps
.has_rwproof
)
1178 host
->mode_reg
|= (ATMCI_MR_WRPROOF
| ATMCI_MR_RDPROOF
);
1180 if (host
->caps
.has_cfg_reg
) {
1181 /* setup High Speed mode in relation with card capacity */
1182 if (ios
->timing
== MMC_TIMING_SD_HS
)
1183 host
->cfg_reg
|= ATMCI_CFG_HSMODE
;
1185 host
->cfg_reg
&= ~ATMCI_CFG_HSMODE
;
1188 if (list_empty(&host
->queue
)) {
1189 atmci_writel(host
, ATMCI_MR
, host
->mode_reg
);
1190 if (host
->caps
.has_cfg_reg
)
1191 atmci_writel(host
, ATMCI_CFG
, host
->cfg_reg
);
1193 host
->need_clock_update
= true;
1196 spin_unlock_bh(&host
->lock
);
1198 bool any_slot_active
= false;
1200 spin_lock_bh(&host
->lock
);
1202 for (i
= 0; i
< ATMCI_MAX_NR_SLOTS
; i
++) {
1203 if (host
->slot
[i
] && host
->slot
[i
]->clock
) {
1204 any_slot_active
= true;
1208 if (!any_slot_active
) {
1209 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_MCIDIS
);
1210 if (host
->mode_reg
) {
1211 atmci_readl(host
, ATMCI_MR
);
1212 clk_disable(host
->mck
);
1216 spin_unlock_bh(&host
->lock
);
1219 switch (ios
->power_mode
) {
1221 set_bit(ATMCI_CARD_NEED_INIT
, &slot
->flags
);
1225 * TODO: None of the currently available AVR32-based
1226 * boards allow MMC power to be turned off. Implement
1227 * power control when this can be tested properly.
1229 * We also need to hook this into the clock management
1230 * somehow so that newly inserted cards aren't
1231 * subjected to a fast clock before we have a chance
1232 * to figure out what the maximum rate is. Currently,
1233 * there's no way to avoid this, and there never will
1234 * be for boards that don't support power control.
1240 static int atmci_get_ro(struct mmc_host
*mmc
)
1242 int read_only
= -ENOSYS
;
1243 struct atmel_mci_slot
*slot
= mmc_priv(mmc
);
1245 if (gpio_is_valid(slot
->wp_pin
)) {
1246 read_only
= gpio_get_value(slot
->wp_pin
);
1247 dev_dbg(&mmc
->class_dev
, "card is %s\n",
1248 read_only
? "read-only" : "read-write");
1254 static int atmci_get_cd(struct mmc_host
*mmc
)
1256 int present
= -ENOSYS
;
1257 struct atmel_mci_slot
*slot
= mmc_priv(mmc
);
1259 if (gpio_is_valid(slot
->detect_pin
)) {
1260 present
= !(gpio_get_value(slot
->detect_pin
) ^
1261 slot
->detect_is_active_high
);
1262 dev_dbg(&mmc
->class_dev
, "card is %spresent\n",
1263 present
? "" : "not ");
1269 static void atmci_enable_sdio_irq(struct mmc_host
*mmc
, int enable
)
1271 struct atmel_mci_slot
*slot
= mmc_priv(mmc
);
1272 struct atmel_mci
*host
= slot
->host
;
1275 atmci_writel(host
, ATMCI_IER
, slot
->sdio_irq
);
1277 atmci_writel(host
, ATMCI_IDR
, slot
->sdio_irq
);
1280 static const struct mmc_host_ops atmci_ops
= {
1281 .request
= atmci_request
,
1282 .set_ios
= atmci_set_ios
,
1283 .get_ro
= atmci_get_ro
,
1284 .get_cd
= atmci_get_cd
,
1285 .enable_sdio_irq
= atmci_enable_sdio_irq
,
1288 /* Called with host->lock held */
1289 static void atmci_request_end(struct atmel_mci
*host
, struct mmc_request
*mrq
)
1290 __releases(&host
->lock
)
1291 __acquires(&host
->lock
)
1293 struct atmel_mci_slot
*slot
= NULL
;
1294 struct mmc_host
*prev_mmc
= host
->cur_slot
->mmc
;
1296 WARN_ON(host
->cmd
|| host
->data
);
1299 * Update the MMC clock rate if necessary. This may be
1300 * necessary if set_ios() is called when a different slot is
1301 * busy transferring data.
1303 if (host
->need_clock_update
) {
1304 atmci_writel(host
, ATMCI_MR
, host
->mode_reg
);
1305 if (host
->caps
.has_cfg_reg
)
1306 atmci_writel(host
, ATMCI_CFG
, host
->cfg_reg
);
1309 host
->cur_slot
->mrq
= NULL
;
1311 if (!list_empty(&host
->queue
)) {
1312 slot
= list_entry(host
->queue
.next
,
1313 struct atmel_mci_slot
, queue_node
);
1314 list_del(&slot
->queue_node
);
1315 dev_vdbg(&host
->pdev
->dev
, "list not empty: %s is next\n",
1316 mmc_hostname(slot
->mmc
));
1317 host
->state
= STATE_SENDING_CMD
;
1318 atmci_start_request(host
, slot
);
1320 dev_vdbg(&host
->pdev
->dev
, "list empty\n");
1321 host
->state
= STATE_IDLE
;
1324 spin_unlock(&host
->lock
);
1325 mmc_request_done(prev_mmc
, mrq
);
1326 spin_lock(&host
->lock
);
1329 static void atmci_command_complete(struct atmel_mci
*host
,
1330 struct mmc_command
*cmd
)
1332 u32 status
= host
->cmd_status
;
1334 /* Read the response from the card (up to 16 bytes) */
1335 cmd
->resp
[0] = atmci_readl(host
, ATMCI_RSPR
);
1336 cmd
->resp
[1] = atmci_readl(host
, ATMCI_RSPR
);
1337 cmd
->resp
[2] = atmci_readl(host
, ATMCI_RSPR
);
1338 cmd
->resp
[3] = atmci_readl(host
, ATMCI_RSPR
);
1340 if (status
& ATMCI_RTOE
)
1341 cmd
->error
= -ETIMEDOUT
;
1342 else if ((cmd
->flags
& MMC_RSP_CRC
) && (status
& ATMCI_RCRCE
))
1343 cmd
->error
= -EILSEQ
;
1344 else if (status
& (ATMCI_RINDE
| ATMCI_RDIRE
| ATMCI_RENDE
))
1350 dev_dbg(&host
->pdev
->dev
,
1351 "command error: status=0x%08x\n", status
);
1354 host
->stop_transfer(host
);
1356 atmci_writel(host
, ATMCI_IDR
, ATMCI_NOTBUSY
1357 | ATMCI_TXRDY
| ATMCI_RXRDY
1358 | ATMCI_DATA_ERROR_FLAGS
);
1363 static void atmci_detect_change(unsigned long data
)
1365 struct atmel_mci_slot
*slot
= (struct atmel_mci_slot
*)data
;
1370 * atmci_cleanup_slot() sets the ATMCI_SHUTDOWN flag before
1371 * freeing the interrupt. We must not re-enable the interrupt
1372 * if it has been freed, and if we're shutting down, it
1373 * doesn't really matter whether the card is present or not.
1376 if (test_bit(ATMCI_SHUTDOWN
, &slot
->flags
))
1379 enable_irq(gpio_to_irq(slot
->detect_pin
));
1380 present
= !(gpio_get_value(slot
->detect_pin
) ^
1381 slot
->detect_is_active_high
);
1382 present_old
= test_bit(ATMCI_CARD_PRESENT
, &slot
->flags
);
1384 dev_vdbg(&slot
->mmc
->class_dev
, "detect change: %d (was %d)\n",
1385 present
, present_old
);
1387 if (present
!= present_old
) {
1388 struct atmel_mci
*host
= slot
->host
;
1389 struct mmc_request
*mrq
;
1391 dev_dbg(&slot
->mmc
->class_dev
, "card %s\n",
1392 present
? "inserted" : "removed");
1394 spin_lock(&host
->lock
);
1397 clear_bit(ATMCI_CARD_PRESENT
, &slot
->flags
);
1399 set_bit(ATMCI_CARD_PRESENT
, &slot
->flags
);
1401 /* Clean up queue if present */
1404 if (mrq
== host
->mrq
) {
1406 * Reset controller to terminate any ongoing
1407 * commands or data transfers.
1409 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_SWRST
);
1410 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_MCIEN
);
1411 atmci_writel(host
, ATMCI_MR
, host
->mode_reg
);
1412 if (host
->caps
.has_cfg_reg
)
1413 atmci_writel(host
, ATMCI_CFG
, host
->cfg_reg
);
1418 switch (host
->state
) {
1421 case STATE_SENDING_CMD
:
1422 mrq
->cmd
->error
= -ENOMEDIUM
;
1426 case STATE_SENDING_DATA
:
1427 mrq
->data
->error
= -ENOMEDIUM
;
1428 host
->stop_transfer(host
);
1430 case STATE_DATA_BUSY
:
1431 case STATE_DATA_ERROR
:
1432 if (mrq
->data
->error
== -EINPROGRESS
)
1433 mrq
->data
->error
= -ENOMEDIUM
;
1437 case STATE_SENDING_STOP
:
1438 mrq
->stop
->error
= -ENOMEDIUM
;
1442 atmci_request_end(host
, mrq
);
1444 list_del(&slot
->queue_node
);
1445 mrq
->cmd
->error
= -ENOMEDIUM
;
1447 mrq
->data
->error
= -ENOMEDIUM
;
1449 mrq
->stop
->error
= -ENOMEDIUM
;
1451 spin_unlock(&host
->lock
);
1452 mmc_request_done(slot
->mmc
, mrq
);
1453 spin_lock(&host
->lock
);
1456 spin_unlock(&host
->lock
);
1458 mmc_detect_change(slot
->mmc
, 0);
1462 static void atmci_tasklet_func(unsigned long priv
)
1464 struct atmel_mci
*host
= (struct atmel_mci
*)priv
;
1465 struct mmc_request
*mrq
= host
->mrq
;
1466 struct mmc_data
*data
= host
->data
;
1467 struct mmc_command
*cmd
= host
->cmd
;
1468 enum atmel_mci_state state
= host
->state
;
1469 enum atmel_mci_state prev_state
;
1472 spin_lock(&host
->lock
);
1474 state
= host
->state
;
1476 dev_vdbg(&host
->pdev
->dev
,
1477 "tasklet: state %u pending/completed/mask %lx/%lx/%x\n",
1478 state
, host
->pending_events
, host
->completed_events
,
1479 atmci_readl(host
, ATMCI_IMR
));
1488 case STATE_SENDING_CMD
:
1489 if (!atmci_test_and_clear_pending(host
,
1490 EVENT_CMD_COMPLETE
))
1494 atmci_set_completed(host
, EVENT_CMD_COMPLETE
);
1495 atmci_command_complete(host
, mrq
->cmd
);
1496 if (!mrq
->data
|| cmd
->error
) {
1497 atmci_request_end(host
, host
->mrq
);
1501 prev_state
= state
= STATE_SENDING_DATA
;
1504 case STATE_SENDING_DATA
:
1505 if (atmci_test_and_clear_pending(host
,
1506 EVENT_DATA_ERROR
)) {
1507 host
->stop_transfer(host
);
1509 atmci_send_stop_cmd(host
, data
);
1510 state
= STATE_DATA_ERROR
;
1514 if (!atmci_test_and_clear_pending(host
,
1515 EVENT_XFER_COMPLETE
))
1518 atmci_set_completed(host
, EVENT_XFER_COMPLETE
);
1519 prev_state
= state
= STATE_DATA_BUSY
;
1522 case STATE_DATA_BUSY
:
1523 if (!atmci_test_and_clear_pending(host
,
1524 EVENT_DATA_COMPLETE
))
1528 atmci_set_completed(host
, EVENT_DATA_COMPLETE
);
1529 status
= host
->data_status
;
1530 if (unlikely(status
& ATMCI_DATA_ERROR_FLAGS
)) {
1531 if (status
& ATMCI_DTOE
) {
1532 dev_dbg(&host
->pdev
->dev
,
1533 "data timeout error\n");
1534 data
->error
= -ETIMEDOUT
;
1535 } else if (status
& ATMCI_DCRCE
) {
1536 dev_dbg(&host
->pdev
->dev
,
1537 "data CRC error\n");
1538 data
->error
= -EILSEQ
;
1540 dev_dbg(&host
->pdev
->dev
,
1541 "data FIFO error (status=%08x)\n",
1546 data
->bytes_xfered
= data
->blocks
* data
->blksz
;
1548 atmci_writel(host
, ATMCI_IDR
, ATMCI_DATA_ERROR_FLAGS
);
1552 atmci_request_end(host
, host
->mrq
);
1556 prev_state
= state
= STATE_SENDING_STOP
;
1558 atmci_send_stop_cmd(host
, data
);
1561 case STATE_SENDING_STOP
:
1562 if (!atmci_test_and_clear_pending(host
,
1563 EVENT_CMD_COMPLETE
))
1567 atmci_command_complete(host
, mrq
->stop
);
1568 atmci_request_end(host
, host
->mrq
);
1571 case STATE_DATA_ERROR
:
1572 if (!atmci_test_and_clear_pending(host
,
1573 EVENT_XFER_COMPLETE
))
1576 state
= STATE_DATA_BUSY
;
1579 } while (state
!= prev_state
);
1581 host
->state
= state
;
1584 spin_unlock(&host
->lock
);
1587 static void atmci_read_data_pio(struct atmel_mci
*host
)
1589 struct scatterlist
*sg
= host
->sg
;
1590 void *buf
= sg_virt(sg
);
1591 unsigned int offset
= host
->pio_offset
;
1592 struct mmc_data
*data
= host
->data
;
1595 unsigned int nbytes
= 0;
1598 value
= atmci_readl(host
, ATMCI_RDR
);
1599 if (likely(offset
+ 4 <= sg
->length
)) {
1600 put_unaligned(value
, (u32
*)(buf
+ offset
));
1605 if (offset
== sg
->length
) {
1606 flush_dcache_page(sg_page(sg
));
1607 host
->sg
= sg
= sg_next(sg
);
1609 if (!sg
|| !host
->sg_len
)
1616 unsigned int remaining
= sg
->length
- offset
;
1617 memcpy(buf
+ offset
, &value
, remaining
);
1618 nbytes
+= remaining
;
1620 flush_dcache_page(sg_page(sg
));
1621 host
->sg
= sg
= sg_next(sg
);
1623 if (!sg
|| !host
->sg_len
)
1626 offset
= 4 - remaining
;
1628 memcpy(buf
, (u8
*)&value
+ remaining
, offset
);
1632 status
= atmci_readl(host
, ATMCI_SR
);
1633 if (status
& ATMCI_DATA_ERROR_FLAGS
) {
1634 atmci_writel(host
, ATMCI_IDR
, (ATMCI_NOTBUSY
| ATMCI_RXRDY
1635 | ATMCI_DATA_ERROR_FLAGS
));
1636 host
->data_status
= status
;
1637 data
->bytes_xfered
+= nbytes
;
1639 atmci_set_pending(host
, EVENT_DATA_ERROR
);
1640 tasklet_schedule(&host
->tasklet
);
1643 } while (status
& ATMCI_RXRDY
);
1645 host
->pio_offset
= offset
;
1646 data
->bytes_xfered
+= nbytes
;
1651 atmci_writel(host
, ATMCI_IDR
, ATMCI_RXRDY
);
1652 atmci_writel(host
, ATMCI_IER
, ATMCI_NOTBUSY
);
1653 data
->bytes_xfered
+= nbytes
;
1655 atmci_set_pending(host
, EVENT_XFER_COMPLETE
);
1658 static void atmci_write_data_pio(struct atmel_mci
*host
)
1660 struct scatterlist
*sg
= host
->sg
;
1661 void *buf
= sg_virt(sg
);
1662 unsigned int offset
= host
->pio_offset
;
1663 struct mmc_data
*data
= host
->data
;
1666 unsigned int nbytes
= 0;
1669 if (likely(offset
+ 4 <= sg
->length
)) {
1670 value
= get_unaligned((u32
*)(buf
+ offset
));
1671 atmci_writel(host
, ATMCI_TDR
, value
);
1675 if (offset
== sg
->length
) {
1676 host
->sg
= sg
= sg_next(sg
);
1678 if (!sg
|| !host
->sg_len
)
1685 unsigned int remaining
= sg
->length
- offset
;
1688 memcpy(&value
, buf
+ offset
, remaining
);
1689 nbytes
+= remaining
;
1691 host
->sg
= sg
= sg_next(sg
);
1693 if (!sg
|| !host
->sg_len
) {
1694 atmci_writel(host
, ATMCI_TDR
, value
);
1698 offset
= 4 - remaining
;
1700 memcpy((u8
*)&value
+ remaining
, buf
, offset
);
1701 atmci_writel(host
, ATMCI_TDR
, value
);
1705 status
= atmci_readl(host
, ATMCI_SR
);
1706 if (status
& ATMCI_DATA_ERROR_FLAGS
) {
1707 atmci_writel(host
, ATMCI_IDR
, (ATMCI_NOTBUSY
| ATMCI_TXRDY
1708 | ATMCI_DATA_ERROR_FLAGS
));
1709 host
->data_status
= status
;
1710 data
->bytes_xfered
+= nbytes
;
1712 atmci_set_pending(host
, EVENT_DATA_ERROR
);
1713 tasklet_schedule(&host
->tasklet
);
1716 } while (status
& ATMCI_TXRDY
);
1718 host
->pio_offset
= offset
;
1719 data
->bytes_xfered
+= nbytes
;
1724 atmci_writel(host
, ATMCI_IDR
, ATMCI_TXRDY
);
1725 atmci_writel(host
, ATMCI_IER
, ATMCI_NOTBUSY
);
1726 data
->bytes_xfered
+= nbytes
;
1728 atmci_set_pending(host
, EVENT_XFER_COMPLETE
);
1731 static void atmci_cmd_interrupt(struct atmel_mci
*host
, u32 status
)
1733 atmci_writel(host
, ATMCI_IDR
, ATMCI_CMDRDY
);
1735 host
->cmd_status
= status
;
1737 atmci_set_pending(host
, EVENT_CMD_COMPLETE
);
1738 tasklet_schedule(&host
->tasklet
);
1741 static void atmci_sdio_interrupt(struct atmel_mci
*host
, u32 status
)
1745 for (i
= 0; i
< ATMCI_MAX_NR_SLOTS
; i
++) {
1746 struct atmel_mci_slot
*slot
= host
->slot
[i
];
1747 if (slot
&& (status
& slot
->sdio_irq
)) {
1748 mmc_signal_sdio_irq(slot
->mmc
);
1754 static irqreturn_t
atmci_interrupt(int irq
, void *dev_id
)
1756 struct atmel_mci
*host
= dev_id
;
1757 u32 status
, mask
, pending
;
1758 unsigned int pass_count
= 0;
1761 status
= atmci_readl(host
, ATMCI_SR
);
1762 mask
= atmci_readl(host
, ATMCI_IMR
);
1763 pending
= status
& mask
;
1767 if (pending
& ATMCI_DATA_ERROR_FLAGS
) {
1768 atmci_writel(host
, ATMCI_IDR
, ATMCI_DATA_ERROR_FLAGS
1769 | ATMCI_RXRDY
| ATMCI_TXRDY
);
1770 pending
&= atmci_readl(host
, ATMCI_IMR
);
1772 host
->data_status
= status
;
1774 atmci_set_pending(host
, EVENT_DATA_ERROR
);
1775 tasklet_schedule(&host
->tasklet
);
1778 if (pending
& ATMCI_TXBUFE
) {
1779 atmci_writel(host
, ATMCI_IDR
, ATMCI_TXBUFE
);
1780 atmci_writel(host
, ATMCI_IDR
, ATMCI_ENDTX
);
1782 * We can receive this interruption before having configured
1783 * the second pdc buffer, so we need to reconfigure first and
1784 * second buffers again
1786 if (host
->data_size
) {
1787 atmci_pdc_set_both_buf(host
, XFER_TRANSMIT
);
1788 atmci_writel(host
, ATMCI_IER
, ATMCI_ENDTX
);
1789 atmci_writel(host
, ATMCI_IER
, ATMCI_TXBUFE
);
1791 atmci_pdc_complete(host
);
1793 } else if (pending
& ATMCI_ENDTX
) {
1794 atmci_writel(host
, ATMCI_IDR
, ATMCI_ENDTX
);
1796 if (host
->data_size
) {
1797 atmci_pdc_set_single_buf(host
,
1798 XFER_TRANSMIT
, PDC_SECOND_BUF
);
1799 atmci_writel(host
, ATMCI_IER
, ATMCI_ENDTX
);
1803 if (pending
& ATMCI_RXBUFF
) {
1804 atmci_writel(host
, ATMCI_IDR
, ATMCI_RXBUFF
);
1805 atmci_writel(host
, ATMCI_IDR
, ATMCI_ENDRX
);
1807 * We can receive this interruption before having configured
1808 * the second pdc buffer, so we need to reconfigure first and
1809 * second buffers again
1811 if (host
->data_size
) {
1812 atmci_pdc_set_both_buf(host
, XFER_RECEIVE
);
1813 atmci_writel(host
, ATMCI_IER
, ATMCI_ENDRX
);
1814 atmci_writel(host
, ATMCI_IER
, ATMCI_RXBUFF
);
1816 atmci_pdc_complete(host
);
1818 } else if (pending
& ATMCI_ENDRX
) {
1819 atmci_writel(host
, ATMCI_IDR
, ATMCI_ENDRX
);
1821 if (host
->data_size
) {
1822 atmci_pdc_set_single_buf(host
,
1823 XFER_RECEIVE
, PDC_SECOND_BUF
);
1824 atmci_writel(host
, ATMCI_IER
, ATMCI_ENDRX
);
1829 if (pending
& ATMCI_NOTBUSY
) {
1830 atmci_writel(host
, ATMCI_IDR
,
1831 ATMCI_DATA_ERROR_FLAGS
| ATMCI_NOTBUSY
);
1832 if (!host
->data_status
)
1833 host
->data_status
= status
;
1835 atmci_set_pending(host
, EVENT_DATA_COMPLETE
);
1836 tasklet_schedule(&host
->tasklet
);
1838 if (pending
& ATMCI_RXRDY
)
1839 atmci_read_data_pio(host
);
1840 if (pending
& ATMCI_TXRDY
)
1841 atmci_write_data_pio(host
);
1843 if (pending
& ATMCI_CMDRDY
)
1844 atmci_cmd_interrupt(host
, status
);
1846 if (pending
& (ATMCI_SDIOIRQA
| ATMCI_SDIOIRQB
))
1847 atmci_sdio_interrupt(host
, status
);
1849 } while (pass_count
++ < 5);
1851 return pass_count
? IRQ_HANDLED
: IRQ_NONE
;
1854 static irqreturn_t
atmci_detect_interrupt(int irq
, void *dev_id
)
1856 struct atmel_mci_slot
*slot
= dev_id
;
1859 * Disable interrupts until the pin has stabilized and check
1860 * the state then. Use mod_timer() since we may be in the
1861 * middle of the timer routine when this interrupt triggers.
1863 disable_irq_nosync(irq
);
1864 mod_timer(&slot
->detect_timer
, jiffies
+ msecs_to_jiffies(20));
1869 static int __init
atmci_init_slot(struct atmel_mci
*host
,
1870 struct mci_slot_pdata
*slot_data
, unsigned int id
,
1871 u32 sdc_reg
, u32 sdio_irq
)
1873 struct mmc_host
*mmc
;
1874 struct atmel_mci_slot
*slot
;
1876 mmc
= mmc_alloc_host(sizeof(struct atmel_mci_slot
), &host
->pdev
->dev
);
1880 slot
= mmc_priv(mmc
);
1883 slot
->detect_pin
= slot_data
->detect_pin
;
1884 slot
->wp_pin
= slot_data
->wp_pin
;
1885 slot
->detect_is_active_high
= slot_data
->detect_is_active_high
;
1886 slot
->sdc_reg
= sdc_reg
;
1887 slot
->sdio_irq
= sdio_irq
;
1889 mmc
->ops
= &atmci_ops
;
1890 mmc
->f_min
= DIV_ROUND_UP(host
->bus_hz
, 512);
1891 mmc
->f_max
= host
->bus_hz
/ 2;
1892 mmc
->ocr_avail
= MMC_VDD_32_33
| MMC_VDD_33_34
;
1894 mmc
->caps
|= MMC_CAP_SDIO_IRQ
;
1895 if (host
->caps
.has_highspeed
)
1896 mmc
->caps
|= MMC_CAP_SD_HIGHSPEED
;
1897 if (slot_data
->bus_width
>= 4)
1898 mmc
->caps
|= MMC_CAP_4_BIT_DATA
;
1901 mmc
->max_req_size
= 32768 * 512;
1902 mmc
->max_blk_size
= 32768;
1903 mmc
->max_blk_count
= 512;
1905 /* Assume card is present initially */
1906 set_bit(ATMCI_CARD_PRESENT
, &slot
->flags
);
1907 if (gpio_is_valid(slot
->detect_pin
)) {
1908 if (gpio_request(slot
->detect_pin
, "mmc_detect")) {
1909 dev_dbg(&mmc
->class_dev
, "no detect pin available\n");
1910 slot
->detect_pin
= -EBUSY
;
1911 } else if (gpio_get_value(slot
->detect_pin
) ^
1912 slot
->detect_is_active_high
) {
1913 clear_bit(ATMCI_CARD_PRESENT
, &slot
->flags
);
1917 if (!gpio_is_valid(slot
->detect_pin
))
1918 mmc
->caps
|= MMC_CAP_NEEDS_POLL
;
1920 if (gpio_is_valid(slot
->wp_pin
)) {
1921 if (gpio_request(slot
->wp_pin
, "mmc_wp")) {
1922 dev_dbg(&mmc
->class_dev
, "no WP pin available\n");
1923 slot
->wp_pin
= -EBUSY
;
1927 host
->slot
[id
] = slot
;
1930 if (gpio_is_valid(slot
->detect_pin
)) {
1933 setup_timer(&slot
->detect_timer
, atmci_detect_change
,
1934 (unsigned long)slot
);
1936 ret
= request_irq(gpio_to_irq(slot
->detect_pin
),
1937 atmci_detect_interrupt
,
1938 IRQF_TRIGGER_FALLING
| IRQF_TRIGGER_RISING
,
1939 "mmc-detect", slot
);
1941 dev_dbg(&mmc
->class_dev
,
1942 "could not request IRQ %d for detect pin\n",
1943 gpio_to_irq(slot
->detect_pin
));
1944 gpio_free(slot
->detect_pin
);
1945 slot
->detect_pin
= -EBUSY
;
1949 atmci_init_debugfs(slot
);
1954 static void __exit
atmci_cleanup_slot(struct atmel_mci_slot
*slot
,
1957 /* Debugfs stuff is cleaned up by mmc core */
1959 set_bit(ATMCI_SHUTDOWN
, &slot
->flags
);
1962 mmc_remove_host(slot
->mmc
);
1964 if (gpio_is_valid(slot
->detect_pin
)) {
1965 int pin
= slot
->detect_pin
;
1967 free_irq(gpio_to_irq(pin
), slot
);
1968 del_timer_sync(&slot
->detect_timer
);
1971 if (gpio_is_valid(slot
->wp_pin
))
1972 gpio_free(slot
->wp_pin
);
1974 slot
->host
->slot
[id
] = NULL
;
1975 mmc_free_host(slot
->mmc
);
1978 static bool atmci_filter(struct dma_chan
*chan
, void *slave
)
1980 struct mci_dma_data
*sl
= slave
;
1982 if (sl
&& find_slave_dev(sl
) == chan
->device
->dev
) {
1983 chan
->private = slave_data_ptr(sl
);
1990 static bool atmci_configure_dma(struct atmel_mci
*host
)
1992 struct mci_platform_data
*pdata
;
1997 pdata
= host
->pdev
->dev
.platform_data
;
1999 if (pdata
&& find_slave_dev(pdata
->dma_slave
)) {
2000 dma_cap_mask_t mask
;
2002 /* Try to grab a DMA channel */
2004 dma_cap_set(DMA_SLAVE
, mask
);
2006 dma_request_channel(mask
, atmci_filter
, pdata
->dma_slave
);
2008 if (!host
->dma
.chan
) {
2009 dev_warn(&host
->pdev
->dev
, "no DMA channel available\n");
2012 dev_info(&host
->pdev
->dev
,
2013 "using %s for DMA transfers\n",
2014 dma_chan_name(host
->dma
.chan
));
2016 host
->dma_conf
.src_addr
= host
->mapbase
+ ATMCI_RDR
;
2017 host
->dma_conf
.src_addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
;
2018 host
->dma_conf
.src_maxburst
= 1;
2019 host
->dma_conf
.dst_addr
= host
->mapbase
+ ATMCI_TDR
;
2020 host
->dma_conf
.dst_addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
;
2021 host
->dma_conf
.dst_maxburst
= 1;
2022 host
->dma_conf
.device_fc
= false;
2027 static inline unsigned int atmci_get_version(struct atmel_mci
*host
)
2029 return atmci_readl(host
, ATMCI_VERSION
) & 0x00000fff;
2033 * HSMCI (High Speed MCI) module is not fully compatible with MCI module.
2034 * HSMCI provides DMA support and a new config register but no more supports
2037 static void __init
atmci_get_cap(struct atmel_mci
*host
)
2039 unsigned int version
;
2041 version
= atmci_get_version(host
);
2042 dev_info(&host
->pdev
->dev
,
2043 "version: 0x%x\n", version
);
2045 host
->caps
.has_dma
= 0;
2046 host
->caps
.has_pdc
= 1;
2047 host
->caps
.has_cfg_reg
= 0;
2048 host
->caps
.has_cstor_reg
= 0;
2049 host
->caps
.has_highspeed
= 0;
2050 host
->caps
.has_rwproof
= 0;
2051 host
->caps
.has_odd_clk_div
= 0;
2053 /* keep only major version number */
2054 switch (version
& 0xf00) {
2056 host
->caps
.has_odd_clk_div
= 1;
2059 #ifdef CONFIG_AT_HDMAC
2060 host
->caps
.has_dma
= 1;
2062 dev_info(&host
->pdev
->dev
,
2063 "has dma capability but dma engine is not selected, then use pio\n");
2065 host
->caps
.has_pdc
= 0;
2066 host
->caps
.has_cfg_reg
= 1;
2067 host
->caps
.has_cstor_reg
= 1;
2068 host
->caps
.has_highspeed
= 1;
2070 host
->caps
.has_rwproof
= 1;
2074 host
->caps
.has_pdc
= 0;
2075 dev_warn(&host
->pdev
->dev
,
2076 "Unmanaged mci version, set minimum capabilities\n");
2081 static int __init
atmci_probe(struct platform_device
*pdev
)
2083 struct mci_platform_data
*pdata
;
2084 struct atmel_mci
*host
;
2085 struct resource
*regs
;
2086 unsigned int nr_slots
;
2090 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2093 pdata
= pdev
->dev
.platform_data
;
2096 irq
= platform_get_irq(pdev
, 0);
2100 host
= kzalloc(sizeof(struct atmel_mci
), GFP_KERNEL
);
2105 spin_lock_init(&host
->lock
);
2106 INIT_LIST_HEAD(&host
->queue
);
2108 host
->mck
= clk_get(&pdev
->dev
, "mci_clk");
2109 if (IS_ERR(host
->mck
)) {
2110 ret
= PTR_ERR(host
->mck
);
2115 host
->regs
= ioremap(regs
->start
, resource_size(regs
));
2119 clk_enable(host
->mck
);
2120 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_SWRST
);
2121 host
->bus_hz
= clk_get_rate(host
->mck
);
2122 clk_disable(host
->mck
);
2124 host
->mapbase
= regs
->start
;
2126 tasklet_init(&host
->tasklet
, atmci_tasklet_func
, (unsigned long)host
);
2128 ret
= request_irq(irq
, atmci_interrupt
, 0, dev_name(&pdev
->dev
), host
);
2130 goto err_request_irq
;
2132 /* Get MCI capabilities and set operations according to it */
2133 atmci_get_cap(host
);
2134 if (host
->caps
.has_dma
&& atmci_configure_dma(host
)) {
2135 host
->prepare_data
= &atmci_prepare_data_dma
;
2136 host
->submit_data
= &atmci_submit_data_dma
;
2137 host
->stop_transfer
= &atmci_stop_transfer_dma
;
2138 } else if (host
->caps
.has_pdc
) {
2139 dev_info(&pdev
->dev
, "using PDC\n");
2140 host
->prepare_data
= &atmci_prepare_data_pdc
;
2141 host
->submit_data
= &atmci_submit_data_pdc
;
2142 host
->stop_transfer
= &atmci_stop_transfer_pdc
;
2144 dev_info(&pdev
->dev
, "using PIO\n");
2145 host
->prepare_data
= &atmci_prepare_data
;
2146 host
->submit_data
= &atmci_submit_data
;
2147 host
->stop_transfer
= &atmci_stop_transfer
;
2150 platform_set_drvdata(pdev
, host
);
2152 /* We need at least one slot to succeed */
2155 if (pdata
->slot
[0].bus_width
) {
2156 ret
= atmci_init_slot(host
, &pdata
->slot
[0],
2157 0, ATMCI_SDCSEL_SLOT_A
, ATMCI_SDIOIRQA
);
2161 if (pdata
->slot
[1].bus_width
) {
2162 ret
= atmci_init_slot(host
, &pdata
->slot
[1],
2163 1, ATMCI_SDCSEL_SLOT_B
, ATMCI_SDIOIRQB
);
2169 dev_err(&pdev
->dev
, "init failed: no slot defined\n");
2173 dev_info(&pdev
->dev
,
2174 "Atmel MCI controller at 0x%08lx irq %d, %u slots\n",
2175 host
->mapbase
, irq
, nr_slots
);
2181 dma_release_channel(host
->dma
.chan
);
2182 free_irq(irq
, host
);
2184 iounmap(host
->regs
);
2192 static int __exit
atmci_remove(struct platform_device
*pdev
)
2194 struct atmel_mci
*host
= platform_get_drvdata(pdev
);
2197 platform_set_drvdata(pdev
, NULL
);
2199 for (i
= 0; i
< ATMCI_MAX_NR_SLOTS
; i
++) {
2201 atmci_cleanup_slot(host
->slot
[i
], i
);
2204 clk_enable(host
->mck
);
2205 atmci_writel(host
, ATMCI_IDR
, ~0UL);
2206 atmci_writel(host
, ATMCI_CR
, ATMCI_CR_MCIDIS
);
2207 atmci_readl(host
, ATMCI_SR
);
2208 clk_disable(host
->mck
);
2211 dma_release_channel(host
->dma
.chan
);
2213 free_irq(platform_get_irq(pdev
, 0), host
);
2214 iounmap(host
->regs
);
2223 static int atmci_suspend(struct device
*dev
)
2225 struct atmel_mci
*host
= dev_get_drvdata(dev
);
2228 for (i
= 0; i
< ATMCI_MAX_NR_SLOTS
; i
++) {
2229 struct atmel_mci_slot
*slot
= host
->slot
[i
];
2234 ret
= mmc_suspend_host(slot
->mmc
);
2237 slot
= host
->slot
[i
];
2239 && test_bit(ATMCI_SUSPENDED
, &slot
->flags
)) {
2240 mmc_resume_host(host
->slot
[i
]->mmc
);
2241 clear_bit(ATMCI_SUSPENDED
, &slot
->flags
);
2246 set_bit(ATMCI_SUSPENDED
, &slot
->flags
);
2253 static int atmci_resume(struct device
*dev
)
2255 struct atmel_mci
*host
= dev_get_drvdata(dev
);
2259 for (i
= 0; i
< ATMCI_MAX_NR_SLOTS
; i
++) {
2260 struct atmel_mci_slot
*slot
= host
->slot
[i
];
2263 slot
= host
->slot
[i
];
2266 if (!test_bit(ATMCI_SUSPENDED
, &slot
->flags
))
2268 err
= mmc_resume_host(slot
->mmc
);
2272 clear_bit(ATMCI_SUSPENDED
, &slot
->flags
);
2277 static SIMPLE_DEV_PM_OPS(atmci_pm
, atmci_suspend
, atmci_resume
);
2278 #define ATMCI_PM_OPS (&atmci_pm)
2280 #define ATMCI_PM_OPS NULL
2283 static struct platform_driver atmci_driver
= {
2284 .remove
= __exit_p(atmci_remove
),
2286 .name
= "atmel_mci",
2291 static int __init
atmci_init(void)
2293 return platform_driver_probe(&atmci_driver
, atmci_probe
);
2296 static void __exit
atmci_exit(void)
2298 platform_driver_unregister(&atmci_driver
);
2301 late_initcall(atmci_init
); /* try to load after dma driver when built-in */
2302 module_exit(atmci_exit
);
2304 MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
2305 MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
2306 MODULE_LICENSE("GPL v2");