Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <william.gray@linaro.org>
Link: https://lore.kernel.org/r/d9dab6696af7eabb2d46f5cbc7871329f499c1c9.1657213745.git.william.gray@linaro.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

William Breathitt Gray and committed by
Jonathan Cameron
e1d965ce 6cfd14c5

+5 -5
+5 -5
drivers/iio/dac/cio-dac.c
··· 16 16 #include <linux/isa.h> 17 17 #include <linux/module.h> 18 18 #include <linux/moduleparam.h> 19 + #include <linux/types.h> 19 20 20 21 #define CIO_DAC_NUM_CHAN 16 21 22 ··· 38 37 /** 39 38 * struct cio_dac_iio - IIO device private data structure 40 39 * @chan_out_states: channels' output states 41 - * @base: base port address of the IIO device 40 + * @base: base memory address of the DAC device 42 41 */ 43 42 struct cio_dac_iio { 44 43 int chan_out_states[CIO_DAC_NUM_CHAN]; 45 - void __iomem *base; 44 + u16 __iomem *base; 46 45 }; 47 46 48 47 static int cio_dac_read_raw(struct iio_dev *indio_dev, ··· 62 61 struct iio_chan_spec const *chan, int val, int val2, long mask) 63 62 { 64 63 struct cio_dac_iio *const priv = iio_priv(indio_dev); 65 - const unsigned int chan_addr_offset = 2 * chan->channel; 66 64 67 65 if (mask != IIO_CHAN_INFO_RAW) 68 66 return -EINVAL; ··· 71 71 return -EINVAL; 72 72 73 73 priv->chan_out_states[chan->channel] = val; 74 - iowrite16(val, priv->base + chan_addr_offset); 74 + iowrite16(val, priv->base + chan->channel); 75 75 76 76 return 0; 77 77 } ··· 117 117 indio_dev->name = dev_name(dev); 118 118 119 119 /* initialize DAC outputs to 0V */ 120 - for (i = 0; i < 32; i += 2) 120 + for (i = 0; i < CIO_DAC_NUM_CHAN; i++) 121 121 iowrite16(0, priv->base + i); 122 122 123 123 return devm_iio_device_register(dev, indio_dev);