1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2017-2018 Socionext Inc.
6 #include <linux/bitfield.h>
7 #include <linux/bitops.h>
9 #include <linux/delay.h>
10 #include <linux/dma-mapping.h>
11 #include <linux/mfd/syscon.h>
12 #include <linux/mfd/tmio.h>
13 #include <linux/mmc/host.h>
14 #include <linux/module.h>
16 #include <linux/of_device.h>
17 #include <linux/pinctrl/consumer.h>
18 #include <linux/platform_device.h>
19 #include <linux/regmap.h>
20 #include <linux/reset.h>
24 #define UNIPHIER_SD_CLK_CTL_DIV1024 BIT(16)
25 #define UNIPHIER_SD_CLK_CTL_DIV1 BIT(10)
26 #define UNIPHIER_SD_CLKCTL_OFFEN BIT(9) // auto SDCLK stop
27 #define UNIPHIER_SD_CC_EXT_MODE 0x1b0
28 #define UNIPHIER_SD_CC_EXT_MODE_DMA BIT(1)
29 #define UNIPHIER_SD_HOST_MODE 0x1c8
30 #define UNIPHIER_SD_VOLT 0x1e4
31 #define UNIPHIER_SD_VOLT_MASK GENMASK(1, 0)
32 #define UNIPHIER_SD_VOLT_OFF 0
33 #define UNIPHIER_SD_VOLT_330 1 // 3.3V signal
34 #define UNIPHIER_SD_VOLT_180 2 // 1.8V signal
35 #define UNIPHIER_SD_DMA_MODE 0x410
36 #define UNIPHIER_SD_DMA_MODE_DIR_MASK GENMASK(17, 16)
37 #define UNIPHIER_SD_DMA_MODE_DIR_TO_DEV 0
38 #define UNIPHIER_SD_DMA_MODE_DIR_FROM_DEV 1
39 #define UNIPHIER_SD_DMA_MODE_WIDTH_MASK GENMASK(5, 4)
40 #define UNIPHIER_SD_DMA_MODE_WIDTH_8 0
41 #define UNIPHIER_SD_DMA_MODE_WIDTH_16 1
42 #define UNIPHIER_SD_DMA_MODE_WIDTH_32 2
43 #define UNIPHIER_SD_DMA_MODE_WIDTH_64 3
44 #define UNIPHIER_SD_DMA_MODE_ADDR_INC BIT(0) // 1: inc, 0: fixed
45 #define UNIPHIER_SD_DMA_CTL 0x414
46 #define UNIPHIER_SD_DMA_CTL_START BIT(0) // start DMA (auto cleared)
47 #define UNIPHIER_SD_DMA_RST 0x418
48 #define UNIPHIER_SD_DMA_RST_CH1 BIT(9)
49 #define UNIPHIER_SD_DMA_RST_CH0 BIT(8)
50 #define UNIPHIER_SD_DMA_ADDR_L 0x440
51 #define UNIPHIER_SD_DMA_ADDR_H 0x444
54 #define UNIPHIER_SDCTRL_CHOFFSET 0x200
55 #define UNIPHIER_SDCTRL_MODE 0x30
56 #define UNIPHIER_SDCTRL_MODE_UHS1MOD BIT(15)
57 #define UNIPHIER_SDCTRL_MODE_SDRSEL BIT(14)
60 * IP is extended to support various features: built-in DMA engine,
61 * 1/1024 divisor, etc.
63 #define UNIPHIER_SD_CAP_EXTENDED_IP BIT(0)
64 /* RX channel of the built-in DMA controller is broken (Pro5) */
65 #define UNIPHIER_SD_CAP_BROKEN_DMA_RX BIT(1)
67 struct uniphier_sd_priv {
68 struct tmio_mmc_data tmio_data;
69 struct pinctrl *pinctrl;
70 struct pinctrl_state *pinstate_uhs;
72 struct reset_control *rst;
73 struct reset_control *rst_br;
74 struct reset_control *rst_hw;
75 struct dma_chan *chan;
76 enum dma_data_direction dma_dir;
77 struct regmap *sdctrl_regmap;
79 unsigned long clk_rate;
83 static void *uniphier_sd_priv(struct tmio_mmc_host *host)
85 return container_of(host->pdata, struct uniphier_sd_priv, tmio_data);
88 static void uniphier_sd_dma_endisable(struct tmio_mmc_host *host, int enable)
90 sd_ctrl_write16(host, CTL_DMA_ENABLE, enable ? DMA_ENABLE_DMASDRW : 0);
93 /* external DMA engine */
94 static void uniphier_sd_external_dma_issue(struct tasklet_struct *t)
96 struct tmio_mmc_host *host = from_tasklet(host, t, dma_issue);
97 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
99 uniphier_sd_dma_endisable(host, 1);
100 dma_async_issue_pending(priv->chan);
103 static void uniphier_sd_external_dma_callback(void *param,
104 const struct dmaengine_result *result)
106 struct tmio_mmc_host *host = param;
107 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
110 dma_unmap_sg(mmc_dev(host->mmc), host->sg_ptr, host->sg_len,
113 spin_lock_irqsave(&host->lock, flags);
115 if (result->result == DMA_TRANS_NOERROR) {
117 * When the external DMA engine is enabled, strangely enough,
118 * the DATAEND flag can be asserted even if the DMA engine has
119 * not been kicked yet. Enable the TMIO_STAT_DATAEND irq only
120 * after we make sure the DMA engine finishes the transfer,
121 * hence, in this callback.
123 tmio_mmc_enable_mmc_irqs(host, TMIO_STAT_DATAEND);
125 host->data->error = -ETIMEDOUT;
126 tmio_mmc_do_data_irq(host);
129 spin_unlock_irqrestore(&host->lock, flags);
132 static void uniphier_sd_external_dma_start(struct tmio_mmc_host *host,
133 struct mmc_data *data)
135 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
136 enum dma_transfer_direction dma_tx_dir;
137 struct dma_async_tx_descriptor *desc;
144 if (data->flags & MMC_DATA_READ) {
145 priv->dma_dir = DMA_FROM_DEVICE;
146 dma_tx_dir = DMA_DEV_TO_MEM;
148 priv->dma_dir = DMA_TO_DEVICE;
149 dma_tx_dir = DMA_MEM_TO_DEV;
152 sg_len = dma_map_sg(mmc_dev(host->mmc), host->sg_ptr, host->sg_len,
157 desc = dmaengine_prep_slave_sg(priv->chan, host->sg_ptr, sg_len,
158 dma_tx_dir, DMA_CTRL_ACK);
162 desc->callback_result = uniphier_sd_external_dma_callback;
163 desc->callback_param = host;
165 cookie = dmaengine_submit(desc);
174 dma_unmap_sg(mmc_dev(host->mmc), host->sg_ptr, host->sg_len,
177 uniphier_sd_dma_endisable(host, 0);
180 static void uniphier_sd_external_dma_enable(struct tmio_mmc_host *host,
185 static void uniphier_sd_external_dma_request(struct tmio_mmc_host *host,
186 struct tmio_mmc_data *pdata)
188 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
189 struct dma_chan *chan;
191 chan = dma_request_chan(mmc_dev(host->mmc), "rx-tx");
193 dev_warn(mmc_dev(host->mmc),
194 "failed to request DMA channel. falling back to PIO\n");
195 return; /* just use PIO even for -EPROBE_DEFER */
198 /* this driver uses a single channel for both RX an TX */
200 host->chan_rx = chan;
201 host->chan_tx = chan;
203 tasklet_setup(&host->dma_issue, uniphier_sd_external_dma_issue);
206 static void uniphier_sd_external_dma_release(struct tmio_mmc_host *host)
208 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
211 dma_release_channel(priv->chan);
214 static void uniphier_sd_external_dma_abort(struct tmio_mmc_host *host)
216 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
218 uniphier_sd_dma_endisable(host, 0);
221 dmaengine_terminate_sync(priv->chan);
224 static void uniphier_sd_external_dma_dataend(struct tmio_mmc_host *host)
226 uniphier_sd_dma_endisable(host, 0);
228 tmio_mmc_do_data_irq(host);
231 static const struct tmio_mmc_dma_ops uniphier_sd_external_dma_ops = {
232 .start = uniphier_sd_external_dma_start,
233 .enable = uniphier_sd_external_dma_enable,
234 .request = uniphier_sd_external_dma_request,
235 .release = uniphier_sd_external_dma_release,
236 .abort = uniphier_sd_external_dma_abort,
237 .dataend = uniphier_sd_external_dma_dataend,
240 static void uniphier_sd_internal_dma_issue(struct tasklet_struct *t)
242 struct tmio_mmc_host *host = from_tasklet(host, t, dma_issue);
245 spin_lock_irqsave(&host->lock, flags);
246 tmio_mmc_enable_mmc_irqs(host, TMIO_STAT_DATAEND);
247 spin_unlock_irqrestore(&host->lock, flags);
249 uniphier_sd_dma_endisable(host, 1);
250 writel(UNIPHIER_SD_DMA_CTL_START, host->ctl + UNIPHIER_SD_DMA_CTL);
253 static void uniphier_sd_internal_dma_start(struct tmio_mmc_host *host,
254 struct mmc_data *data)
256 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
257 struct scatterlist *sg = host->sg_ptr;
259 unsigned int dma_mode_dir;
263 if ((data->flags & MMC_DATA_READ) && !host->chan_rx)
266 if (WARN_ON(host->sg_len != 1))
269 if (!IS_ALIGNED(sg->offset, 8))
272 if (data->flags & MMC_DATA_READ) {
273 priv->dma_dir = DMA_FROM_DEVICE;
274 dma_mode_dir = UNIPHIER_SD_DMA_MODE_DIR_FROM_DEV;
276 priv->dma_dir = DMA_TO_DEVICE;
277 dma_mode_dir = UNIPHIER_SD_DMA_MODE_DIR_TO_DEV;
280 sg_len = dma_map_sg(mmc_dev(host->mmc), sg, 1, priv->dma_dir);
284 dma_mode = FIELD_PREP(UNIPHIER_SD_DMA_MODE_DIR_MASK, dma_mode_dir);
285 dma_mode |= FIELD_PREP(UNIPHIER_SD_DMA_MODE_WIDTH_MASK,
286 UNIPHIER_SD_DMA_MODE_WIDTH_64);
287 dma_mode |= UNIPHIER_SD_DMA_MODE_ADDR_INC;
289 writel(dma_mode, host->ctl + UNIPHIER_SD_DMA_MODE);
291 dma_addr = sg_dma_address(data->sg);
292 writel(lower_32_bits(dma_addr), host->ctl + UNIPHIER_SD_DMA_ADDR_L);
293 writel(upper_32_bits(dma_addr), host->ctl + UNIPHIER_SD_DMA_ADDR_H);
299 uniphier_sd_dma_endisable(host, 0);
302 static void uniphier_sd_internal_dma_enable(struct tmio_mmc_host *host,
307 static void uniphier_sd_internal_dma_request(struct tmio_mmc_host *host,
308 struct tmio_mmc_data *pdata)
310 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
313 * Due to a hardware bug, Pro5 cannot use DMA for RX.
314 * We can still use DMA for TX, but PIO for RX.
316 if (!(priv->caps & UNIPHIER_SD_CAP_BROKEN_DMA_RX))
317 host->chan_rx = (void *)0xdeadbeaf;
319 host->chan_tx = (void *)0xdeadbeaf;
321 tasklet_setup(&host->dma_issue, uniphier_sd_internal_dma_issue);
324 static void uniphier_sd_internal_dma_release(struct tmio_mmc_host *host)
326 /* Each value is set to zero to assume "disabling" each DMA */
327 host->chan_rx = NULL;
328 host->chan_tx = NULL;
331 static void uniphier_sd_internal_dma_abort(struct tmio_mmc_host *host)
335 uniphier_sd_dma_endisable(host, 0);
337 tmp = readl(host->ctl + UNIPHIER_SD_DMA_RST);
338 tmp &= ~(UNIPHIER_SD_DMA_RST_CH1 | UNIPHIER_SD_DMA_RST_CH0);
339 writel(tmp, host->ctl + UNIPHIER_SD_DMA_RST);
341 tmp |= UNIPHIER_SD_DMA_RST_CH1 | UNIPHIER_SD_DMA_RST_CH0;
342 writel(tmp, host->ctl + UNIPHIER_SD_DMA_RST);
345 static void uniphier_sd_internal_dma_dataend(struct tmio_mmc_host *host)
347 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
349 uniphier_sd_dma_endisable(host, 0);
350 dma_unmap_sg(mmc_dev(host->mmc), host->sg_ptr, 1, priv->dma_dir);
352 tmio_mmc_do_data_irq(host);
355 static const struct tmio_mmc_dma_ops uniphier_sd_internal_dma_ops = {
356 .start = uniphier_sd_internal_dma_start,
357 .enable = uniphier_sd_internal_dma_enable,
358 .request = uniphier_sd_internal_dma_request,
359 .release = uniphier_sd_internal_dma_release,
360 .abort = uniphier_sd_internal_dma_abort,
361 .dataend = uniphier_sd_internal_dma_dataend,
364 static int uniphier_sd_clk_enable(struct tmio_mmc_host *host)
366 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
367 struct mmc_host *mmc = host->mmc;
370 ret = clk_prepare_enable(priv->clk);
374 ret = clk_set_rate(priv->clk, ULONG_MAX);
378 priv->clk_rate = clk_get_rate(priv->clk);
380 /* If max-frequency property is set, use it. */
382 mmc->f_max = priv->clk_rate;
385 * 1/512 is the finest divisor in the original IP. Newer versions
386 * also supports 1/1024 divisor. (UniPhier-specific extension)
388 if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP)
389 mmc->f_min = priv->clk_rate / 1024;
391 mmc->f_min = priv->clk_rate / 512;
393 ret = reset_control_deassert(priv->rst);
397 ret = reset_control_deassert(priv->rst_br);
404 reset_control_assert(priv->rst);
406 clk_disable_unprepare(priv->clk);
411 static void uniphier_sd_clk_disable(struct tmio_mmc_host *host)
413 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
415 reset_control_assert(priv->rst_br);
416 reset_control_assert(priv->rst);
417 clk_disable_unprepare(priv->clk);
420 static void uniphier_sd_hw_reset(struct mmc_host *mmc)
422 struct tmio_mmc_host *host = mmc_priv(mmc);
423 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
425 reset_control_assert(priv->rst_hw);
426 /* For eMMC, minimum is 1us but give it 9us for good measure */
428 reset_control_deassert(priv->rst_hw);
429 /* For eMMC, minimum is 200us but give it 300us for good measure */
430 usleep_range(300, 1000);
433 static void uniphier_sd_speed_switch(struct tmio_mmc_host *host)
435 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
439 if (!(host->mmc->caps & MMC_CAP_UHS))
442 if (host->mmc->ios.timing == MMC_TIMING_UHS_SDR50 ||
443 host->mmc->ios.timing == MMC_TIMING_UHS_SDR104)
444 val = UNIPHIER_SDCTRL_MODE_SDRSEL;
446 offset = UNIPHIER_SDCTRL_CHOFFSET * priv->sdctrl_ch
447 + UNIPHIER_SDCTRL_MODE;
448 regmap_write_bits(priv->sdctrl_regmap, offset,
449 UNIPHIER_SDCTRL_MODE_SDRSEL, val);
452 static void uniphier_sd_uhs_enable(struct tmio_mmc_host *host, bool uhs_en)
454 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
458 if (!(host->mmc->caps & MMC_CAP_UHS))
461 val = (uhs_en) ? UNIPHIER_SDCTRL_MODE_UHS1MOD : 0;
463 offset = UNIPHIER_SDCTRL_CHOFFSET * priv->sdctrl_ch
464 + UNIPHIER_SDCTRL_MODE;
465 regmap_write_bits(priv->sdctrl_regmap, offset,
466 UNIPHIER_SDCTRL_MODE_UHS1MOD, val);
469 static void uniphier_sd_set_clock(struct tmio_mmc_host *host,
472 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
473 unsigned long divisor;
476 tmp = readl(host->ctl + (CTL_SD_CARD_CLK_CTL << 1));
478 /* stop the clock before changing its rate to avoid a glitch signal */
479 tmp &= ~CLK_CTL_SCLKEN;
480 writel(tmp, host->ctl + (CTL_SD_CARD_CLK_CTL << 1));
482 uniphier_sd_speed_switch(host);
487 tmp &= ~UNIPHIER_SD_CLK_CTL_DIV1024;
488 tmp &= ~UNIPHIER_SD_CLK_CTL_DIV1;
489 tmp &= ~CLK_CTL_DIV_MASK;
491 divisor = priv->clk_rate / clock;
494 * In the original IP, bit[7:0] represents the divisor.
495 * bit7 set: 1/512, ... bit0 set:1/4, all bits clear: 1/2
497 * The IP does not define a way to achieve 1/1. For UniPhier variants,
498 * bit10 is used for 1/1. Newer versions of UniPhier variants use
502 tmp |= UNIPHIER_SD_CLK_CTL_DIV1;
503 else if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP && divisor > 512)
504 tmp |= UNIPHIER_SD_CLK_CTL_DIV1024;
506 tmp |= roundup_pow_of_two(divisor) >> 2;
508 writel(tmp, host->ctl + (CTL_SD_CARD_CLK_CTL << 1));
510 tmp |= CLK_CTL_SCLKEN;
511 writel(tmp, host->ctl + (CTL_SD_CARD_CLK_CTL << 1));
514 static void uniphier_sd_host_init(struct tmio_mmc_host *host)
516 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
520 * Connected to 32bit AXI.
521 * This register holds settings for SoC-specific internal bus
522 * connection. What is worse, the register spec was changed,
523 * breaking the backward compatibility. Write an appropriate
524 * value depending on a flag associated with a compatible string.
526 if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP)
531 writel(val, host->ctl + UNIPHIER_SD_HOST_MODE);
535 * If supported, the controller can automatically
536 * enable/disable the clock line to the card.
538 if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP)
539 val |= UNIPHIER_SD_CLKCTL_OFFEN;
541 writel(val, host->ctl + (CTL_SD_CARD_CLK_CTL << 1));
544 static int uniphier_sd_start_signal_voltage_switch(struct mmc_host *mmc,
547 struct tmio_mmc_host *host = mmc_priv(mmc);
548 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
549 struct pinctrl_state *pinstate = NULL;
553 switch (ios->signal_voltage) {
554 case MMC_SIGNAL_VOLTAGE_330:
555 val = UNIPHIER_SD_VOLT_330;
558 case MMC_SIGNAL_VOLTAGE_180:
559 val = UNIPHIER_SD_VOLT_180;
560 pinstate = priv->pinstate_uhs;
567 tmp = readl(host->ctl + UNIPHIER_SD_VOLT);
568 tmp &= ~UNIPHIER_SD_VOLT_MASK;
569 tmp |= FIELD_PREP(UNIPHIER_SD_VOLT_MASK, val);
570 writel(tmp, host->ctl + UNIPHIER_SD_VOLT);
573 pinctrl_select_state(priv->pinctrl, pinstate);
575 pinctrl_select_default_state(mmc_dev(mmc));
577 uniphier_sd_uhs_enable(host, uhs_en);
582 static int uniphier_sd_uhs_init(struct tmio_mmc_host *host)
584 struct uniphier_sd_priv *priv = uniphier_sd_priv(host);
585 struct device *dev = &host->pdev->dev;
586 struct device_node *np = dev->of_node;
587 struct of_phandle_args args;
590 priv->pinctrl = devm_pinctrl_get(mmc_dev(host->mmc));
591 if (IS_ERR(priv->pinctrl))
592 return PTR_ERR(priv->pinctrl);
594 priv->pinstate_uhs = pinctrl_lookup_state(priv->pinctrl, "uhs");
595 if (IS_ERR(priv->pinstate_uhs))
596 return PTR_ERR(priv->pinstate_uhs);
598 ret = of_parse_phandle_with_fixed_args(np,
599 "socionext,syscon-uhs-mode",
602 dev_err(dev, "Can't get syscon-uhs-mode property\n");
605 priv->sdctrl_regmap = syscon_node_to_regmap(args.np);
606 of_node_put(args.np);
607 if (IS_ERR(priv->sdctrl_regmap)) {
608 dev_err(dev, "Can't map syscon-uhs-mode\n");
609 return PTR_ERR(priv->sdctrl_regmap);
611 priv->sdctrl_ch = args.args[0];
616 static int uniphier_sd_probe(struct platform_device *pdev)
618 struct device *dev = &pdev->dev;
619 struct uniphier_sd_priv *priv;
620 struct tmio_mmc_data *tmio_data;
621 struct tmio_mmc_host *host;
624 irq = platform_get_irq(pdev, 0);
628 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
632 priv->caps = (unsigned long)of_device_get_match_data(dev);
634 priv->clk = devm_clk_get(dev, NULL);
635 if (IS_ERR(priv->clk)) {
636 dev_err(dev, "failed to get clock\n");
637 return PTR_ERR(priv->clk);
640 priv->rst = devm_reset_control_get_shared(dev, "host");
641 if (IS_ERR(priv->rst)) {
642 dev_err(dev, "failed to get host reset\n");
643 return PTR_ERR(priv->rst);
646 /* old version has one more reset */
647 if (!(priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP)) {
648 priv->rst_br = devm_reset_control_get_shared(dev, "bridge");
649 if (IS_ERR(priv->rst_br)) {
650 dev_err(dev, "failed to get bridge reset\n");
651 return PTR_ERR(priv->rst_br);
655 tmio_data = &priv->tmio_data;
656 tmio_data->flags |= TMIO_MMC_32BIT_DATA_PORT;
657 tmio_data->flags |= TMIO_MMC_USE_BUSY_TIMEOUT;
659 host = tmio_mmc_host_alloc(pdev, tmio_data);
661 return PTR_ERR(host);
663 if (host->mmc->caps & MMC_CAP_HW_RESET) {
664 priv->rst_hw = devm_reset_control_get_exclusive(dev, "hw");
665 if (IS_ERR(priv->rst_hw)) {
666 dev_err(dev, "failed to get hw reset\n");
667 ret = PTR_ERR(priv->rst_hw);
670 host->ops.card_hw_reset = uniphier_sd_hw_reset;
673 if (host->mmc->caps & MMC_CAP_UHS) {
674 ret = uniphier_sd_uhs_init(host);
677 "failed to setup UHS (error %d). Disabling UHS.",
679 host->mmc->caps &= ~MMC_CAP_UHS;
681 host->ops.start_signal_voltage_switch =
682 uniphier_sd_start_signal_voltage_switch;
686 if (priv->caps & UNIPHIER_SD_CAP_EXTENDED_IP)
687 host->dma_ops = &uniphier_sd_internal_dma_ops;
689 host->dma_ops = &uniphier_sd_external_dma_ops;
692 host->clk_enable = uniphier_sd_clk_enable;
693 host->clk_disable = uniphier_sd_clk_disable;
694 host->set_clock = uniphier_sd_set_clock;
696 ret = uniphier_sd_clk_enable(host);
700 uniphier_sd_host_init(host);
702 tmio_data->ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34;
703 if (host->mmc->caps & MMC_CAP_UHS)
704 tmio_data->ocr_mask |= MMC_VDD_165_195;
706 tmio_data->max_segs = 1;
707 tmio_data->max_blk_count = U16_MAX;
709 ret = tmio_mmc_host_probe(host);
713 ret = devm_request_irq(dev, irq, tmio_mmc_irq, IRQF_SHARED,
714 dev_name(dev), host);
721 tmio_mmc_host_remove(host);
723 uniphier_sd_clk_disable(host);
725 tmio_mmc_host_free(host);
730 static int uniphier_sd_remove(struct platform_device *pdev)
732 struct tmio_mmc_host *host = platform_get_drvdata(pdev);
734 tmio_mmc_host_remove(host);
735 uniphier_sd_clk_disable(host);
736 tmio_mmc_host_free(host);
741 static const struct of_device_id uniphier_sd_match[] = {
743 .compatible = "socionext,uniphier-sd-v2.91",
746 .compatible = "socionext,uniphier-sd-v3.1",
747 .data = (void *)(UNIPHIER_SD_CAP_EXTENDED_IP |
748 UNIPHIER_SD_CAP_BROKEN_DMA_RX),
751 .compatible = "socionext,uniphier-sd-v3.1.1",
752 .data = (void *)UNIPHIER_SD_CAP_EXTENDED_IP,
756 MODULE_DEVICE_TABLE(of, uniphier_sd_match);
758 static struct platform_driver uniphier_sd_driver = {
759 .probe = uniphier_sd_probe,
760 .remove = uniphier_sd_remove,
762 .name = "uniphier-sd",
763 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
764 .of_match_table = uniphier_sd_match,
767 module_platform_driver(uniphier_sd_driver);
770 MODULE_DESCRIPTION("UniPhier SD/eMMC host controller driver");
771 MODULE_LICENSE("GPL v2");