From e1d965cebe82e59e6a4c0cf115e5dbd7a9a0d9e5 Mon Sep 17 00:00:00 2001 From: William Breathitt Gray Date: Thu, 7 Jul 2022 13:21:25 -0400 Subject: iio: dac: cio-dac: Cleanup indexing for DAC writes Simplify DAC write code by defining base member as u16 __iomem *; DAC registers are 16-bit so this allows us to index each DAC channel directly in a loop rather than calculating the offsets by multipling by 2 each time. Signed-off-by: William Breathitt Gray Link: https://lore.kernel.org/r/d9dab6696af7eabb2d46f5cbc7871329f499c1c9.1657213745.git.william.gray@linaro.org Signed-off-by: Jonathan Cameron --- drivers/iio/dac/cio-dac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/iio/dac') diff --git a/drivers/iio/dac/cio-dac.c b/drivers/iio/dac/cio-dac.c index 8080984dcb03..791dd999cf29 100644 --- a/drivers/iio/dac/cio-dac.c +++ b/drivers/iio/dac/cio-dac.c @@ -16,6 +16,7 @@ #include #include #include +#include #define CIO_DAC_NUM_CHAN 16 @@ -37,11 +38,11 @@ MODULE_PARM_DESC(base, "Measurement Computing CIO-DAC base addresses"); /** * struct cio_dac_iio - IIO device private data structure * @chan_out_states: channels' output states - * @base: base port address of the IIO device + * @base: base memory address of the DAC device */ struct cio_dac_iio { int chan_out_states[CIO_DAC_NUM_CHAN]; - void __iomem *base; + u16 __iomem *base; }; static int cio_dac_read_raw(struct iio_dev *indio_dev, @@ -61,7 +62,6 @@ static int cio_dac_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { struct cio_dac_iio *const priv = iio_priv(indio_dev); - const unsigned int chan_addr_offset = 2 * chan->channel; if (mask != IIO_CHAN_INFO_RAW) return -EINVAL; @@ -71,7 +71,7 @@ static int cio_dac_write_raw(struct iio_dev *indio_dev, return -EINVAL; priv->chan_out_states[chan->channel] = val; - iowrite16(val, priv->base + chan_addr_offset); + iowrite16(val, priv->base + chan->channel); return 0; } @@ -117,7 +117,7 @@ static int cio_dac_probe(struct device *dev, unsigned int id) indio_dev->name = dev_name(dev); /* initialize DAC outputs to 0V */ - for (i = 0; i < 32; i += 2) + for (i = 0; i < CIO_DAC_NUM_CHAN; i++) iowrite16(0, priv->base + i); return devm_iio_device_register(dev, indio_dev); -- cgit v1.2.3