49 #include "../comedidev.h"
55 #define PCI_VENDOR_ID_CB 0x1307
56 #define EEPROM_SIZE 128
58 #define MAX_AO_CHANNELS 8
81 #define ENABLEDAC 0000002
82 #define DISABLEDAC 0000000
83 #define RANGE2V5 0000000
84 #define RANGE5V 0000200
85 #define RANGE10V 0000300
89 #define DACALIBRATION1 4
92 #define SERIAL_IN_BIT 0x1
93 #define CAL_CHANNEL_MASK (0x7 << 1)
94 #define CAL_CHANNEL_BITS(channel) (((channel) << 1) & CAL_CHANNEL_MASK)
96 #define CAL_COUNTER_MASK 0x1f
98 #define CAL_COUNTER_OVERFLOW_BIT 0x20
100 #define AO_BELOW_REF_BIT 0x40
101 #define SERIAL_OUT_BIT 0x80
103 #define DACALIBRATION2 6
104 #define SELECT_EEPROM_BIT 0x1
106 #define DESELECT_REF_DAC_BIT 0x2
108 #define DESELECT_CALDAC_BIT(n) (0x4 << (n))
110 #define DUMMY_BIT 0x40
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,
227 printk(
"cb_pcidda_ai_cmd\n");
230 printk(
"start_src: %d\n",
cmd->start_src);
231 printk(
"start_arg: %d\n",
cmd->start_arg);
232 printk(
"scan_begin_src: %d\n",
cmd->scan_begin_src);
233 printk(
"convert_src: %d\n",
cmd->convert_src);
234 printk(
"convert_arg: %d\n",
cmd->convert_arg);
235 printk(
"scan_end_src: %d\n",
cmd->scan_end_src);
236 printk(
"scan_end_arg: %d\n",
cmd->scan_end_arg);
239 printk(
"chanlist_len: %d\n",
cmd->chanlist_len);
267 err |= cfc_check_trigger_is_unique(cmd->
convert_src);
268 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
281 #define MAX_SPEED 10000
282 #define MIN_SPEED 1000000000
377 static int cb_pcidda_ns_to_timer(
unsigned int *
ns,
int round)
385 static unsigned int cb_pcidda_serial_in(
struct comedi_device *dev)
388 unsigned int value = 0;
390 const int value_width = 16;
392 for (i = 1; i <= value_width; i++) {
395 value |= 1 << (value_width -
i);
402 static void cb_pcidda_serial_out(
struct comedi_device *dev,
unsigned int value,
403 unsigned int num_bits)
408 for (i = 1; i <= num_bits; i++) {
410 if (value & (1 << (num_bits - i)))
419 static unsigned int cb_pcidda_read_eeprom(
struct comedi_device *dev,
424 unsigned int cal2_bits;
427 const int max_num_caldacs = 4;
429 const int read_instruction = 0x6;
430 const int instruction_length = 3;
436 for (i = 0; i < max_num_caldacs; i++)
441 cb_pcidda_serial_out(dev, read_instruction, instruction_length);
443 cb_pcidda_serial_out(dev, address, address_length);
445 value = cb_pcidda_serial_in(dev);
455 static void cb_pcidda_write_caldac(
struct comedi_device *dev,
456 unsigned int caldac,
unsigned int channel,
460 unsigned int cal2_bits;
463 const int num_channel_bits = 3;
464 const int num_caldac_bits = 8;
466 const int max_num_caldacs = 4;
469 cb_pcidda_serial_out(dev, channel, num_channel_bits);
471 cb_pcidda_serial_out(dev, value, num_caldac_bits);
478 for (i = 0; i < max_num_caldacs; i++)
489 static unsigned int caldac_number(
unsigned int channel)
495 static unsigned int fine_gain_channel(
unsigned int ao_channel)
497 return 4 * (ao_channel % 2);
501 static unsigned int coarse_gain_channel(
unsigned int ao_channel)
503 return 1 + 4 * (ao_channel % 2);
507 static unsigned int coarse_offset_channel(
unsigned int ao_channel)
509 return 2 + 4 * (ao_channel % 2);
513 static unsigned int fine_offset_channel(
unsigned int ao_channel)
515 return 3 + 4 * (ao_channel % 2);
519 static unsigned int offset_eeprom_address(
unsigned int ao_channel,
522 return 0x7 + 2 * range + 12 * ao_channel;
529 static unsigned int gain_eeprom_address(
unsigned int ao_channel,
532 return 0x8 + 2 * range + 12 * ao_channel;
539 static unsigned int eeprom_coarse_byte(
unsigned int word)
541 return (word >> 8) & 0xff;
545 static unsigned int eeprom_fine_byte(
unsigned int word)
551 static void cb_pcidda_calibrate(
struct comedi_device *dev,
unsigned int channel,
555 unsigned int coarse_offset, fine_offset, coarse_gain, fine_gain;
563 [offset_eeprom_address(channel, range)]);
566 [offset_eeprom_address(channel, range)]);
569 [gain_eeprom_address(channel, range)]);
572 [gain_eeprom_address(channel, range)]);
575 cb_pcidda_write_caldac(dev, caldac_number(channel),
576 coarse_offset_channel(channel), coarse_offset);
577 cb_pcidda_write_caldac(dev, caldac_number(channel),
578 fine_offset_channel(channel), fine_offset);
579 cb_pcidda_write_caldac(dev, caldac_number(channel),
580 coarse_gain_channel(channel), coarse_gain);
581 cb_pcidda_write_caldac(dev, caldac_number(channel),
582 fine_gain_channel(channel), fine_gain);
597 if (range != devpriv->
ao_range[channel])
598 cb_pcidda_calibrate(dev, channel, range);
626 command |= channel << 2;
636 static const void *cb_pcidda_find_boardinfo(
struct comedi_device *dev,
642 for (i = 0; i <
ARRAY_SIZE(cb_pcidda_boards); i++) {
643 thisboard = &cb_pcidda_boards[
i];
659 comedi_set_hw_dev(dev, &pcidev->
dev);
661 thisboard = cb_pcidda_find_boardinfo(dev, pcidev);
667 ret = alloc_private(dev,
sizeof(*devpriv));
680 if (thisboard->
status == 2)
682 (
"WARNING: DRIVER FOR THIS BOARD NOT CHECKED WITH MANUAL. "
683 "WORKS ASSUMING FULL COMPATIBILITY WITH PCI-DDA08/12. "
717 for (index = 0; index < thisboard->
ao_chans; index++)
718 cb_pcidda_calibrate(dev, index, devpriv->
ao_range[index]);
727 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
740 .driver_name =
"cb_pcidda",
742 .attach_pci = cb_pcidda_attach_pci,
743 .detach = cb_pcidda_detach,
768 static struct pci_driver cb_pcidda_pci_driver = {
770 .id_table = cb_pcidda_pci_table,
771 .probe = cb_pcidda_pci_probe,