Skip to content

Commit 4981c4d

Browse files
lyakhVinod Koul
authored andcommitted
DMA: shdma: switch DT mode to use configuration data from a match table
This facilitates DMAC DT support by eliminating the need in AUXDATA and avoiding creating complex DT data. This also fits well with DMAC devices, of which SoCs often have multiple identical copies and it is perfectly valid to use a single configuration data set for all of them. Signed-off-by: Guennadi Liakhovetski <[email protected]> Signed-off-by: Vinod Koul <[email protected]>
1 parent 2833c47 commit 4981c4d

File tree

8 files changed

+69
-48
lines changed

8 files changed

+69
-48
lines changed

Documentation/devicetree/bindings/dma/shdma.txt

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,51 @@ Optional properties (currently unused):
2222
* DMA controller
2323

2424
Required properties:
25-
- compatible: should be "renesas,shdma"
25+
- compatible: should be of the form "renesas,shdma-<soc>", where <soc> should
26+
be replaced with the desired SoC model, e.g.
27+
"renesas,shdma-r8a73a4" for the system DMAC on r8a73a4 SoC
2628

2729
Example:
28-
dmac: dma-mux0 {
30+
dmac: dma-multiplexer@0 {
2931
compatible = "renesas,shdma-mux";
3032
#dma-cells = <1>;
31-
dma-channels = <6>;
33+
dma-channels = <20>;
3234
dma-requests = <256>;
33-
reg = <0 0>; /* Needed for AUXDATA */
34-
#address-cells = <1>;
35-
#size-cells = <1>;
35+
#address-cells = <2>;
36+
#size-cells = <2>;
3637
ranges;
3738

38-
dma0: shdma@fe008020 {
39-
compatible = "renesas,shdma";
40-
reg = <0xfe008020 0x270>,
41-
<0xfe009000 0xc>;
39+
dma0: dma-controller@e6700020 {
40+
compatible = "renesas,shdma-r8a73a4";
41+
reg = <0 0xe6700020 0 0x89e0>;
4242
interrupt-parent = <&gic>;
43-
interrupts = <0 34 4
44-
0 28 4
45-
0 29 4
46-
0 30 4
47-
0 31 4
48-
0 32 4
49-
0 33 4>;
43+
interrupts = <0 220 4
44+
0 200 4
45+
0 201 4
46+
0 202 4
47+
0 203 4
48+
0 204 4
49+
0 205 4
50+
0 206 4
51+
0 207 4
52+
0 208 4
53+
0 209 4
54+
0 210 4
55+
0 211 4
56+
0 212 4
57+
0 213 4
58+
0 214 4
59+
0 215 4
60+
0 216 4
61+
0 217 4
62+
0 218 4
63+
0 219 4>;
5064
interrupt-names = "error",
5165
"ch0", "ch1", "ch2", "ch3",
52-
"ch4", "ch5";
53-
};
54-
55-
dma1: shdma@fe018020 {
56-
...
57-
};
58-
59-
dma2: shdma@fe028020 {
60-
...
66+
"ch4", "ch5", "ch6", "ch7",
67+
"ch8", "ch9", "ch10", "ch11",
68+
"ch12", "ch13", "ch14", "ch15",
69+
"ch16", "ch17", "ch18", "ch19";
6170
};
6271
};
6372

drivers/dma/sh/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
obj-$(CONFIG_SH_DMAE_BASE) += shdma-base.o shdma-of.o
22
obj-$(CONFIG_SH_DMAE) += shdma.o
3+
shdma-y := shdmac.o
4+
shdma-objs := $(shdma-y)
35
obj-$(CONFIG_SUDMAC) += sudmac.o

drivers/dma/sh/shdma-base.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,16 @@ static struct shdma_desc *shdma_get_desc(struct shdma_chan *schan)
171171
return NULL;
172172
}
173173

174-
static int shdma_setup_slave(struct shdma_chan *schan, int slave_id)
174+
static int shdma_setup_slave(struct shdma_chan *schan, int slave_id,
175+
dma_addr_t slave_addr)
175176
{
176177
struct shdma_dev *sdev = to_shdma_dev(schan->dma_chan.device);
177178
const struct shdma_ops *ops = sdev->ops;
178179
int ret, match;
179180

180181
if (schan->dev->of_node) {
181182
match = schan->hw_req;
182-
ret = ops->set_slave(schan, match, true);
183+
ret = ops->set_slave(schan, match, slave_addr, true);
183184
if (ret < 0)
184185
return ret;
185186

@@ -194,7 +195,7 @@ static int shdma_setup_slave(struct shdma_chan *schan, int slave_id)
194195
if (test_and_set_bit(slave_id, shdma_slave_used))
195196
return -EBUSY;
196197

197-
ret = ops->set_slave(schan, match, false);
198+
ret = ops->set_slave(schan, match, slave_addr, false);
198199
if (ret < 0) {
199200
clear_bit(slave_id, shdma_slave_used);
200201
return ret;
@@ -236,7 +237,7 @@ bool shdma_chan_filter(struct dma_chan *chan, void *arg)
236237
if (!schan->dev->of_node && match >= slave_num)
237238
return false;
238239

239-
ret = ops->set_slave(schan, match, true);
240+
ret = ops->set_slave(schan, match, 0, true);
240241
if (ret < 0)
241242
return false;
242243

@@ -259,7 +260,7 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
259260
*/
260261
if (slave) {
261262
/* Legacy mode: .private is set in filter */
262-
ret = shdma_setup_slave(schan, slave->slave_id);
263+
ret = shdma_setup_slave(schan, slave->slave_id, 0);
263264
if (ret < 0)
264265
goto esetslave;
265266
} else {
@@ -680,7 +681,9 @@ static int shdma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
680681
* channel, while using it...
681682
*/
682683
config = (struct dma_slave_config *)arg;
683-
ret = shdma_setup_slave(schan, config->slave_id);
684+
ret = shdma_setup_slave(schan, config->slave_id,
685+
config->direction == DMA_DEV_TO_MEM ?
686+
config->src_addr : config->dst_addr);
684687
if (ret < 0)
685688
return ret;
686689
break;

drivers/dma/sh/shdma-of.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ static int shdma_of_probe(struct platform_device *pdev)
4545
const struct of_dev_auxdata *lookup = pdev->dev.platform_data;
4646
int ret;
4747

48-
if (!lookup)
49-
return -EINVAL;
50-
5148
ret = of_dma_controller_register(pdev->dev.of_node,
5249
shdma_of_xlate, pdev);
5350
if (ret < 0)

drivers/dma/sh/shdma.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct sh_dmae_chan {
3131
void __iomem *base;
3232
char dev_id[16]; /* unique name per DMAC of channel */
3333
int pm_error;
34+
dma_addr_t slave_addr;
3435
};
3536

3637
struct sh_dmae_device {

drivers/dma/sh/shdma.c renamed to drivers/dma/sh/shdmac.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <linux/init.h>
2222
#include <linux/module.h>
23+
#include <linux/of.h>
24+
#include <linux/of_device.h>
2325
#include <linux/slab.h>
2426
#include <linux/interrupt.h>
2527
#include <linux/dmaengine.h>
@@ -333,7 +335,7 @@ static const struct sh_dmae_slave_config *dmae_find_slave(
333335
} else {
334336
for (i = 0, cfg = pdata->slave; i < pdata->slave_num; i++, cfg++)
335337
if (cfg->mid_rid == match) {
336-
sh_chan->shdma_chan.slave_id = cfg->slave_id;
338+
sh_chan->shdma_chan.slave_id = i;
337339
return cfg;
338340
}
339341
}
@@ -342,16 +344,18 @@ static const struct sh_dmae_slave_config *dmae_find_slave(
342344
}
343345

344346
static int sh_dmae_set_slave(struct shdma_chan *schan,
345-
int slave_id, bool try)
347+
int slave_id, dma_addr_t slave_addr, bool try)
346348
{
347349
struct sh_dmae_chan *sh_chan = container_of(schan, struct sh_dmae_chan,
348350
shdma_chan);
349351
const struct sh_dmae_slave_config *cfg = dmae_find_slave(sh_chan, slave_id);
350352
if (!cfg)
351353
return -ENXIO;
352354

353-
if (!try)
355+
if (!try) {
354356
sh_chan->config = cfg;
357+
sh_chan->slave_addr = slave_addr ? : cfg->addr;
358+
}
355359

356360
return 0;
357361
}
@@ -641,7 +645,7 @@ static dma_addr_t sh_dmae_slave_addr(struct shdma_chan *schan)
641645
* This is an exclusive slave DMA operation, may only be called after a
642646
* successful slave configuration.
643647
*/
644-
return sh_chan->config->addr;
648+
return sh_chan->slave_addr;
645649
}
646650

647651
static struct shdma_desc *sh_dmae_embedded_desc(void *buf, int i)
@@ -663,9 +667,14 @@ static const struct shdma_ops sh_dmae_shdma_ops = {
663667
.get_partial = sh_dmae_get_partial,
664668
};
665669

670+
static const struct of_device_id sh_dmae_of_match[] = {
671+
{}
672+
};
673+
MODULE_DEVICE_TABLE(of, sh_dmae_of_match);
674+
666675
static int sh_dmae_probe(struct platform_device *pdev)
667676
{
668-
const struct sh_dmae_pdata *pdata = pdev->dev.platform_data;
677+
const struct sh_dmae_pdata *pdata;
669678
unsigned long irqflags = IRQF_DISABLED,
670679
chan_flag[SH_DMAE_MAX_CHANNELS] = {};
671680
int errirq, chan_irq[SH_DMAE_MAX_CHANNELS];
@@ -674,6 +683,11 @@ static int sh_dmae_probe(struct platform_device *pdev)
674683
struct dma_device *dma_dev;
675684
struct resource *chan, *dmars, *errirq_res, *chanirq_res;
676685

686+
if (pdev->dev.of_node)
687+
pdata = of_match_device(sh_dmae_of_match, &pdev->dev)->data;
688+
else
689+
pdata = pdev->dev.platform_data;
690+
677691
/* get platform data */
678692
if (!pdata || !pdata->channel_num)
679693
return -ENODEV;
@@ -902,12 +916,6 @@ static int sh_dmae_remove(struct platform_device *pdev)
902916
return 0;
903917
}
904918

905-
static const struct of_device_id sh_dmae_of_match[] = {
906-
{ .compatible = "renesas,shdma", },
907-
{ }
908-
};
909-
MODULE_DEVICE_TABLE(of, sh_dmae_of_match);
910-
911919
static struct platform_driver sh_dmae_driver = {
912920
.driver = {
913921
.owner = THIS_MODULE,

drivers/dma/sh/sudmac.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ static const struct sudmac_slave_config *sudmac_find_slave(
150150
return NULL;
151151
}
152152

153-
static int sudmac_set_slave(struct shdma_chan *schan, int slave_id, bool try)
153+
static int sudmac_set_slave(struct shdma_chan *schan, int slave_id,
154+
dma_addr_t slave_addr, bool try)
154155
{
155156
struct sudmac_chan *sc = to_chan(schan);
156157
const struct sudmac_slave_config *cfg = sudmac_find_slave(sc, slave_id);

include/linux/shdma-base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct shdma_ops {
9696
dma_addr_t (*slave_addr)(struct shdma_chan *);
9797
int (*desc_setup)(struct shdma_chan *, struct shdma_desc *,
9898
dma_addr_t, dma_addr_t, size_t *);
99-
int (*set_slave)(struct shdma_chan *, int, bool);
99+
int (*set_slave)(struct shdma_chan *, int, dma_addr_t, bool);
100100
void (*setup_xfer)(struct shdma_chan *, int);
101101
void (*start_xfer)(struct shdma_chan *, struct shdma_desc *);
102102
struct shdma_desc *(*embedded_desc)(void *, int);

0 commit comments

Comments
 (0)