2 comedi/drivers/pcl726.c
4 hardware driver for Advantech cards:
5 card: PCL-726, PCL-727, PCL-728
6 driver: pcl726, pcl727, pcl728
8 card: ACL-6126, ACL-6128
9 driver: acl6126, acl6128
11 COMEDI - Linux Control and Measurement Device Interface
12 Copyright (C) 1998 David A. Schleef <ds@schleef.org>
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 Description: Advantech PCL-726 & compatibles
34 Devices: [Advantech] PCL-726 (pcl726), PCL-727 (pcl727), PCL-728 (pcl728),
35 [ADLink] ACL-6126 (acl6126), ACL-6128 (acl6128)
37 Interrupts are not supported.
41 [2]...[7] - D/A output range for channel 1-6:
42 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: +/-10V,
43 4: 4-20mA, 5: unknown (external reference)
47 [2]...[13] - D/A output range for channel 1-12:
48 0: 0-5V, 1: 0-10V, 2: +/-5V,
51 Options for PCL-728 and ACL-6128:
53 [2], [3] - D/A output range for channel 1 and 2:
54 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: +/-10V,
59 [1] - IRQ (0=disable, 3, 5, 6, 7, 9, 10, 11, 12, 15) (currently ignored)
60 [2]...[7] - D/A output range for channel 1-6:
61 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: +/-10V,
66 Thanks to Circuit Specialists for having programming info (!) on
67 their web page. (http://www.cir.com/)
70 #include "../comedidev.h"
72 #include <linux/ioport.h>
74 #undef ACL6126_IRQ /* no interrupt support (yet) */
76 #define PCL726_SIZE 16
77 #define PCL727_SIZE 32
80 #define PCL726_DAC0_HI 0
81 #define PCL726_DAC0_LO 1
83 #define PCL726_DO_HI 12
84 #define PCL726_DO_LO 13
85 #define PCL726_DI_HI 14
86 #define PCL726_DI_LO 15
88 #define PCL727_DO_HI 24
89 #define PCL727_DO_LO 25
90 #define PCL727_DI_HI 0
91 #define PCL727_DI_LO 1
93 static const struct comedi_lrange range_4_20mA
= { 1, {RANGE_mA(4, 20)} };
94 static const struct comedi_lrange range_0_20mA
= { 1, {RANGE_mA(0, 20)} };
96 static const struct comedi_lrange
*const rangelist_726
[] = {
97 &range_unipolar5
, &range_unipolar10
,
98 &range_bipolar5
, &range_bipolar10
,
99 &range_4_20mA
, &range_unknown
102 static const struct comedi_lrange
*const rangelist_727
[] = {
103 &range_unipolar5
, &range_unipolar10
,
108 static const struct comedi_lrange
*const rangelist_728
[] = {
109 &range_unipolar5
, &range_unipolar10
,
110 &range_bipolar5
, &range_bipolar10
,
111 &range_4_20mA
, &range_0_20mA
114 struct pcl726_board
{
116 const char *name
; /* driver name */
117 int n_aochan
; /* num of D/A chans */
118 int num_of_ranges
; /* num of ranges */
119 unsigned int IRQbits
; /* allowed interrupts */
120 unsigned int io_range
; /* len of IO space */
121 char have_dio
; /* 1=card have DI/DO ports */
122 int di_hi
; /* ports for DI/DO operations */
126 const struct comedi_lrange
*const *range_type_list
;
127 /* list of supported ranges */
130 static const struct pcl726_board boardtypes
[] = {
131 {"pcl726", 6, 6, 0x0000, PCL726_SIZE
, 1,
132 PCL726_DI_HI
, PCL726_DI_LO
, PCL726_DO_HI
, PCL726_DO_LO
,
134 {"pcl727", 12, 4, 0x0000, PCL727_SIZE
, 1,
135 PCL727_DI_HI
, PCL727_DI_LO
, PCL727_DO_HI
, PCL727_DO_LO
,
137 {"pcl728", 2, 6, 0x0000, PCL728_SIZE
, 0,
140 {"acl6126", 6, 5, 0x96e8, PCL726_SIZE
, 1,
141 PCL726_DI_HI
, PCL726_DI_LO
, PCL726_DO_HI
, PCL726_DO_LO
,
143 {"acl6128", 2, 6, 0x0000, PCL728_SIZE
, 0,
148 struct pcl726_private
{
151 const struct comedi_lrange
*rangelist
[12];
152 unsigned int ao_readback
[12];
155 static int pcl726_ao_insn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
156 struct comedi_insn
*insn
, unsigned int *data
)
158 struct pcl726_private
*devpriv
= dev
->private;
161 int chan
= CR_CHAN(insn
->chanspec
);
163 for (n
= 0; n
< insn
->n
; n
++) {
165 hi
= (data
[n
] >> 8) & 0xf;
166 if (devpriv
->bipolar
[chan
])
169 * the programming info did not say which order
170 * to write bytes. switch the order of the next
171 * two lines if you get glitches.
173 outb(hi
, dev
->iobase
+ PCL726_DAC0_HI
+ 2 * chan
);
174 outb(lo
, dev
->iobase
+ PCL726_DAC0_LO
+ 2 * chan
);
175 devpriv
->ao_readback
[chan
] = data
[n
];
181 static int pcl726_ao_insn_read(struct comedi_device
*dev
,
182 struct comedi_subdevice
*s
,
183 struct comedi_insn
*insn
, unsigned int *data
)
185 struct pcl726_private
*devpriv
= dev
->private;
186 int chan
= CR_CHAN(insn
->chanspec
);
189 for (n
= 0; n
< insn
->n
; n
++)
190 data
[n
] = devpriv
->ao_readback
[chan
];
194 static int pcl726_di_insn_bits(struct comedi_device
*dev
,
195 struct comedi_subdevice
*s
,
196 struct comedi_insn
*insn
, unsigned int *data
)
198 const struct pcl726_board
*board
= comedi_board(dev
);
200 data
[1] = inb(dev
->iobase
+ board
->di_lo
) |
201 (inb(dev
->iobase
+ board
->di_hi
) << 8);
206 static int pcl726_do_insn_bits(struct comedi_device
*dev
,
207 struct comedi_subdevice
*s
,
208 struct comedi_insn
*insn
, unsigned int *data
)
210 const struct pcl726_board
*board
= comedi_board(dev
);
213 s
->state
&= ~data
[0];
214 s
->state
|= data
[0] & data
[1];
216 if (data
[1] & 0x00ff)
217 outb(s
->state
& 0xff, dev
->iobase
+ board
->do_lo
);
218 if (data
[1] & 0xff00)
219 outb((s
->state
>> 8), dev
->iobase
+ board
->do_hi
);
226 static int pcl726_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
228 const struct pcl726_board
*board
= comedi_board(dev
);
229 struct pcl726_private
*devpriv
;
230 struct comedi_subdevice
*s
;
231 unsigned long iobase
;
232 unsigned int iorange
;
238 iobase
= it
->options
[0];
239 iorange
= board
->io_range
;
240 printk(KERN_WARNING
"comedi%d: pcl726: board=%s, 0x%03lx ", dev
->minor
,
241 board
->name
, iobase
);
242 if (!request_region(iobase
, iorange
, "pcl726")) {
243 printk(KERN_WARNING
"I/O port conflict\n");
247 dev
->iobase
= iobase
;
249 dev
->board_name
= board
->name
;
251 devpriv
= kzalloc(sizeof(*devpriv
), GFP_KERNEL
);
254 dev
->private = devpriv
;
256 for (i
= 0; i
< 12; i
++) {
257 devpriv
->bipolar
[i
] = 0;
258 devpriv
->rangelist
[i
] = &range_unknown
;
263 if (boardtypes
[board
].IRQbits
!= 0) { /* board support IRQ */
264 irq
= it
->options
[1];
265 devpriv
->first_chan
= 2;
266 if (irq
) { /* we want to use IRQ */
267 if (((1 << irq
) & boardtypes
[board
].IRQbits
) == 0) {
269 ", IRQ %d is out of allowed range,"
270 " DISABLING IT", irq
);
271 irq
= 0; /* Bad IRQ */
273 if (request_irq(irq
, interrupt_pcl818
, 0,
276 ", unable to allocate IRQ %d,"
277 " DISABLING IT", irq
);
278 irq
= 0; /* Can't use IRQ */
280 printk(", irq=%d", irq
);
291 ret
= comedi_alloc_subdevices(dev
, 3);
295 s
= &dev
->subdevices
[0];
297 s
->type
= COMEDI_SUBD_AO
;
298 s
->subdev_flags
= SDF_WRITABLE
| SDF_GROUND
;
299 s
->n_chan
= board
->n_aochan
;
302 s
->insn_write
= pcl726_ao_insn
;
303 s
->insn_read
= pcl726_ao_insn_read
;
304 s
->range_table_list
= devpriv
->rangelist
;
305 for (i
= 0; i
< board
->n_aochan
; i
++) {
308 j
= it
->options
[2 + 1];
309 if ((j
< 0) || (j
>= board
->num_of_ranges
)) {
311 ("Invalid range for channel %d! Must be 0<=%d<%d\n",
312 i
, j
, board
->num_of_ranges
- 1);
315 devpriv
->rangelist
[i
] = board
->range_type_list
[j
];
316 if (devpriv
->rangelist
[i
]->range
[0].min
==
317 -devpriv
->rangelist
[i
]->range
[0].max
)
318 devpriv
->bipolar
[i
] = 1; /* bipolar range */
321 s
= &dev
->subdevices
[1];
323 if (!board
->have_dio
) {
324 s
->type
= COMEDI_SUBD_UNUSED
;
326 s
->type
= COMEDI_SUBD_DI
;
327 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
;
331 s
->insn_bits
= pcl726_di_insn_bits
;
332 s
->range_table
= &range_digital
;
335 s
= &dev
->subdevices
[2];
337 if (!board
->have_dio
) {
338 s
->type
= COMEDI_SUBD_UNUSED
;
340 s
->type
= COMEDI_SUBD_DO
;
341 s
->subdev_flags
= SDF_WRITABLE
| SDF_GROUND
;
345 s
->insn_bits
= pcl726_do_insn_bits
;
346 s
->range_table
= &range_digital
;
352 static void pcl726_detach(struct comedi_device
*dev
)
354 const struct pcl726_board
*board
= comedi_board(dev
);
358 free_irq(dev
->irq
, dev
);
361 release_region(dev
->iobase
, board
->io_range
);
364 static struct comedi_driver pcl726_driver
= {
365 .driver_name
= "pcl726",
366 .module
= THIS_MODULE
,
367 .attach
= pcl726_attach
,
368 .detach
= pcl726_detach
,
369 .board_name
= &boardtypes
[0].name
,
370 .num_names
= ARRAY_SIZE(boardtypes
),
371 .offset
= sizeof(struct pcl726_board
),
373 module_comedi_driver(pcl726_driver
);
375 MODULE_AUTHOR("Comedi http://www.comedi.org");
376 MODULE_DESCRIPTION("Comedi low-level driver");
377 MODULE_LICENSE("GPL");