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>
86 return inb(dev->iobase + reg); in labpc_inb()
92 outb(byte, dev->iobase + reg); in labpc_outb()
99 return readb(dev->mmio + reg); in labpc_readb()
105 writeb(byte, dev->mmio + reg); in labpc_writeb()
110 struct labpc_private *devpriv = dev->private; in labpc_cancel()
113 spin_lock_irqsave(&dev->spinlock, flags); in labpc_cancel()
114 devpriv->cmd2 &= ~(CMD2_SWTRIG | CMD2_HWTRIG | CMD2_PRETRIG); in labpc_cancel()
115 devpriv->write_byte(dev, devpriv->cmd2, CMD2_REG); in labpc_cancel()
116 spin_unlock_irqrestore(&dev->spinlock, flags); in labpc_cancel()
118 devpriv->cmd3 = 0; in labpc_cancel()
119 devpriv->write_byte(dev, devpriv->cmd3, CMD3_REG); in labpc_cancel()
130 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_ai_set_chan_and_gain()
131 struct labpc_private *devpriv = dev->private; in labpc_ai_set_chan_and_gain()
133 if (board->is_labpc1200) { in labpc_ai_set_chan_and_gain()
135 * The LabPC-1200 boards do not have a gain in labpc_ai_set_chan_and_gain()
146 devpriv->cmd1 = CMD1_MA(chan); in labpc_ai_set_chan_and_gain()
147 devpriv->cmd1 |= CMD1_GAIN(range); in labpc_ai_set_chan_and_gain()
149 devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG); in labpc_ai_set_chan_and_gain()
160 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_setup_cmd6_reg()
161 struct labpc_private *devpriv = dev->private; in labpc_setup_cmd6_reg()
163 if (!board->is_labpc1200) in labpc_setup_cmd6_reg()
168 devpriv->cmd6 |= CMD6_NRSE; in labpc_setup_cmd6_reg()
170 devpriv->cmd6 &= ~CMD6_NRSE; in labpc_setup_cmd6_reg()
174 devpriv->cmd6 |= CMD6_ADCUNI; in labpc_setup_cmd6_reg()
176 devpriv->cmd6 &= ~CMD6_ADCUNI; in labpc_setup_cmd6_reg()
180 devpriv->cmd6 |= CMD6_HFINTEN; in labpc_setup_cmd6_reg()
182 devpriv->cmd6 &= ~CMD6_HFINTEN; in labpc_setup_cmd6_reg()
186 devpriv->cmd6 |= CMD6_DQINTEN; in labpc_setup_cmd6_reg()
188 devpriv->cmd6 &= ~CMD6_DQINTEN; in labpc_setup_cmd6_reg()
192 devpriv->cmd6 |= CMD6_SCANUP; in labpc_setup_cmd6_reg()
194 devpriv->cmd6 &= ~CMD6_SCANUP; in labpc_setup_cmd6_reg()
196 devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG); in labpc_setup_cmd6_reg()
201 struct labpc_private *devpriv = dev->private; in labpc_read_adc_fifo()
202 unsigned int lsb = devpriv->read_byte(dev, ADC_FIFO_REG); in labpc_read_adc_fifo()
203 unsigned int msb = devpriv->read_byte(dev, ADC_FIFO_REG); in labpc_read_adc_fifo()
210 struct labpc_private *devpriv = dev->private; in labpc_clear_adc_fifo()
212 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG); in labpc_clear_adc_fifo()
221 struct labpc_private *devpriv = dev->private; in labpc_ai_eoc()
223 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); in labpc_ai_eoc()
224 if (devpriv->stat1 & STAT1_DAVAIL) in labpc_ai_eoc()
226 return -EBUSY; in labpc_ai_eoc()
234 struct labpc_private *devpriv = dev->private; in labpc_ai_insn_read()
235 unsigned int chan = CR_CHAN(insn->chanspec); in labpc_ai_insn_read()
236 unsigned int range = CR_RANGE(insn->chanspec); in labpc_ai_insn_read()
237 unsigned int aref = CR_AREF(insn->chanspec); in labpc_ai_insn_read()
250 devpriv->cmd4 = 0; in labpc_ai_insn_read()
251 devpriv->cmd4 |= CMD4_ECLKRCV; in labpc_ai_insn_read()
252 /* single-ended/differential */ in labpc_ai_insn_read()
254 devpriv->cmd4 |= CMD4_SEDIFF; in labpc_ai_insn_read()
255 devpriv->write_byte(dev, devpriv->cmd4, CMD4_REG); in labpc_ai_insn_read()
258 comedi_8254_set_mode(devpriv->counter, 0, I8254_MODE2 | I8254_BINARY); in labpc_ai_insn_read()
262 for (i = 0; i < insn->n; i++) { in labpc_ai_insn_read()
264 devpriv->write_byte(dev, 0x1, ADC_START_CONVERT_REG); in labpc_ai_insn_read()
273 return insn->n; in labpc_ai_insn_read()
279 if (mode == MODE_SINGLE_CHAN || cmd->scan_begin_src == TRIG_FOLLOW) in labpc_use_continuous_mode()
288 if (cmd->convert_src != TRIG_TIMER) in labpc_ai_convert_period()
291 if (mode == MODE_SINGLE_CHAN && cmd->scan_begin_src == TRIG_TIMER) in labpc_ai_convert_period()
292 return cmd->scan_begin_arg; in labpc_ai_convert_period()
294 return cmd->convert_arg; in labpc_ai_convert_period()
298 enum scan_mode mode, unsigned int ns) in labpc_set_ai_convert_period() argument
300 if (cmd->convert_src != TRIG_TIMER) in labpc_set_ai_convert_period()
304 cmd->scan_begin_src == TRIG_TIMER) { in labpc_set_ai_convert_period()
305 cmd->scan_begin_arg = ns; in labpc_set_ai_convert_period()
306 if (cmd->convert_arg > cmd->scan_begin_arg) in labpc_set_ai_convert_period()
307 cmd->convert_arg = cmd->scan_begin_arg; in labpc_set_ai_convert_period()
309 cmd->convert_arg = ns; in labpc_set_ai_convert_period()
316 if (cmd->scan_begin_src != TRIG_TIMER) in labpc_ai_scan_period()
319 if (mode == MODE_SINGLE_CHAN && cmd->convert_src == TRIG_TIMER) in labpc_ai_scan_period()
322 return cmd->scan_begin_arg; in labpc_ai_scan_period()
326 enum scan_mode mode, unsigned int ns) in labpc_set_ai_scan_period() argument
328 if (cmd->scan_begin_src != TRIG_TIMER) in labpc_set_ai_scan_period()
331 if (mode == MODE_SINGLE_CHAN && cmd->convert_src == TRIG_TIMER) in labpc_set_ai_scan_period()
334 cmd->scan_begin_arg = ns; in labpc_set_ai_scan_period()
341 struct comedi_8254 *pacer = dev->pacer; in labpc_adc_timing()
356 pacer->next_div1 = (scan_period - 1) / in labpc_adc_timing()
357 (pacer->osc_base * I8254_MAX_COUNT) + 1; in labpc_adc_timing()
359 comedi_check_trigger_arg_min(&pacer->next_div1, 2); in labpc_adc_timing()
360 comedi_check_trigger_arg_max(&pacer->next_div1, in labpc_adc_timing()
363 base_period = pacer->osc_base * pacer->next_div1; in labpc_adc_timing()
366 switch (cmd->flags & CMDF_ROUND_MASK) { in labpc_adc_timing()
369 pacer->next_div = DIV_ROUND_CLOSEST(convert_period, in labpc_adc_timing()
371 pacer->next_div2 = DIV_ROUND_CLOSEST(scan_period, in labpc_adc_timing()
375 pacer->next_div = DIV_ROUND_UP(convert_period, in labpc_adc_timing()
377 pacer->next_div2 = DIV_ROUND_UP(scan_period, in labpc_adc_timing()
381 pacer->next_div = convert_period / base_period; in labpc_adc_timing()
382 pacer->next_div2 = scan_period / base_period; in labpc_adc_timing()
386 comedi_check_trigger_arg_min(&pacer->next_div, 2); in labpc_adc_timing()
387 comedi_check_trigger_arg_max(&pacer->next_div, I8254_MAX_COUNT); in labpc_adc_timing()
388 comedi_check_trigger_arg_min(&pacer->next_div2, 2); in labpc_adc_timing()
389 comedi_check_trigger_arg_max(&pacer->next_div2, in labpc_adc_timing()
394 base_period * pacer->next_div); in labpc_adc_timing()
396 base_period * pacer->next_div2); in labpc_adc_timing()
401 * (pacer->next_div2 / pacer->next_div1) in labpc_adc_timing()
404 cmd->flags); in labpc_adc_timing()
410 * (pacer->next_div / pacer->next_div1) in labpc_adc_timing()
413 cmd->flags); in labpc_adc_timing()
415 pacer->next_div = pacer->next_div2; in labpc_adc_timing()
425 if (cmd->chanlist_len == 1) in labpc_ai_scan_mode()
429 if (!cmd->chanlist) in labpc_ai_scan_mode()
432 chan0 = CR_CHAN(cmd->chanlist[0]); in labpc_ai_scan_mode()
433 chan1 = CR_CHAN(cmd->chanlist[1]); in labpc_ai_scan_mode()
449 unsigned int chan0 = CR_CHAN(cmd->chanlist[0]); in labpc_ai_check_chanlist()
450 unsigned int range0 = CR_RANGE(cmd->chanlist[0]); in labpc_ai_check_chanlist()
451 unsigned int aref0 = CR_AREF(cmd->chanlist[0]); in labpc_ai_check_chanlist()
454 for (i = 0; i < cmd->chanlist_len; i++) { in labpc_ai_check_chanlist()
455 unsigned int chan = CR_CHAN(cmd->chanlist[i]); in labpc_ai_check_chanlist()
456 unsigned int range = CR_RANGE(cmd->chanlist[i]); in labpc_ai_check_chanlist()
457 unsigned int aref = CR_AREF(cmd->chanlist[i]); in labpc_ai_check_chanlist()
464 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
466 return -EINVAL; in labpc_ai_check_chanlist()
471 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
473 return -EINVAL; in labpc_ai_check_chanlist()
477 if (chan != (cmd->chanlist_len - i - 1)) { in labpc_ai_check_chanlist()
478 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
480 return -EINVAL; in labpc_ai_check_chanlist()
486 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
488 return -EINVAL; in labpc_ai_check_chanlist()
492 dev_dbg(dev->class_dev, in labpc_ai_check_chanlist()
494 return -EINVAL; in labpc_ai_check_chanlist()
504 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_ai_cmdtest()
512 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT); in labpc_ai_cmdtest()
513 err |= comedi_check_trigger_src(&cmd->scan_begin_src, in labpc_ai_cmdtest()
515 err |= comedi_check_trigger_src(&cmd->convert_src, in labpc_ai_cmdtest()
517 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); in labpc_ai_cmdtest()
520 if (board->is_labpc1200) in labpc_ai_cmdtest()
522 err |= comedi_check_trigger_src(&cmd->stop_src, stop_mask); in labpc_ai_cmdtest()
529 err |= comedi_check_trigger_is_unique(cmd->start_src); in labpc_ai_cmdtest()
530 err |= comedi_check_trigger_is_unique(cmd->scan_begin_src); in labpc_ai_cmdtest()
531 err |= comedi_check_trigger_is_unique(cmd->convert_src); in labpc_ai_cmdtest()
532 err |= comedi_check_trigger_is_unique(cmd->stop_src); in labpc_ai_cmdtest()
537 if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT) in labpc_ai_cmdtest()
545 switch (cmd->start_src) { in labpc_ai_cmdtest()
547 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); in labpc_ai_cmdtest()
554 if (!cmd->chanlist_len) in labpc_ai_cmdtest()
555 err |= -EINVAL; in labpc_ai_cmdtest()
556 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, in labpc_ai_cmdtest()
557 cmd->chanlist_len); in labpc_ai_cmdtest()
559 if (cmd->convert_src == TRIG_TIMER) { in labpc_ai_cmdtest()
560 err |= comedi_check_trigger_arg_min(&cmd->convert_arg, in labpc_ai_cmdtest()
561 board->ai_speed); in labpc_ai_cmdtest()
565 if (cmd->scan_begin_src == TRIG_TIMER) { in labpc_ai_cmdtest()
566 if (cmd->convert_src == TRIG_TIMER) { in labpc_ai_cmdtest()
568 &cmd->scan_begin_arg, in labpc_ai_cmdtest()
569 cmd->convert_arg * cmd->chanlist_len); in labpc_ai_cmdtest()
572 &cmd->scan_begin_arg, in labpc_ai_cmdtest()
573 board->ai_speed * cmd->chanlist_len); in labpc_ai_cmdtest()
576 switch (cmd->stop_src) { in labpc_ai_cmdtest()
578 err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1); in labpc_ai_cmdtest()
581 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0); in labpc_ai_cmdtest()
596 tmp = cmd->convert_arg; in labpc_ai_cmdtest()
597 tmp2 = cmd->scan_begin_arg; in labpc_ai_cmdtest()
600 if (tmp != cmd->convert_arg || tmp2 != cmd->scan_begin_arg) in labpc_ai_cmdtest()
607 if (cmd->chanlist && cmd->chanlist_len > 0) in labpc_ai_cmdtest()
618 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_ai_cmd()
619 struct labpc_private *devpriv = dev->private; in labpc_ai_cmd()
620 struct comedi_async *async = s->async; in labpc_ai_cmd()
621 struct comedi_cmd *cmd = &async->cmd; in labpc_ai_cmd()
624 cmd->chanlist[cmd->chanlist_len - 1] : in labpc_ai_cmd()
625 cmd->chanlist[0]; in labpc_ai_cmd()
632 /* make sure board is disabled before setting up acquisition */ in labpc_ai_cmd()
636 if (cmd->stop_src == TRIG_COUNT) in labpc_ai_cmd()
637 devpriv->count = cmd->stop_arg * cmd->chanlist_len; in labpc_ai_cmd()
640 if (cmd->stop_src == TRIG_EXT) { in labpc_ai_cmd()
645 comedi_8254_load(devpriv->counter, 1, in labpc_ai_cmd()
649 comedi_8254_set_mode(devpriv->counter, 1, in labpc_ai_cmd()
654 if (devpriv->dma && in labpc_ai_cmd()
655 (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0) { in labpc_ai_cmd()
658 * and too much setup time for CMDF_WAKE_EOS in labpc_ai_cmd()
661 } else if (board->is_labpc1200 && in labpc_ai_cmd()
662 (cmd->flags & CMDF_WAKE_EOS) == 0 && in labpc_ai_cmd()
663 (cmd->stop_src != TRIG_COUNT || devpriv->count > 256)) { in labpc_ai_cmd()
665 * pc-plus has no fifo-half full interrupt in labpc_ai_cmd()
666 * wake-end-of-scan should interrupt on fifo not empty in labpc_ai_cmd()
673 devpriv->current_transfer = xfer; in labpc_ai_cmd()
678 (cmd->stop_src == TRIG_EXT)); in labpc_ai_cmd()
682 devpriv->cmd1 |= CMD1_SCANEN; in labpc_ai_cmd()
686 * scan up to scan down mode - dunno why. in labpc_ai_cmd()
689 devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG); in labpc_ai_cmd()
692 devpriv->write_byte(dev, cmd->chanlist_len, INTERVAL_COUNT_REG); in labpc_ai_cmd()
694 devpriv->write_byte(dev, 0x1, INTERVAL_STROBE_REG); in labpc_ai_cmd()
696 if (cmd->convert_src == TRIG_TIMER || in labpc_ai_cmd()
697 cmd->scan_begin_src == TRIG_TIMER) { in labpc_ai_cmd()
698 struct comedi_8254 *pacer = dev->pacer; in labpc_ai_cmd()
699 struct comedi_8254 *counter = devpriv->counter; in labpc_ai_cmd()
704 comedi_8254_load(pacer, 0, pacer->divisor1, in labpc_ai_cmd()
710 comedi_8254_write(counter, 0, pacer->divisor); in labpc_ai_cmd()
714 comedi_8254_load(pacer, 1, pacer->divisor2, in labpc_ai_cmd()
724 devpriv->cmd3 |= CMD3_ERRINTEN; in labpc_ai_cmd()
727 devpriv->cmd3 |= CMD3_FIFOINTEN; in labpc_ai_cmd()
728 devpriv->write_byte(dev, devpriv->cmd3, CMD3_REG); in labpc_ai_cmd()
731 devpriv->cmd4 = 0; in labpc_ai_cmd()
732 if (cmd->convert_src != TRIG_EXT) in labpc_ai_cmd()
733 devpriv->cmd4 |= CMD4_ECLKRCV; in labpc_ai_cmd()
739 devpriv->cmd4 |= CMD4_INTSCAN; in labpc_ai_cmd()
740 if (cmd->scan_begin_src == TRIG_EXT) in labpc_ai_cmd()
741 devpriv->cmd4 |= CMD4_EOIRCV; in labpc_ai_cmd()
743 /* single-ended/differential */ in labpc_ai_cmd()
745 devpriv->cmd4 |= CMD4_SEDIFF; in labpc_ai_cmd()
746 devpriv->write_byte(dev, devpriv->cmd4, CMD4_REG); in labpc_ai_cmd()
748 /* startup acquisition */ in labpc_ai_cmd()
750 spin_lock_irqsave(&dev->spinlock, flags); in labpc_ai_cmd()
753 devpriv->cmd2 |= CMD2_TBSEL; in labpc_ai_cmd()
755 devpriv->cmd2 &= ~(CMD2_SWTRIG | CMD2_HWTRIG | CMD2_PRETRIG); in labpc_ai_cmd()
756 if (cmd->start_src == TRIG_EXT) in labpc_ai_cmd()
757 devpriv->cmd2 |= CMD2_HWTRIG; in labpc_ai_cmd()
759 devpriv->cmd2 |= CMD2_SWTRIG; in labpc_ai_cmd()
760 if (cmd->stop_src == TRIG_EXT) in labpc_ai_cmd()
761 devpriv->cmd2 |= (CMD2_HWTRIG | CMD2_PRETRIG); in labpc_ai_cmd()
763 devpriv->write_byte(dev, devpriv->cmd2, CMD2_REG); in labpc_ai_cmd()
765 spin_unlock_irqrestore(&dev->spinlock, flags); in labpc_ai_cmd()
773 struct labpc_private *devpriv = dev->private; in labpc_drain_fifo()
774 struct comedi_async *async = dev->read_subdev->async; in labpc_drain_fifo()
775 struct comedi_cmd *cmd = &async->cmd; in labpc_drain_fifo()
780 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); in labpc_drain_fifo()
782 for (i = 0; (devpriv->stat1 & STAT1_DAVAIL) && i < timeout; in labpc_drain_fifo()
785 if (cmd->stop_src == TRIG_COUNT) { in labpc_drain_fifo()
786 if (devpriv->count == 0) in labpc_drain_fifo()
788 devpriv->count--; in labpc_drain_fifo()
791 comedi_buf_write_samples(dev->read_subdev, &data, 1); in labpc_drain_fifo()
792 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); in labpc_drain_fifo()
795 dev_err(dev->class_dev, "ai timeout, fifo never empties\n"); in labpc_drain_fifo()
796 async->events |= COMEDI_CB_ERROR; in labpc_drain_fifo()
797 return -1; in labpc_drain_fifo()
805 * when acquisition is terminated by stop_src == TRIG_EXT).
809 struct labpc_private *devpriv = dev->private; in labpc_drain_dregs()
811 if (devpriv->current_transfer == isa_dma_transfer) in labpc_drain_dregs()
821 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_interrupt()
822 struct labpc_private *devpriv = dev->private; in labpc_interrupt()
823 struct comedi_subdevice *s = dev->read_subdev; in labpc_interrupt()
827 if (!dev->attached) { in labpc_interrupt()
828 dev_err(dev->class_dev, "premature interrupt\n"); in labpc_interrupt()
832 async = s->async; in labpc_interrupt()
833 cmd = &async->cmd; in labpc_interrupt()
836 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); in labpc_interrupt()
837 if (board->is_labpc1200) in labpc_interrupt()
838 devpriv->stat2 = devpriv->read_byte(dev, STAT2_REG); in labpc_interrupt()
840 if ((devpriv->stat1 & (STAT1_GATA0 | STAT1_CNTINT | STAT1_OVERFLOW | in labpc_interrupt()
842 (devpriv->stat2 & STAT2_OUTA1) == 0 && in labpc_interrupt()
843 (devpriv->stat2 & STAT2_FIFONHF)) { in labpc_interrupt()
847 if (devpriv->stat1 & STAT1_OVERRUN) { in labpc_interrupt()
849 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG); in labpc_interrupt()
850 async->events |= COMEDI_CB_ERROR; in labpc_interrupt()
852 dev_err(dev->class_dev, "overrun\n"); in labpc_interrupt()
856 if (devpriv->current_transfer == isa_dma_transfer) in labpc_interrupt()
861 if (devpriv->stat1 & STAT1_CNTINT) { in labpc_interrupt()
862 dev_err(dev->class_dev, "handled timer interrupt?\n"); in labpc_interrupt()
864 devpriv->write_byte(dev, 0x1, TIMER_CLEAR_REG); in labpc_interrupt()
867 if (devpriv->stat1 & STAT1_OVERFLOW) { in labpc_interrupt()
869 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG); in labpc_interrupt()
870 async->events |= COMEDI_CB_ERROR; in labpc_interrupt()
872 dev_err(dev->class_dev, "overflow\n"); in labpc_interrupt()
876 if (cmd->stop_src == TRIG_EXT) { in labpc_interrupt()
877 if (devpriv->stat2 & STAT2_OUTA1) { in labpc_interrupt()
879 async->events |= COMEDI_CB_EOA; in labpc_interrupt()
883 /* TRIG_COUNT end of acquisition */ in labpc_interrupt()
884 if (cmd->stop_src == TRIG_COUNT) { in labpc_interrupt()
885 if (devpriv->count == 0) in labpc_interrupt()
886 async->events |= COMEDI_CB_EOA; in labpc_interrupt()
897 struct labpc_private *devpriv = dev->private; in labpc_ao_write()
899 devpriv->write_byte(dev, val & 0xff, DAC_LSB_REG(chan)); in labpc_ao_write()
900 devpriv->write_byte(dev, (val >> 8) & 0xff, DAC_MSB_REG(chan)); in labpc_ao_write()
902 s->readback[chan] = val; in labpc_ao_write()
910 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_ao_insn_write()
911 struct labpc_private *devpriv = dev->private; in labpc_ao_insn_write()
917 channel = CR_CHAN(insn->chanspec); in labpc_ao_insn_write()
921 * NOTE: hardware bug in daqcard-1200 means pacing cannot in labpc_ao_insn_write()
924 spin_lock_irqsave(&dev->spinlock, flags); in labpc_ao_insn_write()
925 devpriv->cmd2 &= ~CMD2_LDAC(channel); in labpc_ao_insn_write()
926 devpriv->write_byte(dev, devpriv->cmd2, CMD2_REG); in labpc_ao_insn_write()
927 spin_unlock_irqrestore(&dev->spinlock, flags); in labpc_ao_insn_write()
930 if (board->is_labpc1200) { in labpc_ao_insn_write()
931 range = CR_RANGE(insn->chanspec); in labpc_ao_insn_write()
933 devpriv->cmd6 |= CMD6_DACUNI(channel); in labpc_ao_insn_write()
935 devpriv->cmd6 &= ~CMD6_DACUNI(channel); in labpc_ao_insn_write()
937 devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG); in labpc_ao_insn_write()
940 for (i = 0; i < insn->n; i++) in labpc_ao_insn_write()
943 return insn->n; in labpc_ao_insn_write()
950 struct labpc_private *devpriv = dev->private; in labpc_serial_out()
955 devpriv->cmd5 &= ~CMD5_SCLK; in labpc_serial_out()
957 if (value & (1 << (value_width - i))) in labpc_serial_out()
958 devpriv->cmd5 |= CMD5_SDATA; in labpc_serial_out()
960 devpriv->cmd5 &= ~CMD5_SDATA; in labpc_serial_out()
962 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_serial_out()
964 devpriv->cmd5 |= CMD5_SCLK; in labpc_serial_out()
966 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_serial_out()
973 struct labpc_private *devpriv = dev->private; in labpc_serial_in()
980 devpriv->cmd5 |= CMD5_SCLK; in labpc_serial_in()
982 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_serial_in()
984 devpriv->cmd5 &= ~CMD5_SCLK; in labpc_serial_in()
986 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_serial_in()
989 devpriv->stat2 = devpriv->read_byte(dev, STAT2_REG); in labpc_serial_in()
990 if (devpriv->stat2 & STAT2_PROMOUT) in labpc_serial_in()
991 value |= 1 << (value_width - i); in labpc_serial_in()
1000 struct labpc_private *devpriv = dev->private; in labpc_eeprom_read()
1008 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_read()
1010 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read()
1011 devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_read()
1013 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read()
1023 devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_read()
1025 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read()
1032 struct labpc_private *devpriv = dev->private; in labpc_eeprom_read_status()
1038 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_read_status()
1040 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read_status()
1041 devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_read_status()
1043 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read_status()
1051 devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_read_status()
1053 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_read_status()
1061 struct labpc_private *devpriv = dev->private; in labpc_eeprom_write()
1067 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_write()
1069 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1070 devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_write()
1072 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()
1081 devpriv->cmd5 |= CMD5_EEPROMCS; in labpc_eeprom_write()
1083 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1089 devpriv->cmd5 &= ~CMD5_EEPROMCS; in labpc_eeprom_write()
1091 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1094 devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT); in labpc_eeprom_write()
1096 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_eeprom_write()
1103 struct labpc_private *devpriv = dev->private; in write_caldac()
1106 devpriv->cmd5 &= ~(CMD5_CALDACLD | CMD5_EEPROMCS | CMD5_WRTPRT); in write_caldac()
1108 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in write_caldac()
1116 devpriv->cmd5 |= CMD5_CALDACLD; in write_caldac()
1118 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in write_caldac()
1119 devpriv->cmd5 &= ~CMD5_CALDACLD; in write_caldac()
1121 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in write_caldac()
1129 unsigned int chan = CR_CHAN(insn->chanspec); in labpc_calib_insn_write()
1135 if (insn->n > 0) { in labpc_calib_insn_write()
1136 unsigned int val = data[insn->n - 1]; in labpc_calib_insn_write()
1138 if (s->readback[chan] != val) { in labpc_calib_insn_write()
1140 s->readback[chan] = val; in labpc_calib_insn_write()
1144 return insn->n; in labpc_calib_insn_write()
1158 return -EBUSY; in labpc_eeprom_ready()
1166 unsigned int chan = CR_CHAN(insn->chanspec); in labpc_eeprom_insn_write()
1171 return -EINVAL; in labpc_eeprom_insn_write()
1177 if (insn->n > 0) { in labpc_eeprom_insn_write()
1178 unsigned int val = data[insn->n - 1]; in labpc_eeprom_insn_write()
1185 s->readback[chan] = val; in labpc_eeprom_insn_write()
1188 return insn->n; in labpc_eeprom_insn_write()
1194 const struct labpc_boardinfo *board = dev->board_ptr; in labpc_common_attach()
1202 return -ENOMEM; in labpc_common_attach()
1204 if (dev->mmio) { in labpc_common_attach()
1205 devpriv->read_byte = labpc_readb; in labpc_common_attach()
1206 devpriv->write_byte = labpc_writeb; in labpc_common_attach()
1209 devpriv->read_byte = labpc_inb; in labpc_common_attach()
1210 devpriv->write_byte = labpc_outb; in labpc_common_attach()
1212 return -ENXIO; in labpc_common_attach()
1217 devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG); in labpc_common_attach()
1218 devpriv->write_byte(dev, devpriv->cmd2, CMD2_REG); in labpc_common_attach()
1219 devpriv->write_byte(dev, devpriv->cmd3, CMD3_REG); in labpc_common_attach()
1220 devpriv->write_byte(dev, devpriv->cmd4, CMD4_REG); in labpc_common_attach()
1221 if (board->is_labpc1200) { in labpc_common_attach()
1222 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); in labpc_common_attach()
1223 devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG); in labpc_common_attach()
1228 dev->board_name, dev); in labpc_common_attach()
1230 dev->irq = irq; in labpc_common_attach()
1233 if (dev->mmio) { in labpc_common_attach()
1234 dev->pacer = in labpc_common_attach()
1235 comedi_8254_mm_alloc(dev->mmio + COUNTER_B_BASE_REG, in labpc_common_attach()
1237 devpriv->counter = in labpc_common_attach()
1238 comedi_8254_mm_alloc(dev->mmio + COUNTER_A_BASE_REG, in labpc_common_attach()
1241 dev->pacer = in labpc_common_attach()
1242 comedi_8254_io_alloc(dev->iobase + COUNTER_B_BASE_REG, in labpc_common_attach()
1244 devpriv->counter = in labpc_common_attach()
1245 comedi_8254_io_alloc(dev->iobase + COUNTER_A_BASE_REG, in labpc_common_attach()
1248 if (IS_ERR(dev->pacer)) in labpc_common_attach()
1249 return PTR_ERR(dev->pacer); in labpc_common_attach()
1250 if (IS_ERR(devpriv->counter)) in labpc_common_attach()
1251 return PTR_ERR(devpriv->counter); in labpc_common_attach()
1258 s = &dev->subdevices[0]; in labpc_common_attach()
1259 s->type = COMEDI_SUBD_AI; in labpc_common_attach()
1260 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON | SDF_DIFF; in labpc_common_attach()
1261 s->n_chan = 8; in labpc_common_attach()
1262 s->len_chanlist = 8; in labpc_common_attach()
1263 s->maxdata = 0x0fff; in labpc_common_attach()
1264 s->range_table = board->is_labpc1200 ? in labpc_common_attach()
1266 s->insn_read = labpc_ai_insn_read; in labpc_common_attach()
1267 if (dev->irq) { in labpc_common_attach()
1268 dev->read_subdev = s; in labpc_common_attach()
1269 s->subdev_flags |= SDF_CMD_READ; in labpc_common_attach()
1270 s->do_cmd = labpc_ai_cmd; in labpc_common_attach()
1271 s->do_cmdtest = labpc_ai_cmdtest; in labpc_common_attach()
1272 s->cancel = labpc_cancel; in labpc_common_attach()
1276 s = &dev->subdevices[1]; in labpc_common_attach()
1277 if (board->has_ao) { in labpc_common_attach()
1278 s->type = COMEDI_SUBD_AO; in labpc_common_attach()
1279 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND; in labpc_common_attach()
1280 s->n_chan = 2; in labpc_common_attach()
1281 s->maxdata = 0x0fff; in labpc_common_attach()
1282 s->range_table = &range_labpc_ao; in labpc_common_attach()
1283 s->insn_write = labpc_ao_insn_write; in labpc_common_attach()
1290 for (i = 0; i < s->n_chan; i++) in labpc_common_attach()
1291 labpc_ao_write(dev, s, i, s->maxdata / 2); in labpc_common_attach()
1293 s->type = COMEDI_SUBD_UNUSED; in labpc_common_attach()
1297 s = &dev->subdevices[2]; in labpc_common_attach()
1298 if (dev->mmio) in labpc_common_attach()
1306 s = &dev->subdevices[3]; in labpc_common_attach()
1307 if (board->is_labpc1200) { in labpc_common_attach()
1308 s->type = COMEDI_SUBD_CALIB; in labpc_common_attach()
1309 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; in labpc_common_attach()
1310 s->n_chan = 16; in labpc_common_attach()
1311 s->maxdata = 0xff; in labpc_common_attach()
1312 s->insn_write = labpc_calib_insn_write; in labpc_common_attach()
1318 for (i = 0; i < s->n_chan; i++) { in labpc_common_attach()
1319 write_caldac(dev, i, s->maxdata / 2); in labpc_common_attach()
1320 s->readback[i] = s->maxdata / 2; in labpc_common_attach()
1323 s->type = COMEDI_SUBD_UNUSED; in labpc_common_attach()
1327 s = &dev->subdevices[4]; in labpc_common_attach()
1328 if (board->is_labpc1200) { in labpc_common_attach()
1329 s->type = COMEDI_SUBD_MEMORY; in labpc_common_attach()
1330 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; in labpc_common_attach()
1331 s->n_chan = 256; in labpc_common_attach()
1332 s->maxdata = 0xff; in labpc_common_attach()
1333 s->insn_write = labpc_eeprom_insn_write; in labpc_common_attach()
1339 for (i = 0; i < s->n_chan; i++) in labpc_common_attach()
1340 s->readback[i] = labpc_eeprom_read(dev, i); in labpc_common_attach()
1342 s->type = COMEDI_SUBD_UNUSED; in labpc_common_attach()
1351 struct labpc_private *devpriv = dev->private; in labpc_common_detach()
1354 if (!IS_ERR(devpriv->counter)) in labpc_common_detach()
1355 kfree(devpriv->counter); in labpc_common_detach()