From patchwork Thu Sep 21 14:19:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394343 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 32E19E7D0A2 for ; Thu, 21 Sep 2023 19:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231176AbjIUTDH (ORCPT ); Thu, 21 Sep 2023 15:03:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230301AbjIUTCp (ORCPT ); Thu, 21 Sep 2023 15:02:45 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48F6978BD3 for ; Thu, 21 Sep 2023 10:34:07 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-405361bb9f7so8043875e9.2 for ; Thu, 21 Sep 2023 10:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317645; x=1695922445; 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=y5XZRvh5FJ3F9RXkqi8NbBrwtIOGm1RUjmAFGYn0SWM=; b=dVMUCSMgGxC5z7oixq+a8zo7o+eKw3Y45ona0T23qavK047/uXhvine3W2+FxJExmt iCO02xC0PPhr3GbD3msu7Qsah2Ygh73zsup2DieqoM3M+XRbsTp9E+O5ABtpNvuTqHOg mVPJHRWKJd+9uOgCj9wfjyhCVFxtCYHmwd3gL+jfRonTUUOHktFW3trySzQEN17XtS55 LZ8geKzcA8nIxTxwzDgNcwg2eEzUdUOQiDGf1w6Oy7SKaK4Weko3braUCOWP6rgoTVec CJ2da+kvv6zBJh+F7EMcb7Kw5HU6WIOwrFqES5ggSbjzXkxdC2d41D8S3raKnYLLtpFo iOHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317645; x=1695922445; 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=y5XZRvh5FJ3F9RXkqi8NbBrwtIOGm1RUjmAFGYn0SWM=; b=td4Sc7P5z03aXUe0VffLlH71Xq36+z71kX+OZ9SgVlGYgIyom6FaVA4vJ2DfCqpWXN uB2Ezbq5p3ZYpZ5DuZ2QHODl7UBwM2zhEPqIh6603+tdR7Sv8Bw9hi1Xhxy8cXvv1csJ xhzhi2xLJ8e+WKcJhNq6wA3KYnSc6gAUsA/BW/g0OgewlHPPW0DMwouEw+LBC7efmdhv Pbgp60jhPLAQznoOidKQDlFUfTFnDoLRmdhdzhK9npf3UildhHt1QtBsVjGWDxusvvj7 mipFYjjYFLltFQTUecqQ3U2fsACRKESVZpnk6By2E2nrVcc/Vtm1VMGO7YPKv7JSyn7U 6Xlw== X-Gm-Message-State: AOJu0YzgU78QA7ClMvIYgSbp9gss4sLG8qkDymhfSyadeTUtc29VdQBK WKBRxEGIaGT9DAIHN/Mssnw223rlTRauxLtAZj2sqoca X-Google-Smtp-Source: AGHT+IGc8rbAltPbhW/F+K8m0uCBqxxkmZHh/AgenqhR08Wj+pATxjfsKZe5oZaKwcnGW1CIGp0mkQ== X-Received: by 2002:adf:fd4f:0:b0:317:636b:fcb1 with SMTP id h15-20020adffd4f000000b00317636bfcb1mr5633352wrs.27.1695306151764; Thu, 21 Sep 2023 07:22:31 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:31 -0700 (PDT) From: David Lechner To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-staging@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Axel Haslam , Philip Molloy , David Lechner Subject: [PATCH 1/2] staging: iio: resolver: ad2s1210: add phase_lock_range attributes Date: Thu, 21 Sep 2023 09:19:28 -0500 Message-Id: <20230921141947.57784-3-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds new phase_lock_range and phase_lock_range_available attributes to the ad2s1210 resolver driver. These attributes allow the user to set the phase lock range bit in the control register to modify the behavior of the resolver to digital converter. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 71f0913b7e2e..f5b8b290e860 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -259,6 +259,60 @@ static ssize_t excitation_frequency_store(struct device *dev, return ret; } +static ssize_t phase_lock_range_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + int ret; + + mutex_lock(&st->lock); + ret = regmap_test_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_PHASE_LOCK_RANGE_44); + if (ret < 0) + goto error_ret; + + ret = sprintf(buf, "%d\n", ret ? 44 : 360); + +error_ret: + mutex_unlock(&st->lock); + return ret; +} + +static ssize_t phase_lock_range_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + u16 udata; + int ret; + + ret = kstrtou16(buf, 10, &udata); + if (ret < 0 || (udata != 44 && udata != 360)) + return -EINVAL; + + mutex_lock(&st->lock); + + ret = regmap_update_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_PHASE_LOCK_RANGE_44, + udata == 44 ? AD2S1210_PHASE_LOCK_RANGE_44 : 0); + if (ret < 0) + goto error_ret; + + ret = len; + +error_ret: + mutex_unlock(&st->lock); + return ret; +} + +static ssize_t phase_lock_range_available_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "44 360\n"); +} + /* read the fault register since last sample */ static ssize_t ad2s1210_show_fault(struct device *dev, struct device_attribute *attr, char *buf) @@ -506,6 +560,8 @@ static int ad2s1210_write_raw(struct iio_dev *indio_dev, } static IIO_DEVICE_ATTR_RW(excitation_frequency, 0); +static IIO_DEVICE_ATTR_RW(phase_lock_range, 0); +static IIO_DEVICE_ATTR_RO(phase_lock_range_available, 0); static IIO_DEVICE_ATTR(fault, 0644, ad2s1210_show_fault, ad2s1210_clear_fault, 0); @@ -552,6 +608,8 @@ static const struct iio_chan_spec ad2s1210_channels[] = { static struct attribute *ad2s1210_attributes[] = { &iio_dev_attr_excitation_frequency.dev_attr.attr, + &iio_dev_attr_phase_lock_range.dev_attr.attr, + &iio_dev_attr_phase_lock_range_available.dev_attr.attr, &iio_dev_attr_fault.dev_attr.attr, &iio_dev_attr_los_thrd.dev_attr.attr, &iio_dev_attr_dos_ovr_thrd.dev_attr.attr,