Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Pierre Ossman | 70f1048 | 2007-07-11 20:04:50 +0200 | [diff] [blame] | 2 | * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved. |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 5 | * Copyright (C) 2010 ST-Ericsson AB. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 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. |
| 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/delay.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/highmem.h> |
Nicolas Pitre | 019a5f5 | 2007-10-11 01:06:03 -0400 | [diff] [blame] | 20 | #include <linux/log2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/mmc/host.h> |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 22 | #include <linux/mmc/card.h> |
Russell King | a62c80e | 2006-01-07 13:52:45 +0000 | [diff] [blame] | 23 | #include <linux/amba/bus.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 24 | #include <linux/clk.h> |
Jens Axboe | bd6dee6 | 2007-10-24 09:01:09 +0200 | [diff] [blame] | 25 | #include <linux/scatterlist.h> |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 26 | #include <linux/gpio.h> |
Linus Walleij | 6ef297f | 2009-09-22 14:29:36 +0100 | [diff] [blame] | 27 | #include <linux/amba/mmci.h> |
Linus Walleij | 34e84f3 | 2009-09-22 14:41:40 +0100 | [diff] [blame] | 28 | #include <linux/regulator/consumer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Russell King | 7b09cda | 2005-07-01 12:02:59 +0100 | [diff] [blame] | 30 | #include <asm/div64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/io.h> |
Russell King | c6b8fda | 2005-10-28 14:05:16 +0100 | [diff] [blame] | 32 | #include <asm/sizes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include "mmci.h" |
| 35 | |
| 36 | #define DRIVER_NAME "mmci-pl18x" |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static unsigned int fmax = 515633; |
| 39 | |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 40 | /** |
| 41 | * struct variant_data - MMCI variant-specific quirks |
| 42 | * @clkreg: default value for MCICLOCK register |
Rabin Vincent | 4380c14 | 2010-07-21 12:55:18 +0100 | [diff] [blame] | 43 | * @clkreg_enable: enable value for MMCICLOCK register |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 44 | * @datalength_bits: number of bits in the MMCIDATALENGTH register |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 45 | * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY |
| 46 | * is asserted (likewise for RX) |
| 47 | * @fifohalfsize: number of bytes that can be written when MCI_TXFIFOHALFEMPTY |
| 48 | * is asserted (likewise for RX) |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 49 | * @broken_blockend: the MCI_DATABLOCKEND is broken on the hardware |
| 50 | * and will not work at all. |
| 51 | * @broken_blockend_dma: the MCI_DATABLOCKEND is broken on the hardware when |
| 52 | * using DMA. |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 53 | * @sdio: variant supports SDIO |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame^] | 54 | * @st_clkdiv: true if using a ST-specific clock divider algorithm |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 55 | */ |
| 56 | struct variant_data { |
| 57 | unsigned int clkreg; |
Rabin Vincent | 4380c14 | 2010-07-21 12:55:18 +0100 | [diff] [blame] | 58 | unsigned int clkreg_enable; |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 59 | unsigned int datalength_bits; |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 60 | unsigned int fifosize; |
| 61 | unsigned int fifohalfsize; |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 62 | bool broken_blockend; |
| 63 | bool broken_blockend_dma; |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 64 | bool sdio; |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame^] | 65 | bool st_clkdiv; |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static struct variant_data variant_arm = { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 69 | .fifosize = 16 * 4, |
| 70 | .fifohalfsize = 8 * 4, |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 71 | .datalength_bits = 16, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | static struct variant_data variant_u300 = { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 75 | .fifosize = 16 * 4, |
| 76 | .fifohalfsize = 8 * 4, |
Rabin Vincent | 4380c14 | 2010-07-21 12:55:18 +0100 | [diff] [blame] | 77 | .clkreg_enable = 1 << 13, /* HWFCEN */ |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 78 | .datalength_bits = 16, |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 79 | .broken_blockend_dma = true, |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 80 | .sdio = true, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | static struct variant_data variant_ux500 = { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 84 | .fifosize = 30 * 4, |
| 85 | .fifohalfsize = 8 * 4, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 86 | .clkreg = MCI_CLK_ENABLE, |
Rabin Vincent | 4380c14 | 2010-07-21 12:55:18 +0100 | [diff] [blame] | 87 | .clkreg_enable = 1 << 14, /* HWFCEN */ |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 88 | .datalength_bits = 24, |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 89 | .broken_blockend = true, |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 90 | .sdio = true, |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame^] | 91 | .st_clkdiv = true, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 92 | }; |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame^] | 93 | |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 94 | /* |
| 95 | * This must be called with host->lock held |
| 96 | */ |
| 97 | static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) |
| 98 | { |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 99 | struct variant_data *variant = host->variant; |
| 100 | u32 clk = variant->clkreg; |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 101 | |
| 102 | if (desired) { |
| 103 | if (desired >= host->mclk) { |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame^] | 104 | /* |
| 105 | * The ST clock divider does not like the bypass bit, |
| 106 | * even though it's available. Instead the datasheet |
| 107 | * recommends setting the divider to zero. |
| 108 | */ |
| 109 | if (!variant->st_clkdiv) |
| 110 | clk = MCI_CLK_BYPASS; |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 111 | host->cclk = host->mclk; |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame^] | 112 | } else if (variant->st_clkdiv) { |
| 113 | /* |
| 114 | * DB8500 TRM says f = mclk / (clkdiv + 2) |
| 115 | * => clkdiv = (mclk / f) - 2 |
| 116 | * Round the divider up so we don't exceed the max |
| 117 | * frequency |
| 118 | */ |
| 119 | clk = DIV_ROUND_UP(host->mclk, desired) - 2; |
| 120 | if (clk >= 256) |
| 121 | clk = 255; |
| 122 | host->cclk = host->mclk / (clk + 2); |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 123 | } else { |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame^] | 124 | /* |
| 125 | * PL180 TRM says f = mclk / (2 * (clkdiv + 1)) |
| 126 | * => clkdiv = mclk / (2 * f) - 1 |
| 127 | */ |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 128 | clk = host->mclk / (2 * desired) - 1; |
| 129 | if (clk >= 256) |
| 130 | clk = 255; |
| 131 | host->cclk = host->mclk / (2 * (clk + 1)); |
| 132 | } |
Rabin Vincent | 4380c14 | 2010-07-21 12:55:18 +0100 | [diff] [blame] | 133 | |
| 134 | clk |= variant->clkreg_enable; |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 135 | clk |= MCI_CLK_ENABLE; |
| 136 | /* This hasn't proven to be worthwhile */ |
| 137 | /* clk |= MCI_CLK_PWRSAVE; */ |
| 138 | } |
| 139 | |
Linus Walleij | 9e6c82c | 2009-09-14 12:57:11 +0100 | [diff] [blame] | 140 | if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4) |
Linus Walleij | 771dc15 | 2010-04-08 07:38:52 +0100 | [diff] [blame] | 141 | clk |= MCI_4BIT_BUS; |
| 142 | if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8) |
| 143 | clk |= MCI_ST_8BIT_BUS; |
Linus Walleij | 9e6c82c | 2009-09-14 12:57:11 +0100 | [diff] [blame] | 144 | |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 145 | writel(clk, host->base + MMCICLOCK); |
| 146 | } |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | static void |
| 149 | mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) |
| 150 | { |
| 151 | writel(0, host->base + MMCICOMMAND); |
| 152 | |
Russell King | e47c222 | 2007-01-08 16:42:51 +0000 | [diff] [blame] | 153 | BUG_ON(host->data); |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | host->mrq = NULL; |
| 156 | host->cmd = NULL; |
| 157 | |
| 158 | if (mrq->data) |
| 159 | mrq->data->bytes_xfered = host->data_xfered; |
| 160 | |
| 161 | /* |
| 162 | * Need to drop the host lock here; mmc_request_done may call |
| 163 | * back into the driver... |
| 164 | */ |
| 165 | spin_unlock(&host->lock); |
| 166 | mmc_request_done(host->mmc, mrq); |
| 167 | spin_lock(&host->lock); |
| 168 | } |
| 169 | |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 170 | static void mmci_set_mask1(struct mmci_host *host, unsigned int mask) |
| 171 | { |
| 172 | void __iomem *base = host->base; |
| 173 | |
| 174 | if (host->singleirq) { |
| 175 | unsigned int mask0 = readl(base + MMCIMASK0); |
| 176 | |
| 177 | mask0 &= ~MCI_IRQ1MASK; |
| 178 | mask0 |= mask; |
| 179 | |
| 180 | writel(mask0, base + MMCIMASK0); |
| 181 | } |
| 182 | |
| 183 | writel(mask, base + MMCIMASK1); |
| 184 | } |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | static void mmci_stop_data(struct mmci_host *host) |
| 187 | { |
| 188 | writel(0, host->base + MMCIDATACTRL); |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 189 | mmci_set_mask1(host, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | host->data = NULL; |
| 191 | } |
| 192 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 193 | static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data) |
| 194 | { |
| 195 | unsigned int flags = SG_MITER_ATOMIC; |
| 196 | |
| 197 | if (data->flags & MMC_DATA_READ) |
| 198 | flags |= SG_MITER_TO_SG; |
| 199 | else |
| 200 | flags |= SG_MITER_FROM_SG; |
| 201 | |
| 202 | sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); |
| 203 | } |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) |
| 206 | { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 207 | struct variant_data *variant = host->variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | unsigned int datactrl, timeout, irqmask; |
Russell King | 7b09cda | 2005-07-01 12:02:59 +0100 | [diff] [blame] | 209 | unsigned long long clks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | void __iomem *base; |
Russell King | 3bc87f2 | 2006-08-27 13:51:28 +0100 | [diff] [blame] | 211 | int blksz_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 213 | dev_dbg(mmc_dev(host->mmc), "blksz %04x blks %04x flags %08x\n", |
| 214 | data->blksz, data->blocks, data->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | host->data = data; |
Rabin Vincent | 528320d | 2010-07-21 12:49:49 +0100 | [diff] [blame] | 217 | host->size = data->blksz * data->blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | host->data_xfered = 0; |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 219 | host->blockend = false; |
| 220 | host->dataend = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | mmci_init_sg(host, data); |
| 223 | |
Russell King | 7b09cda | 2005-07-01 12:02:59 +0100 | [diff] [blame] | 224 | clks = (unsigned long long)data->timeout_ns * host->cclk; |
| 225 | do_div(clks, 1000000000UL); |
| 226 | |
| 227 | timeout = data->timeout_clks + (unsigned int)clks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | base = host->base; |
| 230 | writel(timeout, base + MMCIDATATIMER); |
| 231 | writel(host->size, base + MMCIDATALENGTH); |
| 232 | |
Russell King | 3bc87f2 | 2006-08-27 13:51:28 +0100 | [diff] [blame] | 233 | blksz_bits = ffs(data->blksz) - 1; |
| 234 | BUG_ON(1 << blksz_bits != data->blksz); |
| 235 | |
| 236 | datactrl = MCI_DPSM_ENABLE | blksz_bits << 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | if (data->flags & MMC_DATA_READ) { |
| 238 | datactrl |= MCI_DPSM_DIRECTION; |
| 239 | irqmask = MCI_RXFIFOHALFFULLMASK; |
Russell King | 0425a14 | 2006-02-16 16:48:31 +0000 | [diff] [blame] | 240 | |
| 241 | /* |
| 242 | * If we have less than a FIFOSIZE of bytes to transfer, |
| 243 | * trigger a PIO interrupt as soon as any data is available. |
| 244 | */ |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 245 | if (host->size < variant->fifosize) |
Russell King | 0425a14 | 2006-02-16 16:48:31 +0000 | [diff] [blame] | 246 | irqmask |= MCI_RXDATAAVLBLMASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } else { |
| 248 | /* |
| 249 | * We don't actually need to include "FIFO empty" here |
| 250 | * since its implicit in "FIFO half empty". |
| 251 | */ |
| 252 | irqmask = MCI_TXFIFOHALFEMPTYMASK; |
| 253 | } |
| 254 | |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 255 | /* The ST Micro variants has a special bit to enable SDIO */ |
| 256 | if (variant->sdio && host->mmc->card) |
| 257 | if (mmc_card_sdio(host->mmc->card)) |
| 258 | datactrl |= MCI_ST_DPSM_SDIOEN; |
| 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | writel(datactrl, base + MMCIDATACTRL); |
| 261 | writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0); |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 262 | mmci_set_mask1(host, irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static void |
| 266 | mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) |
| 267 | { |
| 268 | void __iomem *base = host->base; |
| 269 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 270 | dev_dbg(mmc_dev(host->mmc), "op %02x arg %08x flags %08x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | cmd->opcode, cmd->arg, cmd->flags); |
| 272 | |
| 273 | if (readl(base + MMCICOMMAND) & MCI_CPSM_ENABLE) { |
| 274 | writel(0, base + MMCICOMMAND); |
| 275 | udelay(1); |
| 276 | } |
| 277 | |
| 278 | c |= cmd->opcode | MCI_CPSM_ENABLE; |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 279 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 280 | if (cmd->flags & MMC_RSP_136) |
| 281 | c |= MCI_CPSM_LONGRSP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | c |= MCI_CPSM_RESPONSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | if (/*interrupt*/0) |
| 285 | c |= MCI_CPSM_INTERRUPT; |
| 286 | |
| 287 | host->cmd = cmd; |
| 288 | |
| 289 | writel(cmd->arg, base + MMCIARGUMENT); |
| 290 | writel(c, base + MMCICOMMAND); |
| 291 | } |
| 292 | |
| 293 | static void |
| 294 | mmci_data_irq(struct mmci_host *host, struct mmc_data *data, |
| 295 | unsigned int status) |
| 296 | { |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 297 | struct variant_data *variant = host->variant; |
| 298 | |
| 299 | /* First check for errors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) { |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 301 | dev_dbg(mmc_dev(host->mmc), "MCI ERROR IRQ (status %08x)\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (status & MCI_DATACRCFAIL) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 303 | data->error = -EILSEQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | else if (status & MCI_DATATIMEOUT) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 305 | data->error = -ETIMEDOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | else if (status & (MCI_TXUNDERRUN|MCI_RXOVERRUN)) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 307 | data->error = -EIO; |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 308 | |
| 309 | /* Force-complete the transaction */ |
| 310 | host->blockend = true; |
| 311 | host->dataend = true; |
Russell King | e9c091b | 2006-01-04 16:24:05 +0000 | [diff] [blame] | 312 | |
| 313 | /* |
| 314 | * We hit an error condition. Ensure that any data |
| 315 | * partially written to a page is properly coherent. |
| 316 | */ |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 317 | if (data->flags & MMC_DATA_READ) { |
| 318 | struct sg_mapping_iter *sg_miter = &host->sg_miter; |
| 319 | unsigned long flags; |
| 320 | |
| 321 | local_irq_save(flags); |
| 322 | if (sg_miter_next(sg_miter)) { |
| 323 | flush_dcache_page(sg_miter->page); |
| 324 | sg_miter_stop(sg_miter); |
| 325 | } |
| 326 | local_irq_restore(flags); |
| 327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 329 | |
| 330 | /* |
| 331 | * On ARM variants in PIO mode, MCI_DATABLOCKEND |
| 332 | * is always sent first, and we increase the |
| 333 | * transfered number of bytes for that IRQ. Then |
| 334 | * MCI_DATAEND follows and we conclude the transaction. |
| 335 | * |
| 336 | * On the Ux500 single-IRQ variant MCI_DATABLOCKEND |
| 337 | * doesn't seem to immediately clear from the status, |
| 338 | * so we can't use it keep count when only one irq is |
| 339 | * used because the irq will hit for other reasons, and |
| 340 | * then the flag is still up. So we use the MCI_DATAEND |
| 341 | * IRQ at the end of the entire transfer because |
| 342 | * MCI_DATABLOCKEND is broken. |
| 343 | * |
| 344 | * In the U300, the IRQs can arrive out-of-order, |
| 345 | * e.g. MCI_DATABLOCKEND sometimes arrives after MCI_DATAEND, |
| 346 | * so for this case we use the flags "blockend" and |
| 347 | * "dataend" to make sure both IRQs have arrived before |
| 348 | * concluding the transaction. (This does not apply |
| 349 | * to the Ux500 which doesn't fire MCI_DATABLOCKEND |
| 350 | * at all.) In DMA mode it suffers from the same problem |
| 351 | * as the Ux500. |
| 352 | */ |
| 353 | if (status & MCI_DATABLOCKEND) { |
| 354 | /* |
| 355 | * Just being a little over-cautious, we do not |
| 356 | * use this progressive update if the hardware blockend |
| 357 | * flag is unreliable: since it can stay high between |
| 358 | * IRQs it will corrupt the transfer counter. |
| 359 | */ |
| 360 | if (!variant->broken_blockend) |
| 361 | host->data_xfered += data->blksz; |
| 362 | host->blockend = true; |
| 363 | } |
| 364 | |
| 365 | if (status & MCI_DATAEND) |
| 366 | host->dataend = true; |
| 367 | |
| 368 | /* |
| 369 | * On variants with broken blockend we shall only wait for dataend, |
| 370 | * on others we must sync with the blockend signal since they can |
| 371 | * appear out-of-order. |
| 372 | */ |
| 373 | if (host->dataend && (host->blockend || variant->broken_blockend)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | mmci_stop_data(host); |
| 375 | |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 376 | /* Reset these flags */ |
| 377 | host->blockend = false; |
| 378 | host->dataend = false; |
| 379 | |
| 380 | /* |
| 381 | * Variants with broken blockend flags need to handle the |
| 382 | * end of the entire transfer here. |
| 383 | */ |
| 384 | if (variant->broken_blockend && !data->error) |
| 385 | host->data_xfered += data->blksz * data->blocks; |
| 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | if (!data->stop) { |
| 388 | mmci_request_end(host, data->mrq); |
| 389 | } else { |
| 390 | mmci_start_command(host, data->stop, 0); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | static void |
| 396 | mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, |
| 397 | unsigned int status) |
| 398 | { |
| 399 | void __iomem *base = host->base; |
| 400 | |
| 401 | host->cmd = NULL; |
| 402 | |
| 403 | cmd->resp[0] = readl(base + MMCIRESPONSE0); |
| 404 | cmd->resp[1] = readl(base + MMCIRESPONSE1); |
| 405 | cmd->resp[2] = readl(base + MMCIRESPONSE2); |
| 406 | cmd->resp[3] = readl(base + MMCIRESPONSE3); |
| 407 | |
| 408 | if (status & MCI_CMDTIMEOUT) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 409 | cmd->error = -ETIMEDOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 411 | cmd->error = -EILSEQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 414 | if (!cmd->data || cmd->error) { |
Russell King | e47c222 | 2007-01-08 16:42:51 +0000 | [diff] [blame] | 415 | if (host->data) |
| 416 | mmci_stop_data(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | mmci_request_end(host, cmd->mrq); |
| 418 | } else if (!(cmd->data->flags & MMC_DATA_READ)) { |
| 419 | mmci_start_data(host, cmd->data); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | static int mmci_pio_read(struct mmci_host *host, char *buffer, unsigned int remain) |
| 424 | { |
| 425 | void __iomem *base = host->base; |
| 426 | char *ptr = buffer; |
| 427 | u32 status; |
Linus Walleij | 26eed9a | 2008-04-26 23:39:44 +0100 | [diff] [blame] | 428 | int host_remain = host->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | do { |
Linus Walleij | 26eed9a | 2008-04-26 23:39:44 +0100 | [diff] [blame] | 431 | int count = host_remain - (readl(base + MMCIFIFOCNT) << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | if (count > remain) |
| 434 | count = remain; |
| 435 | |
| 436 | if (count <= 0) |
| 437 | break; |
| 438 | |
| 439 | readsl(base + MMCIFIFO, ptr, count >> 2); |
| 440 | |
| 441 | ptr += count; |
| 442 | remain -= count; |
Linus Walleij | 26eed9a | 2008-04-26 23:39:44 +0100 | [diff] [blame] | 443 | host_remain -= count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | if (remain == 0) |
| 446 | break; |
| 447 | |
| 448 | status = readl(base + MMCISTATUS); |
| 449 | } while (status & MCI_RXDATAAVLBL); |
| 450 | |
| 451 | return ptr - buffer; |
| 452 | } |
| 453 | |
| 454 | static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int remain, u32 status) |
| 455 | { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 456 | struct variant_data *variant = host->variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | void __iomem *base = host->base; |
| 458 | char *ptr = buffer; |
| 459 | |
| 460 | do { |
| 461 | unsigned int count, maxcnt; |
| 462 | |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 463 | maxcnt = status & MCI_TXFIFOEMPTY ? |
| 464 | variant->fifosize : variant->fifohalfsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | count = min(remain, maxcnt); |
| 466 | |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 467 | /* |
| 468 | * The ST Micro variant for SDIO transfer sizes |
| 469 | * less then 8 bytes should have clock H/W flow |
| 470 | * control disabled. |
| 471 | */ |
| 472 | if (variant->sdio && |
| 473 | mmc_card_sdio(host->mmc->card)) { |
| 474 | if (count < 8) |
| 475 | writel(readl(host->base + MMCICLOCK) & |
| 476 | ~variant->clkreg_enable, |
| 477 | host->base + MMCICLOCK); |
| 478 | else |
| 479 | writel(readl(host->base + MMCICLOCK) | |
| 480 | variant->clkreg_enable, |
| 481 | host->base + MMCICLOCK); |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * SDIO especially may want to send something that is |
| 486 | * not divisible by 4 (as opposed to card sectors |
| 487 | * etc), and the FIFO only accept full 32-bit writes. |
| 488 | * So compensate by adding +3 on the count, a single |
| 489 | * byte become a 32bit write, 7 bytes will be two |
| 490 | * 32bit writes etc. |
| 491 | */ |
| 492 | writesl(base + MMCIFIFO, ptr, (count + 3) >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | ptr += count; |
| 495 | remain -= count; |
| 496 | |
| 497 | if (remain == 0) |
| 498 | break; |
| 499 | |
| 500 | status = readl(base + MMCISTATUS); |
| 501 | } while (status & MCI_TXFIFOHALFEMPTY); |
| 502 | |
| 503 | return ptr - buffer; |
| 504 | } |
| 505 | |
| 506 | /* |
| 507 | * PIO data transfer IRQ handler. |
| 508 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 509 | static irqreturn_t mmci_pio_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
| 511 | struct mmci_host *host = dev_id; |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 512 | struct sg_mapping_iter *sg_miter = &host->sg_miter; |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 513 | struct variant_data *variant = host->variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | void __iomem *base = host->base; |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 515 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | u32 status; |
| 517 | |
| 518 | status = readl(base + MMCISTATUS); |
| 519 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 520 | dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 522 | local_irq_save(flags); |
| 523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | unsigned int remain, len; |
| 526 | char *buffer; |
| 527 | |
| 528 | /* |
| 529 | * For write, we only need to test the half-empty flag |
| 530 | * here - if the FIFO is completely empty, then by |
| 531 | * definition it is more than half empty. |
| 532 | * |
| 533 | * For read, check for data available. |
| 534 | */ |
| 535 | if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL))) |
| 536 | break; |
| 537 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 538 | if (!sg_miter_next(sg_miter)) |
| 539 | break; |
| 540 | |
| 541 | buffer = sg_miter->addr; |
| 542 | remain = sg_miter->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
| 544 | len = 0; |
| 545 | if (status & MCI_RXACTIVE) |
| 546 | len = mmci_pio_read(host, buffer, remain); |
| 547 | if (status & MCI_TXACTIVE) |
| 548 | len = mmci_pio_write(host, buffer, remain, status); |
| 549 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 550 | sg_miter->consumed = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | host->size -= len; |
| 553 | remain -= len; |
| 554 | |
| 555 | if (remain) |
| 556 | break; |
| 557 | |
Russell King | e9c091b | 2006-01-04 16:24:05 +0000 | [diff] [blame] | 558 | if (status & MCI_RXACTIVE) |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 559 | flush_dcache_page(sg_miter->page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | status = readl(base + MMCISTATUS); |
| 562 | } while (1); |
| 563 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 564 | sg_miter_stop(sg_miter); |
| 565 | |
| 566 | local_irq_restore(flags); |
| 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* |
| 569 | * If we're nearing the end of the read, switch to |
| 570 | * "any data available" mode. |
| 571 | */ |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 572 | if (status & MCI_RXACTIVE && host->size < variant->fifosize) |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 573 | mmci_set_mask1(host, MCI_RXDATAAVLBLMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | /* |
| 576 | * If we run out of data, disable the data IRQs; this |
| 577 | * prevents a race where the FIFO becomes empty before |
| 578 | * the chip itself has disabled the data path, and |
| 579 | * stops us racing with our data end IRQ. |
| 580 | */ |
| 581 | if (host->size == 0) { |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 582 | mmci_set_mask1(host, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | writel(readl(base + MMCIMASK0) | MCI_DATAENDMASK, base + MMCIMASK0); |
| 584 | } |
| 585 | |
| 586 | return IRQ_HANDLED; |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | * Handle completion of command and data transfers. |
| 591 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 592 | static irqreturn_t mmci_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
| 594 | struct mmci_host *host = dev_id; |
| 595 | u32 status; |
| 596 | int ret = 0; |
| 597 | |
| 598 | spin_lock(&host->lock); |
| 599 | |
| 600 | do { |
| 601 | struct mmc_command *cmd; |
| 602 | struct mmc_data *data; |
| 603 | |
| 604 | status = readl(host->base + MMCISTATUS); |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 605 | |
| 606 | if (host->singleirq) { |
| 607 | if (status & readl(host->base + MMCIMASK1)) |
| 608 | mmci_pio_irq(irq, dev_id); |
| 609 | |
| 610 | status &= ~MCI_IRQ1MASK; |
| 611 | } |
| 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | status &= readl(host->base + MMCIMASK0); |
| 614 | writel(status, host->base + MMCICLEAR); |
| 615 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 616 | dev_dbg(mmc_dev(host->mmc), "irq0 (data+cmd) %08x\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
| 618 | data = host->data; |
| 619 | if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN| |
| 620 | MCI_RXOVERRUN|MCI_DATAEND|MCI_DATABLOCKEND) && data) |
| 621 | mmci_data_irq(host, data, status); |
| 622 | |
| 623 | cmd = host->cmd; |
| 624 | if (status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|MCI_CMDSENT|MCI_CMDRESPEND) && cmd) |
| 625 | mmci_cmd_irq(host, cmd, status); |
| 626 | |
| 627 | ret = 1; |
| 628 | } while (status); |
| 629 | |
| 630 | spin_unlock(&host->lock); |
| 631 | |
| 632 | return IRQ_RETVAL(ret); |
| 633 | } |
| 634 | |
| 635 | static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 636 | { |
| 637 | struct mmci_host *host = mmc_priv(mmc); |
Linus Walleij | 9e94302 | 2008-10-24 21:17:50 +0100 | [diff] [blame] | 638 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
| 640 | WARN_ON(host->mrq != NULL); |
| 641 | |
Nicolas Pitre | 019a5f5 | 2007-10-11 01:06:03 -0400 | [diff] [blame] | 642 | if (mrq->data && !is_power_of_2(mrq->data->blksz)) { |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 643 | dev_err(mmc_dev(mmc), "unsupported block size (%d bytes)\n", |
| 644 | mrq->data->blksz); |
Pierre Ossman | 255d01a | 2007-07-24 20:38:53 +0200 | [diff] [blame] | 645 | mrq->cmd->error = -EINVAL; |
| 646 | mmc_request_done(mmc, mrq); |
| 647 | return; |
| 648 | } |
| 649 | |
Linus Walleij | 9e94302 | 2008-10-24 21:17:50 +0100 | [diff] [blame] | 650 | spin_lock_irqsave(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
| 652 | host->mrq = mrq; |
| 653 | |
| 654 | if (mrq->data && mrq->data->flags & MMC_DATA_READ) |
| 655 | mmci_start_data(host, mrq->data); |
| 656 | |
| 657 | mmci_start_command(host, mrq->cmd, 0); |
| 658 | |
Linus Walleij | 9e94302 | 2008-10-24 21:17:50 +0100 | [diff] [blame] | 659 | spin_unlock_irqrestore(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 663 | { |
| 664 | struct mmci_host *host = mmc_priv(mmc); |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 665 | u32 pwr = 0; |
| 666 | unsigned long flags; |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 667 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | switch (ios->power_mode) { |
| 670 | case MMC_POWER_OFF: |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 671 | if (host->vcc) |
| 672 | ret = mmc_regulator_set_ocr(mmc, host->vcc, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | break; |
| 674 | case MMC_POWER_UP: |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 675 | if (host->vcc) { |
| 676 | ret = mmc_regulator_set_ocr(mmc, host->vcc, ios->vdd); |
| 677 | if (ret) { |
| 678 | dev_err(mmc_dev(mmc), "unable to set OCR\n"); |
| 679 | /* |
| 680 | * The .set_ios() function in the mmc_host_ops |
| 681 | * struct return void, and failing to set the |
| 682 | * power should be rare so we print an error |
| 683 | * and return here. |
| 684 | */ |
| 685 | return; |
| 686 | } |
| 687 | } |
Rabin Vincent | bb8f563 | 2010-07-21 12:53:57 +0100 | [diff] [blame] | 688 | if (host->plat->vdd_handler) |
| 689 | pwr |= host->plat->vdd_handler(mmc_dev(mmc), ios->vdd, |
| 690 | ios->power_mode); |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 691 | /* The ST version does not have this, fall through to POWER_ON */ |
Linus Walleij | f17a1f0 | 2009-08-04 01:01:02 +0100 | [diff] [blame] | 692 | if (host->hw_designer != AMBA_VENDOR_ST) { |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 693 | pwr |= MCI_PWR_UP; |
| 694 | break; |
| 695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | case MMC_POWER_ON: |
| 697 | pwr |= MCI_PWR_ON; |
| 698 | break; |
| 699 | } |
| 700 | |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 701 | if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) { |
Linus Walleij | f17a1f0 | 2009-08-04 01:01:02 +0100 | [diff] [blame] | 702 | if (host->hw_designer != AMBA_VENDOR_ST) |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 703 | pwr |= MCI_ROD; |
| 704 | else { |
| 705 | /* |
| 706 | * The ST Micro variant use the ROD bit for something |
| 707 | * else and only has OD (Open Drain). |
| 708 | */ |
| 709 | pwr |= MCI_OD; |
| 710 | } |
| 711 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 713 | spin_lock_irqsave(&host->lock, flags); |
| 714 | |
| 715 | mmci_set_clkreg(host, ios->clock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
| 717 | if (host->pwr != pwr) { |
| 718 | host->pwr = pwr; |
| 719 | writel(pwr, host->base + MMCIPOWER); |
| 720 | } |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 721 | |
| 722 | spin_unlock_irqrestore(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 725 | static int mmci_get_ro(struct mmc_host *mmc) |
| 726 | { |
| 727 | struct mmci_host *host = mmc_priv(mmc); |
| 728 | |
| 729 | if (host->gpio_wp == -ENOSYS) |
| 730 | return -ENOSYS; |
| 731 | |
Linus Walleij | 18a06301 | 2010-09-12 12:56:44 +0100 | [diff] [blame] | 732 | return gpio_get_value_cansleep(host->gpio_wp); |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | static int mmci_get_cd(struct mmc_host *mmc) |
| 736 | { |
| 737 | struct mmci_host *host = mmc_priv(mmc); |
Rabin Vincent | 2971944 | 2010-08-09 12:54:43 +0100 | [diff] [blame] | 738 | struct mmci_platform_data *plat = host->plat; |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 739 | unsigned int status; |
| 740 | |
Rabin Vincent | 4b8caec | 2010-08-09 12:56:40 +0100 | [diff] [blame] | 741 | if (host->gpio_cd == -ENOSYS) { |
| 742 | if (!plat->status) |
| 743 | return 1; /* Assume always present */ |
| 744 | |
Rabin Vincent | 2971944 | 2010-08-09 12:54:43 +0100 | [diff] [blame] | 745 | status = plat->status(mmc_dev(host->mmc)); |
Rabin Vincent | 4b8caec | 2010-08-09 12:56:40 +0100 | [diff] [blame] | 746 | } else |
Linus Walleij | 18a06301 | 2010-09-12 12:56:44 +0100 | [diff] [blame] | 747 | status = !!gpio_get_value_cansleep(host->gpio_cd) |
| 748 | ^ plat->cd_invert; |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 749 | |
Russell King | 74bc809 | 2010-07-29 15:58:59 +0100 | [diff] [blame] | 750 | /* |
| 751 | * Use positive logic throughout - status is zero for no card, |
| 752 | * non-zero for card inserted. |
| 753 | */ |
| 754 | return status; |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 755 | } |
| 756 | |
Rabin Vincent | 148b8b3 | 2010-08-09 12:55:48 +0100 | [diff] [blame] | 757 | static irqreturn_t mmci_cd_irq(int irq, void *dev_id) |
| 758 | { |
| 759 | struct mmci_host *host = dev_id; |
| 760 | |
| 761 | mmc_detect_change(host->mmc, msecs_to_jiffies(500)); |
| 762 | |
| 763 | return IRQ_HANDLED; |
| 764 | } |
| 765 | |
David Brownell | ab7aefd | 2006-11-12 17:55:30 -0800 | [diff] [blame] | 766 | static const struct mmc_host_ops mmci_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | .request = mmci_request, |
| 768 | .set_ios = mmci_set_ios, |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 769 | .get_ro = mmci_get_ro, |
| 770 | .get_cd = mmci_get_cd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | }; |
| 772 | |
Alessandro Rubini | 03fbdb1 | 2009-05-20 22:39:08 +0100 | [diff] [blame] | 773 | static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | { |
Linus Walleij | 6ef297f | 2009-09-22 14:29:36 +0100 | [diff] [blame] | 775 | struct mmci_platform_data *plat = dev->dev.platform_data; |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 776 | struct variant_data *variant = id->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | struct mmci_host *host; |
| 778 | struct mmc_host *mmc; |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 779 | unsigned int mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | int ret; |
| 781 | |
| 782 | /* must have platform data */ |
| 783 | if (!plat) { |
| 784 | ret = -EINVAL; |
| 785 | goto out; |
| 786 | } |
| 787 | |
| 788 | ret = amba_request_regions(dev, DRIVER_NAME); |
| 789 | if (ret) |
| 790 | goto out; |
| 791 | |
| 792 | mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev); |
| 793 | if (!mmc) { |
| 794 | ret = -ENOMEM; |
| 795 | goto rel_regions; |
| 796 | } |
| 797 | |
| 798 | host = mmc_priv(mmc); |
Rabin Vincent | 4ea580f | 2009-04-17 08:44:19 +0530 | [diff] [blame] | 799 | host->mmc = mmc; |
Russell King | 012b7d3 | 2009-07-09 15:13:56 +0100 | [diff] [blame] | 800 | |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 801 | host->gpio_wp = -ENOSYS; |
| 802 | host->gpio_cd = -ENOSYS; |
Rabin Vincent | 148b8b3 | 2010-08-09 12:55:48 +0100 | [diff] [blame] | 803 | host->gpio_cd_irq = -1; |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 804 | |
Russell King | 012b7d3 | 2009-07-09 15:13:56 +0100 | [diff] [blame] | 805 | host->hw_designer = amba_manf(dev); |
| 806 | host->hw_revision = amba_rev(dev); |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 807 | dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer); |
| 808 | dev_dbg(mmc_dev(mmc), "revision = 0x%01x\n", host->hw_revision); |
Russell King | 012b7d3 | 2009-07-09 15:13:56 +0100 | [diff] [blame] | 809 | |
Russell King | ee569c4 | 2008-11-30 17:38:14 +0000 | [diff] [blame] | 810 | host->clk = clk_get(&dev->dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | if (IS_ERR(host->clk)) { |
| 812 | ret = PTR_ERR(host->clk); |
| 813 | host->clk = NULL; |
| 814 | goto host_free; |
| 815 | } |
| 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | ret = clk_enable(host->clk); |
| 818 | if (ret) |
Russell King | a8d3584 | 2006-01-03 18:41:37 +0000 | [diff] [blame] | 819 | goto clk_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
| 821 | host->plat = plat; |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 822 | host->variant = variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | host->mclk = clk_get_rate(host->clk); |
Linus Walleij | c8df9a5 | 2008-04-29 09:34:07 +0100 | [diff] [blame] | 824 | /* |
| 825 | * According to the spec, mclk is max 100 MHz, |
| 826 | * so we try to adjust the clock down to this, |
| 827 | * (if possible). |
| 828 | */ |
| 829 | if (host->mclk > 100000000) { |
| 830 | ret = clk_set_rate(host->clk, 100000000); |
| 831 | if (ret < 0) |
| 832 | goto clk_disable; |
| 833 | host->mclk = clk_get_rate(host->clk); |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 834 | dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n", |
| 835 | host->mclk); |
Linus Walleij | c8df9a5 | 2008-04-29 09:34:07 +0100 | [diff] [blame] | 836 | } |
Linus Walleij | dc890c2 | 2009-06-07 23:27:31 +0100 | [diff] [blame] | 837 | host->base = ioremap(dev->res.start, resource_size(&dev->res)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | if (!host->base) { |
| 839 | ret = -ENOMEM; |
| 840 | goto clk_disable; |
| 841 | } |
| 842 | |
| 843 | mmc->ops = &mmci_ops; |
| 844 | mmc->f_min = (host->mclk + 511) / 512; |
Linus Walleij | 808d97c | 2010-04-08 07:39:38 +0100 | [diff] [blame] | 845 | /* |
| 846 | * If the platform data supplies a maximum operating |
| 847 | * frequency, this takes precedence. Else, we fall back |
| 848 | * to using the module parameter, which has a (low) |
| 849 | * default value in case it is not specified. Either |
| 850 | * value must not exceed the clock rate into the block, |
| 851 | * of course. |
| 852 | */ |
| 853 | if (plat->f_max) |
| 854 | mmc->f_max = min(host->mclk, plat->f_max); |
| 855 | else |
| 856 | mmc->f_max = min(host->mclk, fmax); |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 857 | dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max); |
| 858 | |
Linus Walleij | 34e84f3 | 2009-09-22 14:41:40 +0100 | [diff] [blame] | 859 | #ifdef CONFIG_REGULATOR |
| 860 | /* If we're using the regulator framework, try to fetch a regulator */ |
| 861 | host->vcc = regulator_get(&dev->dev, "vmmc"); |
| 862 | if (IS_ERR(host->vcc)) |
| 863 | host->vcc = NULL; |
| 864 | else { |
| 865 | int mask = mmc_regulator_get_ocrmask(host->vcc); |
| 866 | |
| 867 | if (mask < 0) |
| 868 | dev_err(&dev->dev, "error getting OCR mask (%d)\n", |
| 869 | mask); |
| 870 | else { |
| 871 | host->mmc->ocr_avail = (u32) mask; |
| 872 | if (plat->ocr_mask) |
| 873 | dev_warn(&dev->dev, |
| 874 | "Provided ocr_mask/setpower will not be used " |
| 875 | "(using regulator instead)\n"); |
| 876 | } |
| 877 | } |
| 878 | #endif |
| 879 | /* Fall back to platform data if no regulator is found */ |
| 880 | if (host->vcc == NULL) |
| 881 | mmc->ocr_avail = plat->ocr_mask; |
Linus Walleij | 9e6c82c | 2009-09-14 12:57:11 +0100 | [diff] [blame] | 882 | mmc->caps = plat->capabilities; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
| 884 | /* |
| 885 | * We can do SGIO |
| 886 | */ |
Martin K. Petersen | a36274e | 2010-09-10 01:33:59 -0400 | [diff] [blame] | 887 | mmc->max_segs = NR_SG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
| 889 | /* |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 890 | * Since only a certain number of bits are valid in the data length |
| 891 | * register, we must ensure that we don't exceed 2^num-1 bytes in a |
| 892 | * single request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | */ |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 894 | mmc->max_req_size = (1 << variant->datalength_bits) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
| 896 | /* |
| 897 | * Set the maximum segment size. Since we aren't doing DMA |
| 898 | * (yet) we are only limited by the data length register. |
| 899 | */ |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 900 | mmc->max_seg_size = mmc->max_req_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 902 | /* |
| 903 | * Block size can be up to 2048 bytes, but must be a power of two. |
| 904 | */ |
| 905 | mmc->max_blk_size = 2048; |
| 906 | |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 907 | /* |
| 908 | * No limit on the number of blocks transferred. |
| 909 | */ |
| 910 | mmc->max_blk_count = mmc->max_req_size; |
| 911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | spin_lock_init(&host->lock); |
| 913 | |
| 914 | writel(0, host->base + MMCIMASK0); |
| 915 | writel(0, host->base + MMCIMASK1); |
| 916 | writel(0xfff, host->base + MMCICLEAR); |
| 917 | |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 918 | if (gpio_is_valid(plat->gpio_cd)) { |
| 919 | ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)"); |
| 920 | if (ret == 0) |
| 921 | ret = gpio_direction_input(plat->gpio_cd); |
| 922 | if (ret == 0) |
| 923 | host->gpio_cd = plat->gpio_cd; |
| 924 | else if (ret != -ENOSYS) |
| 925 | goto err_gpio_cd; |
Rabin Vincent | 148b8b3 | 2010-08-09 12:55:48 +0100 | [diff] [blame] | 926 | |
| 927 | ret = request_any_context_irq(gpio_to_irq(plat->gpio_cd), |
| 928 | mmci_cd_irq, 0, |
| 929 | DRIVER_NAME " (cd)", host); |
| 930 | if (ret >= 0) |
| 931 | host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd); |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 932 | } |
| 933 | if (gpio_is_valid(plat->gpio_wp)) { |
| 934 | ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)"); |
| 935 | if (ret == 0) |
| 936 | ret = gpio_direction_input(plat->gpio_wp); |
| 937 | if (ret == 0) |
| 938 | host->gpio_wp = plat->gpio_wp; |
| 939 | else if (ret != -ENOSYS) |
| 940 | goto err_gpio_wp; |
| 941 | } |
| 942 | |
Rabin Vincent | 4b8caec | 2010-08-09 12:56:40 +0100 | [diff] [blame] | 943 | if ((host->plat->status || host->gpio_cd != -ENOSYS) |
| 944 | && host->gpio_cd_irq < 0) |
Rabin Vincent | 148b8b3 | 2010-08-09 12:55:48 +0100 | [diff] [blame] | 945 | mmc->caps |= MMC_CAP_NEEDS_POLL; |
| 946 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 947 | ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | if (ret) |
| 949 | goto unmap; |
| 950 | |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 951 | if (dev->irq[1] == NO_IRQ) |
| 952 | host->singleirq = true; |
| 953 | else { |
| 954 | ret = request_irq(dev->irq[1], mmci_pio_irq, IRQF_SHARED, |
| 955 | DRIVER_NAME " (pio)", host); |
| 956 | if (ret) |
| 957 | goto irq0_free; |
| 958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 960 | mask = MCI_IRQENABLE; |
Linus Walleij | f20f8f2 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 961 | /* Don't use the datablockend flag if it's broken */ |
| 962 | if (variant->broken_blockend) |
| 963 | mask &= ~MCI_DATABLOCKEND; |
| 964 | |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 965 | writel(mask, host->base + MMCIMASK0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
| 967 | amba_set_drvdata(dev, mmc); |
| 968 | |
| 969 | mmc_add_host(mmc); |
| 970 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 971 | dev_info(&dev->dev, "%s: MMCI rev %x cfg %02x at 0x%016llx irq %d,%d\n", |
Russell King | d366b64 | 2005-08-19 09:40:08 +0100 | [diff] [blame] | 972 | mmc_hostname(mmc), amba_rev(dev), amba_config(dev), |
Greg Kroah-Hartman | e29419f | 2006-06-12 15:20:16 -0700 | [diff] [blame] | 973 | (unsigned long long)dev->res.start, dev->irq[0], dev->irq[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | return 0; |
| 976 | |
| 977 | irq0_free: |
| 978 | free_irq(dev->irq[0], host); |
| 979 | unmap: |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 980 | if (host->gpio_wp != -ENOSYS) |
| 981 | gpio_free(host->gpio_wp); |
| 982 | err_gpio_wp: |
Rabin Vincent | 148b8b3 | 2010-08-09 12:55:48 +0100 | [diff] [blame] | 983 | if (host->gpio_cd_irq >= 0) |
| 984 | free_irq(host->gpio_cd_irq, host); |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 985 | if (host->gpio_cd != -ENOSYS) |
| 986 | gpio_free(host->gpio_cd); |
| 987 | err_gpio_cd: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | iounmap(host->base); |
| 989 | clk_disable: |
| 990 | clk_disable(host->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | clk_free: |
| 992 | clk_put(host->clk); |
| 993 | host_free: |
| 994 | mmc_free_host(mmc); |
| 995 | rel_regions: |
| 996 | amba_release_regions(dev); |
| 997 | out: |
| 998 | return ret; |
| 999 | } |
| 1000 | |
Linus Walleij | 6dc4a47 | 2009-03-07 00:23:52 +0100 | [diff] [blame] | 1001 | static int __devexit mmci_remove(struct amba_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
| 1003 | struct mmc_host *mmc = amba_get_drvdata(dev); |
| 1004 | |
| 1005 | amba_set_drvdata(dev, NULL); |
| 1006 | |
| 1007 | if (mmc) { |
| 1008 | struct mmci_host *host = mmc_priv(mmc); |
| 1009 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | mmc_remove_host(mmc); |
| 1011 | |
| 1012 | writel(0, host->base + MMCIMASK0); |
| 1013 | writel(0, host->base + MMCIMASK1); |
| 1014 | |
| 1015 | writel(0, host->base + MMCICOMMAND); |
| 1016 | writel(0, host->base + MMCIDATACTRL); |
| 1017 | |
| 1018 | free_irq(dev->irq[0], host); |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 1019 | if (!host->singleirq) |
| 1020 | free_irq(dev->irq[1], host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 1022 | if (host->gpio_wp != -ENOSYS) |
| 1023 | gpio_free(host->gpio_wp); |
Rabin Vincent | 148b8b3 | 2010-08-09 12:55:48 +0100 | [diff] [blame] | 1024 | if (host->gpio_cd_irq >= 0) |
| 1025 | free_irq(host->gpio_cd_irq, host); |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 1026 | if (host->gpio_cd != -ENOSYS) |
| 1027 | gpio_free(host->gpio_cd); |
| 1028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | iounmap(host->base); |
| 1030 | clk_disable(host->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | clk_put(host->clk); |
| 1032 | |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 1033 | if (host->vcc) |
| 1034 | mmc_regulator_set_ocr(mmc, host->vcc, 0); |
Linus Walleij | 34e84f3 | 2009-09-22 14:41:40 +0100 | [diff] [blame] | 1035 | regulator_put(host->vcc); |
| 1036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | mmc_free_host(mmc); |
| 1038 | |
| 1039 | amba_release_regions(dev); |
| 1040 | } |
| 1041 | |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | #ifdef CONFIG_PM |
Pavel Machek | e5378ca | 2005-04-16 15:25:29 -0700 | [diff] [blame] | 1046 | static int mmci_suspend(struct amba_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { |
| 1048 | struct mmc_host *mmc = amba_get_drvdata(dev); |
| 1049 | int ret = 0; |
| 1050 | |
| 1051 | if (mmc) { |
| 1052 | struct mmci_host *host = mmc_priv(mmc); |
| 1053 | |
Matt Fleming | 1a13f8f | 2010-05-26 14:42:08 -0700 | [diff] [blame] | 1054 | ret = mmc_suspend_host(mmc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | if (ret == 0) |
| 1056 | writel(0, host->base + MMCIMASK0); |
| 1057 | } |
| 1058 | |
| 1059 | return ret; |
| 1060 | } |
| 1061 | |
| 1062 | static int mmci_resume(struct amba_device *dev) |
| 1063 | { |
| 1064 | struct mmc_host *mmc = amba_get_drvdata(dev); |
| 1065 | int ret = 0; |
| 1066 | |
| 1067 | if (mmc) { |
| 1068 | struct mmci_host *host = mmc_priv(mmc); |
| 1069 | |
| 1070 | writel(MCI_IRQENABLE, host->base + MMCIMASK0); |
| 1071 | |
| 1072 | ret = mmc_resume_host(mmc); |
| 1073 | } |
| 1074 | |
| 1075 | return ret; |
| 1076 | } |
| 1077 | #else |
| 1078 | #define mmci_suspend NULL |
| 1079 | #define mmci_resume NULL |
| 1080 | #endif |
| 1081 | |
| 1082 | static struct amba_id mmci_ids[] = { |
| 1083 | { |
| 1084 | .id = 0x00041180, |
| 1085 | .mask = 0x000fffff, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 1086 | .data = &variant_arm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | }, |
| 1088 | { |
| 1089 | .id = 0x00041181, |
| 1090 | .mask = 0x000fffff, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 1091 | .data = &variant_arm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | }, |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 1093 | /* ST Micro variants */ |
| 1094 | { |
| 1095 | .id = 0x00180180, |
| 1096 | .mask = 0x00ffffff, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 1097 | .data = &variant_u300, |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 1098 | }, |
| 1099 | { |
| 1100 | .id = 0x00280180, |
| 1101 | .mask = 0x00ffffff, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 1102 | .data = &variant_u300, |
| 1103 | }, |
| 1104 | { |
| 1105 | .id = 0x00480180, |
| 1106 | .mask = 0x00ffffff, |
| 1107 | .data = &variant_ux500, |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 1108 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | { 0, 0 }, |
| 1110 | }; |
| 1111 | |
| 1112 | static struct amba_driver mmci_driver = { |
| 1113 | .drv = { |
| 1114 | .name = DRIVER_NAME, |
| 1115 | }, |
| 1116 | .probe = mmci_probe, |
Linus Walleij | 6dc4a47 | 2009-03-07 00:23:52 +0100 | [diff] [blame] | 1117 | .remove = __devexit_p(mmci_remove), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | .suspend = mmci_suspend, |
| 1119 | .resume = mmci_resume, |
| 1120 | .id_table = mmci_ids, |
| 1121 | }; |
| 1122 | |
| 1123 | static int __init mmci_init(void) |
| 1124 | { |
| 1125 | return amba_driver_register(&mmci_driver); |
| 1126 | } |
| 1127 | |
| 1128 | static void __exit mmci_exit(void) |
| 1129 | { |
| 1130 | amba_driver_unregister(&mmci_driver); |
| 1131 | } |
| 1132 | |
| 1133 | module_init(mmci_init); |
| 1134 | module_exit(mmci_exit); |
| 1135 | module_param(fmax, uint, 0444); |
| 1136 | |
| 1137 | MODULE_DESCRIPTION("ARM PrimeCell PL180/181 Multimedia Card Interface driver"); |
| 1138 | MODULE_LICENSE("GPL"); |