blob: f858651027fd981e739b23a268e3f0c30d0ddda0 [file] [log] [blame]
Linus Walleije8689e62010-09-28 15:57:37 +02001/*
2 * linux/amba/pl08x.h - ARM PrimeCell DMA Controller driver
3 *
4 * Copyright (C) 2005 ARM Ltd
5 * Copyright (C) 2010 ST-Ericsson SA
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * pl08x information required by platform code
12 *
13 * Please credit ARM.com
14 * Documentation: ARM DDI 0196D
15 *
16 */
17
18#ifndef AMBA_PL08X_H
19#define AMBA_PL08X_H
20
21/* We need sizes of structs from this header */
22#include <linux/dmaengine.h>
23#include <linux/interrupt.h>
24
Russell King - ARM Linux7cb72ad2011-01-03 22:35:28 +000025struct pl08x_lli;
26struct pl08x_driver_data;
27
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +000028/* Bitmasks for selecting AHB ports for DMA transfers */
29enum {
30 PL08X_AHB1 = (1 << 0),
31 PL08X_AHB2 = (1 << 1)
32};
33
Linus Walleije8689e62010-09-28 15:57:37 +020034/**
35 * struct pl08x_channel_data - data structure to pass info between
36 * platform and PL08x driver regarding channel configuration
37 * @bus_id: name of this device channel, not just a device name since
38 * devices may have more than one channel e.g. "foo_tx"
39 * @min_signal: the minimum DMA signal number to be muxed in for this
40 * channel (for platforms supporting muxed signals). If you have
41 * static assignments, make sure this is set to the assigned signal
42 * number, PL08x have 16 possible signals in number 0 thru 15 so
43 * when these are not enough they often get muxed (in hardware)
44 * disabling simultaneous use of the same channel for two devices.
45 * @max_signal: the maximum DMA signal number to be muxed in for
46 * the channel. Set to the same as min_signal for
47 * devices with static assignments
48 * @muxval: a number usually used to poke into some mux regiser to
49 * mux in the signal to this channel
50 * @cctl_opt: default options for the channel control register
51 * @addr: source/target address in physical memory for this DMA channel,
52 * can be the address of a FIFO register for burst requests for example.
53 * This can be left undefined if the PrimeCell API is used for configuring
54 * this.
55 * @circular_buffer: whether the buffer passed in is circular and
56 * shall simply be looped round round (like a record baby round
57 * round round round)
58 * @single: the device connected to this channel will request single
59 * DMA transfers, not bursts. (Bursts are default.)
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +000060 * @periph_buses: the device connected to this channel is accessible via
61 * these buses (use PL08X_AHB1 | PL08X_AHB2).
Linus Walleije8689e62010-09-28 15:57:37 +020062 */
63struct pl08x_channel_data {
64 char *bus_id;
65 int min_signal;
66 int max_signal;
67 u32 muxval;
68 u32 cctl;
Linus Walleije8689e62010-09-28 15:57:37 +020069 dma_addr_t addr;
70 bool circular_buffer;
71 bool single;
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +000072 u8 periph_buses;
Linus Walleije8689e62010-09-28 15:57:37 +020073};
74
75/**
76 * Struct pl08x_bus_data - information of source or destination
77 * busses for a transfer
78 * @addr: current address
79 * @maxwidth: the maximum width of a transfer on this bus
80 * @buswidth: the width of this bus in bytes: 1, 2 or 4
81 * @fill_bytes: bytes required to fill to the next bus memory
82 * boundary
83 */
84struct pl08x_bus_data {
85 dma_addr_t addr;
86 u8 maxwidth;
87 u8 buswidth;
Russell King - ARM Linuxcace6582011-01-03 22:37:31 +000088 size_t fill_bytes;
Linus Walleije8689e62010-09-28 15:57:37 +020089};
90
91/**
92 * struct pl08x_phy_chan - holder for the physical channels
93 * @id: physical index to this channel
94 * @lock: a lock to use when altering an instance of this struct
95 * @signal: the physical signal (aka channel) serving this
96 * physical channel right now
97 * @serving: the virtual channel currently being served by this
98 * physical channel
99 */
100struct pl08x_phy_chan {
101 unsigned int id;
102 void __iomem *base;
103 spinlock_t lock;
104 int signal;
105 struct pl08x_dma_chan *serving;
Linus Walleije8689e62010-09-28 15:57:37 +0200106};
107
108/**
109 * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor
110 * @llis_bus: DMA memory address (physical) start for the LLIs
111 * @llis_va: virtual memory address start for the LLIs
112 */
113struct pl08x_txd {
114 struct dma_async_tx_descriptor tx;
115 struct list_head node;
116 enum dma_data_direction direction;
117 struct pl08x_bus_data srcbus;
118 struct pl08x_bus_data dstbus;
Russell King - ARM Linuxcace6582011-01-03 22:37:31 +0000119 size_t len;
Linus Walleije8689e62010-09-28 15:57:37 +0200120 dma_addr_t llis_bus;
121 void *llis_va;
Linus Walleije8689e62010-09-28 15:57:37 +0200122 bool active;
Russell King - ARM Linux70b5ed62011-01-03 22:40:13 +0000123 /* Default cctl value for LLIs */
124 u32 cctl;
Russell King - ARM Linux4983a042011-01-03 22:39:33 +0000125 /*
126 * Settings to be put into the physical channel when we
127 * trigger this txd. Other registers are in llis_va[0].
128 */
129 u32 ccfg;
Linus Walleije8689e62010-09-28 15:57:37 +0200130};
131
132/**
133 * struct pl08x_dma_chan_state - holds the PL08x specific virtual
134 * channel states
135 * @PL08X_CHAN_IDLE: the channel is idle
136 * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport
137 * channel and is running a transfer on it
138 * @PL08X_CHAN_PAUSED: the channel has allocated a physical transport
139 * channel, but the transfer is currently paused
140 * @PL08X_CHAN_WAITING: the channel is waiting for a physical transport
141 * channel to become available (only pertains to memcpy channels)
142 */
143enum pl08x_dma_chan_state {
144 PL08X_CHAN_IDLE,
145 PL08X_CHAN_RUNNING,
146 PL08X_CHAN_PAUSED,
147 PL08X_CHAN_WAITING,
148};
149
150/**
151 * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel
152 * @chan: wrappped abstract channel
153 * @phychan: the physical channel utilized by this channel, if there is one
154 * @tasklet: tasklet scheduled by the IRQ to handle actual work etc
155 * @name: name of channel
156 * @cd: channel platform data
157 * @runtime_addr: address for RX/TX according to the runtime config
158 * @runtime_direction: current direction of this channel according to
159 * runtime config
160 * @lc: last completed transaction on this channel
161 * @desc_list: queued transactions pending on this channel
162 * @at: active transaction on this channel
163 * @lockflags: sometimes we let a lock last between two function calls,
164 * especially prep/submit, and then we need to store the IRQ flags
165 * in the channel state, here
166 * @lock: a lock for this channel data
167 * @host: a pointer to the host (internal use)
168 * @state: whether the channel is idle, paused, running etc
169 * @slave: whether this channel is a device (slave) or for memcpy
170 * @waiting: a TX descriptor on this channel which is waiting for
171 * a physical channel to become available
172 */
173struct pl08x_dma_chan {
174 struct dma_chan chan;
175 struct pl08x_phy_chan *phychan;
176 struct tasklet_struct tasklet;
177 char *name;
178 struct pl08x_channel_data *cd;
179 dma_addr_t runtime_addr;
180 enum dma_data_direction runtime_direction;
Linus Walleije8689e62010-09-28 15:57:37 +0200181 dma_cookie_t lc;
182 struct list_head desc_list;
183 struct pl08x_txd *at;
184 unsigned long lockflags;
185 spinlock_t lock;
Russell King - ARM Linux7cb72ad2011-01-03 22:35:28 +0000186 struct pl08x_driver_data *host;
Linus Walleije8689e62010-09-28 15:57:37 +0200187 enum pl08x_dma_chan_state state;
188 bool slave;
189 struct pl08x_txd *waiting;
190};
191
192/**
193 * struct pl08x_platform_data - the platform configuration for the
194 * PL08x PrimeCells.
195 * @slave_channels: the channels defined for the different devices on the
196 * platform, all inclusive, including multiplexed channels. The available
197 * physical channels will be multiplexed around these signals as they
198 * are requested, just enumerate all possible channels.
199 * @get_signal: request a physical signal to be used for a DMA
200 * transfer immediately: if there is some multiplexing or similar blocking
201 * the use of the channel the transfer can be denied by returning
202 * less than zero, else it returns the allocated signal number
203 * @put_signal: indicate to the platform that this physical signal is not
204 * running any DMA transfer and multiplexing can be recycled
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +0000205 * @lli_buses: buses which LLIs can be fetched from: PL08X_AHB1 | PL08X_AHB2
206 * @mem_buses: buses which memory can be accessed from: PL08X_AHB1 | PL08X_AHB2
Linus Walleije8689e62010-09-28 15:57:37 +0200207 */
208struct pl08x_platform_data {
209 struct pl08x_channel_data *slave_channels;
210 unsigned int num_slave_channels;
211 struct pl08x_channel_data memcpy_channel;
212 int (*get_signal)(struct pl08x_dma_chan *);
213 void (*put_signal)(struct pl08x_dma_chan *);
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +0000214 u8 lli_buses;
215 u8 mem_buses;
Linus Walleije8689e62010-09-28 15:57:37 +0200216};
217
218#ifdef CONFIG_AMBA_PL08X
219bool pl08x_filter_id(struct dma_chan *chan, void *chan_id);
220#else
221static inline bool pl08x_filter_id(struct dma_chan *chan, void *chan_id)
222{
223 return false;
224}
225#endif
226
227#endif /* AMBA_PL08X_H */