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