From 9ac581336a6ddd781d92e03e6d4f2c17cbac021a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 25 Aug 2014 16:03:57 -0700 Subject: [PATCH] staging: comedi: aio_aio12_8: use comedi_subdevice 'readback' Use the new comedi_subdevice 'readback' member and the core provided (*insn_read) for the readback of the analog output subdevice channels. Remove the unused private data and its allocation. For aesthetics, rename the (*insn_write) function and tidy it up. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/aio_aio12_8.c | 47 ++++++++-------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c index 848b95d..61cdd25 100644 --- a/drivers/staging/comedi/drivers/aio_aio12_8.c +++ b/drivers/staging/comedi/drivers/aio_aio12_8.c @@ -97,10 +97,6 @@ static const struct aio12_8_boardtype board_types[] = { }, }; -struct aio12_8_private { - unsigned int ao_readback[4]; -}; - static int aio_aio12_8_ai_eoc(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -149,28 +145,13 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev, return insn->n; } -static int aio_aio12_8_ao_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - struct aio12_8_private *devpriv = dev->private; - unsigned int chan = CR_CHAN(insn->chanspec); - int val = devpriv->ao_readback[chan]; - int i; - - for (i = 0; i < insn->n; i++) - data[i] = val; - return insn->n; -} - -static int aio_aio12_8_ao_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int aio_aio12_8_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - struct aio12_8_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); - unsigned long port = dev->iobase + AIO12_8_DAC_REG(chan); - unsigned int val = 0; + unsigned int val = s->readback[chan]; int i; /* enable DACs */ @@ -178,10 +159,9 @@ static int aio_aio12_8_ao_write(struct comedi_device *dev, for (i = 0; i < insn->n; i++) { val = data[i]; - outw(val, port); + outw(val, dev->iobase + AIO12_8_DAC_REG(chan)); } - - devpriv->ao_readback[chan] = val; + s->readback[chan] = val; return insn->n; } @@ -199,7 +179,6 @@ static int aio_aio12_8_attach(struct comedi_device *dev, struct comedi_devconfig *it) { const struct aio12_8_boardtype *board = comedi_board(dev); - struct aio12_8_private *devpriv; struct comedi_subdevice *s; int ret; @@ -207,10 +186,6 @@ static int aio_aio12_8_attach(struct comedi_device *dev, if (ret) return ret; - devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); - if (!devpriv) - return -ENOMEM; - ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; @@ -236,8 +211,12 @@ static int aio_aio12_8_attach(struct comedi_device *dev, s->n_chan = 4; s->maxdata = 0x0fff; s->range_table = &range_aio_aio12_8; - s->insn_read = aio_aio12_8_ao_read; - s->insn_write = aio_aio12_8_ao_write; + s->insn_write = aio_aio12_8_ao_insn_write; + s->insn_read = comedi_readback_insn_read; + + ret = comedi_alloc_subdev_readback(s); + if (ret) + return ret; } else { s->type = COMEDI_SUBD_UNUSED; } -- 2.7.4