Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mmc/host/omap_hsmmc.c |
| 3 | * |
| 4 | * Driver for OMAP2430/3430 MMC controller. |
| 5 | * |
| 6 | * Copyright (C) 2007 Texas Instruments. |
| 7 | * |
| 8 | * Authors: |
| 9 | * Syed Mohammed Khasim <x0khasim@ti.com> |
| 10 | * Madhusudhan <madhu.cr@ti.com> |
| 11 | * Mohit Jalori <mjalori@ti.com> |
| 12 | * |
| 13 | * This file is licensed under the terms of the GNU General Public License |
| 14 | * version 2. This program is licensed "as is" without any warranty of any |
| 15 | * kind, whether express or implied. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/init.h> |
Andy Shevchenko | ac330f4 | 2011-05-10 15:51:54 +0300 | [diff] [blame] | 20 | #include <linux/kernel.h> |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 21 | #include <linux/debugfs.h> |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 22 | #include <linux/dmaengine.h> |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 23 | #include <linux/seq_file.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/platform_device.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 28 | #include <linux/timer.h> |
| 29 | #include <linux/clk.h> |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 30 | #include <linux/of.h> |
| 31 | #include <linux/of_gpio.h> |
| 32 | #include <linux/of_device.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 33 | #include <linux/mmc/host.h> |
Jarkko Lavinen | 13189e7 | 2009-09-22 16:44:53 -0700 | [diff] [blame] | 34 | #include <linux/mmc/core.h> |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 35 | #include <linux/mmc/mmc.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 36 | #include <linux/io.h> |
| 37 | #include <linux/semaphore.h> |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 38 | #include <linux/gpio.h> |
| 39 | #include <linux/regulator/consumer.h> |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 40 | #include <linux/pm_runtime.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 41 | #include <plat/dma.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 42 | #include <mach/hardware.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 43 | #include <plat/board.h> |
| 44 | #include <plat/mmc.h> |
| 45 | #include <plat/cpu.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 46 | |
| 47 | /* OMAP HSMMC Host Controller Registers */ |
| 48 | #define OMAP_HSMMC_SYSCONFIG 0x0010 |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 49 | #define OMAP_HSMMC_SYSSTATUS 0x0014 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 50 | #define OMAP_HSMMC_CON 0x002C |
| 51 | #define OMAP_HSMMC_BLK 0x0104 |
| 52 | #define OMAP_HSMMC_ARG 0x0108 |
| 53 | #define OMAP_HSMMC_CMD 0x010C |
| 54 | #define OMAP_HSMMC_RSP10 0x0110 |
| 55 | #define OMAP_HSMMC_RSP32 0x0114 |
| 56 | #define OMAP_HSMMC_RSP54 0x0118 |
| 57 | #define OMAP_HSMMC_RSP76 0x011C |
| 58 | #define OMAP_HSMMC_DATA 0x0120 |
| 59 | #define OMAP_HSMMC_HCTL 0x0128 |
| 60 | #define OMAP_HSMMC_SYSCTL 0x012C |
| 61 | #define OMAP_HSMMC_STAT 0x0130 |
| 62 | #define OMAP_HSMMC_IE 0x0134 |
| 63 | #define OMAP_HSMMC_ISE 0x0138 |
| 64 | #define OMAP_HSMMC_CAPA 0x0140 |
| 65 | |
| 66 | #define VS18 (1 << 26) |
| 67 | #define VS30 (1 << 25) |
| 68 | #define SDVS18 (0x5 << 9) |
| 69 | #define SDVS30 (0x6 << 9) |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 70 | #define SDVS33 (0x7 << 9) |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 71 | #define SDVS_MASK 0x00000E00 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 72 | #define SDVSCLR 0xFFFFF1FF |
| 73 | #define SDVSDET 0x00000400 |
| 74 | #define AUTOIDLE 0x1 |
| 75 | #define SDBP (1 << 8) |
| 76 | #define DTO 0xe |
| 77 | #define ICE 0x1 |
| 78 | #define ICS 0x2 |
| 79 | #define CEN (1 << 2) |
| 80 | #define CLKD_MASK 0x0000FFC0 |
| 81 | #define CLKD_SHIFT 6 |
| 82 | #define DTO_MASK 0x000F0000 |
| 83 | #define DTO_SHIFT 16 |
| 84 | #define INT_EN_MASK 0x307F0033 |
Anand Gadiyar | ccdfe3a | 2009-09-22 16:44:21 -0700 | [diff] [blame] | 85 | #define BWR_ENABLE (1 << 4) |
| 86 | #define BRR_ENABLE (1 << 5) |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 87 | #define DTO_ENABLE (1 << 20) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 88 | #define INIT_STREAM (1 << 1) |
| 89 | #define DP_SELECT (1 << 21) |
| 90 | #define DDIR (1 << 4) |
| 91 | #define DMA_EN 0x1 |
| 92 | #define MSBS (1 << 5) |
| 93 | #define BCE (1 << 1) |
| 94 | #define FOUR_BIT (1 << 1) |
Balaji T K | 03b5d92 | 2012-04-09 12:08:33 +0530 | [diff] [blame] | 95 | #define DDR (1 << 19) |
Jarkko Lavinen | 7315301 | 2008-11-21 16:49:54 +0200 | [diff] [blame] | 96 | #define DW8 (1 << 5) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 97 | #define CC 0x1 |
| 98 | #define TC 0x02 |
| 99 | #define OD 0x1 |
| 100 | #define ERR (1 << 15) |
| 101 | #define CMD_TIMEOUT (1 << 16) |
| 102 | #define DATA_TIMEOUT (1 << 20) |
| 103 | #define CMD_CRC (1 << 17) |
| 104 | #define DATA_CRC (1 << 21) |
| 105 | #define CARD_ERR (1 << 28) |
| 106 | #define STAT_CLEAR 0xFFFFFFFF |
| 107 | #define INIT_STREAM_CMD 0x00000000 |
| 108 | #define DUAL_VOLT_OCR_BIT 7 |
| 109 | #define SRC (1 << 25) |
| 110 | #define SRD (1 << 26) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 111 | #define SOFTRESET (1 << 1) |
| 112 | #define RESETDONE (1 << 0) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 113 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 114 | #define MMC_AUTOSUSPEND_DELAY 100 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 115 | #define MMC_TIMEOUT_MS 20 |
Andy Shevchenko | 6b206ef | 2011-07-13 11:16:29 -0400 | [diff] [blame] | 116 | #define OMAP_MMC_MIN_CLOCK 400000 |
| 117 | #define OMAP_MMC_MAX_CLOCK 52000000 |
Kishore Kadiyala | 0005ae7 | 2011-02-28 20:48:05 +0530 | [diff] [blame] | 118 | #define DRIVER_NAME "omap_hsmmc" |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * One controller can have multiple slots, like on some omap boards using |
| 122 | * omap.c controller driver. Luckily this is not currently done on any known |
| 123 | * omap_hsmmc.c device. |
| 124 | */ |
| 125 | #define mmc_slot(host) (host->pdata->slots[host->slot_id]) |
| 126 | |
| 127 | /* |
| 128 | * MMC Host controller read/write API's |
| 129 | */ |
| 130 | #define OMAP_HSMMC_READ(base, reg) \ |
| 131 | __raw_readl((base) + OMAP_HSMMC_##reg) |
| 132 | |
| 133 | #define OMAP_HSMMC_WRITE(base, reg, val) \ |
| 134 | __raw_writel((val), (base) + OMAP_HSMMC_##reg) |
| 135 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 136 | struct omap_hsmmc_next { |
| 137 | unsigned int dma_len; |
| 138 | s32 cookie; |
| 139 | }; |
| 140 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 141 | struct omap_hsmmc_host { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 142 | struct device *dev; |
| 143 | struct mmc_host *mmc; |
| 144 | struct mmc_request *mrq; |
| 145 | struct mmc_command *cmd; |
| 146 | struct mmc_data *data; |
| 147 | struct clk *fclk; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 148 | struct clk *dbclk; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 149 | /* |
| 150 | * vcc == configured supply |
| 151 | * vcc_aux == optional |
| 152 | * - MMC1, supply for DAT4..DAT7 |
| 153 | * - MMC2/MMC2, external level shifter voltage supply, for |
| 154 | * chip (SDIO, eMMC, etc) or transceiver (MMC2 only) |
| 155 | */ |
| 156 | struct regulator *vcc; |
| 157 | struct regulator *vcc_aux; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 158 | void __iomem *base; |
| 159 | resource_size_t mapbase; |
Adrian Hunter | 4dffd7a | 2009-09-22 16:44:58 -0700 | [diff] [blame] | 160 | spinlock_t irq_lock; /* Prevent races with irq handler */ |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 161 | unsigned int dma_len; |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 162 | unsigned int dma_sg_idx; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 163 | unsigned char bus_mode; |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 164 | unsigned char power_mode; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 165 | u32 *buffer; |
| 166 | u32 bytesleft; |
| 167 | int suspended; |
| 168 | int irq; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 169 | int use_dma, dma_ch, dma2; |
| 170 | struct dma_chan *tx_chan; |
| 171 | struct dma_chan *rx_chan; |
Grazvydas Ignotas | f3e2f1d | 2009-01-03 10:36:13 +0000 | [diff] [blame] | 172 | int dma_line_tx, dma_line_rx; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 173 | int slot_id; |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 174 | int response_busy; |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 175 | int context_loss; |
Adrian Hunter | 623821f | 2009-09-22 16:44:51 -0700 | [diff] [blame] | 176 | int vdd; |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 177 | int protect_card; |
| 178 | int reqs_blocked; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 179 | int use_reg; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 180 | int req_in_progress; |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 181 | struct omap_hsmmc_next next_data; |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 182 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 183 | struct omap_mmc_platform_data *pdata; |
| 184 | }; |
| 185 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 186 | static int omap_hsmmc_card_detect(struct device *dev, int slot) |
| 187 | { |
| 188 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 189 | |
| 190 | /* NOTE: assumes card detect signal is active-low */ |
| 191 | return !gpio_get_value_cansleep(mmc->slots[0].switch_pin); |
| 192 | } |
| 193 | |
| 194 | static int omap_hsmmc_get_wp(struct device *dev, int slot) |
| 195 | { |
| 196 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 197 | |
| 198 | /* NOTE: assumes write protect signal is active-high */ |
| 199 | return gpio_get_value_cansleep(mmc->slots[0].gpio_wp); |
| 200 | } |
| 201 | |
| 202 | static int omap_hsmmc_get_cover_state(struct device *dev, int slot) |
| 203 | { |
| 204 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 205 | |
| 206 | /* NOTE: assumes card detect signal is active-low */ |
| 207 | return !gpio_get_value_cansleep(mmc->slots[0].switch_pin); |
| 208 | } |
| 209 | |
| 210 | #ifdef CONFIG_PM |
| 211 | |
| 212 | static int omap_hsmmc_suspend_cdirq(struct device *dev, int slot) |
| 213 | { |
| 214 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 215 | |
| 216 | disable_irq(mmc->slots[0].card_detect_irq); |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static int omap_hsmmc_resume_cdirq(struct device *dev, int slot) |
| 221 | { |
| 222 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 223 | |
| 224 | enable_irq(mmc->slots[0].card_detect_irq); |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | #else |
| 229 | |
| 230 | #define omap_hsmmc_suspend_cdirq NULL |
| 231 | #define omap_hsmmc_resume_cdirq NULL |
| 232 | |
| 233 | #endif |
| 234 | |
Adrian Hunter | b702b10 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 235 | #ifdef CONFIG_REGULATOR |
| 236 | |
Rajendra Nayak | 69b07ec | 2012-03-07 09:55:30 -0500 | [diff] [blame] | 237 | static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on, |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 238 | int vdd) |
| 239 | { |
| 240 | struct omap_hsmmc_host *host = |
| 241 | platform_get_drvdata(to_platform_device(dev)); |
| 242 | int ret = 0; |
| 243 | |
| 244 | /* |
| 245 | * If we don't see a Vcc regulator, assume it's a fixed |
| 246 | * voltage always-on regulator. |
| 247 | */ |
| 248 | if (!host->vcc) |
| 249 | return 0; |
Rajendra Nayak | 1f84b71 | 2012-03-12 20:32:38 +0530 | [diff] [blame] | 250 | /* |
| 251 | * With DT, never turn OFF the regulator. This is because |
| 252 | * the pbias cell programming support is still missing when |
| 253 | * booting with Device tree |
| 254 | */ |
Rajendra Nayak | 4d048f9 | 2012-04-11 15:33:13 +0530 | [diff] [blame] | 255 | if (dev->of_node && !vdd) |
Rajendra Nayak | 1f84b71 | 2012-03-12 20:32:38 +0530 | [diff] [blame] | 256 | return 0; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 257 | |
| 258 | if (mmc_slot(host).before_set_reg) |
| 259 | mmc_slot(host).before_set_reg(dev, slot, power_on, vdd); |
| 260 | |
| 261 | /* |
| 262 | * Assume Vcc regulator is used only to power the card ... OMAP |
| 263 | * VDDS is used to power the pins, optionally with a transceiver to |
| 264 | * support cards using voltages other than VDDS (1.8V nominal). When a |
| 265 | * transceiver is used, DAT3..7 are muxed as transceiver control pins. |
| 266 | * |
| 267 | * In some cases this regulator won't support enable/disable; |
| 268 | * e.g. it's a fixed rail for a WLAN chip. |
| 269 | * |
| 270 | * In other cases vcc_aux switches interface power. Example, for |
| 271 | * eMMC cards it represents VccQ. Sometimes transceivers or SDIO |
| 272 | * chips/cards need an interface voltage rail too. |
| 273 | */ |
| 274 | if (power_on) { |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 275 | ret = mmc_regulator_set_ocr(host->mmc, host->vcc, vdd); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 276 | /* Enable interface voltage rail, if needed */ |
| 277 | if (ret == 0 && host->vcc_aux) { |
| 278 | ret = regulator_enable(host->vcc_aux); |
| 279 | if (ret < 0) |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 280 | ret = mmc_regulator_set_ocr(host->mmc, |
| 281 | host->vcc, 0); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 282 | } |
| 283 | } else { |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 284 | /* Shut down the rail */ |
Adrian Hunter | 6da20c8 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 285 | if (host->vcc_aux) |
| 286 | ret = regulator_disable(host->vcc_aux); |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 287 | if (!ret) { |
| 288 | /* Then proceed to shut down the local regulator */ |
| 289 | ret = mmc_regulator_set_ocr(host->mmc, |
| 290 | host->vcc, 0); |
| 291 | } |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | if (mmc_slot(host).after_set_reg) |
| 295 | mmc_slot(host).after_set_reg(dev, slot, power_on, vdd); |
| 296 | |
| 297 | return ret; |
| 298 | } |
| 299 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 300 | static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host) |
| 301 | { |
| 302 | struct regulator *reg; |
kishore kadiyala | 64be978 | 2010-10-01 16:35:28 -0700 | [diff] [blame] | 303 | int ocr_value = 0; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 304 | |
Rajendra Nayak | 1cb9af4 | 2012-03-07 09:55:31 -0500 | [diff] [blame] | 305 | mmc_slot(host).set_power = omap_hsmmc_set_power; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 306 | |
| 307 | reg = regulator_get(host->dev, "vmmc"); |
| 308 | if (IS_ERR(reg)) { |
| 309 | dev_dbg(host->dev, "vmmc regulator missing\n"); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 310 | } else { |
| 311 | host->vcc = reg; |
kishore kadiyala | 64be978 | 2010-10-01 16:35:28 -0700 | [diff] [blame] | 312 | ocr_value = mmc_regulator_get_ocrmask(reg); |
| 313 | if (!mmc_slot(host).ocr_mask) { |
| 314 | mmc_slot(host).ocr_mask = ocr_value; |
| 315 | } else { |
| 316 | if (!(mmc_slot(host).ocr_mask & ocr_value)) { |
Rajendra Nayak | 2cecdf0 | 2012-02-23 17:02:20 +0530 | [diff] [blame] | 317 | dev_err(host->dev, "ocrmask %x is not supported\n", |
Rajendra Nayak | e3f1adb | 2012-03-07 09:55:31 -0500 | [diff] [blame] | 318 | mmc_slot(host).ocr_mask); |
kishore kadiyala | 64be978 | 2010-10-01 16:35:28 -0700 | [diff] [blame] | 319 | mmc_slot(host).ocr_mask = 0; |
| 320 | return -EINVAL; |
| 321 | } |
| 322 | } |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 323 | |
| 324 | /* Allow an aux regulator */ |
| 325 | reg = regulator_get(host->dev, "vmmc_aux"); |
| 326 | host->vcc_aux = IS_ERR(reg) ? NULL : reg; |
| 327 | |
Balaji T K | b1c1df7 | 2011-05-30 19:55:34 +0530 | [diff] [blame] | 328 | /* For eMMC do not power off when not in sleep state */ |
| 329 | if (mmc_slot(host).no_regulator_off_init) |
| 330 | return 0; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 331 | /* |
| 332 | * UGLY HACK: workaround regulator framework bugs. |
| 333 | * When the bootloader leaves a supply active, it's |
| 334 | * initialized with zero usecount ... and we can't |
| 335 | * disable it without first enabling it. Until the |
| 336 | * framework is fixed, we need a workaround like this |
| 337 | * (which is safe for MMC, but not in general). |
| 338 | */ |
Adrian Hunter | e840ce1 | 2011-05-06 12:14:10 +0300 | [diff] [blame] | 339 | if (regulator_is_enabled(host->vcc) > 0 || |
| 340 | (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) { |
| 341 | int vdd = ffs(mmc_slot(host).ocr_mask) - 1; |
| 342 | |
| 343 | mmc_slot(host).set_power(host->dev, host->slot_id, |
| 344 | 1, vdd); |
| 345 | mmc_slot(host).set_power(host->dev, host->slot_id, |
| 346 | 0, 0); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | return 0; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static void omap_hsmmc_reg_put(struct omap_hsmmc_host *host) |
| 354 | { |
| 355 | regulator_put(host->vcc); |
| 356 | regulator_put(host->vcc_aux); |
| 357 | mmc_slot(host).set_power = NULL; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 358 | } |
| 359 | |
Adrian Hunter | b702b10 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 360 | static inline int omap_hsmmc_have_reg(void) |
| 361 | { |
| 362 | return 1; |
| 363 | } |
| 364 | |
| 365 | #else |
| 366 | |
| 367 | static inline int omap_hsmmc_reg_get(struct omap_hsmmc_host *host) |
| 368 | { |
| 369 | return -EINVAL; |
| 370 | } |
| 371 | |
| 372 | static inline void omap_hsmmc_reg_put(struct omap_hsmmc_host *host) |
| 373 | { |
| 374 | } |
| 375 | |
| 376 | static inline int omap_hsmmc_have_reg(void) |
| 377 | { |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | #endif |
| 382 | |
| 383 | static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data *pdata) |
| 384 | { |
| 385 | int ret; |
| 386 | |
| 387 | if (gpio_is_valid(pdata->slots[0].switch_pin)) { |
Adrian Hunter | b702b10 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 388 | if (pdata->slots[0].cover) |
| 389 | pdata->slots[0].get_cover_state = |
| 390 | omap_hsmmc_get_cover_state; |
| 391 | else |
| 392 | pdata->slots[0].card_detect = omap_hsmmc_card_detect; |
| 393 | pdata->slots[0].card_detect_irq = |
| 394 | gpio_to_irq(pdata->slots[0].switch_pin); |
| 395 | ret = gpio_request(pdata->slots[0].switch_pin, "mmc_cd"); |
| 396 | if (ret) |
| 397 | return ret; |
| 398 | ret = gpio_direction_input(pdata->slots[0].switch_pin); |
| 399 | if (ret) |
| 400 | goto err_free_sp; |
| 401 | } else |
| 402 | pdata->slots[0].switch_pin = -EINVAL; |
| 403 | |
| 404 | if (gpio_is_valid(pdata->slots[0].gpio_wp)) { |
| 405 | pdata->slots[0].get_ro = omap_hsmmc_get_wp; |
| 406 | ret = gpio_request(pdata->slots[0].gpio_wp, "mmc_wp"); |
| 407 | if (ret) |
| 408 | goto err_free_cd; |
| 409 | ret = gpio_direction_input(pdata->slots[0].gpio_wp); |
| 410 | if (ret) |
| 411 | goto err_free_wp; |
| 412 | } else |
| 413 | pdata->slots[0].gpio_wp = -EINVAL; |
| 414 | |
| 415 | return 0; |
| 416 | |
| 417 | err_free_wp: |
| 418 | gpio_free(pdata->slots[0].gpio_wp); |
| 419 | err_free_cd: |
| 420 | if (gpio_is_valid(pdata->slots[0].switch_pin)) |
| 421 | err_free_sp: |
| 422 | gpio_free(pdata->slots[0].switch_pin); |
| 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | static void omap_hsmmc_gpio_free(struct omap_mmc_platform_data *pdata) |
| 427 | { |
| 428 | if (gpio_is_valid(pdata->slots[0].gpio_wp)) |
| 429 | gpio_free(pdata->slots[0].gpio_wp); |
| 430 | if (gpio_is_valid(pdata->slots[0].switch_pin)) |
| 431 | gpio_free(pdata->slots[0].switch_pin); |
| 432 | } |
| 433 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 434 | /* |
Andy Shevchenko | e0c7f99 | 2011-05-06 12:14:05 +0300 | [diff] [blame] | 435 | * Start clock to the card |
| 436 | */ |
| 437 | static void omap_hsmmc_start_clock(struct omap_hsmmc_host *host) |
| 438 | { |
| 439 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
| 440 | OMAP_HSMMC_READ(host->base, SYSCTL) | CEN); |
| 441 | } |
| 442 | |
| 443 | /* |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 444 | * Stop clock to the card |
| 445 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 446 | static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 447 | { |
| 448 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
| 449 | OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN); |
| 450 | if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0) |
| 451 | dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n"); |
| 452 | } |
| 453 | |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 454 | static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host, |
| 455 | struct mmc_command *cmd) |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 456 | { |
| 457 | unsigned int irq_mask; |
| 458 | |
| 459 | if (host->use_dma) |
| 460 | irq_mask = INT_EN_MASK & ~(BRR_ENABLE | BWR_ENABLE); |
| 461 | else |
| 462 | irq_mask = INT_EN_MASK; |
| 463 | |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 464 | /* Disable timeout for erases */ |
| 465 | if (cmd->opcode == MMC_ERASE) |
| 466 | irq_mask &= ~DTO_ENABLE; |
| 467 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 468 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
| 469 | OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); |
| 470 | OMAP_HSMMC_WRITE(host->base, IE, irq_mask); |
| 471 | } |
| 472 | |
| 473 | static void omap_hsmmc_disable_irq(struct omap_hsmmc_host *host) |
| 474 | { |
| 475 | OMAP_HSMMC_WRITE(host->base, ISE, 0); |
| 476 | OMAP_HSMMC_WRITE(host->base, IE, 0); |
| 477 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
| 478 | } |
| 479 | |
Andy Shevchenko | ac330f4 | 2011-05-10 15:51:54 +0300 | [diff] [blame] | 480 | /* Calculate divisor for the given clock frequency */ |
Balaji TK | d83b6e0 | 2011-12-20 15:12:00 +0530 | [diff] [blame] | 481 | static u16 calc_divisor(struct omap_hsmmc_host *host, struct mmc_ios *ios) |
Andy Shevchenko | ac330f4 | 2011-05-10 15:51:54 +0300 | [diff] [blame] | 482 | { |
| 483 | u16 dsor = 0; |
| 484 | |
| 485 | if (ios->clock) { |
Balaji TK | d83b6e0 | 2011-12-20 15:12:00 +0530 | [diff] [blame] | 486 | dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock); |
Andy Shevchenko | ac330f4 | 2011-05-10 15:51:54 +0300 | [diff] [blame] | 487 | if (dsor > 250) |
| 488 | dsor = 250; |
| 489 | } |
| 490 | |
| 491 | return dsor; |
| 492 | } |
| 493 | |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 494 | static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host) |
| 495 | { |
| 496 | struct mmc_ios *ios = &host->mmc->ios; |
| 497 | unsigned long regval; |
| 498 | unsigned long timeout; |
| 499 | |
| 500 | dev_dbg(mmc_dev(host->mmc), "Set clock to %uHz\n", ios->clock); |
| 501 | |
| 502 | omap_hsmmc_stop_clock(host); |
| 503 | |
| 504 | regval = OMAP_HSMMC_READ(host->base, SYSCTL); |
| 505 | regval = regval & ~(CLKD_MASK | DTO_MASK); |
Balaji TK | d83b6e0 | 2011-12-20 15:12:00 +0530 | [diff] [blame] | 506 | regval = regval | (calc_divisor(host, ios) << 6) | (DTO << 16); |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 507 | OMAP_HSMMC_WRITE(host->base, SYSCTL, regval); |
| 508 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
| 509 | OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); |
| 510 | |
| 511 | /* Wait till the ICS bit is set */ |
| 512 | timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); |
| 513 | while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS |
| 514 | && time_before(jiffies, timeout)) |
| 515 | cpu_relax(); |
| 516 | |
| 517 | omap_hsmmc_start_clock(host); |
| 518 | } |
| 519 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 520 | static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host *host) |
| 521 | { |
| 522 | struct mmc_ios *ios = &host->mmc->ios; |
| 523 | u32 con; |
| 524 | |
| 525 | con = OMAP_HSMMC_READ(host->base, CON); |
Balaji T K | 03b5d92 | 2012-04-09 12:08:33 +0530 | [diff] [blame] | 526 | if (ios->timing == MMC_TIMING_UHS_DDR50) |
| 527 | con |= DDR; /* configure in DDR mode */ |
| 528 | else |
| 529 | con &= ~DDR; |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 530 | switch (ios->bus_width) { |
| 531 | case MMC_BUS_WIDTH_8: |
| 532 | OMAP_HSMMC_WRITE(host->base, CON, con | DW8); |
| 533 | break; |
| 534 | case MMC_BUS_WIDTH_4: |
| 535 | OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8); |
| 536 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 537 | OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT); |
| 538 | break; |
| 539 | case MMC_BUS_WIDTH_1: |
| 540 | OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8); |
| 541 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 542 | OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT); |
| 543 | break; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host *host) |
| 548 | { |
| 549 | struct mmc_ios *ios = &host->mmc->ios; |
| 550 | u32 con; |
| 551 | |
| 552 | con = OMAP_HSMMC_READ(host->base, CON); |
| 553 | if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) |
| 554 | OMAP_HSMMC_WRITE(host->base, CON, con | OD); |
| 555 | else |
| 556 | OMAP_HSMMC_WRITE(host->base, CON, con & ~OD); |
| 557 | } |
| 558 | |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 559 | #ifdef CONFIG_PM |
| 560 | |
| 561 | /* |
| 562 | * Restore the MMC host context, if it was lost as result of a |
| 563 | * power state change. |
| 564 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 565 | static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 566 | { |
| 567 | struct mmc_ios *ios = &host->mmc->ios; |
| 568 | struct omap_mmc_platform_data *pdata = host->pdata; |
| 569 | int context_loss = 0; |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 570 | u32 hctl, capa; |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 571 | unsigned long timeout; |
| 572 | |
| 573 | if (pdata->get_context_loss_count) { |
| 574 | context_loss = pdata->get_context_loss_count(host->dev); |
| 575 | if (context_loss < 0) |
| 576 | return 1; |
| 577 | } |
| 578 | |
| 579 | dev_dbg(mmc_dev(host->mmc), "context was %slost\n", |
| 580 | context_loss == host->context_loss ? "not " : ""); |
| 581 | if (host->context_loss == context_loss) |
| 582 | return 1; |
| 583 | |
| 584 | /* Wait for hardware reset */ |
| 585 | timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); |
| 586 | while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE |
| 587 | && time_before(jiffies, timeout)) |
| 588 | ; |
| 589 | |
| 590 | /* Do software reset */ |
| 591 | OMAP_HSMMC_WRITE(host->base, SYSCONFIG, SOFTRESET); |
| 592 | timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); |
| 593 | while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE |
| 594 | && time_before(jiffies, timeout)) |
| 595 | ; |
| 596 | |
| 597 | OMAP_HSMMC_WRITE(host->base, SYSCONFIG, |
| 598 | OMAP_HSMMC_READ(host->base, SYSCONFIG) | AUTOIDLE); |
| 599 | |
Balaji T K | c2200ef | 2012-03-07 09:55:30 -0500 | [diff] [blame] | 600 | if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 601 | if (host->power_mode != MMC_POWER_OFF && |
| 602 | (1 << ios->vdd) <= MMC_VDD_23_24) |
| 603 | hctl = SDVS18; |
| 604 | else |
| 605 | hctl = SDVS30; |
| 606 | capa = VS30 | VS18; |
| 607 | } else { |
| 608 | hctl = SDVS18; |
| 609 | capa = VS18; |
| 610 | } |
| 611 | |
| 612 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 613 | OMAP_HSMMC_READ(host->base, HCTL) | hctl); |
| 614 | |
| 615 | OMAP_HSMMC_WRITE(host->base, CAPA, |
| 616 | OMAP_HSMMC_READ(host->base, CAPA) | capa); |
| 617 | |
| 618 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 619 | OMAP_HSMMC_READ(host->base, HCTL) | SDBP); |
| 620 | |
| 621 | timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); |
| 622 | while ((OMAP_HSMMC_READ(host->base, HCTL) & SDBP) != SDBP |
| 623 | && time_before(jiffies, timeout)) |
| 624 | ; |
| 625 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 626 | omap_hsmmc_disable_irq(host); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 627 | |
| 628 | /* Do not initialize card-specific things if the power is off */ |
| 629 | if (host->power_mode == MMC_POWER_OFF) |
| 630 | goto out; |
| 631 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 632 | omap_hsmmc_set_bus_width(host); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 633 | |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 634 | omap_hsmmc_set_clock(host); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 635 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 636 | omap_hsmmc_set_bus_mode(host); |
| 637 | |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 638 | out: |
| 639 | host->context_loss = context_loss; |
| 640 | |
| 641 | dev_dbg(mmc_dev(host->mmc), "context is restored\n"); |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * Save the MMC host context (store the number of power state changes so far). |
| 647 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 648 | static void omap_hsmmc_context_save(struct omap_hsmmc_host *host) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 649 | { |
| 650 | struct omap_mmc_platform_data *pdata = host->pdata; |
| 651 | int context_loss; |
| 652 | |
| 653 | if (pdata->get_context_loss_count) { |
| 654 | context_loss = pdata->get_context_loss_count(host->dev); |
| 655 | if (context_loss < 0) |
| 656 | return; |
| 657 | host->context_loss = context_loss; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | #else |
| 662 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 663 | static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 664 | { |
| 665 | return 0; |
| 666 | } |
| 667 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 668 | static void omap_hsmmc_context_save(struct omap_hsmmc_host *host) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 669 | { |
| 670 | } |
| 671 | |
| 672 | #endif |
| 673 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 674 | /* |
| 675 | * Send init stream sequence to card |
| 676 | * before sending IDLE command |
| 677 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 678 | static void send_init_stream(struct omap_hsmmc_host *host) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 679 | { |
| 680 | int reg = 0; |
| 681 | unsigned long timeout; |
| 682 | |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 683 | if (host->protect_card) |
| 684 | return; |
| 685 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 686 | disable_irq(host->irq); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 687 | |
| 688 | OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 689 | OMAP_HSMMC_WRITE(host->base, CON, |
| 690 | OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM); |
| 691 | OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD); |
| 692 | |
| 693 | timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); |
| 694 | while ((reg != CC) && time_before(jiffies, timeout)) |
| 695 | reg = OMAP_HSMMC_READ(host->base, STAT) & CC; |
| 696 | |
| 697 | OMAP_HSMMC_WRITE(host->base, CON, |
| 698 | OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM); |
Adrian Hunter | c653a6d | 2009-09-22 16:44:56 -0700 | [diff] [blame] | 699 | |
| 700 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
| 701 | OMAP_HSMMC_READ(host->base, STAT); |
| 702 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 703 | enable_irq(host->irq); |
| 704 | } |
| 705 | |
| 706 | static inline |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 707 | int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 708 | { |
| 709 | int r = 1; |
| 710 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 711 | if (mmc_slot(host).get_cover_state) |
| 712 | r = mmc_slot(host).get_cover_state(host->dev, host->slot_id); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 713 | return r; |
| 714 | } |
| 715 | |
| 716 | static ssize_t |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 717 | omap_hsmmc_show_cover_switch(struct device *dev, struct device_attribute *attr, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 718 | char *buf) |
| 719 | { |
| 720 | struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 721 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 722 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 723 | return sprintf(buf, "%s\n", |
| 724 | omap_hsmmc_cover_is_closed(host) ? "closed" : "open"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 725 | } |
| 726 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 727 | static DEVICE_ATTR(cover_switch, S_IRUGO, omap_hsmmc_show_cover_switch, NULL); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 728 | |
| 729 | static ssize_t |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 730 | omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 731 | char *buf) |
| 732 | { |
| 733 | struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 734 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 735 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 736 | return sprintf(buf, "%s\n", mmc_slot(host).name); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 737 | } |
| 738 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 739 | static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 740 | |
| 741 | /* |
| 742 | * Configure the response type and send the cmd. |
| 743 | */ |
| 744 | static void |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 745 | omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 746 | struct mmc_data *data) |
| 747 | { |
| 748 | int cmdreg = 0, resptype = 0, cmdtype = 0; |
| 749 | |
| 750 | dev_dbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n", |
| 751 | mmc_hostname(host->mmc), cmd->opcode, cmd->arg); |
| 752 | host->cmd = cmd; |
| 753 | |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 754 | omap_hsmmc_enable_irq(host, cmd); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 755 | |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 756 | host->response_busy = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 757 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 758 | if (cmd->flags & MMC_RSP_136) |
| 759 | resptype = 1; |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 760 | else if (cmd->flags & MMC_RSP_BUSY) { |
| 761 | resptype = 3; |
| 762 | host->response_busy = 1; |
| 763 | } else |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 764 | resptype = 2; |
| 765 | } |
| 766 | |
| 767 | /* |
| 768 | * Unlike OMAP1 controller, the cmdtype does not seem to be based on |
| 769 | * ac, bc, adtc, bcr. Only commands ending an open ended transfer need |
| 770 | * a val of 0x3, rest 0x0. |
| 771 | */ |
| 772 | if (cmd == host->mrq->stop) |
| 773 | cmdtype = 0x3; |
| 774 | |
| 775 | cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22); |
| 776 | |
| 777 | if (data) { |
| 778 | cmdreg |= DP_SELECT | MSBS | BCE; |
| 779 | if (data->flags & MMC_DATA_READ) |
| 780 | cmdreg |= DDIR; |
| 781 | else |
| 782 | cmdreg &= ~(DDIR); |
| 783 | } |
| 784 | |
| 785 | if (host->use_dma) |
| 786 | cmdreg |= DMA_EN; |
| 787 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 788 | host->req_in_progress = 1; |
Adrian Hunter | 4dffd7a | 2009-09-22 16:44:58 -0700 | [diff] [blame] | 789 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 790 | OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg); |
| 791 | OMAP_HSMMC_WRITE(host->base, CMD, cmdreg); |
| 792 | } |
| 793 | |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 794 | static int |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 795 | omap_hsmmc_get_dma_dir(struct omap_hsmmc_host *host, struct mmc_data *data) |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 796 | { |
| 797 | if (data->flags & MMC_DATA_WRITE) |
| 798 | return DMA_TO_DEVICE; |
| 799 | else |
| 800 | return DMA_FROM_DEVICE; |
| 801 | } |
| 802 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 803 | static struct dma_chan *omap_hsmmc_get_dma_chan(struct omap_hsmmc_host *host, |
| 804 | struct mmc_data *data) |
| 805 | { |
| 806 | return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan; |
| 807 | } |
| 808 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 809 | static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_request *mrq) |
| 810 | { |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 811 | int dma_ch, dma2; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 812 | unsigned long flags; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 813 | |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 814 | spin_lock_irqsave(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 815 | host->req_in_progress = 0; |
| 816 | dma_ch = host->dma_ch; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 817 | dma2 = host->dma2; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 818 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 819 | |
| 820 | omap_hsmmc_disable_irq(host); |
| 821 | /* Do not complete the request if DMA is still in progress */ |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 822 | if (mrq->data && host->use_dma && (dma_ch != -1 || dma2 != -1)) |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 823 | return; |
| 824 | host->mrq = NULL; |
| 825 | mmc_request_done(host->mmc, mrq); |
| 826 | } |
| 827 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 828 | /* |
| 829 | * Notify the transfer complete to MMC core |
| 830 | */ |
| 831 | static void |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 832 | omap_hsmmc_xfer_done(struct omap_hsmmc_host *host, struct mmc_data *data) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 833 | { |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 834 | if (!data) { |
| 835 | struct mmc_request *mrq = host->mrq; |
| 836 | |
Adrian Hunter | 2305010 | 2009-09-22 16:44:57 -0700 | [diff] [blame] | 837 | /* TC before CC from CMD6 - don't know why, but it happens */ |
| 838 | if (host->cmd && host->cmd->opcode == 6 && |
| 839 | host->response_busy) { |
| 840 | host->response_busy = 0; |
| 841 | return; |
| 842 | } |
| 843 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 844 | omap_hsmmc_request_done(host, mrq); |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 845 | return; |
| 846 | } |
| 847 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 848 | host->data = NULL; |
| 849 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 850 | if (!data->error) |
| 851 | data->bytes_xfered += data->blocks * (data->blksz); |
| 852 | else |
| 853 | data->bytes_xfered = 0; |
| 854 | |
Ming Lei | fe85227 | 2012-06-22 18:49:35 +0800 | [diff] [blame] | 855 | if (!data->stop) { |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 856 | omap_hsmmc_request_done(host, data->mrq); |
Ming Lei | fe85227 | 2012-06-22 18:49:35 +0800 | [diff] [blame] | 857 | return; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 858 | } |
Ming Lei | fe85227 | 2012-06-22 18:49:35 +0800 | [diff] [blame] | 859 | omap_hsmmc_start_command(host, data->stop, NULL); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | /* |
| 863 | * Notify the core about command completion |
| 864 | */ |
| 865 | static void |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 866 | omap_hsmmc_cmd_done(struct omap_hsmmc_host *host, struct mmc_command *cmd) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 867 | { |
| 868 | host->cmd = NULL; |
| 869 | |
| 870 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 871 | if (cmd->flags & MMC_RSP_136) { |
| 872 | /* response type 2 */ |
| 873 | cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10); |
| 874 | cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32); |
| 875 | cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54); |
| 876 | cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76); |
| 877 | } else { |
| 878 | /* response types 1, 1b, 3, 4, 5, 6 */ |
| 879 | cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10); |
| 880 | } |
| 881 | } |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 882 | if ((host->data == NULL && !host->response_busy) || cmd->error) |
| 883 | omap_hsmmc_request_done(host, cmd->mrq); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /* |
| 887 | * DMA clean up for command errors |
| 888 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 889 | static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host *host, int errno) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 890 | { |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 891 | int dma_ch, dma2; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 892 | unsigned long flags; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 893 | |
Jarkko Lavinen | 82788ff | 2008-12-05 12:31:46 +0200 | [diff] [blame] | 894 | host->data->error = errno; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 895 | |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 896 | spin_lock_irqsave(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 897 | dma_ch = host->dma_ch; |
| 898 | host->dma_ch = -1; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 899 | dma2 = host->dma2; |
| 900 | host->dma2 = -1; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 901 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 902 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 903 | if (host->use_dma && dma2 != -1) { |
| 904 | struct dma_chan *chan = omap_hsmmc_get_dma_chan(host, host->data); |
| 905 | |
| 906 | dmaengine_terminate_all(chan); |
| 907 | dma_unmap_sg(chan->device->dev, |
| 908 | host->data->sg, host->data->sg_len, |
| 909 | omap_hsmmc_get_dma_dir(host, host->data)); |
| 910 | |
| 911 | host->data->host_cookie = 0; |
| 912 | } |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 913 | if (host->use_dma && dma_ch != -1) { |
Per Forlin | a9120c3 | 2011-06-17 20:14:21 +0200 | [diff] [blame] | 914 | dma_unmap_sg(mmc_dev(host->mmc), host->data->sg, |
| 915 | host->data->sg_len, |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 916 | omap_hsmmc_get_dma_dir(host, host->data)); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 917 | omap_free_dma(dma_ch); |
Per Forlin | 053bf34 | 2011-11-07 21:55:11 +0530 | [diff] [blame] | 918 | host->data->host_cookie = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 919 | } |
| 920 | host->data = NULL; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | /* |
| 924 | * Readable error output |
| 925 | */ |
| 926 | #ifdef CONFIG_MMC_DEBUG |
Adrian Hunter | 699b958 | 2011-05-06 12:14:01 +0300 | [diff] [blame] | 927 | static void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host, u32 status) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 928 | { |
| 929 | /* --- means reserved bit without definition at documentation */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 930 | static const char *omap_hsmmc_status_bits[] = { |
Adrian Hunter | 699b958 | 2011-05-06 12:14:01 +0300 | [diff] [blame] | 931 | "CC" , "TC" , "BGE", "---", "BWR" , "BRR" , "---" , "---" , |
| 932 | "CIRQ", "OBI" , "---", "---", "---" , "---" , "---" , "ERRI", |
| 933 | "CTO" , "CCRC", "CEB", "CIE", "DTO" , "DCRC", "DEB" , "---" , |
| 934 | "ACE" , "---" , "---", "---", "CERR", "BADA", "---" , "---" |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 935 | }; |
| 936 | char res[256]; |
| 937 | char *buf = res; |
| 938 | int len, i; |
| 939 | |
| 940 | len = sprintf(buf, "MMC IRQ 0x%x :", status); |
| 941 | buf += len; |
| 942 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 943 | for (i = 0; i < ARRAY_SIZE(omap_hsmmc_status_bits); i++) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 944 | if (status & (1 << i)) { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 945 | len = sprintf(buf, " %s", omap_hsmmc_status_bits[i]); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 946 | buf += len; |
| 947 | } |
| 948 | |
| 949 | dev_dbg(mmc_dev(host->mmc), "%s\n", res); |
| 950 | } |
Adrian Hunter | 699b958 | 2011-05-06 12:14:01 +0300 | [diff] [blame] | 951 | #else |
| 952 | static inline void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host, |
| 953 | u32 status) |
| 954 | { |
| 955 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 956 | #endif /* CONFIG_MMC_DEBUG */ |
| 957 | |
Jean Pihet | 3ebf74b | 2009-02-06 16:42:51 +0100 | [diff] [blame] | 958 | /* |
| 959 | * MMC controller internal state machines reset |
| 960 | * |
| 961 | * Used to reset command or data internal state machines, using respectively |
| 962 | * SRC or SRD bit of SYSCTL register |
| 963 | * Can be called from interrupt context |
| 964 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 965 | static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host, |
| 966 | unsigned long bit) |
Jean Pihet | 3ebf74b | 2009-02-06 16:42:51 +0100 | [diff] [blame] | 967 | { |
| 968 | unsigned long i = 0; |
| 969 | unsigned long limit = (loops_per_jiffy * |
| 970 | msecs_to_jiffies(MMC_TIMEOUT_MS)); |
| 971 | |
| 972 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
| 973 | OMAP_HSMMC_READ(host->base, SYSCTL) | bit); |
| 974 | |
Madhusudhan Chikkature | 07ad64b | 2010-10-01 16:35:25 -0700 | [diff] [blame] | 975 | /* |
| 976 | * OMAP4 ES2 and greater has an updated reset logic. |
| 977 | * Monitor a 0->1 transition first |
| 978 | */ |
| 979 | if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) { |
kishore kadiyala | b432b4b | 2010-11-17 22:35:32 -0500 | [diff] [blame] | 980 | while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit)) |
Madhusudhan Chikkature | 07ad64b | 2010-10-01 16:35:25 -0700 | [diff] [blame] | 981 | && (i++ < limit)) |
| 982 | cpu_relax(); |
| 983 | } |
| 984 | i = 0; |
| 985 | |
Jean Pihet | 3ebf74b | 2009-02-06 16:42:51 +0100 | [diff] [blame] | 986 | while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) && |
| 987 | (i++ < limit)) |
| 988 | cpu_relax(); |
| 989 | |
| 990 | if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit) |
| 991 | dev_err(mmc_dev(host->mmc), |
| 992 | "Timeout waiting on controller reset in %s\n", |
| 993 | __func__); |
| 994 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 995 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 996 | static void omap_hsmmc_do_irq(struct omap_hsmmc_host *host, int status) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 997 | { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 998 | struct mmc_data *data; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 999 | int end_cmd = 0, end_trans = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1000 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1001 | if (!host->req_in_progress) { |
| 1002 | do { |
| 1003 | OMAP_HSMMC_WRITE(host->base, STAT, status); |
| 1004 | /* Flush posted write */ |
| 1005 | status = OMAP_HSMMC_READ(host->base, STAT); |
| 1006 | } while (status & INT_EN_MASK); |
| 1007 | return; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | data = host->data; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1011 | dev_dbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status); |
| 1012 | |
| 1013 | if (status & ERR) { |
Adrian Hunter | 699b958 | 2011-05-06 12:14:01 +0300 | [diff] [blame] | 1014 | omap_hsmmc_dbg_report_irq(host, status); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1015 | if ((status & CMD_TIMEOUT) || |
| 1016 | (status & CMD_CRC)) { |
| 1017 | if (host->cmd) { |
| 1018 | if (status & CMD_TIMEOUT) { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1019 | omap_hsmmc_reset_controller_fsm(host, |
| 1020 | SRC); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1021 | host->cmd->error = -ETIMEDOUT; |
| 1022 | } else { |
| 1023 | host->cmd->error = -EILSEQ; |
| 1024 | } |
| 1025 | end_cmd = 1; |
| 1026 | } |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 1027 | if (host->data || host->response_busy) { |
| 1028 | if (host->data) |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1029 | omap_hsmmc_dma_cleanup(host, |
| 1030 | -ETIMEDOUT); |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 1031 | host->response_busy = 0; |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1032 | omap_hsmmc_reset_controller_fsm(host, SRD); |
Jean Pihet | c232f45 | 2009-02-11 13:11:39 -0800 | [diff] [blame] | 1033 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1034 | } |
| 1035 | if ((status & DATA_TIMEOUT) || |
| 1036 | (status & DATA_CRC)) { |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 1037 | if (host->data || host->response_busy) { |
| 1038 | int err = (status & DATA_TIMEOUT) ? |
| 1039 | -ETIMEDOUT : -EILSEQ; |
| 1040 | |
| 1041 | if (host->data) |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1042 | omap_hsmmc_dma_cleanup(host, err); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1043 | else |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 1044 | host->mrq->cmd->error = err; |
| 1045 | host->response_busy = 0; |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1046 | omap_hsmmc_reset_controller_fsm(host, SRD); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1047 | end_trans = 1; |
| 1048 | } |
| 1049 | } |
| 1050 | if (status & CARD_ERR) { |
| 1051 | dev_dbg(mmc_dev(host->mmc), |
| 1052 | "Ignoring card err CMD%d\n", host->cmd->opcode); |
| 1053 | if (host->cmd) |
| 1054 | end_cmd = 1; |
| 1055 | if (host->data) |
| 1056 | end_trans = 1; |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | OMAP_HSMMC_WRITE(host->base, STAT, status); |
| 1061 | |
Jarkko Lavinen | a8fe29d | 2009-04-08 11:18:32 +0300 | [diff] [blame] | 1062 | if (end_cmd || ((status & CC) && host->cmd)) |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1063 | omap_hsmmc_cmd_done(host, host->cmd); |
Jarkko Lavinen | 0a40e64 | 2009-09-22 16:44:54 -0700 | [diff] [blame] | 1064 | if ((end_trans || (status & TC)) && host->mrq) |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1065 | omap_hsmmc_xfer_done(host, data); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1066 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1067 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1068 | /* |
| 1069 | * MMC controller IRQ handler |
| 1070 | */ |
| 1071 | static irqreturn_t omap_hsmmc_irq(int irq, void *dev_id) |
| 1072 | { |
| 1073 | struct omap_hsmmc_host *host = dev_id; |
| 1074 | int status; |
| 1075 | |
| 1076 | status = OMAP_HSMMC_READ(host->base, STAT); |
| 1077 | do { |
| 1078 | omap_hsmmc_do_irq(host, status); |
| 1079 | /* Flush posted write */ |
| 1080 | status = OMAP_HSMMC_READ(host->base, STAT); |
| 1081 | } while (status & INT_EN_MASK); |
Adrian Hunter | 4dffd7a | 2009-09-22 16:44:58 -0700 | [diff] [blame] | 1082 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1083 | return IRQ_HANDLED; |
| 1084 | } |
| 1085 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1086 | static void set_sd_bus_power(struct omap_hsmmc_host *host) |
Adrian Hunter | e13bb30 | 2009-03-12 17:08:26 +0200 | [diff] [blame] | 1087 | { |
| 1088 | unsigned long i; |
| 1089 | |
| 1090 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 1091 | OMAP_HSMMC_READ(host->base, HCTL) | SDBP); |
| 1092 | for (i = 0; i < loops_per_jiffy; i++) { |
| 1093 | if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP) |
| 1094 | break; |
| 1095 | cpu_relax(); |
| 1096 | } |
| 1097 | } |
| 1098 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1099 | /* |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1100 | * Switch MMC interface voltage ... only relevant for MMC1. |
| 1101 | * |
| 1102 | * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver. |
| 1103 | * The MMC2 transceiver controls are used instead of DAT4..DAT7. |
| 1104 | * Some chips, like eMMC ones, use internal transceivers. |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1105 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1106 | static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1107 | { |
| 1108 | u32 reg_val = 0; |
| 1109 | int ret; |
| 1110 | |
| 1111 | /* Disable the clocks */ |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1112 | pm_runtime_put_sync(host->dev); |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 1113 | if (host->dbclk) |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 1114 | clk_disable(host->dbclk); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1115 | |
| 1116 | /* Turn the power off */ |
| 1117 | ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1118 | |
| 1119 | /* Turn the power ON with given VDD 1.8 or 3.0v */ |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 1120 | if (!ret) |
| 1121 | ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, |
| 1122 | vdd); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1123 | pm_runtime_get_sync(host->dev); |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 1124 | if (host->dbclk) |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 1125 | clk_enable(host->dbclk); |
| 1126 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1127 | if (ret != 0) |
| 1128 | goto err; |
| 1129 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1130 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 1131 | OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR); |
| 1132 | reg_val = OMAP_HSMMC_READ(host->base, HCTL); |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1133 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1134 | /* |
| 1135 | * If a MMC dual voltage card is detected, the set_ios fn calls |
| 1136 | * this fn with VDD bit set for 1.8V. Upon card removal from the |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1137 | * slot, omap_hsmmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF. |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1138 | * |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1139 | * Cope with a bit of slop in the range ... per data sheets: |
| 1140 | * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max, |
| 1141 | * but recommended values are 1.71V to 1.89V |
| 1142 | * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max, |
| 1143 | * but recommended values are 2.7V to 3.3V |
| 1144 | * |
| 1145 | * Board setup code shouldn't permit anything very out-of-range. |
| 1146 | * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the |
| 1147 | * middle range) but VSIM can't power DAT4..DAT7 at more than 3V. |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1148 | */ |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1149 | if ((1 << vdd) <= MMC_VDD_23_24) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1150 | reg_val |= SDVS18; |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1151 | else |
| 1152 | reg_val |= SDVS30; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1153 | |
| 1154 | OMAP_HSMMC_WRITE(host->base, HCTL, reg_val); |
Adrian Hunter | e13bb30 | 2009-03-12 17:08:26 +0200 | [diff] [blame] | 1155 | set_sd_bus_power(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1156 | |
| 1157 | return 0; |
| 1158 | err: |
| 1159 | dev_dbg(mmc_dev(host->mmc), "Unable to switch operating voltage\n"); |
| 1160 | return ret; |
| 1161 | } |
| 1162 | |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1163 | /* Protect the card while the cover is open */ |
| 1164 | static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host) |
| 1165 | { |
| 1166 | if (!mmc_slot(host).get_cover_state) |
| 1167 | return; |
| 1168 | |
| 1169 | host->reqs_blocked = 0; |
| 1170 | if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) { |
| 1171 | if (host->protect_card) { |
Rajendra Nayak | 2cecdf0 | 2012-02-23 17:02:20 +0530 | [diff] [blame] | 1172 | dev_info(host->dev, "%s: cover is closed, " |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1173 | "card is now accessible\n", |
| 1174 | mmc_hostname(host->mmc)); |
| 1175 | host->protect_card = 0; |
| 1176 | } |
| 1177 | } else { |
| 1178 | if (!host->protect_card) { |
Rajendra Nayak | 2cecdf0 | 2012-02-23 17:02:20 +0530 | [diff] [blame] | 1179 | dev_info(host->dev, "%s: cover is open, " |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1180 | "card is now inaccessible\n", |
| 1181 | mmc_hostname(host->mmc)); |
| 1182 | host->protect_card = 1; |
| 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1187 | /* |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 1188 | * irq handler to notify the core about card insertion/removal |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1189 | */ |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 1190 | static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1191 | { |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 1192 | struct omap_hsmmc_host *host = dev_id; |
David Brownell | 249d0fa | 2009-02-04 14:42:03 -0800 | [diff] [blame] | 1193 | struct omap_mmc_slot_data *slot = &mmc_slot(host); |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1194 | int carddetect; |
David Brownell | 249d0fa | 2009-02-04 14:42:03 -0800 | [diff] [blame] | 1195 | |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1196 | if (host->suspended) |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 1197 | return IRQ_HANDLED; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1198 | |
| 1199 | sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch"); |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1200 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1201 | if (slot->card_detect) |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1202 | carddetect = slot->card_detect(host->dev, host->slot_id); |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1203 | else { |
| 1204 | omap_hsmmc_protect_card(host); |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1205 | carddetect = -ENOSYS; |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1206 | } |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1207 | |
Madhusudhan Chikkature | cdeebad | 2010-04-06 14:34:49 -0700 | [diff] [blame] | 1208 | if (carddetect) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1209 | mmc_detect_change(host->mmc, (HZ * 200) / 1000); |
Madhusudhan Chikkature | cdeebad | 2010-04-06 14:34:49 -0700 | [diff] [blame] | 1210 | else |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1211 | mmc_detect_change(host->mmc, (HZ * 50) / 1000); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1212 | return IRQ_HANDLED; |
| 1213 | } |
| 1214 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1215 | static int omap_hsmmc_get_dma_sync_dev(struct omap_hsmmc_host *host, |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1216 | struct mmc_data *data) |
| 1217 | { |
| 1218 | int sync_dev; |
| 1219 | |
Grazvydas Ignotas | f3e2f1d | 2009-01-03 10:36:13 +0000 | [diff] [blame] | 1220 | if (data->flags & MMC_DATA_WRITE) |
| 1221 | sync_dev = host->dma_line_tx; |
| 1222 | else |
| 1223 | sync_dev = host->dma_line_rx; |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1224 | return sync_dev; |
| 1225 | } |
| 1226 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1227 | static void omap_hsmmc_config_dma_params(struct omap_hsmmc_host *host, |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1228 | struct mmc_data *data, |
| 1229 | struct scatterlist *sgl) |
| 1230 | { |
| 1231 | int blksz, nblk, dma_ch; |
| 1232 | |
| 1233 | dma_ch = host->dma_ch; |
| 1234 | if (data->flags & MMC_DATA_WRITE) { |
| 1235 | omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT, |
| 1236 | (host->mapbase + OMAP_HSMMC_DATA), 0, 0); |
| 1237 | omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC, |
| 1238 | sg_dma_address(sgl), 0, 0); |
| 1239 | } else { |
| 1240 | omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT, |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1241 | (host->mapbase + OMAP_HSMMC_DATA), 0, 0); |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1242 | omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC, |
| 1243 | sg_dma_address(sgl), 0, 0); |
| 1244 | } |
| 1245 | |
| 1246 | blksz = host->data->blksz; |
| 1247 | nblk = sg_dma_len(sgl) / blksz; |
| 1248 | |
| 1249 | omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32, |
| 1250 | blksz / 4, nblk, OMAP_DMA_SYNC_FRAME, |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1251 | omap_hsmmc_get_dma_sync_dev(host, data), |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1252 | !(data->flags & MMC_DATA_WRITE)); |
| 1253 | |
| 1254 | omap_start_dma(dma_ch); |
| 1255 | } |
| 1256 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1257 | /* |
| 1258 | * DMA call back function |
| 1259 | */ |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1260 | static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *cb_data) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1261 | { |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1262 | struct omap_hsmmc_host *host = cb_data; |
Adrian Hunter | 770d743 | 2011-05-06 12:14:11 +0300 | [diff] [blame] | 1263 | struct mmc_data *data; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1264 | int dma_ch, req_in_progress; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 1265 | unsigned long flags; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1266 | |
Venkatraman S | f3584e5 | 2010-08-10 18:01:54 -0700 | [diff] [blame] | 1267 | if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) { |
| 1268 | dev_warn(mmc_dev(host->mmc), "unexpected dma status %x\n", |
| 1269 | ch_status); |
| 1270 | return; |
| 1271 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1272 | |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 1273 | spin_lock_irqsave(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1274 | if (host->dma_ch < 0) { |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 1275 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1276 | return; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1277 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1278 | |
Adrian Hunter | 770d743 | 2011-05-06 12:14:11 +0300 | [diff] [blame] | 1279 | data = host->mrq->data; |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1280 | host->dma_sg_idx++; |
| 1281 | if (host->dma_sg_idx < host->dma_len) { |
| 1282 | /* Fire up the next transfer. */ |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1283 | omap_hsmmc_config_dma_params(host, data, |
| 1284 | data->sg + host->dma_sg_idx); |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 1285 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1286 | return; |
| 1287 | } |
| 1288 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1289 | if (!data->host_cookie) |
| 1290 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, |
| 1291 | omap_hsmmc_get_dma_dir(host, data)); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1292 | |
| 1293 | req_in_progress = host->req_in_progress; |
| 1294 | dma_ch = host->dma_ch; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1295 | host->dma_ch = -1; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 1296 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1297 | |
| 1298 | omap_free_dma(dma_ch); |
| 1299 | |
| 1300 | /* If DMA has finished after TC, complete the request */ |
| 1301 | if (!req_in_progress) { |
| 1302 | struct mmc_request *mrq = host->mrq; |
| 1303 | |
| 1304 | host->mrq = NULL; |
| 1305 | mmc_request_done(host->mmc, mrq); |
| 1306 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1307 | } |
| 1308 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1309 | static void omap_hsmmc_dma_callback(void *param) |
| 1310 | { |
| 1311 | struct omap_hsmmc_host *host = param; |
| 1312 | struct dma_chan *chan; |
| 1313 | struct mmc_data *data; |
| 1314 | int req_in_progress; |
| 1315 | |
| 1316 | spin_lock_irq(&host->irq_lock); |
| 1317 | if (host->dma2 < 0) { |
| 1318 | spin_unlock_irq(&host->irq_lock); |
| 1319 | return; |
| 1320 | } |
| 1321 | |
| 1322 | data = host->mrq->data; |
| 1323 | chan = omap_hsmmc_get_dma_chan(host, data); |
| 1324 | if (!data->host_cookie) |
| 1325 | dma_unmap_sg(chan->device->dev, |
| 1326 | data->sg, data->sg_len, |
| 1327 | omap_hsmmc_get_dma_dir(host, data)); |
| 1328 | |
| 1329 | req_in_progress = host->req_in_progress; |
| 1330 | host->dma2 = -1; |
| 1331 | spin_unlock_irq(&host->irq_lock); |
| 1332 | |
| 1333 | /* If DMA has finished after TC, complete the request */ |
| 1334 | if (!req_in_progress) { |
| 1335 | struct mmc_request *mrq = host->mrq; |
| 1336 | |
| 1337 | host->mrq = NULL; |
| 1338 | mmc_request_done(host->mmc, mrq); |
| 1339 | } |
| 1340 | } |
| 1341 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1342 | static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host, |
| 1343 | struct mmc_data *data, |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1344 | struct omap_hsmmc_next *next, |
| 1345 | struct device *dev) |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1346 | { |
| 1347 | int dma_len; |
| 1348 | |
| 1349 | if (!next && data->host_cookie && |
| 1350 | data->host_cookie != host->next_data.cookie) { |
Rajendra Nayak | 2cecdf0 | 2012-02-23 17:02:20 +0530 | [diff] [blame] | 1351 | dev_warn(host->dev, "[%s] invalid cookie: data->host_cookie %d" |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1352 | " host->next_data.cookie %d\n", |
| 1353 | __func__, data->host_cookie, host->next_data.cookie); |
| 1354 | data->host_cookie = 0; |
| 1355 | } |
| 1356 | |
| 1357 | /* Check if next job is already prepared */ |
| 1358 | if (next || |
| 1359 | (!next && data->host_cookie != host->next_data.cookie)) { |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1360 | dma_len = dma_map_sg(dev, data->sg, data->sg_len, |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1361 | omap_hsmmc_get_dma_dir(host, data)); |
| 1362 | |
| 1363 | } else { |
| 1364 | dma_len = host->next_data.dma_len; |
| 1365 | host->next_data.dma_len = 0; |
| 1366 | } |
| 1367 | |
| 1368 | |
| 1369 | if (dma_len == 0) |
| 1370 | return -EINVAL; |
| 1371 | |
| 1372 | if (next) { |
| 1373 | next->dma_len = dma_len; |
| 1374 | data->host_cookie = ++next->cookie < 0 ? 1 : next->cookie; |
| 1375 | } else |
| 1376 | host->dma_len = dma_len; |
| 1377 | |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1381 | /* |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1382 | * Routine to configure and start DMA for the MMC card |
| 1383 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1384 | static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host, |
| 1385 | struct mmc_request *req) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1386 | { |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1387 | int dma_ch = 0, ret = 0, i; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1388 | struct mmc_data *data = req->data; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1389 | struct dma_chan *chan; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1390 | |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1391 | /* Sanity check: all the SG entries must be aligned by block size. */ |
Jarkko Lavinen | a3f406f | 2009-09-22 16:44:46 -0700 | [diff] [blame] | 1392 | for (i = 0; i < data->sg_len; i++) { |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1393 | struct scatterlist *sgl; |
| 1394 | |
| 1395 | sgl = data->sg + i; |
| 1396 | if (sgl->length % data->blksz) |
| 1397 | return -EINVAL; |
| 1398 | } |
| 1399 | if ((data->blksz % 4) != 0) |
| 1400 | /* REVISIT: The MMC buffer increments only when MSB is written. |
| 1401 | * Return error for blksz which is non multiple of four. |
| 1402 | */ |
| 1403 | return -EINVAL; |
| 1404 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1405 | BUG_ON(host->dma_ch != -1 || host->dma2 != -1); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1406 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1407 | chan = omap_hsmmc_get_dma_chan(host, data); |
| 1408 | if (!chan) { |
| 1409 | ret = omap_request_dma(omap_hsmmc_get_dma_sync_dev(host, data), |
| 1410 | "MMC/SD", omap_hsmmc_dma_cb, host, &dma_ch); |
| 1411 | if (ret != 0) { |
| 1412 | dev_err(mmc_dev(host->mmc), |
| 1413 | "%s: omap_request_dma() failed with %d\n", |
| 1414 | mmc_hostname(host->mmc), ret); |
| 1415 | return ret; |
| 1416 | } |
| 1417 | ret = omap_hsmmc_pre_dma_transfer(host, data, NULL, |
| 1418 | mmc_dev(host->mmc)); |
| 1419 | if (ret) |
| 1420 | return ret; |
| 1421 | |
| 1422 | host->dma_ch = dma_ch; |
| 1423 | host->dma_sg_idx = 0; |
| 1424 | |
| 1425 | omap_hsmmc_config_dma_params(host, data, data->sg); |
| 1426 | } else { |
| 1427 | struct dma_slave_config cfg; |
| 1428 | struct dma_async_tx_descriptor *tx; |
| 1429 | |
| 1430 | cfg.src_addr = host->mapbase + OMAP_HSMMC_DATA; |
| 1431 | cfg.dst_addr = host->mapbase + OMAP_HSMMC_DATA; |
| 1432 | cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 1433 | cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 1434 | cfg.src_maxburst = data->blksz / 4; |
| 1435 | cfg.dst_maxburst = data->blksz / 4; |
| 1436 | |
| 1437 | ret = dmaengine_slave_config(chan, &cfg); |
| 1438 | if (ret) |
| 1439 | return ret; |
| 1440 | |
| 1441 | ret = omap_hsmmc_pre_dma_transfer(host, data, NULL, |
| 1442 | chan->device->dev); |
| 1443 | if (ret) |
| 1444 | return ret; |
| 1445 | |
| 1446 | tx = dmaengine_prep_slave_sg(chan, data->sg, data->sg_len, |
| 1447 | data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, |
| 1448 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 1449 | if (!tx) { |
| 1450 | dev_err(mmc_dev(host->mmc), "prep_slave_sg() failed\n"); |
| 1451 | /* FIXME: cleanup */ |
| 1452 | return -1; |
| 1453 | } |
| 1454 | |
| 1455 | tx->callback = omap_hsmmc_dma_callback; |
| 1456 | tx->callback_param = host; |
| 1457 | |
| 1458 | /* Does not fail */ |
| 1459 | dmaengine_submit(tx); |
| 1460 | |
| 1461 | host->dma2 = 1; |
| 1462 | |
| 1463 | dma_async_issue_pending(chan); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1464 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1465 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1466 | return 0; |
| 1467 | } |
| 1468 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1469 | static void set_data_timeout(struct omap_hsmmc_host *host, |
Adrian Hunter | e2bf08d | 2009-09-22 16:45:03 -0700 | [diff] [blame] | 1470 | unsigned int timeout_ns, |
| 1471 | unsigned int timeout_clks) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1472 | { |
| 1473 | unsigned int timeout, cycle_ns; |
| 1474 | uint32_t reg, clkd, dto = 0; |
| 1475 | |
| 1476 | reg = OMAP_HSMMC_READ(host->base, SYSCTL); |
| 1477 | clkd = (reg & CLKD_MASK) >> CLKD_SHIFT; |
| 1478 | if (clkd == 0) |
| 1479 | clkd = 1; |
| 1480 | |
| 1481 | cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd); |
Adrian Hunter | e2bf08d | 2009-09-22 16:45:03 -0700 | [diff] [blame] | 1482 | timeout = timeout_ns / cycle_ns; |
| 1483 | timeout += timeout_clks; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1484 | if (timeout) { |
| 1485 | while ((timeout & 0x80000000) == 0) { |
| 1486 | dto += 1; |
| 1487 | timeout <<= 1; |
| 1488 | } |
| 1489 | dto = 31 - dto; |
| 1490 | timeout <<= 1; |
| 1491 | if (timeout && dto) |
| 1492 | dto += 1; |
| 1493 | if (dto >= 13) |
| 1494 | dto -= 13; |
| 1495 | else |
| 1496 | dto = 0; |
| 1497 | if (dto > 14) |
| 1498 | dto = 14; |
| 1499 | } |
| 1500 | |
| 1501 | reg &= ~DTO_MASK; |
| 1502 | reg |= dto << DTO_SHIFT; |
| 1503 | OMAP_HSMMC_WRITE(host->base, SYSCTL, reg); |
| 1504 | } |
| 1505 | |
| 1506 | /* |
| 1507 | * Configure block length for MMC/SD cards and initiate the transfer. |
| 1508 | */ |
| 1509 | static int |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1510 | omap_hsmmc_prepare_data(struct omap_hsmmc_host *host, struct mmc_request *req) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1511 | { |
| 1512 | int ret; |
| 1513 | host->data = req->data; |
| 1514 | |
| 1515 | if (req->data == NULL) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1516 | OMAP_HSMMC_WRITE(host->base, BLK, 0); |
Adrian Hunter | e2bf08d | 2009-09-22 16:45:03 -0700 | [diff] [blame] | 1517 | /* |
| 1518 | * Set an arbitrary 100ms data timeout for commands with |
| 1519 | * busy signal. |
| 1520 | */ |
| 1521 | if (req->cmd->flags & MMC_RSP_BUSY) |
| 1522 | set_data_timeout(host, 100000000U, 0); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1523 | return 0; |
| 1524 | } |
| 1525 | |
| 1526 | OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz) |
| 1527 | | (req->data->blocks << 16)); |
Adrian Hunter | e2bf08d | 2009-09-22 16:45:03 -0700 | [diff] [blame] | 1528 | set_data_timeout(host, req->data->timeout_ns, req->data->timeout_clks); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1529 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1530 | if (host->use_dma) { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1531 | ret = omap_hsmmc_start_dma_transfer(host, req); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1532 | if (ret != 0) { |
| 1533 | dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n"); |
| 1534 | return ret; |
| 1535 | } |
| 1536 | } |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1540 | static void omap_hsmmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq, |
| 1541 | int err) |
| 1542 | { |
| 1543 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
| 1544 | struct mmc_data *data = mrq->data; |
| 1545 | |
| 1546 | if (host->use_dma) { |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1547 | struct dma_chan *c = omap_hsmmc_get_dma_chan(host, data); |
| 1548 | struct device *dev = c ? c->device->dev : mmc_dev(mmc); |
| 1549 | |
Per Forlin | 053bf34 | 2011-11-07 21:55:11 +0530 | [diff] [blame] | 1550 | if (data->host_cookie) |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1551 | dma_unmap_sg(dev, |
| 1552 | data->sg, data->sg_len, |
Per Forlin | 053bf34 | 2011-11-07 21:55:11 +0530 | [diff] [blame] | 1553 | omap_hsmmc_get_dma_dir(host, data)); |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1554 | data->host_cookie = 0; |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | static void omap_hsmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, |
| 1559 | bool is_first_req) |
| 1560 | { |
| 1561 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
| 1562 | |
| 1563 | if (mrq->data->host_cookie) { |
| 1564 | mrq->data->host_cookie = 0; |
| 1565 | return ; |
| 1566 | } |
| 1567 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1568 | if (host->use_dma) { |
| 1569 | struct dma_chan *c = omap_hsmmc_get_dma_chan(host, mrq->data); |
| 1570 | struct device *dev = c ? c->device->dev : mmc_dev(mmc); |
| 1571 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1572 | if (omap_hsmmc_pre_dma_transfer(host, mrq->data, |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1573 | &host->next_data, dev)) |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1574 | mrq->data->host_cookie = 0; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1575 | } |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1576 | } |
| 1577 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1578 | /* |
| 1579 | * Request function. for read/write operation |
| 1580 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1581 | static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1582 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1583 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Jarkko Lavinen | a3f406f | 2009-09-22 16:44:46 -0700 | [diff] [blame] | 1584 | int err; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1585 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1586 | BUG_ON(host->req_in_progress); |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1587 | BUG_ON(host->dma_ch != -1 || host->dma2 != -1); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1588 | if (host->protect_card) { |
| 1589 | if (host->reqs_blocked < 3) { |
| 1590 | /* |
| 1591 | * Ensure the controller is left in a consistent |
| 1592 | * state by resetting the command and data state |
| 1593 | * machines. |
| 1594 | */ |
| 1595 | omap_hsmmc_reset_controller_fsm(host, SRD); |
| 1596 | omap_hsmmc_reset_controller_fsm(host, SRC); |
| 1597 | host->reqs_blocked += 1; |
| 1598 | } |
| 1599 | req->cmd->error = -EBADF; |
| 1600 | if (req->data) |
| 1601 | req->data->error = -EBADF; |
| 1602 | req->cmd->retries = 0; |
| 1603 | mmc_request_done(mmc, req); |
| 1604 | return; |
| 1605 | } else if (host->reqs_blocked) |
| 1606 | host->reqs_blocked = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1607 | WARN_ON(host->mrq != NULL); |
| 1608 | host->mrq = req; |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1609 | err = omap_hsmmc_prepare_data(host, req); |
Jarkko Lavinen | a3f406f | 2009-09-22 16:44:46 -0700 | [diff] [blame] | 1610 | if (err) { |
| 1611 | req->cmd->error = err; |
| 1612 | if (req->data) |
| 1613 | req->data->error = err; |
| 1614 | host->mrq = NULL; |
| 1615 | mmc_request_done(mmc, req); |
| 1616 | return; |
| 1617 | } |
| 1618 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1619 | omap_hsmmc_start_command(host, req->cmd, req->data); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1622 | /* Routine to configure clock values. Exposed API to core */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1623 | static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1624 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1625 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 1626 | int do_send_init_stream = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1627 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1628 | pm_runtime_get_sync(host->dev); |
Adrian Hunter | 5e2ea61 | 2009-09-22 16:44:39 -0700 | [diff] [blame] | 1629 | |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 1630 | if (ios->power_mode != host->power_mode) { |
| 1631 | switch (ios->power_mode) { |
| 1632 | case MMC_POWER_OFF: |
| 1633 | mmc_slot(host).set_power(host->dev, host->slot_id, |
| 1634 | 0, 0); |
Adrian Hunter | 623821f | 2009-09-22 16:44:51 -0700 | [diff] [blame] | 1635 | host->vdd = 0; |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 1636 | break; |
| 1637 | case MMC_POWER_UP: |
| 1638 | mmc_slot(host).set_power(host->dev, host->slot_id, |
| 1639 | 1, ios->vdd); |
Adrian Hunter | 623821f | 2009-09-22 16:44:51 -0700 | [diff] [blame] | 1640 | host->vdd = ios->vdd; |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 1641 | break; |
| 1642 | case MMC_POWER_ON: |
| 1643 | do_send_init_stream = 1; |
| 1644 | break; |
| 1645 | } |
| 1646 | host->power_mode = ios->power_mode; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1647 | } |
| 1648 | |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1649 | /* FIXME: set registers based only on changes to ios */ |
| 1650 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 1651 | omap_hsmmc_set_bus_width(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1652 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 1653 | if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1654 | /* Only MMC1 can interface at 3V without some flavor |
| 1655 | * of external transceiver; but they all handle 1.8V. |
| 1656 | */ |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1657 | if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) && |
Rajendra Nayak | 1f84b71 | 2012-03-12 20:32:38 +0530 | [diff] [blame] | 1658 | (ios->vdd == DUAL_VOLT_OCR_BIT) && |
| 1659 | /* |
| 1660 | * With pbias cell programming missing, this |
| 1661 | * can't be allowed when booting with device |
| 1662 | * tree. |
| 1663 | */ |
Rajendra Nayak | 4d048f9 | 2012-04-11 15:33:13 +0530 | [diff] [blame] | 1664 | !host->dev->of_node) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1665 | /* |
| 1666 | * The mmc_select_voltage fn of the core does |
| 1667 | * not seem to set the power_mode to |
| 1668 | * MMC_POWER_UP upon recalculating the voltage. |
| 1669 | * vdd 1.8v. |
| 1670 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1671 | if (omap_hsmmc_switch_opcond(host, ios->vdd) != 0) |
| 1672 | dev_dbg(mmc_dev(host->mmc), |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1673 | "Switch operation failed\n"); |
| 1674 | } |
| 1675 | } |
| 1676 | |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 1677 | omap_hsmmc_set_clock(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1678 | |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 1679 | if (do_send_init_stream) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1680 | send_init_stream(host); |
| 1681 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 1682 | omap_hsmmc_set_bus_mode(host); |
Adrian Hunter | 5e2ea61 | 2009-09-22 16:44:39 -0700 | [diff] [blame] | 1683 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1684 | pm_runtime_put_autosuspend(host->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | static int omap_hsmmc_get_cd(struct mmc_host *mmc) |
| 1688 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1689 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1690 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1691 | if (!mmc_slot(host).card_detect) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1692 | return -ENOSYS; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1693 | return mmc_slot(host).card_detect(host->dev, host->slot_id); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | static int omap_hsmmc_get_ro(struct mmc_host *mmc) |
| 1697 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1698 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1699 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1700 | if (!mmc_slot(host).get_ro) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1701 | return -ENOSYS; |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1702 | return mmc_slot(host).get_ro(host->dev, 0); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1703 | } |
| 1704 | |
Grazvydas Ignotas | 4816858 | 2010-08-10 18:01:52 -0700 | [diff] [blame] | 1705 | static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card) |
| 1706 | { |
| 1707 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
| 1708 | |
| 1709 | if (mmc_slot(host).init_card) |
| 1710 | mmc_slot(host).init_card(card); |
| 1711 | } |
| 1712 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1713 | static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host) |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 1714 | { |
| 1715 | u32 hctl, capa, value; |
| 1716 | |
| 1717 | /* Only MMC1 supports 3.0V */ |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 1718 | if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 1719 | hctl = SDVS30; |
| 1720 | capa = VS30 | VS18; |
| 1721 | } else { |
| 1722 | hctl = SDVS18; |
| 1723 | capa = VS18; |
| 1724 | } |
| 1725 | |
| 1726 | value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK; |
| 1727 | OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl); |
| 1728 | |
| 1729 | value = OMAP_HSMMC_READ(host->base, CAPA); |
| 1730 | OMAP_HSMMC_WRITE(host->base, CAPA, value | capa); |
| 1731 | |
| 1732 | /* Set the controller to AUTO IDLE mode */ |
| 1733 | value = OMAP_HSMMC_READ(host->base, SYSCONFIG); |
| 1734 | OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE); |
| 1735 | |
| 1736 | /* Set SD bus power bit */ |
Adrian Hunter | e13bb30 | 2009-03-12 17:08:26 +0200 | [diff] [blame] | 1737 | set_sd_bus_power(host); |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 1738 | } |
| 1739 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1740 | static int omap_hsmmc_enable_fclk(struct mmc_host *mmc) |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1741 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1742 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1743 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1744 | pm_runtime_get_sync(host->dev); |
| 1745 | |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1746 | return 0; |
| 1747 | } |
| 1748 | |
Adrian Hunter | 907d2e7 | 2012-02-29 09:17:21 +0200 | [diff] [blame] | 1749 | static int omap_hsmmc_disable_fclk(struct mmc_host *mmc) |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1750 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1751 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1752 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1753 | pm_runtime_mark_last_busy(host->dev); |
| 1754 | pm_runtime_put_autosuspend(host->dev); |
| 1755 | |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1756 | return 0; |
| 1757 | } |
| 1758 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1759 | static const struct mmc_host_ops omap_hsmmc_ops = { |
| 1760 | .enable = omap_hsmmc_enable_fclk, |
| 1761 | .disable = omap_hsmmc_disable_fclk, |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1762 | .post_req = omap_hsmmc_post_req, |
| 1763 | .pre_req = omap_hsmmc_pre_req, |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1764 | .request = omap_hsmmc_request, |
| 1765 | .set_ios = omap_hsmmc_set_ios, |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1766 | .get_cd = omap_hsmmc_get_cd, |
| 1767 | .get_ro = omap_hsmmc_get_ro, |
Grazvydas Ignotas | 4816858 | 2010-08-10 18:01:52 -0700 | [diff] [blame] | 1768 | .init_card = omap_hsmmc_init_card, |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1769 | /* NYET -- enable_sdio_irq */ |
| 1770 | }; |
| 1771 | |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1772 | #ifdef CONFIG_DEBUG_FS |
| 1773 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1774 | static int omap_hsmmc_regs_show(struct seq_file *s, void *data) |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1775 | { |
| 1776 | struct mmc_host *mmc = s->private; |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1777 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 1778 | int context_loss = 0; |
| 1779 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1780 | if (host->pdata->get_context_loss_count) |
| 1781 | context_loss = host->pdata->get_context_loss_count(host->dev); |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1782 | |
Adrian Hunter | 907d2e7 | 2012-02-29 09:17:21 +0200 | [diff] [blame] | 1783 | seq_printf(s, "mmc%d:\n ctx_loss:\t%d:%d\n\nregs:\n", |
| 1784 | mmc->index, host->context_loss, context_loss); |
Adrian Hunter | 5e2ea61 | 2009-09-22 16:44:39 -0700 | [diff] [blame] | 1785 | |
Balaji T K | 7a8c2ce | 2011-07-01 22:09:34 +0530 | [diff] [blame] | 1786 | if (host->suspended) { |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1787 | seq_printf(s, "host suspended, can't read registers\n"); |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1791 | pm_runtime_get_sync(host->dev); |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1792 | |
| 1793 | seq_printf(s, "SYSCONFIG:\t0x%08x\n", |
| 1794 | OMAP_HSMMC_READ(host->base, SYSCONFIG)); |
| 1795 | seq_printf(s, "CON:\t\t0x%08x\n", |
| 1796 | OMAP_HSMMC_READ(host->base, CON)); |
| 1797 | seq_printf(s, "HCTL:\t\t0x%08x\n", |
| 1798 | OMAP_HSMMC_READ(host->base, HCTL)); |
| 1799 | seq_printf(s, "SYSCTL:\t\t0x%08x\n", |
| 1800 | OMAP_HSMMC_READ(host->base, SYSCTL)); |
| 1801 | seq_printf(s, "IE:\t\t0x%08x\n", |
| 1802 | OMAP_HSMMC_READ(host->base, IE)); |
| 1803 | seq_printf(s, "ISE:\t\t0x%08x\n", |
| 1804 | OMAP_HSMMC_READ(host->base, ISE)); |
| 1805 | seq_printf(s, "CAPA:\t\t0x%08x\n", |
| 1806 | OMAP_HSMMC_READ(host->base, CAPA)); |
Adrian Hunter | 5e2ea61 | 2009-09-22 16:44:39 -0700 | [diff] [blame] | 1807 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1808 | pm_runtime_mark_last_busy(host->dev); |
| 1809 | pm_runtime_put_autosuspend(host->dev); |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1810 | |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1811 | return 0; |
| 1812 | } |
| 1813 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1814 | static int omap_hsmmc_regs_open(struct inode *inode, struct file *file) |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1815 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1816 | return single_open(file, omap_hsmmc_regs_show, inode->i_private); |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | static const struct file_operations mmc_regs_fops = { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1820 | .open = omap_hsmmc_regs_open, |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1821 | .read = seq_read, |
| 1822 | .llseek = seq_lseek, |
| 1823 | .release = single_release, |
| 1824 | }; |
| 1825 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1826 | static void omap_hsmmc_debugfs(struct mmc_host *mmc) |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1827 | { |
| 1828 | if (mmc->debugfs_root) |
| 1829 | debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root, |
| 1830 | mmc, &mmc_regs_fops); |
| 1831 | } |
| 1832 | |
| 1833 | #else |
| 1834 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1835 | static void omap_hsmmc_debugfs(struct mmc_host *mmc) |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1836 | { |
| 1837 | } |
| 1838 | |
| 1839 | #endif |
| 1840 | |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1841 | #ifdef CONFIG_OF |
| 1842 | static u16 omap4_reg_offset = 0x100; |
| 1843 | |
| 1844 | static const struct of_device_id omap_mmc_of_match[] = { |
| 1845 | { |
| 1846 | .compatible = "ti,omap2-hsmmc", |
| 1847 | }, |
| 1848 | { |
| 1849 | .compatible = "ti,omap3-hsmmc", |
| 1850 | }, |
| 1851 | { |
| 1852 | .compatible = "ti,omap4-hsmmc", |
| 1853 | .data = &omap4_reg_offset, |
| 1854 | }, |
| 1855 | {}, |
Chris Ball | b6d085f | 2012-04-10 09:57:36 -0400 | [diff] [blame] | 1856 | }; |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1857 | MODULE_DEVICE_TABLE(of, omap_mmc_of_match); |
| 1858 | |
| 1859 | static struct omap_mmc_platform_data *of_get_hsmmc_pdata(struct device *dev) |
| 1860 | { |
| 1861 | struct omap_mmc_platform_data *pdata; |
| 1862 | struct device_node *np = dev->of_node; |
| 1863 | u32 bus_width; |
| 1864 | |
| 1865 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 1866 | if (!pdata) |
| 1867 | return NULL; /* out of memory */ |
| 1868 | |
| 1869 | if (of_find_property(np, "ti,dual-volt", NULL)) |
| 1870 | pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; |
| 1871 | |
| 1872 | /* This driver only supports 1 slot */ |
| 1873 | pdata->nr_slots = 1; |
| 1874 | pdata->slots[0].switch_pin = of_get_named_gpio(np, "cd-gpios", 0); |
| 1875 | pdata->slots[0].gpio_wp = of_get_named_gpio(np, "wp-gpios", 0); |
| 1876 | |
| 1877 | if (of_find_property(np, "ti,non-removable", NULL)) { |
| 1878 | pdata->slots[0].nonremovable = true; |
| 1879 | pdata->slots[0].no_regulator_off_init = true; |
| 1880 | } |
Arnd Bergmann | 7f21779 | 2012-05-13 00:14:24 -0400 | [diff] [blame] | 1881 | of_property_read_u32(np, "bus-width", &bus_width); |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1882 | if (bus_width == 4) |
| 1883 | pdata->slots[0].caps |= MMC_CAP_4_BIT_DATA; |
| 1884 | else if (bus_width == 8) |
| 1885 | pdata->slots[0].caps |= MMC_CAP_8_BIT_DATA; |
| 1886 | |
| 1887 | if (of_find_property(np, "ti,needs-special-reset", NULL)) |
| 1888 | pdata->slots[0].features |= HSMMC_HAS_UPDATED_RESET; |
| 1889 | |
| 1890 | return pdata; |
| 1891 | } |
| 1892 | #else |
| 1893 | static inline struct omap_mmc_platform_data |
| 1894 | *of_get_hsmmc_pdata(struct device *dev) |
| 1895 | { |
| 1896 | return NULL; |
| 1897 | } |
| 1898 | #endif |
| 1899 | |
Felipe Balbi | efa25fd | 2012-03-14 11:18:28 +0200 | [diff] [blame] | 1900 | static int __devinit omap_hsmmc_probe(struct platform_device *pdev) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1901 | { |
| 1902 | struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; |
| 1903 | struct mmc_host *mmc; |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1904 | struct omap_hsmmc_host *host = NULL; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1905 | struct resource *res; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1906 | int ret, irq; |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1907 | const struct of_device_id *match; |
| 1908 | |
| 1909 | match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev); |
| 1910 | if (match) { |
| 1911 | pdata = of_get_hsmmc_pdata(&pdev->dev); |
| 1912 | if (match->data) { |
| 1913 | u16 *offsetp = match->data; |
| 1914 | pdata->reg_offset = *offsetp; |
| 1915 | } |
| 1916 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1917 | |
| 1918 | if (pdata == NULL) { |
| 1919 | dev_err(&pdev->dev, "Platform Data is missing\n"); |
| 1920 | return -ENXIO; |
| 1921 | } |
| 1922 | |
| 1923 | if (pdata->nr_slots == 0) { |
| 1924 | dev_err(&pdev->dev, "No Slots\n"); |
| 1925 | return -ENXIO; |
| 1926 | } |
| 1927 | |
| 1928 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1929 | irq = platform_get_irq(pdev, 0); |
| 1930 | if (res == NULL || irq < 0) |
| 1931 | return -ENXIO; |
| 1932 | |
Chris Ball | 984b203 | 2011-03-22 16:34:42 -0700 | [diff] [blame] | 1933 | res = request_mem_region(res->start, resource_size(res), pdev->name); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1934 | if (res == NULL) |
| 1935 | return -EBUSY; |
| 1936 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1937 | ret = omap_hsmmc_gpio_init(pdata); |
| 1938 | if (ret) |
| 1939 | goto err; |
| 1940 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1941 | mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1942 | if (!mmc) { |
| 1943 | ret = -ENOMEM; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1944 | goto err_alloc; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | host = mmc_priv(mmc); |
| 1948 | host->mmc = mmc; |
| 1949 | host->pdata = pdata; |
| 1950 | host->dev = &pdev->dev; |
| 1951 | host->use_dma = 1; |
| 1952 | host->dev->dma_mask = &pdata->dma_mask; |
| 1953 | host->dma_ch = -1; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 1954 | host->dma2 = -1; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1955 | host->irq = irq; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1956 | host->slot_id = 0; |
Balaji T K | fc307df | 2012-04-02 12:26:47 +0530 | [diff] [blame] | 1957 | host->mapbase = res->start + pdata->reg_offset; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1958 | host->base = ioremap(host->mapbase, SZ_4K); |
Adrian Hunter | 6da20c8 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1959 | host->power_mode = MMC_POWER_OFF; |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1960 | host->next_data.cookie = 1; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1961 | |
| 1962 | platform_set_drvdata(pdev, host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1963 | |
Balaji T K | 7a8c2ce | 2011-07-01 22:09:34 +0530 | [diff] [blame] | 1964 | mmc->ops = &omap_hsmmc_ops; |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1965 | |
Adrian Hunter | e0eb242 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1966 | /* |
| 1967 | * If regulator_disable can only put vcc_aux to sleep then there is |
| 1968 | * no off state. |
| 1969 | */ |
| 1970 | if (mmc_slot(host).vcc_aux_disable_is_sleep) |
| 1971 | mmc_slot(host).no_off = 1; |
| 1972 | |
Daniel Mack | d418ed8 | 2012-02-19 13:20:33 +0100 | [diff] [blame] | 1973 | mmc->f_min = OMAP_MMC_MIN_CLOCK; |
| 1974 | |
| 1975 | if (pdata->max_freq > 0) |
| 1976 | mmc->f_max = pdata->max_freq; |
| 1977 | else |
| 1978 | mmc->f_max = OMAP_MMC_MAX_CLOCK; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1979 | |
Adrian Hunter | 4dffd7a | 2009-09-22 16:44:58 -0700 | [diff] [blame] | 1980 | spin_lock_init(&host->irq_lock); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1981 | |
Russell King | 6f7607c | 2009-01-28 10:22:50 +0000 | [diff] [blame] | 1982 | host->fclk = clk_get(&pdev->dev, "fck"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1983 | if (IS_ERR(host->fclk)) { |
| 1984 | ret = PTR_ERR(host->fclk); |
| 1985 | host->fclk = NULL; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1986 | goto err1; |
| 1987 | } |
| 1988 | |
Paul Walmsley | 9b68256 | 2011-10-06 14:50:35 -0600 | [diff] [blame] | 1989 | if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) { |
| 1990 | dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n"); |
| 1991 | mmc->caps2 |= MMC_CAP2_NO_MULTI_READ; |
| 1992 | } |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1993 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1994 | pm_runtime_enable(host->dev); |
| 1995 | pm_runtime_get_sync(host->dev); |
| 1996 | pm_runtime_set_autosuspend_delay(host->dev, MMC_AUTOSUSPEND_DELAY); |
| 1997 | pm_runtime_use_autosuspend(host->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1998 | |
Balaji T K | 92a3aeb | 2012-02-24 21:14:34 +0530 | [diff] [blame] | 1999 | omap_hsmmc_context_save(host); |
| 2000 | |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2001 | host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck"); |
| 2002 | /* |
| 2003 | * MMC can still work without debounce clock. |
| 2004 | */ |
| 2005 | if (IS_ERR(host->dbclk)) { |
| 2006 | dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n"); |
| 2007 | host->dbclk = NULL; |
| 2008 | } else if (clk_enable(host->dbclk) != 0) { |
| 2009 | dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); |
| 2010 | clk_put(host->dbclk); |
| 2011 | host->dbclk = NULL; |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 2012 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2013 | |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 2014 | /* Since we do only SG emulation, we can have as many segs |
| 2015 | * as we want. */ |
Martin K. Petersen | a36274e | 2010-09-10 01:33:59 -0400 | [diff] [blame] | 2016 | mmc->max_segs = 1024; |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 2017 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2018 | mmc->max_blk_size = 512; /* Block Length at max can be 1024 */ |
| 2019 | mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */ |
| 2020 | mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; |
| 2021 | mmc->max_seg_size = mmc->max_req_size; |
| 2022 | |
Jarkko Lavinen | 13189e7 | 2009-09-22 16:44:53 -0700 | [diff] [blame] | 2023 | mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 2024 | MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2025 | |
Sukumar Ghorai | 3a63833 | 2010-09-15 14:49:23 +0000 | [diff] [blame] | 2026 | mmc->caps |= mmc_slot(host).caps; |
| 2027 | if (mmc->caps & MMC_CAP_8_BIT_DATA) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2028 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
| 2029 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 2030 | if (mmc_slot(host).nonremovable) |
Adrian Hunter | 23d99bb | 2009-09-22 16:44:48 -0700 | [diff] [blame] | 2031 | mmc->caps |= MMC_CAP_NONREMOVABLE; |
| 2032 | |
Eliad Peller | 6fdc75d | 2011-11-22 16:02:18 +0200 | [diff] [blame] | 2033 | mmc->pm_caps = mmc_slot(host).pm_caps; |
| 2034 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2035 | omap_hsmmc_conf_bus_power(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2036 | |
Balaji T K | b7bf773 | 2012-03-07 09:55:30 -0500 | [diff] [blame] | 2037 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); |
| 2038 | if (!res) { |
| 2039 | dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); |
Grazvydas Ignotas | f3e2f1d | 2009-01-03 10:36:13 +0000 | [diff] [blame] | 2040 | goto err_irq; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2041 | } |
Balaji T K | b7bf773 | 2012-03-07 09:55:30 -0500 | [diff] [blame] | 2042 | host->dma_line_tx = res->start; |
| 2043 | |
| 2044 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); |
| 2045 | if (!res) { |
| 2046 | dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n"); |
| 2047 | goto err_irq; |
| 2048 | } |
| 2049 | host->dma_line_rx = res->start; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2050 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 2051 | { |
| 2052 | dma_cap_mask_t mask; |
| 2053 | unsigned sig; |
| 2054 | extern bool omap_dma_filter_fn(struct dma_chan *chan, void *param); |
| 2055 | |
| 2056 | dma_cap_zero(mask); |
| 2057 | dma_cap_set(DMA_SLAVE, mask); |
| 2058 | #if 1 |
| 2059 | sig = host->dma_line_rx; |
| 2060 | host->rx_chan = dma_request_channel(mask, omap_dma_filter_fn, &sig); |
| 2061 | if (!host->rx_chan) { |
| 2062 | dev_warn(mmc_dev(host->mmc), "unable to obtain RX DMA engine channel %u\n", sig); |
| 2063 | } |
| 2064 | #endif |
| 2065 | #if 1 |
| 2066 | sig = host->dma_line_tx; |
| 2067 | host->tx_chan = dma_request_channel(mask, omap_dma_filter_fn, &sig); |
| 2068 | if (!host->tx_chan) { |
| 2069 | dev_warn(mmc_dev(host->mmc), "unable to obtain TX DMA engine channel %u\n", sig); |
| 2070 | } |
| 2071 | #endif |
| 2072 | } |
| 2073 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2074 | /* Request IRQ for MMC operations */ |
Yong Zhang | d9618e9 | 2011-09-22 16:59:04 +0800 | [diff] [blame] | 2075 | ret = request_irq(host->irq, omap_hsmmc_irq, 0, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2076 | mmc_hostname(mmc), host); |
| 2077 | if (ret) { |
| 2078 | dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n"); |
| 2079 | goto err_irq; |
| 2080 | } |
| 2081 | |
| 2082 | if (pdata->init != NULL) { |
| 2083 | if (pdata->init(&pdev->dev) != 0) { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2084 | dev_dbg(mmc_dev(host->mmc), |
| 2085 | "Unable to configure MMC IRQs\n"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2086 | goto err_irq_cd_init; |
| 2087 | } |
| 2088 | } |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2089 | |
Adrian Hunter | b702b10 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 2090 | if (omap_hsmmc_have_reg() && !mmc_slot(host).set_power) { |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2091 | ret = omap_hsmmc_reg_get(host); |
| 2092 | if (ret) |
| 2093 | goto err_reg; |
| 2094 | host->use_reg = 1; |
| 2095 | } |
| 2096 | |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 2097 | mmc->ocr_avail = mmc_slot(host).ocr_mask; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2098 | |
| 2099 | /* Request IRQ for card detect */ |
Adrian Hunter | e1a55f5 | 2009-01-26 13:17:25 +0200 | [diff] [blame] | 2100 | if ((mmc_slot(host).card_detect_irq)) { |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 2101 | ret = request_threaded_irq(mmc_slot(host).card_detect_irq, |
| 2102 | NULL, |
| 2103 | omap_hsmmc_detect, |
Ming Lei | db35f83 | 2012-05-17 10:27:12 +0800 | [diff] [blame] | 2104 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 2105 | mmc_hostname(mmc), host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2106 | if (ret) { |
| 2107 | dev_dbg(mmc_dev(host->mmc), |
| 2108 | "Unable to grab MMC CD IRQ\n"); |
| 2109 | goto err_irq_cd; |
| 2110 | } |
kishore kadiyala | 72f2e2c | 2010-09-24 17:13:20 +0000 | [diff] [blame] | 2111 | pdata->suspend = omap_hsmmc_suspend_cdirq; |
| 2112 | pdata->resume = omap_hsmmc_resume_cdirq; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2113 | } |
| 2114 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 2115 | omap_hsmmc_disable_irq(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2116 | |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 2117 | omap_hsmmc_protect_card(host); |
| 2118 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2119 | mmc_add_host(mmc); |
| 2120 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 2121 | if (mmc_slot(host).name != NULL) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2122 | ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name); |
| 2123 | if (ret < 0) |
| 2124 | goto err_slot_name; |
| 2125 | } |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 2126 | if (mmc_slot(host).card_detect_irq && mmc_slot(host).get_cover_state) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2127 | ret = device_create_file(&mmc->class_dev, |
| 2128 | &dev_attr_cover_switch); |
| 2129 | if (ret < 0) |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2130 | goto err_slot_name; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2133 | omap_hsmmc_debugfs(mmc); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2134 | pm_runtime_mark_last_busy(host->dev); |
| 2135 | pm_runtime_put_autosuspend(host->dev); |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 2136 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2137 | return 0; |
| 2138 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2139 | err_slot_name: |
| 2140 | mmc_remove_host(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2141 | free_irq(mmc_slot(host).card_detect_irq, host); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2142 | err_irq_cd: |
| 2143 | if (host->use_reg) |
| 2144 | omap_hsmmc_reg_put(host); |
| 2145 | err_reg: |
| 2146 | if (host->pdata->cleanup) |
| 2147 | host->pdata->cleanup(&pdev->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2148 | err_irq_cd_init: |
| 2149 | free_irq(host->irq, host); |
| 2150 | err_irq: |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 2151 | if (host->tx_chan) |
| 2152 | dma_release_channel(host->tx_chan); |
| 2153 | if (host->rx_chan) |
| 2154 | dma_release_channel(host->rx_chan); |
Balaji T K | d59d77e | 2012-02-24 21:14:33 +0530 | [diff] [blame] | 2155 | pm_runtime_put_sync(host->dev); |
Tony Lindgren | 37f6190 | 2012-03-08 23:41:35 -0500 | [diff] [blame] | 2156 | pm_runtime_disable(host->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2157 | clk_put(host->fclk); |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2158 | if (host->dbclk) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2159 | clk_disable(host->dbclk); |
| 2160 | clk_put(host->dbclk); |
| 2161 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2162 | err1: |
| 2163 | iounmap(host->base); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2164 | platform_set_drvdata(pdev, NULL); |
| 2165 | mmc_free_host(mmc); |
| 2166 | err_alloc: |
| 2167 | omap_hsmmc_gpio_free(pdata); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2168 | err: |
Russell King | 48b332f | 2012-04-18 11:11:57 +0100 | [diff] [blame] | 2169 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2170 | if (res) |
| 2171 | release_mem_region(res->start, resource_size(res)); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2172 | return ret; |
| 2173 | } |
| 2174 | |
Felipe Balbi | efa25fd | 2012-03-14 11:18:28 +0200 | [diff] [blame] | 2175 | static int __devexit omap_hsmmc_remove(struct platform_device *pdev) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2176 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2177 | struct omap_hsmmc_host *host = platform_get_drvdata(pdev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2178 | struct resource *res; |
| 2179 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2180 | pm_runtime_get_sync(host->dev); |
| 2181 | mmc_remove_host(host->mmc); |
| 2182 | if (host->use_reg) |
| 2183 | omap_hsmmc_reg_put(host); |
| 2184 | if (host->pdata->cleanup) |
| 2185 | host->pdata->cleanup(&pdev->dev); |
| 2186 | free_irq(host->irq, host); |
| 2187 | if (mmc_slot(host).card_detect_irq) |
| 2188 | free_irq(mmc_slot(host).card_detect_irq, host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2189 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame^] | 2190 | if (host->tx_chan) |
| 2191 | dma_release_channel(host->tx_chan); |
| 2192 | if (host->rx_chan) |
| 2193 | dma_release_channel(host->rx_chan); |
| 2194 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2195 | pm_runtime_put_sync(host->dev); |
| 2196 | pm_runtime_disable(host->dev); |
| 2197 | clk_put(host->fclk); |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2198 | if (host->dbclk) { |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2199 | clk_disable(host->dbclk); |
| 2200 | clk_put(host->dbclk); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2201 | } |
| 2202 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2203 | mmc_free_host(host->mmc); |
| 2204 | iounmap(host->base); |
| 2205 | omap_hsmmc_gpio_free(pdev->dev.platform_data); |
| 2206 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2207 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2208 | if (res) |
Chris Ball | 984b203 | 2011-03-22 16:34:42 -0700 | [diff] [blame] | 2209 | release_mem_region(res->start, resource_size(res)); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2210 | platform_set_drvdata(pdev, NULL); |
| 2211 | |
| 2212 | return 0; |
| 2213 | } |
| 2214 | |
| 2215 | #ifdef CONFIG_PM |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2216 | static int omap_hsmmc_suspend(struct device *dev) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2217 | { |
| 2218 | int ret = 0; |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2219 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 2220 | |
| 2221 | if (!host) |
| 2222 | return 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2223 | |
| 2224 | if (host && host->suspended) |
| 2225 | return 0; |
| 2226 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2227 | pm_runtime_get_sync(host->dev); |
| 2228 | host->suspended = 1; |
| 2229 | if (host->pdata->suspend) { |
| 2230 | ret = host->pdata->suspend(dev, host->slot_id); |
Eliad Peller | 31f9d46 | 2011-11-22 16:02:17 +0200 | [diff] [blame] | 2231 | if (ret) { |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2232 | dev_dbg(dev, "Unable to handle MMC board" |
| 2233 | " level suspend\n"); |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 2234 | host->suspended = 0; |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2235 | return ret; |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 2236 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2237 | } |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2238 | ret = mmc_suspend_host(host->mmc); |
| 2239 | |
| 2240 | if (ret) { |
| 2241 | host->suspended = 0; |
| 2242 | if (host->pdata->resume) { |
| 2243 | ret = host->pdata->resume(dev, host->slot_id); |
| 2244 | if (ret) |
| 2245 | dev_dbg(dev, "Unmask interrupt failed\n"); |
| 2246 | } |
| 2247 | goto err; |
| 2248 | } |
| 2249 | |
| 2250 | if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) { |
| 2251 | omap_hsmmc_disable_irq(host); |
| 2252 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 2253 | OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP); |
| 2254 | } |
| 2255 | |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2256 | if (host->dbclk) |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2257 | clk_disable(host->dbclk); |
Eliad Peller | 31f9d46 | 2011-11-22 16:02:17 +0200 | [diff] [blame] | 2258 | err: |
| 2259 | pm_runtime_put_sync(host->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2260 | return ret; |
| 2261 | } |
| 2262 | |
| 2263 | /* Routine to resume the MMC device */ |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2264 | static int omap_hsmmc_resume(struct device *dev) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2265 | { |
| 2266 | int ret = 0; |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2267 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 2268 | |
| 2269 | if (!host) |
| 2270 | return 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2271 | |
| 2272 | if (host && !host->suspended) |
| 2273 | return 0; |
| 2274 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2275 | pm_runtime_get_sync(host->dev); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 2276 | |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2277 | if (host->dbclk) |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2278 | clk_enable(host->dbclk); |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 2279 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2280 | if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) |
| 2281 | omap_hsmmc_conf_bus_power(host); |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 2282 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2283 | if (host->pdata->resume) { |
| 2284 | ret = host->pdata->resume(dev, host->slot_id); |
| 2285 | if (ret) |
| 2286 | dev_dbg(dev, "Unmask interrupt failed\n"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2287 | } |
| 2288 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2289 | omap_hsmmc_protect_card(host); |
| 2290 | |
| 2291 | /* Notify the core to resume the host */ |
| 2292 | ret = mmc_resume_host(host->mmc); |
| 2293 | if (ret == 0) |
| 2294 | host->suspended = 0; |
| 2295 | |
| 2296 | pm_runtime_mark_last_busy(host->dev); |
| 2297 | pm_runtime_put_autosuspend(host->dev); |
| 2298 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2299 | return ret; |
| 2300 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | #else |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2304 | #define omap_hsmmc_suspend NULL |
| 2305 | #define omap_hsmmc_resume NULL |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2306 | #endif |
| 2307 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2308 | static int omap_hsmmc_runtime_suspend(struct device *dev) |
| 2309 | { |
| 2310 | struct omap_hsmmc_host *host; |
| 2311 | |
| 2312 | host = platform_get_drvdata(to_platform_device(dev)); |
| 2313 | omap_hsmmc_context_save(host); |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2314 | dev_dbg(dev, "disabled\n"); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2315 | |
| 2316 | return 0; |
| 2317 | } |
| 2318 | |
| 2319 | static int omap_hsmmc_runtime_resume(struct device *dev) |
| 2320 | { |
| 2321 | struct omap_hsmmc_host *host; |
| 2322 | |
| 2323 | host = platform_get_drvdata(to_platform_device(dev)); |
| 2324 | omap_hsmmc_context_restore(host); |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2325 | dev_dbg(dev, "enabled\n"); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2326 | |
| 2327 | return 0; |
| 2328 | } |
| 2329 | |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2330 | static struct dev_pm_ops omap_hsmmc_dev_pm_ops = { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2331 | .suspend = omap_hsmmc_suspend, |
| 2332 | .resume = omap_hsmmc_resume, |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2333 | .runtime_suspend = omap_hsmmc_runtime_suspend, |
| 2334 | .runtime_resume = omap_hsmmc_runtime_resume, |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2335 | }; |
| 2336 | |
| 2337 | static struct platform_driver omap_hsmmc_driver = { |
Felipe Balbi | efa25fd | 2012-03-14 11:18:28 +0200 | [diff] [blame] | 2338 | .probe = omap_hsmmc_probe, |
| 2339 | .remove = __devexit_p(omap_hsmmc_remove), |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2340 | .driver = { |
| 2341 | .name = DRIVER_NAME, |
| 2342 | .owner = THIS_MODULE, |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2343 | .pm = &omap_hsmmc_dev_pm_ops, |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 2344 | .of_match_table = of_match_ptr(omap_mmc_of_match), |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2345 | }, |
| 2346 | }; |
| 2347 | |
Felipe Balbi | b796450 | 2012-03-14 11:18:32 +0200 | [diff] [blame] | 2348 | module_platform_driver(omap_hsmmc_driver); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2349 | MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver"); |
| 2350 | MODULE_LICENSE("GPL"); |
| 2351 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 2352 | MODULE_AUTHOR("Texas Instruments Inc"); |