From: H Hartley Sweeten Date: Mon, 14 Jul 2014 19:23:48 +0000 (-0700) Subject: staging: comedi: ni_mio_common: merge analog output (*insn_write) functions X-Git-Tag: v3.17-rc1~123^2~684 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=79816da17302910f70a85b4d269aedb067688926;p=karo-tx-linux.git staging: comedi: ni_mio_common: merge analog output (*insn_write) functions Currently the PCI6xxx boards use a different (*insn_write) function for the analog output subdevice. Most of the code is identical to the (*insn_write) used by all the other board types. For aesthetics, merge the two (*insn_write) functions and handle the 'is_6xxx' differences in the common code. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index 6e79bcf3ce87..9bcf8351129d 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -2964,10 +2964,15 @@ static int ni_ao_insn_write(struct comedi_device *dev, int reg; int i; - if (devpriv->is_m_series) + if (devpriv->is_6xxx) { + ni_ao_win_outw(dev, 1 << chan, AO_Immediate_671x); + + reg = DACx_Direct_Data_671x(chan); + } else if (devpriv->is_m_series) { reg = M_Offset_DAC_Direct_Data(chan); - else + } else { reg = (chan) ? DAC1_Direct_Data : DAC0_Direct_Data; + } ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0); @@ -2976,8 +2981,19 @@ static int ni_ao_insn_write(struct comedi_device *dev, devpriv->ao[chan] = val; - if (devpriv->is_m_series) { - /* M-series board always use offset binary values */ + if (devpriv->is_6xxx) { + /* + * 6xxx boards have bipolar outputs, munge the + * unsigned comedi values to 2's complement + */ + val = comedi_offset_munge(s, val); + + ni_ao_win_outw(dev, val, reg); + } else if (devpriv->is_m_series) { + /* + * M-series boards use offset binary values for + * bipolar and uinpolar outputs + */ ni_writew(dev, val, reg); } else { /* @@ -2994,36 +3010,6 @@ static int ni_ao_insn_write(struct comedi_device *dev, return insn->n; } -static int ni_ao_insn_write_671x(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct ni_private *devpriv = dev->private; - unsigned int chan = CR_CHAN(insn->chanspec); - int i; - - ni_ao_win_outw(dev, 1 << chan, AO_Immediate_671x); - - ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0); - - for (i = 0; i < insn->n; i++) { - unsigned int val = data[i]; - - devpriv->ao[chan] = val; - - /* - * 671x boards have +/-10V outputs - * munge the unsigned comedi values to 2's complement - */ - val = comedi_offset_munge(s, val); - - ni_ao_win_outw(dev, val, DACx_Direct_Data_671x(chan)); - } - - return insn->n; -} - static int ni_ao_insn_config(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) @@ -5565,10 +5551,7 @@ static int ni_E_init(struct comedi_device *dev, s->maxdata = (1 << board->aobits) - 1; s->range_table = board->ao_range_table; s->insn_read = &ni_ao_insn_read; - if (devpriv->is_6xxx) - s->insn_write = &ni_ao_insn_write_671x; - else - s->insn_write = &ni_ao_insn_write; + s->insn_write = &ni_ao_insn_write; s->insn_config = &ni_ao_insn_config; #ifdef PCIDMA if (board->n_aochan) {