Lines Matching +full:uniphier +full:- +full:sd +full:- +full:v2
1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2017-2018 Socionext Inc.
10 #include <linux/dma-mapping.h>
52 * IP is extended to support various features: built-in DMA engine,
56 /* RX channel of the built-in DMA controller is broken (Pro5) */
75 return container_of(host->pdata, struct uniphier_sd_priv, tmio_data); in uniphier_sd_priv()
90 dma_async_issue_pending(priv->chan); in uniphier_sd_external_dma_issue()
100 dma_unmap_sg(mmc_dev(host->mmc), host->sg_ptr, host->sg_len, in uniphier_sd_external_dma_callback()
101 priv->dma_dir); in uniphier_sd_external_dma_callback()
103 spin_lock_irqsave(&host->lock, flags); in uniphier_sd_external_dma_callback()
105 if (result->result == DMA_TRANS_NOERROR) { in uniphier_sd_external_dma_callback()
115 host->data->error = -ETIMEDOUT; in uniphier_sd_external_dma_callback()
119 spin_unlock_irqrestore(&host->lock, flags); in uniphier_sd_external_dma_callback()
131 if (!priv->chan) in uniphier_sd_external_dma_start()
134 if (data->flags & MMC_DATA_READ) { in uniphier_sd_external_dma_start()
135 priv->dma_dir = DMA_FROM_DEVICE; in uniphier_sd_external_dma_start()
138 priv->dma_dir = DMA_TO_DEVICE; in uniphier_sd_external_dma_start()
142 sg_len = dma_map_sg(mmc_dev(host->mmc), host->sg_ptr, host->sg_len, in uniphier_sd_external_dma_start()
143 priv->dma_dir); in uniphier_sd_external_dma_start()
147 desc = dmaengine_prep_slave_sg(priv->chan, host->sg_ptr, sg_len, in uniphier_sd_external_dma_start()
152 desc->callback_result = uniphier_sd_external_dma_callback; in uniphier_sd_external_dma_start()
153 desc->callback_param = host; in uniphier_sd_external_dma_start()
159 host->dma_on = true; in uniphier_sd_external_dma_start()
164 dma_unmap_sg(mmc_dev(host->mmc), host->sg_ptr, host->sg_len, in uniphier_sd_external_dma_start()
165 priv->dma_dir); in uniphier_sd_external_dma_start()
181 chan = dma_request_chan(mmc_dev(host->mmc), "rx-tx"); in uniphier_sd_external_dma_request()
183 dev_warn(mmc_dev(host->mmc), in uniphier_sd_external_dma_request()
185 return; /* just use PIO even for -EPROBE_DEFER */ in uniphier_sd_external_dma_request()
189 priv->chan = chan; in uniphier_sd_external_dma_request()
190 host->chan_rx = chan; in uniphier_sd_external_dma_request()
191 host->chan_tx = chan; in uniphier_sd_external_dma_request()
193 tasklet_init(&host->dma_issue, uniphier_sd_external_dma_issue, in uniphier_sd_external_dma_request()
201 if (priv->chan) in uniphier_sd_external_dma_release()
202 dma_release_channel(priv->chan); in uniphier_sd_external_dma_release()
211 if (priv->chan) in uniphier_sd_external_dma_abort()
212 dmaengine_terminate_sync(priv->chan); in uniphier_sd_external_dma_abort()
236 spin_lock_irqsave(&host->lock, flags); in uniphier_sd_internal_dma_issue()
238 spin_unlock_irqrestore(&host->lock, flags); in uniphier_sd_internal_dma_issue()
241 writel(UNIPHIER_SD_DMA_CTL_START, host->ctl + UNIPHIER_SD_DMA_CTL); in uniphier_sd_internal_dma_issue()
248 struct scatterlist *sg = host->sg_ptr; in uniphier_sd_internal_dma_start()
254 if ((data->flags & MMC_DATA_READ) && !host->chan_rx) in uniphier_sd_internal_dma_start()
257 if (WARN_ON(host->sg_len != 1)) in uniphier_sd_internal_dma_start()
260 if (!IS_ALIGNED(sg->offset, 8)) in uniphier_sd_internal_dma_start()
263 if (data->flags & MMC_DATA_READ) { in uniphier_sd_internal_dma_start()
264 priv->dma_dir = DMA_FROM_DEVICE; in uniphier_sd_internal_dma_start()
267 priv->dma_dir = DMA_TO_DEVICE; in uniphier_sd_internal_dma_start()
271 sg_len = dma_map_sg(mmc_dev(host->mmc), sg, 1, priv->dma_dir); in uniphier_sd_internal_dma_start()
280 writel(dma_mode, host->ctl + UNIPHIER_SD_DMA_MODE); in uniphier_sd_internal_dma_start()
282 dma_addr = sg_dma_address(data->sg); in uniphier_sd_internal_dma_start()
283 writel(lower_32_bits(dma_addr), host->ctl + UNIPHIER_SD_DMA_ADDR_L); in uniphier_sd_internal_dma_start()
284 writel(upper_32_bits(dma_addr), host->ctl + UNIPHIER_SD_DMA_ADDR_H); in uniphier_sd_internal_dma_start()
286 host->dma_on = true; in uniphier_sd_internal_dma_start()
307 if (!(priv->caps & UNIPHIER_SD_CAP_BROKEN_DMA_RX)) in uniphier_sd_internal_dma_request()
308 host->chan_rx = (void *)0xdeadbeaf; in uniphier_sd_internal_dma_request()
310 host->chan_tx = (void *)0xdeadbeaf; in uniphier_sd_internal_dma_request()
312 tasklet_init(&host->dma_issue, uniphier_sd_internal_dma_issue, in uniphier_sd_internal_dma_request()
319 host->chan_rx = NULL; in uniphier_sd_internal_dma_release()
320 host->chan_tx = NULL; in uniphier_sd_internal_dma_release()
329 tmp = readl(host->ctl + UNIPHIER_SD_DMA_RST); in uniphier_sd_internal_dma_abort()
331 writel(tmp, host->ctl + UNIPHIER_SD_DMA_RST); in uniphier_sd_internal_dma_abort()
334 writel(tmp, host->ctl + UNIPHIER_SD_DMA_RST); in uniphier_sd_internal_dma_abort()
342 dma_unmap_sg(mmc_dev(host->mmc), host->sg_ptr, 1, priv->dma_dir); in uniphier_sd_internal_dma_dataend()
359 struct mmc_host *mmc = host->mmc; in uniphier_sd_clk_enable()
362 ret = clk_prepare_enable(priv->clk); in uniphier_sd_clk_enable()
366 ret = clk_set_rate(priv->clk, ULONG_MAX); in uniphier_sd_clk_enable()
370 priv->clk_rate = clk_get_rate(priv->clk); in uniphier_sd_clk_enable()
372 /* If max-frequency property is set, use it. */ in uniphier_sd_clk_enable()
373 if (!mmc->f_max) in uniphier_sd_clk_enable()
374 mmc->f_max = priv->clk_rate; in uniphier_sd_clk_enable()
378 * also supports 1/1024 divisor. (UniPhier-specific extension) in uniphier_sd_clk_enable()
380 if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP) in uniphier_sd_clk_enable()
381 mmc->f_min = priv->clk_rate / 1024; in uniphier_sd_clk_enable()
383 mmc->f_min = priv->clk_rate / 512; in uniphier_sd_clk_enable()
385 ret = reset_control_deassert(priv->rst); in uniphier_sd_clk_enable()
389 ret = reset_control_deassert(priv->rst_br); in uniphier_sd_clk_enable()
396 reset_control_assert(priv->rst); in uniphier_sd_clk_enable()
398 clk_disable_unprepare(priv->clk); in uniphier_sd_clk_enable()
407 reset_control_assert(priv->rst_br); in uniphier_sd_clk_disable()
408 reset_control_assert(priv->rst); in uniphier_sd_clk_disable()
409 clk_disable_unprepare(priv->clk); in uniphier_sd_clk_disable()
417 reset_control_assert(priv->rst_hw); in uniphier_sd_hw_reset()
420 reset_control_deassert(priv->rst_hw); in uniphier_sd_hw_reset()
432 tmp = readl(host->ctl + (CTL_SD_CARD_CLK_CTL << 1)); in uniphier_sd_set_clock()
436 writel(tmp, host->ctl + (CTL_SD_CARD_CLK_CTL << 1)); in uniphier_sd_set_clock()
445 divisor = priv->clk_rate / clock; in uniphier_sd_set_clock()
451 * The IP does not define a way to achieve 1/1. For UniPhier variants, in uniphier_sd_set_clock()
452 * bit10 is used for 1/1. Newer versions of UniPhier variants use in uniphier_sd_set_clock()
457 else if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP && divisor > 512) in uniphier_sd_set_clock()
462 writel(tmp, host->ctl + (CTL_SD_CARD_CLK_CTL << 1)); in uniphier_sd_set_clock()
465 writel(tmp, host->ctl + (CTL_SD_CARD_CLK_CTL << 1)); in uniphier_sd_set_clock()
475 * This register holds settings for SoC-specific internal bus in uniphier_sd_host_init()
480 if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP) in uniphier_sd_host_init()
485 writel(val, host->ctl + UNIPHIER_SD_HOST_MODE); in uniphier_sd_host_init()
492 if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP) in uniphier_sd_host_init()
495 writel(val, host->ctl + (CTL_SD_CARD_CLK_CTL << 1)); in uniphier_sd_host_init()
506 switch (ios->signal_voltage) { in uniphier_sd_start_signal_voltage_switch()
512 pinstate = priv->pinstate_uhs; in uniphier_sd_start_signal_voltage_switch()
515 return -ENOTSUPP; in uniphier_sd_start_signal_voltage_switch()
518 tmp = readl(host->ctl + UNIPHIER_SD_VOLT); in uniphier_sd_start_signal_voltage_switch()
521 writel(tmp, host->ctl + UNIPHIER_SD_VOLT); in uniphier_sd_start_signal_voltage_switch()
524 pinctrl_select_state(priv->pinctrl, pinstate); in uniphier_sd_start_signal_voltage_switch()
534 priv->pinctrl = devm_pinctrl_get(mmc_dev(host->mmc)); in uniphier_sd_uhs_init()
535 if (IS_ERR(priv->pinctrl)) in uniphier_sd_uhs_init()
536 return PTR_ERR(priv->pinctrl); in uniphier_sd_uhs_init()
538 priv->pinstate_uhs = pinctrl_lookup_state(priv->pinctrl, "uhs"); in uniphier_sd_uhs_init()
539 if (IS_ERR(priv->pinstate_uhs)) in uniphier_sd_uhs_init()
540 return PTR_ERR(priv->pinstate_uhs); in uniphier_sd_uhs_init()
542 host->ops.start_signal_voltage_switch = in uniphier_sd_uhs_init()
550 struct device *dev = &pdev->dev; in uniphier_sd_probe()
562 return -ENOMEM; in uniphier_sd_probe()
564 priv->caps = (unsigned long)of_device_get_match_data(dev); in uniphier_sd_probe()
566 priv->clk = devm_clk_get(dev, NULL); in uniphier_sd_probe()
567 if (IS_ERR(priv->clk)) { in uniphier_sd_probe()
569 return PTR_ERR(priv->clk); in uniphier_sd_probe()
572 priv->rst = devm_reset_control_get_shared(dev, "host"); in uniphier_sd_probe()
573 if (IS_ERR(priv->rst)) { in uniphier_sd_probe()
575 return PTR_ERR(priv->rst); in uniphier_sd_probe()
579 if (!(priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP)) { in uniphier_sd_probe()
580 priv->rst_br = devm_reset_control_get_shared(dev, "bridge"); in uniphier_sd_probe()
581 if (IS_ERR(priv->rst_br)) { in uniphier_sd_probe()
583 return PTR_ERR(priv->rst_br); in uniphier_sd_probe()
587 tmio_data = &priv->tmio_data; in uniphier_sd_probe()
588 tmio_data->flags |= TMIO_MMC_32BIT_DATA_PORT; in uniphier_sd_probe()
594 if (host->mmc->caps & MMC_CAP_HW_RESET) { in uniphier_sd_probe()
595 priv->rst_hw = devm_reset_control_get_exclusive(dev, "hw"); in uniphier_sd_probe()
596 if (IS_ERR(priv->rst_hw)) { in uniphier_sd_probe()
598 ret = PTR_ERR(priv->rst_hw); in uniphier_sd_probe()
601 host->ops.hw_reset = uniphier_sd_hw_reset; in uniphier_sd_probe()
604 if (host->mmc->caps & MMC_CAP_UHS) { in uniphier_sd_probe()
610 host->mmc->caps &= ~MMC_CAP_UHS; in uniphier_sd_probe()
614 if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP) in uniphier_sd_probe()
615 host->dma_ops = &uniphier_sd_internal_dma_ops; in uniphier_sd_probe()
617 host->dma_ops = &uniphier_sd_external_dma_ops; in uniphier_sd_probe()
619 host->bus_shift = 1; in uniphier_sd_probe()
620 host->clk_enable = uniphier_sd_clk_enable; in uniphier_sd_probe()
621 host->clk_disable = uniphier_sd_clk_disable; in uniphier_sd_probe()
622 host->set_clock = uniphier_sd_set_clock; in uniphier_sd_probe()
630 tmio_data->ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34; in uniphier_sd_probe()
631 if (host->mmc->caps & MMC_CAP_UHS) in uniphier_sd_probe()
632 tmio_data->ocr_mask |= MMC_VDD_165_195; in uniphier_sd_probe()
634 tmio_data->max_segs = 1; in uniphier_sd_probe()
635 tmio_data->max_blk_count = U16_MAX; in uniphier_sd_probe()
668 .compatible = "socionext,uniphier-sd-v2.91",
671 .compatible = "socionext,uniphier-sd-v3.1",
676 .compatible = "socionext,uniphier-sd-v3.1.1",
687 .name = "uniphier-sd",
695 MODULE_DESCRIPTION("UniPhier SD/eMMC host controller driver");
696 MODULE_LICENSE("GPL v2");