diff options
Diffstat (limited to 'drivers/staging/comedi/drivers/ni_mio_common.c')
-rw-r--r-- | drivers/staging/comedi/drivers/ni_mio_common.c | 166 |
1 files changed, 67 insertions, 99 deletions
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index 320b080149b6..11e70173712d 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -686,13 +686,12 @@ static inline void ni_set_ai_dma_channel(struct comedi_device *dev, int channel) { unsigned bitfield; - if (channel >= 0) { + if (channel >= 0) bitfield = (ni_stc_dma_channel_select_bitfield(channel) << AI_DMA_Select_Shift) & AI_DMA_Select_Mask; - } else { + else bitfield = 0; - } ni_set_bitfield(dev, AI_AO_Select, AI_DMA_Select_Mask, bitfield); } @@ -701,13 +700,12 @@ static inline void ni_set_ao_dma_channel(struct comedi_device *dev, int channel) { unsigned bitfield; - if (channel >= 0) { + if (channel >= 0) bitfield = (ni_stc_dma_channel_select_bitfield(channel) << AO_DMA_Select_Shift) & AO_DMA_Select_Mask; - } else { + else bitfield = 0; - } ni_set_bitfield(dev, AI_AO_Select, AO_DMA_Select_Mask, bitfield); } @@ -1127,31 +1125,18 @@ static void ni_ao_fifo_load(struct comedi_device *dev, struct comedi_subdevice *s, int n) { struct ni_private *devpriv = dev->private; - struct comedi_async *async = s->async; - struct comedi_cmd *cmd = &async->cmd; - int chan; int i; unsigned short d; u32 packed_data; - int range; - int err = 1; - chan = async->cur_chan; for (i = 0; i < n; i++) { - err &= comedi_buf_get(s, &d); - if (err == 0) - break; - - range = CR_RANGE(cmd->chanlist[chan]); + comedi_buf_read_samples(s, &d, 1); if (devpriv->is_6xxx) { packed_data = d & 0xffff; /* 6711 only has 16 bit wide ao fifo */ if (!devpriv->is_6711) { - err &= comedi_buf_get(s, &d); - if (err == 0) - break; - chan++; + comedi_buf_read_samples(s, &d, 1); i++; packed_data |= (d << 16) & 0xffff0000; } @@ -1159,12 +1144,7 @@ static void ni_ao_fifo_load(struct comedi_device *dev, } else { ni_writew(dev, d, DAC_FIFO_Data); } - chan++; - chan %= cmd->chanlist_len; } - async->cur_chan = chan; - if (err == 0) - async->events |= COMEDI_CB_OVERFLOW; } /* @@ -1187,21 +1167,20 @@ static int ni_ao_fifo_half_empty(struct comedi_device *dev, struct comedi_subdevice *s) { const struct ni_board_struct *board = dev->board_ptr; - int n; + unsigned int nbytes; + unsigned int nsamples; - n = comedi_buf_read_n_available(s); - if (n == 0) { + nbytes = comedi_buf_read_n_available(s); + if (nbytes == 0) { s->async->events |= COMEDI_CB_OVERFLOW; return 0; } - n /= sizeof(short); - if (n > board->ao_fifo_depth / 2) - n = board->ao_fifo_depth / 2; - - ni_ao_fifo_load(dev, s, n); + nsamples = comedi_bytes_to_samples(s, nbytes); + if (nsamples > board->ao_fifo_depth / 2) + nsamples = board->ao_fifo_depth / 2; - s->async->events |= COMEDI_CB_BLOCK; + ni_ao_fifo_load(dev, s, nsamples); return 1; } @@ -1211,7 +1190,8 @@ static int ni_ao_prep_fifo(struct comedi_device *dev, { const struct ni_board_struct *board = dev->board_ptr; struct ni_private *devpriv = dev->private; - int n; + unsigned int nbytes; + unsigned int nsamples; /* reset fifo */ ni_stc_writew(dev, 1, DAC_FIFO_Clear); @@ -1219,17 +1199,17 @@ static int ni_ao_prep_fifo(struct comedi_device *dev, ni_ao_win_outl(dev, 0x6, AO_FIFO_Offset_Load_611x); /* load some data */ - n = comedi_buf_read_n_available(s); - if (n == 0) + nbytes = comedi_buf_read_n_available(s); + if (nbytes == 0) return 0; - n /= sizeof(short); - if (n > board->ao_fifo_depth) - n = board->ao_fifo_depth; + nsamples = comedi_bytes_to_samples(s, nbytes); + if (nsamples > board->ao_fifo_depth) + nsamples = board->ao_fifo_depth; - ni_ao_fifo_load(dev, s, n); + ni_ao_fifo_load(dev, s, nsamples); - return n; + return nsamples; } static void ni_ai_fifo_read(struct comedi_device *dev, @@ -1237,44 +1217,42 @@ static void ni_ai_fifo_read(struct comedi_device *dev, { struct ni_private *devpriv = dev->private; struct comedi_async *async = s->async; + u32 dl; + unsigned short data; int i; if (devpriv->is_611x) { - unsigned short data[2]; - u32 dl; - for (i = 0; i < n / 2; i++) { dl = ni_readl(dev, ADC_FIFO_Data_611x); /* This may get the hi/lo data in the wrong order */ - data[0] = (dl >> 16) & 0xffff; - data[1] = dl & 0xffff; - cfc_write_array_to_buffer(s, data, sizeof(data)); + data = (dl >> 16) & 0xffff; + comedi_buf_write_samples(s, &data, 1); + data = dl & 0xffff; + comedi_buf_write_samples(s, &data, 1); } /* Check if there's a single sample stuck in the FIFO */ if (n % 2) { dl = ni_readl(dev, ADC_FIFO_Data_611x); - data[0] = dl & 0xffff; - cfc_write_to_buffer(s, data[0]); + data = dl & 0xffff; + comedi_buf_write_samples(s, &data, 1); } } else if (devpriv->is_6143) { - unsigned short data[2]; - u32 dl; - /* This just reads the FIFO assuming the data is present, no checks on the FIFO status are performed */ for (i = 0; i < n / 2; i++) { dl = ni_readl(dev, AIFIFO_Data_6143); - data[0] = (dl >> 16) & 0xffff; - data[1] = dl & 0xffff; - cfc_write_array_to_buffer(s, data, sizeof(data)); + data = (dl >> 16) & 0xffff; + comedi_buf_write_samples(s, &data, 1); + data = dl & 0xffff; + comedi_buf_write_samples(s, &data, 1); } if (n % 2) { /* Assume there is a single sample stuck in the FIFO */ /* Get stranded sample into FIFO */ ni_writel(dev, 0x01, AIFIFO_Control_6143); dl = ni_readl(dev, AIFIFO_Data_6143); - data[0] = (dl >> 16) & 0xffff; - cfc_write_to_buffer(s, data[0]); + data = (dl >> 16) & 0xffff; + comedi_buf_write_samples(s, &data, 1); } } else { if (n > sizeof(devpriv->ai_fifo_buffer) / @@ -1288,9 +1266,7 @@ static void ni_ai_fifo_read(struct comedi_device *dev, devpriv->ai_fifo_buffer[i] = ni_readw(dev, ADC_FIFO_Data_Register); } - cfc_write_array_to_buffer(s, devpriv->ai_fifo_buffer, - n * - sizeof(devpriv->ai_fifo_buffer[0])); + comedi_buf_write_samples(s, devpriv->ai_fifo_buffer, n); } } @@ -1313,8 +1289,8 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev) { struct ni_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; - unsigned short data[2]; u32 dl; + unsigned short data; unsigned short fifo_empty; int i; @@ -1324,9 +1300,10 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev) dl = ni_readl(dev, ADC_FIFO_Data_611x); /* This may get the hi/lo data in the wrong order */ - data[0] = (dl >> 16); - data[1] = (dl & 0xffff); - cfc_write_array_to_buffer(s, data, sizeof(data)); + data = dl >> 16; + comedi_buf_write_samples(s, &data, 1); + data = dl & 0xffff; + comedi_buf_write_samples(s, &data, 1); } } else if (devpriv->is_6143) { i = 0; @@ -1334,9 +1311,10 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev) dl = ni_readl(dev, AIFIFO_Data_6143); /* This may get the hi/lo data in the wrong order */ - data[0] = (dl >> 16); - data[1] = (dl & 0xffff); - cfc_write_array_to_buffer(s, data, sizeof(data)); + data = dl >> 16; + comedi_buf_write_samples(s, &data, 1); + data = dl & 0xffff; + comedi_buf_write_samples(s, &data, 1); i += 2; } /* Check if stranded sample is present */ @@ -1344,8 +1322,8 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev) /* Get stranded sample into FIFO */ ni_writel(dev, 0x01, AIFIFO_Control_6143); dl = ni_readl(dev, AIFIFO_Data_6143); - data[0] = (dl >> 16) & 0xffff; - cfc_write_to_buffer(s, data[0]); + data = (dl >> 16) & 0xffff; + comedi_buf_write_samples(s, &data, 1); } } else { @@ -1364,10 +1342,7 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev) devpriv->ai_fifo_buffer[i] = ni_readw(dev, ADC_FIFO_Data_Register); } - cfc_write_array_to_buffer(s, devpriv->ai_fifo_buffer, - i * - sizeof(devpriv-> - ai_fifo_buffer[0])); + comedi_buf_write_samples(s, devpriv->ai_fifo_buffer, i); } } } @@ -1386,7 +1361,7 @@ static void get_last_sample_611x(struct comedi_device *dev) if (ni_readb(dev, XXX_Status) & 0x80) { dl = ni_readl(dev, ADC_FIFO_Data_611x); data = (dl & 0xffff); - cfc_write_to_buffer(s, data); + comedi_buf_write_samples(s, &data, 1); } } @@ -1408,7 +1383,7 @@ static void get_last_sample_6143(struct comedi_device *dev) /* This may get the hi/lo data in the wrong order */ data = (dl >> 16) & 0xffff; - cfc_write_to_buffer(s, data); + comedi_buf_write_samples(s, &data, 1); } } @@ -1462,7 +1437,7 @@ static void handle_gpct_interrupt(struct comedi_device *dev, ni_tio_handle_interrupt(&devpriv->counter_dev->counters[counter_index], s); - cfc_handle_events(dev, s); + comedi_handle_events(dev, s); #endif } @@ -1518,7 +1493,7 @@ static void handle_a_interrupt(struct comedi_device *dev, unsigned short status, if (comedi_is_subdevice_running(s)) { s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; - cfc_handle_events(dev, s); + comedi_handle_events(dev, s); } return; } @@ -1533,7 +1508,7 @@ static void handle_a_interrupt(struct comedi_device *dev, unsigned short status, if (status & (AI_Overrun_St | AI_Overflow_St)) s->async->events |= COMEDI_CB_OVERFLOW; - cfc_handle_events(dev, s); + comedi_handle_events(dev, s); return; } if (status & AI_SC_TC_St) { @@ -1559,7 +1534,7 @@ static void handle_a_interrupt(struct comedi_device *dev, unsigned short status, if ((status & AI_STOP_St)) ni_handle_eos(dev, s); - cfc_handle_events(dev, s); + comedi_handle_events(dev, s); } static void ack_b_interrupt(struct comedi_device *dev, unsigned short b_status) @@ -1635,7 +1610,7 @@ static void handle_b_interrupt(struct comedi_device *dev, } #endif - cfc_handle_events(dev, s); + comedi_handle_events(dev, s); } static void ni_ai_munge(struct comedi_device *dev, struct comedi_subdevice *s, @@ -1645,12 +1620,12 @@ static void ni_ai_munge(struct comedi_device *dev, struct comedi_subdevice *s, struct ni_private *devpriv = dev->private; struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; - unsigned int length = num_bytes / bytes_per_sample(s); + unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes); unsigned short *array = data; unsigned int *larray = data; unsigned int i; - for (i = 0; i < length; i++) { + for (i = 0; i < nsamples; i++) { #ifdef PCIDMA if (s->subdev_flags & SDF_LSAMPL) larray[i] = le32_to_cpu(larray[i]); @@ -2253,9 +2228,6 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, /* Step 1 : check if triggers are trivially valid */ - if ((cmd->flags & CMDF_WRITE)) - cmd->flags &= ~CMDF_WRITE; - err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT | TRIG_EXT); err |= cfc_check_trigger_src(&cmd->scan_begin_src, @@ -2762,11 +2734,11 @@ static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int chan_index) { struct comedi_cmd *cmd = &s->async->cmd; - unsigned int length = num_bytes / bytes_per_sample(s); + unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes); unsigned short *array = data; unsigned int i; - for (i = 0; i < length; i++) { + for (i = 0; i < nsamples; i++) { unsigned int range = CR_RANGE(cmd->chanlist[chan_index]); unsigned short val = array[i]; @@ -2981,12 +2953,15 @@ static int ni_ao_insn_config(struct comedi_device *dev, { const struct ni_board_struct *board = dev->board_ptr; struct ni_private *devpriv = dev->private; + unsigned int nbytes; switch (data[0]) { case INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE: switch (data[1]) { case COMEDI_OUTPUT: - data[2] = 1 + board->ao_fifo_depth * sizeof(short); + nbytes = comedi_samples_to_bytes(s, + board->ao_fifo_depth); + data[2] = 1 + nbytes; if (devpriv->mite) data[2] += devpriv->mite->fifo_size; break; @@ -3288,9 +3263,6 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, /* Step 1 : check if triggers are trivially valid */ - if ((cmd->flags & CMDF_WRITE) == 0) - cmd->flags |= CMDF_WRITE; - err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT | TRIG_EXT); err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER | TRIG_EXT); @@ -3515,9 +3487,6 @@ static int ni_cdio_cmdtest(struct comedi_device *dev, /* Step 2a : make sure trigger sources are unique */ /* Step 2b : and mutually compatible */ - if (err) - return 2; - /* Step 3: check if arguments are trivially valid */ err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); @@ -3693,7 +3662,7 @@ static void handle_cdio_interrupt(struct comedi_device *dev) M_Offset_CDIO_Command); /* s->async->events |= COMEDI_CB_EOA; */ } - cfc_handle_events(dev, s); + comedi_handle_events(dev, s); } static int ni_serial_hw_readwrite8(struct comedi_device *dev, @@ -3976,7 +3945,7 @@ static unsigned ni_gpct_to_stc_register(enum ni_gpct_register reg) stc_register = Interrupt_B_Enable_Register; break; default: - printk("%s: unhandled register 0x%x in switch.\n", + pr_err("%s: unhandled register 0x%x in switch.\n", __func__, reg); BUG(); return 0; @@ -5472,7 +5441,6 @@ static int ni_E_init(struct comedi_device *dev, s->range_table = board->ao_range_table; s->insn_config = ni_ao_insn_config; s->insn_write = ni_ao_insn_write; - s->insn_read = comedi_readback_insn_read; ret = comedi_alloc_subdev_readback(s); if (ret) |