cd6e1004fb938188df69d4b7bdec6ff62ab7e815
[openwrt/staging/lynxis.git] / target / linux / mediatek / patches-4.14 / 0205-dmaengine-mediatek-Add-MediaTek-High-Speed-DMA-contr.patch
1 From 2b97c5d7886a920adc8f7c32c2a60583475654f2 Mon Sep 17 00:00:00 2001
2 From: Sean Wang <sean.wang@mediatek.com>
3 Date: Fri, 12 May 2017 17:05:12 +0800
4 Subject: [PATCH 205/224] dmaengine: mediatek: Add MediaTek High-Speed DMA
5 controller for MT7622 and MT7623 SoC
6
7 MediaTek High-Speed DMA controller (HSDMA) on MT7622 and MT7623 SoC has
8 a single ring is dedicated to memory-to-memory transfer through ring based
9 descriptor management.
10
11 Even though there is only one physical ring available inside HSDMA, the
12 driver can be easily extended to the support of multiple virtual channels
13 processing simultaneously by means of DMA_VIRTUAL_CHANNELS effort.
14
15 Signed-off-by: Sean Wang <sean.wang@mediatek.com>
16 Cc: Randy Dunlap <rdunlap@infradead.org>
17 Cc: Fengguang Wu <fengguang.wu@intel.com>
18 Cc: Julia Lawall <julia.lawall@lip6.fr>
19 ---
20 drivers/dma/Kconfig | 2 +
21 drivers/dma/Makefile | 1 +
22 drivers/dma/mediatek/Kconfig | 13 +
23 drivers/dma/mediatek/Makefile | 1 +
24 drivers/dma/mediatek/mtk-hsdma.c | 1056 ++++++++++++++++++++++++++++++++++++++
25 5 files changed, 1073 insertions(+)
26 create mode 100644 drivers/dma/mediatek/Kconfig
27 create mode 100644 drivers/dma/mediatek/Makefile
28 create mode 100644 drivers/dma/mediatek/mtk-hsdma.c
29
30 diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
31 index fadc4d8783bd..3100b6dfa6e8 100644
32 --- a/drivers/dma/Kconfig
33 +++ b/drivers/dma/Kconfig
34 @@ -604,6 +604,8 @@ config ZX_DMA
35 # driver files
36 source "drivers/dma/bestcomm/Kconfig"
37
38 +source "drivers/dma/mediatek/Kconfig"
39 +
40 source "drivers/dma/qcom/Kconfig"
41
42 source "drivers/dma/dw/Kconfig"
43 diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
44 index f08f8de1b567..26b0ef43a8f9 100644
45 --- a/drivers/dma/Makefile
46 +++ b/drivers/dma/Makefile
47 @@ -71,5 +71,6 @@ obj-$(CONFIG_XGENE_DMA) += xgene-dma.o
48 obj-$(CONFIG_ZX_DMA) += zx_dma.o
49 obj-$(CONFIG_ST_FDMA) += st_fdma.o
50
51 +obj-y += mediatek/
52 obj-y += qcom/
53 obj-y += xilinx/
54 diff --git a/drivers/dma/mediatek/Kconfig b/drivers/dma/mediatek/Kconfig
55 new file mode 100644
56 index 000000000000..27bac0bba09e
57 --- /dev/null
58 +++ b/drivers/dma/mediatek/Kconfig
59 @@ -0,0 +1,13 @@
60 +
61 +config MTK_HSDMA
62 + tristate "MediaTek High-Speed DMA controller support"
63 + depends on ARCH_MEDIATEK || COMPILE_TEST
64 + select DMA_ENGINE
65 + select DMA_VIRTUAL_CHANNELS
66 + ---help---
67 + Enable support for High-Speed DMA controller on MediaTek
68 + SoCs.
69 +
70 + This controller provides the channels which is dedicated to
71 + memory-to-memory transfer to offload from CPU through ring-
72 + based descriptor management.
73 diff --git a/drivers/dma/mediatek/Makefile b/drivers/dma/mediatek/Makefile
74 new file mode 100644
75 index 000000000000..6e778f842f01
76 --- /dev/null
77 +++ b/drivers/dma/mediatek/Makefile
78 @@ -0,0 +1 @@
79 +obj-$(CONFIG_MTK_HSDMA) += mtk-hsdma.o
80 diff --git a/drivers/dma/mediatek/mtk-hsdma.c b/drivers/dma/mediatek/mtk-hsdma.c
81 new file mode 100644
82 index 000000000000..b7ec56ae02a6
83 --- /dev/null
84 +++ b/drivers/dma/mediatek/mtk-hsdma.c
85 @@ -0,0 +1,1056 @@
86 +// SPDX-License-Identifier: GPL-2.0
87 +// Copyright (c) 2017-2018 MediaTek Inc.
88 +
89 +/*
90 + * Driver for MediaTek High-Speed DMA Controller
91 + *
92 + * Author: Sean Wang <sean.wang@mediatek.com>
93 + *
94 + */
95 +
96 +#include <linux/bitops.h>
97 +#include <linux/clk.h>
98 +#include <linux/dmaengine.h>
99 +#include <linux/dma-mapping.h>
100 +#include <linux/err.h>
101 +#include <linux/iopoll.h>
102 +#include <linux/list.h>
103 +#include <linux/module.h>
104 +#include <linux/of.h>
105 +#include <linux/of_device.h>
106 +#include <linux/of_dma.h>
107 +#include <linux/platform_device.h>
108 +#include <linux/pm_runtime.h>
109 +#include <linux/refcount.h>
110 +#include <linux/slab.h>
111 +
112 +#include "../virt-dma.h"
113 +
114 +#define MTK_HSDMA_USEC_POLL 20
115 +#define MTK_HSDMA_TIMEOUT_POLL 200000
116 +#define MTK_HSDMA_DMA_BUSWIDTHS BIT(DMA_SLAVE_BUSWIDTH_4_BYTES)
117 +
118 +/* The default number of virtual channel */
119 +#define MTK_HSDMA_NR_VCHANS 3
120 +
121 +/* Only one physical channel supported */
122 +#define MTK_HSDMA_NR_MAX_PCHANS 1
123 +
124 +/* Macro for physical descriptor (PD) manipulation */
125 +/* The number of PD which must be 2 of power */
126 +#define MTK_DMA_SIZE 64
127 +#define MTK_HSDMA_NEXT_DESP_IDX(x, y) (((x) + 1) & ((y) - 1))
128 +#define MTK_HSDMA_LAST_DESP_IDX(x, y) (((x) - 1) & ((y) - 1))
129 +#define MTK_HSDMA_MAX_LEN 0x3f80
130 +#define MTK_HSDMA_ALIGN_SIZE 4
131 +#define MTK_HSDMA_PLEN_MASK 0x3fff
132 +#define MTK_HSDMA_DESC_PLEN(x) (((x) & MTK_HSDMA_PLEN_MASK) << 16)
133 +#define MTK_HSDMA_DESC_PLEN_GET(x) (((x) >> 16) & MTK_HSDMA_PLEN_MASK)
134 +
135 +/* Registers for underlying ring manipulation */
136 +#define MTK_HSDMA_TX_BASE 0x0
137 +#define MTK_HSDMA_TX_CNT 0x4
138 +#define MTK_HSDMA_TX_CPU 0x8
139 +#define MTK_HSDMA_TX_DMA 0xc
140 +#define MTK_HSDMA_RX_BASE 0x100
141 +#define MTK_HSDMA_RX_CNT 0x104
142 +#define MTK_HSDMA_RX_CPU 0x108
143 +#define MTK_HSDMA_RX_DMA 0x10c
144 +
145 +/* Registers for global setup */
146 +#define MTK_HSDMA_GLO 0x204
147 +#define MTK_HSDMA_GLO_MULTI_DMA BIT(10)
148 +#define MTK_HSDMA_TX_WB_DDONE BIT(6)
149 +#define MTK_HSDMA_BURST_64BYTES (0x2 << 4)
150 +#define MTK_HSDMA_GLO_RX_BUSY BIT(3)
151 +#define MTK_HSDMA_GLO_RX_DMA BIT(2)
152 +#define MTK_HSDMA_GLO_TX_BUSY BIT(1)
153 +#define MTK_HSDMA_GLO_TX_DMA BIT(0)
154 +#define MTK_HSDMA_GLO_DMA (MTK_HSDMA_GLO_TX_DMA | \
155 + MTK_HSDMA_GLO_RX_DMA)
156 +#define MTK_HSDMA_GLO_BUSY (MTK_HSDMA_GLO_RX_BUSY | \
157 + MTK_HSDMA_GLO_TX_BUSY)
158 +#define MTK_HSDMA_GLO_DEFAULT (MTK_HSDMA_GLO_TX_DMA | \
159 + MTK_HSDMA_GLO_RX_DMA | \
160 + MTK_HSDMA_TX_WB_DDONE | \
161 + MTK_HSDMA_BURST_64BYTES | \
162 + MTK_HSDMA_GLO_MULTI_DMA)
163 +
164 +/* Registers for reset */
165 +#define MTK_HSDMA_RESET 0x208
166 +#define MTK_HSDMA_RST_TX BIT(0)
167 +#define MTK_HSDMA_RST_RX BIT(16)
168 +
169 +/* Registers for interrupt control */
170 +#define MTK_HSDMA_DLYINT 0x20c
171 +#define MTK_HSDMA_RXDLY_INT_EN BIT(15)
172 +
173 +/* Interrupt fires when the pending number's more than the specified */
174 +#define MTK_HSDMA_RXMAX_PINT(x) (((x) & 0x7f) << 8)
175 +
176 +/* Interrupt fires when the pending time's more than the specified in 20 us */
177 +#define MTK_HSDMA_RXMAX_PTIME(x) ((x) & 0x7f)
178 +#define MTK_HSDMA_DLYINT_DEFAULT (MTK_HSDMA_RXDLY_INT_EN | \
179 + MTK_HSDMA_RXMAX_PINT(20) | \
180 + MTK_HSDMA_RXMAX_PTIME(20))
181 +#define MTK_HSDMA_INT_STATUS 0x220
182 +#define MTK_HSDMA_INT_ENABLE 0x228
183 +#define MTK_HSDMA_INT_RXDONE BIT(16)
184 +
185 +enum mtk_hsdma_vdesc_flag {
186 + MTK_HSDMA_VDESC_FINISHED = 0x01,
187 +};
188 +
189 +#define IS_MTK_HSDMA_VDESC_FINISHED(x) ((x) == MTK_HSDMA_VDESC_FINISHED)
190 +
191 +/**
192 + * struct mtk_hsdma_pdesc - This is the struct holding info describing physical
193 + * descriptor (PD) and its placement must be kept at
194 + * 4-bytes alignment in little endian order.
195 + * @desc[1-4]: The control pad used to indicate hardware how to
196 + * deal with the descriptor such as source and
197 + * destination address and data length. The maximum
198 + * data length each pdesc can handle is 0x3f80 bytes
199 + */
200 +struct mtk_hsdma_pdesc {
201 + __le32 desc1;
202 + __le32 desc2;
203 + __le32 desc3;
204 + __le32 desc4;
205 +} __packed __aligned(4);
206 +
207 +/**
208 + * struct mtk_hsdma_vdesc - This is the struct holding info describing virtual
209 + * descriptor (VD)
210 + * @vd: An instance for struct virt_dma_desc
211 + * @len: The total data size device wants to move
212 + * @residue: The remaining data size device will move
213 + * @dest: The destination address device wants to move to
214 + * @src: The source address device wants to move from
215 + */
216 +struct mtk_hsdma_vdesc {
217 + struct virt_dma_desc vd;
218 + size_t len;
219 + size_t residue;
220 + dma_addr_t dest;
221 + dma_addr_t src;
222 +};
223 +
224 +/**
225 + * struct mtk_hsdma_cb - This is the struct holding extra info required for RX
226 + * ring to know what relevant VD the the PD is being
227 + * mapped to.
228 + * @vd: Pointer to the relevant VD.
229 + * @flag: Flag indicating what action should be taken when VD
230 + * is completed.
231 + */
232 +struct mtk_hsdma_cb {
233 + struct virt_dma_desc *vd;
234 + enum mtk_hsdma_vdesc_flag flag;
235 +};
236 +
237 +/**
238 + * struct mtk_hsdma_ring - This struct holds info describing underlying ring
239 + * space
240 + * @txd: The descriptor TX ring which describes DMA source
241 + * information
242 + * @rxd: The descriptor RX ring which describes DMA
243 + * destination information
244 + * @cb: The extra information pointed at by RX ring
245 + * @tphys: The physical addr of TX ring
246 + * @rphys: The physical addr of RX ring
247 + * @cur_tptr: Pointer to the next free descriptor used by the host
248 + * @cur_rptr: Pointer to the last done descriptor by the device
249 + */
250 +struct mtk_hsdma_ring {
251 + struct mtk_hsdma_pdesc *txd;
252 + struct mtk_hsdma_pdesc *rxd;
253 + struct mtk_hsdma_cb *cb;
254 + dma_addr_t tphys;
255 + dma_addr_t rphys;
256 + u16 cur_tptr;
257 + u16 cur_rptr;
258 +};
259 +
260 +/**
261 + * struct mtk_hsdma_pchan - This is the struct holding info describing physical
262 + * channel (PC)
263 + * @ring: An instance for the underlying ring
264 + * @sz_ring: Total size allocated for the ring
265 + * @nr_free: Total number of free rooms in the ring. It would
266 + * be accessed and updated frequently between IRQ
267 + * context and user context to reflect whether ring
268 + * can accept requests from VD.
269 + */
270 +struct mtk_hsdma_pchan {
271 + struct mtk_hsdma_ring ring;
272 + size_t sz_ring;
273 + atomic_t nr_free;
274 +};
275 +
276 +/**
277 + * struct mtk_hsdma_vchan - This is the struct holding info describing virtual
278 + * channel (VC)
279 + * @vc: An instance for struct virt_dma_chan
280 + * @issue_completion: The wait for all issued descriptors completited
281 + * @issue_synchronize: Bool indicating channel synchronization starts
282 + * @desc_hw_processing: List those descriptors the hardware is processing,
283 + * which is protected by vc.lock
284 + */
285 +struct mtk_hsdma_vchan {
286 + struct virt_dma_chan vc;
287 + struct completion issue_completion;
288 + bool issue_synchronize;
289 + struct list_head desc_hw_processing;
290 +};
291 +
292 +/**
293 + * struct mtk_hsdma_soc - This is the struct holding differences among SoCs
294 + * @ddone: Bit mask for DDONE
295 + * @ls0: Bit mask for LS0
296 + */
297 +struct mtk_hsdma_soc {
298 + __le32 ddone;
299 + __le32 ls0;
300 +};
301 +
302 +/**
303 + * struct mtk_hsdma_device - This is the struct holding info describing HSDMA
304 + * device
305 + * @ddev: An instance for struct dma_device
306 + * @base: The mapped register I/O base
307 + * @clk: The clock that device internal is using
308 + * @irq: The IRQ that device are using
309 + * @dma_requests: The number of VCs the device supports to
310 + * @vc: The pointer to all available VCs
311 + * @pc: The pointer to the underlying PC
312 + * @pc_refcnt: Track how many VCs are using the PC
313 + * @lock: Lock protect agaisting multiple VCs access PC
314 + * @soc: The pointer to area holding differences among
315 + * vaious platform
316 + */
317 +struct mtk_hsdma_device {
318 + struct dma_device ddev;
319 + void __iomem *base;
320 + struct clk *clk;
321 + u32 irq;
322 +
323 + u32 dma_requests;
324 + struct mtk_hsdma_vchan *vc;
325 + struct mtk_hsdma_pchan *pc;
326 + refcount_t pc_refcnt;
327 +
328 + /* Lock used to protect against multiple VCs access PC */
329 + spinlock_t lock;
330 +
331 + const struct mtk_hsdma_soc *soc;
332 +};
333 +
334 +static struct mtk_hsdma_device *to_hsdma_dev(struct dma_chan *chan)
335 +{
336 + return container_of(chan->device, struct mtk_hsdma_device, ddev);
337 +}
338 +
339 +static inline struct mtk_hsdma_vchan *to_hsdma_vchan(struct dma_chan *chan)
340 +{
341 + return container_of(chan, struct mtk_hsdma_vchan, vc.chan);
342 +}
343 +
344 +static struct mtk_hsdma_vdesc *to_hsdma_vdesc(struct virt_dma_desc *vd)
345 +{
346 + return container_of(vd, struct mtk_hsdma_vdesc, vd);
347 +}
348 +
349 +static struct device *hsdma2dev(struct mtk_hsdma_device *hsdma)
350 +{
351 + return hsdma->ddev.dev;
352 +}
353 +
354 +static u32 mtk_dma_read(struct mtk_hsdma_device *hsdma, u32 reg)
355 +{
356 + return readl(hsdma->base + reg);
357 +}
358 +
359 +static void mtk_dma_write(struct mtk_hsdma_device *hsdma, u32 reg, u32 val)
360 +{
361 + writel(val, hsdma->base + reg);
362 +}
363 +
364 +static void mtk_dma_rmw(struct mtk_hsdma_device *hsdma, u32 reg,
365 + u32 mask, u32 set)
366 +{
367 + u32 val;
368 +
369 + val = mtk_dma_read(hsdma, reg);
370 + val &= ~mask;
371 + val |= set;
372 + mtk_dma_write(hsdma, reg, val);
373 +}
374 +
375 +static void mtk_dma_set(struct mtk_hsdma_device *hsdma, u32 reg, u32 val)
376 +{
377 + mtk_dma_rmw(hsdma, reg, 0, val);
378 +}
379 +
380 +static void mtk_dma_clr(struct mtk_hsdma_device *hsdma, u32 reg, u32 val)
381 +{
382 + mtk_dma_rmw(hsdma, reg, val, 0);
383 +}
384 +
385 +static void mtk_hsdma_vdesc_free(struct virt_dma_desc *vd)
386 +{
387 + kfree(container_of(vd, struct mtk_hsdma_vdesc, vd));
388 +}
389 +
390 +static int mtk_hsdma_busy_wait(struct mtk_hsdma_device *hsdma)
391 +{
392 + u32 status = 0;
393 +
394 + return readl_poll_timeout(hsdma->base + MTK_HSDMA_GLO, status,
395 + !(status & MTK_HSDMA_GLO_BUSY),
396 + MTK_HSDMA_USEC_POLL,
397 + MTK_HSDMA_TIMEOUT_POLL);
398 +}
399 +
400 +static int mtk_hsdma_alloc_pchan(struct mtk_hsdma_device *hsdma,
401 + struct mtk_hsdma_pchan *pc)
402 +{
403 + struct mtk_hsdma_ring *ring = &pc->ring;
404 + int err;
405 +
406 + memset(pc, 0, sizeof(*pc));
407 +
408 + /*
409 + * Allocate ring space where [0 ... MTK_DMA_SIZE - 1] is for TX ring
410 + * and [MTK_DMA_SIZE ... 2 * MTK_DMA_SIZE - 1] is for RX ring.
411 + */
412 + pc->sz_ring = 2 * MTK_DMA_SIZE * sizeof(*ring->txd);
413 + ring->txd = dma_zalloc_coherent(hsdma2dev(hsdma), pc->sz_ring,
414 + &ring->tphys, GFP_NOWAIT);
415 + if (!ring->txd)
416 + return -ENOMEM;
417 +
418 + ring->rxd = &ring->txd[MTK_DMA_SIZE];
419 + ring->rphys = ring->tphys + MTK_DMA_SIZE * sizeof(*ring->txd);
420 + ring->cur_tptr = 0;
421 + ring->cur_rptr = MTK_DMA_SIZE - 1;
422 +
423 + ring->cb = kcalloc(MTK_DMA_SIZE, sizeof(*ring->cb), GFP_NOWAIT);
424 + if (!ring->cb) {
425 + err = -ENOMEM;
426 + goto err_free_dma;
427 + }
428 +
429 + atomic_set(&pc->nr_free, MTK_DMA_SIZE - 1);
430 +
431 + /* Disable HSDMA and wait for the completion */
432 + mtk_dma_clr(hsdma, MTK_HSDMA_GLO, MTK_HSDMA_GLO_DMA);
433 + err = mtk_hsdma_busy_wait(hsdma);
434 + if (err)
435 + goto err_free_cb;
436 +
437 + /* Reset */
438 + mtk_dma_set(hsdma, MTK_HSDMA_RESET,
439 + MTK_HSDMA_RST_TX | MTK_HSDMA_RST_RX);
440 + mtk_dma_clr(hsdma, MTK_HSDMA_RESET,
441 + MTK_HSDMA_RST_TX | MTK_HSDMA_RST_RX);
442 +
443 + /* Setup HSDMA initial pointer in the ring */
444 + mtk_dma_write(hsdma, MTK_HSDMA_TX_BASE, ring->tphys);
445 + mtk_dma_write(hsdma, MTK_HSDMA_TX_CNT, MTK_DMA_SIZE);
446 + mtk_dma_write(hsdma, MTK_HSDMA_TX_CPU, ring->cur_tptr);
447 + mtk_dma_write(hsdma, MTK_HSDMA_TX_DMA, 0);
448 + mtk_dma_write(hsdma, MTK_HSDMA_RX_BASE, ring->rphys);
449 + mtk_dma_write(hsdma, MTK_HSDMA_RX_CNT, MTK_DMA_SIZE);
450 + mtk_dma_write(hsdma, MTK_HSDMA_RX_CPU, ring->cur_rptr);
451 + mtk_dma_write(hsdma, MTK_HSDMA_RX_DMA, 0);
452 +
453 + /* Enable HSDMA */
454 + mtk_dma_set(hsdma, MTK_HSDMA_GLO, MTK_HSDMA_GLO_DMA);
455 +
456 + /* Setup delayed interrupt */
457 + mtk_dma_write(hsdma, MTK_HSDMA_DLYINT, MTK_HSDMA_DLYINT_DEFAULT);
458 +
459 + /* Enable interrupt */
460 + mtk_dma_set(hsdma, MTK_HSDMA_INT_ENABLE, MTK_HSDMA_INT_RXDONE);
461 +
462 + return 0;
463 +
464 +err_free_cb:
465 + kfree(ring->cb);
466 +
467 +err_free_dma:
468 + dma_free_coherent(hsdma2dev(hsdma),
469 + pc->sz_ring, ring->txd, ring->tphys);
470 + return err;
471 +}
472 +
473 +static void mtk_hsdma_free_pchan(struct mtk_hsdma_device *hsdma,
474 + struct mtk_hsdma_pchan *pc)
475 +{
476 + struct mtk_hsdma_ring *ring = &pc->ring;
477 +
478 + /* Disable HSDMA and then wait for the completion */
479 + mtk_dma_clr(hsdma, MTK_HSDMA_GLO, MTK_HSDMA_GLO_DMA);
480 + mtk_hsdma_busy_wait(hsdma);
481 +
482 + /* Reset pointer in the ring */
483 + mtk_dma_clr(hsdma, MTK_HSDMA_INT_ENABLE, MTK_HSDMA_INT_RXDONE);
484 + mtk_dma_write(hsdma, MTK_HSDMA_TX_BASE, 0);
485 + mtk_dma_write(hsdma, MTK_HSDMA_TX_CNT, 0);
486 + mtk_dma_write(hsdma, MTK_HSDMA_TX_CPU, 0);
487 + mtk_dma_write(hsdma, MTK_HSDMA_RX_BASE, 0);
488 + mtk_dma_write(hsdma, MTK_HSDMA_RX_CNT, 0);
489 + mtk_dma_write(hsdma, MTK_HSDMA_RX_CPU, MTK_DMA_SIZE - 1);
490 +
491 + kfree(ring->cb);
492 +
493 + dma_free_coherent(hsdma2dev(hsdma),
494 + pc->sz_ring, ring->txd, ring->tphys);
495 +}
496 +
497 +static int mtk_hsdma_issue_pending_vdesc(struct mtk_hsdma_device *hsdma,
498 + struct mtk_hsdma_pchan *pc,
499 + struct mtk_hsdma_vdesc *hvd)
500 +{
501 + struct mtk_hsdma_ring *ring = &pc->ring;
502 + struct mtk_hsdma_pdesc *txd, *rxd;
503 + u16 reserved, prev, tlen, num_sgs;
504 + unsigned long flags;
505 +
506 + /* Protect against PC is accessed by multiple VCs simultaneously */
507 + spin_lock_irqsave(&hsdma->lock, flags);
508 +
509 + /*
510 + * Reserve rooms, where pc->nr_free is used to track how many free
511 + * rooms in the ring being updated in user and IRQ context.
512 + */
513 + num_sgs = DIV_ROUND_UP(hvd->len, MTK_HSDMA_MAX_LEN);
514 + reserved = min_t(u16, num_sgs, atomic_read(&pc->nr_free));
515 +
516 + if (!reserved) {
517 + spin_unlock_irqrestore(&hsdma->lock, flags);
518 + return -ENOSPC;
519 + }
520 +
521 + atomic_sub(reserved, &pc->nr_free);
522 +
523 + while (reserved--) {
524 + /* Limit size by PD capability for valid data moving */
525 + tlen = (hvd->len > MTK_HSDMA_MAX_LEN) ?
526 + MTK_HSDMA_MAX_LEN : hvd->len;
527 +
528 + /*
529 + * Setup PDs using the remaining VD info mapped on those
530 + * reserved rooms. And since RXD is shared memory between the
531 + * host and the device allocated by dma_alloc_coherent call,
532 + * the helper macro WRITE_ONCE can ensure the data written to
533 + * RAM would really happens.
534 + */
535 + txd = &ring->txd[ring->cur_tptr];
536 + WRITE_ONCE(txd->desc1, hvd->src);
537 + WRITE_ONCE(txd->desc2,
538 + hsdma->soc->ls0 | MTK_HSDMA_DESC_PLEN(tlen));
539 +
540 + rxd = &ring->rxd[ring->cur_tptr];
541 + WRITE_ONCE(rxd->desc1, hvd->dest);
542 + WRITE_ONCE(rxd->desc2, MTK_HSDMA_DESC_PLEN(tlen));
543 +
544 + /* Associate VD, the PD belonged to */
545 + ring->cb[ring->cur_tptr].vd = &hvd->vd;
546 +
547 + /* Move forward the pointer of TX ring */
548 + ring->cur_tptr = MTK_HSDMA_NEXT_DESP_IDX(ring->cur_tptr,
549 + MTK_DMA_SIZE);
550 +
551 + /* Update VD with remaining data */
552 + hvd->src += tlen;
553 + hvd->dest += tlen;
554 + hvd->len -= tlen;
555 + }
556 +
557 + /*
558 + * Tagging flag for the last PD for VD will be responsible for
559 + * completing VD.
560 + */
561 + if (!hvd->len) {
562 + prev = MTK_HSDMA_LAST_DESP_IDX(ring->cur_tptr, MTK_DMA_SIZE);
563 + ring->cb[prev].flag = MTK_HSDMA_VDESC_FINISHED;
564 + }
565 +
566 + /* Ensure all changes indeed done before we're going on */
567 + wmb();
568 +
569 + /*
570 + * Updating into hardware the pointer of TX ring lets HSDMA to take
571 + * action for those pending PDs.
572 + */
573 + mtk_dma_write(hsdma, MTK_HSDMA_TX_CPU, ring->cur_tptr);
574 +
575 + spin_unlock_irqrestore(&hsdma->lock, flags);
576 +
577 + return 0;
578 +}
579 +
580 +static void mtk_hsdma_issue_vchan_pending(struct mtk_hsdma_device *hsdma,
581 + struct mtk_hsdma_vchan *hvc)
582 +{
583 + struct virt_dma_desc *vd, *vd2;
584 + int err;
585 +
586 + lockdep_assert_held(&hvc->vc.lock);
587 +
588 + list_for_each_entry_safe(vd, vd2, &hvc->vc.desc_issued, node) {
589 + struct mtk_hsdma_vdesc *hvd;
590 +
591 + hvd = to_hsdma_vdesc(vd);
592 +
593 + /* Map VD into PC and all VCs shares a single PC */
594 + err = mtk_hsdma_issue_pending_vdesc(hsdma, hsdma->pc, hvd);
595 +
596 + /*
597 + * Move VD from desc_issued to desc_hw_processing when entire
598 + * VD is fit into available PDs. Otherwise, the uncompleted
599 + * VDs would stay in list desc_issued and then restart the
600 + * processing as soon as possible once underlying ring space
601 + * got freed.
602 + */
603 + if (err == -ENOSPC || hvd->len > 0)
604 + break;
605 +
606 + /*
607 + * The extra list desc_hw_processing is used because
608 + * hardware can't provide sufficient information allowing us
609 + * to know what VDs are still working on the underlying ring.
610 + * Through the additional list, it can help us to implement
611 + * terminate_all, residue calculation and such thing needed
612 + * to know detail descriptor status on the hardware.
613 + */
614 + list_move_tail(&vd->node, &hvc->desc_hw_processing);
615 + }
616 +}
617 +
618 +static void mtk_hsdma_free_rooms_in_ring(struct mtk_hsdma_device *hsdma)
619 +{
620 + struct mtk_hsdma_vchan *hvc;
621 + struct mtk_hsdma_pdesc *rxd;
622 + struct mtk_hsdma_vdesc *hvd;
623 + struct mtk_hsdma_pchan *pc;
624 + struct mtk_hsdma_cb *cb;
625 + int i = MTK_DMA_SIZE;
626 + __le32 desc2;
627 + u32 status;
628 + u16 next;
629 +
630 + /* Read IRQ status */
631 + status = mtk_dma_read(hsdma, MTK_HSDMA_INT_STATUS);
632 + if (unlikely(!(status & MTK_HSDMA_INT_RXDONE)))
633 + goto rx_done;
634 +
635 + pc = hsdma->pc;
636 +
637 + /*
638 + * Using a fail-safe loop with iterations of up to MTK_DMA_SIZE to
639 + * reclaim these finished descriptors: The most number of PDs the ISR
640 + * can handle at one time shouldn't be more than MTK_DMA_SIZE so we
641 + * take it as limited count instead of just using a dangerous infinite
642 + * poll.
643 + */
644 + while (i--) {
645 + next = MTK_HSDMA_NEXT_DESP_IDX(pc->ring.cur_rptr,
646 + MTK_DMA_SIZE);
647 + rxd = &pc->ring.rxd[next];
648 +
649 + /*
650 + * If MTK_HSDMA_DESC_DDONE is no specified, that means data
651 + * moving for the PD is still under going.
652 + */
653 + desc2 = READ_ONCE(rxd->desc2);
654 + if (!(desc2 & hsdma->soc->ddone))
655 + break;
656 +
657 + cb = &pc->ring.cb[next];
658 + if (unlikely(!cb->vd)) {
659 + dev_err(hsdma2dev(hsdma), "cb->vd cannot be null\n");
660 + break;
661 + }
662 +
663 + /* Update residue of VD the associated PD belonged to */
664 + hvd = to_hsdma_vdesc(cb->vd);
665 + hvd->residue -= MTK_HSDMA_DESC_PLEN_GET(rxd->desc2);
666 +
667 + /* Complete VD until the relevant last PD is finished */
668 + if (IS_MTK_HSDMA_VDESC_FINISHED(cb->flag)) {
669 + hvc = to_hsdma_vchan(cb->vd->tx.chan);
670 +
671 + spin_lock(&hvc->vc.lock);
672 +
673 + /* Remove VD from list desc_hw_processing */
674 + list_del(&cb->vd->node);
675 +
676 + /* Add VD into list desc_completed */
677 + vchan_cookie_complete(cb->vd);
678 +
679 + if (hvc->issue_synchronize &&
680 + list_empty(&hvc->desc_hw_processing)) {
681 + complete(&hvc->issue_completion);
682 + hvc->issue_synchronize = false;
683 + }
684 + spin_unlock(&hvc->vc.lock);
685 +
686 + cb->flag = 0;
687 + }
688 +
689 + cb->vd = 0;
690 +
691 + /*
692 + * Recycle the RXD with the helper WRITE_ONCE that can ensure
693 + * data written into RAM would really happens.
694 + */
695 + WRITE_ONCE(rxd->desc1, 0);
696 + WRITE_ONCE(rxd->desc2, 0);
697 + pc->ring.cur_rptr = next;
698 +
699 + /* Release rooms */
700 + atomic_inc(&pc->nr_free);
701 + }
702 +
703 + /* Ensure all changes indeed done before we're going on */
704 + wmb();
705 +
706 + /* Update CPU pointer for those completed PDs */
707 + mtk_dma_write(hsdma, MTK_HSDMA_RX_CPU, pc->ring.cur_rptr);
708 +
709 + /*
710 + * Acking the pending IRQ allows hardware no longer to keep the used
711 + * IRQ line in certain trigger state when software has completed all
712 + * the finished physical descriptors.
713 + */
714 + if (atomic_read(&pc->nr_free) >= MTK_DMA_SIZE - 1)
715 + mtk_dma_write(hsdma, MTK_HSDMA_INT_STATUS, status);
716 +
717 + /* ASAP handles pending VDs in all VCs after freeing some rooms */
718 + for (i = 0; i < hsdma->dma_requests; i++) {
719 + hvc = &hsdma->vc[i];
720 + spin_lock(&hvc->vc.lock);
721 + mtk_hsdma_issue_vchan_pending(hsdma, hvc);
722 + spin_unlock(&hvc->vc.lock);
723 + }
724 +
725 +rx_done:
726 + /* All completed PDs are cleaned up, so enable interrupt again */
727 + mtk_dma_set(hsdma, MTK_HSDMA_INT_ENABLE, MTK_HSDMA_INT_RXDONE);
728 +}
729 +
730 +static irqreturn_t mtk_hsdma_irq(int irq, void *devid)
731 +{
732 + struct mtk_hsdma_device *hsdma = devid;
733 +
734 + /*
735 + * Disable interrupt until all completed PDs are cleaned up in
736 + * mtk_hsdma_free_rooms call.
737 + */
738 + mtk_dma_clr(hsdma, MTK_HSDMA_INT_ENABLE, MTK_HSDMA_INT_RXDONE);
739 +
740 + mtk_hsdma_free_rooms_in_ring(hsdma);
741 +
742 + return IRQ_HANDLED;
743 +}
744 +
745 +static struct virt_dma_desc *mtk_hsdma_find_active_desc(struct dma_chan *c,
746 + dma_cookie_t cookie)
747 +{
748 + struct mtk_hsdma_vchan *hvc = to_hsdma_vchan(c);
749 + struct virt_dma_desc *vd;
750 +
751 + list_for_each_entry(vd, &hvc->desc_hw_processing, node)
752 + if (vd->tx.cookie == cookie)
753 + return vd;
754 +
755 + list_for_each_entry(vd, &hvc->vc.desc_issued, node)
756 + if (vd->tx.cookie == cookie)
757 + return vd;
758 +
759 + return NULL;
760 +}
761 +
762 +static enum dma_status mtk_hsdma_tx_status(struct dma_chan *c,
763 + dma_cookie_t cookie,
764 + struct dma_tx_state *txstate)
765 +{
766 + struct mtk_hsdma_vchan *hvc = to_hsdma_vchan(c);
767 + struct mtk_hsdma_vdesc *hvd;
768 + struct virt_dma_desc *vd;
769 + enum dma_status ret;
770 + unsigned long flags;
771 + size_t bytes = 0;
772 +
773 + ret = dma_cookie_status(c, cookie, txstate);
774 + if (ret == DMA_COMPLETE || !txstate)
775 + return ret;
776 +
777 + spin_lock_irqsave(&hvc->vc.lock, flags);
778 + vd = mtk_hsdma_find_active_desc(c, cookie);
779 + spin_unlock_irqrestore(&hvc->vc.lock, flags);
780 +
781 + if (vd) {
782 + hvd = to_hsdma_vdesc(vd);
783 + bytes = hvd->residue;
784 + }
785 +
786 + dma_set_residue(txstate, bytes);
787 +
788 + return ret;
789 +}
790 +
791 +static void mtk_hsdma_issue_pending(struct dma_chan *c)
792 +{
793 + struct mtk_hsdma_device *hsdma = to_hsdma_dev(c);
794 + struct mtk_hsdma_vchan *hvc = to_hsdma_vchan(c);
795 + unsigned long flags;
796 +
797 + spin_lock_irqsave(&hvc->vc.lock, flags);
798 +
799 + if (vchan_issue_pending(&hvc->vc))
800 + mtk_hsdma_issue_vchan_pending(hsdma, hvc);
801 +
802 + spin_unlock_irqrestore(&hvc->vc.lock, flags);
803 +}
804 +
805 +static struct dma_async_tx_descriptor *
806 +mtk_hsdma_prep_dma_memcpy(struct dma_chan *c, dma_addr_t dest,
807 + dma_addr_t src, size_t len, unsigned long flags)
808 +{
809 + struct mtk_hsdma_vdesc *hvd;
810 +
811 + hvd = kzalloc(sizeof(*hvd), GFP_NOWAIT);
812 + if (!hvd)
813 + return NULL;
814 +
815 + hvd->len = len;
816 + hvd->residue = len;
817 + hvd->src = src;
818 + hvd->dest = dest;
819 +
820 + return vchan_tx_prep(to_virt_chan(c), &hvd->vd, flags);
821 +}
822 +
823 +static int mtk_hsdma_free_inactive_desc(struct dma_chan *c)
824 +{
825 + struct virt_dma_chan *vc = to_virt_chan(c);
826 + unsigned long flags;
827 + LIST_HEAD(head);
828 +
829 + spin_lock_irqsave(&vc->lock, flags);
830 + list_splice_tail_init(&vc->desc_allocated, &head);
831 + list_splice_tail_init(&vc->desc_submitted, &head);
832 + list_splice_tail_init(&vc->desc_issued, &head);
833 + spin_unlock_irqrestore(&vc->lock, flags);
834 +
835 + /* At the point, we don't expect users put descriptor into VC again */
836 + vchan_dma_desc_free_list(vc, &head);
837 +
838 + return 0;
839 +}
840 +
841 +static void mtk_hsdma_free_active_desc(struct dma_chan *c)
842 +{
843 + struct mtk_hsdma_vchan *hvc = to_hsdma_vchan(c);
844 + bool sync_needed = false;
845 +
846 + /*
847 + * Once issue_synchronize is being set, which means once the hardware
848 + * consumes all descriptors for the channel in the ring, the
849 + * synchronization must be be notified immediately it is completed.
850 + */
851 + spin_lock(&hvc->vc.lock);
852 + if (!list_empty(&hvc->desc_hw_processing)) {
853 + hvc->issue_synchronize = true;
854 + sync_needed = true;
855 + }
856 + spin_unlock(&hvc->vc.lock);
857 +
858 + if (sync_needed)
859 + wait_for_completion(&hvc->issue_completion);
860 + /*
861 + * At the point, we expect that all remaining descriptors in the ring
862 + * for the channel should be all processing done.
863 + */
864 + WARN_ONCE(!list_empty(&hvc->desc_hw_processing),
865 + "Desc pending still in list desc_hw_processing\n");
866 +
867 + /* Free all descriptors in list desc_completed */
868 + vchan_synchronize(&hvc->vc);
869 +
870 + WARN_ONCE(!list_empty(&hvc->vc.desc_completed),
871 + "Desc pending still in list desc_completed\n");
872 +}
873 +
874 +static int mtk_hsdma_terminate_all(struct dma_chan *c)
875 +{
876 + /*
877 + * Free pending descriptors not processed yet by hardware that have
878 + * previously been submitted to the channel.
879 + */
880 + mtk_hsdma_free_inactive_desc(c);
881 +
882 + /*
883 + * However, the DMA engine doesn't provide any way to stop these
884 + * descriptors being processed currently by hardware. The only way is
885 + * to just waiting until these descriptors are all processed completely
886 + * through mtk_hsdma_free_active_desc call.
887 + */
888 + mtk_hsdma_free_active_desc(c);
889 +
890 + return 0;
891 +}
892 +
893 +static int mtk_hsdma_alloc_chan_resources(struct dma_chan *c)
894 +{
895 + struct mtk_hsdma_device *hsdma = to_hsdma_dev(c);
896 + int err;
897 +
898 + /*
899 + * Since HSDMA has only one PC, the resource for PC is being allocated
900 + * when the first VC is being created and the other VCs would run on
901 + * the same PC.
902 + */
903 + if (!refcount_read(&hsdma->pc_refcnt)) {
904 + err = mtk_hsdma_alloc_pchan(hsdma, hsdma->pc);
905 + if (err)
906 + return err;
907 + /*
908 + * refcount_inc would complain increment on 0; use-after-free.
909 + * Thus, we need to explicitly set it as 1 initially.
910 + */
911 + refcount_set(&hsdma->pc_refcnt, 1);
912 + } else {
913 + refcount_inc(&hsdma->pc_refcnt);
914 + }
915 +
916 + return 0;
917 +}
918 +
919 +static void mtk_hsdma_free_chan_resources(struct dma_chan *c)
920 +{
921 + struct mtk_hsdma_device *hsdma = to_hsdma_dev(c);
922 +
923 + /* Free all descriptors in all lists on the VC */
924 + mtk_hsdma_terminate_all(c);
925 +
926 + /* The resource for PC is not freed until all the VCs are destroyed */
927 + if (!refcount_dec_and_test(&hsdma->pc_refcnt))
928 + return;
929 +
930 + mtk_hsdma_free_pchan(hsdma, hsdma->pc);
931 +}
932 +
933 +static int mtk_hsdma_hw_init(struct mtk_hsdma_device *hsdma)
934 +{
935 + int err;
936 +
937 + pm_runtime_enable(hsdma2dev(hsdma));
938 + pm_runtime_get_sync(hsdma2dev(hsdma));
939 +
940 + err = clk_prepare_enable(hsdma->clk);
941 + if (err)
942 + return err;
943 +
944 + mtk_dma_write(hsdma, MTK_HSDMA_INT_ENABLE, 0);
945 + mtk_dma_write(hsdma, MTK_HSDMA_GLO, MTK_HSDMA_GLO_DEFAULT);
946 +
947 + return 0;
948 +}
949 +
950 +static int mtk_hsdma_hw_deinit(struct mtk_hsdma_device *hsdma)
951 +{
952 + mtk_dma_write(hsdma, MTK_HSDMA_GLO, 0);
953 +
954 + clk_disable_unprepare(hsdma->clk);
955 +
956 + pm_runtime_put_sync(hsdma2dev(hsdma));
957 + pm_runtime_disable(hsdma2dev(hsdma));
958 +
959 + return 0;
960 +}
961 +
962 +static const struct mtk_hsdma_soc mt7623_soc = {
963 + .ddone = BIT(31),
964 + .ls0 = BIT(30),
965 +};
966 +
967 +static const struct mtk_hsdma_soc mt7622_soc = {
968 + .ddone = BIT(15),
969 + .ls0 = BIT(14),
970 +};
971 +
972 +static const struct of_device_id mtk_hsdma_match[] = {
973 + { .compatible = "mediatek,mt7623-hsdma", .data = &mt7623_soc},
974 + { .compatible = "mediatek,mt7622-hsdma", .data = &mt7622_soc},
975 + { /* sentinel */ }
976 +};
977 +MODULE_DEVICE_TABLE(of, mtk_hsdma_match);
978 +
979 +static int mtk_hsdma_probe(struct platform_device *pdev)
980 +{
981 + struct mtk_hsdma_device *hsdma;
982 + struct mtk_hsdma_vchan *vc;
983 + struct dma_device *dd;
984 + struct resource *res;
985 + int i, err;
986 +
987 + hsdma = devm_kzalloc(&pdev->dev, sizeof(*hsdma), GFP_KERNEL);
988 + if (!hsdma)
989 + return -ENOMEM;
990 +
991 + dd = &hsdma->ddev;
992 +
993 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
994 + hsdma->base = devm_ioremap_resource(&pdev->dev, res);
995 + if (IS_ERR(hsdma->base))
996 + return PTR_ERR(hsdma->base);
997 +
998 + hsdma->soc = of_device_get_match_data(&pdev->dev);
999 + if (!hsdma->soc) {
1000 + dev_err(&pdev->dev, "No device match found\n");
1001 + return -ENODEV;
1002 + }
1003 +
1004 + hsdma->clk = devm_clk_get(&pdev->dev, "hsdma");
1005 + if (IS_ERR(hsdma->clk)) {
1006 + dev_err(&pdev->dev, "No clock for %s\n",
1007 + dev_name(&pdev->dev));
1008 + return PTR_ERR(hsdma->clk);
1009 + }
1010 +
1011 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1012 + if (!res) {
1013 + dev_err(&pdev->dev, "No irq resource for %s\n",
1014 + dev_name(&pdev->dev));
1015 + return -EINVAL;
1016 + }
1017 + hsdma->irq = res->start;
1018 +
1019 + refcount_set(&hsdma->pc_refcnt, 0);
1020 + spin_lock_init(&hsdma->lock);
1021 +
1022 + dma_cap_set(DMA_MEMCPY, dd->cap_mask);
1023 +
1024 + dd->copy_align = MTK_HSDMA_ALIGN_SIZE;
1025 + dd->device_alloc_chan_resources = mtk_hsdma_alloc_chan_resources;
1026 + dd->device_free_chan_resources = mtk_hsdma_free_chan_resources;
1027 + dd->device_tx_status = mtk_hsdma_tx_status;
1028 + dd->device_issue_pending = mtk_hsdma_issue_pending;
1029 + dd->device_prep_dma_memcpy = mtk_hsdma_prep_dma_memcpy;
1030 + dd->device_terminate_all = mtk_hsdma_terminate_all;
1031 + dd->src_addr_widths = MTK_HSDMA_DMA_BUSWIDTHS;
1032 + dd->dst_addr_widths = MTK_HSDMA_DMA_BUSWIDTHS;
1033 + dd->directions = BIT(DMA_MEM_TO_MEM);
1034 + dd->residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
1035 + dd->dev = &pdev->dev;
1036 + INIT_LIST_HEAD(&dd->channels);
1037 +
1038 + hsdma->dma_requests = MTK_HSDMA_NR_VCHANS;
1039 + if (pdev->dev.of_node && of_property_read_u32(pdev->dev.of_node,
1040 + "dma-requests",
1041 + &hsdma->dma_requests)) {
1042 + dev_info(&pdev->dev,
1043 + "Using %u as missing dma-requests property\n",
1044 + MTK_HSDMA_NR_VCHANS);
1045 + }
1046 +
1047 + hsdma->pc = devm_kcalloc(&pdev->dev, MTK_HSDMA_NR_MAX_PCHANS,
1048 + sizeof(*hsdma->pc), GFP_KERNEL);
1049 + if (!hsdma->pc)
1050 + return -ENOMEM;
1051 +
1052 + hsdma->vc = devm_kcalloc(&pdev->dev, hsdma->dma_requests,
1053 + sizeof(*hsdma->vc), GFP_KERNEL);
1054 + if (!hsdma->vc)
1055 + return -ENOMEM;
1056 +
1057 + for (i = 0; i < hsdma->dma_requests; i++) {
1058 + vc = &hsdma->vc[i];
1059 + vc->vc.desc_free = mtk_hsdma_vdesc_free;
1060 + vchan_init(&vc->vc, dd);
1061 + init_completion(&vc->issue_completion);
1062 + INIT_LIST_HEAD(&vc->desc_hw_processing);
1063 + }
1064 +
1065 + err = dma_async_device_register(dd);
1066 + if (err)
1067 + return err;
1068 +
1069 + err = of_dma_controller_register(pdev->dev.of_node,
1070 + of_dma_xlate_by_chan_id, hsdma);
1071 + if (err) {
1072 + dev_err(&pdev->dev,
1073 + "MediaTek HSDMA OF registration failed %d\n", err);
1074 + goto err_unregister;
1075 + }
1076 +
1077 + mtk_hsdma_hw_init(hsdma);
1078 +
1079 + err = devm_request_irq(&pdev->dev, hsdma->irq,
1080 + mtk_hsdma_irq, 0,
1081 + dev_name(&pdev->dev), hsdma);
1082 + if (err) {
1083 + dev_err(&pdev->dev,
1084 + "request_irq failed with err %d\n", err);
1085 + goto err_unregister;
1086 + }
1087 +
1088 + platform_set_drvdata(pdev, hsdma);
1089 +
1090 + dev_info(&pdev->dev, "MediaTek HSDMA driver registered\n");
1091 +
1092 + return 0;
1093 +
1094 +err_unregister:
1095 + dma_async_device_unregister(dd);
1096 +
1097 + return err;
1098 +}
1099 +
1100 +static int mtk_hsdma_remove(struct platform_device *pdev)
1101 +{
1102 + struct mtk_hsdma_device *hsdma = platform_get_drvdata(pdev);
1103 + struct mtk_hsdma_vchan *vc;
1104 + int i;
1105 +
1106 + /* Kill VC task */
1107 + for (i = 0; i < hsdma->dma_requests; i++) {
1108 + vc = &hsdma->vc[i];
1109 +
1110 + list_del(&vc->vc.chan.device_node);
1111 + tasklet_kill(&vc->vc.task);
1112 + }
1113 +
1114 + /* Disable DMA interrupt */
1115 + mtk_dma_write(hsdma, MTK_HSDMA_INT_ENABLE, 0);
1116 +
1117 + /* Waits for any pending IRQ handlers to complete */
1118 + synchronize_irq(hsdma->irq);
1119 +
1120 + /* Disable hardware */
1121 + mtk_hsdma_hw_deinit(hsdma);
1122 +
1123 + dma_async_device_unregister(&hsdma->ddev);
1124 + of_dma_controller_free(pdev->dev.of_node);
1125 +
1126 + return 0;
1127 +}
1128 +
1129 +static struct platform_driver mtk_hsdma_driver = {
1130 + .probe = mtk_hsdma_probe,
1131 + .remove = mtk_hsdma_remove,
1132 + .driver = {
1133 + .name = KBUILD_MODNAME,
1134 + .of_match_table = mtk_hsdma_match,
1135 + },
1136 +};
1137 +module_platform_driver(mtk_hsdma_driver);
1138 +
1139 +MODULE_DESCRIPTION("MediaTek High-Speed DMA Controller Driver");
1140 +MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
1141 +MODULE_LICENSE("GPL v2");
1142 --
1143 2.11.0
1144