aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2014-05-28 19:34:47 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-06-18 17:34:44 -0400
commitf93b399b137062b9108b2bd4cbc5f849d983c19f (patch)
tree786d8130103b95f1e659bbf7c678b00e2c99a037 /drivers
parentd9c4261f6a35bf9067ba0fdaf8ed4775ee0c5cea (diff)
staging: comedi: adq12b: fix ctreg (ai channel/range) programming
This driver only updates the ctreg (ai channel/range) register if the desired channel or range has changed since the last analog input read operation. It does this becuase the hardware requires an udelay to allow the multiplexor to settle. Unfortunatly the current code never updates the 'last_channel' and 'last_range' in the private data so the ctreg gets updated every time. Fix this and simplify it a bit by just storing the last ctreg value in the private data. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/comedi/drivers/adq12b.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/drivers/staging/comedi/drivers/adq12b.c b/drivers/staging/comedi/drivers/adq12b.c
index b4ea37704eaf..e5b236d5f78a 100644
--- a/drivers/staging/comedi/drivers/adq12b.c
+++ b/drivers/staging/comedi/drivers/adq12b.c
@@ -116,8 +116,7 @@ static const struct comedi_lrange range_adq12b_ai_unipolar = {
116struct adq12b_private { 116struct adq12b_private {
117 int unipolar; /* option 2 of comedi_config (1 is iobase) */ 117 int unipolar; /* option 2 of comedi_config (1 is iobase) */
118 int differential; /* option 3 of comedi_config */ 118 int differential; /* option 3 of comedi_config */
119 int last_channel; 119 unsigned int last_ctreg;
120 int last_range;
121}; 120};
122 121
123static int adq12b_ai_eoc(struct comedi_device *dev, 122static int adq12b_ai_eoc(struct comedi_device *dev,
@@ -134,20 +133,23 @@ static int adq12b_ai_eoc(struct comedi_device *dev,
134} 133}
135 134
136static int adq12b_ai_rinsn(struct comedi_device *dev, 135static int adq12b_ai_rinsn(struct comedi_device *dev,
137 struct comedi_subdevice *s, struct comedi_insn *insn, 136 struct comedi_subdevice *s,
137 struct comedi_insn *insn,
138 unsigned int *data) 138 unsigned int *data)
139{ 139{
140 struct adq12b_private *devpriv = dev->private; 140 struct adq12b_private *devpriv = dev->private;
141 unsigned int chan = CR_CHAN(insn->chanspec);
142 unsigned int range = CR_RANGE(insn->chanspec);
143 unsigned int val;
141 int n; 144 int n;
142 int range, channel;
143 unsigned char hi, lo, status; 145 unsigned char hi, lo, status;
144 int ret; 146 int ret;
145 147
146 /* change channel and range only if it is different from the previous */ 148 /* change channel and range only if it is different from the previous */
147 range = CR_RANGE(insn->chanspec); 149 val = (range << 4) | chan;
148 channel = CR_CHAN(insn->chanspec); 150 if (val != devpriv->last_ctreg) {
149 if (channel != devpriv->last_channel || range != devpriv->last_range) { 151 outb(val, dev->iobase + ADQ12B_CTREG);
150 outb((range << 4) | channel, dev->iobase + ADQ12B_CTREG); 152 devpriv->last_ctreg = val;
151 udelay(50); /* wait for the mux to settle */ 153 udelay(50); /* wait for the mux to settle */
152 } 154 }
153 155
@@ -226,12 +228,7 @@ static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
226 228
227 devpriv->unipolar = it->options[1]; 229 devpriv->unipolar = it->options[1];
228 devpriv->differential = it->options[2]; 230 devpriv->differential = it->options[2];
229 /* 231 devpriv->last_ctreg = -1; /* force ctreg update */
230 * initialize channel and range to -1 so we make sure we
231 * always write at least once to the CTREG in the instruction
232 */
233 devpriv->last_channel = -1;
234 devpriv->last_range = -1;
235 232
236 ret = comedi_alloc_subdevices(dev, 3); 233 ret = comedi_alloc_subdevices(dev, 3);
237 if (ret) 234 if (ret)