aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorNaidu Tellapati <naidu.tellapati@imgtec.com>2015-05-07 17:22:17 -0400
committerJonathan Cameron <jic23@kernel.org>2015-05-08 09:37:32 -0400
commit13415a998adb1802b5bd6bd5a336331589e866a1 (patch)
tree2573cf7d00d5e1cabeee0ada45c6fe2794e3bd98 /drivers/iio
parente5f1efb9ae71bbb79629d660dc19b51ce7b95439 (diff)
iio: adc: cc10001: Fix the channel number mapping
When some of the ADC channels are reserved for remote CPUs, the scan index and the corresponding channel number doesn't match. This leads to convesion on the incorrect channel during triggered capture. Fix this by using a scan index to channel mapping encoded in the iio_chan_spec for this purpose while starting conversion on a particular ADC channel in trigger handler. Also, the channel_map is not really used anywhere but in probe(), so no need to keep track of it. Remove it from device structure. While here, add 1 to number of channels to register timestamp channel with the IIO core. Fixes: 1664f6a5b0c8 ("iio: adc: Cosmic Circuits 10001 ADC driver") Signed-off-by: Naidu Tellapati <naidu.tellapati@imgtec.com> Signed-off-by: Ezequiel Garcia <ezequiel.garcia@imgtec.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/adc/cc10001_adc.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/iio/adc/cc10001_adc.c b/drivers/iio/adc/cc10001_adc.c
index 51e2a83c9404..357e6c213784 100644
--- a/drivers/iio/adc/cc10001_adc.c
+++ b/drivers/iio/adc/cc10001_adc.c
@@ -62,7 +62,6 @@ struct cc10001_adc_device {
62 u16 *buf; 62 u16 *buf;
63 63
64 struct mutex lock; 64 struct mutex lock;
65 unsigned long channel_map;
66 unsigned int start_delay_ns; 65 unsigned int start_delay_ns;
67 unsigned int eoc_delay_ns; 66 unsigned int eoc_delay_ns;
68}; 67};
@@ -129,6 +128,7 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
129 struct iio_dev *indio_dev; 128 struct iio_dev *indio_dev;
130 unsigned int delay_ns; 129 unsigned int delay_ns;
131 unsigned int channel; 130 unsigned int channel;
131 unsigned int scan_idx;
132 bool sample_invalid; 132 bool sample_invalid;
133 u16 *data; 133 u16 *data;
134 int i; 134 int i;
@@ -150,9 +150,10 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
150 150
151 i = 0; 151 i = 0;
152 sample_invalid = false; 152 sample_invalid = false;
153 for_each_set_bit(channel, indio_dev->active_scan_mask, 153 for_each_set_bit(scan_idx, indio_dev->active_scan_mask,
154 indio_dev->masklength) { 154 indio_dev->masklength) {
155 155
156 channel = indio_dev->channels[scan_idx].channel;
156 cc10001_adc_start(adc_dev, channel); 157 cc10001_adc_start(adc_dev, channel);
157 158
158 data[i] = cc10001_adc_poll_done(indio_dev, channel, delay_ns); 159 data[i] = cc10001_adc_poll_done(indio_dev, channel, delay_ns);
@@ -255,22 +256,22 @@ static const struct iio_info cc10001_adc_info = {
255 .update_scan_mode = &cc10001_update_scan_mode, 256 .update_scan_mode = &cc10001_update_scan_mode,
256}; 257};
257 258
258static int cc10001_adc_channel_init(struct iio_dev *indio_dev) 259static int cc10001_adc_channel_init(struct iio_dev *indio_dev,
260 unsigned long channel_map)
259{ 261{
260 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev);
261 struct iio_chan_spec *chan_array, *timestamp; 262 struct iio_chan_spec *chan_array, *timestamp;
262 unsigned int bit, idx = 0; 263 unsigned int bit, idx = 0;
263 264
264 indio_dev->num_channels = bitmap_weight(&adc_dev->channel_map, 265 indio_dev->num_channels = bitmap_weight(&channel_map,
265 CC10001_ADC_NUM_CHANNELS); 266 CC10001_ADC_NUM_CHANNELS) + 1;
266 267
267 chan_array = devm_kcalloc(&indio_dev->dev, indio_dev->num_channels + 1, 268 chan_array = devm_kcalloc(&indio_dev->dev, indio_dev->num_channels,
268 sizeof(struct iio_chan_spec), 269 sizeof(struct iio_chan_spec),
269 GFP_KERNEL); 270 GFP_KERNEL);
270 if (!chan_array) 271 if (!chan_array)
271 return -ENOMEM; 272 return -ENOMEM;
272 273
273 for_each_set_bit(bit, &adc_dev->channel_map, CC10001_ADC_NUM_CHANNELS) { 274 for_each_set_bit(bit, &channel_map, CC10001_ADC_NUM_CHANNELS) {
274 struct iio_chan_spec *chan = &chan_array[idx]; 275 struct iio_chan_spec *chan = &chan_array[idx];
275 276
276 chan->type = IIO_VOLTAGE; 277 chan->type = IIO_VOLTAGE;
@@ -305,6 +306,7 @@ static int cc10001_adc_probe(struct platform_device *pdev)
305 unsigned long adc_clk_rate; 306 unsigned long adc_clk_rate;
306 struct resource *res; 307 struct resource *res;
307 struct iio_dev *indio_dev; 308 struct iio_dev *indio_dev;
309 unsigned long channel_map;
308 int ret; 310 int ret;
309 311
310 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev)); 312 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev));
@@ -313,9 +315,9 @@ static int cc10001_adc_probe(struct platform_device *pdev)
313 315
314 adc_dev = iio_priv(indio_dev); 316 adc_dev = iio_priv(indio_dev);
315 317
316 adc_dev->channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0); 318 channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0);
317 if (!of_property_read_u32(node, "adc-reserved-channels", &ret)) 319 if (!of_property_read_u32(node, "adc-reserved-channels", &ret))
318 adc_dev->channel_map &= ~ret; 320 channel_map &= ~ret;
319 321
320 adc_dev->reg = devm_regulator_get(&pdev->dev, "vref"); 322 adc_dev->reg = devm_regulator_get(&pdev->dev, "vref");
321 if (IS_ERR(adc_dev->reg)) 323 if (IS_ERR(adc_dev->reg))
@@ -361,7 +363,7 @@ static int cc10001_adc_probe(struct platform_device *pdev)
361 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES; 363 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES;
362 364
363 /* Setup the ADC channels available on the device */ 365 /* Setup the ADC channels available on the device */
364 ret = cc10001_adc_channel_init(indio_dev); 366 ret = cc10001_adc_channel_init(indio_dev, channel_map);
365 if (ret < 0) 367 if (ret < 0)
366 goto err_disable_clk; 368 goto err_disable_clk;
367 369