2 * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver
4 * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
5 * Copyright (C) 2010 ST-Ericsson AB.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/device.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/highmem.h>
21 #include <linux/log2.h>
22 #include <linux/mmc/host.h>
23 #include <linux/mmc/card.h>
24 #include <linux/amba/bus.h>
25 #include <linux/clk.h>
26 #include <linux/scatterlist.h>
27 #include <linux/gpio.h>
28 #include <linux/amba/mmci.h>
29 #include <linux/regulator/consumer.h>
31 #include <asm/div64.h>
33 #include <asm/sizes.h>
37 #define DRIVER_NAME "mmci-pl18x"
39 static unsigned int fmax
= 515633;
42 * struct variant_data - MMCI variant-specific quirks
43 * @clkreg: default value for MCICLOCK register
44 * @clkreg_enable: enable value for MMCICLOCK register
45 * @datalength_bits: number of bits in the MMCIDATALENGTH register
46 * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY
47 * is asserted (likewise for RX)
48 * @fifohalfsize: number of bytes that can be written when MCI_TXFIFOHALFEMPTY
49 * is asserted (likewise for RX)
50 * @sdio: variant supports SDIO
51 * @st_clkdiv: true if using a ST-specific clock divider algorithm
55 unsigned int clkreg_enable
;
56 unsigned int datalength_bits
;
57 unsigned int fifosize
;
58 unsigned int fifohalfsize
;
63 static struct variant_data variant_arm
= {
65 .fifohalfsize
= 8 * 4,
66 .datalength_bits
= 16,
69 static struct variant_data variant_u300
= {
71 .fifohalfsize
= 8 * 4,
72 .clkreg_enable
= 1 << 13, /* HWFCEN */
73 .datalength_bits
= 16,
77 static struct variant_data variant_ux500
= {
79 .fifohalfsize
= 8 * 4,
80 .clkreg
= MCI_CLK_ENABLE
,
81 .clkreg_enable
= 1 << 14, /* HWFCEN */
82 .datalength_bits
= 24,
88 * This must be called with host->lock held
90 static void mmci_set_clkreg(struct mmci_host
*host
, unsigned int desired
)
92 struct variant_data
*variant
= host
->variant
;
93 u32 clk
= variant
->clkreg
;
96 if (desired
>= host
->mclk
) {
98 host
->cclk
= host
->mclk
;
99 } else if (variant
->st_clkdiv
) {
101 * DB8500 TRM says f = mclk / (clkdiv + 2)
102 * => clkdiv = (mclk / f) - 2
103 * Round the divider up so we don't exceed the max
106 clk
= DIV_ROUND_UP(host
->mclk
, desired
) - 2;
109 host
->cclk
= host
->mclk
/ (clk
+ 2);
112 * PL180 TRM says f = mclk / (2 * (clkdiv + 1))
113 * => clkdiv = mclk / (2 * f) - 1
115 clk
= host
->mclk
/ (2 * desired
) - 1;
118 host
->cclk
= host
->mclk
/ (2 * (clk
+ 1));
121 clk
|= variant
->clkreg_enable
;
122 clk
|= MCI_CLK_ENABLE
;
123 /* This hasn't proven to be worthwhile */
124 /* clk |= MCI_CLK_PWRSAVE; */
127 if (host
->mmc
->ios
.bus_width
== MMC_BUS_WIDTH_4
)
129 if (host
->mmc
->ios
.bus_width
== MMC_BUS_WIDTH_8
)
130 clk
|= MCI_ST_8BIT_BUS
;
132 writel(clk
, host
->base
+ MMCICLOCK
);
136 mmci_request_end(struct mmci_host
*host
, struct mmc_request
*mrq
)
138 writel(0, host
->base
+ MMCICOMMAND
);
146 mrq
->data
->bytes_xfered
= host
->data_xfered
;
149 * Need to drop the host lock here; mmc_request_done may call
150 * back into the driver...
152 spin_unlock(&host
->lock
);
153 mmc_request_done(host
->mmc
, mrq
);
154 spin_lock(&host
->lock
);
157 static void mmci_set_mask1(struct mmci_host
*host
, unsigned int mask
)
159 void __iomem
*base
= host
->base
;
161 if (host
->singleirq
) {
162 unsigned int mask0
= readl(base
+ MMCIMASK0
);
164 mask0
&= ~MCI_IRQ1MASK
;
167 writel(mask0
, base
+ MMCIMASK0
);
170 writel(mask
, base
+ MMCIMASK1
);
173 static void mmci_stop_data(struct mmci_host
*host
)
175 writel(0, host
->base
+ MMCIDATACTRL
);
176 mmci_set_mask1(host
, 0);
180 static void mmci_init_sg(struct mmci_host
*host
, struct mmc_data
*data
)
182 unsigned int flags
= SG_MITER_ATOMIC
;
184 if (data
->flags
& MMC_DATA_READ
)
185 flags
|= SG_MITER_TO_SG
;
187 flags
|= SG_MITER_FROM_SG
;
189 sg_miter_start(&host
->sg_miter
, data
->sg
, data
->sg_len
, flags
);
192 static void mmci_start_data(struct mmci_host
*host
, struct mmc_data
*data
)
194 struct variant_data
*variant
= host
->variant
;
195 unsigned int datactrl
, timeout
, irqmask
;
196 unsigned long long clks
;
200 dev_dbg(mmc_dev(host
->mmc
), "blksz %04x blks %04x flags %08x\n",
201 data
->blksz
, data
->blocks
, data
->flags
);
204 host
->size
= data
->blksz
* data
->blocks
;
205 host
->data_xfered
= 0;
207 mmci_init_sg(host
, data
);
209 clks
= (unsigned long long)data
->timeout_ns
* host
->cclk
;
210 do_div(clks
, 1000000000UL);
212 timeout
= data
->timeout_clks
+ (unsigned int)clks
;
215 writel(timeout
, base
+ MMCIDATATIMER
);
216 writel(host
->size
, base
+ MMCIDATALENGTH
);
218 blksz_bits
= ffs(data
->blksz
) - 1;
219 BUG_ON(1 << blksz_bits
!= data
->blksz
);
221 datactrl
= MCI_DPSM_ENABLE
| blksz_bits
<< 4;
222 if (data
->flags
& MMC_DATA_READ
) {
223 datactrl
|= MCI_DPSM_DIRECTION
;
224 irqmask
= MCI_RXFIFOHALFFULLMASK
;
227 * If we have less than a FIFOSIZE of bytes to transfer,
228 * trigger a PIO interrupt as soon as any data is available.
230 if (host
->size
< variant
->fifosize
)
231 irqmask
|= MCI_RXDATAAVLBLMASK
;
234 * We don't actually need to include "FIFO empty" here
235 * since its implicit in "FIFO half empty".
237 irqmask
= MCI_TXFIFOHALFEMPTYMASK
;
240 /* The ST Micro variants has a special bit to enable SDIO */
241 if (variant
->sdio
&& host
->mmc
->card
)
242 if (mmc_card_sdio(host
->mmc
->card
))
243 datactrl
|= MCI_ST_DPSM_SDIOEN
;
245 writel(datactrl
, base
+ MMCIDATACTRL
);
246 writel(readl(base
+ MMCIMASK0
) & ~MCI_DATAENDMASK
, base
+ MMCIMASK0
);
247 mmci_set_mask1(host
, irqmask
);
251 mmci_start_command(struct mmci_host
*host
, struct mmc_command
*cmd
, u32 c
)
253 void __iomem
*base
= host
->base
;
255 dev_dbg(mmc_dev(host
->mmc
), "op %02x arg %08x flags %08x\n",
256 cmd
->opcode
, cmd
->arg
, cmd
->flags
);
258 if (readl(base
+ MMCICOMMAND
) & MCI_CPSM_ENABLE
) {
259 writel(0, base
+ MMCICOMMAND
);
263 c
|= cmd
->opcode
| MCI_CPSM_ENABLE
;
264 if (cmd
->flags
& MMC_RSP_PRESENT
) {
265 if (cmd
->flags
& MMC_RSP_136
)
266 c
|= MCI_CPSM_LONGRSP
;
267 c
|= MCI_CPSM_RESPONSE
;
270 c
|= MCI_CPSM_INTERRUPT
;
274 writel(cmd
->arg
, base
+ MMCIARGUMENT
);
275 writel(c
, base
+ MMCICOMMAND
);
279 mmci_data_irq(struct mmci_host
*host
, struct mmc_data
*data
,
282 /* First check for errors */
283 if (status
& (MCI_DATACRCFAIL
|MCI_DATATIMEOUT
|MCI_TXUNDERRUN
|MCI_RXOVERRUN
)) {
286 /* Calculate how far we are into the transfer */
287 remain
= readl(host
->base
+ MMCIDATACNT
);
288 success
= data
->blksz
* data
->blocks
- remain
;
290 dev_dbg(mmc_dev(host
->mmc
), "MCI ERROR IRQ (status %08x)\n", status
);
291 if (status
& MCI_DATACRCFAIL
) {
292 /* Last block was not successful */
293 host
->data_xfered
= round_down(success
- 1, data
->blksz
);
294 data
->error
= -EILSEQ
;
295 } else if (status
& MCI_DATATIMEOUT
) {
296 host
->data_xfered
= round_down(success
, data
->blksz
);
297 data
->error
= -ETIMEDOUT
;
298 } else if (status
& (MCI_TXUNDERRUN
|MCI_RXOVERRUN
)) {
299 host
->data_xfered
= round_down(success
, data
->blksz
);
304 * We hit an error condition. Ensure that any data
305 * partially written to a page is properly coherent.
307 if (data
->flags
& MMC_DATA_READ
) {
308 struct sg_mapping_iter
*sg_miter
= &host
->sg_miter
;
311 local_irq_save(flags
);
312 if (sg_miter_next(sg_miter
)) {
313 flush_dcache_page(sg_miter
->page
);
314 sg_miter_stop(sg_miter
);
316 local_irq_restore(flags
);
320 if (status
& MCI_DATABLOCKEND
)
321 dev_err(mmc_dev(host
->mmc
), "stray MCI_DATABLOCKEND interrupt\n");
323 if (status
& MCI_DATAEND
|| data
->error
) {
324 mmci_stop_data(host
);
327 /* The error clause is handled above, success! */
328 host
->data_xfered
+= data
->blksz
* data
->blocks
;
331 mmci_request_end(host
, data
->mrq
);
333 mmci_start_command(host
, data
->stop
, 0);
339 mmci_cmd_irq(struct mmci_host
*host
, struct mmc_command
*cmd
,
342 void __iomem
*base
= host
->base
;
346 if (status
& MCI_CMDTIMEOUT
) {
347 cmd
->error
= -ETIMEDOUT
;
348 } else if (status
& MCI_CMDCRCFAIL
&& cmd
->flags
& MMC_RSP_CRC
) {
349 cmd
->error
= -EILSEQ
;
351 cmd
->resp
[0] = readl(base
+ MMCIRESPONSE0
);
352 cmd
->resp
[1] = readl(base
+ MMCIRESPONSE1
);
353 cmd
->resp
[2] = readl(base
+ MMCIRESPONSE2
);
354 cmd
->resp
[3] = readl(base
+ MMCIRESPONSE3
);
357 if (!cmd
->data
|| cmd
->error
) {
359 mmci_stop_data(host
);
360 mmci_request_end(host
, cmd
->mrq
);
361 } else if (!(cmd
->data
->flags
& MMC_DATA_READ
)) {
362 mmci_start_data(host
, cmd
->data
);
366 static int mmci_pio_read(struct mmci_host
*host
, char *buffer
, unsigned int remain
)
368 void __iomem
*base
= host
->base
;
371 int host_remain
= host
->size
;
374 int count
= host_remain
- (readl(base
+ MMCIFIFOCNT
) << 2);
382 readsl(base
+ MMCIFIFO
, ptr
, count
>> 2);
386 host_remain
-= count
;
391 status
= readl(base
+ MMCISTATUS
);
392 } while (status
& MCI_RXDATAAVLBL
);
397 static int mmci_pio_write(struct mmci_host
*host
, char *buffer
, unsigned int remain
, u32 status
)
399 struct variant_data
*variant
= host
->variant
;
400 void __iomem
*base
= host
->base
;
404 unsigned int count
, maxcnt
;
406 maxcnt
= status
& MCI_TXFIFOEMPTY
?
407 variant
->fifosize
: variant
->fifohalfsize
;
408 count
= min(remain
, maxcnt
);
411 * The ST Micro variant for SDIO transfer sizes
412 * less then 8 bytes should have clock H/W flow
416 mmc_card_sdio(host
->mmc
->card
)) {
418 writel(readl(host
->base
+ MMCICLOCK
) &
419 ~variant
->clkreg_enable
,
420 host
->base
+ MMCICLOCK
);
422 writel(readl(host
->base
+ MMCICLOCK
) |
423 variant
->clkreg_enable
,
424 host
->base
+ MMCICLOCK
);
428 * SDIO especially may want to send something that is
429 * not divisible by 4 (as opposed to card sectors
430 * etc), and the FIFO only accept full 32-bit writes.
431 * So compensate by adding +3 on the count, a single
432 * byte become a 32bit write, 7 bytes will be two
435 writesl(base
+ MMCIFIFO
, ptr
, (count
+ 3) >> 2);
443 status
= readl(base
+ MMCISTATUS
);
444 } while (status
& MCI_TXFIFOHALFEMPTY
);
450 * PIO data transfer IRQ handler.
452 static irqreturn_t
mmci_pio_irq(int irq
, void *dev_id
)
454 struct mmci_host
*host
= dev_id
;
455 struct sg_mapping_iter
*sg_miter
= &host
->sg_miter
;
456 struct variant_data
*variant
= host
->variant
;
457 void __iomem
*base
= host
->base
;
461 status
= readl(base
+ MMCISTATUS
);
463 dev_dbg(mmc_dev(host
->mmc
), "irq1 (pio) %08x\n", status
);
465 local_irq_save(flags
);
468 unsigned int remain
, len
;
472 * For write, we only need to test the half-empty flag
473 * here - if the FIFO is completely empty, then by
474 * definition it is more than half empty.
476 * For read, check for data available.
478 if (!(status
& (MCI_TXFIFOHALFEMPTY
|MCI_RXDATAAVLBL
)))
481 if (!sg_miter_next(sg_miter
))
484 buffer
= sg_miter
->addr
;
485 remain
= sg_miter
->length
;
488 if (status
& MCI_RXACTIVE
)
489 len
= mmci_pio_read(host
, buffer
, remain
);
490 if (status
& MCI_TXACTIVE
)
491 len
= mmci_pio_write(host
, buffer
, remain
, status
);
493 sg_miter
->consumed
= len
;
501 if (status
& MCI_RXACTIVE
)
502 flush_dcache_page(sg_miter
->page
);
504 status
= readl(base
+ MMCISTATUS
);
507 sg_miter_stop(sg_miter
);
509 local_irq_restore(flags
);
512 * If we're nearing the end of the read, switch to
513 * "any data available" mode.
515 if (status
& MCI_RXACTIVE
&& host
->size
< variant
->fifosize
)
516 mmci_set_mask1(host
, MCI_RXDATAAVLBLMASK
);
519 * If we run out of data, disable the data IRQs; this
520 * prevents a race where the FIFO becomes empty before
521 * the chip itself has disabled the data path, and
522 * stops us racing with our data end IRQ.
524 if (host
->size
== 0) {
525 mmci_set_mask1(host
, 0);
526 writel(readl(base
+ MMCIMASK0
) | MCI_DATAENDMASK
, base
+ MMCIMASK0
);
533 * Handle completion of command and data transfers.
535 static irqreturn_t
mmci_irq(int irq
, void *dev_id
)
537 struct mmci_host
*host
= dev_id
;
541 spin_lock(&host
->lock
);
544 struct mmc_command
*cmd
;
545 struct mmc_data
*data
;
547 status
= readl(host
->base
+ MMCISTATUS
);
549 if (host
->singleirq
) {
550 if (status
& readl(host
->base
+ MMCIMASK1
))
551 mmci_pio_irq(irq
, dev_id
);
553 status
&= ~MCI_IRQ1MASK
;
556 status
&= readl(host
->base
+ MMCIMASK0
);
557 writel(status
, host
->base
+ MMCICLEAR
);
559 dev_dbg(mmc_dev(host
->mmc
), "irq0 (data+cmd) %08x\n", status
);
562 if (status
& (MCI_DATACRCFAIL
|MCI_DATATIMEOUT
|MCI_TXUNDERRUN
|
563 MCI_RXOVERRUN
|MCI_DATAEND
|MCI_DATABLOCKEND
) && data
)
564 mmci_data_irq(host
, data
, status
);
567 if (status
& (MCI_CMDCRCFAIL
|MCI_CMDTIMEOUT
|MCI_CMDSENT
|MCI_CMDRESPEND
) && cmd
)
568 mmci_cmd_irq(host
, cmd
, status
);
573 spin_unlock(&host
->lock
);
575 return IRQ_RETVAL(ret
);
578 static void mmci_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
580 struct mmci_host
*host
= mmc_priv(mmc
);
583 WARN_ON(host
->mrq
!= NULL
);
585 if (mrq
->data
&& !is_power_of_2(mrq
->data
->blksz
)) {
586 dev_err(mmc_dev(mmc
), "unsupported block size (%d bytes)\n",
588 mrq
->cmd
->error
= -EINVAL
;
589 mmc_request_done(mmc
, mrq
);
593 spin_lock_irqsave(&host
->lock
, flags
);
597 if (mrq
->data
&& mrq
->data
->flags
& MMC_DATA_READ
)
598 mmci_start_data(host
, mrq
->data
);
600 mmci_start_command(host
, mrq
->cmd
, 0);
602 spin_unlock_irqrestore(&host
->lock
, flags
);
605 static void mmci_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
607 struct mmci_host
*host
= mmc_priv(mmc
);
612 switch (ios
->power_mode
) {
615 ret
= mmc_regulator_set_ocr(mmc
, host
->vcc
, 0);
619 ret
= mmc_regulator_set_ocr(mmc
, host
->vcc
, ios
->vdd
);
621 dev_err(mmc_dev(mmc
), "unable to set OCR\n");
623 * The .set_ios() function in the mmc_host_ops
624 * struct return void, and failing to set the
625 * power should be rare so we print an error
631 if (host
->plat
->vdd_handler
)
632 pwr
|= host
->plat
->vdd_handler(mmc_dev(mmc
), ios
->vdd
,
634 /* The ST version does not have this, fall through to POWER_ON */
635 if (host
->hw_designer
!= AMBA_VENDOR_ST
) {
644 if (ios
->bus_mode
== MMC_BUSMODE_OPENDRAIN
) {
645 if (host
->hw_designer
!= AMBA_VENDOR_ST
)
649 * The ST Micro variant use the ROD bit for something
650 * else and only has OD (Open Drain).
656 spin_lock_irqsave(&host
->lock
, flags
);
658 mmci_set_clkreg(host
, ios
->clock
);
660 if (host
->pwr
!= pwr
) {
662 writel(pwr
, host
->base
+ MMCIPOWER
);
665 spin_unlock_irqrestore(&host
->lock
, flags
);
668 static int mmci_get_ro(struct mmc_host
*mmc
)
670 struct mmci_host
*host
= mmc_priv(mmc
);
672 if (host
->gpio_wp
== -ENOSYS
)
675 return gpio_get_value_cansleep(host
->gpio_wp
);
678 static int mmci_get_cd(struct mmc_host
*mmc
)
680 struct mmci_host
*host
= mmc_priv(mmc
);
681 struct mmci_platform_data
*plat
= host
->plat
;
684 if (host
->gpio_cd
== -ENOSYS
) {
686 return 1; /* Assume always present */
688 status
= plat
->status(mmc_dev(host
->mmc
));
690 status
= !!gpio_get_value_cansleep(host
->gpio_cd
)
694 * Use positive logic throughout - status is zero for no card,
695 * non-zero for card inserted.
700 static irqreturn_t
mmci_cd_irq(int irq
, void *dev_id
)
702 struct mmci_host
*host
= dev_id
;
704 mmc_detect_change(host
->mmc
, msecs_to_jiffies(500));
709 static const struct mmc_host_ops mmci_ops
= {
710 .request
= mmci_request
,
711 .set_ios
= mmci_set_ios
,
712 .get_ro
= mmci_get_ro
,
713 .get_cd
= mmci_get_cd
,
716 static int __devinit
mmci_probe(struct amba_device
*dev
, struct amba_id
*id
)
718 struct mmci_platform_data
*plat
= dev
->dev
.platform_data
;
719 struct variant_data
*variant
= id
->data
;
720 struct mmci_host
*host
;
721 struct mmc_host
*mmc
;
724 /* must have platform data */
730 ret
= amba_request_regions(dev
, DRIVER_NAME
);
734 mmc
= mmc_alloc_host(sizeof(struct mmci_host
), &dev
->dev
);
740 host
= mmc_priv(mmc
);
743 host
->gpio_wp
= -ENOSYS
;
744 host
->gpio_cd
= -ENOSYS
;
745 host
->gpio_cd_irq
= -1;
747 host
->hw_designer
= amba_manf(dev
);
748 host
->hw_revision
= amba_rev(dev
);
749 dev_dbg(mmc_dev(mmc
), "designer ID = 0x%02x\n", host
->hw_designer
);
750 dev_dbg(mmc_dev(mmc
), "revision = 0x%01x\n", host
->hw_revision
);
752 host
->clk
= clk_get(&dev
->dev
, NULL
);
753 if (IS_ERR(host
->clk
)) {
754 ret
= PTR_ERR(host
->clk
);
759 ret
= clk_enable(host
->clk
);
764 host
->variant
= variant
;
765 host
->mclk
= clk_get_rate(host
->clk
);
767 * According to the spec, mclk is max 100 MHz,
768 * so we try to adjust the clock down to this,
771 if (host
->mclk
> 100000000) {
772 ret
= clk_set_rate(host
->clk
, 100000000);
775 host
->mclk
= clk_get_rate(host
->clk
);
776 dev_dbg(mmc_dev(mmc
), "eventual mclk rate: %u Hz\n",
779 host
->base
= ioremap(dev
->res
.start
, resource_size(&dev
->res
));
785 mmc
->ops
= &mmci_ops
;
786 mmc
->f_min
= (host
->mclk
+ 511) / 512;
788 * If the platform data supplies a maximum operating
789 * frequency, this takes precedence. Else, we fall back
790 * to using the module parameter, which has a (low)
791 * default value in case it is not specified. Either
792 * value must not exceed the clock rate into the block,
796 mmc
->f_max
= min(host
->mclk
, plat
->f_max
);
798 mmc
->f_max
= min(host
->mclk
, fmax
);
799 dev_dbg(mmc_dev(mmc
), "clocking block at %u Hz\n", mmc
->f_max
);
801 #ifdef CONFIG_REGULATOR
802 /* If we're using the regulator framework, try to fetch a regulator */
803 host
->vcc
= regulator_get(&dev
->dev
, "vmmc");
804 if (IS_ERR(host
->vcc
))
807 int mask
= mmc_regulator_get_ocrmask(host
->vcc
);
810 dev_err(&dev
->dev
, "error getting OCR mask (%d)\n",
813 host
->mmc
->ocr_avail
= (u32
) mask
;
816 "Provided ocr_mask/setpower will not be used "
817 "(using regulator instead)\n");
821 /* Fall back to platform data if no regulator is found */
822 if (host
->vcc
== NULL
)
823 mmc
->ocr_avail
= plat
->ocr_mask
;
824 mmc
->caps
= plat
->capabilities
;
829 mmc
->max_segs
= NR_SG
;
832 * Since only a certain number of bits are valid in the data length
833 * register, we must ensure that we don't exceed 2^num-1 bytes in a
836 mmc
->max_req_size
= (1 << variant
->datalength_bits
) - 1;
839 * Set the maximum segment size. Since we aren't doing DMA
840 * (yet) we are only limited by the data length register.
842 mmc
->max_seg_size
= mmc
->max_req_size
;
845 * Block size can be up to 2048 bytes, but must be a power of two.
847 mmc
->max_blk_size
= 2048;
850 * No limit on the number of blocks transferred.
852 mmc
->max_blk_count
= mmc
->max_req_size
;
854 spin_lock_init(&host
->lock
);
856 writel(0, host
->base
+ MMCIMASK0
);
857 writel(0, host
->base
+ MMCIMASK1
);
858 writel(0xfff, host
->base
+ MMCICLEAR
);
860 if (gpio_is_valid(plat
->gpio_cd
)) {
861 ret
= gpio_request(plat
->gpio_cd
, DRIVER_NAME
" (cd)");
863 ret
= gpio_direction_input(plat
->gpio_cd
);
865 host
->gpio_cd
= plat
->gpio_cd
;
866 else if (ret
!= -ENOSYS
)
869 ret
= request_any_context_irq(gpio_to_irq(plat
->gpio_cd
),
871 DRIVER_NAME
" (cd)", host
);
873 host
->gpio_cd_irq
= gpio_to_irq(plat
->gpio_cd
);
875 if (gpio_is_valid(plat
->gpio_wp
)) {
876 ret
= gpio_request(plat
->gpio_wp
, DRIVER_NAME
" (wp)");
878 ret
= gpio_direction_input(plat
->gpio_wp
);
880 host
->gpio_wp
= plat
->gpio_wp
;
881 else if (ret
!= -ENOSYS
)
885 if ((host
->plat
->status
|| host
->gpio_cd
!= -ENOSYS
)
886 && host
->gpio_cd_irq
< 0)
887 mmc
->caps
|= MMC_CAP_NEEDS_POLL
;
889 ret
= request_irq(dev
->irq
[0], mmci_irq
, IRQF_SHARED
, DRIVER_NAME
" (cmd)", host
);
893 if (dev
->irq
[1] == NO_IRQ
)
894 host
->singleirq
= true;
896 ret
= request_irq(dev
->irq
[1], mmci_pio_irq
, IRQF_SHARED
,
897 DRIVER_NAME
" (pio)", host
);
902 writel(MCI_IRQENABLE
, host
->base
+ MMCIMASK0
);
904 amba_set_drvdata(dev
, mmc
);
906 dev_info(&dev
->dev
, "%s: PL%03x rev%u at 0x%08llx irq %d,%d\n",
907 mmc_hostname(mmc
), amba_part(dev
), amba_rev(dev
),
908 (unsigned long long)dev
->res
.start
, dev
->irq
[0], dev
->irq
[1]);
915 free_irq(dev
->irq
[0], host
);
917 if (host
->gpio_wp
!= -ENOSYS
)
918 gpio_free(host
->gpio_wp
);
920 if (host
->gpio_cd_irq
>= 0)
921 free_irq(host
->gpio_cd_irq
, host
);
922 if (host
->gpio_cd
!= -ENOSYS
)
923 gpio_free(host
->gpio_cd
);
927 clk_disable(host
->clk
);
933 amba_release_regions(dev
);
938 static int __devexit
mmci_remove(struct amba_device
*dev
)
940 struct mmc_host
*mmc
= amba_get_drvdata(dev
);
942 amba_set_drvdata(dev
, NULL
);
945 struct mmci_host
*host
= mmc_priv(mmc
);
947 mmc_remove_host(mmc
);
949 writel(0, host
->base
+ MMCIMASK0
);
950 writel(0, host
->base
+ MMCIMASK1
);
952 writel(0, host
->base
+ MMCICOMMAND
);
953 writel(0, host
->base
+ MMCIDATACTRL
);
955 free_irq(dev
->irq
[0], host
);
956 if (!host
->singleirq
)
957 free_irq(dev
->irq
[1], host
);
959 if (host
->gpio_wp
!= -ENOSYS
)
960 gpio_free(host
->gpio_wp
);
961 if (host
->gpio_cd_irq
>= 0)
962 free_irq(host
->gpio_cd_irq
, host
);
963 if (host
->gpio_cd
!= -ENOSYS
)
964 gpio_free(host
->gpio_cd
);
967 clk_disable(host
->clk
);
971 mmc_regulator_set_ocr(mmc
, host
->vcc
, 0);
972 regulator_put(host
->vcc
);
976 amba_release_regions(dev
);
983 static int mmci_suspend(struct amba_device
*dev
, pm_message_t state
)
985 struct mmc_host
*mmc
= amba_get_drvdata(dev
);
989 struct mmci_host
*host
= mmc_priv(mmc
);
991 ret
= mmc_suspend_host(mmc
);
993 writel(0, host
->base
+ MMCIMASK0
);
999 static int mmci_resume(struct amba_device
*dev
)
1001 struct mmc_host
*mmc
= amba_get_drvdata(dev
);
1005 struct mmci_host
*host
= mmc_priv(mmc
);
1007 writel(MCI_IRQENABLE
, host
->base
+ MMCIMASK0
);
1009 ret
= mmc_resume_host(mmc
);
1015 #define mmci_suspend NULL
1016 #define mmci_resume NULL
1019 static struct amba_id mmci_ids
[] = {
1023 .data
= &variant_arm
,
1028 .data
= &variant_arm
,
1030 /* ST Micro variants */
1034 .data
= &variant_u300
,
1039 .data
= &variant_u300
,
1044 .data
= &variant_ux500
,
1049 static struct amba_driver mmci_driver
= {
1051 .name
= DRIVER_NAME
,
1053 .probe
= mmci_probe
,
1054 .remove
= __devexit_p(mmci_remove
),
1055 .suspend
= mmci_suspend
,
1056 .resume
= mmci_resume
,
1057 .id_table
= mmci_ids
,
1060 static int __init
mmci_init(void)
1062 return amba_driver_register(&mmci_driver
);
1065 static void __exit
mmci_exit(void)
1067 amba_driver_unregister(&mmci_driver
);
1070 module_init(mmci_init
);
1071 module_exit(mmci_exit
);
1072 module_param(fmax
, uint
, 0444);
1074 MODULE_DESCRIPTION("ARM PrimeCell PL180/181 Multimedia Card Interface driver");
1075 MODULE_LICENSE("GPL");