]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/mmc/host/omap_hsmmc.c
Extra omap code in linux-omap tree
[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                 return IRQ_HANDLED;
438         }
439
440         data = host->data;
441         status = OMAP_HSMMC_READ(host->base, STAT);
442         dev_dbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status);
443
444         if (status & ERR) {
445 #ifdef CONFIG_MMC_DEBUG
446                 mmc_omap_report_irq(host, status);
447 #endif
448                 if ((status & CMD_TIMEOUT) ||
449                         (status & CMD_CRC)) {
450                         if (host->cmd) {
451                                 if (status & CMD_TIMEOUT) {
452                                         mmc_omap_reset_controller_fsm(host, SRC);
453                                         host->cmd->error = -ETIMEDOUT;
454                                 } else {
455                                         host->cmd->error = -EILSEQ;
456                                 }
457                                 end_cmd = 1;
458                         }
459                         if (host->data || host->response_busy) {
460                                 if (host->data)
461                                         mmc_dma_cleanup(host, -ETIMEDOUT);
462                                 host->response_busy = 0;
463                                 mmc_omap_reset_controller_fsm(host, SRD);
464                         }
465                 }
466                 if ((status & DATA_TIMEOUT) ||
467                         (status & DATA_CRC)) {
468                         if (host->data || host->response_busy) {
469                                 int err = (status & DATA_TIMEOUT) ?
470                                                 -ETIMEDOUT : -EILSEQ;
471
472                                 if (host->data)
473                                         mmc_dma_cleanup(host, err);
474                                 else
475                                         host->mrq->cmd->error = err;
476                                 host->response_busy = 0;
477                                 mmc_omap_reset_controller_fsm(host, SRD);
478                                 end_trans = 1;
479                         }
480                 }
481                 if (status & CARD_ERR) {
482                         dev_dbg(mmc_dev(host->mmc),
483                                 "Ignoring card err CMD%d\n", host->cmd->opcode);
484                         if (host->cmd)
485                                 end_cmd = 1;
486                         if (host->data)
487                                 end_trans = 1;
488                 }
489         }
490
491         OMAP_HSMMC_WRITE(host->base, STAT, status);
492         OMAP_HSMMC_READ(host->base, STAT); /* flush posted write */
493
494         if (end_cmd || (status & CC))
495                 mmc_omap_cmd_done(host, host->cmd);
496         if (end_trans || (status & TC))
497                 mmc_omap_xfer_done(host, data);
498
499         return IRQ_HANDLED;
500 }
501
502 static void set_sd_bus_power(struct mmc_omap_host *host)
503 {
504         unsigned long i;
505
506         OMAP_HSMMC_WRITE(host->base, HCTL,
507                          OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
508         for (i = 0; i < loops_per_jiffy; i++) {
509                 if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP)
510                         break;
511                 cpu_relax();
512         }
513 }
514
515 /*
516  * Switch MMC interface voltage ... only relevant for MMC1.
517  *
518  * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
519  * The MMC2 transceiver controls are used instead of DAT4..DAT7.
520  * Some chips, like eMMC ones, use internal transceivers.
521  */
522 static int omap_mmc_switch_opcond(struct mmc_omap_host *host, int vdd)
523 {
524         u32 reg_val = 0;
525         int ret;
526
527         /* Disable the clocks */
528         clk_disable(host->fclk);
529         clk_disable(host->iclk);
530         clk_disable(host->dbclk);
531
532         /* Turn the power off */
533         ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
534         if (ret != 0)
535                 goto err;
536
537         /* Turn the power ON with given VDD 1.8 or 3.0v */
538         ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, vdd);
539         if (ret != 0)
540                 goto err;
541
542         clk_enable(host->fclk);
543         clk_enable(host->iclk);
544         clk_enable(host->dbclk);
545
546         OMAP_HSMMC_WRITE(host->base, HCTL,
547                 OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
548         reg_val = OMAP_HSMMC_READ(host->base, HCTL);
549
550         /*
551          * If a MMC dual voltage card is detected, the set_ios fn calls
552          * this fn with VDD bit set for 1.8V. Upon card removal from the
553          * slot, omap_mmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
554          *
555          * Cope with a bit of slop in the range ... per data sheets:
556          *  - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
557          *    but recommended values are 1.71V to 1.89V
558          *  - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
559          *    but recommended values are 2.7V to 3.3V
560          *
561          * Board setup code shouldn't permit anything very out-of-range.
562          * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
563          * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
564          */
565         if ((1 << vdd) <= MMC_VDD_23_24)
566                 reg_val |= SDVS18;
567         else
568                 reg_val |= SDVS30;
569
570         OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
571         set_sd_bus_power(host);
572
573         return 0;
574 err:
575         dev_dbg(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
576         return ret;
577 }
578
579 /*
580  * Work Item to notify the core about card insertion/removal
581  */
582 static void mmc_omap_detect(struct work_struct *work)
583 {
584         struct mmc_omap_host *host = container_of(work, struct mmc_omap_host,
585                                                 mmc_carddetect_work);
586         struct omap_mmc_slot_data *slot = &mmc_slot(host);
587
588         if (mmc_slot(host).card_detect)
589                 host->carddetect = slot->card_detect(slot->card_detect_irq);
590         else
591                 host->carddetect = -ENOSYS;
592
593         sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
594         if (host->carddetect) {
595                 mmc_detect_change(host->mmc, (HZ * 200) / 1000);
596         } else {
597                 mmc_omap_reset_controller_fsm(host, SRD);
598                 mmc_detect_change(host->mmc, (HZ * 50) / 1000);
599         }
600 }
601
602 /*
603  * ISR for handling card insertion and removal
604  */
605 static irqreturn_t omap_mmc_cd_handler(int irq, void *dev_id)
606 {
607         struct mmc_omap_host *host = (struct mmc_omap_host *)dev_id;
608
609         schedule_work(&host->mmc_carddetect_work);
610
611         return IRQ_HANDLED;
612 }
613
614 static int mmc_omap_get_dma_sync_dev(struct mmc_omap_host *host,
615                                      struct mmc_data *data)
616 {
617         int sync_dev;
618
619         if (data->flags & MMC_DATA_WRITE)
620                 sync_dev = host->dma_line_tx;
621         else
622                 sync_dev = host->dma_line_rx;
623         return sync_dev;
624 }
625
626 static void mmc_omap_config_dma_params(struct mmc_omap_host *host,
627                                        struct mmc_data *data,
628                                        struct scatterlist *sgl)
629 {
630         int blksz, nblk, dma_ch;
631
632         dma_ch = host->dma_ch;
633         if (data->flags & MMC_DATA_WRITE) {
634                 omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
635                         (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
636                 omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
637                         sg_dma_address(sgl), 0, 0);
638         } else {
639                 omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
640                                         (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
641                 omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
642                         sg_dma_address(sgl), 0, 0);
643         }
644
645         blksz = host->data->blksz;
646         nblk = sg_dma_len(sgl) / blksz;
647
648         omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32,
649                         blksz / 4, nblk, OMAP_DMA_SYNC_FRAME,
650                         mmc_omap_get_dma_sync_dev(host, data),
651                         !(data->flags & MMC_DATA_WRITE));
652
653         omap_start_dma(dma_ch);
654 }
655
656 /*
657  * DMA call back function
658  */
659 static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data)
660 {
661         struct mmc_omap_host *host = data;
662
663         if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ)
664                 dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n");
665
666         if (host->dma_ch < 0)
667                 return;
668
669         host->dma_sg_idx++;
670         if (host->dma_sg_idx < host->dma_len) {
671                 /* Fire up the next transfer. */
672                 mmc_omap_config_dma_params(host, host->data,
673                                            host->data->sg + host->dma_sg_idx);
674                 return;
675         }
676
677         omap_free_dma(host->dma_ch);
678         host->dma_ch = -1;
679         /*
680          * DMA Callback: run in interrupt context.
681          * mutex_unlock will through a kernel warning if used.
682          */
683         up(&host->sem);
684 }
685
686 /*
687  * Routine to configure and start DMA for the MMC card
688  */
689 static int
690 mmc_omap_start_dma_transfer(struct mmc_omap_host *host, struct mmc_request *req)
691 {
692         int dma_ch = 0, ret = 0, err = 1, i;
693         struct mmc_data *data = req->data;
694
695         /* Sanity check: all the SG entries must be aligned by block size. */
696         for (i = 0; i < host->dma_len; i++) {
697                 struct scatterlist *sgl;
698
699                 sgl = data->sg + i;
700                 if (sgl->length % data->blksz)
701                         return -EINVAL;
702         }
703         if ((data->blksz % 4) != 0)
704                 /* REVISIT: The MMC buffer increments only when MSB is written.
705                  * Return error for blksz which is non multiple of four.
706                  */
707                 return -EINVAL;
708
709         /*
710          * If for some reason the DMA transfer is still active,
711          * we wait for timeout period and free the dma
712          */
713         if (host->dma_ch != -1) {
714                 set_current_state(TASK_UNINTERRUPTIBLE);
715                 schedule_timeout(100);
716                 if (down_trylock(&host->sem)) {
717                         omap_free_dma(host->dma_ch);
718                         host->dma_ch = -1;
719                         up(&host->sem);
720                         return err;
721                 }
722         } else {
723                 if (down_trylock(&host->sem))
724                         return err;
725         }
726
727         ret = omap_request_dma(mmc_omap_get_dma_sync_dev(host, data), "MMC/SD",
728                                mmc_omap_dma_cb,host, &dma_ch);
729         if (ret != 0) {
730                 dev_err(mmc_dev(host->mmc),
731                         "%s: omap_request_dma() failed with %d\n",
732                         mmc_hostname(host->mmc), ret);
733                 return ret;
734         }
735
736         host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
737                         data->sg_len, mmc_omap_get_dma_dir(host, data));
738         host->dma_ch = dma_ch;
739         host->dma_sg_idx = 0;
740
741         mmc_omap_config_dma_params(host, data, data->sg);
742
743         return 0;
744 }
745
746 static void set_data_timeout(struct mmc_omap_host *host,
747                              struct mmc_request *req)
748 {
749         unsigned int timeout, cycle_ns;
750         uint32_t reg, clkd, dto = 0;
751
752         reg = OMAP_HSMMC_READ(host->base, SYSCTL);
753         clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
754         if (clkd == 0)
755                 clkd = 1;
756
757         cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
758         timeout = req->data->timeout_ns / cycle_ns;
759         timeout += req->data->timeout_clks;
760         if (timeout) {
761                 while ((timeout & 0x80000000) == 0) {
762                         dto += 1;
763                         timeout <<= 1;
764                 }
765                 dto = 31 - dto;
766                 timeout <<= 1;
767                 if (timeout && dto)
768                         dto += 1;
769                 if (dto >= 13)
770                         dto -= 13;
771                 else
772                         dto = 0;
773                 if (dto > 14)
774                         dto = 14;
775         }
776
777         reg &= ~DTO_MASK;
778         reg |= dto << DTO_SHIFT;
779         OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
780 }
781
782 /*
783  * Configure block length for MMC/SD cards and initiate the transfer.
784  */
785 static int
786 mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
787 {
788         int ret;
789         host->data = req->data;
790
791         if (req->data == NULL) {
792                 OMAP_HSMMC_WRITE(host->base, BLK, 0);
793                 return 0;
794         }
795
796         OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
797                                         | (req->data->blocks << 16));
798         set_data_timeout(host, req);
799
800         if (host->use_dma) {
801                 ret = mmc_omap_start_dma_transfer(host, req);
802                 if (ret != 0) {
803                         dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n");
804                         return ret;
805                 }
806         }
807         return 0;
808 }
809
810 /*
811  * Request function. for read/write operation
812  */
813 static void omap_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
814 {
815         struct mmc_omap_host *host = mmc_priv(mmc);
816
817         WARN_ON(host->mrq != NULL);
818         host->mrq = req;
819         mmc_omap_prepare_data(host, req);
820         mmc_omap_start_command(host, req->cmd, req->data);
821 }
822
823
824 /* Routine to configure clock values. Exposed API to core */
825 static void omap_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
826 {
827         struct mmc_omap_host *host = mmc_priv(mmc);
828         u16 dsor = 0;
829         unsigned long regval;
830         unsigned long timeout;
831         u32 con;
832
833         switch (ios->power_mode) {
834         case MMC_POWER_OFF:
835                 mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
836                 break;
837         case MMC_POWER_UP:
838                 mmc_slot(host).set_power(host->dev, host->slot_id, 1, ios->vdd);
839                 break;
840         }
841
842         con = OMAP_HSMMC_READ(host->base, CON);
843         switch (mmc->ios.bus_width) {
844         case MMC_BUS_WIDTH_8:
845                 OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
846                 break;
847         case MMC_BUS_WIDTH_4:
848                 OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
849                 OMAP_HSMMC_WRITE(host->base, HCTL,
850                         OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
851                 break;
852         case MMC_BUS_WIDTH_1:
853                 OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
854                 OMAP_HSMMC_WRITE(host->base, HCTL,
855                         OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
856                 break;
857         }
858
859         if (host->id == OMAP_MMC1_DEVID) {
860                 /* Only MMC1 can interface at 3V without some flavor
861                  * of external transceiver; but they all handle 1.8V.
862                  */
863                 if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
864                         (ios->vdd == DUAL_VOLT_OCR_BIT)) {
865                                 /*
866                                  * The mmc_select_voltage fn of the core does
867                                  * not seem to set the power_mode to
868                                  * MMC_POWER_UP upon recalculating the voltage.
869                                  * vdd 1.8v.
870                                  */
871                                 if (omap_mmc_switch_opcond(host, ios->vdd) != 0)
872                                         dev_dbg(mmc_dev(host->mmc),
873                                                 "Switch operation failed\n");
874                 }
875         }
876
877         if (ios->clock) {
878                 dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
879                 if (dsor < 1)
880                         dsor = 1;
881
882                 if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
883                         dsor++;
884
885                 if (dsor > 250)
886                         dsor = 250;
887         }
888         omap_mmc_stop_clock(host);
889         regval = OMAP_HSMMC_READ(host->base, SYSCTL);
890         regval = regval & ~(CLKD_MASK);
891         regval = regval | (dsor << 6) | (DTO << 16);
892         OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
893         OMAP_HSMMC_WRITE(host->base, SYSCTL,
894                 OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
895
896         /* Wait till the ICS bit is set */
897         timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
898         while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != 0x2
899                 && time_before(jiffies, timeout))
900                 msleep(1);
901
902         OMAP_HSMMC_WRITE(host->base, SYSCTL,
903                 OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
904
905         if (ios->power_mode == MMC_POWER_ON)
906                 send_init_stream(host);
907
908         if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
909                 OMAP_HSMMC_WRITE(host->base, CON,
910                                 OMAP_HSMMC_READ(host->base, CON) | OD);
911 }
912
913 static int omap_hsmmc_get_cd(struct mmc_host *mmc)
914 {
915         struct mmc_omap_host *host = mmc_priv(mmc);
916         struct omap_mmc_platform_data *pdata = host->pdata;
917
918         if (!pdata->slots[0].card_detect)
919                 return -ENOSYS;
920         return pdata->slots[0].card_detect(pdata->slots[0].card_detect_irq);
921 }
922
923 static int omap_hsmmc_get_ro(struct mmc_host *mmc)
924 {
925         struct mmc_omap_host *host = mmc_priv(mmc);
926         struct omap_mmc_platform_data *pdata = host->pdata;
927
928         if (!pdata->slots[0].get_ro)
929                 return -ENOSYS;
930         return pdata->slots[0].get_ro(host->dev, 0);
931 }
932
933 static void omap_hsmmc_init(struct mmc_omap_host *host)
934 {
935         u32 hctl, capa, value;
936
937         /* Only MMC1 supports 3.0V */
938         if (host->id == OMAP_MMC1_DEVID) {
939                 hctl = SDVS30;
940                 capa = VS30 | VS18;
941         } else {
942                 hctl = SDVS18;
943                 capa = VS18;
944         }
945
946         value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
947         OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
948
949         value = OMAP_HSMMC_READ(host->base, CAPA);
950         OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
951
952         /* Set the controller to AUTO IDLE mode */
953         value = OMAP_HSMMC_READ(host->base, SYSCONFIG);
954         OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE);
955
956         /* Set SD bus power bit */
957         set_sd_bus_power(host);
958 }
959
960 static struct mmc_host_ops mmc_omap_ops = {
961         .request = omap_mmc_request,
962         .set_ios = omap_mmc_set_ios,
963         .get_cd = omap_hsmmc_get_cd,
964         .get_ro = omap_hsmmc_get_ro,
965         /* NYET -- enable_sdio_irq */
966 };
967
968 static int __init omap_mmc_probe(struct platform_device *pdev)
969 {
970         struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
971         struct mmc_host *mmc;
972         struct mmc_omap_host *host = NULL;
973         struct resource *res;
974         int ret = 0, irq;
975
976         if (pdata == NULL) {
977                 dev_err(&pdev->dev, "Platform Data is missing\n");
978                 return -ENXIO;
979         }
980
981         if (pdata->nr_slots == 0) {
982                 dev_err(&pdev->dev, "No Slots\n");
983                 return -ENXIO;
984         }
985
986         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
987         irq = platform_get_irq(pdev, 0);
988         if (res == NULL || irq < 0)
989                 return -ENXIO;
990
991         res = request_mem_region(res->start, res->end - res->start + 1,
992                                                         pdev->name);
993         if (res == NULL)
994                 return -EBUSY;
995
996         mmc = mmc_alloc_host(sizeof(struct mmc_omap_host), &pdev->dev);
997         if (!mmc) {
998                 ret = -ENOMEM;
999                 goto err;
1000         }
1001
1002         host            = mmc_priv(mmc);
1003         host->mmc       = mmc;
1004         host->pdata     = pdata;
1005         host->dev       = &pdev->dev;
1006         host->use_dma   = 1;
1007         host->dev->dma_mask = &pdata->dma_mask;
1008         host->dma_ch    = -1;
1009         host->irq       = irq;
1010         host->id        = pdev->id;
1011         host->slot_id   = 0;
1012         host->mapbase   = res->start;
1013         host->base      = ioremap(host->mapbase, SZ_4K);
1014
1015         platform_set_drvdata(pdev, host);
1016         INIT_WORK(&host->mmc_carddetect_work, mmc_omap_detect);
1017
1018         mmc->ops        = &mmc_omap_ops;
1019         mmc->f_min      = 400000;
1020         mmc->f_max      = 52000000;
1021
1022         sema_init(&host->sem, 1);
1023
1024         host->iclk = clk_get(&pdev->dev, "ick");
1025         if (IS_ERR(host->iclk)) {
1026                 ret = PTR_ERR(host->iclk);
1027                 host->iclk = NULL;
1028                 goto err1;
1029         }
1030         host->fclk = clk_get(&pdev->dev, "fck");
1031         if (IS_ERR(host->fclk)) {
1032                 ret = PTR_ERR(host->fclk);
1033                 host->fclk = NULL;
1034                 clk_put(host->iclk);
1035                 goto err1;
1036         }
1037
1038         if (clk_enable(host->fclk) != 0) {
1039                 clk_put(host->iclk);
1040                 clk_put(host->fclk);
1041                 goto err1;
1042         }
1043
1044         if (clk_enable(host->iclk) != 0) {
1045                 clk_disable(host->fclk);
1046                 clk_put(host->iclk);
1047                 clk_put(host->fclk);
1048                 goto err1;
1049         }
1050
1051         host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
1052         /*
1053          * MMC can still work without debounce clock.
1054          */
1055         if (IS_ERR(host->dbclk))
1056                 dev_warn(mmc_dev(host->mmc), "Failed to get debounce clock\n");
1057         else
1058                 if (clk_enable(host->dbclk) != 0)
1059                         dev_dbg(mmc_dev(host->mmc), "Enabling debounce"
1060                                                         " clk failed\n");
1061                 else
1062                         host->dbclk_enabled = 1;
1063
1064         /* Since we do only SG emulation, we can have as many segs
1065          * as we want. */
1066         mmc->max_phys_segs = 1024;
1067         mmc->max_hw_segs = 1024;
1068
1069         mmc->max_blk_size = 512;       /* Block Length at max can be 1024 */
1070         mmc->max_blk_count = 0xFFFF;    /* No. of Blocks is 16 bits */
1071         mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
1072         mmc->max_seg_size = mmc->max_req_size;
1073
1074         mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
1075
1076         if (pdata->slots[host->slot_id].wires >= 8)
1077                 mmc->caps |= MMC_CAP_8_BIT_DATA;
1078         else if (pdata->slots[host->slot_id].wires >= 4)
1079                 mmc->caps |= MMC_CAP_4_BIT_DATA;
1080
1081         omap_hsmmc_init(host);
1082
1083         /* Select DMA lines */
1084         switch (host->id) {
1085         case OMAP_MMC1_DEVID:
1086                 host->dma_line_tx = OMAP24XX_DMA_MMC1_TX;
1087                 host->dma_line_rx = OMAP24XX_DMA_MMC1_RX;
1088                 break;
1089         case OMAP_MMC2_DEVID:
1090                 host->dma_line_tx = OMAP24XX_DMA_MMC2_TX;
1091                 host->dma_line_rx = OMAP24XX_DMA_MMC2_RX;
1092                 break;
1093         case OMAP_MMC3_DEVID:
1094                 host->dma_line_tx = OMAP34XX_DMA_MMC3_TX;
1095                 host->dma_line_rx = OMAP34XX_DMA_MMC3_RX;
1096                 break;
1097         default:
1098                 dev_err(mmc_dev(host->mmc), "Invalid MMC id\n");
1099                 goto err_irq;
1100         }
1101
1102         /* Request IRQ for MMC operations */
1103         ret = request_irq(host->irq, mmc_omap_irq, IRQF_DISABLED,
1104                         mmc_hostname(mmc), host);
1105         if (ret) {
1106                 dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
1107                 goto err_irq;
1108         }
1109
1110         /* initialize power supplies, gpios, etc */
1111         if (pdata->init != NULL) {
1112                 if (pdata->init(&pdev->dev) != 0) {
1113                         dev_dbg(mmc_dev(host->mmc), "late init error\n");
1114                         goto err_irq_cd_init;
1115                 }
1116         }
1117         mmc->ocr_avail = mmc_slot(host).ocr_mask;
1118
1119         /* Request IRQ for card detect */
1120         if ((mmc_slot(host).card_detect_irq)) {
1121                 ret = request_irq(mmc_slot(host).card_detect_irq,
1122                                   omap_mmc_cd_handler,
1123                                   IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
1124                                           | IRQF_DISABLED,
1125                                   mmc_hostname(mmc), host);
1126                 if (ret) {
1127                         dev_dbg(mmc_dev(host->mmc),
1128                                 "Unable to grab MMC CD IRQ\n");
1129                         goto err_irq_cd;
1130                 }
1131         }
1132
1133         OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
1134         OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
1135
1136         mmc_add_host(mmc);
1137
1138         if (host->pdata->slots[host->slot_id].name != NULL) {
1139                 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
1140                 if (ret < 0)
1141                         goto err_slot_name;
1142         }
1143         if (mmc_slot(host).card_detect_irq &&
1144             host->pdata->slots[host->slot_id].get_cover_state) {
1145                 ret = device_create_file(&mmc->class_dev,
1146                                         &dev_attr_cover_switch);
1147                 if (ret < 0)
1148                         goto err_cover_switch;
1149         }
1150
1151         return 0;
1152
1153 err_cover_switch:
1154         device_remove_file(&mmc->class_dev, &dev_attr_cover_switch);
1155 err_slot_name:
1156         mmc_remove_host(mmc);
1157 err_irq_cd:
1158         free_irq(mmc_slot(host).card_detect_irq, host);
1159 err_irq_cd_init:
1160         free_irq(host->irq, host);
1161 err_irq:
1162         clk_disable(host->fclk);
1163         clk_disable(host->iclk);
1164         clk_put(host->fclk);
1165         clk_put(host->iclk);
1166         if (host->dbclk_enabled) {
1167                 clk_disable(host->dbclk);
1168                 clk_put(host->dbclk);
1169         }
1170
1171 err1:
1172         iounmap(host->base);
1173 err:
1174         dev_dbg(mmc_dev(host->mmc), "Probe Failed\n");
1175         release_mem_region(res->start, res->end - res->start + 1);
1176         if (host)
1177                 mmc_free_host(mmc);
1178         return ret;
1179 }
1180
1181 static int omap_mmc_remove(struct platform_device *pdev)
1182 {
1183         struct mmc_omap_host *host = platform_get_drvdata(pdev);
1184         struct resource *res;
1185
1186         if (host) {
1187                 mmc_remove_host(host->mmc);
1188                 if (host->pdata->cleanup)
1189                         host->pdata->cleanup(&pdev->dev);
1190                 free_irq(host->irq, host);
1191                 if (mmc_slot(host).card_detect_irq)
1192                         free_irq(mmc_slot(host).card_detect_irq, host);
1193                 flush_scheduled_work();
1194
1195                 clk_disable(host->fclk);
1196                 clk_disable(host->iclk);
1197                 clk_put(host->fclk);
1198                 clk_put(host->iclk);
1199                 if (host->dbclk_enabled) {
1200                         clk_disable(host->dbclk);
1201                         clk_put(host->dbclk);
1202                 }
1203
1204                 mmc_free_host(host->mmc);
1205                 iounmap(host->base);
1206         }
1207
1208         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1209         if (res)
1210                 release_mem_region(res->start, res->end - res->start + 1);
1211         platform_set_drvdata(pdev, NULL);
1212
1213         return 0;
1214 }
1215
1216 #ifdef CONFIG_PM
1217 static int omap_mmc_suspend(struct platform_device *pdev, pm_message_t state)
1218 {
1219         int ret = 0;
1220         struct mmc_omap_host *host = platform_get_drvdata(pdev);
1221
1222         if (host && host->suspended)
1223                 return 0;
1224
1225         if (host) {
1226                 ret = mmc_suspend_host(host->mmc, state);
1227                 if (ret == 0) {
1228                         host->suspended = 1;
1229
1230                         OMAP_HSMMC_WRITE(host->base, ISE, 0);
1231                         OMAP_HSMMC_WRITE(host->base, IE, 0);
1232
1233                         if (host->pdata->suspend) {
1234                                 ret = host->pdata->suspend(&pdev->dev,
1235                                                                 host->slot_id);
1236                                 if (ret)
1237                                         dev_dbg(mmc_dev(host->mmc),
1238                                                 "Unable to handle MMC board"
1239                                                 " level suspend\n");
1240                         }
1241
1242                         OMAP_HSMMC_WRITE(host->base, HCTL,
1243                                          OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
1244                         clk_disable(host->fclk);
1245                         clk_disable(host->iclk);
1246                         clk_disable(host->dbclk);
1247                 }
1248
1249         }
1250         return ret;
1251 }
1252
1253 /* Routine to resume the MMC device */
1254 static int omap_mmc_resume(struct platform_device *pdev)
1255 {
1256         int ret = 0;
1257         struct mmc_omap_host *host = platform_get_drvdata(pdev);
1258
1259         if (host && !host->suspended)
1260                 return 0;
1261
1262         if (host) {
1263
1264                 ret = clk_enable(host->fclk);
1265                 if (ret)
1266                         goto clk_en_err;
1267
1268                 ret = clk_enable(host->iclk);
1269                 if (ret) {
1270                         clk_disable(host->fclk);
1271                         clk_put(host->fclk);
1272                         goto clk_en_err;
1273                 }
1274
1275                 if (clk_enable(host->dbclk) != 0)
1276                         dev_dbg(mmc_dev(host->mmc),
1277                                         "Enabling debounce clk failed\n");
1278
1279                 omap_hsmmc_init(host);
1280
1281                 if (host->pdata->resume) {
1282                         ret = host->pdata->resume(&pdev->dev, host->slot_id);
1283                         if (ret)
1284                                 dev_dbg(mmc_dev(host->mmc),
1285                                         "Unmask interrupt failed\n");
1286                 }
1287
1288                 /* Notify the core to resume the host */
1289                 ret = mmc_resume_host(host->mmc);
1290                 if (ret == 0)
1291                         host->suspended = 0;
1292         }
1293
1294         return ret;
1295
1296 clk_en_err:
1297         dev_dbg(mmc_dev(host->mmc),
1298                 "Failed to enable MMC clocks during resume\n");
1299         return ret;
1300 }
1301
1302 #else
1303 #define omap_mmc_suspend        NULL
1304 #define omap_mmc_resume         NULL
1305 #endif
1306
1307 static struct platform_driver omap_mmc_driver = {
1308         .probe          = omap_mmc_probe,
1309         .remove         = omap_mmc_remove,
1310         .suspend        = omap_mmc_suspend,
1311         .resume         = omap_mmc_resume,
1312         .driver         = {
1313                 .name = DRIVER_NAME,
1314                 .owner = THIS_MODULE,
1315         },
1316 };
1317
1318 static int __init omap_mmc_init(void)
1319 {
1320         /* Register the MMC driver */
1321         return platform_driver_register(&omap_mmc_driver);
1322 }
1323
1324 static void __exit omap_mmc_cleanup(void)
1325 {
1326         /* Unregister MMC driver */
1327         platform_driver_unregister(&omap_mmc_driver);
1328 }
1329
1330 module_init(omap_mmc_init);
1331 module_exit(omap_mmc_cleanup);
1332
1333 MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
1334 MODULE_LICENSE("GPL");
1335 MODULE_ALIAS("platform:" DRIVER_NAME);
1336 MODULE_AUTHOR("Texas Instruments Inc");