]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/addi-data/hwdrv_apci1032.c
e4e85f472f0f9955dea861162776911f1c574dbc
[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 /*
50 +----------------------------------------------------------------------------+
51 |                               Included files                               |
52 +----------------------------------------------------------------------------+
53 */
54 #include "hwdrv_apci1032.h"
55 #include <linux/delay.h>
56
57 static unsigned int ui_InterruptStatus;
58
59 /*
60 +----------------------------------------------------------------------------+
61 | Function   Name   : int i_APCI1032_ConfigDigitalInput                      |
62 |                         (struct comedi_device *dev,struct comedi_subdevice *s,               |
63 |                      struct comedi_insn *insn,unsigned int *data)                     |
64 +----------------------------------------------------------------------------+
65 | Task              : Configures the digital input Subdevice                 |
66 +----------------------------------------------------------------------------+
67 | Input Parameters  : struct comedi_device *dev : Driver handle                     |
68 |                     unsigned int *data         : Data Pointer contains         |
69 |                                          configuration parameters as below |
70 |                                                                            |
71 |                         data[0]            : 1 Enable  Digital Input Interrupt |
72 |                                                                  0 Disable Digital Input Interrupt |
73 |                         data[1]            : 0 ADDIDATA Interrupt OR LOGIC     |
74 |                                                                : 1 ADDIDATA Interrupt AND LOGIC    |
75 |                         data[2]                        : Interrupt mask for the mode 1         |
76 |                         data[3]                        : Interrupt mask for the mode 2         |
77 |                                                                                                                                        |
78 +----------------------------------------------------------------------------+
79 | Output Parameters :   --                                                                                                       |
80 +----------------------------------------------------------------------------+
81 | Return Value      : TRUE  : No error occur                                 |
82 |                           : FALSE : Error occur. Return the error          |
83 |                                                                                |
84 +----------------------------------------------------------------------------+
85 */
86
87 static int i_APCI1032_ConfigDigitalInput(struct comedi_device *dev,
88                                          struct comedi_subdevice *s,
89                                          struct comedi_insn *insn,
90                                          unsigned int *data)
91 {
92         struct addi_private *devpriv = dev->private;
93         unsigned int ui_TmpValue;
94         unsigned int ul_Command1 = 0;
95         unsigned int ul_Command2 = 0;
96
97         devpriv->tsk_Current = current;
98
99   /*******************************/
100         /* Set the digital input logic */
101   /*******************************/
102         if (data[0] == ADDIDATA_ENABLE) {
103                 ul_Command1 = ul_Command1 | data[2];
104                 ul_Command2 = ul_Command2 | data[3];
105                 outl(ul_Command1,
106                         devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);
107                 outl(ul_Command2,
108                         devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
109                 if (data[1] == ADDIDATA_OR) {
110                         outl(0x4, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
111                         ui_TmpValue =
112                                 inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
113                 }               /* if (data[1] == ADDIDATA_OR) */
114                 else
115                         outl(0x6, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
116                                 /* else if(data[1] == ADDIDATA_OR) */
117         }                       /*  if( data[0] == ADDIDATA_ENABLE) */
118         else {
119                 ul_Command1 = ul_Command1 & 0xFFFF0000;
120                 ul_Command2 = ul_Command2 & 0xFFFF0000;
121                 outl(ul_Command1,
122                         devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);
123                 outl(ul_Command2,
124                         devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
125                 outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
126         }                       /* else if  ( data[0] == ADDIDATA_ENABLE) */
127
128         return insn->n;
129 }
130
131 /*
132 +----------------------------------------------------------------------------+
133 | Function   Name   : int i_APCI1032_Read1DigitalInput                       |
134 |                         (struct comedi_device *dev,struct comedi_subdevice *s,               |
135 |                      struct comedi_insn *insn,unsigned int *data)                     |
136 +----------------------------------------------------------------------------+
137 | Task              : Return the status of the digital input                 |
138 +----------------------------------------------------------------------------+
139 | Input Parameters  : struct comedi_device *dev      : Driver handle                |
140 |                             unsigned int ui_Channel : Channel number to read       |
141 |                     unsigned int *data          : Data Pointer to read status  |
142 +----------------------------------------------------------------------------+
143 | Output Parameters :   --                                                                                                       |
144 +----------------------------------------------------------------------------+
145 | Return Value      : TRUE  : No error occur                                 |
146 |                           : FALSE : Error occur. Return the error          |
147 |                                                                                |
148 +----------------------------------------------------------------------------+
149 */
150 static int i_APCI1032_Read1DigitalInput(struct comedi_device *dev,
151                                         struct comedi_subdevice *s,
152                                         struct comedi_insn *insn,
153                                         unsigned int *data)
154 {
155         struct addi_private *devpriv = dev->private;
156         unsigned int ui_TmpValue = 0;
157         unsigned int ui_Channel;
158         ui_Channel = CR_CHAN(insn->chanspec);
159
160         if (ui_Channel <= 31) {
161                 ui_TmpValue = (unsigned int) inl(devpriv->iobase + APCI1032_DIGITAL_IP);
162 /*
163 * since only 1 channel reqd to bring it to last bit it is rotated 8
164 * +(chan - 1) times then ANDed with 1 for last bit.
165 */
166                 *data = (ui_TmpValue >> ui_Channel) & 0x1;
167         }                       /* if(ui_Channel >= 0 && ui_Channel <=31) */
168         else {
169                 /* comedi_error(dev," \n chan spec wrong\n"); */
170                 return -EINVAL; /*  "sorry channel spec wrong " */
171         }                       /* else if(ui_Channel >= 0 && ui_Channel <=31) */
172         return insn->n;
173 }
174
175 /*
176 +----------------------------------------------------------------------------+
177 | Function   Name   : int i_APCI1032_ReadMoreDigitalInput                    |
178 |                         (struct comedi_device *dev,struct comedi_subdevice *s,               |
179 |                     struct comedi_insn *insn,unsigned int *data)                      |
180 +----------------------------------------------------------------------------+
181 | Task              : Return the status of the Requested digital inputs      |
182 +----------------------------------------------------------------------------+
183 | Input Parameters  : struct comedi_device *dev      : Driver handle                |
184 |                     unsigned int ui_NoOfChannels    : No Of Channels To be Read    |
185 |                      unsigned int *data             : Data Pointer to read status  |
186 +----------------------------------------------------------------------------+
187 | Output Parameters :   --                                                                                                       |
188 +----------------------------------------------------------------------------+
189 | Return Value      : TRUE  : No error occur                                 |
190 |                           : FALSE : Error occur. Return the error          |
191 |                                                                                |
192 +----------------------------------------------------------------------------+
193 */
194
195 static int i_APCI1032_ReadMoreDigitalInput(struct comedi_device *dev,
196                                            struct comedi_subdevice *s,
197                                            struct comedi_insn *insn,
198                                            unsigned int *data)
199 {
200         struct addi_private *devpriv = dev->private;
201         unsigned int ui_PortValue = data[0];
202         unsigned int ui_Mask = 0;
203         unsigned int ui_NoOfChannels;
204
205         ui_NoOfChannels = CR_CHAN(insn->chanspec);
206         if (data[1] == 0) {
207                 *data = (unsigned int) inl(devpriv->iobase + APCI1032_DIGITAL_IP);
208                 switch (ui_NoOfChannels) {
209                 case 2:
210                         ui_Mask = 3;
211                         *data = (*data >> (2 * ui_PortValue)) & ui_Mask;
212                         break;
213                 case 4:
214                         ui_Mask = 15;
215                         *data = (*data >> (4 * ui_PortValue)) & ui_Mask;
216                         break;
217                 case 8:
218                         ui_Mask = 255;
219                         *data = (*data >> (8 * ui_PortValue)) & ui_Mask;
220                         break;
221                 case 16:
222                         ui_Mask = 65535;
223                         *data = (*data >> (16 * ui_PortValue)) & ui_Mask;
224                         break;
225                 case 31:
226                         break;
227                 default:
228                         /* comedi_error(dev," \nchan spec wrong\n"); */
229                         return -EINVAL; /*  "sorry channel spec wrong " */
230                         break;
231                 }               /* switch(ui_NoOfChannels) */
232         }                       /* if(data[1]==0) */
233         else {
234                 if (data[1] == 1)
235                         *data = ui_InterruptStatus;
236                                 /* if(data[1]==1) */
237         }                       /* else if(data[1]==0) */
238         return insn->n;
239 }
240
241 /*
242 +----------------------------------------------------------------------------+
243 | Function   Name   : static void v_APCI1032_Interrupt                                       |
244 |                                         (int irq , void *d)      |
245 +----------------------------------------------------------------------------+
246 | Task              : Interrupt handler for the interruptible digital inputs |
247 +----------------------------------------------------------------------------+
248 | Input Parameters  : int irq                 : irq number                   |
249 |                     void *d                 : void pointer                 |
250 +----------------------------------------------------------------------------+
251 | Output Parameters :   --                                                   |
252 +----------------------------------------------------------------------------+
253 | Return Value      : TRUE  : No error occur                                 |
254 |                           : FALSE : Error occur. Return the error          |
255 |                                                                            |
256 +----------------------------------------------------------------------------+
257 */
258 static void v_APCI1032_Interrupt(int irq, void *d)
259 {
260         struct comedi_device *dev = d;
261         struct addi_private *devpriv = dev->private;
262         unsigned int ui_Temp;
263
264         /* disable the interrupt */
265         ui_Temp = inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
266         outl(ui_Temp & APCI1032_DIGITAL_IP_INTERRUPT_DISABLE,
267                 devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
268         ui_InterruptStatus =
269                 inl(devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_STATUS);
270         ui_InterruptStatus = ui_InterruptStatus & 0X0000FFFF;
271         send_sig(SIGIO, devpriv->tsk_Current, 0);       /*  send signal to the sample */
272         outl(ui_Temp, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);       /* enable the interrupt */
273         return;
274 }
275
276 /*
277 +----------------------------------------------------------------------------+
278 | Function   Name   : int i_APCI1032_Reset(struct comedi_device *dev)               |                                                       |
279 +----------------------------------------------------------------------------+
280 | Task              :resets all the registers                                |
281 +----------------------------------------------------------------------------+
282 | Input Parameters  : struct comedi_device *dev
283 +----------------------------------------------------------------------------+
284 | Output Parameters :   --                                                                                                       |
285 +----------------------------------------------------------------------------+
286 | Return Value      :                                                        |
287 |                                                                                |
288 +----------------------------------------------------------------------------+
289 */
290
291 static int i_APCI1032_Reset(struct comedi_device *dev)
292 {
293         struct addi_private *devpriv = dev->private;
294
295         outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);   /* disable the interrupts */
296         inl(devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_STATUS);    /* Reset the interrupt status register */
297         outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);       /* Disable the and/or interrupt */
298         outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
299         return 0;
300 }