From 36c973d0896a5319cf3089c20e8d9881bc60297e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 14 May 2013 14:32:42 -0700 Subject: [PATCH] staging: comedi: dt9812: convert digital out subdevice to (*insn_bits) Currently the (*insn_write) function for the digital output subdevice only sets the state for a single channel. It's more efficent to use the (*insn_bits) function and allow setting the state for all the channels. The comedi core can use the (*insn_bits) to emulate the (*insn_write) if needed. Also, use the subdevice 'state' variable to hold the current state of the channels instead of 'do_shadow' in the private data. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/dt9812.c | 45 +++++++++++---------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c index 4fd1516..7f6d43a 100644 --- a/drivers/staging/comedi/drivers/dt9812.c +++ b/drivers/staging/comedi/drivers/dt9812.c @@ -265,7 +265,6 @@ struct dt9812_private { } cmd_wr, cmd_rd; u16 device; u16 ao_shadow[2]; - u8 do_shadow; }; static int dt9812_read_info(struct comedi_device *dev, @@ -390,23 +389,11 @@ static int dt9812_digital_out(struct comedi_device *dev, u8 bits) down(&devpriv->sem); ret = dt9812_write_multiple_registers(dev, 1, reg, value); - devpriv->do_shadow = bits; up(&devpriv->sem); return ret; } -static int dt9812_digital_out_shadow(struct comedi_device *dev, u8 *bits) -{ - struct dt9812_private *devpriv = dev->private; - - down(&devpriv->sem); - *bits = devpriv->do_shadow; - up(&devpriv->sem); - - return 0; -} - static void dt9812_configure_mux(struct comedi_device *dev, struct dt9812_rmw_byte *rmw, int channel) { @@ -624,24 +611,24 @@ static int dt9812_di_insn_bits(struct comedi_device *dev, return insn->n; } -static int dt9812_do_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_insn *insn, - unsigned int *data) +static int dt9812_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - unsigned int channel = CR_CHAN(insn->chanspec); - int n; - u8 bits = 0; + unsigned int mask = data[0]; + unsigned int bits = data[1]; - dt9812_digital_out_shadow(dev, &bits); - for (n = 0; n < insn->n; n++) { - u8 mask = 1 << channel; + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); - bits &= ~mask; - if (data[n]) - bits |= mask; + dt9812_digital_out(dev, s->state); } - dt9812_digital_out(dev, bits); - return n; + + data[1] = s->state; + + return insn->n; } static int dt9812_ai_rinsn(struct comedi_device *dev, @@ -849,9 +836,7 @@ static int dt9812_auto_attach(struct comedi_device *dev, s->n_chan = 8; s->maxdata = 1; s->range_table = &range_digital; - s->insn_write = dt9812_do_winsn; - - devpriv->do_shadow = 0; + s->insn_bits = dt9812_do_insn_bits; /* Analog Input subdevice */ s = &dev->subdevices[2]; -- 2.7.4