blob: b4ff9d3e56d18561893f31522de0648273f72ace [file] [log] [blame]
Guennadi Liakhovetski67eacc12013-06-18 18:16:57 +02001/*
2 * SHDMA Device Tree glue
3 *
4 * Copyright (C) 2013 Renesas Electronics Inc.
5 * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
6 *
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/dmaengine.h>
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/of_dma.h>
16#include <linux/of_platform.h>
17#include <linux/platform_device.h>
18#include <linux/shdma-base.h>
19
20#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
21
22static struct dma_chan *shdma_of_xlate(struct of_phandle_args *dma_spec,
23 struct of_dma *ofdma)
24{
25 u32 id = dma_spec->args[0];
26 dma_cap_mask_t mask;
27 struct dma_chan *chan;
28
29 if (dma_spec->args_count != 1)
30 return NULL;
31
32 dma_cap_zero(mask);
33 /* Only slave DMA channels can be allocated via DT */
34 dma_cap_set(DMA_SLAVE, mask);
35
Laurent Pinchart42e4a122013-12-11 15:29:15 +010036 chan = dma_request_channel(mask, shdma_chan_filter,
37 (void *)(uintptr_t)id);
Guennadi Liakhovetski67eacc12013-06-18 18:16:57 +020038 if (chan)
39 to_shdma_chan(chan)->hw_req = id;
40
41 return chan;
42}
43
44static int shdma_of_probe(struct platform_device *pdev)
45{
Jingoo Hand4adcc02013-07-30 17:09:11 +090046 const struct of_dev_auxdata *lookup = dev_get_platdata(&pdev->dev);
Guennadi Liakhovetski67eacc12013-06-18 18:16:57 +020047 int ret;
48
Guennadi Liakhovetski67eacc12013-06-18 18:16:57 +020049 ret = of_dma_controller_register(pdev->dev.of_node,
50 shdma_of_xlate, pdev);
51 if (ret < 0)
52 return ret;
53
54 ret = of_platform_populate(pdev->dev.of_node, NULL, lookup, &pdev->dev);
55 if (ret < 0)
56 of_dma_controller_free(pdev->dev.of_node);
57
58 return ret;
59}
60
61static const struct of_device_id shdma_of_match[] = {
62 { .compatible = "renesas,shdma-mux", },
63 { }
64};
65MODULE_DEVICE_TABLE(of, sh_dmae_of_match);
66
67static struct platform_driver shdma_of = {
68 .driver = {
69 .owner = THIS_MODULE,
70 .name = "shdma-of",
71 .of_match_table = shdma_of_match,
72 },
73 .probe = shdma_of_probe,
74};
75
76module_platform_driver(shdma_of);
77
78MODULE_LICENSE("GPL v2");
79MODULE_DESCRIPTION("SH-DMA driver DT glue");
80MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");