Lines Matching +full:dw +full:- +full:mshc +full:- +full:sdr +full:- +full:timing

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver
18 #include "dw_mmc-pltfm.h"
19 #include "dw_mmc-exynos.h"
21 /* Variations in Exynos specific dw-mshc controller */
52 .compatible = "samsung,exynos4210-dw-mshc",
55 .compatible = "samsung,exynos4412-dw-mshc",
58 .compatible = "samsung,exynos5250-dw-mshc",
61 .compatible = "samsung,exynos5420-dw-mshc",
64 .compatible = "samsung,exynos5420-dw-mshc-smu",
67 .compatible = "samsung,exynos7-dw-mshc",
70 .compatible = "samsung,exynos7-dw-mshc-smu",
73 .compatible = "axis,artpec8-dw-mshc",
80 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_get_ciu_div()
82 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) in dw_mci_exynos_get_ciu_div()
84 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) in dw_mci_exynos_get_ciu_div()
86 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_get_ciu_div()
87 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_get_ciu_div()
88 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_get_ciu_div()
96 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_config_smu()
100 * set for non-ecryption mode at this time. in dw_mci_exynos_config_smu()
102 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU || in dw_mci_exynos_config_smu()
103 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) { in dw_mci_exynos_config_smu()
115 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_priv_init()
119 if (priv->ctrl_type >= DW_MCI_TYPE_EXYNOS5420) { in dw_mci_exynos_priv_init()
120 priv->saved_strobe_ctrl = mci_readl(host, HS400_DLINE_CTRL); in dw_mci_exynos_priv_init()
121 priv->saved_dqs_en = mci_readl(host, HS400_DQS_EN); in dw_mci_exynos_priv_init()
122 priv->saved_dqs_en |= AXI_NON_BLOCKING_WR; in dw_mci_exynos_priv_init()
123 mci_writel(host, HS400_DQS_EN, priv->saved_dqs_en); in dw_mci_exynos_priv_init()
124 if (!priv->dqs_delay) in dw_mci_exynos_priv_init()
125 priv->dqs_delay = in dw_mci_exynos_priv_init()
126 DQS_CTRL_GET_RD_DELAY(priv->saved_strobe_ctrl); in dw_mci_exynos_priv_init()
129 if (priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) { in dw_mci_exynos_priv_init()
130 /* Quirk needed for the ARTPEC-8 SoC */ in dw_mci_exynos_priv_init()
131 host->quirks |= DW_MMC_QUIRK_EXTENDED_TMOUT; in dw_mci_exynos_priv_init()
134 host->bus_hz /= (priv->ciu_div + 1); in dw_mci_exynos_priv_init()
139 static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing) in dw_mci_exynos_set_clksel_timing() argument
141 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_set_clksel_timing()
144 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_set_clksel_timing()
145 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_set_clksel_timing()
146 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_set_clksel_timing()
151 clksel = (clksel & ~SDMMC_CLKSEL_TIMING_MASK) | timing; in dw_mci_exynos_set_clksel_timing()
153 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_set_clksel_timing()
154 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_set_clksel_timing()
155 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_set_clksel_timing()
162 * use of bit 29 (which is reserved on standard MSHC controllers) for in dw_mci_exynos_set_clksel_timing()
167 if (!SDMMC_CLKSEL_GET_DRV_WD3(clksel) && host->slot) in dw_mci_exynos_set_clksel_timing()
168 set_bit(DW_MMC_CARD_NO_USE_HOLD, &host->slot->flags); in dw_mci_exynos_set_clksel_timing()
189 * dw_mci_exynos_suspend_noirq - Exynos-specific suspend code
202 * dw_mci_exynos_resume_noirq - Exynos-specific resume code
215 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_resume_noirq()
223 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_resume_noirq()
224 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_resume_noirq()
225 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_resume_noirq()
231 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_resume_noirq()
232 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_resume_noirq()
233 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_resume_noirq()
245 static void dw_mci_exynos_config_hs400(struct dw_mci *host, u32 timing) in dw_mci_exynos_config_hs400() argument
247 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_config_hs400()
254 if ((priv->ctrl_type < DW_MCI_TYPE_EXYNOS5420) || in dw_mci_exynos_config_hs400()
255 (priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)) { in dw_mci_exynos_config_hs400()
256 if (timing == MMC_TIMING_MMC_HS400) in dw_mci_exynos_config_hs400()
257 dev_warn(host->dev, in dw_mci_exynos_config_hs400()
262 dqs = priv->saved_dqs_en; in dw_mci_exynos_config_hs400()
263 strobe = priv->saved_strobe_ctrl; in dw_mci_exynos_config_hs400()
265 if (timing == MMC_TIMING_MMC_HS400) { in dw_mci_exynos_config_hs400()
267 strobe = DQS_CTRL_RD_DELAY(strobe, priv->dqs_delay); in dw_mci_exynos_config_hs400()
268 } else if (timing == MMC_TIMING_UHS_SDR104) { in dw_mci_exynos_config_hs400()
280 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_adjust_clock()
288 if (!wanted || IS_ERR(host->ciu_clk)) in dw_mci_exynos_adjust_clock()
295 if (wanted == priv->cur_speed) in dw_mci_exynos_adjust_clock()
299 ret = clk_set_rate(host->ciu_clk, wanted * div); in dw_mci_exynos_adjust_clock()
301 dev_warn(host->dev, in dw_mci_exynos_adjust_clock()
302 "failed to set clk-rate %u error: %d\n", in dw_mci_exynos_adjust_clock()
304 actual = clk_get_rate(host->ciu_clk); in dw_mci_exynos_adjust_clock()
305 host->bus_hz = actual / div; in dw_mci_exynos_adjust_clock()
306 priv->cur_speed = wanted; in dw_mci_exynos_adjust_clock()
307 host->current_speed = 0; in dw_mci_exynos_adjust_clock()
312 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_set_ios()
313 unsigned int wanted = ios->clock; in dw_mci_exynos_set_ios()
314 u32 timing = ios->timing, clksel; in dw_mci_exynos_set_ios() local
316 switch (timing) { in dw_mci_exynos_set_ios()
318 /* Update tuned sample timing */ in dw_mci_exynos_set_ios()
320 priv->hs400_timing, priv->tuned_sample); in dw_mci_exynos_set_ios()
324 clksel = priv->ddr_timing; in dw_mci_exynos_set_ios()
326 if (ios->bus_width == MMC_BUS_WIDTH_8) in dw_mci_exynos_set_ios()
331 clksel = (priv->sdr_timing & 0xfff8ffff) | in dw_mci_exynos_set_ios()
332 (priv->ciu_div << 16); in dw_mci_exynos_set_ios()
335 clksel = (priv->ddr_timing & 0xfff8ffff) | in dw_mci_exynos_set_ios()
336 (priv->ciu_div << 16); in dw_mci_exynos_set_ios()
339 clksel = priv->sdr_timing; in dw_mci_exynos_set_ios()
342 /* Set clock timing for the requested speed mode*/ in dw_mci_exynos_set_ios()
346 dw_mci_exynos_config_hs400(host, timing); in dw_mci_exynos_set_ios()
355 struct device_node *np = host->dev->of_node; in dw_mci_exynos_parse_dt()
356 u32 timing[2]; in dw_mci_exynos_parse_dt() local
361 priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); in dw_mci_exynos_parse_dt()
363 return -ENOMEM; in dw_mci_exynos_parse_dt()
367 priv->ctrl_type = exynos_compat[idx].ctrl_type; in dw_mci_exynos_parse_dt()
370 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) in dw_mci_exynos_parse_dt()
371 priv->ciu_div = EXYNOS4412_FIXED_CIU_CLK_DIV - 1; in dw_mci_exynos_parse_dt()
372 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) in dw_mci_exynos_parse_dt()
373 priv->ciu_div = EXYNOS4210_FIXED_CIU_CLK_DIV - 1; in dw_mci_exynos_parse_dt()
375 of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div); in dw_mci_exynos_parse_dt()
376 priv->ciu_div = div; in dw_mci_exynos_parse_dt()
380 "samsung,dw-mshc-sdr-timing", timing, 2); in dw_mci_exynos_parse_dt()
384 priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); in dw_mci_exynos_parse_dt()
387 "samsung,dw-mshc-ddr-timing", timing, 2); in dw_mci_exynos_parse_dt()
391 priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); in dw_mci_exynos_parse_dt()
394 "samsung,dw-mshc-hs400-timing", timing, 2); in dw_mci_exynos_parse_dt()
396 "samsung,read-strobe-delay", &priv->dqs_delay)) in dw_mci_exynos_parse_dt()
397 dev_dbg(host->dev, in dw_mci_exynos_parse_dt()
398 "read-strobe-delay is not found, assuming usage of default value\n"); in dw_mci_exynos_parse_dt()
400 priv->hs400_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], in dw_mci_exynos_parse_dt()
402 host->priv = priv; in dw_mci_exynos_parse_dt()
408 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_get_clksmpl()
410 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_get_clksmpl()
411 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_get_clksmpl()
412 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_get_clksmpl()
421 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_set_clksmpl()
423 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_set_clksmpl()
424 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_set_clksmpl()
425 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_set_clksmpl()
430 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_set_clksmpl()
431 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_set_clksmpl()
432 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_set_clksmpl()
440 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_move_next_clksmpl()
444 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_move_next_clksmpl()
445 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_move_next_clksmpl()
446 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_move_next_clksmpl()
454 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || in dw_mci_exynos_move_next_clksmpl()
455 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || in dw_mci_exynos_move_next_clksmpl()
456 priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) in dw_mci_exynos_move_next_clksmpl()
468 s8 i, loc = -1; in dw_mci_exynos_get_best_clksmpl()
487 * If there is no cadiates value, then it needs to return -EIO. in dw_mci_exynos_get_best_clksmpl()
504 struct dw_mci *host = slot->host; in dw_mci_exynos_execute_tuning()
505 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_execute_tuning()
506 struct mmc_host *mmc = slot->mmc; in dw_mci_exynos_execute_tuning()
525 priv->tuned_sample = found; in dw_mci_exynos_execute_tuning()
527 ret = -EIO; in dw_mci_exynos_execute_tuning()
528 dev_warn(&mmc->class_dev, in dw_mci_exynos_execute_tuning()
538 struct dw_mci_exynos_priv_data *priv = host->priv; in dw_mci_exynos_prepare_hs400_tuning()
540 dw_mci_exynos_set_clksel_timing(host, priv->hs400_timing); in dw_mci_exynos_prepare_hs400_tuning()
541 dw_mci_exynos_adjust_clock(host, (ios->clock) << 1); in dw_mci_exynos_prepare_hs400_tuning()
557 tmp = DIV_ROUND_UP_ULL((u64)timeout_ns * host->bus_hz, NSEC_PER_SEC); in dw_mci_exynos_set_data_timeout()
565 * ((TMOUT[10:8] - 1) * 0xFFFFFF + TMOUT[31:11] * 8) in dw_mci_exynos_set_data_timeout()
575 tmp = tmp - ((tmp2 - 1) * 0xFFFFFF); in dw_mci_exynos_set_data_timeout()
580 dev_dbg(host->dev, "timeout_ns: %u => TMOUT[31:8]: %#08x", in dw_mci_exynos_set_data_timeout()
590 return (((drto_clks & 0x7) - 1) * 0xFFFFFF) + ((drto_clks & 0xFFFFF8)); in dw_mci_exynos_get_drto_clks()
623 { .compatible = "samsung,exynos4412-dw-mshc",
625 { .compatible = "samsung,exynos5250-dw-mshc",
627 { .compatible = "samsung,exynos5420-dw-mshc",
629 { .compatible = "samsung,exynos5420-dw-mshc-smu",
631 { .compatible = "samsung,exynos7-dw-mshc",
633 { .compatible = "samsung,exynos7-dw-mshc-smu",
635 { .compatible = "axis,artpec8-dw-mshc",
647 match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node); in dw_mci_exynos_probe()
648 drv_data = match->data; in dw_mci_exynos_probe()
650 pm_runtime_get_noresume(&pdev->dev); in dw_mci_exynos_probe()
651 pm_runtime_set_active(&pdev->dev); in dw_mci_exynos_probe()
652 pm_runtime_enable(&pdev->dev); in dw_mci_exynos_probe()
656 pm_runtime_disable(&pdev->dev); in dw_mci_exynos_probe()
657 pm_runtime_set_suspended(&pdev->dev); in dw_mci_exynos_probe()
658 pm_runtime_put_noidle(&pdev->dev); in dw_mci_exynos_probe()
668 pm_runtime_disable(&pdev->dev); in dw_mci_exynos_remove()
669 pm_runtime_set_suspended(&pdev->dev); in dw_mci_exynos_remove()
670 pm_runtime_put_noidle(&pdev->dev); in dw_mci_exynos_remove()
696 MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension");