.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Synopsys DesignWare Multimedia Card Interface driver |
---|
3 | 4 | * (Based on NXP driver for lpc 31xx) |
---|
4 | 5 | * |
---|
5 | 6 | * Copyright (C) 2009 NXP Semiconductors |
---|
6 | 7 | * Copyright (C) 2009, 2010 Imagination Technologies Ltd. |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - * (at your option) any later version. |
---|
12 | 8 | */ |
---|
13 | 9 | |
---|
14 | 10 | #include <linux/blkdev.h> |
---|
.. | .. |
---|
40 | 36 | #include <linux/of.h> |
---|
41 | 37 | #include <linux/of_gpio.h> |
---|
42 | 38 | #include <linux/mmc/slot-gpio.h> |
---|
| 39 | +#include <linux/soc/rockchip/rk_sdmmc.h> |
---|
43 | 40 | #include <linux/soc/rockchip/rockchip_decompress.h> |
---|
44 | 41 | |
---|
45 | 42 | #include "dw_mmc.h" |
---|
.. | .. |
---|
109 | 106 | /* Each descriptor can transfer up to 4KB of data in chained mode */ |
---|
110 | 107 | #define DW_MCI_DESC_DATA_LENGTH 0x1000 |
---|
111 | 108 | |
---|
| 109 | +#if IS_ENABLED(CONFIG_CPU_RV1106) |
---|
| 110 | +static spinlock_t *g_sdmmc_ispvicap_lock; |
---|
| 111 | + |
---|
| 112 | +void rv1106_sdmmc_get_lock(void) |
---|
| 113 | +{ |
---|
| 114 | + if (g_sdmmc_ispvicap_lock) |
---|
| 115 | + spin_lock(g_sdmmc_ispvicap_lock); |
---|
| 116 | +} |
---|
| 117 | +EXPORT_SYMBOL(rv1106_sdmmc_get_lock); |
---|
| 118 | + |
---|
| 119 | +void rv1106_sdmmc_put_lock(void) |
---|
| 120 | +{ |
---|
| 121 | + if (g_sdmmc_ispvicap_lock) |
---|
| 122 | + spin_unlock(g_sdmmc_ispvicap_lock); |
---|
| 123 | +} |
---|
| 124 | +EXPORT_SYMBOL(rv1106_sdmmc_put_lock); |
---|
| 125 | +#endif |
---|
| 126 | + |
---|
112 | 127 | #if defined(CONFIG_DEBUG_FS) |
---|
113 | 128 | static int dw_mci_req_show(struct seq_file *s, void *v) |
---|
114 | 129 | { |
---|
.. | .. |
---|
175 | 190 | struct mmc_host *mmc = slot->mmc; |
---|
176 | 191 | struct dw_mci *host = slot->host; |
---|
177 | 192 | struct dentry *root; |
---|
178 | | - struct dentry *node; |
---|
179 | 193 | |
---|
180 | 194 | root = mmc->debugfs_root; |
---|
181 | 195 | if (!root) |
---|
182 | 196 | return; |
---|
183 | 197 | |
---|
184 | | - node = debugfs_create_file("regs", S_IRUSR, root, host, |
---|
185 | | - &dw_mci_regs_fops); |
---|
186 | | - if (!node) |
---|
187 | | - goto err; |
---|
188 | | - |
---|
189 | | - node = debugfs_create_file("req", S_IRUSR, root, slot, |
---|
190 | | - &dw_mci_req_fops); |
---|
191 | | - if (!node) |
---|
192 | | - goto err; |
---|
193 | | - |
---|
194 | | - node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state); |
---|
195 | | - if (!node) |
---|
196 | | - goto err; |
---|
197 | | - |
---|
198 | | - node = debugfs_create_x32("pending_events", S_IRUSR, root, |
---|
199 | | - (u32 *)&host->pending_events); |
---|
200 | | - if (!node) |
---|
201 | | - goto err; |
---|
202 | | - |
---|
203 | | - node = debugfs_create_x32("completed_events", S_IRUSR, root, |
---|
204 | | - (u32 *)&host->completed_events); |
---|
205 | | - if (!node) |
---|
206 | | - goto err; |
---|
207 | | - |
---|
208 | | - return; |
---|
209 | | - |
---|
210 | | -err: |
---|
211 | | - dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n"); |
---|
| 198 | + debugfs_create_file("regs", S_IRUSR, root, host, &dw_mci_regs_fops); |
---|
| 199 | + debugfs_create_file("req", S_IRUSR, root, slot, &dw_mci_req_fops); |
---|
| 200 | + debugfs_create_u32("state", S_IRUSR, root, &host->state); |
---|
| 201 | + debugfs_create_xul("pending_events", S_IRUSR, root, |
---|
| 202 | + &host->pending_events); |
---|
| 203 | + debugfs_create_xul("completed_events", S_IRUSR, root, |
---|
| 204 | + &host->completed_events); |
---|
212 | 205 | } |
---|
213 | 206 | #endif /* defined(CONFIG_DEBUG_FS) */ |
---|
214 | 207 | |
---|
.. | .. |
---|
246 | 239 | * ...also allow sending for SDMMC_CMD_VOLT_SWITCH where busy is |
---|
247 | 240 | * expected. |
---|
248 | 241 | */ |
---|
249 | | -#ifdef CONFIG_ROCKCHIP_THUNDER_BOOT |
---|
250 | | - if (host->slot->mmc->restrict_caps & RESTRICT_CARD_TYPE_EMMC) |
---|
| 242 | +#ifdef CONFIG_ROCKCHIP_THUNDER_BOOT_MMC |
---|
| 243 | + if (host->slot->mmc->caps2 & MMC_CAP2_NO_SD && |
---|
| 244 | + host->slot->mmc->caps2 & MMC_CAP2_NO_SDIO) |
---|
251 | 245 | delay = 0; |
---|
252 | 246 | #endif |
---|
253 | 247 | if ((cmd_flags & SDMMC_CMD_PRV_DAT_WAIT) && |
---|
.. | .. |
---|
488 | 482 | |
---|
489 | 483 | /* Disable and reset the IDMAC interface */ |
---|
490 | 484 | temp = mci_readl(host, CTRL); |
---|
491 | | - temp &= ~SDMMC_CTRL_USE_IDMAC; |
---|
| 485 | + if (!host->is_rv1106_sd) |
---|
| 486 | + temp &= ~SDMMC_CTRL_USE_IDMAC; |
---|
| 487 | + |
---|
492 | 488 | temp |= SDMMC_CTRL_DMA_RESET; |
---|
493 | 489 | mci_writel(host, CTRL, temp); |
---|
494 | 490 | |
---|
495 | 491 | /* Stop the IDMAC running */ |
---|
496 | 492 | temp = mci_readl(host, BMOD); |
---|
497 | | - temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB); |
---|
498 | | - temp |= SDMMC_IDMAC_SWRESET; |
---|
| 493 | + if (host->is_rv1106_sd) { |
---|
| 494 | + temp |= SDMMC_IDMAC_SWRESET; |
---|
| 495 | + } else { |
---|
| 496 | + temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB); |
---|
| 497 | + temp |= SDMMC_IDMAC_SWRESET; |
---|
| 498 | + } |
---|
499 | 499 | mci_writel(host, BMOD, temp); |
---|
500 | 500 | } |
---|
501 | 501 | |
---|
.. | .. |
---|
736 | 736 | } |
---|
737 | 737 | } |
---|
738 | 738 | |
---|
| 739 | + if (host->is_rv1106_sd && (data->flags & MMC_DATA_WRITE)) { |
---|
| 740 | + desc->des0 = desc_last->des0; |
---|
| 741 | + desc->des2 = desc_last->des2; |
---|
| 742 | + desc->des1 = 0x8; /* Random dirty data for last one desc */ |
---|
| 743 | + desc_last = desc; |
---|
| 744 | + } |
---|
| 745 | + |
---|
739 | 746 | /* Set first descriptor */ |
---|
740 | 747 | desc_first->des0 |= cpu_to_le32(IDMAC_DES0_FD); |
---|
741 | 748 | |
---|
.. | .. |
---|
871 | 878 | if (!host->dms) |
---|
872 | 879 | return -ENOMEM; |
---|
873 | 880 | |
---|
874 | | - host->dms->ch = dma_request_slave_channel(host->dev, "rx-tx"); |
---|
875 | | - if (!host->dms->ch) { |
---|
| 881 | + host->dms->ch = dma_request_chan(host->dev, "rx-tx"); |
---|
| 882 | + if (IS_ERR(host->dms->ch)) { |
---|
| 883 | + int ret = PTR_ERR(host->dms->ch); |
---|
| 884 | + |
---|
876 | 885 | dev_err(host->dev, "Failed to get external DMA channel.\n"); |
---|
877 | 886 | kfree(host->dms); |
---|
878 | 887 | host->dms = NULL; |
---|
879 | | - return -ENXIO; |
---|
| 888 | + return ret; |
---|
880 | 889 | } |
---|
881 | 890 | |
---|
882 | 891 | return 0; |
---|
.. | .. |
---|
918 | 927 | * non-word-aligned buffers or lengths. Also, we don't bother |
---|
919 | 928 | * with all the DMA setup overhead for short transfers. |
---|
920 | 929 | */ |
---|
921 | | - if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD) |
---|
| 930 | + if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD && !host->is_rv1106_sd) |
---|
922 | 931 | return -EINVAL; |
---|
923 | 932 | |
---|
924 | 933 | if (data->blksz & 3) |
---|
.. | .. |
---|
976 | 985 | data->host_cookie = COOKIE_UNMAPPED; |
---|
977 | 986 | } |
---|
978 | 987 | |
---|
979 | | -static int dw_mci_set_sdio_status(struct mmc_host *mmc, int val) |
---|
980 | | -{ |
---|
981 | | - struct dw_mci_slot *slot = mmc_priv(mmc); |
---|
982 | | - struct dw_mci *host = slot->host; |
---|
983 | | - |
---|
984 | | - if (!(mmc->restrict_caps & RESTRICT_CARD_TYPE_SDIO)) |
---|
985 | | - return 0; |
---|
986 | | - |
---|
987 | | - spin_lock_bh(&host->lock); |
---|
988 | | - |
---|
989 | | - if (val) |
---|
990 | | - set_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
---|
991 | | - else |
---|
992 | | - clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
---|
993 | | - |
---|
994 | | - spin_unlock_bh(&host->lock); |
---|
995 | | - |
---|
996 | | - mmc_detect_change(slot->mmc, 20); |
---|
997 | | - |
---|
998 | | - return 0; |
---|
999 | | -} |
---|
1000 | | - |
---|
1001 | 988 | static int dw_mci_get_cd(struct mmc_host *mmc) |
---|
1002 | 989 | { |
---|
1003 | 990 | int present; |
---|
1004 | 991 | struct dw_mci_slot *slot = mmc_priv(mmc); |
---|
1005 | 992 | struct dw_mci *host = slot->host; |
---|
1006 | 993 | int gpio_cd = mmc_gpio_get_cd(mmc); |
---|
1007 | | - |
---|
1008 | | -#ifdef CONFIG_SDIO_KEEPALIVE |
---|
1009 | | - if (mmc->logic_remove_card) |
---|
1010 | | - return test_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
---|
1011 | | -#endif |
---|
1012 | 994 | |
---|
1013 | 995 | /* Use platform get_cd function, else try onboard card detect */ |
---|
1014 | 996 | if (((mmc->caps & MMC_CAP_NEEDS_POLL) |
---|
.. | .. |
---|
1358 | 1340 | host->data_status = 0; |
---|
1359 | 1341 | host->dir_status = 0; |
---|
1360 | 1342 | |
---|
| 1343 | + if (host->is_rv1106_sd) |
---|
| 1344 | + mci_writel(host, CTYPE, (slot->ctype << slot->id)); |
---|
| 1345 | + |
---|
1361 | 1346 | data = cmd->data; |
---|
1362 | 1347 | if (data) { |
---|
1363 | 1348 | mci_writel(host, TMOUT, 0xFFFFFFFF); |
---|
1364 | | - mci_writel(host, BYTCNT, data->blksz*data->blocks); |
---|
| 1349 | + if (host->is_rv1106_sd && (data->flags & MMC_DATA_WRITE)) |
---|
| 1350 | + mci_writel(host, BYTCNT, 0); |
---|
| 1351 | + else |
---|
| 1352 | + mci_writel(host, BYTCNT, data->blksz*data->blocks); |
---|
1365 | 1353 | mci_writel(host, BLKSIZ, data->blksz); |
---|
1366 | 1354 | } |
---|
1367 | 1355 | |
---|
.. | .. |
---|
1439 | 1427 | } |
---|
1440 | 1428 | } |
---|
1441 | 1429 | |
---|
| 1430 | +static bool dw_mci_reset(struct dw_mci *host); |
---|
1442 | 1431 | static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq) |
---|
1443 | 1432 | { |
---|
1444 | 1433 | struct dw_mci_slot *slot = mmc_priv(mmc); |
---|
.. | .. |
---|
1458 | 1447 | return; |
---|
1459 | 1448 | } |
---|
1460 | 1449 | |
---|
| 1450 | + if (host->is_rv1106_sd) { |
---|
| 1451 | + u32 reg; |
---|
| 1452 | + |
---|
| 1453 | + readl_poll_timeout(host->regs + SDMMC_STATUS, reg, |
---|
| 1454 | + reg & BIT(2), USEC_PER_MSEC, 500 * USEC_PER_MSEC); |
---|
| 1455 | + } |
---|
| 1456 | + |
---|
1461 | 1457 | spin_lock_bh(&host->lock); |
---|
| 1458 | + |
---|
| 1459 | + if (host->is_rv1106_sd) |
---|
| 1460 | + dw_mci_reset(host); |
---|
1462 | 1461 | |
---|
1463 | 1462 | dw_mci_queue_request(host, slot, mrq); |
---|
1464 | 1463 | |
---|
.. | .. |
---|
1508 | 1507 | |
---|
1509 | 1508 | switch (ios->power_mode) { |
---|
1510 | 1509 | case MMC_POWER_UP: |
---|
| 1510 | + if (!IS_ERR_OR_NULL(slot->host->pinctrl)) |
---|
| 1511 | + pinctrl_select_state(slot->host->pinctrl, slot->host->idle_state); |
---|
| 1512 | + |
---|
1511 | 1513 | if (!IS_ERR(mmc->supply.vmmc)) { |
---|
1512 | 1514 | ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, |
---|
1513 | 1515 | ios->vdd); |
---|
.. | .. |
---|
1524 | 1526 | mci_writel(slot->host, PWREN, regs); |
---|
1525 | 1527 | break; |
---|
1526 | 1528 | case MMC_POWER_ON: |
---|
| 1529 | + if (!IS_ERR_OR_NULL(slot->host->pinctrl)) |
---|
| 1530 | + pinctrl_select_state(slot->host->pinctrl, slot->host->normal_state); |
---|
| 1531 | + |
---|
1527 | 1532 | if (!slot->host->vqmmc_enabled) { |
---|
1528 | 1533 | if (!IS_ERR(mmc->supply.vqmmc)) { |
---|
1529 | 1534 | ret = regulator_enable(mmc->supply.vqmmc); |
---|
.. | .. |
---|
1548 | 1553 | |
---|
1549 | 1554 | break; |
---|
1550 | 1555 | case MMC_POWER_OFF: |
---|
| 1556 | + if (!IS_ERR_OR_NULL(slot->host->pinctrl)) |
---|
| 1557 | + pinctrl_select_state(slot->host->pinctrl, slot->host->idle_state); |
---|
| 1558 | + |
---|
1551 | 1559 | /* Turn clock off before power goes down */ |
---|
1552 | 1560 | dw_mci_setup_bus(slot, false); |
---|
1553 | 1561 | |
---|
1554 | 1562 | if (!IS_ERR(mmc->supply.vmmc)) |
---|
1555 | 1563 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); |
---|
1556 | 1564 | |
---|
1557 | | - if (!IS_ERR(mmc->supply.vqmmc) && slot->host->vqmmc_enabled) { |
---|
1558 | | - ios->signal_voltage = MMC_SIGNAL_VOLTAGE_330; |
---|
1559 | | - mmc_regulator_set_vqmmc(mmc, ios); |
---|
| 1565 | + if (!IS_ERR(mmc->supply.vqmmc) && slot->host->vqmmc_enabled) |
---|
1560 | 1566 | regulator_disable(mmc->supply.vqmmc); |
---|
1561 | | - } |
---|
1562 | 1567 | slot->host->vqmmc_enabled = false; |
---|
1563 | 1568 | |
---|
1564 | 1569 | regs = mci_readl(slot->host, PWREN); |
---|
.. | .. |
---|
1612 | 1617 | |
---|
1613 | 1618 | if (!IS_ERR(mmc->supply.vqmmc)) { |
---|
1614 | 1619 | ret = mmc_regulator_set_vqmmc(mmc, ios); |
---|
1615 | | - |
---|
1616 | | - if (ret) { |
---|
| 1620 | + if (ret < 0) { |
---|
1617 | 1621 | dev_dbg(&mmc->class_dev, |
---|
1618 | 1622 | "Regulator set error %d - %s V\n", |
---|
1619 | 1623 | ret, uhs & v18 ? "1.8" : "3.3"); |
---|
.. | .. |
---|
1843 | 1847 | .pre_req = dw_mci_pre_req, |
---|
1844 | 1848 | .post_req = dw_mci_post_req, |
---|
1845 | 1849 | .set_ios = dw_mci_set_ios, |
---|
1846 | | - .set_sdio_status = dw_mci_set_sdio_status, |
---|
1847 | 1850 | .get_ro = dw_mci_get_ro, |
---|
1848 | 1851 | .get_cd = dw_mci_get_cd, |
---|
1849 | 1852 | .hw_reset = dw_mci_hw_reset, |
---|
.. | .. |
---|
1885 | 1888 | } |
---|
1886 | 1889 | |
---|
1887 | 1890 | spin_unlock(&host->lock); |
---|
| 1891 | + |
---|
1888 | 1892 | mmc_request_done(prev_mmc, mrq); |
---|
1889 | 1893 | spin_lock(&host->lock); |
---|
1890 | 1894 | } |
---|
.. | .. |
---|
1926 | 1930 | { |
---|
1927 | 1931 | u32 status = host->data_status; |
---|
1928 | 1932 | |
---|
| 1933 | + if (host->is_rv1106_sd && (data->flags & MMC_DATA_WRITE) && (status & SDMMC_INT_DATA_OVER)) |
---|
| 1934 | + goto finish; |
---|
| 1935 | + |
---|
1929 | 1936 | if (status & DW_MCI_DATA_ERROR_FLAGS) { |
---|
1930 | 1937 | if (status & SDMMC_INT_DRTO) { |
---|
1931 | 1938 | data->error = -ETIMEDOUT; |
---|
.. | .. |
---|
1958 | 1965 | */ |
---|
1959 | 1966 | dw_mci_reset(host); |
---|
1960 | 1967 | } else { |
---|
| 1968 | +finish: |
---|
1961 | 1969 | data->bytes_xfered = data->blocks * data->blksz; |
---|
1962 | 1970 | data->error = 0; |
---|
1963 | 1971 | } |
---|
.. | .. |
---|
2123 | 2131 | } |
---|
2124 | 2132 | |
---|
2125 | 2133 | prev_state = state = STATE_SENDING_DATA; |
---|
2126 | | - /* fall through */ |
---|
| 2134 | + fallthrough; |
---|
2127 | 2135 | |
---|
2128 | 2136 | case STATE_SENDING_DATA: |
---|
2129 | 2137 | /* |
---|
.. | .. |
---|
2184 | 2192 | } |
---|
2185 | 2193 | prev_state = state = STATE_DATA_BUSY; |
---|
2186 | 2194 | |
---|
2187 | | - /* fall through */ |
---|
| 2195 | + fallthrough; |
---|
2188 | 2196 | |
---|
2189 | 2197 | case STATE_DATA_BUSY: |
---|
2190 | 2198 | if (!dw_mci_clear_pending_data_complete(host)) { |
---|
.. | .. |
---|
2237 | 2245 | */ |
---|
2238 | 2246 | prev_state = state = STATE_SENDING_STOP; |
---|
2239 | 2247 | |
---|
2240 | | - /* fall through */ |
---|
| 2248 | + fallthrough; |
---|
2241 | 2249 | |
---|
2242 | 2250 | case STATE_SENDING_STOP: |
---|
2243 | 2251 | if (!dw_mci_clear_pending_cmd_complete(host)) |
---|
.. | .. |
---|
2762 | 2770 | } |
---|
2763 | 2771 | |
---|
2764 | 2772 | if (pending & SDMMC_INT_DATA_OVER) { |
---|
| 2773 | +rv1106_sd: |
---|
2765 | 2774 | spin_lock_irqsave(&host->irq_lock, irqflags); |
---|
2766 | 2775 | |
---|
2767 | 2776 | del_timer(&host->dto_timer); |
---|
2768 | 2777 | |
---|
2769 | 2778 | mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER); |
---|
| 2779 | + if (host->is_rv1106_sd) |
---|
| 2780 | + pending |= SDMMC_INT_DATA_OVER; |
---|
2770 | 2781 | if (!host->data_status) |
---|
2771 | 2782 | host->data_status = pending; |
---|
2772 | 2783 | smp_wmb(); /* drain writebuffer */ |
---|
.. | .. |
---|
2836 | 2847 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI); |
---|
2837 | 2848 | if (!test_bit(EVENT_DATA_ERROR, &host->pending_events)) |
---|
2838 | 2849 | host->dma_ops->complete((void *)host); |
---|
| 2850 | + |
---|
| 2851 | + if (host->is_rv1106_sd && (pending & SDMMC_IDMAC_INT_TI)) |
---|
| 2852 | + goto rv1106_sd; |
---|
2839 | 2853 | } |
---|
2840 | 2854 | } |
---|
2841 | 2855 | |
---|
.. | .. |
---|
2851 | 2865 | |
---|
2852 | 2866 | if (host->pdata->caps) |
---|
2853 | 2867 | mmc->caps = host->pdata->caps; |
---|
2854 | | - |
---|
2855 | | - /* |
---|
2856 | | - * Support MMC_CAP_ERASE by default. |
---|
2857 | | - * It needs to use trim/discard/erase commands. |
---|
2858 | | - */ |
---|
2859 | | - mmc->caps |= MMC_CAP_ERASE; |
---|
2860 | 2868 | |
---|
2861 | 2869 | if (host->pdata->pm_caps) |
---|
2862 | 2870 | mmc->pm_caps = host->pdata->pm_caps; |
---|
.. | .. |
---|
2875 | 2883 | ctrl_id); |
---|
2876 | 2884 | return -EINVAL; |
---|
2877 | 2885 | } |
---|
2878 | | - /* |
---|
2879 | | - * Some sd cards violate the spec. They claim to support |
---|
2880 | | - * CMD23 but actually not. We don't have a good method to |
---|
2881 | | - * work around them except for adding MMC_QUIRK_BLK_NO_CMD23 |
---|
2882 | | - * one by one. But it's not a acceptable way for our custmors. |
---|
2883 | | - * So removing CMD23 support for all sd cards to solve it. |
---|
2884 | | - */ |
---|
2885 | | - if (!(mmc->restrict_caps & RESTRICT_CARD_TYPE_SD)) |
---|
2886 | | - mmc->caps |= drv_data->caps[ctrl_id]; |
---|
| 2886 | + mmc->caps |= drv_data->caps[ctrl_id]; |
---|
2887 | 2887 | } |
---|
2888 | 2888 | |
---|
2889 | 2889 | if (host->pdata->caps2) |
---|
.. | .. |
---|
2937 | 2937 | |
---|
2938 | 2938 | /* Useful defaults if platform data is unset. */ |
---|
2939 | 2939 | if (host->use_dma == TRANS_MODE_IDMAC) { |
---|
| 2940 | + /* Reserve last desc for dirty data */ |
---|
| 2941 | + if (host->is_rv1106_sd) |
---|
| 2942 | + host->ring_size--; |
---|
| 2943 | + |
---|
2940 | 2944 | mmc->max_segs = host->ring_size; |
---|
2941 | 2945 | mmc->max_blk_size = 65535; |
---|
2942 | 2946 | mmc->max_seg_size = 0x1000; |
---|
.. | .. |
---|
2960 | 2964 | } |
---|
2961 | 2965 | |
---|
2962 | 2966 | dw_mci_get_cd(mmc); |
---|
2963 | | - |
---|
2964 | | -#ifdef CONFIG_SDIO_KEEPALIVE |
---|
2965 | | - if (mmc->logic_remove_card) |
---|
2966 | | - clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
---|
2967 | | -#endif |
---|
2968 | 2967 | |
---|
2969 | 2968 | ret = mmc_add_host(mmc); |
---|
2970 | 2969 | if (ret) |
---|
.. | .. |
---|
3272 | 3271 | return ERR_PTR(ret); |
---|
3273 | 3272 | } |
---|
3274 | 3273 | |
---|
| 3274 | + host->pinctrl = devm_pinctrl_get(host->dev); |
---|
| 3275 | + if (!IS_ERR(host->pinctrl)) { |
---|
| 3276 | + host->normal_state = pinctrl_lookup_state(host->pinctrl, "normal"); |
---|
| 3277 | + if (IS_ERR(host->normal_state)) |
---|
| 3278 | + dev_warn(dev, "No normal pinctrl state\n"); |
---|
| 3279 | + |
---|
| 3280 | + host->idle_state = pinctrl_lookup_state(host->pinctrl, "idle"); |
---|
| 3281 | + if (IS_ERR(host->idle_state)) |
---|
| 3282 | + dev_warn(dev, "No idle pinctrl state\n"); |
---|
| 3283 | + |
---|
| 3284 | + if (!IS_ERR(host->normal_state) && !IS_ERR(host->idle_state)) |
---|
| 3285 | + pinctrl_select_state(host->pinctrl, host->idle_state); |
---|
| 3286 | + else |
---|
| 3287 | + host->pinctrl = NULL; |
---|
| 3288 | + } |
---|
| 3289 | + |
---|
3275 | 3290 | return pdata; |
---|
3276 | 3291 | } |
---|
3277 | 3292 | |
---|
.. | .. |
---|
3311 | 3326 | |
---|
3312 | 3327 | if (!host->pdata) { |
---|
3313 | 3328 | host->pdata = dw_mci_parse_dt(host); |
---|
3314 | | - if (PTR_ERR(host->pdata) == -EPROBE_DEFER) { |
---|
3315 | | - return -EPROBE_DEFER; |
---|
3316 | | - } else if (IS_ERR(host->pdata)) { |
---|
3317 | | - dev_err(host->dev, "platform data not available\n"); |
---|
3318 | | - return -EINVAL; |
---|
3319 | | - } |
---|
| 3329 | + if (IS_ERR(host->pdata)) |
---|
| 3330 | + return dev_err_probe(host->dev, PTR_ERR(host->pdata), |
---|
| 3331 | + "platform data not available\n"); |
---|
3320 | 3332 | } |
---|
3321 | 3333 | |
---|
3322 | 3334 | host->biu_clk = devm_clk_get(host->dev, "biu"); |
---|
.. | .. |
---|
3329 | 3341 | return ret; |
---|
3330 | 3342 | } |
---|
3331 | 3343 | } |
---|
3332 | | -#ifdef CONFIG_ROCKCHIP_THUNDER_BOOT |
---|
3333 | | - if (device_property_read_bool(host->dev, "supports-emmc")) { |
---|
| 3344 | + |
---|
| 3345 | +#ifdef CONFIG_ROCKCHIP_THUNDER_BOOT_MMC |
---|
| 3346 | + if (device_property_read_bool(host->dev, "no-sd") && |
---|
| 3347 | + device_property_read_bool(host->dev, "no-sdio")) { |
---|
3334 | 3348 | if (readl_poll_timeout(host->regs + SDMMC_STATUS, |
---|
3335 | 3349 | fifo_size, |
---|
3336 | 3350 | !(fifo_size & (BIT(10) | GENMASK(7, 4))), |
---|
.. | .. |
---|
3507 | 3521 | goto err_dmaunmap; |
---|
3508 | 3522 | } |
---|
3509 | 3523 | |
---|
| 3524 | + if (host->is_rv1106_sd) { |
---|
| 3525 | +#if IS_ENABLED(CONFIG_CPU_RV1106) |
---|
| 3526 | + g_sdmmc_ispvicap_lock = &host->lock; |
---|
| 3527 | +#endif |
---|
| 3528 | + /* Select IDMAC interface */ |
---|
| 3529 | + fifo_size = mci_readl(host, CTRL); |
---|
| 3530 | + fifo_size |= SDMMC_CTRL_USE_IDMAC; |
---|
| 3531 | + mci_writel(host, CTRL, fifo_size); |
---|
| 3532 | + |
---|
| 3533 | + fifo_size = mci_readl(host, INTMASK); |
---|
| 3534 | + fifo_size &= ~SDMMC_INT_HTO; |
---|
| 3535 | + mci_writel(host, INTMASK, fifo_size); |
---|
| 3536 | + |
---|
| 3537 | + host->slot->mmc->caps &= ~(MMC_CAP_UHS_DDR50 | MMC_CAP_UHS_SDR104 | |
---|
| 3538 | + MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 | |
---|
| 3539 | + MMC_CAP_UHS_SDR12); |
---|
| 3540 | + } |
---|
| 3541 | + |
---|
3510 | 3542 | /* Now that slots are all setup, we can enable card detect */ |
---|
3511 | 3543 | dw_mci_enable_cd(host); |
---|
3512 | 3544 | |
---|
.. | .. |
---|
3604 | 3636 | * Restore the initial value at FIFOTH register |
---|
3605 | 3637 | * And Invalidate the prev_blksz with zero |
---|
3606 | 3638 | */ |
---|
3607 | | - mci_writel(host, FIFOTH, host->fifoth_val); |
---|
3608 | | - host->prev_blksz = 0; |
---|
| 3639 | + mci_writel(host, FIFOTH, host->fifoth_val); |
---|
| 3640 | + host->prev_blksz = 0; |
---|
3609 | 3641 | |
---|
3610 | 3642 | /* Put in max timeout */ |
---|
3611 | 3643 | mci_writel(host, TMOUT, 0xFFFFFFFF); |
---|
3612 | 3644 | |
---|
3613 | 3645 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
---|
3614 | | - mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | |
---|
3615 | | - SDMMC_INT_TXDR | SDMMC_INT_RXDR | |
---|
3616 | | - DW_MCI_ERROR_FLAGS); |
---|
| 3646 | + mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | DW_MCI_ERROR_FLAGS); |
---|
3617 | 3647 | mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); |
---|
3618 | 3648 | |
---|
| 3649 | + if (host->is_rv1106_sd) { |
---|
| 3650 | + /* Select IDMAC interface */ |
---|
| 3651 | + ret = mci_readl(host, CTRL); |
---|
| 3652 | + ret |= SDMMC_CTRL_USE_IDMAC; |
---|
| 3653 | + mci_writel(host, CTRL, ret); |
---|
| 3654 | + |
---|
| 3655 | + ret = mci_readl(host, INTMASK); |
---|
| 3656 | + ret &= ~SDMMC_INT_HTO; |
---|
| 3657 | + mci_writel(host, INTMASK, ret); |
---|
| 3658 | + } |
---|
3619 | 3659 | |
---|
3620 | 3660 | if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) |
---|
3621 | 3661 | dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios); |
---|