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/kernel.h>
21 #include <linux/debugfs.h>
22 #include <linux/seq_file.h>
23 #include <linux/interrupt.h>
24 #include <linux/delay.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/platform_device.h>
27 #include <linux/timer.h>
28 #include <linux/clk.h>
29 #include <linux/mmc/host.h>
30 #include <linux/mmc/core.h>
31 #include <linux/mmc/mmc.h>
33 #include <linux/semaphore.h>
34 #include <linux/gpio.h>
35 #include <linux/regulator/consumer.h>
36 #include <linux/pm_runtime.h>
38 #include <mach/hardware.h>
39 #include <plat/board.h>
43 /* OMAP HSMMC Host Controller Registers */
44 #define OMAP_HSMMC_SYSCONFIG 0x0010
45 #define OMAP_HSMMC_SYSSTATUS 0x0014
46 #define OMAP_HSMMC_CON 0x002C
47 #define OMAP_HSMMC_BLK 0x0104
48 #define OMAP_HSMMC_ARG 0x0108
49 #define OMAP_HSMMC_CMD 0x010C
50 #define OMAP_HSMMC_RSP10 0x0110
51 #define OMAP_HSMMC_RSP32 0x0114
52 #define OMAP_HSMMC_RSP54 0x0118
53 #define OMAP_HSMMC_RSP76 0x011C
54 #define OMAP_HSMMC_DATA 0x0120
55 #define OMAP_HSMMC_HCTL 0x0128
56 #define OMAP_HSMMC_SYSCTL 0x012C
57 #define OMAP_HSMMC_STAT 0x0130
58 #define OMAP_HSMMC_IE 0x0134
59 #define OMAP_HSMMC_ISE 0x0138
60 #define OMAP_HSMMC_CAPA 0x0140
62 #define VS18 (1 << 26)
63 #define VS30 (1 << 25)
64 #define SDVS18 (0x5 << 9)
65 #define SDVS30 (0x6 << 9)
66 #define SDVS33 (0x7 << 9)
67 #define SDVS_MASK 0x00000E00
68 #define SDVSCLR 0xFFFFF1FF
69 #define SDVSDET 0x00000400
76 #define CLKD_MASK 0x0000FFC0
78 #define DTO_MASK 0x000F0000
80 #define INT_EN_MASK 0x307F0033
81 #define BWR_ENABLE (1 << 4)
82 #define BRR_ENABLE (1 << 5)
83 #define DTO_ENABLE (1 << 20)
84 #define INIT_STREAM (1 << 1)
85 #define DP_SELECT (1 << 21)
90 #define FOUR_BIT (1 << 1)
96 #define CMD_TIMEOUT (1 << 16)
97 #define DATA_TIMEOUT (1 << 20)
98 #define CMD_CRC (1 << 17)
99 #define DATA_CRC (1 << 21)
100 #define CARD_ERR (1 << 28)
101 #define STAT_CLEAR 0xFFFFFFFF
102 #define INIT_STREAM_CMD 0x00000000
103 #define DUAL_VOLT_OCR_BIT 7
104 #define SRC (1 << 25)
105 #define SRD (1 << 26)
106 #define SOFTRESET (1 << 1)
107 #define RESETDONE (1 << 0)
110 * FIXME: Most likely all the data using these _DEVID defines should come
111 * from the platform_data, or implemented in controller and slot specific
114 #define OMAP_MMC1_DEVID 0
115 #define OMAP_MMC2_DEVID 1
116 #define OMAP_MMC3_DEVID 2
117 #define OMAP_MMC4_DEVID 3
118 #define OMAP_MMC5_DEVID 4
120 #define MMC_AUTOSUSPEND_DELAY 100
121 #define MMC_TIMEOUT_MS 20
122 #define OMAP_MMC_MIN_CLOCK 400000
123 #define OMAP_MMC_MAX_CLOCK 52000000
124 #define DRIVER_NAME "omap_hsmmc"
127 * One controller can have multiple slots, like on some omap boards using
128 * omap.c controller driver. Luckily this is not currently done on any known
129 * omap_hsmmc.c device.
131 #define mmc_slot(host) (host->pdata->slots[host->slot_id])
134 * MMC Host controller read/write API's
136 #define OMAP_HSMMC_READ(base, reg) \
137 __raw_readl((base) + OMAP_HSMMC_##reg)
139 #define OMAP_HSMMC_WRITE(base, reg, val) \
140 __raw_writel((val), (base) + OMAP_HSMMC_##reg)
142 struct omap_hsmmc_next
{
143 unsigned int dma_len
;
147 struct omap_hsmmc_host
{
149 struct mmc_host
*mmc
;
150 struct mmc_request
*mrq
;
151 struct mmc_command
*cmd
;
152 struct mmc_data
*data
;
156 * vcc == configured supply
157 * vcc_aux == optional
158 * - MMC1, supply for DAT4..DAT7
159 * - MMC2/MMC2, external level shifter voltage supply, for
160 * chip (SDIO, eMMC, etc) or transceiver (MMC2 only)
162 struct regulator
*vcc
;
163 struct regulator
*vcc_aux
;
165 resource_size_t mapbase
;
166 spinlock_t irq_lock
; /* Prevent races with irq handler */
168 unsigned int dma_len
;
169 unsigned int dma_sg_idx
;
170 unsigned char bus_mode
;
171 unsigned char power_mode
;
177 int dma_line_tx
, dma_line_rx
;
188 struct omap_hsmmc_next next_data
;
190 struct omap_mmc_platform_data
*pdata
;
193 static int omap_hsmmc_card_detect(struct device
*dev
, int slot
)
195 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
197 /* NOTE: assumes card detect signal is active-low */
198 return !gpio_get_value_cansleep(mmc
->slots
[0].switch_pin
);
201 static int omap_hsmmc_get_wp(struct device
*dev
, int slot
)
203 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
205 /* NOTE: assumes write protect signal is active-high */
206 return gpio_get_value_cansleep(mmc
->slots
[0].gpio_wp
);
209 static int omap_hsmmc_get_cover_state(struct device
*dev
, int slot
)
211 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
213 /* NOTE: assumes card detect signal is active-low */
214 return !gpio_get_value_cansleep(mmc
->slots
[0].switch_pin
);
219 static int omap_hsmmc_suspend_cdirq(struct device
*dev
, int slot
)
221 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
223 disable_irq(mmc
->slots
[0].card_detect_irq
);
227 static int omap_hsmmc_resume_cdirq(struct device
*dev
, int slot
)
229 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
231 enable_irq(mmc
->slots
[0].card_detect_irq
);
237 #define omap_hsmmc_suspend_cdirq NULL
238 #define omap_hsmmc_resume_cdirq NULL
242 #ifdef CONFIG_REGULATOR
244 static int omap_hsmmc_1_set_power(struct device
*dev
, int slot
, int power_on
,
247 struct omap_hsmmc_host
*host
=
248 platform_get_drvdata(to_platform_device(dev
));
251 if (mmc_slot(host
).before_set_reg
)
252 mmc_slot(host
).before_set_reg(dev
, slot
, power_on
, vdd
);
255 ret
= mmc_regulator_set_ocr(host
->mmc
, host
->vcc
, vdd
);
257 ret
= mmc_regulator_set_ocr(host
->mmc
, host
->vcc
, 0);
259 if (mmc_slot(host
).after_set_reg
)
260 mmc_slot(host
).after_set_reg(dev
, slot
, power_on
, vdd
);
265 static int omap_hsmmc_235_set_power(struct device
*dev
, int slot
, int power_on
,
268 struct omap_hsmmc_host
*host
=
269 platform_get_drvdata(to_platform_device(dev
));
273 * If we don't see a Vcc regulator, assume it's a fixed
274 * voltage always-on regulator.
279 if (mmc_slot(host
).before_set_reg
)
280 mmc_slot(host
).before_set_reg(dev
, slot
, power_on
, vdd
);
283 * Assume Vcc regulator is used only to power the card ... OMAP
284 * VDDS is used to power the pins, optionally with a transceiver to
285 * support cards using voltages other than VDDS (1.8V nominal). When a
286 * transceiver is used, DAT3..7 are muxed as transceiver control pins.
288 * In some cases this regulator won't support enable/disable;
289 * e.g. it's a fixed rail for a WLAN chip.
291 * In other cases vcc_aux switches interface power. Example, for
292 * eMMC cards it represents VccQ. Sometimes transceivers or SDIO
293 * chips/cards need an interface voltage rail too.
296 ret
= mmc_regulator_set_ocr(host
->mmc
, host
->vcc
, vdd
);
297 /* Enable interface voltage rail, if needed */
298 if (ret
== 0 && host
->vcc_aux
) {
299 ret
= regulator_enable(host
->vcc_aux
);
301 ret
= mmc_regulator_set_ocr(host
->mmc
,
305 /* Shut down the rail */
307 ret
= regulator_disable(host
->vcc_aux
);
309 /* Then proceed to shut down the local regulator */
310 ret
= mmc_regulator_set_ocr(host
->mmc
,
315 if (mmc_slot(host
).after_set_reg
)
316 mmc_slot(host
).after_set_reg(dev
, slot
, power_on
, vdd
);
321 static int omap_hsmmc_4_set_power(struct device
*dev
, int slot
, int power_on
,
327 static int omap_hsmmc_1_set_sleep(struct device
*dev
, int slot
, int sleep
,
328 int vdd
, int cardsleep
)
330 struct omap_hsmmc_host
*host
=
331 platform_get_drvdata(to_platform_device(dev
));
332 int mode
= sleep
? REGULATOR_MODE_STANDBY
: REGULATOR_MODE_NORMAL
;
334 return regulator_set_mode(host
->vcc
, mode
);
337 static int omap_hsmmc_235_set_sleep(struct device
*dev
, int slot
, int sleep
,
338 int vdd
, int cardsleep
)
340 struct omap_hsmmc_host
*host
=
341 platform_get_drvdata(to_platform_device(dev
));
345 * If we don't see a Vcc regulator, assume it's a fixed
346 * voltage always-on regulator.
351 mode
= sleep
? REGULATOR_MODE_STANDBY
: REGULATOR_MODE_NORMAL
;
354 return regulator_set_mode(host
->vcc
, mode
);
357 /* VCC can be turned off if card is asleep */
359 err
= mmc_regulator_set_ocr(host
->mmc
, host
->vcc
, 0);
361 err
= mmc_regulator_set_ocr(host
->mmc
, host
->vcc
, vdd
);
363 err
= regulator_set_mode(host
->vcc
, mode
);
367 if (!mmc_slot(host
).vcc_aux_disable_is_sleep
)
368 return regulator_set_mode(host
->vcc_aux
, mode
);
371 return regulator_disable(host
->vcc_aux
);
373 return regulator_enable(host
->vcc_aux
);
376 static int omap_hsmmc_4_set_sleep(struct device
*dev
, int slot
, int sleep
,
377 int vdd
, int cardsleep
)
382 static int omap_hsmmc_reg_get(struct omap_hsmmc_host
*host
)
384 struct regulator
*reg
;
389 case OMAP_MMC1_DEVID
:
390 /* On-chip level shifting via PBIAS0/PBIAS1 */
391 mmc_slot(host
).set_power
= omap_hsmmc_1_set_power
;
392 mmc_slot(host
).set_sleep
= omap_hsmmc_1_set_sleep
;
394 case OMAP_MMC2_DEVID
:
395 case OMAP_MMC3_DEVID
:
396 case OMAP_MMC5_DEVID
:
397 /* Off-chip level shifting, or none */
398 mmc_slot(host
).set_power
= omap_hsmmc_235_set_power
;
399 mmc_slot(host
).set_sleep
= omap_hsmmc_235_set_sleep
;
401 case OMAP_MMC4_DEVID
:
402 mmc_slot(host
).set_power
= omap_hsmmc_4_set_power
;
403 mmc_slot(host
).set_sleep
= omap_hsmmc_4_set_sleep
;
405 pr_err("MMC%d configuration not supported!\n", host
->id
);
409 reg
= regulator_get(host
->dev
, "vmmc");
411 dev_dbg(host
->dev
, "vmmc regulator missing\n");
413 * HACK: until fixed.c regulator is usable,
414 * we don't require a main regulator
417 if (host
->id
== OMAP_MMC1_DEVID
) {
423 ocr_value
= mmc_regulator_get_ocrmask(reg
);
424 if (!mmc_slot(host
).ocr_mask
) {
425 mmc_slot(host
).ocr_mask
= ocr_value
;
427 if (!(mmc_slot(host
).ocr_mask
& ocr_value
)) {
428 pr_err("MMC%d ocrmask %x is not supported\n",
429 host
->id
, mmc_slot(host
).ocr_mask
);
430 mmc_slot(host
).ocr_mask
= 0;
435 /* Allow an aux regulator */
436 reg
= regulator_get(host
->dev
, "vmmc_aux");
437 host
->vcc_aux
= IS_ERR(reg
) ? NULL
: reg
;
439 /* For eMMC do not power off when not in sleep state */
440 if (mmc_slot(host
).no_regulator_off_init
)
443 * UGLY HACK: workaround regulator framework bugs.
444 * When the bootloader leaves a supply active, it's
445 * initialized with zero usecount ... and we can't
446 * disable it without first enabling it. Until the
447 * framework is fixed, we need a workaround like this
448 * (which is safe for MMC, but not in general).
450 if (regulator_is_enabled(host
->vcc
) > 0 ||
451 (host
->vcc_aux
&& regulator_is_enabled(host
->vcc_aux
))) {
452 int vdd
= ffs(mmc_slot(host
).ocr_mask
) - 1;
454 mmc_slot(host
).set_power(host
->dev
, host
->slot_id
,
456 mmc_slot(host
).set_power(host
->dev
, host
->slot_id
,
464 mmc_slot(host
).set_power
= NULL
;
465 mmc_slot(host
).set_sleep
= NULL
;
469 static void omap_hsmmc_reg_put(struct omap_hsmmc_host
*host
)
471 regulator_put(host
->vcc
);
472 regulator_put(host
->vcc_aux
);
473 mmc_slot(host
).set_power
= NULL
;
474 mmc_slot(host
).set_sleep
= NULL
;
477 static inline int omap_hsmmc_have_reg(void)
484 static inline int omap_hsmmc_reg_get(struct omap_hsmmc_host
*host
)
489 static inline void omap_hsmmc_reg_put(struct omap_hsmmc_host
*host
)
493 static inline int omap_hsmmc_have_reg(void)
500 static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data
*pdata
)
504 if (gpio_is_valid(pdata
->slots
[0].switch_pin
)) {
505 if (pdata
->slots
[0].cover
)
506 pdata
->slots
[0].get_cover_state
=
507 omap_hsmmc_get_cover_state
;
509 pdata
->slots
[0].card_detect
= omap_hsmmc_card_detect
;
510 pdata
->slots
[0].card_detect_irq
=
511 gpio_to_irq(pdata
->slots
[0].switch_pin
);
512 ret
= gpio_request(pdata
->slots
[0].switch_pin
, "mmc_cd");
515 ret
= gpio_direction_input(pdata
->slots
[0].switch_pin
);
519 pdata
->slots
[0].switch_pin
= -EINVAL
;
521 if (gpio_is_valid(pdata
->slots
[0].gpio_wp
)) {
522 pdata
->slots
[0].get_ro
= omap_hsmmc_get_wp
;
523 ret
= gpio_request(pdata
->slots
[0].gpio_wp
, "mmc_wp");
526 ret
= gpio_direction_input(pdata
->slots
[0].gpio_wp
);
530 pdata
->slots
[0].gpio_wp
= -EINVAL
;
535 gpio_free(pdata
->slots
[0].gpio_wp
);
537 if (gpio_is_valid(pdata
->slots
[0].switch_pin
))
539 gpio_free(pdata
->slots
[0].switch_pin
);
543 static void omap_hsmmc_gpio_free(struct omap_mmc_platform_data
*pdata
)
545 if (gpio_is_valid(pdata
->slots
[0].gpio_wp
))
546 gpio_free(pdata
->slots
[0].gpio_wp
);
547 if (gpio_is_valid(pdata
->slots
[0].switch_pin
))
548 gpio_free(pdata
->slots
[0].switch_pin
);
552 * Start clock to the card
554 static void omap_hsmmc_start_clock(struct omap_hsmmc_host
*host
)
556 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
,
557 OMAP_HSMMC_READ(host
->base
, SYSCTL
) | CEN
);
561 * Stop clock to the card
563 static void omap_hsmmc_stop_clock(struct omap_hsmmc_host
*host
)
565 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
,
566 OMAP_HSMMC_READ(host
->base
, SYSCTL
) & ~CEN
);
567 if ((OMAP_HSMMC_READ(host
->base
, SYSCTL
) & CEN
) != 0x0)
568 dev_dbg(mmc_dev(host
->mmc
), "MMC Clock is not stoped\n");
571 static void omap_hsmmc_enable_irq(struct omap_hsmmc_host
*host
,
572 struct mmc_command
*cmd
)
574 unsigned int irq_mask
;
577 irq_mask
= INT_EN_MASK
& ~(BRR_ENABLE
| BWR_ENABLE
);
579 irq_mask
= INT_EN_MASK
;
581 /* Disable timeout for erases */
582 if (cmd
->opcode
== MMC_ERASE
)
583 irq_mask
&= ~DTO_ENABLE
;
585 OMAP_HSMMC_WRITE(host
->base
, STAT
, STAT_CLEAR
);
586 OMAP_HSMMC_WRITE(host
->base
, ISE
, irq_mask
);
587 OMAP_HSMMC_WRITE(host
->base
, IE
, irq_mask
);
590 static void omap_hsmmc_disable_irq(struct omap_hsmmc_host
*host
)
592 OMAP_HSMMC_WRITE(host
->base
, ISE
, 0);
593 OMAP_HSMMC_WRITE(host
->base
, IE
, 0);
594 OMAP_HSMMC_WRITE(host
->base
, STAT
, STAT_CLEAR
);
597 /* Calculate divisor for the given clock frequency */
598 static u16
calc_divisor(struct omap_hsmmc_host
*host
, struct mmc_ios
*ios
)
603 dsor
= DIV_ROUND_UP(clk_get_rate(host
->fclk
), ios
->clock
);
611 static void omap_hsmmc_set_clock(struct omap_hsmmc_host
*host
)
613 struct mmc_ios
*ios
= &host
->mmc
->ios
;
614 unsigned long regval
;
615 unsigned long timeout
;
617 dev_dbg(mmc_dev(host
->mmc
), "Set clock to %uHz\n", ios
->clock
);
619 omap_hsmmc_stop_clock(host
);
621 regval
= OMAP_HSMMC_READ(host
->base
, SYSCTL
);
622 regval
= regval
& ~(CLKD_MASK
| DTO_MASK
);
623 regval
= regval
| (calc_divisor(host
, ios
) << 6) | (DTO
<< 16);
624 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
, regval
);
625 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
,
626 OMAP_HSMMC_READ(host
->base
, SYSCTL
) | ICE
);
628 /* Wait till the ICS bit is set */
629 timeout
= jiffies
+ msecs_to_jiffies(MMC_TIMEOUT_MS
);
630 while ((OMAP_HSMMC_READ(host
->base
, SYSCTL
) & ICS
) != ICS
631 && time_before(jiffies
, timeout
))
634 omap_hsmmc_start_clock(host
);
637 static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host
*host
)
639 struct mmc_ios
*ios
= &host
->mmc
->ios
;
642 con
= OMAP_HSMMC_READ(host
->base
, CON
);
643 switch (ios
->bus_width
) {
644 case MMC_BUS_WIDTH_8
:
645 OMAP_HSMMC_WRITE(host
->base
, CON
, con
| DW8
);
647 case MMC_BUS_WIDTH_4
:
648 OMAP_HSMMC_WRITE(host
->base
, CON
, con
& ~DW8
);
649 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
650 OMAP_HSMMC_READ(host
->base
, HCTL
) | FOUR_BIT
);
652 case MMC_BUS_WIDTH_1
:
653 OMAP_HSMMC_WRITE(host
->base
, CON
, con
& ~DW8
);
654 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
655 OMAP_HSMMC_READ(host
->base
, HCTL
) & ~FOUR_BIT
);
660 static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host
*host
)
662 struct mmc_ios
*ios
= &host
->mmc
->ios
;
665 con
= OMAP_HSMMC_READ(host
->base
, CON
);
666 if (ios
->bus_mode
== MMC_BUSMODE_OPENDRAIN
)
667 OMAP_HSMMC_WRITE(host
->base
, CON
, con
| OD
);
669 OMAP_HSMMC_WRITE(host
->base
, CON
, con
& ~OD
);
675 * Restore the MMC host context, if it was lost as result of a
676 * power state change.
678 static int omap_hsmmc_context_restore(struct omap_hsmmc_host
*host
)
680 struct mmc_ios
*ios
= &host
->mmc
->ios
;
681 struct omap_mmc_platform_data
*pdata
= host
->pdata
;
682 int context_loss
= 0;
684 unsigned long timeout
;
686 if (pdata
->get_context_loss_count
) {
687 context_loss
= pdata
->get_context_loss_count(host
->dev
);
688 if (context_loss
< 0)
692 dev_dbg(mmc_dev(host
->mmc
), "context was %slost\n",
693 context_loss
== host
->context_loss
? "not " : "");
694 if (host
->context_loss
== context_loss
)
697 /* Wait for hardware reset */
698 timeout
= jiffies
+ msecs_to_jiffies(MMC_TIMEOUT_MS
);
699 while ((OMAP_HSMMC_READ(host
->base
, SYSSTATUS
) & RESETDONE
) != RESETDONE
700 && time_before(jiffies
, timeout
))
703 /* Do software reset */
704 OMAP_HSMMC_WRITE(host
->base
, SYSCONFIG
, SOFTRESET
);
705 timeout
= jiffies
+ msecs_to_jiffies(MMC_TIMEOUT_MS
);
706 while ((OMAP_HSMMC_READ(host
->base
, SYSSTATUS
) & RESETDONE
) != RESETDONE
707 && time_before(jiffies
, timeout
))
710 OMAP_HSMMC_WRITE(host
->base
, SYSCONFIG
,
711 OMAP_HSMMC_READ(host
->base
, SYSCONFIG
) | AUTOIDLE
);
713 if (host
->id
== OMAP_MMC1_DEVID
) {
714 if (host
->power_mode
!= MMC_POWER_OFF
&&
715 (1 << ios
->vdd
) <= MMC_VDD_23_24
)
725 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
726 OMAP_HSMMC_READ(host
->base
, HCTL
) | hctl
);
728 OMAP_HSMMC_WRITE(host
->base
, CAPA
,
729 OMAP_HSMMC_READ(host
->base
, CAPA
) | capa
);
731 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
732 OMAP_HSMMC_READ(host
->base
, HCTL
) | SDBP
);
734 timeout
= jiffies
+ msecs_to_jiffies(MMC_TIMEOUT_MS
);
735 while ((OMAP_HSMMC_READ(host
->base
, HCTL
) & SDBP
) != SDBP
736 && time_before(jiffies
, timeout
))
739 omap_hsmmc_disable_irq(host
);
741 /* Do not initialize card-specific things if the power is off */
742 if (host
->power_mode
== MMC_POWER_OFF
)
745 omap_hsmmc_set_bus_width(host
);
747 omap_hsmmc_set_clock(host
);
749 omap_hsmmc_set_bus_mode(host
);
752 host
->context_loss
= context_loss
;
754 dev_dbg(mmc_dev(host
->mmc
), "context is restored\n");
759 * Save the MMC host context (store the number of power state changes so far).
761 static void omap_hsmmc_context_save(struct omap_hsmmc_host
*host
)
763 struct omap_mmc_platform_data
*pdata
= host
->pdata
;
766 if (pdata
->get_context_loss_count
) {
767 context_loss
= pdata
->get_context_loss_count(host
->dev
);
768 if (context_loss
< 0)
770 host
->context_loss
= context_loss
;
776 static int omap_hsmmc_context_restore(struct omap_hsmmc_host
*host
)
781 static void omap_hsmmc_context_save(struct omap_hsmmc_host
*host
)
788 * Send init stream sequence to card
789 * before sending IDLE command
791 static void send_init_stream(struct omap_hsmmc_host
*host
)
794 unsigned long timeout
;
796 if (host
->protect_card
)
799 disable_irq(host
->irq
);
801 OMAP_HSMMC_WRITE(host
->base
, IE
, INT_EN_MASK
);
802 OMAP_HSMMC_WRITE(host
->base
, CON
,
803 OMAP_HSMMC_READ(host
->base
, CON
) | INIT_STREAM
);
804 OMAP_HSMMC_WRITE(host
->base
, CMD
, INIT_STREAM_CMD
);
806 timeout
= jiffies
+ msecs_to_jiffies(MMC_TIMEOUT_MS
);
807 while ((reg
!= CC
) && time_before(jiffies
, timeout
))
808 reg
= OMAP_HSMMC_READ(host
->base
, STAT
) & CC
;
810 OMAP_HSMMC_WRITE(host
->base
, CON
,
811 OMAP_HSMMC_READ(host
->base
, CON
) & ~INIT_STREAM
);
813 OMAP_HSMMC_WRITE(host
->base
, STAT
, STAT_CLEAR
);
814 OMAP_HSMMC_READ(host
->base
, STAT
);
816 enable_irq(host
->irq
);
820 int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host
*host
)
824 if (mmc_slot(host
).get_cover_state
)
825 r
= mmc_slot(host
).get_cover_state(host
->dev
, host
->slot_id
);
830 omap_hsmmc_show_cover_switch(struct device
*dev
, struct device_attribute
*attr
,
833 struct mmc_host
*mmc
= container_of(dev
, struct mmc_host
, class_dev
);
834 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
836 return sprintf(buf
, "%s\n",
837 omap_hsmmc_cover_is_closed(host
) ? "closed" : "open");
840 static DEVICE_ATTR(cover_switch
, S_IRUGO
, omap_hsmmc_show_cover_switch
, NULL
);
843 omap_hsmmc_show_slot_name(struct device
*dev
, struct device_attribute
*attr
,
846 struct mmc_host
*mmc
= container_of(dev
, struct mmc_host
, class_dev
);
847 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
849 return sprintf(buf
, "%s\n", mmc_slot(host
).name
);
852 static DEVICE_ATTR(slot_name
, S_IRUGO
, omap_hsmmc_show_slot_name
, NULL
);
855 * Configure the response type and send the cmd.
858 omap_hsmmc_start_command(struct omap_hsmmc_host
*host
, struct mmc_command
*cmd
,
859 struct mmc_data
*data
)
861 int cmdreg
= 0, resptype
= 0, cmdtype
= 0;
863 dev_dbg(mmc_dev(host
->mmc
), "%s: CMD%d, argument 0x%08x\n",
864 mmc_hostname(host
->mmc
), cmd
->opcode
, cmd
->arg
);
867 omap_hsmmc_enable_irq(host
, cmd
);
869 host
->response_busy
= 0;
870 if (cmd
->flags
& MMC_RSP_PRESENT
) {
871 if (cmd
->flags
& MMC_RSP_136
)
873 else if (cmd
->flags
& MMC_RSP_BUSY
) {
875 host
->response_busy
= 1;
881 * Unlike OMAP1 controller, the cmdtype does not seem to be based on
882 * ac, bc, adtc, bcr. Only commands ending an open ended transfer need
883 * a val of 0x3, rest 0x0.
885 if (cmd
== host
->mrq
->stop
)
888 cmdreg
= (cmd
->opcode
<< 24) | (resptype
<< 16) | (cmdtype
<< 22);
891 cmdreg
|= DP_SELECT
| MSBS
| BCE
;
892 if (data
->flags
& MMC_DATA_READ
)
901 host
->req_in_progress
= 1;
903 OMAP_HSMMC_WRITE(host
->base
, ARG
, cmd
->arg
);
904 OMAP_HSMMC_WRITE(host
->base
, CMD
, cmdreg
);
908 omap_hsmmc_get_dma_dir(struct omap_hsmmc_host
*host
, struct mmc_data
*data
)
910 if (data
->flags
& MMC_DATA_WRITE
)
911 return DMA_TO_DEVICE
;
913 return DMA_FROM_DEVICE
;
916 static void omap_hsmmc_request_done(struct omap_hsmmc_host
*host
, struct mmc_request
*mrq
)
920 spin_lock(&host
->irq_lock
);
921 host
->req_in_progress
= 0;
922 dma_ch
= host
->dma_ch
;
923 spin_unlock(&host
->irq_lock
);
925 omap_hsmmc_disable_irq(host
);
926 /* Do not complete the request if DMA is still in progress */
927 if (mrq
->data
&& host
->use_dma
&& dma_ch
!= -1)
930 mmc_request_done(host
->mmc
, mrq
);
934 * Notify the transfer complete to MMC core
937 omap_hsmmc_xfer_done(struct omap_hsmmc_host
*host
, struct mmc_data
*data
)
940 struct mmc_request
*mrq
= host
->mrq
;
942 /* TC before CC from CMD6 - don't know why, but it happens */
943 if (host
->cmd
&& host
->cmd
->opcode
== 6 &&
944 host
->response_busy
) {
945 host
->response_busy
= 0;
949 omap_hsmmc_request_done(host
, mrq
);
956 data
->bytes_xfered
+= data
->blocks
* (data
->blksz
);
958 data
->bytes_xfered
= 0;
961 omap_hsmmc_request_done(host
, data
->mrq
);
964 omap_hsmmc_start_command(host
, data
->stop
, NULL
);
968 * Notify the core about command completion
971 omap_hsmmc_cmd_done(struct omap_hsmmc_host
*host
, struct mmc_command
*cmd
)
975 if (cmd
->flags
& MMC_RSP_PRESENT
) {
976 if (cmd
->flags
& MMC_RSP_136
) {
977 /* response type 2 */
978 cmd
->resp
[3] = OMAP_HSMMC_READ(host
->base
, RSP10
);
979 cmd
->resp
[2] = OMAP_HSMMC_READ(host
->base
, RSP32
);
980 cmd
->resp
[1] = OMAP_HSMMC_READ(host
->base
, RSP54
);
981 cmd
->resp
[0] = OMAP_HSMMC_READ(host
->base
, RSP76
);
983 /* response types 1, 1b, 3, 4, 5, 6 */
984 cmd
->resp
[0] = OMAP_HSMMC_READ(host
->base
, RSP10
);
987 if ((host
->data
== NULL
&& !host
->response_busy
) || cmd
->error
)
988 omap_hsmmc_request_done(host
, cmd
->mrq
);
992 * DMA clean up for command errors
994 static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host
*host
, int errno
)
998 host
->data
->error
= errno
;
1000 spin_lock(&host
->irq_lock
);
1001 dma_ch
= host
->dma_ch
;
1003 spin_unlock(&host
->irq_lock
);
1005 if (host
->use_dma
&& dma_ch
!= -1) {
1006 dma_unmap_sg(mmc_dev(host
->mmc
), host
->data
->sg
,
1008 omap_hsmmc_get_dma_dir(host
, host
->data
));
1009 omap_free_dma(dma_ch
);
1010 host
->data
->host_cookie
= 0;
1016 * Readable error output
1018 #ifdef CONFIG_MMC_DEBUG
1019 static void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host
*host
, u32 status
)
1021 /* --- means reserved bit without definition at documentation */
1022 static const char *omap_hsmmc_status_bits
[] = {
1023 "CC" , "TC" , "BGE", "---", "BWR" , "BRR" , "---" , "---" ,
1024 "CIRQ", "OBI" , "---", "---", "---" , "---" , "---" , "ERRI",
1025 "CTO" , "CCRC", "CEB", "CIE", "DTO" , "DCRC", "DEB" , "---" ,
1026 "ACE" , "---" , "---", "---", "CERR", "BADA", "---" , "---"
1032 len
= sprintf(buf
, "MMC IRQ 0x%x :", status
);
1035 for (i
= 0; i
< ARRAY_SIZE(omap_hsmmc_status_bits
); i
++)
1036 if (status
& (1 << i
)) {
1037 len
= sprintf(buf
, " %s", omap_hsmmc_status_bits
[i
]);
1041 dev_dbg(mmc_dev(host
->mmc
), "%s\n", res
);
1044 static inline void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host
*host
,
1048 #endif /* CONFIG_MMC_DEBUG */
1051 * MMC controller internal state machines reset
1053 * Used to reset command or data internal state machines, using respectively
1054 * SRC or SRD bit of SYSCTL register
1055 * Can be called from interrupt context
1057 static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host
*host
,
1060 unsigned long i
= 0;
1061 unsigned long limit
= (loops_per_jiffy
*
1062 msecs_to_jiffies(MMC_TIMEOUT_MS
));
1064 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
,
1065 OMAP_HSMMC_READ(host
->base
, SYSCTL
) | bit
);
1068 * OMAP4 ES2 and greater has an updated reset logic.
1069 * Monitor a 0->1 transition first
1071 if (mmc_slot(host
).features
& HSMMC_HAS_UPDATED_RESET
) {
1072 while ((!(OMAP_HSMMC_READ(host
->base
, SYSCTL
) & bit
))
1078 while ((OMAP_HSMMC_READ(host
->base
, SYSCTL
) & bit
) &&
1082 if (OMAP_HSMMC_READ(host
->base
, SYSCTL
) & bit
)
1083 dev_err(mmc_dev(host
->mmc
),
1084 "Timeout waiting on controller reset in %s\n",
1088 static void omap_hsmmc_do_irq(struct omap_hsmmc_host
*host
, int status
)
1090 struct mmc_data
*data
;
1091 int end_cmd
= 0, end_trans
= 0;
1093 if (!host
->req_in_progress
) {
1095 OMAP_HSMMC_WRITE(host
->base
, STAT
, status
);
1096 /* Flush posted write */
1097 status
= OMAP_HSMMC_READ(host
->base
, STAT
);
1098 } while (status
& INT_EN_MASK
);
1103 dev_dbg(mmc_dev(host
->mmc
), "IRQ Status is %x\n", status
);
1106 omap_hsmmc_dbg_report_irq(host
, status
);
1107 if ((status
& CMD_TIMEOUT
) ||
1108 (status
& CMD_CRC
)) {
1110 if (status
& CMD_TIMEOUT
) {
1111 omap_hsmmc_reset_controller_fsm(host
,
1113 host
->cmd
->error
= -ETIMEDOUT
;
1115 host
->cmd
->error
= -EILSEQ
;
1119 if (host
->data
|| host
->response_busy
) {
1121 omap_hsmmc_dma_cleanup(host
,
1123 host
->response_busy
= 0;
1124 omap_hsmmc_reset_controller_fsm(host
, SRD
);
1127 if ((status
& DATA_TIMEOUT
) ||
1128 (status
& DATA_CRC
)) {
1129 if (host
->data
|| host
->response_busy
) {
1130 int err
= (status
& DATA_TIMEOUT
) ?
1131 -ETIMEDOUT
: -EILSEQ
;
1134 omap_hsmmc_dma_cleanup(host
, err
);
1136 host
->mrq
->cmd
->error
= err
;
1137 host
->response_busy
= 0;
1138 omap_hsmmc_reset_controller_fsm(host
, SRD
);
1142 if (status
& CARD_ERR
) {
1143 dev_dbg(mmc_dev(host
->mmc
),
1144 "Ignoring card err CMD%d\n", host
->cmd
->opcode
);
1152 OMAP_HSMMC_WRITE(host
->base
, STAT
, status
);
1154 if (end_cmd
|| ((status
& CC
) && host
->cmd
))
1155 omap_hsmmc_cmd_done(host
, host
->cmd
);
1156 if ((end_trans
|| (status
& TC
)) && host
->mrq
)
1157 omap_hsmmc_xfer_done(host
, data
);
1161 * MMC controller IRQ handler
1163 static irqreturn_t
omap_hsmmc_irq(int irq
, void *dev_id
)
1165 struct omap_hsmmc_host
*host
= dev_id
;
1168 status
= OMAP_HSMMC_READ(host
->base
, STAT
);
1170 omap_hsmmc_do_irq(host
, status
);
1171 /* Flush posted write */
1172 status
= OMAP_HSMMC_READ(host
->base
, STAT
);
1173 } while (status
& INT_EN_MASK
);
1178 static void set_sd_bus_power(struct omap_hsmmc_host
*host
)
1182 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
1183 OMAP_HSMMC_READ(host
->base
, HCTL
) | SDBP
);
1184 for (i
= 0; i
< loops_per_jiffy
; i
++) {
1185 if (OMAP_HSMMC_READ(host
->base
, HCTL
) & SDBP
)
1192 * Switch MMC interface voltage ... only relevant for MMC1.
1194 * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
1195 * The MMC2 transceiver controls are used instead of DAT4..DAT7.
1196 * Some chips, like eMMC ones, use internal transceivers.
1198 static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host
*host
, int vdd
)
1203 /* Disable the clocks */
1204 pm_runtime_put_sync(host
->dev
);
1205 if (host
->got_dbclk
)
1206 clk_disable(host
->dbclk
);
1208 /* Turn the power off */
1209 ret
= mmc_slot(host
).set_power(host
->dev
, host
->slot_id
, 0, 0);
1211 /* Turn the power ON with given VDD 1.8 or 3.0v */
1213 ret
= mmc_slot(host
).set_power(host
->dev
, host
->slot_id
, 1,
1215 pm_runtime_get_sync(host
->dev
);
1216 if (host
->got_dbclk
)
1217 clk_enable(host
->dbclk
);
1222 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
1223 OMAP_HSMMC_READ(host
->base
, HCTL
) & SDVSCLR
);
1224 reg_val
= OMAP_HSMMC_READ(host
->base
, HCTL
);
1227 * If a MMC dual voltage card is detected, the set_ios fn calls
1228 * this fn with VDD bit set for 1.8V. Upon card removal from the
1229 * slot, omap_hsmmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
1231 * Cope with a bit of slop in the range ... per data sheets:
1232 * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
1233 * but recommended values are 1.71V to 1.89V
1234 * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
1235 * but recommended values are 2.7V to 3.3V
1237 * Board setup code shouldn't permit anything very out-of-range.
1238 * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
1239 * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
1241 if ((1 << vdd
) <= MMC_VDD_23_24
)
1246 OMAP_HSMMC_WRITE(host
->base
, HCTL
, reg_val
);
1247 set_sd_bus_power(host
);
1251 dev_dbg(mmc_dev(host
->mmc
), "Unable to switch operating voltage\n");
1255 /* Protect the card while the cover is open */
1256 static void omap_hsmmc_protect_card(struct omap_hsmmc_host
*host
)
1258 if (!mmc_slot(host
).get_cover_state
)
1261 host
->reqs_blocked
= 0;
1262 if (mmc_slot(host
).get_cover_state(host
->dev
, host
->slot_id
)) {
1263 if (host
->protect_card
) {
1264 pr_info("%s: cover is closed, "
1265 "card is now accessible\n",
1266 mmc_hostname(host
->mmc
));
1267 host
->protect_card
= 0;
1270 if (!host
->protect_card
) {
1271 pr_info("%s: cover is open, "
1272 "card is now inaccessible\n",
1273 mmc_hostname(host
->mmc
));
1274 host
->protect_card
= 1;
1280 * irq handler to notify the core about card insertion/removal
1282 static irqreturn_t
omap_hsmmc_detect(int irq
, void *dev_id
)
1284 struct omap_hsmmc_host
*host
= dev_id
;
1285 struct omap_mmc_slot_data
*slot
= &mmc_slot(host
);
1288 if (host
->suspended
)
1291 sysfs_notify(&host
->mmc
->class_dev
.kobj
, NULL
, "cover_switch");
1293 if (slot
->card_detect
)
1294 carddetect
= slot
->card_detect(host
->dev
, host
->slot_id
);
1296 omap_hsmmc_protect_card(host
);
1297 carddetect
= -ENOSYS
;
1301 mmc_detect_change(host
->mmc
, (HZ
* 200) / 1000);
1303 mmc_detect_change(host
->mmc
, (HZ
* 50) / 1000);
1307 static int omap_hsmmc_get_dma_sync_dev(struct omap_hsmmc_host
*host
,
1308 struct mmc_data
*data
)
1312 if (data
->flags
& MMC_DATA_WRITE
)
1313 sync_dev
= host
->dma_line_tx
;
1315 sync_dev
= host
->dma_line_rx
;
1319 static void omap_hsmmc_config_dma_params(struct omap_hsmmc_host
*host
,
1320 struct mmc_data
*data
,
1321 struct scatterlist
*sgl
)
1323 int blksz
, nblk
, dma_ch
;
1325 dma_ch
= host
->dma_ch
;
1326 if (data
->flags
& MMC_DATA_WRITE
) {
1327 omap_set_dma_dest_params(dma_ch
, 0, OMAP_DMA_AMODE_CONSTANT
,
1328 (host
->mapbase
+ OMAP_HSMMC_DATA
), 0, 0);
1329 omap_set_dma_src_params(dma_ch
, 0, OMAP_DMA_AMODE_POST_INC
,
1330 sg_dma_address(sgl
), 0, 0);
1332 omap_set_dma_src_params(dma_ch
, 0, OMAP_DMA_AMODE_CONSTANT
,
1333 (host
->mapbase
+ OMAP_HSMMC_DATA
), 0, 0);
1334 omap_set_dma_dest_params(dma_ch
, 0, OMAP_DMA_AMODE_POST_INC
,
1335 sg_dma_address(sgl
), 0, 0);
1338 blksz
= host
->data
->blksz
;
1339 nblk
= sg_dma_len(sgl
) / blksz
;
1341 omap_set_dma_transfer_params(dma_ch
, OMAP_DMA_DATA_TYPE_S32
,
1342 blksz
/ 4, nblk
, OMAP_DMA_SYNC_FRAME
,
1343 omap_hsmmc_get_dma_sync_dev(host
, data
),
1344 !(data
->flags
& MMC_DATA_WRITE
));
1346 omap_start_dma(dma_ch
);
1350 * DMA call back function
1352 static void omap_hsmmc_dma_cb(int lch
, u16 ch_status
, void *cb_data
)
1354 struct omap_hsmmc_host
*host
= cb_data
;
1355 struct mmc_data
*data
;
1356 int dma_ch
, req_in_progress
;
1358 if (!(ch_status
& OMAP_DMA_BLOCK_IRQ
)) {
1359 dev_warn(mmc_dev(host
->mmc
), "unexpected dma status %x\n",
1364 spin_lock(&host
->irq_lock
);
1365 if (host
->dma_ch
< 0) {
1366 spin_unlock(&host
->irq_lock
);
1370 data
= host
->mrq
->data
;
1372 if (host
->dma_sg_idx
< host
->dma_len
) {
1373 /* Fire up the next transfer. */
1374 omap_hsmmc_config_dma_params(host
, data
,
1375 data
->sg
+ host
->dma_sg_idx
);
1376 spin_unlock(&host
->irq_lock
);
1380 if (!data
->host_cookie
)
1381 dma_unmap_sg(mmc_dev(host
->mmc
), data
->sg
, data
->sg_len
,
1382 omap_hsmmc_get_dma_dir(host
, data
));
1384 req_in_progress
= host
->req_in_progress
;
1385 dma_ch
= host
->dma_ch
;
1387 spin_unlock(&host
->irq_lock
);
1389 omap_free_dma(dma_ch
);
1391 /* If DMA has finished after TC, complete the request */
1392 if (!req_in_progress
) {
1393 struct mmc_request
*mrq
= host
->mrq
;
1396 mmc_request_done(host
->mmc
, mrq
);
1400 static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host
*host
,
1401 struct mmc_data
*data
,
1402 struct omap_hsmmc_next
*next
)
1406 if (!next
&& data
->host_cookie
&&
1407 data
->host_cookie
!= host
->next_data
.cookie
) {
1408 pr_warning("[%s] invalid cookie: data->host_cookie %d"
1409 " host->next_data.cookie %d\n",
1410 __func__
, data
->host_cookie
, host
->next_data
.cookie
);
1411 data
->host_cookie
= 0;
1414 /* Check if next job is already prepared */
1416 (!next
&& data
->host_cookie
!= host
->next_data
.cookie
)) {
1417 dma_len
= dma_map_sg(mmc_dev(host
->mmc
), data
->sg
,
1419 omap_hsmmc_get_dma_dir(host
, data
));
1422 dma_len
= host
->next_data
.dma_len
;
1423 host
->next_data
.dma_len
= 0;
1431 next
->dma_len
= dma_len
;
1432 data
->host_cookie
= ++next
->cookie
< 0 ? 1 : next
->cookie
;
1434 host
->dma_len
= dma_len
;
1440 * Routine to configure and start DMA for the MMC card
1442 static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host
*host
,
1443 struct mmc_request
*req
)
1445 int dma_ch
= 0, ret
= 0, i
;
1446 struct mmc_data
*data
= req
->data
;
1448 /* Sanity check: all the SG entries must be aligned by block size. */
1449 for (i
= 0; i
< data
->sg_len
; i
++) {
1450 struct scatterlist
*sgl
;
1453 if (sgl
->length
% data
->blksz
)
1456 if ((data
->blksz
% 4) != 0)
1457 /* REVISIT: The MMC buffer increments only when MSB is written.
1458 * Return error for blksz which is non multiple of four.
1462 BUG_ON(host
->dma_ch
!= -1);
1464 ret
= omap_request_dma(omap_hsmmc_get_dma_sync_dev(host
, data
),
1465 "MMC/SD", omap_hsmmc_dma_cb
, host
, &dma_ch
);
1467 dev_err(mmc_dev(host
->mmc
),
1468 "%s: omap_request_dma() failed with %d\n",
1469 mmc_hostname(host
->mmc
), ret
);
1472 ret
= omap_hsmmc_pre_dma_transfer(host
, data
, NULL
);
1476 host
->dma_ch
= dma_ch
;
1477 host
->dma_sg_idx
= 0;
1479 omap_hsmmc_config_dma_params(host
, data
, data
->sg
);
1484 static void set_data_timeout(struct omap_hsmmc_host
*host
,
1485 unsigned int timeout_ns
,
1486 unsigned int timeout_clks
)
1488 unsigned int timeout
, cycle_ns
;
1489 uint32_t reg
, clkd
, dto
= 0;
1491 reg
= OMAP_HSMMC_READ(host
->base
, SYSCTL
);
1492 clkd
= (reg
& CLKD_MASK
) >> CLKD_SHIFT
;
1496 cycle_ns
= 1000000000 / (clk_get_rate(host
->fclk
) / clkd
);
1497 timeout
= timeout_ns
/ cycle_ns
;
1498 timeout
+= timeout_clks
;
1500 while ((timeout
& 0x80000000) == 0) {
1517 reg
|= dto
<< DTO_SHIFT
;
1518 OMAP_HSMMC_WRITE(host
->base
, SYSCTL
, reg
);
1522 * Configure block length for MMC/SD cards and initiate the transfer.
1525 omap_hsmmc_prepare_data(struct omap_hsmmc_host
*host
, struct mmc_request
*req
)
1528 host
->data
= req
->data
;
1530 if (req
->data
== NULL
) {
1531 OMAP_HSMMC_WRITE(host
->base
, BLK
, 0);
1533 * Set an arbitrary 100ms data timeout for commands with
1536 if (req
->cmd
->flags
& MMC_RSP_BUSY
)
1537 set_data_timeout(host
, 100000000U, 0);
1541 OMAP_HSMMC_WRITE(host
->base
, BLK
, (req
->data
->blksz
)
1542 | (req
->data
->blocks
<< 16));
1543 set_data_timeout(host
, req
->data
->timeout_ns
, req
->data
->timeout_clks
);
1545 if (host
->use_dma
) {
1546 ret
= omap_hsmmc_start_dma_transfer(host
, req
);
1548 dev_dbg(mmc_dev(host
->mmc
), "MMC start dma failure\n");
1555 static void omap_hsmmc_post_req(struct mmc_host
*mmc
, struct mmc_request
*mrq
,
1558 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1559 struct mmc_data
*data
= mrq
->data
;
1561 if (host
->use_dma
) {
1562 if (data
->host_cookie
)
1563 dma_unmap_sg(mmc_dev(host
->mmc
), data
->sg
,
1565 omap_hsmmc_get_dma_dir(host
, data
));
1566 data
->host_cookie
= 0;
1570 static void omap_hsmmc_pre_req(struct mmc_host
*mmc
, struct mmc_request
*mrq
,
1573 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1575 if (mrq
->data
->host_cookie
) {
1576 mrq
->data
->host_cookie
= 0;
1581 if (omap_hsmmc_pre_dma_transfer(host
, mrq
->data
,
1583 mrq
->data
->host_cookie
= 0;
1587 * Request function. for read/write operation
1589 static void omap_hsmmc_request(struct mmc_host
*mmc
, struct mmc_request
*req
)
1591 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1594 BUG_ON(host
->req_in_progress
);
1595 BUG_ON(host
->dma_ch
!= -1);
1596 if (host
->protect_card
) {
1597 if (host
->reqs_blocked
< 3) {
1599 * Ensure the controller is left in a consistent
1600 * state by resetting the command and data state
1603 omap_hsmmc_reset_controller_fsm(host
, SRD
);
1604 omap_hsmmc_reset_controller_fsm(host
, SRC
);
1605 host
->reqs_blocked
+= 1;
1607 req
->cmd
->error
= -EBADF
;
1609 req
->data
->error
= -EBADF
;
1610 req
->cmd
->retries
= 0;
1611 mmc_request_done(mmc
, req
);
1613 } else if (host
->reqs_blocked
)
1614 host
->reqs_blocked
= 0;
1615 WARN_ON(host
->mrq
!= NULL
);
1617 err
= omap_hsmmc_prepare_data(host
, req
);
1619 req
->cmd
->error
= err
;
1621 req
->data
->error
= err
;
1623 mmc_request_done(mmc
, req
);
1627 omap_hsmmc_start_command(host
, req
->cmd
, req
->data
);
1630 /* Routine to configure clock values. Exposed API to core */
1631 static void omap_hsmmc_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
1633 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1634 int do_send_init_stream
= 0;
1636 pm_runtime_get_sync(host
->dev
);
1638 if (ios
->power_mode
!= host
->power_mode
) {
1639 switch (ios
->power_mode
) {
1641 mmc_slot(host
).set_power(host
->dev
, host
->slot_id
,
1646 mmc_slot(host
).set_power(host
->dev
, host
->slot_id
,
1648 host
->vdd
= ios
->vdd
;
1651 do_send_init_stream
= 1;
1654 host
->power_mode
= ios
->power_mode
;
1657 /* FIXME: set registers based only on changes to ios */
1659 omap_hsmmc_set_bus_width(host
);
1661 if (host
->pdata
->controller_flags
& OMAP_HSMMC_SUPPORTS_DUAL_VOLT
) {
1662 /* Only MMC1 can interface at 3V without some flavor
1663 * of external transceiver; but they all handle 1.8V.
1665 if ((OMAP_HSMMC_READ(host
->base
, HCTL
) & SDVSDET
) &&
1666 (ios
->vdd
== DUAL_VOLT_OCR_BIT
)) {
1668 * The mmc_select_voltage fn of the core does
1669 * not seem to set the power_mode to
1670 * MMC_POWER_UP upon recalculating the voltage.
1673 if (omap_hsmmc_switch_opcond(host
, ios
->vdd
) != 0)
1674 dev_dbg(mmc_dev(host
->mmc
),
1675 "Switch operation failed\n");
1679 omap_hsmmc_set_clock(host
);
1681 if (do_send_init_stream
)
1682 send_init_stream(host
);
1684 omap_hsmmc_set_bus_mode(host
);
1686 pm_runtime_put_autosuspend(host
->dev
);
1689 static int omap_hsmmc_get_cd(struct mmc_host
*mmc
)
1691 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1693 if (!mmc_slot(host
).card_detect
)
1695 return mmc_slot(host
).card_detect(host
->dev
, host
->slot_id
);
1698 static int omap_hsmmc_get_ro(struct mmc_host
*mmc
)
1700 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1702 if (!mmc_slot(host
).get_ro
)
1704 return mmc_slot(host
).get_ro(host
->dev
, 0);
1707 static void omap_hsmmc_init_card(struct mmc_host
*mmc
, struct mmc_card
*card
)
1709 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1711 if (mmc_slot(host
).init_card
)
1712 mmc_slot(host
).init_card(card
);
1715 static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host
*host
)
1717 u32 hctl
, capa
, value
;
1719 /* Only MMC1 supports 3.0V */
1720 if (host
->pdata
->controller_flags
& OMAP_HSMMC_SUPPORTS_DUAL_VOLT
) {
1728 value
= OMAP_HSMMC_READ(host
->base
, HCTL
) & ~SDVS_MASK
;
1729 OMAP_HSMMC_WRITE(host
->base
, HCTL
, value
| hctl
);
1731 value
= OMAP_HSMMC_READ(host
->base
, CAPA
);
1732 OMAP_HSMMC_WRITE(host
->base
, CAPA
, value
| capa
);
1734 /* Set the controller to AUTO IDLE mode */
1735 value
= OMAP_HSMMC_READ(host
->base
, SYSCONFIG
);
1736 OMAP_HSMMC_WRITE(host
->base
, SYSCONFIG
, value
| AUTOIDLE
);
1738 /* Set SD bus power bit */
1739 set_sd_bus_power(host
);
1742 static int omap_hsmmc_enable_fclk(struct mmc_host
*mmc
)
1744 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1746 pm_runtime_get_sync(host
->dev
);
1751 static int omap_hsmmc_disable_fclk(struct mmc_host
*mmc
, int lazy
)
1753 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1755 pm_runtime_mark_last_busy(host
->dev
);
1756 pm_runtime_put_autosuspend(host
->dev
);
1761 static const struct mmc_host_ops omap_hsmmc_ops
= {
1762 .enable
= omap_hsmmc_enable_fclk
,
1763 .disable
= omap_hsmmc_disable_fclk
,
1764 .post_req
= omap_hsmmc_post_req
,
1765 .pre_req
= omap_hsmmc_pre_req
,
1766 .request
= omap_hsmmc_request
,
1767 .set_ios
= omap_hsmmc_set_ios
,
1768 .get_cd
= omap_hsmmc_get_cd
,
1769 .get_ro
= omap_hsmmc_get_ro
,
1770 .init_card
= omap_hsmmc_init_card
,
1771 /* NYET -- enable_sdio_irq */
1774 #ifdef CONFIG_DEBUG_FS
1776 static int omap_hsmmc_regs_show(struct seq_file
*s
, void *data
)
1778 struct mmc_host
*mmc
= s
->private;
1779 struct omap_hsmmc_host
*host
= mmc_priv(mmc
);
1780 int context_loss
= 0;
1782 if (host
->pdata
->get_context_loss_count
)
1783 context_loss
= host
->pdata
->get_context_loss_count(host
->dev
);
1785 seq_printf(s
, "mmc%d:\n"
1788 " nesting_cnt:\t%d\n"
1789 " ctx_loss:\t%d:%d\n"
1791 mmc
->index
, mmc
->enabled
? 1 : 0,
1792 host
->dpm_state
, mmc
->nesting_cnt
,
1793 host
->context_loss
, context_loss
);
1795 if (host
->suspended
) {
1796 seq_printf(s
, "host suspended, can't read registers\n");
1800 pm_runtime_get_sync(host
->dev
);
1802 seq_printf(s
, "SYSCONFIG:\t0x%08x\n",
1803 OMAP_HSMMC_READ(host
->base
, SYSCONFIG
));
1804 seq_printf(s
, "CON:\t\t0x%08x\n",
1805 OMAP_HSMMC_READ(host
->base
, CON
));
1806 seq_printf(s
, "HCTL:\t\t0x%08x\n",
1807 OMAP_HSMMC_READ(host
->base
, HCTL
));
1808 seq_printf(s
, "SYSCTL:\t\t0x%08x\n",
1809 OMAP_HSMMC_READ(host
->base
, SYSCTL
));
1810 seq_printf(s
, "IE:\t\t0x%08x\n",
1811 OMAP_HSMMC_READ(host
->base
, IE
));
1812 seq_printf(s
, "ISE:\t\t0x%08x\n",
1813 OMAP_HSMMC_READ(host
->base
, ISE
));
1814 seq_printf(s
, "CAPA:\t\t0x%08x\n",
1815 OMAP_HSMMC_READ(host
->base
, CAPA
));
1817 pm_runtime_mark_last_busy(host
->dev
);
1818 pm_runtime_put_autosuspend(host
->dev
);
1823 static int omap_hsmmc_regs_open(struct inode
*inode
, struct file
*file
)
1825 return single_open(file
, omap_hsmmc_regs_show
, inode
->i_private
);
1828 static const struct file_operations mmc_regs_fops
= {
1829 .open
= omap_hsmmc_regs_open
,
1831 .llseek
= seq_lseek
,
1832 .release
= single_release
,
1835 static void omap_hsmmc_debugfs(struct mmc_host
*mmc
)
1837 if (mmc
->debugfs_root
)
1838 debugfs_create_file("regs", S_IRUSR
, mmc
->debugfs_root
,
1839 mmc
, &mmc_regs_fops
);
1844 static void omap_hsmmc_debugfs(struct mmc_host
*mmc
)
1850 static int __init
omap_hsmmc_probe(struct platform_device
*pdev
)
1852 struct omap_mmc_platform_data
*pdata
= pdev
->dev
.platform_data
;
1853 struct mmc_host
*mmc
;
1854 struct omap_hsmmc_host
*host
= NULL
;
1855 struct resource
*res
;
1858 if (pdata
== NULL
) {
1859 dev_err(&pdev
->dev
, "Platform Data is missing\n");
1863 if (pdata
->nr_slots
== 0) {
1864 dev_err(&pdev
->dev
, "No Slots\n");
1868 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1869 irq
= platform_get_irq(pdev
, 0);
1870 if (res
== NULL
|| irq
< 0)
1873 res
->start
+= pdata
->reg_offset
;
1874 res
->end
+= pdata
->reg_offset
;
1875 res
= request_mem_region(res
->start
, resource_size(res
), pdev
->name
);
1879 ret
= omap_hsmmc_gpio_init(pdata
);
1883 mmc
= mmc_alloc_host(sizeof(struct omap_hsmmc_host
), &pdev
->dev
);
1889 host
= mmc_priv(mmc
);
1891 host
->pdata
= pdata
;
1892 host
->dev
= &pdev
->dev
;
1894 host
->dev
->dma_mask
= &pdata
->dma_mask
;
1897 host
->id
= pdev
->id
;
1899 host
->mapbase
= res
->start
;
1900 host
->base
= ioremap(host
->mapbase
, SZ_4K
);
1901 host
->power_mode
= MMC_POWER_OFF
;
1902 host
->next_data
.cookie
= 1;
1904 platform_set_drvdata(pdev
, host
);
1906 mmc
->ops
= &omap_hsmmc_ops
;
1909 * If regulator_disable can only put vcc_aux to sleep then there is
1912 if (mmc_slot(host
).vcc_aux_disable_is_sleep
)
1913 mmc_slot(host
).no_off
= 1;
1915 mmc
->f_min
= OMAP_MMC_MIN_CLOCK
;
1916 mmc
->f_max
= OMAP_MMC_MAX_CLOCK
;
1918 spin_lock_init(&host
->irq_lock
);
1920 host
->fclk
= clk_get(&pdev
->dev
, "fck");
1921 if (IS_ERR(host
->fclk
)) {
1922 ret
= PTR_ERR(host
->fclk
);
1927 omap_hsmmc_context_save(host
);
1929 mmc
->caps
|= MMC_CAP_DISABLE
;
1930 if (host
->pdata
->controller_flags
& OMAP_HSMMC_BROKEN_MULTIBLOCK_READ
) {
1931 dev_info(&pdev
->dev
, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
1932 mmc
->caps2
|= MMC_CAP2_NO_MULTI_READ
;
1935 pm_runtime_enable(host
->dev
);
1936 pm_runtime_get_sync(host
->dev
);
1937 pm_runtime_set_autosuspend_delay(host
->dev
, MMC_AUTOSUSPEND_DELAY
);
1938 pm_runtime_use_autosuspend(host
->dev
);
1940 if (cpu_is_omap2430()) {
1941 host
->dbclk
= clk_get(&pdev
->dev
, "mmchsdb_fck");
1943 * MMC can still work without debounce clock.
1945 if (IS_ERR(host
->dbclk
))
1946 dev_warn(mmc_dev(host
->mmc
),
1947 "Failed to get debounce clock\n");
1949 host
->got_dbclk
= 1;
1951 if (host
->got_dbclk
)
1952 if (clk_enable(host
->dbclk
) != 0)
1953 dev_dbg(mmc_dev(host
->mmc
), "Enabling debounce"
1957 /* Since we do only SG emulation, we can have as many segs
1959 mmc
->max_segs
= 1024;
1961 mmc
->max_blk_size
= 512; /* Block Length at max can be 1024 */
1962 mmc
->max_blk_count
= 0xFFFF; /* No. of Blocks is 16 bits */
1963 mmc
->max_req_size
= mmc
->max_blk_size
* mmc
->max_blk_count
;
1964 mmc
->max_seg_size
= mmc
->max_req_size
;
1966 mmc
->caps
|= MMC_CAP_MMC_HIGHSPEED
| MMC_CAP_SD_HIGHSPEED
|
1967 MMC_CAP_WAIT_WHILE_BUSY
| MMC_CAP_ERASE
;
1969 mmc
->caps
|= mmc_slot(host
).caps
;
1970 if (mmc
->caps
& MMC_CAP_8_BIT_DATA
)
1971 mmc
->caps
|= MMC_CAP_4_BIT_DATA
;
1973 if (mmc_slot(host
).nonremovable
)
1974 mmc
->caps
|= MMC_CAP_NONREMOVABLE
;
1976 mmc
->pm_caps
= mmc_slot(host
).pm_caps
;
1978 omap_hsmmc_conf_bus_power(host
);
1980 /* Select DMA lines */
1982 case OMAP_MMC1_DEVID
:
1983 host
->dma_line_tx
= OMAP24XX_DMA_MMC1_TX
;
1984 host
->dma_line_rx
= OMAP24XX_DMA_MMC1_RX
;
1986 case OMAP_MMC2_DEVID
:
1987 host
->dma_line_tx
= OMAP24XX_DMA_MMC2_TX
;
1988 host
->dma_line_rx
= OMAP24XX_DMA_MMC2_RX
;
1990 case OMAP_MMC3_DEVID
:
1991 host
->dma_line_tx
= OMAP34XX_DMA_MMC3_TX
;
1992 host
->dma_line_rx
= OMAP34XX_DMA_MMC3_RX
;
1994 case OMAP_MMC4_DEVID
:
1995 host
->dma_line_tx
= OMAP44XX_DMA_MMC4_TX
;
1996 host
->dma_line_rx
= OMAP44XX_DMA_MMC4_RX
;
1998 case OMAP_MMC5_DEVID
:
1999 host
->dma_line_tx
= OMAP44XX_DMA_MMC5_TX
;
2000 host
->dma_line_rx
= OMAP44XX_DMA_MMC5_RX
;
2003 dev_err(mmc_dev(host
->mmc
), "Invalid MMC id\n");
2007 /* Request IRQ for MMC operations */
2008 ret
= request_irq(host
->irq
, omap_hsmmc_irq
, 0,
2009 mmc_hostname(mmc
), host
);
2011 dev_dbg(mmc_dev(host
->mmc
), "Unable to grab HSMMC IRQ\n");
2015 if (pdata
->init
!= NULL
) {
2016 if (pdata
->init(&pdev
->dev
) != 0) {
2017 dev_dbg(mmc_dev(host
->mmc
),
2018 "Unable to configure MMC IRQs\n");
2019 goto err_irq_cd_init
;
2023 if (omap_hsmmc_have_reg() && !mmc_slot(host
).set_power
) {
2024 ret
= omap_hsmmc_reg_get(host
);
2030 mmc
->ocr_avail
= mmc_slot(host
).ocr_mask
;
2032 /* Request IRQ for card detect */
2033 if ((mmc_slot(host
).card_detect_irq
)) {
2034 ret
= request_threaded_irq(mmc_slot(host
).card_detect_irq
,
2037 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
2038 mmc_hostname(mmc
), host
);
2040 dev_dbg(mmc_dev(host
->mmc
),
2041 "Unable to grab MMC CD IRQ\n");
2044 pdata
->suspend
= omap_hsmmc_suspend_cdirq
;
2045 pdata
->resume
= omap_hsmmc_resume_cdirq
;
2048 omap_hsmmc_disable_irq(host
);
2050 omap_hsmmc_protect_card(host
);
2054 if (mmc_slot(host
).name
!= NULL
) {
2055 ret
= device_create_file(&mmc
->class_dev
, &dev_attr_slot_name
);
2059 if (mmc_slot(host
).card_detect_irq
&& mmc_slot(host
).get_cover_state
) {
2060 ret
= device_create_file(&mmc
->class_dev
,
2061 &dev_attr_cover_switch
);
2066 omap_hsmmc_debugfs(mmc
);
2067 pm_runtime_mark_last_busy(host
->dev
);
2068 pm_runtime_put_autosuspend(host
->dev
);
2073 mmc_remove_host(mmc
);
2074 free_irq(mmc_slot(host
).card_detect_irq
, host
);
2077 omap_hsmmc_reg_put(host
);
2079 if (host
->pdata
->cleanup
)
2080 host
->pdata
->cleanup(&pdev
->dev
);
2082 free_irq(host
->irq
, host
);
2084 pm_runtime_mark_last_busy(host
->dev
);
2085 pm_runtime_put_autosuspend(host
->dev
);
2086 clk_put(host
->fclk
);
2087 if (host
->got_dbclk
) {
2088 clk_disable(host
->dbclk
);
2089 clk_put(host
->dbclk
);
2092 iounmap(host
->base
);
2093 platform_set_drvdata(pdev
, NULL
);
2096 omap_hsmmc_gpio_free(pdata
);
2098 release_mem_region(res
->start
, resource_size(res
));
2102 static int omap_hsmmc_remove(struct platform_device
*pdev
)
2104 struct omap_hsmmc_host
*host
= platform_get_drvdata(pdev
);
2105 struct resource
*res
;
2108 pm_runtime_get_sync(host
->dev
);
2109 mmc_remove_host(host
->mmc
);
2111 omap_hsmmc_reg_put(host
);
2112 if (host
->pdata
->cleanup
)
2113 host
->pdata
->cleanup(&pdev
->dev
);
2114 free_irq(host
->irq
, host
);
2115 if (mmc_slot(host
).card_detect_irq
)
2116 free_irq(mmc_slot(host
).card_detect_irq
, host
);
2118 pm_runtime_put_sync(host
->dev
);
2119 pm_runtime_disable(host
->dev
);
2120 clk_put(host
->fclk
);
2121 if (host
->got_dbclk
) {
2122 clk_disable(host
->dbclk
);
2123 clk_put(host
->dbclk
);
2126 mmc_free_host(host
->mmc
);
2127 iounmap(host
->base
);
2128 omap_hsmmc_gpio_free(pdev
->dev
.platform_data
);
2131 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2133 release_mem_region(res
->start
, resource_size(res
));
2134 platform_set_drvdata(pdev
, NULL
);
2140 static int omap_hsmmc_suspend(struct device
*dev
)
2143 struct platform_device
*pdev
= to_platform_device(dev
);
2144 struct omap_hsmmc_host
*host
= platform_get_drvdata(pdev
);
2146 if (host
&& host
->suspended
)
2150 pm_runtime_get_sync(host
->dev
);
2151 host
->suspended
= 1;
2152 if (host
->pdata
->suspend
) {
2153 ret
= host
->pdata
->suspend(&pdev
->dev
,
2156 dev_dbg(mmc_dev(host
->mmc
),
2157 "Unable to handle MMC board"
2158 " level suspend\n");
2159 host
->suspended
= 0;
2163 ret
= mmc_suspend_host(host
->mmc
);
2166 host
->suspended
= 0;
2167 if (host
->pdata
->resume
) {
2168 ret
= host
->pdata
->resume(&pdev
->dev
,
2171 dev_dbg(mmc_dev(host
->mmc
),
2172 "Unmask interrupt failed\n");
2177 if (!(host
->mmc
->pm_flags
& MMC_PM_KEEP_POWER
)) {
2178 omap_hsmmc_disable_irq(host
);
2179 OMAP_HSMMC_WRITE(host
->base
, HCTL
,
2180 OMAP_HSMMC_READ(host
->base
, HCTL
) & ~SDBP
);
2182 if (host
->got_dbclk
)
2183 clk_disable(host
->dbclk
);
2187 pm_runtime_put_sync(host
->dev
);
2191 /* Routine to resume the MMC device */
2192 static int omap_hsmmc_resume(struct device
*dev
)
2195 struct platform_device
*pdev
= to_platform_device(dev
);
2196 struct omap_hsmmc_host
*host
= platform_get_drvdata(pdev
);
2198 if (host
&& !host
->suspended
)
2202 pm_runtime_get_sync(host
->dev
);
2204 if (host
->got_dbclk
)
2205 clk_enable(host
->dbclk
);
2207 if (!(host
->mmc
->pm_flags
& MMC_PM_KEEP_POWER
))
2208 omap_hsmmc_conf_bus_power(host
);
2210 if (host
->pdata
->resume
) {
2211 ret
= host
->pdata
->resume(&pdev
->dev
, host
->slot_id
);
2213 dev_dbg(mmc_dev(host
->mmc
),
2214 "Unmask interrupt failed\n");
2217 omap_hsmmc_protect_card(host
);
2219 /* Notify the core to resume the host */
2220 ret
= mmc_resume_host(host
->mmc
);
2222 host
->suspended
= 0;
2224 pm_runtime_mark_last_busy(host
->dev
);
2225 pm_runtime_put_autosuspend(host
->dev
);
2233 #define omap_hsmmc_suspend NULL
2234 #define omap_hsmmc_resume NULL
2237 static int omap_hsmmc_runtime_suspend(struct device
*dev
)
2239 struct omap_hsmmc_host
*host
;
2241 host
= platform_get_drvdata(to_platform_device(dev
));
2242 omap_hsmmc_context_save(host
);
2243 dev_dbg(mmc_dev(host
->mmc
), "disabled\n");
2248 static int omap_hsmmc_runtime_resume(struct device
*dev
)
2250 struct omap_hsmmc_host
*host
;
2252 host
= platform_get_drvdata(to_platform_device(dev
));
2253 omap_hsmmc_context_restore(host
);
2254 dev_dbg(mmc_dev(host
->mmc
), "enabled\n");
2259 static struct dev_pm_ops omap_hsmmc_dev_pm_ops
= {
2260 .suspend
= omap_hsmmc_suspend
,
2261 .resume
= omap_hsmmc_resume
,
2262 .runtime_suspend
= omap_hsmmc_runtime_suspend
,
2263 .runtime_resume
= omap_hsmmc_runtime_resume
,
2266 static struct platform_driver omap_hsmmc_driver
= {
2267 .remove
= omap_hsmmc_remove
,
2269 .name
= DRIVER_NAME
,
2270 .owner
= THIS_MODULE
,
2271 .pm
= &omap_hsmmc_dev_pm_ops
,
2275 static int __init
omap_hsmmc_init(void)
2277 /* Register the MMC driver */
2278 return platform_driver_probe(&omap_hsmmc_driver
, omap_hsmmc_probe
);
2281 static void __exit
omap_hsmmc_cleanup(void)
2283 /* Unregister MMC driver */
2284 platform_driver_unregister(&omap_hsmmc_driver
);
2287 module_init(omap_hsmmc_init
);
2288 module_exit(omap_hsmmc_cleanup
);
2290 MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
2291 MODULE_LICENSE("GPL");
2292 MODULE_ALIAS("platform:" DRIVER_NAME
);
2293 MODULE_AUTHOR("Texas Instruments Inc");