2 comedi/drivers/pcm724.c
4 Drew Csillag <drew_csillag@yahoo.com>
6 hardware driver for Advantech card:
15 Description: Advantech PCM-3724
16 Author: Drew Csillag <drew_csillag@yahoo.com>
17 Devices: [Advantech] PCM-3724 (pcm724)
20 This is driver for digital I/O boards PCM-3724 with 48 DIO.
21 It needs 8255.o for operations and only immediate mode is supported.
22 See the source for configuration details.
24 Copy/pasted/hacked from pcm724.c
27 * check_driver overrides:
31 #include <linux/module.h>
32 #include "../comedidev.h"
36 #define PCM3724_SIZE 16
57 #define CR_B_MODE 0x04
60 #define CR_A_MODE(a) ((a)<<5)
63 /* used to track configured dios */
69 static int subdev_8255_cb(int dir
, int port
, int data
, unsigned long arg
)
71 unsigned long iobase
= arg
;
74 outb(data
, iobase
+ port
);
77 inbres
= inb(iobase
+ port
);
82 static int compute_buffer(int config
, int devno
, struct comedi_subdevice
*s
)
84 /* 1 in io_bits indicates output */
85 if (s
->io_bits
& 0x0000ff) {
91 if (s
->io_bits
& 0x00ff00) {
97 if (s
->io_bits
& 0xff0000) {
106 static void do_3724_config(struct comedi_device
*dev
,
107 struct comedi_subdevice
*s
, int chanspec
)
109 struct comedi_subdevice
*s_dio1
= &dev
->subdevices
[0];
110 struct comedi_subdevice
*s_dio2
= &dev
->subdevices
[1];
113 unsigned long port_8255_cfg
;
118 /* 1 in io_bits indicates output, 1 in config indicates input */
119 if (!(s
->io_bits
& 0x0000ff))
122 if (!(s
->io_bits
& 0x00ff00))
125 if (!(s
->io_bits
& 0xff0000))
128 buffer_config
= compute_buffer(0, 0, s_dio1
);
129 buffer_config
= compute_buffer(buffer_config
, 1, s_dio2
);
132 port_8255_cfg
= dev
->iobase
+ _8255_CR
;
134 port_8255_cfg
= dev
->iobase
+ SIZE_8255
+ _8255_CR
;
136 outb(buffer_config
, dev
->iobase
+ 8); /* update buffer register */
138 outb(config
, port_8255_cfg
);
141 static void enable_chan(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
144 struct priv_pcm3724
*priv
= dev
->private;
145 struct comedi_subdevice
*s_dio1
= &dev
->subdevices
[0];
151 mask
= 1 << CR_CHAN(chanspec
);
157 if (priv
->dio_1
& 0xff0000)
160 if (priv
->dio_1
& 0xff00)
163 if (priv
->dio_1
& 0xff)
166 if (priv
->dio_2
& 0xff0000)
169 if (priv
->dio_2
& 0xff00)
172 if (priv
->dio_2
& 0xff)
175 outb(gatecfg
, dev
->iobase
+ 9);
178 /* overriding the 8255 insn config */
179 static int subdev_3724_insn_config(struct comedi_device
*dev
,
180 struct comedi_subdevice
*s
,
181 struct comedi_insn
*insn
,
184 unsigned int chan
= CR_CHAN(insn
->chanspec
);
197 ret
= comedi_dio_insn_config(dev
, s
, insn
, data
, mask
);
201 do_3724_config(dev
, s
, insn
->chanspec
);
202 enable_chan(dev
, s
, insn
->chanspec
);
207 static int pcm3724_attach(struct comedi_device
*dev
,
208 struct comedi_devconfig
*it
)
210 struct priv_pcm3724
*priv
;
211 struct comedi_subdevice
*s
;
214 priv
= comedi_alloc_devpriv(dev
, sizeof(*priv
));
218 ret
= comedi_request_region(dev
, it
->options
[0], PCM3724_SIZE
);
222 ret
= comedi_alloc_subdevices(dev
, 2);
226 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
227 s
= &dev
->subdevices
[i
];
228 subdev_8255_init(dev
, s
, subdev_8255_cb
,
229 (unsigned long)(dev
->iobase
+ SIZE_8255
* i
));
230 s
->insn_config
= subdev_3724_insn_config
;
235 static struct comedi_driver pcm3724_driver
= {
236 .driver_name
= "pcm3724",
237 .module
= THIS_MODULE
,
238 .attach
= pcm3724_attach
,
239 .detach
= comedi_legacy_detach
,
241 module_comedi_driver(pcm3724_driver
);
243 MODULE_AUTHOR("Comedi http://www.comedi.org");
244 MODULE_DESCRIPTION("Comedi low-level driver");
245 MODULE_LICENSE("GPL");