blob: 98adf0c51e05bebe09056a19779e717f3a154908 [file] [log] [blame]
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001/*
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 Shevchenkoac330f42011-05-10 15:51:54 +030020#include <linux/kernel.h>
Denis Karpovd900f712009-09-22 16:44:38 -070021#include <linux/debugfs.h>
22#include <linux/seq_file.h>
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010023#include <linux/interrupt.h>
24#include <linux/delay.h>
25#include <linux/dma-mapping.h>
26#include <linux/platform_device.h>
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010027#include <linux/timer.h>
28#include <linux/clk.h>
29#include <linux/mmc/host.h>
Jarkko Lavinen13189e72009-09-22 16:44:53 -070030#include <linux/mmc/core.h>
Adrian Hunter93caf8e692010-08-11 14:17:48 -070031#include <linux/mmc/mmc.h>
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010032#include <linux/io.h>
33#include <linux/semaphore.h>
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080034#include <linux/gpio.h>
35#include <linux/regulator/consumer.h>
Balaji T Kfa4aa2d2011-07-01 22:09:35 +053036#include <linux/pm_runtime.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070037#include <plat/dma.h>
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010038#include <mach/hardware.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070039#include <plat/board.h>
40#include <plat/mmc.h>
41#include <plat/cpu.h>
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010042
43/* OMAP HSMMC Host Controller Registers */
44#define OMAP_HSMMC_SYSCONFIG 0x0010
Denis Karpov11dd62a2009-09-22 16:44:43 -070045#define OMAP_HSMMC_SYSSTATUS 0x0014
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010046#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 Brownelleb250822009-02-17 14:49:01 -080066#define SDVS33 (0x7 << 9)
Kim Kyuwon1b331e62009-02-20 13:10:08 +010067#define SDVS_MASK 0x00000E00
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010068#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 Gadiyarccdfe3a2009-09-22 16:44:21 -070081#define BWR_ENABLE (1 << 4)
82#define BRR_ENABLE (1 << 5)
Adrian Hunter93caf8e692010-08-11 14:17:48 -070083#define DTO_ENABLE (1 << 20)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010084#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 Lavinen73153012008-11-21 16:49:54 +020091#define DW8 (1 << 5)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +010092#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 Karpov11dd62a2009-09-22 16:44:43 -0700106#define SOFTRESET (1 << 1)
107#define RESETDONE (1 << 0)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100108
Balaji T Kfa4aa2d2011-07-01 22:09:35 +0530109#define MMC_AUTOSUSPEND_DELAY 100
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100110#define MMC_TIMEOUT_MS 20
Andy Shevchenko6b206ef2011-07-13 11:16:29 -0400111#define OMAP_MMC_MIN_CLOCK 400000
112#define OMAP_MMC_MAX_CLOCK 52000000
Kishore Kadiyala0005ae72011-02-28 20:48:05 +0530113#define DRIVER_NAME "omap_hsmmc"
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100114
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 Forlin9782aff2011-07-01 18:55:23 +0200131struct omap_hsmmc_next {
132 unsigned int dma_len;
133 s32 cookie;
134};
135
Denis Karpov70a33412009-09-22 16:44:59 -0700136struct omap_hsmmc_host {
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100137 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 Chikkaturea45c6cb2009-01-23 01:05:23 +0100143 struct clk *dbclk;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800144 /*
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 Chikkaturea45c6cb2009-01-23 01:05:23 +0100153 void __iomem *base;
154 resource_size_t mapbase;
Adrian Hunter4dffd7a2009-09-22 16:44:58 -0700155 spinlock_t irq_lock; /* Prevent races with irq handler */
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100156 unsigned int dma_len;
Juha Yrjola0ccd76d2008-11-14 15:22:00 +0200157 unsigned int dma_sg_idx;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100158 unsigned char bus_mode;
Adrian Huntera3621462009-09-22 16:44:42 -0700159 unsigned char power_mode;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100160 u32 *buffer;
161 u32 bytesleft;
162 int suspended;
163 int irq;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100164 int use_dma, dma_ch;
Grazvydas Ignotasf3e2f1d2009-01-03 10:36:13 +0000165 int dma_line_tx, dma_line_rx;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100166 int slot_id;
Adrian Hunter2bec0892009-09-22 16:45:02 -0700167 int got_dbclk;
Adrian Hunter4a694dc2009-01-12 16:13:08 +0200168 int response_busy;
Denis Karpov11dd62a2009-09-22 16:44:43 -0700169 int context_loss;
Adrian Hunter623821f2009-09-22 16:44:51 -0700170 int vdd;
Adrian Hunterb62f6222009-09-22 16:45:01 -0700171 int protect_card;
172 int reqs_blocked;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800173 int use_reg;
Adrian Hunterb4175772010-05-26 14:42:06 -0700174 int req_in_progress;
Per Forlin9782aff2011-07-01 18:55:23 +0200175 struct omap_hsmmc_next next_data;
Denis Karpov11dd62a2009-09-22 16:44:43 -0700176
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100177 struct omap_mmc_platform_data *pdata;
178};
179
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800180static int omap_hsmmc_card_detect(struct device *dev, int slot)
181{
182 struct omap_mmc_platform_data *mmc = dev->platform_data;
183
184 /* NOTE: assumes card detect signal is active-low */
185 return !gpio_get_value_cansleep(mmc->slots[0].switch_pin);
186}
187
188static int omap_hsmmc_get_wp(struct device *dev, int slot)
189{
190 struct omap_mmc_platform_data *mmc = dev->platform_data;
191
192 /* NOTE: assumes write protect signal is active-high */
193 return gpio_get_value_cansleep(mmc->slots[0].gpio_wp);
194}
195
196static int omap_hsmmc_get_cover_state(struct device *dev, int slot)
197{
198 struct omap_mmc_platform_data *mmc = dev->platform_data;
199
200 /* NOTE: assumes card detect signal is active-low */
201 return !gpio_get_value_cansleep(mmc->slots[0].switch_pin);
202}
203
204#ifdef CONFIG_PM
205
206static int omap_hsmmc_suspend_cdirq(struct device *dev, int slot)
207{
208 struct omap_mmc_platform_data *mmc = dev->platform_data;
209
210 disable_irq(mmc->slots[0].card_detect_irq);
211 return 0;
212}
213
214static int omap_hsmmc_resume_cdirq(struct device *dev, int slot)
215{
216 struct omap_mmc_platform_data *mmc = dev->platform_data;
217
218 enable_irq(mmc->slots[0].card_detect_irq);
219 return 0;
220}
221
222#else
223
224#define omap_hsmmc_suspend_cdirq NULL
225#define omap_hsmmc_resume_cdirq NULL
226
227#endif
228
Adrian Hunterb702b102010-02-15 10:03:35 -0800229#ifdef CONFIG_REGULATOR
230
Rajendra Nayak69b07ec2012-03-07 09:55:30 -0500231static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800232 int vdd)
233{
234 struct omap_hsmmc_host *host =
235 platform_get_drvdata(to_platform_device(dev));
236 int ret = 0;
237
238 /*
239 * If we don't see a Vcc regulator, assume it's a fixed
240 * voltage always-on regulator.
241 */
242 if (!host->vcc)
243 return 0;
244
245 if (mmc_slot(host).before_set_reg)
246 mmc_slot(host).before_set_reg(dev, slot, power_on, vdd);
247
248 /*
249 * Assume Vcc regulator is used only to power the card ... OMAP
250 * VDDS is used to power the pins, optionally with a transceiver to
251 * support cards using voltages other than VDDS (1.8V nominal). When a
252 * transceiver is used, DAT3..7 are muxed as transceiver control pins.
253 *
254 * In some cases this regulator won't support enable/disable;
255 * e.g. it's a fixed rail for a WLAN chip.
256 *
257 * In other cases vcc_aux switches interface power. Example, for
258 * eMMC cards it represents VccQ. Sometimes transceivers or SDIO
259 * chips/cards need an interface voltage rail too.
260 */
261 if (power_on) {
Linus Walleij99fc5132010-09-29 01:08:27 -0400262 ret = mmc_regulator_set_ocr(host->mmc, host->vcc, vdd);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800263 /* Enable interface voltage rail, if needed */
264 if (ret == 0 && host->vcc_aux) {
265 ret = regulator_enable(host->vcc_aux);
266 if (ret < 0)
Linus Walleij99fc5132010-09-29 01:08:27 -0400267 ret = mmc_regulator_set_ocr(host->mmc,
268 host->vcc, 0);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800269 }
270 } else {
Linus Walleij99fc5132010-09-29 01:08:27 -0400271 /* Shut down the rail */
Adrian Hunter6da20c82010-02-15 10:03:34 -0800272 if (host->vcc_aux)
273 ret = regulator_disable(host->vcc_aux);
Linus Walleij99fc5132010-09-29 01:08:27 -0400274 if (!ret) {
275 /* Then proceed to shut down the local regulator */
276 ret = mmc_regulator_set_ocr(host->mmc,
277 host->vcc, 0);
278 }
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800279 }
280
281 if (mmc_slot(host).after_set_reg)
282 mmc_slot(host).after_set_reg(dev, slot, power_on, vdd);
283
284 return ret;
285}
286
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800287static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
288{
289 struct regulator *reg;
kishore kadiyala64be9782010-10-01 16:35:28 -0700290 int ocr_value = 0;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800291
Rajendra Nayak1cb9af42012-03-07 09:55:31 -0500292 mmc_slot(host).set_power = omap_hsmmc_set_power;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800293
294 reg = regulator_get(host->dev, "vmmc");
295 if (IS_ERR(reg)) {
296 dev_dbg(host->dev, "vmmc regulator missing\n");
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800297 } else {
298 host->vcc = reg;
kishore kadiyala64be9782010-10-01 16:35:28 -0700299 ocr_value = mmc_regulator_get_ocrmask(reg);
300 if (!mmc_slot(host).ocr_mask) {
301 mmc_slot(host).ocr_mask = ocr_value;
302 } else {
303 if (!(mmc_slot(host).ocr_mask & ocr_value)) {
Rajendra Nayake3f1adb2012-03-07 09:55:31 -0500304 pr_err("MMC ocrmask %x is not supported\n",
305 mmc_slot(host).ocr_mask);
kishore kadiyala64be9782010-10-01 16:35:28 -0700306 mmc_slot(host).ocr_mask = 0;
307 return -EINVAL;
308 }
309 }
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800310
311 /* Allow an aux regulator */
312 reg = regulator_get(host->dev, "vmmc_aux");
313 host->vcc_aux = IS_ERR(reg) ? NULL : reg;
314
Balaji T Kb1c1df72011-05-30 19:55:34 +0530315 /* For eMMC do not power off when not in sleep state */
316 if (mmc_slot(host).no_regulator_off_init)
317 return 0;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800318 /*
319 * UGLY HACK: workaround regulator framework bugs.
320 * When the bootloader leaves a supply active, it's
321 * initialized with zero usecount ... and we can't
322 * disable it without first enabling it. Until the
323 * framework is fixed, we need a workaround like this
324 * (which is safe for MMC, but not in general).
325 */
Adrian Huntere840ce12011-05-06 12:14:10 +0300326 if (regulator_is_enabled(host->vcc) > 0 ||
327 (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) {
328 int vdd = ffs(mmc_slot(host).ocr_mask) - 1;
329
330 mmc_slot(host).set_power(host->dev, host->slot_id,
331 1, vdd);
332 mmc_slot(host).set_power(host->dev, host->slot_id,
333 0, 0);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800334 }
335 }
336
337 return 0;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800338}
339
340static void omap_hsmmc_reg_put(struct omap_hsmmc_host *host)
341{
342 regulator_put(host->vcc);
343 regulator_put(host->vcc_aux);
344 mmc_slot(host).set_power = NULL;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800345}
346
Adrian Hunterb702b102010-02-15 10:03:35 -0800347static inline int omap_hsmmc_have_reg(void)
348{
349 return 1;
350}
351
352#else
353
354static inline int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
355{
356 return -EINVAL;
357}
358
359static inline void omap_hsmmc_reg_put(struct omap_hsmmc_host *host)
360{
361}
362
363static inline int omap_hsmmc_have_reg(void)
364{
365 return 0;
366}
367
368#endif
369
370static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data *pdata)
371{
372 int ret;
373
374 if (gpio_is_valid(pdata->slots[0].switch_pin)) {
Adrian Hunterb702b102010-02-15 10:03:35 -0800375 if (pdata->slots[0].cover)
376 pdata->slots[0].get_cover_state =
377 omap_hsmmc_get_cover_state;
378 else
379 pdata->slots[0].card_detect = omap_hsmmc_card_detect;
380 pdata->slots[0].card_detect_irq =
381 gpio_to_irq(pdata->slots[0].switch_pin);
382 ret = gpio_request(pdata->slots[0].switch_pin, "mmc_cd");
383 if (ret)
384 return ret;
385 ret = gpio_direction_input(pdata->slots[0].switch_pin);
386 if (ret)
387 goto err_free_sp;
388 } else
389 pdata->slots[0].switch_pin = -EINVAL;
390
391 if (gpio_is_valid(pdata->slots[0].gpio_wp)) {
392 pdata->slots[0].get_ro = omap_hsmmc_get_wp;
393 ret = gpio_request(pdata->slots[0].gpio_wp, "mmc_wp");
394 if (ret)
395 goto err_free_cd;
396 ret = gpio_direction_input(pdata->slots[0].gpio_wp);
397 if (ret)
398 goto err_free_wp;
399 } else
400 pdata->slots[0].gpio_wp = -EINVAL;
401
402 return 0;
403
404err_free_wp:
405 gpio_free(pdata->slots[0].gpio_wp);
406err_free_cd:
407 if (gpio_is_valid(pdata->slots[0].switch_pin))
408err_free_sp:
409 gpio_free(pdata->slots[0].switch_pin);
410 return ret;
411}
412
413static void omap_hsmmc_gpio_free(struct omap_mmc_platform_data *pdata)
414{
415 if (gpio_is_valid(pdata->slots[0].gpio_wp))
416 gpio_free(pdata->slots[0].gpio_wp);
417 if (gpio_is_valid(pdata->slots[0].switch_pin))
418 gpio_free(pdata->slots[0].switch_pin);
419}
420
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100421/*
Andy Shevchenkoe0c7f992011-05-06 12:14:05 +0300422 * Start clock to the card
423 */
424static void omap_hsmmc_start_clock(struct omap_hsmmc_host *host)
425{
426 OMAP_HSMMC_WRITE(host->base, SYSCTL,
427 OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
428}
429
430/*
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100431 * Stop clock to the card
432 */
Denis Karpov70a33412009-09-22 16:44:59 -0700433static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100434{
435 OMAP_HSMMC_WRITE(host->base, SYSCTL,
436 OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
437 if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0)
438 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n");
439}
440
Adrian Hunter93caf8e692010-08-11 14:17:48 -0700441static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host,
442 struct mmc_command *cmd)
Adrian Hunterb4175772010-05-26 14:42:06 -0700443{
444 unsigned int irq_mask;
445
446 if (host->use_dma)
447 irq_mask = INT_EN_MASK & ~(BRR_ENABLE | BWR_ENABLE);
448 else
449 irq_mask = INT_EN_MASK;
450
Adrian Hunter93caf8e692010-08-11 14:17:48 -0700451 /* Disable timeout for erases */
452 if (cmd->opcode == MMC_ERASE)
453 irq_mask &= ~DTO_ENABLE;
454
Adrian Hunterb4175772010-05-26 14:42:06 -0700455 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
456 OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
457 OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
458}
459
460static void omap_hsmmc_disable_irq(struct omap_hsmmc_host *host)
461{
462 OMAP_HSMMC_WRITE(host->base, ISE, 0);
463 OMAP_HSMMC_WRITE(host->base, IE, 0);
464 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
465}
466
Andy Shevchenkoac330f42011-05-10 15:51:54 +0300467/* Calculate divisor for the given clock frequency */
Balaji TKd83b6e02011-12-20 15:12:00 +0530468static u16 calc_divisor(struct omap_hsmmc_host *host, struct mmc_ios *ios)
Andy Shevchenkoac330f42011-05-10 15:51:54 +0300469{
470 u16 dsor = 0;
471
472 if (ios->clock) {
Balaji TKd83b6e02011-12-20 15:12:00 +0530473 dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock);
Andy Shevchenkoac330f42011-05-10 15:51:54 +0300474 if (dsor > 250)
475 dsor = 250;
476 }
477
478 return dsor;
479}
480
Andy Shevchenko5934df22011-05-06 12:14:06 +0300481static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host)
482{
483 struct mmc_ios *ios = &host->mmc->ios;
484 unsigned long regval;
485 unsigned long timeout;
486
487 dev_dbg(mmc_dev(host->mmc), "Set clock to %uHz\n", ios->clock);
488
489 omap_hsmmc_stop_clock(host);
490
491 regval = OMAP_HSMMC_READ(host->base, SYSCTL);
492 regval = regval & ~(CLKD_MASK | DTO_MASK);
Balaji TKd83b6e02011-12-20 15:12:00 +0530493 regval = regval | (calc_divisor(host, ios) << 6) | (DTO << 16);
Andy Shevchenko5934df22011-05-06 12:14:06 +0300494 OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
495 OMAP_HSMMC_WRITE(host->base, SYSCTL,
496 OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
497
498 /* Wait till the ICS bit is set */
499 timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
500 while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS
501 && time_before(jiffies, timeout))
502 cpu_relax();
503
504 omap_hsmmc_start_clock(host);
505}
506
Andy Shevchenko3796fb8a2011-07-13 11:31:15 -0400507static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host *host)
508{
509 struct mmc_ios *ios = &host->mmc->ios;
510 u32 con;
511
512 con = OMAP_HSMMC_READ(host->base, CON);
513 switch (ios->bus_width) {
514 case MMC_BUS_WIDTH_8:
515 OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
516 break;
517 case MMC_BUS_WIDTH_4:
518 OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
519 OMAP_HSMMC_WRITE(host->base, HCTL,
520 OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
521 break;
522 case MMC_BUS_WIDTH_1:
523 OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
524 OMAP_HSMMC_WRITE(host->base, HCTL,
525 OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
526 break;
527 }
528}
529
530static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host *host)
531{
532 struct mmc_ios *ios = &host->mmc->ios;
533 u32 con;
534
535 con = OMAP_HSMMC_READ(host->base, CON);
536 if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
537 OMAP_HSMMC_WRITE(host->base, CON, con | OD);
538 else
539 OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
540}
541
Denis Karpov11dd62a2009-09-22 16:44:43 -0700542#ifdef CONFIG_PM
543
544/*
545 * Restore the MMC host context, if it was lost as result of a
546 * power state change.
547 */
Denis Karpov70a33412009-09-22 16:44:59 -0700548static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
Denis Karpov11dd62a2009-09-22 16:44:43 -0700549{
550 struct mmc_ios *ios = &host->mmc->ios;
551 struct omap_mmc_platform_data *pdata = host->pdata;
552 int context_loss = 0;
Andy Shevchenko3796fb8a2011-07-13 11:31:15 -0400553 u32 hctl, capa;
Denis Karpov11dd62a2009-09-22 16:44:43 -0700554 unsigned long timeout;
555
556 if (pdata->get_context_loss_count) {
557 context_loss = pdata->get_context_loss_count(host->dev);
558 if (context_loss < 0)
559 return 1;
560 }
561
562 dev_dbg(mmc_dev(host->mmc), "context was %slost\n",
563 context_loss == host->context_loss ? "not " : "");
564 if (host->context_loss == context_loss)
565 return 1;
566
567 /* Wait for hardware reset */
568 timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
569 while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE
570 && time_before(jiffies, timeout))
571 ;
572
573 /* Do software reset */
574 OMAP_HSMMC_WRITE(host->base, SYSCONFIG, SOFTRESET);
575 timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
576 while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE
577 && time_before(jiffies, timeout))
578 ;
579
580 OMAP_HSMMC_WRITE(host->base, SYSCONFIG,
581 OMAP_HSMMC_READ(host->base, SYSCONFIG) | AUTOIDLE);
582
Balaji T Kc2200ef2012-03-07 09:55:30 -0500583 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
Denis Karpov11dd62a2009-09-22 16:44:43 -0700584 if (host->power_mode != MMC_POWER_OFF &&
585 (1 << ios->vdd) <= MMC_VDD_23_24)
586 hctl = SDVS18;
587 else
588 hctl = SDVS30;
589 capa = VS30 | VS18;
590 } else {
591 hctl = SDVS18;
592 capa = VS18;
593 }
594
595 OMAP_HSMMC_WRITE(host->base, HCTL,
596 OMAP_HSMMC_READ(host->base, HCTL) | hctl);
597
598 OMAP_HSMMC_WRITE(host->base, CAPA,
599 OMAP_HSMMC_READ(host->base, CAPA) | capa);
600
601 OMAP_HSMMC_WRITE(host->base, HCTL,
602 OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
603
604 timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
605 while ((OMAP_HSMMC_READ(host->base, HCTL) & SDBP) != SDBP
606 && time_before(jiffies, timeout))
607 ;
608
Adrian Hunterb4175772010-05-26 14:42:06 -0700609 omap_hsmmc_disable_irq(host);
Denis Karpov11dd62a2009-09-22 16:44:43 -0700610
611 /* Do not initialize card-specific things if the power is off */
612 if (host->power_mode == MMC_POWER_OFF)
613 goto out;
614
Andy Shevchenko3796fb8a2011-07-13 11:31:15 -0400615 omap_hsmmc_set_bus_width(host);
Denis Karpov11dd62a2009-09-22 16:44:43 -0700616
Andy Shevchenko5934df22011-05-06 12:14:06 +0300617 omap_hsmmc_set_clock(host);
Denis Karpov11dd62a2009-09-22 16:44:43 -0700618
Andy Shevchenko3796fb8a2011-07-13 11:31:15 -0400619 omap_hsmmc_set_bus_mode(host);
620
Denis Karpov11dd62a2009-09-22 16:44:43 -0700621out:
622 host->context_loss = context_loss;
623
624 dev_dbg(mmc_dev(host->mmc), "context is restored\n");
625 return 0;
626}
627
628/*
629 * Save the MMC host context (store the number of power state changes so far).
630 */
Denis Karpov70a33412009-09-22 16:44:59 -0700631static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
Denis Karpov11dd62a2009-09-22 16:44:43 -0700632{
633 struct omap_mmc_platform_data *pdata = host->pdata;
634 int context_loss;
635
636 if (pdata->get_context_loss_count) {
637 context_loss = pdata->get_context_loss_count(host->dev);
638 if (context_loss < 0)
639 return;
640 host->context_loss = context_loss;
641 }
642}
643
644#else
645
Denis Karpov70a33412009-09-22 16:44:59 -0700646static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
Denis Karpov11dd62a2009-09-22 16:44:43 -0700647{
648 return 0;
649}
650
Denis Karpov70a33412009-09-22 16:44:59 -0700651static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
Denis Karpov11dd62a2009-09-22 16:44:43 -0700652{
653}
654
655#endif
656
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100657/*
658 * Send init stream sequence to card
659 * before sending IDLE command
660 */
Denis Karpov70a33412009-09-22 16:44:59 -0700661static void send_init_stream(struct omap_hsmmc_host *host)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100662{
663 int reg = 0;
664 unsigned long timeout;
665
Adrian Hunterb62f6222009-09-22 16:45:01 -0700666 if (host->protect_card)
667 return;
668
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100669 disable_irq(host->irq);
Adrian Hunterb4175772010-05-26 14:42:06 -0700670
671 OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100672 OMAP_HSMMC_WRITE(host->base, CON,
673 OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM);
674 OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD);
675
676 timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
677 while ((reg != CC) && time_before(jiffies, timeout))
678 reg = OMAP_HSMMC_READ(host->base, STAT) & CC;
679
680 OMAP_HSMMC_WRITE(host->base, CON,
681 OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM);
Adrian Hunterc653a6d2009-09-22 16:44:56 -0700682
683 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
684 OMAP_HSMMC_READ(host->base, STAT);
685
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100686 enable_irq(host->irq);
687}
688
689static inline
Denis Karpov70a33412009-09-22 16:44:59 -0700690int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100691{
692 int r = 1;
693
Denis Karpov191d1f12009-09-22 16:44:55 -0700694 if (mmc_slot(host).get_cover_state)
695 r = mmc_slot(host).get_cover_state(host->dev, host->slot_id);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100696 return r;
697}
698
699static ssize_t
Denis Karpov70a33412009-09-22 16:44:59 -0700700omap_hsmmc_show_cover_switch(struct device *dev, struct device_attribute *attr,
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100701 char *buf)
702{
703 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
Denis Karpov70a33412009-09-22 16:44:59 -0700704 struct omap_hsmmc_host *host = mmc_priv(mmc);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100705
Denis Karpov70a33412009-09-22 16:44:59 -0700706 return sprintf(buf, "%s\n",
707 omap_hsmmc_cover_is_closed(host) ? "closed" : "open");
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100708}
709
Denis Karpov70a33412009-09-22 16:44:59 -0700710static DEVICE_ATTR(cover_switch, S_IRUGO, omap_hsmmc_show_cover_switch, NULL);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100711
712static ssize_t
Denis Karpov70a33412009-09-22 16:44:59 -0700713omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr,
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100714 char *buf)
715{
716 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
Denis Karpov70a33412009-09-22 16:44:59 -0700717 struct omap_hsmmc_host *host = mmc_priv(mmc);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100718
Denis Karpov191d1f12009-09-22 16:44:55 -0700719 return sprintf(buf, "%s\n", mmc_slot(host).name);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100720}
721
Denis Karpov70a33412009-09-22 16:44:59 -0700722static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100723
724/*
725 * Configure the response type and send the cmd.
726 */
727static void
Denis Karpov70a33412009-09-22 16:44:59 -0700728omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd,
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100729 struct mmc_data *data)
730{
731 int cmdreg = 0, resptype = 0, cmdtype = 0;
732
733 dev_dbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n",
734 mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
735 host->cmd = cmd;
736
Adrian Hunter93caf8e692010-08-11 14:17:48 -0700737 omap_hsmmc_enable_irq(host, cmd);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100738
Adrian Hunter4a694dc2009-01-12 16:13:08 +0200739 host->response_busy = 0;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100740 if (cmd->flags & MMC_RSP_PRESENT) {
741 if (cmd->flags & MMC_RSP_136)
742 resptype = 1;
Adrian Hunter4a694dc2009-01-12 16:13:08 +0200743 else if (cmd->flags & MMC_RSP_BUSY) {
744 resptype = 3;
745 host->response_busy = 1;
746 } else
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100747 resptype = 2;
748 }
749
750 /*
751 * Unlike OMAP1 controller, the cmdtype does not seem to be based on
752 * ac, bc, adtc, bcr. Only commands ending an open ended transfer need
753 * a val of 0x3, rest 0x0.
754 */
755 if (cmd == host->mrq->stop)
756 cmdtype = 0x3;
757
758 cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
759
760 if (data) {
761 cmdreg |= DP_SELECT | MSBS | BCE;
762 if (data->flags & MMC_DATA_READ)
763 cmdreg |= DDIR;
764 else
765 cmdreg &= ~(DDIR);
766 }
767
768 if (host->use_dma)
769 cmdreg |= DMA_EN;
770
Adrian Hunterb4175772010-05-26 14:42:06 -0700771 host->req_in_progress = 1;
Adrian Hunter4dffd7a2009-09-22 16:44:58 -0700772
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100773 OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg);
774 OMAP_HSMMC_WRITE(host->base, CMD, cmdreg);
775}
776
Juha Yrjola0ccd76d2008-11-14 15:22:00 +0200777static int
Denis Karpov70a33412009-09-22 16:44:59 -0700778omap_hsmmc_get_dma_dir(struct omap_hsmmc_host *host, struct mmc_data *data)
Juha Yrjola0ccd76d2008-11-14 15:22:00 +0200779{
780 if (data->flags & MMC_DATA_WRITE)
781 return DMA_TO_DEVICE;
782 else
783 return DMA_FROM_DEVICE;
784}
785
Adrian Hunterb4175772010-05-26 14:42:06 -0700786static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_request *mrq)
787{
788 int dma_ch;
789
790 spin_lock(&host->irq_lock);
791 host->req_in_progress = 0;
792 dma_ch = host->dma_ch;
793 spin_unlock(&host->irq_lock);
794
795 omap_hsmmc_disable_irq(host);
796 /* Do not complete the request if DMA is still in progress */
797 if (mrq->data && host->use_dma && dma_ch != -1)
798 return;
799 host->mrq = NULL;
800 mmc_request_done(host->mmc, mrq);
801}
802
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100803/*
804 * Notify the transfer complete to MMC core
805 */
806static void
Denis Karpov70a33412009-09-22 16:44:59 -0700807omap_hsmmc_xfer_done(struct omap_hsmmc_host *host, struct mmc_data *data)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100808{
Adrian Hunter4a694dc2009-01-12 16:13:08 +0200809 if (!data) {
810 struct mmc_request *mrq = host->mrq;
811
Adrian Hunter23050102009-09-22 16:44:57 -0700812 /* TC before CC from CMD6 - don't know why, but it happens */
813 if (host->cmd && host->cmd->opcode == 6 &&
814 host->response_busy) {
815 host->response_busy = 0;
816 return;
817 }
818
Adrian Hunterb4175772010-05-26 14:42:06 -0700819 omap_hsmmc_request_done(host, mrq);
Adrian Hunter4a694dc2009-01-12 16:13:08 +0200820 return;
821 }
822
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100823 host->data = NULL;
824
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100825 if (!data->error)
826 data->bytes_xfered += data->blocks * (data->blksz);
827 else
828 data->bytes_xfered = 0;
829
830 if (!data->stop) {
Adrian Hunterb4175772010-05-26 14:42:06 -0700831 omap_hsmmc_request_done(host, data->mrq);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100832 return;
833 }
Denis Karpov70a33412009-09-22 16:44:59 -0700834 omap_hsmmc_start_command(host, data->stop, NULL);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100835}
836
837/*
838 * Notify the core about command completion
839 */
840static void
Denis Karpov70a33412009-09-22 16:44:59 -0700841omap_hsmmc_cmd_done(struct omap_hsmmc_host *host, struct mmc_command *cmd)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100842{
843 host->cmd = NULL;
844
845 if (cmd->flags & MMC_RSP_PRESENT) {
846 if (cmd->flags & MMC_RSP_136) {
847 /* response type 2 */
848 cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10);
849 cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32);
850 cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54);
851 cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76);
852 } else {
853 /* response types 1, 1b, 3, 4, 5, 6 */
854 cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10);
855 }
856 }
Adrian Hunterb4175772010-05-26 14:42:06 -0700857 if ((host->data == NULL && !host->response_busy) || cmd->error)
858 omap_hsmmc_request_done(host, cmd->mrq);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100859}
860
861/*
862 * DMA clean up for command errors
863 */
Denis Karpov70a33412009-09-22 16:44:59 -0700864static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host *host, int errno)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100865{
Adrian Hunterb4175772010-05-26 14:42:06 -0700866 int dma_ch;
867
Jarkko Lavinen82788ff2008-12-05 12:31:46 +0200868 host->data->error = errno;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100869
Adrian Hunterb4175772010-05-26 14:42:06 -0700870 spin_lock(&host->irq_lock);
871 dma_ch = host->dma_ch;
872 host->dma_ch = -1;
873 spin_unlock(&host->irq_lock);
874
875 if (host->use_dma && dma_ch != -1) {
Per Forlina9120c32011-06-17 20:14:21 +0200876 dma_unmap_sg(mmc_dev(host->mmc), host->data->sg,
877 host->data->sg_len,
Denis Karpov70a33412009-09-22 16:44:59 -0700878 omap_hsmmc_get_dma_dir(host, host->data));
Adrian Hunterb4175772010-05-26 14:42:06 -0700879 omap_free_dma(dma_ch);
Per Forlin053bf342011-11-07 21:55:11 +0530880 host->data->host_cookie = 0;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100881 }
882 host->data = NULL;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100883}
884
885/*
886 * Readable error output
887 */
888#ifdef CONFIG_MMC_DEBUG
Adrian Hunter699b9582011-05-06 12:14:01 +0300889static void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host, u32 status)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100890{
891 /* --- means reserved bit without definition at documentation */
Denis Karpov70a33412009-09-22 16:44:59 -0700892 static const char *omap_hsmmc_status_bits[] = {
Adrian Hunter699b9582011-05-06 12:14:01 +0300893 "CC" , "TC" , "BGE", "---", "BWR" , "BRR" , "---" , "---" ,
894 "CIRQ", "OBI" , "---", "---", "---" , "---" , "---" , "ERRI",
895 "CTO" , "CCRC", "CEB", "CIE", "DTO" , "DCRC", "DEB" , "---" ,
896 "ACE" , "---" , "---", "---", "CERR", "BADA", "---" , "---"
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100897 };
898 char res[256];
899 char *buf = res;
900 int len, i;
901
902 len = sprintf(buf, "MMC IRQ 0x%x :", status);
903 buf += len;
904
Denis Karpov70a33412009-09-22 16:44:59 -0700905 for (i = 0; i < ARRAY_SIZE(omap_hsmmc_status_bits); i++)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100906 if (status & (1 << i)) {
Denis Karpov70a33412009-09-22 16:44:59 -0700907 len = sprintf(buf, " %s", omap_hsmmc_status_bits[i]);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100908 buf += len;
909 }
910
911 dev_dbg(mmc_dev(host->mmc), "%s\n", res);
912}
Adrian Hunter699b9582011-05-06 12:14:01 +0300913#else
914static inline void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host,
915 u32 status)
916{
917}
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100918#endif /* CONFIG_MMC_DEBUG */
919
Jean Pihet3ebf74b2009-02-06 16:42:51 +0100920/*
921 * MMC controller internal state machines reset
922 *
923 * Used to reset command or data internal state machines, using respectively
924 * SRC or SRD bit of SYSCTL register
925 * Can be called from interrupt context
926 */
Denis Karpov70a33412009-09-22 16:44:59 -0700927static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
928 unsigned long bit)
Jean Pihet3ebf74b2009-02-06 16:42:51 +0100929{
930 unsigned long i = 0;
931 unsigned long limit = (loops_per_jiffy *
932 msecs_to_jiffies(MMC_TIMEOUT_MS));
933
934 OMAP_HSMMC_WRITE(host->base, SYSCTL,
935 OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
936
Madhusudhan Chikkature07ad64b2010-10-01 16:35:25 -0700937 /*
938 * OMAP4 ES2 and greater has an updated reset logic.
939 * Monitor a 0->1 transition first
940 */
941 if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) {
kishore kadiyalab432b4b2010-11-17 22:35:32 -0500942 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit))
Madhusudhan Chikkature07ad64b2010-10-01 16:35:25 -0700943 && (i++ < limit))
944 cpu_relax();
945 }
946 i = 0;
947
Jean Pihet3ebf74b2009-02-06 16:42:51 +0100948 while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
949 (i++ < limit))
950 cpu_relax();
951
952 if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
953 dev_err(mmc_dev(host->mmc),
954 "Timeout waiting on controller reset in %s\n",
955 __func__);
956}
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100957
Adrian Hunterb4175772010-05-26 14:42:06 -0700958static void omap_hsmmc_do_irq(struct omap_hsmmc_host *host, int status)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100959{
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100960 struct mmc_data *data;
Adrian Hunterb4175772010-05-26 14:42:06 -0700961 int end_cmd = 0, end_trans = 0;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100962
Adrian Hunterb4175772010-05-26 14:42:06 -0700963 if (!host->req_in_progress) {
964 do {
965 OMAP_HSMMC_WRITE(host->base, STAT, status);
966 /* Flush posted write */
967 status = OMAP_HSMMC_READ(host->base, STAT);
968 } while (status & INT_EN_MASK);
969 return;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100970 }
971
972 data = host->data;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100973 dev_dbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status);
974
975 if (status & ERR) {
Adrian Hunter699b9582011-05-06 12:14:01 +0300976 omap_hsmmc_dbg_report_irq(host, status);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100977 if ((status & CMD_TIMEOUT) ||
978 (status & CMD_CRC)) {
979 if (host->cmd) {
980 if (status & CMD_TIMEOUT) {
Denis Karpov70a33412009-09-22 16:44:59 -0700981 omap_hsmmc_reset_controller_fsm(host,
982 SRC);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100983 host->cmd->error = -ETIMEDOUT;
984 } else {
985 host->cmd->error = -EILSEQ;
986 }
987 end_cmd = 1;
988 }
Adrian Hunter4a694dc2009-01-12 16:13:08 +0200989 if (host->data || host->response_busy) {
990 if (host->data)
Denis Karpov70a33412009-09-22 16:44:59 -0700991 omap_hsmmc_dma_cleanup(host,
992 -ETIMEDOUT);
Adrian Hunter4a694dc2009-01-12 16:13:08 +0200993 host->response_busy = 0;
Denis Karpov70a33412009-09-22 16:44:59 -0700994 omap_hsmmc_reset_controller_fsm(host, SRD);
Jean Pihetc232f452009-02-11 13:11:39 -0800995 }
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +0100996 }
997 if ((status & DATA_TIMEOUT) ||
998 (status & DATA_CRC)) {
Adrian Hunter4a694dc2009-01-12 16:13:08 +0200999 if (host->data || host->response_busy) {
1000 int err = (status & DATA_TIMEOUT) ?
1001 -ETIMEDOUT : -EILSEQ;
1002
1003 if (host->data)
Denis Karpov70a33412009-09-22 16:44:59 -07001004 omap_hsmmc_dma_cleanup(host, err);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001005 else
Adrian Hunter4a694dc2009-01-12 16:13:08 +02001006 host->mrq->cmd->error = err;
1007 host->response_busy = 0;
Denis Karpov70a33412009-09-22 16:44:59 -07001008 omap_hsmmc_reset_controller_fsm(host, SRD);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001009 end_trans = 1;
1010 }
1011 }
1012 if (status & CARD_ERR) {
1013 dev_dbg(mmc_dev(host->mmc),
1014 "Ignoring card err CMD%d\n", host->cmd->opcode);
1015 if (host->cmd)
1016 end_cmd = 1;
1017 if (host->data)
1018 end_trans = 1;
1019 }
1020 }
1021
1022 OMAP_HSMMC_WRITE(host->base, STAT, status);
1023
Jarkko Lavinena8fe29d2009-04-08 11:18:32 +03001024 if (end_cmd || ((status & CC) && host->cmd))
Denis Karpov70a33412009-09-22 16:44:59 -07001025 omap_hsmmc_cmd_done(host, host->cmd);
Jarkko Lavinen0a40e642009-09-22 16:44:54 -07001026 if ((end_trans || (status & TC)) && host->mrq)
Denis Karpov70a33412009-09-22 16:44:59 -07001027 omap_hsmmc_xfer_done(host, data);
Adrian Hunterb4175772010-05-26 14:42:06 -07001028}
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001029
Adrian Hunterb4175772010-05-26 14:42:06 -07001030/*
1031 * MMC controller IRQ handler
1032 */
1033static irqreturn_t omap_hsmmc_irq(int irq, void *dev_id)
1034{
1035 struct omap_hsmmc_host *host = dev_id;
1036 int status;
1037
1038 status = OMAP_HSMMC_READ(host->base, STAT);
1039 do {
1040 omap_hsmmc_do_irq(host, status);
1041 /* Flush posted write */
1042 status = OMAP_HSMMC_READ(host->base, STAT);
1043 } while (status & INT_EN_MASK);
Adrian Hunter4dffd7a2009-09-22 16:44:58 -07001044
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001045 return IRQ_HANDLED;
1046}
1047
Denis Karpov70a33412009-09-22 16:44:59 -07001048static void set_sd_bus_power(struct omap_hsmmc_host *host)
Adrian Huntere13bb302009-03-12 17:08:26 +02001049{
1050 unsigned long i;
1051
1052 OMAP_HSMMC_WRITE(host->base, HCTL,
1053 OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
1054 for (i = 0; i < loops_per_jiffy; i++) {
1055 if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP)
1056 break;
1057 cpu_relax();
1058 }
1059}
1060
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001061/*
David Brownelleb250822009-02-17 14:49:01 -08001062 * Switch MMC interface voltage ... only relevant for MMC1.
1063 *
1064 * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
1065 * The MMC2 transceiver controls are used instead of DAT4..DAT7.
1066 * Some chips, like eMMC ones, use internal transceivers.
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001067 */
Denis Karpov70a33412009-09-22 16:44:59 -07001068static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001069{
1070 u32 reg_val = 0;
1071 int ret;
1072
1073 /* Disable the clocks */
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301074 pm_runtime_put_sync(host->dev);
Adrian Hunter2bec0892009-09-22 16:45:02 -07001075 if (host->got_dbclk)
1076 clk_disable(host->dbclk);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001077
1078 /* Turn the power off */
1079 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001080
1081 /* Turn the power ON with given VDD 1.8 or 3.0v */
Adrian Hunter2bec0892009-09-22 16:45:02 -07001082 if (!ret)
1083 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1,
1084 vdd);
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301085 pm_runtime_get_sync(host->dev);
Adrian Hunter2bec0892009-09-22 16:45:02 -07001086 if (host->got_dbclk)
1087 clk_enable(host->dbclk);
1088
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001089 if (ret != 0)
1090 goto err;
1091
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001092 OMAP_HSMMC_WRITE(host->base, HCTL,
1093 OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
1094 reg_val = OMAP_HSMMC_READ(host->base, HCTL);
David Brownelleb250822009-02-17 14:49:01 -08001095
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001096 /*
1097 * If a MMC dual voltage card is detected, the set_ios fn calls
1098 * this fn with VDD bit set for 1.8V. Upon card removal from the
Denis Karpov70a33412009-09-22 16:44:59 -07001099 * slot, omap_hsmmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001100 *
David Brownelleb250822009-02-17 14:49:01 -08001101 * Cope with a bit of slop in the range ... per data sheets:
1102 * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
1103 * but recommended values are 1.71V to 1.89V
1104 * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
1105 * but recommended values are 2.7V to 3.3V
1106 *
1107 * Board setup code shouldn't permit anything very out-of-range.
1108 * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
1109 * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001110 */
David Brownelleb250822009-02-17 14:49:01 -08001111 if ((1 << vdd) <= MMC_VDD_23_24)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001112 reg_val |= SDVS18;
David Brownelleb250822009-02-17 14:49:01 -08001113 else
1114 reg_val |= SDVS30;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001115
1116 OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
Adrian Huntere13bb302009-03-12 17:08:26 +02001117 set_sd_bus_power(host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001118
1119 return 0;
1120err:
1121 dev_dbg(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
1122 return ret;
1123}
1124
Adrian Hunterb62f6222009-09-22 16:45:01 -07001125/* Protect the card while the cover is open */
1126static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1127{
1128 if (!mmc_slot(host).get_cover_state)
1129 return;
1130
1131 host->reqs_blocked = 0;
1132 if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) {
1133 if (host->protect_card) {
Girish K Sa3c76eb2011-10-11 11:44:09 +05301134 pr_info("%s: cover is closed, "
Adrian Hunterb62f6222009-09-22 16:45:01 -07001135 "card is now accessible\n",
1136 mmc_hostname(host->mmc));
1137 host->protect_card = 0;
1138 }
1139 } else {
1140 if (!host->protect_card) {
Linus Torvalds3f8ddb02011-11-03 08:05:35 -07001141 pr_info("%s: cover is open, "
Adrian Hunterb62f6222009-09-22 16:45:01 -07001142 "card is now inaccessible\n",
1143 mmc_hostname(host->mmc));
1144 host->protect_card = 1;
1145 }
1146 }
1147}
1148
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001149/*
NeilBrown7efab4f2011-12-30 12:35:13 +11001150 * irq handler to notify the core about card insertion/removal
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001151 */
NeilBrown7efab4f2011-12-30 12:35:13 +11001152static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001153{
NeilBrown7efab4f2011-12-30 12:35:13 +11001154 struct omap_hsmmc_host *host = dev_id;
David Brownell249d0fa2009-02-04 14:42:03 -08001155 struct omap_mmc_slot_data *slot = &mmc_slot(host);
Adrian Huntera6b22402009-09-22 16:44:45 -07001156 int carddetect;
David Brownell249d0fa2009-02-04 14:42:03 -08001157
Adrian Huntera6b22402009-09-22 16:44:45 -07001158 if (host->suspended)
NeilBrown7efab4f2011-12-30 12:35:13 +11001159 return IRQ_HANDLED;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001160
1161 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
Adrian Huntera6b22402009-09-22 16:44:45 -07001162
Denis Karpov191d1f12009-09-22 16:44:55 -07001163 if (slot->card_detect)
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001164 carddetect = slot->card_detect(host->dev, host->slot_id);
Adrian Hunterb62f6222009-09-22 16:45:01 -07001165 else {
1166 omap_hsmmc_protect_card(host);
Adrian Huntera6b22402009-09-22 16:44:45 -07001167 carddetect = -ENOSYS;
Adrian Hunterb62f6222009-09-22 16:45:01 -07001168 }
Adrian Huntera6b22402009-09-22 16:44:45 -07001169
Madhusudhan Chikkaturecdeebad2010-04-06 14:34:49 -07001170 if (carddetect)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001171 mmc_detect_change(host->mmc, (HZ * 200) / 1000);
Madhusudhan Chikkaturecdeebad2010-04-06 14:34:49 -07001172 else
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001173 mmc_detect_change(host->mmc, (HZ * 50) / 1000);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001174 return IRQ_HANDLED;
1175}
1176
Denis Karpov70a33412009-09-22 16:44:59 -07001177static int omap_hsmmc_get_dma_sync_dev(struct omap_hsmmc_host *host,
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001178 struct mmc_data *data)
1179{
1180 int sync_dev;
1181
Grazvydas Ignotasf3e2f1d2009-01-03 10:36:13 +00001182 if (data->flags & MMC_DATA_WRITE)
1183 sync_dev = host->dma_line_tx;
1184 else
1185 sync_dev = host->dma_line_rx;
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001186 return sync_dev;
1187}
1188
Denis Karpov70a33412009-09-22 16:44:59 -07001189static void omap_hsmmc_config_dma_params(struct omap_hsmmc_host *host,
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001190 struct mmc_data *data,
1191 struct scatterlist *sgl)
1192{
1193 int blksz, nblk, dma_ch;
1194
1195 dma_ch = host->dma_ch;
1196 if (data->flags & MMC_DATA_WRITE) {
1197 omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
1198 (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
1199 omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
1200 sg_dma_address(sgl), 0, 0);
1201 } else {
1202 omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
Denis Karpov191d1f12009-09-22 16:44:55 -07001203 (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001204 omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
1205 sg_dma_address(sgl), 0, 0);
1206 }
1207
1208 blksz = host->data->blksz;
1209 nblk = sg_dma_len(sgl) / blksz;
1210
1211 omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32,
1212 blksz / 4, nblk, OMAP_DMA_SYNC_FRAME,
Denis Karpov70a33412009-09-22 16:44:59 -07001213 omap_hsmmc_get_dma_sync_dev(host, data),
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001214 !(data->flags & MMC_DATA_WRITE));
1215
1216 omap_start_dma(dma_ch);
1217}
1218
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001219/*
1220 * DMA call back function
1221 */
Adrian Hunterb4175772010-05-26 14:42:06 -07001222static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *cb_data)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001223{
Adrian Hunterb4175772010-05-26 14:42:06 -07001224 struct omap_hsmmc_host *host = cb_data;
Adrian Hunter770d7432011-05-06 12:14:11 +03001225 struct mmc_data *data;
Adrian Hunterb4175772010-05-26 14:42:06 -07001226 int dma_ch, req_in_progress;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001227
Venkatraman Sf3584e52010-08-10 18:01:54 -07001228 if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) {
1229 dev_warn(mmc_dev(host->mmc), "unexpected dma status %x\n",
1230 ch_status);
1231 return;
1232 }
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001233
Adrian Hunterb4175772010-05-26 14:42:06 -07001234 spin_lock(&host->irq_lock);
1235 if (host->dma_ch < 0) {
1236 spin_unlock(&host->irq_lock);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001237 return;
Adrian Hunterb4175772010-05-26 14:42:06 -07001238 }
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001239
Adrian Hunter770d7432011-05-06 12:14:11 +03001240 data = host->mrq->data;
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001241 host->dma_sg_idx++;
1242 if (host->dma_sg_idx < host->dma_len) {
1243 /* Fire up the next transfer. */
Adrian Hunterb4175772010-05-26 14:42:06 -07001244 omap_hsmmc_config_dma_params(host, data,
1245 data->sg + host->dma_sg_idx);
1246 spin_unlock(&host->irq_lock);
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001247 return;
1248 }
1249
Per Forlin9782aff2011-07-01 18:55:23 +02001250 if (!data->host_cookie)
1251 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
1252 omap_hsmmc_get_dma_dir(host, data));
Adrian Hunterb4175772010-05-26 14:42:06 -07001253
1254 req_in_progress = host->req_in_progress;
1255 dma_ch = host->dma_ch;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001256 host->dma_ch = -1;
Adrian Hunterb4175772010-05-26 14:42:06 -07001257 spin_unlock(&host->irq_lock);
1258
1259 omap_free_dma(dma_ch);
1260
1261 /* If DMA has finished after TC, complete the request */
1262 if (!req_in_progress) {
1263 struct mmc_request *mrq = host->mrq;
1264
1265 host->mrq = NULL;
1266 mmc_request_done(host->mmc, mrq);
1267 }
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001268}
1269
Per Forlin9782aff2011-07-01 18:55:23 +02001270static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host,
1271 struct mmc_data *data,
1272 struct omap_hsmmc_next *next)
1273{
1274 int dma_len;
1275
1276 if (!next && data->host_cookie &&
1277 data->host_cookie != host->next_data.cookie) {
Girish K Sa3c76eb2011-10-11 11:44:09 +05301278 pr_warning("[%s] invalid cookie: data->host_cookie %d"
Per Forlin9782aff2011-07-01 18:55:23 +02001279 " host->next_data.cookie %d\n",
1280 __func__, data->host_cookie, host->next_data.cookie);
1281 data->host_cookie = 0;
1282 }
1283
1284 /* Check if next job is already prepared */
1285 if (next ||
1286 (!next && data->host_cookie != host->next_data.cookie)) {
1287 dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
1288 data->sg_len,
1289 omap_hsmmc_get_dma_dir(host, data));
1290
1291 } else {
1292 dma_len = host->next_data.dma_len;
1293 host->next_data.dma_len = 0;
1294 }
1295
1296
1297 if (dma_len == 0)
1298 return -EINVAL;
1299
1300 if (next) {
1301 next->dma_len = dma_len;
1302 data->host_cookie = ++next->cookie < 0 ? 1 : next->cookie;
1303 } else
1304 host->dma_len = dma_len;
1305
1306 return 0;
1307}
1308
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001309/*
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001310 * Routine to configure and start DMA for the MMC card
1311 */
Denis Karpov70a33412009-09-22 16:44:59 -07001312static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host,
1313 struct mmc_request *req)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001314{
Adrian Hunterb4175772010-05-26 14:42:06 -07001315 int dma_ch = 0, ret = 0, i;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001316 struct mmc_data *data = req->data;
1317
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001318 /* Sanity check: all the SG entries must be aligned by block size. */
Jarkko Lavinena3f406f2009-09-22 16:44:46 -07001319 for (i = 0; i < data->sg_len; i++) {
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001320 struct scatterlist *sgl;
1321
1322 sgl = data->sg + i;
1323 if (sgl->length % data->blksz)
1324 return -EINVAL;
1325 }
1326 if ((data->blksz % 4) != 0)
1327 /* REVISIT: The MMC buffer increments only when MSB is written.
1328 * Return error for blksz which is non multiple of four.
1329 */
1330 return -EINVAL;
1331
Adrian Hunterb4175772010-05-26 14:42:06 -07001332 BUG_ON(host->dma_ch != -1);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001333
Denis Karpov70a33412009-09-22 16:44:59 -07001334 ret = omap_request_dma(omap_hsmmc_get_dma_sync_dev(host, data),
1335 "MMC/SD", omap_hsmmc_dma_cb, host, &dma_ch);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001336 if (ret != 0) {
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001337 dev_err(mmc_dev(host->mmc),
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001338 "%s: omap_request_dma() failed with %d\n",
1339 mmc_hostname(host->mmc), ret);
1340 return ret;
1341 }
Per Forlin9782aff2011-07-01 18:55:23 +02001342 ret = omap_hsmmc_pre_dma_transfer(host, data, NULL);
1343 if (ret)
1344 return ret;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001345
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001346 host->dma_ch = dma_ch;
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001347 host->dma_sg_idx = 0;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001348
Denis Karpov70a33412009-09-22 16:44:59 -07001349 omap_hsmmc_config_dma_params(host, data, data->sg);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001350
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001351 return 0;
1352}
1353
Denis Karpov70a33412009-09-22 16:44:59 -07001354static void set_data_timeout(struct omap_hsmmc_host *host,
Adrian Huntere2bf08d2009-09-22 16:45:03 -07001355 unsigned int timeout_ns,
1356 unsigned int timeout_clks)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001357{
1358 unsigned int timeout, cycle_ns;
1359 uint32_t reg, clkd, dto = 0;
1360
1361 reg = OMAP_HSMMC_READ(host->base, SYSCTL);
1362 clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
1363 if (clkd == 0)
1364 clkd = 1;
1365
1366 cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
Adrian Huntere2bf08d2009-09-22 16:45:03 -07001367 timeout = timeout_ns / cycle_ns;
1368 timeout += timeout_clks;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001369 if (timeout) {
1370 while ((timeout & 0x80000000) == 0) {
1371 dto += 1;
1372 timeout <<= 1;
1373 }
1374 dto = 31 - dto;
1375 timeout <<= 1;
1376 if (timeout && dto)
1377 dto += 1;
1378 if (dto >= 13)
1379 dto -= 13;
1380 else
1381 dto = 0;
1382 if (dto > 14)
1383 dto = 14;
1384 }
1385
1386 reg &= ~DTO_MASK;
1387 reg |= dto << DTO_SHIFT;
1388 OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
1389}
1390
1391/*
1392 * Configure block length for MMC/SD cards and initiate the transfer.
1393 */
1394static int
Denis Karpov70a33412009-09-22 16:44:59 -07001395omap_hsmmc_prepare_data(struct omap_hsmmc_host *host, struct mmc_request *req)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001396{
1397 int ret;
1398 host->data = req->data;
1399
1400 if (req->data == NULL) {
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001401 OMAP_HSMMC_WRITE(host->base, BLK, 0);
Adrian Huntere2bf08d2009-09-22 16:45:03 -07001402 /*
1403 * Set an arbitrary 100ms data timeout for commands with
1404 * busy signal.
1405 */
1406 if (req->cmd->flags & MMC_RSP_BUSY)
1407 set_data_timeout(host, 100000000U, 0);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001408 return 0;
1409 }
1410
1411 OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
1412 | (req->data->blocks << 16));
Adrian Huntere2bf08d2009-09-22 16:45:03 -07001413 set_data_timeout(host, req->data->timeout_ns, req->data->timeout_clks);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001414
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001415 if (host->use_dma) {
Denis Karpov70a33412009-09-22 16:44:59 -07001416 ret = omap_hsmmc_start_dma_transfer(host, req);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001417 if (ret != 0) {
1418 dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n");
1419 return ret;
1420 }
1421 }
1422 return 0;
1423}
1424
Per Forlin9782aff2011-07-01 18:55:23 +02001425static void omap_hsmmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq,
1426 int err)
1427{
1428 struct omap_hsmmc_host *host = mmc_priv(mmc);
1429 struct mmc_data *data = mrq->data;
1430
1431 if (host->use_dma) {
Per Forlin053bf342011-11-07 21:55:11 +05301432 if (data->host_cookie)
1433 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
1434 data->sg_len,
1435 omap_hsmmc_get_dma_dir(host, data));
Per Forlin9782aff2011-07-01 18:55:23 +02001436 data->host_cookie = 0;
1437 }
1438}
1439
1440static void omap_hsmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq,
1441 bool is_first_req)
1442{
1443 struct omap_hsmmc_host *host = mmc_priv(mmc);
1444
1445 if (mrq->data->host_cookie) {
1446 mrq->data->host_cookie = 0;
1447 return ;
1448 }
1449
1450 if (host->use_dma)
1451 if (omap_hsmmc_pre_dma_transfer(host, mrq->data,
1452 &host->next_data))
1453 mrq->data->host_cookie = 0;
1454}
1455
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001456/*
1457 * Request function. for read/write operation
1458 */
Denis Karpov70a33412009-09-22 16:44:59 -07001459static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001460{
Denis Karpov70a33412009-09-22 16:44:59 -07001461 struct omap_hsmmc_host *host = mmc_priv(mmc);
Jarkko Lavinena3f406f2009-09-22 16:44:46 -07001462 int err;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001463
Adrian Hunterb4175772010-05-26 14:42:06 -07001464 BUG_ON(host->req_in_progress);
1465 BUG_ON(host->dma_ch != -1);
1466 if (host->protect_card) {
1467 if (host->reqs_blocked < 3) {
1468 /*
1469 * Ensure the controller is left in a consistent
1470 * state by resetting the command and data state
1471 * machines.
1472 */
1473 omap_hsmmc_reset_controller_fsm(host, SRD);
1474 omap_hsmmc_reset_controller_fsm(host, SRC);
1475 host->reqs_blocked += 1;
1476 }
1477 req->cmd->error = -EBADF;
1478 if (req->data)
1479 req->data->error = -EBADF;
1480 req->cmd->retries = 0;
1481 mmc_request_done(mmc, req);
1482 return;
1483 } else if (host->reqs_blocked)
1484 host->reqs_blocked = 0;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001485 WARN_ON(host->mrq != NULL);
1486 host->mrq = req;
Denis Karpov70a33412009-09-22 16:44:59 -07001487 err = omap_hsmmc_prepare_data(host, req);
Jarkko Lavinena3f406f2009-09-22 16:44:46 -07001488 if (err) {
1489 req->cmd->error = err;
1490 if (req->data)
1491 req->data->error = err;
1492 host->mrq = NULL;
1493 mmc_request_done(mmc, req);
1494 return;
1495 }
1496
Denis Karpov70a33412009-09-22 16:44:59 -07001497 omap_hsmmc_start_command(host, req->cmd, req->data);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001498}
1499
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001500/* Routine to configure clock values. Exposed API to core */
Denis Karpov70a33412009-09-22 16:44:59 -07001501static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001502{
Denis Karpov70a33412009-09-22 16:44:59 -07001503 struct omap_hsmmc_host *host = mmc_priv(mmc);
Adrian Huntera3621462009-09-22 16:44:42 -07001504 int do_send_init_stream = 0;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001505
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301506 pm_runtime_get_sync(host->dev);
Adrian Hunter5e2ea612009-09-22 16:44:39 -07001507
Adrian Huntera3621462009-09-22 16:44:42 -07001508 if (ios->power_mode != host->power_mode) {
1509 switch (ios->power_mode) {
1510 case MMC_POWER_OFF:
1511 mmc_slot(host).set_power(host->dev, host->slot_id,
1512 0, 0);
Adrian Hunter623821f2009-09-22 16:44:51 -07001513 host->vdd = 0;
Adrian Huntera3621462009-09-22 16:44:42 -07001514 break;
1515 case MMC_POWER_UP:
1516 mmc_slot(host).set_power(host->dev, host->slot_id,
1517 1, ios->vdd);
Adrian Hunter623821f2009-09-22 16:44:51 -07001518 host->vdd = ios->vdd;
Adrian Huntera3621462009-09-22 16:44:42 -07001519 break;
1520 case MMC_POWER_ON:
1521 do_send_init_stream = 1;
1522 break;
1523 }
1524 host->power_mode = ios->power_mode;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001525 }
1526
Denis Karpovdd498ef2009-09-22 16:44:49 -07001527 /* FIXME: set registers based only on changes to ios */
1528
Andy Shevchenko3796fb8a2011-07-13 11:31:15 -04001529 omap_hsmmc_set_bus_width(host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001530
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +05301531 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
David Brownelleb250822009-02-17 14:49:01 -08001532 /* Only MMC1 can interface at 3V without some flavor
1533 * of external transceiver; but they all handle 1.8V.
1534 */
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001535 if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
1536 (ios->vdd == DUAL_VOLT_OCR_BIT)) {
1537 /*
1538 * The mmc_select_voltage fn of the core does
1539 * not seem to set the power_mode to
1540 * MMC_POWER_UP upon recalculating the voltage.
1541 * vdd 1.8v.
1542 */
Denis Karpov70a33412009-09-22 16:44:59 -07001543 if (omap_hsmmc_switch_opcond(host, ios->vdd) != 0)
1544 dev_dbg(mmc_dev(host->mmc),
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001545 "Switch operation failed\n");
1546 }
1547 }
1548
Andy Shevchenko5934df22011-05-06 12:14:06 +03001549 omap_hsmmc_set_clock(host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001550
Adrian Huntera3621462009-09-22 16:44:42 -07001551 if (do_send_init_stream)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001552 send_init_stream(host);
1553
Andy Shevchenko3796fb8a2011-07-13 11:31:15 -04001554 omap_hsmmc_set_bus_mode(host);
Adrian Hunter5e2ea612009-09-22 16:44:39 -07001555
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301556 pm_runtime_put_autosuspend(host->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001557}
1558
1559static int omap_hsmmc_get_cd(struct mmc_host *mmc)
1560{
Denis Karpov70a33412009-09-22 16:44:59 -07001561 struct omap_hsmmc_host *host = mmc_priv(mmc);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001562
Denis Karpov191d1f12009-09-22 16:44:55 -07001563 if (!mmc_slot(host).card_detect)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001564 return -ENOSYS;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001565 return mmc_slot(host).card_detect(host->dev, host->slot_id);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001566}
1567
1568static int omap_hsmmc_get_ro(struct mmc_host *mmc)
1569{
Denis Karpov70a33412009-09-22 16:44:59 -07001570 struct omap_hsmmc_host *host = mmc_priv(mmc);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001571
Denis Karpov191d1f12009-09-22 16:44:55 -07001572 if (!mmc_slot(host).get_ro)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001573 return -ENOSYS;
Denis Karpov191d1f12009-09-22 16:44:55 -07001574 return mmc_slot(host).get_ro(host->dev, 0);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001575}
1576
Grazvydas Ignotas48168582010-08-10 18:01:52 -07001577static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
1578{
1579 struct omap_hsmmc_host *host = mmc_priv(mmc);
1580
1581 if (mmc_slot(host).init_card)
1582 mmc_slot(host).init_card(card);
1583}
1584
Denis Karpov70a33412009-09-22 16:44:59 -07001585static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host)
Kim Kyuwon1b331e62009-02-20 13:10:08 +01001586{
1587 u32 hctl, capa, value;
1588
1589 /* Only MMC1 supports 3.0V */
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +05301590 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
Kim Kyuwon1b331e62009-02-20 13:10:08 +01001591 hctl = SDVS30;
1592 capa = VS30 | VS18;
1593 } else {
1594 hctl = SDVS18;
1595 capa = VS18;
1596 }
1597
1598 value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
1599 OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
1600
1601 value = OMAP_HSMMC_READ(host->base, CAPA);
1602 OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
1603
1604 /* Set the controller to AUTO IDLE mode */
1605 value = OMAP_HSMMC_READ(host->base, SYSCONFIG);
1606 OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE);
1607
1608 /* Set SD bus power bit */
Adrian Huntere13bb302009-03-12 17:08:26 +02001609 set_sd_bus_power(host);
Kim Kyuwon1b331e62009-02-20 13:10:08 +01001610}
1611
Denis Karpov70a33412009-09-22 16:44:59 -07001612static int omap_hsmmc_enable_fclk(struct mmc_host *mmc)
Denis Karpovdd498ef2009-09-22 16:44:49 -07001613{
Denis Karpov70a33412009-09-22 16:44:59 -07001614 struct omap_hsmmc_host *host = mmc_priv(mmc);
Denis Karpovdd498ef2009-09-22 16:44:49 -07001615
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301616 pm_runtime_get_sync(host->dev);
1617
Denis Karpovdd498ef2009-09-22 16:44:49 -07001618 return 0;
1619}
1620
Adrian Hunter907d2e72012-02-29 09:17:21 +02001621static int omap_hsmmc_disable_fclk(struct mmc_host *mmc)
Denis Karpovdd498ef2009-09-22 16:44:49 -07001622{
Denis Karpov70a33412009-09-22 16:44:59 -07001623 struct omap_hsmmc_host *host = mmc_priv(mmc);
Denis Karpovdd498ef2009-09-22 16:44:49 -07001624
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301625 pm_runtime_mark_last_busy(host->dev);
1626 pm_runtime_put_autosuspend(host->dev);
1627
Denis Karpovdd498ef2009-09-22 16:44:49 -07001628 return 0;
1629}
1630
Denis Karpov70a33412009-09-22 16:44:59 -07001631static const struct mmc_host_ops omap_hsmmc_ops = {
1632 .enable = omap_hsmmc_enable_fclk,
1633 .disable = omap_hsmmc_disable_fclk,
Per Forlin9782aff2011-07-01 18:55:23 +02001634 .post_req = omap_hsmmc_post_req,
1635 .pre_req = omap_hsmmc_pre_req,
Denis Karpov70a33412009-09-22 16:44:59 -07001636 .request = omap_hsmmc_request,
1637 .set_ios = omap_hsmmc_set_ios,
Denis Karpovdd498ef2009-09-22 16:44:49 -07001638 .get_cd = omap_hsmmc_get_cd,
1639 .get_ro = omap_hsmmc_get_ro,
Grazvydas Ignotas48168582010-08-10 18:01:52 -07001640 .init_card = omap_hsmmc_init_card,
Denis Karpovdd498ef2009-09-22 16:44:49 -07001641 /* NYET -- enable_sdio_irq */
1642};
1643
Denis Karpovd900f712009-09-22 16:44:38 -07001644#ifdef CONFIG_DEBUG_FS
1645
Denis Karpov70a33412009-09-22 16:44:59 -07001646static int omap_hsmmc_regs_show(struct seq_file *s, void *data)
Denis Karpovd900f712009-09-22 16:44:38 -07001647{
1648 struct mmc_host *mmc = s->private;
Denis Karpov70a33412009-09-22 16:44:59 -07001649 struct omap_hsmmc_host *host = mmc_priv(mmc);
Denis Karpov11dd62a2009-09-22 16:44:43 -07001650 int context_loss = 0;
1651
Denis Karpov70a33412009-09-22 16:44:59 -07001652 if (host->pdata->get_context_loss_count)
1653 context_loss = host->pdata->get_context_loss_count(host->dev);
Denis Karpovd900f712009-09-22 16:44:38 -07001654
Adrian Hunter907d2e72012-02-29 09:17:21 +02001655 seq_printf(s, "mmc%d:\n ctx_loss:\t%d:%d\n\nregs:\n",
1656 mmc->index, host->context_loss, context_loss);
Adrian Hunter5e2ea612009-09-22 16:44:39 -07001657
Balaji T K7a8c2ce2011-07-01 22:09:34 +05301658 if (host->suspended) {
Denis Karpovdd498ef2009-09-22 16:44:49 -07001659 seq_printf(s, "host suspended, can't read registers\n");
1660 return 0;
1661 }
1662
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301663 pm_runtime_get_sync(host->dev);
Denis Karpovd900f712009-09-22 16:44:38 -07001664
1665 seq_printf(s, "SYSCONFIG:\t0x%08x\n",
1666 OMAP_HSMMC_READ(host->base, SYSCONFIG));
1667 seq_printf(s, "CON:\t\t0x%08x\n",
1668 OMAP_HSMMC_READ(host->base, CON));
1669 seq_printf(s, "HCTL:\t\t0x%08x\n",
1670 OMAP_HSMMC_READ(host->base, HCTL));
1671 seq_printf(s, "SYSCTL:\t\t0x%08x\n",
1672 OMAP_HSMMC_READ(host->base, SYSCTL));
1673 seq_printf(s, "IE:\t\t0x%08x\n",
1674 OMAP_HSMMC_READ(host->base, IE));
1675 seq_printf(s, "ISE:\t\t0x%08x\n",
1676 OMAP_HSMMC_READ(host->base, ISE));
1677 seq_printf(s, "CAPA:\t\t0x%08x\n",
1678 OMAP_HSMMC_READ(host->base, CAPA));
Adrian Hunter5e2ea612009-09-22 16:44:39 -07001679
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301680 pm_runtime_mark_last_busy(host->dev);
1681 pm_runtime_put_autosuspend(host->dev);
Denis Karpovdd498ef2009-09-22 16:44:49 -07001682
Denis Karpovd900f712009-09-22 16:44:38 -07001683 return 0;
1684}
1685
Denis Karpov70a33412009-09-22 16:44:59 -07001686static int omap_hsmmc_regs_open(struct inode *inode, struct file *file)
Denis Karpovd900f712009-09-22 16:44:38 -07001687{
Denis Karpov70a33412009-09-22 16:44:59 -07001688 return single_open(file, omap_hsmmc_regs_show, inode->i_private);
Denis Karpovd900f712009-09-22 16:44:38 -07001689}
1690
1691static const struct file_operations mmc_regs_fops = {
Denis Karpov70a33412009-09-22 16:44:59 -07001692 .open = omap_hsmmc_regs_open,
Denis Karpovd900f712009-09-22 16:44:38 -07001693 .read = seq_read,
1694 .llseek = seq_lseek,
1695 .release = single_release,
1696};
1697
Denis Karpov70a33412009-09-22 16:44:59 -07001698static void omap_hsmmc_debugfs(struct mmc_host *mmc)
Denis Karpovd900f712009-09-22 16:44:38 -07001699{
1700 if (mmc->debugfs_root)
1701 debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root,
1702 mmc, &mmc_regs_fops);
1703}
1704
1705#else
1706
Denis Karpov70a33412009-09-22 16:44:59 -07001707static void omap_hsmmc_debugfs(struct mmc_host *mmc)
Denis Karpovd900f712009-09-22 16:44:38 -07001708{
1709}
1710
1711#endif
1712
Denis Karpov70a33412009-09-22 16:44:59 -07001713static int __init omap_hsmmc_probe(struct platform_device *pdev)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001714{
1715 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
1716 struct mmc_host *mmc;
Denis Karpov70a33412009-09-22 16:44:59 -07001717 struct omap_hsmmc_host *host = NULL;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001718 struct resource *res;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001719 int ret, irq;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001720
1721 if (pdata == NULL) {
1722 dev_err(&pdev->dev, "Platform Data is missing\n");
1723 return -ENXIO;
1724 }
1725
1726 if (pdata->nr_slots == 0) {
1727 dev_err(&pdev->dev, "No Slots\n");
1728 return -ENXIO;
1729 }
1730
1731 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1732 irq = platform_get_irq(pdev, 0);
1733 if (res == NULL || irq < 0)
1734 return -ENXIO;
1735
kishore kadiyala91a0b082010-10-01 16:35:28 -07001736 res->start += pdata->reg_offset;
1737 res->end += pdata->reg_offset;
Chris Ball984b2032011-03-22 16:34:42 -07001738 res = request_mem_region(res->start, resource_size(res), pdev->name);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001739 if (res == NULL)
1740 return -EBUSY;
1741
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001742 ret = omap_hsmmc_gpio_init(pdata);
1743 if (ret)
1744 goto err;
1745
Denis Karpov70a33412009-09-22 16:44:59 -07001746 mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001747 if (!mmc) {
1748 ret = -ENOMEM;
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001749 goto err_alloc;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001750 }
1751
1752 host = mmc_priv(mmc);
1753 host->mmc = mmc;
1754 host->pdata = pdata;
1755 host->dev = &pdev->dev;
1756 host->use_dma = 1;
1757 host->dev->dma_mask = &pdata->dma_mask;
1758 host->dma_ch = -1;
1759 host->irq = irq;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001760 host->slot_id = 0;
1761 host->mapbase = res->start;
1762 host->base = ioremap(host->mapbase, SZ_4K);
Adrian Hunter6da20c82010-02-15 10:03:34 -08001763 host->power_mode = MMC_POWER_OFF;
Per Forlin9782aff2011-07-01 18:55:23 +02001764 host->next_data.cookie = 1;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001765
1766 platform_set_drvdata(pdev, host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001767
Balaji T K7a8c2ce2011-07-01 22:09:34 +05301768 mmc->ops = &omap_hsmmc_ops;
Denis Karpovdd498ef2009-09-22 16:44:49 -07001769
Adrian Huntere0eb2422010-02-15 10:03:34 -08001770 /*
1771 * If regulator_disable can only put vcc_aux to sleep then there is
1772 * no off state.
1773 */
1774 if (mmc_slot(host).vcc_aux_disable_is_sleep)
1775 mmc_slot(host).no_off = 1;
1776
Daniel Mackd418ed82012-02-19 13:20:33 +01001777 mmc->f_min = OMAP_MMC_MIN_CLOCK;
1778
1779 if (pdata->max_freq > 0)
1780 mmc->f_max = pdata->max_freq;
1781 else
1782 mmc->f_max = OMAP_MMC_MAX_CLOCK;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001783
Adrian Hunter4dffd7a2009-09-22 16:44:58 -07001784 spin_lock_init(&host->irq_lock);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001785
Russell King6f7607c2009-01-28 10:22:50 +00001786 host->fclk = clk_get(&pdev->dev, "fck");
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001787 if (IS_ERR(host->fclk)) {
1788 ret = PTR_ERR(host->fclk);
1789 host->fclk = NULL;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001790 goto err1;
1791 }
1792
Denis Karpov70a33412009-09-22 16:44:59 -07001793 omap_hsmmc_context_save(host);
Denis Karpov11dd62a2009-09-22 16:44:43 -07001794
Paul Walmsley9b682562011-10-06 14:50:35 -06001795 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
1796 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
1797 mmc->caps2 |= MMC_CAP2_NO_MULTI_READ;
1798 }
Denis Karpovdd498ef2009-09-22 16:44:49 -07001799
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301800 pm_runtime_enable(host->dev);
1801 pm_runtime_get_sync(host->dev);
1802 pm_runtime_set_autosuspend_delay(host->dev, MMC_AUTOSUSPEND_DELAY);
1803 pm_runtime_use_autosuspend(host->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001804
Adrian Hunter2bec0892009-09-22 16:45:02 -07001805 if (cpu_is_omap2430()) {
1806 host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
1807 /*
1808 * MMC can still work without debounce clock.
1809 */
1810 if (IS_ERR(host->dbclk))
1811 dev_warn(mmc_dev(host->mmc),
1812 "Failed to get debounce clock\n");
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001813 else
Adrian Hunter2bec0892009-09-22 16:45:02 -07001814 host->got_dbclk = 1;
1815
1816 if (host->got_dbclk)
1817 if (clk_enable(host->dbclk) != 0)
1818 dev_dbg(mmc_dev(host->mmc), "Enabling debounce"
1819 " clk failed\n");
1820 }
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001821
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001822 /* Since we do only SG emulation, we can have as many segs
1823 * as we want. */
Martin K. Petersena36274e2010-09-10 01:33:59 -04001824 mmc->max_segs = 1024;
Juha Yrjola0ccd76d2008-11-14 15:22:00 +02001825
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001826 mmc->max_blk_size = 512; /* Block Length at max can be 1024 */
1827 mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */
1828 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
1829 mmc->max_seg_size = mmc->max_req_size;
1830
Jarkko Lavinen13189e72009-09-22 16:44:53 -07001831 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
Adrian Hunter93caf8e692010-08-11 14:17:48 -07001832 MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001833
Sukumar Ghorai3a638332010-09-15 14:49:23 +00001834 mmc->caps |= mmc_slot(host).caps;
1835 if (mmc->caps & MMC_CAP_8_BIT_DATA)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001836 mmc->caps |= MMC_CAP_4_BIT_DATA;
1837
Denis Karpov191d1f12009-09-22 16:44:55 -07001838 if (mmc_slot(host).nonremovable)
Adrian Hunter23d99bb2009-09-22 16:44:48 -07001839 mmc->caps |= MMC_CAP_NONREMOVABLE;
1840
Eliad Peller6fdc75d2011-11-22 16:02:18 +02001841 mmc->pm_caps = mmc_slot(host).pm_caps;
1842
Denis Karpov70a33412009-09-22 16:44:59 -07001843 omap_hsmmc_conf_bus_power(host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001844
Balaji T Kb7bf7732012-03-07 09:55:30 -05001845 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
1846 if (!res) {
1847 dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n");
Grazvydas Ignotasf3e2f1d2009-01-03 10:36:13 +00001848 goto err_irq;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001849 }
Balaji T Kb7bf7732012-03-07 09:55:30 -05001850 host->dma_line_tx = res->start;
1851
1852 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1853 if (!res) {
1854 dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n");
1855 goto err_irq;
1856 }
1857 host->dma_line_rx = res->start;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001858
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001859 /* Request IRQ for MMC operations */
Yong Zhangd9618e92011-09-22 16:59:04 +08001860 ret = request_irq(host->irq, omap_hsmmc_irq, 0,
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001861 mmc_hostname(mmc), host);
1862 if (ret) {
1863 dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
1864 goto err_irq;
1865 }
1866
1867 if (pdata->init != NULL) {
1868 if (pdata->init(&pdev->dev) != 0) {
Denis Karpov70a33412009-09-22 16:44:59 -07001869 dev_dbg(mmc_dev(host->mmc),
1870 "Unable to configure MMC IRQs\n");
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001871 goto err_irq_cd_init;
1872 }
1873 }
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001874
Adrian Hunterb702b102010-02-15 10:03:35 -08001875 if (omap_hsmmc_have_reg() && !mmc_slot(host).set_power) {
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001876 ret = omap_hsmmc_reg_get(host);
1877 if (ret)
1878 goto err_reg;
1879 host->use_reg = 1;
1880 }
1881
David Brownellb583f262009-05-28 14:04:03 -07001882 mmc->ocr_avail = mmc_slot(host).ocr_mask;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001883
1884 /* Request IRQ for card detect */
Adrian Huntere1a55f52009-01-26 13:17:25 +02001885 if ((mmc_slot(host).card_detect_irq)) {
NeilBrown7efab4f2011-12-30 12:35:13 +11001886 ret = request_threaded_irq(mmc_slot(host).card_detect_irq,
1887 NULL,
1888 omap_hsmmc_detect,
1889 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
1890 mmc_hostname(mmc), host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001891 if (ret) {
1892 dev_dbg(mmc_dev(host->mmc),
1893 "Unable to grab MMC CD IRQ\n");
1894 goto err_irq_cd;
1895 }
kishore kadiyala72f2e2c2010-09-24 17:13:20 +00001896 pdata->suspend = omap_hsmmc_suspend_cdirq;
1897 pdata->resume = omap_hsmmc_resume_cdirq;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001898 }
1899
Adrian Hunterb4175772010-05-26 14:42:06 -07001900 omap_hsmmc_disable_irq(host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001901
Adrian Hunterb62f6222009-09-22 16:45:01 -07001902 omap_hsmmc_protect_card(host);
1903
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001904 mmc_add_host(mmc);
1905
Denis Karpov191d1f12009-09-22 16:44:55 -07001906 if (mmc_slot(host).name != NULL) {
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001907 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
1908 if (ret < 0)
1909 goto err_slot_name;
1910 }
Denis Karpov191d1f12009-09-22 16:44:55 -07001911 if (mmc_slot(host).card_detect_irq && mmc_slot(host).get_cover_state) {
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001912 ret = device_create_file(&mmc->class_dev,
1913 &dev_attr_cover_switch);
1914 if (ret < 0)
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001915 goto err_slot_name;
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001916 }
1917
Denis Karpov70a33412009-09-22 16:44:59 -07001918 omap_hsmmc_debugfs(mmc);
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301919 pm_runtime_mark_last_busy(host->dev);
1920 pm_runtime_put_autosuspend(host->dev);
Denis Karpovd900f712009-09-22 16:44:38 -07001921
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001922 return 0;
1923
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001924err_slot_name:
1925 mmc_remove_host(mmc);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001926 free_irq(mmc_slot(host).card_detect_irq, host);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001927err_irq_cd:
1928 if (host->use_reg)
1929 omap_hsmmc_reg_put(host);
1930err_reg:
1931 if (host->pdata->cleanup)
1932 host->pdata->cleanup(&pdev->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001933err_irq_cd_init:
1934 free_irq(host->irq, host);
1935err_irq:
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301936 pm_runtime_mark_last_busy(host->dev);
1937 pm_runtime_put_autosuspend(host->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001938 clk_put(host->fclk);
Adrian Hunter2bec0892009-09-22 16:45:02 -07001939 if (host->got_dbclk) {
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001940 clk_disable(host->dbclk);
1941 clk_put(host->dbclk);
1942 }
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001943err1:
1944 iounmap(host->base);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001945 platform_set_drvdata(pdev, NULL);
1946 mmc_free_host(mmc);
1947err_alloc:
1948 omap_hsmmc_gpio_free(pdata);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001949err:
Chris Ball984b2032011-03-22 16:34:42 -07001950 release_mem_region(res->start, resource_size(res));
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001951 return ret;
1952}
1953
Denis Karpov70a33412009-09-22 16:44:59 -07001954static int omap_hsmmc_remove(struct platform_device *pdev)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001955{
Denis Karpov70a33412009-09-22 16:44:59 -07001956 struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001957 struct resource *res;
1958
1959 if (host) {
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301960 pm_runtime_get_sync(host->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001961 mmc_remove_host(host->mmc);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001962 if (host->use_reg)
1963 omap_hsmmc_reg_put(host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001964 if (host->pdata->cleanup)
1965 host->pdata->cleanup(&pdev->dev);
1966 free_irq(host->irq, host);
1967 if (mmc_slot(host).card_detect_irq)
1968 free_irq(mmc_slot(host).card_detect_irq, host);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001969
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05301970 pm_runtime_put_sync(host->dev);
1971 pm_runtime_disable(host->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001972 clk_put(host->fclk);
Adrian Hunter2bec0892009-09-22 16:45:02 -07001973 if (host->got_dbclk) {
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001974 clk_disable(host->dbclk);
1975 clk_put(host->dbclk);
1976 }
1977
1978 mmc_free_host(host->mmc);
1979 iounmap(host->base);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -08001980 omap_hsmmc_gpio_free(pdev->dev.platform_data);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001981 }
1982
1983 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1984 if (res)
Chris Ball984b2032011-03-22 16:34:42 -07001985 release_mem_region(res->start, resource_size(res));
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001986 platform_set_drvdata(pdev, NULL);
1987
1988 return 0;
1989}
1990
1991#ifdef CONFIG_PM
Kevin Hilmana791daa2010-05-26 14:42:07 -07001992static int omap_hsmmc_suspend(struct device *dev)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001993{
1994 int ret = 0;
Kevin Hilmana791daa2010-05-26 14:42:07 -07001995 struct platform_device *pdev = to_platform_device(dev);
Denis Karpov70a33412009-09-22 16:44:59 -07001996 struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01001997
1998 if (host && host->suspended)
1999 return 0;
2000
2001 if (host) {
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05302002 pm_runtime_get_sync(host->dev);
Adrian Huntera6b22402009-09-22 16:44:45 -07002003 host->suspended = 1;
2004 if (host->pdata->suspend) {
2005 ret = host->pdata->suspend(&pdev->dev,
2006 host->slot_id);
2007 if (ret) {
2008 dev_dbg(mmc_dev(host->mmc),
2009 "Unable to handle MMC board"
2010 " level suspend\n");
2011 host->suspended = 0;
2012 return ret;
2013 }
2014 }
Matt Fleming1a13f8f2010-05-26 14:42:08 -07002015 ret = mmc_suspend_host(host->mmc);
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05302016
Eliad Peller31f9d462011-11-22 16:02:17 +02002017 if (ret) {
Adrian Huntera6b22402009-09-22 16:44:45 -07002018 host->suspended = 0;
2019 if (host->pdata->resume) {
2020 ret = host->pdata->resume(&pdev->dev,
2021 host->slot_id);
2022 if (ret)
2023 dev_dbg(mmc_dev(host->mmc),
2024 "Unmask interrupt failed\n");
2025 }
Eliad Peller31f9d462011-11-22 16:02:17 +02002026 goto err;
Adrian Huntera6b22402009-09-22 16:44:45 -07002027 }
Eliad Peller31f9d462011-11-22 16:02:17 +02002028
2029 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) {
2030 omap_hsmmc_disable_irq(host);
2031 OMAP_HSMMC_WRITE(host->base, HCTL,
2032 OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
2033 }
2034 if (host->got_dbclk)
2035 clk_disable(host->dbclk);
2036
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002037 }
Eliad Peller31f9d462011-11-22 16:02:17 +02002038err:
2039 pm_runtime_put_sync(host->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002040 return ret;
2041}
2042
2043/* Routine to resume the MMC device */
Kevin Hilmana791daa2010-05-26 14:42:07 -07002044static int omap_hsmmc_resume(struct device *dev)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002045{
2046 int ret = 0;
Kevin Hilmana791daa2010-05-26 14:42:07 -07002047 struct platform_device *pdev = to_platform_device(dev);
Denis Karpov70a33412009-09-22 16:44:59 -07002048 struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002049
2050 if (host && !host->suspended)
2051 return 0;
2052
2053 if (host) {
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05302054 pm_runtime_get_sync(host->dev);
Denis Karpov11dd62a2009-09-22 16:44:43 -07002055
Adrian Hunter2bec0892009-09-22 16:45:02 -07002056 if (host->got_dbclk)
2057 clk_enable(host->dbclk);
2058
Eliad Peller31f9d462011-11-22 16:02:17 +02002059 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER))
2060 omap_hsmmc_conf_bus_power(host);
Kim Kyuwon1b331e62009-02-20 13:10:08 +01002061
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002062 if (host->pdata->resume) {
2063 ret = host->pdata->resume(&pdev->dev, host->slot_id);
2064 if (ret)
2065 dev_dbg(mmc_dev(host->mmc),
2066 "Unmask interrupt failed\n");
2067 }
2068
Adrian Hunterb62f6222009-09-22 16:45:01 -07002069 omap_hsmmc_protect_card(host);
2070
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002071 /* Notify the core to resume the host */
2072 ret = mmc_resume_host(host->mmc);
2073 if (ret == 0)
2074 host->suspended = 0;
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05302075
2076 pm_runtime_mark_last_busy(host->dev);
2077 pm_runtime_put_autosuspend(host->dev);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002078 }
2079
2080 return ret;
2081
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002082}
2083
2084#else
Denis Karpov70a33412009-09-22 16:44:59 -07002085#define omap_hsmmc_suspend NULL
2086#define omap_hsmmc_resume NULL
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002087#endif
2088
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05302089static int omap_hsmmc_runtime_suspend(struct device *dev)
2090{
2091 struct omap_hsmmc_host *host;
2092
2093 host = platform_get_drvdata(to_platform_device(dev));
2094 omap_hsmmc_context_save(host);
2095 dev_dbg(mmc_dev(host->mmc), "disabled\n");
2096
2097 return 0;
2098}
2099
2100static int omap_hsmmc_runtime_resume(struct device *dev)
2101{
2102 struct omap_hsmmc_host *host;
2103
2104 host = platform_get_drvdata(to_platform_device(dev));
2105 omap_hsmmc_context_restore(host);
2106 dev_dbg(mmc_dev(host->mmc), "enabled\n");
2107
2108 return 0;
2109}
2110
Kevin Hilmana791daa2010-05-26 14:42:07 -07002111static struct dev_pm_ops omap_hsmmc_dev_pm_ops = {
Denis Karpov70a33412009-09-22 16:44:59 -07002112 .suspend = omap_hsmmc_suspend,
2113 .resume = omap_hsmmc_resume,
Balaji T Kfa4aa2d2011-07-01 22:09:35 +05302114 .runtime_suspend = omap_hsmmc_runtime_suspend,
2115 .runtime_resume = omap_hsmmc_runtime_resume,
Kevin Hilmana791daa2010-05-26 14:42:07 -07002116};
2117
2118static struct platform_driver omap_hsmmc_driver = {
2119 .remove = omap_hsmmc_remove,
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002120 .driver = {
2121 .name = DRIVER_NAME,
2122 .owner = THIS_MODULE,
Kevin Hilmana791daa2010-05-26 14:42:07 -07002123 .pm = &omap_hsmmc_dev_pm_ops,
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002124 },
2125};
2126
Denis Karpov70a33412009-09-22 16:44:59 -07002127static int __init omap_hsmmc_init(void)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002128{
2129 /* Register the MMC driver */
Roger Quadros87532982009-10-26 16:49:38 -07002130 return platform_driver_probe(&omap_hsmmc_driver, omap_hsmmc_probe);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002131}
2132
Denis Karpov70a33412009-09-22 16:44:59 -07002133static void __exit omap_hsmmc_cleanup(void)
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002134{
2135 /* Unregister MMC driver */
Denis Karpov70a33412009-09-22 16:44:59 -07002136 platform_driver_unregister(&omap_hsmmc_driver);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002137}
2138
Denis Karpov70a33412009-09-22 16:44:59 -07002139module_init(omap_hsmmc_init);
2140module_exit(omap_hsmmc_cleanup);
Madhusudhan Chikkaturea45c6cb2009-01-23 01:05:23 +01002141
2142MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
2143MODULE_LICENSE("GPL");
2144MODULE_ALIAS("platform:" DRIVER_NAME);
2145MODULE_AUTHOR("Texas Instruments Inc");