diff options
Diffstat (limited to 'drivers/mmc/host/mmci.c')
-rw-r--r-- | drivers/mmc/host/mmci.c | 148 |
1 files changed, 88 insertions, 60 deletions
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 4917af96bae1..7edae83603dd 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <linux/amba/mmci.h> | 26 | #include <linux/amba/mmci.h> |
27 | #include <linux/regulator/consumer.h> | 27 | #include <linux/regulator/consumer.h> |
28 | 28 | ||
29 | #include <asm/cacheflush.h> | ||
30 | #include <asm/div64.h> | 29 | #include <asm/div64.h> |
31 | #include <asm/io.h> | 30 | #include <asm/io.h> |
32 | #include <asm/sizes.h> | 31 | #include <asm/sizes.h> |
@@ -37,12 +36,39 @@ | |||
37 | 36 | ||
38 | static unsigned int fmax = 515633; | 37 | static unsigned int fmax = 515633; |
39 | 38 | ||
39 | /** | ||
40 | * struct variant_data - MMCI variant-specific quirks | ||
41 | * @clkreg: default value for MCICLOCK register | ||
42 | * @clkreg_enable: enable value for MMCICLOCK register | ||
43 | * @datalength_bits: number of bits in the MMCIDATALENGTH register | ||
44 | */ | ||
45 | struct variant_data { | ||
46 | unsigned int clkreg; | ||
47 | unsigned int clkreg_enable; | ||
48 | unsigned int datalength_bits; | ||
49 | }; | ||
50 | |||
51 | static struct variant_data variant_arm = { | ||
52 | .datalength_bits = 16, | ||
53 | }; | ||
54 | |||
55 | static struct variant_data variant_u300 = { | ||
56 | .clkreg_enable = 1 << 13, /* HWFCEN */ | ||
57 | .datalength_bits = 16, | ||
58 | }; | ||
59 | |||
60 | static struct variant_data variant_ux500 = { | ||
61 | .clkreg = MCI_CLK_ENABLE, | ||
62 | .clkreg_enable = 1 << 14, /* HWFCEN */ | ||
63 | .datalength_bits = 24, | ||
64 | }; | ||
40 | /* | 65 | /* |
41 | * This must be called with host->lock held | 66 | * This must be called with host->lock held |
42 | */ | 67 | */ |
43 | static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) | 68 | static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) |
44 | { | 69 | { |
45 | u32 clk = 0; | 70 | struct variant_data *variant = host->variant; |
71 | u32 clk = variant->clkreg; | ||
46 | 72 | ||
47 | if (desired) { | 73 | if (desired) { |
48 | if (desired >= host->mclk) { | 74 | if (desired >= host->mclk) { |
@@ -54,8 +80,8 @@ static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) | |||
54 | clk = 255; | 80 | clk = 255; |
55 | host->cclk = host->mclk / (2 * (clk + 1)); | 81 | host->cclk = host->mclk / (2 * (clk + 1)); |
56 | } | 82 | } |
57 | if (host->hw_designer == AMBA_VENDOR_ST) | 83 | |
58 | clk |= MCI_ST_FCEN; /* Bug fix in ST IP block */ | 84 | clk |= variant->clkreg_enable; |
59 | clk |= MCI_CLK_ENABLE; | 85 | clk |= MCI_CLK_ENABLE; |
60 | /* This hasn't proven to be worthwhile */ | 86 | /* This hasn't proven to be worthwhile */ |
61 | /* clk |= MCI_CLK_PWRSAVE; */ | 87 | /* clk |= MCI_CLK_PWRSAVE; */ |
@@ -98,6 +124,18 @@ static void mmci_stop_data(struct mmci_host *host) | |||
98 | host->data = NULL; | 124 | host->data = NULL; |
99 | } | 125 | } |
100 | 126 | ||
127 | static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data) | ||
128 | { | ||
129 | unsigned int flags = SG_MITER_ATOMIC; | ||
130 | |||
131 | if (data->flags & MMC_DATA_READ) | ||
132 | flags |= SG_MITER_TO_SG; | ||
133 | else | ||
134 | flags |= SG_MITER_FROM_SG; | ||
135 | |||
136 | sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); | ||
137 | } | ||
138 | |||
101 | static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) | 139 | static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) |
102 | { | 140 | { |
103 | unsigned int datactrl, timeout, irqmask; | 141 | unsigned int datactrl, timeout, irqmask; |
@@ -109,7 +147,7 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) | |||
109 | data->blksz, data->blocks, data->flags); | 147 | data->blksz, data->blocks, data->flags); |
110 | 148 | ||
111 | host->data = data; | 149 | host->data = data; |
112 | host->size = data->blksz; | 150 | host->size = data->blksz * data->blocks; |
113 | host->data_xfered = 0; | 151 | host->data_xfered = 0; |
114 | 152 | ||
115 | mmci_init_sg(host, data); | 153 | mmci_init_sg(host, data); |
@@ -210,8 +248,17 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data, | |||
210 | * We hit an error condition. Ensure that any data | 248 | * We hit an error condition. Ensure that any data |
211 | * partially written to a page is properly coherent. | 249 | * partially written to a page is properly coherent. |
212 | */ | 250 | */ |
213 | if (host->sg_len && data->flags & MMC_DATA_READ) | 251 | if (data->flags & MMC_DATA_READ) { |
214 | flush_dcache_page(sg_page(host->sg_ptr)); | 252 | struct sg_mapping_iter *sg_miter = &host->sg_miter; |
253 | unsigned long flags; | ||
254 | |||
255 | local_irq_save(flags); | ||
256 | if (sg_miter_next(sg_miter)) { | ||
257 | flush_dcache_page(sg_miter->page); | ||
258 | sg_miter_stop(sg_miter); | ||
259 | } | ||
260 | local_irq_restore(flags); | ||
261 | } | ||
215 | } | 262 | } |
216 | if (status & MCI_DATAEND) { | 263 | if (status & MCI_DATAEND) { |
217 | mmci_stop_data(host); | 264 | mmci_stop_data(host); |
@@ -314,15 +361,18 @@ static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int rem | |||
314 | static irqreturn_t mmci_pio_irq(int irq, void *dev_id) | 361 | static irqreturn_t mmci_pio_irq(int irq, void *dev_id) |
315 | { | 362 | { |
316 | struct mmci_host *host = dev_id; | 363 | struct mmci_host *host = dev_id; |
364 | struct sg_mapping_iter *sg_miter = &host->sg_miter; | ||
317 | void __iomem *base = host->base; | 365 | void __iomem *base = host->base; |
366 | unsigned long flags; | ||
318 | u32 status; | 367 | u32 status; |
319 | 368 | ||
320 | status = readl(base + MMCISTATUS); | 369 | status = readl(base + MMCISTATUS); |
321 | 370 | ||
322 | dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status); | 371 | dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status); |
323 | 372 | ||
373 | local_irq_save(flags); | ||
374 | |||
324 | do { | 375 | do { |
325 | unsigned long flags; | ||
326 | unsigned int remain, len; | 376 | unsigned int remain, len; |
327 | char *buffer; | 377 | char *buffer; |
328 | 378 | ||
@@ -336,11 +386,11 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id) | |||
336 | if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL))) | 386 | if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL))) |
337 | break; | 387 | break; |
338 | 388 | ||
339 | /* | 389 | if (!sg_miter_next(sg_miter)) |
340 | * Map the current scatter buffer. | 390 | break; |
341 | */ | 391 | |
342 | buffer = mmci_kmap_atomic(host, &flags) + host->sg_off; | 392 | buffer = sg_miter->addr; |
343 | remain = host->sg_ptr->length - host->sg_off; | 393 | remain = sg_miter->length; |
344 | 394 | ||
345 | len = 0; | 395 | len = 0; |
346 | if (status & MCI_RXACTIVE) | 396 | if (status & MCI_RXACTIVE) |
@@ -348,31 +398,24 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id) | |||
348 | if (status & MCI_TXACTIVE) | 398 | if (status & MCI_TXACTIVE) |
349 | len = mmci_pio_write(host, buffer, remain, status); | 399 | len = mmci_pio_write(host, buffer, remain, status); |
350 | 400 | ||
351 | /* | 401 | sg_miter->consumed = len; |
352 | * Unmap the buffer. | ||
353 | */ | ||
354 | mmci_kunmap_atomic(host, buffer, &flags); | ||
355 | 402 | ||
356 | host->sg_off += len; | ||
357 | host->size -= len; | 403 | host->size -= len; |
358 | remain -= len; | 404 | remain -= len; |
359 | 405 | ||
360 | if (remain) | 406 | if (remain) |
361 | break; | 407 | break; |
362 | 408 | ||
363 | /* | ||
364 | * If we were reading, and we have completed this | ||
365 | * page, ensure that the data cache is coherent. | ||
366 | */ | ||
367 | if (status & MCI_RXACTIVE) | 409 | if (status & MCI_RXACTIVE) |
368 | flush_dcache_page(sg_page(host->sg_ptr)); | 410 | flush_dcache_page(sg_miter->page); |
369 | |||
370 | if (!mmci_next_sg(host)) | ||
371 | break; | ||
372 | 411 | ||
373 | status = readl(base + MMCISTATUS); | 412 | status = readl(base + MMCISTATUS); |
374 | } while (1); | 413 | } while (1); |
375 | 414 | ||
415 | sg_miter_stop(sg_miter); | ||
416 | |||
417 | local_irq_restore(flags); | ||
418 | |||
376 | /* | 419 | /* |
377 | * If we're nearing the end of the read, switch to | 420 | * If we're nearing the end of the read, switch to |
378 | * "any data available" mode. | 421 | * "any data available" mode. |
@@ -477,16 +520,9 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
477 | /* This implicitly enables the regulator */ | 520 | /* This implicitly enables the regulator */ |
478 | mmc_regulator_set_ocr(host->vcc, ios->vdd); | 521 | mmc_regulator_set_ocr(host->vcc, ios->vdd); |
479 | #endif | 522 | #endif |
480 | /* | 523 | if (host->plat->vdd_handler) |
481 | * The translate_vdd function is not used if you have | 524 | pwr |= host->plat->vdd_handler(mmc_dev(mmc), ios->vdd, |
482 | * an external regulator, or your design is really weird. | 525 | ios->power_mode); |
483 | * Using it would mean sending in power control BOTH using | ||
484 | * a regulator AND the 4 MMCIPWR bits. If we don't have | ||
485 | * a regulator, we might have some other platform specific | ||
486 | * power control behind this translate function. | ||
487 | */ | ||
488 | if (!host->vcc && host->plat->translate_vdd) | ||
489 | pwr |= host->plat->translate_vdd(mmc_dev(mmc), ios->vdd); | ||
490 | /* The ST version does not have this, fall through to POWER_ON */ | 526 | /* The ST version does not have this, fall through to POWER_ON */ |
491 | if (host->hw_designer != AMBA_VENDOR_ST) { | 527 | if (host->hw_designer != AMBA_VENDOR_ST) { |
492 | pwr |= MCI_PWR_UP; | 528 | pwr |= MCI_PWR_UP; |
@@ -551,21 +587,10 @@ static const struct mmc_host_ops mmci_ops = { | |||
551 | .get_cd = mmci_get_cd, | 587 | .get_cd = mmci_get_cd, |
552 | }; | 588 | }; |
553 | 589 | ||
554 | static void mmci_check_status(unsigned long data) | ||
555 | { | ||
556 | struct mmci_host *host = (struct mmci_host *)data; | ||
557 | unsigned int status = mmci_get_cd(host->mmc); | ||
558 | |||
559 | if (status ^ host->oldstat) | ||
560 | mmc_detect_change(host->mmc, 0); | ||
561 | |||
562 | host->oldstat = status; | ||
563 | mod_timer(&host->timer, jiffies + HZ); | ||
564 | } | ||
565 | |||
566 | static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | 590 | static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) |
567 | { | 591 | { |
568 | struct mmci_platform_data *plat = dev->dev.platform_data; | 592 | struct mmci_platform_data *plat = dev->dev.platform_data; |
593 | struct variant_data *variant = id->data; | ||
569 | struct mmci_host *host; | 594 | struct mmci_host *host; |
570 | struct mmc_host *mmc; | 595 | struct mmc_host *mmc; |
571 | int ret; | 596 | int ret; |
@@ -609,6 +634,7 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | |||
609 | goto clk_free; | 634 | goto clk_free; |
610 | 635 | ||
611 | host->plat = plat; | 636 | host->plat = plat; |
637 | host->variant = variant; | ||
612 | host->mclk = clk_get_rate(host->clk); | 638 | host->mclk = clk_get_rate(host->clk); |
613 | /* | 639 | /* |
614 | * According to the spec, mclk is max 100 MHz, | 640 | * According to the spec, mclk is max 100 MHz, |
@@ -669,6 +695,7 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | |||
669 | if (host->vcc == NULL) | 695 | if (host->vcc == NULL) |
670 | mmc->ocr_avail = plat->ocr_mask; | 696 | mmc->ocr_avail = plat->ocr_mask; |
671 | mmc->caps = plat->capabilities; | 697 | mmc->caps = plat->capabilities; |
698 | mmc->caps |= MMC_CAP_NEEDS_POLL; | ||
672 | 699 | ||
673 | /* | 700 | /* |
674 | * We can do SGIO | 701 | * We can do SGIO |
@@ -677,10 +704,11 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | |||
677 | mmc->max_phys_segs = NR_SG; | 704 | mmc->max_phys_segs = NR_SG; |
678 | 705 | ||
679 | /* | 706 | /* |
680 | * Since we only have a 16-bit data length register, we must | 707 | * Since only a certain number of bits are valid in the data length |
681 | * ensure that we don't exceed 2^16-1 bytes in a single request. | 708 | * register, we must ensure that we don't exceed 2^num-1 bytes in a |
709 | * single request. | ||
682 | */ | 710 | */ |
683 | mmc->max_req_size = 65535; | 711 | mmc->max_req_size = (1 << variant->datalength_bits) - 1; |
684 | 712 | ||
685 | /* | 713 | /* |
686 | * Set the maximum segment size. Since we aren't doing DMA | 714 | * Set the maximum segment size. Since we aren't doing DMA |
@@ -734,7 +762,6 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | |||
734 | writel(MCI_IRQENABLE, host->base + MMCIMASK0); | 762 | writel(MCI_IRQENABLE, host->base + MMCIMASK0); |
735 | 763 | ||
736 | amba_set_drvdata(dev, mmc); | 764 | amba_set_drvdata(dev, mmc); |
737 | host->oldstat = mmci_get_cd(host->mmc); | ||
738 | 765 | ||
739 | mmc_add_host(mmc); | 766 | mmc_add_host(mmc); |
740 | 767 | ||
@@ -742,12 +769,6 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | |||
742 | mmc_hostname(mmc), amba_rev(dev), amba_config(dev), | 769 | mmc_hostname(mmc), amba_rev(dev), amba_config(dev), |
743 | (unsigned long long)dev->res.start, dev->irq[0], dev->irq[1]); | 770 | (unsigned long long)dev->res.start, dev->irq[0], dev->irq[1]); |
744 | 771 | ||
745 | init_timer(&host->timer); | ||
746 | host->timer.data = (unsigned long)host; | ||
747 | host->timer.function = mmci_check_status; | ||
748 | host->timer.expires = jiffies + HZ; | ||
749 | add_timer(&host->timer); | ||
750 | |||
751 | return 0; | 772 | return 0; |
752 | 773 | ||
753 | irq0_free: | 774 | irq0_free: |
@@ -781,8 +802,6 @@ static int __devexit mmci_remove(struct amba_device *dev) | |||
781 | if (mmc) { | 802 | if (mmc) { |
782 | struct mmci_host *host = mmc_priv(mmc); | 803 | struct mmci_host *host = mmc_priv(mmc); |
783 | 804 | ||
784 | del_timer_sync(&host->timer); | ||
785 | |||
786 | mmc_remove_host(mmc); | 805 | mmc_remove_host(mmc); |
787 | 806 | ||
788 | writel(0, host->base + MMCIMASK0); | 807 | writel(0, host->base + MMCIMASK0); |
@@ -856,19 +875,28 @@ static struct amba_id mmci_ids[] = { | |||
856 | { | 875 | { |
857 | .id = 0x00041180, | 876 | .id = 0x00041180, |
858 | .mask = 0x000fffff, | 877 | .mask = 0x000fffff, |
878 | .data = &variant_arm, | ||
859 | }, | 879 | }, |
860 | { | 880 | { |
861 | .id = 0x00041181, | 881 | .id = 0x00041181, |
862 | .mask = 0x000fffff, | 882 | .mask = 0x000fffff, |
883 | .data = &variant_arm, | ||
863 | }, | 884 | }, |
864 | /* ST Micro variants */ | 885 | /* ST Micro variants */ |
865 | { | 886 | { |
866 | .id = 0x00180180, | 887 | .id = 0x00180180, |
867 | .mask = 0x00ffffff, | 888 | .mask = 0x00ffffff, |
889 | .data = &variant_u300, | ||
868 | }, | 890 | }, |
869 | { | 891 | { |
870 | .id = 0x00280180, | 892 | .id = 0x00280180, |
871 | .mask = 0x00ffffff, | 893 | .mask = 0x00ffffff, |
894 | .data = &variant_u300, | ||
895 | }, | ||
896 | { | ||
897 | .id = 0x00480180, | ||
898 | .mask = 0x00ffffff, | ||
899 | .data = &variant_ux500, | ||
872 | }, | 900 | }, |
873 | { 0, 0 }, | 901 | { 0, 0 }, |
874 | }; | 902 | }; |