4 Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data.com
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.
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.
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
20 You should also find the complete GPL in the COPYING file accompanying this source code.
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 +-----------------------------------------------------------------------+
40 +----------+-----------+------------------------------------------------+
41 | Date | Author | Description of updates |
42 +----------+-----------+------------------------------------------------+
46 +----------+-----------+------------------------------------------------+
50 +----------------------------------------------------------------------------+
52 +----------------------------------------------------------------------------+
54 #include "hwdrv_apci1032.h"
55 #include <linux/delay.h>
57 static unsigned int ui_InterruptStatus;
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 |
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 |
78 +----------------------------------------------------------------------------+
79 | Output Parameters : -- |
80 +----------------------------------------------------------------------------+
81 | Return Value : TRUE : No error occur |
82 | : FALSE : Error occur. Return the error |
84 +----------------------------------------------------------------------------+
87 static int i_APCI1032_ConfigDigitalInput(struct comedi_device *dev,
88 struct comedi_subdevice *s,
89 struct comedi_insn *insn,
92 struct addi_private *devpriv = dev->private;
93 unsigned int ui_TmpValue;
94 unsigned int ul_Command1 = 0;
95 unsigned int ul_Command2 = 0;
97 devpriv->tsk_Current = current;
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];
106 devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);
108 devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
109 if (data[1] == ADDIDATA_OR) {
110 outl(0x4, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
112 inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
113 } /* if (data[1] == ADDIDATA_OR) */
115 outl(0x6, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
116 /* else if(data[1] == ADDIDATA_OR) */
117 } /* if( data[0] == ADDIDATA_ENABLE) */
119 ul_Command1 = ul_Command1 & 0xFFFF0000;
120 ul_Command2 = ul_Command2 & 0xFFFF0000;
122 devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);
124 devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
125 outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
126 } /* else if ( data[0] == ADDIDATA_ENABLE) */
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 |
148 +----------------------------------------------------------------------------+
150 static int i_APCI1032_Read1DigitalInput(struct comedi_device *dev,
151 struct comedi_subdevice *s,
152 struct comedi_insn *insn,
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);
160 if (ui_Channel <= 31) {
161 ui_TmpValue = (unsigned int) inl(devpriv->iobase + APCI1032_DIGITAL_IP);
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.
166 *data = (ui_TmpValue >> ui_Channel) & 0x1;
167 } /* if(ui_Channel >= 0 && ui_Channel <=31) */
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) */
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 |
192 +----------------------------------------------------------------------------+
195 static int i_APCI1032_ReadMoreDigitalInput(struct comedi_device *dev,
196 struct comedi_subdevice *s,
197 struct comedi_insn *insn,
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;
205 ui_NoOfChannels = CR_CHAN(insn->chanspec);
207 *data = (unsigned int) inl(devpriv->iobase + APCI1032_DIGITAL_IP);
208 switch (ui_NoOfChannels) {
211 *data = (*data >> (2 * ui_PortValue)) & ui_Mask;
215 *data = (*data >> (4 * ui_PortValue)) & ui_Mask;
219 *data = (*data >> (8 * ui_PortValue)) & ui_Mask;
223 *data = (*data >> (16 * ui_PortValue)) & ui_Mask;
228 /* comedi_error(dev," \nchan spec wrong\n"); */
229 return -EINVAL; /* "sorry channel spec wrong " */
231 } /* switch(ui_NoOfChannels) */
232 } /* if(data[1]==0) */
235 *data = ui_InterruptStatus;
237 } /* else if(data[1]==0) */
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 |
256 +----------------------------------------------------------------------------+
258 static void v_APCI1032_Interrupt(int irq, void *d)
260 struct comedi_device *dev = d;
261 struct addi_private *devpriv = dev->private;
262 unsigned int ui_Temp;
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);
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 */
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 +----------------------------------------------------------------------------+
288 +----------------------------------------------------------------------------+
291 static int i_APCI1032_Reset(struct comedi_device *dev)
293 struct addi_private *devpriv = dev->private;
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);