workqueue: Calling destroy_work_on_stack() to pair with INIT_WORK_ONSTACK()
[linux-2.6-block.git] / drivers / staging / comedi / drivers / ni_tio.h
1 /*
2     drivers/ni_tio.h
3     Header file for NI general purpose counter support code (ni_tio.c)
4
5     COMEDI - Linux Control and Measurement Device Interface
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 */
17
18 #ifndef _COMEDI_NI_TIO_H
19 #define _COMEDI_NI_TIO_H
20
21 #include "../comedidev.h"
22
23 /* forward declarations */
24 struct mite_struct;
25 struct ni_gpct_device;
26
27 enum ni_gpct_register {
28         NITIO_G0_Autoincrement_Reg,
29         NITIO_G1_Autoincrement_Reg,
30         NITIO_G2_Autoincrement_Reg,
31         NITIO_G3_Autoincrement_Reg,
32         NITIO_G0_Command_Reg,
33         NITIO_G1_Command_Reg,
34         NITIO_G2_Command_Reg,
35         NITIO_G3_Command_Reg,
36         NITIO_G0_HW_Save_Reg,
37         NITIO_G1_HW_Save_Reg,
38         NITIO_G2_HW_Save_Reg,
39         NITIO_G3_HW_Save_Reg,
40         NITIO_G0_SW_Save_Reg,
41         NITIO_G1_SW_Save_Reg,
42         NITIO_G2_SW_Save_Reg,
43         NITIO_G3_SW_Save_Reg,
44         NITIO_G0_Mode_Reg,
45         NITIO_G1_Mode_Reg,
46         NITIO_G2_Mode_Reg,
47         NITIO_G3_Mode_Reg,
48         NITIO_G0_LoadA_Reg,
49         NITIO_G1_LoadA_Reg,
50         NITIO_G2_LoadA_Reg,
51         NITIO_G3_LoadA_Reg,
52         NITIO_G0_LoadB_Reg,
53         NITIO_G1_LoadB_Reg,
54         NITIO_G2_LoadB_Reg,
55         NITIO_G3_LoadB_Reg,
56         NITIO_G0_Input_Select_Reg,
57         NITIO_G1_Input_Select_Reg,
58         NITIO_G2_Input_Select_Reg,
59         NITIO_G3_Input_Select_Reg,
60         NITIO_G0_Counting_Mode_Reg,
61         NITIO_G1_Counting_Mode_Reg,
62         NITIO_G2_Counting_Mode_Reg,
63         NITIO_G3_Counting_Mode_Reg,
64         NITIO_G0_Second_Gate_Reg,
65         NITIO_G1_Second_Gate_Reg,
66         NITIO_G2_Second_Gate_Reg,
67         NITIO_G3_Second_Gate_Reg,
68         NITIO_G01_Status_Reg,
69         NITIO_G23_Status_Reg,
70         NITIO_G01_Joint_Reset_Reg,
71         NITIO_G23_Joint_Reset_Reg,
72         NITIO_G01_Joint_Status1_Reg,
73         NITIO_G23_Joint_Status1_Reg,
74         NITIO_G01_Joint_Status2_Reg,
75         NITIO_G23_Joint_Status2_Reg,
76         NITIO_G0_DMA_Config_Reg,
77         NITIO_G1_DMA_Config_Reg,
78         NITIO_G2_DMA_Config_Reg,
79         NITIO_G3_DMA_Config_Reg,
80         NITIO_G0_DMA_Status_Reg,
81         NITIO_G1_DMA_Status_Reg,
82         NITIO_G2_DMA_Status_Reg,
83         NITIO_G3_DMA_Status_Reg,
84         NITIO_G0_ABZ_Reg,
85         NITIO_G1_ABZ_Reg,
86         NITIO_G0_Interrupt_Acknowledge_Reg,
87         NITIO_G1_Interrupt_Acknowledge_Reg,
88         NITIO_G2_Interrupt_Acknowledge_Reg,
89         NITIO_G3_Interrupt_Acknowledge_Reg,
90         NITIO_G0_Status_Reg,
91         NITIO_G1_Status_Reg,
92         NITIO_G2_Status_Reg,
93         NITIO_G3_Status_Reg,
94         NITIO_G0_Interrupt_Enable_Reg,
95         NITIO_G1_Interrupt_Enable_Reg,
96         NITIO_G2_Interrupt_Enable_Reg,
97         NITIO_G3_Interrupt_Enable_Reg,
98         NITIO_Num_Registers,
99 };
100
101 enum ni_gpct_variant {
102         ni_gpct_variant_e_series,
103         ni_gpct_variant_m_series,
104         ni_gpct_variant_660x
105 };
106
107 struct ni_gpct {
108         struct ni_gpct_device *counter_dev;
109         unsigned counter_index;
110         unsigned chip_index;
111         uint64_t clock_period_ps;       /* clock period in picoseconds */
112         struct mite_channel *mite_chan;
113         spinlock_t lock;
114 };
115
116 struct ni_gpct_device {
117         struct comedi_device *dev;
118         void (*write_register) (struct ni_gpct *counter, unsigned bits,
119                                 enum ni_gpct_register reg);
120         unsigned (*read_register) (struct ni_gpct *counter,
121                                    enum ni_gpct_register reg);
122         enum ni_gpct_variant variant;
123         struct ni_gpct *counters;
124         unsigned num_counters;
125         unsigned regs[NITIO_Num_Registers];
126         spinlock_t regs_lock;
127 };
128
129 extern struct ni_gpct_device *ni_gpct_device_construct(struct comedi_device
130                                                        *dev,
131                                                        void (*write_register)
132                                                        (struct ni_gpct *
133                                                         counter, unsigned bits,
134                                                         enum ni_gpct_register
135                                                         reg),
136                                                        unsigned (*read_register)
137                                                        (struct ni_gpct *
138                                                         counter,
139                                                         enum ni_gpct_register
140                                                         reg),
141                                                        enum ni_gpct_variant
142                                                        variant,
143                                                        unsigned num_counters);
144 extern void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev);
145 extern void ni_tio_init_counter(struct ni_gpct *counter);
146 extern int ni_tio_rinsn(struct ni_gpct *counter,
147                         struct comedi_insn *insn, unsigned int *data);
148 extern int ni_tio_insn_config(struct ni_gpct *counter,
149                               struct comedi_insn *insn, unsigned int *data);
150 extern int ni_tio_winsn(struct ni_gpct *counter,
151                         struct comedi_insn *insn, unsigned int *data);
152 extern int ni_tio_cmd(struct ni_gpct *counter, struct comedi_async *async);
153 extern int ni_tio_cmdtest(struct ni_gpct *counter, struct comedi_cmd *cmd);
154 extern int ni_tio_cancel(struct ni_gpct *counter);
155 extern void ni_tio_handle_interrupt(struct ni_gpct *counter,
156                                     struct comedi_subdevice *s);
157 extern void ni_tio_set_mite_channel(struct ni_gpct *counter,
158                                     struct mite_channel *mite_chan);
159 extern void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter,
160                                            int *gate_error, int *tc_error,
161                                            int *perm_stale_data,
162                                            int *stale_data);
163
164 static inline struct ni_gpct *subdev_to_counter(struct comedi_subdevice *s)
165 {
166         return s->private;
167 }
168
169 #endif /* _COMEDI_NI_TIO_H */