Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
[sfrench/cifs-2.6.git] / drivers / staging / meilhaus / me4600_ao.h
1 /**
2  * @file me4600_ao.h
3  *
4  * @brief Meilhaus ME-4000 analog output subdevice class.
5  * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6  * @author Guenter Gebhardt
7  */
8
9 /*
10  * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
11  *
12  * This file is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26
27 #ifndef _ME4600_AO_H_
28 # define _ME4600_AO_H_
29
30 # include <linux/version.h>
31 # include "mesubdevice.h"
32 # include "mecirc_buf.h"
33 # include "meioctl.h"
34
35 # ifdef __KERNEL__
36
37 #  ifdef BOSCH
38 #   undef ME_SYNAPSE
39 #   ifndef _CBUFF_32b_t
40 #        define _CBUFF_32b_t
41 #   endif //_CBUFF_32b_t
42 #  endif //BOSCH
43
44 #  define ME4600_AO_MAX_SUBDEVICES              4
45 #  define ME4600_AO_FIFO_COUNT                  4096
46
47 #  define ME4600_AO_BASE_FREQUENCY              33000000LL
48
49 #  define ME4600_AO_MIN_ACQ_TICKS               0LL
50 #  define ME4600_AO_MAX_ACQ_TICKS               0LL
51
52 #  define ME4600_AO_MIN_CHAN_TICKS              66LL
53 #  define ME4600_AO_MAX_CHAN_TICKS              0xFFFFFFFFLL
54
55 #  define ME4600_AO_MIN_RANGE                   -10000000
56 #  define ME4600_AO_MAX_RANGE                   9999694
57
58 #  define ME4600_AO_MAX_DATA                    0xFFFF
59
60 #  ifdef ME_SYNAPSE
61 #   define ME4600_AO_CIRC_BUF_SIZE_ORDER                8       // 2^n PAGES =>> Maximum value of 1MB for Synapse
62 #  else
63 #   define ME4600_AO_CIRC_BUF_SIZE_ORDER                5       // 2^n PAGES =>> 128KB
64 #  endif
65 #  define ME4600_AO_CIRC_BUF_SIZE               PAGE_SIZE<<ME4600_AO_CIRC_BUF_SIZE_ORDER        // Buffer size in bytes.
66
67 #  ifdef _CBUFF_32b_t
68 #   define ME4600_AO_CIRC_BUF_COUNT     ((ME4600_AO_CIRC_BUF_SIZE) / sizeof(uint32_t))  // Size in values
69 #  else
70 #   define ME4600_AO_CIRC_BUF_COUNT     ((ME4600_AO_CIRC_BUF_SIZE) / sizeof(uint16_t))  // Size in values
71 #  endif
72
73 #  define ME4600_AO_CONTINOUS                                   0x0
74 #  define ME4600_AO_WRAP_MODE                                   0x1
75 #  define ME4600_AO_HW_MODE                                             0x2
76
77 #  define ME4600_AO_HW_WRAP_MODE                                (ME4600_AO_WRAP_MODE | ME4600_AO_HW_MODE)
78 #  define ME4600_AO_SW_WRAP_MODE                                ME4600_AO_WRAP_MODE
79
80 #  define ME4600_AO_INF_STOP_MODE                               0x0
81 #  define ME4600_AO_ACQ_STOP_MODE                               0x1
82 #  define ME4600_AO_SCAN_STOP_MODE                              0x2
83
84 #  ifdef BOSCH                  //SPECIAL BUILD FOR BOSCH
85
86 /* Bits for flags attribute. */
87 #   define ME4600_AO_FLAGS_BROKEN_PIPE                  0x1
88 #   define ME4600_AO_FLAGS_SW_WRAP_MODE_0               0x2
89 #   define ME4600_AO_FLAGS_SW_WRAP_MODE_1               0x4
90 #   define ME4600_AO_FLAGS_SW_WRAP_MODE_MASK    (ME4600_AO_FLAGS_SW_WRAP_MODE_0 | ME4600_AO_FLAGS_SW_WRAP_MODE_1)
91
92 #   define ME4600_AO_FLAGS_SW_WRAP_MODE_NONE    0x0
93 #   define ME4600_AO_FLAGS_SW_WRAP_MODE_INF             0x2
94 #   define ME4600_AO_FLAGS_SW_WRAP_MODE_FIN             0x4
95
96         /**
97         * @brief The ME-4000 analog output subdevice class.
98         */
99 typedef struct me4600_ao_subdevice {
100         /* Inheritance */
101         me_subdevice_t base;                            /**< The subdevice base class. */
102
103         /* Attributes */
104         spinlock_t subdevice_lock;                      /**< Spin lock to protect the subdevice from concurrent access. */
105         spinlock_t *preload_reg_lock;           /**< Spin lock to protect #preload_reg from concurrent access. */
106         uint32_t *preload_flags;
107
108         unsigned int irq;                                       /**< The interrupt request number assigned by the PCI BIOS. */
109         me_circ_buf_t circ_buf;                         /**< Circular buffer holding measurment data. */
110         wait_queue_head_t wait_queue;           /**< Wait queue to put on tasks waiting for data to arrive. */
111
112         int single_value;                                       /**< Mirror of the value written in single mode. */
113
114         int volatile flags;                                     /**< Flags used for storing SW wraparound setup and error signalling from ISR. */
115         unsigned int wrap_count;                        /**< The user defined wraparound cycle count. */
116         unsigned int wrap_remaining;            /**< The wraparound cycle down counter used by a running conversion. */
117         unsigned int ao_idx;                            /**< The index of this analog output on this device. */
118         int fifo;                                                       /**< If set this device has a FIFO. */
119
120         int bosch_fw;                                           /**< If set the bosch firmware is in PROM. */
121
122         /* Registers */
123         uint32_t ctrl_reg;
124         uint32_t status_reg;
125         uint32_t fifo_reg;
126         uint32_t single_reg;
127         uint32_t timer_reg;
128         uint32_t irq_status_reg;
129         uint32_t preload_reg;
130         uint32_t reg_base;
131 } me4600_ao_subdevice_t;
132
133         /**
134         * @brief The constructor to generate a ME-4000 analog output subdevice instance for BOSCH project.
135         *
136         * @param reg_base The register base address of the device as returned by the PCI BIOS.
137         * @param ctrl_reg_lock Pointer to spin lock protecting the control register from concurrent access.
138         * @param preload_flags Pointer to spin lock protecting the hold&trigger register from concurrent access.
139         * @param ao_idx Subdevice number.
140         * @param fifo Flag set if subdevice has hardware FIFO.
141         * @param irq IRQ number.
142         *
143         * @return Pointer to new instance on success.\n
144         * NULL on error.
145         */
146 me4600_ao_subdevice_t *me4600_ao_constructor(uint32_t reg_base,
147                                              spinlock_t * preload_reg_lock,
148                                              uint32_t * preload_flags,
149                                              int ao_idx, int fifo, int irq);
150
151 #  else //~BOSCH
152
153 //ME4600_AO_FLAGS_BROKEN_PIPE is OBSOLETE => Now problems are reported in status.
154
155 typedef enum ME4600_AO_STATUS {
156         ao_status_none = 0,
157         ao_status_single_configured,
158         ao_status_single_run_wait,
159         ao_status_single_run,
160         ao_status_single_end_wait,
161         ao_status_single_end,
162         ao_status_stream_configured,
163         ao_status_stream_run_wait,
164         ao_status_stream_run,
165         ao_status_stream_end_wait,
166         ao_status_stream_end,
167         ao_status_stream_fifo_error,
168         ao_status_stream_buffer_error,
169         ao_status_stream_error,
170         ao_status_last
171 } ME4600_AO_STATUS;
172
173 typedef struct me4600_ao_timeout {
174         unsigned long start_time;
175         unsigned long delay;
176 } me4600_ao_timeout_t;
177
178         /**
179         * @brief The ME-4600 analog output subdevice class.
180         */
181 typedef struct me4600_ao_subdevice {
182         /* Inheritance */
183         me_subdevice_t base;                                            /**< The subdevice base class. */
184         unsigned int ao_idx;                                            /**< The index of this analog output on this device. */
185
186         /* Attributes */
187         spinlock_t subdevice_lock;                                      /**< Spin lock to protect the subdevice from concurrent access. */
188         spinlock_t *preload_reg_lock;                           /**< Spin lock to protect preload_reg from concurrent access. */
189
190         uint32_t *preload_flags;
191
192         /* Hardware feautres */
193         unsigned int irq;                                                       /**< The interrupt request number assigned by the PCI BIOS. */
194         int fifo;                                                                       /**< If set this device has a FIFO. */
195         int bitpattern;                                                         /**< If set this device use bitpattern. */
196
197         int single_value;                                                       /**< Mirror of the output value in single mode. */
198         int single_value_in_fifo;                                       /**< Mirror of the value written in single mode. */
199         uint32_t ctrl_trg;                                                      /**< Mirror of the trigger settings. */
200
201         volatile int mode;                                                      /**< Flags used for storing SW wraparound setup*/
202         int stop_mode;                                                          /**< The user defined stop condition flag. */
203         unsigned int start_mode;
204         unsigned int stop_count;                                        /**< The user defined dates presentation end count. */
205         unsigned int stop_data_count;                           /**< The stop presentation count. */
206         unsigned int data_count;                                        /**< The real presentation count. */
207         unsigned int preloaded_count;                           /**< The next data addres in buffer. <= for wraparound mode. */
208         int hardware_stop_delay;                                        /**< The time that stop can take. This is only to not show hardware bug to user. */
209
210         volatile enum ME4600_AO_STATUS status;          /**< The current stream status flag. */
211         me4600_ao_timeout_t timeout;                            /**< The timeout for start in blocking and non-blocking mode. */
212
213                                                                                 /* Registers *//**< All registers are 32 bits long. */
214         unsigned long ctrl_reg;
215         unsigned long status_reg;
216         unsigned long fifo_reg;
217         unsigned long single_reg;
218         unsigned long timer_reg;
219         unsigned long irq_status_reg;
220         unsigned long preload_reg;
221         unsigned long reg_base;
222
223         /* Software buffer */
224         me_circ_buf_t circ_buf;                                         /**< Circular buffer holding measurment data. 32 bit long */
225         wait_queue_head_t wait_queue;                           /**< Wait queue to put on tasks waiting for data to arrive. */
226
227         struct workqueue_struct *me4600_workqueue;
228         struct delayed_work ao_control_task;
229
230         volatile int ao_control_task_flag;                      /**< Flag controling reexecuting of control task */
231
232 } me4600_ao_subdevice_t;
233
234         /**
235         * @brief The constructor to generate a ME-4600 analog output subdevice instance.
236         *
237         * @param reg_base The register base address of the device as returned by the PCI BIOS.
238         * @param ctrl_reg_lock Pointer to spin lock protecting the control register from concurrent access.
239         * @param preload_flags Pointer to spin lock protecting the hold&trigger register from concurrent access.
240         * @param ao_idx Subdevice number.
241         * @param fifo Flag set if subdevice has hardware FIFO.
242         * @param irq IRQ number.
243         * @param me4600_wq Queue for asynchronous task (1 queue for all subdevice on 1 board).
244         *
245         * @return Pointer to new instance on success.\n
246         * NULL on error.
247         */
248 me4600_ao_subdevice_t *me4600_ao_constructor(uint32_t reg_base,
249                                              spinlock_t * preload_reg_lock,
250                                              uint32_t * preload_flags,
251                                              int ao_idx,
252                                              int fifo,
253                                              int irq,
254                                              struct workqueue_struct
255                                              *me4600_wq);
256
257 #  endif //BOSCH
258 # endif //__KERNEL__
259 #endif // ~_ME4600_AO_H_