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>
27 #include "sdhci.h"
61 #define S3C_SDHCI_CTRL2_ENCLKOUTHOLD BIT(8)
84 #define S3C_SDHCI_CTRL3_FIA1_MASK (0x7f << 8)
85 #define S3C_SDHCI_CTRL3_FIA1_SHIFT (8)
86 #define S3C_SDHCI_CTRL3_FIA1(_x) ((_x) << 8)
102 * struct sdhci_s3c - S3C SDHCI instance
103 * @host: The SDHCI host created
112 * @no_divider: No or non-standard internal clock divider.
130 * struct sdhci_s3c_drv_data - S3C SDHCI platform specific driver data
131 * @sdhci_quirks: sdhci host specific quirks.
132 * @no_divider: no or non-standard internal clock divider.
135 * 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()
439 struct device_node *node = dev->of_node; in sdhci_s3c_parse_dt()
442 /* if the bus-width property is not specified, assume width as 1 */ in sdhci_s3c_parse_dt()
443 if (of_property_read_u32(node, "bus-width", &max_width)) in sdhci_s3c_parse_dt()
445 pdata->max_width = max_width; in sdhci_s3c_parse_dt()
448 if (of_property_read_bool(node, "broken-cd")) { in sdhci_s3c_parse_dt()
449 pdata->cd_type = S3C_SDHCI_CD_NONE; in sdhci_s3c_parse_dt()
453 if (of_property_read_bool(node, "non-removable")) { in sdhci_s3c_parse_dt()
454 pdata->cd_type = S3C_SDHCI_CD_PERMANENT; in sdhci_s3c_parse_dt()
458 if (of_property_present(node, "cd-gpios")) in sdhci_s3c_parse_dt()
462 pdata->cd_type = S3C_SDHCI_CD_INTERNAL; in sdhci_s3c_parse_dt()
469 return -EINVAL; in sdhci_s3c_parse_dt()
477 if (pdev->dev.of_node) in sdhci_s3c_get_driver_data()
478 return of_device_get_match_data(&pdev->dev); in sdhci_s3c_get_driver_data()
481 platform_get_device_id(pdev)->driver_data; in sdhci_s3c_get_driver_data()
488 struct device *dev = &pdev->dev; in sdhci_s3c_probe()
493 if (!pdev->dev.platform_data && !pdev->dev.of_node) { in sdhci_s3c_probe()
495 return -ENOENT; in sdhci_s3c_probe()
509 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in sdhci_s3c_probe()
511 ret = -ENOMEM; in sdhci_s3c_probe()
515 if (pdev->dev.of_node) { in sdhci_s3c_probe()
516 ret = sdhci_s3c_parse_dt(&pdev->dev, host, pdata); in sdhci_s3c_probe()
520 memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); in sdhci_s3c_probe()
525 sc->host = host; in sdhci_s3c_probe()
526 sc->pdev = pdev; in sdhci_s3c_probe()
527 sc->pdata = pdata; in sdhci_s3c_probe()
528 sc->cur_clk = -1; in sdhci_s3c_probe()
532 sc->clk_io = devm_clk_get(dev, "hsmmc"); in sdhci_s3c_probe()
533 if (IS_ERR(sc->clk_io)) { in sdhci_s3c_probe()
535 ret = PTR_ERR(sc->clk_io); in sdhci_s3c_probe()
540 clk_prepare_enable(sc->clk_io); in sdhci_s3c_probe()
546 sc->clk_bus[ptr] = devm_clk_get(dev, name); in sdhci_s3c_probe()
547 if (IS_ERR(sc->clk_bus[ptr])) in sdhci_s3c_probe()
551 sc->clk_rates[ptr] = clk_get_rate(sc->clk_bus[ptr]); in sdhci_s3c_probe()
554 ptr, name, sc->clk_rates[ptr]); in sdhci_s3c_probe()
559 ret = -ENOENT; in sdhci_s3c_probe()
563 host->ioaddr = devm_platform_ioremap_resource(pdev, 0); in sdhci_s3c_probe()
564 if (IS_ERR(host->ioaddr)) { in sdhci_s3c_probe()
565 ret = PTR_ERR(host->ioaddr); in sdhci_s3c_probe()
570 if (pdata->cfg_gpio) in sdhci_s3c_probe()
571 pdata->cfg_gpio(pdev, pdata->max_width); in sdhci_s3c_probe()
573 host->hw_name = "samsung-hsmmc"; in sdhci_s3c_probe()
574 host->ops = &sdhci_s3c_ops_s3c6410; in sdhci_s3c_probe()
575 host->quirks = 0; in sdhci_s3c_probe()
576 host->quirks2 = 0; in sdhci_s3c_probe()
577 host->irq = irq; in sdhci_s3c_probe()
580 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; in sdhci_s3c_probe()
581 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT; in sdhci_s3c_probe()
583 host->quirks |= drv_data->sdhci_quirks; in sdhci_s3c_probe()
584 host->ops = drv_data->ops; in sdhci_s3c_probe()
585 sc->no_divider = drv_data->no_divider; in sdhci_s3c_probe()
592 host->quirks |= SDHCI_QUIRK_BROKEN_DMA; in sdhci_s3c_probe()
596 /* It seems we do not get an DATA transfer complete on non-busy in sdhci_s3c_probe()
598 * SDHCI block, or a missing configuration that needs to be set. */ in sdhci_s3c_probe()
599 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ; in sdhci_s3c_probe()
602 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12; in sdhci_s3c_probe()
605 host->quirks |= SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC; in sdhci_s3c_probe()
607 if (pdata->cd_type == S3C_SDHCI_CD_NONE || in sdhci_s3c_probe()
608 pdata->cd_type == S3C_SDHCI_CD_PERMANENT) in sdhci_s3c_probe()
609 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; in sdhci_s3c_probe()
611 if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT) in sdhci_s3c_probe()
612 host->mmc->caps = MMC_CAP_NONREMOVABLE; in sdhci_s3c_probe()
614 switch (pdata->max_width) { in sdhci_s3c_probe()
615 case 8: in sdhci_s3c_probe()
616 host->mmc->caps |= MMC_CAP_8_BIT_DATA; in sdhci_s3c_probe()
619 host->mmc->caps |= MMC_CAP_4_BIT_DATA; in sdhci_s3c_probe()
623 if (pdata->pm_caps) in sdhci_s3c_probe()
624 host->mmc->pm_caps |= pdata->pm_caps; in sdhci_s3c_probe()
626 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR | in sdhci_s3c_probe()
630 host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK; in sdhci_s3c_probe()
633 if (pdata->host_caps) in sdhci_s3c_probe()
634 host->mmc->caps |= pdata->host_caps; in sdhci_s3c_probe()
636 if (pdata->host_caps2) in sdhci_s3c_probe()
637 host->mmc->caps2 |= pdata->host_caps2; in sdhci_s3c_probe()
639 pm_runtime_enable(&pdev->dev); in sdhci_s3c_probe()
640 pm_runtime_set_autosuspend_delay(&pdev->dev, 50); in sdhci_s3c_probe()
641 pm_runtime_use_autosuspend(&pdev->dev); in sdhci_s3c_probe()
642 pm_suspend_ignore_children(&pdev->dev, 1); in sdhci_s3c_probe()
644 ret = mmc_of_parse(host->mmc); in sdhci_s3c_probe()
653 if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL) in sdhci_s3c_probe()
654 clk_disable_unprepare(sc->clk_io); in sdhci_s3c_probe()
659 pm_runtime_disable(&pdev->dev); in sdhci_s3c_probe()
662 clk_disable_unprepare(sc->clk_io); in sdhci_s3c_probe()
675 if (sc->ext_cd_irq) in sdhci_s3c_remove()
676 free_irq(sc->ext_cd_irq, sc); in sdhci_s3c_remove()
679 if (sc->pdata->cd_type != S3C_SDHCI_CD_INTERNAL) in sdhci_s3c_remove()
680 clk_prepare_enable(sc->clk_io); in sdhci_s3c_remove()
684 pm_runtime_dont_use_autosuspend(&pdev->dev); in sdhci_s3c_remove()
685 pm_runtime_disable(&pdev->dev); in sdhci_s3c_remove()
687 clk_disable_unprepare(sc->clk_io); in sdhci_s3c_remove()
697 if (host->tuning_mode != SDHCI_TUNING_MODE_3) in sdhci_s3c_suspend()
698 mmc_retune_needed(host->mmc); in sdhci_s3c_suspend()
716 struct clk *busclk = ourhost->clk_io; in sdhci_s3c_runtime_suspend()
721 if (host->tuning_mode != SDHCI_TUNING_MODE_3) in sdhci_s3c_runtime_suspend()
722 mmc_retune_needed(host->mmc); in sdhci_s3c_runtime_suspend()
724 if (ourhost->cur_clk >= 0) in sdhci_s3c_runtime_suspend()
725 clk_disable_unprepare(ourhost->clk_bus[ourhost->cur_clk]); in sdhci_s3c_runtime_suspend()
734 struct clk *busclk = ourhost->clk_io; in sdhci_s3c_runtime_resume()
738 if (ourhost->cur_clk >= 0) in sdhci_s3c_runtime_resume()
739 clk_prepare_enable(ourhost->clk_bus[ourhost->cur_clk]); in sdhci_s3c_runtime_resume()
753 .name = "s3c-sdhci",
767 { .compatible = "samsung,s3c6410-sdhci", },
768 { .compatible = "samsung,exynos4210-sdhci",
780 .name = "s3c-sdhci",
789 MODULE_DESCRIPTION("Samsung SDHCI (HSMMC) glue");