Commit eaf57d50 authored by Miquel Raynal's avatar Miquel Raynal Committed by Jonathan Cameron

iio: adc: max1027: Create a helper to enable/disable the cnvst trigger

There are two ways to physically trigger a conversion:
- A falling edge on the cnvst pin
- A write operation on the conversion register

Let's create a helper for this.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: default avatarNuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20210921115408.66711-7-miquel.raynal@bootlin.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 4201519a
...@@ -272,6 +272,25 @@ struct max1027_state { ...@@ -272,6 +272,25 @@ struct max1027_state {
u8 reg ____cacheline_aligned; u8 reg ____cacheline_aligned;
}; };
static int max1027_enable_trigger(struct iio_dev *indio_dev, bool enable)
{
struct max1027_state *st = iio_priv(indio_dev);
st->reg = MAX1027_SETUP_REG | MAX1027_REF_MODE2;
/*
* Start acquisition on:
* MODE0: external hardware trigger wired to the cnvst input pin
* MODE2: conversion register write
*/
if (enable)
st->reg |= MAX1027_CKS_MODE0;
else
st->reg |= MAX1027_CKS_MODE2;
return spi_write(st->spi, &st->reg, 1);
}
static int max1027_read_single_value(struct iio_dev *indio_dev, static int max1027_read_single_value(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, struct iio_chan_spec const *chan,
int *val) int *val)
...@@ -284,14 +303,9 @@ static int max1027_read_single_value(struct iio_dev *indio_dev, ...@@ -284,14 +303,9 @@ static int max1027_read_single_value(struct iio_dev *indio_dev,
return -EBUSY; return -EBUSY;
} }
/* Start acquisition on conversion register write */ ret = max1027_enable_trigger(indio_dev, false);
st->reg = MAX1027_SETUP_REG | MAX1027_REF_MODE2 | MAX1027_CKS_MODE2; if (ret)
ret = spi_write(st->spi, &st->reg, 1);
if (ret < 0) {
dev_err(&indio_dev->dev,
"Failed to configure setup register\n");
return ret; return ret;
}
/* Configure conversion register with the requested chan */ /* Configure conversion register with the requested chan */
st->reg = MAX1027_CONV_REG | MAX1027_CHAN(chan->channel) | st->reg = MAX1027_CONV_REG | MAX1027_CHAN(chan->channel) |
...@@ -397,11 +411,8 @@ static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state) ...@@ -397,11 +411,8 @@ static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
int ret; int ret;
if (state) { if (state) {
/* Start acquisition on cnvst */ ret = max1027_enable_trigger(indio_dev, state);
st->reg = MAX1027_SETUP_REG | MAX1027_CKS_MODE0 | if (ret)
MAX1027_REF_MODE2;
ret = spi_write(st->spi, &st->reg, 1);
if (ret < 0)
return ret; return ret;
/* /*
...@@ -418,10 +429,8 @@ static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state) ...@@ -418,10 +429,8 @@ static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
return ret; return ret;
} else { } else {
/* Start acquisition on conversion register write */ /* Start acquisition on conversion register write */
st->reg = MAX1027_SETUP_REG | MAX1027_CKS_MODE2 | ret = max1027_enable_trigger(indio_dev, state);
MAX1027_REF_MODE2; if (ret)
ret = spi_write(st->spi, &st->reg, 1);
if (ret < 0)
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment