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