]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/addi-data/APCI1710_Ttl.c
Merge tag 'please-pull-einj-fix-for-acpi5' of git://git.kernel.org/pub/scm/linux...
[karo-tx-linux.git] / drivers / staging / comedi / drivers / addi-data / APCI1710_Ttl.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     : API APCI1710    | Compiler : gcc                        |
33   | Module name : TTL.C           | Version  : 2.96                       |
34   +-------------------------------+---------------------------------------+
35   | Project manager: Eric Stolz   | Date     :  02/12/2002                |
36   +-----------------------------------------------------------------------+
37   | Description :   APCI-1710 TTL I/O module                              |
38   |                                                                       |
39   |                                                                       |
40   +-----------------------------------------------------------------------+
41   |                             UPDATES                                   |
42   +-----------------------------------------------------------------------+
43   |   Date   |   Author  |          Description of updates                |
44   +----------+-----------+------------------------------------------------+
45   | 13/05/98 | S. Weber  | TTL digital input / output implementation      |
46   |----------|-----------|------------------------------------------------|
47   | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |
48   |          |           |   available                                    |
49   +-----------------------------------------------------------------------+
50   |          |           |                                                |
51   |          |           |                                                |
52   +-----------------------------------------------------------------------+
53 */
54
55 #define APCI1710_TTL_INIT               0
56 #define APCI1710_TTL_INITDIRECTION      1
57
58 #define APCI1710_TTL_READCHANNEL        0
59 #define APCI1710_TTL_READPORT           1
60
61 /*
62 +----------------------------------------------------------------------------+
63 | Function Name     : _INT_ i_APCI1710_InitTTLIODirection                    |
64 |                               (unsigned char_    b_BoardHandle,                     |
65 |                                unsigned char_    b_ModulNbr,                        |
66 |                                unsigned char_    b_PortAMode,                       |
67 |                                unsigned char_    b_PortBMode,                       |
68 |                                unsigned char_    b_PortCMode,                       |
69 |                                unsigned char_    b_PortDMode)                       |
70 +----------------------------------------------------------------------------+
71 | Task           APCI1710_TTL_INIT (using defaults)   : Configure the TTL I/O operating mode from selected     |
72 |                     module  (b_ModulNbr). You must calling this function be|
73 |                     for you call any other function witch access of TTL.   |
74                                  APCI1710_TTL_INITDIRECTION(user inputs for direction)
75
76 +----------------------------------------------------------------------------+
77 | Input Parameters  : unsigned char_ b_BoardHandle         : Handle of board APCI-1710|
78 |                     unsigned char_ b_ModulNbr            : Module number to         |
79 |                                                   configure (0 to 3)
80                 b_ModulNbr = (unsigned char) CR_AREF(insn->chanspec);
81                 b_InitType = (unsigned char) data[0];
82                 b_PortAMode     = (unsigned char) data[1];
83                 b_PortBMode = (unsigned char) data[2];
84                 b_PortCMode = (unsigned char) data[3];
85                 b_PortDMode     = (unsigned char) data[4];|
86 +----------------------------------------------------------------------------+
87 | Output Parameters : -                                                      |
88 +----------------------------------------------------------------------------+
89 | Return Value      : 0: No error                                            |
90 |                    -1: The handle parameter of the board is wrong          |
91 |                    -2: The module parameter is wrong                       |
92 |                    -3: The module is not a TTL module                      |
93 |                    -4: Function not available for this version             |
94 |                    -5: Port A mode selection is wrong                      |
95 |                    -6: Port B mode selection is wrong                      |
96 |                    -7: Port C mode selection is wrong                      |
97 |                    -8: Port D mode selection is wrong                      |
98 +----------------------------------------------------------------------------+
99 */
100
101 static int i_APCI1710_InsnConfigInitTTLIO(struct comedi_device *dev,
102                                           struct comedi_subdevice *s,
103                                           struct comedi_insn *insn,
104                                           unsigned int *data)
105 {
106         struct addi_private *devpriv = dev->private;
107         int i_ReturnValue = 0;
108         unsigned char b_ModulNbr;
109         unsigned char b_InitType;
110         unsigned char b_PortAMode;
111         unsigned char b_PortBMode;
112         unsigned char b_PortCMode;
113         unsigned char b_PortDMode;
114
115         b_ModulNbr = (unsigned char) CR_AREF(insn->chanspec);
116         b_InitType = (unsigned char) data[0];
117         i_ReturnValue = insn->n;
118
119         /**************************/
120         /* Test the module number */
121         /**************************/
122
123         if (b_ModulNbr < 4) {
124            /**************************/
125                 /* Test if TTL I/O module */
126            /**************************/
127
128                 if ((devpriv->s_BoardInfos.
129                                 dw_MolduleConfiguration[b_ModulNbr] &
130                                 0xFFFF0000UL) == APCI1710_TTL_IO) {
131                         switch (b_InitType) {
132                         case APCI1710_TTL_INIT:
133
134                                 devpriv->s_ModuleInfo[b_ModulNbr].
135                                         s_TTLIOInfo.b_TTLInit = 1;
136
137               /***************************/
138                                 /* Set TTL port A to input */
139               /***************************/
140
141                                 devpriv->s_ModuleInfo[b_ModulNbr].
142                                         s_TTLIOInfo.b_PortConfiguration[0] = 0;
143
144               /***************************/
145                                 /* Set TTL port B to input */
146               /***************************/
147
148                                 devpriv->s_ModuleInfo[b_ModulNbr].
149                                         s_TTLIOInfo.b_PortConfiguration[1] = 0;
150
151               /***************************/
152                                 /* Set TTL port C to input */
153               /***************************/
154
155                                 devpriv->s_ModuleInfo[b_ModulNbr].
156                                         s_TTLIOInfo.b_PortConfiguration[2] = 0;
157
158               /****************************/
159                                 /* Set TTL port D to output */
160               /****************************/
161
162                                 devpriv->s_ModuleInfo[b_ModulNbr].
163                                         s_TTLIOInfo.b_PortConfiguration[3] = 1;
164
165               /*************************/
166                                 /* Set the configuration */
167               /*************************/
168
169                                 outl(0x8,
170                                         devpriv->s_BoardInfos.ui_Address + 20 +
171                                         (64 * b_ModulNbr));
172                                 break;
173
174                         case APCI1710_TTL_INITDIRECTION:
175
176                                 b_PortAMode = (unsigned char) data[1];
177                                 b_PortBMode = (unsigned char) data[2];
178                                 b_PortCMode = (unsigned char) data[3];
179                                 b_PortDMode = (unsigned char) data[4];
180
181               /********************/
182                                 /* Test the version */
183               /********************/
184
185                                 if ((devpriv->s_BoardInfos.
186                                                 dw_MolduleConfiguration
187                                                 [b_ModulNbr] & 0xFFFF) >=
188                                         0x3230) {
189                  /************************/
190                                         /* Test the port A mode */
191                  /************************/
192
193                                         if ((b_PortAMode == 0)
194                                                 || (b_PortAMode == 1)) {
195                     /************************/
196                                                 /* Test the port B mode */
197                     /************************/
198
199                                                 if ((b_PortBMode == 0)
200                                                         || (b_PortBMode == 1)) {
201                        /************************/
202                                                         /* Test the port C mode */
203                        /************************/
204
205                                                         if ((b_PortCMode == 0)
206                                                                 || (b_PortCMode
207                                                                         == 1)) {
208                           /************************/
209                                                                 /* Test the port D mode */
210                           /************************/
211
212                                                                 if ((b_PortDMode == 0) || (b_PortDMode == 1)) {
213                                                                         devpriv->
214                                                                                 s_ModuleInfo
215                                                                                 [b_ModulNbr].
216                                                                                 s_TTLIOInfo.
217                                                                                 b_TTLInit
218                                                                                 =
219                                                                                 1;
220
221                              /***********************/
222                                                                         /* Set TTL port A mode */
223                              /***********************/
224
225                                                                         devpriv->
226                                                                                 s_ModuleInfo
227                                                                                 [b_ModulNbr].
228                                                                                 s_TTLIOInfo.
229                                                                                 b_PortConfiguration
230                                                                                 [0]
231                                                                                 =
232                                                                                 b_PortAMode;
233
234                              /***********************/
235                                                                         /* Set TTL port B mode */
236                              /***********************/
237
238                                                                         devpriv->
239                                                                                 s_ModuleInfo
240                                                                                 [b_ModulNbr].
241                                                                                 s_TTLIOInfo.
242                                                                                 b_PortConfiguration
243                                                                                 [1]
244                                                                                 =
245                                                                                 b_PortBMode;
246
247                              /***********************/
248                                                                         /* Set TTL port C mode */
249                              /***********************/
250
251                                                                         devpriv->
252                                                                                 s_ModuleInfo
253                                                                                 [b_ModulNbr].
254                                                                                 s_TTLIOInfo.
255                                                                                 b_PortConfiguration
256                                                                                 [2]
257                                                                                 =
258                                                                                 b_PortCMode;
259
260                              /***********************/
261                                                                         /* Set TTL port D mode */
262                              /***********************/
263
264                                                                         devpriv->
265                                                                                 s_ModuleInfo
266                                                                                 [b_ModulNbr].
267                                                                                 s_TTLIOInfo.
268                                                                                 b_PortConfiguration
269                                                                                 [3]
270                                                                                 =
271                                                                                 b_PortDMode;
272
273                              /*************************/
274                                                                         /* Set the configuration */
275                              /*************************/
276
277                                                                         outl((b_PortAMode << 0) | (b_PortBMode << 1) | (b_PortCMode << 2) | (b_PortDMode << 3), devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr));
278                                                                 } else {
279                              /**********************************/
280                                                                         /* Port D mode selection is wrong */
281                              /**********************************/
282
283                                                                         DPRINTK("Port D mode selection is wrong\n");
284                                                                         i_ReturnValue
285                                                                                 =
286                                                                                 -8;
287                                                                 }
288                                                         } else {
289                           /**********************************/
290                                                                 /* Port C mode selection is wrong */
291                           /**********************************/
292
293                                                                 DPRINTK("Port C mode selection is wrong\n");
294                                                                 i_ReturnValue =
295                                                                         -7;
296                                                         }
297                                                 } else {
298                        /**********************************/
299                                                         /* Port B mode selection is wrong */
300                        /**********************************/
301
302                                                         DPRINTK("Port B mode selection is wrong\n");
303                                                         i_ReturnValue = -6;
304                                                 }
305                                         } else {
306                     /**********************************/
307                                                 /* Port A mode selection is wrong */
308                     /**********************************/
309
310                                                 DPRINTK("Port A mode selection is wrong\n");
311                                                 i_ReturnValue = -5;
312                                         }
313                                 } else {
314                  /*******************************************/
315                                         /* Function not available for this version */
316                  /*******************************************/
317
318                                         DPRINTK("Function not available for this version\n");
319                                         i_ReturnValue = -4;
320                                 }
321                                 break;
322
323                                 DPRINTK("\n");
324                         default:
325                                 printk("Bad Config Type\n");
326                         }       /*  switch end */
327                 } else {
328               /**********************************/
329                         /* The module is not a TTL module */
330               /**********************************/
331
332                         DPRINTK("The module is not a TTL module\n");
333                         i_ReturnValue = -3;
334                 }
335         } else {
336            /***********************/
337                 /* Module number error */
338            /***********************/
339
340                 DPRINTK("Module number error\n");
341                 i_ReturnValue = -2;
342         }
343
344         return i_ReturnValue;
345 }
346
347 /*
348 +----------------------------------------------------------------------------+
349 |                            INPUT FUNCTIONS                                 |
350 +----------------------------------------------------------------------------+
351 */
352
353 /*
354 +----------------------------------------------------------------------------+
355 | Function Name     : _INT_   i_APCI1710_ReadTTLIOChannelValue               |
356 |                                       (unsigned char_     b_BoardHandle,            |
357 |                                        unsigned char_     b_ModulNbr,               |
358 |                                        unsigned char_     b_SelectedPort,           |
359 |                                        unsigned char_     b_InputChannel,           |
360 |                                        unsigned char *_   pb_ChannelStatus)          |
361 +----------------------------------------------------------------------------+
362 | Task              : Read the status from selected TTL digital input        |
363 |                     (b_InputChannel)
364 +----------------------------------------------------------------------------+
365 | Task              : Read the status from digital input port                |
366 |                     (b_SelectedPort) from selected TTL module (b_ModulNbr) |
367 +----------------------------------------------------------------------------+
368
369 +----------------------------------------------------------------------------+
370 | Input Parameters  : unsigned char_ b_BoardHandle         : Handle of board APCI-1710|
371 |                     unsigned char_ b_ModulNbr            : Module number to         |
372 |                                                   configure (0 to 7)       |
373 |                     unsigned char_ b_SelectedPort,       : Selection from TTL I/O   |
374 |                                                   port (0 to 2)            |
375 |                                                      0 : Port A selection  |
376 |                                                      1 : Port B selection  |
377 |                                                      2 : Port C selection  |
378 |                                                      3 : Port D selection  |
379 |                     unsigned char_ b_InputChannel        : Selection from digital   |
380 |                                                   input ( 0 to 2)
381 APCI1710_TTL_READCHANNEL
382         b_ModulNbr        = CR_AREF(insn->chanspec);
383         b_SelectedPort= CR_RANGE(insn->chanspec);
384         b_InputChannel= CR_CHAN(insn->chanspec);
385         b_ReadType        = (unsigned char) data[0];
386
387  APCI1710_TTL_READPORT|
388         b_ModulNbr        = CR_AREF(insn->chanspec);
389         b_SelectedPort= CR_RANGE(insn->chanspec);
390         b_ReadType        = (unsigned char) data[0];
391
392 +----------------------------------------------------------------------------+
393 | Output Parameters : data[0]
394
395         unsigned char *_  pb_ChannelStatus    : Digital input channel    |
396 |                                                   status                   |
397 |                                                   0 : Channle is not active|
398 |                                                   1 : Channle is active    |
399 +----------------------------------------------------------------------------+
400 | Return Value      : 0: No error                                            |
401 |                    -1: The handle parameter of the board is wrong          |
402 |                    -2: The module parameter is wrong                       |
403 |                    -3: The module is not a TTL module                      |
404 |                    -4: The selected TTL input port is wrong                |
405 |                    -5: The selected TTL digital input is wrong             |
406 |                    -6: TTL I/O not initialised                             |
407 +----------------------------------------------------------------------------+
408 */
409
410 static int i_APCI1710_InsnBitsReadTTLIO(struct comedi_device *dev,
411                                         struct comedi_subdevice *s,
412                                         struct comedi_insn *insn,
413                                         unsigned int *data)
414 {
415         struct addi_private *devpriv = dev->private;
416         int i_ReturnValue = 0;
417         unsigned int dw_StatusReg;
418         unsigned char b_ModulNbr;
419         unsigned char b_SelectedPort;
420         unsigned char b_InputChannel;
421         unsigned char b_ReadType;
422         unsigned char *pb_ChannelStatus;
423         unsigned char *pb_PortValue;
424
425         i_ReturnValue = insn->n;
426         b_ReadType = (unsigned char) data[0];
427         b_ModulNbr = CR_AREF(insn->chanspec);
428         b_SelectedPort = CR_RANGE(insn->chanspec);
429         b_InputChannel = CR_CHAN(insn->chanspec);
430
431         /**************************/
432         /* Test the module number */
433         /**************************/
434
435         if (b_ModulNbr < 4) {
436            /**************************/
437                 /* Test if TTL I/O module */
438            /**************************/
439
440                 if ((devpriv->s_BoardInfos.
441                                 dw_MolduleConfiguration[b_ModulNbr] &
442                                 0xFFFF0000UL) == APCI1710_TTL_IO) {
443                         switch (b_ReadType) {
444
445                         case APCI1710_TTL_READCHANNEL:
446                                 pb_ChannelStatus = (unsigned char *) &data[0];
447               /********************************/
448                                 /* Test the TTL I/O port number */
449               /********************************/
450
451                                 if (((b_SelectedPort <= 2)
452                                                 && ((devpriv->s_BoardInfos.
453                                                                 dw_MolduleConfiguration
454                                                                 [b_ModulNbr] &
455                                                                 0xFFFF) ==
456                                                         0x3130))
457                                         || ((b_SelectedPort <= 3)
458                                                 && ((devpriv->s_BoardInfos.
459                                                                 dw_MolduleConfiguration
460                                                                 [b_ModulNbr] &
461                                                                 0xFFFF) >=
462                                                         0x3230))) {
463                  /******************************************/
464                                         /* Test the digital imnput channel number */
465                  /******************************************/
466
467                                         if (((b_InputChannel <= 7)
468                                                         && (b_SelectedPort < 3))
469                                                 || ((b_InputChannel <= 1)
470                                                         && (b_SelectedPort ==
471                                                                 3))) {
472                     /******************************************/
473                                                 /* Test if the TTL I/O module initialised */
474                     /******************************************/
475
476                                                 if (devpriv->
477                                                         s_ModuleInfo
478                                                         [b_ModulNbr].
479                                                         s_TTLIOInfo.b_TTLInit ==
480                                                         1) {
481                        /***********************************/
482                                                         /* Test if TTL port used for input */
483                        /***********************************/
484
485                                                         if (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) == 0x3130) || (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3230) && (devpriv->s_ModuleInfo[b_ModulNbr].s_TTLIOInfo.b_PortConfiguration[b_SelectedPort] == 0))) {
486                           /**************************/
487                                                                 /* Read all digital input */
488                           /**************************/
489
490                                                                 dw_StatusReg =
491                                                                         inl
492                                                                         (devpriv->
493                                                                         s_BoardInfos.
494                                                                         ui_Address
495                                                                         +
496                                                                         (64 * b_ModulNbr));
497
498                                                                 *pb_ChannelStatus
499                                                                         =
500                                                                         (unsigned char) (
501                                                                         (dw_StatusReg
502                                                                                 >>
503                                                                                 (8 * b_SelectedPort)) >> b_InputChannel) & 1;
504                                                         } else {
505                           /*******************************/
506                                                                 /* Selected TTL I/O port error */
507                           /*******************************/
508
509                                                                 DPRINTK("Selected TTL I/O port error\n");
510                                                                 i_ReturnValue =
511                                                                         -4;
512                                                         }
513                                                 } else {
514                        /***************************/
515                                                         /* TTL I/O not initialised */
516                        /***************************/
517
518                                                         DPRINTK("TTL I/O not initialised\n");
519                                                         i_ReturnValue = -6;
520                                                 }
521                                         } else {
522                     /********************************/
523                                                 /* Selected digital input error */
524                     /********************************/
525
526                                                 DPRINTK("Selected digital input error\n");
527                                                 i_ReturnValue = -5;
528                                         }
529                                 } else {
530                  /*******************************/
531                                         /* Selected TTL I/O port error */
532                  /*******************************/
533
534                                         DPRINTK("Selected TTL I/O port error\n");
535                                         i_ReturnValue = -4;
536                                 }
537                                 break;
538
539                         case APCI1710_TTL_READPORT:
540                                 pb_PortValue = (unsigned char *) &data[0];
541                           /********************************/
542                                 /* Test the TTL I/O port number */
543                           /********************************/
544
545                                 if (((b_SelectedPort <= 2)
546                                                 && ((devpriv->s_BoardInfos.
547                                                                 dw_MolduleConfiguration
548                                                                 [b_ModulNbr] &
549                                                                 0xFFFF) ==
550                                                         0x3130))
551                                         || ((b_SelectedPort <= 3)
552                                                 && ((devpriv->s_BoardInfos.
553                                                                 dw_MolduleConfiguration
554                                                                 [b_ModulNbr] &
555                                                                 0xFFFF) >=
556                                                         0x3230))) {
557                  /******************************************/
558                                         /* Test if the TTL I/O module initialised */
559                  /******************************************/
560
561                                         if (devpriv->s_ModuleInfo[b_ModulNbr].
562                                                 s_TTLIOInfo.b_TTLInit == 1) {
563                     /***********************************/
564                                                 /* Test if TTL port used for input */
565                     /***********************************/
566
567                                                 if (((devpriv->s_BoardInfos.
568                                                                         dw_MolduleConfiguration
569                                                                         [b_ModulNbr]
570                                                                         &
571                                                                         0xFFFF)
572                                                                 == 0x3130)
573                                                         || (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3230) && (devpriv->s_ModuleInfo[b_ModulNbr].s_TTLIOInfo.b_PortConfiguration[b_SelectedPort] == 0))) {
574                        /**************************/
575                                                         /* Read all digital input */
576                        /**************************/
577
578                                                         dw_StatusReg =
579                                                                 inl(devpriv->
580                                                                 s_BoardInfos.
581                                                                 ui_Address +
582                                                                 (64 * b_ModulNbr));
583
584                                                         *pb_PortValue =
585                                                                 (unsigned char) (
586                                                                 (dw_StatusReg >>
587                                                                         (8 * b_SelectedPort)) & 0xFF);
588                                                 } else {
589                        /*******************************/
590                                                         /* Selected TTL I/O port error */
591                        /*******************************/
592
593                                                         DPRINTK("Selected TTL I/O port error\n");
594                                                         i_ReturnValue = -4;
595                                                 }
596                                         } else {
597                     /***************************/
598                                                 /* TTL I/O not initialised */
599                     /***************************/
600
601                                                 DPRINTK("TTL I/O not initialised\n");
602                                                 i_ReturnValue = -5;
603                                         }
604                                 } else {
605                  /*******************************/
606                                         /* Selected TTL I/O port error */
607                  /*******************************/
608
609                                         DPRINTK("Selected TTL I/O port error\n");
610                                         i_ReturnValue = -4;
611                                 }
612                                 break;
613
614                         default:
615                                 printk("Bad ReadType\n");
616
617                         }       /* End Switch */
618                 } else {
619               /**********************************/
620                         /* The module is not a TTL module */
621               /**********************************/
622
623                         DPRINTK("The module is not a TTL module\n");
624                         i_ReturnValue = -3;
625                 }
626         } else {
627            /***********************/
628                 /* Module number error */
629            /***********************/
630
631                 DPRINTK("Module number error\n");
632                 i_ReturnValue = -2;
633         }
634
635         return i_ReturnValue;
636 }
637
638 /*
639 +----------------------------------------------------------------------------+
640 | Function Name     : int i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device
641 *dev,struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data)              |
642 +----------------------------------------------------------------------------+
643 | Task              : Read the status from all digital input ports           |
644 |                     (port A, port B and port C) from selected TTL          |
645 |                     module (b_ModulNbr)                                    |
646 +----------------------------------------------------------------------------+
647 | Input Parameters  : unsigned char_ b_BoardHandle         : Handle of board APCI-1710|
648 |                     unsigned char_ b_ModulNbr            : Module number to         |
649 |                                                   configure (0 to 3)       |
650 +----------------------------------------------------------------------------+
651 | Output Parameters : PULONG_  pul_PortValue      : Digital TTL inputs port  |
652 |                                                   status                   |
653 +----------------------------------------------------------------------------+
654 | Return Value      : 0: No error                                            |
655 |                    -1: The handle parameter of the board is wrong          |
656 |                    -2: The module parameter is wrong                       |
657 |                    -3: The module is not a TTL module                      |
658 |                    -4: TTL I/O not initialised                             |
659 +----------------------------------------------------------------------------+
660 */
661
662 static int i_APCI1710_InsnReadTTLIOAllPortValue(struct comedi_device *dev,
663                                                 struct comedi_subdevice *s,
664                                                 struct comedi_insn *insn,
665                                                 unsigned int *data)
666 {
667         struct addi_private *devpriv = dev->private;
668         int i_ReturnValue = 0;
669         unsigned int dw_StatusReg;
670         unsigned char b_ModulNbr;
671         unsigned int *pul_PortValue;
672
673         b_ModulNbr = (unsigned char) CR_AREF(insn->chanspec);
674         i_ReturnValue = insn->n;
675         pul_PortValue = (unsigned int *) &data[0];
676
677         /**************************/
678         /* Test the module number */
679         /**************************/
680
681         if (b_ModulNbr < 4) {
682            /**************************/
683                 /* Test if TTL I/O module */
684            /**************************/
685
686                 if ((devpriv->s_BoardInfos.
687                                 dw_MolduleConfiguration[b_ModulNbr] &
688                                 0xFFFF0000UL) == APCI1710_TTL_IO) {
689               /******************************************/
690                         /* Test if the TTL I/O module initialised */
691               /******************************************/
692
693                         if (devpriv->
694                                 s_ModuleInfo[b_ModulNbr].
695                                 s_TTLIOInfo.b_TTLInit == 1) {
696                  /**************************/
697                                 /* Read all digital input */
698                  /**************************/
699
700                                 dw_StatusReg = inl(devpriv->s_BoardInfos.
701                                         ui_Address + (64 * b_ModulNbr));
702
703                  /**********************/
704                                 /* Test if TTL Rev1.0 */
705                  /**********************/
706
707                                 if ((devpriv->s_BoardInfos.
708                                                 dw_MolduleConfiguration
709                                                 [b_ModulNbr] & 0xFFFF) ==
710                                         0x3130) {
711                                         *pul_PortValue =
712                                                 dw_StatusReg & 0xFFFFFFUL;
713                                 } else {
714                     /**************************************/
715                                         /* Test if port A not used for output */
716                     /**************************************/
717
718                                         if (devpriv->s_ModuleInfo[b_ModulNbr].
719                                                 s_TTLIOInfo.
720                                                 b_PortConfiguration[0] == 1) {
721                                                 *pul_PortValue =
722                                                         dw_StatusReg &
723                                                         0x3FFFF00UL;
724                                         }
725
726                     /**************************************/
727                                         /* Test if port B not used for output */
728                     /**************************************/
729
730                                         if (devpriv->
731                                                 s_ModuleInfo[b_ModulNbr].
732                                                 s_TTLIOInfo.
733                                                 b_PortConfiguration[1] == 1) {
734                                                 *pul_PortValue =
735                                                         dw_StatusReg &
736                                                         0x3FF00FFUL;
737                                         }
738
739                     /**************************************/
740                                         /* Test if port C not used for output */
741                     /**************************************/
742
743                                         if (devpriv->
744                                                 s_ModuleInfo[b_ModulNbr].
745                                                 s_TTLIOInfo.
746                                                 b_PortConfiguration[2] == 1) {
747                                                 *pul_PortValue =
748                                                         dw_StatusReg &
749                                                         0x300FFFFUL;
750                                         }
751
752                     /**************************************/
753                                         /* Test if port D not used for output */
754                     /**************************************/
755
756                                         if (devpriv->
757                                                 s_ModuleInfo[b_ModulNbr].
758                                                 s_TTLIOInfo.
759                                                 b_PortConfiguration[3] == 1) {
760                                                 *pul_PortValue =
761                                                         dw_StatusReg &
762                                                         0xFFFFFFUL;
763                                         }
764                                 }
765                         } else {
766                  /***************************/
767                                 /* TTL I/O not initialised */
768                  /***************************/
769                                 DPRINTK("TTL I/O not initialised\n");
770                                 i_ReturnValue = -5;
771                         }
772                 } else {
773               /**********************************/
774                         /* The module is not a TTL module */
775               /**********************************/
776                         DPRINTK("The module is not a TTL module\n");
777                         i_ReturnValue = -3;
778                 }
779         } else {
780            /***********************/
781                 /* Module number error */
782            /***********************/
783                 DPRINTK("Module number error\n");
784                 i_ReturnValue = -2;
785         }
786
787         return i_ReturnValue;
788 }
789
790 /*
791 +----------------------------------------------------------------------------+
792 |                            OUTPUT FUNCTIONS                                |
793 +----------------------------------------------------------------------------+
794 */
795
796 /*
797 +----------------------------------------------------------------------------+
798 | Function Name     : _INT_ i_APCI1710_SetTTLIOChlOn                         |
799 |                               (unsigned char_           b_BoardHandle,              |
800 |                                unsigned char_           b_ModulNbr,                 |
801 |                                unsigned char_           b_OutputChannel)
802 int i_APCI1710_InsnWriteSetTTLIOChlOnOff(struct comedi_device *dev,struct comedi_subdevice *s,
803         struct comedi_insn *insn,unsigned int *data)           |
804 +----------------------------------------------------------------------------+
805 | Task              : Sets or resets  the output witch has been passed with the         |
806 |                     parameter b_Channel. Setting an output means setting   |
807 |                     an ouput high.                                         |
808 +----------------------------------------------------------------------------+
809 | Input Parameters  : unsigned char_ b_BoardHandle   : Handle of board APCI-1710      |
810 |                     unsigned char_ b_ModulNbr      : Selected module number (0 to 3)|
811 |                     unsigned char_ b_OutputChannel : Selection from digital output  |
812 |                                             channel (0 or 1)               |
813 |                                                0      : PD0                |
814 |                                                1      : PD1                |
815 |                                                2 to 9 : PA                 |
816 |                                               10 to 17: PB                 |
817 |                                               18 to 25: PC                 |
818
819   b_ModulNbr       = CR_AREF(insn->chanspec);
820         b_OutputChannel= CR_CHAN(insn->chanspec);
821         ui_State           = data[0]; /*  ON or OFF */
822 +----------------------------------------------------------------------------+
823 | Output Parameters : -                                                      |
824 +----------------------------------------------------------------------------+
825 | Return Value      : 0: No error                                            |
826 |                    -1: The handle parameter of the board is wrong          |
827 |                    -2: The module parameter is wrong                       |
828 |                    -3: The module is not a TTL I/O module                  |
829 |                    -4: The selected digital output is wrong                |
830 |                    -5: TTL I/O not initialised see function                |
831 |                        " i_APCI1710_InitTTLIO"
832 +----------------------------------------------------------------------------+
833 */
834
835 static int i_APCI1710_InsnWriteSetTTLIOChlOnOff(struct comedi_device *dev,
836                                                 struct comedi_subdevice *s,
837                                                 struct comedi_insn *insn,
838                                                 unsigned int *data)
839 {
840         struct addi_private *devpriv = dev->private;
841         int i_ReturnValue = 0;
842         unsigned int dw_StatusReg = 0;
843         unsigned char b_ModulNbr;
844         unsigned char b_OutputChannel;
845         unsigned int ui_State;
846
847         i_ReturnValue = insn->n;
848         b_ModulNbr = CR_AREF(insn->chanspec);
849         b_OutputChannel = CR_CHAN(insn->chanspec);
850         ui_State = data[0];     /*  ON or OFF */
851
852         /**************************/
853         /* Test the module number */
854         /**************************/
855
856         if (b_ModulNbr < 4) {
857            /**************************/
858                 /* Test if TTL I/O module */
859            /**************************/
860
861                 if ((devpriv->s_BoardInfos.
862                                 dw_MolduleConfiguration[b_ModulNbr] &
863                                 0xFFFF0000UL) == APCI1710_TTL_IO) {
864               /******************************************/
865                         /* Test if the TTL I/O module initialised */
866               /******************************************/
867
868                         if (devpriv->s_ModuleInfo[b_ModulNbr].
869                                 s_TTLIOInfo.b_TTLInit == 1) {
870                  /***********************************/
871                                 /* Test the TTL I/O channel number */
872                  /***********************************/
873
874                                 if (((b_OutputChannel <= 1)
875                                                 && ((devpriv->s_BoardInfos.
876                                                                 dw_MolduleConfiguration
877                                                                 [b_ModulNbr] &
878                                                                 0xFFFF) ==
879                                                         0x3130))
880                                         || ((b_OutputChannel <= 25)
881                                                 && ((devpriv->s_BoardInfos.
882                                                                 dw_MolduleConfiguration
883                                                                 [b_ModulNbr] &
884                                                                 0xFFFF) >=
885                                                         0x3230))) {
886                     /****************************************************/
887                                         /* Test if the selected channel is a output channel */
888                     /****************************************************/
889
890                                         if (((b_OutputChannel <= 1)
891                                                         && (devpriv->
892                                                                 s_ModuleInfo
893                                                                 [b_ModulNbr].
894                                                                 s_TTLIOInfo.
895                                                                 b_PortConfiguration
896                                                                 [3] == 1))
897                                                 || ((b_OutputChannel >= 2)
898                                                         && (b_OutputChannel <=
899                                                                 9)
900                                                         && (devpriv->
901                                                                 s_ModuleInfo
902                                                                 [b_ModulNbr].
903                                                                 s_TTLIOInfo.
904                                                                 b_PortConfiguration
905                                                                 [0] == 1))
906                                                 || ((b_OutputChannel >= 10)
907                                                         && (b_OutputChannel <=
908                                                                 17)
909                                                         && (devpriv->
910                                                                 s_ModuleInfo
911                                                                 [b_ModulNbr].
912                                                                 s_TTLIOInfo.
913                                                                 b_PortConfiguration
914                                                                 [1] == 1))
915                                                 || ((b_OutputChannel >= 18)
916                                                         && (b_OutputChannel <=
917                                                                 25)
918                                                         && (devpriv->
919                                                                 s_ModuleInfo
920                                                                 [b_ModulNbr].
921                                                                 s_TTLIOInfo.
922                                                                 b_PortConfiguration
923                                                                 [2] == 1))) {
924                        /************************/
925                                                 /* Test if PD0 selected */
926                        /************************/
927
928                                                 if (b_OutputChannel == 0) {
929
930                                                         outl(ui_State,
931                                                                 devpriv->
932                                                                 s_BoardInfos.
933                                                                 ui_Address +
934                                                                 (64 * b_ModulNbr));
935                                                 } else {
936                           /************************/
937                                                         /* Test if PD1 selected */
938                           /************************/
939
940                                                         if (b_OutputChannel ==
941                                                                 1) {
942
943                                                                 outl(ui_State,
944                                                                         devpriv->
945                                                                         s_BoardInfos.
946                                                                         ui_Address
947                                                                         + 4 +
948                                                                         (64 * b_ModulNbr));
949                                                         } else {
950                                                                 b_OutputChannel
951                                                                         =
952                                                                         b_OutputChannel
953                                                                         - 2;
954
955                              /********************/
956                                                                 /* Read all channel */
957                              /********************/
958
959                                                                 dw_StatusReg =
960                                                                         inl
961                                                                         (devpriv->
962                                                                         s_BoardInfos.
963                                                                         ui_Address
964                                                                         +
965                                                                         (64 * b_ModulNbr));
966                                                                 if (ui_State)   /*  ON */
967                                                                 {
968                                                                         dw_StatusReg
969                                                                                 =
970                                                                                 (dw_StatusReg
971                                                                                 >>
972                                                                                 ((b_OutputChannel / 8) * 8)) & 0xFF;
973                                                                         dw_StatusReg
974                                                                                 =
975                                                                                 dw_StatusReg
976                                                                                 |
977                                                                                 (1
978                                                                                 <<
979                                                                                 (b_OutputChannel
980                                                                                         %
981                                                                                         8));
982                                                                 } else  /*  Off */
983                                                                 {
984                                                                         dw_StatusReg
985                                                                                 =
986                                                                                 (dw_StatusReg
987                                                                                 >>
988                                                                                 ((b_OutputChannel / 8) * 8)) & 0xFF;
989                                                                         dw_StatusReg
990                                                                                 =
991                                                                                 dw_StatusReg
992                                                                                 &
993                                                                                 (0xFF
994                                                                                 -
995                                                                                 (1 << (b_OutputChannel % 8)));
996
997                                                                 }
998
999                              /****************************/
1000                                                                 /* Set the new output value */
1001                              /****************************/
1002
1003                                                                 outl(dw_StatusReg, devpriv->s_BoardInfos.ui_Address + 8 + ((b_OutputChannel / 8) * 4) + (64 * b_ModulNbr));
1004                                                         }
1005                                                 }
1006                                         } else {
1007                        /************************************/
1008                                                 /* The selected TTL output is wrong */
1009                        /************************************/
1010
1011                                                 DPRINTK(" The selected TTL output is wrong\n");
1012                                                 i_ReturnValue = -4;
1013                                         }
1014                                 } else {
1015                     /************************************/
1016                                         /* The selected TTL output is wrong */
1017                     /************************************/
1018
1019                                         DPRINTK("The selected TTL output is wrong\n");
1020                                         i_ReturnValue = -4;
1021                                 }
1022                         } else {
1023                  /***************************/
1024                                 /* TTL I/O not initialised */
1025                  /***************************/
1026
1027                                 DPRINTK("TTL I/O not initialised\n");
1028                                 i_ReturnValue = -5;
1029                         }
1030                 } else {
1031               /**************************************/
1032                         /* The module is not a TTL I/O module */
1033               /**************************************/
1034
1035                         DPRINTK("The module is not a TTL I/O module\n");
1036                         i_ReturnValue = -3;
1037                 }
1038         } else {
1039            /***********************/
1040                 /* Module number error */
1041            /***********************/
1042
1043                 DPRINTK("Module number error\n");
1044                 i_ReturnValue = -2;
1045         }
1046
1047         return i_ReturnValue;
1048 }