|
9 | 9 | * published by the Free Software Foundation.
|
10 | 10 | */
|
11 | 11 |
|
| 12 | +#include <linux/bitops.h> |
12 | 13 | #include <linux/device.h>
|
13 | 14 | #include <linux/dma-mapping.h>
|
14 | 15 | #include <linux/io-64-nonatomic-hi-lo.h>
|
|
62 | 63 | * need a custom accessor.
|
63 | 64 | */
|
64 | 65 |
|
| 66 | +static unsigned long global_flags; |
| 67 | +/* |
| 68 | + * Workaround for avoiding to use RX DMAC by multiple channels. |
| 69 | + * On R-Car H3 ES1.* and M3-W ES1.0, when multiple SDHI channels use |
| 70 | + * RX DMAC simultaneously, sometimes hundreds of bytes data are not |
| 71 | + * stored into the system memory even if the DMAC interrupt happened. |
| 72 | + * So, this driver then uses one RX DMAC channel only. |
| 73 | + */ |
| 74 | +#define SDHI_INTERNAL_DMAC_ONE_RX_ONLY 0 |
| 75 | +#define SDHI_INTERNAL_DMAC_RX_IN_USE 1 |
| 76 | + |
65 | 77 | /* Definitions for sampling clocks */
|
66 | 78 | static struct renesas_sdhi_scc rcar_gen3_scc_taps[] = {
|
67 | 79 | {
|
@@ -126,6 +138,9 @@ renesas_sdhi_internal_dmac_abort_dma(struct tmio_mmc_host *host) {
|
126 | 138 | renesas_sdhi_internal_dmac_dm_write(host, DM_CM_RST,
|
127 | 139 | RST_RESERVED_BITS | val);
|
128 | 140 |
|
| 141 | + if (host->data && host->data->flags & MMC_DATA_READ) |
| 142 | + clear_bit(SDHI_INTERNAL_DMAC_RX_IN_USE, &global_flags); |
| 143 | + |
129 | 144 | renesas_sdhi_internal_dmac_enable_dma(host, true);
|
130 | 145 | }
|
131 | 146 |
|
@@ -155,6 +170,9 @@ renesas_sdhi_internal_dmac_start_dma(struct tmio_mmc_host *host,
|
155 | 170 | if (data->flags & MMC_DATA_READ) {
|
156 | 171 | dtran_mode |= DTRAN_MODE_CH_NUM_CH1;
|
157 | 172 | dir = DMA_FROM_DEVICE;
|
| 173 | + if (test_bit(SDHI_INTERNAL_DMAC_ONE_RX_ONLY, &global_flags) && |
| 174 | + test_and_set_bit(SDHI_INTERNAL_DMAC_RX_IN_USE, &global_flags)) |
| 175 | + goto force_pio; |
158 | 176 | } else {
|
159 | 177 | dtran_mode |= DTRAN_MODE_CH_NUM_CH0;
|
160 | 178 | dir = DMA_TO_DEVICE;
|
@@ -208,6 +226,9 @@ static void renesas_sdhi_internal_dmac_complete_tasklet_fn(unsigned long arg)
|
208 | 226 | renesas_sdhi_internal_dmac_enable_dma(host, false);
|
209 | 227 | dma_unmap_sg(&host->pdev->dev, host->sg_ptr, host->sg_len, dir);
|
210 | 228 |
|
| 229 | + if (dir == DMA_FROM_DEVICE) |
| 230 | + clear_bit(SDHI_INTERNAL_DMAC_RX_IN_USE, &global_flags); |
| 231 | + |
211 | 232 | tmio_mmc_do_data_irq(host);
|
212 | 233 | out:
|
213 | 234 | spin_unlock_irq(&host->lock);
|
@@ -251,18 +272,24 @@ static const struct tmio_mmc_dma_ops renesas_sdhi_internal_dmac_dma_ops = {
|
251 | 272 | * implementation as others may use a different implementation.
|
252 | 273 | */
|
253 | 274 | static const struct soc_device_attribute gen3_soc_whitelist[] = {
|
254 |
| - { .soc_id = "r8a7795", .revision = "ES1.*" }, |
255 |
| - { .soc_id = "r8a7795", .revision = "ES2.0" }, |
256 |
| - { .soc_id = "r8a7796", .revision = "ES1.0" }, |
257 |
| - { .soc_id = "r8a77995", .revision = "ES1.0" }, |
258 |
| - { /* sentinel */ } |
| 275 | + { .soc_id = "r8a7795", .revision = "ES1.*", |
| 276 | + .data = (void *)BIT(SDHI_INTERNAL_DMAC_ONE_RX_ONLY) }, |
| 277 | + { .soc_id = "r8a7795", .revision = "ES2.0" }, |
| 278 | + { .soc_id = "r8a7796", .revision = "ES1.0", |
| 279 | + .data = (void *)BIT(SDHI_INTERNAL_DMAC_ONE_RX_ONLY) }, |
| 280 | + { .soc_id = "r8a77995", .revision = "ES1.0" }, |
| 281 | + { /* sentinel */ } |
259 | 282 | };
|
260 | 283 |
|
261 | 284 | static int renesas_sdhi_internal_dmac_probe(struct platform_device *pdev)
|
262 | 285 | {
|
263 |
| - if (!soc_device_match(gen3_soc_whitelist)) |
| 286 | + const struct soc_device_attribute *soc = soc_device_match(gen3_soc_whitelist); |
| 287 | + |
| 288 | + if (!soc) |
264 | 289 | return -ENODEV;
|
265 | 290 |
|
| 291 | + global_flags |= (unsigned long)soc->data; |
| 292 | + |
266 | 293 | return renesas_sdhi_probe(pdev, &renesas_sdhi_internal_dmac_dma_ops);
|
267 | 294 | }
|
268 | 295 |
|
|
0 commit comments