]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/addi-data/hwdrv_apci1032.c
staging: comedi: hwrdv_apci1032: absorb private header
[karo-tx-linux.git] / drivers / staging / comedi / drivers / addi-data / hwdrv_apci1032.c
1 /**
2 @verbatim
3
4 Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module.
5
6         ADDI-DATA GmbH
7         Dieselstrasse 3
8         D-77833 Ottersweier
9         Tel: +19(0)7223/9493-0
10         Fax: +49(0)7223/9493-92
11         http://www.addi-data.com
12         info@addi-data.com
13
14 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 You should also find the complete GPL in the COPYING file accompanying this source code.
21
22 @endverbatim
23 */
24 /*
25
26   +-----------------------------------------------------------------------+
27   | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
28   +-----------------------------------------------------------------------+
29   | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |
30   | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |
31   +-------------------------------+---------------------------------------+
32   | Project     : APCI-1032       | Compiler   : GCC                      |
33   | Module name : hwdrv_apci1032.c| Version    : 2.96                     |
34   +-------------------------------+---------------------------------------+
35   | Project manager: Eric Stolz   | Date       :  02/12/2002              |
36   +-------------------------------+---------------------------------------+
37   | Description :   Hardware Layer Access For APCI-1032                   |
38   +-----------------------------------------------------------------------+
39   |                             UPDATES                                   |
40   +----------+-----------+------------------------------------------------+
41   |   Date   |   Author  |          Description of updates                |
42   +----------+-----------+------------------------------------------------+
43   |          |           |                                                |
44   |          |           |                                                |
45   |          |           |                                                |
46   +----------+-----------+------------------------------------------------+
47 */
48
49 /*********      Definitions for APCI-1032 card  *****/
50
51 #define APCI1032_ADDRESS_RANGE                  20
52 /* DIGITAL INPUT DEFINE */
53
54 #define APCI1032_DIGITAL_IP                     0
55 #define APCI1032_DIGITAL_IP_INTERRUPT_MODE1     4
56 #define APCI1032_DIGITAL_IP_INTERRUPT_MODE2     8
57 #define APCI1032_DIGITAL_IP_IRQ                 16
58
59 /* Digital Input IRQ Function Selection */
60 #define ADDIDATA_OR                             0
61 #define ADDIDATA_AND                            1
62
63 /* Digital Input Interrupt Status */
64 #define APCI1032_DIGITAL_IP_INTERRUPT_STATUS    12
65
66 /* Digital Input Interrupt Enable Disable. */
67 #define APCI1032_DIGITAL_IP_INTERRUPT_ENABLE    0x4
68 #define APCI1032_DIGITAL_IP_INTERRUPT_DISABLE   0xfffffffb
69
70 /* ADDIDATA Enable Disable */
71 #define ADDIDATA_ENABLE                         1
72 #define ADDIDATA_DISABLE                        0
73
74 static unsigned int ui_InterruptStatus;
75
76 /*
77 +----------------------------------------------------------------------------+
78 | Function   Name   : int i_APCI1032_ConfigDigitalInput                      |
79 |                         (struct comedi_device *dev,struct comedi_subdevice *s,               |
80 |                      struct comedi_insn *insn,unsigned int *data)                     |
81 +----------------------------------------------------------------------------+
82 | Task              : Configures the digital input Subdevice                 |
83 +----------------------------------------------------------------------------+
84 | Input Parameters  : struct comedi_device *dev : Driver handle                     |
85 |                     unsigned int *data         : Data Pointer contains         |
86 |                                          configuration parameters as below |
87 |                                                                            |
88 |                         data[0]            : 1 Enable  Digital Input Interrupt |
89 |                                                                  0 Disable Digital Input Interrupt |
90 |                         data[1]            : 0 ADDIDATA Interrupt OR LOGIC     |
91 |                                                                : 1 ADDIDATA Interrupt AND LOGIC    |
92 |                         data[2]                        : Interrupt mask for the mode 1         |
93 |                         data[3]                        : Interrupt mask for the mode 2         |
94 |                                                                                                                                        |
95 +----------------------------------------------------------------------------+
96 | Output Parameters :   --                                                                                                       |
97 +----------------------------------------------------------------------------+
98 | Return Value      : TRUE  : No error occur                                 |
99 |                           : FALSE : Error occur. Return the error          |
100 |                                                                                |
101 +----------------------------------------------------------------------------+
102 */
103
104 static int i_APCI1032_ConfigDigitalInput(struct comedi_device *dev,
105                                          struct comedi_subdevice *s,
106                                          struct comedi_insn *insn,
107                                          unsigned int *data)
108 {
109         struct addi_private *devpriv = dev->private;
110         unsigned int ui_TmpValue;
111         unsigned int ul_Command1 = 0;
112         unsigned int ul_Command2 = 0;
113
114         devpriv->tsk_Current = current;
115
116   /*******************************/
117         /* Set the digital input logic */
118   /*******************************/
119         if (data[0] == ADDIDATA_ENABLE) {
120                 ul_Command1 = ul_Command1 | data[2];
121                 ul_Command2 = ul_Command2 | data[3];
122                 outl(ul_Command1,
123                         devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);
124                 outl(ul_Command2,
125                         devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
126                 if (data[1] == ADDIDATA_OR) {
127                         outl(0x4, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
128                         ui_TmpValue =
129                                 inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
130                 }               /* if (data[1] == ADDIDATA_OR) */
131                 else
132                         outl(0x6, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
133                                 /* else if(data[1] == ADDIDATA_OR) */
134         }                       /*  if( data[0] == ADDIDATA_ENABLE) */
135         else {
136                 ul_Command1 = ul_Command1 & 0xFFFF0000;
137                 ul_Command2 = ul_Command2 & 0xFFFF0000;
138                 outl(ul_Command1,
139                         devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);
140                 outl(ul_Command2,
141                         devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
142                 outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
143         }                       /* else if  ( data[0] == ADDIDATA_ENABLE) */
144
145         return insn->n;
146 }
147
148 /*
149 +----------------------------------------------------------------------------+
150 | Function   Name   : int i_APCI1032_Read1DigitalInput                       |
151 |                         (struct comedi_device *dev,struct comedi_subdevice *s,               |
152 |                      struct comedi_insn *insn,unsigned int *data)                     |
153 +----------------------------------------------------------------------------+
154 | Task              : Return the status of the digital input                 |
155 +----------------------------------------------------------------------------+
156 | Input Parameters  : struct comedi_device *dev      : Driver handle                |
157 |                             unsigned int ui_Channel : Channel number to read       |
158 |                     unsigned int *data          : Data Pointer to read status  |
159 +----------------------------------------------------------------------------+
160 | Output Parameters :   --                                                                                                       |
161 +----------------------------------------------------------------------------+
162 | Return Value      : TRUE  : No error occur                                 |
163 |                           : FALSE : Error occur. Return the error          |
164 |                                                                                |
165 +----------------------------------------------------------------------------+
166 */
167 static int i_APCI1032_Read1DigitalInput(struct comedi_device *dev,
168                                         struct comedi_subdevice *s,
169                                         struct comedi_insn *insn,
170                                         unsigned int *data)
171 {
172         struct addi_private *devpriv = dev->private;
173         unsigned int ui_TmpValue = 0;
174         unsigned int ui_Channel;
175         ui_Channel = CR_CHAN(insn->chanspec);
176
177         if (ui_Channel <= 31) {
178                 ui_TmpValue = (unsigned int) inl(devpriv->iobase + APCI1032_DIGITAL_IP);
179 /*
180 * since only 1 channel reqd to bring it to last bit it is rotated 8
181 * +(chan - 1) times then ANDed with 1 for last bit.
182 */
183                 *data = (ui_TmpValue >> ui_Channel) & 0x1;
184         }                       /* if(ui_Channel >= 0 && ui_Channel <=31) */
185         else {
186                 /* comedi_error(dev," \n chan spec wrong\n"); */
187                 return -EINVAL; /*  "sorry channel spec wrong " */
188         }                       /* else if(ui_Channel >= 0 && ui_Channel <=31) */
189         return insn->n;
190 }
191
192 /*
193 +----------------------------------------------------------------------------+
194 | Function   Name   : int i_APCI1032_ReadMoreDigitalInput                    |
195 |                         (struct comedi_device *dev,struct comedi_subdevice *s,               |
196 |                     struct comedi_insn *insn,unsigned int *data)                      |
197 +----------------------------------------------------------------------------+
198 | Task              : Return the status of the Requested digital inputs      |
199 +----------------------------------------------------------------------------+
200 | Input Parameters  : struct comedi_device *dev      : Driver handle                |
201 |                     unsigned int ui_NoOfChannels    : No Of Channels To be Read    |
202 |                      unsigned int *data             : Data Pointer to read status  |
203 +----------------------------------------------------------------------------+
204 | Output Parameters :   --                                                                                                       |
205 +----------------------------------------------------------------------------+
206 | Return Value      : TRUE  : No error occur                                 |
207 |                           : FALSE : Error occur. Return the error          |
208 |                                                                                |
209 +----------------------------------------------------------------------------+
210 */
211
212 static int i_APCI1032_ReadMoreDigitalInput(struct comedi_device *dev,
213                                            struct comedi_subdevice *s,
214                                            struct comedi_insn *insn,
215                                            unsigned int *data)
216 {
217         struct addi_private *devpriv = dev->private;
218         unsigned int ui_PortValue = data[0];
219         unsigned int ui_Mask = 0;
220         unsigned int ui_NoOfChannels;
221
222         ui_NoOfChannels = CR_CHAN(insn->chanspec);
223         if (data[1] == 0) {
224                 *data = (unsigned int) inl(devpriv->iobase + APCI1032_DIGITAL_IP);
225                 switch (ui_NoOfChannels) {
226                 case 2:
227                         ui_Mask = 3;
228                         *data = (*data >> (2 * ui_PortValue)) & ui_Mask;
229                         break;
230                 case 4:
231                         ui_Mask = 15;
232                         *data = (*data >> (4 * ui_PortValue)) & ui_Mask;
233                         break;
234                 case 8:
235                         ui_Mask = 255;
236                         *data = (*data >> (8 * ui_PortValue)) & ui_Mask;
237                         break;
238                 case 16:
239                         ui_Mask = 65535;
240                         *data = (*data >> (16 * ui_PortValue)) & ui_Mask;
241                         break;
242                 case 31:
243                         break;
244                 default:
245                         /* comedi_error(dev," \nchan spec wrong\n"); */
246                         return -EINVAL; /*  "sorry channel spec wrong " */
247                         break;
248                 }               /* switch(ui_NoOfChannels) */
249         }                       /* if(data[1]==0) */
250         else {
251                 if (data[1] == 1)
252                         *data = ui_InterruptStatus;
253                                 /* if(data[1]==1) */
254         }                       /* else if(data[1]==0) */
255         return insn->n;
256 }
257
258 /*
259 +----------------------------------------------------------------------------+
260 | Function   Name   : static void v_APCI1032_Interrupt                                       |
261 |                                         (int irq , void *d)      |
262 +----------------------------------------------------------------------------+
263 | Task              : Interrupt handler for the interruptible digital inputs |
264 +----------------------------------------------------------------------------+
265 | Input Parameters  : int irq                 : irq number                   |
266 |                     void *d                 : void pointer                 |
267 +----------------------------------------------------------------------------+
268 | Output Parameters :   --                                                   |
269 +----------------------------------------------------------------------------+
270 | Return Value      : TRUE  : No error occur                                 |
271 |                           : FALSE : Error occur. Return the error          |
272 |                                                                            |
273 +----------------------------------------------------------------------------+
274 */
275 static void v_APCI1032_Interrupt(int irq, void *d)
276 {
277         struct comedi_device *dev = d;
278         struct addi_private *devpriv = dev->private;
279         unsigned int ui_Temp;
280
281         /* disable the interrupt */
282         ui_Temp = inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
283         outl(ui_Temp & APCI1032_DIGITAL_IP_INTERRUPT_DISABLE,
284                 devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
285         ui_InterruptStatus =
286                 inl(devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_STATUS);
287         ui_InterruptStatus = ui_InterruptStatus & 0X0000FFFF;
288         send_sig(SIGIO, devpriv->tsk_Current, 0);       /*  send signal to the sample */
289         outl(ui_Temp, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);       /* enable the interrupt */
290         return;
291 }
292
293 /*
294 +----------------------------------------------------------------------------+
295 | Function   Name   : int i_APCI1032_Reset(struct comedi_device *dev)               |                                                       |
296 +----------------------------------------------------------------------------+
297 | Task              :resets all the registers                                |
298 +----------------------------------------------------------------------------+
299 | Input Parameters  : struct comedi_device *dev
300 +----------------------------------------------------------------------------+
301 | Output Parameters :   --                                                                                                       |
302 +----------------------------------------------------------------------------+
303 | Return Value      :                                                        |
304 |                                                                                |
305 +----------------------------------------------------------------------------+
306 */
307
308 static int i_APCI1032_Reset(struct comedi_device *dev)
309 {
310         struct addi_private *devpriv = dev->private;
311
312         outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);   /* disable the interrupts */
313         inl(devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_STATUS);    /* Reset the interrupt status register */
314         outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);       /* Disable the and/or interrupt */
315         outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
316         return 0;
317 }