From b26bdebbd5e7408515dea67da6f17d880b8a6ee7 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 25 Aug 2014 16:04:46 -0700 Subject: [PATCH] staging: comedi: cb_pcimdas: cleanup cb_pcimdas_ao_winsn() The comedi core validates the insn->chanspec and data values before calling the (*insn_write) functions. The 'chan' will always be valid and the data values do not need to be masked. Tidy up this function and remove the unnecessary code. For aesthetics, rename the function. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/cb_pcimdas.c | 32 ++++++++------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c index f1c0dafb98dd..18e1801698ee 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdas.c +++ b/drivers/staging/comedi/drivers/cb_pcimdas.c @@ -159,32 +159,24 @@ static int cb_pcimdas_ai_rinsn(struct comedi_device *dev, return n; } -static int cb_pcimdas_ao_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int cb_pcimdas_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct cb_pcimdas_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int val = devpriv->ao_readback[chan]; + unsigned int reg = (chan) ? DAC1_OFFSET : DAC0_OFFSET; int i; - int chan = CR_CHAN(insn->chanspec); - /* Writing a list of values to an AO channel is probably not - * very useful, but that's how the interface is defined. */ for (i = 0; i < insn->n; i++) { - switch (chan) { - case 0: - outw(data[i] & 0x0FFF, devpriv->daqio + DAC0_OFFSET); - break; - case 1: - outw(data[i] & 0x0FFF, devpriv->daqio + DAC1_OFFSET); - break; - default: - return -1; - } - devpriv->ao_readback[chan] = data[i]; + val = data[i]; + outw(val, devpriv->daqio + reg); } + devpriv->ao_readback[chan] = val; - /* return the number of samples read/written */ - return i; + return insn->n; } /* AO subdevices should have a read insn as well as a write insn. @@ -247,7 +239,7 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev, s->maxdata = 0xfff; /* ranges are hardware settable, but not software readable. */ s->range_table = &range_unknown; - s->insn_write = &cb_pcimdas_ao_winsn; + s->insn_write = cb_pcimdas_ao_insn_write; s->insn_read = &cb_pcimdas_ao_rinsn; s = &dev->subdevices[2]; -- 2.34.1