19 #include <linux/module.h>
37 #include <asm/sizes.h>
39 #include <mach/hardware.h>
45 #define DRIVER_NAME "pxa2xx-mci"
48 #define CLKRT_OFF (~0)
50 #define mmc_has_26MHz() (cpu_is_pxa300() || cpu_is_pxa310() \
85 #ifdef CONFIG_REGULATOR
88 if (IS_ERR(host->
vcc))
91 host->
mmc->ocr_avail = mmc_regulator_get_ocrmask(host->
vcc);
94 "ocr_mask/setpower will not be used\n");
100 host->
pdata->ocr_mask :
105 static inline int pxamci_set_power(
struct pxamci_host *host,
106 unsigned char power_mode,
115 ret = mmc_regulator_set_ocr(host->
mmc, host->
vcc, vdd);
119 ret = mmc_regulator_set_ocr(host->
mmc, host->
vcc, 0);
125 gpio_is_valid(host->
pdata->gpio_power)) {
126 on = ((1 << vdd) & host->
pdata->ocr_mask);
128 !!on ^ host->
pdata->gpio_power_invert);
136 static void pxamci_stop_clock(
struct pxamci_host *host)
146 if (!(v & STAT_CLK_EN))
156 static void pxamci_enable_irq(
struct pxamci_host *host,
unsigned int mask)
161 host->
imask &= ~mask;
163 spin_unlock_irqrestore(&host->
lock, flags);
166 static void pxamci_disable_irq(
struct pxamci_host *host,
unsigned int mask)
173 spin_unlock_irqrestore(&host->
lock, flags);
178 unsigned int nob = data->
blocks;
179 unsigned long long clks;
180 unsigned int timeout;
215 for (i = 0; i < host->
dma_len; i++) {
265 #define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE))
299 static int pxamci_cmd_done(
struct pxamci_host *host,
unsigned int stat)
315 for (i = 0; i < 4; i++) {
318 cmd->
resp[
i] = v << 24 | w1 << 8 | w2 >> 8;
333 pr_debug(
"ignoring CRC from command %d - *risky*\n", cmd->
opcode);
348 pxamci_finish_request(host, host->
mrq);
354 static int pxamci_data_done(
struct pxamci_host *host,
unsigned int stat)
384 if (host->
mrq->stop) {
385 pxamci_stop_clock(host);
386 pxamci_start_cmd(host, host->
mrq->stop, host->
cmdat);
388 pxamci_finish_request(host, host->
mrq);
405 pr_debug(
"PXAMCI: irq %08x stat %08x\n", ireg, stat);
408 handled |= pxamci_cmd_done(host, stat);
410 handled |= pxamci_data_done(host, stat);
412 mmc_signal_sdio_irq(host->
mmc);
429 pxamci_stop_clock(host);
435 pxamci_setup_data(host, mrq->
data);
446 pxamci_start_cmd(host, mrq->
cmd, cmdat);
449 static int pxamci_get_ro(
struct mmc_host *mmc)
453 if (host->
pdata && gpio_is_valid(host->
pdata->gpio_card_ro)) {
454 if (host->
pdata->gpio_card_ro_invert)
474 unsigned int clk = rate / ios->
clock;
479 if (ios->
clock == 26000000) {
492 if (rate / clk > ios->
clock)
494 host->
clkrt = fls(clk) - 1;
501 pxamci_stop_clock(host);
538 static void pxamci_enable_sdio_irq(
struct mmc_host *host,
int enable)
543 pxamci_enable_irq(pxa_host,
SDIO_INT);
545 pxamci_disable_irq(pxa_host,
SDIO_INT);
549 .request = pxamci_request,
550 .get_ro = pxamci_get_ro,
551 .set_ios = pxamci_set_ios,
552 .enable_sdio_irq = pxamci_enable_sdio_irq,
555 static void pxamci_dma_irq(
int dma,
void *devid)
558 int dcsr =
DCSR(dma);
564 pr_err(
"%s: DMA error on channel %d (DCSR=%#x)\n",
567 pxamci_data_done(host, 0);
571 static irqreturn_t pxamci_detect_irq(
int irq,
void *devid)
601 of_get_named_gpio(np,
"cd-gpios", 0);
603 of_get_named_gpio(np,
"wp-gpios", 0);
607 of_get_named_gpio(np,
"pxa-mmc,gpio-power", 0);
609 if (of_property_read_u32(np,
"pxa-mmc,detect-delay-ms", &tmp) == 0)
628 int ret, irq, gpio_cd = -1, gpio_ro = -1, gpio_power = -1;
630 ret = pxamci_of_init(pdev);
649 mmc->
ops = &pxamci_ops;
672 host = mmc_priv(mmc);
675 host->
pdata = pdev->
dev.platform_data;
679 if (IS_ERR(host->
clk)) {
680 ret = PTR_ERR(host->
clk);
693 pxamci_init_ocr(host);
726 pxamci_stop_clock(host);
732 pxamci_dma_irq, host);
742 platform_set_drvdata(pdev, mmc);
759 gpio_cd = host->
pdata->gpio_card_detect;
760 gpio_ro = host->
pdata->gpio_card_ro;
761 gpio_power = host->
pdata->gpio_power;
763 if (gpio_is_valid(gpio_power)) {
766 dev_err(&pdev->
dev,
"Failed requesting gpio_power %d\n", gpio_power);
770 host->
pdata->gpio_power_invert);
772 if (gpio_is_valid(gpio_ro)) {
775 dev_err(&pdev->
dev,
"Failed requesting gpio_ro %d\n", gpio_ro);
780 if (gpio_is_valid(gpio_cd)) {
783 dev_err(&pdev->
dev,
"Failed requesting gpio_cd %d\n", gpio_cd);
790 "mmc card detect", mmc);
792 dev_err(&pdev->
dev,
"failed to request card detect IRQ\n");
793 goto err_request_irq;
798 host->
pdata->init(&pdev->
dev, pxamci_detect_irq, mmc);
800 if (gpio_is_valid(gpio_power) && host->
pdata->setpower)
801 dev_warn(&pdev->
dev,
"gpio_power and setpower() both defined\n");
802 if (gpio_is_valid(gpio_ro) && host->
pdata->get_ro)
803 dev_warn(&pdev->
dev,
"gpio_ro and get_ro() both defined\n");
834 struct mmc_host *mmc = platform_get_drvdata(pdev);
835 int gpio_cd = -1, gpio_ro = -1, gpio_power = -1;
837 platform_set_drvdata(pdev,
NULL);
845 gpio_cd = host->
pdata->gpio_card_detect;
846 gpio_ro = host->
pdata->gpio_card_ro;
847 gpio_power = host->
pdata->gpio_power;
849 if (gpio_is_valid(gpio_cd)) {
853 if (gpio_is_valid(gpio_ro))
855 if (gpio_is_valid(gpio_power))
863 pxamci_stop_clock(host);
886 static int pxamci_suspend(
struct device *
dev)
897 static int pxamci_resume(
struct device *dev)
908 static const struct dev_pm_ops pxamci_pm_ops = {
910 .resume = pxamci_resume,
915 .probe = pxamci_probe,
916 .remove = pxamci_remove,
922 .pm = &pxamci_pm_ops,