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