2 * Driver for STM32 DMA controller
4 * Inspired by dma-jz4740.c and tegra20-apb-dma.c
6 * Copyright (C) M'boumba Cedric Madianga 2015
7 * Author: M'boumba Cedric Madianga <cedric.madianga@gmail.com>
8 * Pierre-Yves Mordret <pierre-yves.mordret@st.com>
10 * License terms: GNU General Public License (GPL), version 2
13 #include <linux/clk.h>
14 #include <linux/delay.h>
15 #include <linux/dmaengine.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/err.h>
18 #include <linux/init.h>
19 #include <linux/jiffies.h>
20 #include <linux/list.h>
21 #include <linux/module.h>
23 #include <linux/of_device.h>
24 #include <linux/of_dma.h>
25 #include <linux/platform_device.h>
26 #include <linux/pm_runtime.h>
27 #include <linux/reset.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
33 #define STM32_DMA_LISR 0x0000 /* DMA Low Int Status Reg */
34 #define STM32_DMA_HISR 0x0004 /* DMA High Int Status Reg */
35 #define STM32_DMA_LIFCR 0x0008 /* DMA Low Int Flag Clear Reg */
36 #define STM32_DMA_HIFCR 0x000c /* DMA High Int Flag Clear Reg */
37 #define STM32_DMA_TCI BIT(5) /* Transfer Complete Interrupt */
38 #define STM32_DMA_HTI BIT(4) /* Half Transfer Interrupt */
39 #define STM32_DMA_TEI BIT(3) /* Transfer Error Interrupt */
40 #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */
41 #define STM32_DMA_FEI BIT(0) /* FIFO Error Interrupt */
42 #define STM32_DMA_MASKI (STM32_DMA_TCI \
47 /* DMA Stream x Configuration Register */
48 #define STM32_DMA_SCR(x) (0x0010 + 0x18 * (x)) /* x = 0..7 */
49 #define STM32_DMA_SCR_REQ(n) ((n & 0x7) << 25)
50 #define STM32_DMA_SCR_MBURST_MASK GENMASK(24, 23)
51 #define STM32_DMA_SCR_MBURST(n) ((n & 0x3) << 23)
52 #define STM32_DMA_SCR_PBURST_MASK GENMASK(22, 21)
53 #define STM32_DMA_SCR_PBURST(n) ((n & 0x3) << 21)
54 #define STM32_DMA_SCR_PL_MASK GENMASK(17, 16)
55 #define STM32_DMA_SCR_PL(n) ((n & 0x3) << 16)
56 #define STM32_DMA_SCR_MSIZE_MASK GENMASK(14, 13)
57 #define STM32_DMA_SCR_MSIZE(n) ((n & 0x3) << 13)
58 #define STM32_DMA_SCR_PSIZE_MASK GENMASK(12, 11)
59 #define STM32_DMA_SCR_PSIZE(n) ((n & 0x3) << 11)
60 #define STM32_DMA_SCR_PSIZE_GET(n) ((n & STM32_DMA_SCR_PSIZE_MASK) >> 11)
61 #define STM32_DMA_SCR_DIR_MASK GENMASK(7, 6)
62 #define STM32_DMA_SCR_DIR(n) ((n & 0x3) << 6)
63 #define STM32_DMA_SCR_CT BIT(19) /* Target in double buffer */
64 #define STM32_DMA_SCR_DBM BIT(18) /* Double Buffer Mode */
65 #define STM32_DMA_SCR_PINCOS BIT(15) /* Peripheral inc offset size */
66 #define STM32_DMA_SCR_MINC BIT(10) /* Memory increment mode */
67 #define STM32_DMA_SCR_PINC BIT(9) /* Peripheral increment mode */
68 #define STM32_DMA_SCR_CIRC BIT(8) /* Circular mode */
69 #define STM32_DMA_SCR_PFCTRL BIT(5) /* Peripheral Flow Controller */
70 #define STM32_DMA_SCR_TCIE BIT(4) /* Transfer Complete Int Enable
72 #define STM32_DMA_SCR_TEIE BIT(2) /* Transfer Error Int Enable */
73 #define STM32_DMA_SCR_DMEIE BIT(1) /* Direct Mode Err Int Enable */
74 #define STM32_DMA_SCR_EN BIT(0) /* Stream Enable */
75 #define STM32_DMA_SCR_CFG_MASK (STM32_DMA_SCR_PINC \
76 | STM32_DMA_SCR_MINC \
77 | STM32_DMA_SCR_PINCOS \
78 | STM32_DMA_SCR_PL_MASK)
79 #define STM32_DMA_SCR_IRQ_MASK (STM32_DMA_SCR_TCIE \
80 | STM32_DMA_SCR_TEIE \
81 | STM32_DMA_SCR_DMEIE)
83 /* DMA Stream x number of data register */
84 #define STM32_DMA_SNDTR(x) (0x0014 + 0x18 * (x))
86 /* DMA stream peripheral address register */
87 #define STM32_DMA_SPAR(x) (0x0018 + 0x18 * (x))
89 /* DMA stream x memory 0 address register */
90 #define STM32_DMA_SM0AR(x) (0x001c + 0x18 * (x))
92 /* DMA stream x memory 1 address register */
93 #define STM32_DMA_SM1AR(x) (0x0020 + 0x18 * (x))
95 /* DMA stream x FIFO control register */
96 #define STM32_DMA_SFCR(x) (0x0024 + 0x18 * (x))
97 #define STM32_DMA_SFCR_FTH_MASK GENMASK(1, 0)
98 #define STM32_DMA_SFCR_FTH(n) (n & STM32_DMA_SFCR_FTH_MASK)
99 #define STM32_DMA_SFCR_FEIE BIT(7) /* FIFO error interrupt enable */
100 #define STM32_DMA_SFCR_DMDIS BIT(2) /* Direct mode disable */
101 #define STM32_DMA_SFCR_MASK (STM32_DMA_SFCR_FEIE \
102 | STM32_DMA_SFCR_DMDIS)
105 #define STM32_DMA_DEV_TO_MEM 0x00
106 #define STM32_DMA_MEM_TO_DEV 0x01
107 #define STM32_DMA_MEM_TO_MEM 0x02
109 /* DMA priority level */
110 #define STM32_DMA_PRIORITY_LOW 0x00
111 #define STM32_DMA_PRIORITY_MEDIUM 0x01
112 #define STM32_DMA_PRIORITY_HIGH 0x02
113 #define STM32_DMA_PRIORITY_VERY_HIGH 0x03
115 /* DMA FIFO threshold selection */
116 #define STM32_DMA_FIFO_THRESHOLD_1QUARTERFULL 0x00
117 #define STM32_DMA_FIFO_THRESHOLD_HALFFULL 0x01
118 #define STM32_DMA_FIFO_THRESHOLD_3QUARTERSFULL 0x02
119 #define STM32_DMA_FIFO_THRESHOLD_FULL 0x03
121 #define STM32_DMA_MAX_DATA_ITEMS 0xffff
123 * Valid transfer starts from @0 to @0xFFFE leading to unaligned scatter
124 * gather at boundary. Thus it's safer to round down this value on FIFO
127 #define STM32_DMA_ALIGNED_MAX_DATA_ITEMS \
128 ALIGN_DOWN(STM32_DMA_MAX_DATA_ITEMS, 16)
129 #define STM32_DMA_MAX_CHANNELS 0x08
130 #define STM32_DMA_MAX_REQUEST_ID 0x08
131 #define STM32_DMA_MAX_DATA_PARAM 0x03
132 #define STM32_DMA_FIFO_SIZE 16 /* FIFO is 16 bytes */
133 #define STM32_DMA_MIN_BURST 4
134 #define STM32_DMA_MAX_BURST 16
137 #define STM32_DMA_THRESHOLD_FTR_MASK GENMASK(1, 0)
138 #define STM32_DMA_THRESHOLD_FTR_GET(n) ((n) & STM32_DMA_THRESHOLD_FTR_MASK)
140 enum stm32_dma_width {
146 enum stm32_dma_burst_size {
147 STM32_DMA_BURST_SINGLE,
148 STM32_DMA_BURST_INCR4,
149 STM32_DMA_BURST_INCR8,
150 STM32_DMA_BURST_INCR16,
154 * struct stm32_dma_cfg - STM32 DMA custom configuration
155 * @channel_id: channel ID
156 * @request_line: DMA request
157 * @stream_config: 32bit mask specifying the DMA channel configuration
158 * @features: 32bit mask specifying the DMA Feature list
160 struct stm32_dma_cfg {
167 struct stm32_dma_chan_reg {
180 struct stm32_dma_sg_req {
182 struct stm32_dma_chan_reg chan_reg;
185 struct stm32_dma_desc {
186 struct virt_dma_desc vdesc;
189 struct stm32_dma_sg_req sg_req[];
192 struct stm32_dma_chan {
193 struct virt_dma_chan vchan;
198 struct stm32_dma_desc *desc;
200 struct dma_slave_config dma_sconfig;
201 struct stm32_dma_chan_reg chan_reg;
207 struct stm32_dma_device {
208 struct dma_device ddev;
211 struct reset_control *rst;
213 struct stm32_dma_chan chan[STM32_DMA_MAX_CHANNELS];
216 static struct stm32_dma_device *stm32_dma_get_dev(struct stm32_dma_chan *chan)
218 return container_of(chan->vchan.chan.device, struct stm32_dma_device,
222 static struct stm32_dma_chan *to_stm32_dma_chan(struct dma_chan *c)
224 return container_of(c, struct stm32_dma_chan, vchan.chan);
227 static struct stm32_dma_desc *to_stm32_dma_desc(struct virt_dma_desc *vdesc)
229 return container_of(vdesc, struct stm32_dma_desc, vdesc);
232 static struct device *chan2dev(struct stm32_dma_chan *chan)
234 return &chan->vchan.chan.dev->device;
237 static u32 stm32_dma_read(struct stm32_dma_device *dmadev, u32 reg)
239 return readl_relaxed(dmadev->base + reg);
242 static void stm32_dma_write(struct stm32_dma_device *dmadev, u32 reg, u32 val)
244 writel_relaxed(val, dmadev->base + reg);
247 static struct stm32_dma_desc *stm32_dma_alloc_desc(u32 num_sgs)
249 return kzalloc(sizeof(struct stm32_dma_desc) +
250 sizeof(struct stm32_dma_sg_req) * num_sgs, GFP_NOWAIT);
253 static int stm32_dma_get_width(struct stm32_dma_chan *chan,
254 enum dma_slave_buswidth width)
257 case DMA_SLAVE_BUSWIDTH_1_BYTE:
258 return STM32_DMA_BYTE;
259 case DMA_SLAVE_BUSWIDTH_2_BYTES:
260 return STM32_DMA_HALF_WORD;
261 case DMA_SLAVE_BUSWIDTH_4_BYTES:
262 return STM32_DMA_WORD;
264 dev_err(chan2dev(chan), "Dma bus width not supported\n");
269 static enum dma_slave_buswidth stm32_dma_get_max_width(u32 buf_len,
272 enum dma_slave_buswidth max_width;
274 if (threshold == STM32_DMA_FIFO_THRESHOLD_FULL)
275 max_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
277 max_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
279 while ((buf_len < max_width || buf_len % max_width) &&
280 max_width > DMA_SLAVE_BUSWIDTH_1_BYTE)
281 max_width = max_width >> 1;
286 static bool stm32_dma_fifo_threshold_is_allowed(u32 burst, u32 threshold,
287 enum dma_slave_buswidth width)
291 if (width != DMA_SLAVE_BUSWIDTH_UNDEFINED) {
294 * If number of beats fit in several whole bursts
295 * this configuration is allowed.
297 remaining = ((STM32_DMA_FIFO_SIZE / width) *
298 (threshold + 1) / 4) % burst;
310 static bool stm32_dma_is_burst_possible(u32 buf_len, u32 threshold)
313 * Buffer or period length has to be aligned on FIFO depth.
314 * Otherwise bytes may be stuck within FIFO at buffer or period
317 return ((buf_len % ((threshold + 1) * 4)) == 0);
320 static u32 stm32_dma_get_best_burst(u32 buf_len, u32 max_burst, u32 threshold,
321 enum dma_slave_buswidth width)
323 u32 best_burst = max_burst;
325 if (best_burst == 1 || !stm32_dma_is_burst_possible(buf_len, threshold))
328 while ((buf_len < best_burst * width && best_burst > 1) ||
329 !stm32_dma_fifo_threshold_is_allowed(best_burst, threshold,
331 if (best_burst > STM32_DMA_MIN_BURST)
332 best_burst = best_burst >> 1;
340 static int stm32_dma_get_burst(struct stm32_dma_chan *chan, u32 maxburst)
345 return STM32_DMA_BURST_SINGLE;
347 return STM32_DMA_BURST_INCR4;
349 return STM32_DMA_BURST_INCR8;
351 return STM32_DMA_BURST_INCR16;
353 dev_err(chan2dev(chan), "Dma burst size not supported\n");
358 static void stm32_dma_set_fifo_config(struct stm32_dma_chan *chan,
359 u32 src_burst, u32 dst_burst)
361 chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_MASK;
362 chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_DMEIE;
364 if (!src_burst && !dst_burst) {
365 /* Using direct mode */
366 chan->chan_reg.dma_scr |= STM32_DMA_SCR_DMEIE;
368 /* Using FIFO mode */
369 chan->chan_reg.dma_sfcr |= STM32_DMA_SFCR_MASK;
373 static int stm32_dma_slave_config(struct dma_chan *c,
374 struct dma_slave_config *config)
376 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
378 memcpy(&chan->dma_sconfig, config, sizeof(*config));
380 chan->config_init = true;
385 static u32 stm32_dma_irq_status(struct stm32_dma_chan *chan)
387 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
391 * Read "flags" from DMA_xISR register corresponding to the selected
392 * DMA channel at the correct bit offset inside that register.
394 * If (ch % 4) is 2 or 3, left shift the mask by 16 bits.
395 * If (ch % 4) is 1 or 3, additionally left shift the mask by 6 bits.
399 dma_isr = stm32_dma_read(dmadev, STM32_DMA_HISR);
401 dma_isr = stm32_dma_read(dmadev, STM32_DMA_LISR);
403 flags = dma_isr >> (((chan->id & 2) << 3) | ((chan->id & 1) * 6));
405 return flags & STM32_DMA_MASKI;
408 static void stm32_dma_irq_clear(struct stm32_dma_chan *chan, u32 flags)
410 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
414 * Write "flags" to the DMA_xIFCR register corresponding to the selected
415 * DMA channel at the correct bit offset inside that register.
417 * If (ch % 4) is 2 or 3, left shift the mask by 16 bits.
418 * If (ch % 4) is 1 or 3, additionally left shift the mask by 6 bits.
420 flags &= STM32_DMA_MASKI;
421 dma_ifcr = flags << (((chan->id & 2) << 3) | ((chan->id & 1) * 6));
424 stm32_dma_write(dmadev, STM32_DMA_HIFCR, dma_ifcr);
426 stm32_dma_write(dmadev, STM32_DMA_LIFCR, dma_ifcr);
429 static int stm32_dma_disable_chan(struct stm32_dma_chan *chan)
431 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
432 unsigned long timeout = jiffies + msecs_to_jiffies(5000);
436 dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(id));
438 if (dma_scr & STM32_DMA_SCR_EN) {
439 dma_scr &= ~STM32_DMA_SCR_EN;
440 stm32_dma_write(dmadev, STM32_DMA_SCR(id), dma_scr);
443 dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(id));
444 dma_scr &= STM32_DMA_SCR_EN;
448 if (time_after_eq(jiffies, timeout)) {
449 dev_err(chan2dev(chan), "%s: timeout!\n",
460 static void stm32_dma_stop(struct stm32_dma_chan *chan)
462 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
463 u32 dma_scr, dma_sfcr, status;
466 /* Disable interrupts */
467 dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
468 dma_scr &= ~STM32_DMA_SCR_IRQ_MASK;
469 stm32_dma_write(dmadev, STM32_DMA_SCR(chan->id), dma_scr);
470 dma_sfcr = stm32_dma_read(dmadev, STM32_DMA_SFCR(chan->id));
471 dma_sfcr &= ~STM32_DMA_SFCR_FEIE;
472 stm32_dma_write(dmadev, STM32_DMA_SFCR(chan->id), dma_sfcr);
475 ret = stm32_dma_disable_chan(chan);
479 /* Clear interrupt status if it is there */
480 status = stm32_dma_irq_status(chan);
482 dev_dbg(chan2dev(chan), "%s(): clearing interrupt: 0x%08x\n",
484 stm32_dma_irq_clear(chan, status);
490 static int stm32_dma_terminate_all(struct dma_chan *c)
492 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
496 spin_lock_irqsave(&chan->vchan.lock, flags);
499 stm32_dma_stop(chan);
503 vchan_get_all_descriptors(&chan->vchan, &head);
504 spin_unlock_irqrestore(&chan->vchan.lock, flags);
505 vchan_dma_desc_free_list(&chan->vchan, &head);
510 static void stm32_dma_synchronize(struct dma_chan *c)
512 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
514 vchan_synchronize(&chan->vchan);
517 static void stm32_dma_dump_reg(struct stm32_dma_chan *chan)
519 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
520 u32 scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
521 u32 ndtr = stm32_dma_read(dmadev, STM32_DMA_SNDTR(chan->id));
522 u32 spar = stm32_dma_read(dmadev, STM32_DMA_SPAR(chan->id));
523 u32 sm0ar = stm32_dma_read(dmadev, STM32_DMA_SM0AR(chan->id));
524 u32 sm1ar = stm32_dma_read(dmadev, STM32_DMA_SM1AR(chan->id));
525 u32 sfcr = stm32_dma_read(dmadev, STM32_DMA_SFCR(chan->id));
527 dev_dbg(chan2dev(chan), "SCR: 0x%08x\n", scr);
528 dev_dbg(chan2dev(chan), "NDTR: 0x%08x\n", ndtr);
529 dev_dbg(chan2dev(chan), "SPAR: 0x%08x\n", spar);
530 dev_dbg(chan2dev(chan), "SM0AR: 0x%08x\n", sm0ar);
531 dev_dbg(chan2dev(chan), "SM1AR: 0x%08x\n", sm1ar);
532 dev_dbg(chan2dev(chan), "SFCR: 0x%08x\n", sfcr);
535 static void stm32_dma_configure_next_sg(struct stm32_dma_chan *chan);
537 static void stm32_dma_start_transfer(struct stm32_dma_chan *chan)
539 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
540 struct virt_dma_desc *vdesc;
541 struct stm32_dma_sg_req *sg_req;
542 struct stm32_dma_chan_reg *reg;
546 ret = stm32_dma_disable_chan(chan);
551 vdesc = vchan_next_desc(&chan->vchan);
555 chan->desc = to_stm32_dma_desc(vdesc);
559 if (chan->next_sg == chan->desc->num_sgs)
562 sg_req = &chan->desc->sg_req[chan->next_sg];
563 reg = &sg_req->chan_reg;
565 stm32_dma_write(dmadev, STM32_DMA_SCR(chan->id), reg->dma_scr);
566 stm32_dma_write(dmadev, STM32_DMA_SPAR(chan->id), reg->dma_spar);
567 stm32_dma_write(dmadev, STM32_DMA_SM0AR(chan->id), reg->dma_sm0ar);
568 stm32_dma_write(dmadev, STM32_DMA_SFCR(chan->id), reg->dma_sfcr);
569 stm32_dma_write(dmadev, STM32_DMA_SM1AR(chan->id), reg->dma_sm1ar);
570 stm32_dma_write(dmadev, STM32_DMA_SNDTR(chan->id), reg->dma_sndtr);
574 /* Clear interrupt status if it is there */
575 status = stm32_dma_irq_status(chan);
577 stm32_dma_irq_clear(chan, status);
579 if (chan->desc->cyclic)
580 stm32_dma_configure_next_sg(chan);
582 stm32_dma_dump_reg(chan);
585 reg->dma_scr |= STM32_DMA_SCR_EN;
586 stm32_dma_write(dmadev, STM32_DMA_SCR(chan->id), reg->dma_scr);
590 dev_dbg(chan2dev(chan), "vchan %pK: started\n", &chan->vchan);
593 static void stm32_dma_configure_next_sg(struct stm32_dma_chan *chan)
595 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
596 struct stm32_dma_sg_req *sg_req;
597 u32 dma_scr, dma_sm0ar, dma_sm1ar, id;
600 dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(id));
602 if (dma_scr & STM32_DMA_SCR_DBM) {
603 if (chan->next_sg == chan->desc->num_sgs)
606 sg_req = &chan->desc->sg_req[chan->next_sg];
608 if (dma_scr & STM32_DMA_SCR_CT) {
609 dma_sm0ar = sg_req->chan_reg.dma_sm0ar;
610 stm32_dma_write(dmadev, STM32_DMA_SM0AR(id), dma_sm0ar);
611 dev_dbg(chan2dev(chan), "CT=1 <=> SM0AR: 0x%08x\n",
612 stm32_dma_read(dmadev, STM32_DMA_SM0AR(id)));
614 dma_sm1ar = sg_req->chan_reg.dma_sm1ar;
615 stm32_dma_write(dmadev, STM32_DMA_SM1AR(id), dma_sm1ar);
616 dev_dbg(chan2dev(chan), "CT=0 <=> SM1AR: 0x%08x\n",
617 stm32_dma_read(dmadev, STM32_DMA_SM1AR(id)));
622 static void stm32_dma_handle_chan_done(struct stm32_dma_chan *chan)
625 if (chan->desc->cyclic) {
626 vchan_cyclic_callback(&chan->desc->vdesc);
628 stm32_dma_configure_next_sg(chan);
631 if (chan->next_sg == chan->desc->num_sgs) {
632 list_del(&chan->desc->vdesc.node);
633 vchan_cookie_complete(&chan->desc->vdesc);
636 stm32_dma_start_transfer(chan);
641 static irqreturn_t stm32_dma_chan_irq(int irq, void *devid)
643 struct stm32_dma_chan *chan = devid;
644 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
645 u32 status, scr, sfcr;
647 spin_lock(&chan->vchan.lock);
649 status = stm32_dma_irq_status(chan);
650 scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
651 sfcr = stm32_dma_read(dmadev, STM32_DMA_SFCR(chan->id));
653 if (status & STM32_DMA_TCI) {
654 stm32_dma_irq_clear(chan, STM32_DMA_TCI);
655 if (scr & STM32_DMA_SCR_TCIE)
656 stm32_dma_handle_chan_done(chan);
657 status &= ~STM32_DMA_TCI;
659 if (status & STM32_DMA_HTI) {
660 stm32_dma_irq_clear(chan, STM32_DMA_HTI);
661 status &= ~STM32_DMA_HTI;
663 if (status & STM32_DMA_FEI) {
664 stm32_dma_irq_clear(chan, STM32_DMA_FEI);
665 status &= ~STM32_DMA_FEI;
666 if (sfcr & STM32_DMA_SFCR_FEIE) {
667 if (!(scr & STM32_DMA_SCR_EN))
668 dev_err(chan2dev(chan), "FIFO Error\n");
670 dev_dbg(chan2dev(chan), "FIFO over/underrun\n");
674 stm32_dma_irq_clear(chan, status);
675 dev_err(chan2dev(chan), "DMA error: status=0x%08x\n", status);
676 if (!(scr & STM32_DMA_SCR_EN))
677 dev_err(chan2dev(chan), "chan disabled by HW\n");
680 spin_unlock(&chan->vchan.lock);
685 static void stm32_dma_issue_pending(struct dma_chan *c)
687 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
690 spin_lock_irqsave(&chan->vchan.lock, flags);
691 if (vchan_issue_pending(&chan->vchan) && !chan->desc && !chan->busy) {
692 dev_dbg(chan2dev(chan), "vchan %pK: issued\n", &chan->vchan);
693 stm32_dma_start_transfer(chan);
696 spin_unlock_irqrestore(&chan->vchan.lock, flags);
699 static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
700 enum dma_transfer_direction direction,
701 enum dma_slave_buswidth *buswidth,
704 enum dma_slave_buswidth src_addr_width, dst_addr_width;
705 int src_bus_width, dst_bus_width;
706 int src_burst_size, dst_burst_size;
707 u32 src_maxburst, dst_maxburst, src_best_burst, dst_best_burst;
708 u32 dma_scr, threshold;
710 src_addr_width = chan->dma_sconfig.src_addr_width;
711 dst_addr_width = chan->dma_sconfig.dst_addr_width;
712 src_maxburst = chan->dma_sconfig.src_maxburst;
713 dst_maxburst = chan->dma_sconfig.dst_maxburst;
714 threshold = chan->threshold;
718 /* Set device data size */
719 dst_bus_width = stm32_dma_get_width(chan, dst_addr_width);
720 if (dst_bus_width < 0)
721 return dst_bus_width;
723 /* Set device burst size */
724 dst_best_burst = stm32_dma_get_best_burst(buf_len,
729 dst_burst_size = stm32_dma_get_burst(chan, dst_best_burst);
730 if (dst_burst_size < 0)
731 return dst_burst_size;
733 /* Set memory data size */
734 src_addr_width = stm32_dma_get_max_width(buf_len, threshold);
735 chan->mem_width = src_addr_width;
736 src_bus_width = stm32_dma_get_width(chan, src_addr_width);
737 if (src_bus_width < 0)
738 return src_bus_width;
740 /* Set memory burst size */
741 src_maxburst = STM32_DMA_MAX_BURST;
742 src_best_burst = stm32_dma_get_best_burst(buf_len,
746 src_burst_size = stm32_dma_get_burst(chan, src_best_burst);
747 if (src_burst_size < 0)
748 return src_burst_size;
750 dma_scr = STM32_DMA_SCR_DIR(STM32_DMA_MEM_TO_DEV) |
751 STM32_DMA_SCR_PSIZE(dst_bus_width) |
752 STM32_DMA_SCR_MSIZE(src_bus_width) |
753 STM32_DMA_SCR_PBURST(dst_burst_size) |
754 STM32_DMA_SCR_MBURST(src_burst_size);
756 /* Set FIFO threshold */
757 chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_FTH_MASK;
758 chan->chan_reg.dma_sfcr |= STM32_DMA_SFCR_FTH(threshold);
760 /* Set peripheral address */
761 chan->chan_reg.dma_spar = chan->dma_sconfig.dst_addr;
762 *buswidth = dst_addr_width;
766 /* Set device data size */
767 src_bus_width = stm32_dma_get_width(chan, src_addr_width);
768 if (src_bus_width < 0)
769 return src_bus_width;
771 /* Set device burst size */
772 src_best_burst = stm32_dma_get_best_burst(buf_len,
776 chan->mem_burst = src_best_burst;
777 src_burst_size = stm32_dma_get_burst(chan, src_best_burst);
778 if (src_burst_size < 0)
779 return src_burst_size;
781 /* Set memory data size */
782 dst_addr_width = stm32_dma_get_max_width(buf_len, threshold);
783 chan->mem_width = dst_addr_width;
784 dst_bus_width = stm32_dma_get_width(chan, dst_addr_width);
785 if (dst_bus_width < 0)
786 return dst_bus_width;
788 /* Set memory burst size */
789 dst_maxburst = STM32_DMA_MAX_BURST;
790 dst_best_burst = stm32_dma_get_best_burst(buf_len,
794 chan->mem_burst = dst_best_burst;
795 dst_burst_size = stm32_dma_get_burst(chan, dst_best_burst);
796 if (dst_burst_size < 0)
797 return dst_burst_size;
799 dma_scr = STM32_DMA_SCR_DIR(STM32_DMA_DEV_TO_MEM) |
800 STM32_DMA_SCR_PSIZE(src_bus_width) |
801 STM32_DMA_SCR_MSIZE(dst_bus_width) |
802 STM32_DMA_SCR_PBURST(src_burst_size) |
803 STM32_DMA_SCR_MBURST(dst_burst_size);
805 /* Set FIFO threshold */
806 chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_FTH_MASK;
807 chan->chan_reg.dma_sfcr |= STM32_DMA_SFCR_FTH(threshold);
809 /* Set peripheral address */
810 chan->chan_reg.dma_spar = chan->dma_sconfig.src_addr;
811 *buswidth = chan->dma_sconfig.src_addr_width;
815 dev_err(chan2dev(chan), "Dma direction is not supported\n");
819 stm32_dma_set_fifo_config(chan, src_best_burst, dst_best_burst);
821 /* Set DMA control register */
822 chan->chan_reg.dma_scr &= ~(STM32_DMA_SCR_DIR_MASK |
823 STM32_DMA_SCR_PSIZE_MASK | STM32_DMA_SCR_MSIZE_MASK |
824 STM32_DMA_SCR_PBURST_MASK | STM32_DMA_SCR_MBURST_MASK);
825 chan->chan_reg.dma_scr |= dma_scr;
830 static void stm32_dma_clear_reg(struct stm32_dma_chan_reg *regs)
832 memset(regs, 0, sizeof(struct stm32_dma_chan_reg));
835 static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg(
836 struct dma_chan *c, struct scatterlist *sgl,
837 u32 sg_len, enum dma_transfer_direction direction,
838 unsigned long flags, void *context)
840 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
841 struct stm32_dma_desc *desc;
842 struct scatterlist *sg;
843 enum dma_slave_buswidth buswidth;
847 if (!chan->config_init) {
848 dev_err(chan2dev(chan), "dma channel is not configured\n");
853 dev_err(chan2dev(chan), "Invalid segment length %d\n", sg_len);
857 desc = stm32_dma_alloc_desc(sg_len);
861 /* Set peripheral flow controller */
862 if (chan->dma_sconfig.device_fc)
863 chan->chan_reg.dma_scr |= STM32_DMA_SCR_PFCTRL;
865 chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_PFCTRL;
867 for_each_sg(sgl, sg, sg_len, i) {
868 ret = stm32_dma_set_xfer_param(chan, direction, &buswidth,
873 desc->sg_req[i].len = sg_dma_len(sg);
875 nb_data_items = desc->sg_req[i].len / buswidth;
876 if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) {
877 dev_err(chan2dev(chan), "nb items not supported\n");
881 stm32_dma_clear_reg(&desc->sg_req[i].chan_reg);
882 desc->sg_req[i].chan_reg.dma_scr = chan->chan_reg.dma_scr;
883 desc->sg_req[i].chan_reg.dma_sfcr = chan->chan_reg.dma_sfcr;
884 desc->sg_req[i].chan_reg.dma_spar = chan->chan_reg.dma_spar;
885 desc->sg_req[i].chan_reg.dma_sm0ar = sg_dma_address(sg);
886 desc->sg_req[i].chan_reg.dma_sm1ar = sg_dma_address(sg);
887 desc->sg_req[i].chan_reg.dma_sndtr = nb_data_items;
890 desc->num_sgs = sg_len;
891 desc->cyclic = false;
893 return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
900 static struct dma_async_tx_descriptor *stm32_dma_prep_dma_cyclic(
901 struct dma_chan *c, dma_addr_t buf_addr, size_t buf_len,
902 size_t period_len, enum dma_transfer_direction direction,
905 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
906 struct stm32_dma_desc *desc;
907 enum dma_slave_buswidth buswidth;
908 u32 num_periods, nb_data_items;
911 if (!buf_len || !period_len) {
912 dev_err(chan2dev(chan), "Invalid buffer/period len\n");
916 if (!chan->config_init) {
917 dev_err(chan2dev(chan), "dma channel is not configured\n");
921 if (buf_len % period_len) {
922 dev_err(chan2dev(chan), "buf_len not multiple of period_len\n");
927 * We allow to take more number of requests till DMA is
928 * not started. The driver will loop over all requests.
929 * Once DMA is started then new requests can be queued only after
930 * terminating the DMA.
933 dev_err(chan2dev(chan), "Request not allowed when dma busy\n");
937 ret = stm32_dma_set_xfer_param(chan, direction, &buswidth, period_len);
941 nb_data_items = period_len / buswidth;
942 if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) {
943 dev_err(chan2dev(chan), "number of items not supported\n");
947 /* Enable Circular mode or double buffer mode */
948 if (buf_len == period_len)
949 chan->chan_reg.dma_scr |= STM32_DMA_SCR_CIRC;
951 chan->chan_reg.dma_scr |= STM32_DMA_SCR_DBM;
953 /* Clear periph ctrl if client set it */
954 chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_PFCTRL;
956 num_periods = buf_len / period_len;
958 desc = stm32_dma_alloc_desc(num_periods);
962 for (i = 0; i < num_periods; i++) {
963 desc->sg_req[i].len = period_len;
965 stm32_dma_clear_reg(&desc->sg_req[i].chan_reg);
966 desc->sg_req[i].chan_reg.dma_scr = chan->chan_reg.dma_scr;
967 desc->sg_req[i].chan_reg.dma_sfcr = chan->chan_reg.dma_sfcr;
968 desc->sg_req[i].chan_reg.dma_spar = chan->chan_reg.dma_spar;
969 desc->sg_req[i].chan_reg.dma_sm0ar = buf_addr;
970 desc->sg_req[i].chan_reg.dma_sm1ar = buf_addr;
971 desc->sg_req[i].chan_reg.dma_sndtr = nb_data_items;
972 buf_addr += period_len;
975 desc->num_sgs = num_periods;
978 return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
981 static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
982 struct dma_chan *c, dma_addr_t dest,
983 dma_addr_t src, size_t len, unsigned long flags)
985 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
986 enum dma_slave_buswidth max_width;
987 struct stm32_dma_desc *desc;
988 size_t xfer_count, offset;
989 u32 num_sgs, best_burst, dma_burst, threshold;
992 num_sgs = DIV_ROUND_UP(len, STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
993 desc = stm32_dma_alloc_desc(num_sgs);
997 threshold = chan->threshold;
999 for (offset = 0, i = 0; offset < len; offset += xfer_count, i++) {
1000 xfer_count = min_t(size_t, len - offset,
1001 STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
1003 /* Compute best burst size */
1004 max_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
1005 best_burst = stm32_dma_get_best_burst(len, STM32_DMA_MAX_BURST,
1006 threshold, max_width);
1007 dma_burst = stm32_dma_get_burst(chan, best_burst);
1009 stm32_dma_clear_reg(&desc->sg_req[i].chan_reg);
1010 desc->sg_req[i].chan_reg.dma_scr =
1011 STM32_DMA_SCR_DIR(STM32_DMA_MEM_TO_MEM) |
1012 STM32_DMA_SCR_PBURST(dma_burst) |
1013 STM32_DMA_SCR_MBURST(dma_burst) |
1014 STM32_DMA_SCR_MINC |
1015 STM32_DMA_SCR_PINC |
1016 STM32_DMA_SCR_TCIE |
1018 desc->sg_req[i].chan_reg.dma_sfcr |= STM32_DMA_SFCR_MASK;
1019 desc->sg_req[i].chan_reg.dma_sfcr |=
1020 STM32_DMA_SFCR_FTH(threshold);
1021 desc->sg_req[i].chan_reg.dma_spar = src + offset;
1022 desc->sg_req[i].chan_reg.dma_sm0ar = dest + offset;
1023 desc->sg_req[i].chan_reg.dma_sndtr = xfer_count;
1024 desc->sg_req[i].len = xfer_count;
1027 desc->num_sgs = num_sgs;
1028 desc->cyclic = false;
1030 return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
1033 static u32 stm32_dma_get_remaining_bytes(struct stm32_dma_chan *chan)
1035 u32 dma_scr, width, ndtr;
1036 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
1038 dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
1039 width = STM32_DMA_SCR_PSIZE_GET(dma_scr);
1040 ndtr = stm32_dma_read(dmadev, STM32_DMA_SNDTR(chan->id));
1042 return ndtr << width;
1045 static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan,
1046 struct stm32_dma_desc *desc,
1049 u32 modulo, burst_size;
1054 * In cyclic mode, for the last period, residue = remaining bytes from
1057 if (chan->desc->cyclic && next_sg == 0) {
1058 residue = stm32_dma_get_remaining_bytes(chan);
1063 * For all other periods in cyclic mode, and in sg mode,
1064 * residue = remaining bytes from NDTR + remaining periods/sg to be
1067 for (i = next_sg; i < desc->num_sgs; i++)
1068 residue += desc->sg_req[i].len;
1069 residue += stm32_dma_get_remaining_bytes(chan);
1072 if (!chan->mem_burst)
1075 burst_size = chan->mem_burst * chan->mem_width;
1076 modulo = residue % burst_size;
1078 residue = residue - modulo + burst_size;
1083 static enum dma_status stm32_dma_tx_status(struct dma_chan *c,
1084 dma_cookie_t cookie,
1085 struct dma_tx_state *state)
1087 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
1088 struct virt_dma_desc *vdesc;
1089 enum dma_status status;
1090 unsigned long flags;
1093 status = dma_cookie_status(c, cookie, state);
1094 if (status == DMA_COMPLETE || !state)
1097 spin_lock_irqsave(&chan->vchan.lock, flags);
1098 vdesc = vchan_find_desc(&chan->vchan, cookie);
1099 if (chan->desc && cookie == chan->desc->vdesc.tx.cookie)
1100 residue = stm32_dma_desc_residue(chan, chan->desc,
1103 residue = stm32_dma_desc_residue(chan,
1104 to_stm32_dma_desc(vdesc), 0);
1105 dma_set_residue(state, residue);
1107 spin_unlock_irqrestore(&chan->vchan.lock, flags);
1112 static int stm32_dma_alloc_chan_resources(struct dma_chan *c)
1114 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
1115 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
1118 chan->config_init = false;
1120 ret = pm_runtime_get_sync(dmadev->ddev.dev);
1124 ret = stm32_dma_disable_chan(chan);
1126 pm_runtime_put(dmadev->ddev.dev);
1131 static void stm32_dma_free_chan_resources(struct dma_chan *c)
1133 struct stm32_dma_chan *chan = to_stm32_dma_chan(c);
1134 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
1135 unsigned long flags;
1137 dev_dbg(chan2dev(chan), "Freeing channel %d\n", chan->id);
1140 spin_lock_irqsave(&chan->vchan.lock, flags);
1141 stm32_dma_stop(chan);
1143 spin_unlock_irqrestore(&chan->vchan.lock, flags);
1146 pm_runtime_put(dmadev->ddev.dev);
1148 vchan_free_chan_resources(to_virt_chan(c));
1151 static void stm32_dma_desc_free(struct virt_dma_desc *vdesc)
1153 kfree(container_of(vdesc, struct stm32_dma_desc, vdesc));
1156 static void stm32_dma_set_config(struct stm32_dma_chan *chan,
1157 struct stm32_dma_cfg *cfg)
1159 stm32_dma_clear_reg(&chan->chan_reg);
1161 chan->chan_reg.dma_scr = cfg->stream_config & STM32_DMA_SCR_CFG_MASK;
1162 chan->chan_reg.dma_scr |= STM32_DMA_SCR_REQ(cfg->request_line);
1164 /* Enable Interrupts */
1165 chan->chan_reg.dma_scr |= STM32_DMA_SCR_TEIE | STM32_DMA_SCR_TCIE;
1167 chan->threshold = STM32_DMA_THRESHOLD_FTR_GET(cfg->features);
1170 static struct dma_chan *stm32_dma_of_xlate(struct of_phandle_args *dma_spec,
1171 struct of_dma *ofdma)
1173 struct stm32_dma_device *dmadev = ofdma->of_dma_data;
1174 struct device *dev = dmadev->ddev.dev;
1175 struct stm32_dma_cfg cfg;
1176 struct stm32_dma_chan *chan;
1179 if (dma_spec->args_count < 4) {
1180 dev_err(dev, "Bad number of cells\n");
1184 cfg.channel_id = dma_spec->args[0];
1185 cfg.request_line = dma_spec->args[1];
1186 cfg.stream_config = dma_spec->args[2];
1187 cfg.features = dma_spec->args[3];
1189 if (cfg.channel_id >= STM32_DMA_MAX_CHANNELS ||
1190 cfg.request_line >= STM32_DMA_MAX_REQUEST_ID) {
1191 dev_err(dev, "Bad channel and/or request id\n");
1195 chan = &dmadev->chan[cfg.channel_id];
1197 c = dma_get_slave_channel(&chan->vchan.chan);
1199 dev_err(dev, "No more channels available\n");
1203 stm32_dma_set_config(chan, &cfg);
1208 static const struct of_device_id stm32_dma_of_match[] = {
1209 { .compatible = "st,stm32-dma", },
1212 MODULE_DEVICE_TABLE(of, stm32_dma_of_match);
1214 static int stm32_dma_probe(struct platform_device *pdev)
1216 struct stm32_dma_chan *chan;
1217 struct stm32_dma_device *dmadev;
1218 struct dma_device *dd;
1219 const struct of_device_id *match;
1220 struct resource *res;
1223 match = of_match_device(stm32_dma_of_match, &pdev->dev);
1225 dev_err(&pdev->dev, "Error: No device match found\n");
1229 dmadev = devm_kzalloc(&pdev->dev, sizeof(*dmadev), GFP_KERNEL);
1235 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1236 dmadev->base = devm_ioremap_resource(&pdev->dev, res);
1237 if (IS_ERR(dmadev->base))
1238 return PTR_ERR(dmadev->base);
1240 dmadev->clk = devm_clk_get(&pdev->dev, NULL);
1241 if (IS_ERR(dmadev->clk)) {
1242 dev_err(&pdev->dev, "Error: Missing controller clock\n");
1243 return PTR_ERR(dmadev->clk);
1246 ret = clk_prepare_enable(dmadev->clk);
1248 dev_err(&pdev->dev, "clk_prep_enable error: %d\n", ret);
1252 dmadev->mem2mem = of_property_read_bool(pdev->dev.of_node,
1255 dmadev->rst = devm_reset_control_get(&pdev->dev, NULL);
1256 if (!IS_ERR(dmadev->rst)) {
1257 reset_control_assert(dmadev->rst);
1259 reset_control_deassert(dmadev->rst);
1262 dma_cap_set(DMA_SLAVE, dd->cap_mask);
1263 dma_cap_set(DMA_PRIVATE, dd->cap_mask);
1264 dma_cap_set(DMA_CYCLIC, dd->cap_mask);
1265 dd->device_alloc_chan_resources = stm32_dma_alloc_chan_resources;
1266 dd->device_free_chan_resources = stm32_dma_free_chan_resources;
1267 dd->device_tx_status = stm32_dma_tx_status;
1268 dd->device_issue_pending = stm32_dma_issue_pending;
1269 dd->device_prep_slave_sg = stm32_dma_prep_slave_sg;
1270 dd->device_prep_dma_cyclic = stm32_dma_prep_dma_cyclic;
1271 dd->device_config = stm32_dma_slave_config;
1272 dd->device_terminate_all = stm32_dma_terminate_all;
1273 dd->device_synchronize = stm32_dma_synchronize;
1274 dd->src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
1275 BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
1276 BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
1277 dd->dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
1278 BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
1279 BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
1280 dd->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
1281 dd->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
1282 dd->max_burst = STM32_DMA_MAX_BURST;
1283 dd->dev = &pdev->dev;
1284 INIT_LIST_HEAD(&dd->channels);
1286 if (dmadev->mem2mem) {
1287 dma_cap_set(DMA_MEMCPY, dd->cap_mask);
1288 dd->device_prep_dma_memcpy = stm32_dma_prep_dma_memcpy;
1289 dd->directions |= BIT(DMA_MEM_TO_MEM);
1292 for (i = 0; i < STM32_DMA_MAX_CHANNELS; i++) {
1293 chan = &dmadev->chan[i];
1295 chan->vchan.desc_free = stm32_dma_desc_free;
1296 vchan_init(&chan->vchan, dd);
1299 ret = dma_async_device_register(dd);
1303 for (i = 0; i < STM32_DMA_MAX_CHANNELS; i++) {
1304 chan = &dmadev->chan[i];
1305 res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
1308 dev_err(&pdev->dev, "No irq resource for chan %d\n", i);
1309 goto err_unregister;
1311 chan->irq = res->start;
1312 ret = devm_request_irq(&pdev->dev, chan->irq,
1313 stm32_dma_chan_irq, 0,
1314 dev_name(chan2dev(chan)), chan);
1317 "request_irq failed with err %d channel %d\n",
1319 goto err_unregister;
1323 ret = of_dma_controller_register(pdev->dev.of_node,
1324 stm32_dma_of_xlate, dmadev);
1327 "STM32 DMA DMA OF registration failed %d\n", ret);
1328 goto err_unregister;
1331 platform_set_drvdata(pdev, dmadev);
1333 pm_runtime_set_active(&pdev->dev);
1334 pm_runtime_enable(&pdev->dev);
1335 pm_runtime_get_noresume(&pdev->dev);
1336 pm_runtime_put(&pdev->dev);
1338 dev_info(&pdev->dev, "STM32 DMA driver registered\n");
1343 dma_async_device_unregister(dd);
1345 clk_disable_unprepare(dmadev->clk);
1351 static int stm32_dma_runtime_suspend(struct device *dev)
1353 struct stm32_dma_device *dmadev = dev_get_drvdata(dev);
1355 clk_disable_unprepare(dmadev->clk);
1360 static int stm32_dma_runtime_resume(struct device *dev)
1362 struct stm32_dma_device *dmadev = dev_get_drvdata(dev);
1365 ret = clk_prepare_enable(dmadev->clk);
1367 dev_err(dev, "failed to prepare_enable clock\n");
1375 static const struct dev_pm_ops stm32_dma_pm_ops = {
1376 SET_RUNTIME_PM_OPS(stm32_dma_runtime_suspend,
1377 stm32_dma_runtime_resume, NULL)
1380 static struct platform_driver stm32_dma_driver = {
1382 .name = "stm32-dma",
1383 .of_match_table = stm32_dma_of_match,
1384 .pm = &stm32_dma_pm_ops,
1388 static int __init stm32_dma_init(void)
1390 return platform_driver_probe(&stm32_dma_driver, stm32_dma_probe);
1392 subsys_initcall(stm32_dma_init);