staging: comedi: addi-data: remove devpriv macro
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / comedi / drivers / addi-data / hwdrv_apci1564.c
CommitLineData
c995fe94
ADG
1/**
2@verbatim
3
4Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
5
356cdbcb
BP
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
25417922 11 http://www.addi-data.com
356cdbcb 12 info@addi-data.com
c995fe94
ADG
13
14This 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
16This 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
18You 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
39cfb97b 20You should also find the complete GPL in the COPYING file accompanying this source code.
c995fe94
ADG
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-1564 | Compiler : GCC |
33 | Module name : hwdrv_apci1564.c| Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: Eric Stolz | Date : 02/12/2002 |
36 +-------------------------------+---------------------------------------+
6cd5a9a3 37 | Description : Hardware Layer Access For APCI-1564 |
c995fe94
ADG
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
55#include <linux/delay.h>
56#include "hwdrv_apci1564.h"
57
b58d9b17 58/* Global variables */
0b437fc4
GKH
59static unsigned int ui_InterruptStatus_1564 = 0;
60static unsigned int ui_InterruptData, ui_Type;
c995fe94
ADG
61
62/*
63+----------------------------------------------------------------------------+
64| Function Name : int i_APCI1564_ConfigDigitalInput |
34c43922 65| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 66| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
67+----------------------------------------------------------------------------+
68| Task : Configures the digital input Subdevice |
69+----------------------------------------------------------------------------+
71b5f4f1 70| Input Parameters : struct comedi_device *dev : Driver handle |
790c5541 71| unsigned int *data : Data Pointer contains |
c995fe94
ADG
72| configuration parameters as below |
73| |
74| data[0] : 1 Enable Digital Input Interrupt |
75| 0 Disable Digital Input Interrupt |
76| data[1] : 0 ADDIDATA Interrupt OR LOGIC |
77| : 1 ADDIDATA Interrupt AND LOGIC |
78| data[2] : Interrupt mask for the mode 1 |
79| data[3] : Interrupt mask for the mode 2 |
80| |
81+----------------------------------------------------------------------------+
82| Output Parameters : -- |
83+----------------------------------------------------------------------------+
84| Return Value : TRUE : No error occur |
85| : FALSE : Error occur. Return the error |
86| |
87+----------------------------------------------------------------------------+
88*/
da91b269
BP
89int i_APCI1564_ConfigDigitalInput(struct comedi_device *dev, struct comedi_subdevice *s,
90 struct comedi_insn *insn, unsigned int *data)
c995fe94 91{
843690b7
HS
92 struct addi_private *devpriv = dev->private;
93
c995fe94
ADG
94 devpriv->tsk_Current = current;
95 /*******************************/
96 /* Set the digital input logic */
97 /*******************************/
98 if (data[0] == ADDIDATA_ENABLE) {
99 data[2] = data[2] << 4;
100 data[3] = data[3] << 4;
101 outl(data[2],
102 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
103 APCI1564_DIGITAL_IP_INTERRUPT_MODE1);
104 outl(data[3],
105 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
106 APCI1564_DIGITAL_IP_INTERRUPT_MODE2);
107 if (data[1] == ADDIDATA_OR) {
108 outl(0x4,
109 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
110 APCI1564_DIGITAL_IP_IRQ);
b58d9b17 111 } /* if (data[1] == ADDIDATA_OR) */
c995fe94
ADG
112 else {
113 outl(0x6,
114 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
115 APCI1564_DIGITAL_IP_IRQ);
b58d9b17
BP
116 } /* else if (data[1] == ADDIDATA_OR) */
117 } /* if (data[0] == ADDIDATA_ENABLE) */
c995fe94
ADG
118 else {
119 outl(0x0,
120 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
121 APCI1564_DIGITAL_IP_INTERRUPT_MODE1);
122 outl(0x0,
123 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
124 APCI1564_DIGITAL_IP_INTERRUPT_MODE2);
125 outl(0x0,
126 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
127 APCI1564_DIGITAL_IP_IRQ);
b58d9b17 128 } /* else if (data[0] == ADDIDATA_ENABLE) */
c995fe94
ADG
129
130 return insn->n;
131}
132
133/*
134+----------------------------------------------------------------------------+
135| Function Name : int i_APCI1564_Read1DigitalInput |
34c43922 136| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 137| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
138+----------------------------------------------------------------------------+
139| Task : Return the status of the digital input |
140+----------------------------------------------------------------------------+
71b5f4f1 141| Input Parameters : struct comedi_device *dev : Driver handle |
117102b0 142| unsigned int ui_Channel : Channel number to read |
790c5541 143| unsigned int *data : Data Pointer to read status |
c995fe94
ADG
144+----------------------------------------------------------------------------+
145| Output Parameters : -- |
146+----------------------------------------------------------------------------+
147| Return Value : TRUE : No error occur |
148| : FALSE : Error occur. Return the error |
149| |
150+----------------------------------------------------------------------------+
151*/
da91b269
BP
152int i_APCI1564_Read1DigitalInput(struct comedi_device *dev, struct comedi_subdevice *s,
153 struct comedi_insn *insn, unsigned int *data)
c995fe94 154{
843690b7 155 struct addi_private *devpriv = dev->private;
117102b0
BP
156 unsigned int ui_TmpValue = 0;
157 unsigned int ui_Channel;
c995fe94
ADG
158
159 ui_Channel = CR_CHAN(insn->chanspec);
dc8af068 160 if (ui_Channel <= 31) {
c995fe94 161 ui_TmpValue =
117102b0 162 (unsigned int) inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP);
b58d9b17
BP
163/*
164* since only 1 channel reqd to bring it to last bit it is rotated 8
165* +(chan - 1) times then ANDed with 1 for last bit.
166*/
c995fe94 167 *data = (ui_TmpValue >> ui_Channel) & 0x1;
b58d9b17 168 } /* if (ui_Channel >= 0 && ui_Channel <=31) */
c995fe94
ADG
169 else {
170 comedi_error(dev, "Not a valid channel number !!! \n");
b58d9b17
BP
171 return -EINVAL; /* "sorry channel spec wrong " */
172 } /* else if (ui_Channel >= 0 && ui_Channel <=31) */
c995fe94
ADG
173 return insn->n;
174}
175
176/*
177+----------------------------------------------------------------------------+
178| Function Name : int i_APCI1564_ReadMoreDigitalInput |
34c43922 179| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 180| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
181+----------------------------------------------------------------------------+
182| Task : Return the status of the Requested digital inputs |
183+----------------------------------------------------------------------------+
71b5f4f1 184| Input Parameters : struct comedi_device *dev : Driver handle |
117102b0
BP
185| unsigned int ui_NoOfChannels : No Of Channels To be Read |
186| unsigned int *data : Data Pointer to read status |
c995fe94
ADG
187+----------------------------------------------------------------------------+
188| Output Parameters : -- |
189+----------------------------------------------------------------------------+
190| Return Value : TRUE : No error occur |
191| : FALSE : Error occur. Return the error |
192| |
193+----------------------------------------------------------------------------+
194*/
da91b269
BP
195int i_APCI1564_ReadMoreDigitalInput(struct comedi_device *dev, struct comedi_subdevice *s,
196 struct comedi_insn *insn, unsigned int *data)
c995fe94 197{
843690b7 198 struct addi_private *devpriv = dev->private;
117102b0
BP
199 unsigned int ui_PortValue = data[0];
200 unsigned int ui_Mask = 0;
201 unsigned int ui_NoOfChannels;
c995fe94
ADG
202
203 ui_NoOfChannels = CR_CHAN(insn->chanspec);
204 if (data[1] == 0) {
117102b0 205 *data = (unsigned int) inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP);
c995fe94
ADG
206 switch (ui_NoOfChannels) {
207 case 2:
208 ui_Mask = 3;
209 *data = (*data >> (2 * ui_PortValue)) & ui_Mask;
210 break;
211 case 4:
212 ui_Mask = 15;
213 *data = (*data >> (4 * ui_PortValue)) & ui_Mask;
214 break;
215 case 8:
216 ui_Mask = 255;
217 *data = (*data >> (8 * ui_PortValue)) & ui_Mask;
218 break;
219 case 16:
220 ui_Mask = 65535;
221 *data = (*data >> (16 * ui_PortValue)) & ui_Mask;
222 break;
223 case 31:
224 break;
225 default:
226 comedi_error(dev, "Not a valid Channel number !!!\n");
b58d9b17 227 return -EINVAL; /* "sorry channel spec wrong " */
c995fe94 228 break;
b58d9b17
BP
229 } /* switch (ui_NoOfChannels) */
230 } /* if (data[1]==0) */
c995fe94
ADG
231 else {
232 if (data[1] == 1) {
233 *data = ui_InterruptStatus_1564;
b58d9b17
BP
234 } /* if (data[1]==1) */
235 } /* else if (data[1]==0) */
c995fe94
ADG
236 return insn->n;
237}
238
239/*
240+----------------------------------------------------------------------------+
241| Function Name : int i_APCI1564_ConfigDigitalOutput |
34c43922 242| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 243| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
244+----------------------------------------------------------------------------+
245| Task : Configures The Digital Output Subdevice. |
246+----------------------------------------------------------------------------+
71b5f4f1 247| Input Parameters : struct comedi_device *dev : Driver handle |
117102b0 248| unsigned int *data : Data Pointer contains |
c995fe94
ADG
249| configuration parameters as below |
250| |
251| data[1] : 1 Enable VCC Interrupt |
252| 0 Disable VCC Interrupt |
253| data[2] : 1 Enable CC Interrupt |
254| 0 Disable CC Interrupt |
255| |
256+----------------------------------------------------------------------------+
257| Output Parameters : -- |
258+----------------------------------------------------------------------------+
259| Return Value : TRUE : No error occur |
260| : FALSE : Error occur. Return the error |
261| |
262+----------------------------------------------------------------------------+
263*/
da91b269
BP
264int i_APCI1564_ConfigDigitalOutput(struct comedi_device *dev, struct comedi_subdevice *s,
265 struct comedi_insn *insn, unsigned int *data)
c995fe94 266{
843690b7 267 struct addi_private *devpriv = dev->private;
82a6e2e7 268 unsigned int ul_Command = 0;
c995fe94
ADG
269
270 if ((data[0] != 0) && (data[0] != 1)) {
271 comedi_error(dev,
272 "Not a valid Data !!! ,Data should be 1 or 0\n");
273 return -EINVAL;
b58d9b17 274 } /* if ((data[0]!=0) && (data[0]!=1)) */
c995fe94
ADG
275 if (data[0]) {
276 devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE;
b58d9b17 277 } /* if (data[0]) */
c995fe94
ADG
278 else {
279 devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;
b58d9b17 280 } /* else if (data[0]) */
c995fe94
ADG
281 if (data[1] == ADDIDATA_ENABLE) {
282 ul_Command = ul_Command | 0x1;
b58d9b17 283 } /* if (data[1] == ADDIDATA_ENABLE) */
c995fe94
ADG
284 else {
285 ul_Command = ul_Command & 0xFFFFFFFE;
b58d9b17 286 } /* else if (data[1] == ADDIDATA_ENABLE) */
c995fe94
ADG
287 if (data[2] == ADDIDATA_ENABLE) {
288 ul_Command = ul_Command | 0x2;
b58d9b17 289 } /* if (data[2] == ADDIDATA_ENABLE) */
c995fe94
ADG
290 else {
291 ul_Command = ul_Command & 0xFFFFFFFD;
b58d9b17 292 } /* else if (data[2] == ADDIDATA_ENABLE) */
c995fe94
ADG
293 outl(ul_Command,
294 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
295 APCI1564_DIGITAL_OP_INTERRUPT);
296 ui_InterruptData =
297 inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
298 APCI1564_DIGITAL_OP_INTERRUPT);
299 devpriv->tsk_Current = current;
300 return insn->n;
301}
302
303/*
304+----------------------------------------------------------------------------+
305| Function Name : int i_APCI1564_WriteDigitalOutput |
34c43922 306| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 307| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
308+----------------------------------------------------------------------------+
309| Task : Writes port value To the selected port |
310+----------------------------------------------------------------------------+
71b5f4f1 311| Input Parameters : struct comedi_device *dev : Driver handle |
117102b0
BP
312| unsigned int ui_NoOfChannels : No Of Channels To Write |
313| unsigned int *data : Data Pointer to read status |
c995fe94
ADG
314+----------------------------------------------------------------------------+
315| Output Parameters : -- |
316+----------------------------------------------------------------------------+
317| Return Value : TRUE : No error occur |
318| : FALSE : Error occur. Return the error |
319| |
320+----------------------------------------------------------------------------+
321*/
da91b269
BP
322int i_APCI1564_WriteDigitalOutput(struct comedi_device *dev, struct comedi_subdevice *s,
323 struct comedi_insn *insn, unsigned int *data)
c995fe94 324{
843690b7 325 struct addi_private *devpriv = dev->private;
117102b0
BP
326 unsigned int ui_Temp, ui_Temp1;
327 unsigned int ui_NoOfChannel;
c995fe94
ADG
328
329 ui_NoOfChannel = CR_CHAN(insn->chanspec);
330 if (devpriv->b_OutputMemoryStatus) {
331 ui_Temp =
332 inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
333 APCI1564_DIGITAL_OP_RW);
b58d9b17 334 } /* if (devpriv->b_OutputMemoryStatus ) */
c995fe94
ADG
335 else {
336 ui_Temp = 0;
b58d9b17 337 } /* else if (devpriv->b_OutputMemoryStatus ) */
c995fe94
ADG
338 if (data[3] == 0) {
339 if (data[1] == 0) {
340 data[0] = (data[0] << ui_NoOfChannel) | ui_Temp;
341 outl(data[0],
342 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
343 APCI1564_DIGITAL_OP_RW);
b58d9b17 344 } /* if (data[1]==0) */
c995fe94
ADG
345 else {
346 if (data[1] == 1) {
347 switch (ui_NoOfChannel) {
348 case 2:
349 data[0] =
350 (data[0] << (2 *
351 data[2])) | ui_Temp;
352 break;
353 case 4:
354 data[0] =
355 (data[0] << (4 *
356 data[2])) | ui_Temp;
357 break;
358 case 8:
359 data[0] =
360 (data[0] << (8 *
361 data[2])) | ui_Temp;
362 break;
363 case 16:
364 data[0] =
365 (data[0] << (16 *
366 data[2])) | ui_Temp;
367 break;
368 case 31:
369 data[0] = data[0] | ui_Temp;
370 break;
371 default:
372 comedi_error(dev, " chan spec wrong");
b58d9b17
BP
373 return -EINVAL; /* "sorry channel spec wrong " */
374 } /* switch (ui_NoOfChannels) */
c995fe94
ADG
375 outl(data[0],
376 devpriv->i_IobaseAmcc +
377 APCI1564_DIGITAL_OP +
378 APCI1564_DIGITAL_OP_RW);
b58d9b17 379 } /* if (data[1]==1) */
c995fe94
ADG
380 else {
381 printk("\nSpecified channel not supported\n");
b58d9b17
BP
382 } /* else if (data[1]==1) */
383 } /* else if (data[1]==0) */
384 } /* if(data[3]==0) */
c995fe94
ADG
385 else {
386 if (data[3] == 1) {
387 if (data[1] == 0) {
388 data[0] = ~data[0] & 0x1;
389 ui_Temp1 = 1;
390 ui_Temp1 = ui_Temp1 << ui_NoOfChannel;
391 ui_Temp = ui_Temp | ui_Temp1;
392 data[0] =
393 (data[0] << ui_NoOfChannel) ^
394 0xffffffff;
395 data[0] = data[0] & ui_Temp;
396 outl(data[0],
397 devpriv->i_IobaseAmcc +
398 APCI1564_DIGITAL_OP +
399 APCI1564_DIGITAL_OP_RW);
b58d9b17 400 } /* if (data[1]==0) */
c995fe94
ADG
401 else {
402 if (data[1] == 1) {
403 switch (ui_NoOfChannel) {
404 case 2:
405 data[0] = ~data[0] & 0x3;
406 ui_Temp1 = 3;
407 ui_Temp1 =
408 ui_Temp1 << 2 * data[2];
409 ui_Temp = ui_Temp | ui_Temp1;
410 data[0] =
411 ((data[0] << (2 *
412 data
413 [2])) ^
414 0xffffffff) & ui_Temp;
415 break;
416 case 4:
417 data[0] = ~data[0] & 0xf;
418 ui_Temp1 = 15;
419 ui_Temp1 =
420 ui_Temp1 << 4 * data[2];
421 ui_Temp = ui_Temp | ui_Temp1;
422 data[0] =
423 ((data[0] << (4 *
424 data
425 [2])) ^
426 0xffffffff) & ui_Temp;
427 break;
428 case 8:
429 data[0] = ~data[0] & 0xff;
430 ui_Temp1 = 255;
431 ui_Temp1 =
432 ui_Temp1 << 8 * data[2];
433 ui_Temp = ui_Temp | ui_Temp1;
434 data[0] =
435 ((data[0] << (8 *
436 data
437 [2])) ^
438 0xffffffff) & ui_Temp;
439 break;
440 case 16:
441 data[0] = ~data[0] & 0xffff;
442 ui_Temp1 = 65535;
443 ui_Temp1 =
444 ui_Temp1 << 16 *
445 data[2];
446 ui_Temp = ui_Temp | ui_Temp1;
447 data[0] =
448 ((data[0] << (16 *
449 data
450 [2])) ^
451 0xffffffff) & ui_Temp;
452 break;
453 case 31:
454 break;
455 default:
456 comedi_error(dev,
457 " chan spec wrong");
b58d9b17
BP
458 return -EINVAL; /* "sorry channel spec wrong " */
459 } /* switch(ui_NoOfChannels) */
c995fe94
ADG
460 outl(data[0],
461 devpriv->i_IobaseAmcc +
462 APCI1564_DIGITAL_OP +
463 APCI1564_DIGITAL_OP_RW);
b58d9b17 464 } /* if (data[1]==1) */
c995fe94
ADG
465 else {
466 printk("\nSpecified channel not supported\n");
b58d9b17
BP
467 } /* else if (data[1]==1) */
468 } /* else if (data[1]==0) */
469 } /* if (data[3]==1); */
c995fe94
ADG
470 else {
471 printk("\nSpecified functionality does not exist\n");
472 return -EINVAL;
b58d9b17
BP
473 } /* else if (data[3]==1) */
474 } /* else if (data[3]==0) */
c995fe94
ADG
475 return insn->n;
476}
477
478/*
479+----------------------------------------------------------------------------+
480| Function Name : int i_APCI1564_ReadDigitalOutput |
34c43922 481| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 482| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
483+----------------------------------------------------------------------------+
484| Task : Read value of the selected channel or port |
485+----------------------------------------------------------------------------+
71b5f4f1 486| Input Parameters : struct comedi_device *dev : Driver handle |
117102b0
BP
487| unsigned int ui_NoOfChannels : No Of Channels To read |
488| unsigned int *data : Data Pointer to read status |
c995fe94
ADG
489+----------------------------------------------------------------------------+
490| Output Parameters : -- |
491+----------------------------------------------------------------------------+
492| Return Value : TRUE : No error occur |
493| : FALSE : Error occur. Return the error |
494| |
495+----------------------------------------------------------------------------+
496*/
da91b269
BP
497int i_APCI1564_ReadDigitalOutput(struct comedi_device *dev, struct comedi_subdevice *s,
498 struct comedi_insn *insn, unsigned int *data)
c995fe94 499{
843690b7 500 struct addi_private *devpriv = dev->private;
117102b0
BP
501 unsigned int ui_Temp;
502 unsigned int ui_NoOfChannel;
c995fe94
ADG
503
504 ui_NoOfChannel = CR_CHAN(insn->chanspec);
505 ui_Temp = data[0];
506 *data = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
507 APCI1564_DIGITAL_OP_RW);
508 if (ui_Temp == 0) {
509 *data = (*data >> ui_NoOfChannel) & 0x1;
b58d9b17 510 } /* if (ui_Temp==0) */
c995fe94
ADG
511 else {
512 if (ui_Temp == 1) {
513 switch (ui_NoOfChannel) {
514 case 2:
515 *data = (*data >> (2 * data[1])) & 3;
516 break;
517
518 case 4:
519 *data = (*data >> (4 * data[1])) & 15;
520 break;
521
522 case 8:
523 *data = (*data >> (8 * data[1])) & 255;
524 break;
525
526 case 16:
527 *data = (*data >> (16 * data[1])) & 65535;
528 break;
529
530 case 31:
531 break;
532
533 default:
534 comedi_error(dev, " chan spec wrong");
b58d9b17 535 return -EINVAL; /* "sorry channel spec wrong " */
c995fe94 536 break;
b58d9b17
BP
537 } /* switch(ui_NoOfChannels) */
538 } /* if (ui_Temp==1) */
c995fe94
ADG
539 else {
540 printk("\nSpecified channel not supported \n");
b58d9b17
BP
541 } /* else if (ui_Temp==1) */
542 } /* else if (ui_Temp==0) */
c995fe94
ADG
543 return insn->n;
544}
545
546/*
547+----------------------------------------------------------------------------+
548| Function Name : int i_APCI1564_ConfigTimerCounterWatchdog |
34c43922 549| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 550| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
551+----------------------------------------------------------------------------+
552| Task : Configures The Timer , Counter or Watchdog |
553+----------------------------------------------------------------------------+
71b5f4f1 554| Input Parameters : struct comedi_device *dev : Driver handle |
117102b0 555| unsigned int *data : Data Pointer contains |
c995fe94
ADG
556| configuration parameters as below |
557| |
558| data[0] : 0 Configure As Timer |
559| 1 Configure As Counter |
560| 2 Configure As Watchdog |
561| data[1] : 1 Enable Interrupt |
562| 0 Disable Interrupt |
563| data[2] : Time Unit |
564| data[3] : Reload Value |
565| data[4] : Timer Mode |
566| data[5] : Timer Counter Watchdog Number|
567 data[6] : Counter Direction
568+----------------------------------------------------------------------------+
569| Output Parameters : -- |
570+----------------------------------------------------------------------------+
571| Return Value : TRUE : No error occur |
572| : FALSE : Error occur. Return the error |
573| |
574+----------------------------------------------------------------------------+
575*/
da91b269
BP
576int i_APCI1564_ConfigTimerCounterWatchdog(struct comedi_device *dev,
577 struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data)
c995fe94 578{
843690b7 579 struct addi_private *devpriv = dev->private;
82a6e2e7 580 unsigned int ul_Command1 = 0;
843690b7 581
c995fe94
ADG
582 devpriv->tsk_Current = current;
583 if (data[0] == ADDIDATA_WATCHDOG) {
584 devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG;
585
b58d9b17 586 /* Disable the watchdog */
c995fe94
ADG
587 outl(0x0,
588 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG +
589 APCI1564_TCW_PROG);
b58d9b17 590 /* Loading the Reload value */
c995fe94
ADG
591 outl(data[3],
592 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG +
593 APCI1564_TCW_RELOAD_VALUE);
b58d9b17 594 } /* if (data[0]==ADDIDATA_WATCHDOG) */
c995fe94 595 else if (data[0] == ADDIDATA_TIMER) {
b58d9b17 596 /* First Stop The Timer */
c995fe94
ADG
597 ul_Command1 =
598 inl(devpriv->i_IobaseAmcc + APCI1564_TIMER +
599 APCI1564_TCW_PROG);
600 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
b58d9b17 601 outl(ul_Command1, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); /* Stop The Timer */
c995fe94
ADG
602
603 devpriv->b_TimerSelectMode = ADDIDATA_TIMER;
604 if (data[1] == 1) {
b58d9b17 605 outl(0x02, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
c995fe94
ADG
606 outl(0x0,
607 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
608 APCI1564_DIGITAL_IP_IRQ);
609 outl(0x0,
610 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
611 APCI1564_DIGITAL_OP_IRQ);
612 outl(0x0,
613 devpriv->i_IobaseAmcc +
614 APCI1564_DIGITAL_OP_WATCHDOG +
615 APCI1564_TCW_IRQ);
616 outl(0x0,
617 devpriv->iobase + APCI1564_COUNTER1 +
618 APCI1564_TCW_IRQ);
619 outl(0x0,
620 devpriv->iobase + APCI1564_COUNTER2 +
621 APCI1564_TCW_IRQ);
622 outl(0x0,
623 devpriv->iobase + APCI1564_COUNTER3 +
624 APCI1564_TCW_IRQ);
625 outl(0x0,
626 devpriv->iobase + APCI1564_COUNTER4 +
627 APCI1564_TCW_IRQ);
b58d9b17 628 } /* if (data[1]==1) */
c995fe94 629 else {
b58d9b17
BP
630 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); /* disable Timer interrupt */
631 } /* else if (data[1]==1) */
c995fe94 632
b58d9b17 633 /* Loading Timebase */
c995fe94
ADG
634
635 outl(data[2],
636 devpriv->i_IobaseAmcc + APCI1564_TIMER +
637 APCI1564_TCW_TIMEBASE);
638
b58d9b17 639 /* Loading the Reload value */
c995fe94
ADG
640 outl(data[3],
641 devpriv->i_IobaseAmcc + APCI1564_TIMER +
642 APCI1564_TCW_RELOAD_VALUE);
643
644 ul_Command1 =
645 inl(devpriv->i_IobaseAmcc + APCI1564_TIMER +
646 APCI1564_TCW_PROG);
647 ul_Command1 =
648 (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL;
b58d9b17
BP
649 outl(ul_Command1, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); /* mode 2 */
650 } /* else if (data[0]==ADDIDATA_TIMER) */
c995fe94
ADG
651 else if (data[0] == ADDIDATA_COUNTER) {
652 devpriv->b_TimerSelectMode = ADDIDATA_COUNTER;
653 devpriv->b_ModeSelectRegister = data[5];
654
b58d9b17 655 /* First Stop The Counter */
c995fe94
ADG
656 ul_Command1 =
657 inl(devpriv->iobase + ((data[5] - 1) * 0x20) +
658 APCI1564_TCW_PROG);
659 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
b58d9b17 660 outl(ul_Command1, devpriv->iobase + ((data[5] - 1) * 0x20) + APCI1564_TCW_PROG); /* Stop The Timer */
c995fe94
ADG
661
662 /************************/
663 /* Set the reload value */
664 /************************/
665 outl(data[3],
666 devpriv->iobase + ((data[5] - 1) * 0x20) +
667 APCI1564_TCW_RELOAD_VALUE);
668
669 /******************************/
670 /* Set the mode : */
671 /* - Disable the hardware */
672 /* - Disable the counter mode */
673 /* - Disable the warning */
674 /* - Disable the reset */
675 /* - Disable the timer mode */
676 /* - Enable the counter mode */
677 /******************************/
678 ul_Command1 =
679 (ul_Command1 & 0xFFFC19E2UL) | 0x80000UL |
82a6e2e7 680 (unsigned int) ((unsigned int) data[4] << 16UL);
c995fe94
ADG
681 outl(ul_Command1,
682 devpriv->iobase + ((data[5] - 1) * 0x20) +
683 APCI1564_TCW_PROG);
684
b58d9b17 685 /* Enable or Disable Interrupt */
c995fe94
ADG
686 ul_Command1 = (ul_Command1 & 0xFFFFF9FD) | (data[1] << 1);
687 outl(ul_Command1,
688 devpriv->iobase + ((data[5] - 1) * 0x20) +
689 APCI1564_TCW_PROG);
690
691 /*****************************/
692 /* Set the Up/Down selection */
693 /*****************************/
694 ul_Command1 = (ul_Command1 & 0xFFFBF9FFUL) | (data[6] << 18);
695 outl(ul_Command1,
696 devpriv->iobase + ((data[5] - 1) * 0x20) +
697 APCI1564_TCW_PROG);
b58d9b17 698 } /* else if (data[0]==ADDIDATA_COUNTER) */
c995fe94
ADG
699 else {
700 printk(" Invalid subdevice.");
b58d9b17 701 } /* else if (data[0]==ADDIDATA_WATCHDOG) */
c995fe94
ADG
702
703 return insn->n;
704}
705
706/*
707+----------------------------------------------------------------------------+
708| Function Name : int i_APCI1564_StartStopWriteTimerCounterWatchdog |
34c43922 709| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 710| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
711+----------------------------------------------------------------------------+
712| Task : Start / Stop The Selected Timer , Counter or Watchdog |
713+----------------------------------------------------------------------------+
71b5f4f1 714| Input Parameters : struct comedi_device *dev : Driver handle |
117102b0 715| unsigned int *data : Data Pointer contains |
c995fe94
ADG
716| configuration parameters as below |
717| |
718| data[0] : 0 Timer |
719| 1 Counter |
720| 2 Watchdog | | data[1] : 1 Start |
721| 0 Stop |
722| 2 Trigger |
723| Clear (Only Counter) |
724+----------------------------------------------------------------------------+
725| Output Parameters : -- |
726+----------------------------------------------------------------------------+
727| Return Value : TRUE : No error occur |
728| : FALSE : Error occur. Return the error |
729| |
730+----------------------------------------------------------------------------+
731*/
da91b269
BP
732int i_APCI1564_StartStopWriteTimerCounterWatchdog(struct comedi_device *dev,
733 struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data)
c995fe94 734{
843690b7 735 struct addi_private *devpriv = dev->private;
82a6e2e7 736 unsigned int ul_Command1 = 0;
843690b7 737
c995fe94
ADG
738 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) {
739 switch (data[1]) {
b58d9b17
BP
740 case 0: /* stop the watchdog */
741 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + APCI1564_TCW_PROG); /* disable the watchdog */
c995fe94 742 break;
b58d9b17 743 case 1: /* start the watchdog */
c995fe94
ADG
744 outl(0x0001,
745 devpriv->i_IobaseAmcc +
746 APCI1564_DIGITAL_OP_WATCHDOG +
747 APCI1564_TCW_PROG);
748 break;
b58d9b17 749 case 2: /* Software trigger */
c995fe94
ADG
750 outl(0x0201,
751 devpriv->i_IobaseAmcc +
752 APCI1564_DIGITAL_OP_WATCHDOG +
753 APCI1564_TCW_PROG);
754 break;
755 default:
756 printk("\nSpecified functionality does not exist\n");
757 return -EINVAL;
b58d9b17
BP
758 } /* switch (data[1]) */
759 } /* if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) */
c995fe94
ADG
760 if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) {
761 if (data[1] == 1) {
762 ul_Command1 =
763 inl(devpriv->i_IobaseAmcc + APCI1564_TIMER +
764 APCI1564_TCW_PROG);
765 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
766
b58d9b17 767 /* Enable the Timer */
c995fe94
ADG
768 outl(ul_Command1,
769 devpriv->i_IobaseAmcc + APCI1564_TIMER +
770 APCI1564_TCW_PROG);
b58d9b17 771 } /* if (data[1]==1) */
c995fe94 772 else if (data[1] == 0) {
b58d9b17 773 /* Stop The Timer */
c995fe94
ADG
774
775 ul_Command1 =
776 inl(devpriv->i_IobaseAmcc + APCI1564_TIMER +
777 APCI1564_TCW_PROG);
778 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
779 outl(ul_Command1,
780 devpriv->i_IobaseAmcc + APCI1564_TIMER +
781 APCI1564_TCW_PROG);
b58d9b17
BP
782 } /* else if(data[1]==0) */
783 } /* if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) */
c995fe94
ADG
784 if (devpriv->b_TimerSelectMode == ADDIDATA_COUNTER) {
785 ul_Command1 =
786 inl(devpriv->iobase + ((devpriv->b_ModeSelectRegister -
787 1) * 0x20) + APCI1564_TCW_PROG);
788 if (data[1] == 1) {
b58d9b17 789 /* Start the Counter subdevice */
c995fe94 790 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
b58d9b17 791 } /* if (data[1] == 1) */
c995fe94 792 else if (data[1] == 0) {
b58d9b17 793 /* Stops the Counter subdevice */
c995fe94
ADG
794 ul_Command1 = 0;
795
b58d9b17 796 } /* else if (data[1] == 0) */
c995fe94 797 else if (data[1] == 2) {
b58d9b17 798 /* Clears the Counter subdevice */
c995fe94 799 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x400;
b58d9b17 800 } /* else if (data[1] == 3) */
c995fe94
ADG
801 outl(ul_Command1,
802 devpriv->iobase + ((devpriv->b_ModeSelectRegister -
803 1) * 0x20) + APCI1564_TCW_PROG);
b58d9b17 804 } /* if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) */
c995fe94
ADG
805 return insn->n;
806}
807
808/*
809+----------------------------------------------------------------------------+
810| Function Name : int i_APCI1564_ReadTimerCounterWatchdog |
34c43922 811| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 812| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
813+----------------------------------------------------------------------------+
814| Task : Read The Selected Timer , Counter or Watchdog |
815+----------------------------------------------------------------------------+
71b5f4f1 816| Input Parameters : struct comedi_device *dev : Driver handle |
117102b0 817| unsigned int *data : Data Pointer contains |
c995fe94
ADG
818| configuration parameters as below |
819| |
820
821+----------------------------------------------------------------------------+
822| Output Parameters : -- |
823+----------------------------------------------------------------------------+
824| Return Value : TRUE : No error occur |
825| : FALSE : Error occur. Return the error |
826| |
827+----------------------------------------------------------------------------+
828*/
da91b269
BP
829int i_APCI1564_ReadTimerCounterWatchdog(struct comedi_device *dev,
830 struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data)
c995fe94 831{
843690b7 832 struct addi_private *devpriv = dev->private;
82a6e2e7 833 unsigned int ul_Command1 = 0;
c995fe94
ADG
834
835 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) {
b58d9b17 836 /* Stores the status of the Watchdog */
c995fe94
ADG
837 data[0] =
838 inl(devpriv->i_IobaseAmcc +
839 APCI1564_DIGITAL_OP_WATCHDOG +
840 APCI1564_TCW_TRIG_STATUS) & 0x1;
841 data[1] =
842 inl(devpriv->i_IobaseAmcc +
843 APCI1564_DIGITAL_OP_WATCHDOG);
b58d9b17 844 } /* if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) */
c995fe94 845 else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) {
b58d9b17 846 /* Stores the status of the Timer */
c995fe94
ADG
847 data[0] =
848 inl(devpriv->i_IobaseAmcc + APCI1564_TIMER +
849 APCI1564_TCW_TRIG_STATUS) & 0x1;
850
b58d9b17 851 /* Stores the Actual value of the Timer */
c995fe94 852 data[1] = inl(devpriv->i_IobaseAmcc + APCI1564_TIMER);
b58d9b17 853 } /* else if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) */
c995fe94 854 else if (devpriv->b_TimerSelectMode == ADDIDATA_COUNTER) {
b58d9b17 855 /* Read the Counter Actual Value. */
c995fe94
ADG
856 data[0] =
857 inl(devpriv->iobase + ((devpriv->b_ModeSelectRegister -
858 1) * 0x20) +
859 APCI1564_TCW_SYNC_ENABLEDISABLE);
860 ul_Command1 =
861 inl(devpriv->iobase + ((devpriv->b_ModeSelectRegister -
862 1) * 0x20) + APCI1564_TCW_TRIG_STATUS);
863
864 /***********************************/
865 /* Get the software trigger status */
866 /***********************************/
1783fbfe 867 data[1] = (unsigned char) ((ul_Command1 >> 1) & 1);
c995fe94
ADG
868
869 /***********************************/
870 /* Get the hardware trigger status */
871 /***********************************/
1783fbfe 872 data[2] = (unsigned char) ((ul_Command1 >> 2) & 1);
c995fe94
ADG
873
874 /*********************************/
875 /* Get the software clear status */
876 /*********************************/
1783fbfe 877 data[3] = (unsigned char) ((ul_Command1 >> 3) & 1);
c995fe94
ADG
878
879 /***************************/
880 /* Get the overflow status */
881 /***************************/
1783fbfe 882 data[4] = (unsigned char) ((ul_Command1 >> 0) & 1);
b58d9b17 883 } /* else if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) */
c995fe94
ADG
884 else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER)
885 && (devpriv->b_TimerSelectMode != ADDIDATA_WATCHDOG)
886 && (devpriv->b_TimerSelectMode != ADDIDATA_COUNTER)) {
887 printk("\n Invalid Subdevice !!!\n");
b58d9b17 888 } /* else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)&& (devpriv->b_TimerSelectMode!=ADDIDATA_COUNTER)) */
c995fe94
ADG
889 return insn->n;
890}
891
892/*
893+----------------------------------------------------------------------------+
894| Function Name : int i_APCI1564_ReadInterruptStatus |
34c43922 895| (struct comedi_device *dev,struct comedi_subdevice *s, |
90035c08 896| struct comedi_insn *insn,unsigned int *data) |
c995fe94
ADG
897+----------------------------------------------------------------------------+
898| Task :Reads the interrupt status register |
899+----------------------------------------------------------------------------+
900| Input Parameters : |
901+----------------------------------------------------------------------------+
902| Output Parameters : -- |
903+----------------------------------------------------------------------------+
904| Return Value : |
905| |
906+----------------------------------------------------------------------------+
907*/
908
da91b269
BP
909int i_APCI1564_ReadInterruptStatus(struct comedi_device *dev, struct comedi_subdevice *s,
910 struct comedi_insn *insn, unsigned int *data)
c995fe94
ADG
911{
912 *data = ui_Type;
913 return insn->n;
914}
915
916/*
917+----------------------------------------------------------------------------+
918| Function Name : static void v_APCI1564_Interrupt |
919| (int irq , void *d) |
920+----------------------------------------------------------------------------+
921| Task : Interrupt handler for the interruptible digital inputs |
922+----------------------------------------------------------------------------+
923| Input Parameters : int irq : irq number |
924| void *d : void pointer |
925+----------------------------------------------------------------------------+
926| Output Parameters : -- |
927+----------------------------------------------------------------------------+
928| Return Value : TRUE : No error occur |
929| : FALSE : Error occur. Return the error |
930| |
931+----------------------------------------------------------------------------+
932*/
3019b410 933static void v_APCI1564_Interrupt(int irq, void *d)
c995fe94 934{
71b5f4f1 935 struct comedi_device *dev = d;
843690b7 936 struct addi_private *devpriv = dev->private;
117102b0
BP
937 unsigned int ui_DO, ui_DI;
938 unsigned int ui_Timer;
939 unsigned int ui_C1, ui_C2, ui_C3, ui_C4;
82a6e2e7 940 unsigned int ul_Command2 = 0;
843690b7 941
c995fe94
ADG
942 ui_DI = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
943 APCI1564_DIGITAL_IP_IRQ) & 0x01;
944 ui_DO = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
945 APCI1564_DIGITAL_OP_IRQ) & 0x01;
946 ui_Timer =
947 inl(devpriv->i_IobaseAmcc + APCI1564_TIMER +
948 APCI1564_TCW_IRQ) & 0x01;
949 ui_C1 = inl(devpriv->iobase + APCI1564_COUNTER1 +
950 APCI1564_TCW_IRQ) & 0x1;
951 ui_C2 = inl(devpriv->iobase + APCI1564_COUNTER2 +
952 APCI1564_TCW_IRQ) & 0x1;
953 ui_C3 = inl(devpriv->iobase + APCI1564_COUNTER3 +
954 APCI1564_TCW_IRQ) & 0x1;
955 ui_C4 = inl(devpriv->iobase + APCI1564_COUNTER4 +
956 APCI1564_TCW_IRQ) & 0x1;
957 if (ui_DI == 0 && ui_DO == 0 && ui_Timer == 0 && ui_C1 == 0
958 && ui_C2 == 0 && ui_C3 == 0 && ui_C4 == 0) {
959 printk("\nInterrupt from unknown source\n");
b58d9b17 960 } /* if(ui_DI==0 && ui_DO==0 && ui_Timer==0 && ui_C1==0 && ui_C2==0 && ui_C3==0 && ui_C4==0) */
c995fe94
ADG
961
962 if (ui_DI == 1) {
963 ui_DI = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
964 APCI1564_DIGITAL_IP_IRQ);
965 outl(0x0,
966 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
967 APCI1564_DIGITAL_IP_IRQ);
968 ui_InterruptStatus_1564 =
969 inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +
970 APCI1564_DIGITAL_IP_INTERRUPT_STATUS);
971 ui_InterruptStatus_1564 = ui_InterruptStatus_1564 & 0X000FFFF0;
b58d9b17
BP
972 send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
973 outl(ui_DI, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ); /* enable the interrupt */
c995fe94
ADG
974 return;
975 }
976
977 if (ui_DO == 1) {
b58d9b17 978 /* Check for Digital Output interrupt Type - 1: Vcc interrupt 2: CC interrupt. */
c995fe94
ADG
979 ui_Type =
980 inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
981 APCI1564_DIGITAL_OP_INTERRUPT_STATUS) & 0x3;
b58d9b17 982 /* Disable the Interrupt */
c995fe94
ADG
983 outl(0x0,
984 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
985 APCI1564_DIGITAL_OP_INTERRUPT);
986
b58d9b17 987 /* Sends signal to user space */
c995fe94
ADG
988 send_sig(SIGIO, devpriv->tsk_Current, 0);
989
b58d9b17 990 } /* if (ui_DO) */
c995fe94 991
c3744138
BP
992 if (ui_Timer == 1) {
993 devpriv->b_TimerSelectMode = ADDIDATA_TIMER;
994 if (devpriv->b_TimerSelectMode) {
c995fe94 995
c3744138
BP
996 /* Disable Timer Interrupt */
997 ul_Command2 =
998 inl(devpriv->i_IobaseAmcc + APCI1564_TIMER +
999 APCI1564_TCW_PROG);
1000 outl(0x0,
1001 devpriv->i_IobaseAmcc + APCI1564_TIMER +
1002 APCI1564_TCW_PROG);
c995fe94 1003
c3744138
BP
1004 /* Send a signal to from kernel to user space */
1005 send_sig(SIGIO, devpriv->tsk_Current, 0);
c995fe94 1006
c3744138 1007 /* Enable Timer Interrupt */
c995fe94 1008
c3744138
BP
1009 outl(ul_Command2,
1010 devpriv->i_IobaseAmcc + APCI1564_TIMER +
1011 APCI1564_TCW_PROG);
1012 }
1013 }/* if (ui_Timer == 1) */
c995fe94 1014
c995fe94 1015
c3744138
BP
1016 if (ui_C1 == 1) {
1017 devpriv->b_TimerSelectMode = ADDIDATA_COUNTER;
1018 if (devpriv->b_TimerSelectMode) {
c995fe94 1019
c3744138
BP
1020 /* Disable Counter Interrupt */
1021 ul_Command2 =
1022 inl(devpriv->iobase + APCI1564_COUNTER1 +
1023 APCI1564_TCW_PROG);
1024 outl(0x0,
1025 devpriv->iobase + APCI1564_COUNTER1 +
1026 APCI1564_TCW_PROG);
c995fe94 1027
c3744138
BP
1028 /* Send a signal to from kernel to user space */
1029 send_sig(SIGIO, devpriv->tsk_Current, 0);
c995fe94 1030
c3744138
BP
1031 /* Enable Counter Interrupt */
1032 outl(ul_Command2,
1033 devpriv->iobase + APCI1564_COUNTER1 +
1034 APCI1564_TCW_PROG);
1035 }
1036 } /* if (ui_C1 == 1) */
c995fe94 1037
c3744138
BP
1038 if (ui_C2 == 1) {
1039 devpriv->b_TimerSelectMode = ADDIDATA_COUNTER;
1040 if (devpriv->b_TimerSelectMode) {
c995fe94 1041
c3744138
BP
1042 /* Disable Counter Interrupt */
1043 ul_Command2 =
1044 inl(devpriv->iobase + APCI1564_COUNTER2 +
1045 APCI1564_TCW_PROG);
1046 outl(0x0,
1047 devpriv->iobase + APCI1564_COUNTER2 +
1048 APCI1564_TCW_PROG);
c995fe94 1049
c3744138
BP
1050 /* Send a signal to from kernel to user space */
1051 send_sig(SIGIO, devpriv->tsk_Current, 0);
c995fe94 1052
c3744138
BP
1053 /* Enable Counter Interrupt */
1054 outl(ul_Command2,
1055 devpriv->iobase + APCI1564_COUNTER2 +
1056 APCI1564_TCW_PROG);
1057 }
1058 } /* if ((ui_C2 == 1) */
c995fe94 1059
c3744138
BP
1060 if (ui_C3 == 1) {
1061 devpriv->b_TimerSelectMode = ADDIDATA_COUNTER;
1062 if (devpriv->b_TimerSelectMode) {
c995fe94 1063
c3744138
BP
1064 /* Disable Counter Interrupt */
1065 ul_Command2 =
1066 inl(devpriv->iobase + APCI1564_COUNTER3 +
1067 APCI1564_TCW_PROG);
1068 outl(0x0,
1069 devpriv->iobase + APCI1564_COUNTER3 +
1070 APCI1564_TCW_PROG);
1071
1072 /* Send a signal to from kernel to user space */
1073 send_sig(SIGIO, devpriv->tsk_Current, 0);
1074
1075 /* Enable Counter Interrupt */
1076 outl(ul_Command2,
1077 devpriv->iobase + APCI1564_COUNTER3 +
1078 APCI1564_TCW_PROG);
1079 }
1080 } /* if ((ui_C3 == 1) */
1081
1082 if (ui_C4 == 1) {
1083 devpriv->b_TimerSelectMode = ADDIDATA_COUNTER;
1084 if (devpriv->b_TimerSelectMode) {
1085
1086 /* Disable Counter Interrupt */
1087 ul_Command2 =
1088 inl(devpriv->iobase + APCI1564_COUNTER4 +
1089 APCI1564_TCW_PROG);
1090 outl(0x0,
1091 devpriv->iobase + APCI1564_COUNTER4 +
1092 APCI1564_TCW_PROG);
1093
1094 /* Send a signal to from kernel to user space */
1095 send_sig(SIGIO, devpriv->tsk_Current, 0);
1096
1097 /* Enable Counter Interrupt */
1098 outl(ul_Command2,
1099 devpriv->iobase + APCI1564_COUNTER4 +
1100 APCI1564_TCW_PROG);
1101 }
1102 } /* if (ui_C4 == 1) */
c995fe94
ADG
1103 return;
1104}
1105
1106/*
1107+----------------------------------------------------------------------------+
71b5f4f1 1108| Function Name : int i_APCI1564_Reset(struct comedi_device *dev) | |
c995fe94
ADG
1109+----------------------------------------------------------------------------+
1110| Task :resets all the registers |
1111+----------------------------------------------------------------------------+
71b5f4f1 1112| Input Parameters : struct comedi_device *dev
c995fe94
ADG
1113+----------------------------------------------------------------------------+
1114| Output Parameters : -- |
1115+----------------------------------------------------------------------------+
1116| Return Value : |
1117| |
1118+----------------------------------------------------------------------------+
1119*/
1120
da91b269 1121int i_APCI1564_Reset(struct comedi_device *dev)
c995fe94 1122{
843690b7
HS
1123 struct addi_private *devpriv = dev->private;
1124
b58d9b17
BP
1125 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP_IRQ); /* disable the interrupts */
1126 inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP_INTERRUPT_STATUS); /* Reset the interrupt status register */
1127 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP_INTERRUPT_MODE1); /* Disable the and/or interrupt */
c995fe94
ADG
1128 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP_INTERRUPT_MODE2);
1129 devpriv->b_DigitalOutputRegister = 0;
1130 ui_Type = 0;
b58d9b17
BP
1131 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP); /* Resets the output channels */
1132 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_INTERRUPT); /* Disables the interrupt. */
c995fe94
ADG
1133 outl(0x0,
1134 devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG +
1135 APCI1564_TCW_RELOAD_VALUE);
1136 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_TIMER);
1137 outl(0x0, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);
1138
1139 outl(0x0, devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);
1140 outl(0x0, devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG);
1141 outl(0x0, devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG);
1142 outl(0x0, devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);
1143 return 0;
1144}