hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/dma/pl330.c
....@@ -1,16 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
34 * http://www.samsung.com
45 *
56 * Copyright (C) 2010 Samsung Electronics Co. Ltd.
67 * Jaswinder Singh <jassi.brar@samsung.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
128 */
139
10
+#include <linux/debugfs.h>
1411 #include <linux/kernel.h>
1512 #include <linux/io.h>
1613 #include <linux/init.h>
....@@ -28,6 +25,7 @@
2825 #include <linux/err.h>
2926 #include <linux/pm_runtime.h>
3027 #include <linux/bug.h>
28
+#include <linux/reset.h>
3129
3230 #include "dmaengine.h"
3331 #define PL330_MAX_CHAN 8
....@@ -37,16 +35,6 @@
3735
3836 #define PL330_QUIRK_BROKEN_NO_FLUSHP BIT(0)
3937 #define PL330_QUIRK_PERIPH_BURST BIT(1)
40
-
41
-#ifdef CONFIG_CPU_RV1126
42
-#undef writel
43
-#define writel(v, c) \
44
- do { \
45
- readl_relaxed(c); \
46
- __iowmb(); \
47
- writel_relaxed(v, c); \
48
- } while (0)
49
-#endif
5038
5139 enum pl330_cachectrl {
5240 CCTRL0, /* Noncacheable and nonbufferable */
....@@ -268,7 +256,7 @@
268256 static unsigned cmd_line;
269257 #define PL330_DBGCMD_DUMP(off, x...) do { \
270258 printk("%x:", cmd_line); \
271
- printk(x); \
259
+ printk(KERN_CONT x); \
272260 cmd_line += off; \
273261 } while (0)
274262 #define PL330_DBGMC_START(addr) (cmd_line = addr)
....@@ -298,7 +286,7 @@
298286 u32 irq_ns;
299287 };
300288
301
-/**
289
+/*
302290 * Request Configuration.
303291 * The PL330 core does not modify this and uses the last
304292 * working configuration if the request doesn't provide any.
....@@ -417,6 +405,12 @@
417405 */
418406 BUSY,
419407 /*
408
+ * Pause was called while descriptor was BUSY. Due to hardware
409
+ * limitations, only termination is possible for descriptors
410
+ * that have been paused.
411
+ */
412
+ PAUSED,
413
+ /*
420414 * Sitting on the channel work_list but xfer done
421415 * by PL330 core
422416 */
....@@ -460,8 +454,7 @@
460454 /* DMA-mapped view of the FIFO; may differ if an IOMMU is present */
461455 dma_addr_t fifo_dma;
462456 enum dma_data_direction dir;
463
- unsigned int src_interlace_size;
464
- unsigned int dst_interlace_size;
457
+ struct dma_slave_config slave_config;
465458
466459 /* for runtime pm tracking */
467460 bool active;
....@@ -470,9 +463,6 @@
470463 struct pl330_dmac {
471464 /* DMA-Engine Device */
472465 struct dma_device ddma;
473
-
474
- /* Holds info about sg limitations */
475
- struct device_dma_parameters dma_parms;
476466
477467 /* Pool of descriptors available for the DMAC's channels */
478468 struct list_head desc_pool;
....@@ -509,6 +499,9 @@
509499 unsigned int num_peripherals;
510500 struct dma_pl330_chan *peripherals; /* keep at end */
511501 int quirks;
502
+
503
+ struct reset_control *rstc;
504
+ struct reset_control *rstc_ocp;
512505 };
513506
514507 static struct pl330_of_quirks {
....@@ -554,15 +547,19 @@
554547 /* For cyclic capability */
555548 bool cyclic;
556549 size_t num_periods;
557
- /* interlace size */
558
- unsigned int src_interlace_size;
559
- unsigned int dst_interlace_size;
550
+
551
+ /* interleaved size */
552
+ struct data_chunk sgl;
560553 };
561554
562555 struct _xfer_spec {
563556 u32 ccr;
564557 struct dma_pl330_desc *desc;
565558 };
559
+
560
+static int pl330_config_write(struct dma_chan *chan,
561
+ struct dma_slave_config *slave_config,
562
+ enum dma_transfer_direction direction);
566563
567564 static inline bool _queue_full(struct pl330_thread *thrd)
568565 {
....@@ -1080,7 +1077,7 @@
10801077 return true;
10811078 }
10821079
1083
-static bool _start(struct pl330_thread *thrd)
1080
+static bool pl330_start_thread(struct pl330_thread *thrd)
10841081 {
10851082 switch (_state(thrd)) {
10861083 case PL330_STATE_FAULT_COMPLETING:
....@@ -1088,16 +1085,16 @@
10881085
10891086 if (_state(thrd) == PL330_STATE_KILLING)
10901087 UNTIL(thrd, PL330_STATE_STOPPED)
1091
- /* fall through */
1088
+ fallthrough;
10921089
10931090 case PL330_STATE_FAULTING:
10941091 _stop(thrd);
1095
- /* fall through */
1092
+ fallthrough;
10961093
10971094 case PL330_STATE_KILLING:
10981095 case PL330_STATE_COMPLETING:
10991096 UNTIL(thrd, PL330_STATE_STOPPED)
1100
- /* fall through */
1097
+ fallthrough;
11011098
11021099 case PL330_STATE_STOPPED:
11031100 return _trigger(thrd);
....@@ -1148,7 +1145,6 @@
11481145
11491146 switch (direction) {
11501147 case DMA_MEM_TO_MEM:
1151
- /* fall through */
11521148 case DMA_MEM_TO_DEV:
11531149 off += _emit_LD(dry_run, &buf[off], cond);
11541150 break;
....@@ -1182,7 +1178,6 @@
11821178
11831179 switch (direction) {
11841180 case DMA_MEM_TO_MEM:
1185
- /* fall through */
11861181 case DMA_DEV_TO_MEM:
11871182 off += _emit_ST(dry_run, &buf[off], cond);
11881183 break;
....@@ -1213,7 +1208,7 @@
12131208 const struct _xfer_spec *pxs, int cyc,
12141209 enum pl330_cond cond)
12151210 {
1216
- int off = 0;
1211
+ int off = 0, i = 0, burstn = 1;
12171212
12181213 /*
12191214 * do FLUSHP at beginning to clear any stale dma requests before the
....@@ -1221,22 +1216,31 @@
12211216 */
12221217 if (!(pl330->quirks & PL330_QUIRK_BROKEN_NO_FLUSHP))
12231218 off += _emit_FLUSHP(dry_run, &buf[off], pxs->desc->peri);
1219
+
1220
+ if (pxs->desc->sgl.size) {
1221
+ WARN_ON(BYTE_MOD_BURST_LEN(pxs->desc->sgl.size, pxs->ccr));
1222
+ burstn = BYTE_TO_BURST(pxs->desc->sgl.size, pxs->ccr);
1223
+ }
1224
+
12241225 while (cyc--) {
1225
- off += _emit_WFP(dry_run, &buf[off], cond, pxs->desc->peri);
1226
- off += _emit_load(dry_run, &buf[off], cond, pxs->desc->rqtype,
1227
- pxs->desc->peri);
1228
- off += _emit_store(dry_run, &buf[off], cond, pxs->desc->rqtype,
1229
- pxs->desc->peri);
1226
+ for (i = 0; i < burstn; i++) {
1227
+ off += _emit_WFP(dry_run, &buf[off], cond, pxs->desc->peri);
1228
+ off += _emit_load(dry_run, &buf[off], cond, pxs->desc->rqtype,
1229
+ pxs->desc->peri);
1230
+ off += _emit_store(dry_run, &buf[off], cond, pxs->desc->rqtype,
1231
+ pxs->desc->peri);
1232
+ }
1233
+
12301234 switch (pxs->desc->rqtype) {
12311235 case DMA_DEV_TO_MEM:
1232
- if (pxs->desc->dst_interlace_size)
1236
+ if (pxs->desc->sgl.dst_icg)
12331237 off += _emit_ADDH(dry_run, &buf[off], DST,
1234
- pxs->desc->dst_interlace_size);
1238
+ pxs->desc->sgl.dst_icg);
12351239 break;
12361240 case DMA_MEM_TO_DEV:
1237
- if (pxs->desc->src_interlace_size)
1241
+ if (pxs->desc->sgl.src_icg)
12381242 off += _emit_ADDH(dry_run, &buf[off], SRC,
1239
- pxs->desc->src_interlace_size);
1243
+ pxs->desc->sgl.src_icg);
12401244 break;
12411245 default:
12421246 WARN_ON(1);
....@@ -1258,7 +1262,6 @@
12581262
12591263 switch (pxs->desc->rqtype) {
12601264 case DMA_MEM_TO_DEV:
1261
- /* fall through */
12621265 case DMA_DEV_TO_MEM:
12631266 off += _ldst_peripheral(pl330, dry_run, &buf[off], pxs, cyc,
12641267 cond);
....@@ -1293,7 +1296,7 @@
12931296
12941297 switch (pxs->desc->rqtype) {
12951298 case DMA_MEM_TO_DEV:
1296
- /* fall through */
1299
+ fallthrough;
12971300 case DMA_DEV_TO_MEM:
12981301 /*
12991302 * dregs_len = (total bytes - BURST_TO_BYTE(bursts, ccr)) /
....@@ -1457,8 +1460,7 @@
14571460 off += _emit_LPEND(dry_run, &buf[off], &lpend);
14581461 }
14591462
1460
- if (!pxs->desc->src_interlace_size &&
1461
- !pxs->desc->dst_interlace_size) {
1463
+ if (!pxs->desc->sgl.src_icg && !pxs->desc->sgl.dst_icg) {
14621464 num_dregs = BYTE_MOD_BURST_LEN(x->bytes, pxs->ccr);
14631465
14641466 if (num_dregs) {
....@@ -1533,19 +1535,16 @@
15331535 BRST_SIZE(ccr);
15341536 int off = 0;
15351537
1536
- if (pxs->desc->rqtype == DMA_DEV_TO_MEM)
1537
- bursts = x->bytes / (BRST_SIZE(ccr) * BRST_LEN(ccr) +
1538
- pxs->desc->dst_interlace_size);
1539
- else if (pxs->desc->rqtype == DMA_MEM_TO_DEV)
1540
- bursts = x->bytes / (BRST_SIZE(ccr) * BRST_LEN(ccr) +
1541
- pxs->desc->src_interlace_size);
1538
+ if (pxs->desc->sgl.size)
1539
+ bursts = x->bytes / pxs->desc->sgl.size;
1540
+
15421541 while (bursts) {
15431542 c = bursts;
15441543 off += _loop(pl330, dry_run, &buf[off], &c, pxs);
15451544 bursts -= c;
15461545 }
1547
- if (!pxs->desc->src_interlace_size &&
1548
- !pxs->desc->dst_interlace_size)
1546
+
1547
+ if (!pxs->desc->sgl.src_icg && !pxs->desc->sgl.dst_icg)
15491548 off += _dregs(pl330, dry_run, &buf[off], pxs, num_dregs);
15501549
15511550 return off;
....@@ -1578,12 +1577,9 @@
15781577 unsigned long bursts = BYTE_TO_BURST(x->bytes, ccr);
15791578 int off = 0;
15801579
1581
- if (pxs->desc->rqtype == DMA_DEV_TO_MEM)
1582
- bursts = x->bytes / (BRST_SIZE(ccr) * BRST_LEN(ccr)
1583
- + pxs->desc->dst_interlace_size);
1584
- else if (pxs->desc->rqtype == DMA_MEM_TO_DEV)
1585
- bursts = x->bytes / (BRST_SIZE(ccr) * BRST_LEN(ccr)
1586
- + pxs->desc->src_interlace_size);
1580
+ if (pxs->desc->sgl.size)
1581
+ bursts = x->bytes / pxs->desc->sgl.size;
1582
+
15871583 /* Setup Loop(s) */
15881584 off += _loop_cyclic(pl330, dry_run, &buf[off], bursts, pxs, ev);
15891585
....@@ -1767,9 +1763,9 @@
17671763 tasklet_schedule(&pch->task);
17681764 }
17691765
1770
-static void pl330_dotask(unsigned long data)
1766
+static void pl330_dotask(struct tasklet_struct *t)
17711767 {
1772
- struct pl330_dmac *pl330 = (struct pl330_dmac *) data;
1768
+ struct pl330_dmac *pl330 = from_tasklet(pl330, t, tasks);
17731769 unsigned long flags;
17741770 int i;
17751771
....@@ -1898,7 +1894,7 @@
18981894 thrd->req[active].desc = NULL;
18991895 thrd->req_running = -1;
19001896 /* Get going again ASAP */
1901
- _start(thrd);
1897
+ pl330_start_thread(thrd);
19021898 }
19031899
19041900 /* For now, just make a list of callbacks to be done */
....@@ -2126,9 +2122,10 @@
21262122 if (ret) {
21272123 dev_err(pl330->ddma.dev, "%s:%d Can't to create channels for DMAC!\n",
21282124 __func__, __LINE__);
2129
- dma_free_coherent(pl330->ddma.dev,
2125
+ dma_free_attrs(pl330->ddma.dev,
21302126 chans * pl330->mcbufsz,
2131
- pl330->mcode_cpu, pl330->mcode_bus);
2127
+ pl330->mcode_cpu, pl330->mcode_bus,
2128
+ DMA_ATTR_PRIVILEGED);
21322129 return ret;
21332130 }
21342131
....@@ -2174,7 +2171,7 @@
21742171 return ret;
21752172 }
21762173
2177
- tasklet_init(&pl330->tasks, pl330_dotask, (unsigned long) pl330);
2174
+ tasklet_setup(&pl330->tasks, pl330_dotask);
21782175
21792176 pl330->state = INIT;
21802177
....@@ -2207,9 +2204,9 @@
22072204 /* Free DMAC resources */
22082205 dmac_free_threads(pl330);
22092206
2210
- dma_free_coherent(pl330->ddma.dev,
2207
+ dma_free_attrs(pl330->ddma.dev,
22112208 pl330->pcfg.num_chan * pl330->mcbufsz, pl330->mcode_cpu,
2212
- pl330->mcode_bus);
2209
+ pl330->mcode_bus, DMA_ATTR_PRIVILEGED);
22132210 }
22142211
22152212 /* forward declaration */
....@@ -2238,7 +2235,7 @@
22382235 list_for_each_entry(desc, &pch->work_list, node) {
22392236
22402237 /* If already submitted */
2241
- if (desc->status == BUSY)
2238
+ if (desc->status == BUSY || desc->status == PAUSED)
22422239 continue;
22432240
22442241 ret = pl330_submit_req(pch->thread, desc);
....@@ -2257,9 +2254,9 @@
22572254 }
22582255 }
22592256
2260
-static void pl330_tasklet(unsigned long data)
2257
+static void pl330_tasklet(struct tasklet_struct *t)
22612258 {
2262
- struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
2259
+ struct dma_pl330_chan *pch = from_tasklet(pch, t, task);
22632260 struct dma_pl330_desc *desc, *_dt;
22642261 unsigned long flags;
22652262 bool power_down = false;
....@@ -2299,7 +2296,7 @@
22992296 } else {
23002297 /* Make sure the PL330 Channel thread is active */
23012298 spin_lock(&pch->thread->dmac->lock);
2302
- _start(pch->thread);
2299
+ pl330_start_thread(pch->thread);
23032300 spin_unlock(&pch->thread->dmac->lock);
23042301 }
23052302
....@@ -2367,7 +2364,7 @@
23672364 return -ENOMEM;
23682365 }
23692366
2370
- tasklet_init(&pch->task, pl330_tasklet, (unsigned long) pch);
2367
+ tasklet_setup(&pch->task, pl330_tasklet);
23712368
23722369 spin_unlock_irqrestore(&pl330->lock, flags);
23732370
....@@ -2432,31 +2429,38 @@
24322429 return max_burst_len;
24332430 }
24342431
2432
+static int pl330_config_write(struct dma_chan *chan,
2433
+ struct dma_slave_config *slave_config,
2434
+ enum dma_transfer_direction direction)
2435
+{
2436
+ struct dma_pl330_chan *pch = to_pchan(chan);
2437
+
2438
+ pl330_unprep_slave_fifo(pch);
2439
+ if (direction == DMA_MEM_TO_DEV) {
2440
+ if (slave_config->dst_addr)
2441
+ pch->fifo_addr = slave_config->dst_addr;
2442
+ if (slave_config->dst_addr_width)
2443
+ pch->burst_sz = __ffs(slave_config->dst_addr_width);
2444
+ pch->burst_len = fixup_burst_len(slave_config->dst_maxburst,
2445
+ pch->dmac->quirks);
2446
+ } else if (direction == DMA_DEV_TO_MEM) {
2447
+ if (slave_config->src_addr)
2448
+ pch->fifo_addr = slave_config->src_addr;
2449
+ if (slave_config->src_addr_width)
2450
+ pch->burst_sz = __ffs(slave_config->src_addr_width);
2451
+ pch->burst_len = fixup_burst_len(slave_config->src_maxburst,
2452
+ pch->dmac->quirks);
2453
+ }
2454
+
2455
+ return 0;
2456
+}
2457
+
24352458 static int pl330_config(struct dma_chan *chan,
24362459 struct dma_slave_config *slave_config)
24372460 {
24382461 struct dma_pl330_chan *pch = to_pchan(chan);
24392462
2440
- pl330_unprep_slave_fifo(pch);
2441
- if (slave_config->direction == DMA_MEM_TO_DEV) {
2442
- if (slave_config->dst_addr)
2443
- pch->fifo_addr = slave_config->dst_addr;
2444
- if (slave_config->dst_addr_width)
2445
- pch->burst_sz = __ffs(slave_config->dst_addr_width);
2446
- if (slave_config->src_interlace_size)
2447
- pch->src_interlace_size = slave_config->src_interlace_size;
2448
- pch->burst_len = fixup_burst_len(slave_config->dst_maxburst,
2449
- pch->dmac->quirks);
2450
- } else if (slave_config->direction == DMA_DEV_TO_MEM) {
2451
- if (slave_config->src_addr)
2452
- pch->fifo_addr = slave_config->src_addr;
2453
- if (slave_config->src_addr_width)
2454
- pch->burst_sz = __ffs(slave_config->src_addr_width);
2455
- if (slave_config->dst_interlace_size)
2456
- pch->dst_interlace_size = slave_config->dst_interlace_size;
2457
- pch->burst_len = fixup_burst_len(slave_config->src_maxburst,
2458
- pch->dmac->quirks);
2459
- }
2463
+ memcpy(&pch->slave_config, slave_config, sizeof(*slave_config));
24602464
24612465 return 0;
24622466 }
....@@ -2467,7 +2471,6 @@
24672471 struct dma_pl330_desc *desc;
24682472 unsigned long flags;
24692473 struct pl330_dmac *pl330 = pch->dmac;
2470
- LIST_HEAD(list);
24712474 bool power_down = false;
24722475
24732476 pm_runtime_get_sync(pl330->ddma.dev);
....@@ -2517,6 +2520,7 @@
25172520 {
25182521 struct dma_pl330_chan *pch = to_pchan(chan);
25192522 struct pl330_dmac *pl330 = pch->dmac;
2523
+ struct dma_pl330_desc *desc;
25202524 unsigned long flags;
25212525
25222526 pm_runtime_get_sync(pl330->ddma.dev);
....@@ -2526,6 +2530,10 @@
25262530 _stop(pch->thread);
25272531 spin_unlock(&pl330->lock);
25282532
2533
+ list_for_each_entry(desc, &pch->work_list, node) {
2534
+ if (desc->status == BUSY)
2535
+ desc->status = PAUSED;
2536
+ }
25292537 spin_unlock_irqrestore(&pch->lock, flags);
25302538 pm_runtime_mark_last_busy(pl330->ddma.dev);
25312539 pm_runtime_put_autosuspend(pl330->ddma.dev);
....@@ -2615,7 +2623,7 @@
26152623 else if (running && desc == running)
26162624 transferred =
26172625 pl330_get_current_xferred_count(pch, desc);
2618
- else if (desc->status == BUSY)
2626
+ else if (desc->status == BUSY || desc->status == PAUSED)
26192627 /*
26202628 * Busy but not running means either just enqueued,
26212629 * or finished and not yet marked done
....@@ -2631,6 +2639,9 @@
26312639 switch (desc->status) {
26322640 case DONE:
26332641 ret = DMA_COMPLETE;
2642
+ break;
2643
+ case PAUSED:
2644
+ ret = DMA_PAUSED;
26342645 break;
26352646 case PREP:
26362647 case BUSY:
....@@ -2672,7 +2683,7 @@
26722683 list_splice_tail_init(&pch->submitted_list, &pch->work_list);
26732684 spin_unlock_irqrestore(&pch->lock, flags);
26742685
2675
- pl330_tasklet((unsigned long)pch);
2686
+ pl330_tasklet(&pch->task);
26762687 }
26772688
26782689 /*
....@@ -2776,7 +2787,7 @@
27762787
27772788 /* If the DMAC pool is empty, alloc new */
27782789 if (!desc) {
2779
- DEFINE_SPINLOCK(lock);
2790
+ static DEFINE_SPINLOCK(lock);
27802791 LIST_HEAD(pool);
27812792
27822793 if (!add_desc(&pool, &lock, GFP_ATOMIC, 1))
....@@ -2796,6 +2807,10 @@
27962807
27972808 desc->cyclic = false;
27982809 desc->num_periods = 1;
2810
+
2811
+ desc->sgl.size = 0;
2812
+ desc->sgl.src_icg = 0;
2813
+ desc->sgl.dst_icg = 0;
27992814
28002815 dma_async_tx_descriptor_init(&desc->txd, &pch->chan);
28012816
....@@ -2862,8 +2877,8 @@
28622877 {
28632878 struct dma_pl330_desc *desc = NULL;
28642879 struct dma_pl330_chan *pch = to_pchan(chan);
2865
- dma_addr_t dst;
2866
- dma_addr_t src;
2880
+ dma_addr_t dst = 0;
2881
+ dma_addr_t src = 0;
28672882
28682883 if (len % period_len != 0)
28692884 return NULL;
....@@ -2873,6 +2888,8 @@
28732888 __func__, __LINE__);
28742889 return NULL;
28752890 }
2891
+
2892
+ pl330_config_write(chan, &pch->slave_config, direction);
28762893
28772894 if (!pl330_prep_slave_fifo(pch, direction))
28782895 return NULL;
....@@ -2911,8 +2928,80 @@
29112928 desc->num_periods = len / period_len;
29122929 desc->txd.flags = flags;
29132930
2914
- desc->src_interlace_size = pch->src_interlace_size;
2915
- desc->dst_interlace_size = pch->dst_interlace_size;
2931
+ return &desc->txd;
2932
+}
2933
+
2934
+static struct dma_async_tx_descriptor *pl330_prep_interleaved_dma(
2935
+ struct dma_chan *chan, struct dma_interleaved_template *xt,
2936
+ unsigned long flags)
2937
+{
2938
+ struct dma_pl330_desc *desc = NULL;
2939
+ struct dma_pl330_chan *pch = to_pchan(chan);
2940
+ dma_addr_t dst = 0, src = 0;
2941
+ size_t size, src_icg, dst_icg, period_bytes, buffer_bytes, full_buffer_bytes;
2942
+ size_t nump = 0, numf = 0;
2943
+
2944
+ if (!xt->numf || !xt->sgl[0].size || xt->frame_size != 1)
2945
+ return NULL;
2946
+
2947
+#ifdef CONFIG_NO_GKI
2948
+ nump = xt->nump;
2949
+#endif
2950
+ numf = xt->numf;
2951
+ size = xt->sgl[0].size;
2952
+ period_bytes = size * nump;
2953
+ buffer_bytes = size * numf;
2954
+
2955
+ if (flags & DMA_PREP_REPEAT && (!nump || (numf % nump)))
2956
+ return NULL;
2957
+
2958
+ src_icg = dmaengine_get_src_icg(xt, &xt->sgl[0]);
2959
+ dst_icg = dmaengine_get_dst_icg(xt, &xt->sgl[0]);
2960
+
2961
+ pl330_config_write(chan, &pch->slave_config, xt->dir);
2962
+
2963
+ if (!pl330_prep_slave_fifo(pch, xt->dir))
2964
+ return NULL;
2965
+
2966
+ desc = pl330_get_desc(pch);
2967
+ if (!desc) {
2968
+ dev_err(chan->device->dev, "Failed to get desc\n");
2969
+ return NULL;
2970
+ }
2971
+
2972
+ if (xt->dir == DMA_MEM_TO_DEV) {
2973
+ desc->rqcfg.src_inc = 1;
2974
+ desc->rqcfg.dst_inc = 0;
2975
+ src = xt->src_start;
2976
+ dst = pch->fifo_dma;
2977
+ full_buffer_bytes = (size + src_icg) * numf;
2978
+ } else {
2979
+ desc->rqcfg.src_inc = 0;
2980
+ desc->rqcfg.dst_inc = 1;
2981
+ src = pch->fifo_dma;
2982
+ dst = xt->dst_start;
2983
+ full_buffer_bytes = (size + dst_icg) * numf;
2984
+ }
2985
+
2986
+ desc->rqtype = xt->dir;
2987
+ desc->rqcfg.brst_size = pch->burst_sz;
2988
+ desc->rqcfg.brst_len = pch->burst_len;
2989
+ desc->bytes_requested = full_buffer_bytes;
2990
+ desc->sgl.size = size;
2991
+ desc->sgl.src_icg = src_icg;
2992
+ desc->sgl.dst_icg = dst_icg;
2993
+ desc->txd.flags = flags;
2994
+
2995
+ if (flags & DMA_PREP_REPEAT) {
2996
+ desc->cyclic = true;
2997
+ desc->num_periods = numf / nump;
2998
+ fill_px(&desc->px, dst, src, period_bytes);
2999
+ } else {
3000
+ fill_px(&desc->px, dst, src, buffer_bytes);
3001
+ }
3002
+
3003
+ dev_dbg(chan->device->dev, "size: %zu, src_icg: %zu, dst_icg: %zu, nump: %zu, numf: %zu\n",
3004
+ size, src_icg, dst_icg, nump, numf);
29163005
29173006 return &desc->txd;
29183007 }
....@@ -3004,6 +3093,8 @@
30043093 if (unlikely(!pch || !sgl || !sg_len))
30053094 return NULL;
30063095
3096
+ pl330_config_write(chan, &pch->slave_config, direction);
3097
+
30073098 if (!pl330_prep_slave_fifo(pch, direction))
30083099 return NULL;
30093100
....@@ -3044,8 +3135,6 @@
30443135 desc->rqcfg.brst_len = pch->burst_len;
30453136 desc->rqtype = direction;
30463137 desc->bytes_requested = sg_dma_len(sg);
3047
- desc->src_interlace_size = pch->src_interlace_size;
3048
- desc->dst_interlace_size = pch->dst_interlace_size;
30493138 }
30503139
30513140 /* Return the last desc in the chain */
....@@ -3068,6 +3157,55 @@
30683157 BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | \
30693158 BIT(DMA_SLAVE_BUSWIDTH_8_BYTES)
30703159
3160
+#ifdef CONFIG_DEBUG_FS
3161
+static int pl330_debugfs_show(struct seq_file *s, void *data)
3162
+{
3163
+ struct pl330_dmac *pl330 = s->private;
3164
+ int chans, pchs, ch, pr;
3165
+
3166
+ chans = pl330->pcfg.num_chan;
3167
+ pchs = pl330->num_peripherals;
3168
+
3169
+ seq_puts(s, "PL330 physical channels:\n");
3170
+ seq_puts(s, "THREAD:\t\tCHANNEL:\n");
3171
+ seq_puts(s, "--------\t-----\n");
3172
+ for (ch = 0; ch < chans; ch++) {
3173
+ struct pl330_thread *thrd = &pl330->channels[ch];
3174
+ int found = -1;
3175
+
3176
+ for (pr = 0; pr < pchs; pr++) {
3177
+ struct dma_pl330_chan *pch = &pl330->peripherals[pr];
3178
+
3179
+ if (!pch->thread || thrd->id != pch->thread->id)
3180
+ continue;
3181
+
3182
+ found = pr;
3183
+ }
3184
+
3185
+ seq_printf(s, "%d\t\t", thrd->id);
3186
+ if (found == -1)
3187
+ seq_puts(s, "--\n");
3188
+ else
3189
+ seq_printf(s, "%d\n", found);
3190
+ }
3191
+
3192
+ return 0;
3193
+}
3194
+
3195
+DEFINE_SHOW_ATTRIBUTE(pl330_debugfs);
3196
+
3197
+static inline void init_pl330_debugfs(struct pl330_dmac *pl330)
3198
+{
3199
+ debugfs_create_file(dev_name(pl330->ddma.dev),
3200
+ S_IFREG | 0444, NULL, pl330,
3201
+ &pl330_debugfs_fops);
3202
+}
3203
+#else
3204
+static inline void init_pl330_debugfs(struct pl330_dmac *pl330)
3205
+{
3206
+}
3207
+#endif
3208
+
30713209 /*
30723210 * Runtime PM callbacks are provided by amba/bus.c driver.
30733211 *
....@@ -3078,12 +3216,7 @@
30783216 {
30793217 struct amba_device *pcdev = to_amba_device(dev);
30803218
3081
- pm_runtime_disable(dev);
3082
-
3083
- if (!pm_runtime_status_suspended(dev)) {
3084
- /* amba did not disable the clock */
3085
- amba_pclk_disable(pcdev);
3086
- }
3219
+ pm_runtime_force_suspend(dev);
30873220 amba_pclk_unprepare(pcdev);
30883221
30893222 return 0;
....@@ -3098,15 +3231,14 @@
30983231 if (ret)
30993232 return ret;
31003233
3101
- if (!pm_runtime_status_suspended(dev))
3102
- ret = amba_pclk_enable(pcdev);
3103
-
3104
- pm_runtime_enable(dev);
3234
+ pm_runtime_force_resume(dev);
31053235
31063236 return ret;
31073237 }
31083238
3109
-static SIMPLE_DEV_PM_OPS(pl330_pm, pl330_suspend, pl330_resume);
3239
+static const struct dev_pm_ops pl330_pm = {
3240
+ SET_LATE_SYSTEM_SLEEP_PM_OPS(pl330_suspend, pl330_resume)
3241
+};
31103242
31113243 static int
31123244 pl330_probe(struct amba_device *adev, const struct amba_id *id)
....@@ -3118,6 +3250,7 @@
31183250 struct resource *res;
31193251 int i, ret, irq;
31203252 int num_chan;
3253
+ int val;
31213254 struct device_node *np = adev->dev.of_node;
31223255
31233256 ret = dma_set_mask_and_coherent(&adev->dev, DMA_BIT_MASK(32));
....@@ -3132,7 +3265,12 @@
31323265 pd = &pl330->ddma;
31333266 pd->dev = &adev->dev;
31343267
3135
- pl330->mcbufsz = 0;
3268
+ if (!device_property_read_u32(&adev->dev, "arm,pl330-mcbufsz-bytes", &val)) {
3269
+ if ((val > 0) && (val <= PAGE_SIZE))
3270
+ pl330->mcbufsz = val;
3271
+
3272
+ dev_info(&adev->dev, "mcbufsz: %d bytes\n", pl330->mcbufsz);
3273
+ }
31363274
31373275 /* get quirk */
31383276 for (i = 0; i < ARRAY_SIZE(of_quirks); i++)
....@@ -3145,6 +3283,29 @@
31453283 return PTR_ERR(pl330->base);
31463284
31473285 amba_set_drvdata(adev, pl330);
3286
+
3287
+ pl330->rstc = devm_reset_control_get_optional(&adev->dev, "dma");
3288
+ if (IS_ERR(pl330->rstc)) {
3289
+ return dev_err_probe(&adev->dev, PTR_ERR(pl330->rstc), "Failed to get reset!\n");
3290
+ } else {
3291
+ ret = reset_control_deassert(pl330->rstc);
3292
+ if (ret) {
3293
+ dev_err(&adev->dev, "Couldn't deassert the device from reset!\n");
3294
+ return ret;
3295
+ }
3296
+ }
3297
+
3298
+ pl330->rstc_ocp = devm_reset_control_get_optional(&adev->dev, "dma-ocp");
3299
+ if (IS_ERR(pl330->rstc_ocp)) {
3300
+ return dev_err_probe(&adev->dev, PTR_ERR(pl330->rstc_ocp),
3301
+ "Failed to get OCP reset!\n");
3302
+ } else {
3303
+ ret = reset_control_deassert(pl330->rstc_ocp);
3304
+ if (ret) {
3305
+ dev_err(&adev->dev, "Couldn't deassert the device from OCP reset!\n");
3306
+ return ret;
3307
+ }
3308
+ }
31483309
31493310 for (i = 0; i < AMBA_NR_IRQS; i++) {
31503311 irq = adev->irq[i];
....@@ -3209,12 +3370,16 @@
32093370 dma_cap_set(DMA_SLAVE, pd->cap_mask);
32103371 dma_cap_set(DMA_CYCLIC, pd->cap_mask);
32113372 dma_cap_set(DMA_PRIVATE, pd->cap_mask);
3373
+ dma_cap_set(DMA_INTERLEAVE, pd->cap_mask);
3374
+ dma_cap_set(DMA_REPEAT, pd->cap_mask);
3375
+ dma_cap_set(DMA_LOAD_EOT, pd->cap_mask);
32123376 }
32133377
32143378 pd->device_alloc_chan_resources = pl330_alloc_chan_resources;
32153379 pd->device_free_chan_resources = pl330_free_chan_resources;
32163380 pd->device_prep_dma_memcpy = pl330_prep_dma_memcpy;
32173381 pd->device_prep_dma_cyclic = pl330_prep_dma_cyclic;
3382
+ pd->device_prep_interleaved_dma = pl330_prep_interleaved_dma;
32183383 pd->device_tx_status = pl330_tx_status;
32193384 pd->device_prep_slave_sg = pl330_prep_slave_sg;
32203385 pd->device_config = pl330_config;
....@@ -3242,8 +3407,6 @@
32423407 }
32433408 }
32443409
3245
- adev->dev.dma_parms = &pl330->dma_parms;
3246
-
32473410 /*
32483411 * This is the limit for transfers with a buswidth of 1, larger
32493412 * buswidths will have larger limits.
....@@ -3253,6 +3416,7 @@
32533416 dev_err(&adev->dev, "unable to set the seg size\n");
32543417
32553418
3419
+ init_pl330_debugfs(pl330);
32563420 dev_info(&adev->dev,
32573421 "Loaded driver for PL330 DMAC-%x\n", adev->periphid);
32583422 dev_info(&adev->dev,
....@@ -3284,10 +3448,15 @@
32843448 probe_err2:
32853449 pl330_del(pl330);
32863450
3451
+ if (pl330->rstc_ocp)
3452
+ reset_control_assert(pl330->rstc_ocp);
3453
+
3454
+ if (pl330->rstc)
3455
+ reset_control_assert(pl330->rstc);
32873456 return ret;
32883457 }
32893458
3290
-static int pl330_remove(struct amba_device *adev)
3459
+static void pl330_remove(struct amba_device *adev)
32913460 {
32923461 struct pl330_dmac *pl330 = amba_get_drvdata(adev);
32933462 struct dma_pl330_chan *pch, *_p;
....@@ -3322,7 +3491,11 @@
33223491
33233492 pl330_del(pl330);
33243493
3325
- return 0;
3494
+ if (pl330->rstc_ocp)
3495
+ reset_control_assert(pl330->rstc_ocp);
3496
+
3497
+ if (pl330->rstc)
3498
+ reset_control_assert(pl330->rstc);
33263499 }
33273500
33283501 static const struct amba_id pl330_ids[] = {