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