2 * Portions copyright (C) 2003 Russell King, PXA MMCI Driver
3 * Portions copyright (C) 2004-2005 Pierre Ossman, W83L51xD SD/MMC driver
5 * Copyright 2008 Embedded Alley Solutions, Inc.
6 * Copyright 2009-2011 Freescale Semiconductor, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/ioport.h>
27 #include <linux/of_device.h>
28 #include <linux/of_gpio.h>
29 #include <linux/platform_device.h>
30 #include <linux/delay.h>
31 #include <linux/interrupt.h>
32 #include <linux/dma-mapping.h>
33 #include <linux/dmaengine.h>
34 #include <linux/highmem.h>
35 #include <linux/clk.h>
36 #include <linux/err.h>
37 #include <linux/completion.h>
38 #include <linux/mmc/host.h>
39 #include <linux/mmc/mmc.h>
40 #include <linux/mmc/sdio.h>
41 #include <linux/mmc/slot-gpio.h>
42 #include <linux/gpio.h>
43 #include <linux/regulator/consumer.h>
44 #include <linux/module.h>
45 #include <linux/stmp_device.h>
46 #include <linux/spi/mxs-spi.h>
48 #define DRIVER_NAME "mxs-mmc"
50 #define MXS_MMC_IRQ_BITS (BM_SSP_CTRL1_SDIO_IRQ | \
51 BM_SSP_CTRL1_RESP_ERR_IRQ | \
52 BM_SSP_CTRL1_RESP_TIMEOUT_IRQ | \
53 BM_SSP_CTRL1_DATA_TIMEOUT_IRQ | \
54 BM_SSP_CTRL1_DATA_CRC_IRQ | \
55 BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ | \
56 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ | \
57 BM_SSP_CTRL1_FIFO_OVERRUN_IRQ)
59 /* card detect polling timeout */
60 #define MXS_MMC_DETECT_TIMEOUT (HZ/2)
66 struct mmc_request
*mrq
;
67 struct mmc_command
*cmd
;
68 struct mmc_data
*data
;
70 unsigned char bus_width
;
75 static int mxs_mmc_get_cd(struct mmc_host
*mmc
)
77 struct mxs_mmc_host
*host
= mmc_priv(mmc
);
78 struct mxs_ssp
*ssp
= &host
->ssp
;
81 ret
= mmc_gpio_get_cd(mmc
);
85 present
= !(readl(ssp
->base
+ HW_SSP_STATUS(ssp
)) &
86 BM_SSP_STATUS_CARD_DETECT
);
88 if (mmc
->caps2
& MMC_CAP2_CD_ACTIVE_HIGH
)
94 static int mxs_mmc_reset(struct mxs_mmc_host
*host
)
96 struct mxs_ssp
*ssp
= &host
->ssp
;
100 ret
= stmp_reset_block(ssp
->base
);
104 ctrl0
= BM_SSP_CTRL0_IGNORE_CRC
;
105 ctrl1
= BF_SSP(0x3, CTRL1_SSP_MODE
) |
106 BF_SSP(0x7, CTRL1_WORD_LENGTH
) |
107 BM_SSP_CTRL1_DMA_ENABLE
|
108 BM_SSP_CTRL1_POLARITY
|
109 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ_EN
|
110 BM_SSP_CTRL1_DATA_CRC_IRQ_EN
|
111 BM_SSP_CTRL1_DATA_TIMEOUT_IRQ_EN
|
112 BM_SSP_CTRL1_RESP_TIMEOUT_IRQ_EN
|
113 BM_SSP_CTRL1_RESP_ERR_IRQ_EN
;
115 writel(BF_SSP(0xffff, TIMING_TIMEOUT
) |
116 BF_SSP(2, TIMING_CLOCK_DIVIDE
) |
117 BF_SSP(0, TIMING_CLOCK_RATE
),
118 ssp
->base
+ HW_SSP_TIMING(ssp
));
120 if (host
->sdio_irq_en
) {
121 ctrl0
|= BM_SSP_CTRL0_SDIO_IRQ_CHECK
;
122 ctrl1
|= BM_SSP_CTRL1_SDIO_IRQ_EN
;
125 writel(ctrl0
, ssp
->base
+ HW_SSP_CTRL0
);
126 writel(ctrl1
, ssp
->base
+ HW_SSP_CTRL1(ssp
));
130 static void mxs_mmc_start_cmd(struct mxs_mmc_host
*host
,
131 struct mmc_command
*cmd
);
133 static void mxs_mmc_request_done(struct mxs_mmc_host
*host
)
135 struct mmc_command
*cmd
= host
->cmd
;
136 struct mmc_data
*data
= host
->data
;
137 struct mmc_request
*mrq
= host
->mrq
;
138 struct mxs_ssp
*ssp
= &host
->ssp
;
140 if (mmc_resp_type(cmd
) & MMC_RSP_PRESENT
) {
141 if (mmc_resp_type(cmd
) & MMC_RSP_136
) {
142 cmd
->resp
[3] = readl(ssp
->base
+ HW_SSP_SDRESP0(ssp
));
143 cmd
->resp
[2] = readl(ssp
->base
+ HW_SSP_SDRESP1(ssp
));
144 cmd
->resp
[1] = readl(ssp
->base
+ HW_SSP_SDRESP2(ssp
));
145 cmd
->resp
[0] = readl(ssp
->base
+ HW_SSP_SDRESP3(ssp
));
147 cmd
->resp
[0] = readl(ssp
->base
+ HW_SSP_SDRESP0(ssp
));
152 dma_unmap_sg(mmc_dev(host
->mmc
), data
->sg
,
153 data
->sg_len
, ssp
->dma_dir
);
155 * If there was an error on any block, we mark all
156 * data blocks as being in error.
159 data
->bytes_xfered
= data
->blocks
* data
->blksz
;
161 data
->bytes_xfered
= 0;
165 mxs_mmc_start_cmd(host
, mrq
->stop
);
171 mmc_request_done(host
->mmc
, mrq
);
174 static void mxs_mmc_dma_irq_callback(void *param
)
176 struct mxs_mmc_host
*host
= param
;
178 mxs_mmc_request_done(host
);
181 static irqreturn_t
mxs_mmc_irq_handler(int irq
, void *dev_id
)
183 struct mxs_mmc_host
*host
= dev_id
;
184 struct mmc_command
*cmd
= host
->cmd
;
185 struct mmc_data
*data
= host
->data
;
186 struct mxs_ssp
*ssp
= &host
->ssp
;
189 spin_lock(&host
->lock
);
191 stat
= readl(ssp
->base
+ HW_SSP_CTRL1(ssp
));
192 writel(stat
& MXS_MMC_IRQ_BITS
,
193 ssp
->base
+ HW_SSP_CTRL1(ssp
) + STMP_OFFSET_REG_CLR
);
195 spin_unlock(&host
->lock
);
197 if ((stat
& BM_SSP_CTRL1_SDIO_IRQ
) && (stat
& BM_SSP_CTRL1_SDIO_IRQ_EN
))
198 mmc_signal_sdio_irq(host
->mmc
);
200 if (stat
& BM_SSP_CTRL1_RESP_TIMEOUT_IRQ
)
201 cmd
->error
= -ETIMEDOUT
;
202 else if (stat
& BM_SSP_CTRL1_RESP_ERR_IRQ
)
206 if (stat
& (BM_SSP_CTRL1_DATA_TIMEOUT_IRQ
|
207 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ
))
208 data
->error
= -ETIMEDOUT
;
209 else if (stat
& BM_SSP_CTRL1_DATA_CRC_IRQ
)
210 data
->error
= -EILSEQ
;
211 else if (stat
& (BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ
|
212 BM_SSP_CTRL1_FIFO_OVERRUN_IRQ
))
219 static struct dma_async_tx_descriptor
*mxs_mmc_prep_dma(
220 struct mxs_mmc_host
*host
, unsigned long flags
)
222 struct mxs_ssp
*ssp
= &host
->ssp
;
223 struct dma_async_tx_descriptor
*desc
;
224 struct mmc_data
*data
= host
->data
;
225 struct scatterlist
* sgl
;
230 dma_map_sg(mmc_dev(host
->mmc
), data
->sg
,
231 data
->sg_len
, ssp
->dma_dir
);
233 sg_len
= data
->sg_len
;
236 sgl
= (struct scatterlist
*) ssp
->ssp_pio_words
;
237 sg_len
= SSP_PIO_NUM
;
240 desc
= dmaengine_prep_slave_sg(ssp
->dmach
,
241 sgl
, sg_len
, ssp
->slave_dirn
, flags
);
243 desc
->callback
= mxs_mmc_dma_irq_callback
;
244 desc
->callback_param
= host
;
247 dma_unmap_sg(mmc_dev(host
->mmc
), data
->sg
,
248 data
->sg_len
, ssp
->dma_dir
);
254 static void mxs_mmc_bc(struct mxs_mmc_host
*host
)
256 struct mxs_ssp
*ssp
= &host
->ssp
;
257 struct mmc_command
*cmd
= host
->cmd
;
258 struct dma_async_tx_descriptor
*desc
;
259 u32 ctrl0
, cmd0
, cmd1
;
261 ctrl0
= BM_SSP_CTRL0_ENABLE
| BM_SSP_CTRL0_IGNORE_CRC
;
262 cmd0
= BF_SSP(cmd
->opcode
, CMD0_CMD
) | BM_SSP_CMD0_APPEND_8CYC
;
265 if (host
->sdio_irq_en
) {
266 ctrl0
|= BM_SSP_CTRL0_SDIO_IRQ_CHECK
;
267 cmd0
|= BM_SSP_CMD0_CONT_CLKING_EN
| BM_SSP_CMD0_SLOW_CLKING_EN
;
270 ssp
->ssp_pio_words
[0] = ctrl0
;
271 ssp
->ssp_pio_words
[1] = cmd0
;
272 ssp
->ssp_pio_words
[2] = cmd1
;
273 ssp
->dma_dir
= DMA_NONE
;
274 ssp
->slave_dirn
= DMA_TRANS_NONE
;
275 desc
= mxs_mmc_prep_dma(host
, DMA_CTRL_ACK
);
279 dmaengine_submit(desc
);
280 dma_async_issue_pending(ssp
->dmach
);
284 dev_warn(mmc_dev(host
->mmc
),
285 "%s: failed to prep dma\n", __func__
);
288 static void mxs_mmc_ac(struct mxs_mmc_host
*host
)
290 struct mxs_ssp
*ssp
= &host
->ssp
;
291 struct mmc_command
*cmd
= host
->cmd
;
292 struct dma_async_tx_descriptor
*desc
;
293 u32 ignore_crc
, get_resp
, long_resp
;
294 u32 ctrl0
, cmd0
, cmd1
;
296 ignore_crc
= (mmc_resp_type(cmd
) & MMC_RSP_CRC
) ?
297 0 : BM_SSP_CTRL0_IGNORE_CRC
;
298 get_resp
= (mmc_resp_type(cmd
) & MMC_RSP_PRESENT
) ?
299 BM_SSP_CTRL0_GET_RESP
: 0;
300 long_resp
= (mmc_resp_type(cmd
) & MMC_RSP_136
) ?
301 BM_SSP_CTRL0_LONG_RESP
: 0;
303 ctrl0
= BM_SSP_CTRL0_ENABLE
| ignore_crc
| get_resp
| long_resp
;
304 cmd0
= BF_SSP(cmd
->opcode
, CMD0_CMD
);
307 if (host
->sdio_irq_en
) {
308 ctrl0
|= BM_SSP_CTRL0_SDIO_IRQ_CHECK
;
309 cmd0
|= BM_SSP_CMD0_CONT_CLKING_EN
| BM_SSP_CMD0_SLOW_CLKING_EN
;
312 ssp
->ssp_pio_words
[0] = ctrl0
;
313 ssp
->ssp_pio_words
[1] = cmd0
;
314 ssp
->ssp_pio_words
[2] = cmd1
;
315 ssp
->dma_dir
= DMA_NONE
;
316 ssp
->slave_dirn
= DMA_TRANS_NONE
;
317 desc
= mxs_mmc_prep_dma(host
, DMA_CTRL_ACK
);
321 dmaengine_submit(desc
);
322 dma_async_issue_pending(ssp
->dmach
);
326 dev_warn(mmc_dev(host
->mmc
),
327 "%s: failed to prep dma\n", __func__
);
330 static unsigned short mxs_ns_to_ssp_ticks(unsigned clock_rate
, unsigned ns
)
332 const unsigned int ssp_timeout_mul
= 4096;
334 * Calculate ticks in ms since ns are large numbers
337 const unsigned int clock_per_ms
= clock_rate
/ 1000;
338 const unsigned int ms
= ns
/ 1000;
339 const unsigned int ticks
= ms
* clock_per_ms
;
340 const unsigned int ssp_ticks
= ticks
/ ssp_timeout_mul
;
342 WARN_ON(ssp_ticks
== 0);
346 static void mxs_mmc_adtc(struct mxs_mmc_host
*host
)
348 struct mmc_command
*cmd
= host
->cmd
;
349 struct mmc_data
*data
= cmd
->data
;
350 struct dma_async_tx_descriptor
*desc
;
351 struct scatterlist
*sgl
= data
->sg
, *sg
;
352 unsigned int sg_len
= data
->sg_len
;
355 unsigned short dma_data_dir
, timeout
;
356 enum dma_transfer_direction slave_dirn
;
357 unsigned int data_size
= 0, log2_blksz
;
358 unsigned int blocks
= data
->blocks
;
360 struct mxs_ssp
*ssp
= &host
->ssp
;
362 u32 ignore_crc
, get_resp
, long_resp
, read
;
363 u32 ctrl0
, cmd0
, cmd1
, val
;
365 ignore_crc
= (mmc_resp_type(cmd
) & MMC_RSP_CRC
) ?
366 0 : BM_SSP_CTRL0_IGNORE_CRC
;
367 get_resp
= (mmc_resp_type(cmd
) & MMC_RSP_PRESENT
) ?
368 BM_SSP_CTRL0_GET_RESP
: 0;
369 long_resp
= (mmc_resp_type(cmd
) & MMC_RSP_136
) ?
370 BM_SSP_CTRL0_LONG_RESP
: 0;
372 if (data
->flags
& MMC_DATA_WRITE
) {
373 dma_data_dir
= DMA_TO_DEVICE
;
374 slave_dirn
= DMA_MEM_TO_DEV
;
377 dma_data_dir
= DMA_FROM_DEVICE
;
378 slave_dirn
= DMA_DEV_TO_MEM
;
379 read
= BM_SSP_CTRL0_READ
;
382 ctrl0
= BF_SSP(host
->bus_width
, CTRL0_BUS_WIDTH
) |
383 ignore_crc
| get_resp
| long_resp
|
384 BM_SSP_CTRL0_DATA_XFER
| read
|
385 BM_SSP_CTRL0_WAIT_FOR_IRQ
|
388 cmd0
= BF_SSP(cmd
->opcode
, CMD0_CMD
);
390 /* get logarithm to base 2 of block size for setting register */
391 log2_blksz
= ilog2(data
->blksz
);
394 * take special care of the case that data size from data->sg
395 * is not equal to blocks x blksz
397 for_each_sg(sgl
, sg
, sg_len
, i
)
398 data_size
+= sg
->length
;
400 if (data_size
!= data
->blocks
* data
->blksz
)
403 /* xfer count, block size and count need to be set differently */
404 if (ssp_is_old(ssp
)) {
405 ctrl0
|= BF_SSP(data_size
, CTRL0_XFER_COUNT
);
406 cmd0
|= BF_SSP(log2_blksz
, CMD0_BLOCK_SIZE
) |
407 BF_SSP(blocks
- 1, CMD0_BLOCK_COUNT
);
409 writel(data_size
, ssp
->base
+ HW_SSP_XFER_SIZE
);
410 writel(BF_SSP(log2_blksz
, BLOCK_SIZE_BLOCK_SIZE
) |
411 BF_SSP(blocks
- 1, BLOCK_SIZE_BLOCK_COUNT
),
412 ssp
->base
+ HW_SSP_BLOCK_SIZE
);
415 if ((cmd
->opcode
== MMC_STOP_TRANSMISSION
) ||
416 (cmd
->opcode
== SD_IO_RW_EXTENDED
))
417 cmd0
|= BM_SSP_CMD0_APPEND_8CYC
;
421 if (host
->sdio_irq_en
) {
422 ctrl0
|= BM_SSP_CTRL0_SDIO_IRQ_CHECK
;
423 cmd0
|= BM_SSP_CMD0_CONT_CLKING_EN
| BM_SSP_CMD0_SLOW_CLKING_EN
;
426 /* set the timeout count */
427 timeout
= mxs_ns_to_ssp_ticks(ssp
->clk_rate
, data
->timeout_ns
);
428 val
= readl(ssp
->base
+ HW_SSP_TIMING(ssp
));
429 val
&= ~(BM_SSP_TIMING_TIMEOUT
);
430 val
|= BF_SSP(timeout
, TIMING_TIMEOUT
);
431 writel(val
, ssp
->base
+ HW_SSP_TIMING(ssp
));
434 ssp
->ssp_pio_words
[0] = ctrl0
;
435 ssp
->ssp_pio_words
[1] = cmd0
;
436 ssp
->ssp_pio_words
[2] = cmd1
;
437 ssp
->dma_dir
= DMA_NONE
;
438 ssp
->slave_dirn
= DMA_TRANS_NONE
;
439 desc
= mxs_mmc_prep_dma(host
, 0);
444 WARN_ON(host
->data
!= NULL
);
446 ssp
->dma_dir
= dma_data_dir
;
447 ssp
->slave_dirn
= slave_dirn
;
448 desc
= mxs_mmc_prep_dma(host
, DMA_PREP_INTERRUPT
| DMA_CTRL_ACK
);
452 dmaengine_submit(desc
);
453 dma_async_issue_pending(ssp
->dmach
);
456 dev_warn(mmc_dev(host
->mmc
),
457 "%s: failed to prep dma\n", __func__
);
460 static void mxs_mmc_start_cmd(struct mxs_mmc_host
*host
,
461 struct mmc_command
*cmd
)
465 switch (mmc_cmd_type(cmd
)) {
479 dev_warn(mmc_dev(host
->mmc
),
480 "%s: unknown MMC command\n", __func__
);
485 static void mxs_mmc_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
487 struct mxs_mmc_host
*host
= mmc_priv(mmc
);
489 WARN_ON(host
->mrq
!= NULL
);
491 mxs_mmc_start_cmd(host
, mrq
->cmd
);
494 static void mxs_mmc_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
496 struct mxs_mmc_host
*host
= mmc_priv(mmc
);
498 if (ios
->bus_width
== MMC_BUS_WIDTH_8
)
500 else if (ios
->bus_width
== MMC_BUS_WIDTH_4
)
506 mxs_ssp_set_clk_rate(&host
->ssp
, ios
->clock
);
509 static void mxs_mmc_enable_sdio_irq(struct mmc_host
*mmc
, int enable
)
511 struct mxs_mmc_host
*host
= mmc_priv(mmc
);
512 struct mxs_ssp
*ssp
= &host
->ssp
;
515 spin_lock_irqsave(&host
->lock
, flags
);
517 host
->sdio_irq_en
= enable
;
520 writel(BM_SSP_CTRL0_SDIO_IRQ_CHECK
,
521 ssp
->base
+ HW_SSP_CTRL0
+ STMP_OFFSET_REG_SET
);
522 writel(BM_SSP_CTRL1_SDIO_IRQ_EN
,
523 ssp
->base
+ HW_SSP_CTRL1(ssp
) + STMP_OFFSET_REG_SET
);
525 writel(BM_SSP_CTRL0_SDIO_IRQ_CHECK
,
526 ssp
->base
+ HW_SSP_CTRL0
+ STMP_OFFSET_REG_CLR
);
527 writel(BM_SSP_CTRL1_SDIO_IRQ_EN
,
528 ssp
->base
+ HW_SSP_CTRL1(ssp
) + STMP_OFFSET_REG_CLR
);
531 spin_unlock_irqrestore(&host
->lock
, flags
);
533 if (enable
&& readl(ssp
->base
+ HW_SSP_STATUS(ssp
)) &
534 BM_SSP_STATUS_SDIO_IRQ
)
535 mmc_signal_sdio_irq(host
->mmc
);
539 static const struct mmc_host_ops mxs_mmc_ops
= {
540 .request
= mxs_mmc_request
,
541 .get_ro
= mmc_gpio_get_ro
,
542 .get_cd
= mxs_mmc_get_cd
,
543 .set_ios
= mxs_mmc_set_ios
,
544 .enable_sdio_irq
= mxs_mmc_enable_sdio_irq
,
547 static struct platform_device_id mxs_ssp_ids
[] = {
550 .driver_data
= IMX23_SSP
,
553 .driver_data
= IMX28_SSP
,
558 MODULE_DEVICE_TABLE(platform
, mxs_ssp_ids
);
560 static const struct of_device_id mxs_mmc_dt_ids
[] = {
561 { .compatible
= "fsl,imx23-mmc", .data
= (void *) IMX23_SSP
, },
562 { .compatible
= "fsl,imx28-mmc", .data
= (void *) IMX28_SSP
, },
565 MODULE_DEVICE_TABLE(of
, mxs_mmc_dt_ids
);
567 static int mxs_mmc_probe(struct platform_device
*pdev
)
569 const struct of_device_id
*of_id
=
570 of_match_device(mxs_mmc_dt_ids
, &pdev
->dev
);
571 struct mxs_mmc_host
*host
;
572 struct mmc_host
*mmc
;
573 struct resource
*iores
;
574 int ret
= 0, irq_err
;
575 struct regulator
*reg_vmmc
;
578 iores
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
579 irq_err
= platform_get_irq(pdev
, 0);
580 if (!iores
|| irq_err
< 0)
583 mmc
= mmc_alloc_host(sizeof(struct mxs_mmc_host
), &pdev
->dev
);
587 host
= mmc_priv(mmc
);
589 ssp
->dev
= &pdev
->dev
;
590 ssp
->base
= devm_ioremap_resource(&pdev
->dev
, iores
);
591 if (IS_ERR(ssp
->base
)) {
592 ret
= PTR_ERR(ssp
->base
);
596 ssp
->devid
= (enum mxs_ssp_id
) of_id
->data
;
599 host
->sdio_irq_en
= 0;
601 reg_vmmc
= devm_regulator_get(&pdev
->dev
, "vmmc");
602 if (!IS_ERR(reg_vmmc
)) {
603 ret
= regulator_enable(reg_vmmc
);
606 "Failed to enable vmmc regulator: %d\n", ret
);
611 ssp
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
612 if (IS_ERR(ssp
->clk
)) {
613 ret
= PTR_ERR(ssp
->clk
);
616 clk_prepare_enable(ssp
->clk
);
618 ret
= mxs_mmc_reset(host
);
620 dev_err(&pdev
->dev
, "Failed to reset mmc: %d\n", ret
);
621 goto out_clk_disable
;
624 ssp
->dmach
= dma_request_slave_channel(&pdev
->dev
, "rx-tx");
626 dev_err(mmc_dev(host
->mmc
),
627 "%s: failed to request dma\n", __func__
);
629 goto out_clk_disable
;
632 /* set mmc core parameters */
633 mmc
->ops
= &mxs_mmc_ops
;
634 mmc
->caps
= MMC_CAP_SD_HIGHSPEED
| MMC_CAP_MMC_HIGHSPEED
|
635 MMC_CAP_SDIO_IRQ
| MMC_CAP_NEEDS_POLL
;
638 mmc
->f_max
= 288000000;
640 ret
= mmc_of_parse(mmc
);
642 goto out_clk_disable
;
644 mmc
->ocr_avail
= MMC_VDD_32_33
| MMC_VDD_33_34
;
647 mmc
->max_blk_size
= 1 << 0xf;
648 mmc
->max_blk_count
= (ssp_is_old(ssp
)) ? 0xff : 0xffffff;
649 mmc
->max_req_size
= (ssp_is_old(ssp
)) ? 0xffff : 0xffffffff;
650 mmc
->max_seg_size
= dma_get_max_seg_size(ssp
->dmach
->device
->dev
);
652 platform_set_drvdata(pdev
, mmc
);
654 ret
= devm_request_irq(&pdev
->dev
, irq_err
, mxs_mmc_irq_handler
, 0,
659 spin_lock_init(&host
->lock
);
661 ret
= mmc_add_host(mmc
);
665 dev_info(mmc_dev(host
->mmc
), "initialized\n");
671 dma_release_channel(ssp
->dmach
);
673 clk_disable_unprepare(ssp
->clk
);
679 static int mxs_mmc_remove(struct platform_device
*pdev
)
681 struct mmc_host
*mmc
= platform_get_drvdata(pdev
);
682 struct mxs_mmc_host
*host
= mmc_priv(mmc
);
683 struct mxs_ssp
*ssp
= &host
->ssp
;
685 mmc_remove_host(mmc
);
688 dma_release_channel(ssp
->dmach
);
690 clk_disable_unprepare(ssp
->clk
);
698 static int mxs_mmc_suspend(struct device
*dev
)
700 struct mmc_host
*mmc
= dev_get_drvdata(dev
);
701 struct mxs_mmc_host
*host
= mmc_priv(mmc
);
702 struct mxs_ssp
*ssp
= &host
->ssp
;
704 clk_disable_unprepare(ssp
->clk
);
708 static int mxs_mmc_resume(struct device
*dev
)
710 struct mmc_host
*mmc
= dev_get_drvdata(dev
);
711 struct mxs_mmc_host
*host
= mmc_priv(mmc
);
712 struct mxs_ssp
*ssp
= &host
->ssp
;
714 clk_prepare_enable(ssp
->clk
);
718 static const struct dev_pm_ops mxs_mmc_pm_ops
= {
719 .suspend
= mxs_mmc_suspend
,
720 .resume
= mxs_mmc_resume
,
724 static struct platform_driver mxs_mmc_driver
= {
725 .probe
= mxs_mmc_probe
,
726 .remove
= mxs_mmc_remove
,
727 .id_table
= mxs_ssp_ids
,
730 .owner
= THIS_MODULE
,
732 .pm
= &mxs_mmc_pm_ops
,
734 .of_match_table
= mxs_mmc_dt_ids
,
738 module_platform_driver(mxs_mmc_driver
);
740 MODULE_DESCRIPTION("FREESCALE MXS MMC peripheral");
741 MODULE_AUTHOR("Freescale Semiconductor");
742 MODULE_LICENSE("GPL");
743 MODULE_ALIAS("platform:" DRIVER_NAME
);