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