GNU Linux-libre 4.9.309-gnu1
[releases.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_desc {
32         __le32 count;
33         __le32 addr;
34         __le32 next;
35         u32 dar;
36 };
37
38 struct mite_ring {
39         struct device *hw_dev;
40         unsigned int n_links;
41         struct mite_dma_desc *descs;
42         dma_addr_t dma_addr;
43 };
44
45 struct mite_channel {
46         struct mite *mite;
47         unsigned int channel;
48         int dir;
49         int done;
50         struct mite_ring *ring;
51 };
52
53 struct mite {
54         struct pci_dev *pcidev;
55         void __iomem *mmio;
56         struct mite_channel channels[MAX_MITE_DMA_CHANNELS];
57         int num_channels;
58         unsigned int fifo_size;
59         /* protects mite_channel from being released by the driver */
60         spinlock_t lock;
61 };
62
63 u32 mite_bytes_in_transit(struct mite_channel *);
64
65 void mite_sync_dma(struct mite_channel *, struct comedi_subdevice *);
66 void mite_ack_linkc(struct mite_channel *, struct comedi_subdevice *s,
67                     bool sync);
68 int mite_done(struct mite_channel *);
69
70 void mite_dma_arm(struct mite_channel *);
71 void mite_dma_disarm(struct mite_channel *);
72
73 void mite_prep_dma(struct mite_channel *,
74                    unsigned int num_device_bits, unsigned int num_memory_bits);
75
76 struct mite_channel *mite_request_channel_in_range(struct mite *,
77                                                    struct mite_ring *,
78                                                    unsigned int min_channel,
79                                                    unsigned int max_channel);
80 struct mite_channel *mite_request_channel(struct mite *, struct mite_ring *);
81 void mite_release_channel(struct mite_channel *);
82
83 int mite_init_ring_descriptors(struct mite_ring *, struct comedi_subdevice *,
84                                unsigned int nbytes);
85 int mite_buf_change(struct mite_ring *, struct comedi_subdevice *);
86
87 struct mite_ring *mite_alloc_ring(struct mite *);
88 void mite_free_ring(struct mite_ring *);
89
90 struct mite *mite_attach(struct comedi_device *, bool use_win1);
91 void mite_detach(struct mite *);
92
93 /*
94  * Mite registers (used outside of the mite driver)
95  */
96 #define MITE_IODWBSR            0xc0    /* IO Device Window Base Size */
97 #define MITE_IODWBSR_1          0xc4    /* IO Device Window1 Base Size */
98 #define WENAB                   BIT(7)  /* window enable */
99 #define MITE_IODWCR_1           0xf4
100
101 #endif