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