Lines Matching +full:acquisition +full:- +full:time +full:- +full:ns
1 // SPDX-License-Identifier: GPL-2.0+
7 * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net>
83 return inb(dev->iobase + reg); in labpc_inb()
89 outb(byte, dev->iobase + reg); in labpc_outb()
94 return readb(dev->mmio + reg); in labpc_readb()
100 writeb(byte, dev->mmio + reg); in labpc_writeb()
105 struct labpc_private *devpriv = dev->private; in labpc_cancel()
108 spin_lock_irqsave(&dev->spinlock, flags); in labpc_cancel()
109 devpriv->cmd2 &= ~(CMD2_SWTRIG | CMD2_HWTRIG | CMD2_PRETRIG); in labpc_cancel()
110 devpriv->write_byte(dev, devpriv->cmd2, CMD2_REG); in labpc_cancel()
111 spin_unlock_irqrestore(&dev->spinlock, flags); in labpc_cancel()
113 devpriv->cmd3 = 0; in labpc_cancel()
114 devpriv->write_byte(dev, devpriv->cmd3, CMD3_REG); in labpc_cancel()
125 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_ai_set_chan_and_gain()
126 struct labpc_private *devpriv = dev->private; in labpc_ai_set_chan_and_gain()
128 if (board->is_labpc1200) { in labpc_ai_set_chan_and_gain()
130 * The LabPC-1200 boards do not have a gain in labpc_ai_set_chan_and_gain()
141 devpriv->cmd1 = CMD1_MA(chan); in labpc_ai_set_chan_and_gain()
142 devpriv->cmd1 |= CMD1_GAIN(range); in labpc_ai_set_chan_and_gain()
144 devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG); in labpc_ai_set_chan_and_gain()
155 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_setup_cmd6_reg()
156 struct labpc_private *devpriv = dev->private; in labpc_setup_cmd6_reg()
158 if (!board->is_labpc1200) in labpc_setup_cmd6_reg()
163 devpriv->cmd6 |= CMD6_NRSE; in labpc_setup_cmd6_reg()
165 devpriv->cmd6 &= ~CMD6_NRSE; in labpc_setup_cmd6_reg()
169 devpriv->cmd6 |= CMD6_ADCUNI; in labpc_setup_cmd6_reg()
171 devpriv->cmd6 &= ~CMD6_ADCUNI; in labpc_setup_cmd6_reg()
175 devpriv->cmd6 |= CMD6_HFINTEN; in labpc_setup_cmd6_reg()
177 devpriv->cmd6 &= ~CMD6_HFINTEN; in labpc_setup_cmd6_reg()
181 devpriv->cmd6 |= CMD6_DQINTEN; in labpc_setup_cmd6_reg()
183 devpriv->cmd6 &= ~CMD6_DQINTEN; in labpc_setup_cmd6_reg()
187 devpriv->cmd6 |= CMD6_SCANUP; in labpc_setup_cmd6_reg()
189 devpriv->cmd6 &= ~CMD6_SCANUP; in labpc_setup_cmd6_reg()
191 devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG); in labpc_setup_cmd6_reg()
196 struct labpc_private *devpriv = dev->private; in labpc_read_adc_fifo()
197 unsigned int lsb = devpriv->read_byte(dev, ADC_FIFO_REG); in labpc_read_adc_fifo()
198 unsigned int msb = devpriv->read_byte(dev, ADC_FIFO_REG); in labpc_read_adc_fifo()
205 struct labpc_private *devpriv = dev->private; in labpc_clear_adc_fifo()
207 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG); in labpc_clear_adc_fifo()
216 struct labpc_private *devpriv = dev->private; in labpc_ai_eoc()
218 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); in labpc_ai_eoc()
219 if (devpriv->stat1 & STAT1_DAVAIL) in labpc_ai_eoc()
221 return -EBUSY; in labpc_ai_eoc()
229 struct labpc_private *devpriv = dev->private; in labpc_ai_insn_read()
230 unsigned int chan = CR_CHAN(insn->chanspec); in labpc_ai_insn_read()
231 unsigned int range = CR_RANGE(insn->chanspec); in labpc_ai_insn_read()
232 unsigned int aref = CR_AREF(insn->chanspec); in labpc_ai_insn_read()
245 devpriv->cmd4 = 0; in labpc_ai_insn_read()
246 devpriv->cmd4 |= CMD4_ECLKRCV; in labpc_ai_insn_read()
247 /* single-ended/differential */ in labpc_ai_insn_read()
249 devpriv->cmd4 |= CMD4_SEDIFF; in labpc_ai_insn_read()
250 devpriv->write_byte(dev, devpriv->cmd4, CMD4_REG); in labpc_ai_insn_read()
253 comedi_8254_set_mode(devpriv->counter, 0, I8254_MODE2 | I8254_BINARY); in labpc_ai_insn_read()
257 for (i = 0; i < insn->n; i++) { in labpc_ai_insn_read()
259 devpriv->write_byte(dev, 0x1, ADC_START_CONVERT_REG); in labpc_ai_insn_read()
268 return insn->n; in labpc_ai_insn_read()
274 if (mode == MODE_SINGLE_CHAN || cmd->scan_begin_src == TRIG_FOLLOW) in labpc_use_continuous_mode()
283 if (cmd->convert_src != TRIG_TIMER) in labpc_ai_convert_period()
286 if (mode == MODE_SINGLE_CHAN && cmd->scan_begin_src == TRIG_TIMER) in labpc_ai_convert_period()
287 return cmd->scan_begin_arg; in labpc_ai_convert_period()
289 return cmd->convert_arg; in labpc_ai_convert_period()
293 enum scan_mode mode, unsigned int ns) in labpc_set_ai_convert_period() argument
295 if (cmd->convert_src != TRIG_TIMER) in labpc_set_ai_convert_period()
299 cmd->scan_begin_src == TRIG_TIMER) { in labpc_set_ai_convert_period()
300 cmd->scan_begin_arg = ns; in labpc_set_ai_convert_period()
301 if (cmd->convert_arg > cmd->scan_begin_arg) in labpc_set_ai_convert_period()
302 cmd->convert_arg = cmd->scan_begin_arg; in labpc_set_ai_convert_period()
304 cmd->convert_arg = ns; in labpc_set_ai_convert_period()
311 if (cmd->scan_begin_src != TRIG_TIMER) in labpc_ai_scan_period()
314 if (mode == MODE_SINGLE_CHAN && cmd->convert_src == TRIG_TIMER) in labpc_ai_scan_period()
317 return cmd->scan_begin_arg; in labpc_ai_scan_period()
321 enum scan_mode mode, unsigned int ns) in labpc_set_ai_scan_period() argument
323 if (cmd->scan_begin_src != TRIG_TIMER) in labpc_set_ai_scan_period()
326 if (mode == MODE_SINGLE_CHAN && cmd->convert_src == TRIG_TIMER) in labpc_set_ai_scan_period()
329 cmd->scan_begin_arg = ns; in labpc_set_ai_scan_period()
336 struct comedi_8254 *pacer = dev->pacer; in labpc_adc_timing()
351 pacer->next_div1 = (scan_period - 1) / in labpc_adc_timing()
352 (pacer->osc_base * I8254_MAX_COUNT) + 1; in labpc_adc_timing()
354 comedi_check_trigger_arg_min(&pacer->next_div1, 2); in labpc_adc_timing()
355 comedi_check_trigger_arg_max(&pacer->next_div1, in labpc_adc_timing()
358 base_period = pacer->osc_base * pacer->next_div1; in labpc_adc_timing()
361 switch (cmd->flags & CMDF_ROUND_MASK) { in labpc_adc_timing()
364 pacer->next_div = DIV_ROUND_CLOSEST(convert_period, in labpc_adc_timing()
366 pacer->next_div2 = DIV_ROUND_CLOSEST(scan_period, in labpc_adc_timing()
370 pacer->next_div = DIV_ROUND_UP(convert_period, in labpc_adc_timing()
372 pacer->next_div2 = DIV_ROUND_UP(scan_period, in labpc_adc_timing()
376 pacer->next_div = convert_period / base_period; in labpc_adc_timing()
377 pacer->next_div2 = scan_period / base_period; in labpc_adc_timing()
381 comedi_check_trigger_arg_min(&pacer->next_div, 2); in labpc_adc_timing()
382 comedi_check_trigger_arg_max(&pacer->next_div, I8254_MAX_COUNT); in labpc_adc_timing()
383 comedi_check_trigger_arg_min(&pacer->next_div2, 2); in labpc_adc_timing()
384 comedi_check_trigger_arg_max(&pacer->next_div2, in labpc_adc_timing()
389 base_period * pacer->next_div); in labpc_adc_timing()
391 base_period * pacer->next_div2); in labpc_adc_timing()
396 * (pacer->next_div2 / pacer->next_div1) in labpc_adc_timing()
399 cmd->flags); in labpc_adc_timing()
405 * (pacer->next_div / pacer->next_div1) in labpc_adc_timing()
408 cmd->flags); in labpc_adc_timing()
410 pacer->next_div = pacer->next_div2; in labpc_adc_timing()
420 if (cmd->chanlist_len == 1) in labpc_ai_scan_mode()
424 if (!cmd->chanlist) in labpc_ai_scan_mode()
427 chan0 = CR_CHAN(cmd->chanlist[0]); in labpc_ai_scan_mode()
428 chan1 = CR_CHAN(cmd->chanlist[1]); in labpc_ai_scan_mode()
444 unsigned int chan0 = CR_CHAN(cmd->chanlist[0]); in labpc_ai_check_chanlist()
445 unsigned int range0 = CR_RANGE(cmd->chanlist[0]); in labpc_ai_check_chanlist()
446 unsigned int aref0 = CR_AREF(cmd->chanlist[0]); in labpc_ai_check_chanlist()
449 for (i = 0; i < cmd->chanlist_len; i++) { in labpc_ai_check_chanlist()
450 unsigned int chan = CR_CHAN(cmd->chanlist[i]); in labpc_ai_check_chanlist()
451 unsigned int range = CR_RANGE(cmd->chanlist[i]); in labpc_ai_check_chanlist()
452 unsigned int aref = CR_AREF(cmd->chanlist[i]); in labpc_ai_check_chanlist()
459 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
461 return -EINVAL; in labpc_ai_check_chanlist()
466 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
468 return -EINVAL; in labpc_ai_check_chanlist()
472 if (chan != (cmd->chanlist_len - i - 1)) { in labpc_ai_check_chanlist()
473 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
475 return -EINVAL; in labpc_ai_check_chanlist()
481 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
483 return -EINVAL; in labpc_ai_check_chanlist()
487 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
489 return -EINVAL; in labpc_ai_check_chanlist()
499 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_ai_cmdtest()
507 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT); in labpc_ai_cmdtest()
508 err |= comedi_check_trigger_src(&cmd->scan_begin_src, in labpc_ai_cmdtest()
510 err |= comedi_check_trigger_src(&cmd->convert_src, in labpc_ai_cmdtest()
512 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); in labpc_ai_cmdtest()
515 if (board->is_labpc1200) in labpc_ai_cmdtest()
517 err |= comedi_check_trigger_src(&cmd->stop_src, stop_mask); in labpc_ai_cmdtest()
524 err |= comedi_check_trigger_is_unique(cmd->start_src); in labpc_ai_cmdtest()
525 err |= comedi_check_trigger_is_unique(cmd->scan_begin_src); in labpc_ai_cmdtest()
526 err |= comedi_check_trigger_is_unique(cmd->convert_src); in labpc_ai_cmdtest()
527 err |= comedi_check_trigger_is_unique(cmd->stop_src); in labpc_ai_cmdtest()
532 if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT) in labpc_ai_cmdtest()
540 switch (cmd->start_src) { in labpc_ai_cmdtest()
542 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); in labpc_ai_cmdtest()
549 if (!cmd->chanlist_len) in labpc_ai_cmdtest()
550 err |= -EINVAL; in labpc_ai_cmdtest()
551 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, in labpc_ai_cmdtest()
552 cmd->chanlist_len); in labpc_ai_cmdtest()
554 if (cmd->convert_src == TRIG_TIMER) { in labpc_ai_cmdtest()
555 err |= comedi_check_trigger_arg_min(&cmd->convert_arg, in labpc_ai_cmdtest()
556 board->ai_speed); in labpc_ai_cmdtest()
560 if (cmd->scan_begin_src == TRIG_TIMER) { in labpc_ai_cmdtest()
561 if (cmd->convert_src == TRIG_TIMER) { in labpc_ai_cmdtest()
563 &cmd->scan_begin_arg, in labpc_ai_cmdtest()
564 cmd->convert_arg * cmd->chanlist_len); in labpc_ai_cmdtest()
567 &cmd->scan_begin_arg, in labpc_ai_cmdtest()
568 board->ai_speed * cmd->chanlist_len); in labpc_ai_cmdtest()
571 switch (cmd->stop_src) { in labpc_ai_cmdtest()
573 err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1); in labpc_ai_cmdtest()
576 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0); in labpc_ai_cmdtest()
591 tmp = cmd->convert_arg; in labpc_ai_cmdtest()
592 tmp2 = cmd->scan_begin_arg; in labpc_ai_cmdtest()
595 if (tmp != cmd->convert_arg || tmp2 != cmd->scan_begin_arg) in labpc_ai_cmdtest()
602 if (cmd->chanlist && cmd->chanlist_len > 0) in labpc_ai_cmdtest()
613 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_ai_cmd()
614 struct labpc_private *devpriv = dev->private; in labpc_ai_cmd()
615 struct comedi_async *async = s->async; in labpc_ai_cmd()
616 struct comedi_cmd *cmd = &async->cmd; in labpc_ai_cmd()
619 cmd->chanlist[cmd->chanlist_len - 1] : in labpc_ai_cmd()
620 cmd->chanlist[0]; in labpc_ai_cmd()
627 /* make sure board is disabled before setting up acquisition */ in labpc_ai_cmd()
631 if (cmd->stop_src == TRIG_COUNT) in labpc_ai_cmd()
632 devpriv->count = cmd->stop_arg * cmd->chanlist_len; in labpc_ai_cmd()
635 if (cmd->stop_src == TRIG_EXT) { in labpc_ai_cmd()
640 comedi_8254_load(devpriv->counter, 1, in labpc_ai_cmd()
644 comedi_8254_set_mode(devpriv->counter, 1, in labpc_ai_cmd()
649 if (devpriv->dma && in labpc_ai_cmd()
650 (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0) { in labpc_ai_cmd()
653 * and too much setup time for CMDF_WAKE_EOS in labpc_ai_cmd()
656 } else if (board->is_labpc1200 && in labpc_ai_cmd()
657 (cmd->flags & CMDF_WAKE_EOS) == 0 && in labpc_ai_cmd()
658 (cmd->stop_src != TRIG_COUNT || devpriv->count > 256)) { in labpc_ai_cmd()
660 * pc-plus has no fifo-half full interrupt in labpc_ai_cmd()
661 * wake-end-of-scan should interrupt on fifo not empty in labpc_ai_cmd()
668 devpriv->current_transfer = xfer; in labpc_ai_cmd()
673 (cmd->stop_src == TRIG_EXT)); in labpc_ai_cmd()
677 devpriv->cmd1 |= CMD1_SCANEN; in labpc_ai_cmd()
681 * scan up to scan down mode - dunno why. in labpc_ai_cmd()
684 devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG); in labpc_ai_cmd()
687 devpriv->write_byte(dev, cmd->chanlist_len, INTERVAL_COUNT_REG); in labpc_ai_cmd()
689 devpriv->write_byte(dev, 0x1, INTERVAL_STROBE_REG); in labpc_ai_cmd()
691 if (cmd->convert_src == TRIG_TIMER || in labpc_ai_cmd()
692 cmd->scan_begin_src == TRIG_TIMER) { in labpc_ai_cmd()
693 struct comedi_8254 *pacer = dev->pacer; in labpc_ai_cmd()
694 struct comedi_8254 *counter = devpriv->counter; in labpc_ai_cmd()
699 comedi_8254_load(pacer, 0, pacer->divisor1, in labpc_ai_cmd()
705 comedi_8254_write(counter, 0, pacer->divisor); in labpc_ai_cmd()
709 comedi_8254_load(pacer, 1, pacer->divisor2, in labpc_ai_cmd()
719 devpriv->cmd3 |= CMD3_ERRINTEN; in labpc_ai_cmd()
722 devpriv->cmd3 |= CMD3_FIFOINTEN; in labpc_ai_cmd()
723 devpriv->write_byte(dev, devpriv->cmd3, CMD3_REG); in labpc_ai_cmd()
726 devpriv->cmd4 = 0; in labpc_ai_cmd()
727 if (cmd->convert_src != TRIG_EXT) in labpc_ai_cmd()
728 devpriv->cmd4 |= CMD4_ECLKRCV; in labpc_ai_cmd()
734 devpriv->cmd4 |= CMD4_INTSCAN; in labpc_ai_cmd()
735 if (cmd->scan_begin_src == TRIG_EXT) in labpc_ai_cmd()
736 devpriv->cmd4 |= CMD4_EOIRCV; in labpc_ai_cmd()
738 /* single-ended/differential */ in labpc_ai_cmd()
740 devpriv->cmd4 |= CMD4_SEDIFF; in labpc_ai_cmd()
741 devpriv->write_byte(dev, devpriv->cmd4, CMD4_REG); in labpc_ai_cmd()
743 /* startup acquisition */ in labpc_ai_cmd()
745 spin_lock_irqsave(&dev->spinlock, flags); in labpc_ai_cmd()
748 devpriv->cmd2 |= CMD2_TBSEL; in labpc_ai_cmd()
750 devpriv->cmd2 &= ~(CMD2_SWTRIG | CMD2_HWTRIG | CMD2_PRETRIG); in labpc_ai_cmd()
751 if (cmd->start_src == TRIG_EXT) in labpc_ai_cmd()
752 devpriv->cmd2 |= CMD2_HWTRIG; in labpc_ai_cmd()
754 devpriv->cmd2 |= CMD2_SWTRIG; in labpc_ai_cmd()
755 if (cmd->stop_src == TRIG_EXT) in labpc_ai_cmd()
756 devpriv->cmd2 |= (CMD2_HWTRIG | CMD2_PRETRIG); in labpc_ai_cmd()
758 devpriv->write_byte(dev, devpriv->cmd2, CMD2_REG); in labpc_ai_cmd()
760 spin_unlock_irqrestore(&dev->spinlock, flags); in labpc_ai_cmd()
768 struct labpc_private *devpriv = dev->private; in labpc_drain_fifo()
769 struct comedi_async *async = dev->read_subdev->async; in labpc_drain_fifo()
770 struct comedi_cmd *cmd = &async->cmd; in labpc_drain_fifo()
775 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); in labpc_drain_fifo()
777 for (i = 0; (devpriv->stat1 & STAT1_DAVAIL) && i < timeout; in labpc_drain_fifo()
780 if (cmd->stop_src == TRIG_COUNT) { in labpc_drain_fifo()
781 if (devpriv->count == 0) in labpc_drain_fifo()
783 devpriv->count--; in labpc_drain_fifo()
786 comedi_buf_write_samples(dev->read_subdev, &data, 1); in labpc_drain_fifo()
787 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); in labpc_drain_fifo()
790 dev_err(dev->class_dev, "ai timeout, fifo never empties\n"); in labpc_drain_fifo()
791 async->events |= COMEDI_CB_ERROR; in labpc_drain_fifo()
792 return -1; in labpc_drain_fifo()
800 * when acquisition is terminated by stop_src == TRIG_EXT).
804 struct labpc_private *devpriv = dev->private; in labpc_drain_dregs()
806 if (devpriv->current_transfer == isa_dma_transfer) in labpc_drain_dregs()
816 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_interrupt()
817 struct labpc_private *devpriv = dev->private; in labpc_interrupt()
818 struct comedi_subdevice *s = dev->read_subdev; in labpc_interrupt()
822 if (!dev->attached) { in labpc_interrupt()
823 dev_err(dev->class_dev, "premature interrupt\n"); in labpc_interrupt()
827 async = s->async; in labpc_interrupt()
828 cmd = &async->cmd; in labpc_interrupt()
831 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); in labpc_interrupt()
832 if (board->is_labpc1200) in labpc_interrupt()
833 devpriv->stat2 = devpriv->read_byte(dev, STAT2_REG); in labpc_interrupt()
835 if ((devpriv->stat1 & (STAT1_GATA0 | STAT1_CNTINT | STAT1_OVERFLOW | in labpc_interrupt()
837 (devpriv->stat2 & STAT2_OUTA1) == 0 && in labpc_interrupt()
838 (devpriv->stat2 & STAT2_FIFONHF)) { in labpc_interrupt()
842 if (devpriv->stat1 & STAT1_OVERRUN) { in labpc_interrupt()
844 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG); in labpc_interrupt()
845 async->events |= COMEDI_CB_ERROR; in labpc_interrupt()
847 dev_err(dev->class_dev, "overrun\n"); in labpc_interrupt()
851 if (devpriv->current_transfer == isa_dma_transfer) in labpc_interrupt()
856 if (devpriv->stat1 & STAT1_CNTINT) { in labpc_interrupt()
857 dev_err(dev->class_dev, "handled timer interrupt?\n"); in labpc_interrupt()
859 devpriv->write_byte(dev, 0x1, TIMER_CLEAR_REG); in labpc_interrupt()
862 if (devpriv->stat1 & STAT1_OVERFLOW) { in labpc_interrupt()
864 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG); in labpc_interrupt()
865 async->events |= COMEDI_CB_ERROR; in labpc_interrupt()
867 dev_err(dev->class_dev, "overflow\n"); in labpc_interrupt()
871 if (cmd->stop_src == TRIG_EXT) { in labpc_interrupt()
872 if (devpriv->stat2 & STAT2_OUTA1) { in labpc_interrupt()
874 async->events |= COMEDI_CB_EOA; in labpc_interrupt()
878 /* TRIG_COUNT end of acquisition */ in labpc_interrupt()
879 if (cmd->stop_src == TRIG_COUNT) { in labpc_interrupt()
880 if (devpriv->count == 0) in labpc_interrupt()
881 async->events |= COMEDI_CB_EOA; in labpc_interrupt()
892 struct labpc_private *devpriv = dev->private; in labpc_ao_write()
894 devpriv->write_byte(dev, val & 0xff, DAC_LSB_REG(chan)); in labpc_ao_write()
895 devpriv->write_byte(dev, (val >> 8) & 0xff, DAC_MSB_REG(chan)); in labpc_ao_write()
897 s->readback[chan] = val; in labpc_ao_write()
905 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_ao_insn_write()
906 struct labpc_private *devpriv = dev->private; in labpc_ao_insn_write()
912 channel = CR_CHAN(insn->chanspec); in labpc_ao_insn_write()
916 * NOTE: hardware bug in daqcard-1200 means pacing cannot in labpc_ao_insn_write()
919 spin_lock_irqsave(&dev->spinlock, flags); in labpc_ao_insn_write()
920 devpriv->cmd2 &= ~CMD2_LDAC(channel); in labpc_ao_insn_write()
921 devpriv->write_byte(dev, devpriv->cmd2, CMD2_REG); in labpc_ao_insn_write()
922 spin_unlock_irqrestore(&dev->spinlock, flags); in labpc_ao_insn_write()
925 if (board->is_labpc1200) { in labpc_ao_insn_write()
926 range = CR_RANGE(insn->chanspec); in labpc_ao_insn_write()
928 devpriv->cmd6 |= CMD6_DACUNI(channel); in labpc_ao_insn_write()
930 devpriv->cmd6 &= ~CMD6_DACUNI(channel); in labpc_ao_insn_write()
932 devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG); in labpc_ao_insn_write()
935 for (i = 0; i < insn->n; i++) in labpc_ao_insn_write()
938 return insn->n; in labpc_ao_insn_write()
945 struct labpc_private *devpriv = dev->private; in labpc_serial_out()
950 devpriv->cmd5 &= ~CMD5_SCLK; in labpc_serial_out()
952 if (value & (1 << (value_width - i))) in labpc_serial_out()
953 devpriv->cmd5 |= CMD5_SDATA; in labpc_serial_out()
955 devpriv->cmd5 &= ~CMD5_SDATA; in labpc_serial_out()
957 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_serial_out()
959 devpriv->cmd5 |= CMD5_SCLK; in labpc_serial_out()
961 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_serial_out()
968 struct labpc_private *devpriv = dev->private; in labpc_serial_in()
975 devpriv->cmd5 |= CMD5_SCLK; in labpc_serial_in()
977 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_serial_in()
979 devpriv->cmd5 &= ~CMD5_SCLK; in labpc_serial_in()
981 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_serial_in()
984 devpriv->stat2 = devpriv->read_byte(dev, STAT2_REG); in labpc_serial_in()
985 if (devpriv->stat2 & STAT2_PROMOUT) in labpc_serial_in()
986 value |= 1 << (value_width - i); in labpc_serial_in()
995 struct labpc_private *devpriv = dev->private; in labpc_eeprom_read()
1003 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_read()
1005 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read()
1006 devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_read()
1008 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read()
1018 devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_read()
1020 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read()
1027 struct labpc_private *devpriv = dev->private; in labpc_eeprom_read_status()
1033 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_read_status()
1035 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read_status()
1036 devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_read_status()
1038 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read_status()
1046 devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_read_status()
1048 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read_status()
1056 struct labpc_private *devpriv = dev->private; in labpc_eeprom_write()
1062 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_write()
1064 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1065 devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_write()
1067 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1071 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_write()
1073 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1076 devpriv->cmd5 |= CMD5_EEPROMCS; in labpc_eeprom_write()
1078 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1084 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_write()
1086 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1089 devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_write()
1091 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1098 struct labpc_private *devpriv = dev->private; in write_caldac()
1101 devpriv->cmd5 &= ~(CMD5_CALDACLD | CMD5_EEPROMCS | CMD5_WRTPRT); in write_caldac()
1103 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in write_caldac()
1111 devpriv->cmd5 |= CMD5_CALDACLD; in write_caldac()
1113 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in write_caldac()
1114 devpriv->cmd5 &= ~CMD5_CALDACLD; in write_caldac()
1116 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in write_caldac()
1124 unsigned int chan = CR_CHAN(insn->chanspec); in labpc_calib_insn_write()
1130 if (insn->n > 0) { in labpc_calib_insn_write()
1131 unsigned int val = data[insn->n - 1]; in labpc_calib_insn_write()
1133 if (s->readback[chan] != val) { in labpc_calib_insn_write()
1135 s->readback[chan] = val; in labpc_calib_insn_write()
1139 return insn->n; in labpc_calib_insn_write()
1153 return -EBUSY; in labpc_eeprom_ready()
1161 unsigned int chan = CR_CHAN(insn->chanspec); in labpc_eeprom_insn_write()
1166 return -EINVAL; in labpc_eeprom_insn_write()
1172 if (insn->n > 0) { in labpc_eeprom_insn_write()
1173 unsigned int val = data[insn->n - 1]; in labpc_eeprom_insn_write()
1180 s->readback[chan] = val; in labpc_eeprom_insn_write()
1183 return insn->n; in labpc_eeprom_insn_write()
1189 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_common_attach()
1197 return -ENOMEM; in labpc_common_attach()
1199 if (dev->mmio) { in labpc_common_attach()
1200 devpriv->read_byte = labpc_readb; in labpc_common_attach()
1201 devpriv->write_byte = labpc_writeb; in labpc_common_attach()
1203 devpriv->read_byte = labpc_inb; in labpc_common_attach()
1204 devpriv->write_byte = labpc_outb; in labpc_common_attach()
1208 devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG); in labpc_common_attach()
1209 devpriv->write_byte(dev, devpriv->cmd2, CMD2_REG); in labpc_common_attach()
1210 devpriv->write_byte(dev, devpriv->cmd3, CMD3_REG); in labpc_common_attach()
1211 devpriv->write_byte(dev, devpriv->cmd4, CMD4_REG); in labpc_common_attach()
1212 if (board->is_labpc1200) { in labpc_common_attach()
1213 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_common_attach()
1214 devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG); in labpc_common_attach()
1219 dev->board_name, dev); in labpc_common_attach()
1221 dev->irq = irq; in labpc_common_attach()
1224 if (dev->mmio) { in labpc_common_attach()
1225 dev->pacer = comedi_8254_mm_init(dev->mmio + COUNTER_B_BASE_REG, in labpc_common_attach()
1228 devpriv->counter = comedi_8254_mm_init(dev->mmio + in labpc_common_attach()
1233 dev->pacer = comedi_8254_init(dev->iobase + COUNTER_B_BASE_REG, in labpc_common_attach()
1236 devpriv->counter = comedi_8254_init(dev->iobase + in labpc_common_attach()
1241 if (!dev->pacer || !devpriv->counter) in labpc_common_attach()
1242 return -ENOMEM; in labpc_common_attach()
1249 s = &dev->subdevices[0]; in labpc_common_attach()
1250 s->type = COMEDI_SUBD_AI; in labpc_common_attach()
1251 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON | SDF_DIFF; in labpc_common_attach()
1252 s->n_chan = 8; in labpc_common_attach()
1253 s->len_chanlist = 8; in labpc_common_attach()
1254 s->maxdata = 0x0fff; in labpc_common_attach()
1255 s->range_table = board->is_labpc1200 ? in labpc_common_attach()
1257 s->insn_read = labpc_ai_insn_read; in labpc_common_attach()
1258 if (dev->irq) { in labpc_common_attach()
1259 dev->read_subdev = s; in labpc_common_attach()
1260 s->subdev_flags |= SDF_CMD_READ; in labpc_common_attach()
1261 s->do_cmd = labpc_ai_cmd; in labpc_common_attach()
1262 s->do_cmdtest = labpc_ai_cmdtest; in labpc_common_attach()
1263 s->cancel = labpc_cancel; in labpc_common_attach()
1267 s = &dev->subdevices[1]; in labpc_common_attach()
1268 if (board->has_ao) { in labpc_common_attach()
1269 s->type = COMEDI_SUBD_AO; in labpc_common_attach()
1270 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND; in labpc_common_attach()
1271 s->n_chan = 2; in labpc_common_attach()
1272 s->maxdata = 0x0fff; in labpc_common_attach()
1273 s->range_table = &range_labpc_ao; in labpc_common_attach()
1274 s->insn_write = labpc_ao_insn_write; in labpc_common_attach()
1281 for (i = 0; i < s->n_chan; i++) in labpc_common_attach()
1282 labpc_ao_write(dev, s, i, s->maxdata / 2); in labpc_common_attach()
1284 s->type = COMEDI_SUBD_UNUSED; in labpc_common_attach()
1288 s = &dev->subdevices[2]; in labpc_common_attach()
1289 if (dev->mmio) in labpc_common_attach()
1297 s = &dev->subdevices[3]; in labpc_common_attach()
1298 if (board->is_labpc1200) { in labpc_common_attach()
1299 s->type = COMEDI_SUBD_CALIB; in labpc_common_attach()
1300 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; in labpc_common_attach()
1301 s->n_chan = 16; in labpc_common_attach()
1302 s->maxdata = 0xff; in labpc_common_attach()
1303 s->insn_write = labpc_calib_insn_write; in labpc_common_attach()
1309 for (i = 0; i < s->n_chan; i++) { in labpc_common_attach()
1310 write_caldac(dev, i, s->maxdata / 2); in labpc_common_attach()
1311 s->readback[i] = s->maxdata / 2; in labpc_common_attach()
1314 s->type = COMEDI_SUBD_UNUSED; in labpc_common_attach()
1318 s = &dev->subdevices[4]; in labpc_common_attach()
1319 if (board->is_labpc1200) { in labpc_common_attach()
1320 s->type = COMEDI_SUBD_MEMORY; in labpc_common_attach()
1321 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; in labpc_common_attach()
1322 s->n_chan = 256; in labpc_common_attach()
1323 s->maxdata = 0xff; in labpc_common_attach()
1324 s->insn_write = labpc_eeprom_insn_write; in labpc_common_attach()
1330 for (i = 0; i < s->n_chan; i++) in labpc_common_attach()
1331 s->readback[i] = labpc_eeprom_read(dev, i); in labpc_common_attach()
1333 s->type = COMEDI_SUBD_UNUSED; in labpc_common_attach()
1342 struct labpc_private *devpriv = dev->private; in labpc_common_detach()
1345 kfree(devpriv->counter); in labpc_common_detach()