History

Merge tag 'staging-4.17-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging

Pull IIO driver fixes from Greg KH: "Here are some old IIO driver fixes that were sitting in my tree for a few weeks. Sorry about not getting them to you sooner. They fix a number of small IIO driver issues that have been reported. All of these have been in linux-next for a while with no reported problems" * tag 'staging-4.17-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: iio: adc: select buffer for at91-sama5d2_adc iio: hid-sensor-trigger: Fix sometimes not powering up the sensor after resume iio: adc: at91-sama5d2_adc: fix channel configuration for differential channels iio:kfifo_buf: check for uint overflow iio:buffer: make length types match kfifo types iio: adc: stm32-dfsdm: fix sample rate for div2 spi clock iio: adc: stm32-dfsdm: fix successive oversampling settings iio: ad7793: implement IIO_CHAN_INFO_SAMP_FREQ

Linus Torvalds committed 8 years ago

Commit 34a8e642 parents 7fdf3e8 9d569b18 files · +93 −68Browse files

Unified · Split

8 files
  1. drivers/iio/adc/Kconfig +1 −0
  2. drivers/iio/adc/ad7793.c +24 −51
  3. drivers/iio/adc/at91-sama5d2_adc.c +37 −4
  4. drivers/iio/adc/stm32-dfsdm-adc.c +14 −3
  5. drivers/iio/buffer/industrialio-buffer-dma.c +1 −1
  6. drivers/iio/buffer/kfifo_buf.c +9 −2
  7. drivers/iio/common/hid-sensors/hid-sensor-trigger.c +4 −4
  8. include/linux/iio/buffer_impl.h +3 −3
drivers/iio/adc/Kconfig+1−0
@@ -158,6 +158,7 @@ config AT91_SAMA5D2_ADC · 157 unmodified lines
158 depends on ARCH_AT91 || COMPILE_TEST158 depends on ARCH_AT91 || COMPILE_TEST
159 depends on HAS_IOMEM159 depends on HAS_IOMEM
160 depends on HAS_DMA160 depends on HAS_DMA
161 select IIO_BUFFER
161 select IIO_TRIGGERED_BUFFER162 select IIO_TRIGGERED_BUFFER
162 help163 help
163 Say yes here to build support for Atmel SAMA5D2 ADC which is164 Say yes here to build support for Atmel SAMA5D2 ADC which is
drivers/iio/adc/ad7793.c+24−51
@@ -348,55 +348,6 @@ static const u16 ad7793_sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39, · 347 unmodified lines
348static const u16 ad7797_sample_freq_avail[16] = {0, 0, 0, 123, 62, 50, 0,348static const u16 ad7797_sample_freq_avail[16] = {0, 0, 0, 123, 62, 50, 0,
349 33, 0, 17, 16, 12, 10, 8, 6, 4};349 33, 0, 17, 16, 12, 10, 8, 6, 4};
350 350
351static ssize_t ad7793_read_frequency(struct device *dev,
352 struct device_attribute *attr,
353 char *buf)
354{
355 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
356 struct ad7793_state *st = iio_priv(indio_dev);
357
358 return sprintf(buf, "%d\n",
359 st->chip_info->sample_freq_avail[AD7793_MODE_RATE(st->mode)]);
360}
361
362static ssize_t ad7793_write_frequency(struct device *dev,
363 struct device_attribute *attr,
364 const char *buf,
365 size_t len)
366{
367 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
368 struct ad7793_state *st = iio_priv(indio_dev);
369 long lval;
370 int i, ret;
371
372 ret = kstrtol(buf, 10, &lval);
373 if (ret)
374 return ret;
375
376 if (lval == 0)
377 return -EINVAL;
378
379 for (i = 0; i < 16; i++)
380 if (lval == st->chip_info->sample_freq_avail[i])
381 break;
382 if (i == 16)
383 return -EINVAL;
384
385 ret = iio_device_claim_direct_mode(indio_dev);
386 if (ret)
387 return ret;
388 st->mode &= ~AD7793_MODE_RATE(-1);
389 st->mode |= AD7793_MODE_RATE(i);
390 ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode), st->mode);
391 iio_device_release_direct_mode(indio_dev);
392
393 return len;
394}
395
396static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
397 ad7793_read_frequency,
398 ad7793_write_frequency);
399
400static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(351static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
401 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");352 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");
402 353
@@ -424,7 +375,6 @@ static IIO_DEVICE_ATTR_NAMED(in_m_in_scale_available, · 21 unmodified lines
424 ad7793_show_scale_available, NULL, 0);375 ad7793_show_scale_available, NULL, 0);
425 376
426static struct attribute *ad7793_attributes[] = {377static struct attribute *ad7793_attributes[] = {
427 &iio_dev_attr_sampling_frequency.dev_attr.attr,
428 &iio_const_attr_sampling_frequency_available.dev_attr.attr,378 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
429 &iio_dev_attr_in_m_in_scale_available.dev_attr.attr,379 &iio_dev_attr_in_m_in_scale_available.dev_attr.attr,
430 NULL380 NULL
@@ -435,7 +385,6 @@ static const struct attribute_group ad7793_attribute_group = { · 4 unmodified lines
435};385};
436 386
437static struct attribute *ad7797_attributes[] = {387static struct attribute *ad7797_attributes[] = {
438 &iio_dev_attr_sampling_frequency.dev_attr.attr,
439 &iio_const_attr_sampling_frequency_available_ad7797.dev_attr.attr,388 &iio_const_attr_sampling_frequency_available_ad7797.dev_attr.attr,
440 NULL389 NULL
441};390};
@@ -505,6 +454,10 @@ static int ad7793_read_raw(struct iio_dev *indio_dev, · 63 unmodified lines
505 *val -= offset;454 *val -= offset;
506 }455 }
507 return IIO_VAL_INT;456 return IIO_VAL_INT;
457 case IIO_CHAN_INFO_SAMP_FREQ:
458 *val = st->chip_info
459 ->sample_freq_avail[AD7793_MODE_RATE(st->mode)];
460 return IIO_VAL_INT;
508 }461 }
509 return -EINVAL;462 return -EINVAL;
510}463}
@@ -542,6 +495,26 @@ static int ad7793_write_raw(struct iio_dev *indio_dev, · 31 unmodified lines
542 break;495 break;
543 }496 }
544 break;497 break;
498 case IIO_CHAN_INFO_SAMP_FREQ:
499 if (!val) {
500 ret = -EINVAL;
501 break;
502 }
503
504 for (i = 0; i < 16; i++)
505 if (val == st->chip_info->sample_freq_avail[i])
506 break;
507
508 if (i == 16) {
509 ret = -EINVAL;
510 break;
511 }
512
513 st->mode &= ~AD7793_MODE_RATE(-1);
514 st->mode |= AD7793_MODE_RATE(i);
515 ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode),
516 st->mode);
517 break;
545 default:518 default:
546 ret = -EINVAL;519 ret = -EINVAL;
547 }520 }
drivers/iio/adc/at91-sama5d2_adc.c+37−4
@@ -333,6 +333,27 @@ static const struct iio_chan_spec at91_adc_channels[] = { · 332 unmodified lines
333 + AT91_SAMA5D2_DIFF_CHAN_CNT + 1),333 + AT91_SAMA5D2_DIFF_CHAN_CNT + 1),
334};334};
335 335
336static int at91_adc_chan_xlate(struct iio_dev *indio_dev, int chan)
337{
338 int i;
339
340 for (i = 0; i < indio_dev->num_channels; i++) {
341 if (indio_dev->channels[i].scan_index == chan)
342 return i;
343 }
344 return -EINVAL;
345}
346
347static inline struct iio_chan_spec const *
348at91_adc_chan_get(struct iio_dev *indio_dev, int chan)
349{
350 int index = at91_adc_chan_xlate(indio_dev, chan);
351
352 if (index < 0)
353 return NULL;
354 return indio_dev->channels + index;
355}
356
336static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)357static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
337{358{
338 struct iio_dev *indio = iio_trigger_get_drvdata(trig);359 struct iio_dev *indio = iio_trigger_get_drvdata(trig);
@@ -350,8 +371,10 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) · 11 unmodified lines
350 at91_adc_writel(st, AT91_SAMA5D2_TRGR, status);371 at91_adc_writel(st, AT91_SAMA5D2_TRGR, status);
351 372
352 for_each_set_bit(bit, indio->active_scan_mask, indio->num_channels) {373 for_each_set_bit(bit, indio->active_scan_mask, indio->num_channels) {
353 struct iio_chan_spec const *chan = indio->channels + bit;374 struct iio_chan_spec const *chan = at91_adc_chan_get(indio, bit);
354 375
376 if (!chan)
377 continue;
355 if (state) {378 if (state) {
356 at91_adc_writel(st, AT91_SAMA5D2_CHER,379 at91_adc_writel(st, AT91_SAMA5D2_CHER,
357 BIT(chan->channel));380 BIT(chan->channel));
@@ -448,7 +471,11 @@ static int at91_adc_dma_start(struct iio_dev *indio_dev) · 90 unmodified lines
448 471
449 for_each_set_bit(bit, indio_dev->active_scan_mask,472 for_each_set_bit(bit, indio_dev->active_scan_mask,
450 indio_dev->num_channels) {473 indio_dev->num_channels) {
451 struct iio_chan_spec const *chan = indio_dev->channels + bit;474 struct iio_chan_spec const *chan =
475 at91_adc_chan_get(indio_dev, bit);
476
477 if (!chan)
478 continue;
452 479
453 st->dma_st.rx_buf_sz += chan->scan_type.storagebits / 8;480 st->dma_st.rx_buf_sz += chan->scan_type.storagebits / 8;
454 }481 }
@@ -526,8 +553,11 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev) · 71 unmodified lines
526 */553 */
527 for_each_set_bit(bit, indio_dev->active_scan_mask,554 for_each_set_bit(bit, indio_dev->active_scan_mask,
528 indio_dev->num_channels) {555 indio_dev->num_channels) {
529 struct iio_chan_spec const *chan = indio_dev->channels + bit;556 struct iio_chan_spec const *chan =
557 at91_adc_chan_get(indio_dev, bit);
530 558
559 if (!chan)
560 continue;
531 if (st->dma_st.dma_chan)561 if (st->dma_st.dma_chan)
532 at91_adc_readl(st, chan->address);562 at91_adc_readl(st, chan->address);
533 }563 }
@@ -587,8 +617,11 @@ static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev, · 53 unmodified lines
587 617
588 for_each_set_bit(bit, indio_dev->active_scan_mask,618 for_each_set_bit(bit, indio_dev->active_scan_mask,
589 indio_dev->num_channels) {619 indio_dev->num_channels) {
590 struct iio_chan_spec const *chan = indio_dev->channels + bit;620 struct iio_chan_spec const *chan =
621 at91_adc_chan_get(indio_dev, bit);
591 622
623 if (!chan)
624 continue;
592 st->buffer[i] = at91_adc_readl(st, chan->address);625 st->buffer[i] = at91_adc_readl(st, chan->address);
593 i++;626 i++;
594 }627 }
drivers/iio/adc/stm32-dfsdm-adc.c+14−3
@@ -144,6 +144,7 @@ static int stm32_dfsdm_set_osrs(struct stm32_dfsdm_filter *fl, · 143 unmodified lines
144 * Leave as soon as if exact resolution if reached.144 * Leave as soon as if exact resolution if reached.
145 * Otherwise the higher resolution below 32 bits is kept.145 * Otherwise the higher resolution below 32 bits is kept.
146 */146 */
147 fl->res = 0;
147 for (fosr = 1; fosr <= DFSDM_MAX_FL_OVERSAMPLING; fosr++) {148 for (fosr = 1; fosr <= DFSDM_MAX_FL_OVERSAMPLING; fosr++) {
148 for (iosr = 1; iosr <= DFSDM_MAX_INT_OVERSAMPLING; iosr++) {149 for (iosr = 1; iosr <= DFSDM_MAX_INT_OVERSAMPLING; iosr++) {
149 if (fast)150 if (fast)
@@ -193,7 +194,7 @@ static int stm32_dfsdm_set_osrs(struct stm32_dfsdm_filter *fl, · 43 unmodified lines
193 }194 }
194 }195 }
195 196
196 if (!fl->fosr)197 if (!fl->res)
197 return -EINVAL;198 return -EINVAL;
198 199
199 return 0;200 return 0;
@@ -770,7 +771,7 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, · 570 unmodified lines
770 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);771 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
771 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];772 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
772 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel];773 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel];
773 unsigned int spi_freq = adc->spi_freq;774 unsigned int spi_freq;
774 int ret = -EINVAL;775 int ret = -EINVAL;
775 776
776 switch (mask) {777 switch (mask) {
@@ -784,8 +785,18 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, · 7 unmodified lines
784 case IIO_CHAN_INFO_SAMP_FREQ:785 case IIO_CHAN_INFO_SAMP_FREQ:
785 if (!val)786 if (!val)
786 return -EINVAL;787 return -EINVAL;
787 if (ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL)788
789 switch (ch->src) {
790 case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL:
788 spi_freq = adc->dfsdm->spi_master_freq;791 spi_freq = adc->dfsdm->spi_master_freq;
792 break;
793 case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING:
794 case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING:
795 spi_freq = adc->dfsdm->spi_master_freq / 2;
796 break;
797 default:
798 spi_freq = adc->spi_freq;
799 }
789 800
790 if (spi_freq % val)801 if (spi_freq % val)
791 dev_warn(&indio_dev->dev,802 dev_warn(&indio_dev->dev,
drivers/iio/buffer/industrialio-buffer-dma.c+1−1
@@ -587,7 +587,7 @@ EXPORT_SYMBOL_GPL(iio_dma_buffer_set_bytes_per_datum); · 586 unmodified lines
587 * Should be used as the set_length callback for iio_buffer_access_ops587 * Should be used as the set_length callback for iio_buffer_access_ops
588 * struct for DMA buffers.588 * struct for DMA buffers.
589 */589 */
590int iio_dma_buffer_set_length(struct iio_buffer *buffer, int length)590int iio_dma_buffer_set_length(struct iio_buffer *buffer, unsigned int length)
591{591{
592 /* Avoid an invalid state */592 /* Avoid an invalid state */
593 if (length < 2)593 if (length < 2)
drivers/iio/buffer/kfifo_buf.c+9−2
@@ -22,11 +22,18 @@ struct iio_kfifo { · 21 unmodified lines
22#define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer)22#define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer)
23 23
24static inline int __iio_allocate_kfifo(struct iio_kfifo *buf,24static inline int __iio_allocate_kfifo(struct iio_kfifo *buf,
25 int bytes_per_datum, int length)25 size_t bytes_per_datum, unsigned int length)
26{26{
27 if ((length == 0) || (bytes_per_datum == 0))27 if ((length == 0) || (bytes_per_datum == 0))
28 return -EINVAL;28 return -EINVAL;
29 29
30 /*
31 * Make sure we don't overflow an unsigned int after kfifo rounds up to
32 * the next power of 2.
33 */
34 if (roundup_pow_of_two(length) > UINT_MAX / bytes_per_datum)
35 return -EINVAL;
36
30 return __kfifo_alloc((struct __kfifo *)&buf->kf, length,37 return __kfifo_alloc((struct __kfifo *)&buf->kf, length,
31 bytes_per_datum, GFP_KERNEL);38 bytes_per_datum, GFP_KERNEL);
32}39}
@@ -67,7 +74,7 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd) · 34 unmodified lines
67 return 0;74 return 0;
68}75}
69 76
70static int iio_set_length_kfifo(struct iio_buffer *r, int length)77static int iio_set_length_kfifo(struct iio_buffer *r, unsigned int length)
71{78{
72 /* Avoid an invalid state */79 /* Avoid an invalid state */
73 if (length < 2)80 if (length < 2)
drivers/iio/common/hid-sensors/hid-sensor-trigger.c+4−4
@@ -178,14 +178,14 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) · 177 unmodified lines
178#ifdef CONFIG_PM178#ifdef CONFIG_PM
179 int ret;179 int ret;
180 180
181 atomic_set(&st->user_requested_state, state);
182
183 if (atomic_add_unless(&st->runtime_pm_enable, 1, 1))181 if (atomic_add_unless(&st->runtime_pm_enable, 1, 1))
184 pm_runtime_enable(&st->pdev->dev);182 pm_runtime_enable(&st->pdev->dev);
185 183
186 if (state)184 if (state) {
185 atomic_inc(&st->user_requested_state);
187 ret = pm_runtime_get_sync(&st->pdev->dev);186 ret = pm_runtime_get_sync(&st->pdev->dev);
188 else {187 } else {
188 atomic_dec(&st->user_requested_state);
189 pm_runtime_mark_last_busy(&st->pdev->dev);189 pm_runtime_mark_last_busy(&st->pdev->dev);
190 pm_runtime_use_autosuspend(&st->pdev->dev);190 pm_runtime_use_autosuspend(&st->pdev->dev);
191 ret = pm_runtime_put_autosuspend(&st->pdev->dev);191 ret = pm_runtime_put_autosuspend(&st->pdev->dev);
include/linux/iio/buffer_impl.h+3−3
@@ -53,7 +53,7 @@ struct iio_buffer_access_funcs { · 52 unmodified lines
53 int (*request_update)(struct iio_buffer *buffer);53 int (*request_update)(struct iio_buffer *buffer);
54 54
55 int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd);55 int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd);
56 int (*set_length)(struct iio_buffer *buffer, int length);56 int (*set_length)(struct iio_buffer *buffer, unsigned int length);
57 57
58 int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);58 int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
59 int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);59 int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
@@ -72,10 +72,10 @@ struct iio_buffer_access_funcs { · 12 unmodified lines
72 */72 */
73struct iio_buffer {73struct iio_buffer {
74 /** @length: Number of datums in buffer. */74 /** @length: Number of datums in buffer. */
75 int length;75 unsigned int length;
76 76
77 /** @bytes_per_datum: Size of individual datum including timestamp. */77 /** @bytes_per_datum: Size of individual datum including timestamp. */
78 int bytes_per_datum;78 size_t bytes_per_datum;
79 79
80 /**80 /**
81 * @access: Buffer access functions associated with the81 * @access: Buffer access functions associated with the