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