.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for the MMC / SD / SDIO IP found in: |
---|
3 | 4 | * |
---|
4 | 5 | * TC6393XB, TC6391XB, TC6387XB, T7L66XB, ASIC3, SH-Mobile SoCs |
---|
5 | 6 | * |
---|
6 | | - * Copyright (C) 2015-17 Renesas Electronics Corporation |
---|
7 | | - * Copyright (C) 2016-17 Sang Engineering, Wolfram Sang |
---|
| 7 | + * Copyright (C) 2015-19 Renesas Electronics Corporation |
---|
| 8 | + * Copyright (C) 2016-19 Sang Engineering, Wolfram Sang |
---|
8 | 9 | * Copyright (C) 2017 Horms Solutions, Simon Horman |
---|
9 | 10 | * Copyright (C) 2011 Guennadi Liakhovetski |
---|
10 | 11 | * Copyright (C) 2007 Ian Molton |
---|
11 | 12 | * Copyright (C) 2004 Ian Molton |
---|
12 | | - * |
---|
13 | | - * This program is free software; you can redistribute it and/or modify |
---|
14 | | - * it under the terms of the GNU General Public License version 2 as |
---|
15 | | - * published by the Free Software Foundation. |
---|
16 | 13 | * |
---|
17 | 14 | * This driver draws mainly on scattered spec sheets, Reverse engineering |
---|
18 | 15 | * of the toshiba e800 SD driver and some parts of the 2.4 ASIC3 driver (4 bit |
---|
.. | .. |
---|
29 | 26 | |
---|
30 | 27 | #include <linux/delay.h> |
---|
31 | 28 | #include <linux/device.h> |
---|
| 29 | +#include <linux/dma-mapping.h> |
---|
32 | 30 | #include <linux/highmem.h> |
---|
33 | 31 | #include <linux/interrupt.h> |
---|
34 | 32 | #include <linux/io.h> |
---|
.. | .. |
---|
48 | 46 | #include <linux/scatterlist.h> |
---|
49 | 47 | #include <linux/sizes.h> |
---|
50 | 48 | #include <linux/spinlock.h> |
---|
51 | | -#include <linux/swiotlb.h> |
---|
52 | 49 | #include <linux/workqueue.h> |
---|
53 | 50 | |
---|
54 | 51 | #include "tmio_mmc.h" |
---|
.. | .. |
---|
58 | 55 | { |
---|
59 | 56 | if (host->dma_ops) |
---|
60 | 57 | host->dma_ops->start(host, data); |
---|
| 58 | +} |
---|
| 59 | + |
---|
| 60 | +static inline void tmio_mmc_end_dma(struct tmio_mmc_host *host) |
---|
| 61 | +{ |
---|
| 62 | + if (host->dma_ops && host->dma_ops->end) |
---|
| 63 | + host->dma_ops->end(host); |
---|
61 | 64 | } |
---|
62 | 65 | |
---|
63 | 66 | static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable) |
---|
.. | .. |
---|
161 | 164 | } |
---|
162 | 165 | } |
---|
163 | 166 | |
---|
164 | | -static void tmio_mmc_clk_start(struct tmio_mmc_host *host) |
---|
165 | | -{ |
---|
166 | | - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN | |
---|
167 | | - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); |
---|
168 | | - |
---|
169 | | - /* HW engineers overrode docs: no sleep needed on R-Car2+ */ |
---|
170 | | - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) |
---|
171 | | - usleep_range(10000, 11000); |
---|
172 | | - |
---|
173 | | - if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) { |
---|
174 | | - sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100); |
---|
175 | | - usleep_range(10000, 11000); |
---|
176 | | - } |
---|
177 | | -} |
---|
178 | | - |
---|
179 | | -static void tmio_mmc_clk_stop(struct tmio_mmc_host *host) |
---|
180 | | -{ |
---|
181 | | - if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) { |
---|
182 | | - sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0000); |
---|
183 | | - usleep_range(10000, 11000); |
---|
184 | | - } |
---|
185 | | - |
---|
186 | | - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & |
---|
187 | | - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); |
---|
188 | | - |
---|
189 | | - /* HW engineers overrode docs: no sleep needed on R-Car2+ */ |
---|
190 | | - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) |
---|
191 | | - usleep_range(10000, 11000); |
---|
192 | | -} |
---|
193 | | - |
---|
194 | | -static void tmio_mmc_set_clock(struct tmio_mmc_host *host, |
---|
195 | | - unsigned int new_clock) |
---|
196 | | -{ |
---|
197 | | - u32 clk = 0, clock; |
---|
198 | | - |
---|
199 | | - if (new_clock == 0) { |
---|
200 | | - tmio_mmc_clk_stop(host); |
---|
201 | | - return; |
---|
202 | | - } |
---|
203 | | - /* |
---|
204 | | - * Both HS400 and HS200/SD104 set 200MHz, but some devices need to |
---|
205 | | - * set 400MHz to distinguish the CPG settings in HS400. |
---|
206 | | - */ |
---|
207 | | - if (host->mmc->ios.timing == MMC_TIMING_MMC_HS400 && |
---|
208 | | - host->pdata->flags & TMIO_MMC_HAVE_4TAP_HS400 && |
---|
209 | | - new_clock == 200000000) |
---|
210 | | - new_clock = 400000000; |
---|
211 | | - |
---|
212 | | - if (host->clk_update) |
---|
213 | | - clock = host->clk_update(host, new_clock) / 512; |
---|
214 | | - else |
---|
215 | | - clock = host->mmc->f_min; |
---|
216 | | - |
---|
217 | | - for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) |
---|
218 | | - clock <<= 1; |
---|
219 | | - |
---|
220 | | - /* 1/1 clock is option */ |
---|
221 | | - if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && |
---|
222 | | - ((clk >> 22) & 0x1)) { |
---|
223 | | - if (!(host->mmc->ios.timing == MMC_TIMING_MMC_HS400)) |
---|
224 | | - clk |= 0xff; |
---|
225 | | - else |
---|
226 | | - clk &= ~0xff; |
---|
227 | | - } |
---|
228 | | - |
---|
229 | | - if (host->set_clk_div) |
---|
230 | | - host->set_clk_div(host->pdev, (clk >> 22) & 1); |
---|
231 | | - |
---|
232 | | - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & |
---|
233 | | - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); |
---|
234 | | - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK); |
---|
235 | | - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) |
---|
236 | | - usleep_range(10000, 11000); |
---|
237 | | - |
---|
238 | | - tmio_mmc_clk_start(host); |
---|
239 | | -} |
---|
240 | | - |
---|
241 | 167 | static void tmio_mmc_reset(struct tmio_mmc_host *host) |
---|
242 | 168 | { |
---|
243 | 169 | /* FIXME - should we set stop clock reg here */ |
---|
244 | 170 | sd_ctrl_write16(host, CTL_RESET_SD, 0x0000); |
---|
245 | | - if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) |
---|
246 | | - sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0000); |
---|
247 | 171 | usleep_range(10000, 11000); |
---|
248 | 172 | sd_ctrl_write16(host, CTL_RESET_SD, 0x0001); |
---|
249 | | - if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) |
---|
250 | | - sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0001); |
---|
251 | 173 | usleep_range(10000, 11000); |
---|
| 174 | + |
---|
| 175 | + if (host->reset) |
---|
| 176 | + host->reset(host); |
---|
| 177 | + |
---|
| 178 | + tmio_mmc_abort_dma(host); |
---|
252 | 179 | |
---|
253 | 180 | if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) { |
---|
254 | 181 | sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask); |
---|
255 | 182 | sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001); |
---|
256 | 183 | } |
---|
257 | | - |
---|
258 | 184 | } |
---|
259 | 185 | |
---|
260 | 186 | static void tmio_mmc_reset_work(struct work_struct *work) |
---|
.. | .. |
---|
299 | 225 | |
---|
300 | 226 | /* Ready for new calls */ |
---|
301 | 227 | host->mrq = NULL; |
---|
302 | | - |
---|
303 | | - tmio_mmc_abort_dma(host); |
---|
304 | 228 | mmc_request_done(host->mmc, mrq); |
---|
305 | 229 | } |
---|
306 | 230 | |
---|
.. | .. |
---|
447 | 371 | unsigned int count; |
---|
448 | 372 | unsigned long flags; |
---|
449 | 373 | |
---|
450 | | - if ((host->chan_tx || host->chan_rx) && !host->force_pio) { |
---|
| 374 | + if (host->dma_on) { |
---|
451 | 375 | pr_err("PIO IRQ in DMA mode!\n"); |
---|
452 | 376 | return; |
---|
453 | 377 | } else if (!data) { |
---|
.. | .. |
---|
519 | 443 | */ |
---|
520 | 444 | |
---|
521 | 445 | if (data->flags & MMC_DATA_READ) { |
---|
522 | | - if (host->chan_rx && !host->force_pio) |
---|
| 446 | + if (host->dma_on) |
---|
523 | 447 | tmio_mmc_check_bounce_buffer(host); |
---|
524 | 448 | dev_dbg(&host->pdev->dev, "Complete Rx request %p\n", |
---|
525 | 449 | host->mrq); |
---|
.. | .. |
---|
556 | 480 | if (stat & TMIO_STAT_CRCFAIL || stat & TMIO_STAT_STOPBIT_ERR || |
---|
557 | 481 | stat & TMIO_STAT_TXUNDERRUN) |
---|
558 | 482 | data->error = -EILSEQ; |
---|
559 | | - if (host->chan_tx && (data->flags & MMC_DATA_WRITE) && !host->force_pio) { |
---|
| 483 | + if (host->dma_on && (data->flags & MMC_DATA_WRITE)) { |
---|
560 | 484 | u32 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS); |
---|
561 | 485 | bool done = false; |
---|
562 | 486 | |
---|
.. | .. |
---|
580 | 504 | tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND); |
---|
581 | 505 | tmio_mmc_dataend_dma(host); |
---|
582 | 506 | } |
---|
583 | | - } else if (host->chan_rx && (data->flags & MMC_DATA_READ) && !host->force_pio) { |
---|
| 507 | + } else if (host->dma_on && (data->flags & MMC_DATA_READ)) { |
---|
584 | 508 | tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND); |
---|
585 | 509 | tmio_mmc_dataend_dma(host); |
---|
586 | 510 | } else { |
---|
.. | .. |
---|
633 | 557 | */ |
---|
634 | 558 | if (host->data && (!cmd->error || cmd->error == -EILSEQ)) { |
---|
635 | 559 | if (host->data->flags & MMC_DATA_READ) { |
---|
636 | | - if (host->force_pio || !host->chan_rx) { |
---|
| 560 | + if (!host->dma_on) { |
---|
637 | 561 | tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_READOP); |
---|
638 | 562 | } else { |
---|
639 | 563 | tmio_mmc_disable_mmc_irqs(host, |
---|
.. | .. |
---|
641 | 565 | tasklet_schedule(&host->dma_issue); |
---|
642 | 566 | } |
---|
643 | 567 | } else { |
---|
644 | | - if (host->force_pio || !host->chan_tx) { |
---|
| 568 | + if (!host->dma_on) { |
---|
645 | 569 | tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_WRITEOP); |
---|
646 | 570 | } else { |
---|
647 | 571 | tmio_mmc_disable_mmc_irqs(host, |
---|
.. | .. |
---|
774 | 698 | |
---|
775 | 699 | tmio_mmc_init_sg(host, data); |
---|
776 | 700 | host->data = data; |
---|
777 | | - host->force_pio = false; |
---|
| 701 | + host->dma_on = false; |
---|
778 | 702 | |
---|
779 | 703 | /* Set transfer length / blocksize */ |
---|
780 | 704 | sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz); |
---|
.. | .. |
---|
786 | 710 | tmio_mmc_start_dma(host, data); |
---|
787 | 711 | |
---|
788 | 712 | return 0; |
---|
789 | | -} |
---|
790 | | - |
---|
791 | | -static void tmio_mmc_hw_reset(struct mmc_host *mmc) |
---|
792 | | -{ |
---|
793 | | - struct tmio_mmc_host *host = mmc_priv(mmc); |
---|
794 | | - |
---|
795 | | - if (host->hw_reset) |
---|
796 | | - host->hw_reset(host); |
---|
797 | | -} |
---|
798 | | - |
---|
799 | | -static int tmio_mmc_execute_tuning(struct mmc_host *mmc, u32 opcode) |
---|
800 | | -{ |
---|
801 | | - struct tmio_mmc_host *host = mmc_priv(mmc); |
---|
802 | | - int i, ret = 0; |
---|
803 | | - |
---|
804 | | - if (!host->init_tuning || !host->select_tuning) |
---|
805 | | - /* Tuning is not supported */ |
---|
806 | | - goto out; |
---|
807 | | - |
---|
808 | | - host->tap_num = host->init_tuning(host); |
---|
809 | | - if (!host->tap_num) |
---|
810 | | - /* Tuning is not supported */ |
---|
811 | | - goto out; |
---|
812 | | - |
---|
813 | | - if (host->tap_num * 2 >= sizeof(host->taps) * BITS_PER_BYTE) { |
---|
814 | | - dev_warn_once(&host->pdev->dev, |
---|
815 | | - "Too many taps, skipping tuning. Please consider updating size of taps field of tmio_mmc_host\n"); |
---|
816 | | - goto out; |
---|
817 | | - } |
---|
818 | | - |
---|
819 | | - bitmap_zero(host->taps, host->tap_num * 2); |
---|
820 | | - |
---|
821 | | - /* Issue CMD19 twice for each tap */ |
---|
822 | | - for (i = 0; i < 2 * host->tap_num; i++) { |
---|
823 | | - if (host->prepare_tuning) |
---|
824 | | - host->prepare_tuning(host, i % host->tap_num); |
---|
825 | | - |
---|
826 | | - ret = mmc_send_tuning(mmc, opcode, NULL); |
---|
827 | | - if (ret == 0) |
---|
828 | | - set_bit(i, host->taps); |
---|
829 | | - |
---|
830 | | - usleep_range(1000, 1200); |
---|
831 | | - } |
---|
832 | | - |
---|
833 | | - ret = host->select_tuning(host); |
---|
834 | | - |
---|
835 | | -out: |
---|
836 | | - if (ret < 0) { |
---|
837 | | - dev_warn(&host->pdev->dev, "Tuning procedure failed\n"); |
---|
838 | | - tmio_mmc_hw_reset(mmc); |
---|
839 | | - } |
---|
840 | | - |
---|
841 | | - return ret; |
---|
842 | 713 | } |
---|
843 | 714 | |
---|
844 | 715 | static void tmio_process_mrq(struct tmio_mmc_host *host, |
---|
.. | .. |
---|
906 | 777 | |
---|
907 | 778 | spin_lock_irqsave(&host->lock, flags); |
---|
908 | 779 | |
---|
| 780 | + tmio_mmc_end_dma(host); |
---|
| 781 | + |
---|
909 | 782 | mrq = host->mrq; |
---|
910 | 783 | if (IS_ERR_OR_NULL(mrq)) { |
---|
911 | 784 | spin_unlock_irqrestore(&host->lock, flags); |
---|
.. | .. |
---|
926 | 799 | if (mrq->cmd->error || (mrq->data && mrq->data->error)) |
---|
927 | 800 | tmio_mmc_abort_dma(host); |
---|
928 | 801 | |
---|
929 | | - /* SCC error means retune, but executed command was still successful */ |
---|
930 | | - if (host->check_scc_error && host->check_scc_error(host)) |
---|
| 802 | + /* Error means retune, but executed command was still successful */ |
---|
| 803 | + if (host->check_retune && host->check_retune(host)) |
---|
931 | 804 | mmc_retune_needed(host->mmc); |
---|
932 | 805 | |
---|
933 | 806 | /* If SET_BLOCK_COUNT, continue with main command */ |
---|
.. | .. |
---|
935 | 808 | tmio_process_mrq(host, mrq); |
---|
936 | 809 | return; |
---|
937 | 810 | } |
---|
| 811 | + |
---|
| 812 | + if (host->fixup_request) |
---|
| 813 | + host->fixup_request(host, mrq); |
---|
938 | 814 | |
---|
939 | 815 | mmc_request_done(host->mmc, mrq); |
---|
940 | 816 | } |
---|
.. | .. |
---|
1051 | 927 | switch (ios->power_mode) { |
---|
1052 | 928 | case MMC_POWER_OFF: |
---|
1053 | 929 | tmio_mmc_power_off(host); |
---|
1054 | | - tmio_mmc_clk_stop(host); |
---|
| 930 | + /* For R-Car Gen2+, we need to reset SDHI specific SCC */ |
---|
| 931 | + if (host->pdata->flags & TMIO_MMC_MIN_RCAR2) |
---|
| 932 | + host->reset(host); |
---|
| 933 | + host->set_clock(host, 0); |
---|
1055 | 934 | break; |
---|
1056 | 935 | case MMC_POWER_UP: |
---|
1057 | 936 | tmio_mmc_power_on(host, ios->vdd); |
---|
1058 | | - tmio_mmc_set_clock(host, ios->clock); |
---|
| 937 | + host->set_clock(host, ios->clock); |
---|
1059 | 938 | tmio_mmc_set_bus_width(host, ios->bus_width); |
---|
1060 | 939 | break; |
---|
1061 | 940 | case MMC_POWER_ON: |
---|
1062 | | - tmio_mmc_set_clock(host, ios->clock); |
---|
| 941 | + host->set_clock(host, ios->clock); |
---|
1063 | 942 | tmio_mmc_set_bus_width(host, ios->bus_width); |
---|
1064 | 943 | break; |
---|
1065 | 944 | } |
---|
.. | .. |
---|
1105 | 984 | return blk_size; |
---|
1106 | 985 | } |
---|
1107 | 986 | |
---|
1108 | | -static int tmio_mmc_prepare_hs400_tuning(struct mmc_host *mmc, |
---|
1109 | | - struct mmc_ios *ios) |
---|
1110 | | -{ |
---|
1111 | | - struct tmio_mmc_host *host = mmc_priv(mmc); |
---|
1112 | | - |
---|
1113 | | - if (host->prepare_hs400_tuning) |
---|
1114 | | - host->prepare_hs400_tuning(host); |
---|
1115 | | - |
---|
1116 | | - return 0; |
---|
1117 | | -} |
---|
1118 | | - |
---|
1119 | | -static void tmio_mmc_hs400_downgrade(struct mmc_host *mmc) |
---|
1120 | | -{ |
---|
1121 | | - struct tmio_mmc_host *host = mmc_priv(mmc); |
---|
1122 | | - |
---|
1123 | | - if (host->hs400_downgrade) |
---|
1124 | | - host->hs400_downgrade(host); |
---|
1125 | | -} |
---|
1126 | | - |
---|
1127 | | -static void tmio_mmc_hs400_complete(struct mmc_host *mmc) |
---|
1128 | | -{ |
---|
1129 | | - struct tmio_mmc_host *host = mmc_priv(mmc); |
---|
1130 | | - |
---|
1131 | | - if (host->hs400_complete) |
---|
1132 | | - host->hs400_complete(host); |
---|
1133 | | -} |
---|
1134 | | - |
---|
1135 | | -static const struct mmc_host_ops tmio_mmc_ops = { |
---|
| 987 | +static struct mmc_host_ops tmio_mmc_ops = { |
---|
1136 | 988 | .request = tmio_mmc_request, |
---|
1137 | 989 | .set_ios = tmio_mmc_set_ios, |
---|
1138 | 990 | .get_ro = tmio_mmc_get_ro, |
---|
1139 | 991 | .get_cd = tmio_mmc_get_cd, |
---|
1140 | 992 | .enable_sdio_irq = tmio_mmc_enable_sdio_irq, |
---|
1141 | 993 | .multi_io_quirk = tmio_multi_io_quirk, |
---|
1142 | | - .hw_reset = tmio_mmc_hw_reset, |
---|
1143 | | - .execute_tuning = tmio_mmc_execute_tuning, |
---|
1144 | | - .prepare_hs400_tuning = tmio_mmc_prepare_hs400_tuning, |
---|
1145 | | - .hs400_downgrade = tmio_mmc_hs400_downgrade, |
---|
1146 | | - .hs400_complete = tmio_mmc_hs400_complete, |
---|
1147 | 994 | }; |
---|
1148 | 995 | |
---|
1149 | 996 | static int tmio_mmc_init_ocr(struct tmio_mmc_host *host) |
---|
.. | .. |
---|
1158 | 1005 | |
---|
1159 | 1006 | /* use ocr_mask if no regulator */ |
---|
1160 | 1007 | if (!mmc->ocr_avail) |
---|
1161 | | - mmc->ocr_avail = pdata->ocr_mask; |
---|
| 1008 | + mmc->ocr_avail = pdata->ocr_mask; |
---|
1162 | 1009 | |
---|
1163 | 1010 | /* |
---|
1164 | 1011 | * try again. |
---|
.. | .. |
---|
1192 | 1039 | { |
---|
1193 | 1040 | struct tmio_mmc_host *host; |
---|
1194 | 1041 | struct mmc_host *mmc; |
---|
1195 | | - struct resource *res; |
---|
1196 | 1042 | void __iomem *ctl; |
---|
1197 | 1043 | int ret; |
---|
1198 | 1044 | |
---|
1199 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
1200 | | - ctl = devm_ioremap_resource(&pdev->dev, res); |
---|
| 1045 | + ctl = devm_platform_ioremap_resource(pdev, 0); |
---|
1201 | 1046 | if (IS_ERR(ctl)) |
---|
1202 | 1047 | return ERR_CAST(ctl); |
---|
1203 | 1048 | |
---|
.. | .. |
---|
1245 | 1090 | int ret; |
---|
1246 | 1091 | |
---|
1247 | 1092 | /* |
---|
1248 | | - * Check the sanity of mmc->f_min to prevent tmio_mmc_set_clock() from |
---|
| 1093 | + * Check the sanity of mmc->f_min to prevent host->set_clock() from |
---|
1249 | 1094 | * looping forever... |
---|
1250 | 1095 | */ |
---|
1251 | 1096 | if (mmc->f_min == 0) |
---|
.. | .. |
---|
1255 | 1100 | _host->write16_hook = NULL; |
---|
1256 | 1101 | |
---|
1257 | 1102 | _host->set_pwr = pdata->set_pwr; |
---|
1258 | | - _host->set_clk_div = pdata->set_clk_div; |
---|
1259 | 1103 | |
---|
1260 | 1104 | ret = tmio_mmc_init_ocr(_host); |
---|
1261 | 1105 | if (ret < 0) |
---|
1262 | 1106 | return ret; |
---|
1263 | 1107 | |
---|
1264 | | - if (pdata->flags & TMIO_MMC_USE_GPIO_CD) { |
---|
1265 | | - ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio, 0); |
---|
1266 | | - if (ret) |
---|
1267 | | - return ret; |
---|
1268 | | - } |
---|
| 1108 | + /* |
---|
| 1109 | + * Look for a card detect GPIO, if it fails with anything |
---|
| 1110 | + * else than a probe deferral, just live without it. |
---|
| 1111 | + */ |
---|
| 1112 | + ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0); |
---|
| 1113 | + if (ret == -EPROBE_DEFER) |
---|
| 1114 | + return ret; |
---|
1269 | 1115 | |
---|
1270 | | - mmc->caps |= MMC_CAP_ERASE | MMC_CAP_4_BIT_DATA | pdata->capabilities; |
---|
| 1116 | + mmc->caps |= MMC_CAP_4_BIT_DATA | pdata->capabilities; |
---|
1271 | 1117 | mmc->caps2 |= pdata->capabilities2; |
---|
1272 | 1118 | mmc->max_segs = pdata->max_segs ? : 32; |
---|
1273 | | - mmc->max_blk_size = 512; |
---|
| 1119 | + mmc->max_blk_size = TMIO_MAX_BLK_SIZE; |
---|
1274 | 1120 | mmc->max_blk_count = pdata->max_blk_count ? : |
---|
1275 | 1121 | (PAGE_SIZE / mmc->max_blk_size) * mmc->max_segs; |
---|
1276 | | - mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; |
---|
1277 | | - /* |
---|
1278 | | - * Since swiotlb has memory size limitation, this will calculate |
---|
1279 | | - * the maximum size locally (because we don't have any APIs for it now) |
---|
1280 | | - * and check the current max_req_size. And then, this will update |
---|
1281 | | - * the max_req_size if needed as a workaround. |
---|
1282 | | - */ |
---|
1283 | | - if (swiotlb_max_segment()) { |
---|
1284 | | - unsigned int max_size = (1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; |
---|
1285 | | - |
---|
1286 | | - if (mmc->max_req_size > max_size) |
---|
1287 | | - mmc->max_req_size = max_size; |
---|
1288 | | - } |
---|
| 1122 | + mmc->max_req_size = min_t(size_t, |
---|
| 1123 | + mmc->max_blk_size * mmc->max_blk_count, |
---|
| 1124 | + dma_max_mapping_size(&pdev->dev)); |
---|
1289 | 1125 | mmc->max_seg_size = mmc->max_req_size; |
---|
1290 | 1126 | |
---|
1291 | 1127 | if (mmc_can_gpio_ro(mmc)) |
---|
.. | .. |
---|
1318 | 1154 | if (pdata->flags & TMIO_MMC_SDIO_IRQ) |
---|
1319 | 1155 | _host->sdio_irq_mask = TMIO_SDIO_MASK_ALL; |
---|
1320 | 1156 | |
---|
1321 | | - tmio_mmc_clk_stop(_host); |
---|
| 1157 | + _host->set_clock(_host, 0); |
---|
1322 | 1158 | tmio_mmc_reset(_host); |
---|
1323 | 1159 | |
---|
1324 | 1160 | _host->sdcard_irq_mask = sd_ctrl_read16_and_16_as_32(_host, CTL_IRQ_MASK); |
---|
1325 | | - tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL); |
---|
| 1161 | + if (!_host->sdcard_irq_mask_all) |
---|
| 1162 | + _host->sdcard_irq_mask_all = TMIO_MASK_ALL; |
---|
| 1163 | + tmio_mmc_disable_mmc_irqs(_host, _host->sdcard_irq_mask_all); |
---|
1326 | 1164 | |
---|
1327 | 1165 | if (_host->native_hotplug) |
---|
1328 | 1166 | tmio_mmc_enable_mmc_irqs(_host, |
---|
.. | .. |
---|
1338 | 1176 | /* See if we also get DMA */ |
---|
1339 | 1177 | tmio_mmc_request_dma(_host, pdata); |
---|
1340 | 1178 | |
---|
| 1179 | + pm_runtime_get_noresume(&pdev->dev); |
---|
1341 | 1180 | pm_runtime_set_active(&pdev->dev); |
---|
1342 | 1181 | pm_runtime_set_autosuspend_delay(&pdev->dev, 50); |
---|
1343 | 1182 | pm_runtime_use_autosuspend(&pdev->dev); |
---|
.. | .. |
---|
1348 | 1187 | goto remove_host; |
---|
1349 | 1188 | |
---|
1350 | 1189 | dev_pm_qos_expose_latency_limit(&pdev->dev, 100); |
---|
| 1190 | + pm_runtime_put(&pdev->dev); |
---|
1351 | 1191 | |
---|
1352 | 1192 | return 0; |
---|
1353 | 1193 | |
---|
1354 | 1194 | remove_host: |
---|
| 1195 | + pm_runtime_put_noidle(&pdev->dev); |
---|
1355 | 1196 | tmio_mmc_host_remove(_host); |
---|
1356 | 1197 | return ret; |
---|
1357 | 1198 | } |
---|
.. | .. |
---|
1362 | 1203 | struct platform_device *pdev = host->pdev; |
---|
1363 | 1204 | struct mmc_host *mmc = host->mmc; |
---|
1364 | 1205 | |
---|
| 1206 | + pm_runtime_get_sync(&pdev->dev); |
---|
| 1207 | + |
---|
1365 | 1208 | if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) |
---|
1366 | 1209 | sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000); |
---|
1367 | | - |
---|
1368 | | - if (!host->native_hotplug) |
---|
1369 | | - pm_runtime_get_sync(&pdev->dev); |
---|
1370 | 1210 | |
---|
1371 | 1211 | dev_pm_qos_hide_latency_limit(&pdev->dev); |
---|
1372 | 1212 | |
---|
.. | .. |
---|
1374 | 1214 | cancel_work_sync(&host->done); |
---|
1375 | 1215 | cancel_delayed_work_sync(&host->delayed_reset_work); |
---|
1376 | 1216 | tmio_mmc_release_dma(host); |
---|
| 1217 | + tmio_mmc_disable_mmc_irqs(host, host->sdcard_irq_mask_all); |
---|
1377 | 1218 | |
---|
1378 | | - pm_runtime_put_sync(&pdev->dev); |
---|
| 1219 | + if (host->native_hotplug) |
---|
| 1220 | + pm_runtime_put_noidle(&pdev->dev); |
---|
| 1221 | + |
---|
1379 | 1222 | pm_runtime_disable(&pdev->dev); |
---|
| 1223 | + pm_runtime_dont_use_autosuspend(&pdev->dev); |
---|
| 1224 | + pm_runtime_put_noidle(&pdev->dev); |
---|
1380 | 1225 | } |
---|
1381 | 1226 | EXPORT_SYMBOL_GPL(tmio_mmc_host_remove); |
---|
1382 | 1227 | |
---|
.. | .. |
---|
1399 | 1244 | { |
---|
1400 | 1245 | struct tmio_mmc_host *host = dev_get_drvdata(dev); |
---|
1401 | 1246 | |
---|
1402 | | - tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL); |
---|
| 1247 | + tmio_mmc_disable_mmc_irqs(host, host->sdcard_irq_mask_all); |
---|
1403 | 1248 | |
---|
1404 | 1249 | if (host->clk_cache) |
---|
1405 | | - tmio_mmc_clk_stop(host); |
---|
| 1250 | + host->set_clock(host, 0); |
---|
1406 | 1251 | |
---|
1407 | 1252 | tmio_mmc_clk_disable(host); |
---|
1408 | 1253 | |
---|
.. | .. |
---|
1410 | 1255 | } |
---|
1411 | 1256 | EXPORT_SYMBOL_GPL(tmio_mmc_host_runtime_suspend); |
---|
1412 | 1257 | |
---|
1413 | | -static bool tmio_mmc_can_retune(struct tmio_mmc_host *host) |
---|
1414 | | -{ |
---|
1415 | | - return host->tap_num && mmc_can_retune(host->mmc); |
---|
1416 | | -} |
---|
1417 | | - |
---|
1418 | 1258 | int tmio_mmc_host_runtime_resume(struct device *dev) |
---|
1419 | 1259 | { |
---|
1420 | 1260 | struct tmio_mmc_host *host = dev_get_drvdata(dev); |
---|
1421 | 1261 | |
---|
1422 | | - tmio_mmc_reset(host); |
---|
1423 | 1262 | tmio_mmc_clk_enable(host); |
---|
| 1263 | + tmio_mmc_reset(host); |
---|
1424 | 1264 | |
---|
1425 | 1265 | if (host->clk_cache) |
---|
1426 | | - tmio_mmc_set_clock(host, host->clk_cache); |
---|
| 1266 | + host->set_clock(host, host->clk_cache); |
---|
1427 | 1267 | |
---|
1428 | 1268 | if (host->native_hotplug) |
---|
1429 | 1269 | tmio_mmc_enable_mmc_irqs(host, |
---|
.. | .. |
---|
1431 | 1271 | |
---|
1432 | 1272 | tmio_mmc_enable_dma(host, true); |
---|
1433 | 1273 | |
---|
1434 | | - if (tmio_mmc_can_retune(host) && host->select_tuning(host)) |
---|
1435 | | - dev_warn(&host->pdev->dev, "Tuning selection failed\n"); |
---|
| 1274 | + mmc_retune_needed(host->mmc); |
---|
1436 | 1275 | |
---|
1437 | 1276 | return 0; |
---|
1438 | 1277 | } |
---|