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 <linux/module.h>
13 #include <linux/interrupt.h>
14 #include <linux/clk.h>
16 #include <linux/of_device.h>
17 #include <linux/of_address.h>
18 #include <linux/of_irq.h>
19 #include <linux/of_dma.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/pm_runtime.h>
22 #include <linux/pm_domain.h>
24 #include "fsl-edma-common.h"
26 #define ARGS_RX BIT(0)
27 #define ARGS_REMOTE BIT(1)
28 #define ARGS_MULTI_FIFO BIT(2)
29 #define ARGS_EVEN_CH BIT(3)
30 #define ARGS_ODD_CH BIT(4)
32 static void fsl_edma_synchronize(struct dma_chan *chan)
34 struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan);
36 vchan_synchronize(&fsl_chan->vchan);
39 static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id)
41 struct fsl_edma_engine *fsl_edma = dev_id;
42 unsigned int intr, ch;
43 struct edma_regs *regs = &fsl_edma->regs;
45 intr = edma_readl(fsl_edma, regs->intl);
49 for (ch = 0; ch < fsl_edma->n_chans; ch++) {
50 if (intr & (0x1 << ch)) {
51 edma_writeb(fsl_edma, EDMA_CINT_CINT(ch), regs->cint);
52 fsl_edma_tx_chan_handler(&fsl_edma->chans[ch]);
58 static irqreturn_t fsl_edma3_tx_handler(int irq, void *dev_id)
60 struct fsl_edma_chan *fsl_chan = dev_id;
63 intr = edma_readl_chreg(fsl_chan, ch_int);
67 edma_writel_chreg(fsl_chan, 1, ch_int);
69 fsl_edma_tx_chan_handler(fsl_chan);
74 static irqreturn_t fsl_edma_err_handler(int irq, void *dev_id)
76 struct fsl_edma_engine *fsl_edma = dev_id;
78 struct edma_regs *regs = &fsl_edma->regs;
80 err = edma_readl(fsl_edma, regs->errl);
84 for (ch = 0; ch < fsl_edma->n_chans; ch++) {
85 if (err & (0x1 << ch)) {
86 fsl_edma_disable_request(&fsl_edma->chans[ch]);
87 edma_writeb(fsl_edma, EDMA_CERR_CERR(ch), regs->cerr);
88 fsl_edma_err_chan_handler(&fsl_edma->chans[ch]);
94 static irqreturn_t fsl_edma_irq_handler(int irq, void *dev_id)
96 if (fsl_edma_tx_handler(irq, dev_id) == IRQ_HANDLED)
99 return fsl_edma_err_handler(irq, dev_id);
102 static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec,
103 struct of_dma *ofdma)
105 struct fsl_edma_engine *fsl_edma = ofdma->of_dma_data;
106 struct dma_chan *chan, *_chan;
107 struct fsl_edma_chan *fsl_chan;
108 u32 dmamux_nr = fsl_edma->drvdata->dmamuxs;
109 unsigned long chans_per_mux = fsl_edma->n_chans / dmamux_nr;
111 if (dma_spec->args_count != 2)
114 mutex_lock(&fsl_edma->fsl_edma_mutex);
115 list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels, device_node) {
116 if (chan->client_count)
118 if ((chan->chan_id / chans_per_mux) == dma_spec->args[0]) {
119 chan = dma_get_slave_channel(chan);
121 chan->device->privatecnt++;
122 fsl_chan = to_fsl_edma_chan(chan);
123 fsl_chan->slave_id = dma_spec->args[1];
124 fsl_edma_chan_mux(fsl_chan, fsl_chan->slave_id,
126 mutex_unlock(&fsl_edma->fsl_edma_mutex);
131 mutex_unlock(&fsl_edma->fsl_edma_mutex);
135 static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec,
136 struct of_dma *ofdma)
138 struct fsl_edma_engine *fsl_edma = ofdma->of_dma_data;
139 struct dma_chan *chan, *_chan;
140 struct fsl_edma_chan *fsl_chan;
144 if (dma_spec->args_count != 3)
147 b_chmux = !!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_CHMUX);
149 mutex_lock(&fsl_edma->fsl_edma_mutex);
150 list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels,
153 if (chan->client_count)
156 fsl_chan = to_fsl_edma_chan(chan);
157 i = fsl_chan - fsl_edma->chans;
159 fsl_chan->priority = dma_spec->args[1];
160 fsl_chan->is_rxchan = dma_spec->args[2] & ARGS_RX;
161 fsl_chan->is_remote = dma_spec->args[2] & ARGS_REMOTE;
162 fsl_chan->is_multi_fifo = dma_spec->args[2] & ARGS_MULTI_FIFO;
164 if ((dma_spec->args[2] & ARGS_EVEN_CH) && (i & 0x1))
167 if ((dma_spec->args[2] & ARGS_ODD_CH) && !(i & 0x1))
170 if (!b_chmux && i == dma_spec->args[0]) {
171 chan = dma_get_slave_channel(chan);
172 chan->device->privatecnt++;
173 mutex_unlock(&fsl_edma->fsl_edma_mutex);
175 } else if (b_chmux && !fsl_chan->srcid) {
176 /* if controller support channel mux, choose a free channel */
177 chan = dma_get_slave_channel(chan);
178 chan->device->privatecnt++;
179 fsl_chan->srcid = dma_spec->args[0];
180 mutex_unlock(&fsl_edma->fsl_edma_mutex);
184 mutex_unlock(&fsl_edma->fsl_edma_mutex);
189 fsl_edma_irq_init(struct platform_device *pdev, struct fsl_edma_engine *fsl_edma)
193 edma_writel(fsl_edma, ~0, fsl_edma->regs.intl);
195 fsl_edma->txirq = platform_get_irq_byname(pdev, "edma-tx");
196 if (fsl_edma->txirq < 0)
197 return fsl_edma->txirq;
199 fsl_edma->errirq = platform_get_irq_byname(pdev, "edma-err");
200 if (fsl_edma->errirq < 0)
201 return fsl_edma->errirq;
203 if (fsl_edma->txirq == fsl_edma->errirq) {
204 ret = devm_request_irq(&pdev->dev, fsl_edma->txirq,
205 fsl_edma_irq_handler, 0, "eDMA", fsl_edma);
207 dev_err(&pdev->dev, "Can't register eDMA IRQ.\n");
211 ret = devm_request_irq(&pdev->dev, fsl_edma->txirq,
212 fsl_edma_tx_handler, 0, "eDMA tx", fsl_edma);
214 dev_err(&pdev->dev, "Can't register eDMA tx IRQ.\n");
218 ret = devm_request_irq(&pdev->dev, fsl_edma->errirq,
219 fsl_edma_err_handler, 0, "eDMA err", fsl_edma);
221 dev_err(&pdev->dev, "Can't register eDMA err IRQ.\n");
229 static int fsl_edma3_irq_init(struct platform_device *pdev, struct fsl_edma_engine *fsl_edma)
234 for (i = 0; i < fsl_edma->n_chans; i++) {
236 struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[i];
238 if (fsl_edma->chan_masked & BIT(i))
241 /* request channel irq */
242 fsl_chan->txirq = platform_get_irq(pdev, i);
243 if (fsl_chan->txirq < 0) {
244 dev_err(&pdev->dev, "Can't get chan %d's irq.\n", i);
248 ret = devm_request_irq(&pdev->dev, fsl_chan->txirq,
249 fsl_edma3_tx_handler, IRQF_SHARED,
250 fsl_chan->chan_name, fsl_chan);
252 dev_err(&pdev->dev, "Can't register chan%d's IRQ.\n", i);
261 fsl_edma2_irq_init(struct platform_device *pdev,
262 struct fsl_edma_engine *fsl_edma)
267 edma_writel(fsl_edma, ~0, fsl_edma->regs.intl);
269 count = platform_irq_count(pdev);
270 dev_dbg(&pdev->dev, "%s Found %d interrupts\r\n", __func__, count);
272 dev_err(&pdev->dev, "Interrupts in DTS not correct.\n");
276 * 16 channel independent interrupts + 1 error interrupt on i.mx7ulp.
277 * 2 channel share one interrupt, for example, ch0/ch16, ch1/ch17...
278 * For now, just simply request irq without IRQF_SHARED flag, since 16
279 * channels are enough on i.mx7ulp whose M4 domain own some peripherals.
281 for (i = 0; i < count; i++) {
282 irq = platform_get_irq(pdev, i);
286 /* The last IRQ is for eDMA err */
288 ret = devm_request_irq(&pdev->dev, irq,
289 fsl_edma_err_handler,
290 0, "eDMA2-ERR", fsl_edma);
292 ret = devm_request_irq(&pdev->dev, irq,
293 fsl_edma_tx_handler, 0,
294 fsl_edma->chans[i].chan_name,
303 static void fsl_edma_irq_exit(
304 struct platform_device *pdev, struct fsl_edma_engine *fsl_edma)
306 if (fsl_edma->txirq == fsl_edma->errirq) {
307 devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
309 devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
310 devm_free_irq(&pdev->dev, fsl_edma->errirq, fsl_edma);
314 static void fsl_disable_clocks(struct fsl_edma_engine *fsl_edma, int nr_clocks)
318 for (i = 0; i < nr_clocks; i++)
319 clk_disable_unprepare(fsl_edma->muxclk[i]);
322 static struct fsl_edma_drvdata vf610_data = {
323 .dmamuxs = DMAMUX_NR,
324 .flags = FSL_EDMA_DRV_WRAP_IO,
325 .chreg_off = EDMA_TCD,
326 .chreg_space_sz = sizeof(struct fsl_edma_hw_tcd),
327 .setup_irq = fsl_edma_irq_init,
330 static struct fsl_edma_drvdata ls1028a_data = {
331 .dmamuxs = DMAMUX_NR,
332 .flags = FSL_EDMA_DRV_MUX_SWAP | FSL_EDMA_DRV_WRAP_IO,
333 .chreg_off = EDMA_TCD,
334 .chreg_space_sz = sizeof(struct fsl_edma_hw_tcd),
335 .setup_irq = fsl_edma_irq_init,
338 static struct fsl_edma_drvdata imx7ulp_data = {
340 .chreg_off = EDMA_TCD,
341 .chreg_space_sz = sizeof(struct fsl_edma_hw_tcd),
342 .flags = FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_CONFIG32,
343 .setup_irq = fsl_edma2_irq_init,
346 static struct fsl_edma_drvdata imx8qm_data = {
347 .flags = FSL_EDMA_DRV_HAS_PD | FSL_EDMA_DRV_EDMA3,
348 .chreg_space_sz = 0x10000,
349 .chreg_off = 0x10000,
350 .setup_irq = fsl_edma3_irq_init,
353 static struct fsl_edma_drvdata imx8qm_audio_data = {
354 .flags = FSL_EDMA_DRV_QUIRK_SWAPPED | FSL_EDMA_DRV_HAS_PD | FSL_EDMA_DRV_EDMA3,
355 .chreg_space_sz = 0x10000,
356 .chreg_off = 0x10000,
357 .setup_irq = fsl_edma3_irq_init,
360 static struct fsl_edma_drvdata imx93_data3 = {
361 .flags = FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_EDMA3,
362 .chreg_space_sz = 0x10000,
363 .chreg_off = 0x10000,
364 .setup_irq = fsl_edma3_irq_init,
367 static struct fsl_edma_drvdata imx93_data4 = {
368 .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_EDMA4,
369 .chreg_space_sz = 0x8000,
370 .chreg_off = 0x10000,
371 .setup_irq = fsl_edma3_irq_init,
374 static const struct of_device_id fsl_edma_dt_ids[] = {
375 { .compatible = "fsl,vf610-edma", .data = &vf610_data},
376 { .compatible = "fsl,ls1028a-edma", .data = &ls1028a_data},
377 { .compatible = "fsl,imx7ulp-edma", .data = &imx7ulp_data},
378 { .compatible = "fsl,imx8qm-edma", .data = &imx8qm_data},
379 { .compatible = "fsl,imx8qm-adma", .data = &imx8qm_audio_data},
380 { .compatible = "fsl,imx93-edma3", .data = &imx93_data3},
381 { .compatible = "fsl,imx93-edma4", .data = &imx93_data4},
384 MODULE_DEVICE_TABLE(of, fsl_edma_dt_ids);
386 static int fsl_edma3_attach_pd(struct platform_device *pdev, struct fsl_edma_engine *fsl_edma)
388 struct fsl_edma_chan *fsl_chan;
389 struct device_link *link;
390 struct device *pd_chan;
396 for (i = 0; i < fsl_edma->n_chans; i++) {
397 if (fsl_edma->chan_masked & BIT(i))
400 fsl_chan = &fsl_edma->chans[i];
402 pd_chan = dev_pm_domain_attach_by_id(dev, i);
403 if (IS_ERR_OR_NULL(pd_chan)) {
404 dev_err(dev, "Failed attach pd %d\n", i);
408 link = device_link_add(dev, pd_chan, DL_FLAG_STATELESS |
412 dev_err(dev, "Failed to add device_link to %d\n", i);
416 fsl_chan->pd_dev = pd_chan;
418 pm_runtime_use_autosuspend(fsl_chan->pd_dev);
419 pm_runtime_set_autosuspend_delay(fsl_chan->pd_dev, 200);
420 pm_runtime_set_active(fsl_chan->pd_dev);
426 static int fsl_edma_probe(struct platform_device *pdev)
428 const struct of_device_id *of_id =
429 of_match_device(fsl_edma_dt_ids, &pdev->dev);
430 struct device_node *np = pdev->dev.of_node;
431 struct fsl_edma_engine *fsl_edma;
432 const struct fsl_edma_drvdata *drvdata = NULL;
433 u32 chan_mask[2] = {0, 0};
434 struct edma_regs *regs;
439 drvdata = of_id->data;
441 dev_err(&pdev->dev, "unable to find driver data\n");
445 ret = of_property_read_u32(np, "dma-channels", &chans);
447 dev_err(&pdev->dev, "Can't get dma-channels.\n");
451 fsl_edma = devm_kzalloc(&pdev->dev, struct_size(fsl_edma, chans, chans),
456 fsl_edma->drvdata = drvdata;
457 fsl_edma->n_chans = chans;
458 mutex_init(&fsl_edma->fsl_edma_mutex);
460 fsl_edma->membase = devm_platform_ioremap_resource(pdev, 0);
461 if (IS_ERR(fsl_edma->membase))
462 return PTR_ERR(fsl_edma->membase);
464 if (!(drvdata->flags & FSL_EDMA_DRV_SPLIT_REG)) {
465 fsl_edma_setup_regs(fsl_edma);
466 regs = &fsl_edma->regs;
469 if (drvdata->flags & FSL_EDMA_DRV_HAS_DMACLK) {
470 fsl_edma->dmaclk = devm_clk_get_enabled(&pdev->dev, "dma");
471 if (IS_ERR(fsl_edma->dmaclk)) {
472 dev_err(&pdev->dev, "Missing DMA block clock.\n");
473 return PTR_ERR(fsl_edma->dmaclk);
477 if (drvdata->flags & FSL_EDMA_DRV_HAS_CHCLK) {
478 fsl_edma->chclk = devm_clk_get_enabled(&pdev->dev, "mp");
479 if (IS_ERR(fsl_edma->chclk)) {
480 dev_err(&pdev->dev, "Missing MP block clock.\n");
481 return PTR_ERR(fsl_edma->chclk);
485 ret = of_property_read_variable_u32_array(np, "dma-channel-mask", chan_mask, 1, 2);
488 fsl_edma->chan_masked = chan_mask[1];
489 fsl_edma->chan_masked <<= 32;
490 fsl_edma->chan_masked |= chan_mask[0];
493 for (i = 0; i < fsl_edma->drvdata->dmamuxs; i++) {
496 /* eDMAv3 mux register move to TCD area if ch_mux exist */
497 if (drvdata->flags & FSL_EDMA_DRV_SPLIT_REG)
500 fsl_edma->muxbase[i] = devm_platform_ioremap_resource(pdev,
502 if (IS_ERR(fsl_edma->muxbase[i])) {
503 /* on error: disable all previously enabled clks */
504 fsl_disable_clocks(fsl_edma, i);
505 return PTR_ERR(fsl_edma->muxbase[i]);
508 sprintf(clkname, "dmamux%d", i);
509 fsl_edma->muxclk[i] = devm_clk_get_enabled(&pdev->dev, clkname);
510 if (IS_ERR(fsl_edma->muxclk[i])) {
511 dev_err(&pdev->dev, "Missing DMAMUX block clock.\n");
512 /* on error: disable all previously enabled clks */
513 return PTR_ERR(fsl_edma->muxclk[i]);
517 fsl_edma->big_endian = of_property_read_bool(np, "big-endian");
519 if (drvdata->flags & FSL_EDMA_DRV_HAS_PD) {
520 ret = fsl_edma3_attach_pd(pdev, fsl_edma);
525 INIT_LIST_HEAD(&fsl_edma->dma_dev.channels);
526 for (i = 0; i < fsl_edma->n_chans; i++) {
527 struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[i];
530 if (fsl_edma->chan_masked & BIT(i))
533 snprintf(fsl_chan->chan_name, sizeof(fsl_chan->chan_name), "%s-CH%02d",
534 dev_name(&pdev->dev), i);
536 fsl_chan->edma = fsl_edma;
537 fsl_chan->pm_state = RUNNING;
538 fsl_chan->slave_id = 0;
539 fsl_chan->idle = true;
540 fsl_chan->dma_dir = DMA_NONE;
541 fsl_chan->vchan.desc_free = fsl_edma_free_desc;
543 len = (drvdata->flags & FSL_EDMA_DRV_SPLIT_REG) ?
544 offsetof(struct fsl_edma3_ch_reg, tcd) : 0;
545 fsl_chan->tcd = fsl_edma->membase
546 + i * drvdata->chreg_space_sz + drvdata->chreg_off + len;
548 fsl_chan->pdev = pdev;
549 vchan_init(&fsl_chan->vchan, &fsl_edma->dma_dev);
551 edma_write_tcdreg(fsl_chan, 0, csr);
552 fsl_edma_chan_mux(fsl_chan, 0, false);
555 ret = fsl_edma->drvdata->setup_irq(pdev, fsl_edma);
559 dma_cap_set(DMA_PRIVATE, fsl_edma->dma_dev.cap_mask);
560 dma_cap_set(DMA_SLAVE, fsl_edma->dma_dev.cap_mask);
561 dma_cap_set(DMA_CYCLIC, fsl_edma->dma_dev.cap_mask);
562 dma_cap_set(DMA_MEMCPY, fsl_edma->dma_dev.cap_mask);
564 fsl_edma->dma_dev.dev = &pdev->dev;
565 fsl_edma->dma_dev.device_alloc_chan_resources
566 = fsl_edma_alloc_chan_resources;
567 fsl_edma->dma_dev.device_free_chan_resources
568 = fsl_edma_free_chan_resources;
569 fsl_edma->dma_dev.device_tx_status = fsl_edma_tx_status;
570 fsl_edma->dma_dev.device_prep_slave_sg = fsl_edma_prep_slave_sg;
571 fsl_edma->dma_dev.device_prep_dma_cyclic = fsl_edma_prep_dma_cyclic;
572 fsl_edma->dma_dev.device_prep_dma_memcpy = fsl_edma_prep_memcpy;
573 fsl_edma->dma_dev.device_config = fsl_edma_slave_config;
574 fsl_edma->dma_dev.device_pause = fsl_edma_pause;
575 fsl_edma->dma_dev.device_resume = fsl_edma_resume;
576 fsl_edma->dma_dev.device_terminate_all = fsl_edma_terminate_all;
577 fsl_edma->dma_dev.device_synchronize = fsl_edma_synchronize;
578 fsl_edma->dma_dev.device_issue_pending = fsl_edma_issue_pending;
580 fsl_edma->dma_dev.src_addr_widths = FSL_EDMA_BUSWIDTHS;
581 fsl_edma->dma_dev.dst_addr_widths = FSL_EDMA_BUSWIDTHS;
583 if (drvdata->flags & FSL_EDMA_DRV_BUS_8BYTE) {
584 fsl_edma->dma_dev.src_addr_widths |= BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
585 fsl_edma->dma_dev.dst_addr_widths |= BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
588 fsl_edma->dma_dev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
589 if (drvdata->flags & FSL_EDMA_DRV_DEV_TO_DEV)
590 fsl_edma->dma_dev.directions |= BIT(DMA_DEV_TO_DEV);
592 fsl_edma->dma_dev.copy_align = drvdata->flags & FSL_EDMA_DRV_ALIGN_64BYTE ?
593 DMAENGINE_ALIGN_64_BYTES :
594 DMAENGINE_ALIGN_32_BYTES;
596 /* Per worst case 'nbytes = 1' take CITER as the max_seg_size */
597 dma_set_max_seg_size(fsl_edma->dma_dev.dev, 0x3fff);
599 fsl_edma->dma_dev.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
601 platform_set_drvdata(pdev, fsl_edma);
603 ret = dma_async_device_register(&fsl_edma->dma_dev);
606 "Can't register Freescale eDMA engine. (%d)\n", ret);
610 ret = of_dma_controller_register(np,
611 drvdata->flags & FSL_EDMA_DRV_SPLIT_REG ? fsl_edma3_xlate : fsl_edma_xlate,
615 "Can't register Freescale eDMA of_dma. (%d)\n", ret);
616 dma_async_device_unregister(&fsl_edma->dma_dev);
620 /* enable round robin arbitration */
621 if (!(drvdata->flags & FSL_EDMA_DRV_SPLIT_REG))
622 edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr);
627 static int fsl_edma_remove(struct platform_device *pdev)
629 struct device_node *np = pdev->dev.of_node;
630 struct fsl_edma_engine *fsl_edma = platform_get_drvdata(pdev);
632 fsl_edma_irq_exit(pdev, fsl_edma);
633 fsl_edma_cleanup_vchan(&fsl_edma->dma_dev);
634 of_dma_controller_free(np);
635 dma_async_device_unregister(&fsl_edma->dma_dev);
636 fsl_disable_clocks(fsl_edma, fsl_edma->drvdata->dmamuxs);
641 static int fsl_edma_suspend_late(struct device *dev)
643 struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev);
644 struct fsl_edma_chan *fsl_chan;
648 for (i = 0; i < fsl_edma->n_chans; i++) {
649 fsl_chan = &fsl_edma->chans[i];
650 if (fsl_edma->chan_masked & BIT(i))
652 spin_lock_irqsave(&fsl_chan->vchan.lock, flags);
653 /* Make sure chan is idle or will force disable. */
654 if (unlikely(!fsl_chan->idle)) {
655 dev_warn(dev, "WARN: There is non-idle channel.");
656 fsl_edma_disable_request(fsl_chan);
657 fsl_edma_chan_mux(fsl_chan, 0, false);
660 fsl_chan->pm_state = SUSPENDED;
661 spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags);
667 static int fsl_edma_resume_early(struct device *dev)
669 struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev);
670 struct fsl_edma_chan *fsl_chan;
671 struct edma_regs *regs = &fsl_edma->regs;
674 for (i = 0; i < fsl_edma->n_chans; i++) {
675 fsl_chan = &fsl_edma->chans[i];
676 if (fsl_edma->chan_masked & BIT(i))
678 fsl_chan->pm_state = RUNNING;
679 edma_write_tcdreg(fsl_chan, 0, csr);
680 if (fsl_chan->slave_id != 0)
681 fsl_edma_chan_mux(fsl_chan, fsl_chan->slave_id, true);
684 if (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG))
685 edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr);
691 * eDMA provides the service to others, so it should be suspend late
692 * and resume early. When eDMA suspend, all of the clients should stop
693 * the DMA data transmission and let the channel idle.
695 static const struct dev_pm_ops fsl_edma_pm_ops = {
696 .suspend_late = fsl_edma_suspend_late,
697 .resume_early = fsl_edma_resume_early,
700 static struct platform_driver fsl_edma_driver = {
703 .of_match_table = fsl_edma_dt_ids,
704 .pm = &fsl_edma_pm_ops,
706 .probe = fsl_edma_probe,
707 .remove = fsl_edma_remove,
710 static int __init fsl_edma_init(void)
712 return platform_driver_register(&fsl_edma_driver);
714 subsys_initcall(fsl_edma_init);
716 static void __exit fsl_edma_exit(void)
718 platform_driver_unregister(&fsl_edma_driver);
720 module_exit(fsl_edma_exit);
722 MODULE_ALIAS("platform:fsl-edma");
723 MODULE_DESCRIPTION("Freescale eDMA engine driver");
724 MODULE_LICENSE("GPL v2");