From patchwork Tue Oct 10 21:12:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13416156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71731CD98C0 for ; Tue, 10 Oct 2023 21:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343745AbjJJVM6 (ORCPT ); Tue, 10 Oct 2023 17:12:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232348AbjJJVM5 (ORCPT ); Tue, 10 Oct 2023 17:12:57 -0400 Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89DA194 for ; Tue, 10 Oct 2023 14:12:55 -0700 (PDT) Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-1dd1db54d42so4226246fac.3 for ; Tue, 10 Oct 2023 14:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1696972375; x=1697577175; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7dl0PVkUbqTQUh7CeF07K0JAD05VmhLtJ0L4pxcpgSQ=; b=3DdiKNuXIbm+BaIGBuSLXIhp/76erp9K6yOykYfDGiQCNoO+E/nXhy5Sid4PT7Sppu 66i2p2yTXUg6B0oLK17QZ+QqM/MHeM+x+LCIk5oaIfpS7SBAhbBMg9BV4yA4YKG1uHTF K2RY+nS1eZWpjfa092PQOls3szKl7pkgPEP/lvZ82qBiiMSEtpBWtRhl5SpX+swLVFdq GX2zyEjdwyTJfLOTK8zlX9Bce8uq5rfckbCx3m+H9iUNZU8zYR8W1uqKFyXQyDUPCORv AWORnz5GR01lMIfBi5G/cYSquCZZfqu1UWvG+2CVE8q22kUlU6xs2eDLmG2KSat/N38k RWog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696972375; x=1697577175; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7dl0PVkUbqTQUh7CeF07K0JAD05VmhLtJ0L4pxcpgSQ=; b=Bgrfm6rH/ksMDro+mMin1uJBBMpUte13p5/CSoX1s1sufPhMBvYwHGMXXnIJCE+uzy zBh83EFDMmKitmU462Wv2v7KpujMJ61/3pDKuuEo3nY4G9r+hOF1hD8CkHaYvhk/UGcC AjsgMp2EzceAi7wW5Ku7vlJfA2VKdsIoaKdy+MQQDnD+iln1b4EOFUKk1eq00yHBjmyk GUIcF9QXCvbrDORBU5D4Wrc1DZfxhOQcpk3pE+Ts4yKLHGJ4JwsfYfsOYTGaPP+4AxKE IMZ1j5qEcp8GCogcKJLWUXpHitaNhF2eAV3Wj9j6ndWGrRh90KfOYZ5uv8vP3JRs1gWY RzzQ== X-Gm-Message-State: AOJu0YyKad80rhTC0o04DQ+otPs87/npt5rgBME1GHgtxnhwLW89873F CJXs56Z8mnBdQzDkKOmyu4FcycNpwEFpzM/TZQ9/1A== X-Google-Smtp-Source: AGHT+IEp7Iox6+XTb6EqSgkNZ6rYDfaZHXv9bmQpeEXZiJesGGO2MkkD0pbgtDQXWNgE2ewQpPhM9w== X-Received: by 2002:a05:6870:2326:b0:1bb:8867:f7ed with SMTP id w38-20020a056870232600b001bb8867f7edmr23858681oao.33.1696972374798; Tue, 10 Oct 2023 14:12:54 -0700 (PDT) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id ed46-20020a056870b7ae00b001e98b1544fesm52494oab.9.2023.10.10.14.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 14:12:54 -0700 (PDT) From: David Lechner To: linux-iio@vger.kernel.org, linux-staging@lists.linux.dev Cc: David Lechner , Jonathan Cameron , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Axel Haslam , Philip Molloy , linux-kernel@vger.kernel.org Subject: [PATCH v5 1/4] staging: iio: resolver: ad2s1210: refactor sample toggle Date: Tue, 10 Oct 2023 16:12:33 -0500 Message-ID: <20231010-ad2s1210-mainline-v5-1-35a0f6ffa04a@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010-ad2s1210-mainline-v5-0-35a0f6ffa04a@baylibre.com> References: <20231010-ad2s1210-mainline-v5-0-35a0f6ffa04a@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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 --- v5 changes: New patch in v5. drivers/staging/iio/resolver/ad2s1210.c | 30 ++++++++++++++++++++++-------- 1 file 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 @@ -286,6 +286,26 @@ static int ad2s1210_regmap_reg_read(void *context, unsigned int reg, return 0; } +/* + * 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. * @@ -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);