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
158158 depends on ARCH_AT91 || COMPILE_TEST
159159 depends on HAS_IOMEM
160160 depends on HAS_DMA
161+ select IIO_BUFFER
161162 select IIO_TRIGGERED_BUFFER
162163 help
163164 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
348348 static const u16 ad7797_sample_freq_avail[16] = {0, 0, 0, 123, 62, 50, 0,
349349 33, 0, 17, 16, 12, 10, 8, 6, 4};
350350
351−static 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−
362−static 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−
396−static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
397− ad7793_read_frequency,
398− ad7793_write_frequency);
399−
400351 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
401352 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");
402353
@@ -424,7 +375,6 @@ static IIO_DEVICE_ATTR_NAMED(in_m_in_scale_available, · 21 unmodified lines
424375 ad7793_show_scale_available, NULL, 0);
425376
426377 static struct attribute *ad7793_attributes[] = {
427− &iio_dev_attr_sampling_frequency.dev_attr.attr,
428378 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
429379 &iio_dev_attr_in_m_in_scale_available.dev_attr.attr,
430380 NULL
@@ -435,7 +385,6 @@ static const struct attribute_group ad7793_attribute_group = { · 4 unmodified lines
435385 };
436386
437387 static struct attribute *ad7797_attributes[] = {
438− &iio_dev_attr_sampling_frequency.dev_attr.attr,
439388 &iio_const_attr_sampling_frequency_available_ad7797.dev_attr.attr,
440389 NULL
441390 };
@@ -505,6 +454,10 @@ static int ad7793_read_raw(struct iio_dev *indio_dev, · 63 unmodified lines
505454 *val -= offset;
506455 }
507456 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;
508461 }
509462 return -EINVAL;
510463 }
@@ -542,6 +495,26 @@ static int ad7793_write_raw(struct iio_dev *indio_dev, · 31 unmodified lines
542495 break;
543496 }
544497 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;
545518 default:
546519 ret = -EINVAL;
547520 }
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
333333 + AT91_SAMA5D2_DIFF_CHAN_CNT + 1),
334334 };
335335
336+static 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+
347+static inline struct iio_chan_spec const *
348+at91_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+
336357 static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
337358 {
338359 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
350371 at91_adc_writel(st, AT91_SAMA5D2_TRGR, status);
351372
352373 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);
354375
376+ if (!chan)
377+ continue;
355378 if (state) {
356379 at91_adc_writel(st, AT91_SAMA5D2_CHER,
357380 BIT(chan->channel));
@@ -448,7 +471,11 @@ static int at91_adc_dma_start(struct iio_dev *indio_dev) · 90 unmodified lines
448471
449472 for_each_set_bit(bit, indio_dev->active_scan_mask,
450473 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;
452479
453480 st->dma_st.rx_buf_sz += chan->scan_type.storagebits / 8;
454481 }
@@ -526,8 +553,11 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev) · 71 unmodified lines
526553 */
527554 for_each_set_bit(bit, indio_dev->active_scan_mask,
528555 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);
530558
559+ if (!chan)
560+ continue;
531561 if (st->dma_st.dma_chan)
532562 at91_adc_readl(st, chan->address);
533563 }
@@ -587,8 +617,11 @@ static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev, · 53 unmodified lines
587617
588618 for_each_set_bit(bit, indio_dev->active_scan_mask,
589619 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);
591622
623+ if (!chan)
624+ continue;
592625 st->buffer[i] = at91_adc_readl(st, chan->address);
593626 i++;
594627 }
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
144144 * Leave as soon as if exact resolution if reached.
145145 * Otherwise the higher resolution below 32 bits is kept.
146146 */
147+ fl->res = 0;
147148 for (fosr = 1; fosr <= DFSDM_MAX_FL_OVERSAMPLING; fosr++) {
148149 for (iosr = 1; iosr <= DFSDM_MAX_INT_OVERSAMPLING; iosr++) {
149150 if (fast)
@@ -193,7 +194,7 @@ static int stm32_dfsdm_set_osrs(struct stm32_dfsdm_filter *fl, · 43 unmodified lines
193194 }
194195 }
195196
196− if (!fl->fosr)
197+ if (!fl->res)
197198 return -EINVAL;
198199
199200 return 0;
@@ -770,7 +771,7 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, · 570 unmodified lines
770771 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
771772 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
772773 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel];
773− unsigned int spi_freq = adc->spi_freq;
774+ unsigned int spi_freq;
774775 int ret = -EINVAL;
775776
776777 switch (mask) {
@@ -784,8 +785,18 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, · 7 unmodified lines
784785 case IIO_CHAN_INFO_SAMP_FREQ:
785786 if (!val)
786787 return -EINVAL;
787− if (ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL)
788+
789+ switch (ch->src) {
790+ case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL:
788791 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+ }
789800
790801 if (spi_freq % val)
791802 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
587587 * Should be used as the set_length callback for iio_buffer_access_ops
588588 * struct for DMA buffers.
589589 */
590−int iio_dma_buffer_set_length(struct iio_buffer *buffer, int length)
590+int iio_dma_buffer_set_length(struct iio_buffer *buffer, unsigned int length)
591591 {
592592 /* Avoid an invalid state */
593593 if (length < 2)
drivers/iio/buffer/kfifo_buf.c+9−2
@@ -22,11 +22,18 @@ struct iio_kfifo { · 21 unmodified lines
2222 #define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer)
2323
2424 static 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)
2626 {
2727 if ((length == 0) || (bytes_per_datum == 0))
2828 return -EINVAL;
2929
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+
3037 return __kfifo_alloc((struct __kfifo *)&buf->kf, length,
3138 bytes_per_datum, GFP_KERNEL);
3239 }
@@ -67,7 +74,7 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd) · 34 unmodified lines
6774 return 0;
6875 }
6976
70−static int iio_set_length_kfifo(struct iio_buffer *r, int length)
77+static int iio_set_length_kfifo(struct iio_buffer *r, unsigned int length)
7178 {
7279 /* Avoid an invalid state */
7380 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
178178 #ifdef CONFIG_PM
179179 int ret;
180180
181− atomic_set(&st->user_requested_state, state);
182−
183181 if (atomic_add_unless(&st->runtime_pm_enable, 1, 1))
184182 pm_runtime_enable(&st->pdev->dev);
185183
186− if (state)
184+ if (state) {
185+ atomic_inc(&st->user_requested_state);
187186 ret = pm_runtime_get_sync(&st->pdev->dev);
188− else {
187+ } else {
188+ atomic_dec(&st->user_requested_state);
189189 pm_runtime_mark_last_busy(&st->pdev->dev);
190190 pm_runtime_use_autosuspend(&st->pdev->dev);
191191 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
5353 int (*request_update)(struct iio_buffer *buffer);
5454
5555 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);
5757
5858 int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
5959 int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
@@ -72,10 +72,10 @@ struct iio_buffer_access_funcs { · 12 unmodified lines
7272 */
7373 struct iio_buffer {
7474 /** @length: Number of datums in buffer. */
75− int length;
75+ unsigned int length;
7676
7777 /** @bytes_per_datum: Size of individual datum including timestamp. */
78− int bytes_per_datum;
78+ size_t bytes_per_datum;
7979
8080 /**
8181 * @access: Buffer access functions associated with the