1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * BRIEF MODULE DESCRIPTION
4*4882a593Smuzhiyun * The Descriptor Based DMA channel manager that first appeared
5*4882a593Smuzhiyun * on the Au1550. I started with dma.c, but I think all that is
6*4882a593Smuzhiyun * left is this initial comment :-)
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Copyright 2004 Embedded Edge, LLC
9*4882a593Smuzhiyun * dan@embeddededge.com
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify it
12*4882a593Smuzhiyun * under the terms of the GNU General Public License as published by the
13*4882a593Smuzhiyun * Free Software Foundation; either version 2 of the License, or (at your
14*4882a593Smuzhiyun * option) any later version.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
17*4882a593Smuzhiyun * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18*4882a593Smuzhiyun * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19*4882a593Smuzhiyun * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*4882a593Smuzhiyun * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21*4882a593Smuzhiyun * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22*4882a593Smuzhiyun * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23*4882a593Smuzhiyun * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25*4882a593Smuzhiyun * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*4882a593Smuzhiyun *
27*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License along
28*4882a593Smuzhiyun * with this program; if not, write to the Free Software Foundation, Inc.,
29*4882a593Smuzhiyun * 675 Mass Ave, Cambridge, MA 02139, USA.
30*4882a593Smuzhiyun *
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #include <linux/init.h>
34*4882a593Smuzhiyun #include <linux/kernel.h>
35*4882a593Smuzhiyun #include <linux/slab.h>
36*4882a593Smuzhiyun #include <linux/spinlock.h>
37*4882a593Smuzhiyun #include <linux/interrupt.h>
38*4882a593Smuzhiyun #include <linux/export.h>
39*4882a593Smuzhiyun #include <linux/syscore_ops.h>
40*4882a593Smuzhiyun #include <asm/mach-au1x00/au1000.h>
41*4882a593Smuzhiyun #include <asm/mach-au1x00/au1xxx_dbdma.h>
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun /*
44*4882a593Smuzhiyun * The Descriptor Based DMA supports up to 16 channels.
45*4882a593Smuzhiyun *
46*4882a593Smuzhiyun * There are 32 devices defined. We keep an internal structure
47*4882a593Smuzhiyun * of devices using these channels, along with additional
48*4882a593Smuzhiyun * information.
49*4882a593Smuzhiyun *
50*4882a593Smuzhiyun * We allocate the descriptors and allow access to them through various
51*4882a593Smuzhiyun * functions. The drivers allocate the data buffers and assign them
52*4882a593Smuzhiyun * to the descriptors.
53*4882a593Smuzhiyun */
54*4882a593Smuzhiyun static DEFINE_SPINLOCK(au1xxx_dbdma_spin_lock);
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /* I couldn't find a macro that did this... */
57*4882a593Smuzhiyun #define ALIGN_ADDR(x, a) ((((u32)(x)) + (a-1)) & ~(a-1))
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun static dbdma_global_t *dbdma_gptr =
60*4882a593Smuzhiyun (dbdma_global_t *)KSEG1ADDR(AU1550_DBDMA_CONF_PHYS_ADDR);
61*4882a593Smuzhiyun static int dbdma_initialized;
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun static dbdev_tab_t *dbdev_tab;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun static dbdev_tab_t au1550_dbdev_tab[] __initdata = {
66*4882a593Smuzhiyun /* UARTS */
67*4882a593Smuzhiyun { AU1550_DSCR_CMD0_UART0_TX, DEV_FLAGS_OUT, 0, 8, 0x11100004, 0, 0 },
68*4882a593Smuzhiyun { AU1550_DSCR_CMD0_UART0_RX, DEV_FLAGS_IN, 0, 8, 0x11100000, 0, 0 },
69*4882a593Smuzhiyun { AU1550_DSCR_CMD0_UART3_TX, DEV_FLAGS_OUT, 0, 8, 0x11400004, 0, 0 },
70*4882a593Smuzhiyun { AU1550_DSCR_CMD0_UART3_RX, DEV_FLAGS_IN, 0, 8, 0x11400000, 0, 0 },
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun /* EXT DMA */
73*4882a593Smuzhiyun { AU1550_DSCR_CMD0_DMA_REQ0, 0, 0, 0, 0x00000000, 0, 0 },
74*4882a593Smuzhiyun { AU1550_DSCR_CMD0_DMA_REQ1, 0, 0, 0, 0x00000000, 0, 0 },
75*4882a593Smuzhiyun { AU1550_DSCR_CMD0_DMA_REQ2, 0, 0, 0, 0x00000000, 0, 0 },
76*4882a593Smuzhiyun { AU1550_DSCR_CMD0_DMA_REQ3, 0, 0, 0, 0x00000000, 0, 0 },
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun /* USB DEV */
79*4882a593Smuzhiyun { AU1550_DSCR_CMD0_USBDEV_RX0, DEV_FLAGS_IN, 4, 8, 0x10200000, 0, 0 },
80*4882a593Smuzhiyun { AU1550_DSCR_CMD0_USBDEV_TX0, DEV_FLAGS_OUT, 4, 8, 0x10200004, 0, 0 },
81*4882a593Smuzhiyun { AU1550_DSCR_CMD0_USBDEV_TX1, DEV_FLAGS_OUT, 4, 8, 0x10200008, 0, 0 },
82*4882a593Smuzhiyun { AU1550_DSCR_CMD0_USBDEV_TX2, DEV_FLAGS_OUT, 4, 8, 0x1020000c, 0, 0 },
83*4882a593Smuzhiyun { AU1550_DSCR_CMD0_USBDEV_RX3, DEV_FLAGS_IN, 4, 8, 0x10200010, 0, 0 },
84*4882a593Smuzhiyun { AU1550_DSCR_CMD0_USBDEV_RX4, DEV_FLAGS_IN, 4, 8, 0x10200014, 0, 0 },
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /* PSCs */
87*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PSC0_TX, DEV_FLAGS_OUT, 0, 0, 0x11a0001c, 0, 0 },
88*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PSC0_RX, DEV_FLAGS_IN, 0, 0, 0x11a0001c, 0, 0 },
89*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PSC1_TX, DEV_FLAGS_OUT, 0, 0, 0x11b0001c, 0, 0 },
90*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PSC1_RX, DEV_FLAGS_IN, 0, 0, 0x11b0001c, 0, 0 },
91*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PSC2_TX, DEV_FLAGS_OUT, 0, 0, 0x10a0001c, 0, 0 },
92*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PSC2_RX, DEV_FLAGS_IN, 0, 0, 0x10a0001c, 0, 0 },
93*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PSC3_TX, DEV_FLAGS_OUT, 0, 0, 0x10b0001c, 0, 0 },
94*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PSC3_RX, DEV_FLAGS_IN, 0, 0, 0x10b0001c, 0, 0 },
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun { AU1550_DSCR_CMD0_PCI_WRITE, 0, 0, 0, 0x00000000, 0, 0 }, /* PCI */
97*4882a593Smuzhiyun { AU1550_DSCR_CMD0_NAND_FLASH, 0, 0, 0, 0x00000000, 0, 0 }, /* NAND */
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /* MAC 0 */
100*4882a593Smuzhiyun { AU1550_DSCR_CMD0_MAC0_RX, DEV_FLAGS_IN, 0, 0, 0x00000000, 0, 0 },
101*4882a593Smuzhiyun { AU1550_DSCR_CMD0_MAC0_TX, DEV_FLAGS_OUT, 0, 0, 0x00000000, 0, 0 },
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /* MAC 1 */
104*4882a593Smuzhiyun { AU1550_DSCR_CMD0_MAC1_RX, DEV_FLAGS_IN, 0, 0, 0x00000000, 0, 0 },
105*4882a593Smuzhiyun { AU1550_DSCR_CMD0_MAC1_TX, DEV_FLAGS_OUT, 0, 0, 0x00000000, 0, 0 },
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun { DSCR_CMD0_THROTTLE, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
108*4882a593Smuzhiyun { DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
109*4882a593Smuzhiyun };
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun static dbdev_tab_t au1200_dbdev_tab[] __initdata = {
112*4882a593Smuzhiyun { AU1200_DSCR_CMD0_UART0_TX, DEV_FLAGS_OUT, 0, 8, 0x11100004, 0, 0 },
113*4882a593Smuzhiyun { AU1200_DSCR_CMD0_UART0_RX, DEV_FLAGS_IN, 0, 8, 0x11100000, 0, 0 },
114*4882a593Smuzhiyun { AU1200_DSCR_CMD0_UART1_TX, DEV_FLAGS_OUT, 0, 8, 0x11200004, 0, 0 },
115*4882a593Smuzhiyun { AU1200_DSCR_CMD0_UART1_RX, DEV_FLAGS_IN, 0, 8, 0x11200000, 0, 0 },
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun { AU1200_DSCR_CMD0_DMA_REQ0, 0, 0, 0, 0x00000000, 0, 0 },
118*4882a593Smuzhiyun { AU1200_DSCR_CMD0_DMA_REQ1, 0, 0, 0, 0x00000000, 0, 0 },
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun { AU1200_DSCR_CMD0_MAE_BE, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
121*4882a593Smuzhiyun { AU1200_DSCR_CMD0_MAE_FE, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
122*4882a593Smuzhiyun { AU1200_DSCR_CMD0_MAE_BOTH, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
123*4882a593Smuzhiyun { AU1200_DSCR_CMD0_LCD, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun { AU1200_DSCR_CMD0_SDMS_TX0, DEV_FLAGS_OUT, 4, 8, 0x10600000, 0, 0 },
126*4882a593Smuzhiyun { AU1200_DSCR_CMD0_SDMS_RX0, DEV_FLAGS_IN, 4, 8, 0x10600004, 0, 0 },
127*4882a593Smuzhiyun { AU1200_DSCR_CMD0_SDMS_TX1, DEV_FLAGS_OUT, 4, 8, 0x10680000, 0, 0 },
128*4882a593Smuzhiyun { AU1200_DSCR_CMD0_SDMS_RX1, DEV_FLAGS_IN, 4, 8, 0x10680004, 0, 0 },
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun { AU1200_DSCR_CMD0_AES_RX, DEV_FLAGS_IN , 4, 32, 0x10300008, 0, 0 },
131*4882a593Smuzhiyun { AU1200_DSCR_CMD0_AES_TX, DEV_FLAGS_OUT, 4, 32, 0x10300004, 0, 0 },
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun { AU1200_DSCR_CMD0_PSC0_TX, DEV_FLAGS_OUT, 0, 16, 0x11a0001c, 0, 0 },
134*4882a593Smuzhiyun { AU1200_DSCR_CMD0_PSC0_RX, DEV_FLAGS_IN, 0, 16, 0x11a0001c, 0, 0 },
135*4882a593Smuzhiyun { AU1200_DSCR_CMD0_PSC0_SYNC, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
136*4882a593Smuzhiyun { AU1200_DSCR_CMD0_PSC1_TX, DEV_FLAGS_OUT, 0, 16, 0x11b0001c, 0, 0 },
137*4882a593Smuzhiyun { AU1200_DSCR_CMD0_PSC1_RX, DEV_FLAGS_IN, 0, 16, 0x11b0001c, 0, 0 },
138*4882a593Smuzhiyun { AU1200_DSCR_CMD0_PSC1_SYNC, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun { AU1200_DSCR_CMD0_CIM_RXA, DEV_FLAGS_IN, 0, 32, 0x14004020, 0, 0 },
141*4882a593Smuzhiyun { AU1200_DSCR_CMD0_CIM_RXB, DEV_FLAGS_IN, 0, 32, 0x14004040, 0, 0 },
142*4882a593Smuzhiyun { AU1200_DSCR_CMD0_CIM_RXC, DEV_FLAGS_IN, 0, 32, 0x14004060, 0, 0 },
143*4882a593Smuzhiyun { AU1200_DSCR_CMD0_CIM_SYNC, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun { AU1200_DSCR_CMD0_NAND_FLASH, DEV_FLAGS_IN, 0, 0, 0x00000000, 0, 0 },
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun { DSCR_CMD0_THROTTLE, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
148*4882a593Smuzhiyun { DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
149*4882a593Smuzhiyun };
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun static dbdev_tab_t au1300_dbdev_tab[] __initdata = {
152*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UART0_TX, DEV_FLAGS_OUT, 0, 8, 0x10100004, 0, 0 },
153*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UART0_RX, DEV_FLAGS_IN, 0, 8, 0x10100000, 0, 0 },
154*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UART1_TX, DEV_FLAGS_OUT, 0, 8, 0x10101004, 0, 0 },
155*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UART1_RX, DEV_FLAGS_IN, 0, 8, 0x10101000, 0, 0 },
156*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UART2_TX, DEV_FLAGS_OUT, 0, 8, 0x10102004, 0, 0 },
157*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UART2_RX, DEV_FLAGS_IN, 0, 8, 0x10102000, 0, 0 },
158*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UART3_TX, DEV_FLAGS_OUT, 0, 8, 0x10103004, 0, 0 },
159*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UART3_RX, DEV_FLAGS_IN, 0, 8, 0x10103000, 0, 0 },
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun { AU1300_DSCR_CMD0_SDMS_TX0, DEV_FLAGS_OUT, 4, 8, 0x10600000, 0, 0 },
162*4882a593Smuzhiyun { AU1300_DSCR_CMD0_SDMS_RX0, DEV_FLAGS_IN, 4, 8, 0x10600004, 0, 0 },
163*4882a593Smuzhiyun { AU1300_DSCR_CMD0_SDMS_TX1, DEV_FLAGS_OUT, 8, 8, 0x10601000, 0, 0 },
164*4882a593Smuzhiyun { AU1300_DSCR_CMD0_SDMS_RX1, DEV_FLAGS_IN, 8, 8, 0x10601004, 0, 0 },
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun { AU1300_DSCR_CMD0_AES_RX, DEV_FLAGS_IN , 4, 32, 0x10300008, 0, 0 },
167*4882a593Smuzhiyun { AU1300_DSCR_CMD0_AES_TX, DEV_FLAGS_OUT, 4, 32, 0x10300004, 0, 0 },
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun { AU1300_DSCR_CMD0_PSC0_TX, DEV_FLAGS_OUT, 0, 16, 0x10a0001c, 0, 0 },
170*4882a593Smuzhiyun { AU1300_DSCR_CMD0_PSC0_RX, DEV_FLAGS_IN, 0, 16, 0x10a0001c, 0, 0 },
171*4882a593Smuzhiyun { AU1300_DSCR_CMD0_PSC1_TX, DEV_FLAGS_OUT, 0, 16, 0x10a0101c, 0, 0 },
172*4882a593Smuzhiyun { AU1300_DSCR_CMD0_PSC1_RX, DEV_FLAGS_IN, 0, 16, 0x10a0101c, 0, 0 },
173*4882a593Smuzhiyun { AU1300_DSCR_CMD0_PSC2_TX, DEV_FLAGS_OUT, 0, 16, 0x10a0201c, 0, 0 },
174*4882a593Smuzhiyun { AU1300_DSCR_CMD0_PSC2_RX, DEV_FLAGS_IN, 0, 16, 0x10a0201c, 0, 0 },
175*4882a593Smuzhiyun { AU1300_DSCR_CMD0_PSC3_TX, DEV_FLAGS_OUT, 0, 16, 0x10a0301c, 0, 0 },
176*4882a593Smuzhiyun { AU1300_DSCR_CMD0_PSC3_RX, DEV_FLAGS_IN, 0, 16, 0x10a0301c, 0, 0 },
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun { AU1300_DSCR_CMD0_LCD, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
179*4882a593Smuzhiyun { AU1300_DSCR_CMD0_NAND_FLASH, DEV_FLAGS_IN, 0, 0, 0x00000000, 0, 0 },
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun { AU1300_DSCR_CMD0_SDMS_TX2, DEV_FLAGS_OUT, 4, 8, 0x10602000, 0, 0 },
182*4882a593Smuzhiyun { AU1300_DSCR_CMD0_SDMS_RX2, DEV_FLAGS_IN, 4, 8, 0x10602004, 0, 0 },
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun { AU1300_DSCR_CMD0_CIM_SYNC, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun { AU1300_DSCR_CMD0_UDMA, DEV_FLAGS_ANYUSE, 0, 32, 0x14001810, 0, 0 },
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun { AU1300_DSCR_CMD0_DMA_REQ0, 0, 0, 0, 0x00000000, 0, 0 },
189*4882a593Smuzhiyun { AU1300_DSCR_CMD0_DMA_REQ1, 0, 0, 0, 0x00000000, 0, 0 },
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun { DSCR_CMD0_THROTTLE, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
192*4882a593Smuzhiyun { DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
193*4882a593Smuzhiyun };
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun /* 32 predefined plus 32 custom */
196*4882a593Smuzhiyun #define DBDEV_TAB_SIZE 64
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun static chan_tab_t *chan_tab_ptr[NUM_DBDMA_CHANS];
199*4882a593Smuzhiyun
find_dbdev_id(u32 id)200*4882a593Smuzhiyun static dbdev_tab_t *find_dbdev_id(u32 id)
201*4882a593Smuzhiyun {
202*4882a593Smuzhiyun int i;
203*4882a593Smuzhiyun dbdev_tab_t *p;
204*4882a593Smuzhiyun for (i = 0; i < DBDEV_TAB_SIZE; ++i) {
205*4882a593Smuzhiyun p = &dbdev_tab[i];
206*4882a593Smuzhiyun if (p->dev_id == id)
207*4882a593Smuzhiyun return p;
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun return NULL;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun
au1xxx_ddma_get_nextptr_virt(au1x_ddma_desc_t * dp)212*4882a593Smuzhiyun void *au1xxx_ddma_get_nextptr_virt(au1x_ddma_desc_t *dp)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun return phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
215*4882a593Smuzhiyun }
216*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_ddma_get_nextptr_virt);
217*4882a593Smuzhiyun
au1xxx_ddma_add_device(dbdev_tab_t * dev)218*4882a593Smuzhiyun u32 au1xxx_ddma_add_device(dbdev_tab_t *dev)
219*4882a593Smuzhiyun {
220*4882a593Smuzhiyun u32 ret = 0;
221*4882a593Smuzhiyun dbdev_tab_t *p;
222*4882a593Smuzhiyun static u16 new_id = 0x1000;
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun p = find_dbdev_id(~0);
225*4882a593Smuzhiyun if (NULL != p) {
226*4882a593Smuzhiyun memcpy(p, dev, sizeof(dbdev_tab_t));
227*4882a593Smuzhiyun p->dev_id = DSCR_DEV2CUSTOM_ID(new_id, dev->dev_id);
228*4882a593Smuzhiyun ret = p->dev_id;
229*4882a593Smuzhiyun new_id++;
230*4882a593Smuzhiyun #if 0
231*4882a593Smuzhiyun printk(KERN_DEBUG "add_device: id:%x flags:%x padd:%x\n",
232*4882a593Smuzhiyun p->dev_id, p->dev_flags, p->dev_physaddr);
233*4882a593Smuzhiyun #endif
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun return ret;
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_ddma_add_device);
239*4882a593Smuzhiyun
au1xxx_ddma_del_device(u32 devid)240*4882a593Smuzhiyun void au1xxx_ddma_del_device(u32 devid)
241*4882a593Smuzhiyun {
242*4882a593Smuzhiyun dbdev_tab_t *p = find_dbdev_id(devid);
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun if (p != NULL) {
245*4882a593Smuzhiyun memset(p, 0, sizeof(dbdev_tab_t));
246*4882a593Smuzhiyun p->dev_id = ~0;
247*4882a593Smuzhiyun }
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_ddma_del_device);
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun /* Allocate a channel and return a non-zero descriptor if successful. */
au1xxx_dbdma_chan_alloc(u32 srcid,u32 destid,void (* callback)(int,void *),void * callparam)252*4882a593Smuzhiyun u32 au1xxx_dbdma_chan_alloc(u32 srcid, u32 destid,
253*4882a593Smuzhiyun void (*callback)(int, void *), void *callparam)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun unsigned long flags;
256*4882a593Smuzhiyun u32 used, chan;
257*4882a593Smuzhiyun u32 dcp;
258*4882a593Smuzhiyun int i;
259*4882a593Smuzhiyun dbdev_tab_t *stp, *dtp;
260*4882a593Smuzhiyun chan_tab_t *ctp;
261*4882a593Smuzhiyun au1x_dma_chan_t *cp;
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun /*
264*4882a593Smuzhiyun * We do the initialization on the first channel allocation.
265*4882a593Smuzhiyun * We have to wait because of the interrupt handler initialization
266*4882a593Smuzhiyun * which can't be done successfully during board set up.
267*4882a593Smuzhiyun */
268*4882a593Smuzhiyun if (!dbdma_initialized)
269*4882a593Smuzhiyun return 0;
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun stp = find_dbdev_id(srcid);
272*4882a593Smuzhiyun if (stp == NULL)
273*4882a593Smuzhiyun return 0;
274*4882a593Smuzhiyun dtp = find_dbdev_id(destid);
275*4882a593Smuzhiyun if (dtp == NULL)
276*4882a593Smuzhiyun return 0;
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun used = 0;
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun /* Check to see if we can get both channels. */
281*4882a593Smuzhiyun spin_lock_irqsave(&au1xxx_dbdma_spin_lock, flags);
282*4882a593Smuzhiyun if (!(stp->dev_flags & DEV_FLAGS_INUSE) ||
283*4882a593Smuzhiyun (stp->dev_flags & DEV_FLAGS_ANYUSE)) {
284*4882a593Smuzhiyun /* Got source */
285*4882a593Smuzhiyun stp->dev_flags |= DEV_FLAGS_INUSE;
286*4882a593Smuzhiyun if (!(dtp->dev_flags & DEV_FLAGS_INUSE) ||
287*4882a593Smuzhiyun (dtp->dev_flags & DEV_FLAGS_ANYUSE)) {
288*4882a593Smuzhiyun /* Got destination */
289*4882a593Smuzhiyun dtp->dev_flags |= DEV_FLAGS_INUSE;
290*4882a593Smuzhiyun } else {
291*4882a593Smuzhiyun /* Can't get dest. Release src. */
292*4882a593Smuzhiyun stp->dev_flags &= ~DEV_FLAGS_INUSE;
293*4882a593Smuzhiyun used++;
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun } else
296*4882a593Smuzhiyun used++;
297*4882a593Smuzhiyun spin_unlock_irqrestore(&au1xxx_dbdma_spin_lock, flags);
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun if (used)
300*4882a593Smuzhiyun return 0;
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun /* Let's see if we can allocate a channel for it. */
303*4882a593Smuzhiyun ctp = NULL;
304*4882a593Smuzhiyun chan = 0;
305*4882a593Smuzhiyun spin_lock_irqsave(&au1xxx_dbdma_spin_lock, flags);
306*4882a593Smuzhiyun for (i = 0; i < NUM_DBDMA_CHANS; i++)
307*4882a593Smuzhiyun if (chan_tab_ptr[i] == NULL) {
308*4882a593Smuzhiyun /*
309*4882a593Smuzhiyun * If kmalloc fails, it is caught below same
310*4882a593Smuzhiyun * as a channel not available.
311*4882a593Smuzhiyun */
312*4882a593Smuzhiyun ctp = kmalloc(sizeof(chan_tab_t), GFP_ATOMIC);
313*4882a593Smuzhiyun chan_tab_ptr[i] = ctp;
314*4882a593Smuzhiyun break;
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun spin_unlock_irqrestore(&au1xxx_dbdma_spin_lock, flags);
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun if (ctp != NULL) {
319*4882a593Smuzhiyun memset(ctp, 0, sizeof(chan_tab_t));
320*4882a593Smuzhiyun ctp->chan_index = chan = i;
321*4882a593Smuzhiyun dcp = KSEG1ADDR(AU1550_DBDMA_PHYS_ADDR);
322*4882a593Smuzhiyun dcp += (0x0100 * chan);
323*4882a593Smuzhiyun ctp->chan_ptr = (au1x_dma_chan_t *)dcp;
324*4882a593Smuzhiyun cp = (au1x_dma_chan_t *)dcp;
325*4882a593Smuzhiyun ctp->chan_src = stp;
326*4882a593Smuzhiyun ctp->chan_dest = dtp;
327*4882a593Smuzhiyun ctp->chan_callback = callback;
328*4882a593Smuzhiyun ctp->chan_callparam = callparam;
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun /* Initialize channel configuration. */
331*4882a593Smuzhiyun i = 0;
332*4882a593Smuzhiyun if (stp->dev_intlevel)
333*4882a593Smuzhiyun i |= DDMA_CFG_SED;
334*4882a593Smuzhiyun if (stp->dev_intpolarity)
335*4882a593Smuzhiyun i |= DDMA_CFG_SP;
336*4882a593Smuzhiyun if (dtp->dev_intlevel)
337*4882a593Smuzhiyun i |= DDMA_CFG_DED;
338*4882a593Smuzhiyun if (dtp->dev_intpolarity)
339*4882a593Smuzhiyun i |= DDMA_CFG_DP;
340*4882a593Smuzhiyun if ((stp->dev_flags & DEV_FLAGS_SYNC) ||
341*4882a593Smuzhiyun (dtp->dev_flags & DEV_FLAGS_SYNC))
342*4882a593Smuzhiyun i |= DDMA_CFG_SYNC;
343*4882a593Smuzhiyun cp->ddma_cfg = i;
344*4882a593Smuzhiyun wmb(); /* drain writebuffer */
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun /*
347*4882a593Smuzhiyun * Return a non-zero value that can be used to find the channel
348*4882a593Smuzhiyun * information in subsequent operations.
349*4882a593Smuzhiyun */
350*4882a593Smuzhiyun return (u32)(&chan_tab_ptr[chan]);
351*4882a593Smuzhiyun }
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun /* Release devices */
354*4882a593Smuzhiyun stp->dev_flags &= ~DEV_FLAGS_INUSE;
355*4882a593Smuzhiyun dtp->dev_flags &= ~DEV_FLAGS_INUSE;
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun return 0;
358*4882a593Smuzhiyun }
359*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_chan_alloc);
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun /*
362*4882a593Smuzhiyun * Set the device width if source or destination is a FIFO.
363*4882a593Smuzhiyun * Should be 8, 16, or 32 bits.
364*4882a593Smuzhiyun */
au1xxx_dbdma_set_devwidth(u32 chanid,int bits)365*4882a593Smuzhiyun u32 au1xxx_dbdma_set_devwidth(u32 chanid, int bits)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun u32 rv;
368*4882a593Smuzhiyun chan_tab_t *ctp;
369*4882a593Smuzhiyun dbdev_tab_t *stp, *dtp;
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
372*4882a593Smuzhiyun stp = ctp->chan_src;
373*4882a593Smuzhiyun dtp = ctp->chan_dest;
374*4882a593Smuzhiyun rv = 0;
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun if (stp->dev_flags & DEV_FLAGS_IN) { /* Source in fifo */
377*4882a593Smuzhiyun rv = stp->dev_devwidth;
378*4882a593Smuzhiyun stp->dev_devwidth = bits;
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun if (dtp->dev_flags & DEV_FLAGS_OUT) { /* Destination out fifo */
381*4882a593Smuzhiyun rv = dtp->dev_devwidth;
382*4882a593Smuzhiyun dtp->dev_devwidth = bits;
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun return rv;
386*4882a593Smuzhiyun }
387*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_set_devwidth);
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun /* Allocate a descriptor ring, initializing as much as possible. */
au1xxx_dbdma_ring_alloc(u32 chanid,int entries)390*4882a593Smuzhiyun u32 au1xxx_dbdma_ring_alloc(u32 chanid, int entries)
391*4882a593Smuzhiyun {
392*4882a593Smuzhiyun int i;
393*4882a593Smuzhiyun u32 desc_base, srcid, destid;
394*4882a593Smuzhiyun u32 cmd0, cmd1, src1, dest1;
395*4882a593Smuzhiyun u32 src0, dest0;
396*4882a593Smuzhiyun chan_tab_t *ctp;
397*4882a593Smuzhiyun dbdev_tab_t *stp, *dtp;
398*4882a593Smuzhiyun au1x_ddma_desc_t *dp;
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun /*
401*4882a593Smuzhiyun * I guess we could check this to be within the
402*4882a593Smuzhiyun * range of the table......
403*4882a593Smuzhiyun */
404*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
405*4882a593Smuzhiyun stp = ctp->chan_src;
406*4882a593Smuzhiyun dtp = ctp->chan_dest;
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun /*
409*4882a593Smuzhiyun * The descriptors must be 32-byte aligned. There is a
410*4882a593Smuzhiyun * possibility the allocation will give us such an address,
411*4882a593Smuzhiyun * and if we try that first we are likely to not waste larger
412*4882a593Smuzhiyun * slabs of memory.
413*4882a593Smuzhiyun */
414*4882a593Smuzhiyun desc_base = (u32)kmalloc_array(entries, sizeof(au1x_ddma_desc_t),
415*4882a593Smuzhiyun GFP_KERNEL|GFP_DMA);
416*4882a593Smuzhiyun if (desc_base == 0)
417*4882a593Smuzhiyun return 0;
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun if (desc_base & 0x1f) {
420*4882a593Smuzhiyun /*
421*4882a593Smuzhiyun * Lost....do it again, allocate extra, and round
422*4882a593Smuzhiyun * the address base.
423*4882a593Smuzhiyun */
424*4882a593Smuzhiyun kfree((const void *)desc_base);
425*4882a593Smuzhiyun i = entries * sizeof(au1x_ddma_desc_t);
426*4882a593Smuzhiyun i += (sizeof(au1x_ddma_desc_t) - 1);
427*4882a593Smuzhiyun desc_base = (u32)kmalloc(i, GFP_KERNEL|GFP_DMA);
428*4882a593Smuzhiyun if (desc_base == 0)
429*4882a593Smuzhiyun return 0;
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun ctp->cdb_membase = desc_base;
432*4882a593Smuzhiyun desc_base = ALIGN_ADDR(desc_base, sizeof(au1x_ddma_desc_t));
433*4882a593Smuzhiyun } else
434*4882a593Smuzhiyun ctp->cdb_membase = desc_base;
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun dp = (au1x_ddma_desc_t *)desc_base;
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun /* Keep track of the base descriptor. */
439*4882a593Smuzhiyun ctp->chan_desc_base = dp;
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun /* Initialize the rings with as much information as we know. */
442*4882a593Smuzhiyun srcid = stp->dev_id;
443*4882a593Smuzhiyun destid = dtp->dev_id;
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun cmd0 = cmd1 = src1 = dest1 = 0;
446*4882a593Smuzhiyun src0 = dest0 = 0;
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_SID(srcid);
449*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_DID(destid);
450*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_IE | DSCR_CMD0_CV;
451*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_ST(DSCR_CMD0_ST_NOCHANGE);
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun /* Is it mem to mem transfer? */
454*4882a593Smuzhiyun if (((DSCR_CUSTOM2DEV_ID(srcid) == DSCR_CMD0_THROTTLE) ||
455*4882a593Smuzhiyun (DSCR_CUSTOM2DEV_ID(srcid) == DSCR_CMD0_ALWAYS)) &&
456*4882a593Smuzhiyun ((DSCR_CUSTOM2DEV_ID(destid) == DSCR_CMD0_THROTTLE) ||
457*4882a593Smuzhiyun (DSCR_CUSTOM2DEV_ID(destid) == DSCR_CMD0_ALWAYS)))
458*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_MEM;
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun switch (stp->dev_devwidth) {
461*4882a593Smuzhiyun case 8:
462*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_BYTE);
463*4882a593Smuzhiyun break;
464*4882a593Smuzhiyun case 16:
465*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_HALFWORD);
466*4882a593Smuzhiyun break;
467*4882a593Smuzhiyun case 32:
468*4882a593Smuzhiyun default:
469*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_WORD);
470*4882a593Smuzhiyun break;
471*4882a593Smuzhiyun }
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun switch (dtp->dev_devwidth) {
474*4882a593Smuzhiyun case 8:
475*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_BYTE);
476*4882a593Smuzhiyun break;
477*4882a593Smuzhiyun case 16:
478*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_HALFWORD);
479*4882a593Smuzhiyun break;
480*4882a593Smuzhiyun case 32:
481*4882a593Smuzhiyun default:
482*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_WORD);
483*4882a593Smuzhiyun break;
484*4882a593Smuzhiyun }
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun /*
487*4882a593Smuzhiyun * If the device is marked as an in/out FIFO, ensure it is
488*4882a593Smuzhiyun * set non-coherent.
489*4882a593Smuzhiyun */
490*4882a593Smuzhiyun if (stp->dev_flags & DEV_FLAGS_IN)
491*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_SN; /* Source in FIFO */
492*4882a593Smuzhiyun if (dtp->dev_flags & DEV_FLAGS_OUT)
493*4882a593Smuzhiyun cmd0 |= DSCR_CMD0_DN; /* Destination out FIFO */
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun /*
496*4882a593Smuzhiyun * Set up source1. For now, assume no stride and increment.
497*4882a593Smuzhiyun * A channel attribute update can change this later.
498*4882a593Smuzhiyun */
499*4882a593Smuzhiyun switch (stp->dev_tsize) {
500*4882a593Smuzhiyun case 1:
501*4882a593Smuzhiyun src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE1);
502*4882a593Smuzhiyun break;
503*4882a593Smuzhiyun case 2:
504*4882a593Smuzhiyun src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE2);
505*4882a593Smuzhiyun break;
506*4882a593Smuzhiyun case 4:
507*4882a593Smuzhiyun src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE4);
508*4882a593Smuzhiyun break;
509*4882a593Smuzhiyun case 8:
510*4882a593Smuzhiyun default:
511*4882a593Smuzhiyun src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE8);
512*4882a593Smuzhiyun break;
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun /* If source input is FIFO, set static address. */
516*4882a593Smuzhiyun if (stp->dev_flags & DEV_FLAGS_IN) {
517*4882a593Smuzhiyun if (stp->dev_flags & DEV_FLAGS_BURSTABLE)
518*4882a593Smuzhiyun src1 |= DSCR_SRC1_SAM(DSCR_xAM_BURST);
519*4882a593Smuzhiyun else
520*4882a593Smuzhiyun src1 |= DSCR_SRC1_SAM(DSCR_xAM_STATIC);
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun
523*4882a593Smuzhiyun if (stp->dev_physaddr)
524*4882a593Smuzhiyun src0 = stp->dev_physaddr;
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun /*
527*4882a593Smuzhiyun * Set up dest1. For now, assume no stride and increment.
528*4882a593Smuzhiyun * A channel attribute update can change this later.
529*4882a593Smuzhiyun */
530*4882a593Smuzhiyun switch (dtp->dev_tsize) {
531*4882a593Smuzhiyun case 1:
532*4882a593Smuzhiyun dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE1);
533*4882a593Smuzhiyun break;
534*4882a593Smuzhiyun case 2:
535*4882a593Smuzhiyun dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE2);
536*4882a593Smuzhiyun break;
537*4882a593Smuzhiyun case 4:
538*4882a593Smuzhiyun dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE4);
539*4882a593Smuzhiyun break;
540*4882a593Smuzhiyun case 8:
541*4882a593Smuzhiyun default:
542*4882a593Smuzhiyun dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE8);
543*4882a593Smuzhiyun break;
544*4882a593Smuzhiyun }
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun /* If destination output is FIFO, set static address. */
547*4882a593Smuzhiyun if (dtp->dev_flags & DEV_FLAGS_OUT) {
548*4882a593Smuzhiyun if (dtp->dev_flags & DEV_FLAGS_BURSTABLE)
549*4882a593Smuzhiyun dest1 |= DSCR_DEST1_DAM(DSCR_xAM_BURST);
550*4882a593Smuzhiyun else
551*4882a593Smuzhiyun dest1 |= DSCR_DEST1_DAM(DSCR_xAM_STATIC);
552*4882a593Smuzhiyun }
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun if (dtp->dev_physaddr)
555*4882a593Smuzhiyun dest0 = dtp->dev_physaddr;
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun #if 0
558*4882a593Smuzhiyun printk(KERN_DEBUG "did:%x sid:%x cmd0:%x cmd1:%x source0:%x "
559*4882a593Smuzhiyun "source1:%x dest0:%x dest1:%x\n",
560*4882a593Smuzhiyun dtp->dev_id, stp->dev_id, cmd0, cmd1, src0,
561*4882a593Smuzhiyun src1, dest0, dest1);
562*4882a593Smuzhiyun #endif
563*4882a593Smuzhiyun for (i = 0; i < entries; i++) {
564*4882a593Smuzhiyun dp->dscr_cmd0 = cmd0;
565*4882a593Smuzhiyun dp->dscr_cmd1 = cmd1;
566*4882a593Smuzhiyun dp->dscr_source0 = src0;
567*4882a593Smuzhiyun dp->dscr_source1 = src1;
568*4882a593Smuzhiyun dp->dscr_dest0 = dest0;
569*4882a593Smuzhiyun dp->dscr_dest1 = dest1;
570*4882a593Smuzhiyun dp->dscr_stat = 0;
571*4882a593Smuzhiyun dp->sw_context = 0;
572*4882a593Smuzhiyun dp->sw_status = 0;
573*4882a593Smuzhiyun dp->dscr_nxtptr = DSCR_NXTPTR(virt_to_phys(dp + 1));
574*4882a593Smuzhiyun dp++;
575*4882a593Smuzhiyun }
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun /* Make last descrptor point to the first. */
578*4882a593Smuzhiyun dp--;
579*4882a593Smuzhiyun dp->dscr_nxtptr = DSCR_NXTPTR(virt_to_phys(ctp->chan_desc_base));
580*4882a593Smuzhiyun ctp->get_ptr = ctp->put_ptr = ctp->cur_ptr = ctp->chan_desc_base;
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun return (u32)ctp->chan_desc_base;
583*4882a593Smuzhiyun }
584*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_ring_alloc);
585*4882a593Smuzhiyun
586*4882a593Smuzhiyun /*
587*4882a593Smuzhiyun * Put a source buffer into the DMA ring.
588*4882a593Smuzhiyun * This updates the source pointer and byte count. Normally used
589*4882a593Smuzhiyun * for memory to fifo transfers.
590*4882a593Smuzhiyun */
au1xxx_dbdma_put_source(u32 chanid,dma_addr_t buf,int nbytes,u32 flags)591*4882a593Smuzhiyun u32 au1xxx_dbdma_put_source(u32 chanid, dma_addr_t buf, int nbytes, u32 flags)
592*4882a593Smuzhiyun {
593*4882a593Smuzhiyun chan_tab_t *ctp;
594*4882a593Smuzhiyun au1x_ddma_desc_t *dp;
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun /*
597*4882a593Smuzhiyun * I guess we could check this to be within the
598*4882a593Smuzhiyun * range of the table......
599*4882a593Smuzhiyun */
600*4882a593Smuzhiyun ctp = *(chan_tab_t **)chanid;
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun /*
603*4882a593Smuzhiyun * We should have multiple callers for a particular channel,
604*4882a593Smuzhiyun * an interrupt doesn't affect this pointer nor the descriptor,
605*4882a593Smuzhiyun * so no locking should be needed.
606*4882a593Smuzhiyun */
607*4882a593Smuzhiyun dp = ctp->put_ptr;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun /*
610*4882a593Smuzhiyun * If the descriptor is valid, we are way ahead of the DMA
611*4882a593Smuzhiyun * engine, so just return an error condition.
612*4882a593Smuzhiyun */
613*4882a593Smuzhiyun if (dp->dscr_cmd0 & DSCR_CMD0_V)
614*4882a593Smuzhiyun return 0;
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun /* Load up buffer address and byte count. */
617*4882a593Smuzhiyun dp->dscr_source0 = buf & ~0UL;
618*4882a593Smuzhiyun dp->dscr_cmd1 = nbytes;
619*4882a593Smuzhiyun /* Check flags */
620*4882a593Smuzhiyun if (flags & DDMA_FLAGS_IE)
621*4882a593Smuzhiyun dp->dscr_cmd0 |= DSCR_CMD0_IE;
622*4882a593Smuzhiyun if (flags & DDMA_FLAGS_NOIE)
623*4882a593Smuzhiyun dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun /*
626*4882a593Smuzhiyun * There is an errata on the Au1200/Au1550 parts that could result
627*4882a593Smuzhiyun * in "stale" data being DMA'ed. It has to do with the snoop logic on
628*4882a593Smuzhiyun * the cache eviction buffer. DMA_NONCOHERENT is on by default for
629*4882a593Smuzhiyun * these parts. If it is fixed in the future, these dma_cache_inv will
630*4882a593Smuzhiyun * just be nothing more than empty macros. See io.h.
631*4882a593Smuzhiyun */
632*4882a593Smuzhiyun dma_cache_wback_inv((unsigned long)buf, nbytes);
633*4882a593Smuzhiyun dp->dscr_cmd0 |= DSCR_CMD0_V; /* Let it rip */
634*4882a593Smuzhiyun wmb(); /* drain writebuffer */
635*4882a593Smuzhiyun dma_cache_wback_inv((unsigned long)dp, sizeof(*dp));
636*4882a593Smuzhiyun ctp->chan_ptr->ddma_dbell = 0;
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun /* Get next descriptor pointer. */
639*4882a593Smuzhiyun ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun /* Return something non-zero. */
642*4882a593Smuzhiyun return nbytes;
643*4882a593Smuzhiyun }
644*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_put_source);
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun /* Put a destination buffer into the DMA ring.
647*4882a593Smuzhiyun * This updates the destination pointer and byte count. Normally used
648*4882a593Smuzhiyun * to place an empty buffer into the ring for fifo to memory transfers.
649*4882a593Smuzhiyun */
au1xxx_dbdma_put_dest(u32 chanid,dma_addr_t buf,int nbytes,u32 flags)650*4882a593Smuzhiyun u32 au1xxx_dbdma_put_dest(u32 chanid, dma_addr_t buf, int nbytes, u32 flags)
651*4882a593Smuzhiyun {
652*4882a593Smuzhiyun chan_tab_t *ctp;
653*4882a593Smuzhiyun au1x_ddma_desc_t *dp;
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun /* I guess we could check this to be within the
656*4882a593Smuzhiyun * range of the table......
657*4882a593Smuzhiyun */
658*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun /* We should have multiple callers for a particular channel,
661*4882a593Smuzhiyun * an interrupt doesn't affect this pointer nor the descriptor,
662*4882a593Smuzhiyun * so no locking should be needed.
663*4882a593Smuzhiyun */
664*4882a593Smuzhiyun dp = ctp->put_ptr;
665*4882a593Smuzhiyun
666*4882a593Smuzhiyun /* If the descriptor is valid, we are way ahead of the DMA
667*4882a593Smuzhiyun * engine, so just return an error condition.
668*4882a593Smuzhiyun */
669*4882a593Smuzhiyun if (dp->dscr_cmd0 & DSCR_CMD0_V)
670*4882a593Smuzhiyun return 0;
671*4882a593Smuzhiyun
672*4882a593Smuzhiyun /* Load up buffer address and byte count */
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun /* Check flags */
675*4882a593Smuzhiyun if (flags & DDMA_FLAGS_IE)
676*4882a593Smuzhiyun dp->dscr_cmd0 |= DSCR_CMD0_IE;
677*4882a593Smuzhiyun if (flags & DDMA_FLAGS_NOIE)
678*4882a593Smuzhiyun dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
679*4882a593Smuzhiyun
680*4882a593Smuzhiyun dp->dscr_dest0 = buf & ~0UL;
681*4882a593Smuzhiyun dp->dscr_cmd1 = nbytes;
682*4882a593Smuzhiyun #if 0
683*4882a593Smuzhiyun printk(KERN_DEBUG "cmd0:%x cmd1:%x source0:%x source1:%x dest0:%x dest1:%x\n",
684*4882a593Smuzhiyun dp->dscr_cmd0, dp->dscr_cmd1, dp->dscr_source0,
685*4882a593Smuzhiyun dp->dscr_source1, dp->dscr_dest0, dp->dscr_dest1);
686*4882a593Smuzhiyun #endif
687*4882a593Smuzhiyun /*
688*4882a593Smuzhiyun * There is an errata on the Au1200/Au1550 parts that could result in
689*4882a593Smuzhiyun * "stale" data being DMA'ed. It has to do with the snoop logic on the
690*4882a593Smuzhiyun * cache eviction buffer. DMA_NONCOHERENT is on by default for these
691*4882a593Smuzhiyun * parts. If it is fixed in the future, these dma_cache_inv will just
692*4882a593Smuzhiyun * be nothing more than empty macros. See io.h.
693*4882a593Smuzhiyun */
694*4882a593Smuzhiyun dma_cache_inv((unsigned long)buf, nbytes);
695*4882a593Smuzhiyun dp->dscr_cmd0 |= DSCR_CMD0_V; /* Let it rip */
696*4882a593Smuzhiyun wmb(); /* drain writebuffer */
697*4882a593Smuzhiyun dma_cache_wback_inv((unsigned long)dp, sizeof(*dp));
698*4882a593Smuzhiyun ctp->chan_ptr->ddma_dbell = 0;
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun /* Get next descriptor pointer. */
701*4882a593Smuzhiyun ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
702*4882a593Smuzhiyun
703*4882a593Smuzhiyun /* Return something non-zero. */
704*4882a593Smuzhiyun return nbytes;
705*4882a593Smuzhiyun }
706*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_put_dest);
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun /*
709*4882a593Smuzhiyun * Get a destination buffer into the DMA ring.
710*4882a593Smuzhiyun * Normally used to get a full buffer from the ring during fifo
711*4882a593Smuzhiyun * to memory transfers. This does not set the valid bit, you will
712*4882a593Smuzhiyun * have to put another destination buffer to keep the DMA going.
713*4882a593Smuzhiyun */
au1xxx_dbdma_get_dest(u32 chanid,void ** buf,int * nbytes)714*4882a593Smuzhiyun u32 au1xxx_dbdma_get_dest(u32 chanid, void **buf, int *nbytes)
715*4882a593Smuzhiyun {
716*4882a593Smuzhiyun chan_tab_t *ctp;
717*4882a593Smuzhiyun au1x_ddma_desc_t *dp;
718*4882a593Smuzhiyun u32 rv;
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun /*
721*4882a593Smuzhiyun * I guess we could check this to be within the
722*4882a593Smuzhiyun * range of the table......
723*4882a593Smuzhiyun */
724*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
725*4882a593Smuzhiyun
726*4882a593Smuzhiyun /*
727*4882a593Smuzhiyun * We should have multiple callers for a particular channel,
728*4882a593Smuzhiyun * an interrupt doesn't affect this pointer nor the descriptor,
729*4882a593Smuzhiyun * so no locking should be needed.
730*4882a593Smuzhiyun */
731*4882a593Smuzhiyun dp = ctp->get_ptr;
732*4882a593Smuzhiyun
733*4882a593Smuzhiyun /*
734*4882a593Smuzhiyun * If the descriptor is valid, we are way ahead of the DMA
735*4882a593Smuzhiyun * engine, so just return an error condition.
736*4882a593Smuzhiyun */
737*4882a593Smuzhiyun if (dp->dscr_cmd0 & DSCR_CMD0_V)
738*4882a593Smuzhiyun return 0;
739*4882a593Smuzhiyun
740*4882a593Smuzhiyun /* Return buffer address and byte count. */
741*4882a593Smuzhiyun *buf = (void *)(phys_to_virt(dp->dscr_dest0));
742*4882a593Smuzhiyun *nbytes = dp->dscr_cmd1;
743*4882a593Smuzhiyun rv = dp->dscr_stat;
744*4882a593Smuzhiyun
745*4882a593Smuzhiyun /* Get next descriptor pointer. */
746*4882a593Smuzhiyun ctp->get_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun /* Return something non-zero. */
749*4882a593Smuzhiyun return rv;
750*4882a593Smuzhiyun }
751*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(au1xxx_dbdma_get_dest);
752*4882a593Smuzhiyun
au1xxx_dbdma_stop(u32 chanid)753*4882a593Smuzhiyun void au1xxx_dbdma_stop(u32 chanid)
754*4882a593Smuzhiyun {
755*4882a593Smuzhiyun chan_tab_t *ctp;
756*4882a593Smuzhiyun au1x_dma_chan_t *cp;
757*4882a593Smuzhiyun int halt_timeout = 0;
758*4882a593Smuzhiyun
759*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
760*4882a593Smuzhiyun
761*4882a593Smuzhiyun cp = ctp->chan_ptr;
762*4882a593Smuzhiyun cp->ddma_cfg &= ~DDMA_CFG_EN; /* Disable channel */
763*4882a593Smuzhiyun wmb(); /* drain writebuffer */
764*4882a593Smuzhiyun while (!(cp->ddma_stat & DDMA_STAT_H)) {
765*4882a593Smuzhiyun udelay(1);
766*4882a593Smuzhiyun halt_timeout++;
767*4882a593Smuzhiyun if (halt_timeout > 100) {
768*4882a593Smuzhiyun printk(KERN_WARNING "warning: DMA channel won't halt\n");
769*4882a593Smuzhiyun break;
770*4882a593Smuzhiyun }
771*4882a593Smuzhiyun }
772*4882a593Smuzhiyun /* clear current desc valid and doorbell */
773*4882a593Smuzhiyun cp->ddma_stat |= (DDMA_STAT_DB | DDMA_STAT_V);
774*4882a593Smuzhiyun wmb(); /* drain writebuffer */
775*4882a593Smuzhiyun }
776*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_stop);
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun /*
779*4882a593Smuzhiyun * Start using the current descriptor pointer. If the DBDMA encounters
780*4882a593Smuzhiyun * a non-valid descriptor, it will stop. In this case, we can just
781*4882a593Smuzhiyun * continue by adding a buffer to the list and starting again.
782*4882a593Smuzhiyun */
au1xxx_dbdma_start(u32 chanid)783*4882a593Smuzhiyun void au1xxx_dbdma_start(u32 chanid)
784*4882a593Smuzhiyun {
785*4882a593Smuzhiyun chan_tab_t *ctp;
786*4882a593Smuzhiyun au1x_dma_chan_t *cp;
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
789*4882a593Smuzhiyun cp = ctp->chan_ptr;
790*4882a593Smuzhiyun cp->ddma_desptr = virt_to_phys(ctp->cur_ptr);
791*4882a593Smuzhiyun cp->ddma_cfg |= DDMA_CFG_EN; /* Enable channel */
792*4882a593Smuzhiyun wmb(); /* drain writebuffer */
793*4882a593Smuzhiyun cp->ddma_dbell = 0;
794*4882a593Smuzhiyun wmb(); /* drain writebuffer */
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_start);
797*4882a593Smuzhiyun
au1xxx_dbdma_reset(u32 chanid)798*4882a593Smuzhiyun void au1xxx_dbdma_reset(u32 chanid)
799*4882a593Smuzhiyun {
800*4882a593Smuzhiyun chan_tab_t *ctp;
801*4882a593Smuzhiyun au1x_ddma_desc_t *dp;
802*4882a593Smuzhiyun
803*4882a593Smuzhiyun au1xxx_dbdma_stop(chanid);
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
806*4882a593Smuzhiyun ctp->get_ptr = ctp->put_ptr = ctp->cur_ptr = ctp->chan_desc_base;
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun /* Run through the descriptors and reset the valid indicator. */
809*4882a593Smuzhiyun dp = ctp->chan_desc_base;
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun do {
812*4882a593Smuzhiyun dp->dscr_cmd0 &= ~DSCR_CMD0_V;
813*4882a593Smuzhiyun /*
814*4882a593Smuzhiyun * Reset our software status -- this is used to determine
815*4882a593Smuzhiyun * if a descriptor is in use by upper level software. Since
816*4882a593Smuzhiyun * posting can reset 'V' bit.
817*4882a593Smuzhiyun */
818*4882a593Smuzhiyun dp->sw_status = 0;
819*4882a593Smuzhiyun dp = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
820*4882a593Smuzhiyun } while (dp != ctp->chan_desc_base);
821*4882a593Smuzhiyun }
822*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_reset);
823*4882a593Smuzhiyun
au1xxx_get_dma_residue(u32 chanid)824*4882a593Smuzhiyun u32 au1xxx_get_dma_residue(u32 chanid)
825*4882a593Smuzhiyun {
826*4882a593Smuzhiyun chan_tab_t *ctp;
827*4882a593Smuzhiyun au1x_dma_chan_t *cp;
828*4882a593Smuzhiyun u32 rv;
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
831*4882a593Smuzhiyun cp = ctp->chan_ptr;
832*4882a593Smuzhiyun
833*4882a593Smuzhiyun /* This is only valid if the channel is stopped. */
834*4882a593Smuzhiyun rv = cp->ddma_bytecnt;
835*4882a593Smuzhiyun wmb(); /* drain writebuffer */
836*4882a593Smuzhiyun
837*4882a593Smuzhiyun return rv;
838*4882a593Smuzhiyun }
839*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(au1xxx_get_dma_residue);
840*4882a593Smuzhiyun
au1xxx_dbdma_chan_free(u32 chanid)841*4882a593Smuzhiyun void au1xxx_dbdma_chan_free(u32 chanid)
842*4882a593Smuzhiyun {
843*4882a593Smuzhiyun chan_tab_t *ctp;
844*4882a593Smuzhiyun dbdev_tab_t *stp, *dtp;
845*4882a593Smuzhiyun
846*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
847*4882a593Smuzhiyun stp = ctp->chan_src;
848*4882a593Smuzhiyun dtp = ctp->chan_dest;
849*4882a593Smuzhiyun
850*4882a593Smuzhiyun au1xxx_dbdma_stop(chanid);
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun kfree((void *)ctp->cdb_membase);
853*4882a593Smuzhiyun
854*4882a593Smuzhiyun stp->dev_flags &= ~DEV_FLAGS_INUSE;
855*4882a593Smuzhiyun dtp->dev_flags &= ~DEV_FLAGS_INUSE;
856*4882a593Smuzhiyun chan_tab_ptr[ctp->chan_index] = NULL;
857*4882a593Smuzhiyun
858*4882a593Smuzhiyun kfree(ctp);
859*4882a593Smuzhiyun }
860*4882a593Smuzhiyun EXPORT_SYMBOL(au1xxx_dbdma_chan_free);
861*4882a593Smuzhiyun
dbdma_interrupt(int irq,void * dev_id)862*4882a593Smuzhiyun static irqreturn_t dbdma_interrupt(int irq, void *dev_id)
863*4882a593Smuzhiyun {
864*4882a593Smuzhiyun u32 intstat;
865*4882a593Smuzhiyun u32 chan_index;
866*4882a593Smuzhiyun chan_tab_t *ctp;
867*4882a593Smuzhiyun au1x_ddma_desc_t *dp;
868*4882a593Smuzhiyun au1x_dma_chan_t *cp;
869*4882a593Smuzhiyun
870*4882a593Smuzhiyun intstat = dbdma_gptr->ddma_intstat;
871*4882a593Smuzhiyun wmb(); /* drain writebuffer */
872*4882a593Smuzhiyun chan_index = __ffs(intstat);
873*4882a593Smuzhiyun
874*4882a593Smuzhiyun ctp = chan_tab_ptr[chan_index];
875*4882a593Smuzhiyun cp = ctp->chan_ptr;
876*4882a593Smuzhiyun dp = ctp->cur_ptr;
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun /* Reset interrupt. */
879*4882a593Smuzhiyun cp->ddma_irq = 0;
880*4882a593Smuzhiyun wmb(); /* drain writebuffer */
881*4882a593Smuzhiyun
882*4882a593Smuzhiyun if (ctp->chan_callback)
883*4882a593Smuzhiyun ctp->chan_callback(irq, ctp->chan_callparam);
884*4882a593Smuzhiyun
885*4882a593Smuzhiyun ctp->cur_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
886*4882a593Smuzhiyun return IRQ_RETVAL(1);
887*4882a593Smuzhiyun }
888*4882a593Smuzhiyun
au1xxx_dbdma_dump(u32 chanid)889*4882a593Smuzhiyun void au1xxx_dbdma_dump(u32 chanid)
890*4882a593Smuzhiyun {
891*4882a593Smuzhiyun chan_tab_t *ctp;
892*4882a593Smuzhiyun au1x_ddma_desc_t *dp;
893*4882a593Smuzhiyun dbdev_tab_t *stp, *dtp;
894*4882a593Smuzhiyun au1x_dma_chan_t *cp;
895*4882a593Smuzhiyun u32 i = 0;
896*4882a593Smuzhiyun
897*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
898*4882a593Smuzhiyun stp = ctp->chan_src;
899*4882a593Smuzhiyun dtp = ctp->chan_dest;
900*4882a593Smuzhiyun cp = ctp->chan_ptr;
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun printk(KERN_DEBUG "Chan %x, stp %x (dev %d) dtp %x (dev %d)\n",
903*4882a593Smuzhiyun (u32)ctp, (u32)stp, stp - dbdev_tab, (u32)dtp,
904*4882a593Smuzhiyun dtp - dbdev_tab);
905*4882a593Smuzhiyun printk(KERN_DEBUG "desc base %x, get %x, put %x, cur %x\n",
906*4882a593Smuzhiyun (u32)(ctp->chan_desc_base), (u32)(ctp->get_ptr),
907*4882a593Smuzhiyun (u32)(ctp->put_ptr), (u32)(ctp->cur_ptr));
908*4882a593Smuzhiyun
909*4882a593Smuzhiyun printk(KERN_DEBUG "dbdma chan %x\n", (u32)cp);
910*4882a593Smuzhiyun printk(KERN_DEBUG "cfg %08x, desptr %08x, statptr %08x\n",
911*4882a593Smuzhiyun cp->ddma_cfg, cp->ddma_desptr, cp->ddma_statptr);
912*4882a593Smuzhiyun printk(KERN_DEBUG "dbell %08x, irq %08x, stat %08x, bytecnt %08x\n",
913*4882a593Smuzhiyun cp->ddma_dbell, cp->ddma_irq, cp->ddma_stat,
914*4882a593Smuzhiyun cp->ddma_bytecnt);
915*4882a593Smuzhiyun
916*4882a593Smuzhiyun /* Run through the descriptors */
917*4882a593Smuzhiyun dp = ctp->chan_desc_base;
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun do {
920*4882a593Smuzhiyun printk(KERN_DEBUG "Dp[%d]= %08x, cmd0 %08x, cmd1 %08x\n",
921*4882a593Smuzhiyun i++, (u32)dp, dp->dscr_cmd0, dp->dscr_cmd1);
922*4882a593Smuzhiyun printk(KERN_DEBUG "src0 %08x, src1 %08x, dest0 %08x, dest1 %08x\n",
923*4882a593Smuzhiyun dp->dscr_source0, dp->dscr_source1,
924*4882a593Smuzhiyun dp->dscr_dest0, dp->dscr_dest1);
925*4882a593Smuzhiyun printk(KERN_DEBUG "stat %08x, nxtptr %08x\n",
926*4882a593Smuzhiyun dp->dscr_stat, dp->dscr_nxtptr);
927*4882a593Smuzhiyun dp = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
928*4882a593Smuzhiyun } while (dp != ctp->chan_desc_base);
929*4882a593Smuzhiyun }
930*4882a593Smuzhiyun
931*4882a593Smuzhiyun /* Put a descriptor into the DMA ring.
932*4882a593Smuzhiyun * This updates the source/destination pointers and byte count.
933*4882a593Smuzhiyun */
au1xxx_dbdma_put_dscr(u32 chanid,au1x_ddma_desc_t * dscr)934*4882a593Smuzhiyun u32 au1xxx_dbdma_put_dscr(u32 chanid, au1x_ddma_desc_t *dscr)
935*4882a593Smuzhiyun {
936*4882a593Smuzhiyun chan_tab_t *ctp;
937*4882a593Smuzhiyun au1x_ddma_desc_t *dp;
938*4882a593Smuzhiyun u32 nbytes = 0;
939*4882a593Smuzhiyun
940*4882a593Smuzhiyun /*
941*4882a593Smuzhiyun * I guess we could check this to be within the
942*4882a593Smuzhiyun * range of the table......
943*4882a593Smuzhiyun */
944*4882a593Smuzhiyun ctp = *((chan_tab_t **)chanid);
945*4882a593Smuzhiyun
946*4882a593Smuzhiyun /*
947*4882a593Smuzhiyun * We should have multiple callers for a particular channel,
948*4882a593Smuzhiyun * an interrupt doesn't affect this pointer nor the descriptor,
949*4882a593Smuzhiyun * so no locking should be needed.
950*4882a593Smuzhiyun */
951*4882a593Smuzhiyun dp = ctp->put_ptr;
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun /*
954*4882a593Smuzhiyun * If the descriptor is valid, we are way ahead of the DMA
955*4882a593Smuzhiyun * engine, so just return an error condition.
956*4882a593Smuzhiyun */
957*4882a593Smuzhiyun if (dp->dscr_cmd0 & DSCR_CMD0_V)
958*4882a593Smuzhiyun return 0;
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun /* Load up buffer addresses and byte count. */
961*4882a593Smuzhiyun dp->dscr_dest0 = dscr->dscr_dest0;
962*4882a593Smuzhiyun dp->dscr_source0 = dscr->dscr_source0;
963*4882a593Smuzhiyun dp->dscr_dest1 = dscr->dscr_dest1;
964*4882a593Smuzhiyun dp->dscr_source1 = dscr->dscr_source1;
965*4882a593Smuzhiyun dp->dscr_cmd1 = dscr->dscr_cmd1;
966*4882a593Smuzhiyun nbytes = dscr->dscr_cmd1;
967*4882a593Smuzhiyun /* Allow the caller to specify if an interrupt is generated */
968*4882a593Smuzhiyun dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
969*4882a593Smuzhiyun dp->dscr_cmd0 |= dscr->dscr_cmd0 | DSCR_CMD0_V;
970*4882a593Smuzhiyun ctp->chan_ptr->ddma_dbell = 0;
971*4882a593Smuzhiyun
972*4882a593Smuzhiyun /* Get next descriptor pointer. */
973*4882a593Smuzhiyun ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun /* Return something non-zero. */
976*4882a593Smuzhiyun return nbytes;
977*4882a593Smuzhiyun }
978*4882a593Smuzhiyun
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun static unsigned long alchemy_dbdma_pm_data[NUM_DBDMA_CHANS + 1][6];
981*4882a593Smuzhiyun
alchemy_dbdma_suspend(void)982*4882a593Smuzhiyun static int alchemy_dbdma_suspend(void)
983*4882a593Smuzhiyun {
984*4882a593Smuzhiyun int i;
985*4882a593Smuzhiyun void __iomem *addr;
986*4882a593Smuzhiyun
987*4882a593Smuzhiyun addr = (void __iomem *)KSEG1ADDR(AU1550_DBDMA_CONF_PHYS_ADDR);
988*4882a593Smuzhiyun alchemy_dbdma_pm_data[0][0] = __raw_readl(addr + 0x00);
989*4882a593Smuzhiyun alchemy_dbdma_pm_data[0][1] = __raw_readl(addr + 0x04);
990*4882a593Smuzhiyun alchemy_dbdma_pm_data[0][2] = __raw_readl(addr + 0x08);
991*4882a593Smuzhiyun alchemy_dbdma_pm_data[0][3] = __raw_readl(addr + 0x0c);
992*4882a593Smuzhiyun
993*4882a593Smuzhiyun /* save channel configurations */
994*4882a593Smuzhiyun addr = (void __iomem *)KSEG1ADDR(AU1550_DBDMA_PHYS_ADDR);
995*4882a593Smuzhiyun for (i = 1; i <= NUM_DBDMA_CHANS; i++) {
996*4882a593Smuzhiyun alchemy_dbdma_pm_data[i][0] = __raw_readl(addr + 0x00);
997*4882a593Smuzhiyun alchemy_dbdma_pm_data[i][1] = __raw_readl(addr + 0x04);
998*4882a593Smuzhiyun alchemy_dbdma_pm_data[i][2] = __raw_readl(addr + 0x08);
999*4882a593Smuzhiyun alchemy_dbdma_pm_data[i][3] = __raw_readl(addr + 0x0c);
1000*4882a593Smuzhiyun alchemy_dbdma_pm_data[i][4] = __raw_readl(addr + 0x10);
1001*4882a593Smuzhiyun alchemy_dbdma_pm_data[i][5] = __raw_readl(addr + 0x14);
1002*4882a593Smuzhiyun
1003*4882a593Smuzhiyun /* halt channel */
1004*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[i][0] & ~1, addr + 0x00);
1005*4882a593Smuzhiyun wmb();
1006*4882a593Smuzhiyun while (!(__raw_readl(addr + 0x14) & 1))
1007*4882a593Smuzhiyun wmb();
1008*4882a593Smuzhiyun
1009*4882a593Smuzhiyun addr += 0x100; /* next channel base */
1010*4882a593Smuzhiyun }
1011*4882a593Smuzhiyun /* disable channel interrupts */
1012*4882a593Smuzhiyun addr = (void __iomem *)KSEG1ADDR(AU1550_DBDMA_CONF_PHYS_ADDR);
1013*4882a593Smuzhiyun __raw_writel(0, addr + 0x0c);
1014*4882a593Smuzhiyun wmb();
1015*4882a593Smuzhiyun
1016*4882a593Smuzhiyun return 0;
1017*4882a593Smuzhiyun }
1018*4882a593Smuzhiyun
alchemy_dbdma_resume(void)1019*4882a593Smuzhiyun static void alchemy_dbdma_resume(void)
1020*4882a593Smuzhiyun {
1021*4882a593Smuzhiyun int i;
1022*4882a593Smuzhiyun void __iomem *addr;
1023*4882a593Smuzhiyun
1024*4882a593Smuzhiyun addr = (void __iomem *)KSEG1ADDR(AU1550_DBDMA_CONF_PHYS_ADDR);
1025*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[0][0], addr + 0x00);
1026*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[0][1], addr + 0x04);
1027*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[0][2], addr + 0x08);
1028*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[0][3], addr + 0x0c);
1029*4882a593Smuzhiyun
1030*4882a593Smuzhiyun /* restore channel configurations */
1031*4882a593Smuzhiyun addr = (void __iomem *)KSEG1ADDR(AU1550_DBDMA_PHYS_ADDR);
1032*4882a593Smuzhiyun for (i = 1; i <= NUM_DBDMA_CHANS; i++) {
1033*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[i][0], addr + 0x00);
1034*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[i][1], addr + 0x04);
1035*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[i][2], addr + 0x08);
1036*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[i][3], addr + 0x0c);
1037*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[i][4], addr + 0x10);
1038*4882a593Smuzhiyun __raw_writel(alchemy_dbdma_pm_data[i][5], addr + 0x14);
1039*4882a593Smuzhiyun wmb();
1040*4882a593Smuzhiyun addr += 0x100; /* next channel base */
1041*4882a593Smuzhiyun }
1042*4882a593Smuzhiyun }
1043*4882a593Smuzhiyun
1044*4882a593Smuzhiyun static struct syscore_ops alchemy_dbdma_syscore_ops = {
1045*4882a593Smuzhiyun .suspend = alchemy_dbdma_suspend,
1046*4882a593Smuzhiyun .resume = alchemy_dbdma_resume,
1047*4882a593Smuzhiyun };
1048*4882a593Smuzhiyun
dbdma_setup(unsigned int irq,dbdev_tab_t * idtable)1049*4882a593Smuzhiyun static int __init dbdma_setup(unsigned int irq, dbdev_tab_t *idtable)
1050*4882a593Smuzhiyun {
1051*4882a593Smuzhiyun int ret;
1052*4882a593Smuzhiyun
1053*4882a593Smuzhiyun dbdev_tab = kcalloc(DBDEV_TAB_SIZE, sizeof(dbdev_tab_t), GFP_KERNEL);
1054*4882a593Smuzhiyun if (!dbdev_tab)
1055*4882a593Smuzhiyun return -ENOMEM;
1056*4882a593Smuzhiyun
1057*4882a593Smuzhiyun memcpy(dbdev_tab, idtable, 32 * sizeof(dbdev_tab_t));
1058*4882a593Smuzhiyun for (ret = 32; ret < DBDEV_TAB_SIZE; ret++)
1059*4882a593Smuzhiyun dbdev_tab[ret].dev_id = ~0;
1060*4882a593Smuzhiyun
1061*4882a593Smuzhiyun dbdma_gptr->ddma_config = 0;
1062*4882a593Smuzhiyun dbdma_gptr->ddma_throttle = 0;
1063*4882a593Smuzhiyun dbdma_gptr->ddma_inten = 0xffff;
1064*4882a593Smuzhiyun wmb(); /* drain writebuffer */
1065*4882a593Smuzhiyun
1066*4882a593Smuzhiyun ret = request_irq(irq, dbdma_interrupt, 0, "dbdma", (void *)dbdma_gptr);
1067*4882a593Smuzhiyun if (ret)
1068*4882a593Smuzhiyun printk(KERN_ERR "Cannot grab DBDMA interrupt!\n");
1069*4882a593Smuzhiyun else {
1070*4882a593Smuzhiyun dbdma_initialized = 1;
1071*4882a593Smuzhiyun register_syscore_ops(&alchemy_dbdma_syscore_ops);
1072*4882a593Smuzhiyun }
1073*4882a593Smuzhiyun
1074*4882a593Smuzhiyun return ret;
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun
alchemy_dbdma_init(void)1077*4882a593Smuzhiyun static int __init alchemy_dbdma_init(void)
1078*4882a593Smuzhiyun {
1079*4882a593Smuzhiyun switch (alchemy_get_cputype()) {
1080*4882a593Smuzhiyun case ALCHEMY_CPU_AU1550:
1081*4882a593Smuzhiyun return dbdma_setup(AU1550_DDMA_INT, au1550_dbdev_tab);
1082*4882a593Smuzhiyun case ALCHEMY_CPU_AU1200:
1083*4882a593Smuzhiyun return dbdma_setup(AU1200_DDMA_INT, au1200_dbdev_tab);
1084*4882a593Smuzhiyun case ALCHEMY_CPU_AU1300:
1085*4882a593Smuzhiyun return dbdma_setup(AU1300_DDMA_INT, au1300_dbdev_tab);
1086*4882a593Smuzhiyun }
1087*4882a593Smuzhiyun return 0;
1088*4882a593Smuzhiyun }
1089*4882a593Smuzhiyun subsys_initcall(alchemy_dbdma_init);
1090