From 3b85aa6378b2a978f7bf38096c6309e771b218b0 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 31 Aug 2012 20:41:42 +0100 Subject: [PATCH] staging: comedi: das08: Rearrange AO write functions Combine the AO write functions for 'JR' boards and other boards into a single function and factor out the data writing from the comedi instruction handling so it can be called from elsewhere in a later patch. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/das08.c | 60 ++++++++++++---------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c index 6aa8064..13e6ac7 100644 --- a/drivers/staging/comedi/drivers/das08.c +++ b/drivers/staging/comedi/drivers/das08.c @@ -369,56 +369,39 @@ static int das08jr_do_wbits(struct comedi_device *dev, return insn->n; } -static int das08jr_ao_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static void das08_ao_set_data(struct comedi_device *dev, + unsigned int chan, unsigned int data) { - int n; - int lsb, msb; - int chan; - - lsb = data[0] & 0xff; - msb = (data[0] >> 8) & 0xff; - - chan = CR_CHAN(insn->chanspec); + const struct das08_board_struct *thisboard = comedi_board(dev); + unsigned char lsb; + unsigned char msb; - for (n = 0; n < insn->n; n++) { + lsb = data & 0xff; + msb = (data >> 8) & 0xff; + if (thisboard->is_jr) { outb(lsb, dev->iobase + DAS08JR_AO_LSB(chan)); outb(msb, dev->iobase + DAS08JR_AO_MSB(chan)); - /* load DACs */ inb(dev->iobase + DAS08JR_DIO); + } else { + outb(lsb, dev->iobase + DAS08AO_AO_LSB(chan)); + outb(msb, dev->iobase + DAS08AO_AO_MSB(chan)); + /* load DACs */ + inb(dev->iobase + DAS08AO_AO_UPDATE); } - - return n; } -/* - * - * The -aox boards have the DACs at a different offset and use - * a different method to force an update. - * - */ -static int das08ao_ao_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int das08_ao_winsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { - int n; - int lsb, msb; - int chan; - - lsb = data[0] & 0xff; - msb = (data[0] >> 8) & 0xf; + unsigned int n; + unsigned int chan; chan = CR_CHAN(insn->chanspec); - for (n = 0; n < insn->n; n++) { - outb(lsb, dev->iobase + DAS08AO_AO_LSB(chan)); - outb(msb, dev->iobase + DAS08AO_AO_MSB(chan)); - - /* load DACs */ - inb(dev->iobase + DAS08AO_AO_UPDATE); - } + for (n = 0; n < insn->n; n++) + das08_ao_set_data(dev, chan, *data); return n; } @@ -681,8 +664,7 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase) s->n_chan = 2; s->maxdata = (1 << thisboard->ao_nbits) - 1; s->range_table = &range_bipolar5; - s->insn_write = - thisboard->is_jr ? das08jr_ao_winsn : das08ao_ao_winsn; + s->insn_write = das08_ao_winsn; } else { s->type = COMEDI_SUBD_UNUSED; } -- 2.7.4