blob: cd8f629da58f7bee0cb35ae44e9393812e3f5906 [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
Linus Walleije8689e62010-09-28 15:57:37 +020015 */
16
17#ifndef AMBA_PL08X_H
18#define AMBA_PL08X_H
19
20/* We need sizes of structs from this header */
21#include <linux/dmaengine.h>
22#include <linux/interrupt.h>
23
Russell King - ARM Linux7cb72ad2011-01-03 22:35:28 +000024struct pl08x_lli;
25struct pl08x_driver_data;
26
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +000027/* Bitmasks for selecting AHB ports for DMA transfers */
28enum {
29 PL08X_AHB1 = (1 << 0),
30 PL08X_AHB2 = (1 << 1)
31};
32
Linus Walleije8689e62010-09-28 15:57:37 +020033/**
34 * struct pl08x_channel_data - data structure to pass info between
35 * platform and PL08x driver regarding channel configuration
36 * @bus_id: name of this device channel, not just a device name since
37 * devices may have more than one channel e.g. "foo_tx"
38 * @min_signal: the minimum DMA signal number to be muxed in for this
39 * channel (for platforms supporting muxed signals). If you have
40 * static assignments, make sure this is set to the assigned signal
41 * number, PL08x have 16 possible signals in number 0 thru 15 so
42 * when these are not enough they often get muxed (in hardware)
43 * disabling simultaneous use of the same channel for two devices.
44 * @max_signal: the maximum DMA signal number to be muxed in for
45 * the channel. Set to the same as min_signal for
46 * devices with static assignments
47 * @muxval: a number usually used to poke into some mux regiser to
48 * mux in the signal to this channel
49 * @cctl_opt: default options for the channel control register
50 * @addr: source/target address in physical memory for this DMA channel,
51 * can be the address of a FIFO register for burst requests for example.
52 * This can be left undefined if the PrimeCell API is used for configuring
53 * this.
54 * @circular_buffer: whether the buffer passed in is circular and
55 * shall simply be looped round round (like a record baby round
56 * round round round)
Russell King - ARM Linux94ae8522011-01-16 20:18:05 +000057 * @single: the device connected to this channel will request single DMA
58 * transfers, not bursts. (Bursts are default.)
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +000059 * @periph_buses: the device connected to this channel is accessible via
60 * these buses (use PL08X_AHB1 | PL08X_AHB2).
Linus Walleije8689e62010-09-28 15:57:37 +020061 */
62struct pl08x_channel_data {
63 char *bus_id;
64 int min_signal;
65 int max_signal;
66 u32 muxval;
67 u32 cctl;
Linus Walleije8689e62010-09-28 15:57:37 +020068 dma_addr_t addr;
69 bool circular_buffer;
70 bool single;
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +000071 u8 periph_buses;
Linus Walleije8689e62010-09-28 15:57:37 +020072};
73
74/**
75 * Struct pl08x_bus_data - information of source or destination
76 * busses for a transfer
77 * @addr: current address
78 * @maxwidth: the maximum width of a transfer on this bus
79 * @buswidth: the width of this bus in bytes: 1, 2 or 4
Russell King - ARM Linux94ae8522011-01-16 20:18:05 +000080 * @fill_bytes: bytes required to fill to the next bus memory boundary
Linus Walleije8689e62010-09-28 15:57:37 +020081 */
82struct pl08x_bus_data {
83 dma_addr_t addr;
84 u8 maxwidth;
85 u8 buswidth;
Russell King - ARM Linuxcace6582011-01-03 22:37:31 +000086 size_t fill_bytes;
Linus Walleije8689e62010-09-28 15:57:37 +020087};
88
89/**
90 * struct pl08x_phy_chan - holder for the physical channels
91 * @id: physical index to this channel
92 * @lock: a lock to use when altering an instance of this struct
Russell King - ARM Linux94ae8522011-01-16 20:18:05 +000093 * @signal: the physical signal (aka channel) serving this physical channel
94 * right now
95 * @serving: the virtual channel currently being served by this physical
96 * channel
Linus Walleije8689e62010-09-28 15:57:37 +020097 */
98struct pl08x_phy_chan {
99 unsigned int id;
100 void __iomem *base;
101 spinlock_t lock;
102 int signal;
103 struct pl08x_dma_chan *serving;
Linus Walleije8689e62010-09-28 15:57:37 +0200104};
105
106/**
107 * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor
Viresh Kumar5a612332011-08-05 15:32:30 +0530108 * @tx: async tx descriptor
109 * @node: node for txd list for channels
110 * @src_addr: src address of txd
111 * @dst_addr: dst address of txd
112 * @len: transfer len in bytes
113 * @direction: direction of transfer
Linus Walleije8689e62010-09-28 15:57:37 +0200114 * @llis_bus: DMA memory address (physical) start for the LLIs
115 * @llis_va: virtual memory address start for the LLIs
Viresh Kumar5a612332011-08-05 15:32:30 +0530116 * @cctl: control reg values for current txd
117 * @ccfg: config reg values for current txd
Linus Walleije8689e62010-09-28 15:57:37 +0200118 */
119struct pl08x_txd {
120 struct dma_async_tx_descriptor tx;
121 struct list_head node;
122 enum dma_data_direction direction;
Russell King - ARM Linuxd7244e92011-01-03 22:43:35 +0000123 dma_addr_t src_addr;
124 dma_addr_t dst_addr;
Russell King - ARM Linuxcace6582011-01-03 22:37:31 +0000125 size_t len;
Linus Walleije8689e62010-09-28 15:57:37 +0200126 dma_addr_t llis_bus;
Dan Williams96a608a2011-01-14 17:51:11 -0800127 struct pl08x_lli *llis_va;
Russell King - ARM Linux70b5ed62011-01-03 22:40:13 +0000128 /* Default cctl value for LLIs */
129 u32 cctl;
Russell King - ARM Linux4983a042011-01-03 22:39:33 +0000130 /*
131 * Settings to be put into the physical channel when we
132 * trigger this txd. Other registers are in llis_va[0].
133 */
134 u32 ccfg;
Linus Walleije8689e62010-09-28 15:57:37 +0200135};
136
137/**
Russell King - ARM Linux94ae8522011-01-16 20:18:05 +0000138 * struct pl08x_dma_chan_state - holds the PL08x specific virtual channel
139 * states
Linus Walleije8689e62010-09-28 15:57:37 +0200140 * @PL08X_CHAN_IDLE: the channel is idle
141 * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport
142 * channel and is running a transfer on it
143 * @PL08X_CHAN_PAUSED: the channel has allocated a physical transport
144 * channel, but the transfer is currently paused
145 * @PL08X_CHAN_WAITING: the channel is waiting for a physical transport
146 * channel to become available (only pertains to memcpy channels)
147 */
148enum pl08x_dma_chan_state {
149 PL08X_CHAN_IDLE,
150 PL08X_CHAN_RUNNING,
151 PL08X_CHAN_PAUSED,
152 PL08X_CHAN_WAITING,
153};
154
155/**
156 * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel
157 * @chan: wrappped abstract channel
158 * @phychan: the physical channel utilized by this channel, if there is one
Russell King - ARM Linux8087aac2011-01-03 22:45:17 +0000159 * @phychan_hold: if non-zero, hold on to the physical channel even if we
Russell King - ARM Linux94ae8522011-01-16 20:18:05 +0000160 * have no pending entries
Linus Walleije8689e62010-09-28 15:57:37 +0200161 * @tasklet: tasklet scheduled by the IRQ to handle actual work etc
162 * @name: name of channel
163 * @cd: channel platform data
164 * @runtime_addr: address for RX/TX according to the runtime config
165 * @runtime_direction: current direction of this channel according to
166 * runtime config
167 * @lc: last completed transaction on this channel
Russell King - ARM Linux15c17232011-01-03 22:44:36 +0000168 * @pend_list: queued transactions pending on this channel
Linus Walleije8689e62010-09-28 15:57:37 +0200169 * @at: active transaction on this channel
Linus Walleije8689e62010-09-28 15:57:37 +0200170 * @lock: a lock for this channel data
171 * @host: a pointer to the host (internal use)
172 * @state: whether the channel is idle, paused, running etc
173 * @slave: whether this channel is a device (slave) or for memcpy
Russell King - ARM Linux94ae8522011-01-16 20:18:05 +0000174 * @waiting: a TX descriptor on this channel which is waiting for a physical
175 * channel to become available
Linus Walleije8689e62010-09-28 15:57:37 +0200176 */
177struct pl08x_dma_chan {
178 struct dma_chan chan;
179 struct pl08x_phy_chan *phychan;
Russell King - ARM Linux8087aac2011-01-03 22:45:17 +0000180 int phychan_hold;
Linus Walleije8689e62010-09-28 15:57:37 +0200181 struct tasklet_struct tasklet;
182 char *name;
Russell King - ARM Linuxfa020e72011-07-21 17:13:07 +0100183 const struct pl08x_channel_data *cd;
Russell King - ARM Linuxb207b4d2011-07-21 17:12:27 +0100184 dma_addr_t src_addr;
185 dma_addr_t dst_addr;
Russell King - ARM Linuxf14c4262011-07-21 17:12:47 +0100186 u32 src_cctl;
187 u32 dst_cctl;
Linus Walleije8689e62010-09-28 15:57:37 +0200188 enum dma_data_direction runtime_direction;
Linus Walleije8689e62010-09-28 15:57:37 +0200189 dma_cookie_t lc;
Russell King - ARM Linux15c17232011-01-03 22:44:36 +0000190 struct list_head pend_list;
Linus Walleije8689e62010-09-28 15:57:37 +0200191 struct pl08x_txd *at;
Linus Walleije8689e62010-09-28 15:57:37 +0200192 spinlock_t lock;
Russell King - ARM Linux7cb72ad2011-01-03 22:35:28 +0000193 struct pl08x_driver_data *host;
Linus Walleije8689e62010-09-28 15:57:37 +0200194 enum pl08x_dma_chan_state state;
195 bool slave;
196 struct pl08x_txd *waiting;
197};
198
199/**
Russell King - ARM Linux94ae8522011-01-16 20:18:05 +0000200 * struct pl08x_platform_data - the platform configuration for the PL08x
201 * PrimeCells.
Linus Walleije8689e62010-09-28 15:57:37 +0200202 * @slave_channels: the channels defined for the different devices on the
203 * platform, all inclusive, including multiplexed channels. The available
Russell King - ARM Linux94ae8522011-01-16 20:18:05 +0000204 * physical channels will be multiplexed around these signals as they are
205 * requested, just enumerate all possible channels.
206 * @get_signal: request a physical signal to be used for a DMA transfer
207 * immediately: if there is some multiplexing or similar blocking the use
208 * of the channel the transfer can be denied by returning less than zero,
209 * else it returns the allocated signal number
Linus Walleije8689e62010-09-28 15:57:37 +0200210 * @put_signal: indicate to the platform that this physical signal is not
211 * running any DMA transfer and multiplexing can be recycled
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +0000212 * @lli_buses: buses which LLIs can be fetched from: PL08X_AHB1 | PL08X_AHB2
213 * @mem_buses: buses which memory can be accessed from: PL08X_AHB1 | PL08X_AHB2
Linus Walleije8689e62010-09-28 15:57:37 +0200214 */
215struct pl08x_platform_data {
Russell King - ARM Linuxfa020e72011-07-21 17:13:07 +0100216 const struct pl08x_channel_data *slave_channels;
Linus Walleije8689e62010-09-28 15:57:37 +0200217 unsigned int num_slave_channels;
218 struct pl08x_channel_data memcpy_channel;
219 int (*get_signal)(struct pl08x_dma_chan *);
220 void (*put_signal)(struct pl08x_dma_chan *);
Russell King - ARM Linux30749cb2011-01-03 22:41:13 +0000221 u8 lli_buses;
222 u8 mem_buses;
Linus Walleije8689e62010-09-28 15:57:37 +0200223};
224
225#ifdef CONFIG_AMBA_PL08X
226bool pl08x_filter_id(struct dma_chan *chan, void *chan_id);
227#else
228static inline bool pl08x_filter_id(struct dma_chan *chan, void *chan_id)
229{
230 return false;
231}
232#endif
233
234#endif /* AMBA_PL08X_H */