2 * drivers/mmc/host/omap_hsmmc.c
4 * Driver for OMAP2430/3430 MMC controller.
6 * Copyright (C) 2007 Texas Instruments.
9 * Syed Mohammed Khasim <x0khasim@ti.com>
10 * Madhusudhan <madhu.cr@ti.com>
11 * Mohit Jalori <mjalori@ti.com>
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.
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>
29 #include <asm/semaphore.h>
31 #include <asm/hardware.h>
32 #include <asm/arch/board.h>
33 #include <asm/arch/mmc.h>
34 #include <asm/arch/cpu.h>
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
56 #define SDVS18 (0x5<<9)
57 #define SDVS30 (0x6<<9)
58 #define SDVSCLR 0xFFFFF1FF
59 #define SDVSDET 0x00000400
66 #define CLKD_MASK 0x0000FFC0
67 #define INT_EN_MASK 0x307F0033
68 #define INIT_STREAM (1<<1)
69 #define DP_SELECT (1<<21)
74 #define FOUR_BIT 1 << 1
79 #define CMD_TIMEOUT (1 << 16)
80 #define DATA_TIMEOUT (1 << 20)
81 #define CMD_CRC (1 << 17)
82 #define DATA_CRC (1 << 21)
83 #define CARD_ERR (1 << 28)
84 #define STAT_CLEAR 0xFFFFFFFF
85 #define INIT_STREAM_CMD 0x00000000
86 #define DUAL_VOLT_OCR_BIT 7
88 #define OMAP_MMC1_DEVID 1
89 #define OMAP_MMC2_DEVID 2
90 #define OMAP_MMC_DATADIR_NONE 0
91 #define OMAP_MMC_DATADIR_READ 1
92 #define OMAP_MMC_DATADIR_WRITE 2
93 #define MMC_TIMEOUT_MS 20
94 #define OMAP_MMC_MASTER_CLOCK 96000000
95 #define DRIVER_NAME "mmci-omap"
97 * slot_id is device id - 1, device id is a static value
98 * of 1 to represent device 1 etc..
100 #define mmc_slot(host) (host->pdata->slots[host->slot_id])
103 * MMC Host controller read/write API's
105 #define OMAP_HSMMC_READ(base, reg) \
106 __raw_readl((base) + OMAP_HSMMC_##reg)
108 #define OMAP_HSMMC_WRITE(base, reg, val) \
109 __raw_writel((val), (base) + OMAP_HSMMC_##reg)
111 struct mmc_omap_host
{
113 struct mmc_host
*mmc
;
114 struct mmc_request
*mrq
;
115 struct mmc_command
*cmd
;
116 struct mmc_data
*data
;
120 struct semaphore sem
;
121 struct work_struct mmc_carddetect_work
;
123 resource_size_t mapbase
;
125 unsigned int dma_len
;
126 unsigned int dma_dir
;
127 unsigned char bus_mode
;
128 unsigned char datadir
;
138 struct omap_mmc_platform_data
*pdata
;
142 * Stop clock to the card
144 static void omap_mmc_stop_clock(struct mmc_omap_host
*host
)
146 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
,
147 OMAP_HSMMC_READ(host
->base
, SYSCTL
) & ~CEN
);
148 if ((OMAP_HSMMC_READ(host
->base
, SYSCTL
) & CEN
) != 0x0)
149 dev_dbg(mmc_dev(host
->mmc
), "MMC Clock is not stoped\n");
153 * Send init stream sequence to card
154 * before sending IDLE command
156 static void send_init_stream(struct mmc_omap_host
*host
)
159 unsigned long timeout
;
161 disable_irq(host
->irq
);
162 OMAP_HSMMC_WRITE(host
->base
, CON
,
163 OMAP_HSMMC_READ(host
->base
, CON
) | INIT_STREAM
);
164 OMAP_HSMMC_WRITE(host
->base
, CMD
, INIT_STREAM_CMD
);
166 timeout
= jiffies
+ msecs_to_jiffies(MMC_TIMEOUT_MS
);
167 while ((reg
!= CC
) && time_before(jiffies
, timeout
))
168 reg
= OMAP_HSMMC_READ(host
->base
, STAT
) & CC
;
170 OMAP_HSMMC_WRITE(host
->base
, CON
,
171 OMAP_HSMMC_READ(host
->base
, CON
) & ~INIT_STREAM
);
172 enable_irq(host
->irq
);
176 * Configure the response type and send the cmd.
179 mmc_omap_start_command(struct mmc_omap_host
*host
, struct mmc_command
*cmd
,
180 struct mmc_data
*data
)
182 int cmdreg
= 0, resptype
= 0, cmdtype
= 0;
184 dev_dbg(mmc_dev(host
->mmc
), "%s: CMD%d, argument 0x%08x\n",
185 mmc_hostname(host
->mmc
), cmd
->opcode
, cmd
->arg
);
189 * Clear status bits and enable interrupts
191 OMAP_HSMMC_WRITE(host
->base
, STAT
, STAT_CLEAR
);
192 OMAP_HSMMC_WRITE(host
->base
, ISE
, INT_EN_MASK
);
193 OMAP_HSMMC_WRITE(host
->base
, IE
, INT_EN_MASK
);
195 if (cmd
->flags
& MMC_RSP_PRESENT
) {
196 if (cmd
->flags
& MMC_RSP_136
)
203 * Unlike OMAP1 controller, the cmdtype does not seem to be based on
204 * ac, bc, adtc, bcr. Only CMD12 needs a val of 0x3, rest 0x0.
206 if (cmd
->opcode
== 12)
209 cmdreg
= (cmd
->opcode
<< 24) | (resptype
<< 16) | (cmdtype
<< 22);
212 cmdreg
|= DP_SELECT
| MSBS
| BCE
;
213 if (data
->flags
& MMC_DATA_READ
)
222 OMAP_HSMMC_WRITE(host
->base
, ARG
, cmd
->arg
);
223 OMAP_HSMMC_WRITE(host
->base
, CMD
, cmdreg
);
227 * Notify the transfer complete to MMC core
230 mmc_omap_xfer_done(struct mmc_omap_host
*host
, struct mmc_data
*data
)
234 if (host
->use_dma
&& host
->dma_ch
!= -1)
235 dma_unmap_sg(mmc_dev(host
->mmc
), data
->sg
, host
->dma_len
,
238 host
->datadir
= OMAP_MMC_DATADIR_NONE
;
241 data
->bytes_xfered
+= data
->blocks
* (data
->blksz
);
243 data
->bytes_xfered
= 0;
247 mmc_request_done(host
->mmc
, data
->mrq
);
250 mmc_omap_start_command(host
, data
->stop
, NULL
);
254 * Notify the core about command completion
257 mmc_omap_cmd_done(struct mmc_omap_host
*host
, struct mmc_command
*cmd
)
261 if (cmd
->flags
& MMC_RSP_PRESENT
) {
262 if (cmd
->flags
& MMC_RSP_136
) {
263 /* response type 2 */
264 cmd
->resp
[3] = OMAP_HSMMC_READ(host
->base
, RSP10
);
265 cmd
->resp
[2] = OMAP_HSMMC_READ(host
->base
, RSP32
);
266 cmd
->resp
[1] = OMAP_HSMMC_READ(host
->base
, RSP54
);
267 cmd
->resp
[0] = OMAP_HSMMC_READ(host
->base
, RSP76
);
269 /* response types 1, 1b, 3, 4, 5, 6 */
270 cmd
->resp
[0] = OMAP_HSMMC_READ(host
->base
, RSP10
);
273 if (host
->data
== NULL
|| cmd
->error
) {
275 mmc_request_done(host
->mmc
, cmd
->mrq
);
280 * DMA clean up for command errors
282 static void mmc_dma_cleanup(struct mmc_omap_host
*host
)
284 host
->data
->error
= -ETIMEDOUT
;
286 if (host
->use_dma
&& host
->dma_ch
!= -1) {
287 dma_unmap_sg(mmc_dev(host
->mmc
), host
->data
->sg
, host
->dma_len
,
289 omap_free_dma(host
->dma_ch
);
294 host
->datadir
= OMAP_MMC_DATADIR_NONE
;
298 * MMC controller IRQ handler
300 static irqreturn_t
mmc_omap_irq(int irq
, void *dev_id
)
302 struct mmc_omap_host
*host
= dev_id
;
303 int end_cmd
= 0, end_trans
= 0, status
;
305 if (host
->cmd
== NULL
&& host
->data
== NULL
) {
306 OMAP_HSMMC_WRITE(host
->base
, STAT
,
307 OMAP_HSMMC_READ(host
->base
, STAT
));
311 status
= OMAP_HSMMC_READ(host
->base
, STAT
);
312 dev_dbg(mmc_dev(host
->mmc
), "IRQ Status is %x\n", status
);
315 if ((status
& CMD_TIMEOUT
) ||
316 (status
& CMD_CRC
)) {
318 if (status
& CMD_TIMEOUT
)
319 host
->cmd
->error
= -ETIMEDOUT
;
321 host
->cmd
->error
= -EILSEQ
;
325 mmc_dma_cleanup(host
);
327 if ((status
& DATA_TIMEOUT
) ||
328 (status
& DATA_CRC
)) {
330 if (status
& DATA_TIMEOUT
)
331 mmc_dma_cleanup(host
);
333 host
->data
->error
= -EILSEQ
;
337 if (status
& CARD_ERR
) {
338 dev_dbg(mmc_dev(host
->mmc
),
339 "Ignoring card err CMD%d\n", host
->cmd
->opcode
);
347 OMAP_HSMMC_WRITE(host
->base
, STAT
, status
);
349 if (end_cmd
|| (status
& CC
))
350 mmc_omap_cmd_done(host
, host
->cmd
);
351 if (end_trans
|| (status
& TC
))
352 mmc_omap_xfer_done(host
, host
->data
);
358 * Switch MMC operating voltage
360 static int omap_mmc_switch_opcond(struct mmc_omap_host
*host
, int vdd
)
365 /* Disable the clocks */
366 clk_disable(host
->fclk
);
367 clk_disable(host
->iclk
);
368 clk_disable(host
->dbclk
);
370 /* Turn the power off */
371 ret
= mmc_slot(host
).set_power(host
->dev
, host
->slot_id
, 0, 0);
375 /* Turn the power ON with given VDD 1.8 or 3.0v */
376 ret
= mmc_slot(host
).set_power(host
->dev
, host
->slot_id
, 1, vdd
);
380 clk_enable(host
->fclk
);
381 clk_enable(host
->iclk
);
382 clk_enable(host
->dbclk
);
384 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
385 OMAP_HSMMC_READ(host
->base
, HCTL
) & SDVSCLR
);
386 reg_val
= OMAP_HSMMC_READ(host
->base
, HCTL
);
388 * If a MMC dual voltage card is detected, the set_ios fn calls
389 * this fn with VDD bit set for 1.8V. Upon card removal from the
390 * slot, mmc_omap_detect fn sets the VDD back to 3V.
392 * Only MMC1 supports 3.0V. MMC2 will not function if SDVS30 is
395 if (host
->id
== OMAP_MMC1_DEVID
&& (((1 << vdd
) == MMC_VDD_32_33
) ||
396 ((1 << vdd
) == MMC_VDD_33_34
)))
398 if ((1 << vdd
) == MMC_VDD_165_195
)
401 OMAP_HSMMC_WRITE(host
->base
, HCTL
, reg_val
);
403 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
404 OMAP_HSMMC_READ(host
->base
, HCTL
) | SDBP
);
408 dev_dbg(mmc_dev(host
->mmc
), "Unable to switch operating voltage\n");
413 * Work Item to notify the core about card insertion/removal
415 static void mmc_omap_detect(struct work_struct
*work
)
418 struct mmc_omap_host
*host
= container_of(work
, struct mmc_omap_host
,
419 mmc_carddetect_work
);
421 if (host
->carddetect
) {
422 if (!(OMAP_HSMMC_READ(host
->base
, HCTL
) & SDVSDET
)) {
424 * Set the VDD back to 3V when the card is removed
425 * before the set_ios fn turns off the power.
427 vdd
= fls(host
->mmc
->ocr_avail
) - 1;
428 if (omap_mmc_switch_opcond(host
, vdd
) != 0)
429 host
->mmc
->ios
.vdd
= vdd
;
431 mmc_detect_change(host
->mmc
, (HZ
* 200) / 1000);
433 mmc_detect_change(host
->mmc
, (HZ
* 50) / 1000);
437 * ISR for handling card insertion and removal
439 static irqreturn_t
omap_mmc_cd_handler(int irq
, void *dev_id
)
441 struct mmc_omap_host
*host
= (struct mmc_omap_host
*)dev_id
;
443 host
->carddetect
= mmc_slot(host
).card_detect(irq
);
444 schedule_work(&host
->mmc_carddetect_work
);
450 * DMA call back function
452 static void mmc_omap_dma_cb(int lch
, u16 ch_status
, void *data
)
454 struct mmc_omap_host
*host
= data
;
456 if (ch_status
& OMAP2_DMA_MISALIGNED_ERR_IRQ
)
457 dev_dbg(mmc_dev(host
->mmc
), "MISALIGNED_ADRS_ERR\n");
459 if (host
->dma_ch
< 0)
462 omap_free_dma(host
->dma_ch
);
465 * DMA Callback: run in interrupt context.
466 * mutex_unlock will through a kernel warning if used.
472 * Configure dma src and destination parameters
474 static int mmc_omap_config_dma_param(int sync_dir
, struct mmc_omap_host
*host
,
475 struct mmc_data
*data
)
478 omap_set_dma_dest_params(host
->dma_ch
, 0,
479 OMAP_DMA_AMODE_CONSTANT
,
480 (host
->mapbase
+ OMAP_HSMMC_DATA
), 0, 0);
481 omap_set_dma_src_params(host
->dma_ch
, 0,
482 OMAP_DMA_AMODE_POST_INC
,
483 sg_dma_address(&data
->sg
[0]), 0, 0);
485 omap_set_dma_src_params(host
->dma_ch
, 0,
486 OMAP_DMA_AMODE_CONSTANT
,
487 (host
->mapbase
+ OMAP_HSMMC_DATA
), 0, 0);
488 omap_set_dma_dest_params(host
->dma_ch
, 0,
489 OMAP_DMA_AMODE_POST_INC
,
490 sg_dma_address(&data
->sg
[0]), 0, 0);
495 * Routine to configure and start DMA for the MMC card
498 mmc_omap_start_dma_transfer(struct mmc_omap_host
*host
, struct mmc_request
*req
)
500 int sync_dev
, sync_dir
= 0;
501 int dma_ch
= 0, ret
= 0, err
= 1;
502 struct mmc_data
*data
= req
->data
;
505 * If for some reason the DMA transfer is still active,
506 * we wait for timeout period and free the dma
508 if (host
->dma_ch
!= -1) {
509 set_current_state(TASK_UNINTERRUPTIBLE
);
510 schedule_timeout(100);
511 if (down_trylock(&host
->sem
)) {
512 omap_free_dma(host
->dma_ch
);
518 if (down_trylock(&host
->sem
))
522 if (!(data
->flags
& MMC_DATA_WRITE
)) {
523 host
->dma_dir
= DMA_FROM_DEVICE
;
524 if (host
->id
== OMAP_MMC1_DEVID
)
525 sync_dev
= OMAP24XX_DMA_MMC1_RX
;
527 sync_dev
= OMAP24XX_DMA_MMC2_RX
;
529 host
->dma_dir
= DMA_TO_DEVICE
;
530 if (host
->id
== OMAP_MMC1_DEVID
)
531 sync_dev
= OMAP24XX_DMA_MMC1_TX
;
533 sync_dev
= OMAP24XX_DMA_MMC2_TX
;
536 ret
= omap_request_dma(sync_dev
, "MMC/SD", mmc_omap_dma_cb
,
539 dev_dbg(mmc_dev(host
->mmc
),
540 "%s: omap_request_dma() failed with %d\n",
541 mmc_hostname(host
->mmc
), ret
);
545 host
->dma_len
= dma_map_sg(mmc_dev(host
->mmc
), data
->sg
,
546 data
->sg_len
, host
->dma_dir
);
547 host
->dma_ch
= dma_ch
;
549 if (!(data
->flags
& MMC_DATA_WRITE
))
550 mmc_omap_config_dma_param(1, host
, data
);
552 mmc_omap_config_dma_param(0, host
, data
);
554 if ((data
->blksz
% 4) == 0)
555 omap_set_dma_transfer_params(dma_ch
, OMAP_DMA_DATA_TYPE_S32
,
556 (data
->blksz
/ 4), data
->blocks
, OMAP_DMA_SYNC_FRAME
,
559 /* REVISIT: The MMC buffer increments only when MSB is written.
560 * Return error for blksz which is non multiple of four.
564 omap_start_dma(dma_ch
);
569 * Configure block length for MMC/SD cards and initiate the transfer.
572 mmc_omap_prepare_data(struct mmc_omap_host
*host
, struct mmc_request
*req
)
575 host
->data
= req
->data
;
577 if (req
->data
== NULL
) {
578 host
->datadir
= OMAP_MMC_DATADIR_NONE
;
579 OMAP_HSMMC_WRITE(host
->base
, BLK
, 0);
583 OMAP_HSMMC_WRITE(host
->base
, BLK
, (req
->data
->blksz
)
584 | (req
->data
->blocks
<< 16));
586 host
->datadir
= (req
->data
->flags
& MMC_DATA_WRITE
) ?
587 OMAP_MMC_DATADIR_WRITE
: OMAP_MMC_DATADIR_READ
;
590 ret
= mmc_omap_start_dma_transfer(host
, req
);
592 dev_dbg(mmc_dev(host
->mmc
), "MMC start dma failure\n");
600 * Request function. for read/write operation
602 static void omap_mmc_request(struct mmc_host
*mmc
, struct mmc_request
*req
)
604 struct mmc_omap_host
*host
= mmc_priv(mmc
);
606 WARN_ON(host
->mrq
!= NULL
);
608 mmc_omap_prepare_data(host
, req
);
609 mmc_omap_start_command(host
, req
->cmd
, req
->data
);
613 /* Routine to configure clock values. Exposed API to core */
614 static void omap_mmc_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
616 struct mmc_omap_host
*host
= mmc_priv(mmc
);
618 unsigned long regval
;
619 unsigned long timeout
;
621 switch (ios
->power_mode
) {
623 mmc_slot(host
).set_power(host
->dev
, host
->slot_id
, 0, 0);
626 mmc_slot(host
).set_power(host
->dev
, host
->slot_id
, 1, ios
->vdd
);
630 switch (mmc
->ios
.bus_width
) {
631 case MMC_BUS_WIDTH_4
:
632 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
633 OMAP_HSMMC_READ(host
->base
, HCTL
) | FOUR_BIT
);
635 case MMC_BUS_WIDTH_1
:
636 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
637 OMAP_HSMMC_READ(host
->base
, HCTL
) & ~FOUR_BIT
);
641 if (host
->id
== OMAP_MMC1_DEVID
) {
642 /* Only MMC1 can operate at 3V/1.8V */
643 if ((OMAP_HSMMC_READ(host
->base
, HCTL
) & SDVSDET
) &&
644 (ios
->vdd
== DUAL_VOLT_OCR_BIT
)) {
646 * The mmc_select_voltage fn of the core does
647 * not seem to set the power_mode to
648 * MMC_POWER_UP upon recalculating the voltage.
651 if (omap_mmc_switch_opcond(host
, ios
->vdd
) != 0)
652 dev_dbg(mmc_dev(host
->mmc
),
653 "Switch operation failed\n");
658 dsor
= OMAP_MMC_MASTER_CLOCK
/ ios
->clock
;
662 if (OMAP_MMC_MASTER_CLOCK
/ dsor
> ios
->clock
)
668 omap_mmc_stop_clock(host
);
669 regval
= OMAP_HSMMC_READ(host
->base
, SYSCTL
);
670 regval
= regval
& ~(CLKD_MASK
);
671 regval
= regval
| (dsor
<< 6) | (DTO
<< 16);
672 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
, regval
);
673 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
,
674 OMAP_HSMMC_READ(host
->base
, SYSCTL
) | ICE
);
676 /* Wait till the ICS bit is set */
677 timeout
= jiffies
+ msecs_to_jiffies(MMC_TIMEOUT_MS
);
678 while ((OMAP_HSMMC_READ(host
->base
, SYSCTL
) & ICS
) != 0x2
679 && time_before(jiffies
, timeout
))
682 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
,
683 OMAP_HSMMC_READ(host
->base
, SYSCTL
) | CEN
);
685 if (ios
->power_mode
== MMC_POWER_ON
)
686 send_init_stream(host
);
688 if (ios
->bus_mode
== MMC_BUSMODE_OPENDRAIN
)
689 OMAP_HSMMC_WRITE(host
->base
, CON
,
690 OMAP_HSMMC_READ(host
->base
, CON
) | OD
);
692 /* NOTE: Read only switch not supported yet */
693 static struct mmc_host_ops mmc_omap_ops
= {
694 .request
= omap_mmc_request
,
695 .set_ios
= omap_mmc_set_ios
,
698 static int __init
omap_mmc_probe(struct platform_device
*pdev
)
700 struct omap_mmc_platform_data
*pdata
= pdev
->dev
.platform_data
;
701 struct mmc_host
*mmc
;
702 struct mmc_omap_host
*host
= NULL
;
703 struct resource
*res
;
708 dev_err(&pdev
->dev
, "Platform Data is missing\n");
712 if (pdata
->nr_slots
== 0) {
713 dev_err(&pdev
->dev
, "No Slots\n");
717 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
718 irq
= platform_get_irq(pdev
, 0);
719 if (res
== NULL
|| irq
< 0)
722 res
= request_mem_region(res
->start
, res
->end
- res
->start
+ 1,
727 mmc
= mmc_alloc_host(sizeof(struct mmc_omap_host
), &pdev
->dev
);
733 host
= mmc_priv(mmc
);
741 host
->mapbase
= res
->start
;
742 host
->base
= ioremap(host
->mapbase
, SZ_4K
);
743 mmc
->ops
= &mmc_omap_ops
;
745 mmc
->f_max
= 52000000;
747 sema_init(&host
->sem
, 1);
749 host
->iclk
= clk_get(&pdev
->dev
, "mmchs_ick");
750 if (IS_ERR(host
->iclk
)) {
751 ret
= PTR_ERR(host
->iclk
);
755 host
->fclk
= clk_get(&pdev
->dev
, "mmchs_fck");
756 if (IS_ERR(host
->fclk
)) {
757 ret
= PTR_ERR(host
->fclk
);
763 if (clk_enable(host
->fclk
) != 0)
766 if (clk_enable(host
->iclk
) != 0) {
767 clk_disable(host
->fclk
);
772 host
->dbclk
= clk_get(&pdev
->dev
, "mmchsdb_fck");
774 * MMC can still work without debounce clock.
776 if (IS_ERR(host
->dbclk
))
777 dev_dbg(mmc_dev(host
->mmc
), "Failed to get debounce clock\n");
779 if (clk_enable(host
->dbclk
) != 0)
780 dev_dbg(mmc_dev(host
->mmc
), "Enabling debounce"
783 host
->dbclk_enabled
= 1;
785 #ifdef CONFIG_MMC_BLOCK_BOUNCE
786 mmc
->max_phys_segs
= 1;
787 mmc
->max_hw_segs
= 1;
789 mmc
->max_blk_size
= 512; /* Block Length at max can be 1024 */
790 mmc
->max_blk_count
= 0xFFFF; /* No. of Blocks is 16 bits */
791 mmc
->max_req_size
= mmc
->max_blk_size
* mmc
->max_blk_count
;
792 mmc
->max_seg_size
= mmc
->max_req_size
;
794 mmc
->ocr_avail
= mmc_slot(host
).ocr_mask
;
795 mmc
->caps
|= MMC_CAP_MULTIWRITE
| MMC_CAP_MMC_HIGHSPEED
|
796 MMC_CAP_SD_HIGHSPEED
;
798 if (pdata
->conf
.wire4
)
799 mmc
->caps
|= MMC_CAP_4_BIT_DATA
;
801 /* Only MMC1 supports 3.0V */
802 if (host
->id
== OMAP_MMC1_DEVID
) {
810 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
811 OMAP_HSMMC_READ(host
->base
, HCTL
) | hctl
);
813 OMAP_HSMMC_WRITE(host
->base
, CAPA
,
814 OMAP_HSMMC_READ(host
->base
, CAPA
) | capa
);
816 /* Set the controller to AUTO IDLE mode */
817 OMAP_HSMMC_WRITE(host
->base
, SYSCONFIG
,
818 OMAP_HSMMC_READ(host
->base
, SYSCONFIG
) | AUTOIDLE
);
820 /* Set SD bus power bit */
821 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
822 OMAP_HSMMC_READ(host
->base
, HCTL
) | SDBP
);
824 /* Request IRQ for MMC operations */
825 ret
= request_irq(host
->irq
, mmc_omap_irq
, IRQF_DISABLED
, pdev
->name
,
828 dev_dbg(mmc_dev(host
->mmc
), "Unable to grab HSMMC IRQ\n");
832 /* Request IRQ for card detect */
833 if ((mmc_slot(host
).card_detect_irq
) && (mmc_slot(host
).card_detect
)) {
834 ret
= request_irq(mmc_slot(host
).card_detect_irq
,
835 omap_mmc_cd_handler
, IRQF_DISABLED
, "MMC CD",
838 dev_dbg(mmc_dev(host
->mmc
),
839 "Unable to grab MMC CD IRQ");
840 free_irq(host
->irq
, host
);
845 INIT_WORK(&host
->mmc_carddetect_work
, mmc_omap_detect
);
846 if (pdata
->init
!= NULL
) {
847 if (pdata
->init(&pdev
->dev
) != 0) {
848 free_irq(mmc_slot(host
).card_detect_irq
, host
);
849 free_irq(host
->irq
, host
);
854 OMAP_HSMMC_WRITE(host
->base
, ISE
, INT_EN_MASK
);
855 OMAP_HSMMC_WRITE(host
->base
, IE
, INT_EN_MASK
);
857 platform_set_drvdata(pdev
, host
);
863 dev_dbg(mmc_dev(host
->mmc
), "Probe Failed\n");
869 dev_dbg(mmc_dev(host
->mmc
), "Unable to configure MMC IRQs\n");
870 clk_disable(host
->fclk
);
871 clk_disable(host
->iclk
);
874 if (host
->dbclk_enabled
) {
875 clk_disable(host
->dbclk
);
876 clk_put(host
->dbclk
);
884 static int omap_mmc_remove(struct platform_device
*pdev
)
886 struct mmc_omap_host
*host
= platform_get_drvdata(pdev
);
888 platform_set_drvdata(pdev
, NULL
);
890 host
->pdata
->cleanup(&pdev
->dev
);
891 free_irq(host
->irq
, host
);
892 if (mmc_slot(host
).card_detect_irq
)
893 free_irq(mmc_slot(host
).card_detect_irq
, host
);
894 flush_scheduled_work();
896 clk_disable(host
->fclk
);
897 clk_disable(host
->iclk
);
900 if (host
->dbclk_enabled
) {
901 clk_disable(host
->dbclk
);
902 clk_put(host
->dbclk
);
905 mmc_free_host(host
->mmc
);
912 static int omap_mmc_suspend(struct platform_device
*pdev
, pm_message_t state
)
915 struct mmc_omap_host
*host
= platform_get_drvdata(pdev
);
917 if (host
&& host
->suspended
)
921 ret
= mmc_suspend_host(host
->mmc
, state
);
925 OMAP_HSMMC_WRITE(host
->base
, ISE
, 0);
926 OMAP_HSMMC_WRITE(host
->base
, IE
, 0);
928 ret
= host
->pdata
->suspend(&pdev
->dev
, host
->slot_id
);
930 dev_dbg(mmc_dev(host
->mmc
),
931 "Unable to handle MMC board"
934 if (!(OMAP_HSMMC_READ(host
->base
, HCTL
) & SDVSDET
)) {
935 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
936 OMAP_HSMMC_READ(host
->base
, HCTL
)
938 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
939 OMAP_HSMMC_READ(host
->base
, HCTL
)
941 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
942 OMAP_HSMMC_READ(host
->base
, HCTL
)
946 clk_disable(host
->fclk
);
947 clk_disable(host
->iclk
);
948 clk_disable(host
->dbclk
);
955 /* Routine to resume the MMC device */
956 static int omap_mmc_resume(struct platform_device
*pdev
)
959 struct mmc_omap_host
*host
= platform_get_drvdata(pdev
);
961 if (host
&& !host
->suspended
)
966 ret
= clk_enable(host
->fclk
);
970 ret
= clk_enable(host
->iclk
);
972 clk_disable(host
->fclk
);
977 if (clk_enable(host
->dbclk
) != 0)
978 dev_dbg(mmc_dev(host
->mmc
),
979 "Enabling debounce clk failed\n");
981 ret
= host
->pdata
->resume(&pdev
->dev
, host
->slot_id
);
983 dev_dbg(mmc_dev(host
->mmc
),
984 "Unmask interrupt failed\n");
986 /* Notify the core to resume the host */
987 ret
= mmc_resume_host(host
->mmc
);
995 dev_dbg(mmc_dev(host
->mmc
),
996 "Failed to enable MMC clocks during resume\n");
1001 #define omap_mmc_suspend NULL
1002 #define omap_mmc_resume NULL
1005 static struct platform_driver omap_mmc_driver
= {
1006 .probe
= omap_mmc_probe
,
1007 .remove
= omap_mmc_remove
,
1008 .suspend
= omap_mmc_suspend
,
1009 .resume
= omap_mmc_resume
,
1011 .name
= DRIVER_NAME
,
1012 .owner
= THIS_MODULE
,
1016 static int __init
omap_mmc_init(void)
1018 /* Register the MMC driver */
1019 return platform_driver_register(&omap_mmc_driver
);
1022 static void __exit
omap_mmc_cleanup(void)
1024 /* Unregister MMC driver */
1025 platform_driver_unregister(&omap_mmc_driver
);
1028 module_init(omap_mmc_init
);
1029 module_exit(omap_mmc_cleanup
);
1031 MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
1032 MODULE_LICENSE("GPL");
1033 MODULE_ALIAS("platform:" DRIVER_NAME
);
1034 MODULE_AUTHOR("Texas Instruments Inc");