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 "../comedidev.h"
33 #include <linux/ioport.h>
34 #include <linux/delay.h>
38 #define PCM3724_SIZE 16
59 #define CR_B_MODE 0x04
62 #define CR_A_MODE(a) ((a)<<5)
65 struct pcm3724_board
{
66 const char *name
; /* driver name */
67 int dio
; /* num of DIO */
68 int numofports
; /* num of 8255 subdevices */
69 unsigned int IRQbits
; /* allowed interrupts */
70 unsigned int io_range
; /* len of IO space */
73 /* used to track configured dios */
79 static int subdev_8255_cb(int dir
, int port
, int data
, unsigned long arg
)
81 unsigned long iobase
= arg
;
83 /* printk("8255cb %d %d %d %lx\n", dir,port,data,arg); */
85 /* printk("8255 cb outb(%x, %lx)\n", data, iobase+port); */
86 outb(data
, iobase
+ port
);
89 inbres
= inb(iobase
+ port
);
90 /* printk("8255 cb inb(%lx) = %x\n", iobase+port, inbres); */
95 static int compute_buffer(int config
, int devno
, struct comedi_subdevice
*s
)
97 /* 1 in io_bits indicates output */
98 if (s
->io_bits
& 0x0000ff) {
104 if (s
->io_bits
& 0x00ff00) {
110 if (s
->io_bits
& 0xff0000) {
119 static void do_3724_config(struct comedi_device
*dev
,
120 struct comedi_subdevice
*s
, int chanspec
)
122 struct comedi_subdevice
*s_dio1
= &dev
->subdevices
[0];
123 struct comedi_subdevice
*s_dio2
= &dev
->subdevices
[1];
126 unsigned long port_8255_cfg
;
131 /* 1 in io_bits indicates output, 1 in config indicates input */
132 if (!(s
->io_bits
& 0x0000ff))
135 if (!(s
->io_bits
& 0x00ff00))
138 if (!(s
->io_bits
& 0xff0000))
141 buffer_config
= compute_buffer(0, 0, s_dio1
);
142 buffer_config
= compute_buffer(buffer_config
, 1, s_dio2
);
145 port_8255_cfg
= dev
->iobase
+ _8255_CR
;
147 port_8255_cfg
= dev
->iobase
+ SIZE_8255
+ _8255_CR
;
149 outb(buffer_config
, dev
->iobase
+ 8); /* update buffer register */
150 /* printk("pcm3724 buffer_config (%lx) %d, %x\n",
151 dev->iobase + _8255_CR, chanspec, buffer_config); */
153 outb(config
, port_8255_cfg
);
156 static void enable_chan(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
159 struct comedi_subdevice
*s_dio1
= &dev
->subdevices
[0];
162 struct priv_pcm3724
*priv
;
167 mask
= 1 << CR_CHAN(chanspec
);
173 if (priv
->dio_1
& 0xff0000)
176 if (priv
->dio_1
& 0xff00)
179 if (priv
->dio_1
& 0xff)
182 if (priv
->dio_2
& 0xff0000)
185 if (priv
->dio_2
& 0xff00)
188 if (priv
->dio_2
& 0xff)
191 /* printk("gate control %x\n", gatecfg); */
192 outb(gatecfg
, dev
->iobase
+ 9);
195 /* overriding the 8255 insn config */
196 static int subdev_3724_insn_config(struct comedi_device
*dev
,
197 struct comedi_subdevice
*s
,
198 struct comedi_insn
*insn
, unsigned int *data
)
203 mask
= 1 << CR_CHAN(insn
->chanspec
);
206 else if (mask
& 0x00ff00)
208 else if (mask
& 0x0f0000)
214 case INSN_CONFIG_DIO_INPUT
:
217 case INSN_CONFIG_DIO_OUTPUT
:
220 case INSN_CONFIG_DIO_QUERY
:
221 data
[1] = (s
->io_bits
& bits
) ? COMEDI_OUTPUT
: COMEDI_INPUT
;
228 do_3724_config(dev
, s
, insn
->chanspec
);
229 enable_chan(dev
, s
, insn
->chanspec
);
233 static int pcm3724_attach(struct comedi_device
*dev
,
234 struct comedi_devconfig
*it
)
236 const struct pcm3724_board
*board
= comedi_board(dev
);
237 struct comedi_subdevice
*s
;
238 unsigned long iobase
;
239 unsigned int iorange
;
240 int ret
, i
, n_subdevices
;
242 iobase
= it
->options
[0];
243 iorange
= board
->io_range
;
245 ret
= alloc_private(dev
, sizeof(struct priv_pcm3724
));
249 ((struct priv_pcm3724
*)(dev
->private))->dio_1
= 0;
250 ((struct priv_pcm3724
*)(dev
->private))->dio_2
= 0;
252 printk(KERN_INFO
"comedi%d: pcm3724: board=%s, 0x%03lx ", dev
->minor
,
253 board
->name
, iobase
);
254 if (!iobase
|| !request_region(iobase
, iorange
, "pcm3724")) {
255 printk("I/O port conflict\n");
259 dev
->iobase
= iobase
;
260 dev
->board_name
= board
->name
;
261 printk(KERN_INFO
"\n");
263 n_subdevices
= board
->numofports
;
265 ret
= comedi_alloc_subdevices(dev
, n_subdevices
);
269 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
270 s
= &dev
->subdevices
[i
];
271 subdev_8255_init(dev
, s
, subdev_8255_cb
,
272 (unsigned long)(dev
->iobase
+ SIZE_8255
* i
));
273 s
->insn_config
= subdev_3724_insn_config
;
278 static void pcm3724_detach(struct comedi_device
*dev
)
280 const struct pcm3724_board
*board
= comedi_board(dev
);
281 struct comedi_subdevice
*s
;
284 if (dev
->subdevices
) {
285 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
286 s
= &dev
->subdevices
[i
];
287 subdev_8255_cleanup(dev
, s
);
291 release_region(dev
->iobase
, board
->io_range
);
294 static const struct pcm3724_board boardtypes
[] = {
295 { "pcm3724", 48, 2, 0x00fc, PCM3724_SIZE
, },
298 static struct comedi_driver pcm3724_driver
= {
299 .driver_name
= "pcm3724",
300 .module
= THIS_MODULE
,
301 .attach
= pcm3724_attach
,
302 .detach
= pcm3724_detach
,
303 .board_name
= &boardtypes
[0].name
,
304 .num_names
= ARRAY_SIZE(boardtypes
),
305 .offset
= sizeof(struct pcm3724_board
),
307 module_comedi_driver(pcm3724_driver
);
309 MODULE_AUTHOR("Comedi http://www.comedi.org");
310 MODULE_DESCRIPTION("Comedi low-level driver");
311 MODULE_LICENSE("GPL");