Lines Matching +full:mmc +full:- +full:card
2 * drivers/mmc/host/omap_hsmmc.c
4 * Driver for OMAP2430/3430 MMC controller.
27 #include <linux/dma-mapping.h>
34 #include <linux/mmc/host.h>
35 #include <linux/mmc/core.h>
36 #include <linux/mmc/mmc.h>
37 #include <linux/mmc/slot-gpio.h>
44 #include <linux/platform_data/hsmmc-omap.h>
153 #define mmc_pdata(host) host->pdata
156 * MMC Host controller read/write API's
171 struct mmc_host *mmc; member
216 static int omap_hsmmc_enable_supply(struct mmc_host *mmc) in omap_hsmmc_enable_supply() argument
219 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_enable_supply()
220 struct mmc_ios *ios = &mmc->ios; in omap_hsmmc_enable_supply()
222 if (!IS_ERR(mmc->supply.vmmc)) { in omap_hsmmc_enable_supply()
223 ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd); in omap_hsmmc_enable_supply()
229 if (!IS_ERR(mmc->supply.vqmmc) && !host->vqmmc_enabled) { in omap_hsmmc_enable_supply()
230 ret = regulator_enable(mmc->supply.vqmmc); in omap_hsmmc_enable_supply()
232 dev_err(mmc_dev(mmc), "vmmc_aux reg enable failed\n"); in omap_hsmmc_enable_supply()
235 host->vqmmc_enabled = 1; in omap_hsmmc_enable_supply()
241 if (!IS_ERR(mmc->supply.vmmc)) in omap_hsmmc_enable_supply()
242 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); in omap_hsmmc_enable_supply()
247 static int omap_hsmmc_disable_supply(struct mmc_host *mmc) in omap_hsmmc_disable_supply() argument
251 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_disable_supply()
253 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) { in omap_hsmmc_disable_supply()
254 ret = regulator_disable(mmc->supply.vqmmc); in omap_hsmmc_disable_supply()
256 dev_err(mmc_dev(mmc), "vmmc_aux reg disable failed\n"); in omap_hsmmc_disable_supply()
259 host->vqmmc_enabled = 0; in omap_hsmmc_disable_supply()
262 if (!IS_ERR(mmc->supply.vmmc)) { in omap_hsmmc_disable_supply()
263 ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); in omap_hsmmc_disable_supply()
271 if (!IS_ERR(mmc->supply.vqmmc)) { in omap_hsmmc_disable_supply()
272 status = regulator_enable(mmc->supply.vqmmc); in omap_hsmmc_disable_supply()
274 dev_err(mmc_dev(mmc), "vmmc_aux re-enable failed\n"); in omap_hsmmc_disable_supply()
284 if (IS_ERR(host->pbias)) in omap_hsmmc_set_pbias()
288 if (host->pbias_enabled == 0) { in omap_hsmmc_set_pbias()
289 ret = regulator_enable(host->pbias); in omap_hsmmc_set_pbias()
291 dev_err(host->dev, "pbias reg enable fail\n"); in omap_hsmmc_set_pbias()
294 host->pbias_enabled = 1; in omap_hsmmc_set_pbias()
297 if (host->pbias_enabled == 1) { in omap_hsmmc_set_pbias()
298 ret = regulator_disable(host->pbias); in omap_hsmmc_set_pbias()
300 dev_err(host->dev, "pbias reg disable fail\n"); in omap_hsmmc_set_pbias()
303 host->pbias_enabled = 0; in omap_hsmmc_set_pbias()
312 struct mmc_host *mmc = host->mmc; in omap_hsmmc_set_power() local
317 * voltage always-on regulator. in omap_hsmmc_set_power()
319 if (IS_ERR(mmc->supply.vmmc)) in omap_hsmmc_set_power()
327 * Assume Vcc regulator is used only to power the card ... OMAP in omap_hsmmc_set_power()
340 ret = omap_hsmmc_enable_supply(mmc); in omap_hsmmc_set_power()
348 ret = omap_hsmmc_disable_supply(mmc); in omap_hsmmc_set_power()
356 omap_hsmmc_disable_supply(mmc); in omap_hsmmc_set_power()
383 struct mmc_host *mmc = host->mmc; in omap_hsmmc_disable_boot_regulators() local
391 ret = omap_hsmmc_disable_boot_regulator(mmc->supply.vmmc); in omap_hsmmc_disable_boot_regulators()
393 dev_err(host->dev, "fail to disable boot enabled vmmc reg\n"); in omap_hsmmc_disable_boot_regulators()
397 ret = omap_hsmmc_disable_boot_regulator(mmc->supply.vqmmc); in omap_hsmmc_disable_boot_regulators()
399 dev_err(host->dev, in omap_hsmmc_disable_boot_regulators()
404 ret = omap_hsmmc_disable_boot_regulator(host->pbias); in omap_hsmmc_disable_boot_regulators()
406 dev_err(host->dev, in omap_hsmmc_disable_boot_regulators()
417 struct mmc_host *mmc = host->mmc; in omap_hsmmc_reg_get() local
420 ret = mmc_regulator_get_supply(mmc); in omap_hsmmc_reg_get()
425 if (IS_ERR(mmc->supply.vqmmc)) { in omap_hsmmc_reg_get()
426 mmc->supply.vqmmc = devm_regulator_get_optional(host->dev, in omap_hsmmc_reg_get()
428 if (IS_ERR(mmc->supply.vqmmc)) { in omap_hsmmc_reg_get()
429 ret = PTR_ERR(mmc->supply.vqmmc); in omap_hsmmc_reg_get()
430 if ((ret != -ENODEV) && host->dev->of_node) in omap_hsmmc_reg_get()
432 dev_dbg(host->dev, "unable to get vmmc_aux regulator %ld\n", in omap_hsmmc_reg_get()
433 PTR_ERR(mmc->supply.vqmmc)); in omap_hsmmc_reg_get()
437 host->pbias = devm_regulator_get_optional(host->dev, "pbias"); in omap_hsmmc_reg_get()
438 if (IS_ERR(host->pbias)) { in omap_hsmmc_reg_get()
439 ret = PTR_ERR(host->pbias); in omap_hsmmc_reg_get()
440 if ((ret != -ENODEV) && host->dev->of_node) { in omap_hsmmc_reg_get()
441 dev_err(host->dev, in omap_hsmmc_reg_get()
442 "SD card detect fail? enable CONFIG_REGULATOR_PBIAS\n"); in omap_hsmmc_reg_get()
445 dev_dbg(host->dev, "unable to get pbias regulator %ld\n", in omap_hsmmc_reg_get()
446 PTR_ERR(host->pbias)); in omap_hsmmc_reg_get()
450 if (mmc_pdata(host)->no_regulator_off_init) in omap_hsmmc_reg_get()
461 * Start clock to the card
465 OMAP_HSMMC_WRITE(host->base, SYSCTL, in omap_hsmmc_start_clock()
466 OMAP_HSMMC_READ(host->base, SYSCTL) | CEN); in omap_hsmmc_start_clock()
470 * Stop clock to the card
474 OMAP_HSMMC_WRITE(host->base, SYSCTL, in omap_hsmmc_stop_clock()
475 OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN); in omap_hsmmc_stop_clock()
476 if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0) in omap_hsmmc_stop_clock()
477 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stopped\n"); in omap_hsmmc_stop_clock()
486 if (host->use_dma) in omap_hsmmc_enable_irq()
490 if (cmd->opcode == MMC_ERASE) in omap_hsmmc_enable_irq()
493 spin_lock_irqsave(&host->irq_lock, flags); in omap_hsmmc_enable_irq()
494 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); in omap_hsmmc_enable_irq()
495 OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); in omap_hsmmc_enable_irq()
497 /* latch pending CIRQ, but don't signal MMC core */ in omap_hsmmc_enable_irq()
498 if (host->flags & HSMMC_SDIO_IRQ_ENABLED) in omap_hsmmc_enable_irq()
500 OMAP_HSMMC_WRITE(host->base, IE, irq_mask); in omap_hsmmc_enable_irq()
501 spin_unlock_irqrestore(&host->irq_lock, flags); in omap_hsmmc_enable_irq()
509 spin_lock_irqsave(&host->irq_lock, flags); in omap_hsmmc_disable_irq()
511 if (host->flags & HSMMC_SDIO_IRQ_ENABLED) in omap_hsmmc_disable_irq()
513 OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); in omap_hsmmc_disable_irq()
514 OMAP_HSMMC_WRITE(host->base, IE, irq_mask); in omap_hsmmc_disable_irq()
515 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); in omap_hsmmc_disable_irq()
516 spin_unlock_irqrestore(&host->irq_lock, flags); in omap_hsmmc_disable_irq()
524 if (ios->clock) { in calc_divisor()
525 dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock); in calc_divisor()
535 struct mmc_ios *ios = &host->mmc->ios; in omap_hsmmc_set_clock()
540 dev_vdbg(mmc_dev(host->mmc), "Set clock to %uHz\n", ios->clock); in omap_hsmmc_set_clock()
544 regval = OMAP_HSMMC_READ(host->base, SYSCTL); in omap_hsmmc_set_clock()
548 OMAP_HSMMC_WRITE(host->base, SYSCTL, regval); in omap_hsmmc_set_clock()
549 OMAP_HSMMC_WRITE(host->base, SYSCTL, in omap_hsmmc_set_clock()
550 OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); in omap_hsmmc_set_clock()
554 while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS in omap_hsmmc_set_clock()
559 * Enable High-Speed Support in omap_hsmmc_set_clock()
560 * Pre-Requisites in omap_hsmmc_set_clock()
561 * - Controller should support High-Speed-Enable Bit in omap_hsmmc_set_clock()
562 * - Controller should not be using DDR Mode in omap_hsmmc_set_clock()
563 * - Controller should advertise that it supports High Speed in omap_hsmmc_set_clock()
565 * - MMC/SD clock coming out of controller > 25MHz in omap_hsmmc_set_clock()
567 if ((mmc_pdata(host)->features & HSMMC_HAS_HSPE_SUPPORT) && in omap_hsmmc_set_clock()
568 (ios->timing != MMC_TIMING_MMC_DDR52) && in omap_hsmmc_set_clock()
569 (ios->timing != MMC_TIMING_UHS_DDR50) && in omap_hsmmc_set_clock()
570 ((OMAP_HSMMC_READ(host->base, CAPA) & HSS) == HSS)) { in omap_hsmmc_set_clock()
571 regval = OMAP_HSMMC_READ(host->base, HCTL); in omap_hsmmc_set_clock()
572 if (clkdiv && (clk_get_rate(host->fclk)/clkdiv) > 25000000) in omap_hsmmc_set_clock()
577 OMAP_HSMMC_WRITE(host->base, HCTL, regval); in omap_hsmmc_set_clock()
585 struct mmc_ios *ios = &host->mmc->ios; in omap_hsmmc_set_bus_width()
588 con = OMAP_HSMMC_READ(host->base, CON); in omap_hsmmc_set_bus_width()
589 if (ios->timing == MMC_TIMING_MMC_DDR52 || in omap_hsmmc_set_bus_width()
590 ios->timing == MMC_TIMING_UHS_DDR50) in omap_hsmmc_set_bus_width()
594 switch (ios->bus_width) { in omap_hsmmc_set_bus_width()
596 OMAP_HSMMC_WRITE(host->base, CON, con | DW8); in omap_hsmmc_set_bus_width()
599 OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8); in omap_hsmmc_set_bus_width()
600 OMAP_HSMMC_WRITE(host->base, HCTL, in omap_hsmmc_set_bus_width()
601 OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT); in omap_hsmmc_set_bus_width()
604 OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8); in omap_hsmmc_set_bus_width()
605 OMAP_HSMMC_WRITE(host->base, HCTL, in omap_hsmmc_set_bus_width()
606 OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT); in omap_hsmmc_set_bus_width()
613 struct mmc_ios *ios = &host->mmc->ios; in omap_hsmmc_set_bus_mode()
616 con = OMAP_HSMMC_READ(host->base, CON); in omap_hsmmc_set_bus_mode()
617 if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) in omap_hsmmc_set_bus_mode()
618 OMAP_HSMMC_WRITE(host->base, CON, con | OD); in omap_hsmmc_set_bus_mode()
620 OMAP_HSMMC_WRITE(host->base, CON, con & ~OD); in omap_hsmmc_set_bus_mode()
626 * Restore the MMC host context, if it was lost as result of a
631 struct mmc_ios *ios = &host->mmc->ios; in omap_hsmmc_context_restore()
635 if (host->con == OMAP_HSMMC_READ(host->base, CON) && in omap_hsmmc_context_restore()
636 host->hctl == OMAP_HSMMC_READ(host->base, HCTL) && in omap_hsmmc_context_restore()
637 host->sysctl == OMAP_HSMMC_READ(host->base, SYSCTL) && in omap_hsmmc_context_restore()
638 host->capa == OMAP_HSMMC_READ(host->base, CAPA)) in omap_hsmmc_context_restore()
641 host->context_loss++; in omap_hsmmc_context_restore()
643 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { in omap_hsmmc_context_restore()
644 if (host->power_mode != MMC_POWER_OFF && in omap_hsmmc_context_restore()
645 (1 << ios->vdd) <= MMC_VDD_23_24) in omap_hsmmc_context_restore()
655 if (host->mmc->caps & MMC_CAP_SDIO_IRQ) in omap_hsmmc_context_restore()
658 OMAP_HSMMC_WRITE(host->base, HCTL, in omap_hsmmc_context_restore()
659 OMAP_HSMMC_READ(host->base, HCTL) | hctl); in omap_hsmmc_context_restore()
661 OMAP_HSMMC_WRITE(host->base, CAPA, in omap_hsmmc_context_restore()
662 OMAP_HSMMC_READ(host->base, CAPA) | capa); in omap_hsmmc_context_restore()
664 OMAP_HSMMC_WRITE(host->base, HCTL, in omap_hsmmc_context_restore()
665 OMAP_HSMMC_READ(host->base, HCTL) | SDBP); in omap_hsmmc_context_restore()
668 while ((OMAP_HSMMC_READ(host->base, HCTL) & SDBP) != SDBP in omap_hsmmc_context_restore()
672 OMAP_HSMMC_WRITE(host->base, ISE, 0); in omap_hsmmc_context_restore()
673 OMAP_HSMMC_WRITE(host->base, IE, 0); in omap_hsmmc_context_restore()
674 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); in omap_hsmmc_context_restore()
676 /* Do not initialize card-specific things if the power is off */ in omap_hsmmc_context_restore()
677 if (host->power_mode == MMC_POWER_OFF) in omap_hsmmc_context_restore()
687 dev_dbg(mmc_dev(host->mmc), "context is restored: restore count %d\n", in omap_hsmmc_context_restore()
688 host->context_loss); in omap_hsmmc_context_restore()
693 * Save the MMC host context (store the number of power state changes so far).
697 host->con = OMAP_HSMMC_READ(host->base, CON); in omap_hsmmc_context_save()
698 host->hctl = OMAP_HSMMC_READ(host->base, HCTL); in omap_hsmmc_context_save()
699 host->sysctl = OMAP_HSMMC_READ(host->base, SYSCTL); in omap_hsmmc_context_save()
700 host->capa = OMAP_HSMMC_READ(host->base, CAPA); in omap_hsmmc_context_save()
717 * Send init stream sequence to card
725 disable_irq(host->irq); in send_init_stream()
727 OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK); in send_init_stream()
728 OMAP_HSMMC_WRITE(host->base, CON, in send_init_stream()
729 OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM); in send_init_stream()
730 OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD); in send_init_stream()
734 reg = OMAP_HSMMC_READ(host->base, STAT) & CC_EN; in send_init_stream()
736 OMAP_HSMMC_WRITE(host->base, CON, in send_init_stream()
737 OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM); in send_init_stream()
739 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); in send_init_stream()
740 OMAP_HSMMC_READ(host->base, STAT); in send_init_stream()
742 enable_irq(host->irq); in send_init_stream()
749 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); in omap_hsmmc_show_slot_name() local
750 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_show_slot_name()
752 return sprintf(buf, "%s\n", mmc_pdata(host)->name); in omap_hsmmc_show_slot_name()
766 dev_vdbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n", in omap_hsmmc_start_command()
767 mmc_hostname(host->mmc), cmd->opcode, cmd->arg); in omap_hsmmc_start_command()
768 host->cmd = cmd; in omap_hsmmc_start_command()
772 host->response_busy = 0; in omap_hsmmc_start_command()
773 if (cmd->flags & MMC_RSP_PRESENT) { in omap_hsmmc_start_command()
774 if (cmd->flags & MMC_RSP_136) in omap_hsmmc_start_command()
776 else if (cmd->flags & MMC_RSP_BUSY) { in omap_hsmmc_start_command()
778 host->response_busy = 1; in omap_hsmmc_start_command()
788 if (cmd == host->mrq->stop) in omap_hsmmc_start_command()
791 cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22); in omap_hsmmc_start_command()
793 if ((host->flags & AUTO_CMD23) && mmc_op_multi(cmd->opcode) && in omap_hsmmc_start_command()
794 host->mrq->sbc) { in omap_hsmmc_start_command()
796 OMAP_HSMMC_WRITE(host->base, SDMASA, host->mrq->sbc->arg); in omap_hsmmc_start_command()
800 if (data->flags & MMC_DATA_READ) in omap_hsmmc_start_command()
806 if (host->use_dma) in omap_hsmmc_start_command()
809 host->req_in_progress = 1; in omap_hsmmc_start_command()
811 OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg); in omap_hsmmc_start_command()
812 OMAP_HSMMC_WRITE(host->base, CMD, cmdreg); in omap_hsmmc_start_command()
818 return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan; in omap_hsmmc_get_dma_chan()
826 spin_lock_irqsave(&host->irq_lock, flags); in omap_hsmmc_request_done()
827 host->req_in_progress = 0; in omap_hsmmc_request_done()
828 dma_ch = host->dma_ch; in omap_hsmmc_request_done()
829 spin_unlock_irqrestore(&host->irq_lock, flags); in omap_hsmmc_request_done()
833 if (mrq->data && host->use_dma && dma_ch != -1) in omap_hsmmc_request_done()
835 host->mrq = NULL; in omap_hsmmc_request_done()
836 mmc_request_done(host->mmc, mrq); in omap_hsmmc_request_done()
840 * Notify the transfer complete to MMC core
846 struct mmc_request *mrq = host->mrq; in omap_hsmmc_xfer_done()
848 /* TC before CC from CMD6 - don't know why, but it happens */ in omap_hsmmc_xfer_done()
849 if (host->cmd && host->cmd->opcode == 6 && in omap_hsmmc_xfer_done()
850 host->response_busy) { in omap_hsmmc_xfer_done()
851 host->response_busy = 0; in omap_hsmmc_xfer_done()
859 host->data = NULL; in omap_hsmmc_xfer_done()
861 if (!data->error) in omap_hsmmc_xfer_done()
862 data->bytes_xfered += data->blocks * (data->blksz); in omap_hsmmc_xfer_done()
864 data->bytes_xfered = 0; in omap_hsmmc_xfer_done()
866 if (data->stop && (data->error || !host->mrq->sbc)) in omap_hsmmc_xfer_done()
867 omap_hsmmc_start_command(host, data->stop, NULL); in omap_hsmmc_xfer_done()
869 omap_hsmmc_request_done(host, data->mrq); in omap_hsmmc_xfer_done()
878 if (host->mrq->sbc && (host->cmd == host->mrq->sbc) && in omap_hsmmc_cmd_done()
879 !host->mrq->sbc->error && !(host->flags & AUTO_CMD23)) { in omap_hsmmc_cmd_done()
880 host->cmd = NULL; in omap_hsmmc_cmd_done()
882 omap_hsmmc_start_command(host, host->mrq->cmd, in omap_hsmmc_cmd_done()
883 host->mrq->data); in omap_hsmmc_cmd_done()
887 host->cmd = NULL; in omap_hsmmc_cmd_done()
889 if (cmd->flags & MMC_RSP_PRESENT) { in omap_hsmmc_cmd_done()
890 if (cmd->flags & MMC_RSP_136) { in omap_hsmmc_cmd_done()
892 cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10); in omap_hsmmc_cmd_done()
893 cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32); in omap_hsmmc_cmd_done()
894 cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54); in omap_hsmmc_cmd_done()
895 cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76); in omap_hsmmc_cmd_done()
898 cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10); in omap_hsmmc_cmd_done()
901 if ((host->data == NULL && !host->response_busy) || cmd->error) in omap_hsmmc_cmd_done()
902 omap_hsmmc_request_done(host, host->mrq); in omap_hsmmc_cmd_done()
913 host->data->error = errno; in omap_hsmmc_dma_cleanup()
915 spin_lock_irqsave(&host->irq_lock, flags); in omap_hsmmc_dma_cleanup()
916 dma_ch = host->dma_ch; in omap_hsmmc_dma_cleanup()
917 host->dma_ch = -1; in omap_hsmmc_dma_cleanup()
918 spin_unlock_irqrestore(&host->irq_lock, flags); in omap_hsmmc_dma_cleanup()
920 if (host->use_dma && dma_ch != -1) { in omap_hsmmc_dma_cleanup()
921 struct dma_chan *chan = omap_hsmmc_get_dma_chan(host, host->data); in omap_hsmmc_dma_cleanup()
924 dma_unmap_sg(chan->device->dev, in omap_hsmmc_dma_cleanup()
925 host->data->sg, host->data->sg_len, in omap_hsmmc_dma_cleanup()
926 mmc_get_dma_dir(host->data)); in omap_hsmmc_dma_cleanup()
928 host->data->host_cookie = 0; in omap_hsmmc_dma_cleanup()
930 host->data = NULL; in omap_hsmmc_dma_cleanup()
939 /* --- means reserved bit without definition at documentation */ in omap_hsmmc_dbg_report_irq()
941 "CC" , "TC" , "BGE", "---", "BWR" , "BRR" , "---" , "---" , in omap_hsmmc_dbg_report_irq()
942 "CIRQ", "OBI" , "---", "---", "---" , "---" , "---" , "ERRI", in omap_hsmmc_dbg_report_irq()
943 "CTO" , "CCRC", "CEB", "CIE", "DTO" , "DCRC", "DEB" , "---" , in omap_hsmmc_dbg_report_irq()
944 "ACE" , "---" , "---", "---", "CERR", "BADA", "---" , "---" in omap_hsmmc_dbg_report_irq()
950 len = sprintf(buf, "MMC IRQ 0x%x :", status); in omap_hsmmc_dbg_report_irq()
959 dev_vdbg(mmc_dev(host->mmc), "%s\n", res); in omap_hsmmc_dbg_report_irq()
969 * MMC controller internal state machines reset
981 OMAP_HSMMC_WRITE(host->base, SYSCTL, in omap_hsmmc_reset_controller_fsm()
982 OMAP_HSMMC_READ(host->base, SYSCTL) | bit); in omap_hsmmc_reset_controller_fsm()
986 * Monitor a 0->1 transition first in omap_hsmmc_reset_controller_fsm()
988 if (mmc_pdata(host)->features & HSMMC_HAS_UPDATED_RESET) { in omap_hsmmc_reset_controller_fsm()
989 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit)) in omap_hsmmc_reset_controller_fsm()
995 while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) && in omap_hsmmc_reset_controller_fsm()
999 if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit) in omap_hsmmc_reset_controller_fsm()
1000 dev_err(mmc_dev(host->mmc), in omap_hsmmc_reset_controller_fsm()
1010 if (host->cmd) in hsmmc_command_incomplete()
1011 host->cmd->error = err; in hsmmc_command_incomplete()
1014 if (host->data) { in hsmmc_command_incomplete()
1017 } else if (host->mrq && host->mrq->cmd) in hsmmc_command_incomplete()
1018 host->mrq->cmd->error = err; in hsmmc_command_incomplete()
1027 data = host->data; in omap_hsmmc_do_irq()
1028 dev_vdbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status); in omap_hsmmc_do_irq()
1035 if (host->data || host->response_busy) { in omap_hsmmc_do_irq()
1037 host->response_busy = 0; in omap_hsmmc_do_irq()
1040 hsmmc_command_incomplete(host, -ETIMEDOUT, end_cmd); in omap_hsmmc_do_irq()
1043 hsmmc_command_incomplete(host, -EILSEQ, end_cmd); in omap_hsmmc_do_irq()
1047 ac12 = OMAP_HSMMC_READ(host->base, AC12); in omap_hsmmc_do_irq()
1048 if (!(ac12 & ACNE) && host->mrq->sbc) { in omap_hsmmc_do_irq()
1051 error = -ETIMEDOUT; in omap_hsmmc_do_irq()
1053 error = -EILSEQ; in omap_hsmmc_do_irq()
1054 host->mrq->sbc->error = error; in omap_hsmmc_do_irq()
1057 dev_dbg(mmc_dev(host->mmc), "AC12 err: 0x%x\n", ac12); in omap_hsmmc_do_irq()
1061 OMAP_HSMMC_WRITE(host->base, STAT, status); in omap_hsmmc_do_irq()
1062 if (end_cmd || ((status & CC_EN) && host->cmd)) in omap_hsmmc_do_irq()
1063 omap_hsmmc_cmd_done(host, host->cmd); in omap_hsmmc_do_irq()
1064 if ((end_trans || (status & TC_EN)) && host->mrq) in omap_hsmmc_do_irq()
1069 * MMC controller IRQ handler
1076 status = OMAP_HSMMC_READ(host->base, STAT); in omap_hsmmc_irq()
1078 if (host->req_in_progress) in omap_hsmmc_irq()
1082 mmc_signal_sdio_irq(host->mmc); in omap_hsmmc_irq()
1085 status = OMAP_HSMMC_READ(host->base, STAT); in omap_hsmmc_irq()
1095 OMAP_HSMMC_WRITE(host->base, HCTL, in set_sd_bus_power()
1096 OMAP_HSMMC_READ(host->base, HCTL) | SDBP); in set_sd_bus_power()
1098 if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP) in set_sd_bus_power()
1105 * Switch MMC interface voltage ... only relevant for MMC1.
1117 clk_disable_unprepare(host->dbclk); in omap_hsmmc_switch_opcond()
1125 clk_prepare_enable(host->dbclk); in omap_hsmmc_switch_opcond()
1130 OMAP_HSMMC_WRITE(host->base, HCTL, in omap_hsmmc_switch_opcond()
1131 OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR); in omap_hsmmc_switch_opcond()
1132 reg_val = OMAP_HSMMC_READ(host->base, HCTL); in omap_hsmmc_switch_opcond()
1135 * If a MMC dual voltage card is detected, the set_ios fn calls in omap_hsmmc_switch_opcond()
1136 * this fn with VDD bit set for 1.8V. Upon card removal from the in omap_hsmmc_switch_opcond()
1140 * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max, in omap_hsmmc_switch_opcond()
1142 * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max, in omap_hsmmc_switch_opcond()
1145 * Board setup code shouldn't permit anything very out-of-range. in omap_hsmmc_switch_opcond()
1146 * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the in omap_hsmmc_switch_opcond()
1154 OMAP_HSMMC_WRITE(host->base, HCTL, reg_val); in omap_hsmmc_switch_opcond()
1159 dev_err(mmc_dev(host->mmc), "Unable to switch operating voltage\n"); in omap_hsmmc_switch_opcond()
1170 spin_lock_irq(&host->irq_lock); in omap_hsmmc_dma_callback()
1171 if (host->dma_ch < 0) { in omap_hsmmc_dma_callback()
1172 spin_unlock_irq(&host->irq_lock); in omap_hsmmc_dma_callback()
1176 data = host->mrq->data; in omap_hsmmc_dma_callback()
1178 if (!data->host_cookie) in omap_hsmmc_dma_callback()
1179 dma_unmap_sg(chan->device->dev, in omap_hsmmc_dma_callback()
1180 data->sg, data->sg_len, in omap_hsmmc_dma_callback()
1183 req_in_progress = host->req_in_progress; in omap_hsmmc_dma_callback()
1184 host->dma_ch = -1; in omap_hsmmc_dma_callback()
1185 spin_unlock_irq(&host->irq_lock); in omap_hsmmc_dma_callback()
1189 struct mmc_request *mrq = host->mrq; in omap_hsmmc_dma_callback()
1191 host->mrq = NULL; in omap_hsmmc_dma_callback()
1192 mmc_request_done(host->mmc, mrq); in omap_hsmmc_dma_callback()
1203 if (!next && data->host_cookie && in omap_hsmmc_pre_dma_transfer()
1204 data->host_cookie != host->next_data.cookie) { in omap_hsmmc_pre_dma_transfer()
1205 dev_warn(host->dev, "[%s] invalid cookie: data->host_cookie %d" in omap_hsmmc_pre_dma_transfer()
1206 " host->next_data.cookie %d\n", in omap_hsmmc_pre_dma_transfer()
1207 __func__, data->host_cookie, host->next_data.cookie); in omap_hsmmc_pre_dma_transfer()
1208 data->host_cookie = 0; in omap_hsmmc_pre_dma_transfer()
1212 if (next || data->host_cookie != host->next_data.cookie) { in omap_hsmmc_pre_dma_transfer()
1213 dma_len = dma_map_sg(chan->device->dev, data->sg, data->sg_len, in omap_hsmmc_pre_dma_transfer()
1217 dma_len = host->next_data.dma_len; in omap_hsmmc_pre_dma_transfer()
1218 host->next_data.dma_len = 0; in omap_hsmmc_pre_dma_transfer()
1223 return -EINVAL; in omap_hsmmc_pre_dma_transfer()
1226 next->dma_len = dma_len; in omap_hsmmc_pre_dma_transfer()
1227 data->host_cookie = ++next->cookie < 0 ? 1 : next->cookie; in omap_hsmmc_pre_dma_transfer()
1229 host->dma_len = dma_len; in omap_hsmmc_pre_dma_transfer()
1235 * Routine to configure and start DMA for the MMC card
1242 struct mmc_data *data = req->data; in omap_hsmmc_setup_dma_transfer()
1245 .src_addr = host->mapbase + OMAP_HSMMC_DATA, in omap_hsmmc_setup_dma_transfer()
1246 .dst_addr = host->mapbase + OMAP_HSMMC_DATA, in omap_hsmmc_setup_dma_transfer()
1249 .src_maxburst = data->blksz / 4, in omap_hsmmc_setup_dma_transfer()
1250 .dst_maxburst = data->blksz / 4, in omap_hsmmc_setup_dma_transfer()
1254 for (i = 0; i < data->sg_len; i++) { in omap_hsmmc_setup_dma_transfer()
1257 sgl = data->sg + i; in omap_hsmmc_setup_dma_transfer()
1258 if (sgl->length % data->blksz) in omap_hsmmc_setup_dma_transfer()
1259 return -EINVAL; in omap_hsmmc_setup_dma_transfer()
1261 if ((data->blksz % 4) != 0) in omap_hsmmc_setup_dma_transfer()
1262 /* REVISIT: The MMC buffer increments only when MSB is written. in omap_hsmmc_setup_dma_transfer()
1265 return -EINVAL; in omap_hsmmc_setup_dma_transfer()
1267 BUG_ON(host->dma_ch != -1); in omap_hsmmc_setup_dma_transfer()
1279 tx = dmaengine_prep_slave_sg(chan, data->sg, data->sg_len, in omap_hsmmc_setup_dma_transfer()
1280 data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, in omap_hsmmc_setup_dma_transfer()
1283 dev_err(mmc_dev(host->mmc), "prep_slave_sg() failed\n"); in omap_hsmmc_setup_dma_transfer()
1285 return -1; in omap_hsmmc_setup_dma_transfer()
1288 tx->callback = omap_hsmmc_dma_callback; in omap_hsmmc_setup_dma_transfer()
1289 tx->callback_param = host; in omap_hsmmc_setup_dma_transfer()
1294 host->dma_ch = 1; in omap_hsmmc_setup_dma_transfer()
1307 reg = OMAP_HSMMC_READ(host->base, SYSCTL); in set_data_timeout()
1312 cycle_ns = 1000000000 / (host->clk_rate / clkd); in set_data_timeout()
1320 dto = 31 - dto; in set_data_timeout()
1325 dto -= 13; in set_data_timeout()
1334 OMAP_HSMMC_WRITE(host->base, SYSCTL, reg); in set_data_timeout()
1339 struct mmc_request *req = host->mrq; in omap_hsmmc_start_dma_transfer()
1342 if (!req->data) in omap_hsmmc_start_dma_transfer()
1344 OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz) in omap_hsmmc_start_dma_transfer()
1345 | (req->data->blocks << 16)); in omap_hsmmc_start_dma_transfer()
1346 set_data_timeout(host, req->data->timeout_ns, in omap_hsmmc_start_dma_transfer()
1347 req->data->timeout_clks); in omap_hsmmc_start_dma_transfer()
1348 chan = omap_hsmmc_get_dma_chan(host, req->data); in omap_hsmmc_start_dma_transfer()
1353 * Configure block length for MMC/SD cards and initiate the transfer.
1361 host->data = req->data; in omap_hsmmc_prepare_data()
1363 if (req->data == NULL) { in omap_hsmmc_prepare_data()
1364 OMAP_HSMMC_WRITE(host->base, BLK, 0); in omap_hsmmc_prepare_data()
1365 if (req->cmd->flags & MMC_RSP_BUSY) { in omap_hsmmc_prepare_data()
1366 timeout = req->cmd->busy_timeout * NSEC_PER_MSEC; in omap_hsmmc_prepare_data()
1380 if (host->use_dma) { in omap_hsmmc_prepare_data()
1383 dev_err(mmc_dev(host->mmc), "MMC start dma failure\n"); in omap_hsmmc_prepare_data()
1390 static void omap_hsmmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq, in omap_hsmmc_post_req() argument
1393 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_post_req()
1394 struct mmc_data *data = mrq->data; in omap_hsmmc_post_req()
1396 if (host->use_dma && data->host_cookie) { in omap_hsmmc_post_req()
1399 dma_unmap_sg(c->device->dev, data->sg, data->sg_len, in omap_hsmmc_post_req()
1401 data->host_cookie = 0; in omap_hsmmc_post_req()
1405 static void omap_hsmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq) in omap_hsmmc_pre_req() argument
1407 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_pre_req()
1409 if (mrq->data->host_cookie) { in omap_hsmmc_pre_req()
1410 mrq->data->host_cookie = 0; in omap_hsmmc_pre_req()
1414 if (host->use_dma) { in omap_hsmmc_pre_req()
1415 struct dma_chan *c = omap_hsmmc_get_dma_chan(host, mrq->data); in omap_hsmmc_pre_req()
1417 if (omap_hsmmc_pre_dma_transfer(host, mrq->data, in omap_hsmmc_pre_req()
1418 &host->next_data, c)) in omap_hsmmc_pre_req()
1419 mrq->data->host_cookie = 0; in omap_hsmmc_pre_req()
1426 static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req) in omap_hsmmc_request() argument
1428 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_request()
1431 BUG_ON(host->req_in_progress); in omap_hsmmc_request()
1432 BUG_ON(host->dma_ch != -1); in omap_hsmmc_request()
1433 if (host->reqs_blocked) in omap_hsmmc_request()
1434 host->reqs_blocked = 0; in omap_hsmmc_request()
1435 WARN_ON(host->mrq != NULL); in omap_hsmmc_request()
1436 host->mrq = req; in omap_hsmmc_request()
1437 host->clk_rate = clk_get_rate(host->fclk); in omap_hsmmc_request()
1440 req->cmd->error = err; in omap_hsmmc_request()
1441 if (req->data) in omap_hsmmc_request()
1442 req->data->error = err; in omap_hsmmc_request()
1443 host->mrq = NULL; in omap_hsmmc_request()
1444 mmc_request_done(mmc, req); in omap_hsmmc_request()
1447 if (req->sbc && !(host->flags & AUTO_CMD23)) { in omap_hsmmc_request()
1448 omap_hsmmc_start_command(host, req->sbc, NULL); in omap_hsmmc_request()
1453 omap_hsmmc_start_command(host, req->cmd, req->data); in omap_hsmmc_request()
1457 static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) in omap_hsmmc_set_ios() argument
1459 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_set_ios()
1462 if (ios->power_mode != host->power_mode) { in omap_hsmmc_set_ios()
1463 switch (ios->power_mode) { in omap_hsmmc_set_ios()
1474 host->power_mode = ios->power_mode; in omap_hsmmc_set_ios()
1481 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { in omap_hsmmc_set_ios()
1485 if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) && in omap_hsmmc_set_ios()
1486 (ios->vdd == DUAL_VOLT_OCR_BIT)) { in omap_hsmmc_set_ios()
1493 if (omap_hsmmc_switch_opcond(host, ios->vdd) != 0) in omap_hsmmc_set_ios()
1494 dev_dbg(mmc_dev(host->mmc), in omap_hsmmc_set_ios()
1507 static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card) in omap_hsmmc_init_card() argument
1509 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_init_card()
1511 if (card->type == MMC_TYPE_SDIO || card->type == MMC_TYPE_SD_COMBO) { in omap_hsmmc_init_card()
1512 struct device_node *np = mmc_dev(mmc)->of_node; in omap_hsmmc_init_card()
1518 * Documentation/devicetree/bindings/mmc/mmc-card.txt in omap_hsmmc_init_card()
1529 dev_info(host->dev, "found wl1251\n"); in omap_hsmmc_init_card()
1530 card->quirks |= MMC_QUIRK_NONSTD_SDIO; in omap_hsmmc_init_card()
1531 card->cccr.wide_bus = 1; in omap_hsmmc_init_card()
1532 card->cis.vendor = 0x104c; in omap_hsmmc_init_card()
1533 card->cis.device = 0x9066; in omap_hsmmc_init_card()
1534 card->cis.blksize = 512; in omap_hsmmc_init_card()
1535 card->cis.max_dtr = 24000000; in omap_hsmmc_init_card()
1536 card->ocr = 0x80; in omap_hsmmc_init_card()
1542 static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable) in omap_hsmmc_enable_sdio_irq() argument
1544 struct omap_hsmmc_host *host = mmc_priv(mmc); in omap_hsmmc_enable_sdio_irq()
1548 spin_lock_irqsave(&host->irq_lock, flags); in omap_hsmmc_enable_sdio_irq()
1550 con = OMAP_HSMMC_READ(host->base, CON); in omap_hsmmc_enable_sdio_irq()
1551 irq_mask = OMAP_HSMMC_READ(host->base, ISE); in omap_hsmmc_enable_sdio_irq()
1553 host->flags |= HSMMC_SDIO_IRQ_ENABLED; in omap_hsmmc_enable_sdio_irq()
1557 host->flags &= ~HSMMC_SDIO_IRQ_ENABLED; in omap_hsmmc_enable_sdio_irq()
1561 OMAP_HSMMC_WRITE(host->base, CON, con); in omap_hsmmc_enable_sdio_irq()
1562 OMAP_HSMMC_WRITE(host->base, IE, irq_mask); in omap_hsmmc_enable_sdio_irq()
1568 if (!host->req_in_progress || !enable) in omap_hsmmc_enable_sdio_irq()
1569 OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); in omap_hsmmc_enable_sdio_irq()
1572 OMAP_HSMMC_READ(host->base, IE); in omap_hsmmc_enable_sdio_irq()
1574 spin_unlock_irqrestore(&host->irq_lock, flags); in omap_hsmmc_enable_sdio_irq()
1582 * For omaps with wake-up path, wakeirq will be irq from pinctrl and in omap_hsmmc_configure_wake_irq()
1587 if (!host->dev->of_node || !host->wake_irq) in omap_hsmmc_configure_wake_irq()
1588 return -ENODEV; in omap_hsmmc_configure_wake_irq()
1590 ret = dev_pm_set_dedicated_wake_irq(host->dev, host->wake_irq); in omap_hsmmc_configure_wake_irq()
1592 dev_err(mmc_dev(host->mmc), "Unable to request wake IRQ\n"); in omap_hsmmc_configure_wake_irq()
1597 * Some omaps don't have wake-up path from deeper idle states in omap_hsmmc_configure_wake_irq()
1598 * and need to remux SDIO DAT1 to GPIO for wake-up from idle. in omap_hsmmc_configure_wake_irq()
1600 if (host->pdata->controller_flags & OMAP_HSMMC_SWAKEUP_MISSING) { in omap_hsmmc_configure_wake_irq()
1601 struct pinctrl *p = devm_pinctrl_get(host->dev); in omap_hsmmc_configure_wake_irq()
1608 dev_info(host->dev, "missing idle pinctrl state\n"); in omap_hsmmc_configure_wake_irq()
1610 ret = -EINVAL; in omap_hsmmc_configure_wake_irq()
1616 OMAP_HSMMC_WRITE(host->base, HCTL, in omap_hsmmc_configure_wake_irq()
1617 OMAP_HSMMC_READ(host->base, HCTL) | IWE); in omap_hsmmc_configure_wake_irq()
1621 dev_pm_clear_wake_irq(host->dev); in omap_hsmmc_configure_wake_irq()
1623 dev_warn(host->dev, "no SDIO IRQ support, falling back to polling\n"); in omap_hsmmc_configure_wake_irq()
1624 host->wake_irq = 0; in omap_hsmmc_configure_wake_irq()
1633 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { in omap_hsmmc_conf_bus_power()
1641 value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK; in omap_hsmmc_conf_bus_power()
1642 OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl); in omap_hsmmc_conf_bus_power()
1644 value = OMAP_HSMMC_READ(host->base, CAPA); in omap_hsmmc_conf_bus_power()
1645 OMAP_HSMMC_WRITE(host->base, CAPA, value | capa); in omap_hsmmc_conf_bus_power()
1651 static int omap_hsmmc_multi_io_quirk(struct mmc_card *card, in omap_hsmmc_multi_io_quirk() argument
1676 struct mmc_host *mmc = s->private; in mmc_regs_show() local
1677 struct omap_hsmmc_host *host = mmc_priv(mmc); in mmc_regs_show()
1679 seq_printf(s, "mmc%d:\n", mmc->index); in mmc_regs_show()
1681 (mmc->caps & MMC_CAP_SDIO_IRQ) ? "interrupt" : "polling"); in mmc_regs_show()
1683 if (mmc->caps & MMC_CAP_SDIO_IRQ) { in mmc_regs_show()
1685 (host->flags & HSMMC_SDIO_IRQ_ENABLED) ? "enabled" in mmc_regs_show()
1688 seq_printf(s, "ctx_loss:\t%d\n", host->context_loss); in mmc_regs_show()
1690 pm_runtime_get_sync(host->dev); in mmc_regs_show()
1693 OMAP_HSMMC_READ(host->base, CON)); in mmc_regs_show()
1695 OMAP_HSMMC_READ(host->base, PSTATE)); in mmc_regs_show()
1697 OMAP_HSMMC_READ(host->base, HCTL)); in mmc_regs_show()
1699 OMAP_HSMMC_READ(host->base, SYSCTL)); in mmc_regs_show()
1701 OMAP_HSMMC_READ(host->base, IE)); in mmc_regs_show()
1703 OMAP_HSMMC_READ(host->base, ISE)); in mmc_regs_show()
1705 OMAP_HSMMC_READ(host->base, CAPA)); in mmc_regs_show()
1707 pm_runtime_mark_last_busy(host->dev); in mmc_regs_show()
1708 pm_runtime_put_autosuspend(host->dev); in mmc_regs_show()
1715 static void omap_hsmmc_debugfs(struct mmc_host *mmc) in omap_hsmmc_debugfs() argument
1717 if (mmc->debugfs_root) in omap_hsmmc_debugfs()
1718 debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root, in omap_hsmmc_debugfs()
1719 mmc, &mmc_regs_fops); in omap_hsmmc_debugfs()
1724 static void omap_hsmmc_debugfs(struct mmc_host *mmc) in omap_hsmmc_debugfs() argument
1746 .compatible = "ti,omap2-hsmmc",
1749 .compatible = "ti,omap3-pre-es3-hsmmc",
1753 .compatible = "ti,omap3-hsmmc",
1756 .compatible = "ti,omap4-hsmmc",
1760 .compatible = "ti,am33xx-hsmmc",
1770 struct device_node *np = dev->of_node; in of_get_hsmmc_pdata()
1774 return ERR_PTR(-ENOMEM); /* out of memory */ in of_get_hsmmc_pdata()
1777 if (legacy && legacy->name) in of_get_hsmmc_pdata()
1778 pdata->name = legacy->name; in of_get_hsmmc_pdata()
1780 if (of_find_property(np, "ti,dual-volt", NULL)) in of_get_hsmmc_pdata()
1781 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; in of_get_hsmmc_pdata()
1783 if (of_find_property(np, "ti,non-removable", NULL)) { in of_get_hsmmc_pdata()
1784 pdata->nonremovable = true; in of_get_hsmmc_pdata()
1785 pdata->no_regulator_off_init = true; in of_get_hsmmc_pdata()
1788 if (of_find_property(np, "ti,needs-special-reset", NULL)) in of_get_hsmmc_pdata()
1789 pdata->features |= HSMMC_HAS_UPDATED_RESET; in of_get_hsmmc_pdata()
1791 if (of_find_property(np, "ti,needs-special-hs-handling", NULL)) in of_get_hsmmc_pdata()
1792 pdata->features |= HSMMC_HAS_HSPE_SUPPORT; in of_get_hsmmc_pdata()
1800 return ERR_PTR(-EINVAL); in of_get_hsmmc_pdata()
1806 struct omap_hsmmc_platform_data *pdata = pdev->dev.platform_data; in omap_hsmmc_probe()
1807 struct mmc_host *mmc; in omap_hsmmc_probe() local
1815 match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev); in omap_hsmmc_probe()
1817 pdata = of_get_hsmmc_pdata(&pdev->dev); in omap_hsmmc_probe()
1822 if (match->data) { in omap_hsmmc_probe()
1823 data = match->data; in omap_hsmmc_probe()
1824 pdata->reg_offset = data->reg_offset; in omap_hsmmc_probe()
1825 pdata->controller_flags |= data->controller_flags; in omap_hsmmc_probe()
1830 dev_err(&pdev->dev, "Platform Data is missing\n"); in omap_hsmmc_probe()
1831 return -ENXIO; in omap_hsmmc_probe()
1837 return -ENXIO; in omap_hsmmc_probe()
1839 base = devm_ioremap_resource(&pdev->dev, res); in omap_hsmmc_probe()
1843 mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev); in omap_hsmmc_probe()
1844 if (!mmc) { in omap_hsmmc_probe()
1845 ret = -ENOMEM; in omap_hsmmc_probe()
1849 ret = mmc_of_parse(mmc); in omap_hsmmc_probe()
1853 host = mmc_priv(mmc); in omap_hsmmc_probe()
1854 host->mmc = mmc; in omap_hsmmc_probe()
1855 host->pdata = pdata; in omap_hsmmc_probe()
1856 host->dev = &pdev->dev; in omap_hsmmc_probe()
1857 host->use_dma = 1; in omap_hsmmc_probe()
1858 host->dma_ch = -1; in omap_hsmmc_probe()
1859 host->irq = irq; in omap_hsmmc_probe()
1860 host->mapbase = res->start + pdata->reg_offset; in omap_hsmmc_probe()
1861 host->base = base + pdata->reg_offset; in omap_hsmmc_probe()
1862 host->power_mode = MMC_POWER_OFF; in omap_hsmmc_probe()
1863 host->next_data.cookie = 1; in omap_hsmmc_probe()
1864 host->pbias_enabled = 0; in omap_hsmmc_probe()
1865 host->vqmmc_enabled = 0; in omap_hsmmc_probe()
1869 if (pdev->dev.of_node) in omap_hsmmc_probe()
1870 host->wake_irq = irq_of_parse_and_map(pdev->dev.of_node, 1); in omap_hsmmc_probe()
1872 mmc->ops = &omap_hsmmc_ops; in omap_hsmmc_probe()
1874 mmc->f_min = OMAP_MMC_MIN_CLOCK; in omap_hsmmc_probe()
1876 if (pdata->max_freq > 0) in omap_hsmmc_probe()
1877 mmc->f_max = pdata->max_freq; in omap_hsmmc_probe()
1878 else if (mmc->f_max == 0) in omap_hsmmc_probe()
1879 mmc->f_max = OMAP_MMC_MAX_CLOCK; in omap_hsmmc_probe()
1881 spin_lock_init(&host->irq_lock); in omap_hsmmc_probe()
1883 host->fclk = devm_clk_get(&pdev->dev, "fck"); in omap_hsmmc_probe()
1884 if (IS_ERR(host->fclk)) { in omap_hsmmc_probe()
1885 ret = PTR_ERR(host->fclk); in omap_hsmmc_probe()
1886 host->fclk = NULL; in omap_hsmmc_probe()
1890 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) { in omap_hsmmc_probe()
1891 …dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performanc… in omap_hsmmc_probe()
1895 device_init_wakeup(&pdev->dev, true); in omap_hsmmc_probe()
1896 pm_runtime_enable(host->dev); in omap_hsmmc_probe()
1897 pm_runtime_get_sync(host->dev); in omap_hsmmc_probe()
1898 pm_runtime_set_autosuspend_delay(host->dev, MMC_AUTOSUSPEND_DELAY); in omap_hsmmc_probe()
1899 pm_runtime_use_autosuspend(host->dev); in omap_hsmmc_probe()
1903 host->dbclk = devm_clk_get(&pdev->dev, "mmchsdb_fck"); in omap_hsmmc_probe()
1905 * MMC can still work without debounce clock. in omap_hsmmc_probe()
1907 if (IS_ERR(host->dbclk)) { in omap_hsmmc_probe()
1908 host->dbclk = NULL; in omap_hsmmc_probe()
1909 } else if (clk_prepare_enable(host->dbclk) != 0) { in omap_hsmmc_probe()
1910 dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); in omap_hsmmc_probe()
1911 host->dbclk = NULL; in omap_hsmmc_probe()
1916 mmc->max_segs = 64; in omap_hsmmc_probe()
1918 mmc->max_blk_size = 512; /* Block Length at max can be 1024 */ in omap_hsmmc_probe()
1919 mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */ in omap_hsmmc_probe()
1920 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; in omap_hsmmc_probe()
1922 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | in omap_hsmmc_probe()
1925 mmc->caps |= mmc_pdata(host)->caps; in omap_hsmmc_probe()
1926 if (mmc->caps & MMC_CAP_8_BIT_DATA) in omap_hsmmc_probe()
1927 mmc->caps |= MMC_CAP_4_BIT_DATA; in omap_hsmmc_probe()
1929 if (mmc_pdata(host)->nonremovable) in omap_hsmmc_probe()
1930 mmc->caps |= MMC_CAP_NONREMOVABLE; in omap_hsmmc_probe()
1932 mmc->pm_caps |= mmc_pdata(host)->pm_caps; in omap_hsmmc_probe()
1936 host->rx_chan = dma_request_chan(&pdev->dev, "rx"); in omap_hsmmc_probe()
1937 if (IS_ERR(host->rx_chan)) { in omap_hsmmc_probe()
1938 dev_err(mmc_dev(host->mmc), "RX DMA channel request failed\n"); in omap_hsmmc_probe()
1939 ret = PTR_ERR(host->rx_chan); in omap_hsmmc_probe()
1943 host->tx_chan = dma_request_chan(&pdev->dev, "tx"); in omap_hsmmc_probe()
1944 if (IS_ERR(host->tx_chan)) { in omap_hsmmc_probe()
1945 dev_err(mmc_dev(host->mmc), "TX DMA channel request failed\n"); in omap_hsmmc_probe()
1946 ret = PTR_ERR(host->tx_chan); in omap_hsmmc_probe()
1953 * 32-bit transfers, the DMA engine can do longer segments than this in omap_hsmmc_probe()
1954 * but there is no way to represent that in the DMA model - if we in omap_hsmmc_probe()
1957 mmc->max_seg_size = min3(mmc->max_req_size, in omap_hsmmc_probe()
1958 dma_get_max_seg_size(host->rx_chan->device->dev), in omap_hsmmc_probe()
1959 dma_get_max_seg_size(host->tx_chan->device->dev)); in omap_hsmmc_probe()
1961 /* Request IRQ for MMC operations */ in omap_hsmmc_probe()
1962 ret = devm_request_irq(&pdev->dev, host->irq, omap_hsmmc_irq, 0, in omap_hsmmc_probe()
1963 mmc_hostname(mmc), host); in omap_hsmmc_probe()
1965 dev_err(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n"); in omap_hsmmc_probe()
1973 if (!mmc->ocr_avail) in omap_hsmmc_probe()
1974 mmc->ocr_avail = mmc_pdata(host)->ocr_mask; in omap_hsmmc_probe()
1980 * wake-up interrupt configured from device tree. This is because in omap_hsmmc_probe()
1981 * the wake-up interrupt is needed for idle state and some in omap_hsmmc_probe()
1988 mmc->caps |= MMC_CAP_SDIO_IRQ; in omap_hsmmc_probe()
1990 mmc_add_host(mmc); in omap_hsmmc_probe()
1992 if (mmc_pdata(host)->name != NULL) { in omap_hsmmc_probe()
1993 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name); in omap_hsmmc_probe()
1998 omap_hsmmc_debugfs(mmc); in omap_hsmmc_probe()
1999 pm_runtime_mark_last_busy(host->dev); in omap_hsmmc_probe()
2000 pm_runtime_put_autosuspend(host->dev); in omap_hsmmc_probe()
2005 mmc_remove_host(mmc); in omap_hsmmc_probe()
2007 device_init_wakeup(&pdev->dev, false); in omap_hsmmc_probe()
2008 if (!IS_ERR_OR_NULL(host->tx_chan)) in omap_hsmmc_probe()
2009 dma_release_channel(host->tx_chan); in omap_hsmmc_probe()
2010 if (!IS_ERR_OR_NULL(host->rx_chan)) in omap_hsmmc_probe()
2011 dma_release_channel(host->rx_chan); in omap_hsmmc_probe()
2012 pm_runtime_dont_use_autosuspend(host->dev); in omap_hsmmc_probe()
2013 pm_runtime_put_sync(host->dev); in omap_hsmmc_probe()
2014 pm_runtime_disable(host->dev); in omap_hsmmc_probe()
2015 clk_disable_unprepare(host->dbclk); in omap_hsmmc_probe()
2017 mmc_free_host(mmc); in omap_hsmmc_probe()
2026 pm_runtime_get_sync(host->dev); in omap_hsmmc_remove()
2027 mmc_remove_host(host->mmc); in omap_hsmmc_remove()
2029 dma_release_channel(host->tx_chan); in omap_hsmmc_remove()
2030 dma_release_channel(host->rx_chan); in omap_hsmmc_remove()
2032 dev_pm_clear_wake_irq(host->dev); in omap_hsmmc_remove()
2033 pm_runtime_dont_use_autosuspend(host->dev); in omap_hsmmc_remove()
2034 pm_runtime_put_sync(host->dev); in omap_hsmmc_remove()
2035 pm_runtime_disable(host->dev); in omap_hsmmc_remove()
2036 device_init_wakeup(&pdev->dev, false); in omap_hsmmc_remove()
2037 clk_disable_unprepare(host->dbclk); in omap_hsmmc_remove()
2039 mmc_free_host(host->mmc); in omap_hsmmc_remove()
2052 pm_runtime_get_sync(host->dev); in omap_hsmmc_suspend()
2054 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) { in omap_hsmmc_suspend()
2055 OMAP_HSMMC_WRITE(host->base, ISE, 0); in omap_hsmmc_suspend()
2056 OMAP_HSMMC_WRITE(host->base, IE, 0); in omap_hsmmc_suspend()
2057 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); in omap_hsmmc_suspend()
2058 OMAP_HSMMC_WRITE(host->base, HCTL, in omap_hsmmc_suspend()
2059 OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP); in omap_hsmmc_suspend()
2062 clk_disable_unprepare(host->dbclk); in omap_hsmmc_suspend()
2064 pm_runtime_put_sync(host->dev); in omap_hsmmc_suspend()
2068 /* Routine to resume the MMC device */
2076 pm_runtime_get_sync(host->dev); in omap_hsmmc_resume()
2078 clk_prepare_enable(host->dbclk); in omap_hsmmc_resume()
2080 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) in omap_hsmmc_resume()
2083 pm_runtime_mark_last_busy(host->dev); in omap_hsmmc_resume()
2084 pm_runtime_put_autosuspend(host->dev); in omap_hsmmc_resume()
2099 spin_lock_irqsave(&host->irq_lock, flags); in omap_hsmmc_runtime_suspend()
2100 if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) && in omap_hsmmc_runtime_suspend()
2101 (host->flags & HSMMC_SDIO_IRQ_ENABLED)) { in omap_hsmmc_runtime_suspend()
2103 OMAP_HSMMC_WRITE(host->base, ISE, 0); in omap_hsmmc_runtime_suspend()
2104 OMAP_HSMMC_WRITE(host->base, IE, 0); in omap_hsmmc_runtime_suspend()
2106 if (!(OMAP_HSMMC_READ(host->base, PSTATE) & DLEV_DAT(1))) { in omap_hsmmc_runtime_suspend()
2110 * multi-core, abort in omap_hsmmc_runtime_suspend()
2113 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); in omap_hsmmc_runtime_suspend()
2114 OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN); in omap_hsmmc_runtime_suspend()
2115 OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN); in omap_hsmmc_runtime_suspend()
2117 ret = -EBUSY; in omap_hsmmc_runtime_suspend()
2127 spin_unlock_irqrestore(&host->irq_lock, flags); in omap_hsmmc_runtime_suspend()
2140 spin_lock_irqsave(&host->irq_lock, flags); in omap_hsmmc_runtime_resume()
2141 if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) && in omap_hsmmc_runtime_resume()
2142 (host->flags & HSMMC_SDIO_IRQ_ENABLED)) { in omap_hsmmc_runtime_resume()
2144 pinctrl_select_default_state(host->dev); in omap_hsmmc_runtime_resume()
2147 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); in omap_hsmmc_runtime_resume()
2148 OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN); in omap_hsmmc_runtime_resume()
2149 OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN); in omap_hsmmc_runtime_resume()
2151 pinctrl_select_default_state(host->dev); in omap_hsmmc_runtime_resume()
2153 spin_unlock_irqrestore(&host->irq_lock, flags); in omap_hsmmc_runtime_resume()
2175 MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");