Lines Matching +full:sdhci +full:- +full:8

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* linux/drivers/mmc/host/sdhci-s3c.c
9 * SDHCI (HSMMC) support for Samsung SoC
14 #include <linux/dma-mapping.h>
16 #include <linux/platform_data/mmc-sdhci-s3c.h>
29 #include "sdhci.h"
63 #define S3C_SDHCI_CTRL2_ENCLKOUTHOLD BIT(8)
86 #define S3C_SDHCI_CTRL3_FIA1_MASK (0x7f << 8)
87 #define S3C_SDHCI_CTRL3_FIA1_SHIFT (8)
88 #define S3C_SDHCI_CTRL3_FIA1(_x) ((_x) << 8)
104 * struct sdhci_s3c - S3C SDHCI instance
105 * @host: The SDHCI host created
114 * @no_divider: No or non-standard internal clock divider.
132 * struct sdhci_s3c_driver_data - S3C SDHCI platform specific driver data
133 * @sdhci_quirks: sdhci host specific quirks.
134 * @no_divider: no or non-standard internal clock divider.
136 * Specifies platform specific configuration of sdhci controller.
151 * sdhci_s3c_get_max_clk - callback to get maximum clock frequency.
152 * @host: The SDHCI host instance.
163 rate = ourhost->clk_rates[src]; in sdhci_s3c_get_max_clk()
172 * sdhci_s3c_consider_clock - consider one the bus clocks for current setting
173 * @ourhost: Our SDHCI instance.
182 struct clk *clksrc = ourhost->clk_bus[src]; in sdhci_s3c_consider_clock()
189 * If controller uses a non-standard clock division, find the best clock in sdhci_s3c_consider_clock()
192 if (ourhost->no_divider) { in sdhci_s3c_consider_clock()
194 return wanted - rate; in sdhci_s3c_consider_clock()
197 rate = ourhost->clk_rates[src]; in sdhci_s3c_consider_clock()
199 for (shift = 0; shift <= 8; ++shift) { in sdhci_s3c_consider_clock()
204 if (shift > 8) { in sdhci_s3c_consider_clock()
205 dev_dbg(&ourhost->pdev->dev, in sdhci_s3c_consider_clock()
211 dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n", in sdhci_s3c_consider_clock()
214 return wanted - (rate >> shift); in sdhci_s3c_consider_clock()
218 * sdhci_s3c_set_clock - callback on clock change
219 * @host: The SDHCI host being changed
234 host->mmc->actual_clock = 0; in sdhci_s3c_set_clock()
250 dev_dbg(&ourhost->pdev->dev, in sdhci_s3c_set_clock()
255 if (ourhost->cur_clk != best_src) { in sdhci_s3c_set_clock()
256 struct clk *clk = ourhost->clk_bus[best_src]; in sdhci_s3c_set_clock()
259 if (ourhost->cur_clk >= 0) in sdhci_s3c_set_clock()
261 ourhost->clk_bus[ourhost->cur_clk]); in sdhci_s3c_set_clock()
263 ourhost->cur_clk = best_src; in sdhci_s3c_set_clock()
264 host->max_clk = ourhost->clk_rates[best_src]; in sdhci_s3c_set_clock()
268 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL); in sdhci_s3c_set_clock()
270 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2); in sdhci_s3c_set_clock()
273 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2); in sdhci_s3c_set_clock()
277 host->ioaddr + S3C64XX_SDHCI_CONTROL4); in sdhci_s3c_set_clock()
279 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2); in sdhci_s3c_set_clock()
285 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2); in sdhci_s3c_set_clock()
291 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL3); in sdhci_s3c_set_clock()
297 * sdhci_s3c_get_min_clock - callback to get minimal supported clock value
298 * @host: The SDHCI host being queried
312 rate = ourhost->clk_rates[src] / 256; in sdhci_s3c_get_min_clock()
322 /* sdhci_cmu_get_max_clk - callback to get maximum clock frequency.*/
332 clk = ourhost->clk_bus[src]; in sdhci_cmu_get_max_clock()
344 /* sdhci_cmu_get_min_clock - callback to get minimal supported clock value. */
354 clk = ourhost->clk_bus[src]; in sdhci_cmu_get_min_clock()
366 /* sdhci_cmu_set_clock - callback on clock change.*/
370 struct device *dev = &ourhost->pdev->dev; in sdhci_cmu_set_clock()
375 host->mmc->actual_clock = 0; in sdhci_cmu_set_clock()
390 ret = clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock); in sdhci_cmu_set_clock()
393 mmc_hostname(host->mmc), clock); in sdhci_cmu_set_clock()
406 mmc_hostname(host->mmc)); in sdhci_cmu_set_clock()
409 timeout--; in sdhci_cmu_set_clock()
430 struct device_node *node = dev->of_node; in sdhci_s3c_parse_dt()
433 /* if the bus-width property is not specified, assume width as 1 */ in sdhci_s3c_parse_dt()
434 if (of_property_read_u32(node, "bus-width", &max_width)) in sdhci_s3c_parse_dt()
436 pdata->max_width = max_width; in sdhci_s3c_parse_dt()
439 if (of_get_property(node, "broken-cd", NULL)) { in sdhci_s3c_parse_dt()
440 pdata->cd_type = S3C_SDHCI_CD_NONE; in sdhci_s3c_parse_dt()
444 if (of_get_property(node, "non-removable", NULL)) { in sdhci_s3c_parse_dt()
445 pdata->cd_type = S3C_SDHCI_CD_PERMANENT; in sdhci_s3c_parse_dt()
449 if (of_get_named_gpio(node, "cd-gpios", 0)) in sdhci_s3c_parse_dt()
453 pdata->cd_type = S3C_SDHCI_CD_INTERNAL; in sdhci_s3c_parse_dt()
460 return -EINVAL; in sdhci_s3c_parse_dt()
472 if (pdev->dev.of_node) { in sdhci_s3c_get_driver_data()
474 match = of_match_node(sdhci_s3c_dt_match, pdev->dev.of_node); in sdhci_s3c_get_driver_data()
475 return (struct sdhci_s3c_drv_data *)match->data; in sdhci_s3c_get_driver_data()
479 platform_get_device_id(pdev)->driver_data; in sdhci_s3c_get_driver_data()
486 struct device *dev = &pdev->dev; in sdhci_s3c_probe()
491 if (!pdev->dev.platform_data && !pdev->dev.of_node) { in sdhci_s3c_probe()
493 return -ENOENT; in sdhci_s3c_probe()
507 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in sdhci_s3c_probe()
509 ret = -ENOMEM; in sdhci_s3c_probe()
513 if (pdev->dev.of_node) { in sdhci_s3c_probe()
514 ret = sdhci_s3c_parse_dt(&pdev->dev, host, pdata); in sdhci_s3c_probe()
518 memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); in sdhci_s3c_probe()
523 sc->host = host; in sdhci_s3c_probe()
524 sc->pdev = pdev; in sdhci_s3c_probe()
525 sc->pdata = pdata; in sdhci_s3c_probe()
526 sc->cur_clk = -1; in sdhci_s3c_probe()
530 sc->clk_io = devm_clk_get(dev, "hsmmc"); in sdhci_s3c_probe()
531 if (IS_ERR(sc->clk_io)) { in sdhci_s3c_probe()
533 ret = PTR_ERR(sc->clk_io); in sdhci_s3c_probe()
538 clk_prepare_enable(sc->clk_io); in sdhci_s3c_probe()
544 sc->clk_bus[ptr] = devm_clk_get(dev, name); in sdhci_s3c_probe()
545 if (IS_ERR(sc->clk_bus[ptr])) in sdhci_s3c_probe()
549 sc->clk_rates[ptr] = clk_get_rate(sc->clk_bus[ptr]); in sdhci_s3c_probe()
552 ptr, name, sc->clk_rates[ptr]); in sdhci_s3c_probe()
557 ret = -ENOENT; in sdhci_s3c_probe()
561 host->ioaddr = devm_platform_ioremap_resource(pdev, 0); in sdhci_s3c_probe()
562 if (IS_ERR(host->ioaddr)) { in sdhci_s3c_probe()
563 ret = PTR_ERR(host->ioaddr); in sdhci_s3c_probe()
568 if (pdata->cfg_gpio) in sdhci_s3c_probe()
569 pdata->cfg_gpio(pdev, pdata->max_width); in sdhci_s3c_probe()
571 host->hw_name = "samsung-hsmmc"; in sdhci_s3c_probe()
572 host->ops = &sdhci_s3c_ops; in sdhci_s3c_probe()
573 host->quirks = 0; in sdhci_s3c_probe()
574 host->quirks2 = 0; in sdhci_s3c_probe()
575 host->irq = irq; in sdhci_s3c_probe()
578 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; in sdhci_s3c_probe()
579 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT; in sdhci_s3c_probe()
581 host->quirks |= drv_data->sdhci_quirks; in sdhci_s3c_probe()
582 sc->no_divider = drv_data->no_divider; in sdhci_s3c_probe()
589 host->quirks |= SDHCI_QUIRK_BROKEN_DMA; in sdhci_s3c_probe()
593 /* It seems we do not get an DATA transfer complete on non-busy in sdhci_s3c_probe()
595 * SDHCI block, or a missing configuration that needs to be set. */ in sdhci_s3c_probe()
596 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ; in sdhci_s3c_probe()
599 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12; in sdhci_s3c_probe()
602 host->quirks |= SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC; in sdhci_s3c_probe()
604 if (pdata->cd_type == S3C_SDHCI_CD_NONE || in sdhci_s3c_probe()
605 pdata->cd_type == S3C_SDHCI_CD_PERMANENT) in sdhci_s3c_probe()
606 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; in sdhci_s3c_probe()
608 if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT) in sdhci_s3c_probe()
609 host->mmc->caps = MMC_CAP_NONREMOVABLE; in sdhci_s3c_probe()
611 switch (pdata->max_width) { in sdhci_s3c_probe()
612 case 8: in sdhci_s3c_probe()
613 host->mmc->caps |= MMC_CAP_8_BIT_DATA; in sdhci_s3c_probe()
616 host->mmc->caps |= MMC_CAP_4_BIT_DATA; in sdhci_s3c_probe()
620 if (pdata->pm_caps) in sdhci_s3c_probe()
621 host->mmc->pm_caps |= pdata->pm_caps; in sdhci_s3c_probe()
623 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR | in sdhci_s3c_probe()
627 host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK; in sdhci_s3c_probe()
633 if (sc->no_divider) { in sdhci_s3c_probe()
640 if (pdata->host_caps) in sdhci_s3c_probe()
641 host->mmc->caps |= pdata->host_caps; in sdhci_s3c_probe()
643 if (pdata->host_caps2) in sdhci_s3c_probe()
644 host->mmc->caps2 |= pdata->host_caps2; in sdhci_s3c_probe()
646 pm_runtime_enable(&pdev->dev); in sdhci_s3c_probe()
647 pm_runtime_set_autosuspend_delay(&pdev->dev, 50); in sdhci_s3c_probe()
648 pm_runtime_use_autosuspend(&pdev->dev); in sdhci_s3c_probe()
649 pm_suspend_ignore_children(&pdev->dev, 1); in sdhci_s3c_probe()
651 ret = mmc_of_parse(host->mmc); in sdhci_s3c_probe()
660 if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL) in sdhci_s3c_probe()
661 clk_disable_unprepare(sc->clk_io); in sdhci_s3c_probe()
666 pm_runtime_disable(&pdev->dev); in sdhci_s3c_probe()
669 clk_disable_unprepare(sc->clk_io); in sdhci_s3c_probe()
682 if (sc->ext_cd_irq) in sdhci_s3c_remove()
683 free_irq(sc->ext_cd_irq, sc); in sdhci_s3c_remove()
686 if (sc->pdata->cd_type != S3C_SDHCI_CD_INTERNAL) in sdhci_s3c_remove()
687 clk_prepare_enable(sc->clk_io); in sdhci_s3c_remove()
691 pm_runtime_dont_use_autosuspend(&pdev->dev); in sdhci_s3c_remove()
692 pm_runtime_disable(&pdev->dev); in sdhci_s3c_remove()
694 clk_disable_unprepare(sc->clk_io); in sdhci_s3c_remove()
706 if (host->tuning_mode != SDHCI_TUNING_MODE_3) in sdhci_s3c_suspend()
707 mmc_retune_needed(host->mmc); in sdhci_s3c_suspend()
725 struct clk *busclk = ourhost->clk_io; in sdhci_s3c_runtime_suspend()
730 if (host->tuning_mode != SDHCI_TUNING_MODE_3) in sdhci_s3c_runtime_suspend()
731 mmc_retune_needed(host->mmc); in sdhci_s3c_runtime_suspend()
733 if (ourhost->cur_clk >= 0) in sdhci_s3c_runtime_suspend()
734 clk_disable_unprepare(ourhost->clk_bus[ourhost->cur_clk]); in sdhci_s3c_runtime_suspend()
743 struct clk *busclk = ourhost->clk_io; in sdhci_s3c_runtime_resume()
747 if (ourhost->cur_clk >= 0) in sdhci_s3c_runtime_resume()
748 clk_prepare_enable(ourhost->clk_bus[ourhost->cur_clk]); in sdhci_s3c_runtime_resume()
762 .name = "s3c-sdhci",
775 { .compatible = "samsung,s3c6410-sdhci", },
776 { .compatible = "samsung,exynos4210-sdhci",
788 .name = "s3c-sdhci",
797 MODULE_DESCRIPTION("Samsung SDHCI (HSMMC) glue");
800 MODULE_ALIAS("platform:s3c-sdhci");