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