1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/dma/fsl-edma.c
5 * Copyright 2013-2014 Freescale Semiconductor, Inc.
7 * Driver for the Freescale eDMA engine with flexible channel multiplexing
8 * capability for DMA request sources. The eDMA block can be found on some
9 * Vybrid and Layerscape SoCs.
12 #include <dt-bindings/dma/fsl-edma.h>
13 #include <linux/bitfield.h>
14 #include <linux/module.h>
15 #include <linux/interrupt.h>
16 #include <linux/clk.h>
18 #include <linux/of_dma.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/pm_domain.h>
22 #include <linux/property.h>
24 #include "fsl-edma-common.h"
26 static void fsl_edma_synchronize(struct dma_chan
*chan
)
28 struct fsl_edma_chan
*fsl_chan
= to_fsl_edma_chan(chan
);
30 vchan_synchronize(&fsl_chan
->vchan
);
33 static irqreturn_t
fsl_edma_tx_handler(int irq
, void *dev_id
)
35 struct fsl_edma_engine
*fsl_edma
= dev_id
;
36 unsigned int intr
, ch
;
37 struct edma_regs
*regs
= &fsl_edma
->regs
;
39 intr
= edma_readl(fsl_edma
, regs
->intl
);
43 for (ch
= 0; ch
< fsl_edma
->n_chans
; ch
++) {
44 if (intr
& (0x1 << ch
)) {
45 edma_writeb(fsl_edma
, EDMA_CINT_CINT(ch
), regs
->cint
);
46 fsl_edma_tx_chan_handler(&fsl_edma
->chans
[ch
]);
52 static irqreturn_t
fsl_edma3_tx_handler(int irq
, void *dev_id
)
54 struct fsl_edma_chan
*fsl_chan
= dev_id
;
57 intr
= edma_readl_chreg(fsl_chan
, ch_int
);
61 edma_writel_chreg(fsl_chan
, 1, ch_int
);
63 fsl_edma_tx_chan_handler(fsl_chan
);
68 static irqreturn_t
fsl_edma2_tx_handler(int irq
, void *devi_id
)
70 struct fsl_edma_chan
*fsl_chan
= devi_id
;
72 return fsl_edma_tx_handler(irq
, fsl_chan
->edma
);
75 static irqreturn_t
fsl_edma_err_handler(int irq
, void *dev_id
)
77 struct fsl_edma_engine
*fsl_edma
= dev_id
;
79 struct edma_regs
*regs
= &fsl_edma
->regs
;
81 err
= edma_readl(fsl_edma
, regs
->errl
);
85 for (ch
= 0; ch
< fsl_edma
->n_chans
; ch
++) {
86 if (err
& (0x1 << ch
)) {
87 fsl_edma_disable_request(&fsl_edma
->chans
[ch
]);
88 edma_writeb(fsl_edma
, EDMA_CERR_CERR(ch
), regs
->cerr
);
89 fsl_edma_err_chan_handler(&fsl_edma
->chans
[ch
]);
95 static irqreturn_t
fsl_edma_irq_handler(int irq
, void *dev_id
)
97 if (fsl_edma_tx_handler(irq
, dev_id
) == IRQ_HANDLED
)
100 return fsl_edma_err_handler(irq
, dev_id
);
103 static bool fsl_edma_srcid_in_use(struct fsl_edma_engine
*fsl_edma
, u32 srcid
)
105 struct fsl_edma_chan
*fsl_chan
;
108 for (i
= 0; i
< fsl_edma
->n_chans
; i
++) {
109 fsl_chan
= &fsl_edma
->chans
[i
];
111 if (fsl_chan
->srcid
&& srcid
== fsl_chan
->srcid
) {
112 dev_err(&fsl_chan
->pdev
->dev
, "The srcid is in use, can't use!");
119 static struct dma_chan
*fsl_edma_xlate(struct of_phandle_args
*dma_spec
,
120 struct of_dma
*ofdma
)
122 struct fsl_edma_engine
*fsl_edma
= ofdma
->of_dma_data
;
123 struct dma_chan
*chan
, *_chan
;
124 struct fsl_edma_chan
*fsl_chan
;
125 u32 dmamux_nr
= fsl_edma
->drvdata
->dmamuxs
;
126 unsigned long chans_per_mux
= fsl_edma
->n_chans
/ dmamux_nr
;
128 if (dma_spec
->args_count
!= 2)
131 guard(mutex
)(&fsl_edma
->fsl_edma_mutex
);
133 list_for_each_entry_safe(chan
, _chan
, &fsl_edma
->dma_dev
.channels
, device_node
) {
134 if (chan
->client_count
)
137 if (fsl_edma_srcid_in_use(fsl_edma
, dma_spec
->args
[1]))
140 if ((chan
->chan_id
/ chans_per_mux
) == dma_spec
->args
[0]) {
141 chan
= dma_get_slave_channel(chan
);
143 chan
->device
->privatecnt
++;
144 fsl_chan
= to_fsl_edma_chan(chan
);
145 fsl_chan
->srcid
= dma_spec
->args
[1];
147 if (!fsl_chan
->srcid
) {
148 dev_err(&fsl_chan
->pdev
->dev
, "Invalidate srcid %d\n",
153 fsl_edma_chan_mux(fsl_chan
, fsl_chan
->srcid
,
162 static struct dma_chan
*fsl_edma3_xlate(struct of_phandle_args
*dma_spec
,
163 struct of_dma
*ofdma
)
165 struct fsl_edma_engine
*fsl_edma
= ofdma
->of_dma_data
;
166 struct dma_chan
*chan
, *_chan
;
167 struct fsl_edma_chan
*fsl_chan
;
171 if (dma_spec
->args_count
!= 3)
174 b_chmux
= !!(fsl_edma
->drvdata
->flags
& FSL_EDMA_DRV_HAS_CHMUX
);
176 guard(mutex
)(&fsl_edma
->fsl_edma_mutex
);
177 list_for_each_entry_safe(chan
, _chan
, &fsl_edma
->dma_dev
.channels
,
180 if (chan
->client_count
)
183 fsl_chan
= to_fsl_edma_chan(chan
);
184 if (fsl_edma_srcid_in_use(fsl_edma
, dma_spec
->args
[0]))
186 i
= fsl_chan
- fsl_edma
->chans
;
188 fsl_chan
->priority
= dma_spec
->args
[1];
189 fsl_chan
->is_rxchan
= dma_spec
->args
[2] & FSL_EDMA_RX
;
190 fsl_chan
->is_remote
= dma_spec
->args
[2] & FSL_EDMA_REMOTE
;
191 fsl_chan
->is_multi_fifo
= dma_spec
->args
[2] & FSL_EDMA_MULTI_FIFO
;
193 if ((dma_spec
->args
[2] & FSL_EDMA_EVEN_CH
) && (i
& 0x1))
196 if ((dma_spec
->args
[2] & FSL_EDMA_ODD_CH
) && !(i
& 0x1))
199 if (!b_chmux
&& i
== dma_spec
->args
[0]) {
200 chan
= dma_get_slave_channel(chan
);
201 chan
->device
->privatecnt
++;
203 } else if (b_chmux
&& !fsl_chan
->srcid
) {
204 /* if controller support channel mux, choose a free channel */
205 chan
= dma_get_slave_channel(chan
);
206 chan
->device
->privatecnt
++;
207 fsl_chan
->srcid
= dma_spec
->args
[0];
215 fsl_edma_irq_init(struct platform_device
*pdev
, struct fsl_edma_engine
*fsl_edma
)
219 edma_writel(fsl_edma
, ~0, fsl_edma
->regs
.intl
);
221 fsl_edma
->txirq
= platform_get_irq_byname(pdev
, "edma-tx");
222 if (fsl_edma
->txirq
< 0)
223 return fsl_edma
->txirq
;
225 fsl_edma
->errirq
= platform_get_irq_byname(pdev
, "edma-err");
226 if (fsl_edma
->errirq
< 0)
227 return fsl_edma
->errirq
;
229 if (fsl_edma
->txirq
== fsl_edma
->errirq
) {
230 ret
= devm_request_irq(&pdev
->dev
, fsl_edma
->txirq
,
231 fsl_edma_irq_handler
, 0, "eDMA", fsl_edma
);
233 dev_err(&pdev
->dev
, "Can't register eDMA IRQ.\n");
237 ret
= devm_request_irq(&pdev
->dev
, fsl_edma
->txirq
,
238 fsl_edma_tx_handler
, 0, "eDMA tx", fsl_edma
);
240 dev_err(&pdev
->dev
, "Can't register eDMA tx IRQ.\n");
244 ret
= devm_request_irq(&pdev
->dev
, fsl_edma
->errirq
,
245 fsl_edma_err_handler
, 0, "eDMA err", fsl_edma
);
247 dev_err(&pdev
->dev
, "Can't register eDMA err IRQ.\n");
255 static int fsl_edma3_irq_init(struct platform_device
*pdev
, struct fsl_edma_engine
*fsl_edma
)
259 for (i
= 0; i
< fsl_edma
->n_chans
; i
++) {
261 struct fsl_edma_chan
*fsl_chan
= &fsl_edma
->chans
[i
];
263 if (fsl_edma
->chan_masked
& BIT(i
))
266 /* request channel irq */
267 fsl_chan
->txirq
= platform_get_irq(pdev
, i
);
268 if (fsl_chan
->txirq
< 0)
271 fsl_chan
->irq_handler
= fsl_edma3_tx_handler
;
278 fsl_edma2_irq_init(struct platform_device
*pdev
,
279 struct fsl_edma_engine
*fsl_edma
)
284 edma_writel(fsl_edma
, ~0, fsl_edma
->regs
.intl
);
286 count
= platform_irq_count(pdev
);
287 dev_dbg(&pdev
->dev
, "%s Found %d interrupts\r\n", __func__
, count
);
289 dev_err(&pdev
->dev
, "Interrupts in DTS not correct.\n");
293 * 16 channel independent interrupts + 1 error interrupt on i.mx7ulp.
294 * 2 channel share one interrupt, for example, ch0/ch16, ch1/ch17...
295 * For now, just simply request irq without IRQF_SHARED flag, since 16
296 * channels are enough on i.mx7ulp whose M4 domain own some peripherals.
298 for (i
= 0; i
< count
; i
++) {
299 irq
= platform_get_irq(pdev
, i
);
304 /* The last IRQ is for eDMA err */
305 if (i
== count
- 1) {
306 ret
= devm_request_irq(&pdev
->dev
, irq
,
307 fsl_edma_err_handler
,
308 0, "eDMA2-ERR", fsl_edma
);
310 fsl_edma
->chans
[i
].txirq
= irq
;
311 fsl_edma
->chans
[i
].irq_handler
= fsl_edma2_tx_handler
;
321 static void fsl_edma_irq_exit(
322 struct platform_device
*pdev
, struct fsl_edma_engine
*fsl_edma
)
324 if (fsl_edma
->txirq
== fsl_edma
->errirq
) {
325 devm_free_irq(&pdev
->dev
, fsl_edma
->txirq
, fsl_edma
);
327 devm_free_irq(&pdev
->dev
, fsl_edma
->txirq
, fsl_edma
);
328 devm_free_irq(&pdev
->dev
, fsl_edma
->errirq
, fsl_edma
);
332 static void fsl_disable_clocks(struct fsl_edma_engine
*fsl_edma
, int nr_clocks
)
336 for (i
= 0; i
< nr_clocks
; i
++)
337 clk_disable_unprepare(fsl_edma
->muxclk
[i
]);
340 static struct fsl_edma_drvdata vf610_data
= {
341 .dmamuxs
= DMAMUX_NR
,
342 .flags
= FSL_EDMA_DRV_WRAP_IO
,
343 .chreg_off
= EDMA_TCD
,
344 .chreg_space_sz
= sizeof(struct fsl_edma_hw_tcd
),
345 .setup_irq
= fsl_edma_irq_init
,
348 static struct fsl_edma_drvdata ls1028a_data
= {
349 .dmamuxs
= DMAMUX_NR
,
350 .flags
= FSL_EDMA_DRV_MUX_SWAP
| FSL_EDMA_DRV_WRAP_IO
,
351 .chreg_off
= EDMA_TCD
,
352 .chreg_space_sz
= sizeof(struct fsl_edma_hw_tcd
),
353 .setup_irq
= fsl_edma_irq_init
,
356 static struct fsl_edma_drvdata imx7ulp_data
= {
358 .chreg_off
= EDMA_TCD
,
359 .chreg_space_sz
= sizeof(struct fsl_edma_hw_tcd
),
360 .flags
= FSL_EDMA_DRV_HAS_DMACLK
| FSL_EDMA_DRV_CONFIG32
,
361 .setup_irq
= fsl_edma2_irq_init
,
364 static struct fsl_edma_drvdata imx8qm_data
= {
365 .flags
= FSL_EDMA_DRV_HAS_PD
| FSL_EDMA_DRV_EDMA3
| FSL_EDMA_DRV_MEM_REMOTE
,
366 .chreg_space_sz
= 0x10000,
367 .chreg_off
= 0x10000,
368 .setup_irq
= fsl_edma3_irq_init
,
371 static struct fsl_edma_drvdata imx8ulp_data
= {
372 .flags
= FSL_EDMA_DRV_HAS_CHMUX
| FSL_EDMA_DRV_HAS_CHCLK
| FSL_EDMA_DRV_HAS_DMACLK
|
374 .chreg_space_sz
= 0x10000,
375 .chreg_off
= 0x10000,
376 .mux_off
= 0x10000 + offsetof(struct fsl_edma3_ch_reg
, ch_mux
),
378 .setup_irq
= fsl_edma3_irq_init
,
381 static struct fsl_edma_drvdata imx93_data3
= {
382 .flags
= FSL_EDMA_DRV_HAS_DMACLK
| FSL_EDMA_DRV_EDMA3
,
383 .chreg_space_sz
= 0x10000,
384 .chreg_off
= 0x10000,
385 .setup_irq
= fsl_edma3_irq_init
,
388 static struct fsl_edma_drvdata imx93_data4
= {
389 .flags
= FSL_EDMA_DRV_HAS_CHMUX
| FSL_EDMA_DRV_HAS_DMACLK
| FSL_EDMA_DRV_EDMA4
,
390 .chreg_space_sz
= 0x8000,
391 .chreg_off
= 0x10000,
392 .mux_off
= 0x10000 + offsetof(struct fsl_edma3_ch_reg
, ch_mux
),
394 .setup_irq
= fsl_edma3_irq_init
,
397 static struct fsl_edma_drvdata imx95_data5
= {
398 .flags
= FSL_EDMA_DRV_HAS_CHMUX
| FSL_EDMA_DRV_HAS_DMACLK
| FSL_EDMA_DRV_EDMA4
|
400 .chreg_space_sz
= 0x8000,
401 .chreg_off
= 0x10000,
403 .mux_skip
= sizeof(u32
),
404 .setup_irq
= fsl_edma3_irq_init
,
407 static const struct of_device_id fsl_edma_dt_ids
[] = {
408 { .compatible
= "fsl,vf610-edma", .data
= &vf610_data
},
409 { .compatible
= "fsl,ls1028a-edma", .data
= &ls1028a_data
},
410 { .compatible
= "fsl,imx7ulp-edma", .data
= &imx7ulp_data
},
411 { .compatible
= "fsl,imx8qm-edma", .data
= &imx8qm_data
},
412 { .compatible
= "fsl,imx8ulp-edma", .data
= &imx8ulp_data
},
413 { .compatible
= "fsl,imx93-edma3", .data
= &imx93_data3
},
414 { .compatible
= "fsl,imx93-edma4", .data
= &imx93_data4
},
415 { .compatible
= "fsl,imx95-edma5", .data
= &imx95_data5
},
418 MODULE_DEVICE_TABLE(of
, fsl_edma_dt_ids
);
420 static int fsl_edma3_attach_pd(struct platform_device
*pdev
, struct fsl_edma_engine
*fsl_edma
)
422 struct fsl_edma_chan
*fsl_chan
;
423 struct device_link
*link
;
424 struct device
*pd_chan
;
430 for (i
= 0; i
< fsl_edma
->n_chans
; i
++) {
431 if (fsl_edma
->chan_masked
& BIT(i
))
434 fsl_chan
= &fsl_edma
->chans
[i
];
436 pd_chan
= dev_pm_domain_attach_by_id(dev
, i
);
437 if (IS_ERR_OR_NULL(pd_chan
)) {
438 dev_err(dev
, "Failed attach pd %d\n", i
);
442 link
= device_link_add(dev
, pd_chan
, DL_FLAG_STATELESS
|
446 dev_err(dev
, "Failed to add device_link to %d\n", i
);
450 fsl_chan
->pd_dev
= pd_chan
;
452 pm_runtime_use_autosuspend(fsl_chan
->pd_dev
);
453 pm_runtime_set_autosuspend_delay(fsl_chan
->pd_dev
, 200);
454 pm_runtime_set_active(fsl_chan
->pd_dev
);
460 static int fsl_edma_probe(struct platform_device
*pdev
)
462 struct device_node
*np
= pdev
->dev
.of_node
;
463 struct fsl_edma_engine
*fsl_edma
;
464 const struct fsl_edma_drvdata
*drvdata
= NULL
;
465 u32 chan_mask
[2] = {0, 0};
467 struct edma_regs
*regs
;
471 drvdata
= device_get_match_data(&pdev
->dev
);
473 dev_err(&pdev
->dev
, "unable to find driver data\n");
477 ret
= of_property_read_u32(np
, "dma-channels", &chans
);
479 dev_err(&pdev
->dev
, "Can't get dma-channels.\n");
483 fsl_edma
= devm_kzalloc(&pdev
->dev
, struct_size(fsl_edma
, chans
, chans
),
488 fsl_edma
->drvdata
= drvdata
;
489 fsl_edma
->n_chans
= chans
;
490 mutex_init(&fsl_edma
->fsl_edma_mutex
);
492 fsl_edma
->membase
= devm_platform_ioremap_resource(pdev
, 0);
493 if (IS_ERR(fsl_edma
->membase
))
494 return PTR_ERR(fsl_edma
->membase
);
496 if (!(drvdata
->flags
& FSL_EDMA_DRV_SPLIT_REG
)) {
497 fsl_edma_setup_regs(fsl_edma
);
498 regs
= &fsl_edma
->regs
;
501 if (drvdata
->flags
& FSL_EDMA_DRV_HAS_DMACLK
) {
502 fsl_edma
->dmaclk
= devm_clk_get_enabled(&pdev
->dev
, "dma");
503 if (IS_ERR(fsl_edma
->dmaclk
)) {
504 dev_err(&pdev
->dev
, "Missing DMA block clock.\n");
505 return PTR_ERR(fsl_edma
->dmaclk
);
509 ret
= of_property_read_variable_u32_array(np
, "dma-channel-mask", chan_mask
, 1, 2);
512 fsl_edma
->chan_masked
= chan_mask
[1];
513 fsl_edma
->chan_masked
<<= 32;
514 fsl_edma
->chan_masked
|= chan_mask
[0];
517 for (i
= 0; i
< fsl_edma
->drvdata
->dmamuxs
; i
++) {
520 /* eDMAv3 mux register move to TCD area if ch_mux exist */
521 if (drvdata
->flags
& FSL_EDMA_DRV_SPLIT_REG
)
524 fsl_edma
->muxbase
[i
] = devm_platform_ioremap_resource(pdev
,
526 if (IS_ERR(fsl_edma
->muxbase
[i
])) {
527 /* on error: disable all previously enabled clks */
528 fsl_disable_clocks(fsl_edma
, i
);
529 return PTR_ERR(fsl_edma
->muxbase
[i
]);
532 sprintf(clkname
, "dmamux%d", i
);
533 fsl_edma
->muxclk
[i
] = devm_clk_get_enabled(&pdev
->dev
, clkname
);
534 if (IS_ERR(fsl_edma
->muxclk
[i
])) {
535 dev_err(&pdev
->dev
, "Missing DMAMUX block clock.\n");
536 /* on error: disable all previously enabled clks */
537 return PTR_ERR(fsl_edma
->muxclk
[i
]);
541 fsl_edma
->big_endian
= of_property_read_bool(np
, "big-endian");
543 if (drvdata
->flags
& FSL_EDMA_DRV_HAS_PD
) {
544 ret
= fsl_edma3_attach_pd(pdev
, fsl_edma
);
549 if (drvdata
->flags
& FSL_EDMA_DRV_TCD64
)
550 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
552 INIT_LIST_HEAD(&fsl_edma
->dma_dev
.channels
);
553 for (i
= 0; i
< fsl_edma
->n_chans
; i
++) {
554 struct fsl_edma_chan
*fsl_chan
= &fsl_edma
->chans
[i
];
557 if (fsl_edma
->chan_masked
& BIT(i
))
560 snprintf(fsl_chan
->chan_name
, sizeof(fsl_chan
->chan_name
), "%s-CH%02d",
561 dev_name(&pdev
->dev
), i
);
563 fsl_chan
->edma
= fsl_edma
;
564 fsl_chan
->pm_state
= RUNNING
;
566 fsl_chan
->dma_dir
= DMA_NONE
;
567 fsl_chan
->vchan
.desc_free
= fsl_edma_free_desc
;
569 len
= (drvdata
->flags
& FSL_EDMA_DRV_SPLIT_REG
) ?
570 offsetof(struct fsl_edma3_ch_reg
, tcd
) : 0;
571 fsl_chan
->tcd
= fsl_edma
->membase
572 + i
* drvdata
->chreg_space_sz
+ drvdata
->chreg_off
+ len
;
573 fsl_chan
->mux_addr
= fsl_edma
->membase
+ drvdata
->mux_off
+ i
* drvdata
->mux_skip
;
575 if (drvdata
->flags
& FSL_EDMA_DRV_HAS_CHCLK
) {
576 snprintf(clk_name
, sizeof(clk_name
), "ch%02d", i
);
577 fsl_chan
->clk
= devm_clk_get_enabled(&pdev
->dev
,
578 (const char *)clk_name
);
580 if (IS_ERR(fsl_chan
->clk
))
581 return PTR_ERR(fsl_chan
->clk
);
583 fsl_chan
->pdev
= pdev
;
584 vchan_init(&fsl_chan
->vchan
, &fsl_edma
->dma_dev
);
586 edma_write_tcdreg(fsl_chan
, cpu_to_le32(0), csr
);
587 fsl_edma_chan_mux(fsl_chan
, 0, false);
588 if (fsl_chan
->edma
->drvdata
->flags
& FSL_EDMA_DRV_HAS_CHCLK
)
589 clk_disable_unprepare(fsl_chan
->clk
);
592 ret
= fsl_edma
->drvdata
->setup_irq(pdev
, fsl_edma
);
596 dma_cap_set(DMA_PRIVATE
, fsl_edma
->dma_dev
.cap_mask
);
597 dma_cap_set(DMA_SLAVE
, fsl_edma
->dma_dev
.cap_mask
);
598 dma_cap_set(DMA_CYCLIC
, fsl_edma
->dma_dev
.cap_mask
);
599 dma_cap_set(DMA_MEMCPY
, fsl_edma
->dma_dev
.cap_mask
);
601 fsl_edma
->dma_dev
.dev
= &pdev
->dev
;
602 fsl_edma
->dma_dev
.device_alloc_chan_resources
603 = fsl_edma_alloc_chan_resources
;
604 fsl_edma
->dma_dev
.device_free_chan_resources
605 = fsl_edma_free_chan_resources
;
606 fsl_edma
->dma_dev
.device_tx_status
= fsl_edma_tx_status
;
607 fsl_edma
->dma_dev
.device_prep_slave_sg
= fsl_edma_prep_slave_sg
;
608 fsl_edma
->dma_dev
.device_prep_dma_cyclic
= fsl_edma_prep_dma_cyclic
;
609 fsl_edma
->dma_dev
.device_prep_dma_memcpy
= fsl_edma_prep_memcpy
;
610 fsl_edma
->dma_dev
.device_config
= fsl_edma_slave_config
;
611 fsl_edma
->dma_dev
.device_pause
= fsl_edma_pause
;
612 fsl_edma
->dma_dev
.device_resume
= fsl_edma_resume
;
613 fsl_edma
->dma_dev
.device_terminate_all
= fsl_edma_terminate_all
;
614 fsl_edma
->dma_dev
.device_synchronize
= fsl_edma_synchronize
;
615 fsl_edma
->dma_dev
.device_issue_pending
= fsl_edma_issue_pending
;
617 fsl_edma
->dma_dev
.src_addr_widths
= FSL_EDMA_BUSWIDTHS
;
618 fsl_edma
->dma_dev
.dst_addr_widths
= FSL_EDMA_BUSWIDTHS
;
620 if (drvdata
->flags
& FSL_EDMA_DRV_BUS_8BYTE
) {
621 fsl_edma
->dma_dev
.src_addr_widths
|= BIT(DMA_SLAVE_BUSWIDTH_8_BYTES
);
622 fsl_edma
->dma_dev
.dst_addr_widths
|= BIT(DMA_SLAVE_BUSWIDTH_8_BYTES
);
625 fsl_edma
->dma_dev
.directions
= BIT(DMA_DEV_TO_MEM
) | BIT(DMA_MEM_TO_DEV
);
626 if (drvdata
->flags
& FSL_EDMA_DRV_DEV_TO_DEV
)
627 fsl_edma
->dma_dev
.directions
|= BIT(DMA_DEV_TO_DEV
);
629 fsl_edma
->dma_dev
.copy_align
= drvdata
->flags
& FSL_EDMA_DRV_ALIGN_64BYTE
?
630 DMAENGINE_ALIGN_64_BYTES
:
631 DMAENGINE_ALIGN_32_BYTES
;
633 /* Per worst case 'nbytes = 1' take CITER as the max_seg_size */
634 dma_set_max_seg_size(fsl_edma
->dma_dev
.dev
,
635 FIELD_GET(EDMA_TCD_ITER_MASK
, EDMA_TCD_ITER_MASK
));
637 fsl_edma
->dma_dev
.residue_granularity
= DMA_RESIDUE_GRANULARITY_SEGMENT
;
639 platform_set_drvdata(pdev
, fsl_edma
);
641 ret
= dma_async_device_register(&fsl_edma
->dma_dev
);
644 "Can't register Freescale eDMA engine. (%d)\n", ret
);
648 ret
= of_dma_controller_register(np
,
649 drvdata
->flags
& FSL_EDMA_DRV_SPLIT_REG
? fsl_edma3_xlate
: fsl_edma_xlate
,
653 "Can't register Freescale eDMA of_dma. (%d)\n", ret
);
654 dma_async_device_unregister(&fsl_edma
->dma_dev
);
658 /* enable round robin arbitration */
659 if (!(drvdata
->flags
& FSL_EDMA_DRV_SPLIT_REG
))
660 edma_writel(fsl_edma
, EDMA_CR_ERGA
| EDMA_CR_ERCA
, regs
->cr
);
665 static void fsl_edma_remove(struct platform_device
*pdev
)
667 struct device_node
*np
= pdev
->dev
.of_node
;
668 struct fsl_edma_engine
*fsl_edma
= platform_get_drvdata(pdev
);
670 fsl_edma_irq_exit(pdev
, fsl_edma
);
671 fsl_edma_cleanup_vchan(&fsl_edma
->dma_dev
);
672 of_dma_controller_free(np
);
673 dma_async_device_unregister(&fsl_edma
->dma_dev
);
674 fsl_disable_clocks(fsl_edma
, fsl_edma
->drvdata
->dmamuxs
);
677 static int fsl_edma_suspend_late(struct device
*dev
)
679 struct fsl_edma_engine
*fsl_edma
= dev_get_drvdata(dev
);
680 struct fsl_edma_chan
*fsl_chan
;
684 for (i
= 0; i
< fsl_edma
->n_chans
; i
++) {
685 fsl_chan
= &fsl_edma
->chans
[i
];
686 if (fsl_edma
->chan_masked
& BIT(i
))
688 spin_lock_irqsave(&fsl_chan
->vchan
.lock
, flags
);
689 /* Make sure chan is idle or will force disable. */
690 if (unlikely(fsl_chan
->status
== DMA_IN_PROGRESS
)) {
691 dev_warn(dev
, "WARN: There is non-idle channel.");
692 fsl_edma_disable_request(fsl_chan
);
693 fsl_edma_chan_mux(fsl_chan
, 0, false);
696 fsl_chan
->pm_state
= SUSPENDED
;
697 spin_unlock_irqrestore(&fsl_chan
->vchan
.lock
, flags
);
703 static int fsl_edma_resume_early(struct device
*dev
)
705 struct fsl_edma_engine
*fsl_edma
= dev_get_drvdata(dev
);
706 struct fsl_edma_chan
*fsl_chan
;
707 struct edma_regs
*regs
= &fsl_edma
->regs
;
710 for (i
= 0; i
< fsl_edma
->n_chans
; i
++) {
711 fsl_chan
= &fsl_edma
->chans
[i
];
712 if (fsl_edma
->chan_masked
& BIT(i
))
714 fsl_chan
->pm_state
= RUNNING
;
715 edma_write_tcdreg(fsl_chan
, 0, csr
);
716 if (fsl_chan
->srcid
!= 0)
717 fsl_edma_chan_mux(fsl_chan
, fsl_chan
->srcid
, true);
720 if (!(fsl_edma
->drvdata
->flags
& FSL_EDMA_DRV_SPLIT_REG
))
721 edma_writel(fsl_edma
, EDMA_CR_ERGA
| EDMA_CR_ERCA
, regs
->cr
);
727 * eDMA provides the service to others, so it should be suspend late
728 * and resume early. When eDMA suspend, all of the clients should stop
729 * the DMA data transmission and let the channel idle.
731 static const struct dev_pm_ops fsl_edma_pm_ops
= {
732 .suspend_late
= fsl_edma_suspend_late
,
733 .resume_early
= fsl_edma_resume_early
,
736 static struct platform_driver fsl_edma_driver
= {
739 .of_match_table
= fsl_edma_dt_ids
,
740 .pm
= &fsl_edma_pm_ops
,
742 .probe
= fsl_edma_probe
,
743 .remove
= fsl_edma_remove
,
746 static int __init
fsl_edma_init(void)
748 return platform_driver_register(&fsl_edma_driver
);
750 subsys_initcall(fsl_edma_init
);
752 static void __exit
fsl_edma_exit(void)
754 platform_driver_unregister(&fsl_edma_driver
);
756 module_exit(fsl_edma_exit
);
758 MODULE_ALIAS("platform:fsl-edma");
759 MODULE_DESCRIPTION("Freescale eDMA engine driver");
760 MODULE_LICENSE("GPL v2");