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