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

iio: make stm32 trigger driver use INDIO_HARDWARE_TRIGGERED mode

Add validate function to be use to use the correct trigger.
Add an attribute to configure device mode like for quadrature and
enable modes

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@st.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Benjamin Gaignard and committed by
Jonathan Cameron
9eba381b d89e119a

+76
+15
Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
··· 138 138 Counting is enabled on rising edge of the connected 139 139 trigger, and remains enabled for the duration of this 140 140 selected mode. 141 + 142 + What: /sys/bus/iio/devices/iio:deviceX/in_count_trigger_mode_available 143 + KernelVersion: 4.13 144 + Contact: benjamin.gaignard@st.com 145 + Description: 146 + Reading returns the list possible trigger modes. 147 + 148 + What: /sys/bus/iio/devices/iio:deviceX/in_count0_trigger_mode 149 + KernelVersion: 4.13 150 + Contact: benjamin.gaignard@st.com 151 + Description: 152 + Configure the device counter trigger mode 153 + counting direction is set by in_count0_count_direction 154 + attribute and the counter is clocked by the connected trigger 155 + rising edges.
+61
drivers/iio/trigger/stm32-timer-trigger.c
··· 417 417 return -EINVAL; 418 418 } 419 419 420 + static int stm32_counter_validate_trigger(struct iio_dev *indio_dev, 421 + struct iio_trigger *trig) 422 + { 423 + struct stm32_timer_trigger *priv = iio_priv(indio_dev); 424 + const char * const *cur = priv->valids; 425 + unsigned int i = 0; 426 + 427 + if (!is_stm32_timer_trigger(trig)) 428 + return -EINVAL; 429 + 430 + while (cur && *cur) { 431 + if (!strncmp(trig->name, *cur, strlen(trig->name))) { 432 + regmap_update_bits(priv->regmap, 433 + TIM_SMCR, TIM_SMCR_TS, 434 + i << TIM_SMCR_TS_SHIFT); 435 + return 0; 436 + } 437 + cur++; 438 + i++; 439 + } 440 + 441 + return -EINVAL; 442 + } 443 + 420 444 static const struct iio_info stm32_trigger_info = { 421 445 .driver_module = THIS_MODULE, 446 + .validate_trigger = stm32_counter_validate_trigger, 422 447 .read_raw = stm32_counter_read_raw, 423 448 .write_raw = stm32_counter_write_raw 449 + }; 450 + 451 + static const char *const stm32_trigger_modes[] = { 452 + "trigger", 453 + }; 454 + 455 + static int stm32_set_trigger_mode(struct iio_dev *indio_dev, 456 + const struct iio_chan_spec *chan, 457 + unsigned int mode) 458 + { 459 + struct stm32_timer_trigger *priv = iio_priv(indio_dev); 460 + 461 + regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, TIM_SMCR_SMS); 462 + 463 + return 0; 464 + } 465 + 466 + static int stm32_get_trigger_mode(struct iio_dev *indio_dev, 467 + const struct iio_chan_spec *chan) 468 + { 469 + struct stm32_timer_trigger *priv = iio_priv(indio_dev); 470 + u32 smcr; 471 + 472 + regmap_read(priv->regmap, TIM_SMCR, &smcr); 473 + 474 + return smcr == TIM_SMCR_SMS ? 0 : -EINVAL; 475 + } 476 + 477 + static const struct iio_enum stm32_trigger_mode_enum = { 478 + .items = stm32_trigger_modes, 479 + .num_items = ARRAY_SIZE(stm32_trigger_modes), 480 + .set = stm32_set_trigger_mode, 481 + .get = stm32_get_trigger_mode 424 482 }; 425 483 426 484 static const char *const stm32_enable_modes[] = { ··· 664 606 IIO_ENUM_AVAILABLE("quadrature_mode", &stm32_quadrature_mode_enum), 665 607 IIO_ENUM("enable_mode", IIO_SEPARATE, &stm32_enable_mode_enum), 666 608 IIO_ENUM_AVAILABLE("enable_mode", &stm32_enable_mode_enum), 609 + IIO_ENUM("trigger_mode", IIO_SEPARATE, &stm32_trigger_mode_enum), 610 + IIO_ENUM_AVAILABLE("trigger_mode", &stm32_trigger_mode_enum), 667 611 {} 668 612 }; 669 613 ··· 690 630 indio_dev->name = dev_name(dev); 691 631 indio_dev->dev.parent = dev; 692 632 indio_dev->info = &stm32_trigger_info; 633 + indio_dev->modes = INDIO_HARDWARE_TRIGGERED; 693 634 indio_dev->num_channels = 1; 694 635 indio_dev->channels = &stm32_trigger_channel; 695 636 indio_dev->dev.of_node = dev->of_node;