blob: 4a1820bdee3244b04f4f3cf375e065ac55f24a65 [file] [log] [blame]
Marek Vasutf7c752c2011-11-08 23:18:15 +00001/*
2 * Freescale i.MX28 APBH DMA
3 *
4 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5 * on behalf of DENX Software Engineering GmbH
6 *
7 * Based on code from LTIB:
8 * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26#ifndef __DMA_H__
27#define __DMA_H__
28
29#include <linux/list.h>
30
31#ifndef CONFIG_ARCH_DMA_PIO_WORDS
32#define DMA_PIO_WORDS 15
33#else
34#define DMA_PIO_WORDS CONFIG_ARCH_DMA_PIO_WORDS
35#endif
36
37#define MXS_DMA_ALIGNMENT 32
38
39/*
40 * MXS DMA channels
41 */
42enum {
43 MXS_DMA_CHANNEL_AHB_APBH_SSP0 = 0,
44 MXS_DMA_CHANNEL_AHB_APBH_SSP1,
45 MXS_DMA_CHANNEL_AHB_APBH_SSP2,
46 MXS_DMA_CHANNEL_AHB_APBH_SSP3,
47 MXS_DMA_CHANNEL_AHB_APBH_GPMI0,
48 MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
49 MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
50 MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
51 MXS_DMA_CHANNEL_AHB_APBH_GPMI4,
52 MXS_DMA_CHANNEL_AHB_APBH_GPMI5,
53 MXS_DMA_CHANNEL_AHB_APBH_GPMI6,
54 MXS_DMA_CHANNEL_AHB_APBH_GPMI7,
55 MXS_DMA_CHANNEL_AHB_APBH_SSP,
56 MXS_MAX_DMA_CHANNELS,
57};
58
59/*
60 * MXS DMA hardware command.
61 *
62 * This structure describes the in-memory layout of an entire DMA command,
63 * including space for the maximum number of PIO accesses. See the appropriate
64 * reference manual for a detailed description of what these fields mean to the
65 * DMA hardware.
66 */
67#define MXS_DMA_DESC_COMMAND_MASK 0x3
68#define MXS_DMA_DESC_COMMAND_OFFSET 0
69#define MXS_DMA_DESC_COMMAND_NO_DMAXFER 0x0
70#define MXS_DMA_DESC_COMMAND_DMA_WRITE 0x1
71#define MXS_DMA_DESC_COMMAND_DMA_READ 0x2
72#define MXS_DMA_DESC_COMMAND_DMA_SENSE 0x3
73#define MXS_DMA_DESC_CHAIN (1 << 2)
74#define MXS_DMA_DESC_IRQ (1 << 3)
75#define MXS_DMA_DESC_NAND_LOCK (1 << 4)
76#define MXS_DMA_DESC_NAND_WAIT_4_READY (1 << 5)
77#define MXS_DMA_DESC_DEC_SEM (1 << 6)
78#define MXS_DMA_DESC_WAIT4END (1 << 7)
79#define MXS_DMA_DESC_HALT_ON_TERMINATE (1 << 8)
80#define MXS_DMA_DESC_TERMINATE_FLUSH (1 << 9)
81#define MXS_DMA_DESC_PIO_WORDS_MASK (0xf << 12)
82#define MXS_DMA_DESC_PIO_WORDS_OFFSET 12
83#define MXS_DMA_DESC_BYTES_MASK (0xffff << 16)
84#define MXS_DMA_DESC_BYTES_OFFSET 16
85
86struct mxs_dma_cmd {
87 unsigned long next;
88 unsigned long data;
89 union {
90 dma_addr_t address;
91 unsigned long alternate;
92 };
93 unsigned long pio_words[DMA_PIO_WORDS];
94};
95
96/*
97 * MXS DMA command descriptor.
98 *
99 * This structure incorporates an MXS DMA hardware command structure, along
100 * with metadata.
101 */
102#define MXS_DMA_DESC_FIRST (1 << 0)
103#define MXS_DMA_DESC_LAST (1 << 1)
104#define MXS_DMA_DESC_READY (1 << 31)
105
106struct mxs_dma_desc {
107 struct mxs_dma_cmd cmd;
108 unsigned int flags;
109 dma_addr_t address;
110 void *buffer;
111 struct list_head node;
112};
113
114/**
115 * MXS DMA channel
116 *
117 * This structure represents a single DMA channel. The MXS platform code
118 * maintains an array of these structures to represent every DMA channel in the
119 * system (see mxs_dma_channels).
120 */
121#define MXS_DMA_FLAGS_IDLE 0
122#define MXS_DMA_FLAGS_BUSY (1 << 0)
123#define MXS_DMA_FLAGS_FREE 0
124#define MXS_DMA_FLAGS_ALLOCATED (1 << 16)
125#define MXS_DMA_FLAGS_VALID (1 << 31)
126
127struct mxs_dma_chan {
128 const char *name;
129 unsigned long dev;
130 struct mxs_dma_device *dma;
131 unsigned int flags;
132 unsigned int active_num;
133 unsigned int pending_num;
134 struct list_head active;
135 struct list_head done;
136};
137
Marek Vasutf7c752c2011-11-08 23:18:15 +0000138struct mxs_dma_desc *mxs_dma_desc_alloc(void);
139void mxs_dma_desc_free(struct mxs_dma_desc *);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000140int mxs_dma_desc_append(int channel, struct mxs_dma_desc *pdesc);
141
Marek Vasutf7c752c2011-11-08 23:18:15 +0000142int mxs_dma_go(int chan);
Marek Vasut93541b42012-04-08 17:34:46 +0000143void mxs_dma_init(void);
144int mxs_dma_init_channel(int chan);
145int mxs_dma_release(int chan);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000146
147#endif /* __DMA_H__ */