21 #ifndef __ANALOGY_NI_MITE_H__
22 #define __ANALOGY_NI_MITE_H__
24 #include <linux/pci.h>
28 #define PCI_VENDOR_ID_NATINST 0x1093
29 #define PCI_MITE_SIZE 4096
30 #define PCI_DAQ_SIZE 4096
31 #define PCI_DAQ_SIZE_660X 8192
33 #define MAX_MITE_DMA_CHANNELS 8
35 #define TOP_OF_PAGE(x) ((x)|(~(PAGE_MASK)))
37 struct mite_dma_descriptor {
44 struct mite_dma_descriptor_ring {
45 struct pci_dev *pcidev;
47 struct mite_dma_descriptor *descriptors;
48 dma_addr_t descriptors_dma_addr;
52 struct mite_struct *mite;
56 struct mite_dma_descriptor_ring *ring;
60 struct list_head list;
65 struct mite_channel channels[MAX_MITE_DMA_CHANNELS];
66 u32 channel_allocated[MAX_MITE_DMA_CHANNELS];
68 struct pci_dev *pcidev;
69 resource_size_t mite_phys_addr;
71 resource_size_t daq_phys_addr;
76 struct mite_dma_descriptor_ring *mite_alloc_ring(
struct mite_struct *mite)
78 struct mite_dma_descriptor_ring *ring =
79 kmalloc(
sizeof(
struct mite_dma_descriptor_ring), GFP_DMA);
84 memset(ring, 0,
sizeof(
struct mite_dma_descriptor_ring));
86 ring->pcidev = mite->pcidev;
87 if (ring->pcidev == NULL) {
95 static inline void mite_free_ring(
struct mite_dma_descriptor_ring *ring)
98 if (ring->descriptors) {
102 sizeof(
struct mite_dma_descriptor),
103 ring->descriptors, ring->descriptors_dma_addr);
109 static inline unsigned int mite_irq(
struct mite_struct *mite)
111 return mite->pcidev->irq;
113 static inline unsigned int mite_device_id(
struct mite_struct *mite)
115 return mite->pcidev->device;
118 int a4l_mite_setup(
struct mite_struct *mite,
int use_iodwbsr_1);
119 void a4l_mite_unsetup(
struct mite_struct *mite);
120 void a4l_mite_list_devices(
void);
121 struct mite_struct * a4l_mite_find_device(
int bus,
122 int slot,
unsigned short device_id);
123 struct mite_channel *
124 a4l_mite_request_channel_in_range(
struct mite_struct *mite,
125 struct mite_dma_descriptor_ring *ring,
126 unsigned min_channel,
unsigned max_channel);
127 static inline struct mite_channel *mite_request_channel(
struct mite_struct
128 *mite,
struct mite_dma_descriptor_ring *ring)
130 return a4l_mite_request_channel_in_range(mite, ring, 0,
131 mite->num_channels - 1);
133 void a4l_mite_release_channel(
struct mite_channel *mite_chan);
135 void a4l_mite_dma_arm(
struct mite_channel *mite_chan);
136 void a4l_mite_dma_disarm(
struct mite_channel *mite_chan);
137 int a4l_mite_sync_input_dma(
struct mite_channel *mite_chan,
a4l_subd_t *subd);
138 int a4l_mite_sync_output_dma(
struct mite_channel *mite_chan,
a4l_subd_t *subd);
139 u32 a4l_mite_bytes_written_to_memory_lb(
struct mite_channel *mite_chan);
140 u32 a4l_mite_bytes_written_to_memory_ub(
struct mite_channel *mite_chan);
141 u32 a4l_mite_bytes_read_from_memory_lb(
struct mite_channel *mite_chan);
142 u32 a4l_mite_bytes_read_from_memory_ub(
struct mite_channel *mite_chan);
143 u32 a4l_mite_bytes_in_transit(
struct mite_channel *mite_chan);
144 u32 a4l_mite_get_status(
struct mite_channel *mite_chan);
145 int a4l_mite_done(
struct mite_channel *mite_chan);
146 void a4l_mite_prep_dma(
struct mite_channel *mite_chan,
147 unsigned int num_device_bits,
unsigned int num_memory_bits);
148 int a4l_mite_buf_change(
struct mite_dma_descriptor_ring *ring,
a4l_subd_t *subd);
150 #ifdef CONFIG_DEBUG_MITE
151 void mite_print_chsr(
unsigned int chsr);
152 void a4l_mite_dump_regs(
struct mite_channel *mite_chan);
155 static inline int CHAN_OFFSET(
int channel)
157 return 0x500 + 0x100 * channel;
160 enum mite_registers {
164 MITE_UNKNOWN_DMA_BURST_REG = 0x28,
166 MITE_IODWBSR_1 = 0xc4,
167 MITE_IODWCR_1 = 0xf4,
168 MITE_PCI_CONFIG_OFFSET = 0x300,
171 static inline int MITE_CHOR(
int channel)
173 return CHAN_OFFSET(channel) + 0x0;
175 static inline int MITE_CHCR(
int channel)
177 return CHAN_OFFSET(channel) + 0x4;
179 static inline int MITE_TCR(
int channel)
181 return CHAN_OFFSET(channel) + 0x8;
183 static inline int MITE_MCR(
int channel)
185 return CHAN_OFFSET(channel) + 0xc;
187 static inline int MITE_MAR(
int channel)
189 return CHAN_OFFSET(channel) + 0x10;
191 static inline int MITE_DCR(
int channel)
193 return CHAN_OFFSET(channel) + 0x14;
195 static inline int MITE_DAR(
int channel)
197 return CHAN_OFFSET(channel) + 0x18;
199 static inline int MITE_LKCR(
int channel)
201 return CHAN_OFFSET(channel) + 0x1c;
203 static inline int MITE_LKAR(
int channel)
205 return CHAN_OFFSET(channel) + 0x20;
207 static inline int MITE_LLKAR(
int channel)
209 return CHAN_OFFSET(channel) + 0x24;
211 static inline int MITE_BAR(
int channel)
213 return CHAN_OFFSET(channel) + 0x28;
215 static inline int MITE_BCR(
int channel)
217 return CHAN_OFFSET(channel) + 0x2c;
219 static inline int MITE_SAR(
int channel)
221 return CHAN_OFFSET(channel) + 0x30;
223 static inline int MITE_WSCR(
int channel)
225 return CHAN_OFFSET(channel) + 0x34;
227 static inline int MITE_WSER(
int channel)
229 return CHAN_OFFSET(channel) + 0x38;
231 static inline int MITE_CHSR(
int channel)
233 return CHAN_OFFSET(channel) + 0x3c;
235 static inline int MITE_FCR(
int channel)
237 return CHAN_OFFSET(channel) + 0x40;
240 enum MITE_IODWBSR_bits {
244 static inline unsigned MITE_IODWBSR_1_WSIZE_bits(
unsigned size)
250 return (order - 1) & 0x1f;
253 enum MITE_UNKNOWN_DMA_BURST_bits {
254 UNKNOWN_DMA_BURST_ENABLE_BITS = 0x600
257 static inline int mite_csigr_version(u32 csigr_bits)
259 return csigr_bits & 0xf;
261 static inline int mite_csigr_type(u32 csigr_bits)
263 return (csigr_bits >> 4) & 0xf;
265 static inline int mite_csigr_mmode(u32 csigr_bits)
267 return (csigr_bits >> 8) & 0x3;
269 static inline int mite_csigr_imode(u32 csigr_bits)
271 return (csigr_bits >> 12) & 0x3;
273 static inline int mite_csigr_dmac(u32 csigr_bits)
275 return (csigr_bits >> 16) & 0xf;
277 static inline int mite_csigr_wpdep(u32 csigr_bits)
279 unsigned int wpdep_bits = (csigr_bits >> 20) & 0x7;
283 return 1 << (wpdep_bits - 1);
285 static inline int mite_csigr_wins(u32 csigr_bits)
287 return (csigr_bits >> 24) & 0x1f;
289 static inline int mite_csigr_iowins(u32 csigr_bits)
291 return (csigr_bits >> 29) & 0x7;
299 DCR_NORMAL = (1 << 29),
303 enum MITE_CHOR_bits {
304 CHOR_DMARESET = (1 << 31),
305 CHOR_SET_SEND_TC = (1 << 11),
306 CHOR_CLR_SEND_TC = (1 << 10),
307 CHOR_SET_LPAUSE = (1 << 9),
308 CHOR_CLR_LPAUSE = (1 << 8),
309 CHOR_CLRDONE = (1 << 7),
310 CHOR_CLRRB = (1 << 6),
311 CHOR_CLRLC = (1 << 5),
312 CHOR_FRESET = (1 << 4),
313 CHOR_ABORT = (1 << 3),
314 CHOR_STOP = (1 << 2),
315 CHOR_CONT = (1 << 1),
316 CHOR_START = (1 << 0),
317 CHOR_PON = (CHOR_CLR_SEND_TC | CHOR_CLR_LPAUSE),
320 enum MITE_CHCR_bits {
321 CHCR_SET_DMA_IE = (1 << 31),
322 CHCR_CLR_DMA_IE = (1 << 30),
323 CHCR_SET_LINKP_IE = (1 << 29),
324 CHCR_CLR_LINKP_IE = (1 << 28),
325 CHCR_SET_SAR_IE = (1 << 27),
326 CHCR_CLR_SAR_IE = (1 << 26),
327 CHCR_SET_DONE_IE = (1 << 25),
328 CHCR_CLR_DONE_IE = (1 << 24),
329 CHCR_SET_MRDY_IE = (1 << 23),
330 CHCR_CLR_MRDY_IE = (1 << 22),
331 CHCR_SET_DRDY_IE = (1 << 21),
332 CHCR_CLR_DRDY_IE = (1 << 20),
333 CHCR_SET_LC_IE = (1 << 19),
334 CHCR_CLR_LC_IE = (1 << 18),
335 CHCR_SET_CONT_RB_IE = (1 << 17),
336 CHCR_CLR_CONT_RB_IE = (1 << 16),
337 CHCR_FIFODIS = (1 << 15),
339 CHCR_BURSTEN = (1 << 14),
341 CHCR_BYTE_SWAP_DEVICE = (1 << 6),
342 CHCR_BYTE_SWAP_MEMORY = (1 << 4),
344 CHCR_DEV_TO_MEM = CHCR_DIR,
346 CHCR_NORMAL = (0 << 0),
347 CHCR_CONTINUE = (1 << 0),
348 CHCR_RINGBUFF = (2 << 0),
349 CHCR_LINKSHORT = (4 << 0),
350 CHCR_LINKLONG = (5 << 0),
352 (CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE | CHCR_CLR_SAR_IE |
353 CHCR_CLR_DONE_IE | CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE |
354 CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE),
357 enum ConfigRegister_bits {
358 CR_REQS_MASK = 0x7 << 16,
359 CR_ASEQDONT = 0x0 << 10,
360 CR_ASEQUP = 0x1 << 10,
361 CR_ASEQDOWN = 0x2 << 10,
362 CR_ASEQ_MASK = 0x3 << 10,
363 CR_PSIZE8 = (1 << 8),
364 CR_PSIZE16 = (2 << 8),
365 CR_PSIZE32 = (3 << 8),
366 CR_PORTCPU = (0 << 6),
367 CR_PORTIO = (1 << 6),
368 CR_PORTVXI = (2 << 6),
369 CR_PORTMXI = (3 << 6),
370 CR_AMDEVICE = (1 << 0),
372 static inline int CR_REQS(
int source)
374 return (source & 0x7) << 16;
376 static inline int CR_REQSDRQ(
unsigned drq_line)
380 return CR_REQS((drq_line & 0x3) | 0x4);
382 static inline int CR_RL(
unsigned int retry_limit)
386 while (retry_limit) {
391 __a4l_err(
"bug! retry_limit too large\n");
393 return (value & 0x7) << 21;
397 CHSR_INT = (1 << 31),
398 CHSR_LPAUSES = (1 << 29),
399 CHSR_SARS = (1 << 27),
400 CHSR_DONE = (1 << 25),
401 CHSR_MRDY = (1 << 23),
402 CHSR_DRDY = (1 << 21),
403 CHSR_LINKC = (1 << 19),
404 CHSR_CONTS_RB = (1 << 17),
405 CHSR_ERROR = (1 << 15),
406 CHSR_SABORT = (1 << 14),
407 CHSR_HABORT = (1 << 13),
408 CHSR_STOPS = (1 << 12),
409 CHSR_OPERR_mask = (3 << 10),
410 CHSR_OPERR_NOERROR = (0 << 10),
411 CHSR_OPERR_FIFOERROR = (1 << 10),
412 CHSR_OPERR_LINKERROR = (1 << 10),
413 CHSR_XFERR = (1 << 9),
415 CHSR_DRQ1 = (1 << 7),
416 CHSR_DRQ0 = (1 << 6),
417 CHSR_LxERR_mask = (3 << 4),
418 CHSR_LBERR = (1 << 4),
419 CHSR_LRERR = (2 << 4),
420 CHSR_LOERR = (3 << 4),
421 CHSR_MxERR_mask = (3 << 2),
422 CHSR_MBERR = (1 << 2),
423 CHSR_MRERR = (2 << 2),
424 CHSR_MOERR = (3 << 2),
425 CHSR_DxERR_mask = (3 << 0),
426 CHSR_DBERR = (1 << 0),
427 CHSR_DRERR = (2 << 0),
428 CHSR_DOERR = (3 << 0),
431 static inline void mite_dma_reset(
struct mite_channel *mite_chan)
433 writel(CHOR_DMARESET | CHOR_FRESET,
434 mite_chan->mite->mite_io_addr + MITE_CHOR(mite_chan->channel));
Analogy for Linux, driver facilities.
Structure describing the subdevice.
Definition: subdevice.h:180