Skip to content

Commit

Permalink
iio: logic: m2k-trigger-ad: Add trigger holdoff support
Browse files Browse the repository at this point in the history
Trigger hold off add the possibility to ingnore all the trigger
events during a period specified using the holdoff attribute.
The raw value from attribute times 10ns represent the actual holdoff
period.

Signed-off-by: Bogdan Togorean <bogdan.togorean@analog.com>
  • Loading branch information
btogorean authored and commodo committed Sep 17, 2020
1 parent 8446cf3 commit bd9f616
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions drivers/iio/logic/m2k-trigger-ad.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define AXI_ADC_TRIG_REG_TRIGGERED 0x3c
#define AXI_ADC_TRIG_REG_DELAY 0x40
#define AXI_ADC_TRIG_REG_STREAMING 0x44
#define AXI_ADC_TRIG_REG_HOLDOFF 0x48

/* AXI_ADC_TRIG_REG_CONFIG_TRIGGER */
#define CONF_LOW_LEVEL 0
Expand All @@ -49,6 +50,8 @@
#define TRIGGER_ADC_CHAN 2
#define TRIGGER_MIX_CHAN 2

#define TRIGGER_HOLDOFF_MASK GENMASK(31, 0)

#define IIO_ENUM_AVAILABLE_SEPARATE(_name, _e) \
{ \
.name = (_name "_available"), \
Expand Down Expand Up @@ -497,6 +500,35 @@ static ssize_t axi_adc_trig_set_streaming(struct iio_dev *indio_dev,
return len;
}

static ssize_t axi_adc_trig_get_holdoff(struct iio_dev *indio_dev,
uintptr_t priv, const struct iio_chan_spec *chan, char *buf)
{
struct axi_adc_trig *axi_adc_trig = iio_priv(indio_dev);
unsigned int val;

val = axi_adc_trig_read(axi_adc_trig, AXI_ADC_TRIG_REG_HOLDOFF);
val &= TRIGGER_HOLDOFF_MASK;

return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}

static ssize_t axi_adc_trig_set_holdoff(struct iio_dev *indio_dev,
uintptr_t priv, const struct iio_chan_spec *chan, const char *buf,
size_t len)
{
struct axi_adc_trig *axi_adc_trig = iio_priv(indio_dev);
unsigned int val;
int ret;

ret = kstrtouint(buf, 10, &val);
if (ret < 0)
return ret;

axi_adc_trig_write(axi_adc_trig, AXI_ADC_TRIG_REG_HOLDOFF, val);

return len;
}

static ssize_t axi_adc_trig_get_embedded_trigger(struct iio_dev *indio_dev,
uintptr_t priv, const struct iio_chan_spec *chan, char *buf)
{
Expand Down Expand Up @@ -565,6 +597,12 @@ static const struct iio_chan_spec_ext_info axi_adc_trig_analog_info[] = {
.write = axi_adc_trig_set_streaming,
.read = axi_adc_trig_get_streaming,
},
{
.name = "holdoff_raw",
.shared = IIO_SHARED_BY_ALL,
.write = axi_adc_trig_set_holdoff,
.read = axi_adc_trig_get_holdoff,
},
{}
};

Expand Down

0 comments on commit bd9f616

Please sign in to comment.