summaryrefslogtreecommitdiff
path: root/drivers/staging/iio/resolver
diff options
context:
space:
mode:
authorDavid Lechner <dlechner@baylibre.com>2023-10-11 00:12:33 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2023-10-12 10:56:08 +0300
commit27ffa2216acfab3527064ec13666f35d70f76045 (patch)
treee5832bb8b82159c036f272a264bd681c2185c86c /drivers/staging/iio/resolver
parent73aa842baf877cc8c8da819f4ea927307dd8b6e4 (diff)
downloadlinux-27ffa2216acfab3527064ec13666f35d70f76045.tar.xz
staging: iio: resolver: ad2s1210: refactor sample toggle
This refactors the sample line toggle in the ad2s1210 resolver driver to a separate function. The sample has some timing requirements, so this ensures that it is always done the same way, both in the existing call sites and any future usage. Previously, the sample line was kept on for the duration of the read, but this is not necessary. Data is latched in on the rising edge and after the specified delay the state of the sample line does not matter. Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://lore.kernel.org/r/20231010-ad2s1210-mainline-v5-1-35a0f6ffa04a@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/staging/iio/resolver')
-rw-r--r--drivers/staging/iio/resolver/ad2s1210.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
index e0bea3c68664..59c273a4b6a9 100644
--- a/drivers/staging/iio/resolver/ad2s1210.c
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -287,6 +287,26 @@ static int ad2s1210_regmap_reg_read(void *context, unsigned int reg,
}
/*
+ * Toggles the SAMPLE line on the AD2S1210 to latch in the current position,
+ * velocity, and faults.
+ *
+ * Must be called with lock held.
+ */
+static void ad2s1210_toggle_sample_line(struct ad2s1210_state *st)
+{
+ /*
+ * Datasheet specifies minimum hold time t16 = 2 * tck + 20 ns. So the
+ * longest time needed is when CLKIN is 6.144 MHz, in which case t16
+ * ~= 350 ns. The same delay is also needed before re-asserting the
+ * SAMPLE line.
+ */
+ gpiod_set_value(st->sample_gpio, 1);
+ ndelay(350);
+ gpiod_set_value(st->sample_gpio, 0);
+ ndelay(350);
+}
+
+/*
* Sets the excitation frequency and performs software reset.
*
* Must be called with lock held.
@@ -405,10 +425,8 @@ static int ad2s1210_single_conversion(struct iio_dev *indio_dev,
int ret;
mutex_lock(&st->lock);
- gpiod_set_value(st->sample_gpio, 1);
+ ad2s1210_toggle_sample_line(st);
timestamp = iio_get_time_ns(indio_dev);
- /* delay (6 * tck + 20) nano seconds */
- udelay(1);
switch (chan->type) {
case IIO_ANGL:
@@ -444,9 +462,6 @@ static int ad2s1210_single_conversion(struct iio_dev *indio_dev,
ad2s1210_push_events(indio_dev, st->sample.fault, timestamp);
error_ret:
- gpiod_set_value(st->sample_gpio, 0);
- /* delay (2 * tck + 20) nano seconds */
- udelay(1);
mutex_unlock(&st->lock);
return ret;
}
@@ -1268,7 +1283,7 @@ static irqreturn_t ad2s1210_trigger_handler(int irq, void *p)
mutex_lock(&st->lock);
memset(&st->scan, 0, sizeof(st->scan));
- gpiod_set_value(st->sample_gpio, 1);
+ ad2s1210_toggle_sample_line(st);
if (test_bit(0, indio_dev->active_scan_mask)) {
ret = ad2s1210_set_mode(st, MOD_POS);
@@ -1298,7 +1313,6 @@ static irqreturn_t ad2s1210_trigger_handler(int irq, void *p)
iio_push_to_buffers_with_timestamp(indio_dev, &st->scan, pf->timestamp);
error_ret:
- gpiod_set_value(st->sample_gpio, 0);
mutex_unlock(&st->lock);
iio_trigger_notify_done(indio_dev->trig);