diff options
author | Benjamin Gaignard <benjamin.gaignard@linaro.org> | 2017-04-04 03:47:52 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2017-04-14 10:09:04 -0400 |
commit | 2a830a45ffb05d1aa8d7866235501f635678bec6 (patch) | |
tree | a5a48abbea064c60f455ffb9dd249543f7fcf27d /drivers/iio/trigger/stm32-timer-trigger.c | |
parent | 4adec7da0536a345d901d7ba55b6c93a14eeeaff (diff) |
iio: stm32 trigger: Add counter enable modes
Device counting could be controlled by the level or the edges of
a trigger.
in_count0_enable_mode attibute allow to set the control mode.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@st.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/trigger/stm32-timer-trigger.c')
-rw-r--r-- | drivers/iio/trigger/stm32-timer-trigger.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c index 7db904cae926..0f1a2cf334bf 100644 --- a/drivers/iio/trigger/stm32-timer-trigger.c +++ b/drivers/iio/trigger/stm32-timer-trigger.c | |||
@@ -353,6 +353,74 @@ static const struct iio_info stm32_trigger_info = { | |||
353 | .write_raw = stm32_counter_write_raw | 353 | .write_raw = stm32_counter_write_raw |
354 | }; | 354 | }; |
355 | 355 | ||
356 | static const char *const stm32_enable_modes[] = { | ||
357 | "always", | ||
358 | "gated", | ||
359 | "triggered", | ||
360 | }; | ||
361 | |||
362 | static int stm32_enable_mode2sms(int mode) | ||
363 | { | ||
364 | switch (mode) { | ||
365 | case 0: | ||
366 | return 0; | ||
367 | case 1: | ||
368 | return 5; | ||
369 | case 2: | ||
370 | return 6; | ||
371 | } | ||
372 | |||
373 | return -EINVAL; | ||
374 | } | ||
375 | |||
376 | static int stm32_set_enable_mode(struct iio_dev *indio_dev, | ||
377 | const struct iio_chan_spec *chan, | ||
378 | unsigned int mode) | ||
379 | { | ||
380 | struct stm32_timer_trigger *priv = iio_priv(indio_dev); | ||
381 | int sms = stm32_enable_mode2sms(mode); | ||
382 | |||
383 | if (sms < 0) | ||
384 | return sms; | ||
385 | |||
386 | regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, sms); | ||
387 | |||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | static int stm32_sms2enable_mode(int mode) | ||
392 | { | ||
393 | switch (mode) { | ||
394 | case 0: | ||
395 | return 0; | ||
396 | case 5: | ||
397 | return 1; | ||
398 | case 6: | ||
399 | return 2; | ||
400 | } | ||
401 | |||
402 | return -EINVAL; | ||
403 | } | ||
404 | |||
405 | static int stm32_get_enable_mode(struct iio_dev *indio_dev, | ||
406 | const struct iio_chan_spec *chan) | ||
407 | { | ||
408 | struct stm32_timer_trigger *priv = iio_priv(indio_dev); | ||
409 | u32 smcr; | ||
410 | |||
411 | regmap_read(priv->regmap, TIM_SMCR, &smcr); | ||
412 | smcr &= TIM_SMCR_SMS; | ||
413 | |||
414 | return stm32_sms2enable_mode(smcr); | ||
415 | } | ||
416 | |||
417 | static const struct iio_enum stm32_enable_mode_enum = { | ||
418 | .items = stm32_enable_modes, | ||
419 | .num_items = ARRAY_SIZE(stm32_enable_modes), | ||
420 | .set = stm32_set_enable_mode, | ||
421 | .get = stm32_get_enable_mode | ||
422 | }; | ||
423 | |||
356 | static const char *const stm32_quadrature_modes[] = { | 424 | static const char *const stm32_quadrature_modes[] = { |
357 | "channel_A", | 425 | "channel_A", |
358 | "channel_B", | 426 | "channel_B", |
@@ -466,6 +534,8 @@ static const struct iio_chan_spec_ext_info stm32_trigger_count_info[] = { | |||
466 | IIO_ENUM_AVAILABLE("count_direction", &stm32_count_direction_enum), | 534 | IIO_ENUM_AVAILABLE("count_direction", &stm32_count_direction_enum), |
467 | IIO_ENUM("quadrature_mode", IIO_SEPARATE, &stm32_quadrature_mode_enum), | 535 | IIO_ENUM("quadrature_mode", IIO_SEPARATE, &stm32_quadrature_mode_enum), |
468 | IIO_ENUM_AVAILABLE("quadrature_mode", &stm32_quadrature_mode_enum), | 536 | IIO_ENUM_AVAILABLE("quadrature_mode", &stm32_quadrature_mode_enum), |
537 | IIO_ENUM("enable_mode", IIO_SEPARATE, &stm32_enable_mode_enum), | ||
538 | IIO_ENUM_AVAILABLE("enable_mode", &stm32_enable_mode_enum), | ||
469 | {} | 539 | {} |
470 | }; | 540 | }; |
471 | 541 | ||