1 /*
2 * COMEDI ISA DMA support functions
3 * Copyright (c) 2014 H Hartley Sweeten <hsweeten@visionengravers.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16 #ifndef _COMEDI_ISADMA_H
17 #define _COMEDI_ISADMA_H
18
19 /*
20 * These are used to avoid issues when <asm/dma.h> and the DMA_MODE_
21 * defines are not available.
22 */
23 #define COMEDI_ISADMA_READ 0
24 #define COMEDI_ISADMA_WRITE 1
25
26 /**
27 * struct comedi_isadma_desc - cookie for ISA DMA
28 * @virt_addr: virtual address of buffer
29 * @hw_addr: hardware (bus) address of buffer
30 * @chan: DMA channel
31 * @maxsize: allocated size of buffer (in bytes)
32 * @size: transfer size (in bytes)
33 * @mode: DMA_MODE_READ or DMA_MODE_WRITE
34 */
35 struct comedi_isadma_desc {
36 void *virt_addr;
37 dma_addr_t hw_addr;
38 unsigned int chan;
39 unsigned int maxsize;
40 unsigned int size;
41 char mode;
42 };
43
44 /**
45 * struct comedi_isadma - ISA DMA data
46 * @desc: cookie for each DMA buffer
47 * @n_desc: the number of cookies
48 * @cur_dma: the current cookie in use
49 * @chan: the first DMA channel requested
50 * @chan2: the second DMA channel requested
51 */
52 struct comedi_isadma {
53 struct comedi_isadma_desc *desc;
54 int n_desc;
55 int cur_dma;
56 unsigned int chan;
57 unsigned int chan2;
58 };
59
60 #if IS_ENABLED(CONFIG_ISA_DMA_API)
61
62 void comedi_isadma_program(struct comedi_isadma_desc *);
63 unsigned int comedi_isadma_disable(unsigned int dma_chan);
64 unsigned int comedi_isadma_disable_on_sample(unsigned int dma_chan,
65 unsigned int size);
66 unsigned int comedi_isadma_poll(struct comedi_isadma *);
67 void comedi_isadma_set_mode(struct comedi_isadma_desc *, char dma_dir);
68
69 struct comedi_isadma *comedi_isadma_alloc(struct comedi_device *,
70 int n_desc, unsigned int dma_chan1,
71 unsigned int dma_chan2,
72 unsigned int maxsize, char dma_dir);
73 void comedi_isadma_free(struct comedi_isadma *);
74
75 #else /* !IS_ENABLED(CONFIG_ISA_DMA_API) */
76
comedi_isadma_program(struct comedi_isadma_desc * desc)77 static inline void comedi_isadma_program(struct comedi_isadma_desc *desc)
78 {
79 }
80
comedi_isadma_disable(unsigned int dma_chan)81 static inline unsigned int comedi_isadma_disable(unsigned int dma_chan)
82 {
83 return 0;
84 }
85
86 static inline unsigned int
comedi_isadma_disable_on_sample(unsigned int dma_chan,unsigned int size)87 comedi_isadma_disable_on_sample(unsigned int dma_chan, unsigned int size)
88 {
89 return 0;
90 }
91
comedi_isadma_poll(struct comedi_isadma * dma)92 static inline unsigned int comedi_isadma_poll(struct comedi_isadma *dma)
93 {
94 return 0;
95 }
96
comedi_isadma_set_mode(struct comedi_isadma_desc * desc,char dma_dir)97 static inline void comedi_isadma_set_mode(struct comedi_isadma_desc *desc,
98 char dma_dir)
99 {
100 }
101
102 static inline struct comedi_isadma *
comedi_isadma_alloc(struct comedi_device * dev,int n_desc,unsigned int dma_chan1,unsigned int dma_chan2,unsigned int maxsize,char dma_dir)103 comedi_isadma_alloc(struct comedi_device *dev, int n_desc,
104 unsigned int dma_chan1, unsigned int dma_chan2,
105 unsigned int maxsize, char dma_dir)
106 {
107 return NULL;
108 }
109
comedi_isadma_free(struct comedi_isadma * dma)110 static inline void comedi_isadma_free(struct comedi_isadma *dma)
111 {
112 }
113
114 #endif /* !IS_ENABLED(CONFIG_ISA_DMA_API) */
115
116 #endif /* #ifndef _COMEDI_ISADMA_H */
117