xref: /OK3568_Linux_fs/kernel/drivers/dma/sh/shdma-of.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * SHDMA Device Tree glue
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2013 Renesas Electronics Inc.
6*4882a593Smuzhiyun  * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/dmaengine.h>
10*4882a593Smuzhiyun #include <linux/module.h>
11*4882a593Smuzhiyun #include <linux/of.h>
12*4882a593Smuzhiyun #include <linux/of_dma.h>
13*4882a593Smuzhiyun #include <linux/of_platform.h>
14*4882a593Smuzhiyun #include <linux/platform_device.h>
15*4882a593Smuzhiyun #include <linux/shdma-base.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
18*4882a593Smuzhiyun 
shdma_of_xlate(struct of_phandle_args * dma_spec,struct of_dma * ofdma)19*4882a593Smuzhiyun static struct dma_chan *shdma_of_xlate(struct of_phandle_args *dma_spec,
20*4882a593Smuzhiyun 				       struct of_dma *ofdma)
21*4882a593Smuzhiyun {
22*4882a593Smuzhiyun 	u32 id = dma_spec->args[0];
23*4882a593Smuzhiyun 	dma_cap_mask_t mask;
24*4882a593Smuzhiyun 	struct dma_chan *chan;
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun 	if (dma_spec->args_count != 1)
27*4882a593Smuzhiyun 		return NULL;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	dma_cap_zero(mask);
30*4882a593Smuzhiyun 	/* Only slave DMA channels can be allocated via DT */
31*4882a593Smuzhiyun 	dma_cap_set(DMA_SLAVE, mask);
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	chan = dma_request_channel(mask, shdma_chan_filter,
34*4882a593Smuzhiyun 				   (void *)(uintptr_t)id);
35*4882a593Smuzhiyun 	if (chan)
36*4882a593Smuzhiyun 		to_shdma_chan(chan)->hw_req = id;
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 	return chan;
39*4882a593Smuzhiyun }
40*4882a593Smuzhiyun 
shdma_of_probe(struct platform_device * pdev)41*4882a593Smuzhiyun static int shdma_of_probe(struct platform_device *pdev)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun 	const struct of_dev_auxdata *lookup = dev_get_platdata(&pdev->dev);
44*4882a593Smuzhiyun 	int ret;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	ret = of_dma_controller_register(pdev->dev.of_node,
47*4882a593Smuzhiyun 					 shdma_of_xlate, pdev);
48*4882a593Smuzhiyun 	if (ret < 0)
49*4882a593Smuzhiyun 		return ret;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	ret = of_platform_populate(pdev->dev.of_node, NULL, lookup, &pdev->dev);
52*4882a593Smuzhiyun 	if (ret < 0)
53*4882a593Smuzhiyun 		of_dma_controller_free(pdev->dev.of_node);
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	return ret;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun static const struct of_device_id shdma_of_match[] = {
59*4882a593Smuzhiyun 	{ .compatible = "renesas,shdma-mux", },
60*4882a593Smuzhiyun 	{ }
61*4882a593Smuzhiyun };
62*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, sh_dmae_of_match);
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun static struct platform_driver shdma_of = {
65*4882a593Smuzhiyun 	.driver		= {
66*4882a593Smuzhiyun 		.name	= "shdma-of",
67*4882a593Smuzhiyun 		.of_match_table = shdma_of_match,
68*4882a593Smuzhiyun 	},
69*4882a593Smuzhiyun 	.probe		= shdma_of_probe,
70*4882a593Smuzhiyun };
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun module_platform_driver(shdma_of);
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
75*4882a593Smuzhiyun MODULE_DESCRIPTION("SH-DMA driver DT glue");
76*4882a593Smuzhiyun MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
77