1f707079dSWolfram Sang // SPDX-License-Identifier: GPL-2.0
22a68ea78SSimon Horman /*
32a68ea78SSimon Horman  * DMA support for Internal DMAC with SDHI SD/SDIO controller
42a68ea78SSimon Horman  *
52a68ea78SSimon Horman  * Copyright (C) 2016-17 Renesas Electronics Corporation
62a68ea78SSimon Horman  * Copyright (C) 2016-17 Horms Solutions, Simon Horman
72a68ea78SSimon Horman  */
82a68ea78SSimon Horman 
90cbc94daSWolfram Sang #include <linux/bitops.h>
102a68ea78SSimon Horman #include <linux/device.h>
112a68ea78SSimon Horman #include <linux/dma-mapping.h>
122a68ea78SSimon Horman #include <linux/io-64-nonatomic-hi-lo.h>
132a68ea78SSimon Horman #include <linux/mfd/tmio.h>
142a68ea78SSimon Horman #include <linux/mmc/host.h>
152a68ea78SSimon Horman #include <linux/mod_devicetable.h>
162a68ea78SSimon Horman #include <linux/module.h>
172a68ea78SSimon Horman #include <linux/pagemap.h>
182a68ea78SSimon Horman #include <linux/scatterlist.h>
19cd09780fSSimon Horman #include <linux/sys_soc.h>
202a68ea78SSimon Horman 
212a68ea78SSimon Horman #include "renesas_sdhi.h"
222a68ea78SSimon Horman #include "tmio_mmc.h"
232a68ea78SSimon Horman 
242a68ea78SSimon Horman #define DM_CM_DTRAN_MODE	0x820
252a68ea78SSimon Horman #define DM_CM_DTRAN_CTRL	0x828
262a68ea78SSimon Horman #define DM_CM_RST		0x830
272a68ea78SSimon Horman #define DM_CM_INFO1		0x840
282a68ea78SSimon Horman #define DM_CM_INFO1_MASK	0x848
292a68ea78SSimon Horman #define DM_CM_INFO2		0x850
302a68ea78SSimon Horman #define DM_CM_INFO2_MASK	0x858
312a68ea78SSimon Horman #define DM_DTRAN_ADDR		0x880
322a68ea78SSimon Horman 
332a68ea78SSimon Horman /* DM_CM_DTRAN_MODE */
342a68ea78SSimon Horman #define DTRAN_MODE_CH_NUM_CH0	0	/* "downstream" = for write commands */
35c1ec8f86SSergei Shtylyov #define DTRAN_MODE_CH_NUM_CH1	BIT(16)	/* "upstream" = for read commands */
36c1ec8f86SSergei Shtylyov #define DTRAN_MODE_BUS_WIDTH	(BIT(5) | BIT(4))
372a68ea78SSimon Horman #define DTRAN_MODE_ADDR_MODE	BIT(0)	/* 1 = Increment address */
382a68ea78SSimon Horman 
392a68ea78SSimon Horman /* DM_CM_DTRAN_CTRL */
402a68ea78SSimon Horman #define DTRAN_CTRL_DM_START	BIT(0)
412a68ea78SSimon Horman 
422a68ea78SSimon Horman /* DM_CM_RST */
432a68ea78SSimon Horman #define RST_DTRANRST1		BIT(9)
442a68ea78SSimon Horman #define RST_DTRANRST0		BIT(8)
459faf870eSSergei Shtylyov #define RST_RESERVED_BITS	GENMASK_ULL(31, 0)
462a68ea78SSimon Horman 
472a68ea78SSimon Horman /* DM_CM_INFO1 and DM_CM_INFO1_MASK */
482a68ea78SSimon Horman #define INFO1_CLEAR		0
49d2332f88SSergei Shtylyov #define INFO1_MASK_CLEAR	GENMASK_ULL(31, 0)
502a68ea78SSimon Horman #define INFO1_DTRANEND1		BIT(17)
512a68ea78SSimon Horman #define INFO1_DTRANEND0		BIT(16)
522a68ea78SSimon Horman 
532a68ea78SSimon Horman /* DM_CM_INFO2 and DM_CM_INFO2_MASK */
54d2332f88SSergei Shtylyov #define INFO2_MASK_CLEAR	GENMASK_ULL(31, 0)
552a68ea78SSimon Horman #define INFO2_DTRANERR1		BIT(17)
562a68ea78SSimon Horman #define INFO2_DTRANERR0		BIT(16)
572a68ea78SSimon Horman 
582a68ea78SSimon Horman /*
592a68ea78SSimon Horman  * Specification of this driver:
602a68ea78SSimon Horman  * - host->chan_{rx,tx} will be used as a flag of enabling/disabling the dma
612a68ea78SSimon Horman  * - Since this SDHI DMAC register set has 16 but 32-bit width, we
622a68ea78SSimon Horman  *   need a custom accessor.
632a68ea78SSimon Horman  */
642a68ea78SSimon Horman 
650cbc94daSWolfram Sang static unsigned long global_flags;
660cbc94daSWolfram Sang /*
670cbc94daSWolfram Sang  * Workaround for avoiding to use RX DMAC by multiple channels.
680cbc94daSWolfram Sang  * On R-Car H3 ES1.* and M3-W ES1.0, when multiple SDHI channels use
690cbc94daSWolfram Sang  * RX DMAC simultaneously, sometimes hundreds of bytes data are not
700cbc94daSWolfram Sang  * stored into the system memory even if the DMAC interrupt happened.
710cbc94daSWolfram Sang  * So, this driver then uses one RX DMAC channel only.
720cbc94daSWolfram Sang  */
730cbc94daSWolfram Sang #define SDHI_INTERNAL_DMAC_ONE_RX_ONLY	0
740cbc94daSWolfram Sang #define SDHI_INTERNAL_DMAC_RX_IN_USE	1
750cbc94daSWolfram Sang 
762a68ea78SSimon Horman /* Definitions for sampling clocks */
772a68ea78SSimon Horman static struct renesas_sdhi_scc rcar_gen3_scc_taps[] = {
782a68ea78SSimon Horman 	{
792a68ea78SSimon Horman 		.clk_rate = 0,
802a68ea78SSimon Horman 		.tap = 0x00000300,
812a68ea78SSimon Horman 	},
822a68ea78SSimon Horman };
832a68ea78SSimon Horman 
8426eb2607SMasaharu Hayakawa static const struct renesas_sdhi_of_data of_rcar_r8a7795_compatible = {
8526eb2607SMasaharu Hayakawa 	.tmio_flags	= TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_CLK_ACTUAL |
8626eb2607SMasaharu Hayakawa 			  TMIO_MMC_HAVE_CBSY | TMIO_MMC_MIN_RCAR2 |
8726eb2607SMasaharu Hayakawa 			  TMIO_MMC_HAVE_4TAP_HS400,
8826eb2607SMasaharu Hayakawa 	.capabilities	= MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
8926eb2607SMasaharu Hayakawa 			  MMC_CAP_CMD23,
9026eb2607SMasaharu Hayakawa 	.capabilities2	= MMC_CAP2_NO_WRITE_PROTECT,
9126eb2607SMasaharu Hayakawa 	.bus_shift	= 2,
9226eb2607SMasaharu Hayakawa 	.scc_offset	= 0x1000,
9326eb2607SMasaharu Hayakawa 	.taps		= rcar_gen3_scc_taps,
9426eb2607SMasaharu Hayakawa 	.taps_num	= ARRAY_SIZE(rcar_gen3_scc_taps),
9526eb2607SMasaharu Hayakawa 	/* DMAC can handle 0xffffffff blk count but only 1 segment */
9626eb2607SMasaharu Hayakawa 	.max_blk_count	= 0xffffffff,
9726eb2607SMasaharu Hayakawa 	.max_segs	= 1,
9826eb2607SMasaharu Hayakawa };
9926eb2607SMasaharu Hayakawa 
1002a68ea78SSimon Horman static const struct renesas_sdhi_of_data of_rcar_gen3_compatible = {
1012ad1db05SMasahiro Yamada 	.tmio_flags	= TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_CLK_ACTUAL |
1022ad1db05SMasahiro Yamada 			  TMIO_MMC_HAVE_CBSY | TMIO_MMC_MIN_RCAR2,
1032a68ea78SSimon Horman 	.capabilities	= MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1042a68ea78SSimon Horman 			  MMC_CAP_CMD23,
105ef5332c1SWolfram Sang 	.capabilities2	= MMC_CAP2_NO_WRITE_PROTECT,
1062a68ea78SSimon Horman 	.bus_shift	= 2,
1072a68ea78SSimon Horman 	.scc_offset	= 0x1000,
1082a68ea78SSimon Horman 	.taps		= rcar_gen3_scc_taps,
1092a68ea78SSimon Horman 	.taps_num	= ARRAY_SIZE(rcar_gen3_scc_taps),
110ebca50dfSWolfram Sang 	/* DMAC can handle 0xffffffff blk count but only 1 segment */
1112a68ea78SSimon Horman 	.max_blk_count	= 0xffffffff,
1122a68ea78SSimon Horman 	.max_segs	= 1,
1132a68ea78SSimon Horman };
1142a68ea78SSimon Horman 
1152a68ea78SSimon Horman static const struct of_device_id renesas_sdhi_internal_dmac_of_match[] = {
11660ab43baSFabrizio Castro 	{ .compatible = "renesas,sdhi-mmc-r8a77470", .data = &of_rcar_gen3_compatible, },
11726eb2607SMasaharu Hayakawa 	{ .compatible = "renesas,sdhi-r8a7795", .data = &of_rcar_r8a7795_compatible, },
11826eb2607SMasaharu Hayakawa 	{ .compatible = "renesas,sdhi-r8a7796", .data = &of_rcar_r8a7795_compatible, },
119d6dc425aSSimon Horman 	{ .compatible = "renesas,rcar-gen3-sdhi", .data = &of_rcar_gen3_compatible, },
1202a68ea78SSimon Horman 	{},
1212a68ea78SSimon Horman };
1222a68ea78SSimon Horman MODULE_DEVICE_TABLE(of, renesas_sdhi_internal_dmac_of_match);
1232a68ea78SSimon Horman 
1242a68ea78SSimon Horman static void
1252a68ea78SSimon Horman renesas_sdhi_internal_dmac_dm_write(struct tmio_mmc_host *host,
1262a68ea78SSimon Horman 				    int addr, u64 val)
1272a68ea78SSimon Horman {
1282a68ea78SSimon Horman 	writeq(val, host->ctl + addr);
1292a68ea78SSimon Horman }
1302a68ea78SSimon Horman 
1312a68ea78SSimon Horman static void
1322a68ea78SSimon Horman renesas_sdhi_internal_dmac_enable_dma(struct tmio_mmc_host *host, bool enable)
1332a68ea78SSimon Horman {
134058db286SMasahiro Yamada 	struct renesas_sdhi *priv = host_to_priv(host);
135058db286SMasahiro Yamada 
1362a68ea78SSimon Horman 	if (!host->chan_tx || !host->chan_rx)
1372a68ea78SSimon Horman 		return;
1382a68ea78SSimon Horman 
1392a68ea78SSimon Horman 	if (!enable)
1402a68ea78SSimon Horman 		renesas_sdhi_internal_dmac_dm_write(host, DM_CM_INFO1,
1412a68ea78SSimon Horman 						    INFO1_CLEAR);
1422a68ea78SSimon Horman 
143058db286SMasahiro Yamada 	if (priv->dma_priv.enable)
144058db286SMasahiro Yamada 		priv->dma_priv.enable(host, enable);
1452a68ea78SSimon Horman }
1462a68ea78SSimon Horman 
1472a68ea78SSimon Horman static void
1482a68ea78SSimon Horman renesas_sdhi_internal_dmac_abort_dma(struct tmio_mmc_host *host) {
1492a68ea78SSimon Horman 	u64 val = RST_DTRANRST1 | RST_DTRANRST0;
1502a68ea78SSimon Horman 
1512a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_enable_dma(host, false);
1522a68ea78SSimon Horman 
1532a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_dm_write(host, DM_CM_RST,
1542a68ea78SSimon Horman 					    RST_RESERVED_BITS & ~val);
1552a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_dm_write(host, DM_CM_RST,
1562a68ea78SSimon Horman 					    RST_RESERVED_BITS | val);
1572a68ea78SSimon Horman 
1580cbc94daSWolfram Sang 	clear_bit(SDHI_INTERNAL_DMAC_RX_IN_USE, &global_flags);
1590cbc94daSWolfram Sang 
1602a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_enable_dma(host, true);
1612a68ea78SSimon Horman }
1622a68ea78SSimon Horman 
1632a68ea78SSimon Horman static void
1642a68ea78SSimon Horman renesas_sdhi_internal_dmac_dataend_dma(struct tmio_mmc_host *host) {
16590d95106SMasahiro Yamada 	struct renesas_sdhi *priv = host_to_priv(host);
16690d95106SMasahiro Yamada 
16790d95106SMasahiro Yamada 	tasklet_schedule(&priv->dma_priv.dma_complete);
1682a68ea78SSimon Horman }
1692a68ea78SSimon Horman 
1702a68ea78SSimon Horman static void
1712a68ea78SSimon Horman renesas_sdhi_internal_dmac_start_dma(struct tmio_mmc_host *host,
1722a68ea78SSimon Horman 				     struct mmc_data *data)
1732a68ea78SSimon Horman {
1742a68ea78SSimon Horman 	struct scatterlist *sg = host->sg_ptr;
175c1ec8f86SSergei Shtylyov 	u32 dtran_mode = DTRAN_MODE_BUS_WIDTH | DTRAN_MODE_ADDR_MODE;
1762a68ea78SSimon Horman 
177ae275b9dSMasaharu Hayakawa 	if (!dma_map_sg(&host->pdev->dev, sg, host->sg_len,
178ae275b9dSMasaharu Hayakawa 			mmc_get_dma_dir(data)))
17948e1dc10SYoshihiro Shimoda 		goto force_pio;
1802a68ea78SSimon Horman 
181ae275b9dSMasaharu Hayakawa 	/* This DMAC cannot handle if buffer is not 8-bytes alignment */
182fe6e0494SYoshihiro Shimoda 	if (!IS_ALIGNED(sg_dma_address(sg), 8))
183fe6e0494SYoshihiro Shimoda 		goto force_pio_with_unmap;
184ae275b9dSMasaharu Hayakawa 
1852a68ea78SSimon Horman 	if (data->flags & MMC_DATA_READ) {
1862a68ea78SSimon Horman 		dtran_mode |= DTRAN_MODE_CH_NUM_CH1;
1870cbc94daSWolfram Sang 		if (test_bit(SDHI_INTERNAL_DMAC_ONE_RX_ONLY, &global_flags) &&
1880cbc94daSWolfram Sang 		    test_and_set_bit(SDHI_INTERNAL_DMAC_RX_IN_USE, &global_flags))
189fe6e0494SYoshihiro Shimoda 			goto force_pio_with_unmap;
1902a68ea78SSimon Horman 	} else {
1912a68ea78SSimon Horman 		dtran_mode |= DTRAN_MODE_CH_NUM_CH0;
1922a68ea78SSimon Horman 	}
1932a68ea78SSimon Horman 
1942a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_enable_dma(host, true);
1952a68ea78SSimon Horman 
1962a68ea78SSimon Horman 	/* set dma parameters */
1972a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_dm_write(host, DM_CM_DTRAN_MODE,
1982a68ea78SSimon Horman 					    dtran_mode);
1992a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_dm_write(host, DM_DTRAN_ADDR,
200a028b435SNiklas Söderlund 					    sg_dma_address(sg));
20148e1dc10SYoshihiro Shimoda 
20248e1dc10SYoshihiro Shimoda 	return;
20348e1dc10SYoshihiro Shimoda 
204fe6e0494SYoshihiro Shimoda force_pio_with_unmap:
205fe6e0494SYoshihiro Shimoda 	dma_unmap_sg(&host->pdev->dev, sg, host->sg_len, mmc_get_dma_dir(data));
206fe6e0494SYoshihiro Shimoda 
20748e1dc10SYoshihiro Shimoda force_pio:
20848e1dc10SYoshihiro Shimoda 	host->force_pio = true;
20948e1dc10SYoshihiro Shimoda 	renesas_sdhi_internal_dmac_enable_dma(host, false);
2102a68ea78SSimon Horman }
2112a68ea78SSimon Horman 
2122a68ea78SSimon Horman static void renesas_sdhi_internal_dmac_issue_tasklet_fn(unsigned long arg)
2132a68ea78SSimon Horman {
2142a68ea78SSimon Horman 	struct tmio_mmc_host *host = (struct tmio_mmc_host *)arg;
2152a68ea78SSimon Horman 
2162a68ea78SSimon Horman 	tmio_mmc_enable_mmc_irqs(host, TMIO_STAT_DATAEND);
2172a68ea78SSimon Horman 
2182a68ea78SSimon Horman 	/* start the DMAC */
2192a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_dm_write(host, DM_CM_DTRAN_CTRL,
2202a68ea78SSimon Horman 					    DTRAN_CTRL_DM_START);
2212a68ea78SSimon Horman }
2222a68ea78SSimon Horman 
2232a68ea78SSimon Horman static void renesas_sdhi_internal_dmac_complete_tasklet_fn(unsigned long arg)
2242a68ea78SSimon Horman {
2252a68ea78SSimon Horman 	struct tmio_mmc_host *host = (struct tmio_mmc_host *)arg;
2262a68ea78SSimon Horman 	enum dma_data_direction dir;
2272a68ea78SSimon Horman 
2282a68ea78SSimon Horman 	spin_lock_irq(&host->lock);
2292a68ea78SSimon Horman 
2302a68ea78SSimon Horman 	if (!host->data)
2312a68ea78SSimon Horman 		goto out;
2322a68ea78SSimon Horman 
2332a68ea78SSimon Horman 	if (host->data->flags & MMC_DATA_READ)
2342a68ea78SSimon Horman 		dir = DMA_FROM_DEVICE;
2352a68ea78SSimon Horman 	else
2362a68ea78SSimon Horman 		dir = DMA_TO_DEVICE;
2372a68ea78SSimon Horman 
2382a68ea78SSimon Horman 	renesas_sdhi_internal_dmac_enable_dma(host, false);
2392a68ea78SSimon Horman 	dma_unmap_sg(&host->pdev->dev, host->sg_ptr, host->sg_len, dir);
2402a68ea78SSimon Horman 
2410cbc94daSWolfram Sang 	if (dir == DMA_FROM_DEVICE)
2420cbc94daSWolfram Sang 		clear_bit(SDHI_INTERNAL_DMAC_RX_IN_USE, &global_flags);
2430cbc94daSWolfram Sang 
2442a68ea78SSimon Horman 	tmio_mmc_do_data_irq(host);
2452a68ea78SSimon Horman out:
2462a68ea78SSimon Horman 	spin_unlock_irq(&host->lock);
2472a68ea78SSimon Horman }
2482a68ea78SSimon Horman 
2492a68ea78SSimon Horman static void
2502a68ea78SSimon Horman renesas_sdhi_internal_dmac_request_dma(struct tmio_mmc_host *host,
2512a68ea78SSimon Horman 				       struct tmio_mmc_data *pdata)
2522a68ea78SSimon Horman {
25390d95106SMasahiro Yamada 	struct renesas_sdhi *priv = host_to_priv(host);
25490d95106SMasahiro Yamada 
255d2332f88SSergei Shtylyov 	/* Disable DMAC interrupts, we don't use them */
256d2332f88SSergei Shtylyov 	renesas_sdhi_internal_dmac_dm_write(host, DM_CM_INFO1_MASK,
257d2332f88SSergei Shtylyov 					    INFO1_MASK_CLEAR);
258d2332f88SSergei Shtylyov 	renesas_sdhi_internal_dmac_dm_write(host, DM_CM_INFO2_MASK,
259d2332f88SSergei Shtylyov 					    INFO2_MASK_CLEAR);
260d2332f88SSergei Shtylyov 
2612a68ea78SSimon Horman 	/* Each value is set to non-zero to assume "enabling" each DMA */
2622a68ea78SSimon Horman 	host->chan_rx = host->chan_tx = (void *)0xdeadbeaf;
2632a68ea78SSimon Horman 
26490d95106SMasahiro Yamada 	tasklet_init(&priv->dma_priv.dma_complete,
2652a68ea78SSimon Horman 		     renesas_sdhi_internal_dmac_complete_tasklet_fn,
2662a68ea78SSimon Horman 		     (unsigned long)host);
2672a68ea78SSimon Horman 	tasklet_init(&host->dma_issue,
2682a68ea78SSimon Horman 		     renesas_sdhi_internal_dmac_issue_tasklet_fn,
2692a68ea78SSimon Horman 		     (unsigned long)host);
2702a68ea78SSimon Horman }
2712a68ea78SSimon Horman 
2722a68ea78SSimon Horman static void
2732a68ea78SSimon Horman renesas_sdhi_internal_dmac_release_dma(struct tmio_mmc_host *host)
2742a68ea78SSimon Horman {
2752a68ea78SSimon Horman 	/* Each value is set to zero to assume "disabling" each DMA */
2762a68ea78SSimon Horman 	host->chan_rx = host->chan_tx = NULL;
2772a68ea78SSimon Horman }
2782a68ea78SSimon Horman 
27910154068SJulia Lawall static const struct tmio_mmc_dma_ops renesas_sdhi_internal_dmac_dma_ops = {
2802a68ea78SSimon Horman 	.start = renesas_sdhi_internal_dmac_start_dma,
2812a68ea78SSimon Horman 	.enable = renesas_sdhi_internal_dmac_enable_dma,
2822a68ea78SSimon Horman 	.request = renesas_sdhi_internal_dmac_request_dma,
2832a68ea78SSimon Horman 	.release = renesas_sdhi_internal_dmac_release_dma,
2842a68ea78SSimon Horman 	.abort = renesas_sdhi_internal_dmac_abort_dma,
2852a68ea78SSimon Horman 	.dataend = renesas_sdhi_internal_dmac_dataend_dma,
2862a68ea78SSimon Horman };
2872a68ea78SSimon Horman 
288cd09780fSSimon Horman /*
289cd09780fSSimon Horman  * Whitelist of specific R-Car Gen3 SoC ES versions to use this DMAC
290cd09780fSSimon Horman  * implementation as others may use a different implementation.
291cd09780fSSimon Horman  */
29260ab43baSFabrizio Castro static const struct soc_device_attribute soc_whitelist[] = {
2931abf9e52SWolfram Sang 	/* specific ones */
2940cbc94daSWolfram Sang 	{ .soc_id = "r8a7795", .revision = "ES1.*",
2950cbc94daSWolfram Sang 	  .data = (void *)BIT(SDHI_INTERNAL_DMAC_ONE_RX_ONLY) },
2960cbc94daSWolfram Sang 	{ .soc_id = "r8a7796", .revision = "ES1.0",
2970cbc94daSWolfram Sang 	  .data = (void *)BIT(SDHI_INTERNAL_DMAC_ONE_RX_ONLY) },
2981abf9e52SWolfram Sang 	/* generic ones */
2992e1501a8SFabrizio Castro 	{ .soc_id = "r8a774a1" },
30060ab43baSFabrizio Castro 	{ .soc_id = "r8a77470" },
3011abf9e52SWolfram Sang 	{ .soc_id = "r8a7795" },
3021abf9e52SWolfram Sang 	{ .soc_id = "r8a7796" },
303caeffcf1SMasaharu Hayakawa 	{ .soc_id = "r8a77965" },
30416a129b3SSergei Shtylyov 	{ .soc_id = "r8a77970" },
305e419768fSSergei Shtylyov 	{ .soc_id = "r8a77980" },
3061abf9e52SWolfram Sang 	{ .soc_id = "r8a77995" },
307cd09780fSSimon Horman 	{ /* sentinel */ }
308cd09780fSSimon Horman };
309cd09780fSSimon Horman 
3102a68ea78SSimon Horman static int renesas_sdhi_internal_dmac_probe(struct platform_device *pdev)
3112a68ea78SSimon Horman {
31260ab43baSFabrizio Castro 	const struct soc_device_attribute *soc = soc_device_match(soc_whitelist);
31354541815SNiklas Söderlund 	struct device *dev = &pdev->dev;
3140cbc94daSWolfram Sang 
3150cbc94daSWolfram Sang 	if (!soc)
316cd09780fSSimon Horman 		return -ENODEV;
317cd09780fSSimon Horman 
3180cbc94daSWolfram Sang 	global_flags |= (unsigned long)soc->data;
3190cbc94daSWolfram Sang 
32054541815SNiklas Söderlund 	dev->dma_parms = devm_kzalloc(dev, sizeof(*dev->dma_parms), GFP_KERNEL);
32154541815SNiklas Söderlund 	if (!dev->dma_parms)
32254541815SNiklas Söderlund 		return -ENOMEM;
32354541815SNiklas Söderlund 
32454541815SNiklas Söderlund 	/* value is max of SD_SECCNT. Confirmed by HW engineers */
32554541815SNiklas Söderlund 	dma_set_max_seg_size(dev, 0xffffffff);
32654541815SNiklas Söderlund 
3272a68ea78SSimon Horman 	return renesas_sdhi_probe(pdev, &renesas_sdhi_internal_dmac_dma_ops);
3282a68ea78SSimon Horman }
3292a68ea78SSimon Horman 
3302a68ea78SSimon Horman static const struct dev_pm_ops renesas_sdhi_internal_dmac_dev_pm_ops = {
3312a68ea78SSimon Horman 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
3322a68ea78SSimon Horman 				pm_runtime_force_resume)
3332a68ea78SSimon Horman 	SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
3342a68ea78SSimon Horman 			   tmio_mmc_host_runtime_resume,
3352a68ea78SSimon Horman 			   NULL)
3362a68ea78SSimon Horman };
3372a68ea78SSimon Horman 
3382a68ea78SSimon Horman static struct platform_driver renesas_internal_dmac_sdhi_driver = {
3392a68ea78SSimon Horman 	.driver		= {
3402a68ea78SSimon Horman 		.name	= "renesas_sdhi_internal_dmac",
3412a68ea78SSimon Horman 		.pm	= &renesas_sdhi_internal_dmac_dev_pm_ops,
3422a68ea78SSimon Horman 		.of_match_table = renesas_sdhi_internal_dmac_of_match,
3432a68ea78SSimon Horman 	},
3442a68ea78SSimon Horman 	.probe		= renesas_sdhi_internal_dmac_probe,
3452a68ea78SSimon Horman 	.remove		= renesas_sdhi_remove,
3462a68ea78SSimon Horman };
3472a68ea78SSimon Horman 
3482a68ea78SSimon Horman module_platform_driver(renesas_internal_dmac_sdhi_driver);
3492a68ea78SSimon Horman 
3502a68ea78SSimon Horman MODULE_DESCRIPTION("Renesas SDHI driver for internal DMAC");
3512a68ea78SSimon Horman MODULE_AUTHOR("Yoshihiro Shimoda");
3522a68ea78SSimon Horman MODULE_LICENSE("GPL v2");
353