Merge branch 'linux-linaro-lsk-v4.4-android' of git://git.linaro.org/kernel/linux...
[firefly-linux-kernel-4.4.55.git] / drivers / dma / pl330.c
index 8250950aab8b652f86fdf8fe99955c7f94738c36..5e0c2607176fab6bcf19686b06dc57a35a66f2ba 100644 (file)
@@ -33,6 +33,9 @@
 #define PL330_MAX_CHAN         8
 #define PL330_MAX_IRQS         32
 #define PL330_MAX_PERI         32
+#define PL330_MAX_BURST         16
+
+#define PL330_QUIRK_BROKEN_NO_FLUSHP BIT(0)
 
 enum pl330_cachectrl {
        CCTRL0,         /* Noncacheable and nonbufferable */
@@ -237,6 +240,7 @@ enum pl330_byteswap {
 
 #define BYTE_TO_BURST(b, ccr)  ((b) / BRST_SIZE(ccr) / BRST_LEN(ccr))
 #define BURST_TO_BYTE(c, ccr)  ((c) * BRST_SIZE(ccr) * BRST_LEN(ccr))
+#define BYTE_MOD_BURST_LEN(b, ccr)     (((b) / BRST_SIZE(ccr)) % BRST_LEN(ccr))
 
 /*
  * With 256 bytes, we can do more than 2.5MB and 5MB xfers per req
@@ -491,6 +495,19 @@ struct pl330_dmac {
        /* Peripheral channels connected to this DMAC */
        unsigned int num_peripherals;
        struct dma_pl330_chan *peripherals; /* keep at end */
+       /* set peripherals request type according to soc config*/
+       enum pl330_cond peripherals_req_type;
+       int quirks;
+};
+
+static struct pl330_of_quirks {
+       char *quirk;
+       int id;
+} of_quirks[] = {
+       {
+               .quirk = "arm,pl330-broken-no-flushp",
+               .id = PL330_QUIRK_BROKEN_NO_FLUSHP,
+       }
 };
 
 struct dma_pl330_desc {
@@ -1140,47 +1157,57 @@ static inline int _ldst_memtomem(unsigned dry_run, u8 buf[],
        return off;
 }
 
-static inline int _ldst_devtomem(unsigned dry_run, u8 buf[],
-               const struct _xfer_spec *pxs, int cyc)
+static inline int _ldst_devtomem(struct pl330_dmac *pl330, unsigned dry_run,
+                                u8 buf[], const struct _xfer_spec *pxs,
+                                int cyc)
 {
        int off = 0;
+       enum pl330_cond cond = pl330->peripherals_req_type;
 
        while (cyc--) {
-               off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->desc->peri);
-               off += _emit_LDP(dry_run, &buf[off], SINGLE, pxs->desc->peri);
+               off += _emit_WFP(dry_run, &buf[off], cond, pxs->desc->peri);
+               off += _emit_LDP(dry_run, &buf[off], cond, pxs->desc->peri);
                off += _emit_ST(dry_run, &buf[off], ALWAYS);
-               off += _emit_FLUSHP(dry_run, &buf[off], pxs->desc->peri);
+
+               if (!(pl330->quirks & PL330_QUIRK_BROKEN_NO_FLUSHP))
+                       off += _emit_FLUSHP(dry_run, &buf[off],
+                                           pxs->desc->peri);
        }
 
        return off;
 }
 
-static inline int _ldst_memtodev(unsigned dry_run, u8 buf[],
-               const struct _xfer_spec *pxs, int cyc)
+static inline int _ldst_memtodev(struct pl330_dmac *pl330,
+                                unsigned dry_run, u8 buf[],
+                                const struct _xfer_spec *pxs, int cyc)
 {
        int off = 0;
+       enum pl330_cond cond = pl330->peripherals_req_type;
 
        while (cyc--) {
-               off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->desc->peri);
+               off += _emit_WFP(dry_run, &buf[off], cond, pxs->desc->peri);
                off += _emit_LD(dry_run, &buf[off], ALWAYS);
-               off += _emit_STP(dry_run, &buf[off], SINGLE, pxs->desc->peri);
-               off += _emit_FLUSHP(dry_run, &buf[off], pxs->desc->peri);
+               off += _emit_STP(dry_run, &buf[off], cond, pxs->desc->peri);
+
+               if (!(pl330->quirks & PL330_QUIRK_BROKEN_NO_FLUSHP))
+                       off += _emit_FLUSHP(dry_run, &buf[off],
+                                           pxs->desc->peri);
        }
 
        return off;
 }
 
-static int _bursts(unsigned dry_run, u8 buf[],
+static int _bursts(struct pl330_dmac *pl330, unsigned dry_run, u8 buf[],
                const struct _xfer_spec *pxs, int cyc)
 {
        int off = 0;
 
        switch (pxs->desc->rqtype) {
        case DMA_MEM_TO_DEV:
-               off += _ldst_memtodev(dry_run, &buf[off], pxs, cyc);
+               off += _ldst_memtodev(pl330, dry_run, &buf[off], pxs, cyc);
                break;
        case DMA_DEV_TO_MEM:
-               off += _ldst_devtomem(dry_run, &buf[off], pxs, cyc);
+               off += _ldst_devtomem(pl330, dry_run, &buf[off], pxs, cyc);
                break;
        case DMA_MEM_TO_MEM:
                off += _ldst_memtomem(dry_run, &buf[off], pxs, cyc);
@@ -1194,7 +1221,7 @@ static int _bursts(unsigned dry_run, u8 buf[],
 }
 
 /* Returns bytes consumed and updates bursts */
-static inline int _loop(unsigned dry_run, u8 buf[],
+static inline int _loop(struct pl330_dmac *pl330, unsigned dry_run, u8 buf[],
                unsigned long *bursts, const struct _xfer_spec *pxs)
 {
        int cyc, cycmax, szlp, szlpend, szbrst, off;
@@ -1202,7 +1229,7 @@ static inline int _loop(unsigned dry_run, u8 buf[],
        struct _arg_LPEND lpend;
 
        if (*bursts == 1)
-               return _bursts(dry_run, buf, pxs, 1);
+               return _bursts(pl330, dry_run, buf, pxs, 1);
 
        /* Max iterations possible in DMALP is 256 */
        if (*bursts >= 256*256) {
@@ -1220,7 +1247,7 @@ static inline int _loop(unsigned dry_run, u8 buf[],
        }
 
        szlp = _emit_LP(1, buf, 0, 0);
-       szbrst = _bursts(1, buf, pxs, 1);
+       szbrst = _bursts(pl330, 1, buf, pxs, 1);
 
        lpend.cond = ALWAYS;
        lpend.forever = false;
@@ -1252,7 +1279,7 @@ static inline int _loop(unsigned dry_run, u8 buf[],
        off += _emit_LP(dry_run, &buf[off], 1, lcnt1);
        ljmp1 = off;
 
-       off += _bursts(dry_run, &buf[off], pxs, cyc);
+       off += _bursts(pl330, dry_run, &buf[off], pxs, cyc);
 
        lpend.cond = ALWAYS;
        lpend.forever = false;
@@ -1275,8 +1302,9 @@ static inline int _loop(unsigned dry_run, u8 buf[],
        return off;
 }
 
-static inline int _setup_loops(unsigned dry_run, u8 buf[],
-               const struct _xfer_spec *pxs)
+static inline int _setup_loops(struct pl330_dmac *pl330,
+                              unsigned dry_run, u8 buf[],
+                              const struct _xfer_spec *pxs)
 {
        struct pl330_xfer *x = &pxs->desc->px;
        u32 ccr = pxs->ccr;
@@ -1285,15 +1313,16 @@ static inline int _setup_loops(unsigned dry_run, u8 buf[],
 
        while (bursts) {
                c = bursts;
-               off += _loop(dry_run, &buf[off], &c, pxs);
+               off += _loop(pl330, dry_run, &buf[off], &c, pxs);
                bursts -= c;
        }
 
        return off;
 }
 
-static inline int _setup_xfer(unsigned dry_run, u8 buf[],
-               const struct _xfer_spec *pxs)
+static inline int _setup_xfer(struct pl330_dmac *pl330,
+                             unsigned dry_run, u8 buf[],
+                             const struct _xfer_spec *pxs)
 {
        struct pl330_xfer *x = &pxs->desc->px;
        int off = 0;
@@ -1304,7 +1333,21 @@ static inline int _setup_xfer(unsigned dry_run, u8 buf[],
        off += _emit_MOV(dry_run, &buf[off], DAR, x->dst_addr);
 
        /* Setup Loop(s) */
-       off += _setup_loops(dry_run, &buf[off], pxs);
+       off += _setup_loops(pl330, dry_run, &buf[off], pxs);
+
+       if (pl330->peripherals_req_type == BURST) {
+               unsigned int ccr = pxs->ccr;
+               unsigned long c = 0;
+
+               c = BYTE_MOD_BURST_LEN(x->bytes, pxs->ccr);
+
+               if (c) {
+                       ccr &= ~(0xf << CC_SRCBRSTLEN_SHFT);
+                       ccr &= ~(0xf << CC_DSTBRSTLEN_SHFT);
+                       off += _emit_MOV(dry_run, &buf[off], CCR, ccr);
+                       off += _loop(pl330, dry_run, &buf[off], &c, pxs);
+               }
+       }
 
        return off;
 }
@@ -1313,8 +1356,9 @@ static inline int _setup_xfer(unsigned dry_run, u8 buf[],
  * A req is a sequence of one or more xfer units.
  * Returns the number of bytes taken to setup the MC for the req.
  */
-static int _setup_req(unsigned dry_run, struct pl330_thread *thrd,
-               unsigned index, struct _xfer_spec *pxs)
+static int _setup_req(struct pl330_dmac *pl330, unsigned dry_run,
+                     struct pl330_thread *thrd, unsigned index,
+                     struct _xfer_spec *pxs)
 {
        struct _pl330_req *req = &thrd->req[index];
        struct pl330_xfer *x;
@@ -1327,11 +1371,13 @@ static int _setup_req(unsigned dry_run, struct pl330_thread *thrd,
        off += _emit_MOV(dry_run, &buf[off], CCR, pxs->ccr);
 
        x = &pxs->desc->px;
-       /* Error if xfer length is not aligned at burst size */
-       if (x->bytes % (BRST_SIZE(pxs->ccr) * BRST_LEN(pxs->ccr)))
-               return -EINVAL;
+       if (pl330->peripherals_req_type != BURST) {
+               /* Error if xfer length is not aligned at burst size */
+               if (x->bytes % (BRST_SIZE(pxs->ccr) * BRST_LEN(pxs->ccr)))
+                       return -EINVAL;
+       }
 
-       off += _setup_xfer(dry_run, &buf[off], pxs);
+       off += _setup_xfer(pl330, dry_run, &buf[off], pxs);
 
        /* DMASEV peripheral/event */
        off += _emit_SEV(dry_run, &buf[off], thrd->ev);
@@ -1425,7 +1471,7 @@ static int pl330_submit_req(struct pl330_thread *thrd,
        xs.desc = desc;
 
        /* First dry run to check if req is acceptable */
-       ret = _setup_req(1, thrd, idx, &xs);
+       ret = _setup_req(pl330, 1, thrd, idx, &xs);
        if (ret < 0)
                goto xfer_exit;
 
@@ -1439,7 +1485,7 @@ static int pl330_submit_req(struct pl330_thread *thrd,
        /* Hook the request */
        thrd->lstenq = idx;
        thrd->req[idx].desc = desc;
-       _setup_req(0, thrd, idx, &xs);
+       _setup_req(pl330, 0, thrd, idx, &xs);
 
        ret = 0;
 
@@ -2571,7 +2617,12 @@ static struct dma_async_tx_descriptor *pl330_prep_dma_cyclic(
 
                desc->rqtype = direction;
                desc->rqcfg.brst_size = pch->burst_sz;
-               desc->rqcfg.brst_len = 1;
+
+               if (pl330->peripherals_req_type == BURST)
+                       desc->rqcfg.brst_len = pch->burst_len;
+               else
+                       desc->rqcfg.brst_len = 1;
+
                desc->bytes_requested = period_len;
                fill_px(&desc->px, dst, src, period_len);
 
@@ -2673,6 +2724,7 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 {
        struct dma_pl330_desc *first, *desc = NULL;
        struct dma_pl330_chan *pch = to_pchan(chan);
+       struct pl330_dmac *pl330 = pch->dmac;
        struct scatterlist *sg;
        int i;
        dma_addr_t addr;
@@ -2716,7 +2768,12 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
                }
 
                desc->rqcfg.brst_size = pch->burst_sz;
-               desc->rqcfg.brst_len = 1;
+
+               if (pl330->peripherals_req_type == BURST)
+                       desc->rqcfg.brst_len = pch->burst_len;
+               else
+                       desc->rqcfg.brst_len = 1;
+
                desc->rqtype = direction;
                desc->bytes_requested = sg_dma_len(sg);
        }
@@ -2792,6 +2849,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
        struct resource *res;
        int i, ret, irq;
        int num_chan;
+       struct device_node *np = adev->dev.of_node;
 
        pdat = dev_get_platdata(&adev->dev);
 
@@ -2811,6 +2869,16 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 
        pl330->mcbufsz = pdat ? pdat->mcbuf_sz : 0;
 
+       if (of_find_property(np, "peripherals-req-type-burst", NULL))
+               pl330->peripherals_req_type = BURST;
+       else
+               pl330->peripherals_req_type = SINGLE;
+
+       /* get quirk */
+       for (i = 0; i < ARRAY_SIZE(of_quirks); i++)
+               if (of_property_read_bool(np, of_quirks[i].quirk))
+                       pl330->quirks |= of_quirks[i].id;
+
        res = &adev->res;
        pl330->base = devm_ioremap_resource(&adev->dev, res);
        if (IS_ERR(pl330->base))
@@ -2906,6 +2974,8 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
        pd->dst_addr_widths = PL330_DMA_BUSWIDTHS;
        pd->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
        pd->residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
+       pd->max_burst = ((pl330->quirks & PL330_QUIRK_BROKEN_NO_FLUSHP) ?
+                        1 : PL330_MAX_BURST);
 
        ret = dma_async_device_register(pd);
        if (ret) {