3 * Hardware driver for NI Mite PCI interface chip
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1999 David A. Schleef <ds@schleef.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
22 #include <linux/spinlock.h>
24 #define MAX_MITE_DMA_CHANNELS 8
27 struct comedi_subdevice;
31 struct mite_dma_descriptor {
38 struct mite_dma_descriptor_ring {
39 struct device *hw_dev;
41 struct mite_dma_descriptor *descriptors;
42 dma_addr_t descriptors_dma_addr;
46 struct mite_struct *mite;
50 struct mite_dma_descriptor_ring *ring;
54 struct pci_dev *pcidev;
55 void __iomem *mite_io_addr;
56 struct mite_channel channels[MAX_MITE_DMA_CHANNELS];
57 short channel_allocated[MAX_MITE_DMA_CHANNELS];
59 unsigned int fifo_size;
60 /* protects mite_channel from being released by the driver */
64 struct mite_struct *mite_alloc(struct pci_dev *pcidev);
66 int mite_setup2(struct comedi_device *, struct mite_struct *, bool use_win1);
68 static inline int mite_setup(struct comedi_device *dev,
69 struct mite_struct *mite)
71 return mite_setup2(dev, mite, false);
74 void mite_detach(struct mite_struct *mite);
75 struct mite_dma_descriptor_ring *mite_alloc_ring(struct mite_struct *mite);
76 void mite_free_ring(struct mite_dma_descriptor_ring *ring);
78 mite_request_channel_in_range(struct mite_struct *mite,
79 struct mite_dma_descriptor_ring *ring,
80 unsigned int min_channel,
81 unsigned int max_channel);
82 static inline struct mite_channel *
83 mite_request_channel(struct mite_struct *mite,
84 struct mite_dma_descriptor_ring *ring)
86 return mite_request_channel_in_range(mite, ring, 0,
87 mite->num_channels - 1);
90 void mite_release_channel(struct mite_channel *mite_chan);
92 void mite_dma_arm(struct mite_channel *mite_chan);
93 void mite_dma_disarm(struct mite_channel *mite_chan);
94 void mite_sync_dma(struct mite_channel *mite_chan, struct comedi_subdevice *s);
95 u32 mite_bytes_in_transit(struct mite_channel *mite_chan);
96 void mite_ack_linkc(struct mite_channel *, struct comedi_subdevice *,
98 int mite_done(struct mite_channel *mite_chan);
100 void mite_prep_dma(struct mite_channel *mite_chan,
101 unsigned int num_device_bits, unsigned int num_memory_bits);
102 int mite_buf_change(struct mite_dma_descriptor_ring *ring,
103 struct comedi_subdevice *s);
104 int mite_init_ring_descriptors(struct mite_dma_descriptor_ring *ring,
105 struct comedi_subdevice *s,
106 unsigned int nbytes);
109 * Mite registers (used outside of the mite driver)
111 #define MITE_IODWBSR 0xc0 /* IO Device Window Base Size */
112 #define MITE_IODWBSR_1 0xc4 /* IO Device Window1 Base Size */
113 #define WENAB BIT(7) /* window enable */
114 #define MITE_IODWCR_1 0xf4