]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/mmc/host/omap_hsmmc.c
Merge branch 'omap-fixes'
[linux-2.6-omap-h63xx.git] / drivers / mmc / host / omap_hsmmc.c
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>
20 #include <linux/interrupt.h>
21 #include <linux/delay.h>
22 #include <linux/dma-mapping.h>
23 #include <linux/platform_device.h>
24 #include <linux/workqueue.h>
25 #include <linux/timer.h>
26 #include <linux/clk.h>
27 #include <linux/mmc/host.h>
28 #include <linux/io.h>
29 #include <linux/semaphore.h>
30 #include <mach/dma.h>
31 #include <mach/hardware.h>
32 #include <mach/board.h>
33 #include <mach/mmc.h>
34 #include <mach/cpu.h>
35
36 /* OMAP HSMMC Host Controller Registers */
37 #define OMAP_HSMMC_SYSCONFIG    0x0010
38 #define OMAP_HSMMC_CON          0x002C
39 #define OMAP_HSMMC_BLK          0x0104
40 #define OMAP_HSMMC_ARG          0x0108
41 #define OMAP_HSMMC_CMD          0x010C
42 #define OMAP_HSMMC_RSP10        0x0110
43 #define OMAP_HSMMC_RSP32        0x0114
44 #define OMAP_HSMMC_RSP54        0x0118
45 #define OMAP_HSMMC_RSP76        0x011C
46 #define OMAP_HSMMC_DATA         0x0120
47 #define OMAP_HSMMC_HCTL         0x0128
48 #define OMAP_HSMMC_SYSCTL       0x012C
49 #define OMAP_HSMMC_STAT         0x0130
50 #define OMAP_HSMMC_IE           0x0134
51 #define OMAP_HSMMC_ISE          0x0138
52 #define OMAP_HSMMC_CAPA         0x0140
53
54 #define VS18                    (1 << 26)
55 #define VS30                    (1 << 25)
56 #define SDVS18                  (0x5 << 9)
57 #define SDVS30                  (0x6 << 9)
58 #define SDVS33                  (0x7 << 9)
59 #define SDVS_MASK               0x00000E00
60 #define SDVSCLR                 0xFFFFF1FF
61 #define SDVSDET                 0x00000400
62 #define AUTOIDLE                0x1
63 #define SDBP                    (1 << 8)
64 #define DTO                     0xe
65 #define ICE                     0x1
66 #define ICS                     0x2
67 #define CEN                     (1 << 2)
68 #define CLKD_MASK               0x0000FFC0
69 #define CLKD_SHIFT              6
70 #define DTO_MASK                0x000F0000
71 #define DTO_SHIFT               16
72 #define INT_EN_MASK             0x307F0033
73 #define INIT_STREAM             (1 << 1)
74 #define DP_SELECT               (1 << 21)
75 #define DDIR                    (1 << 4)
76 #define DMA_EN                  0x1
77 #define MSBS                    (1 << 5)
78 #define BCE                     (1 << 1)
79 #define FOUR_BIT                (1 << 1)
80 #define DW8                     (1 << 5)
81 #define CC                      0x1
82 #define TC                      0x02
83 #define OD                      0x1
84 #define ERR                     (1 << 15)
85 #define CMD_TIMEOUT             (1 << 16)
86 #define DATA_TIMEOUT            (1 << 20)
87 #define CMD_CRC                 (1 << 17)
88 #define DATA_CRC                (1 << 21)
89 #define CARD_ERR                (1 << 28)
90 #define STAT_CLEAR              0xFFFFFFFF
91 #define INIT_STREAM_CMD         0x00000000
92 #define DUAL_VOLT_OCR_BIT       7
93 #define SRC                     (1 << 25)
94 #define SRD                     (1 << 26)
95
96 /*
97  * FIXME: Most likely all the data using these _DEVID defines should come
98  * from the platform_data, or implemented in controller and slot specific
99  * functions.
100  */
101 #define OMAP_MMC1_DEVID         0
102 #define OMAP_MMC2_DEVID         1
103 #define OMAP_MMC3_DEVID         2
104
105 #define MMC_TIMEOUT_MS          20
106 #define OMAP_MMC_MASTER_CLOCK   96000000
107 #define DRIVER_NAME             "mmci-omap-hs"
108
109 /*
110  * One controller can have multiple slots, like on some omap boards using
111  * omap.c controller driver. Luckily this is not currently done on any known
112  * omap_hsmmc.c device.
113  */
114 #define mmc_slot(host)          (host->pdata->slots[host->slot_id])
115
116 /*
117  * MMC Host controller read/write API's
118  */
119 #define OMAP_HSMMC_READ(base, reg)      \
120         __raw_readl((base) + OMAP_HSMMC_##reg)
121
122 #define OMAP_HSMMC_WRITE(base, reg, val) \
123         __raw_writel((val), (base) + OMAP_HSMMC_##reg)
124
125 struct mmc_omap_host {
126         struct  device          *dev;
127         struct  mmc_host        *mmc;
128         struct  mmc_request     *mrq;
129         struct  mmc_command     *cmd;
130         struct  mmc_data        *data;
131         struct  clk             *fclk;
132         struct  clk             *iclk;
133         struct  clk             *dbclk;
134         struct  semaphore       sem;
135         struct  work_struct     mmc_carddetect_work;
136         void    __iomem         *base;
137         resource_size_t         mapbase;
138         unsigned int            id;
139         unsigned int            dma_len;
140         unsigned int            dma_sg_idx;
141         unsigned char           bus_mode;
142         u32                     *buffer;
143         u32                     bytesleft;
144         int                     suspended;
145         int                     irq;
146         int                     carddetect;
147         int                     use_dma, dma_ch;
148         int                     dma_line_tx, dma_line_rx;
149         int                     slot_id;
150         int                     dbclk_enabled;
151         int                     response_busy;
152         struct  omap_mmc_platform_data  *pdata;
153 };
154
155 /*
156  * Stop clock to the card
157  */
158 static void omap_mmc_stop_clock(struct mmc_omap_host *host)
159 {
160         OMAP_HSMMC_WRITE(host->base, SYSCTL,
161                 OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
162         if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0)
163                 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n");
164 }
165
166 /*
167  * Send init stream sequence to card
168  * before sending IDLE command
169  */
170 static void send_init_stream(struct mmc_omap_host *host)
171 {
172         int reg = 0;
173         unsigned long timeout;
174
175         disable_irq(host->irq);
176         OMAP_HSMMC_WRITE(host->base, CON,
177                 OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM);
178         OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD);
179
180         timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
181         while ((reg != CC) && time_before(jiffies, timeout))
182                 reg = OMAP_HSMMC_READ(host->base, STAT) & CC;
183
184         OMAP_HSMMC_WRITE(host->base, CON,
185                 OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM);
186         enable_irq(host->irq);
187 }
188
189 static inline
190 int mmc_omap_cover_is_closed(struct mmc_omap_host *host)
191 {
192         int r = 1;
193
194         if (host->pdata->slots[host->slot_id].get_cover_state)
195                 r = host->pdata->slots[host->slot_id].get_cover_state(host->dev,
196                         host->slot_id);
197         return r;
198 }
199
200 static ssize_t
201 mmc_omap_show_cover_switch(struct device *dev, struct device_attribute *attr,
202                            char *buf)
203 {
204         struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
205         struct mmc_omap_host *host = mmc_priv(mmc);
206
207         return sprintf(buf, "%s\n", mmc_omap_cover_is_closed(host) ? "closed" :
208                        "open");
209 }
210
211 static DEVICE_ATTR(cover_switch, S_IRUGO, mmc_omap_show_cover_switch, NULL);
212
213 static ssize_t
214 mmc_omap_show_slot_name(struct device *dev, struct device_attribute *attr,
215                         char *buf)
216 {
217         struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
218         struct mmc_omap_host *host = mmc_priv(mmc);
219         struct omap_mmc_slot_data slot = host->pdata->slots[host->slot_id];
220
221         return sprintf(buf, "%s\n", slot.name);
222 }
223
224 static DEVICE_ATTR(slot_name, S_IRUGO, mmc_omap_show_slot_name, NULL);
225
226 /*
227  * Configure the response type and send the cmd.
228  */
229 static void
230 mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd,
231         struct mmc_data *data)
232 {
233         int cmdreg = 0, resptype = 0, cmdtype = 0;
234
235         dev_dbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n",
236                 mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
237         host->cmd = cmd;
238
239         /*
240          * Clear status bits and enable interrupts
241          */
242         OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
243         OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
244         OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
245
246         host->response_busy = 0;
247         if (cmd->flags & MMC_RSP_PRESENT) {
248                 if (cmd->flags & MMC_RSP_136)
249                         resptype = 1;
250                 else if (cmd->flags & MMC_RSP_BUSY) {
251                         resptype = 3;
252                         host->response_busy = 1;
253                 } else
254                         resptype = 2;
255         }
256
257         /*
258          * Unlike OMAP1 controller, the cmdtype does not seem to be based on
259          * ac, bc, adtc, bcr. Only commands ending an open ended transfer need
260          * a val of 0x3, rest 0x0.
261          */
262         if (cmd == host->mrq->stop)
263                 cmdtype = 0x3;
264
265         cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
266
267         if (data) {
268                 cmdreg |= DP_SELECT | MSBS | BCE;
269                 if (data->flags & MMC_DATA_READ)
270                         cmdreg |= DDIR;
271                 else
272                         cmdreg &= ~(DDIR);
273         }
274
275         if (host->use_dma)
276                 cmdreg |= DMA_EN;
277
278         OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg);
279         OMAP_HSMMC_WRITE(host->base, CMD, cmdreg);
280 }
281
282 static int
283 mmc_omap_get_dma_dir(struct mmc_omap_host *host, struct mmc_data *data)
284 {
285         if (data->flags & MMC_DATA_WRITE)
286                 return DMA_TO_DEVICE;
287         else
288                 return DMA_FROM_DEVICE;
289 }
290
291 /*
292  * Notify the transfer complete to MMC core
293  */
294 static void
295 mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data)
296 {
297         if (!data) {
298                 struct mmc_request *mrq = host->mrq;
299
300                 host->mrq = NULL;
301                 mmc_omap_fclk_lazy_disable(host);
302                 mmc_request_done(host->mmc, mrq);
303                 return;
304         }
305
306         host->data = NULL;
307
308         if (host->use_dma && host->dma_ch != -1)
309                 dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->dma_len,
310                         mmc_omap_get_dma_dir(host, data));
311
312         if (!data->error)
313                 data->bytes_xfered += data->blocks * (data->blksz);
314         else
315                 data->bytes_xfered = 0;
316
317         if (!data->stop) {
318                 host->mrq = NULL;
319                 mmc_request_done(host->mmc, data->mrq);
320                 return;
321         }
322         mmc_omap_start_command(host, data->stop, NULL);
323 }
324
325 /*
326  * Notify the core about command completion
327  */
328 static void
329 mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd)
330 {
331         host->cmd = NULL;
332
333         if (cmd->flags & MMC_RSP_PRESENT) {
334                 if (cmd->flags & MMC_RSP_136) {
335                         /* response type 2 */
336                         cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10);
337                         cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32);
338                         cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54);
339                         cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76);
340                 } else {
341                         /* response types 1, 1b, 3, 4, 5, 6 */
342                         cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10);
343                 }
344         }
345         if ((host->data == NULL && !host->response_busy) || cmd->error) {
346                 host->mrq = NULL;
347                 mmc_request_done(host->mmc, cmd->mrq);
348         }
349 }
350
351 /*
352  * DMA clean up for command errors
353  */
354 static void mmc_dma_cleanup(struct mmc_omap_host *host, int errno)
355 {
356         host->data->error = errno;
357
358         if (host->use_dma && host->dma_ch != -1) {
359                 dma_unmap_sg(mmc_dev(host->mmc), host->data->sg, host->dma_len,
360                         mmc_omap_get_dma_dir(host, host->data));
361                 omap_free_dma(host->dma_ch);
362                 host->dma_ch = -1;
363                 up(&host->sem);
364         }
365         host->data = NULL;
366 }
367
368 /*
369  * Readable error output
370  */
371 #ifdef CONFIG_MMC_DEBUG
372 static void mmc_omap_report_irq(struct mmc_omap_host *host, u32 status)
373 {
374         /* --- means reserved bit without definition at documentation */
375         static const char *mmc_omap_status_bits[] = {
376                 "CC", "TC", "BGE", "---", "BWR", "BRR", "---", "---", "CIRQ",
377                 "OBI", "---", "---", "---", "---", "---", "ERRI", "CTO", "CCRC",
378                 "CEB", "CIE", "DTO", "DCRC", "DEB", "---", "ACE", "---",
379                 "---", "---", "---", "CERR", "CERR", "BADA", "---", "---", "---"
380         };
381         char res[256];
382         char *buf = res;
383         int len, i;
384
385         len = sprintf(buf, "MMC IRQ 0x%x :", status);
386         buf += len;
387
388         for (i = 0; i < ARRAY_SIZE(mmc_omap_status_bits); i++)
389                 if (status & (1 << i)) {
390                         len = sprintf(buf, " %s", mmc_omap_status_bits[i]);
391                         buf += len;
392                 }
393
394         dev_dbg(mmc_dev(host->mmc), "%s\n", res);
395 }
396 #endif  /* CONFIG_MMC_DEBUG */
397
398 /*
399  * MMC controller internal state machines reset
400  *
401  * Used to reset command or data internal state machines, using respectively
402  *  SRC or SRD bit of SYSCTL register
403  * Can be called from interrupt context
404  */
405 static inline void mmc_omap_reset_controller_fsm(struct mmc_omap_host *host,
406                 unsigned long bit)
407 {
408         unsigned long i = 0;
409         unsigned long limit = (loops_per_jiffy *
410                                 msecs_to_jiffies(MMC_TIMEOUT_MS));
411
412         OMAP_HSMMC_WRITE(host->base, SYSCTL,
413                          OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
414
415         while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
416                 (i++ < limit))
417                 cpu_relax();
418
419         if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
420                 dev_err(mmc_dev(host->mmc),
421                         "Timeout waiting on controller reset in %s\n",
422                         __func__);
423 }
424
425 /*
426  * MMC controller IRQ handler
427  */
428 static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
429 {
430         struct mmc_omap_host *host = dev_id;
431         struct mmc_data *data;
432         int end_cmd = 0, end_trans = 0, status;
433
434         if (host->mrq == NULL) {
435                 OMAP_HSMMC_WRITE(host->base, STAT,
436                         OMAP_HSMMC_READ(host->base, STAT));
437                 /* Flush posted write */
438                 OMAP_HSMMC_READ(host->base, STAT);
439                 return IRQ_HANDLED;
440         }
441
442         data = host->data;
443         status = OMAP_HSMMC_READ(host->base, STAT);
444         dev_dbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status);
445
446         if (status & ERR) {
447 #ifdef CONFIG_MMC_DEBUG
448                 mmc_omap_report_irq(host, status);
449 #endif
450                 if ((status & CMD_TIMEOUT) ||
451                         (status & CMD_CRC)) {
452                         if (host->cmd) {
453                                 if (status & CMD_TIMEOUT) {
454                                         mmc_omap_reset_controller_fsm(host, SRC);
455                                         host->cmd->error = -ETIMEDOUT;
456                                 } else {
457                                         host->cmd->error = -EILSEQ;
458                                 }
459                                 end_cmd = 1;
460                         }
461                         if (host->data || host->response_busy) {
462                                 if (host->data)
463                                         mmc_dma_cleanup(host, -ETIMEDOUT);
464                                 host->response_busy = 0;
465                                 mmc_omap_reset_controller_fsm(host, SRD);
466                         }
467                 }
468                 if ((status & DATA_TIMEOUT) ||
469                         (status & DATA_CRC)) {
470                         if (host->data || host->response_busy) {
471                                 int err = (status & DATA_TIMEOUT) ?
472                                                 -ETIMEDOUT : -EILSEQ;
473
474                                 if (host->data)
475                                         mmc_dma_cleanup(host, err);
476                                 else
477                                         host->mrq->cmd->error = err;
478                                 host->response_busy = 0;
479                                 mmc_omap_reset_controller_fsm(host, SRD);
480                                 end_trans = 1;
481                         }
482                 }
483                 if (status & CARD_ERR) {
484                         dev_dbg(mmc_dev(host->mmc),
485                                 "Ignoring card err CMD%d\n", host->cmd->opcode);
486                         if (host->cmd)
487                                 end_cmd = 1;
488                         if (host->data)
489                                 end_trans = 1;
490                 }
491         }
492
493         OMAP_HSMMC_WRITE(host->base, STAT, status);
494         /* Flush posted write */
495         OMAP_HSMMC_READ(host->base, STAT);
496
497         if (end_cmd || (status & CC))
498                 mmc_omap_cmd_done(host, host->cmd);
499         if (end_trans || (status & TC))
500                 mmc_omap_xfer_done(host, data);
501
502         return IRQ_HANDLED;
503 }
504
505 static void set_sd_bus_power(struct mmc_omap_host *host)
506 {
507         unsigned long i;
508
509         OMAP_HSMMC_WRITE(host->base, HCTL,
510                          OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
511         for (i = 0; i < loops_per_jiffy; i++) {
512                 if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP)
513                         break;
514                 cpu_relax();
515         }
516 }
517
518 /*
519  * Switch MMC interface voltage ... only relevant for MMC1.
520  *
521  * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
522  * The MMC2 transceiver controls are used instead of DAT4..DAT7.
523  * Some chips, like eMMC ones, use internal transceivers.
524  */
525 static int omap_mmc_switch_opcond(struct mmc_omap_host *host, int vdd)
526 {
527         u32 reg_val = 0;
528         int ret;
529
530         /* Disable the clocks */
531         clk_disable(host->fclk);
532         clk_disable(host->iclk);
533         clk_disable(host->dbclk);
534
535         /* Turn the power off */
536         ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
537         if (ret != 0)
538                 goto err;
539
540         /* Turn the power ON with given VDD 1.8 or 3.0v */
541         ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, vdd);
542         if (ret != 0)
543                 goto err;
544
545         clk_enable(host->fclk);
546         clk_enable(host->iclk);
547         clk_enable(host->dbclk);
548
549         OMAP_HSMMC_WRITE(host->base, HCTL,
550                 OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
551         reg_val = OMAP_HSMMC_READ(host->base, HCTL);
552
553         /*
554          * If a MMC dual voltage card is detected, the set_ios fn calls
555          * this fn with VDD bit set for 1.8V. Upon card removal from the
556          * slot, omap_mmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
557          *
558          * Cope with a bit of slop in the range ... per data sheets:
559          *  - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
560          *    but recommended values are 1.71V to 1.89V
561          *  - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
562          *    but recommended values are 2.7V to 3.3V
563          *
564          * Board setup code shouldn't permit anything very out-of-range.
565          * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
566          * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
567          */
568         if ((1 << vdd) <= MMC_VDD_23_24)
569                 reg_val |= SDVS18;
570         else
571                 reg_val |= SDVS30;
572
573         OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
574         set_sd_bus_power(host);
575
576         return 0;
577 err:
578         dev_dbg(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
579         return ret;
580 }
581
582 /*
583  * Work Item to notify the core about card insertion/removal
584  */
585 static void mmc_omap_detect(struct work_struct *work)
586 {
587         struct mmc_omap_host *host = container_of(work, struct mmc_omap_host,
588                                                 mmc_carddetect_work);
589         struct omap_mmc_slot_data *slot = &mmc_slot(host);
590
591         if (mmc_slot(host).card_detect)
592                 host->carddetect = slot->card_detect(slot->card_detect_irq);
593         else
594                 host->carddetect = -ENOSYS;
595
596         sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
597         if (host->carddetect) {
598                 mmc_detect_change(host->mmc, (HZ * 200) / 1000);
599         } else {
600                 mmc_omap_reset_controller_fsm(host, SRD);
601                 mmc_detect_change(host->mmc, (HZ * 50) / 1000);
602         }
603 }
604
605 /*
606  * ISR for handling card insertion and removal
607  */
608 static irqreturn_t omap_mmc_cd_handler(int irq, void *dev_id)
609 {
610         struct mmc_omap_host *host = (struct mmc_omap_host *)dev_id;
611
612         schedule_work(&host->mmc_carddetect_work);
613
614         return IRQ_HANDLED;
615 }
616
617 static int mmc_omap_get_dma_sync_dev(struct mmc_omap_host *host,
618                                      struct mmc_data *data)
619 {
620         int sync_dev;
621
622         if (data->flags & MMC_DATA_WRITE)
623                 sync_dev = host->dma_line_tx;
624         else
625                 sync_dev = host->dma_line_rx;
626         return sync_dev;
627 }
628
629 static void mmc_omap_config_dma_params(struct mmc_omap_host *host,
630                                        struct mmc_data *data,
631                                        struct scatterlist *sgl)
632 {
633         int blksz, nblk, dma_ch;
634
635         dma_ch = host->dma_ch;
636         if (data->flags & MMC_DATA_WRITE) {
637                 omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
638                         (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
639                 omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
640                         sg_dma_address(sgl), 0, 0);
641         } else {
642                 omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
643                                         (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
644                 omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
645                         sg_dma_address(sgl), 0, 0);
646         }
647
648         blksz = host->data->blksz;
649         nblk = sg_dma_len(sgl) / blksz;
650
651         omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32,
652                         blksz / 4, nblk, OMAP_DMA_SYNC_FRAME,
653                         mmc_omap_get_dma_sync_dev(host, data),
654                         !(data->flags & MMC_DATA_WRITE));
655
656         omap_start_dma(dma_ch);
657 }
658
659 /*
660  * DMA call back function
661  */
662 static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data)
663 {
664         struct mmc_omap_host *host = data;
665
666         if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ)
667                 dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n");
668
669         if (host->dma_ch < 0)
670                 return;
671
672         host->dma_sg_idx++;
673         if (host->dma_sg_idx < host->dma_len) {
674                 /* Fire up the next transfer. */
675                 mmc_omap_config_dma_params(host, host->data,
676                                            host->data->sg + host->dma_sg_idx);
677                 return;
678         }
679
680         omap_free_dma(host->dma_ch);
681         host->dma_ch = -1;
682         /*
683          * DMA Callback: run in interrupt context.
684          * mutex_unlock will through a kernel warning if used.
685          */
686         up(&host->sem);
687 }
688
689 /*
690  * Routine to configure and start DMA for the MMC card
691  */
692 static int
693 mmc_omap_start_dma_transfer(struct mmc_omap_host *host, struct mmc_request *req)
694 {
695         int dma_ch = 0, ret = 0, err = 1, i;
696         struct mmc_data *data = req->data;
697
698         /* Sanity check: all the SG entries must be aligned by block size. */
699         for (i = 0; i < host->dma_len; i++) {
700                 struct scatterlist *sgl;
701
702                 sgl = data->sg + i;
703                 if (sgl->length % data->blksz)
704                         return -EINVAL;
705         }
706         if ((data->blksz % 4) != 0)
707                 /* REVISIT: The MMC buffer increments only when MSB is written.
708                  * Return error for blksz which is non multiple of four.
709                  */
710                 return -EINVAL;
711
712         /*
713          * If for some reason the DMA transfer is still active,
714          * we wait for timeout period and free the dma
715          */
716         if (host->dma_ch != -1) {
717                 set_current_state(TASK_UNINTERRUPTIBLE);
718                 schedule_timeout(100);
719                 if (down_trylock(&host->sem)) {
720                         omap_free_dma(host->dma_ch);
721                         host->dma_ch = -1;
722                         up(&host->sem);
723                         return err;
724                 }
725         } else {
726                 if (down_trylock(&host->sem))
727                         return err;
728         }
729
730         ret = omap_request_dma(mmc_omap_get_dma_sync_dev(host, data), "MMC/SD",
731                                mmc_omap_dma_cb,host, &dma_ch);
732         if (ret != 0) {
733                 dev_err(mmc_dev(host->mmc),
734                         "%s: omap_request_dma() failed with %d\n",
735                         mmc_hostname(host->mmc), ret);
736                 return ret;
737         }
738
739         host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
740                         data->sg_len, mmc_omap_get_dma_dir(host, data));
741         host->dma_ch = dma_ch;
742         host->dma_sg_idx = 0;
743
744         mmc_omap_config_dma_params(host, data, data->sg);
745
746         return 0;
747 }
748
749 static void set_data_timeout(struct mmc_omap_host *host,
750                              struct mmc_request *req)
751 {
752         unsigned int timeout, cycle_ns;
753         uint32_t reg, clkd, dto = 0;
754
755         reg = OMAP_HSMMC_READ(host->base, SYSCTL);
756         clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
757         if (clkd == 0)
758                 clkd = 1;
759
760         cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
761         timeout = req->data->timeout_ns / cycle_ns;
762         timeout += req->data->timeout_clks;
763         if (timeout) {
764                 while ((timeout & 0x80000000) == 0) {
765                         dto += 1;
766                         timeout <<= 1;
767                 }
768                 dto = 31 - dto;
769                 timeout <<= 1;
770                 if (timeout && dto)
771                         dto += 1;
772                 if (dto >= 13)
773                         dto -= 13;
774                 else
775                         dto = 0;
776                 if (dto > 14)
777                         dto = 14;
778         }
779
780         reg &= ~DTO_MASK;
781         reg |= dto << DTO_SHIFT;
782         OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
783 }
784
785 /*
786  * Configure block length for MMC/SD cards and initiate the transfer.
787  */
788 static int
789 mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
790 {
791         int ret;
792         host->data = req->data;
793
794         if (req->data == NULL) {
795                 OMAP_HSMMC_WRITE(host->base, BLK, 0);
796                 return 0;
797         }
798
799         OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
800                                         | (req->data->blocks << 16));
801         set_data_timeout(host, req);
802
803         if (host->use_dma) {
804                 ret = mmc_omap_start_dma_transfer(host, req);
805                 if (ret != 0) {
806                         dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n");
807                         return ret;
808                 }
809         }
810         return 0;
811 }
812
813 /*
814  * Request function. for read/write operation
815  */
816 static void omap_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
817 {
818         struct mmc_omap_host *host = mmc_priv(mmc);
819
820         WARN_ON(host->mrq != NULL);
821         host->mrq = req;
822         mmc_omap_prepare_data(host, req);
823         mmc_omap_start_command(host, req->cmd, req->data);
824 }
825
826
827 /* Routine to configure clock values. Exposed API to core */
828 static void omap_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
829 {
830         struct mmc_omap_host *host = mmc_priv(mmc);
831         u16 dsor = 0;
832         unsigned long regval;
833         unsigned long timeout;
834         u32 con;
835
836         switch (ios->power_mode) {
837         case MMC_POWER_OFF:
838                 mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
839                 break;
840         case MMC_POWER_UP:
841                 mmc_slot(host).set_power(host->dev, host->slot_id, 1, ios->vdd);
842                 break;
843         }
844
845         con = OMAP_HSMMC_READ(host->base, CON);
846         switch (mmc->ios.bus_width) {
847         case MMC_BUS_WIDTH_8:
848                 OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
849                 break;
850         case MMC_BUS_WIDTH_4:
851                 OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
852                 OMAP_HSMMC_WRITE(host->base, HCTL,
853                         OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
854                 break;
855         case MMC_BUS_WIDTH_1:
856                 OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
857                 OMAP_HSMMC_WRITE(host->base, HCTL,
858                         OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
859                 break;
860         }
861
862         if (host->id == OMAP_MMC1_DEVID) {
863                 /* Only MMC1 can interface at 3V without some flavor
864                  * of external transceiver; but they all handle 1.8V.
865                  */
866                 if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
867                         (ios->vdd == DUAL_VOLT_OCR_BIT)) {
868                                 /*
869                                  * The mmc_select_voltage fn of the core does
870                                  * not seem to set the power_mode to
871                                  * MMC_POWER_UP upon recalculating the voltage.
872                                  * vdd 1.8v.
873                                  */
874                                 if (omap_mmc_switch_opcond(host, ios->vdd) != 0)
875                                         dev_dbg(mmc_dev(host->mmc),
876                                                 "Switch operation failed\n");
877                 }
878         }
879
880         if (ios->clock) {
881                 dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
882                 if (dsor < 1)
883                         dsor = 1;
884
885                 if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
886                         dsor++;
887
888                 if (dsor > 250)
889                         dsor = 250;
890         }
891         omap_mmc_stop_clock(host);
892         regval = OMAP_HSMMC_READ(host->base, SYSCTL);
893         regval = regval & ~(CLKD_MASK);
894         regval = regval | (dsor << 6) | (DTO << 16);
895         OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
896         OMAP_HSMMC_WRITE(host->base, SYSCTL,
897                 OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
898
899         /* Wait till the ICS bit is set */
900         timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
901         while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != 0x2
902                 && time_before(jiffies, timeout))
903                 msleep(1);
904
905         OMAP_HSMMC_WRITE(host->base, SYSCTL,
906                 OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
907
908         if (ios->power_mode == MMC_POWER_ON)
909                 send_init_stream(host);
910
911         if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
912                 OMAP_HSMMC_WRITE(host->base, CON,
913                                 OMAP_HSMMC_READ(host->base, CON) | OD);
914 }
915
916 static int omap_hsmmc_get_cd(struct mmc_host *mmc)
917 {
918         struct mmc_omap_host *host = mmc_priv(mmc);
919         struct omap_mmc_platform_data *pdata = host->pdata;
920
921         if (!pdata->slots[0].card_detect)
922                 return -ENOSYS;
923         return pdata->slots[0].card_detect(pdata->slots[0].card_detect_irq);
924 }
925
926 static int omap_hsmmc_get_ro(struct mmc_host *mmc)
927 {
928         struct mmc_omap_host *host = mmc_priv(mmc);
929         struct omap_mmc_platform_data *pdata = host->pdata;
930
931         if (!pdata->slots[0].get_ro)
932                 return -ENOSYS;
933         return pdata->slots[0].get_ro(host->dev, 0);
934 }
935
936 static void omap_hsmmc_init(struct mmc_omap_host *host)
937 {
938         u32 hctl, capa, value;
939
940         /* Only MMC1 supports 3.0V */
941         if (host->id == OMAP_MMC1_DEVID) {
942                 hctl = SDVS30;
943                 capa = VS30 | VS18;
944         } else {
945                 hctl = SDVS18;
946                 capa = VS18;
947         }
948
949         value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
950         OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
951
952         value = OMAP_HSMMC_READ(host->base, CAPA);
953         OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
954
955         /* Set the controller to AUTO IDLE mode */
956         value = OMAP_HSMMC_READ(host->base, SYSCONFIG);
957         OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE);
958
959         /* Set SD bus power bit */
960         set_sd_bus_power(host);
961 }
962
963 static struct mmc_host_ops mmc_omap_ops = {
964         .request = omap_mmc_request,
965         .set_ios = omap_mmc_set_ios,
966         .get_cd = omap_hsmmc_get_cd,
967         .get_ro = omap_hsmmc_get_ro,
968         /* NYET -- enable_sdio_irq */
969 };
970
971 static int __init omap_mmc_probe(struct platform_device *pdev)
972 {
973         struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
974         struct mmc_host *mmc;
975         struct mmc_omap_host *host = NULL;
976         struct resource *res;
977         int ret = 0, irq;
978
979         if (pdata == NULL) {
980                 dev_err(&pdev->dev, "Platform Data is missing\n");
981                 return -ENXIO;
982         }
983
984         if (pdata->nr_slots == 0) {
985                 dev_err(&pdev->dev, "No Slots\n");
986                 return -ENXIO;
987         }
988
989         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
990         irq = platform_get_irq(pdev, 0);
991         if (res == NULL || irq < 0)
992                 return -ENXIO;
993
994         res = request_mem_region(res->start, res->end - res->start + 1,
995                                                         pdev->name);
996         if (res == NULL)
997                 return -EBUSY;
998
999         mmc = mmc_alloc_host(sizeof(struct mmc_omap_host), &pdev->dev);
1000         if (!mmc) {
1001                 ret = -ENOMEM;
1002                 goto err;
1003         }
1004
1005         host            = mmc_priv(mmc);
1006         host->mmc       = mmc;
1007         host->pdata     = pdata;
1008         host->dev       = &pdev->dev;
1009         host->use_dma   = 1;
1010         host->dev->dma_mask = &pdata->dma_mask;
1011         host->dma_ch    = -1;
1012         host->irq       = irq;
1013         host->id        = pdev->id;
1014         host->slot_id   = 0;
1015         host->mapbase   = res->start;
1016         host->base      = ioremap(host->mapbase, SZ_4K);
1017
1018         platform_set_drvdata(pdev, host);
1019         INIT_WORK(&host->mmc_carddetect_work, mmc_omap_detect);
1020
1021         mmc->ops        = &mmc_omap_ops;
1022         mmc->f_min      = 400000;
1023         mmc->f_max      = 52000000;
1024
1025         sema_init(&host->sem, 1);
1026
1027         host->iclk = clk_get(&pdev->dev, "ick");
1028         if (IS_ERR(host->iclk)) {
1029                 ret = PTR_ERR(host->iclk);
1030                 host->iclk = NULL;
1031                 goto err1;
1032         }
1033         host->fclk = clk_get(&pdev->dev, "fck");
1034         if (IS_ERR(host->fclk)) {
1035                 ret = PTR_ERR(host->fclk);
1036                 host->fclk = NULL;
1037                 clk_put(host->iclk);
1038                 goto err1;
1039         }
1040
1041         if (clk_enable(host->fclk) != 0) {
1042                 clk_put(host->iclk);
1043                 clk_put(host->fclk);
1044                 goto err1;
1045         }
1046
1047         if (clk_enable(host->iclk) != 0) {
1048                 clk_disable(host->fclk);
1049                 clk_put(host->iclk);
1050                 clk_put(host->fclk);
1051                 goto err1;
1052         }
1053
1054         host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
1055         /*
1056          * MMC can still work without debounce clock.
1057          */
1058         if (IS_ERR(host->dbclk))
1059                 dev_warn(mmc_dev(host->mmc), "Failed to get debounce clock\n");
1060         else
1061                 if (clk_enable(host->dbclk) != 0)
1062                         dev_dbg(mmc_dev(host->mmc), "Enabling debounce"
1063                                                         " clk failed\n");
1064                 else
1065                         host->dbclk_enabled = 1;
1066
1067         /* Since we do only SG emulation, we can have as many segs
1068          * as we want. */
1069         mmc->max_phys_segs = 1024;
1070         mmc->max_hw_segs = 1024;
1071
1072         mmc->max_blk_size = 512;       /* Block Length at max can be 1024 */
1073         mmc->max_blk_count = 0xFFFF;    /* No. of Blocks is 16 bits */
1074         mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
1075         mmc->max_seg_size = mmc->max_req_size;
1076
1077         mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
1078
1079         if (pdata->slots[host->slot_id].wires >= 8)
1080                 mmc->caps |= MMC_CAP_8_BIT_DATA;
1081         else if (pdata->slots[host->slot_id].wires >= 4)
1082                 mmc->caps |= MMC_CAP_4_BIT_DATA;
1083
1084         omap_hsmmc_init(host);
1085
1086         /* Select DMA lines */
1087         switch (host->id) {
1088         case OMAP_MMC1_DEVID:
1089                 host->dma_line_tx = OMAP24XX_DMA_MMC1_TX;
1090                 host->dma_line_rx = OMAP24XX_DMA_MMC1_RX;
1091                 break;
1092         case OMAP_MMC2_DEVID:
1093                 host->dma_line_tx = OMAP24XX_DMA_MMC2_TX;
1094                 host->dma_line_rx = OMAP24XX_DMA_MMC2_RX;
1095                 break;
1096         case OMAP_MMC3_DEVID:
1097                 host->dma_line_tx = OMAP34XX_DMA_MMC3_TX;
1098                 host->dma_line_rx = OMAP34XX_DMA_MMC3_RX;
1099                 break;
1100         default:
1101                 dev_err(mmc_dev(host->mmc), "Invalid MMC id\n");
1102                 goto err_irq;
1103         }
1104
1105         /* Request IRQ for MMC operations */
1106         ret = request_irq(host->irq, mmc_omap_irq, IRQF_DISABLED,
1107                         mmc_hostname(mmc), host);
1108         if (ret) {
1109                 dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
1110                 goto err_irq;
1111         }
1112
1113         /* initialize power supplies, gpios, etc */
1114         if (pdata->init != NULL) {
1115                 if (pdata->init(&pdev->dev) != 0) {
1116                         dev_dbg(mmc_dev(host->mmc), "late init error\n");
1117                         goto err_irq_cd_init;
1118                 }
1119         }
1120         mmc->ocr_avail = mmc_slot(host).ocr_mask;
1121
1122         /* Request IRQ for card detect */
1123         if ((mmc_slot(host).card_detect_irq)) {
1124                 ret = request_irq(mmc_slot(host).card_detect_irq,
1125                                   omap_mmc_cd_handler,
1126                                   IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
1127                                           | IRQF_DISABLED,
1128                                   mmc_hostname(mmc), host);
1129                 if (ret) {
1130                         dev_dbg(mmc_dev(host->mmc),
1131                                 "Unable to grab MMC CD IRQ\n");
1132                         goto err_irq_cd;
1133                 }
1134         }
1135
1136         OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
1137         OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
1138
1139         mmc_add_host(mmc);
1140
1141         if (host->pdata->slots[host->slot_id].name != NULL) {
1142                 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
1143                 if (ret < 0)
1144                         goto err_slot_name;
1145         }
1146         if (mmc_slot(host).card_detect_irq &&
1147             host->pdata->slots[host->slot_id].get_cover_state) {
1148                 ret = device_create_file(&mmc->class_dev,
1149                                         &dev_attr_cover_switch);
1150                 if (ret < 0)
1151                         goto err_cover_switch;
1152         }
1153
1154         return 0;
1155
1156 err_cover_switch:
1157         device_remove_file(&mmc->class_dev, &dev_attr_cover_switch);
1158 err_slot_name:
1159         mmc_remove_host(mmc);
1160 err_irq_cd:
1161         free_irq(mmc_slot(host).card_detect_irq, host);
1162 err_irq_cd_init:
1163         free_irq(host->irq, host);
1164 err_irq:
1165         clk_disable(host->fclk);
1166         clk_disable(host->iclk);
1167         clk_put(host->fclk);
1168         clk_put(host->iclk);
1169         if (host->dbclk_enabled) {
1170                 clk_disable(host->dbclk);
1171                 clk_put(host->dbclk);
1172         }
1173
1174 err1:
1175         iounmap(host->base);
1176 err:
1177         dev_dbg(mmc_dev(host->mmc), "Probe Failed\n");
1178         release_mem_region(res->start, res->end - res->start + 1);
1179         if (host)
1180                 mmc_free_host(mmc);
1181         return ret;
1182 }
1183
1184 static int omap_mmc_remove(struct platform_device *pdev)
1185 {
1186         struct mmc_omap_host *host = platform_get_drvdata(pdev);
1187         struct resource *res;
1188
1189         if (host) {
1190                 mmc_remove_host(host->mmc);
1191                 if (host->pdata->cleanup)
1192                         host->pdata->cleanup(&pdev->dev);
1193                 free_irq(host->irq, host);
1194                 if (mmc_slot(host).card_detect_irq)
1195                         free_irq(mmc_slot(host).card_detect_irq, host);
1196                 flush_scheduled_work();
1197
1198                 clk_disable(host->fclk);
1199                 clk_disable(host->iclk);
1200                 clk_put(host->fclk);
1201                 clk_put(host->iclk);
1202                 if (host->dbclk_enabled) {
1203                         clk_disable(host->dbclk);
1204                         clk_put(host->dbclk);
1205                 }
1206
1207                 mmc_free_host(host->mmc);
1208                 iounmap(host->base);
1209         }
1210
1211         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1212         if (res)
1213                 release_mem_region(res->start, res->end - res->start + 1);
1214         platform_set_drvdata(pdev, NULL);
1215
1216         return 0;
1217 }
1218
1219 #ifdef CONFIG_PM
1220 static int omap_mmc_suspend(struct platform_device *pdev, pm_message_t state)
1221 {
1222         int ret = 0;
1223         struct mmc_omap_host *host = platform_get_drvdata(pdev);
1224
1225         if (host && host->suspended)
1226                 return 0;
1227
1228         if (host) {
1229                 ret = mmc_suspend_host(host->mmc, state);
1230                 if (ret == 0) {
1231                         host->suspended = 1;
1232
1233                         OMAP_HSMMC_WRITE(host->base, ISE, 0);
1234                         OMAP_HSMMC_WRITE(host->base, IE, 0);
1235
1236                         if (host->pdata->suspend) {
1237                                 ret = host->pdata->suspend(&pdev->dev,
1238                                                                 host->slot_id);
1239                                 if (ret)
1240                                         dev_dbg(mmc_dev(host->mmc),
1241                                                 "Unable to handle MMC board"
1242                                                 " level suspend\n");
1243                         }
1244
1245                         OMAP_HSMMC_WRITE(host->base, HCTL,
1246                                          OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
1247                         clk_disable(host->fclk);
1248                         clk_disable(host->iclk);
1249                         clk_disable(host->dbclk);
1250                 }
1251
1252         }
1253         return ret;
1254 }
1255
1256 /* Routine to resume the MMC device */
1257 static int omap_mmc_resume(struct platform_device *pdev)
1258 {
1259         int ret = 0;
1260         struct mmc_omap_host *host = platform_get_drvdata(pdev);
1261
1262         if (host && !host->suspended)
1263                 return 0;
1264
1265         if (host) {
1266
1267                 ret = clk_enable(host->fclk);
1268                 if (ret)
1269                         goto clk_en_err;
1270
1271                 ret = clk_enable(host->iclk);
1272                 if (ret) {
1273                         clk_disable(host->fclk);
1274                         clk_put(host->fclk);
1275                         goto clk_en_err;
1276                 }
1277
1278                 if (clk_enable(host->dbclk) != 0)
1279                         dev_dbg(mmc_dev(host->mmc),
1280                                         "Enabling debounce clk failed\n");
1281
1282                 omap_hsmmc_init(host);
1283
1284                 if (host->pdata->resume) {
1285                         ret = host->pdata->resume(&pdev->dev, host->slot_id);
1286                         if (ret)
1287                                 dev_dbg(mmc_dev(host->mmc),
1288                                         "Unmask interrupt failed\n");
1289                 }
1290
1291                 /* Notify the core to resume the host */
1292                 ret = mmc_resume_host(host->mmc);
1293                 if (ret == 0)
1294                         host->suspended = 0;
1295         }
1296
1297         return ret;
1298
1299 clk_en_err:
1300         dev_dbg(mmc_dev(host->mmc),
1301                 "Failed to enable MMC clocks during resume\n");
1302         return ret;
1303 }
1304
1305 #else
1306 #define omap_mmc_suspend        NULL
1307 #define omap_mmc_resume         NULL
1308 #endif
1309
1310 static struct platform_driver omap_mmc_driver = {
1311         .probe          = omap_mmc_probe,
1312         .remove         = omap_mmc_remove,
1313         .suspend        = omap_mmc_suspend,
1314         .resume         = omap_mmc_resume,
1315         .driver         = {
1316                 .name = DRIVER_NAME,
1317                 .owner = THIS_MODULE,
1318         },
1319 };
1320
1321 static int __init omap_mmc_init(void)
1322 {
1323         /* Register the MMC driver */
1324         return platform_driver_register(&omap_mmc_driver);
1325 }
1326
1327 static void __exit omap_mmc_cleanup(void)
1328 {
1329         /* Unregister MMC driver */
1330         platform_driver_unregister(&omap_mmc_driver);
1331 }
1332
1333 module_init(omap_mmc_init);
1334 module_exit(omap_mmc_cleanup);
1335
1336 MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
1337 MODULE_LICENSE("GPL");
1338 MODULE_ALIAS("platform:" DRIVER_NAME);
1339 MODULE_AUTHOR("Texas Instruments Inc");