1f8959d858687b0c74845131a367634332edef8f
[cascardo/linux.git] / drivers / staging / comedi / drivers / mite.h
1 /*
2  * module/mite.h
3  * Hardware driver for NI Mite PCI interface chip
4  *
5  * COMEDI - Linux Control and Measurement Device Interface
6  * Copyright (C) 1999 David A. Schleef <ds@schleef.org>
7  *
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.
12  *
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.
17  */
18
19 #ifndef _MITE_H_
20 #define _MITE_H_
21
22 #include <linux/spinlock.h>
23
24 #define MAX_MITE_DMA_CHANNELS 8
25
26 struct comedi_device;
27 struct comedi_subdevice;
28 struct device;
29 struct pci_dev;
30
31 struct mite_dma_descriptor {
32         __le32 count;
33         __le32 addr;
34         __le32 next;
35         u32 dar;
36 };
37
38 struct mite_dma_descriptor_ring {
39         struct device *hw_dev;
40         unsigned int n_links;
41         struct mite_dma_descriptor *descriptors;
42         dma_addr_t descriptors_dma_addr;
43 };
44
45 struct mite_channel {
46         struct mite_struct *mite;
47         unsigned int channel;
48         int dir;
49         int done;
50         struct mite_dma_descriptor_ring *ring;
51 };
52
53 struct mite_struct {
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];
58         int num_channels;
59         unsigned int fifo_size;
60         /* protects mite_channel from being released by the driver */
61         spinlock_t lock;
62 };
63
64 struct mite_struct *mite_alloc(struct pci_dev *pcidev);
65
66 int mite_setup2(struct comedi_device *, struct mite_struct *, bool use_win1);
67
68 static inline int mite_setup(struct comedi_device *dev,
69                              struct mite_struct *mite)
70 {
71         return mite_setup2(dev, mite, false);
72 }
73
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);
77 struct mite_channel *
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)
85 {
86         return mite_request_channel_in_range(mite, ring, 0,
87                                              mite->num_channels - 1);
88 }
89
90 void mite_release_channel(struct mite_channel *mite_chan);
91
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 *,
97                     bool sync);
98 int mite_done(struct mite_channel *mite_chan);
99
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);
107
108 /*
109  * Mite registers (used outside of the mite driver)
110  */
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
115
116 #endif