52fb9faad819e4ec445afffd61b0ff219b7d23c4
[mplayer/glamo.git] / drivers / libglamo / dma.h
blob52fb9faad819e4ec445afffd61b0ff219b7d23c4
1 /*
2 * Glamo DMA engine.
4 * Copyright (C) 2007 OpenMoko, Inc.
5 * Author: Chia-I Wu <olv@openmoko.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 or
10 * (at your option) version 3 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
22 #ifndef _DMA_H_
23 #define _DMA_H_
25 #include <stdlib.h> /* for exit() */
26 #include "hw.h"
28 #define GLAMO_REG_WIDTH sizeof(GLAMO_REG_TYPE)
31 * some engines only support MMIO mode; while
32 * some engines only support CMDQ mode
34 enum glamo_dma_mode {
35 GLAMO_DMA_MODE_MMIO,
36 GLAMO_DMA_MODE_CMDQ,
39 enum glamo_dma_wait_type {
40 GLAMO_DMA_WAIT_CMDQ,
41 GLAMO_DMA_WAIT_ISP,
42 GLAMO_DMA_WAIT_ALL,
45 struct glamo_dma_manager {
46 enum glamo_dma_mode mode;
48 unsigned char *lbuf;
49 int lsize;
50 int llen;
52 volatile GLAMO_REG_TYPE *cmdq;
53 int size;
54 int r;
55 int w;
58 struct glamo_dma_manager *glamo_dma_new(enum glamo_dma_mode t);
59 void glamo_dma_destroy(struct glamo_dma_manager *dma);
60 void glamo_dma_flush(struct glamo_dma_manager *dma);
61 void glamo_dma_wait(struct glamo_dma_manager *dma, enum glamo_dma_wait_type t);
62 void glamo_dma_dump(struct glamo_dma_manager *dma);
64 #define GLAMO_DMA_VARS \
65 GLAMO_REG_TYPE *__p; int __count, __total
67 #define GLAMO_DMA_BEGIN(dma, n) \
68 do { \
69 if (dma->llen + n * GLAMO_REG_WIDTH > dma->lsize) \
70 glamo_dma_flush(dma); \
71 __p = (GLAMO_REG_TYPE *) (dma->lbuf + dma->llen); \
72 __count = 0; __total = n; \
73 } while (0)
75 #define GLAMO_DMA_OUT(dma, v1, v2) \
76 do { \
77 __p[__count++] = v1; \
78 __p[__count++] = v2; \
79 } while (0)
81 #define GLAMO_DMA_END(dma) \
82 do { \
83 if (__count != __total) \
84 { \
85 fprintf(stderr, "count != total (%d != %d) " \
86 "at %s:%d\n", __count, __total, \
87 __FILE__, __LINE__); \
88 exit(1); \
89 } \
90 dma->llen += __count * GLAMO_REG_WIDTH; \
91 } while (0)
93 #define GLAMO_DMA_BURST(dma, reg, n) \
94 GLAMO_DMA_OUT(dma, (1 << 15) | reg, n)
96 #endif /* _DMA_H */