From dcbd4ed87cc82398238eb870008a338b4faec76f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 20 Nov 2014 15:10:48 -0700 Subject: [PATCH] staging: comedi: adv_pci1724: introduce adv_pci1724_insn_write() The analog output, offset calib, and gain calib subdevices all use similar (*insn_write) functions. The onyl difference is the 'mode' that is passed to the set_dac() helper. Introduce a new (*insn_write) function that can be used by all the subdevices. Use the s->private member to pass the 'mode' needed by set_dac(). Remove the subdevice specific (*insn_write) functions. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/adv_pci1724.c | 68 ++++++++-------------------- 1 file changed, 18 insertions(+), 50 deletions(-) diff --git a/drivers/staging/comedi/drivers/adv_pci1724.c b/drivers/staging/comedi/drivers/adv_pci1724.c index db5f6eb..cc70ed8 100644 --- a/drivers/staging/comedi/drivers/adv_pci1724.c +++ b/drivers/staging/comedi/drivers/adv_pci1724.c @@ -158,62 +158,27 @@ static int set_dac(struct comedi_device *dev, unsigned mode, unsigned channel, return 0; } -static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int adv_pci1724_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - int channel = CR_CHAN(insn->chanspec); - int retval; - int i; - - /* turn off synchronous mode */ - outl(0, dev->iobase + SYNC_OUTPUT_REG); - - for (i = 0; i < insn->n; ++i) { - retval = set_dac(dev, DAC_NORMAL_MODE, channel, data[i]); - if (retval < 0) - return retval; - s->readback[channel] = data[i]; - } - return insn->n; -} - -static int offset_write_insn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - int channel = CR_CHAN(insn->chanspec); - int retval; + unsigned long mode = (unsigned long)s->private; + unsigned int chan = CR_CHAN(insn->chanspec); + int ret; int i; /* turn off synchronous mode */ outl(0, dev->iobase + SYNC_OUTPUT_REG); for (i = 0; i < insn->n; ++i) { - retval = set_dac(dev, DAC_OFFSET_MODE, channel, data[i]); - if (retval < 0) - return retval; - s->readback[channel] = data[i]; - } - - return insn->n; -} - -static int gain_write_insn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - int channel = CR_CHAN(insn->chanspec); - int retval; - int i; + unsigned int val = data[i]; - /* turn off synchronous mode */ - outl(0, dev->iobase + SYNC_OUTPUT_REG); + ret = set_dac(dev, mode, chan, val); + if (ret < 0) + return ret; - for (i = 0; i < insn->n; ++i) { - retval = set_dac(dev, DAC_GAIN_MODE, channel, data[i]); - if (retval < 0) - return retval; - s->readback[channel] = data[i]; + s->readback[chan] = val; } return insn->n; @@ -237,7 +202,8 @@ static int setup_subdevices(struct comedi_device *dev) s->n_chan = 32; s->maxdata = 0x3fff; s->range_table = &ao_ranges_1724; - s->insn_write = ao_winsn; + s->insn_write = adv_pci1724_insn_write; + s->private = (void *)DAC_NORMAL_MODE; ret = comedi_alloc_subdev_readback(s); if (ret) @@ -249,7 +215,8 @@ static int setup_subdevices(struct comedi_device *dev) s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = 32; s->maxdata = 0x3fff; - s->insn_write = offset_write_insn; + s->insn_write = adv_pci1724_insn_write; + s->private = (void *)DAC_OFFSET_MODE; ret = comedi_alloc_subdev_readback(s); if (ret) @@ -261,7 +228,8 @@ static int setup_subdevices(struct comedi_device *dev) s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = 32; s->maxdata = 0x3fff; - s->insn_write = gain_write_insn; + s->insn_write = adv_pci1724_insn_write; + s->private = (void *)DAC_GAIN_MODE; ret = comedi_alloc_subdev_readback(s); if (ret) -- 2.7.4