aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1723.c149
1 files changed, 87 insertions, 62 deletions
diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c
index 6b0b7eda3be..1644490ed0a 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -60,35 +60,57 @@ TODO:
60#define IORANGE_1723 0x2A 60#define IORANGE_1723 0x2A
61 61
62/* all the registers for the pci1723 board */ 62/* all the registers for the pci1723 board */
63#define PCI1723_DA(N) ((N)<<1) /* W: D/A register N (0 to 7) */ 63#define PCI1723_DA(N) ((N)<<1) /* W: D/A register N (0 to 7) */
64 64
65#define PCI1723_SYN_SET 0x12 /*synchronized set register */ 65#define PCI1723_SYN_SET 0x12 /* synchronized set register */
66#define PCI1723_ALL_CHNNELE_SYN_STROBE 0x12 /*synchronized status register */ 66#define PCI1723_ALL_CHNNELE_SYN_STROBE 0x12
67 67 /* synchronized status register */
68#define PCI1723_RANGE_CALIBRATION_MODE 0x14 /* range and calibration mode */ 68
69#define PCI1723_RANGE_CALIBRATION_STATUS 0x14 /* range and calibration status */ 69#define PCI1723_RANGE_CALIBRATION_MODE 0x14
70 70 /* range and calibration mode */
71#define PCI1723_CONTROL_CMD_CALIBRATION_FUN 0x16 /* SADC control command for calibration function */ 71#define PCI1723_RANGE_CALIBRATION_STATUS 0x14
72#define PCI1723_STATUS_CMD_CALIBRATION_FUN 0x16 /* SADC control status for calibration function */ 72 /* range and calibration status */
73 73
74#define PCI1723_CALIBRATION_PARA_STROBE 0x18 /* Calibration parameter strobe */ 74#define PCI1723_CONTROL_CMD_CALIBRATION_FUN 0x16
75 /*
76 * SADC control command for
77 * calibration function
78 */
79#define PCI1723_STATUS_CMD_CALIBRATION_FUN 0x16
80 /*
81 * SADC control status for
82 * calibration function
83 */
84
85#define PCI1723_CALIBRATION_PARA_STROBE 0x18
86 /* Calibration parameter strobe */
75 87
76#define PCI1723_DIGITAL_IO_PORT_SET 0x1A /* Digital I/O port setting */ 88#define PCI1723_DIGITAL_IO_PORT_SET 0x1A /* Digital I/O port setting */
77#define PCI1723_DIGITAL_IO_PORT_MODE 0x1A /* Digital I/O port mode */ 89#define PCI1723_DIGITAL_IO_PORT_MODE 0x1A /* Digital I/O port mode */
78 90
79#define PCI1723_WRITE_DIGITAL_OUTPUT_CMD 0x1C /* Write digital output command */ 91#define PCI1723_WRITE_DIGITAL_OUTPUT_CMD 0x1C
92 /* Write digital output command */
80#define PCI1723_READ_DIGITAL_INPUT_DATA 0x1C /* Read digital input data */ 93#define PCI1723_READ_DIGITAL_INPUT_DATA 0x1C /* Read digital input data */
81 94
82#define PCI1723_WRITE_CAL_CMD 0x1E /* Write calibration command */ 95#define PCI1723_WRITE_CAL_CMD 0x1E /* Write calibration command */
83#define PCI1723_READ_CAL_STATUS 0x1E /* Read calibration status */ 96#define PCI1723_READ_CAL_STATUS 0x1E /* Read calibration status */
84 97
85#define PCI1723_SYN_STROBE 0x20 /* Synchronized strobe */ 98#define PCI1723_SYN_STROBE 0x20 /* Synchronized strobe */
86 99
87#define PCI1723_RESET_ALL_CHN_STROBE 0x22 /* Reset all D/A channels strobe */ 100#define PCI1723_RESET_ALL_CHN_STROBE 0x22
101 /* Reset all D/A channels strobe */
88 102
89#define PCI1723_RESET_CAL_CONTROL_STROBE 0x24 /* Reset the calibration controller strobe */ 103#define PCI1723_RESET_CAL_CONTROL_STROBE 0x24
104 /*
105 * Reset the calibration
106 * controller strobe
107 */
90 108
91#define PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE 0x26 /* Change D/A channels output type strobe */ 109#define PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE 0x26
110 /*
111 * Change D/A channels output
112 * type strobe
113 */
92 114
93#define PCI1723_SELECT_CALIBRATION 0x28 /* Select the calibration Ref_V */ 115#define PCI1723_SELECT_CALIBRATION 0x28 /* Select the calibration Ref_V */
94 116
@@ -104,14 +126,14 @@ static const struct comedi_lrange range_pci1723 = { 1, {
104 */ 126 */
105struct pci1723_board { 127struct pci1723_board {
106 const char *name; 128 const char *name;
107 int vendor_id; /* PCI vendor a device ID of card */ 129 int vendor_id; /* PCI vendor a device ID of card */
108 int device_id; 130 int device_id;
109 int iorange; 131 int iorange;
110 char cardtype; 132 char cardtype;
111 int n_aochan; /* num of D/A chans */ 133 int n_aochan; /* num of D/A chans */
112 int n_diochan; /* num of DIO chans */ 134 int n_diochan; /* num of DIO chans */
113 int ao_maxdata; /* resolution of D/A */ 135 int ao_maxdata; /* resolution of D/A */
114 const struct comedi_lrange *rangelist_ao; /* rangelist for D/A */ 136 const struct comedi_lrange *rangelist_ao; /* rangelist for D/A */
115}; 137};
116 138
117static const struct pci1723_board boardtypes[] = { 139static const struct pci1723_board boardtypes[] = {
@@ -128,8 +150,10 @@ static const struct pci1723_board boardtypes[] = {
128 }, 150 },
129}; 151};
130 152
131/* This is used by modprobe to translate PCI IDs to drivers. Should 153/*
132 * only be used for PCI and ISA-PnP devices */ 154 * This is used by modprobe to translate PCI IDs to drivers.
155 * Should only be used for PCI and ISA-PnP devices
156 */
133static DEFINE_PCI_DEVICE_TABLE(pci1723_pci_table) = { 157static DEFINE_PCI_DEVICE_TABLE(pci1723_pci_table) = {
134 { 158 {
135 PCI_VENDOR_ID_ADVANTECH, 0x1723, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, { 159 PCI_VENDOR_ID_ADVANTECH, 0x1723, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {
@@ -157,47 +181,47 @@ static struct comedi_driver driver_pci1723 = {
157 .detach = pci1723_detach, 181 .detach = pci1723_detach,
158}; 182};
159 183
160/* this structure is for data unique to this hardware driver. */ 184/* This structure is for data unique to this hardware driver. */
161struct pci1723_private { 185struct pci1723_private {
162 int valid; /* card is usable; */ 186 int valid; /* card is usable; */
163 187
164 struct pci_dev *pcidev; 188 struct pci_dev *pcidev;
165 unsigned char da_range[8]; /* D/A output range for each channel */ 189 unsigned char da_range[8]; /* D/A output range for each channel */
166 190
167 short ao_data[8]; /* data output buffer */ 191 short ao_data[8]; /* data output buffer */
168}; 192};
169 193
170/*the following macro to make it easy to 194/* The following macro to make it easy to access the private structure. */
171* access the private structure.
172*/
173#define devpriv ((struct pci1723_private *)dev->private) 195#define devpriv ((struct pci1723_private *)dev->private)
174 196
175#define this_board boardtypes 197#define this_board boardtypes
176 198
177/* 199/*
178 * the pci1723 card reset; 200 * The pci1723 card reset;
179 */ 201 */
180static int pci1723_reset(struct comedi_device *dev) 202static int pci1723_reset(struct comedi_device *dev)
181{ 203{
182 int i; 204 int i;
183 DPRINTK("adv_pci1723 EDBG: BGN: pci1723_reset(...)\n"); 205 DPRINTK("adv_pci1723 EDBG: BGN: pci1723_reset(...)\n");
184 206
185 outw(0x01, dev->iobase + PCI1723_SYN_SET); /* set synchronous output mode */ 207 outw(0x01, dev->iobase + PCI1723_SYN_SET);
208 /* set synchronous output mode */
186 209
187 for (i = 0; i < 8; i++) { 210 for (i = 0; i < 8; i++) {
188 /* set all outputs to 0V */ 211 /* set all outputs to 0V */
189 devpriv->ao_data[i] = 0x8000; 212 devpriv->ao_data[i] = 0x8000;
190 outw(devpriv->ao_data[i], dev->iobase + PCI1723_DA(i)); 213 outw(devpriv->ao_data[i], dev->iobase + PCI1723_DA(i));
191 /* set all ranges to +/- 10V */ 214 /* set all ranges to +/- 10V */
192 devpriv->da_range[i] = 0; 215 devpriv->da_range[i] = 0;
193 outw(((devpriv->da_range[i] << 4) | i), 216 outw(((devpriv->da_range[i] << 4) | i),
194 PCI1723_RANGE_CALIBRATION_MODE); 217 PCI1723_RANGE_CALIBRATION_MODE);
195 } 218 }
196 219
197 outw(0, dev->iobase + PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE); /* update ranges */ 220 outw(0, dev->iobase + PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE);
198 outw(0, dev->iobase + PCI1723_SYN_STROBE); /* update outputs */ 221 /* update ranges */
222 outw(0, dev->iobase + PCI1723_SYN_STROBE); /* update outputs */
199 223
200 /* set asynchronous output mode */ 224 /* set asynchronous output mode */
201 outw(0, dev->iobase + PCI1723_SYN_SET); 225 outw(0, dev->iobase + PCI1723_SYN_SET);
202 226
203 DPRINTK("adv_pci1723 EDBG: END: pci1723_reset(...)\n"); 227 DPRINTK("adv_pci1723 EDBG: END: pci1723_reset(...)\n");
@@ -251,11 +275,11 @@ static int pci1723_dio_insn_config(struct comedi_device *dev,
251 unsigned short dio_mode; 275 unsigned short dio_mode;
252 276
253 mask = 1 << CR_CHAN(insn->chanspec); 277 mask = 1 << CR_CHAN(insn->chanspec);
254 if (mask & 0x00FF) { 278 if (mask & 0x00FF)
255 bits = 0x00FF; 279 bits = 0x00FF;
256 } else { 280 else
257 bits = 0xFF00; 281 bits = 0xFF00;
258 } 282
259 switch (data[0]) { 283 switch (data[0]) {
260 case INSN_CONFIG_DIO_INPUT: 284 case INSN_CONFIG_DIO_INPUT:
261 s->io_bits &= ~bits; 285 s->io_bits &= ~bits;
@@ -270,12 +294,12 @@ static int pci1723_dio_insn_config(struct comedi_device *dev,
270 return -EINVAL; 294 return -EINVAL;
271 } 295 }
272 296
273 /* update hardware DIO mode */ 297 /* update hardware DIO mode */
274 dio_mode = 0x0000; /* low byte output, high byte output */ 298 dio_mode = 0x0000; /* low byte output, high byte output */
275 if ((s->io_bits & 0x00FF) == 0) 299 if ((s->io_bits & 0x00FF) == 0)
276 dio_mode |= 0x0001; /* low byte input */ 300 dio_mode |= 0x0001; /* low byte input */
277 if ((s->io_bits & 0xFF00) == 0) 301 if ((s->io_bits & 0xFF00) == 0)
278 dio_mode |= 0x0002; /* high byte input */ 302 dio_mode |= 0x0002; /* high byte input */
279 outw(dio_mode, dev->iobase + PCI1723_DIGITAL_IO_PORT_SET); 303 outw(dio_mode, dev->iobase + PCI1723_DIGITAL_IO_PORT_SET);
280 return 1; 304 return 1;
281} 305}
@@ -311,7 +335,8 @@ static int pci1723_attach(struct comedi_device *dev,
311 int opt_bus, opt_slot; 335 int opt_bus, opt_slot;
312 const char *errstr; 336 const char *errstr;
313 337
314 printk("comedi%d: adv_pci1723: board=%s", dev->minor, this_board->name); 338 printk(KERN_ERR "comedi%d: adv_pci1723: board=%s",
339 dev->minor, this_board->name);
315 340
316 opt_bus = it->options[0]; 341 opt_bus = it->options[0];
317 opt_slot = it->options[1]; 342 opt_slot = it->options[1];
@@ -349,10 +374,10 @@ static int pci1723_attach(struct comedi_device *dev,
349 374
350 if (!pcidev) { 375 if (!pcidev) {
351 if (opt_bus || opt_slot) { 376 if (opt_bus || opt_slot) {
352 printk(" - Card at b:s %d:%d %s\n", 377 printk(KERN_ERR " - Card at b:s %d:%d %s\n",
353 opt_bus, opt_slot, errstr); 378 opt_bus, opt_slot, errstr);
354 } else { 379 } else {
355 printk(" - Card %s\n", errstr); 380 printk(KERN_ERR " - Card %s\n", errstr);
356 } 381 }
357 return -EIO; 382 return -EIO;
358 } 383 }
@@ -362,8 +387,8 @@ static int pci1723_attach(struct comedi_device *dev,
362 pci_func = PCI_FUNC(pcidev->devfn); 387 pci_func = PCI_FUNC(pcidev->devfn);
363 iobase = pci_resource_start(pcidev, 2); 388 iobase = pci_resource_start(pcidev, 2);
364 389
365 printk(", b:s:f=%d:%d:%d, io=0x%4x", pci_bus, pci_slot, pci_func, 390 printk(KERN_ERR ", b:s:f=%d:%d:%d, io=0x%4x",
366 iobase); 391 pci_bus, pci_slot, pci_func, iobase);
367 392
368 dev->iobase = iobase; 393 dev->iobase = iobase;
369 394
@@ -398,22 +423,23 @@ static int pci1723_attach(struct comedi_device *dev,
398 s->insn_write = pci1723_ao_write_winsn; 423 s->insn_write = pci1723_ao_write_winsn;
399 s->insn_read = pci1723_insn_read_ao; 424 s->insn_read = pci1723_insn_read_ao;
400 425
401 /* read DIO config */ 426 /* read DIO config */
402 switch (inw(dev->iobase + PCI1723_DIGITAL_IO_PORT_MODE) & 0x03) { 427 switch (inw(dev->iobase + PCI1723_DIGITAL_IO_PORT_MODE)
403 case 0x00: /* low byte output, high byte output */ 428 & 0x03) {
429 case 0x00: /* low byte output, high byte output */
404 s->io_bits = 0xFFFF; 430 s->io_bits = 0xFFFF;
405 break; 431 break;
406 case 0x01: /* low byte input, high byte output */ 432 case 0x01: /* low byte input, high byte output */
407 s->io_bits = 0xFF00; 433 s->io_bits = 0xFF00;
408 break; 434 break;
409 case 0x02: /* low byte output, high byte input */ 435 case 0x02: /* low byte output, high byte input */
410 s->io_bits = 0x00FF; 436 s->io_bits = 0x00FF;
411 break; 437 break;
412 case 0x03: /* low byte input, high byte input */ 438 case 0x03: /* low byte input, high byte input */
413 s->io_bits = 0x0000; 439 s->io_bits = 0x0000;
414 break; 440 break;
415 } 441 }
416 /* read DIO port state */ 442 /* read DIO port state */
417 s->state = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA); 443 s->state = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA);
418 444
419 subdev++; 445 subdev++;
@@ -450,16 +476,15 @@ static int pci1723_attach(struct comedi_device *dev,
450 */ 476 */
451static int pci1723_detach(struct comedi_device *dev) 477static int pci1723_detach(struct comedi_device *dev)
452{ 478{
453 printk("comedi%d: pci1723: remove\n", dev->minor); 479 printk(KERN_ERR "comedi%d: pci1723: remove\n", dev->minor);
454 480
455 if (dev->private) { 481 if (dev->private) {
456 if (devpriv->valid) 482 if (devpriv->valid)
457 pci1723_reset(dev); 483 pci1723_reset(dev);
458 484
459 if (devpriv->pcidev) { 485 if (devpriv->pcidev) {
460 if (dev->iobase) { 486 if (dev->iobase)
461 comedi_pci_disable(devpriv->pcidev); 487 comedi_pci_disable(devpriv->pcidev);
462 }
463 pci_dev_put(devpriv->pcidev); 488 pci_dev_put(devpriv->pcidev);
464 } 489 }
465 } 490 }