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