blob: be35fadddf752a2deb8358b93e7420708f4b2408 [file] [log] [blame]
Linus Walleij8d318a52010-03-30 15:33:42 +02001/*
2 * driver/dma/ste_dma40_ll.h
3 *
4 * Copyright (C) ST-Ericsson 2007-2010
5 * License terms: GNU General Public License (GPL) version 2
6 * Author: Per Friden <per.friden@stericsson.com>
7 * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
8 */
9#ifndef STE_DMA40_LL_H
10#define STE_DMA40_LL_H
11
12#define D40_DREG_PCBASE 0x400
13#define D40_DREG_PCDELTA (8 * 4)
14#define D40_LLI_ALIGN 16 /* LLI alignment must be 16 bytes. */
15
Linus Walleijef1872e2010-06-20 21:24:52 +000016#define D40_LCPA_CHAN_SIZE 32
17#define D40_LCPA_CHAN_DST_DELTA 16
18
Linus Walleij8d318a52010-03-30 15:33:42 +020019#define D40_TYPE_TO_GROUP(type) (type / 16)
20#define D40_TYPE_TO_EVENT(type) (type % 16)
21
22/* Most bits of the CFG register are the same in log as in phy mode */
23#define D40_SREG_CFG_MST_POS 15
24#define D40_SREG_CFG_TIM_POS 14
25#define D40_SREG_CFG_EIM_POS 13
26#define D40_SREG_CFG_LOG_INCR_POS 12
27#define D40_SREG_CFG_PHY_PEN_POS 12
28#define D40_SREG_CFG_PSIZE_POS 10
29#define D40_SREG_CFG_ESIZE_POS 8
30#define D40_SREG_CFG_PRI_POS 7
31#define D40_SREG_CFG_LBE_POS 6
32#define D40_SREG_CFG_LOG_GIM_POS 5
33#define D40_SREG_CFG_LOG_MFU_POS 4
34#define D40_SREG_CFG_PHY_TM_POS 4
35#define D40_SREG_CFG_PHY_EVTL_POS 0
36
37
38/* Standard channel parameters - basic mode (element register) */
39#define D40_SREG_ELEM_PHY_ECNT_POS 16
40#define D40_SREG_ELEM_PHY_EIDX_POS 0
41
42#define D40_SREG_ELEM_PHY_ECNT_MASK (0xFFFF << D40_SREG_ELEM_PHY_ECNT_POS)
43
44/* Standard channel parameters - basic mode (Link register) */
45#define D40_SREG_LNK_PHY_TCP_POS 0
46#define D40_SREG_LNK_PHY_LMP_POS 1
47#define D40_SREG_LNK_PHY_PRE_POS 2
48/*
49 * Source destination link address. Contains the
50 * 29-bit byte word aligned address of the reload area.
51 */
52#define D40_SREG_LNK_PHYS_LNK_MASK 0xFFFFFFF8UL
53
54/* Standard basic channel logical mode */
55
56/* Element register */
57#define D40_SREG_ELEM_LOG_ECNT_POS 16
58#define D40_SREG_ELEM_LOG_LIDX_POS 8
59#define D40_SREG_ELEM_LOG_LOS_POS 1
60#define D40_SREG_ELEM_LOG_TCP_POS 0
61
62#define D40_SREG_ELEM_LOG_LIDX_MASK (0xFF << D40_SREG_ELEM_LOG_LIDX_POS)
63
64/* Link register */
65#define D40_DEACTIVATE_EVENTLINE 0x0
66#define D40_ACTIVATE_EVENTLINE 0x1
67#define D40_EVENTLINE_POS(i) (2 * i)
68#define D40_EVENTLINE_MASK(i) (0x3 << D40_EVENTLINE_POS(i))
69
70/* Standard basic channel logical params in memory */
71
72/* LCSP0 */
73#define D40_MEM_LCSP0_ECNT_POS 16
74#define D40_MEM_LCSP0_SPTR_POS 0
75
76#define D40_MEM_LCSP0_ECNT_MASK (0xFFFF << D40_MEM_LCSP0_ECNT_POS)
77#define D40_MEM_LCSP0_SPTR_MASK (0xFFFF << D40_MEM_LCSP0_SPTR_POS)
78
79/* LCSP1 */
80#define D40_MEM_LCSP1_SPTR_POS 16
81#define D40_MEM_LCSP1_SCFG_MST_POS 15
82#define D40_MEM_LCSP1_SCFG_TIM_POS 14
83#define D40_MEM_LCSP1_SCFG_EIM_POS 13
84#define D40_MEM_LCSP1_SCFG_INCR_POS 12
85#define D40_MEM_LCSP1_SCFG_PSIZE_POS 10
86#define D40_MEM_LCSP1_SCFG_ESIZE_POS 8
87#define D40_MEM_LCSP1_SLOS_POS 1
88#define D40_MEM_LCSP1_STCP_POS 0
89
90#define D40_MEM_LCSP1_SPTR_MASK (0xFFFF << D40_MEM_LCSP1_SPTR_POS)
91#define D40_MEM_LCSP1_SCFG_TIM_MASK (0x1 << D40_MEM_LCSP1_SCFG_TIM_POS)
92#define D40_MEM_LCSP1_SCFG_INCR_MASK (0x1 << D40_MEM_LCSP1_SCFG_INCR_POS)
93#define D40_MEM_LCSP1_SCFG_PSIZE_MASK (0x3 << D40_MEM_LCSP1_SCFG_PSIZE_POS)
94#define D40_MEM_LCSP1_SLOS_MASK (0x7F << D40_MEM_LCSP1_SLOS_POS)
95#define D40_MEM_LCSP1_STCP_MASK (0x1 << D40_MEM_LCSP1_STCP_POS)
96
97/* LCSP2 */
98#define D40_MEM_LCSP2_ECNT_POS 16
99
100#define D40_MEM_LCSP2_ECNT_MASK (0xFFFF << D40_MEM_LCSP2_ECNT_POS)
101
102/* LCSP3 */
103#define D40_MEM_LCSP3_DCFG_MST_POS 15
104#define D40_MEM_LCSP3_DCFG_TIM_POS 14
105#define D40_MEM_LCSP3_DCFG_EIM_POS 13
106#define D40_MEM_LCSP3_DCFG_INCR_POS 12
107#define D40_MEM_LCSP3_DCFG_PSIZE_POS 10
108#define D40_MEM_LCSP3_DCFG_ESIZE_POS 8
109#define D40_MEM_LCSP3_DLOS_POS 1
110#define D40_MEM_LCSP3_DTCP_POS 0
111
112#define D40_MEM_LCSP3_DLOS_MASK (0x7F << D40_MEM_LCSP3_DLOS_POS)
113#define D40_MEM_LCSP3_DTCP_MASK (0x1 << D40_MEM_LCSP3_DTCP_POS)
114
115
116/* Standard channel parameter register offsets */
117#define D40_CHAN_REG_SSCFG 0x00
118#define D40_CHAN_REG_SSELT 0x04
119#define D40_CHAN_REG_SSPTR 0x08
120#define D40_CHAN_REG_SSLNK 0x0C
121#define D40_CHAN_REG_SDCFG 0x10
122#define D40_CHAN_REG_SDELT 0x14
123#define D40_CHAN_REG_SDPTR 0x18
124#define D40_CHAN_REG_SDLNK 0x1C
125
126/* DMA Register Offsets */
127#define D40_DREG_GCC 0x000
128#define D40_DREG_PRTYP 0x004
129#define D40_DREG_PRSME 0x008
130#define D40_DREG_PRSMO 0x00C
131#define D40_DREG_PRMSE 0x010
132#define D40_DREG_PRMSO 0x014
133#define D40_DREG_PRMOE 0x018
134#define D40_DREG_PRMOO 0x01C
135#define D40_DREG_LCPA 0x020
136#define D40_DREG_LCLA 0x024
137#define D40_DREG_ACTIVE 0x050
138#define D40_DREG_ACTIVO 0x054
139#define D40_DREG_FSEB1 0x058
140#define D40_DREG_FSEB2 0x05C
141#define D40_DREG_PCMIS 0x060
142#define D40_DREG_PCICR 0x064
143#define D40_DREG_PCTIS 0x068
144#define D40_DREG_PCEIS 0x06C
145#define D40_DREG_LCMIS0 0x080
146#define D40_DREG_LCMIS1 0x084
147#define D40_DREG_LCMIS2 0x088
148#define D40_DREG_LCMIS3 0x08C
149#define D40_DREG_LCICR0 0x090
150#define D40_DREG_LCICR1 0x094
151#define D40_DREG_LCICR2 0x098
152#define D40_DREG_LCICR3 0x09C
153#define D40_DREG_LCTIS0 0x0A0
154#define D40_DREG_LCTIS1 0x0A4
155#define D40_DREG_LCTIS2 0x0A8
156#define D40_DREG_LCTIS3 0x0AC
157#define D40_DREG_LCEIS0 0x0B0
158#define D40_DREG_LCEIS1 0x0B4
159#define D40_DREG_LCEIS2 0x0B8
160#define D40_DREG_LCEIS3 0x0BC
161#define D40_DREG_STFU 0xFC8
162#define D40_DREG_ICFG 0xFCC
163#define D40_DREG_PERIPHID0 0xFE0
164#define D40_DREG_PERIPHID1 0xFE4
165#define D40_DREG_PERIPHID2 0xFE8
Jonas Aaberg3ae02672010-08-09 12:08:18 +0000166#define D40_DREG_PERIPHID2_REV_POS 4
167#define D40_DREG_PERIPHID2_REV_MASK (0xf << D40_DREG_PERIPHID2_REV_POS)
168#define D40_DREG_PERIPHID2_DESIGNER_MASK 0xf
Linus Walleij8d318a52010-03-30 15:33:42 +0200169#define D40_DREG_PERIPHID3 0xFEC
170#define D40_DREG_CELLID0 0xFF0
171#define D40_DREG_CELLID1 0xFF4
172#define D40_DREG_CELLID2 0xFF8
173#define D40_DREG_CELLID3 0xFFC
174
175/* LLI related structures */
176
177/**
178 * struct d40_phy_lli - The basic configration register for each physical
179 * channel.
180 *
181 * @reg_cfg: The configuration register.
182 * @reg_elt: The element register.
183 * @reg_ptr: The pointer register.
184 * @reg_lnk: The link register.
185 *
186 * These registers are set up for both physical and logical transfers
187 * Note that the bit in each register means differently in logical and
188 * physical(standard) mode.
189 *
190 * This struct must be 16 bytes aligned, and only contain physical registers
191 * since it will be directly accessed by the DMA.
192 */
193struct d40_phy_lli {
194 u32 reg_cfg;
195 u32 reg_elt;
196 u32 reg_ptr;
197 u32 reg_lnk;
198};
199
200/**
201 * struct d40_phy_lli_bidir - struct for a transfer.
202 *
203 * @src: Register settings for src channel.
204 * @dst: Register settings for dst channel.
Linus Walleij8d318a52010-03-30 15:33:42 +0200205 *
206 * All DMA transfers have a source and a destination.
207 */
208
209struct d40_phy_lli_bidir {
210 struct d40_phy_lli *src;
211 struct d40_phy_lli *dst;
Linus Walleij8d318a52010-03-30 15:33:42 +0200212};
213
214
215/**
216 * struct d40_log_lli - logical lli configuration
217 *
218 * @lcsp02: Either maps to register lcsp0 if src or lcsp2 if dst.
219 * @lcsp13: Either maps to register lcsp1 if src or lcsp3 if dst.
220 *
221 * This struct must be 8 bytes aligned since it will be accessed directy by
222 * the DMA. Never add any none hw mapped registers to this struct.
223 */
224
225struct d40_log_lli {
226 u32 lcsp02;
227 u32 lcsp13;
228};
229
230/**
231 * struct d40_log_lli_bidir - For both src and dst
232 *
233 * @src: pointer to src lli configuration.
234 * @dst: pointer to dst lli configuration.
235 *
236 * You always have a src and a dst when doing DMA transfers.
237 */
238
239struct d40_log_lli_bidir {
240 struct d40_log_lli *src;
241 struct d40_log_lli *dst;
242};
243
244/**
245 * struct d40_log_lli_full - LCPA layout
246 *
247 * @lcsp0: Logical Channel Standard Param 0 - Src.
248 * @lcsp1: Logical Channel Standard Param 1 - Src.
249 * @lcsp2: Logical Channel Standard Param 2 - Dst.
250 * @lcsp3: Logical Channel Standard Param 3 - Dst.
251 *
252 * This struct maps to LCPA physical memory layout. Must map to
253 * the hw.
254 */
255struct d40_log_lli_full {
256 u32 lcsp0;
257 u32 lcsp1;
258 u32 lcsp2;
259 u32 lcsp3;
260};
261
262/**
263 * struct d40_def_lcsp - Default LCSP1 and LCSP3 settings
264 *
265 * @lcsp3: The default configuration for dst.
266 * @lcsp1: The default configuration for src.
267 */
268struct d40_def_lcsp {
269 u32 lcsp3;
270 u32 lcsp1;
271};
272
273/**
274 * struct d40_lcla_elem - Info for one LCA element.
275 *
276 * @src_id: logical channel src id
277 * @dst_id: logical channel dst id
278 * @src: LCPA formated src parameters
279 * @dst: LCPA formated dst parameters
280 *
281 */
282struct d40_lcla_elem {
283 int src_id;
284 int dst_id;
285 struct d40_log_lli *src;
286 struct d40_log_lli *dst;
287};
288
289/* Physical channels */
290
291void d40_phy_cfg(struct stedma40_chan_cfg *cfg,
292 u32 *src_cfg, u32 *dst_cfg, bool is_log);
293
294void d40_log_cfg(struct stedma40_chan_cfg *cfg,
295 u32 *lcsp1, u32 *lcsp2);
296
297int d40_phy_sg_to_lli(struct scatterlist *sg,
298 int sg_len,
299 dma_addr_t target,
300 struct d40_phy_lli *lli,
301 dma_addr_t lli_phys,
302 u32 reg_cfg,
303 u32 data_width,
Jonas Aaberg0246e772010-08-09 12:08:10 +0000304 int psize);
Linus Walleij8d318a52010-03-30 15:33:42 +0200305
306int d40_phy_fill_lli(struct d40_phy_lli *lli,
307 dma_addr_t data,
308 u32 data_size,
309 int psize,
310 dma_addr_t next_lli,
311 u32 reg_cfg,
312 bool term_int,
313 u32 data_width,
314 bool is_device);
315
316void d40_phy_lli_write(void __iomem *virtbase,
317 u32 phy_chan_num,
318 struct d40_phy_lli *lli_dst,
319 struct d40_phy_lli *lli_src);
320
321/* Logical channels */
322
323void d40_log_fill_lli(struct d40_log_lli *lli,
324 dma_addr_t data, u32 data_size,
325 u32 lli_next_off, u32 reg_cfg,
326 u32 data_width,
327 bool term_int, bool addr_inc);
328
329int d40_log_sg_to_dev(struct d40_lcla_elem *lcla,
330 struct scatterlist *sg,
331 int sg_len,
332 struct d40_log_lli_bidir *lli,
333 struct d40_def_lcsp *lcsp,
334 u32 src_data_width,
335 u32 dst_data_width,
336 enum dma_data_direction direction,
Jonas Aaberg0246e772010-08-09 12:08:10 +0000337 dma_addr_t dev_addr, int max_len,
Linus Walleij8d318a52010-03-30 15:33:42 +0200338 int llis_per_log);
339
Linus Walleij508849a2010-06-20 21:26:07 +0000340int d40_log_lli_write(struct d40_log_lli_full *lcpa,
341 struct d40_log_lli *lcla_src,
342 struct d40_log_lli *lcla_dst,
343 struct d40_log_lli *lli_dst,
344 struct d40_log_lli *lli_src,
345 int llis_per_log);
Linus Walleij8d318a52010-03-30 15:33:42 +0200346
347int d40_log_sg_to_lli(int lcla_id,
348 struct scatterlist *sg,
349 int sg_len,
350 struct d40_log_lli *lli_sg,
351 u32 lcsp13, /* src or dst*/
352 u32 data_width,
Jonas Aaberg0246e772010-08-09 12:08:10 +0000353 int max_len, int llis_per_log);
Linus Walleij8d318a52010-03-30 15:33:42 +0200354
355#endif /* STE_DMA40_LLI_H */