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