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