dmaengine: PL08x: get src/dst addr direct from dma_slave_config struct
[firefly-linux-kernel-4.4.55.git] / drivers / dma / amba-pl08x.c
index 49ecbbb8932df2ecbc10aa601edd274acc21cf19..31447dbe23a6f26d03d18abbb6321ff60ac61569 100644 (file)
@@ -90,6 +90,7 @@
 #define DRIVER_NAME    "pl08xdmac"
 
 static struct amba_driver pl08x_amba_driver;
+struct pl08x_driver_data;
 
 /**
  * struct vendor_data - vendor-specific config parameters for PL08x derivatives
@@ -118,6 +119,140 @@ struct pl08x_lli {
        u32 cctl;
 };
 
+/**
+ * struct pl08x_bus_data - information of source or destination
+ * busses for a transfer
+ * @addr: current address
+ * @maxwidth: the maximum width of a transfer on this bus
+ * @buswidth: the width of this bus in bytes: 1, 2 or 4
+ */
+struct pl08x_bus_data {
+       dma_addr_t addr;
+       u8 maxwidth;
+       u8 buswidth;
+};
+
+/**
+ * struct pl08x_phy_chan - holder for the physical channels
+ * @id: physical index to this channel
+ * @lock: a lock to use when altering an instance of this struct
+ * @signal: the physical signal (aka channel) serving this physical channel
+ * right now
+ * @serving: the virtual channel currently being served by this physical
+ * channel
+ */
+struct pl08x_phy_chan {
+       unsigned int id;
+       void __iomem *base;
+       spinlock_t lock;
+       int signal;
+       struct pl08x_dma_chan *serving;
+};
+
+/**
+ * struct pl08x_sg - structure containing data per sg
+ * @src_addr: src address of sg
+ * @dst_addr: dst address of sg
+ * @len: transfer len in bytes
+ * @node: node for txd's dsg_list
+ */
+struct pl08x_sg {
+       dma_addr_t src_addr;
+       dma_addr_t dst_addr;
+       size_t len;
+       struct list_head node;
+};
+
+/**
+ * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor
+ * @tx: async tx descriptor
+ * @node: node for txd list for channels
+ * @dsg_list: list of children sg's
+ * @direction: direction of transfer
+ * @llis_bus: DMA memory address (physical) start for the LLIs
+ * @llis_va: virtual memory address start for the LLIs
+ * @cctl: control reg values for current txd
+ * @ccfg: config reg values for current txd
+ */
+struct pl08x_txd {
+       struct dma_async_tx_descriptor tx;
+       struct list_head node;
+       struct list_head dsg_list;
+       enum dma_transfer_direction direction;
+       dma_addr_t llis_bus;
+       struct pl08x_lli *llis_va;
+       /* Default cctl value for LLIs */
+       u32 cctl;
+       /*
+        * Settings to be put into the physical channel when we
+        * trigger this txd.  Other registers are in llis_va[0].
+        */
+       u32 ccfg;
+};
+
+/**
+ * struct pl08x_dma_chan_state - holds the PL08x specific virtual channel
+ * states
+ * @PL08X_CHAN_IDLE: the channel is idle
+ * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport
+ * channel and is running a transfer on it
+ * @PL08X_CHAN_PAUSED: the channel has allocated a physical transport
+ * channel, but the transfer is currently paused
+ * @PL08X_CHAN_WAITING: the channel is waiting for a physical transport
+ * channel to become available (only pertains to memcpy channels)
+ */
+enum pl08x_dma_chan_state {
+       PL08X_CHAN_IDLE,
+       PL08X_CHAN_RUNNING,
+       PL08X_CHAN_PAUSED,
+       PL08X_CHAN_WAITING,
+};
+
+/**
+ * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel
+ * @chan: wrappped abstract channel
+ * @phychan: the physical channel utilized by this channel, if there is one
+ * @phychan_hold: if non-zero, hold on to the physical channel even if we
+ * have no pending entries
+ * @tasklet: tasklet scheduled by the IRQ to handle actual work etc
+ * @name: name of channel
+ * @cd: channel platform data
+ * @runtime_addr: address for RX/TX according to the runtime config
+ * @runtime_direction: current direction of this channel according to
+ * runtime config
+ * @pend_list: queued transactions pending on this channel
+ * @at: active transaction on this channel
+ * @lock: a lock for this channel data
+ * @host: a pointer to the host (internal use)
+ * @state: whether the channel is idle, paused, running etc
+ * @slave: whether this channel is a device (slave) or for memcpy
+ * @device_fc: Flow Controller Settings for ccfg register. Only valid for slave
+ * channels. Fill with 'true' if peripheral should be flow controller. Direction
+ * will be selected at Runtime.
+ * @waiting: a TX descriptor on this channel which is waiting for a physical
+ * channel to become available
+ */
+struct pl08x_dma_chan {
+       struct dma_chan chan;
+       struct pl08x_phy_chan *phychan;
+       int phychan_hold;
+       struct tasklet_struct tasklet;
+       const char *name;
+       const struct pl08x_channel_data *cd;
+       struct dma_slave_config cfg;
+       u32 src_cctl;
+       u32 dst_cctl;
+       enum dma_transfer_direction runtime_direction;
+       struct list_head pend_list;
+       struct pl08x_txd *at;
+       spinlock_t lock;
+       struct pl08x_driver_data *host;
+       enum pl08x_dma_chan_state state;
+       bool slave;
+       bool device_fc;
+       struct pl08x_txd *waiting;
+};
+
 /**
  * struct pl08x_driver_data - the local state holder for the PL08x
  * @slave: slave engine for this instance
@@ -146,7 +281,6 @@ struct pl08x_driver_data {
        int pool_ctr;
        u8 lli_buses;
        u8 mem_buses;
-       spinlock_t lock;
 };
 
 /*
@@ -404,7 +538,6 @@ pl08x_get_phy_channel(struct pl08x_driver_data *pl08x,
                return NULL;
        }
 
-       pm_runtime_get_sync(&pl08x->adev->dev);
        return ch;
 }
 
@@ -418,8 +551,6 @@ static inline void pl08x_put_phy_channel(struct pl08x_driver_data *pl08x,
        /* Stop the channel and clear its interrupts */
        pl08x_terminate_phy_chan(pl08x, ch);
 
-       pm_runtime_put(&pl08x->adev->dev);
-
        /* Mark it as free */
        ch->serving = NULL;
        spin_unlock_irqrestore(&ch->lock, flags);
@@ -878,7 +1009,7 @@ static int prep_phy_channel(struct pl08x_dma_chan *plchan,
         * Can the platform allow us to use this channel?
         */
        if (plchan->slave && pl08x->pd->get_signal) {
-               ret = pl08x->pd->get_signal(plchan);
+               ret = pl08x->pd->get_signal(plchan->cd);
                if (ret < 0) {
                        dev_dbg(&pl08x->adev->dev,
                                "unable to use physical channel %d for transfer on %s due to platform restrictions\n",
@@ -913,7 +1044,7 @@ static void release_phy_channel(struct pl08x_dma_chan *plchan)
        struct pl08x_driver_data *pl08x = plchan->host;
 
        if ((plchan->phychan->signal >= 0) && pl08x->pd->put_signal) {
-               pl08x->pd->put_signal(plchan);
+               pl08x->pd->put_signal(plchan->cd, plchan->phychan->signal);
                plchan->phychan->signal = -1;
        }
        pl08x_put_phy_channel(pl08x, plchan->phychan);
@@ -1113,6 +1244,8 @@ static int dma_set_runtime_config(struct dma_chan *chan,
                return -EINVAL;
        }
 
+       plchan->cfg = *config;
+
        cctl |= width << PL080_CONTROL_SWIDTH_SHIFT;
        cctl |= width << PL080_CONTROL_DWIDTH_SHIFT;
 
@@ -1131,12 +1264,10 @@ static int dma_set_runtime_config(struct dma_chan *chan,
        plchan->device_fc = config->device_fc;
 
        if (plchan->runtime_direction == DMA_DEV_TO_MEM) {
-               plchan->src_addr = config->src_addr;
                plchan->src_cctl = pl08x_cctl(cctl) | PL080_CONTROL_DST_INCR |
                        pl08x_select_bus(plchan->cd->periph_buses,
                                         pl08x->mem_buses);
        } else {
-               plchan->dst_addr = config->dst_addr;
                plchan->dst_cctl = pl08x_cctl(cctl) | PL080_CONTROL_SRC_INCR |
                        pl08x_select_bus(pl08x->mem_buses,
                                         plchan->cd->periph_buses);
@@ -1290,7 +1421,7 @@ static struct dma_async_tx_descriptor *pl08x_prep_dma_memcpy(
        }
        list_add_tail(&dsg->node, &txd->dsg_list);
 
-       txd->direction = DMA_NONE;
+       txd->direction = DMA_MEM_TO_MEM;
        dsg->src_addr = src;
        dsg->dst_addr = dest;
        dsg->len = len;
@@ -1350,10 +1481,10 @@ static struct dma_async_tx_descriptor *pl08x_prep_slave_sg(
 
        if (direction == DMA_MEM_TO_DEV) {
                txd->cctl = plchan->dst_cctl;
-               slave_addr = plchan->dst_addr;
+               slave_addr = plchan->cfg.dst_addr;
        } else if (direction == DMA_DEV_TO_MEM) {
                txd->cctl = plchan->src_cctl;
-               slave_addr = plchan->src_addr;
+               slave_addr = plchan->cfg.src_addr;
        } else {
                pl08x_free_txd(pl08x, txd);
                dev_err(&pl08x->adev->dev,
@@ -1658,8 +1789,8 @@ static void pl08x_dma_slave_init(struct pl08x_dma_chan *chan)
 
        chan->slave = true;
        chan->name = chan->cd->bus_id;
-       chan->src_addr = chan->cd->addr;
-       chan->dst_addr = chan->cd->addr;
+       chan->cfg.src_addr = chan->cd->addr;
+       chan->cfg.dst_addr = chan->cd->addr;
        chan->src_cctl = cctl | PL080_CONTROL_DST_INCR |
                pl08x_select_bus(chan->cd->periph_buses, chan->host->mem_buses);
        chan->dst_cctl = cctl | PL080_CONTROL_SRC_INCR |
@@ -1705,13 +1836,6 @@ static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
                                return -ENOMEM;
                        }
                }
-               if (chan->cd->circular_buffer) {
-                       dev_err(&pl08x->adev->dev,
-                               "channel %s: circular buffers not supported\n",
-                               chan->name);
-                       kfree(chan);
-                       continue;
-               }
                dev_dbg(&pl08x->adev->dev,
                         "initialize virtual channel \"%s\"\n",
                         chan->name);
@@ -1851,9 +1975,6 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
                goto out_no_pl08x;
        }
 
-       pm_runtime_set_active(&adev->dev);
-       pm_runtime_enable(&adev->dev);
-
        /* Initialize memcpy engine */
        dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask);
        pl08x->memcpy.dev = &adev->dev;
@@ -1903,8 +2024,6 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
                goto out_no_lli_pool;
        }
 
-       spin_lock_init(&pl08x->lock);
-
        pl08x->base = ioremap(adev->res.start, resource_size(&adev->res));
        if (!pl08x->base) {
                ret = -ENOMEM;
@@ -2007,7 +2126,6 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
                 amba_part(adev), amba_rev(adev),
                 (unsigned long long)adev->res.start, adev->irq[0]);
 
-       pm_runtime_put(&adev->dev);
        return 0;
 
 out_no_slave_reg:
@@ -2026,9 +2144,6 @@ out_no_ioremap:
        dma_pool_destroy(pl08x->pool);
 out_no_lli_pool:
 out_no_platdata:
-       pm_runtime_put(&adev->dev);
-       pm_runtime_disable(&adev->dev);
-
        kfree(pl08x);
 out_no_pl08x:
        amba_release_regions(adev);