aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/trigger/stm32-timer-trigger.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-08-20 13:45:54 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-08-20 13:45:54 -0400
commit2c68888f1d76c668024a9efa50af382df4f3cf8e (patch)
treee4b09f736e9febb5a70444bb692d170479b35a0f /drivers/iio/trigger/stm32-timer-trigger.c
parentf299aec6ebd747298e35934cff7709c6b119ca52 (diff)
parent8b35a5f87a73842601cd376e0f5b9b25831390f4 (diff)
Merge tag 'fixes-for-4.13b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: Second set of IIO fixes for the 4.13 cycle. Given the late stage of this series, some more involved fixes have been held back for the upcoming merge window. The hid-sensor issue has been causing problems for a long time so it is great to have that one finally fixed! No more bug reports for the userspace guys (well about that anyway). * documentation - some warning fixes due to missing colons in kernel-doc. * adis16480 - fix accel scale factor. * bmp280 - properly initialize the device for humidity readings - without this the humidity readings may be skipped and a magic value of 0x8000 returned. * hid-sensor-strigger - fix a race with user space when powering up the sensor. * ina291 - Avoid an underflow for the sleeping time as a result of supporting the fastest rates. * st-magnetometer - Fix the status register address for hte LSM303AGR, - Remove the ihl property for LSM303AGR as the sensor doesn't support active low for the dataready line. * stm32-adc - Fix use of a common clock rate. * stm32-timer - fix the quadrature mode get routine to account for the magic 0 value. set on boot. - fix the return value of write_raw, - fix the get/set down count direction as the enum value was not being converted to the relevant bit field, - add an enable attribute to actually turn it on when in encoder mode, - missing mask when reading the trigger mode.
Diffstat (limited to 'drivers/iio/trigger/stm32-timer-trigger.c')
-rw-r--r--drivers/iio/trigger/stm32-timer-trigger.c82
1 files changed, 59 insertions, 23 deletions
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c
index d22bc56dd9fc..25ad6abfee22 100644
--- a/drivers/iio/trigger/stm32-timer-trigger.c
+++ b/drivers/iio/trigger/stm32-timer-trigger.c
@@ -366,34 +366,32 @@ static int stm32_counter_read_raw(struct iio_dev *indio_dev,
366 int *val, int *val2, long mask) 366 int *val, int *val2, long mask)
367{ 367{
368 struct stm32_timer_trigger *priv = iio_priv(indio_dev); 368 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
369 u32 dat;
369 370
370 switch (mask) { 371 switch (mask) {
371 case IIO_CHAN_INFO_RAW: 372 case IIO_CHAN_INFO_RAW:
372 { 373 regmap_read(priv->regmap, TIM_CNT, &dat);
373 u32 cnt; 374 *val = dat;
374 375 return IIO_VAL_INT;
375 regmap_read(priv->regmap, TIM_CNT, &cnt);
376 *val = cnt;
377 376
377 case IIO_CHAN_INFO_ENABLE:
378 regmap_read(priv->regmap, TIM_CR1, &dat);
379 *val = (dat & TIM_CR1_CEN) ? 1 : 0;
378 return IIO_VAL_INT; 380 return IIO_VAL_INT;
379 }
380 case IIO_CHAN_INFO_SCALE:
381 {
382 u32 smcr;
383 381
384 regmap_read(priv->regmap, TIM_SMCR, &smcr); 382 case IIO_CHAN_INFO_SCALE:
385 smcr &= TIM_SMCR_SMS; 383 regmap_read(priv->regmap, TIM_SMCR, &dat);
384 dat &= TIM_SMCR_SMS;
386 385
387 *val = 1; 386 *val = 1;
388 *val2 = 0; 387 *val2 = 0;
389 388
390 /* in quadrature case scale = 0.25 */ 389 /* in quadrature case scale = 0.25 */
391 if (smcr == 3) 390 if (dat == 3)
392 *val2 = 2; 391 *val2 = 2;
393 392
394 return IIO_VAL_FRACTIONAL_LOG2; 393 return IIO_VAL_FRACTIONAL_LOG2;
395 } 394 }
396 }
397 395
398 return -EINVAL; 396 return -EINVAL;
399} 397}
@@ -403,15 +401,31 @@ static int stm32_counter_write_raw(struct iio_dev *indio_dev,
403 int val, int val2, long mask) 401 int val, int val2, long mask)
404{ 402{
405 struct stm32_timer_trigger *priv = iio_priv(indio_dev); 403 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
404 u32 dat;
406 405
407 switch (mask) { 406 switch (mask) {
408 case IIO_CHAN_INFO_RAW: 407 case IIO_CHAN_INFO_RAW:
409 regmap_write(priv->regmap, TIM_CNT, val); 408 return regmap_write(priv->regmap, TIM_CNT, val);
410 409
411 return IIO_VAL_INT;
412 case IIO_CHAN_INFO_SCALE: 410 case IIO_CHAN_INFO_SCALE:
413 /* fixed scale */ 411 /* fixed scale */
414 return -EINVAL; 412 return -EINVAL;
413
414 case IIO_CHAN_INFO_ENABLE:
415 if (val) {
416 regmap_read(priv->regmap, TIM_CR1, &dat);
417 if (!(dat & TIM_CR1_CEN))
418 clk_enable(priv->clk);
419 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN,
420 TIM_CR1_CEN);
421 } else {
422 regmap_read(priv->regmap, TIM_CR1, &dat);
423 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN,
424 0);
425 if (dat & TIM_CR1_CEN)
426 clk_disable(priv->clk);
427 }
428 return 0;
415 } 429 }
416 430
417 return -EINVAL; 431 return -EINVAL;
@@ -471,7 +485,7 @@ static int stm32_get_trigger_mode(struct iio_dev *indio_dev,
471 485
472 regmap_read(priv->regmap, TIM_SMCR, &smcr); 486 regmap_read(priv->regmap, TIM_SMCR, &smcr);
473 487
474 return smcr == TIM_SMCR_SMS ? 0 : -EINVAL; 488 return (smcr & TIM_SMCR_SMS) == TIM_SMCR_SMS ? 0 : -EINVAL;
475} 489}
476 490
477static const struct iio_enum stm32_trigger_mode_enum = { 491static const struct iio_enum stm32_trigger_mode_enum = {
@@ -507,9 +521,19 @@ static int stm32_set_enable_mode(struct iio_dev *indio_dev,
507{ 521{
508 struct stm32_timer_trigger *priv = iio_priv(indio_dev); 522 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
509 int sms = stm32_enable_mode2sms(mode); 523 int sms = stm32_enable_mode2sms(mode);
524 u32 val;
510 525
511 if (sms < 0) 526 if (sms < 0)
512 return sms; 527 return sms;
528 /*
529 * Triggered mode sets CEN bit automatically by hardware. So, first
530 * enable counter clock, so it can use it. Keeps it in sync with CEN.
531 */
532 if (sms == 6) {
533 regmap_read(priv->regmap, TIM_CR1, &val);
534 if (!(val & TIM_CR1_CEN))
535 clk_enable(priv->clk);
536 }
513 537
514 regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, sms); 538 regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, sms);
515 539
@@ -571,11 +595,14 @@ static int stm32_get_quadrature_mode(struct iio_dev *indio_dev,
571{ 595{
572 struct stm32_timer_trigger *priv = iio_priv(indio_dev); 596 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
573 u32 smcr; 597 u32 smcr;
598 int mode;
574 599
575 regmap_read(priv->regmap, TIM_SMCR, &smcr); 600 regmap_read(priv->regmap, TIM_SMCR, &smcr);
576 smcr &= TIM_SMCR_SMS; 601 mode = (smcr & TIM_SMCR_SMS) - 1;
602 if ((mode < 0) || (mode > ARRAY_SIZE(stm32_quadrature_modes)))
603 return -EINVAL;
577 604
578 return smcr - 1; 605 return mode;
579} 606}
580 607
581static const struct iio_enum stm32_quadrature_mode_enum = { 608static const struct iio_enum stm32_quadrature_mode_enum = {
@@ -592,13 +619,20 @@ static const char *const stm32_count_direction_states[] = {
592 619
593static int stm32_set_count_direction(struct iio_dev *indio_dev, 620static int stm32_set_count_direction(struct iio_dev *indio_dev,
594 const struct iio_chan_spec *chan, 621 const struct iio_chan_spec *chan,
595 unsigned int mode) 622 unsigned int dir)
596{ 623{
597 struct stm32_timer_trigger *priv = iio_priv(indio_dev); 624 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
625 u32 val;
626 int mode;
598 627
599 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_DIR, mode); 628 /* In encoder mode, direction is RO (given by TI1/TI2 signals) */
629 regmap_read(priv->regmap, TIM_SMCR, &val);
630 mode = (val & TIM_SMCR_SMS) - 1;
631 if ((mode >= 0) || (mode < ARRAY_SIZE(stm32_quadrature_modes)))
632 return -EBUSY;
600 633
601 return 0; 634 return regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_DIR,
635 dir ? TIM_CR1_DIR : 0);
602} 636}
603 637
604static int stm32_get_count_direction(struct iio_dev *indio_dev, 638static int stm32_get_count_direction(struct iio_dev *indio_dev,
@@ -609,7 +643,7 @@ static int stm32_get_count_direction(struct iio_dev *indio_dev,
609 643
610 regmap_read(priv->regmap, TIM_CR1, &cr1); 644 regmap_read(priv->regmap, TIM_CR1, &cr1);
611 645
612 return (cr1 & TIM_CR1_DIR); 646 return ((cr1 & TIM_CR1_DIR) ? 1 : 0);
613} 647}
614 648
615static const struct iio_enum stm32_count_direction_enum = { 649static const struct iio_enum stm32_count_direction_enum = {
@@ -672,7 +706,9 @@ static const struct iio_chan_spec_ext_info stm32_trigger_count_info[] = {
672static const struct iio_chan_spec stm32_trigger_channel = { 706static const struct iio_chan_spec stm32_trigger_channel = {
673 .type = IIO_COUNT, 707 .type = IIO_COUNT,
674 .channel = 0, 708 .channel = 0,
675 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 709 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
710 BIT(IIO_CHAN_INFO_ENABLE) |
711 BIT(IIO_CHAN_INFO_SCALE),
676 .ext_info = stm32_trigger_count_info, 712 .ext_info = stm32_trigger_count_info,
677 .indexed = 1 713 .indexed = 1
678}; 714};