3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
4 * Project manager: Eric Stolz
9 * Tel: +19(0)7223/9493-0
10 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
25 #include <linux/module.h>
26 #include <linux/pci.h>
28 #include "../comedidev.h"
29 #include "addi_watchdog.h"
30 #include "comedi_fc.h"
33 * PCI bar 1 I/O Register map - Digital input/output
35 #define APCI1516_DI_REG 0x00
36 #define APCI1516_DO_REG 0x04
39 * PCI bar 2 I/O Register map - Watchdog (APCI-1516 and APCI-2016)
41 #define APCI1516_WDOG_REG 0x00
43 enum apci1516_boardid
{
49 struct apci1516_boardinfo
{
56 static const struct apci1516_boardinfo apci1516_boardtypes
[] = {
74 struct apci1516_private
{
75 unsigned long wdog_iobase
;
78 static int apci1516_di_insn_bits(struct comedi_device
*dev
,
79 struct comedi_subdevice
*s
,
80 struct comedi_insn
*insn
,
83 data
[1] = inw(dev
->iobase
+ APCI1516_DI_REG
);
88 static int apci1516_do_insn_bits(struct comedi_device
*dev
,
89 struct comedi_subdevice
*s
,
90 struct comedi_insn
*insn
,
93 s
->state
= inw(dev
->iobase
+ APCI1516_DO_REG
);
95 if (comedi_dio_update_state(s
, data
))
96 outw(s
->state
, dev
->iobase
+ APCI1516_DO_REG
);
103 static int apci1516_reset(struct comedi_device
*dev
)
105 const struct apci1516_boardinfo
*this_board
= comedi_board(dev
);
106 struct apci1516_private
*devpriv
= dev
->private;
108 if (!this_board
->has_wdog
)
111 outw(0x0, dev
->iobase
+ APCI1516_DO_REG
);
113 addi_watchdog_reset(devpriv
->wdog_iobase
);
118 static int apci1516_auto_attach(struct comedi_device
*dev
,
119 unsigned long context
)
121 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
122 const struct apci1516_boardinfo
*this_board
= NULL
;
123 struct apci1516_private
*devpriv
;
124 struct comedi_subdevice
*s
;
127 if (context
< ARRAY_SIZE(apci1516_boardtypes
))
128 this_board
= &apci1516_boardtypes
[context
];
131 dev
->board_ptr
= this_board
;
132 dev
->board_name
= this_board
->name
;
134 devpriv
= comedi_alloc_devpriv(dev
, sizeof(*devpriv
));
138 ret
= comedi_pci_enable(dev
);
142 dev
->iobase
= pci_resource_start(pcidev
, 1);
143 devpriv
->wdog_iobase
= pci_resource_start(pcidev
, 2);
145 ret
= comedi_alloc_subdevices(dev
, 3);
149 /* Initialize the digital input subdevice */
150 s
= &dev
->subdevices
[0];
151 if (this_board
->di_nchan
) {
152 s
->type
= COMEDI_SUBD_DI
;
153 s
->subdev_flags
= SDF_READABLE
;
154 s
->n_chan
= this_board
->di_nchan
;
156 s
->range_table
= &range_digital
;
157 s
->insn_bits
= apci1516_di_insn_bits
;
159 s
->type
= COMEDI_SUBD_UNUSED
;
162 /* Initialize the digital output subdevice */
163 s
= &dev
->subdevices
[1];
164 if (this_board
->do_nchan
) {
165 s
->type
= COMEDI_SUBD_DO
;
166 s
->subdev_flags
= SDF_WRITEABLE
;
167 s
->n_chan
= this_board
->do_nchan
;
169 s
->range_table
= &range_digital
;
170 s
->insn_bits
= apci1516_do_insn_bits
;
172 s
->type
= COMEDI_SUBD_UNUSED
;
175 /* Initialize the watchdog subdevice */
176 s
= &dev
->subdevices
[2];
177 if (this_board
->has_wdog
) {
178 ret
= addi_watchdog_init(s
, devpriv
->wdog_iobase
);
182 s
->type
= COMEDI_SUBD_UNUSED
;
189 static void apci1516_detach(struct comedi_device
*dev
)
193 comedi_pci_disable(dev
);
196 static struct comedi_driver apci1516_driver
= {
197 .driver_name
= "addi_apci_1516",
198 .module
= THIS_MODULE
,
199 .auto_attach
= apci1516_auto_attach
,
200 .detach
= apci1516_detach
,
203 static int apci1516_pci_probe(struct pci_dev
*dev
,
204 const struct pci_device_id
*id
)
206 return comedi_pci_auto_config(dev
, &apci1516_driver
, id
->driver_data
);
209 static DEFINE_PCI_DEVICE_TABLE(apci1516_pci_table
) = {
210 { PCI_VDEVICE(ADDIDATA
, 0x1000), BOARD_APCI1016
},
211 { PCI_VDEVICE(ADDIDATA
, 0x1001), BOARD_APCI1516
},
212 { PCI_VDEVICE(ADDIDATA
, 0x1002), BOARD_APCI2016
},
215 MODULE_DEVICE_TABLE(pci
, apci1516_pci_table
);
217 static struct pci_driver apci1516_pci_driver
= {
218 .name
= "addi_apci_1516",
219 .id_table
= apci1516_pci_table
,
220 .probe
= apci1516_pci_probe
,
221 .remove
= comedi_pci_auto_unconfig
,
223 module_comedi_pci_driver(apci1516_driver
, apci1516_pci_driver
);
225 MODULE_DESCRIPTION("ADDI-DATA APCI-1016/1516/2016, 16 channel DIO boards");
226 MODULE_AUTHOR("Comedi http://www.comedi.org");
227 MODULE_LICENSE("GPL");