2 comedi/drivers/cb_pcidda.c
3 This intends to be a driver for the ComputerBoards / MeasurementComputing
6 Copyright (C) 2001 Ivan Martinez <ivanmr@altavista.com>
7 Copyright (C) 2001 Frank Mori Hess <fmhess@users.sourceforge.net>
9 COMEDI - Linux Control and Measurement Device Interface
10 Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 Description: MeasurementComputing PCI-DDA series
30 Author: Ivan Martinez <ivanmr@altavista.com>, Frank Mori Hess <fmhess@users.sourceforge.net>
31 Status: Supports 08/16, 04/16, 02/16, 08/12, 04/12, and 02/12
32 Devices: [Measurement Computing] PCI-DDA08/12 (cb_pcidda), PCI-DDA04/12,
33 PCI-DDA02/12, PCI-DDA08/16, PCI-DDA04/16, PCI-DDA02/16
35 Configuration options:
36 [0] - PCI bus of device (optional)
37 [1] - PCI slot of device (optional)
38 If bus/slot is not specified, the first available PCI
41 Only simple analog output writing is supported.
43 So far it has only been tested with:
45 Please report success/failure with other different cards to
49 #include "../comedidev.h"
51 #include "comedi_pci.h"
54 #define PCI_VENDOR_ID_CB 0x1307 /* PCI vendor number of ComputerBoards */
55 #define EEPROM_SIZE 128 /* number of entries in eeprom */
56 #define MAX_AO_CHANNELS 8 /* maximum number of ao channels for supported boards */
58 /* PCI-DDA base addresses */
59 #define DIGITALIO_BADRINDEX 2
60 /* DIGITAL I/O is pci_dev->resource[2] */
61 #define DIGITALIO_SIZE 8
62 /* DIGITAL I/O uses 8 I/O port addresses */
63 #define DAC_BADRINDEX 3
64 /* DAC is pci_dev->resource[3] */
66 /* Digital I/O registers */
67 #define PORT1A 0 /* PORT 1A DATA */
69 #define PORT1B 1 /* PORT 1B DATA */
71 #define PORT1C 2 /* PORT 1C DATA */
73 #define CONTROL1 3 /* CONTROL REGISTER 1 */
75 #define PORT2A 4 /* PORT 2A DATA */
77 #define PORT2B 5 /* PORT 2B DATA */
79 #define PORT2C 6 /* PORT 2C DATA */
81 #define CONTROL2 7 /* CONTROL REGISTER 2 */
84 #define DACONTROL 0 /* D/A CONTROL REGISTER */
85 #define SU 0000001 /* Simultaneous update enabled */
86 #define NOSU 0000000 /* Simultaneous update disabled */
87 #define ENABLEDAC 0000002 /* Enable specified DAC */
88 #define DISABLEDAC 0000000 /* Disable specified DAC */
89 #define RANGE2V5 0000000 /* 2.5V */
90 #define RANGE5V 0000200 /* 5V */
91 #define RANGE10V 0000300 /* 10V */
92 #define UNIP 0000400 /* Unipolar outputs */
93 #define BIP 0000000 /* Bipolar outputs */
95 #define DACALIBRATION1 4 /* D/A CALIBRATION REGISTER 1 */
97 #define SERIAL_IN_BIT 0x1 /* serial data input for eeprom, caldacs, reference dac */
98 #define CAL_CHANNEL_MASK (0x7 << 1)
99 #define CAL_CHANNEL_BITS(channel) (((channel) << 1) & CAL_CHANNEL_MASK)
101 #define CAL_COUNTER_MASK 0x1f
102 #define CAL_COUNTER_OVERFLOW_BIT 0x20 /* calibration counter overflow status bit */
103 #define AO_BELOW_REF_BIT 0x40 /* analog output is less than reference dac voltage */
104 #define SERIAL_OUT_BIT 0x80 /* serial data out, for reading from eeprom */
106 #define DACALIBRATION2 6 /* D/A CALIBRATION REGISTER 2 */
107 #define SELECT_EEPROM_BIT 0x1 /* send serial data in to eeprom */
108 #define DESELECT_REF_DAC_BIT 0x2 /* don't send serial data to MAX542 reference dac */
109 #define DESELECT_CALDAC_BIT(n) (0x4 << (n)) /* don't send serial data to caldac n */
110 #define DUMMY_BIT 0x40 /* manual says to set this bit with no explanation */
112 #define DADATA 8 /* FIRST D/A DATA REGISTER (0) */
114 static const struct comedi_lrange cb_pcidda_ranges = {
127 * Board descriptions for two imaginary boards. Describing the
128 * boards in this way is optional, and completely driver-dependent.
129 * Some drivers use arrays such as this, other do not.
131 struct cb_pcidda_board {
133 char status; /* Driver status: */
137 * 1 - manual read, not tested
138 * 2 - manual not read
141 unsigned short device_id;
144 const struct comedi_lrange *ranges;
147 static const struct cb_pcidda_board cb_pcidda_boards[] = {
149 .name = "pci-dda02/12",
154 .ranges = &cb_pcidda_ranges,
157 .name = "pci-dda04/12",
162 .ranges = &cb_pcidda_ranges,
165 .name = "pci-dda08/12",
170 .ranges = &cb_pcidda_ranges,
173 .name = "pci-dda02/16",
178 .ranges = &cb_pcidda_ranges,
181 .name = "pci-dda04/16",
186 .ranges = &cb_pcidda_ranges,
189 .name = "pci-dda08/16",
194 .ranges = &cb_pcidda_ranges,
198 static DEFINE_PCI_DEVICE_TABLE(cb_pcidda_pci_table) = {
199 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0020) },
200 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0021) },
201 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0022) },
202 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0023) },
203 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0024) },
204 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0025) },
208 MODULE_DEVICE_TABLE(pci, cb_pcidda_pci_table);
211 * Useful for shorthand access to the particular board structure
213 #define thisboard ((const struct cb_pcidda_board *)dev->board_ptr)
215 /* this structure is for data unique to this hardware driver. If
216 several hardware drivers keep similar information in this structure,
217 feel free to suggest moving the variable to the struct comedi_device struct. */
218 struct cb_pcidda_private {
221 /* would be useful for a PCI device */
222 struct pci_dev *pci_dev;
224 unsigned long digitalio;
227 /* unsigned long control_status; */
228 /* unsigned long adc_fifo; */
230 unsigned int dac_cal1_bits; /* bits last written to da calibration register 1 */
231 unsigned int ao_range[MAX_AO_CHANNELS]; /* current range settings for output channels */
232 u16 eeprom_data[EEPROM_SIZE]; /* software copy of board's eeprom */
236 * most drivers define the following macro to make it easy to
237 * access the private structure.
239 #define devpriv ((struct cb_pcidda_private *)dev->private)
241 static int cb_pcidda_attach(struct comedi_device *dev,
242 struct comedi_devconfig *it);
243 static int cb_pcidda_detach(struct comedi_device *dev);
244 /* static int cb_pcidda_ai_rinsn(struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data); */
245 static int cb_pcidda_ao_winsn(struct comedi_device *dev,
246 struct comedi_subdevice *s,
247 struct comedi_insn *insn, unsigned int *data);
249 /* static int cb_pcidda_ai_cmd(struct comedi_device *dev, struct *comedi_subdevice *s);*/
250 /* static int cb_pcidda_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd); */
251 /* static int cb_pcidda_ns_to_timer(unsigned int *ns,int *round); */
253 static unsigned int cb_pcidda_serial_in(struct comedi_device *dev);
254 static void cb_pcidda_serial_out(struct comedi_device *dev, unsigned int value,
255 unsigned int num_bits);
256 static unsigned int cb_pcidda_read_eeprom(struct comedi_device *dev,
257 unsigned int address);
258 static void cb_pcidda_calibrate(struct comedi_device *dev, unsigned int channel,
262 * The struct comedi_driver structure tells the Comedi core module
263 * which functions to call to configure/deconfigure (attach/detach)
264 * the board, and also about the kernel module that contains
267 static struct comedi_driver driver_cb_pcidda = {
268 .driver_name = "cb_pcidda",
269 .module = THIS_MODULE,
270 .attach = cb_pcidda_attach,
271 .detach = cb_pcidda_detach,
275 * Attach is called by the Comedi core to configure the driver
276 * for a particular board.
278 static int cb_pcidda_attach(struct comedi_device *dev,
279 struct comedi_devconfig *it)
281 struct comedi_subdevice *s;
282 struct pci_dev *pcidev = NULL;
285 printk("comedi%d: cb_pcidda: ", dev->minor);
288 * Allocate the private structure area.
290 if (alloc_private(dev, sizeof(struct cb_pcidda_private)) < 0)
294 * Probe the device to determine what device in the series it is.
298 for_each_pci_dev(pcidev) {
299 if (pcidev->vendor == PCI_VENDOR_ID_CB) {
300 if (it->options[0] || it->options[1]) {
301 if (pcidev->bus->number != it->options[0] ||
302 PCI_SLOT(pcidev->devfn) != it->options[1]) {
306 for (index = 0; index < ARRAY_SIZE(cb_pcidda_boards); index++) {
307 if (cb_pcidda_boards[index].device_id ==
316 ("Not a ComputerBoards/MeasurementComputing card on requested position\n");
320 devpriv->pci_dev = pcidev;
321 dev->board_ptr = cb_pcidda_boards + index;
322 /* "thisboard" macro can be used from here. */
323 printk("Found %s at requested position\n", thisboard->name);
326 * Enable PCI device and request regions.
328 if (comedi_pci_enable(pcidev, thisboard->name)) {
330 ("cb_pcidda: failed to enable PCI device and request regions\n");
335 * Allocate the I/O ports.
338 pci_resource_start(devpriv->pci_dev, DIGITALIO_BADRINDEX);
339 devpriv->dac = pci_resource_start(devpriv->pci_dev, DAC_BADRINDEX);
342 * Warn about the status of the driver.
344 if (thisboard->status == 2)
346 ("WARNING: DRIVER FOR THIS BOARD NOT CHECKED WITH MANUAL. "
347 "WORKS ASSUMING FULL COMPATIBILITY WITH PCI-DDA08/12. "
348 "PLEASE REPORT USAGE TO <ivanmr@altavista.com>.\n");
351 * Initialize dev->board_name.
353 dev->board_name = thisboard->name;
356 * Allocate the subdevice structures.
358 if (alloc_subdevices(dev, 3) < 0)
361 s = dev->subdevices + 0;
362 /* analog output subdevice */
363 s->type = COMEDI_SUBD_AO;
364 s->subdev_flags = SDF_WRITABLE;
365 s->n_chan = thisboard->ao_chans;
366 s->maxdata = (1 << thisboard->ao_bits) - 1;
367 s->range_table = thisboard->ranges;
368 s->insn_write = cb_pcidda_ao_winsn;
370 /* s->subdev_flags |= SDF_CMD_READ; */
371 /* s->do_cmd = cb_pcidda_ai_cmd; */
372 /* s->do_cmdtest = cb_pcidda_ai_cmdtest; */
374 /* two 8255 digital io subdevices */
375 s = dev->subdevices + 1;
376 subdev_8255_init(dev, s, NULL, devpriv->digitalio);
377 s = dev->subdevices + 2;
378 subdev_8255_init(dev, s, NULL, devpriv->digitalio + PORT2A);
381 for (index = 0; index < EEPROM_SIZE; index++) {
382 devpriv->eeprom_data[index] = cb_pcidda_read_eeprom(dev, index);
383 printk(" %i:0x%x ", index, devpriv->eeprom_data[index]);
387 /* set calibrations dacs */
388 for (index = 0; index < thisboard->ao_chans; index++)
389 cb_pcidda_calibrate(dev, index, devpriv->ao_range[index]);
395 * _detach is called to deconfigure a device. It should deallocate
397 * This function is also called when _attach() fails, so it should be
398 * careful not to release resources that were not necessarily
399 * allocated by _attach(). dev->private and dev->subdevices are
400 * deallocated automatically by the core.
402 static int cb_pcidda_detach(struct comedi_device *dev)
405 * Deallocate the I/O ports.
408 if (devpriv->pci_dev) {
410 comedi_pci_disable(devpriv->pci_dev);
411 pci_dev_put(devpriv->pci_dev);
415 if (dev->subdevices) {
416 subdev_8255_cleanup(dev, dev->subdevices + 1);
417 subdev_8255_cleanup(dev, dev->subdevices + 2);
420 printk("comedi%d: cb_pcidda: remove\n", dev->minor);
426 * I will program this later... ;-)
429 static int cb_pcidda_ai_cmd(struct comedi_device *dev,
430 struct comedi_subdevice *s)
432 printk("cb_pcidda_ai_cmd\n");
433 printk("subdev: %d\n", cmd->subdev);
434 printk("flags: %d\n", cmd->flags);
435 printk("start_src: %d\n", cmd->start_src);
436 printk("start_arg: %d\n", cmd->start_arg);
437 printk("scan_begin_src: %d\n", cmd->scan_begin_src);
438 printk("convert_src: %d\n", cmd->convert_src);
439 printk("convert_arg: %d\n", cmd->convert_arg);
440 printk("scan_end_src: %d\n", cmd->scan_end_src);
441 printk("scan_end_arg: %d\n", cmd->scan_end_arg);
442 printk("stop_src: %d\n", cmd->stop_src);
443 printk("stop_arg: %d\n", cmd->stop_arg);
444 printk("chanlist_len: %d\n", cmd->chanlist_len);
449 static int cb_pcidda_ai_cmdtest(struct comedi_device *dev,
450 struct comedi_subdevice *s,
451 struct comedi_cmd *cmd)
456 /* cmdtest tests a particular command to see if it is valid.
457 * Using the cmdtest ioctl, a user can create a valid cmd
458 * and then have it executes by the cmd ioctl.
460 * cmdtest returns 1,2,3,4 or 0, depending on which tests
461 * the command passes. */
463 /* step 1: make sure trigger sources are trivially valid */
465 tmp = cmd->start_src;
466 cmd->start_src &= TRIG_NOW;
467 if (!cmd->start_src || tmp != cmd->start_src)
470 tmp = cmd->scan_begin_src;
471 cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
472 if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
475 tmp = cmd->convert_src;
476 cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
477 if (!cmd->convert_src || tmp != cmd->convert_src)
480 tmp = cmd->scan_end_src;
481 cmd->scan_end_src &= TRIG_COUNT;
482 if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
486 cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
487 if (!cmd->stop_src || tmp != cmd->stop_src)
493 /* step 2: make sure trigger sources are unique and mutually compatible */
495 /* note that mutual compatibility is not an issue here */
496 if (cmd->scan_begin_src != TRIG_TIMER
497 && cmd->scan_begin_src != TRIG_EXT)
499 if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
501 if (cmd->stop_src != TRIG_TIMER && cmd->stop_src != TRIG_EXT)
507 /* step 3: make sure arguments are trivially compatible */
509 if (cmd->start_arg != 0) {
513 #define MAX_SPEED 10000 /* in nanoseconds */
514 #define MIN_SPEED 1000000000 /* in nanoseconds */
516 if (cmd->scan_begin_src == TRIG_TIMER) {
517 if (cmd->scan_begin_arg < MAX_SPEED) {
518 cmd->scan_begin_arg = MAX_SPEED;
521 if (cmd->scan_begin_arg > MIN_SPEED) {
522 cmd->scan_begin_arg = MIN_SPEED;
526 /* external trigger */
527 /* should be level/edge, hi/lo specification here */
528 /* should specify multiple external triggers */
529 if (cmd->scan_begin_arg > 9) {
530 cmd->scan_begin_arg = 9;
534 if (cmd->convert_src == TRIG_TIMER) {
535 if (cmd->convert_arg < MAX_SPEED) {
536 cmd->convert_arg = MAX_SPEED;
539 if (cmd->convert_arg > MIN_SPEED) {
540 cmd->convert_arg = MIN_SPEED;
544 /* external trigger */
546 if (cmd->convert_arg > 9) {
547 cmd->convert_arg = 9;
552 if (cmd->scan_end_arg != cmd->chanlist_len) {
553 cmd->scan_end_arg = cmd->chanlist_len;
556 if (cmd->stop_src == TRIG_COUNT) {
557 if (cmd->stop_arg > 0x00ffffff) {
558 cmd->stop_arg = 0x00ffffff;
563 if (cmd->stop_arg != 0) {
572 /* step 4: fix up any arguments */
574 if (cmd->scan_begin_src == TRIG_TIMER) {
575 tmp = cmd->scan_begin_arg;
576 cb_pcidda_ns_to_timer(&cmd->scan_begin_arg,
577 cmd->flags & TRIG_ROUND_MASK);
578 if (tmp != cmd->scan_begin_arg)
581 if (cmd->convert_src == TRIG_TIMER) {
582 tmp = cmd->convert_arg;
583 cb_pcidda_ns_to_timer(&cmd->convert_arg,
584 cmd->flags & TRIG_ROUND_MASK);
585 if (tmp != cmd->convert_arg)
587 if (cmd->scan_begin_src == TRIG_TIMER &&
588 cmd->scan_begin_arg <
589 cmd->convert_arg * cmd->scan_end_arg) {
590 cmd->scan_begin_arg =
591 cmd->convert_arg * cmd->scan_end_arg;
603 /* This function doesn't require a particular form, this is just
604 * what happens to be used in some of the drivers. It should
605 * convert ns nanoseconds to a counter value suitable for programming
606 * the device. Also, it should adjust ns so that it cooresponds to
607 * the actual time that the device will use. */
609 static int cb_pcidda_ns_to_timer(unsigned int *ns, int round)
616 static int cb_pcidda_ao_winsn(struct comedi_device *dev,
617 struct comedi_subdevice *s,
618 struct comedi_insn *insn, unsigned int *data)
620 unsigned int command;
621 unsigned int channel, range;
623 channel = CR_CHAN(insn->chanspec);
624 range = CR_RANGE(insn->chanspec);
626 /* adjust calibration dacs if range has changed */
627 if (range != devpriv->ao_range[channel])
628 cb_pcidda_calibrate(dev, channel, range);
630 /* output channel configuration */
631 command = NOSU | ENABLEDAC;
633 /* output channel range */
636 command |= BIP | RANGE10V;
639 command |= BIP | RANGE5V;
642 command |= BIP | RANGE2V5;
645 command |= UNIP | RANGE10V;
648 command |= UNIP | RANGE5V;
651 command |= UNIP | RANGE2V5;
655 /* output channel specification */
656 command |= channel << 2;
657 outw(command, devpriv->dac + DACONTROL);
660 outw(data[0], devpriv->dac + DADATA + channel * 2);
662 /* return the number of samples read/written */
666 /* lowlevel read from eeprom */
667 static unsigned int cb_pcidda_serial_in(struct comedi_device *dev)
669 unsigned int value = 0;
671 const int value_width = 16; /* number of bits wide values are */
673 for (i = 1; i <= value_width; i++) {
674 /* read bits most significant bit first */
675 if (inw_p(devpriv->dac + DACALIBRATION1) & SERIAL_OUT_BIT)
676 value |= 1 << (value_width - i);
682 /* lowlevel write to eeprom/dac */
683 static void cb_pcidda_serial_out(struct comedi_device *dev, unsigned int value,
684 unsigned int num_bits)
688 for (i = 1; i <= num_bits; i++) {
689 /* send bits most significant bit first */
690 if (value & (1 << (num_bits - i)))
691 devpriv->dac_cal1_bits |= SERIAL_IN_BIT;
693 devpriv->dac_cal1_bits &= ~SERIAL_IN_BIT;
694 outw_p(devpriv->dac_cal1_bits, devpriv->dac + DACALIBRATION1);
698 /* reads a 16 bit value from board's eeprom */
699 static unsigned int cb_pcidda_read_eeprom(struct comedi_device *dev,
700 unsigned int address)
703 unsigned int cal2_bits;
705 const int max_num_caldacs = 4; /* one caldac for every two dac channels */
706 const int read_instruction = 0x6; /* bits to send to tell eeprom we want to read */
707 const int instruction_length = 3;
708 const int address_length = 8;
710 /* send serial output stream to eeprom */
711 cal2_bits = SELECT_EEPROM_BIT | DESELECT_REF_DAC_BIT | DUMMY_BIT;
712 /* deactivate caldacs (one caldac for every two channels) */
713 for (i = 0; i < max_num_caldacs; i++)
714 cal2_bits |= DESELECT_CALDAC_BIT(i);
715 outw_p(cal2_bits, devpriv->dac + DACALIBRATION2);
717 /* tell eeprom we want to read */
718 cb_pcidda_serial_out(dev, read_instruction, instruction_length);
719 /* send address we want to read from */
720 cb_pcidda_serial_out(dev, address, address_length);
722 value = cb_pcidda_serial_in(dev);
724 /* deactivate eeprom */
725 cal2_bits &= ~SELECT_EEPROM_BIT;
726 outw_p(cal2_bits, devpriv->dac + DACALIBRATION2);
731 /* writes to 8 bit calibration dacs */
732 static void cb_pcidda_write_caldac(struct comedi_device *dev,
733 unsigned int caldac, unsigned int channel,
736 unsigned int cal2_bits;
738 const int num_channel_bits = 3; /* caldacs use 3 bit channel specification */
739 const int num_caldac_bits = 8; /* 8 bit calibration dacs */
740 const int max_num_caldacs = 4; /* one caldac for every two dac channels */
742 /* write 3 bit channel */
743 cb_pcidda_serial_out(dev, channel, num_channel_bits);
744 /* write 8 bit caldac value */
745 cb_pcidda_serial_out(dev, value, num_caldac_bits);
748 * latch stream into appropriate caldac deselect reference dac
750 cal2_bits = DESELECT_REF_DAC_BIT | DUMMY_BIT;
751 /* deactivate caldacs (one caldac for every two channels) */
752 for (i = 0; i < max_num_caldacs; i++)
753 cal2_bits |= DESELECT_CALDAC_BIT(i);
754 /* activate the caldac we want */
755 cal2_bits &= ~DESELECT_CALDAC_BIT(caldac);
756 outw_p(cal2_bits, devpriv->dac + DACALIBRATION2);
757 /* deactivate caldac */
758 cal2_bits |= DESELECT_CALDAC_BIT(caldac);
759 outw_p(cal2_bits, devpriv->dac + DACALIBRATION2);
762 /* returns caldac that calibrates given analog out channel */
763 static unsigned int caldac_number(unsigned int channel)
768 /* returns caldac channel that provides fine gain for given ao channel */
769 static unsigned int fine_gain_channel(unsigned int ao_channel)
771 return 4 * (ao_channel % 2);
774 /* returns caldac channel that provides coarse gain for given ao channel */
775 static unsigned int coarse_gain_channel(unsigned int ao_channel)
777 return 1 + 4 * (ao_channel % 2);
780 /* returns caldac channel that provides coarse offset for given ao channel */
781 static unsigned int coarse_offset_channel(unsigned int ao_channel)
783 return 2 + 4 * (ao_channel % 2);
786 /* returns caldac channel that provides fine offset for given ao channel */
787 static unsigned int fine_offset_channel(unsigned int ao_channel)
789 return 3 + 4 * (ao_channel % 2);
792 /* returns eeprom address that provides offset for given ao channel and range */
793 static unsigned int offset_eeprom_address(unsigned int ao_channel,
796 return 0x7 + 2 * range + 12 * ao_channel;
799 /* returns eeprom address that provides gain calibration for given ao channel and range */
800 static unsigned int gain_eeprom_address(unsigned int ao_channel,
803 return 0x8 + 2 * range + 12 * ao_channel;
806 /* returns upper byte of eeprom entry, which gives the coarse adjustment values */
807 static unsigned int eeprom_coarse_byte(unsigned int word)
809 return (word >> 8) & 0xff;
812 /* returns lower byte of eeprom entry, which gives the fine adjustment values */
813 static unsigned int eeprom_fine_byte(unsigned int word)
818 /* set caldacs to eeprom values for given channel and range */
819 static void cb_pcidda_calibrate(struct comedi_device *dev, unsigned int channel,
822 unsigned int coarse_offset, fine_offset, coarse_gain, fine_gain;
824 /* remember range so we can tell when we need to readjust calibration */
825 devpriv->ao_range[channel] = range;
827 /* get values from eeprom data */
829 eeprom_coarse_byte(devpriv->eeprom_data
830 [offset_eeprom_address(channel, range)]);
832 eeprom_fine_byte(devpriv->eeprom_data
833 [offset_eeprom_address(channel, range)]);
835 eeprom_coarse_byte(devpriv->eeprom_data
836 [gain_eeprom_address(channel, range)]);
838 eeprom_fine_byte(devpriv->eeprom_data
839 [gain_eeprom_address(channel, range)]);
842 cb_pcidda_write_caldac(dev, caldac_number(channel),
843 coarse_offset_channel(channel), coarse_offset);
844 cb_pcidda_write_caldac(dev, caldac_number(channel),
845 fine_offset_channel(channel), fine_offset);
846 cb_pcidda_write_caldac(dev, caldac_number(channel),
847 coarse_gain_channel(channel), coarse_gain);
848 cb_pcidda_write_caldac(dev, caldac_number(channel),
849 fine_gain_channel(channel), fine_gain);
853 * A convenient macro that defines init_module() and cleanup_module(),
856 static int __devinit driver_cb_pcidda_pci_probe(struct pci_dev *dev,
857 const struct pci_device_id *ent)
859 return comedi_pci_auto_config(dev, driver_cb_pcidda.driver_name);
862 static void __devexit driver_cb_pcidda_pci_remove(struct pci_dev *dev)
864 comedi_pci_auto_unconfig(dev);
867 static struct pci_driver driver_cb_pcidda_pci_driver = {
868 .id_table = cb_pcidda_pci_table,
869 .probe = &driver_cb_pcidda_pci_probe,
870 .remove = __devexit_p(&driver_cb_pcidda_pci_remove)
873 static int __init driver_cb_pcidda_init_module(void)
877 retval = comedi_driver_register(&driver_cb_pcidda);
881 driver_cb_pcidda_pci_driver.name = (char *)driver_cb_pcidda.driver_name;
882 return pci_register_driver(&driver_cb_pcidda_pci_driver);
885 static void __exit driver_cb_pcidda_cleanup_module(void)
887 pci_unregister_driver(&driver_cb_pcidda_pci_driver);
888 comedi_driver_unregister(&driver_cb_pcidda);
891 module_init(driver_cb_pcidda_init_module);
892 module_exit(driver_cb_pcidda_cleanup_module);
894 MODULE_AUTHOR("Comedi http://www.comedi.org");
895 MODULE_DESCRIPTION("Comedi low-level driver");
896 MODULE_LICENSE("GPL");