1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * module/mite.h
4  * Hardware driver for NI Mite PCI interface chip
5  *
6  * COMEDI - Linux Control and Measurement Device Interface
7  * Copyright (C) 1999 David A. Schleef <ds@schleef.org>
8  */
9 
10 #ifndef _MITE_H_
11 #define _MITE_H_
12 
13 #include <linux/spinlock.h>
14 
15 #define MAX_MITE_DMA_CHANNELS 8
16 
17 struct comedi_device;
18 struct comedi_subdevice;
19 struct device;
20 struct pci_dev;
21 
22 struct mite_dma_desc {
23 	__le32 count;
24 	__le32 addr;
25 	__le32 next;
26 	u32 dar;
27 };
28 
29 struct mite_ring {
30 	struct device *hw_dev;
31 	unsigned int n_links;
32 	struct mite_dma_desc *descs;
33 	dma_addr_t dma_addr;
34 };
35 
36 struct mite_channel {
37 	struct mite *mite;
38 	unsigned int channel;
39 	int dir;
40 	int done;
41 	struct mite_ring *ring;
42 };
43 
44 struct mite {
45 	struct pci_dev *pcidev;
46 	void __iomem *mmio;
47 	struct mite_channel channels[MAX_MITE_DMA_CHANNELS];
48 	int num_channels;
49 	unsigned int fifo_size;
50 	/* protects mite_channel from being released by the driver */
51 	spinlock_t lock;
52 };
53 
54 u32 mite_bytes_in_transit(struct mite_channel *mite_chan);
55 
56 void mite_sync_dma(struct mite_channel *mite_chan, struct comedi_subdevice *s);
57 void mite_ack_linkc(struct mite_channel *mite_chan, struct comedi_subdevice *s,
58 		    bool sync);
59 int mite_done(struct mite_channel *mite_chan);
60 
61 void mite_dma_arm(struct mite_channel *mite_chan);
62 void mite_dma_disarm(struct mite_channel *mite_chan);
63 
64 void mite_prep_dma(struct mite_channel *mite_chan,
65 		   unsigned int num_device_bits, unsigned int num_memory_bits);
66 
67 struct mite_channel *mite_request_channel_in_range(struct mite *mite,
68 						   struct mite_ring *ring,
69 						   unsigned int min_channel,
70 						   unsigned int max_channel);
71 struct mite_channel *mite_request_channel(struct mite *mite,
72 					  struct mite_ring *ring);
73 void mite_release_channel(struct mite_channel *mite_chan);
74 
75 int mite_init_ring_descriptors(struct mite_ring *ring,
76 			       struct comedi_subdevice *s, unsigned int nbytes);
77 int mite_buf_change(struct mite_ring *ring, struct comedi_subdevice *s);
78 
79 struct mite_ring *mite_alloc_ring(struct mite *mite);
80 void mite_free_ring(struct mite_ring *ring);
81 
82 struct mite *mite_attach(struct comedi_device *dev, bool use_win1);
83 void mite_detach(struct mite *mite);
84 
85 /*
86  * Mite registers (used outside of the mite driver)
87  */
88 #define MITE_IODWBSR		0xc0	/* IO Device Window Base Size */
89 #define MITE_IODWBSR_1		0xc4	/* IO Device Window1 Base Size */
90 #define WENAB			BIT(7)	/* window enable */
91 #define MITE_IODWCR_1		0xf4
92 
93 #endif
94