H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * COMEDI driver for the ADLINK PCI-723x/743x series boards. |
| 3 | * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com> |
| 4 | * |
| 5 | * Based on the adl_pci7230 driver written by: |
| 6 | * David Fernandez <dfcastelao@gmail.com> |
| 7 | * and the adl_pci7432 driver written by: |
| 8 | * Michel Lachaine <mike@mikelachaine.ca> |
| 9 | * |
| 10 | * COMEDI - Linux Control and Measurement Device Interface |
| 11 | * Copyright (C) 2000 David A. Schleef <ds@schleef.org> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | /* |
| 25 | Driver: adl_pci7x3x |
| 26 | Description: 32/64-Channel Isolated Digital I/O Boards |
| 27 | Devices: (ADLink) PCI-7230 [adl_pci7230] - 16 input / 16 output |
| 28 | (ADLink) PCI-7233 [adl_pci7233] - 32 input |
| 29 | (ADLink) PCI-7234 [adl_pci7234] - 32 output |
| 30 | (ADLink) PCI-7432 [adl_pci7432] - 32 input / 32 output |
| 31 | (ADLink) PCI-7433 [adl_pci7433] - 64 input |
| 32 | (ADLink) PCI-7434 [adl_pci7434] - 64 output |
| 33 | Author: H Hartley Sweeten <hsweeten@visionengravers.com> |
| 34 | Updated: Thu, 02 Aug 2012 14:27:46 -0700 |
| 35 | Status: untested |
| 36 | |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 37 | The PCI-7230, PCI-7432 and PCI-7433 boards also support external |
| 38 | interrupt signals on digital input channels 0 and 1. The PCI-7233 |
| 39 | has dual-interrupt sources for change-of-state (COS) on any 16 |
| 40 | digital input channels of LSB and for COS on any 16 digital input |
| 41 | lines of MSB. Interrupts are not currently supported by this |
| 42 | driver. |
| 43 | |
H Hartley Sweeten | 4a79f73 | 2013-02-04 17:13:01 -0700 | [diff] [blame] | 44 | Configuration Options: not applicable, uses comedi PCI auto config |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 45 | */ |
| 46 | |
H Hartley Sweeten | ce157f8 | 2013-06-24 17:04:43 -0700 | [diff] [blame] | 47 | #include <linux/module.h> |
H Hartley Sweeten | 33782dd | 2013-01-30 15:22:21 -0700 | [diff] [blame] | 48 | #include <linux/pci.h> |
| 49 | |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 50 | #include "../comedidev.h" |
| 51 | |
| 52 | /* |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 53 | * Register I/O map (32-bit access only) |
| 54 | */ |
| 55 | #define PCI7X3X_DIO_REG 0x00 |
| 56 | #define PCI743X_DIO_REG 0x04 |
| 57 | |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 58 | enum apci1516_boardid { |
| 59 | BOARD_PCI7230, |
| 60 | BOARD_PCI7233, |
| 61 | BOARD_PCI7234, |
| 62 | BOARD_PCI7432, |
| 63 | BOARD_PCI7433, |
| 64 | BOARD_PCI7434, |
| 65 | }; |
| 66 | |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 67 | struct adl_pci7x3x_boardinfo { |
| 68 | const char *name; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 69 | int nsubdevs; |
| 70 | int di_nchan; |
| 71 | int do_nchan; |
| 72 | }; |
| 73 | |
| 74 | static const struct adl_pci7x3x_boardinfo adl_pci7x3x_boards[] = { |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 75 | [BOARD_PCI7230] = { |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 76 | .name = "adl_pci7230", |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 77 | .nsubdevs = 2, |
| 78 | .di_nchan = 16, |
| 79 | .do_nchan = 16, |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 80 | }, |
| 81 | [BOARD_PCI7233] = { |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 82 | .name = "adl_pci7233", |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 83 | .nsubdevs = 1, |
| 84 | .di_nchan = 32, |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 85 | }, |
| 86 | [BOARD_PCI7234] = { |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 87 | .name = "adl_pci7234", |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 88 | .nsubdevs = 1, |
| 89 | .do_nchan = 32, |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 90 | }, |
| 91 | [BOARD_PCI7432] = { |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 92 | .name = "adl_pci7432", |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 93 | .nsubdevs = 2, |
| 94 | .di_nchan = 32, |
| 95 | .do_nchan = 32, |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 96 | }, |
| 97 | [BOARD_PCI7433] = { |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 98 | .name = "adl_pci7433", |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 99 | .nsubdevs = 2, |
| 100 | .di_nchan = 64, |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 101 | }, |
| 102 | [BOARD_PCI7434] = { |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 103 | .name = "adl_pci7434", |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 104 | .nsubdevs = 2, |
| 105 | .do_nchan = 64, |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | static int adl_pci7x3x_do_insn_bits(struct comedi_device *dev, |
| 110 | struct comedi_subdevice *s, |
| 111 | struct comedi_insn *insn, |
| 112 | unsigned int *data) |
| 113 | { |
H Hartley Sweeten | 69af599 | 2012-08-14 13:45:53 -0700 | [diff] [blame] | 114 | unsigned long reg = (unsigned long)s->private; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 115 | |
H Hartley Sweeten | 97f4289 | 2013-08-30 11:05:58 -0700 | [diff] [blame] | 116 | if (comedi_dio_update_state(s, data)) |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 117 | outl(s->state, dev->iobase + reg); |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 118 | |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 119 | data[1] = s->state; |
| 120 | |
| 121 | return insn->n; |
| 122 | } |
| 123 | |
| 124 | static int adl_pci7x3x_di_insn_bits(struct comedi_device *dev, |
| 125 | struct comedi_subdevice *s, |
| 126 | struct comedi_insn *insn, |
| 127 | unsigned int *data) |
| 128 | { |
H Hartley Sweeten | 69af599 | 2012-08-14 13:45:53 -0700 | [diff] [blame] | 129 | unsigned long reg = (unsigned long)s->private; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 130 | |
| 131 | data[1] = inl(dev->iobase + reg); |
| 132 | |
| 133 | return insn->n; |
| 134 | } |
| 135 | |
Bill Pemberton | a690b7e | 2012-11-19 13:21:58 -0500 | [diff] [blame] | 136 | static int adl_pci7x3x_auto_attach(struct comedi_device *dev, |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 137 | unsigned long context) |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 138 | { |
Ian Abbott | 750af5e | 2012-10-30 13:30:04 +0000 | [diff] [blame] | 139 | struct pci_dev *pcidev = comedi_to_pci_dev(dev); |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 140 | const struct adl_pci7x3x_boardinfo *board = NULL; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 141 | struct comedi_subdevice *s; |
| 142 | int subdev; |
| 143 | int nchan; |
| 144 | int ret; |
| 145 | |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 146 | if (context < ARRAY_SIZE(adl_pci7x3x_boards)) |
| 147 | board = &adl_pci7x3x_boards[context]; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 148 | if (!board) |
| 149 | return -ENODEV; |
| 150 | dev->board_ptr = board; |
| 151 | dev->board_name = board->name; |
| 152 | |
H Hartley Sweeten | 818f569 | 2013-03-13 10:36:31 -0700 | [diff] [blame] | 153 | ret = comedi_pci_enable(dev); |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 154 | if (ret) |
| 155 | return ret; |
| 156 | dev->iobase = pci_resource_start(pcidev, 2); |
| 157 | |
| 158 | /* |
| 159 | * One or two subdevices are setup by this driver depending on |
| 160 | * the number of digital inputs and/or outputs provided by the |
| 161 | * board. Each subdevice has a maximum of 32 channels. |
| 162 | * |
| 163 | * PCI-7230 - 2 subdevices: 0 - 16 input, 1 - 16 output |
| 164 | * PCI-7233 - 1 subdevice: 0 - 32 input |
| 165 | * PCI-7234 - 1 subdevice: 0 - 32 output |
| 166 | * PCI-7432 - 2 subdevices: 0 - 32 input, 1 - 32 output |
| 167 | * PCI-7433 - 2 subdevices: 0 - 32 input, 1 - 32 input |
| 168 | * PCI-7434 - 2 subdevices: 0 - 32 output, 1 - 32 output |
| 169 | */ |
| 170 | ret = comedi_alloc_subdevices(dev, board->nsubdevs); |
| 171 | if (ret) |
| 172 | return ret; |
| 173 | |
| 174 | subdev = 0; |
| 175 | |
| 176 | if (board->di_nchan) { |
| 177 | nchan = min(board->di_nchan, 32); |
| 178 | |
H Hartley Sweeten | 2bac8ab | 2012-09-05 18:24:52 -0700 | [diff] [blame] | 179 | s = &dev->subdevices[subdev]; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 180 | /* Isolated digital inputs 0 to 15/31 */ |
| 181 | s->type = COMEDI_SUBD_DI; |
| 182 | s->subdev_flags = SDF_READABLE; |
| 183 | s->n_chan = nchan; |
| 184 | s->maxdata = 1; |
| 185 | s->insn_bits = adl_pci7x3x_di_insn_bits; |
| 186 | s->range_table = &range_digital; |
| 187 | |
| 188 | s->private = (void *)PCI7X3X_DIO_REG; |
| 189 | |
| 190 | subdev++; |
| 191 | |
| 192 | nchan = board->di_nchan - nchan; |
| 193 | if (nchan) { |
H Hartley Sweeten | 2bac8ab | 2012-09-05 18:24:52 -0700 | [diff] [blame] | 194 | s = &dev->subdevices[subdev]; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 195 | /* Isolated digital inputs 32 to 63 */ |
| 196 | s->type = COMEDI_SUBD_DI; |
| 197 | s->subdev_flags = SDF_READABLE; |
| 198 | s->n_chan = nchan; |
| 199 | s->maxdata = 1; |
| 200 | s->insn_bits = adl_pci7x3x_di_insn_bits; |
| 201 | s->range_table = &range_digital; |
| 202 | |
| 203 | s->private = (void *)PCI743X_DIO_REG; |
| 204 | |
| 205 | subdev++; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | if (board->do_nchan) { |
| 210 | nchan = min(board->do_nchan, 32); |
| 211 | |
H Hartley Sweeten | 2bac8ab | 2012-09-05 18:24:52 -0700 | [diff] [blame] | 212 | s = &dev->subdevices[subdev]; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 213 | /* Isolated digital outputs 0 to 15/31 */ |
| 214 | s->type = COMEDI_SUBD_DO; |
| 215 | s->subdev_flags = SDF_WRITABLE; |
| 216 | s->n_chan = nchan; |
| 217 | s->maxdata = 1; |
| 218 | s->insn_bits = adl_pci7x3x_do_insn_bits; |
| 219 | s->range_table = &range_digital; |
| 220 | |
| 221 | s->private = (void *)PCI7X3X_DIO_REG; |
| 222 | |
| 223 | subdev++; |
| 224 | |
| 225 | nchan = board->do_nchan - nchan; |
| 226 | if (nchan) { |
H Hartley Sweeten | 2bac8ab | 2012-09-05 18:24:52 -0700 | [diff] [blame] | 227 | s = &dev->subdevices[subdev]; |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 228 | /* Isolated digital outputs 32 to 63 */ |
| 229 | s->type = COMEDI_SUBD_DO; |
| 230 | s->subdev_flags = SDF_WRITABLE; |
| 231 | s->n_chan = nchan; |
| 232 | s->maxdata = 1; |
| 233 | s->insn_bits = adl_pci7x3x_do_insn_bits; |
| 234 | s->range_table = &range_digital; |
| 235 | |
| 236 | s->private = (void *)PCI743X_DIO_REG; |
| 237 | |
| 238 | subdev++; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | dev_info(dev->class_dev, "%s attached (%d inputs/%d outputs)\n", |
| 243 | dev->board_name, board->di_nchan, board->do_nchan); |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 248 | static struct comedi_driver adl_pci7x3x_driver = { |
| 249 | .driver_name = "adl_pci7x3x", |
| 250 | .module = THIS_MODULE, |
Ian Abbott | 750af5e | 2012-10-30 13:30:04 +0000 | [diff] [blame] | 251 | .auto_attach = adl_pci7x3x_auto_attach, |
H Hartley Sweeten | 7f072f5 | 2013-03-13 10:35:51 -0700 | [diff] [blame] | 252 | .detach = comedi_pci_disable, |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
Bill Pemberton | a690b7e | 2012-11-19 13:21:58 -0500 | [diff] [blame] | 255 | static int adl_pci7x3x_pci_probe(struct pci_dev *dev, |
H Hartley Sweeten | b8f4ac2 | 2013-03-05 09:53:41 -0700 | [diff] [blame] | 256 | const struct pci_device_id *id) |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 257 | { |
H Hartley Sweeten | b8f4ac2 | 2013-03-05 09:53:41 -0700 | [diff] [blame] | 258 | return comedi_pci_auto_config(dev, &adl_pci7x3x_driver, |
| 259 | id->driver_data); |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 260 | } |
| 261 | |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 262 | static DEFINE_PCI_DEVICE_TABLE(adl_pci7x3x_pci_table) = { |
H Hartley Sweeten | b5357e6 | 2013-03-05 09:59:07 -0700 | [diff] [blame] | 263 | { PCI_VDEVICE(ADLINK, 0x7230), BOARD_PCI7230 }, |
| 264 | { PCI_VDEVICE(ADLINK, 0x7233), BOARD_PCI7233 }, |
| 265 | { PCI_VDEVICE(ADLINK, 0x7234), BOARD_PCI7234 }, |
| 266 | { PCI_VDEVICE(ADLINK, 0x7432), BOARD_PCI7432 }, |
| 267 | { PCI_VDEVICE(ADLINK, 0x7433), BOARD_PCI7433 }, |
| 268 | { PCI_VDEVICE(ADLINK, 0x7434), BOARD_PCI7434 }, |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 269 | { 0 } |
| 270 | }; |
| 271 | MODULE_DEVICE_TABLE(pci, adl_pci7x3x_pci_table); |
| 272 | |
| 273 | static struct pci_driver adl_pci7x3x_pci_driver = { |
| 274 | .name = "adl_pci7x3x", |
| 275 | .id_table = adl_pci7x3x_pci_table, |
| 276 | .probe = adl_pci7x3x_pci_probe, |
Peter Huewe | 9901a4d | 2013-01-22 23:40:03 +0100 | [diff] [blame] | 277 | .remove = comedi_pci_auto_unconfig, |
H Hartley Sweeten | 8f567c3 | 2012-08-03 10:28:18 -0700 | [diff] [blame] | 278 | }; |
| 279 | module_comedi_pci_driver(adl_pci7x3x_driver, adl_pci7x3x_pci_driver); |
| 280 | |
| 281 | MODULE_DESCRIPTION("ADLINK PCI-723x/743x Isolated Digital I/O boards"); |
| 282 | MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>"); |
| 283 | MODULE_LICENSE("GPL"); |