summaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi/drivers.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2014-08-25 16:03:54 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-08-30 13:22:29 -0700
commitd27620669209e3cc87f13449326eeb68229e4bd0 (patch)
treec856c907f75fe8f5b947518004a1a6feca1f9a0f /drivers/staging/comedi/drivers.c
parentd0be9430420457bfffcf4fa7f1ee26dbfd8cedb6 (diff)
downloadop-kernel-dev-d27620669209e3cc87f13449326eeb68229e4bd0.zip
op-kernel-dev-d27620669209e3cc87f13449326eeb68229e4bd0.tar.gz
staging: comedi: add a 'readback' member to comedi_subdevice
The analog output hardware in most comedi drivers does not provide a way to readback to last values written to the channels. In order to provide an (*insn_read) for the analog output subdevice, the comedi drivers save the last values for each channel in the private data. Add a new member, 'readback', to the comedi_subdevice definition to provide a common way to save these values. Introduce a comedi core function, comedi_alloc_subdev_readback(), to allocate the memory needed to save the values. This memory will be automatically kfree'd when the driver is detached. Introduce a comedi core function, comedi_readback_insn_read(), that the comedi drivers can use for the (*insn_read) of a subdevice to return the saved values for each channel. This will allow removing the boilerplate in the comedi drivers to return the saved values. In some drivers it will also allow removing the private data completely. 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/staging/comedi/drivers.c')
-rw-r--r--drivers/staging/comedi/drivers.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 9ada130..c4ed8fd 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -96,6 +96,22 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
}
EXPORT_SYMBOL_GPL(comedi_alloc_subdevices);
+/**
+ * comedi_alloc_subdev_readback() - Allocate memory for the subdevice readback.
+ * @s: comedi_subdevice struct
+ */
+int comedi_alloc_subdev_readback(struct comedi_subdevice *s)
+{
+ if (!s->n_chan)
+ return -EINVAL;
+
+ s->readback = kcalloc(s->n_chan, sizeof(*s->readback), GFP_KERNEL);
+ if (!s->readback)
+ return -ENOMEM;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(comedi_alloc_subdev_readback);
+
static void comedi_device_detach_cleanup(struct comedi_device *dev)
{
int i;
@@ -111,6 +127,7 @@ static void comedi_device_detach_cleanup(struct comedi_device *dev)
comedi_buf_alloc(dev, s, 0);
kfree(s->async);
}
+ kfree(s->readback);
}
kfree(dev->subdevices);
dev->subdevices = NULL;
@@ -157,6 +174,31 @@ int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
}
/**
+ * comedi_readback_insn_read() - A generic (*insn_read) for subdevice readback.
+ * @dev: comedi_device struct
+ * @s: comedi_subdevice struct
+ * @insn: comedi_insn struct
+ * @data: pointer to return the readback data
+ */
+int comedi_readback_insn_read(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned int *data)
+{
+ unsigned int chan = CR_CHAN(insn->chanspec);
+ int i;
+
+ if (!s->readback)
+ return -EINVAL;
+
+ for (i = 0; i < insn->n; i++)
+ data[i] = s->readback[chan];
+
+ return insn->n;
+}
+EXPORT_SYMBOL_GPL(comedi_readback_insn_read);
+
+/**
* comedi_timeout() - busy-wait for a driver condition to occur.
* @dev: comedi_device struct
* @s: comedi_subdevice struct
OpenPOWER on IntegriCloud