From 6a911d8aa54bc79256e766580a19bbd91e76d48f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:44:17 -0700 Subject: [PATCH] staging: comedi: quatech_daqp_cs: use (*insn_bits) for digital outputs Change the subdevice operation used to write the digital outputs from a (*insn_write) to a (*insn_bits) function. The (*insn_write) functions are expected to write 'insn->n' number of samples. The (*insn_bits) functions just write a single sample (insn->n = 1). Change the return from '1' to 'insn->n' to clarify what the return is. Using an (*insn_bits) function to write the digital outputs also allows the user to read the current state of the output channels. Fix the io operation used to update the digital outputs. The register is only 8-bits and should by updated with an outb() not an outw(). Also, set the 'maxdata' for the subdevice. For digital io this value should be '1' (digital io can only be 1 or 0). Remove the setting of the len_chanlist for the subdevice. This variable only has meaning for subdevices that support asynchronous commands. The comedi core will initialize it appropriately during the postconfig. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../staging/comedi/drivers/quatech_daqp_cs.c | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index dbb8593a8db8..f11104252c96 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -686,20 +686,28 @@ static int daqp_di_insn_bits(struct comedi_device *dev, return insn->n; } -/* Digital output routine */ - -static int daqp_do_insn_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int daqp_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct daqp_private *devpriv = dev->private; + unsigned int mask = data[0]; + unsigned int bits = data[1]; if (devpriv->stop) return -EIO; - outw(data[0] & 0xf, dev->iobase + DAQP_DIGITAL_IO); + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); - return 1; + outb(s->state, dev->iobase + DAQP_DIGITAL_IO); + } + + data[1] = s->state; + + return insn->n; } static int daqp_auto_attach(struct comedi_device *dev, @@ -764,8 +772,8 @@ static int daqp_auto_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE; s->n_chan = 1; - s->len_chanlist = 1; - s->insn_write = daqp_do_insn_write; + s->maxdata = 1; + s->insn_bits = daqp_do_insn_bits; return 0; } -- 2.39.5