From patchwork Thu Sep 21 14:43:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5264949vqi; Thu, 21 Sep 2023 18:59:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZVc1bAVmJkjuz0Ro5ok2MrZJVMSBT4Q23Z9y4NDQoYppYlSaJArDz3ABW0KZmh7R9R4NB X-Received: by 2002:a67:fc43:0:b0:452:8e0e:9aff with SMTP id p3-20020a67fc43000000b004528e0e9affmr7820826vsq.2.1695347945567; Thu, 21 Sep 2023 18:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695347945; cv=none; d=google.com; s=arc-20160816; b=C8WX1mlG+JyneNNRI9iwF0w73bZp0j4GT26O9nGwodh/yVlNvxV53iVqflXWmJrWIB eWOSDfPExumL/SFJNk0bRQi3yrkxU4TOZxP0LaWFTBhKrzsPWWVFw41F6vIkk4Iot++w Ax/1xvxeArHhBJ5ZxdUb7x3lDLHc/x7nyxjcMzhzf54basYl71i7GZMK+q/t8ZduD0Gb Ri2rQBMoB0JotWY4P8iW3/n/UYLLZ+EWXPeVZ6eHW3YHQguKpRJZ5daKm2T+ra82d6sO TEDR+M5m4Pgj7pWJcxdXfUICtWKHclttgpDsN4IZ8UwrKar8iV3w2rFHKUjPFS6dvbXC gyMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SZXK6IdVBTSXcGTIHRUU/WhDyCqjH/rftizzn5sbxAE=; fh=C4qFzWBbU+iijlDhs/dktaO9OFebujDGzWZ9aaAuuew=; b=eJBpHGnKsCtH6WUwkhv2eU07LfritEdtdd5sfx79n7y4FDtCxKfyUlkWI86KkUdloI KgZLIFD/MVWgLIG7YEoglEzuygKQI/Rdkb2FNi5/1ZYtyd2EbCEcMTnH9Wa6tHOacLKN RDyIE1dH3H9I3sq87n0pA0zM4jKR23/q0cNvBD98zcw4bHaeDFtBKbk4N1cf0MHumHCw 6tJBYALspbd59Kwc/o3iPvnmWs484ds7yafP1gDzpGXlGiatD9Bp1HHZaARUXXNKo6bW zUAU5PhUTVrI5d7jLGvQ0+iAkHZxSsk/y+K5KSYVSqbbMRfjQ0d0vGesTmWuk6Oln+Jo /SKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=k1i4uBjT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id k33-20020a634b61000000b00578f23273a3si2767058pgl.738.2023.09.21.18.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 18:59:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=k1i4uBjT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E1BC484EAC72; Thu, 21 Sep 2023 13:34:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232031AbjIUUeM (ORCPT + 29 others); Thu, 21 Sep 2023 16:34:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232014AbjIUUdm (ORCPT ); Thu, 21 Sep 2023 16:33:42 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66F82266EA for ; Thu, 21 Sep 2023 10:32:32 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c01d22f332so28698751fa.0 for ; Thu, 21 Sep 2023 10:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317549; x=1695922349; 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=SZXK6IdVBTSXcGTIHRUU/WhDyCqjH/rftizzn5sbxAE=; b=k1i4uBjTloXGxXlLxo2zcwKsbn6RrrqAdMoTX9iZ7Cx7ZaOHg6WnbwC8mF4FmoDypf ZFOJIabFJgxhrMx/l5pCOg1Rxj700qsrVDLR2trikSx5Wqc6DXD30AyEMUY/4WOZm39h BnagZwFRmlK5RaIhfouTfu0peyGOlGqlN9qqb2sU67c3rd2ktpiFS1i8JxuJ9EWCYNv9 +hK/d5mMK4H9KS+o3ikUqlxKGgp/LTjevFQFeoTQoEfadvYR86FyHtIj+7Zz/JfIXyUL O0Um9KE9ZepIv0/FeCHYQ14GyxQl/rRmGhsU6tjKokgASXjRIhQVbbAe2jPaRyg7OTvf PI2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317549; x=1695922349; 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=SZXK6IdVBTSXcGTIHRUU/WhDyCqjH/rftizzn5sbxAE=; b=ps0Sm/Q1rTIee54D9URaUF1iLFMmiRCNb86WZmYdvBjnlDyA05W4ev/ApFHylknmHV 0UzD0OBHHmzlAHNOqg3DUyIgB5kpEeQjfc+lI73KT9TCDmjww2Ex52Al76N2lSzi1B7z ykSie/7Ayk/GMgAEDcgMDvVeEdqdcdjrg0nvIwU4U61UGAgfI7pO5WdEglf/5Kj0hVNn 1UF1i7vjll6DQPYr7dRk45xuayjUN3M8CBc5MlU0XX2nL5o/7L92VlmO4ya2m1/Zofgy 9oWbTJEzl7a6uxi3mAayb7VrE0Yxx/YViu3fA7Q0h+8tgWLLpdmBIkeV9Og3yR644NFF fihg== X-Gm-Message-State: AOJu0YyV3Y6jgMv9/xEuqan+7JyPHIA+RV4shXMtPkx+iHSuA6rIrdIG xM4yZiWO7Asd3wyLa7JGvmyK3enyUeNLRSJB0rv86/CJ X-Received: by 2002:a5d:4dc2:0:b0:320:968:f3b0 with SMTP id f2-20020a5d4dc2000000b003200968f3b0mr6330695wru.35.1695307453560; Thu, 21 Sep 2023 07:44:13 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:13 -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 , Apelete Seketeli Subject: [PATCH v2 01/19] dt-bindings: iio: resolver: add devicetree bindings for ad2s1210 Date: Thu, 21 Sep 2023 09:43:42 -0500 Message-Id: <20230921144400.62380-2-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:34:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777701167566909462 X-GMAIL-MSGID: 1777701167566909462 This adds new DeviceTree bindings for the Analog Devices, Inc. AD2S1210 resolver-to-digital converter. Co-developed-by: Apelete Seketeli Signed-off-by: Apelete Seketeli Signed-off-by: David Lechner Reviewed-by: Rob Herring --- v2 changes: * Add Co-developed-by: * Remove extraneous quotes on strings * Remove extraneous pipe on some multi-line descriptions .../bindings/iio/resolver/adi,ad2s1210.yaml | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/resolver/adi,ad2s1210.yaml diff --git a/Documentation/devicetree/bindings/iio/resolver/adi,ad2s1210.yaml b/Documentation/devicetree/bindings/iio/resolver/adi,ad2s1210.yaml new file mode 100644 index 000000000000..f55c9652cfb7 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/resolver/adi,ad2s1210.yaml @@ -0,0 +1,150 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/resolver/adi,ad2s1210.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD2S1210 Resolver-to-Digital Converter + +maintainers: + - Michael Hennerich + +description: | + The AD2S1210 is a complete 10-bit to 16-bit resolution tracking + resolver-to-digital converter, integrating an on-board programmable + sinusoidal oscillator that provides sine wave excitation for + resolvers. + + The AD2S1210 allows the user to read the angular position or the + angular velocity data directly from the parallel outputs or through + the serial interface. + + A1 A0 Result + 0 0 Normal mode - position output + 0 1 Normal mode - velocity output + 1 0 Reserved + 1 1 Configuration mode + + In normal mode, the resolution of the digital output is selected using + the RES0 and RES1 input pins. In configuration mode, the resolution is + selected by setting the RES0 and RES1 bits in the control register. + + RES1 RES0 Resolution (Bits) + 0 0 10 + 0 1 12 + 1 0 14 + 1 1 16 + + Note on SPI connections: The CS line on the AD2S1210 should hard-wired to + logic low and the WR/FSYNC line on the AD2S1210 should be connected to the + SPI CSn output of the SPI controller. + + Datasheet: + https://www.analog.com/media/en/technical-documentation/data-sheets/ad2s1210.pdf + +properties: + compatible: + const: adi,ad2s1210 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 25000000 + + spi-cpha: true + + clocks: + maxItems: 1 + description: External oscillator clock (CLKIN). + + reset-gpios: + description: + GPIO connected to the /RESET pin. As the line needs to be low for the + reset to be active, it should be configured as GPIO_ACTIVE_LOW. + maxItems: 1 + + sample-gpios: + description: + GPIO connected to the /SAMPLE pin. As the line needs to be low to trigger + a sample, it should be configured as GPIO_ACTIVE_LOW. + maxItems: 1 + + mode-gpios: + description: + GPIO lines connected to the A0 and A1 pins. These pins select the data + transfer mode. + minItems: 2 + maxItems: 2 + + resolution-gpios: + description: + GPIO lines connected to the RES0 and RES1 pins. These pins select the + resolution of the digital output. If omitted, it is assumed that the + RES0 and RES1 pins are hard-wired to match the assigned-resolution-bits + property. + minItems: 2 + maxItems: 2 + + fault-gpios: + description: + GPIO lines connected to the LOT and DOS pins. These pins combined indicate + the type of fault present, if any. As these pins a pulled low to indicate + a fault condition, they should be configured as GPIO_ACTIVE_LOW. + minItems: 2 + maxItems: 2 + + adi,fixed-mode: + description: + This is used to indicate the selected mode if A0 and A1 are hard-wired + instead of connected to GPIOS (i.e. mode-gpios is omitted). + $ref: /schemas/types.yaml#/definitions/string + enum: [config, velocity, position] + + assigned-resolution-bits: + description: + Resolution of the digital output required by the application. This + determines the precision of the angle and/or the maximum speed that can + be measured. If resolution-gpios is omitted, it is assumed that RES0 and + RES1 are hard-wired to match this value. + enum: [10, 12, 14, 16] + +required: + - compatible + - reg + - spi-cpha + - clocks + - sample-gpios + - assigned-resolution-bits + +oneOf: + - required: + - mode-gpios + - required: + - adi,fixed-mode + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include + + spi { + #address-cells = <1>; + #size-cells = <0>; + + resolver@0 { + compatible = "adi,ad2s1210"; + reg = <0>; + spi-max-frequency = <20000000>; + spi-cpha; + clocks = <&ext_osc>; + sample-gpios = <&gpio0 90 GPIO_ACTIVE_LOW>; + mode-gpios = <&gpio0 86 0>, <&gpio0 87 0>; + resolution-gpios = <&gpio0 88 0>, <&gpio0 89 0>; + assigned-resolution-bits = <16>; + }; + }; From patchwork Thu Sep 21 14:43:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143232 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5386224vqi; Fri, 22 Sep 2023 00:38:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfzJrpW5wPETd7WcdHRY6SC+loU07ZVAcV9QLINNs+vltocER9N3eBk4YP2r+EZypxD7sy X-Received: by 2002:a05:6a20:144c:b0:148:658a:a73d with SMTP id a12-20020a056a20144c00b00148658aa73dmr9177525pzi.5.1695368322402; Fri, 22 Sep 2023 00:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695368322; cv=none; d=google.com; s=arc-20160816; b=tMUTO1EbY0ah0eCAeV4Hl2HKs8VH+bIC2zWdGBKP0gnstwmnywsgKgZ48WMuGR03hU RZws31eM9C0UxbAeYH1YdWmqe9FSCrHsvmMXDaOG43BBMbwRXVK7pH6eWIkVVoK3IAi0 PuNrOo7/NX4rYJsm1cjjmSO51uGgyXPxAuTFrcFuNb+idz846gphEY9CtnX+9phhtxTT dLpSrwgX4lqlNfsvg1opK+/ZSTqAGfLG6JIj8E7+lIifxecQae+2+95JXJBg1R3NoHlX Hx6EUz98Gc/Nr88brOYIiZtQ5tXGkH3Ayaawh5xTHJiscuPNtVSg3kOErlSC2OnSvhvE a7BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dOWL8UFN0vGXrTIparX6s/KCVRR+pmZ6D/qH1lVsdWQ=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=c42yPEywzu5SNsINogN1yL6IFJ5QzQcLGy4PBD0/UNaEBxi8b0zARSZctJmcQ0JuZk qV0NOlQ4/Gjxza2S6mS383ZQ60fJsVV8V9w7bn18BTdZJjuX50RUln0EL82//CRnC0Us pDaAsf5q0XqBc50NaAuAYu8U7AaQR35PMXQRrNvnKkPWBXTtkTPtl+Y2TjXPiFqGYTer hbgZ88ZXzITce1mw4e5cag4sRWZ1mUt2MVbkd0kNFnS1w2wHLpmEdKdutdL4gWeIoEda QFr+T4kZ14s8wX16p/Amc8L3YdgKhKmNZ6QVcZpgeKC7rqTJQge5dT1v1PDv9np2bmig ekAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=t41sic2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id s11-20020a170902ea0b00b001c36705bce1si3372754plg.474.2023.09.22.00.38.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:38:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=t41sic2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DF8FD83328CC; Thu, 21 Sep 2023 13:47:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232260AbjIUUrX (ORCPT + 29 others); Thu, 21 Sep 2023 16:47:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231653AbjIUUrD (ORCPT ); Thu, 21 Sep 2023 16:47:03 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7CB356D31 for ; Thu, 21 Sep 2023 10:28:17 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id a640c23a62f3a-9ae22bf33a0so529594666b.0 for ; Thu, 21 Sep 2023 10:28:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317295; x=1695922095; 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=dOWL8UFN0vGXrTIparX6s/KCVRR+pmZ6D/qH1lVsdWQ=; b=t41sic2vSUatU0Dgg6ZF67xbNGnoLEJKP1R7JWFu7gtuFJmf+/emAPIsdfPlZUALvf xbrywqbmKcygEGqwBcc2iSO4Jko7YfPV1u107sNo0ccDotEkoDKXL2hLftUENZ54Ts7Q suK8I3QYLhTEAtt1UHi/+4WCebeoKYJWvldYC4QZxr5nJvI5DQNRDU14yLpE63aS4qj/ dehy2UN8YJwDzv57GJvrjJLLCblrtMOwTVzzI5pQpJsRLBKGWZ5w5oE5z91FMBR8g+vz CDgB26u8pLawbodtMwHs22QwhKmQi9tZWkrt/ADRK34U5mIOaW0+esplsX/Ar443FbtM GFFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317295; x=1695922095; 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=dOWL8UFN0vGXrTIparX6s/KCVRR+pmZ6D/qH1lVsdWQ=; b=iWxMLO7n0OOTw4VY1zz0LhL6RtJpwaewMMaomK/8p5nVMYMHXyIO9gcWdjYsBdM8B9 WwuftL5m9y5v4h2mvEzOCOKA9wj6lcMJnamNOwu5m1lEoafD0nBznskvk695gs1TU2WC cWf57/2PcKW1A5e69+r8TzYu8aQSG9FjErtbVEtkHpkq/PoNKOtFwXAw6xs1+hxlNiHH 7mU1GIXnr2OJ+2JVKzXbRB/uVK+TZ7ZvaU4W9vzhu/RhbnMVSRqocWn9yVbDKyeyRamw aaAVB+V/3BtkLO2B93Z0ZC0JhYCVzP38bHGlAK0lQym2+YogsPX6IeRQuW5x8/L8J3oD PK4A== X-Gm-Message-State: AOJu0YxrfCPmEUGzs6PTaPchCSx8HO9gNV/mmOGljvKZDOJuX9IeNvIk 3EJtTZlmquPcdGjTKagGeHnuaUC3QjaBfMreDtzyl6MsuqY= X-Received: by 2002:a05:600c:3789:b0:3fb:c075:b308 with SMTP id o9-20020a05600c378900b003fbc075b308mr4598413wmr.12.1695307454403; Thu, 21 Sep 2023 07:44:14 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:14 -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 v2 02/19] staging: iio: Documentation: document IIO resolver AD2S1210 sysfs attributes Date: Thu, 21 Sep 2023 09:43:43 -0500 Message-Id: <20230921144400.62380-3-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:47:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777722533751583976 X-GMAIL-MSGID: 1777722533751583976 This adds documentation for the device-specific sysfs attributes of the iio/resolver/ad2s1210 driver. Signed-off-by: David Lechner --- .../sysfs-bus-iio-resolver-ad2s1210 | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 drivers/staging/iio/Documentation/sysfs-bus-iio-resolver-ad2s1210 diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-resolver-ad2s1210 b/drivers/staging/iio/Documentation/sysfs-bus-iio-resolver-ad2s1210 new file mode 100644 index 000000000000..32890c85168e --- /dev/null +++ b/drivers/staging/iio/Documentation/sysfs-bus-iio-resolver-ad2s1210 @@ -0,0 +1,109 @@ +What: /sys/bus/iio/devices/iio:deviceX/dos_mis_thrd +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Degradation of Signal Mismatch + Threshold value. Writing sets the value. Valid values are 0 (0V) + to 127 (4.826V). To convert the value to volts, multiply by + 0.038. + +What: /sys/bus/iio/devices/iio:deviceX/dos_ovr_thrd +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Degradation of Signal Overrange + Threshold value. Writing sets the value. Valid values are 0 (0V) + to 127 (4.826V). To convert the value to volts, multiply by + 0.038. + +What: /sys/bus/iio/devices/iio:deviceX/dos_rst_max_thrd +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Degradation of Signal Reset Maximum + Threshold value. Writing sets the value. Valid values are 0 (0V) + to 127 (4.826V). To convert the value to volts, multiply by + 0.038. + +What: /sys/bus/iio/devices/iio:deviceX/dos_rst_min_thrd +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Degradation of Signal Reset Minimum + Threshold value. Writing sets the value. Valid values are 0 (0V) + to 127 (4.826V). To convert the value to volts, multiply by + 0.038. + +What: /sys/bus/iio/devices/iio:deviceX/fault +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns a hex value containing the fault bit flags. + + Bit Description + --- ----------- + D7 Sine/cosine inputs clipped + D6 Sine/cosine inputs below LOS threshold + D5 Sine/cosine inputs exceed DOS overrange threshold + D4 Sine/cosine inputs exceed DOS mismatch threshold + D3 Tracking error exceeds LOT threshold + D2 Velocity exceeds maximum tracking rate + D1 Phase error exceeds phase lock range + D0 Configuration parity error + + Writing any value will clear any fault conditions. + +What: /sys/bus/iio/devices/iio:deviceX/excitation_frequency +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Excitation Frequency in Hz. Writing + sets the Excitation Frequency and performs a software reset on + the device to apply the change. Valid values are 2000 (2kHz) to + 20000 (20kHz). + +What: /sys/bus/iio/devices/iio:deviceX/los_thrd +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Loss of Signal Reset Threshold + value. Writing sets the value. Valid values are 0 (0V) to + 127 (4.826V). To convert the value to volts, multiply by 0.038. + +What: /sys/bus/iio/devices/iio:deviceX/lot_high_thrd +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Loss of Position Tracking Detection + High Threshold value. Writing sets the value. Valid values are + 0 (0 deg) to 127 (9/18/45 deg). The interpretation of the value + depends on the selected resolution. To convert the value to + degrees, multiply by 0.35 for 10-bit resolution, multiply by + 0.14 for 12-bit resolution or multiply by 0.09 for 14 and 16-bit + resolution. + +What: /sys/bus/iio/devices/iio:deviceX/lot_low_thrd +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Loss of Position Tracking Detection + Low Threshold value. Writing sets the value. Valid values are + 0 (0 deg) to 127 (9/18/45 deg). The interpretation of the value + depends on the selected resolution. To convert the value to + degrees, multiply by 0.35 for 10-bit resolution, multiply by + 0.14 for 12-bit resolution or multiply by 0.09 for 14 and 16-bit + resolution. + +What: /sys/bus/iio/devices/iio:deviceX/phase_lock_range +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the current Phase lock range in degrees. Writing + sets the value in the configuration register. + +What: /sys/bus/iio/devices/iio:deviceX/phase_lock_range_available +KernelVersion: 6.7 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns the possible values for the phase_lock_range + attribute, namely 44 and 360. From patchwork Thu Sep 21 14:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 142992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5192772vqi; Thu, 21 Sep 2023 16:01:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYRGJevK43eAI0I7K11umjESYoMroHvMjaxD79Y9scgFVVFeNSqa5PjY2aTLDYwvw54sM/ X-Received: by 2002:a05:6a00:a1b:b0:68f:dfda:1814 with SMTP id p27-20020a056a000a1b00b0068fdfda1814mr7622986pfh.18.1695337298953; Thu, 21 Sep 2023 16:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695337298; cv=none; d=google.com; s=arc-20160816; b=mKYG6+0BSsND/w/7WngSKocA5koPIY+iuxNMVYiXf087J27/dpOQ4yQ4IRCacqJdj1 pmvBmGf39P0KfdiWt9NRy0aq3uiuB6E4Z4HZrsCXY9UmDLtCTarfqrbVuzdsH9EtBQsy QOqZyJZozpeN9JvTdZRFreyIO+3SeRkO/kRGD9vz4nfjxNoDCOxjoow7JSI/RQ7VtzMQ a08lzC6U4zkvt27hlqVesaDKBFa3oUFkBCGlaxZgjpuM67S+XYST0J/kz7opW5Zaj0uO 2Q4ZKV2E5CYc8+ZZM2ADBVbkfoqN9rzsXwmWCfHRTD6iUu3716fNILSiyfdErGwsE0Bu ItiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NWszhBlTWMiwkXqgF1w4h8oNmYkV0xe9wPBMJvnXBgI=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=GxKKJFqgX03V09uHAc3JAzB+3j7OY+9uun2eTEROg2m6zyY3jQGinlB9aCWKJSZ90O nAbiY+0Z7FlY9Fjp49zTrw7uz7bTCBns0woT2lcK246+deciPylhYo6RF/JgYrEQlqp9 Qmkqat1uWsH1jtY7avZ6emPz6QclkDB7fDx8v62K7VPRL/DQL3EMFQT2H3C6qWSI2IKW FbxTrDxI5E97tApRiEe7I2OBOjG1fijQCBzzO6aOOo8eTNSDDoOxpoZWAyhsEgeosf1Y 2cTvI69l/FtRxHCrweI09RUW3yJjeCP36wdeHSx0T2mfgvO+rYDrw/b5J7wl6gCd5PLk PYuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=QBLXTUv2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s132-20020a63778a000000b0057822296958si2501989pgc.127.2023.09.21.16.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 16:01:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=QBLXTUv2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DF997828952C; Thu, 21 Sep 2023 11:54:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbjIUSxz (ORCPT + 28 others); Thu, 21 Sep 2023 14:53:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbjIUSxV (ORCPT ); Thu, 21 Sep 2023 14:53:21 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F240900ED for ; Thu, 21 Sep 2023 10:46:27 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-50317080342so2226823e87.2 for ; Thu, 21 Sep 2023 10:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318385; x=1695923185; 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=NWszhBlTWMiwkXqgF1w4h8oNmYkV0xe9wPBMJvnXBgI=; b=QBLXTUv2w46Huf/WDJ3zyFzZ1LM/+FazknkYHKDSibQkMof8TcpZ69Cz7x8g9R0ifu vX5xnIjCuKDkRxGcdaAonCNJBJkY9LGlIZJ7mHQ71Z296130lHkEJ0fmi+2IAdSzWptz s8sQltIvy6G5tbj796Bpt/72torA2+qea5Is/NKnpmLDir/TlOBjiSxhuWwMs3OAKTnV 0x4LLbzcKeVP9XHqurIkwGAG0EtIDagQA+ZCjfAR9DvVfFBjy8svcL9cH+v9ikW4815O 4F+67Z9XgGebtD6KIGikm2wIYX7rT15Uqx7pVcQuo8twWtQT72/Y7nVWXat4hpH9um9t Uf8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318385; x=1695923185; 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=NWszhBlTWMiwkXqgF1w4h8oNmYkV0xe9wPBMJvnXBgI=; b=niy8a5KYNohQ8xV5Y7VXwHsljiKVyy6AkbPRaLQm8fA/o9NU8QB26wRu2wADUHr0Ue b2K+wPRWNZ1RorXkQEQB8tS8DhAcryev1aYOTi7z62xjj49zon+3Ey0COOF5PjGXdfe4 ve7Hq2PtvKZQQcbf7ahnMn2lxrtfpx0e4UER+mZKhho7xYRuN0sxhvAKhGpWlcF6ErJH YDaZctoK+lBjvYwapSeUtef26UTwdk5It+8w1U6MEem7XXPDkpNtSv7c1m0AqjW5oUIf HoHzGKVfD1PQTSomWeiO8j8LTEoaPeNY6TnBJ5o3+4nKmI+NeSdEEcb+cojo0bXng+8R n68w== X-Gm-Message-State: AOJu0Yw5pM6VQgpvc4lWYn2TtTCg0TPoNSxlPMNFdmSW4s0hX1jri/+q QaK6eH+UlVBCQeNSfoxfuQdS5LN0jAboQZMOEaoW6NwK X-Received: by 2002:a05:600c:ad4:b0:3f9:b430:199b with SMTP id c20-20020a05600c0ad400b003f9b430199bmr5382212wmr.15.1695307455234; Thu, 21 Sep 2023 07:44:15 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:14 -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 v2 03/19] staging: iio: resolver: ad2s1210: fix ad2s1210_show_fault Date: Thu, 21 Sep 2023 09:43:44 -0500 Message-Id: <20230921144400.62380-4-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 11:54:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777690003394324237 X-GMAIL-MSGID: 1777690003394324237 When reading the fault attribute, an empty string was printed if the fault register value was non-zero. This is fixed by checking that the return value is less than zero instead of not zero. Also always print two hex digits while we are touching this line. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 06de5823eb8e..84743e31261a 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -393,7 +393,7 @@ static ssize_t ad2s1210_show_fault(struct device *dev, ret = ad2s1210_config_read(st, AD2S1210_REG_FAULT); mutex_unlock(&st->lock); - return ret ? ret : sprintf(buf, "0x%x\n", ret); + return (ret < 0) ? ret : sprintf(buf, "0x%02x\n", ret); } static ssize_t ad2s1210_clear_fault(struct device *dev, From patchwork Thu Sep 21 14:43:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5235199vqi; Thu, 21 Sep 2023 17:39:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWv2xucktKfMr7YfmijNkrFs30jtFmf3ksPhuSQ5NLeqjB9Qn88dbicKuQV5zIG8V/8ae/ X-Received: by 2002:a05:6870:d24f:b0:1c8:b870:4e62 with SMTP id h15-20020a056870d24f00b001c8b8704e62mr7513850oac.52.1695343183124; Thu, 21 Sep 2023 17:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695343183; cv=none; d=google.com; s=arc-20160816; b=QbTCLsUv0K5TDKgJ2rLlgoiK1R8WjEunWwGUU+aQR0HXxk/ab2VLoXex+58RShWirr Bq3OMqRz7hEya5Hm3QyZcR7sDvDfOdVenQ5f8cGJKe/quzs2210acDKw2ZMJ/OY0j6kG DSgSf63BPTVaBcnC0yDr6HqjTq6oiCPOeNGNPNhCW973OOctL4xAF3aMJkiSIRxDXweu B/9kYJcKHP2jXyMGXp3DuxJW9L1z6Q7mqRqaqQ7vpzV3xREr6rTbOtH0JBv1H0okfECA hCZdadwNmJptgKlicVmOsxDmTOc3o+6fhoYfD4d+YB86+79KoXCHKF8c5+PLuV90lLSf QOow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=x9YCZ78k5Zg5KKitr5PpHsZw/Rz0qYyLXQR2L135bIs=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=m7P4jY90GT+ceW1N/WGD6JHtGhwUH7VbWvmmbMdWxTVYKa3TL/NKmLqkC7bjVGXyNQ VQBbXnDFzSPivXvcvgzAv/7pQ14bv7Z9GageNQ5Hus2pJweq4THm1A3X/K1GOn22sNpa Fu0zj0tcfexL/6vgk9yDhe8chgPHA0ejReQdAxiW9+wcX3G4w4O6opyLwFq3LsbtIX9P Hyb6U6blpFQFMkMjD8KMwmOsj4ADpwBE3fmzE7K6eMSie6dTSXR3aQoOgatmYD/iyjt7 PgApjywIl9xUEfKnYJg7skYsPk48ajnWwTAymyfqfRe5PgekJUEbZAA2Lrw6Zt42YMI/ PEOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="TZ/cVj3B"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id e62-20020a636941000000b00578b26be643si2443036pgc.606.2023.09.21.17.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:39:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="TZ/cVj3B"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 382F4808BE42; Thu, 21 Sep 2023 13:45:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232023AbjIUUeS (ORCPT + 29 others); Thu, 21 Sep 2023 16:34:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232010AbjIUUdz (ORCPT ); Thu, 21 Sep 2023 16:33:55 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 708778DEC2 for ; Thu, 21 Sep 2023 10:44:05 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31427ddd3fbso1230014f8f.0 for ; Thu, 21 Sep 2023 10:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318244; x=1695923044; 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=x9YCZ78k5Zg5KKitr5PpHsZw/Rz0qYyLXQR2L135bIs=; b=TZ/cVj3BtM2LyOm9DpFOV7gOkoRa7TUkjblhakk106DhTxxjy3BOMUnnp2BEhtbsEg yLi7vpgkforM2Eb90Si9ejD/U4TvG+0z8iXs1EwASpE3LiChVwBjnuxj7sic1FJjOpV1 LPb2lH06pQPBtV4YgChseIROWsvlA6ghUAG1MWc2lEwNLgu+AZGm4bxRv4kuhIpVt00a ab5Kelj7CGdHMUEpRtMmJUgr0kquoJuWAMGsBi3fF7B+qawt/C4hrDv803FPHIi3poU3 CSzAF01rLePGAVUQhqXk5hQlrlhoa8Ot5XVxrTi8rhWWFuu3A6WybJ4qWQ5/jp/UQmhq c6vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318244; x=1695923044; 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=x9YCZ78k5Zg5KKitr5PpHsZw/Rz0qYyLXQR2L135bIs=; b=wpMRC+ab7Dma+HweglXr3ZGq1yMF0z3jMvM3IqlKEyeiUXNObiJqh1xny63N3AeX9d 61qN1WzaD1Tj1r6rqwuV1Gkz44nMseljVo+RLrkESvsZZ+ClHvYsMmfAb9NNfErLvqzx vLkVP8i9t8NUWYWlbUuQJY6f1vfM75TB3zJslpA5fu69GWD2MZHInX0mEDSsefPgKWyd QRmzGP/hcoko31dgSkLl4rMxGA7qcuAep4VuVByIDDFHUjdQsWd4meJv+o6k8K/jKfU6 +9iGGNxcReUFZGCbV3N19c7MxUJn+T5GHou/8DzbRt5dv5W/j3wT2sRSqfz0lQWKV5q/ mpsw== X-Gm-Message-State: AOJu0YxwNn+BT47c6g6jyDlff8JwRwWb9TFzMxMG9z8jWn49NWy/MZ6S ftmw6OdNFPj+2ejv451yaWC5uwaRvnBp5psQRlZoj/6f X-Received: by 2002:a05:600c:ce:b0:401:d2cb:e6f2 with SMTP id u14-20020a05600c00ce00b00401d2cbe6f2mr5107214wmm.32.1695307456325; Thu, 21 Sep 2023 07:44:16 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:16 -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 v2 04/19] staging: iio: resolver: ad2s1210: fix not restoring sample gpio in channel read Date: Thu, 21 Sep 2023 09:43:45 -0500 Message-Id: <20230921144400.62380-5-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:45:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777696173807263323 X-GMAIL-MSGID: 1777696173807263323 In theory, this code path should not be reachable because of the previous switch statement. But just in case we should make sure we are restoring the SAMPLE gpio to its original state before returning in addition to releasing the mutex lock. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 84743e31261a..0bdd5a30d45d 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -510,8 +510,8 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, ret = IIO_VAL_INT; break; default: - mutex_unlock(&st->lock); - return -EINVAL; + ret = -EINVAL; + break; } error_ret: From patchwork Thu Sep 21 14:43:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 142958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5176491vqi; Thu, 21 Sep 2023 15:24:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/Exv0jqAE8g0D8tmJQDTuwh2G/IE77PSVz5hIj6PQx04OpouJHHs1XAgviIFf2Tt4ax+9 X-Received: by 2002:a05:6a00:2389:b0:68a:59c6:c0a6 with SMTP id f9-20020a056a00238900b0068a59c6c0a6mr8161968pfc.24.1695335047165; Thu, 21 Sep 2023 15:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695335047; cv=none; d=google.com; s=arc-20160816; b=Q2pq/mVkwgaXcF4JGIPlXhf9PoqEktXZN/Me7RQy5yWyif5KpuPdjvNlQ6Neqx65l0 xY+HApO2HkvZ8qQsz2TiMSOoKmKEmUNhEy1SlqB1b6tZ0ir2eNRTLrP+7OozqMsBoXR6 eE2IDd8QucJkXDbq3XAw5rSv4R1gG1AvQIgnCG+gGGNn4lpyV3Ba71WInhMFiTP2OCA3 wEW2oxsC1/6oYija8IxzXHCc8SP0U01fcNwPA59wFbGXpEsvcS877oa1AFuWtSzfYEs9 7y3iC03y5QKivVpWZjMKRCEwKuhzEuf6QDx3fWij6wll6Akyblt3dMBRntTC7ug9wXtf LwfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NC6Tj/wZ71OdWmHfRNe2x49Rd8CoFCC05cRR7nhn858=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=akNgfPnLvp6XNjZU21lh7zGzi5Jpr0E9MNNO52amLy4oZC0dvtUbvAsXoKFF8Nbc/8 lL35odQp+x5AXoMfjie6pBViB1Hc/pG0gQoW7p6oAP2XyReyaiZTY9ldQhVlKRzwe+mZ dfjIQDcubePLMYxv35ZGRlwhEvQHrlk6rzBJ7wRa6WbIcCBRyLftYAcpykq9epOEQIYl EgwbmXasMX8LcDj43oV/+QFyYIT7up7Tujyyy5xX4GwPHKzES0sDDS/t4c3zNmihaV+5 IMu/B81NApeeqpIJOUiKMNtHAsLfq70sYc2DoMfjefvY4uBHCq2ffHLjsMHvC6zAuN5u z9eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=xfyEMLZ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id z16-20020a656650000000b0057808a9b0besi2085160pgv.664.2023.09.21.15.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:24:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=xfyEMLZ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A22758063009; Thu, 21 Sep 2023 13:50:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbjIUUuF (ORCPT + 29 others); Thu, 21 Sep 2023 16:50:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232518AbjIUUta (ORCPT ); Thu, 21 Sep 2023 16:49:30 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F393D88AE6 for ; Thu, 21 Sep 2023 10:39:24 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-52f3ba561d9so2621244a12.1 for ; Thu, 21 Sep 2023 10:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317963; x=1695922763; 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=NC6Tj/wZ71OdWmHfRNe2x49Rd8CoFCC05cRR7nhn858=; b=xfyEMLZ9nPlOSFp7g01Ba29mZS7fnL34InjOc1pS+FYWsmjlJ4Sq9T715W+NAA1jNq 7gzsKyK1OdCTeRL1C7yyZDtm52/pA04ZB2v2l6QAlJAcDzR0qD8bFHJX0VBFWvx9IBIS PvXSwuVCXmGdcx2bWyCzJjz1yP4mHwPkadmjWb0bEUGgl6f2KdEaaFwwIV8hAGvvxMtU F6UtxET1JDqkWhGsW3Jw0MNWhkh4VCJoKJ0EzWqlRYaGHMCVyAS4w3OpHW/w15Q8R4Fp A+sLWNZxZjzVGBKlIUjzkHbVpa84D1QmI6Y0kKzNdWUB4aDHrVksBhHx1wYuhiKJOc3e JcMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317963; x=1695922763; 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=NC6Tj/wZ71OdWmHfRNe2x49Rd8CoFCC05cRR7nhn858=; b=kV7XN2yKcL15M69Jp3I2FrTd8l7VT3LTvUSKfatC/HsdyN4GBbjP/Z+NCbwaR/7JP9 4SfJ0D05BuzCxedC3rkz0b+d5S+fdxuo0daUtknyYQVFrEt0/Jq7A3BXguzPY30njie+ u7885HyJ807DzZfuZ8jXv6sNzuMBWS+rloE5noz+Cf4ZHp90d4J1XUNLGnnNDcAixJJj F/NS18UExr3KViMOsA8pva3Cw9iCeQBJjsdFpU9TtnniGLz4RBQW50/D0gctfuLh3zVo nb9/GsH3zHRJOpOovYtzzBT1czcQ7kbwd0FCu94M1zFwQaXph8Vq8ZQMeBp3H1HS6Xht aePQ== X-Gm-Message-State: AOJu0YzFBgr6ynBSFx+ZTC4sPgLbMaRU+bDr9fSSQxmSdGgzPEttSxiO kkkOz5ddJ2sYOeGAIExNzHLBdhy64+nExm8jYGinlur0 X-Received: by 2002:a05:600c:3789:b0:3fb:c075:b308 with SMTP id o9-20020a05600c378900b003fbc075b308mr4598503wmr.12.1695307457067; Thu, 21 Sep 2023 07:44:17 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:16 -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 v2 05/19] staging: iio: resolver: ad2s1210: fix probe Date: Thu, 21 Sep 2023 09:43:46 -0500 Message-Id: <20230921144400.62380-6-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:50:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777687642145359792 X-GMAIL-MSGID: 1777687642145359792 This fixes a number of issues in the ad2s1210_probe() function: - Move call to ad2s1210_setup_gpios() after `st->sdev = spi;`. This fixes use of this pointer before it is initialized. - Check return value on ad2s1210_initial(). - Move devm_iio_device_register() to the end to avoid race of registering before fully initialized. - Remove call to spi_setup(). Note: MODE_3 was incorrect, it should be MODE_1 but we can let the device tree select this. - Change default value for fclkin. This is an external oscillator, not the SPI bus clock. (Will use device tree to get the correct value in a future patch. For now, using the eval board value.) - Remove spi_set_drvdata(). Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 0bdd5a30d45d..9c7f76114360 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -3,6 +3,7 @@ * ad2s1210.c support for the ADI Resolver to Digital Converters: AD2S1210 * * Copyright (c) 2010-2010 Analog Devices Inc. + * Copyright (C) 2023 BayLibre, SAS */ #include #include @@ -657,12 +658,8 @@ static int ad2s1210_probe(struct spi_device *spi) indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; - st = iio_priv(indio_dev); - ret = ad2s1210_setup_gpios(st); - if (ret < 0) - return ret; - spi_set_drvdata(spi, indio_dev); + st = iio_priv(indio_dev); mutex_init(&st->lock); st->sdev = spi; @@ -671,22 +668,25 @@ static int ad2s1210_probe(struct spi_device *spi) st->resolution = 12; st->fexcit = AD2S1210_DEF_EXCIT; + ret = ad2s1210_setup_clocks(st); + if (ret < 0) + return ret; + + ret = ad2s1210_setup_gpios(st); + if (ret < 0) + return ret; + + ret = ad2s1210_initial(st); + if (ret < 0) + return ret; + indio_dev->info = &ad2s1210_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = ad2s1210_channels; indio_dev->num_channels = ARRAY_SIZE(ad2s1210_channels); indio_dev->name = spi_get_device_id(spi)->name; - ret = devm_iio_device_register(&spi->dev, indio_dev); - if (ret) - return ret; - - st->fclkin = spi->max_speed_hz; - spi->mode = SPI_MODE_3; - spi_setup(spi); - ad2s1210_initial(st); - - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct of_device_id ad2s1210_of_match[] = { From patchwork Thu Sep 21 14:43:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5225553vqi; Thu, 21 Sep 2023 17:15:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHue1QfvjF9+oFI47cOsZxjvwlOWCCRL10d3xH6GBu9ThW7/2JFbVhVhykyaTChzov3W9jY X-Received: by 2002:a05:6a21:1a0:b0:14c:d494:77d1 with SMTP id le32-20020a056a2101a000b0014cd49477d1mr8486686pzb.10.1695341754377; Thu, 21 Sep 2023 17:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695341754; cv=none; d=google.com; s=arc-20160816; b=A+WJxdXRDIwWPzyIEzPcjliXyUbObTH0L1XERsfEif1jstsiHywR6/CRmhjTz6iA3d 7b9WQQjV4gcG9MRZGmCR8vWUx0Z1Up1Oi8ZUCO1RQtzfqGHQQOn3hNM0JLEQR4A4nt72 c59CpL12+28jRdGbrpEH7rEv/D5ltQ/qA1xyBuHNdt34UUAuFJaLYlwzpMVoyz9qGgnz yZRCXEi3SNWB/z2pErZaiixRp+i9lbnk9CqIG3U5ZbhqVDxfxfb2POSOQIQvcqVZg7O5 UfKpTn18p96EX3P6jswd47oxOa1z3+6n1zqTNBh7OuLtHdfr97D09Q/UDPXLtUxyaMKw tgDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gabiCx8aQ+iMVEJft2DL0LHbd3RWq71VIbUUi+w3JfM=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=vsOOBChIQec3A3QD+8/yxhQTIU1N5zJKB868nNVb3klWlWmYf4QSehgmDh07FjPP6O JruqyZD38IjRwfWGT5x7Pe6T5VmClPmfnCWtDPhKNCUzKmyo2cE2sJPP0qibXumLMTqJ HjJQYfVY9nWoFzkLWeeGD5FDrvmYXfl7r3tLTQCkWrGmHHHXbMWgU2j8k5jscETdigIX SvYG3IjbsPRKIb7OVvwtLCSLewWJgCu0dyzgabpnd4PVvcjSzBKWPAzh4Xuv7EOScC6f HrmafVif9nNJVlQ8COeVYauRsb3pIjzvcWBXgzA0zJl6JkwOMI9PJZmKmNboR8pYhLJ8 od0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=xGCIO8Gh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e20-20020a170902f1d400b001c5bfe458a1si2397497plc.356.2023.09.21.17.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:15:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=xGCIO8Gh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 14DBE82E3C75; Thu, 21 Sep 2023 13:02:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231442AbjIUUCV (ORCPT + 28 others); Thu, 21 Sep 2023 16:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231298AbjIUUB5 (ORCPT ); Thu, 21 Sep 2023 16:01:57 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D91F5FF9 for ; Thu, 21 Sep 2023 10:26:33 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-99bf3f59905so150335966b.3 for ; Thu, 21 Sep 2023 10:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317188; x=1695921988; 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=gabiCx8aQ+iMVEJft2DL0LHbd3RWq71VIbUUi+w3JfM=; b=xGCIO8GhGgIu/zVimnGMfMtEq8vXj6YV7MglFnLBjjEy+vrm7BbFLBNjze1YKeDKf+ KlD+eoNmLbpjQF/va/d3Wp594g3RAECBD2CIZa8eTLxHCD1hwRZd8iXF8JS+gtzqTis9 O38GMxhr9+xlZQ6ZY2bPa57WSAUdXx4SWVwk9ryaJtgtfk3m66KxnCQZwV8Pve97rSDc py3GGM95HQ5lxcyVJ9F1VVI9l6s/gY735I5ZdgAnZBERZzsL2JdMuy7kKKR+09Bw1Ohn wHrLKoIToQ4jXEW318iH5Kh49egtk1b76piDtoWkntSNjVxZJinjBfDPtO6S8PNnkD7w mXIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317188; x=1695921988; 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=gabiCx8aQ+iMVEJft2DL0LHbd3RWq71VIbUUi+w3JfM=; b=uTlkcmhjJQCXpmcahfAWopdTp1uvWvVVQTS1obXp4bmW1wFNRlPUG6BGQVjuEZNVKV Uq/YPvl77QWZt6jHMcihBKB5Q5yag/fE+0R0F+Nz4t+iwrtsp0aZ17L08/8kCWS8gZke pdJBLzSSCbgJB+cssi6AYjn8aMnkHncu0WMtdhzT00wMxMX8yN740LBqIm1gDoUiUC4A UoWtz8kn+jsHFPvp87zdbbZwP3NnJn8WLEBx5MZSdOCpR69r4d3/yELdh3BZzhZUBMbE Ky9ejbmv5ZdZoPN8ScicUF7dPHzY8JLjEgfi5JM2IFRgV/v18+9O37EAE4qN0C9sdaTt VCdw== X-Gm-Message-State: AOJu0Yx8LSJbPIUNK1gyTbO3LnObsQffSssAGuFoKa4UhONE8rGBpiHH AqML9B94hleA48TTK5CQZ4WQbLUWz8LO8CArp6O7xl1a X-Received: by 2002:a05:600c:ad4:b0:3f9:b430:199b with SMTP id c20-20020a05600c0ad400b003f9b430199bmr5382331wmr.15.1695307457930; Thu, 21 Sep 2023 07:44:17 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:17 -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 v2 06/19] staging: iio: resolver: ad2s1210: always use 16-bit value for raw read Date: Thu, 21 Sep 2023 09:43:47 -0500 Message-Id: <20230921144400.62380-7-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:02:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777694675393664732 X-GMAIL-MSGID: 1777694675393664732 This removes the special handling for resolutions lower than 16 bits. This will allow us to use a fixed scale independent of the resolution. Also, for the record, according to the datasheet, the logic for the special handling based on hysteresis that was removed was incorrect. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 9c7f76114360..985b8fecd65a 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -465,10 +465,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, long m) { struct ad2s1210_state *st = iio_priv(indio_dev); - u16 negative; int ret = 0; - u16 pos; - s16 vel; mutex_lock(&st->lock); gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); @@ -494,20 +491,11 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, switch (chan->type) { case IIO_ANGL: - pos = be16_to_cpup((__be16 *)st->rx); - if (st->hysteresis) - pos >>= 16 - st->resolution; - *val = pos; + *val = be16_to_cpup((__be16 *)st->rx); ret = IIO_VAL_INT; break; case IIO_ANGL_VEL: - vel = be16_to_cpup((__be16 *)st->rx); - vel >>= 16 - st->resolution; - if (vel & 0x8000) { - negative = (0xffff >> st->resolution) << st->resolution; - vel |= negative; - } - *val = vel; + *val = (s16)be16_to_cpup((__be16 *)st->rx); ret = IIO_VAL_INT; break; default: From patchwork Thu Sep 21 14:43:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5323627vqi; Thu, 21 Sep 2023 21:50:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1DX5/KldAOhLU+L5SMpB8M9F3GgHzasUlanJh5xWlGCTi2UoE3bg2WIttUbTl8FgpCgJr X-Received: by 2002:a05:6a20:4303:b0:15c:8555:a21c with SMTP id h3-20020a056a20430300b0015c8555a21cmr2563280pzk.8.1695358228610; Thu, 21 Sep 2023 21:50:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695358228; cv=none; d=google.com; s=arc-20160816; b=lC/W7GPtH8x9YWp1tVF0p0mr9l0W/PIW0kINaEIQ4zqd59U4aH+psihWdcd0Z9yZ4i lNOdAKPURH2y5bRRwnusnLpf0OlBaI22pnNgwCF5C52OybwpSMC9hfvTiSefU2cnf3Mg cx5f8L0FzCUJRRGtLqidaV7/wSBJSyaRyYIuOQk7hnG5F25ZaKuXxYVENKTEibOm4+GT jiR393orINoXhymYBCB2XLkwxOE2LWtqydN2VFu7wff6UC6Y8r5fiSAS1IBlvbpqNJUx caEnywgXaoWuSfkAftDeY7n10Dc2bANeicqmWuGHKYLdGQ/XKY+pQGg6QIN6Q4fmLm4d FVPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8xPn0fJb1G79vmQneRtFHd9riwOuPrJO1tNQT+KG0zw=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=FpwBn20y49bYCieA5AiF5Agm1VytgyDuZyMl0FitnP1GIbcTllt8988Ah2ZwTWVjJ2 ZVFPc/2qMqVe8o11GqV/7XfY+0FfvvDksPABQCTTFFLIeUqJLIx9p/5idW6cJezzIrMR XLy/TKpcmIS5L8YjK1cvjbncHKmFCOwwLP5Oyo3ZiebhhoSWLO+J0Npqw4d+GDTWMhV9 8Tum2DX7AICyWg/aNV+e+Kx404qRy2tyGHTg6bTwhkzrHuOVj+A5wrpVlDS5hqqwvFSi /m2kb5olYVEsTq7LA+Cue670JOdhEQttdU00+ysTYeuod0c0LBNWIXe66HuTn7f3y+oP rSsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=vGywFzIy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id dw27-20020a056a00369b00b0068beea8071esi2976811pfb.221.2023.09.21.21.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 21:50:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=vGywFzIy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3BB2B8335B09; Thu, 21 Sep 2023 13:22:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231718AbjIUUWb (ORCPT + 29 others); Thu, 21 Sep 2023 16:22:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231425AbjIUUWC (ORCPT ); Thu, 21 Sep 2023 16:22:02 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D853C10182 for ; Thu, 21 Sep 2023 10:29:57 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9ad8bba8125so159472066b.3 for ; Thu, 21 Sep 2023 10:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317389; x=1695922189; 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=8xPn0fJb1G79vmQneRtFHd9riwOuPrJO1tNQT+KG0zw=; b=vGywFzIyVlqaDtmzt/UED2fs7D4gyvtpUpoVEYskX/NnqTJWi+d2dOREdB9MHu3jhF iXa6d8zI2/l5YlGsHsS18qdy0IifUAfL7m5Eb883TRSFtDTrDNVXb7+t79iTsZoOgAjp bfwEH0mn6xsosTGSXQjuyDGGUG1kIxjqowW727EzLI5pzYmhUWbjRwFzQ/DVCOha2D44 G0gA7K11g+N/iHfbjiMg03LHJCeCiKJ4JHRhDhP62sw04qX2+6gHH8Q+MBq1UoM5Ysdl l5Fbm9uz3Zi/lS7srCfesrx4C7uA7H4Yn9eFrOS7kXYhAgogiQ5Rm8aCdvcoPnRYnxUV 5aAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317389; x=1695922189; 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=8xPn0fJb1G79vmQneRtFHd9riwOuPrJO1tNQT+KG0zw=; b=RreOZaiTLF7pvd8XYXR0Xd661UKZKBuM1hJMhPdXvicijBLMs7E6XXUl/GtwXhBx83 3y2ExcN1Xedw7J6WjdXHJ2KLL7kk8phNHflqjzaPygoJh0INfZn902OODse3uaiJOWMh j+0RvwqcDPKDXXE0n89R6FjodAysV9Lqjef8byxNAMK5McI75pQlc4qJFNL5qKjoUCpW +jgEM1sq2baKr7Wnr4zSLV41EOhotcJm4useYxy4yYzhUBbfazXStFOP4mY5LWJgfLXv RQ5AjNZhjMQR1fEt8vONwlpgL26eXLj7Fw+A/rJ9tMZJYZ9qrVVMArdh71blG1Y+C5Bp 416A== X-Gm-Message-State: AOJu0YzopoRev/spIpX7HwQvMFovmBfMRasYi478tEB1SDTKugjHdn08 q7N0Jlk2k5ziEyzF9pdxWiQQBJz3iRwoR6ggWIzojkeH X-Received: by 2002:a7b:c859:0:b0:402:95a0:b2ae with SMTP id c25-20020a7bc859000000b0040295a0b2aemr4971411wml.32.1695307458717; Thu, 21 Sep 2023 07:44:18 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:18 -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 v2 07/19] staging: iio: resolver: ad2s1210: implement IIO_CHAN_INFO_SCALE Date: Thu, 21 Sep 2023 09:43:48 -0500 Message-Id: <20230921144400.62380-8-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:22:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777711950253630168 X-GMAIL-MSGID: 1777711950253630168 This adds an implementation of IIO_CHAN_INFO_SCALE to the ad2s1210 resolver driver. This allows userspace to get the scale factor for the raw values. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 107 ++++++++++++++++-------- 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 985b8fecd65a..95d43b241a75 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -458,56 +458,91 @@ static ssize_t ad2s1210_store_reg(struct device *dev, return ret < 0 ? ret : len; } +static const int ad2s1210_velocity_scale[] = { + 17089132, /* 8.192MHz / (2*pi * 2500 / 2^15) */ + 42722830, /* 8.192MHz / (2*pi * 1000 / 2^15) */ + 85445659, /* 8.192MHz / (2*pi * 500 / 2^15) */ + 341782638, /* 8.192MHz / (2*pi * 125 / 2^15) */ +}; + static int ad2s1210_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, - long m) + long mask) { struct ad2s1210_state *st = iio_priv(indio_dev); int ret = 0; - mutex_lock(&st->lock); - gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); - /* delay (6 * tck + 20) nano seconds */ - udelay(1); + switch (mask) { + case IIO_CHAN_INFO_RAW: + mutex_lock(&st->lock); + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); + /* delay (6 * tck + 20) nano seconds */ + udelay(1); + + switch (chan->type) { + case IIO_ANGL: + ad2s1210_set_mode(MOD_POS, st); + break; + case IIO_ANGL_VEL: + ad2s1210_set_mode(MOD_VEL, st); + break; + default: + ret = -EINVAL; + break; + } + if (ret < 0) + goto error_info_raw; + ret = spi_read(st->sdev, st->rx, 2); + if (ret < 0) + goto error_info_raw; + + switch (chan->type) { + case IIO_ANGL: + *val = be16_to_cpup((__be16 *)st->rx); + ret = IIO_VAL_INT; + break; + case IIO_ANGL_VEL: + *val = (s16)be16_to_cpup((__be16 *)st->rx); + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + break; + } - switch (chan->type) { - case IIO_ANGL: - ad2s1210_set_mode(MOD_POS, st); - break; - case IIO_ANGL_VEL: - ad2s1210_set_mode(MOD_VEL, st); - break; - default: - ret = -EINVAL; +error_info_raw: + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); + /* delay (2 * tck + 20) nano seconds */ + udelay(1); + mutex_unlock(&st->lock); break; - } - if (ret < 0) - goto error_ret; - ret = spi_read(st->sdev, st->rx, 2); - if (ret < 0) - goto error_ret; - switch (chan->type) { - case IIO_ANGL: - *val = be16_to_cpup((__be16 *)st->rx); - ret = IIO_VAL_INT; - break; - case IIO_ANGL_VEL: - *val = (s16)be16_to_cpup((__be16 *)st->rx); - ret = IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL: + /* approx 0.3 arc min converted to radians */ + *val = 0; + *val2 = 95874; + ret = IIO_VAL_INT_PLUS_NANO; + break; + case IIO_ANGL_VEL: + *val = st->fclkin; + *val2 = ad2s1210_velocity_scale[st->resolution]; + ret = IIO_VAL_FRACTIONAL; + break; + default: + ret = -EINVAL; + break; + } break; + default: ret = -EINVAL; break; } -error_ret: - gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); - /* delay (2 * tck + 20) nano seconds */ - udelay(1); - mutex_unlock(&st->lock); return ret; } @@ -549,12 +584,14 @@ static const struct iio_chan_spec ad2s1210_channels[] = { .type = IIO_ANGL, .indexed = 1, .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), }, { .type = IIO_ANGL_VEL, .indexed = 1, .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), } }; From patchwork Thu Sep 21 14:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 142930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5154294vqi; Thu, 21 Sep 2023 14:38:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfmHc/7WLTD0eGH/TErV8OKLuY2o3e7d+vdcQInLNZzAOADuBBWao3Lix+rzxfVT4Jr6ln X-Received: by 2002:a05:6a20:1389:b0:15d:9ee7:1811 with SMTP id hn9-20020a056a20138900b0015d9ee71811mr870755pzc.36.1695332326897; Thu, 21 Sep 2023 14:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695332326; cv=none; d=google.com; s=arc-20160816; b=BSwgs3Ob8Ki+wY2FkomgAVY/AOU8EEbcmxBR/ODUzKILLGzVQQnDM1j21ckB56VoON triFQTdeNUaA9PdLG1O6SF4Og5oOjXaxp29QY6QUfMv03yvJu/yQzo7K9f3BsgSARllf iiuf/N3jQ92FWtT5kcuzPBjY8upYmrUDOq3Xf3qZ8VeV5bM9szbDAXBBdMTIK2qQDE8E VsGBnQXNVR5sH7dzzHfVwiyuStaCIkNn0W3W5XrhYnUDTJam/JRR1OKxvie9+Qn2qinr d1t4xxvJMbTJB3/FnTa0+TOB8I6INfE9PFDGJo2/mLYBvbQfVV3z1MaaxzTWZyf1H9IH mfFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=phvZq4VpwSFX4vyqlS17/uN/agj73xAJlQboMqH0z3o=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=haa+ijuJyBingCi6hSCVKMUVb2lqkVjwnR8tqSI1BXxe9epzNSHcqfXLZPcjbba+hS FqfrnpqhV7ZvxGn3mVn6zC3x/cATXaMJPkqJ1e+PIpRVnP8aqzKpnTDUUx+cn70Y9Wcx OxyiX1k41W7l4jDcUJGAsPE5fbSf9wE0bsCDydEfHZDRLZt1EkVS176OUBLe9IcZFBfD 3Of42N5eUhXJnVT2qGwpKWTQiUHQjwizGSOaAxbW4EyBoUZqEb74dN6xtlw19b+OGaI8 DwM7tlUmN1cC028cn6aPQ/5UDoA4nXeTBO8vRC1xuaRbqdpubKKeEzT9HLgHHRZrWwNd oe2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=bwoijMUN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id bg26-20020a056a02011a00b00573e7fd674esi2124781pgb.661.2023.09.21.14.38.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:38:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=bwoijMUN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8F83E8363C51; Thu, 21 Sep 2023 13:00:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbjIUUAj (ORCPT + 28 others); Thu, 21 Sep 2023 16:00:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbjIUUAB (ORCPT ); Thu, 21 Sep 2023 16:00:01 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3287B101A5 for ; Thu, 21 Sep 2023 10:30:03 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2c00b37ad84so22109891fa.0 for ; Thu, 21 Sep 2023 10:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317394; x=1695922194; 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=phvZq4VpwSFX4vyqlS17/uN/agj73xAJlQboMqH0z3o=; b=bwoijMUNheaeHMc9bTKSK2DN9ZhujbfmI/Y+P5dZLU/ox5VdeCd4N+mQtaCd3rJi2T QkBsSPyqcZ/x6MlcB3ZmZIkZB8biCMKJ7JMUxrQLR6KDGYtP0rm1RwKJNH+e1m2AvkiQ wB83l8HpKxu/U5QWmUjBFnhiepHAZp3KKttr0+mDJOucjgLnbmqyRYf4lKU5I6LwTB32 Q5Ek45uxYbLzc4pjULI/2F4BBX7JpbE55YrWzTXZmRDLntWiKPNXgGiCLsR2G2NSH4zK F/dgPIVGVX2M34yfOO1GHH3dcQgPVUEZR4rvEzR0/o4r8tM+nXldGZFEMZahJZJ+J43v XT+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317394; x=1695922194; 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=phvZq4VpwSFX4vyqlS17/uN/agj73xAJlQboMqH0z3o=; b=tNnfOsym/LcVUET/uvJn/t9wkzb2D1+KWal+XndPDbIJM1fgvA2jmrQ48Smh39TIg4 FhXthmizycIV+dVMrgbdbX1+V5Xijb4cAAjz2tVubpjXTBjdYleLrlJnn+7fBs8XFYoy J550LrB7oUhpFcPr/z4R0NDDZ78t8dN3xx1ewyj+0ohX2jbg6c5mgmGLIlqeJaswDRhr /Zh8mJXAOv9oxICPRE92kN5OeTzKAmTL69akiKw0dYi69SHAQA4aTa9gtDqkKRSUzL6t MQPoWib4/3cJawTZgHqzQzMfXgXrYVMlTn7QZo1kGk3E2j6EFTZKk6wh83qzX1yHm+cb jifQ== X-Gm-Message-State: AOJu0Yzr7rvZj4Sg3VBrNF8BoiXpZGKhHafuEOijlxd8ekwVujzDyAWH DjHNA9CRnetNtM3MfWFX0XmeMj+kTPPxtv+M7IOvWtLH X-Received: by 2002:a05:600c:4ec7:b0:405:37bb:d93e with SMTP id g7-20020a05600c4ec700b0040537bbd93emr1147858wmq.9.1695307459769; Thu, 21 Sep 2023 07:44:19 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:19 -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 v2 08/19] staging: iio: resolver: ad2s1210: use devicetree to get fclkin Date: Thu, 21 Sep 2023 09:43:49 -0500 Message-Id: <20230921144400.62380-9-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:00:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777684789511526704 X-GMAIL-MSGID: 1777684789511526704 This removes the fclkin sysfs attribute and replaces it with getting the fclkin clock rate using the clk subsystem (i.e. from the devicetree). The fclkin clock comes from an external oscillator that is connected directly to the AD2S1210 chip, so users of the sysfs attributes should not need to be concerned with this. Also sort includes while we are touching this. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/Kconfig | 1 + drivers/staging/iio/resolver/ad2s1210.c | 76 +++++++++---------------- 2 files changed, 28 insertions(+), 49 deletions(-) diff --git a/drivers/staging/iio/resolver/Kconfig b/drivers/staging/iio/resolver/Kconfig index 6d1e2622e0b0..bebb35822c9e 100644 --- a/drivers/staging/iio/resolver/Kconfig +++ b/drivers/staging/iio/resolver/Kconfig @@ -7,6 +7,7 @@ menu "Resolver to digital converters" config AD2S1210 tristate "Analog Devices ad2s1210 driver" depends on SPI + depends on COMMON_CLK depends on GPIOLIB || COMPILE_TEST help Say yes here to build support for Analog Devices spi resolver diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 95d43b241a75..153ac7704ad7 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -5,16 +5,17 @@ * Copyright (c) 2010-2010 Analog Devices Inc. * Copyright (C) 2023 BayLibre, SAS */ -#include -#include +#include +#include #include +#include +#include +#include #include -#include #include +#include #include -#include -#include -#include +#include #include #include @@ -91,7 +92,8 @@ struct ad2s1210_state { struct mutex lock; struct spi_device *sdev; struct gpio_desc *gpios[5]; - unsigned int fclkin; + /** The external oscillator frequency in Hz. */ + unsigned long fclkin; unsigned int fexcit; bool hysteresis; u8 resolution; @@ -198,45 +200,6 @@ static inline int ad2s1210_soft_reset(struct ad2s1210_state *st) return ad2s1210_config_write(st, 0x0); } -static ssize_t ad2s1210_show_fclkin(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - - return sprintf(buf, "%u\n", st->fclkin); -} - -static ssize_t ad2s1210_store_fclkin(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - unsigned int fclkin; - int ret; - - ret = kstrtouint(buf, 10, &fclkin); - if (ret) - return ret; - if (fclkin < AD2S1210_MIN_CLKIN || fclkin > AD2S1210_MAX_CLKIN) { - dev_err(dev, "ad2s1210: fclkin out of range\n"); - return -EINVAL; - } - - mutex_lock(&st->lock); - st->fclkin = fclkin; - - ret = ad2s1210_update_frequency_control_word(st); - if (ret < 0) - goto error_ret; - ret = ad2s1210_soft_reset(st); -error_ret: - mutex_unlock(&st->lock); - - return ret < 0 ? ret : len; -} - static ssize_t ad2s1210_show_fexcit(struct device *dev, struct device_attribute *attr, char *buf) @@ -546,8 +509,6 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, return ret; } -static IIO_DEVICE_ATTR(fclkin, 0644, - ad2s1210_show_fclkin, ad2s1210_store_fclkin, 0); static IIO_DEVICE_ATTR(fexcit, 0644, ad2s1210_show_fexcit, ad2s1210_store_fexcit, 0); static IIO_DEVICE_ATTR(control, 0644, @@ -596,7 +557,6 @@ static const struct iio_chan_spec ad2s1210_channels[] = { }; static struct attribute *ad2s1210_attributes[] = { - &iio_dev_attr_fclkin.dev_attr.attr, &iio_dev_attr_fexcit.dev_attr.attr, &iio_dev_attr_control.dev_attr.attr, &iio_dev_attr_bits.dev_attr.attr, @@ -654,6 +614,24 @@ static const struct iio_info ad2s1210_info = { .attrs = &ad2s1210_attribute_group, }; +static int ad2s1210_setup_clocks(struct ad2s1210_state *st) +{ + struct device *dev = &st->sdev->dev; + struct clk *clk; + + clk = devm_clk_get_enabled(dev, NULL); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "failed to get clock\n"); + + st->fclkin = clk_get_rate(clk); + if (st->fclkin < AD2S1210_MIN_CLKIN || st->fclkin > AD2S1210_MAX_CLKIN) + return dev_err_probe(dev, -EINVAL, + "clock frequency out of range: %lu\n", + st->fclkin); + + return 0; +} + static int ad2s1210_setup_gpios(struct ad2s1210_state *st) { struct spi_device *spi = st->sdev; From patchwork Thu Sep 21 14:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5320135vqi; Thu, 21 Sep 2023 21:38:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVIWNNXJKJkM2z3jAHkTMLPrTrcbHXnod7P8vv423TkRK/mV4knbMyJlPXSUIdIRS8NR5/ X-Received: by 2002:a17:90a:f18c:b0:26b:f67:9d1b with SMTP id bv12-20020a17090af18c00b0026b0f679d1bmr6660036pjb.30.1695357534042; Thu, 21 Sep 2023 21:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695357534; cv=none; d=google.com; s=arc-20160816; b=RFJ/17fkkztqXSTDHp5ozbJktwY1bzPSVQ3yizviQJDMLcqlgC64DmBMrqlgyL/u6o BJp4PYSjmygAcWu2pT44KgKqsxhGOJMI+VgccRiRa2TK32YR2h/zOZzO04R1lbHQgCiW CiRhsNM+/wu9dM3bcUW4SeuplBCr32qrrDkMtbb+NFGbab1ei7uiDxYLojES2dc3MoKw AKhPtLVacZuF6wntkaOs2SATQf7NeFqO62yDMYXvp9h2LRi1BUXaJ+Ndo7E22vVLEP9M hI35ukZQo2XL/iAavnGSlS2EiZD3AToKRd2o4tTzQB/xOX+uMXAJLI3/cFg8g3xnCN1O fMLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ms6XtDC2gqm1+y4qBooiAiA+r/YZdcas3vjvFP4dBPU=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=XxyPS2tbl0i730QxGv+OIsN5SI1XRy00Q5KhiANsW+/Qn0XFd76qki/ML19+AiXOhG SkBUjhGR/wWY0slcKgRHeLRTmLMRFNCtEhfocAKAt1fU5KQdAlMTQChctFo/+JNfFoUy FUOICBiqbsLGuo88Lz3hM4vAtzYsL55SS0qbWArCL49zRtHci1U06VZiCkVJUDusHWT3 w/jc0lDLiEGTbCbSYDoAMlyneyRJm42kt+GFM96tFc5zokm2JhqKnsQF86d8767DUtcY BXGLHXcCfIdnk2/Qf3WdlUHSy7XCKXesHWMJRNux/rT0teRx3mWbntKplth3//QBdo6B 9R+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=nXuDY0t0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id e4-20020a17090301c400b001bba894ac4asi3221567plh.274.2023.09.21.21.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 21:38:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=nXuDY0t0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4DB46804B38F; Thu, 21 Sep 2023 12:05:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbjIUTD4 (ORCPT + 28 others); Thu, 21 Sep 2023 15:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230472AbjIUTDa (ORCPT ); Thu, 21 Sep 2023 15:03:30 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FEF148ABB for ; Thu, 21 Sep 2023 10:51:11 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-99c3c8adb27so155515166b.1 for ; Thu, 21 Sep 2023 10:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318668; x=1695923468; 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=ms6XtDC2gqm1+y4qBooiAiA+r/YZdcas3vjvFP4dBPU=; b=nXuDY0t0R73qoaxq6JxaucM6jnOcgxzMozP4e97ailV6Lo3My4WC/royyvKioQl9Wv EmKBdYSkZ3jb6kpJyuxiR+ijAi9pRoHlsQU5mDE5DBE3PtscU4D00iRBOypNnb/EGXVS bTR7itEBKd3p1bexXHEFRngfyIz1fQ6iQ0cUxaHhDezb9CkPAzc9r9/aayX6GHKoUKb/ uy8i5E62B0M7hM5MRiKo+Knie9h2EiOWOh78sbnrIEwCAiIurpTXW/rifa3HtgAopa+2 Uk1YCdk/56r3OBu4u4xWg+Nt2o/U4eX94fr4rmWfJGSJG3Vch7Wo9w2WMqubLN4so1JU 2cZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318668; x=1695923468; 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=ms6XtDC2gqm1+y4qBooiAiA+r/YZdcas3vjvFP4dBPU=; b=cGRj40TqDNbbZXBiLIs3roG3128S5JWImkTqzPnJHslk4pt48nLI+ZWmioqoSmgUwX 2+SlfSpIu4dOkgK3ug+Or/IzbQZ4A1QipNLYPzbyKsfFfVk/U+U9oS5WFAfKycJN1K2z 0wMdlGq8iCFzuaSX1RiumdVp2JCD5s8H7VAPBNGcK9tbMYnXrqP6y5p0JBT2efw5KfkV 9f/jsykJUlBbJuCpB2+VPyCrKSFLgLtSnsKCGZafAgNWMBAKsLiVz67tBU3tQ7L5w+cc 7sFLE/3ZNN5QQOpIq5I5ucLgsCneoIoQU4rA+SNRLUY1GKWNS891L4sBTYN7GGzAZMG5 jBxg== X-Gm-Message-State: AOJu0Yy7KnFIOaL0Umpf36r883uunUgPktzq2E/okTc4ur6OoyzGVid5 X7Fc1prkgKJ9OS142IzW8fyS2ljMj9sHuen+nEhHNiBl X-Received: by 2002:a7b:ce91:0:b0:3fe:4548:1892 with SMTP id q17-20020a7bce91000000b003fe45481892mr5142594wmj.16.1695307460586; Thu, 21 Sep 2023 07:44:20 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:20 -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 v2 09/19] staging: iio: resolver: ad2s1210: use regmap for config registers Date: Thu, 21 Sep 2023 09:43:50 -0500 Message-Id: <20230921144400.62380-10-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:05:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777711221710675786 X-GMAIL-MSGID: 1777711221710675786 This makes use of the regmap API to read and write the configuration registers. This simplifies code quite a bit and makes it safer (previously, it was easy to write a bad value to the config registers which causes the chip to lock up and need to be reset). Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 251 ++++++++++++++---------- 1 file changed, 149 insertions(+), 102 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 153ac7704ad7..3c81ee61b897 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -5,6 +5,7 @@ * Copyright (c) 2010-2010 Analog Devices Inc. * Copyright (C) 2023 BayLibre, SAS */ +#include #include #include #include @@ -12,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,21 +24,20 @@ #define DRV_NAME "ad2s1210" +/* default value of control register on powerup */ #define AD2S1210_DEF_CONTROL 0x7E -#define AD2S1210_MSB_IS_HIGH 0x80 -#define AD2S1210_MSB_IS_LOW 0x7F -#define AD2S1210_PHASE_LOCK_RANGE_44 0x20 -#define AD2S1210_ENABLE_HYSTERESIS 0x10 -#define AD2S1210_SET_ENRES1 0x08 -#define AD2S1210_SET_ENRES0 0x04 -#define AD2S1210_SET_RES1 0x02 -#define AD2S1210_SET_RES0 0x01 - -#define AD2S1210_SET_RESOLUTION (AD2S1210_SET_RES1 | AD2S1210_SET_RES0) - -#define AD2S1210_REG_POSITION 0x80 -#define AD2S1210_REG_VELOCITY 0x82 +/* control register flags */ +#define AD2S1210_ADDRESS_DATA BIT(7) +#define AD2S1210_PHASE_LOCK_RANGE_44 BIT(5) +#define AD2S1210_ENABLE_HYSTERESIS BIT(4) +#define AD2S1210_SET_ENRES GENMASK(3, 2) +#define AD2S1210_SET_RES GENMASK(1, 0) + +#define AD2S1210_REG_POSITION_MSB 0x80 +#define AD2S1210_REG_POSITION_LSB 0x81 +#define AD2S1210_REG_VELOCITY_MSB 0x82 +#define AD2S1210_REG_VELOCITY_LSB 0x83 #define AD2S1210_REG_LOS_THRD 0x88 #define AD2S1210_REG_DOS_OVR_THRD 0x89 #define AD2S1210_REG_DOS_MIS_THRD 0x8A @@ -92,6 +93,8 @@ struct ad2s1210_state { struct mutex lock; struct spi_device *sdev; struct gpio_desc *gpios[5]; + /** Used to access config registers. */ + struct regmap *regmap; /** The external oscillator frequency in Hz. */ unsigned long fclkin; unsigned int fexcit; @@ -116,24 +119,51 @@ static inline void ad2s1210_set_mode(enum ad2s1210_mode mode, st->mode = mode; } -/* write 1 bytes (address or data) to the chip */ -static int ad2s1210_config_write(struct ad2s1210_state *st, u8 data) +/* + * Writes the given data to the given register address. + * + * If the mode is configurable, the device will first be placed in + * configuration mode. + */ +static int ad2s1210_regmap_reg_write(void *context, unsigned int reg, + unsigned int val) { - int ret; + struct ad2s1210_state *st = context; + struct spi_transfer xfers[] = { + { + .len = 1, + .rx_buf = &st->rx[0], + .tx_buf = &st->tx[0], + .cs_change = 1, + }, { + .len = 1, + .rx_buf = &st->rx[1], + .tx_buf = &st->tx[1], + }, + }; + + /* values can only be 7 bits, the MSB indicates an address */ + if (val & ~0x7F) + return -EINVAL; + + st->tx[0] = reg; + st->tx[1] = val; ad2s1210_set_mode(MOD_CONFIG, st); - st->tx[0] = data; - ret = spi_write(st->sdev, st->tx, 1); - if (ret < 0) - return ret; - return 0; + return spi_sync_transfer(st->sdev, xfers, ARRAY_SIZE(xfers)); } -/* read value from one of the registers */ -static int ad2s1210_config_read(struct ad2s1210_state *st, - unsigned char address) +/* + * Reads value from one of the registers. + * + * If the mode is configurable, the device will first be placed in + * configuration mode. + */ +static int ad2s1210_regmap_reg_read(void *context, unsigned int reg, + unsigned int *val) { + struct ad2s1210_state *st = context; struct spi_transfer xfers[] = { { .len = 1, @@ -146,22 +176,34 @@ static int ad2s1210_config_read(struct ad2s1210_state *st, .tx_buf = &st->tx[1], }, }; - int ret = 0; + int ret; ad2s1210_set_mode(MOD_CONFIG, st); - st->tx[0] = address | AD2S1210_MSB_IS_HIGH; + st->tx[0] = reg; + /* Must be valid register address here otherwise this could write data. + * It doesn't matter which one. + */ st->tx[1] = AD2S1210_REG_FAULT; - ret = spi_sync_transfer(st->sdev, xfers, 2); + + ret = spi_sync_transfer(st->sdev, xfers, ARRAY_SIZE(xfers)); if (ret < 0) return ret; - return st->rx[1]; + /* If the D7 bit is set on any read/write register, it indicates a + * parity error. The fault register is read-only and the D7 bit means + * something else there. + */ + if (reg != AD2S1210_REG_FAULT && st->rx[1] & AD2S1210_ADDRESS_DATA) + return -EBADMSG; + + *val = st->rx[1]; + + return 0; } static inline int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st) { - int ret; unsigned char fcw; fcw = (unsigned char)(st->fexcit * (1 << 15) / st->fclkin); @@ -170,11 +212,7 @@ int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st) return -ERANGE; } - ret = ad2s1210_config_write(st, AD2S1210_REG_EXCIT_FREQ); - if (ret < 0) - return ret; - - return ad2s1210_config_write(st, fcw); + return regmap_write(st->regmap, AD2S1210_REG_EXCIT_FREQ, fcw); } static const int ad2s1210_res_pins[4][2] = { @@ -191,13 +229,7 @@ static inline void ad2s1210_set_resolution_pin(struct ad2s1210_state *st) static inline int ad2s1210_soft_reset(struct ad2s1210_state *st) { - int ret; - - ret = ad2s1210_config_write(st, AD2S1210_REG_SOFT_RESET); - if (ret < 0) - return ret; - - return ad2s1210_config_write(st, 0x0); + return regmap_write(st->regmap, AD2S1210_REG_SOFT_RESET, 0); } static ssize_t ad2s1210_show_fexcit(struct device *dev, @@ -242,12 +274,13 @@ static ssize_t ad2s1210_show_control(struct device *dev, char *buf) { struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + unsigned int value; int ret; mutex_lock(&st->lock); - ret = ad2s1210_config_read(st, AD2S1210_REG_CONTROL); + ret = regmap_read(st->regmap, AD2S1210_REG_CONTROL, &value); mutex_unlock(&st->lock); - return ret < 0 ? ret : sprintf(buf, "0x%x\n", ret); + return ret < 0 ? ret : sprintf(buf, "0x%x\n", value); } static ssize_t ad2s1210_store_control(struct device *dev, @@ -264,25 +297,13 @@ static ssize_t ad2s1210_store_control(struct device *dev, return -EINVAL; mutex_lock(&st->lock); - ret = ad2s1210_config_write(st, AD2S1210_REG_CONTROL); - if (ret < 0) - goto error_ret; - data = udata & AD2S1210_MSB_IS_LOW; - ret = ad2s1210_config_write(st, data); + data = udata & ~AD2S1210_ADDRESS_DATA; + ret = regmap_write(st->regmap, AD2S1210_REG_CONTROL, data); if (ret < 0) goto error_ret; - ret = ad2s1210_config_read(st, AD2S1210_REG_CONTROL); - if (ret < 0) - goto error_ret; - if (ret & AD2S1210_MSB_IS_HIGH) { - ret = -EIO; - dev_err(dev, - "ad2s1210: write control register fail\n"); - goto error_ret; - } st->resolution = - ad2s1210_resolution_value[data & AD2S1210_SET_RESOLUTION]; + ad2s1210_resolution_value[data & AD2S1210_SET_RES]; ad2s1210_set_resolution_pin(st); ret = len; st->hysteresis = !!(data & AD2S1210_ENABLE_HYSTERESIS); @@ -315,30 +336,17 @@ static ssize_t ad2s1210_store_resolution(struct device *dev, dev_err(dev, "ad2s1210: resolution out of range\n"); return -EINVAL; } + + data = (udata - 10) >> 1; + mutex_lock(&st->lock); - ret = ad2s1210_config_read(st, AD2S1210_REG_CONTROL); - if (ret < 0) - goto error_ret; - data = ret; - data &= ~AD2S1210_SET_RESOLUTION; - data |= (udata - 10) >> 1; - ret = ad2s1210_config_write(st, AD2S1210_REG_CONTROL); - if (ret < 0) - goto error_ret; - ret = ad2s1210_config_write(st, data & AD2S1210_MSB_IS_LOW); + ret = regmap_update_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_SET_RES, data); if (ret < 0) goto error_ret; - ret = ad2s1210_config_read(st, AD2S1210_REG_CONTROL); - if (ret < 0) - goto error_ret; - data = ret; - if (data & AD2S1210_MSB_IS_HIGH) { - ret = -EIO; - dev_err(dev, "ad2s1210: setting resolution fail\n"); - goto error_ret; - } + st->resolution = - ad2s1210_resolution_value[data & AD2S1210_SET_RESOLUTION]; + ad2s1210_resolution_value[data & AD2S1210_SET_RES]; ad2s1210_set_resolution_pin(st); ret = len; error_ret: @@ -351,13 +359,14 @@ static ssize_t ad2s1210_show_fault(struct device *dev, struct device_attribute *attr, char *buf) { struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + unsigned int value; int ret; mutex_lock(&st->lock); - ret = ad2s1210_config_read(st, AD2S1210_REG_FAULT); + ret = regmap_read(st->regmap, AD2S1210_REG_FAULT, &value); mutex_unlock(&st->lock); - return (ret < 0) ? ret : sprintf(buf, "0x%02x\n", ret); + return ret < 0 ? ret : sprintf(buf, "0x%02x\n", value); } static ssize_t ad2s1210_clear_fault(struct device *dev, @@ -366,6 +375,7 @@ static ssize_t ad2s1210_clear_fault(struct device *dev, size_t len) { struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + unsigned int value; int ret; mutex_lock(&st->lock); @@ -373,7 +383,7 @@ static ssize_t ad2s1210_clear_fault(struct device *dev, /* delay (2 * tck + 20) nano seconds */ udelay(1); gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); - ret = ad2s1210_config_read(st, AD2S1210_REG_FAULT); + ret = regmap_read(st->regmap, AD2S1210_REG_FAULT, &value); if (ret < 0) goto error_ret; gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); @@ -390,13 +400,14 @@ static ssize_t ad2s1210_show_reg(struct device *dev, { struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); struct iio_dev_attr *iattr = to_iio_dev_attr(attr); + unsigned int value; int ret; mutex_lock(&st->lock); - ret = ad2s1210_config_read(st, iattr->address); + ret = regmap_read(st->regmap, iattr->address, &value); mutex_unlock(&st->lock); - return ret < 0 ? ret : sprintf(buf, "%d\n", ret); + return ret < 0 ? ret : sprintf(buf, "%d\n", value); } static ssize_t ad2s1210_store_reg(struct device *dev, @@ -409,14 +420,11 @@ static ssize_t ad2s1210_store_reg(struct device *dev, struct iio_dev_attr *iattr = to_iio_dev_attr(attr); ret = kstrtou8(buf, 10, &data); - if (ret) + if (ret < 0) return -EINVAL; + mutex_lock(&st->lock); - ret = ad2s1210_config_write(st, iattr->address); - if (ret < 0) - goto error_ret; - ret = ad2s1210_config_write(st, data & AD2S1210_MSB_IS_LOW); -error_ret: + ret = regmap_write(st->regmap, iattr->address, data); mutex_unlock(&st->lock); return ret < 0 ? ret : len; } @@ -583,23 +591,12 @@ static int ad2s1210_initial(struct ad2s1210_state *st) mutex_lock(&st->lock); ad2s1210_set_resolution_pin(st); - ret = ad2s1210_config_write(st, AD2S1210_REG_CONTROL); - if (ret < 0) - goto error_ret; - data = AD2S1210_DEF_CONTROL & ~(AD2S1210_SET_RESOLUTION); + data = AD2S1210_DEF_CONTROL & ~AD2S1210_SET_RES; data |= (st->resolution - 10) >> 1; - ret = ad2s1210_config_write(st, data); - if (ret < 0) - goto error_ret; - ret = ad2s1210_config_read(st, AD2S1210_REG_CONTROL); + ret = regmap_write(st->regmap, AD2S1210_REG_CONTROL, data); if (ret < 0) goto error_ret; - if (ret & AD2S1210_MSB_IS_HIGH) { - ret = -EIO; - goto error_ret; - } - ret = ad2s1210_update_frequency_control_word(st); if (ret < 0) goto error_ret; @@ -652,6 +649,52 @@ static int ad2s1210_setup_gpios(struct ad2s1210_state *st) return 0; } +static const struct regmap_range ad2s1210_regmap_readable_ranges[] = { + regmap_reg_range(AD2S1210_REG_POSITION_MSB, AD2S1210_REG_VELOCITY_LSB), + regmap_reg_range(AD2S1210_REG_LOS_THRD, AD2S1210_REG_LOT_LOW_THRD), + regmap_reg_range(AD2S1210_REG_EXCIT_FREQ, AD2S1210_REG_CONTROL), + regmap_reg_range(AD2S1210_REG_FAULT, AD2S1210_REG_FAULT), +}; + +static const struct regmap_access_table ad2s1210_regmap_rd_table = { + .yes_ranges = ad2s1210_regmap_readable_ranges, + .n_yes_ranges = ARRAY_SIZE(ad2s1210_regmap_readable_ranges), +}; + +static const struct regmap_range ad2s1210_regmap_writeable_ranges[] = { + regmap_reg_range(AD2S1210_REG_LOS_THRD, AD2S1210_REG_LOT_LOW_THRD), + regmap_reg_range(AD2S1210_REG_EXCIT_FREQ, AD2S1210_REG_CONTROL), + regmap_reg_range(AD2S1210_REG_SOFT_RESET, AD2S1210_REG_SOFT_RESET), + regmap_reg_range(AD2S1210_REG_FAULT, AD2S1210_REG_FAULT), +}; + +static const struct regmap_access_table ad2s1210_regmap_wr_table = { + .yes_ranges = ad2s1210_regmap_writeable_ranges, + .n_yes_ranges = ARRAY_SIZE(ad2s1210_regmap_writeable_ranges), +}; + +static int ad2s1210_setup_regmap(struct ad2s1210_state *st) +{ + struct device *dev = &st->sdev->dev; + const struct regmap_config config = { + .reg_bits = 8, + .val_bits = 8, + .disable_locking = true, + .reg_read = ad2s1210_regmap_reg_read, + .reg_write = ad2s1210_regmap_reg_write, + .rd_table = &ad2s1210_regmap_rd_table, + .wr_table = &ad2s1210_regmap_wr_table, + .can_sleep = true, + }; + + st->regmap = devm_regmap_init(dev, NULL, st, &config); + if (IS_ERR(st->regmap)) + return dev_err_probe(dev, PTR_ERR(st->regmap), + "failed to allocate register map\n"); + + return 0; +} + static int ad2s1210_probe(struct spi_device *spi) { struct iio_dev *indio_dev; @@ -679,6 +722,10 @@ static int ad2s1210_probe(struct spi_device *spi) if (ret < 0) return ret; + ret = ad2s1210_setup_regmap(st); + if (ret < 0) + return ret; + ret = ad2s1210_initial(st); if (ret < 0) return ret; From patchwork Thu Sep 21 14:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5825020vqi; Fri, 22 Sep 2023 12:41:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHperPa1XWb/FoNeiOH043QZGD2Jxq1XpVRuv0jGQyRUlKZmMnTFpl7tyDYDWylwdildh0Q X-Received: by 2002:a05:6a21:a593:b0:13d:7f7b:1926 with SMTP id gd19-20020a056a21a59300b0013d7f7b1926mr5266001pzc.11.1695411710408; Fri, 22 Sep 2023 12:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695411710; cv=none; d=google.com; s=arc-20160816; b=eyahza9KvrLhD+6wMTIRgLuy+wtZbkiv2oEzLoeYXvwSijY5tqE664FoorwBgFuh0e LzB0gkHNsbeUiCMqGdaxxjWo2LLbuHDDxGgB+75uXVof//0TCOsb0bcMG5JHVEVzKaQO zhc/kgXRxYplDaf3GtciVWkbZBBrC1cGxTkOgbu+PHBOo6TRPonTkuAOYFKz9V/Fe4ll TS85pvjJYo3hJvkoH7q3UmlAW1vP4f1e4/pZ/AfDOn4id51zp11fpVYXG5mv1HzrsX73 I7wn7ZXpf+C0neKS17LA+CgnmKI9vfyYSCxfVwZ046IJIwrA9HpANuS3ZJUcth+oVKqP eLbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NDg1sZsypbtmVZl9501Jvjfjp7cqgNO2wWu9eDz+bAo=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=kj9WR99rvNYV13xtxZzjEba1S8MZjT+S+wwWCRHKLbLaRMCZwFti16ziRNza1Gem3e oHE9DL669Lxx41BRzA8TRsyCiLPvHES7vesfZ88bG+5tIw6wrEPeNhsKEs6FdBTYt3Ow 2o8anAwH97IajkmaSUo8jlf8QtSgwkmEZUhUIsWx7FV1/iFx/CqErSXvE1bet4VFB9TC hOWKkzoQvPq7zsv3i1xxo2+NmQIOjzet54vmUnJzLKbdxZbhni4yhgTvb3ieWobNmmFi X794wjCUMXi0chJiYlH6wVX9Ct/zxvuSSqWkDASE0b7R5s1gtYc7//NUpvGEHQXfnhzE lCBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=ui7Ox8IF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w64-20020a638243000000b00578a2db484esi4351178pgd.248.2023.09.22.12.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:41:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=ui7Ox8IF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0D0DE820DA06; Thu, 21 Sep 2023 12:30:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230505AbjIUTaZ (ORCPT + 28 others); Thu, 21 Sep 2023 15:30:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231130AbjIUT3t (ORCPT ); Thu, 21 Sep 2023 15:29:49 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9141DAC3EB for ; Thu, 21 Sep 2023 11:01:54 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-99c3d3c3db9so160694866b.3 for ; Thu, 21 Sep 2023 11:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695319313; x=1695924113; 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=NDg1sZsypbtmVZl9501Jvjfjp7cqgNO2wWu9eDz+bAo=; b=ui7Ox8IF5Qgem4/I2L5PMc/oxrZj4rgl7jhksURNP1NKFMULGvZ9lf9joLQ3zd4Ss4 xP5AXsBvZZL3BncL1gcrHAaEGFE4SlQqxc0dhAhk4BJVgp717sb/clppOQWX5xCwWOBa DXLA3Y+t+YxHilWupSurJuUFbDbBCKTjS621wPv5Hkfxr4iQrC1jn5yeMyi1RStMIlvH IshZtNHhy937YsKTMzaPeralQ1xveBWm+p81vYRCcF6FsJ7PNdvDxQzjQIDlSXrR9V+l wL1/Q+ygYrGPoxm4i5LE3G5mJSfZeCdNZiLLAaVBq7B4viZJD3U/WNbKzonWk9uhOCrG eOnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695319313; x=1695924113; 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=NDg1sZsypbtmVZl9501Jvjfjp7cqgNO2wWu9eDz+bAo=; b=Dj3ccJDQ/ARanJsltTVik/vUvSM//uBM6BnIDG9p3OoDs7/HGqqoux+EVUMpFvXWbq buWGb+55AzeJxQNAbjs9iSgbZ/7lfp9dhHZKeZR4KVf+JE85LtKX3kWVct8RerjegMaK yWHykYq7UiDOIsNrVwV/PVS8FTFNZbgMjNLI1MPXnpibUMERz7eboJ3qQiSIu5VkW1mj X25kvmW/+mOh15ynRRgnKUQ23y6kfD8Nn00s8oRmkCCfgKXHKJbw/SgaPPW1Ix3RaqdY LQhB+i4V2wmEFlAj7n6wmnM4SzEk/rPVwIbJRGbC7I6W+mihewrKDU5vQ/A+E7itQkUb 1OOw== X-Gm-Message-State: AOJu0YwNZ8EfL/0QfEIBB4hScnvVOO/0ULuIGXnFGZZd4pv+8g0HEr8j 8y8q55x9mfilm+eulbuHAtm6NBxVC7dwPlvWn1utIR3Z X-Received: by 2002:a05:600c:2245:b0:402:906:1e87 with SMTP id a5-20020a05600c224500b0040209061e87mr5026780wmm.31.1695307461363; Thu, 21 Sep 2023 07:44:21 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:21 -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 v2 10/19] staging: iio: resolver: ad2s1210: add debugfs reg access Date: Thu, 21 Sep 2023 09:43:51 -0500 Message-Id: <20230921144400.62380-11-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:30:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777768029234334149 X-GMAIL-MSGID: 1777768029234334149 This add an implementation of debugfs_reg_access for the AD2S1210 driver. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 3c81ee61b897..b99928394e3f 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -606,9 +606,29 @@ static int ad2s1210_initial(struct ad2s1210_state *st) return ret; } +static int ad2s1210_debugfs_reg_access(struct iio_dev *indio_dev, + unsigned int reg, unsigned int writeval, + unsigned int *readval) +{ + struct ad2s1210_state *st = iio_priv(indio_dev); + int ret; + + mutex_lock(&st->lock); + + if (readval) + ret = regmap_read(st->regmap, reg, readval); + else + ret = regmap_write(st->regmap, reg, writeval); + + mutex_unlock(&st->lock); + + return ret; +} + static const struct iio_info ad2s1210_info = { .read_raw = ad2s1210_read_raw, .attrs = &ad2s1210_attribute_group, + .debugfs_reg_access = &ad2s1210_debugfs_reg_access, }; static int ad2s1210_setup_clocks(struct ad2s1210_state *st) From patchwork Thu Sep 21 14:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 142853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5083289vqi; Thu, 21 Sep 2023 12:21:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvSOHJdGWUa8AknfAvE2UQt6frRHFISnmK/hKVuxjPOjRuHbm0lUW63ZrFAdkNeR7lvtGv X-Received: by 2002:a05:6a21:6d90:b0:14d:e615:277c with SMTP id wl16-20020a056a216d9000b0014de615277cmr612647pzb.11.1695324102652; Thu, 21 Sep 2023 12:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695324102; cv=none; d=google.com; s=arc-20160816; b=rS4PFzWROImAsq3y/7wUuu+kwAf5dTIlSrX/vpuB1gR2DKcA11aoR1xPHPZOu269jY lXoOKDYt1SC+FmjuYtVhs8NcK9FYwCZPucdg8GIni/qH/5NNF9QlwaD9YC9jdgwUYgnZ fMBZrDNnd6mEVxZlJn26WpH2jmGOCsZmKe+EDbf/ecpah3mVAzuHnKYifBcsB3NhZ9+9 SP7uyYLCkX0Z5SOorIvNNZ5SgLvOI4jJdn8Q2UqS5f45hveIMsz/5X5VMZv/Wgs5h2QY KuDiQpFY54R+4s+8cUH6TneK0A/8D9RWynSrrP6HdvFdp83TyyaoW+gg3MFg+MUTsnEi Qb5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T9WVKxDU/WCTxqQ52/M5ua8wasfSRRcZpI1eeblkSC8=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=rmAIfY/0/QuEPNGTjmhWpheX9Rf16rfStn3aBjIrKz5f8sqU1m5Xr1waVTFSAjzTYS /ZCV67UshY1vxJxesRBOUQVbPm6K2935xEZ/WkMXt+e1WQX2qvJ+ip2tB1CW3G3MdgL8 yMQ+K28qZRYZodzS4c1KNPzkPzDokTmhl8f+Usm2hfOrBo6iRdZte9LNbnqpKoxMMQ61 BXtXsxiuEDDpMnGKXiugc+UUxSlX3D0kOufTiloHuYGmEbUizN8GCje1sa3m1fazh3L5 El8EMzhzTkHdZrwb5OV2OBxDmnmkpGD+HdasAFs3/xur/IYw9fMnfZ5fHlmMDW2YXbLS Q23w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=YHRnfXMh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id a2-20020a056a000c8200b0064f78c32b89si2198369pfv.95.2023.09.21.12.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 12:21:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=YHRnfXMh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D646E812E00F; Thu, 21 Sep 2023 12:02:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231150AbjIUTBp (ORCPT + 28 others); Thu, 21 Sep 2023 15:01:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjIUTBS (ORCPT ); Thu, 21 Sep 2023 15:01:18 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 298108A83C for ; Thu, 21 Sep 2023 10:41:00 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-32155a45957so1268433f8f.0 for ; Thu, 21 Sep 2023 10:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318058; x=1695922858; 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=T9WVKxDU/WCTxqQ52/M5ua8wasfSRRcZpI1eeblkSC8=; b=YHRnfXMhVBk2dvvmkqmAOc1C4QYUs0kKnOkjW+E8mLcmyFl36HQjoh9GgkL3P8vUzO HWZSgoyKC0Ufvoia0cmNKgulSRNWvSNRnJ8UhKAiUpSJOS1lnYtesZ+VH0+XQLE5bQ2u OHIukkHUmrgx3j0j0XrAScdodoKsKKg0uu7qPtL6Tn+M4z30KGTy4lBC+ZeGxY8H5zJQ VL4Ye11HaycTBGVmrzTNbA5B6cN1mR41dci9VNugZxqlJL9+xFYAUgZP3EVR82f9dEuw xxnnyLd94qYjlLIrcOiPnka8LDuljtmaWlmOp7W3DcJsyQYlsYSPtXJpcLYnqcSbPVgu FMtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318058; x=1695922858; 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=T9WVKxDU/WCTxqQ52/M5ua8wasfSRRcZpI1eeblkSC8=; b=sneitSQV8TVZbvGUIUQxV+xDXfIGNHoAYXDiSqzXWNNLH1bbj3QtaUcGz7w8yONiJk fvuKGV9KIRMCEUk4bWkultP13318jrDCNJy22cG6jlwoGQ5ur20+BGu74VCPFVaBhVVW TVD6Y2rl1dlnbyHb/7Xufcsi0OKivQWObMYHARd9OkdXFkgenSX1ZolCvt3Pw9Ctu3Ji AGtPwplIcRNTTTZHkrWmIBNpk0bHQZNOppu3qNtGM1QPrudGvrmglwhk08/qqHXWU84y oMptoEqI2A1d6PMxSbOzXWo4pu1aWCYAUaJOPTZPbrMeCJjaNv6PSzj5Y3YD3UV+WCHA MTeg== X-Gm-Message-State: AOJu0YzSFANDVhcxefla/a9AUeak8zPwNsyvYMk/NESOFsDgQxDqqYs6 Mv94ZxTJGYRWjnbibiWQJsfI+aNQUg3aqmnd+jKuo0HS X-Received: by 2002:a5d:500d:0:b0:317:58e4:e941 with SMTP id e13-20020a5d500d000000b0031758e4e941mr5405435wrt.33.1695307462223; Thu, 21 Sep 2023 07:44:22 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:21 -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 v2 11/19] staging: iio: resolver: ad2s1210: remove config attribute Date: Thu, 21 Sep 2023 09:43:52 -0500 Message-Id: <20230921144400.62380-12-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:02:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777676165929516098 X-GMAIL-MSGID: 1777676165929516098 This removes the config register sysfs attribute. Writing to the config register directly can be dangerous and userspace should not need to have to know the register layout. This register can still be accessed though debugfs if needed. We can add new attributes to set specific flags in the config register in the future if needed (e.g. `enable_hysterisis` and `phase_lock_range`). Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 47 ------------------------- 1 file changed, 47 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index b99928394e3f..223cc4702188 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -269,50 +269,6 @@ static ssize_t ad2s1210_store_fexcit(struct device *dev, return ret < 0 ? ret : len; } -static ssize_t ad2s1210_show_control(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - unsigned int value; - int ret; - - mutex_lock(&st->lock); - ret = regmap_read(st->regmap, AD2S1210_REG_CONTROL, &value); - mutex_unlock(&st->lock); - return ret < 0 ? ret : sprintf(buf, "0x%x\n", value); -} - -static ssize_t ad2s1210_store_control(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - unsigned char udata; - unsigned char data; - int ret; - - ret = kstrtou8(buf, 16, &udata); - if (ret) - return -EINVAL; - - mutex_lock(&st->lock); - data = udata & ~AD2S1210_ADDRESS_DATA; - ret = regmap_write(st->regmap, AD2S1210_REG_CONTROL, data); - if (ret < 0) - goto error_ret; - - st->resolution = - ad2s1210_resolution_value[data & AD2S1210_SET_RES]; - ad2s1210_set_resolution_pin(st); - ret = len; - st->hysteresis = !!(data & AD2S1210_ENABLE_HYSTERESIS); - -error_ret: - mutex_unlock(&st->lock); - return ret; -} - static ssize_t ad2s1210_show_resolution(struct device *dev, struct device_attribute *attr, char *buf) @@ -519,8 +475,6 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, static IIO_DEVICE_ATTR(fexcit, 0644, ad2s1210_show_fexcit, ad2s1210_store_fexcit, 0); -static IIO_DEVICE_ATTR(control, 0644, - ad2s1210_show_control, ad2s1210_store_control, 0); static IIO_DEVICE_ATTR(bits, 0644, ad2s1210_show_resolution, ad2s1210_store_resolution, 0); static IIO_DEVICE_ATTR(fault, 0644, @@ -566,7 +520,6 @@ static const struct iio_chan_spec ad2s1210_channels[] = { static struct attribute *ad2s1210_attributes[] = { &iio_dev_attr_fexcit.dev_attr.attr, - &iio_dev_attr_control.dev_attr.attr, &iio_dev_attr_bits.dev_attr.attr, &iio_dev_attr_fault.dev_attr.attr, &iio_dev_attr_los_thrd.dev_attr.attr, From patchwork Thu Sep 21 14:43:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5326824vqi; Thu, 21 Sep 2023 22:01:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDT65pwJCgJVvUmUdPym4B7yBoERFm+ZkvcCsaHvqnIl9FBHBPUkrYKpjvQayigTkrVzdn X-Received: by 2002:a17:902:d504:b0:1c1:d5d1:a364 with SMTP id b4-20020a170902d50400b001c1d5d1a364mr2680667plg.33.1695358861102; Thu, 21 Sep 2023 22:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695358861; cv=none; d=google.com; s=arc-20160816; b=1BY/yG0EhhcJuD8esa3NYcOchMZ4N6ujEM+RDOGq1ja07u6DK7p0FpT6xVmG07Gozd QpCpzBGO/rh3QXYTwczEUYfArX4Auj/kRqow6a8w4lFBhGZtjECJngx5pJBImwKCVnW8 an9dDqOWPHQeAx8WVOhalS7usUELmc1dklSPjbBJWy+K5OcMmie4Qtf9j95/MOOFJwTH AetzV2INfyR7JXVOcC+z0pH873uKM33T3g4T7FH+ai+l3pjuT8YVqVsEZB8Tu4P0YDCJ 3BLoCPIfikbu29k9sC/nTmBtUIBB6NMJEaf9uF8QVaaFf2YqhvzStKufOadmKyljh3km sF9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xoiF1sc5Yv1hjuRdgeGOkvi9X2NDURf5lh9dRaGmJUM=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=CL9GpiI7lpayhbWapPBcytUlgTAl7QqtmacBqaD6BWb0AxHQ8akaFJ1KrlV53CSmcn snkO9iQ6uDemY0PRJ25hYJCOiUWcNcF2kDQs5I5fpML2OBcgrVAEsfIuSUOnQns5QlZ1 JauBVTiKg4c0tO5Op9MjRZNaZBUpC9RdNwUQNT/bJGGqAF6EyKb2Iolr2DnwY1lnbp4R fwbLycCKe0LT3E/v+d4NMKSTtq8xGObFyrewIvEbSmY5bBesTbe5dqbpN9nBXNToS+pk siDY8AaAi/5tvK7iH1e8kmas3sLxBq2Z5py70gkCOO3JWnChcrnvj8Vrb1QYr5LBAPE9 f3Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=oELGhuow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id j10-20020a170902da8a00b001c563263222si3162926plx.376.2023.09.21.22.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 22:01:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=oELGhuow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id DDC80838EFC0; Thu, 21 Sep 2023 13:59:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231719AbjIUU7H (ORCPT + 29 others); Thu, 21 Sep 2023 16:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232299AbjIUU6n (ORCPT ); Thu, 21 Sep 2023 16:58:43 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E599AECC5 for ; Thu, 21 Sep 2023 11:06:12 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-32008e339adso1260792f8f.2 for ; Thu, 21 Sep 2023 11:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695319571; x=1695924371; 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=xoiF1sc5Yv1hjuRdgeGOkvi9X2NDURf5lh9dRaGmJUM=; b=oELGhuowt3RAg1V+VVLrU/8nFUATbP/7CT9ycBfnw8mhtBh89EjnxJVZ29Si1lCz+0 v0JNxBH/QhTRwwYruxWGnPZuWAfyqT/lAp08yDi+rnuHjVRHMrdJiu9tOpCCQuEHGH/H 639iJZ5p3EibmV72VazbHjm0lH5AD7yofcw1eRAFTujCN4MOXCoZFm4jEL+gG1eMe21U XbWdeAHH9fOExOuZvW9mg0ijn3H0fhfjSjoD7pS5EVUWKUGpF6I+kXzZ0GTAZWMvDi1f r+iL2533c6wMTO4A/eo2YmQmdpGf6RTY1ojox4VRVgdhoROIef0F/Fzadp66GBqh9+Sy 50kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695319571; x=1695924371; 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=xoiF1sc5Yv1hjuRdgeGOkvi9X2NDURf5lh9dRaGmJUM=; b=MwVKh6lS/lQyIZyckI9Kh/WFb1b2DTslqVU07i6zVkgNTADUA10Ov6Uaw3NYwkVTu6 tr2mSsTImMCL3HVUDHpQJz/iPtL+2Vl54mAawVSLsfjQeRZaBCdi9HMt6oH7XorHt/ag aGOr73WukoTffJz/z8YVg8bZAvId4ZJofLFBlXvhcgID/Ip1fZQtIjerEoXMLWrj/IS0 nd46AyIFABJnLmxqdo5Z/rdUtiTRn6EOhOQOp2TTgwk4ZULpwoBD5no5Xs89j6x6DD+P 60LftmGHC0aUlUVuO9eJOJ+8f0E0iQsaLbXZ1xQdpj4wmlBKxg8VyuYKptj2d9zNUL4E erUQ== X-Gm-Message-State: AOJu0YzD71Cu+41OrNidLXudJIGWybEyOD6AM1l3xtEDLPcW64c01LX2 aTYeClSUXCDrtRUeDKFLsFC7s5oBmMXrWHU1KR1wtazS X-Received: by 2002:a05:600c:22ce:b0:401:b493:f7c1 with SMTP id 14-20020a05600c22ce00b00401b493f7c1mr5204399wmg.35.1695307463044; Thu, 21 Sep 2023 07:44:23 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:22 -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 v2 12/19] staging: iio: resolver: ad2s1210: rework gpios Date: Thu, 21 Sep 2023 09:43:53 -0500 Message-Id: <20230921144400.62380-13-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:59:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777712613150466718 X-GMAIL-MSGID: 1777712613150466718 - Remove "adi," prefix from gpio names. - Sample gpio is now expected to be active low. - Convert A0 and A1 gpios to "mode-gpios" gpio array. - Convert RES0 and RES1 gpios to "resolution-gpios" gpio array. - Remove extraneous lookup tables. - Remove unused mode field from state struct. - Swap argument order of ad2s1210_set_mode() while we are touching this. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 162 ++++++++++++------------ 1 file changed, 84 insertions(+), 78 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 223cc4702188..7a1069d948eb 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -60,39 +60,21 @@ #define AD2S1210_DEF_EXCIT 10000 enum ad2s1210_mode { - MOD_POS = 0, - MOD_VEL, - MOD_CONFIG, - MOD_RESERVED, + MOD_POS = 0b00, + MOD_VEL = 0b01, + MOD_RESERVED = 0b10, + MOD_CONFIG = 0b11, }; -enum ad2s1210_gpios { - AD2S1210_SAMPLE, - AD2S1210_A0, - AD2S1210_A1, - AD2S1210_RES0, - AD2S1210_RES1, -}; - -struct ad2s1210_gpio { - const char *name; - unsigned long flags; -}; - -static const struct ad2s1210_gpio gpios[] = { - [AD2S1210_SAMPLE] = { .name = "adi,sample", .flags = GPIOD_OUT_LOW }, - [AD2S1210_A0] = { .name = "adi,a0", .flags = GPIOD_OUT_LOW }, - [AD2S1210_A1] = { .name = "adi,a1", .flags = GPIOD_OUT_LOW }, - [AD2S1210_RES0] = { .name = "adi,res0", .flags = GPIOD_OUT_LOW }, - [AD2S1210_RES1] = { .name = "adi,res1", .flags = GPIOD_OUT_LOW }, -}; - -static const unsigned int ad2s1210_resolution_value[] = { 10, 12, 14, 16 }; - struct ad2s1210_state { struct mutex lock; struct spi_device *sdev; - struct gpio_desc *gpios[5]; + /** GPIO pin connected to SAMPLE line. */ + struct gpio_desc *sample_gpio; + /** GPIO pins connected to A0 and A1 lines. */ + struct gpio_descs *mode_gpios; + /** GPIO pins connected to RES0 and RES1 lines. */ + struct gpio_descs *resolution_gpios; /** Used to access config registers. */ struct regmap *regmap; /** The external oscillator frequency in Hz. */ @@ -100,23 +82,19 @@ struct ad2s1210_state { unsigned int fexcit; bool hysteresis; u8 resolution; - enum ad2s1210_mode mode; u8 rx[2] __aligned(IIO_DMA_MINALIGN); u8 tx[2]; }; -static const int ad2s1210_mode_vals[4][2] = { - [MOD_POS] = { 0, 0 }, - [MOD_VEL] = { 0, 1 }, - [MOD_CONFIG] = { 1, 1 }, -}; - -static inline void ad2s1210_set_mode(enum ad2s1210_mode mode, - struct ad2s1210_state *st) +static int ad2s1210_set_mode(struct ad2s1210_state *st, enum ad2s1210_mode mode) { - gpiod_set_value(st->gpios[AD2S1210_A0], ad2s1210_mode_vals[mode][0]); - gpiod_set_value(st->gpios[AD2S1210_A1], ad2s1210_mode_vals[mode][1]); - st->mode = mode; + struct gpio_descs *gpios = st->mode_gpios; + DECLARE_BITMAP(bitmap, 2); + + bitmap[0] = mode; + + return gpiod_set_array_value(gpios->ndescs, gpios->desc, gpios->info, + bitmap); } /* @@ -141,6 +119,7 @@ static int ad2s1210_regmap_reg_write(void *context, unsigned int reg, .tx_buf = &st->tx[1], }, }; + int ret; /* values can only be 7 bits, the MSB indicates an address */ if (val & ~0x7F) @@ -149,7 +128,9 @@ static int ad2s1210_regmap_reg_write(void *context, unsigned int reg, st->tx[0] = reg; st->tx[1] = val; - ad2s1210_set_mode(MOD_CONFIG, st); + ret = ad2s1210_set_mode(st, MOD_CONFIG); + if (ret < 0) + return ret; return spi_sync_transfer(st->sdev, xfers, ARRAY_SIZE(xfers)); } @@ -178,7 +159,10 @@ static int ad2s1210_regmap_reg_read(void *context, unsigned int reg, }; int ret; - ad2s1210_set_mode(MOD_CONFIG, st); + ret = ad2s1210_set_mode(st, MOD_CONFIG); + if (ret < 0) + return ret; + st->tx[0] = reg; /* Must be valid register address here otherwise this could write data. * It doesn't matter which one. @@ -215,16 +199,16 @@ int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st) return regmap_write(st->regmap, AD2S1210_REG_EXCIT_FREQ, fcw); } -static const int ad2s1210_res_pins[4][2] = { - { 0, 0 }, {0, 1}, {1, 0}, {1, 1} -}; - -static inline void ad2s1210_set_resolution_pin(struct ad2s1210_state *st) +static int ad2s1210_set_resolution_gpios(struct ad2s1210_state *st, + u8 resolution) { - gpiod_set_value(st->gpios[AD2S1210_RES0], - ad2s1210_res_pins[(st->resolution - 10) / 2][0]); - gpiod_set_value(st->gpios[AD2S1210_RES1], - ad2s1210_res_pins[(st->resolution - 10) / 2][1]); + struct gpio_descs *gpios = st->resolution_gpios; + DECLARE_BITMAP(bitmap, 2); + + bitmap[0] = (resolution - 10) >> 1; + + return gpiod_set_array_value(gpios->ndescs, gpios->desc, gpios->info, + bitmap); } static inline int ad2s1210_soft_reset(struct ad2s1210_state *st) @@ -301,10 +285,13 @@ static ssize_t ad2s1210_store_resolution(struct device *dev, if (ret < 0) goto error_ret; - st->resolution = - ad2s1210_resolution_value[data & AD2S1210_SET_RES]; - ad2s1210_set_resolution_pin(st); + ret = ad2s1210_set_resolution_gpios(st, udata); + if (ret < 0) + goto error_ret; + + st->resolution = udata; ret = len; + error_ret: mutex_unlock(&st->lock); return ret; @@ -335,15 +322,19 @@ static ssize_t ad2s1210_clear_fault(struct device *dev, int ret; mutex_lock(&st->lock); - gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); + + gpiod_set_value(st->sample_gpio, 1); /* delay (2 * tck + 20) nano seconds */ udelay(1); - gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); + gpiod_set_value(st->sample_gpio, 0); + ret = regmap_read(st->regmap, AD2S1210_REG_FAULT, &value); if (ret < 0) goto error_ret; - gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); - gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); + + gpiod_set_value(st->sample_gpio, 1); + gpiod_set_value(st->sample_gpio, 0); + error_ret: mutex_unlock(&st->lock); @@ -404,16 +395,16 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: mutex_lock(&st->lock); - gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); + gpiod_set_value(st->sample_gpio, 1); /* delay (6 * tck + 20) nano seconds */ udelay(1); switch (chan->type) { case IIO_ANGL: - ad2s1210_set_mode(MOD_POS, st); + ret = ad2s1210_set_mode(st, MOD_POS); break; case IIO_ANGL_VEL: - ad2s1210_set_mode(MOD_VEL, st); + ret = ad2s1210_set_mode(st, MOD_VEL); break; default: ret = -EINVAL; @@ -440,7 +431,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, } error_info_raw: - gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); + gpiod_set_value(st->sample_gpio, 0); /* delay (2 * tck + 20) nano seconds */ udelay(1); mutex_unlock(&st->lock); @@ -542,7 +533,9 @@ static int ad2s1210_initial(struct ad2s1210_state *st) int ret; mutex_lock(&st->lock); - ad2s1210_set_resolution_pin(st); + ret = ad2s1210_set_resolution_gpios(st, st->resolution); + if (ret < 0) + return ret; data = AD2S1210_DEF_CONTROL & ~AD2S1210_SET_RES; data |= (st->resolution - 10) >> 1; @@ -604,20 +597,34 @@ static int ad2s1210_setup_clocks(struct ad2s1210_state *st) static int ad2s1210_setup_gpios(struct ad2s1210_state *st) { - struct spi_device *spi = st->sdev; - int i, ret; - - for (i = 0; i < ARRAY_SIZE(gpios); i++) { - st->gpios[i] = devm_gpiod_get(&spi->dev, gpios[i].name, - gpios[i].flags); - if (IS_ERR(st->gpios[i])) { - ret = PTR_ERR(st->gpios[i]); - dev_err(&spi->dev, - "ad2s1210: failed to request %s GPIO: %d\n", - gpios[i].name, ret); - return ret; - } - } + struct device *dev = &st->sdev->dev; + + /* should not be sampling on startup */ + st->sample_gpio = devm_gpiod_get(dev, "sample", GPIOD_OUT_LOW); + if (IS_ERR(st->sample_gpio)) + return dev_err_probe(dev, PTR_ERR(st->sample_gpio), + "failed to request sample GPIO\n"); + + /* both pins high means that we start in config mode */ + st->mode_gpios = devm_gpiod_get_array(dev, "mode", GPIOD_OUT_HIGH); + if (IS_ERR(st->mode_gpios)) + return dev_err_probe(dev, PTR_ERR(st->mode_gpios), + "failed to request mode GPIOs\n"); + + if (st->mode_gpios->ndescs != 2) + return dev_err_probe(dev, -EINVAL, + "requires exactly 2 mode-gpios\n"); + + /* both pins high means that we start with 16-bit resolution */ + st->resolution_gpios = devm_gpiod_get_array(dev, "resolution", + GPIOD_OUT_HIGH); + if (IS_ERR(st->resolution_gpios)) + return dev_err_probe(dev, PTR_ERR(st->resolution_gpios), + "failed to request resolution GPIOs\n"); + + if (st->resolution_gpios->ndescs != 2) + return dev_err_probe(dev, -EINVAL, + "requires exactly 2 resolution-gpios\n"); return 0; } @@ -683,7 +690,6 @@ static int ad2s1210_probe(struct spi_device *spi) mutex_init(&st->lock); st->sdev = spi; st->hysteresis = true; - st->mode = MOD_CONFIG; st->resolution = 12; st->fexcit = AD2S1210_DEF_EXCIT; From patchwork Thu Sep 21 14:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 142869 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5099362vqi; Thu, 21 Sep 2023 12:53:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEn+VgnWSR+RhkYOHArCxT6itMAKghzjmZco+LSLGgAPzMkSmfAh1KRIrItkG8QkuxLpGOW X-Received: by 2002:a05:6a20:3d89:b0:158:7fdf:66df with SMTP id s9-20020a056a203d8900b001587fdf66dfmr7699169pzi.18.1695326010332; Thu, 21 Sep 2023 12:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695326010; cv=none; d=google.com; s=arc-20160816; b=jXw/AMyFxamHkrx+JOpeVkL5EsCpQL0DN9IPH9K8Gs8TIfZQ3LnCwSketb9xauINEc FklweEGJQTumrn0CDtWjgJldeXZfBSSw4zYpj9PASshy+ClyJAaRURc+D17rRIW8tS3T XNXUTgLnDrtPEuJvNuDbjfWjR2eBu4MeDSS1OG8RsAQVgUPo6ycV7JJc4RnrXA4EXtO4 tGRrR7KqtaB9I+BPmXo2IezKGoYbDbbfsLrmEHYK3WTCK4VjJKfDTUcdl3bxp5YxU+W1 RP3uctg2BuE7K41G2jZ55J9gIWC7uvA791IQJS0nxnJxJ38UzayO0ORQRejThuzrmjuZ 2sww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AZybWEnlutF3BnUcq+xH7uoi35RICanW/277eMaA8Sc=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=TOY5VSYMCqQk5Ab4tVPuQfYwI4wdmyQoLXlbL+VwlNves68GMvWcFlY0oiphkoKOhV oYM16HoTqCjcwxCDWgws9op4C9Q2Jugs8tAlr6iIt8tW59CF5+SyAIrMgFJkqlRaKPbp Ps0THiPXG9hAFrrf5s4ozbf2Xkmrr8d39d6NPBv7CbDH9voPG+3xS0LMUI1leQ8w1GGf zPNbpRB466Szv7VB56DKAxZNZCniC7lg3atonGKbg1vTvrPors0s5myuhat/oKuuvJ0y wPmCi3iUWgEAv/me9dZSGCQAxJzH/XNXdVxQ09SngB9wMTpCG9aVt7kXOcrHxPleNvzb BVbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=Wa+0TJfS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id cg19-20020a056a00291300b0068fc080f79dsi2122020pfb.122.2023.09.21.12.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 12:53:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=Wa+0TJfS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id CC86981D2B76; Thu, 21 Sep 2023 10:29:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbjIUR2z (ORCPT + 29 others); Thu, 21 Sep 2023 13:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbjIUR2C (ORCPT ); Thu, 21 Sep 2023 13:28:02 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F45A15A1A for ; Thu, 21 Sep 2023 10:11:40 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-502e7d66c1eso2090880e87.1 for ; Thu, 21 Sep 2023 10:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316297; x=1695921097; 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=AZybWEnlutF3BnUcq+xH7uoi35RICanW/277eMaA8Sc=; b=Wa+0TJfSg/UDK+AC2TyH9GbNsYbpjZ9R1OPFodTI8y/QyRWWKKflfq3FAIij7Fk39H HlD3VIUBo49Q01QPS7P4nCvvaX0NaQcIvUqfXg6foGCSs8fOnvx8Me8ErmZaf/B3QEzH VlCzRxDgXHwdRhAWapJN76SssJhnTCpnx+DyEe9zGI4qI+E8VxXMx+arIIAKwfMyvyKo pMNn59bl63jroONgue0/wSazS2GCfJ65+hRpI3Z7AlgE+6SiYokBM5+IbdQnyzhCP/cz F78drs9bMNDlv6VHG9+0rlH4ifkdt1KBWXSybDtMrTk1y3caLuDEMjL+a6jKagNQEbfl evhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316297; x=1695921097; 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=AZybWEnlutF3BnUcq+xH7uoi35RICanW/277eMaA8Sc=; b=oJs47N9d2XnKKjb8vtdf2UUqZ22TQShEzsNH4napJPY2fBhkqtuXgX89EBSs8OV357 xwSPtIA0SNPV7Pwe+Z+rtk57iGVsxo3qX40bMeK+gipF6U1G7cuTo909ea9INC3+GCQn 71W3Wkl6HuvvZZmk4fHUTQWh4+wSG3iGW7ZtdT7QK1sKzxk/xIEdP0pl3i2bHRXVbkkh l3SGtmJTDLid4vkGQNiZR5UFuo6MvorPQ0sSeVrBgkcc6kKScxuc9/pdgX8l4yaSpoEV IpsPjc/IrD6S75Pn2vgn2JxT/ur0plEySR4QIfqbzutCJAsuhUO+hTwtmMmAL389IaLG DyPg== X-Gm-Message-State: AOJu0Yw6CSsJ+XIf/iEcfWLIp4qd05qVtiFD+0oNTZWoOB3aSkpOAHes C/g5WVj5e6ofBK+GCsq4wQF3/pxLO6e8gL0e2KhhVDNs X-Received: by 2002:a05:600c:2312:b0:3fe:d71a:d84e with SMTP id 18-20020a05600c231200b003fed71ad84emr5046284wmo.1.1695307464020; Thu, 21 Sep 2023 07:44:24 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:23 -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 v2 13/19] staging: iio: resolver: ad2s1210: implement hysteresis as channel attr Date: Thu, 21 Sep 2023 09:43:54 -0500 Message-Id: <20230921144400.62380-14-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 21 Sep 2023 10:29:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777678166502488610 X-GMAIL-MSGID: 1777678166502488610 The AD2S1210 resolver has a hysteresis feature that can be used to prevent flicker in the LSB of the position register. This can be either enabled or disabled. Disabling hysteresis is useful for increasing precision by oversampling. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 88 ++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 7a1069d948eb..fe413759deb9 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -80,7 +80,6 @@ struct ad2s1210_state { /** The external oscillator frequency in Hz. */ unsigned long fclkin; unsigned int fexcit; - bool hysteresis; u8 resolution; u8 rx[2] __aligned(IIO_DMA_MINALIGN); u8 tx[2]; @@ -456,6 +455,27 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, } break; + case IIO_CHAN_INFO_HYSTERESIS: + switch (chan->type) { + case IIO_ANGL: + mutex_lock(&st->lock); + ret = regmap_test_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_ENABLE_HYSTERESIS); + if (ret < 0) + goto error_info_hysteresis; + + *val = !!ret; + ret = IIO_VAL_INT; + +error_info_hysteresis: + mutex_unlock(&st->lock); + break; + default: + ret = -EINVAL; + break; + } + break; + default: ret = -EINVAL; break; @@ -464,6 +484,64 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, return ret; } +static int ad2s1210_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, + int *length, long mask) +{ + static const int available[] = { 0, 1 }; + int ret = -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_HYSTERESIS: + switch (chan->type) { + case IIO_ANGL: + *vals = available; + *type = IIO_VAL_INT; + *length = ARRAY_SIZE(available); + ret = IIO_AVAIL_LIST; + break; + default: + break; + } + default: + break; + } + + return ret; +} + +static int ad2s1210_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct ad2s1210_state *st = iio_priv(indio_dev); + int ret = -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_HYSTERESIS: + switch (chan->type) { + case IIO_ANGL: + mutex_lock(&st->lock); + ret = regmap_update_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_ENABLE_HYSTERESIS, + val ? AD2S1210_ENABLE_HYSTERESIS + : 0); + mutex_unlock(&st->lock); + break; + + default: + break; + } + break; + + default: + break; + } + + return ret; +} + static IIO_DEVICE_ATTR(fexcit, 0644, ad2s1210_show_fexcit, ad2s1210_store_fexcit, 0); static IIO_DEVICE_ATTR(bits, 0644, @@ -499,7 +577,10 @@ static const struct iio_chan_spec ad2s1210_channels[] = { .indexed = 1, .channel = 0, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE), + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_HYSTERESIS), + .info_mask_separate_available = + BIT(IIO_CHAN_INFO_HYSTERESIS), }, { .type = IIO_ANGL_VEL, .indexed = 1, @@ -573,6 +654,8 @@ static int ad2s1210_debugfs_reg_access(struct iio_dev *indio_dev, static const struct iio_info ad2s1210_info = { .read_raw = ad2s1210_read_raw, + .read_avail = ad2s1210_read_avail, + .write_raw = ad2s1210_write_raw, .attrs = &ad2s1210_attribute_group, .debugfs_reg_access = &ad2s1210_debugfs_reg_access, }; @@ -689,7 +772,6 @@ static int ad2s1210_probe(struct spi_device *spi) mutex_init(&st->lock); st->sdev = spi; - st->hysteresis = true; st->resolution = 12; st->fexcit = AD2S1210_DEF_EXCIT; From patchwork Thu Sep 21 14:43:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5334733vqi; Thu, 21 Sep 2023 22:22:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEc4IJA0fJRmnmCqIVXE8Sx73V4KaEboizXpWgmP089cJujR8VB1sNG7co3qH40D1f5fSWa X-Received: by 2002:a17:903:44a:b0:1bb:25bd:d09c with SMTP id iw10-20020a170903044a00b001bb25bdd09cmr6382284plb.1.1695360143563; Thu, 21 Sep 2023 22:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695360143; cv=none; d=google.com; s=arc-20160816; b=pUWFt12u7e2eOGvT/UlNlZxhM8agKlm87BPxEEh89CaF1m3uGUANzHkSQ/54aKAItP VLCXjEFerXxk1cb91RIaXV9dDBkRm7xjsMoNloBNbkqB7kuLNx+sJ3nkSnu1tt2E7Ckb JiwwWBQZi2/7DwBcUiwf6R+52nB3H7tfIDlAFEvlDs11ldNrdbiwVRR3StNx73eC6//w 2Z3pchGuQg38O1ClKGw2hCdn6w7lRgsvQQv94lQmJryLALWxDKxHx8weVozfi0qNOluc QUh5QWCue88UODIS9095Aqi5HPRYrxPvieJ2TjraJgj0QLakv/63zCaH46t3oUzyaU6j bLQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lWgDNsrrXF5syWEsVgdKbxr1ASE09oFAZQly/Ty6i74=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=KOpCcNV6j9iTZ27CTjWaCDIdMX1O3RrazUel0O6z0DH8olc3oCuQ4uCo/ZT2KlS+I0 JGX/9bmOLiau+Jr7S2i/R8tbzydSExWGRwqGBVCX0FwZxFooaCJBGM5K5iDqlI46Xyql aYZdlXiD5wjOTGO5QeIUlCizavdkRU8n8tZzuhy4O2AjhhKTpE3uDvLenm/a9oTZv7aB BMvCf/wWRc9WD28lT22TiXIrb5UmwcTbY2UGhzFIC/2XlZysgvi4UwLs+TlHczXvl012 bkstvmB/aQRdfqElDvtmO+l1c9C6qPHEPhscGb3zXrncrwUSYNkh4/xRKLW2auhacADg p8tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=uqTYfFEe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id o9-20020a170903210900b001c43fce9c7asi2836447ple.444.2023.09.21.22.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 22:22:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=uqTYfFEe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id C93968313D10; Thu, 21 Sep 2023 09:59:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbjIUQ7m (ORCPT + 29 others); Thu, 21 Sep 2023 12:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjIUQ7g (ORCPT ); Thu, 21 Sep 2023 12:59:36 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D38971FD7 for ; Thu, 21 Sep 2023 09:58:52 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2bffc55af02so20982981fa.2 for ; Thu, 21 Sep 2023 09:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695315526; x=1695920326; 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=lWgDNsrrXF5syWEsVgdKbxr1ASE09oFAZQly/Ty6i74=; b=uqTYfFEeeWgBsPBStdNoN6apMlc4EyrOu2AbgpXVG4DcUx9ILbxXSOwXzWM+PPzlC6 ub+ecZiA98fguJ3K6NHrGtHFV8IjM0kA8iBvcp6A7NOEi86ZQIg+0AGOfCYYe3YrXT/n Bv35QgNrfgOjoYWPbr6cXj8TlXSmG7QbuwptozoSmQ0wluy65JKlaf4PVvIk9Cc6Kzgf 2NZdiAdOhr4M6jHxBZobLTnCeg34hKX172wpU68rt/S7CiU+1QLJMx1opmc+k6F0rPor CBCeLqRp+kICmN0PaCZ7iVLdiQiA1NfUJBcTLL0xQZinJ5JgY7QFx7pZxrMKfK9ac9fc sDcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695315526; x=1695920326; 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=lWgDNsrrXF5syWEsVgdKbxr1ASE09oFAZQly/Ty6i74=; b=rTqGW5p5ZMk9rphJzV4YVQeWyt0yIeqg/QlKlCnRJ5qnv1KxYTCN1k1PTvRPlSvyXO uQe/jPrlBBCJOy15Z0YhHUVWVRQBpjuIGZ+Hjsdc0SbELFntKl3P5qNb/uQgNPy2qoHP 8Wd1NXguIlBGHjdu+SPcgrA0gzWW02Ywn3jMOOYDteZiKkbXmBLIoXyiRBMO/N2jfN9v nS4ihZDTbzgc893OoyPciJ3HyZ2aIwsKQoby7rrGjRU66HIO7AlJUnJsuHC6ZwnmLi42 FLPft6Tv/T2bH7OZzWqV+jF/XbaFnimxoFY3WH+UZU6EBlYPxJ8+V8N7DA86a2yfoFnX 0kuA== X-Gm-Message-State: AOJu0Yx9DbhdxLnn1cpqS6r0zBkId4900uZ7ZNj/fcLknQMLRvBPuAO/ igYSbI2SnNilHwMevUSzqLOaIL4wxJBwfOoxrPzdtKE7 X-Received: by 2002:a1c:7718:0:b0:401:d803:6242 with SMTP id t24-20020a1c7718000000b00401d8036242mr5422512wmi.27.1695307464880; Thu, 21 Sep 2023 07:44:24 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:24 -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 v2 14/19] staging: iio: resolver: ad2s1210: refactor setting excitation frequency Date: Thu, 21 Sep 2023 09:43:55 -0500 Message-Id: <20230921144400.62380-15-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 09:59:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777713957763744949 X-GMAIL-MSGID: 1777713957763744949 This combines the ad2s1210_update_frequency_control_word() and ad2s1210_soft_reset() functions into a single function since they both have to be called together. Also clean up a few things while touching this: - move AD2S1210_DEF_EXCIT macro with similar macros - remove unnecessary dev_err() calls Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 63 ++++++++++++------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index fe413759deb9..f1ffee34ebbc 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -53,12 +53,11 @@ #define AD2S1210_MIN_CLKIN 6144000 #define AD2S1210_MAX_CLKIN 10240000 #define AD2S1210_MIN_EXCIT 2000 +#define AD2S1210_DEF_EXCIT 10000 #define AD2S1210_MAX_EXCIT 20000 #define AD2S1210_MIN_FCW 0x4 #define AD2S1210_MAX_FCW 0x50 -#define AD2S1210_DEF_EXCIT 10000 - enum ad2s1210_mode { MOD_POS = 0b00, MOD_VEL = 0b01, @@ -184,18 +183,29 @@ static int ad2s1210_regmap_reg_read(void *context, unsigned int reg, return 0; } -static inline -int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st) +/* + * Sets the excitation frequency and performs software reset. + * + * Must be called with lock held. + */ +static int ad2s1210_set_excitation_frequency(struct ad2s1210_state *st, + u16 fexcit) { - unsigned char fcw; + int ret; + u8 fcw; - fcw = (unsigned char)(st->fexcit * (1 << 15) / st->fclkin); - if (fcw < AD2S1210_MIN_FCW || fcw > AD2S1210_MAX_FCW) { - dev_err(&st->sdev->dev, "ad2s1210: FCW out of range\n"); + fcw = fexcit * (1 << 15) / st->fclkin; + if (fcw < AD2S1210_MIN_FCW || fcw > AD2S1210_MAX_FCW) return -ERANGE; - } - return regmap_write(st->regmap, AD2S1210_REG_EXCIT_FREQ, fcw); + ret = regmap_write(st->regmap, AD2S1210_REG_EXCIT_FREQ, fcw); + if (ret < 0) + return ret; + + st->fexcit = fexcit; + + /* software reset reinitializes the excitation frequency output */ + return regmap_write(st->regmap, AD2S1210_REG_SOFT_RESET, 0); } static int ad2s1210_set_resolution_gpios(struct ad2s1210_state *st, @@ -210,11 +220,6 @@ static int ad2s1210_set_resolution_gpios(struct ad2s1210_state *st, bitmap); } -static inline int ad2s1210_soft_reset(struct ad2s1210_state *st) -{ - return regmap_write(st->regmap, AD2S1210_REG_SOFT_RESET, 0); -} - static ssize_t ad2s1210_show_fexcit(struct device *dev, struct device_attribute *attr, char *buf) @@ -229,27 +234,24 @@ static ssize_t ad2s1210_store_fexcit(struct device *dev, const char *buf, size_t len) { struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - unsigned int fexcit; + u16 fexcit; int ret; - ret = kstrtouint(buf, 10, &fexcit); - if (ret < 0) - return ret; - if (fexcit < AD2S1210_MIN_EXCIT || fexcit > AD2S1210_MAX_EXCIT) { - dev_err(dev, - "ad2s1210: excitation frequency out of range\n"); + ret = kstrtou16(buf, 10, &fexcit); + if (ret < 0 || fexcit < AD2S1210_MIN_EXCIT || fexcit > AD2S1210_MAX_EXCIT) return -EINVAL; - } + mutex_lock(&st->lock); - st->fexcit = fexcit; - ret = ad2s1210_update_frequency_control_word(st); + ret = ad2s1210_set_excitation_frequency(st, fexcit); if (ret < 0) goto error_ret; - ret = ad2s1210_soft_reset(st); + + ret = len; + error_ret: mutex_unlock(&st->lock); - return ret < 0 ? ret : len; + return ret; } static ssize_t ad2s1210_show_resolution(struct device *dev, @@ -624,10 +626,8 @@ static int ad2s1210_initial(struct ad2s1210_state *st) if (ret < 0) goto error_ret; - ret = ad2s1210_update_frequency_control_word(st); - if (ret < 0) - goto error_ret; - ret = ad2s1210_soft_reset(st); + ret = ad2s1210_set_excitation_frequency(st, AD2S1210_DEF_EXCIT); + error_ret: mutex_unlock(&st->lock); return ret; @@ -773,7 +773,6 @@ static int ad2s1210_probe(struct spi_device *spi) mutex_init(&st->lock); st->sdev = spi; st->resolution = 12; - st->fexcit = AD2S1210_DEF_EXCIT; ret = ad2s1210_setup_clocks(st); if (ret < 0) From patchwork Thu Sep 21 14:43:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 142877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5111573vqi; Thu, 21 Sep 2023 13:15:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtwr8H7NCDi5V2/ze9HJZAq7tzXbOU89r3tRoAqfIdUFW2PPJafS9Iaiu0r4rgpO/1sriY X-Received: by 2002:a17:902:a40c:b0:1bd:d6b5:a54f with SMTP id p12-20020a170902a40c00b001bdd6b5a54fmr5655925plq.55.1695327322078; Thu, 21 Sep 2023 13:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695327322; cv=none; d=google.com; s=arc-20160816; b=nTJsLGCQxyrRfz5K8tb85/t+C5d+f6SJqkskS6FMiEEsyylQks19/3Cy+5v3udtpzh B6GmeW+OtA5WN6agqkL22DvdSz5oNjqKSwmk9VIvVx46gGtXA4C54R5vi0YyF1tEoUuG 5Z90KhN5DcV8iILiOQN8uojPgwj8cW7oTYJKdTw9g/XmeWLkLeVHaLpK7ZrppdrpE0Ui e1HRSiOh9v2sQlG5FBFtZZeXUTQ2ivT3e0YtpnodMOAcWR/HWGSVzsoPHGTYMex3yp9p 3nACP50Gtr+JqyXgkNSUWvLZ56n2MI1MGq6chIRK8gcAcsbcMX1Tz03Yid54/b/faz+6 UWug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FFHoFBATjyYAR3S3Kihiw7DM+oB505Wu13vuO5lq7BQ=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=Gh1MzOjDfrQaompFggtodIwWOW+bVO9FwstTt8fz9PReHVZ2HjtDVOMYNprMq1xR4R D3jMZ83VDpRzh6mmAB8tWejhEo0IV7DadwOiWH+bShRSl+pdm/PmKdfrBqU2z8GBLGQj z4kpAjd74l4gVigFhYyp4TFXS3nhi21IY0pAknXVW3qEC9q57kkCnOe/kSo9m7Z8aMK4 QFTZWdwifuLhBqczCLEXCCcKX/fQjkrwdVB7fraGkNm4TPSLeHPW7L6nD/B2r/R3IJYV OiXSFMIHfL5/MJAoNwsicT4embrRUKaBXw0PR/1fUfF2RLL17FZXN5Vi9JUzOlRwr3DX BL7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="W/ATYciT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id d10-20020a170902654a00b001bb9375b349si2038016pln.536.2023.09.21.13.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:15:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="W/ATYciT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id F10768227436; Thu, 21 Sep 2023 13:03:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230218AbjIUUDR (ORCPT + 28 others); Thu, 21 Sep 2023 16:03:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbjIUUCk (ORCPT ); Thu, 21 Sep 2023 16:02:40 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5737257B0D for ; Thu, 21 Sep 2023 10:28:00 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-530e180ffcbso1381749a12.1 for ; Thu, 21 Sep 2023 10:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317276; x=1695922076; 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=FFHoFBATjyYAR3S3Kihiw7DM+oB505Wu13vuO5lq7BQ=; b=W/ATYciTyI2eXLzb8z9l7I7kt+ECVbTH/WTc7rQ1iKlT/lMkmlSqQc8qOqRq8lBcRI myozTsm6nt+bUl3q88o6tY/LUiHjHY4avOyjTVInWlYHUuY0AgOvUCrsCviHKnm1n+64 YX3aINC2DkR64VeFN+EAjZAEJbQfUukoETSGWs8kzcCW5hOb8qP/1yEIT87WFPLB06YY 8oX5rbTR2EHMqpjBFRfhZ9kp/Bzgt4m5HyJlZiu9vZBXxDNIMSLeDzEbvblQuAI+ZQ59 S2+e401MNlAuiNfWYLASXD16wj3wKbqIMRwXctPljoAeaqhDJxPzC+Blh68BuVxyCx2C H0OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317276; x=1695922076; 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=FFHoFBATjyYAR3S3Kihiw7DM+oB505Wu13vuO5lq7BQ=; b=eG02j1a8WSvsBrMDiz+B5qwmdcoHEGsdxkjT2T1slt833sSVlHb4FPG4D44+D6mHpI DUD/mcIm2dYPxSXSwdGyMKsv2mgywII/3RDJhO/fPLN2H5F6ykYmGrLWkqx8BF0H35BT xMzCF2HDEekRbGnxMqeJRw7MnkzptcpRPs5FFINuG1Om+Yyhpx/95UtxbP5wu4kxbGwh H0LZs+DVzugK2s4eQYj2+usMIFRgjTwIb2dkmiCKqOQQeumtKSUXYZZ4FoLM4CAYzpyy S9tylnKhg5kDOe9mAG5+vB16c5GOwT2eonvzcy8xLCM0VC8baISD9eWhTQWb/jeTlwtQ rnTQ== X-Gm-Message-State: AOJu0YzEvtT7R+1KMPbvaKJiIsz8hzbSlOl9yGT35XNFWbSlG50L7Ced GvM0EoDYPR19pNDFAuPUHVYzcwq6BnpNrOdNOdunylab X-Received: by 2002:a7b:ce15:0:b0:401:daf2:273b with SMTP id m21-20020a7bce15000000b00401daf2273bmr5282558wmc.12.1695307465779; Thu, 21 Sep 2023 07:44:25 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:25 -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 v2 15/19] staging: iio: resolver: ad2s1210: read excitation frequency from control register Date: Thu, 21 Sep 2023 09:43:56 -0500 Message-Id: <20230921144400.62380-16-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:03:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777679541898750241 X-GMAIL-MSGID: 1777679541898750241 This modifies the ad2s1210_show_fexcit() function to read the excitation frequency from the control register. This way we don't have to keep track of the value and don't risk returning a stale value. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index f1ffee34ebbc..27294eff99ef 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -78,7 +78,6 @@ struct ad2s1210_state { struct regmap *regmap; /** The external oscillator frequency in Hz. */ unsigned long fclkin; - unsigned int fexcit; u8 resolution; u8 rx[2] __aligned(IIO_DMA_MINALIGN); u8 tx[2]; @@ -202,8 +201,6 @@ static int ad2s1210_set_excitation_frequency(struct ad2s1210_state *st, if (ret < 0) return ret; - st->fexcit = fexcit; - /* software reset reinitializes the excitation frequency output */ return regmap_write(st->regmap, AD2S1210_REG_SOFT_RESET, 0); } @@ -225,8 +222,22 @@ static ssize_t ad2s1210_show_fexcit(struct device *dev, char *buf) { struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + unsigned int value; + u16 fexcit; + int ret; - return sprintf(buf, "%u\n", st->fexcit); + mutex_lock(&st->lock); + ret = regmap_read(st->regmap, AD2S1210_REG_EXCIT_FREQ, &value); + if (ret < 0) + goto error_ret; + + fexcit = value * st->fclkin / (1 << 15); + + ret = sprintf(buf, "%u\n", fexcit); + +error_ret: + mutex_unlock(&st->lock); + return ret; } static ssize_t ad2s1210_store_fexcit(struct device *dev, From patchwork Thu Sep 21 14:43:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143197 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5345135vqi; Thu, 21 Sep 2023 22:53:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXzdhTiDwl31C7PgzAxebiITodZqbKntUQ0Q7naDXqr4Ikeyj1UHHxZpLgQZrFnG+NQJrn X-Received: by 2002:a17:90a:c793:b0:274:e82d:db27 with SMTP id gn19-20020a17090ac79300b00274e82ddb27mr7016525pjb.31.1695362010597; Thu, 21 Sep 2023 22:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695362010; cv=none; d=google.com; s=arc-20160816; b=mj8eFdPb9awiQMJZ+m+khg7VKjEq1ttmbflfifP/OA7zGoP14HNOaCZphoOyTIyqCC 2BIieOxiWfPWcs0Zcv5x750ENQsW5Fe79RGYeloB7C5zB2KSMaT41fipa1BIdJPVnGbR Ff0gOXMLOhOyckVmmLlYjsLQrWOaULUBaCTPA5uiK5GPJK5aNdz/YbKdYjv7OlpCKCSl IW04y1H+azbLca7TIoZeeAb7SQGD1dvlcQC1Y9irhpJYX+//u/cu8Sv5t6aAtmBL+1ex DkvFfZek2PKPWsJiKahcVFx/dIfIp5CCHc9zNGwQp6FAI0YCg6/swuvkeoXUWlpCUYFV OGGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nYFN9YS9lGoY3Drq+6yfHeUu5PUEzCkva/9j6XN0ZE4=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=ABr/g9ZpDZZ4w8k7BIt3umrgZ5RVvpxqsqTfV7DxvfTFBmWKJdLp+Bpl32p1RUpdfU fi3mXVsRnFmOiD/1YUi8fxcNqCEdEJBk4OcuAaswkbqeU97xx2sF1EFqdQmowroLmuu7 mk9CZHi3vgUzYKbZkUF/rCUo75Rv1LdHKNWeQuR0bBxru8NFK7ZTxs+yHtQkNY9MbxC5 kJQaUZatMukGSssRcYgq/0sS2WnYrUlL8wgRhFZJrAmNfwSxkudXw3EkdjtPdYpyq+21 l9aURtBpFluXBJPXMSc8P9t/J7MOh2+Edxh3VqtO1JkUeNSo3pMnu5Z3ZuHIfil60QhE N02A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=qUoTboMI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id lx4-20020a17090b4b0400b0026b043c8bbesi3504749pjb.136.2023.09.21.22.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 22:53:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=qUoTboMI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 59717808D4AC; Thu, 21 Sep 2023 10:53:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbjIURwh (ORCPT + 29 others); Thu, 21 Sep 2023 13:52:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230064AbjIURwY (ORCPT ); Thu, 21 Sep 2023 13:52:24 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBC546900D for ; Thu, 21 Sep 2023 10:30:21 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-50307acd445so2126474e87.0 for ; Thu, 21 Sep 2023 10:30:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317412; x=1695922212; 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=nYFN9YS9lGoY3Drq+6yfHeUu5PUEzCkva/9j6XN0ZE4=; b=qUoTboMIeKzd8421AFwx9laig8g+W6M7oJlWwpXuSZ9YTDaEauUoKdCWO50Ncvt1Me IsjlpJAiBAdGcXCOJWUi0lvj+42KZ1hYWzKe8Mu+UtlU8a9MvcZAG7wtmsXFSL1D6hE/ HJZxq2QPyAuBw4c8XmmQ4YqEqeEgXVqEO2atpgA6carSC/apENn1Cp18V+3VGQZdp/oD QrZynGVUf2XNWJEvwPNgwHiKRcIOe9SuSMurvslg3LYWWKSWSJlYO8m+laHb/zE3D392 134QwMMt46oyz+8RdeBsVgxQzFtMi+o8Ajbjzncru8ouR6+w+eqtVOTpqKOMhRc+O2io bdjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317412; x=1695922212; 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=nYFN9YS9lGoY3Drq+6yfHeUu5PUEzCkva/9j6XN0ZE4=; b=qACZ7+CjYpuQbg8bX3dqCP5zmYu+UOp8hPFbXAk2hO/wunMWQLpbwt+YMfdq8CrtMb BUzX9TyH0Uj9pXnNAK30BqLobYlXtgDCyZnuI97PRC5iHO0I3xdCgdfL5A2o10fqVSaH IRfwwuhDEYv7YUfwwfHq3XhuuHn26x3QMfq816bKOqpdKZBwvWNMt60bmm7nuhvxssq0 KHN/4TdiRBAJno/s8GJlSDZ3C0pq1ttJPqXqLHTAHj7cH3iurvSnt4G905se4R3hXiei D7sftSOAKyhY6EvVR6ppy3X7qvqnc0FjPdx/VorSFyUXdePR9lx8WqQY5FIZNfDFxDIS 6v3g== X-Gm-Message-State: AOJu0YxqM/N8Hq+VEe409ZAnr7Jrs/17l4JhnqB6dVH7fVTQAFEdP9Y5 F4faJOSg3urM75ifGXGb/UXjIxrXAjB2O39q8OujgSKN X-Received: by 2002:a05:600c:478a:b0:405:3955:5872 with SMTP id k10-20020a05600c478a00b0040539555872mr743765wmo.18.1695307466583; Thu, 21 Sep 2023 07:44:26 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:26 -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 v2 16/19] staging: iio: resolver: ad2s1210: rename fexcit attribute Date: Thu, 21 Sep 2023 09:43:57 -0500 Message-Id: <20230921144400.62380-17-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 21 Sep 2023 10:53:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777715915464233869 X-GMAIL-MSGID: 1777715915464233869 This renames the fexcit attribute to excitation_frequency to be more human-readable. Since we are already making many breaking changes to the staging driver, this is a good time to do this. Also make use of IIO_DEVICE_ATTR_RW while we are touching this. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 27294eff99ef..14bec2b20939 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -217,9 +217,9 @@ static int ad2s1210_set_resolution_gpios(struct ad2s1210_state *st, bitmap); } -static ssize_t ad2s1210_show_fexcit(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t excitation_frequency_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); unsigned int value; @@ -240,9 +240,9 @@ static ssize_t ad2s1210_show_fexcit(struct device *dev, return ret; } -static ssize_t ad2s1210_store_fexcit(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) +static ssize_t excitation_frequency_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 fexcit; @@ -555,8 +555,7 @@ static int ad2s1210_write_raw(struct iio_dev *indio_dev, return ret; } -static IIO_DEVICE_ATTR(fexcit, 0644, - ad2s1210_show_fexcit, ad2s1210_store_fexcit, 0); +static IIO_DEVICE_ATTR_RW(excitation_frequency, 0); static IIO_DEVICE_ATTR(bits, 0644, ad2s1210_show_resolution, ad2s1210_store_resolution, 0); static IIO_DEVICE_ATTR(fault, 0644, @@ -604,7 +603,7 @@ static const struct iio_chan_spec ad2s1210_channels[] = { }; static struct attribute *ad2s1210_attributes[] = { - &iio_dev_attr_fexcit.dev_attr.attr, + &iio_dev_attr_excitation_frequency.dev_attr.attr, &iio_dev_attr_bits.dev_attr.attr, &iio_dev_attr_fault.dev_attr.attr, &iio_dev_attr_los_thrd.dev_attr.attr, From patchwork Thu Sep 21 14:43:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143388 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5513055vqi; Fri, 22 Sep 2023 05:03:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMA4mBChoMM4Rbumb9jt/LwBd8SvOFKbAaE1WGe1KhGniB24wEBnwsjA0s6EHBiBcoIAUM X-Received: by 2002:a17:90a:17c5:b0:268:1b60:5031 with SMTP id q63-20020a17090a17c500b002681b605031mr8054571pja.12.1695384189881; Fri, 22 Sep 2023 05:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695384189; cv=none; d=google.com; s=arc-20160816; b=mVJOzBHH/ndOm5ET2EseIBQtXQ8R06pPZ//GnjALGywA/H8XbU2V/l0oG5zwo49a3p 9CxhR3aygq4iY1Rwknvw6jYrZFCWDBO5FdNmfpsPKptCC3pc8ilcbnnFUdmpBVqEKOVM UDlyWB9gytlwZVcDrRohT7r92sGObaQlok4gTbS4N7GpbC9Ko6K68r+et2x9YvRfmkIs w+Uy0F+akKGbyYXy8bjxx4tTDgVZ/Bo6QbmX17oCXR7oPJ+iOefsTh8msYO+cmbfjyYW bx9K05c6DOhzM6aCD+3e/RogBDxtZ2M0E9vhVl6y+wOOye9NB7hyGdoA2SpRVe9XZ89a iFzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bSzhqtQuH6rCmKnaqNrN1q0TijVTu8SKnjt98b8WvE0=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=aqOE/4otbxwU1KeBSs7et0QdCXargX2p3N5Xq5izvgNkG4p/F2geIDGoYf1bkmoHZz W+mVvioFaArhpYpeOu0QN0LS8r01lH1aHOSP9KC1MOFSzAk50wFmSMNYxvcZvCs1xjmk /qeFnQFbToZJpPcEsT+bd1T2sqP0Zw7q0S31zuhGl4Vlz7BoXt/8tMFTzgtFJkqnxRGn 6P3Ql5Pobi8IMrS7gS7Hkm6Oh52pkMpE4u1kjyaVeeJeUwP3V+UP4THcu/+WelTco80o GjFT/ZVW4cb1/jaEB2fZCZdASycrrGVEmmbHGR7FKsP9yskeU3nCOBAcnOrbA4vPqkqG 7N2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=SIm82iHh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bf18-20020a17090b0b1200b0026b6a7d9e43si3687720pjb.14.2023.09.22.05.03.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 05:03:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=SIm82iHh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 980DD82AE67E; Thu, 21 Sep 2023 11:12:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229668AbjIUSM7 (ORCPT + 29 others); Thu, 21 Sep 2023 14:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230326AbjIUSME (ORCPT ); Thu, 21 Sep 2023 14:12:04 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2886F19AD for ; Thu, 21 Sep 2023 10:52:43 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-405361bb93bso8058665e9.3 for ; Thu, 21 Sep 2023 10:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318761; x=1695923561; 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=bSzhqtQuH6rCmKnaqNrN1q0TijVTu8SKnjt98b8WvE0=; b=SIm82iHhvz+z+t9gHmJ8dRvSEtHXPTD4yyfvvsQvdg5nRrEa7XkO2Yoi7gMxWYzoNa W2Dw/S4Qv0r51gZK+kjcgs60NGYAFbedQ5kswS8jH86sSm0t4Kqn50jXqq3Y+trIxOnd z7DQOhP3UTDoJr/SBgz9wrDP6DV49cUuF/ckZU6WikZHPMAho7Ta0v4bn+uhQUm44Y/D ngbYI8/dJsQu4tZFrFgIdY88Lx6w3JiC6e/A6fzO+Y20L/p9qbfMSk7v7vNzS96cnpLW joGSpeFaRLY2DaZ0SCXUNXubW6CBRvBIe0Ajvjq6pB+09sxqi0KsZ/b17d8TI5bk9amc JR5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318761; x=1695923561; 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=bSzhqtQuH6rCmKnaqNrN1q0TijVTu8SKnjt98b8WvE0=; b=C0bgZTXguQhB2sSRnpxH5DW8KWI3HdUdi1IBbYKvUyuAhxyAEvhd134OEQFnM8yDUI AjmFf3ouOQqtOCFR/YXAdBS0FHeDwyONlPjdg5AE+/reZTibV+7xTILdnE9A6ZyS4pMr UL8YP1ifArAOnkPYplQyj8Bke/cD2puJbKy5ImmjOlOjPNCbxv0olVlNe3MlWMQy4Vtl hEjdKzM/LyNECXyZQxJWDi+qwCnabppoxGEdsABL9NAIeIizj9hbyTv54Xyv/FK6vytQ fUXZky9gEdkaIVFIYC0SJ+7aFzYjJYkWvC0OpSRHDCl+c5OWGfQ3T00I8bX3IxlOaMaI 3eoA== X-Gm-Message-State: AOJu0Yw0tosUGoKl2wzgTCDMabvF3x6KmxJWVJbJP6DmUYLrTcI10V4b E7z4t8TJhdG96CIIZdoAW2bZVo2nEzV7wfShSB/+mXXK X-Received: by 2002:a05:600c:1c28:b0:405:3557:8e49 with SMTP id j40-20020a05600c1c2800b0040535578e49mr1403445wms.40.1695307467567; Thu, 21 Sep 2023 07:44:27 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:27 -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 v2 17/19] staging: iio: resolver: ad2s1210: convert resolution to devicetree property Date: Thu, 21 Sep 2023 09:43:58 -0500 Message-Id: <20230921144400.62380-18-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 11:12:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777739171864424553 X-GMAIL-MSGID: 1777739171864424553 Selecting the resolution was implemented as the `bits` sysfs attribute. However, the selection of the resolution depends on how the hardware is wired and the specific application, so this is rather a job for devicetree to describe. A new devicetree property `adi,resolution` to specify the resolution required for each chip is added and the `bits` sysfs attribute is removed. Since the resolution is now supplied by a devicetree property, the resolution-gpios are now optional and we can allow for the case where the resolution pins on the AD2S1210 are hard-wired instead of requiring them to be connected to gpios. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 136 +++++++++++------------- 1 file changed, 61 insertions(+), 75 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 14bec2b20939..71f0913b7e2e 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -65,6 +65,13 @@ enum ad2s1210_mode { MOD_CONFIG = 0b11, }; +enum ad2s1210_resolution { + AD2S1210_RES_10 = 0b00, + AD2S1210_RES_12 = 0b01, + AD2S1210_RES_14 = 0b10, + AD2S1210_RES_16 = 0b11, +}; + struct ad2s1210_state { struct mutex lock; struct spi_device *sdev; @@ -72,13 +79,12 @@ struct ad2s1210_state { struct gpio_desc *sample_gpio; /** GPIO pins connected to A0 and A1 lines. */ struct gpio_descs *mode_gpios; - /** GPIO pins connected to RES0 and RES1 lines. */ - struct gpio_descs *resolution_gpios; /** Used to access config registers. */ struct regmap *regmap; /** The external oscillator frequency in Hz. */ unsigned long fclkin; - u8 resolution; + /** The selected resolution */ + enum ad2s1210_resolution resolution; u8 rx[2] __aligned(IIO_DMA_MINALIGN); u8 tx[2]; }; @@ -205,18 +211,6 @@ static int ad2s1210_set_excitation_frequency(struct ad2s1210_state *st, return regmap_write(st->regmap, AD2S1210_REG_SOFT_RESET, 0); } -static int ad2s1210_set_resolution_gpios(struct ad2s1210_state *st, - u8 resolution) -{ - struct gpio_descs *gpios = st->resolution_gpios; - DECLARE_BITMAP(bitmap, 2); - - bitmap[0] = (resolution - 10) >> 1; - - return gpiod_set_array_value(gpios->ndescs, gpios->desc, gpios->info, - bitmap); -} - static ssize_t excitation_frequency_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -265,50 +259,6 @@ static ssize_t excitation_frequency_store(struct device *dev, return ret; } -static ssize_t ad2s1210_show_resolution(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - - return sprintf(buf, "%d\n", st->resolution); -} - -static ssize_t ad2s1210_store_resolution(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - unsigned char data; - unsigned char udata; - int ret; - - ret = kstrtou8(buf, 10, &udata); - if (ret || udata < 10 || udata > 16) { - dev_err(dev, "ad2s1210: resolution out of range\n"); - return -EINVAL; - } - - data = (udata - 10) >> 1; - - mutex_lock(&st->lock); - ret = regmap_update_bits(st->regmap, AD2S1210_REG_CONTROL, - AD2S1210_SET_RES, data); - if (ret < 0) - goto error_ret; - - ret = ad2s1210_set_resolution_gpios(st, udata); - if (ret < 0) - goto error_ret; - - st->resolution = udata; - ret = len; - -error_ret: - mutex_unlock(&st->lock); - return ret; -} - /* read the fault register since last sample */ static ssize_t ad2s1210_show_fault(struct device *dev, struct device_attribute *attr, char *buf) @@ -556,8 +506,6 @@ static int ad2s1210_write_raw(struct iio_dev *indio_dev, } static IIO_DEVICE_ATTR_RW(excitation_frequency, 0); -static IIO_DEVICE_ATTR(bits, 0644, - ad2s1210_show_resolution, ad2s1210_store_resolution, 0); static IIO_DEVICE_ATTR(fault, 0644, ad2s1210_show_fault, ad2s1210_clear_fault, 0); @@ -604,7 +552,6 @@ static const struct iio_chan_spec ad2s1210_channels[] = { static struct attribute *ad2s1210_attributes[] = { &iio_dev_attr_excitation_frequency.dev_attr.attr, - &iio_dev_attr_bits.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, @@ -626,12 +573,10 @@ static int ad2s1210_initial(struct ad2s1210_state *st) int ret; mutex_lock(&st->lock); - ret = ad2s1210_set_resolution_gpios(st, st->resolution); - if (ret < 0) - return ret; data = AD2S1210_DEF_CONTROL & ~AD2S1210_SET_RES; - data |= (st->resolution - 10) >> 1; + data |= st->resolution; + ret = regmap_write(st->regmap, AD2S1210_REG_CONTROL, data); if (ret < 0) goto error_ret; @@ -670,6 +615,26 @@ static const struct iio_info ad2s1210_info = { .debugfs_reg_access = &ad2s1210_debugfs_reg_access, }; +static int ad2s1210_setup_properties(struct ad2s1210_state *st) +{ + struct device *dev = &st->sdev->dev; + u32 val; + int ret; + + ret = device_property_read_u32(dev, "assigned-resolution-bits", &val); + if (ret < 0) + return dev_err_probe(dev, ret, + "failed to read assigned-resolution-bits property\n"); + + if (val < 10 || val > 16) + return dev_err_probe(dev, -EINVAL, + "resolution out of range: %u\n", val); + + st->resolution = (val - 10) >> 1; + + return 0; +} + static int ad2s1210_setup_clocks(struct ad2s1210_state *st) { struct device *dev = &st->sdev->dev; @@ -691,6 +656,9 @@ static int ad2s1210_setup_clocks(struct ad2s1210_state *st) static int ad2s1210_setup_gpios(struct ad2s1210_state *st) { struct device *dev = &st->sdev->dev; + struct gpio_descs *resolution_gpios; + DECLARE_BITMAP(bitmap, 2); + int ret; /* should not be sampling on startup */ st->sample_gpio = devm_gpiod_get(dev, "sample", GPIOD_OUT_LOW); @@ -708,16 +676,31 @@ static int ad2s1210_setup_gpios(struct ad2s1210_state *st) return dev_err_probe(dev, -EINVAL, "requires exactly 2 mode-gpios\n"); - /* both pins high means that we start with 16-bit resolution */ - st->resolution_gpios = devm_gpiod_get_array(dev, "resolution", - GPIOD_OUT_HIGH); - if (IS_ERR(st->resolution_gpios)) - return dev_err_probe(dev, PTR_ERR(st->resolution_gpios), + /* If resolution gpios are provided, they get set to the required + * resolution, otherwise it is assumed the RES0 and RES1 pins are + * hard-wired to match the resolution indicated in the devicetree. + */ + resolution_gpios = devm_gpiod_get_array_optional(dev, "resolution", + GPIOD_ASIS); + if (IS_ERR(resolution_gpios)) + return dev_err_probe(dev, PTR_ERR(resolution_gpios), "failed to request resolution GPIOs\n"); - if (st->resolution_gpios->ndescs != 2) - return dev_err_probe(dev, -EINVAL, - "requires exactly 2 resolution-gpios\n"); + if (resolution_gpios) { + if (resolution_gpios->ndescs != 2) + return dev_err_probe(dev, -EINVAL, + "requires exactly 2 resolution-gpios\n"); + + bitmap[0] = st->resolution; + + ret = gpiod_set_array_value(resolution_gpios->ndescs, + resolution_gpios->desc, + resolution_gpios->info, + bitmap); + if (ret < 0) + return dev_err_probe(dev, ret, + "failed to set resolution gpios\n"); + } return 0; } @@ -782,7 +765,10 @@ static int ad2s1210_probe(struct spi_device *spi) mutex_init(&st->lock); st->sdev = spi; - st->resolution = 12; + + ret = ad2s1210_setup_properties(st); + if (ret < 0) + return ret; ret = ad2s1210_setup_clocks(st); if (ret < 0) From patchwork Thu Sep 21 14:43:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5231488vqi; Thu, 21 Sep 2023 17:30:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAAV1DXQ6XO8dvCBaqaG1aS323gIZEAKK8imga+a0wxSXgmGtj6mgfrM6zP3UCcLepz1iX X-Received: by 2002:a17:902:c404:b0:1be:e7ba:3a97 with SMTP id k4-20020a170902c40400b001bee7ba3a97mr8518057plk.15.1695342636946; Thu, 21 Sep 2023 17:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695342636; cv=none; d=google.com; s=arc-20160816; b=dI4pC2mIGhyD3Wfzgltmw2o1zYl65GtG1CStgu27ST6NANq1r2rNcoCaQvYFQ1LP6h RnOO0+tYv4B2RNxVhpuziwK6IDbOcT3G+YVE69WnTZ3sXHElUXCxCoPY1aKECc9WKA2s Gc6r2sd5uBTNV32/WrAXL6w5fLC8kXksEuQLEaOcg7gYv39JYko1kGaytB6YRUsYThEm 7CIEYC8aNKsYdj1rVB2rq//atsIjuK4SBjbStItiFxk5/DpjXcAEBEwTj6Elqr7LlP+F 1WvKo8LOZM7lBV8Ay0CyF/4fXViyplkfCWGkvAcnef+h6Pluu6f7FgueB+6G1NdOHHji hPrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y5XZRvh5FJ3F9RXkqi8NbBrwtIOGm1RUjmAFGYn0SWM=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=0lOVhhir0egAv+c7MjOwCGIT1qU0oTXIj2kE3zz83iBFwP+mEYeVmFtbx3lXqxLfrN Bue9ecxKqptZ+49ri1FKNcLqgD27DsJEQuD7v301oU18UL/hPh3dtw6gpo3vRzbOz/lO XZJiHCR+O7OFIN7SzkL4DXM0P012Df8wcfpO/uSPV/iCN+1iZNAfaxe4JVkgS+asoRTH 7rRRoP9yA9PgxiO01NR9SMrBJmrDwPD0baZwvyU9hPgl/iFTbAu8H3xy4rQbpJrNtZbY oEsXMTi7vdlK7l7TqX5zy8wuVLN/0JYtH3t/8jYgk5+7WL7f4xB883UM22mjssSNgtRU FWhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="G3Nlc/Nn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id m17-20020a170902f21100b001c0ab540e67si2357307plc.213.2023.09.21.17.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:30:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="G3Nlc/Nn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 910508024FF1; Thu, 21 Sep 2023 12:58:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbjIUT6h (ORCPT + 28 others); Thu, 21 Sep 2023 15:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230486AbjIUT6X (ORCPT ); Thu, 21 Sep 2023 15:58:23 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23555E0A4 for ; Thu, 21 Sep 2023 10:29:47 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-401da71b83cso12844465e9.2 for ; Thu, 21 Sep 2023 10:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317375; x=1695922175; 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=G3Nlc/Nn/wLfLhPbsfjQt9FgtoM0PgvCc6mxXqC+4By9eIxGr9FxJ9FBI/5Q/72r1u R2hu3ehA3431xwmKQRLwLZs104RWynFdOtOwpYhcv82J6IIom8p5DT/kENc2B2uEI4Kk VgiEVSOCkCvQZZRxAYCYoyDsI9XcNnr1Lk9p+8/pNnpBRzdgTJPL+pfNU5Ngd0H6ls9v mr9e0idwX+lTIBHxPE59ofBnm5vjNE4GE2+TxLwWI1MuNIfrHbpZbnFhA7AtmZmrUXVo rGNbRxyULeMGS5f2pZuQxMN1mdNk1DKg2GGr2VJlJoNeQmjcRPnCCBH0pqqV9dRA4Rv2 EODQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317375; x=1695922175; 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=aWuEp68I5iO0s2opKJx7Q217L6n/8Idx7cY8kFXEBmrDOZYWdE0NApqvKy83dzCejp AW1IKH2SI72+oCywYK6FNal3eHCGbE/EbhShitqvFzBt3Cd56YAF4zwXWpKPucYq2l4f oQQlolIeDxxMWIevg6HoqT/O1JLLZ2p3Bml7EzVrOf9VfQb9YW7ySqwyMlW2z3RJXAOe D8x1RxwB+jUBymUmZqsLQpk1oYvUZ9eEH4BKYMgU7/47msIJr8MmcyREmiKM7IPkrdW6 cxCzESPSWZ1rFn2ZHE+s+NOKdm6TBpI08b5+53axOBaIuSyTSOVc0BCdsz3I2e/eDtR2 COAA== X-Gm-Message-State: AOJu0YwpSjAAmjq2ygeAMDqS3HHXLvi/7rysQEtrGNr6scPXMu0xZoGx xR4RI5eUm+3/me/vblhkFSUiDeoPhfMgLA54mUBbb7Ah X-Received: by 2002:a5d:4289:0:b0:319:7a9f:c63 with SMTP id k9-20020a5d4289000000b003197a9f0c63mr5309192wrq.50.1695307468423; Thu, 21 Sep 2023 07:44:28 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:28 -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 v2 18/19] staging: iio: resolver: ad2s1210: add phase_lock_range attributes Date: Thu, 21 Sep 2023 09:43:59 -0500 Message-Id: <20230921144400.62380-19-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:58:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777695600638180131 X-GMAIL-MSGID: 1777695600638180131 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, From patchwork Thu Sep 21 14:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 143136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5293514vqi; Thu, 21 Sep 2023 20:22:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+1IJ9rSOoBhbxanLLTeFVCbrchKAdIftKLyDvQti233mc/nAvSuMe+xSxgALnytgbJD6f X-Received: by 2002:a17:90b:203:b0:274:7de5:10c7 with SMTP id fy3-20020a17090b020300b002747de510c7mr2134561pjb.11.1695352927760; Thu, 21 Sep 2023 20:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695352927; cv=none; d=google.com; s=arc-20160816; b=qnK1zmVSgEG4Opq9uOVrlbEpw6Q0pN0ICQkW196rQW5DcaCXNIcnaNU8GzUMR2TYQ5 fceq/kXC+xvy1EzfpBfuaHH/uGmzQn0tX8D+k/OpxqXYhOFBhfLQxa9C3E+GVKG8QUnb 2jBFm5zkYMXVwPQAKkcPAZQOXiaewWt9gjyEQXR+dsa7CE6hAPXE3fDaapKefdb/iwA2 4N3VZuPeiqBz6j2MkzgZKLE/246FdQJ0P8V/jQUT+XPNtD/qYAFp512/N4LoKaBWzojD SLbO8jxTYNr6sCzeh9XnByfSHAsyQ7e7L2Xlnt52VpvgdKJrWtxm+KYczKTfkv8AiYFI kVwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BurSNjw3LRUUcMvXtonPsGB5QUx7CZPo8/XQKc8tXvQ=; fh=rOC7q8UJisRayejF6PsoKdRfRTtXVZOwgDCXOG0B/ws=; b=i/O7iWnQ8rJsp8Je+AFg3agKEUcDnBPUCtTGIqYeavR4XAXAVWMR/qYKmN0HFj/sXm ukm7kGVntoFz/Ve1IqmabHDyeGqDmjsXT3uoEypRD/8w6QVbswfx7onlfjxwAeSUBC5m ng/dt4Lo2pEn1uwGMTkJbJ2M1klW/+RNM8UsKn7FbcTOttxcn82rqYi4F63ZdMM0UHBJ y52YxxKZTGEk8VFctPZI8QYjW5bTRip/m1F9Qkc27T4mnuxlLVSiIUHh71vZsimxZyPW /Nod8NcMPqgvkPhg4c3h/Kf83Y6n7ciauVF4z9z6140/+Ly5v6eGucHAudeT48VGvoFy tFtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="kZh6uBu/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id 26-20020a63155a000000b00578e29ae274si2749042pgv.521.2023.09.21.20.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 20:22:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="kZh6uBu/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 1638581A7D10; Thu, 21 Sep 2023 13:19:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231502AbjIUUSA (ORCPT + 29 others); Thu, 21 Sep 2023 16:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229909AbjIUURa (ORCPT ); Thu, 21 Sep 2023 16:17:30 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81F0C4F38B for ; Thu, 21 Sep 2023 10:28:43 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2bfea381255so20605011fa.3 for ; Thu, 21 Sep 2023 10:28:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317321; x=1695922121; 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=BurSNjw3LRUUcMvXtonPsGB5QUx7CZPo8/XQKc8tXvQ=; b=kZh6uBu/pkLkpTzo/OfqIJlSEKHtreiZoPZImZJV+Mr1gME/Wzq9OXmca2un4J5bwR n0iiltbCuixbjTaypArA15qmhfX8K0aU2JmX51H+BClGEmKMgo3wWZAHdK0HMhu86YQn zcfA4LMkB7HRd6d9+X6Xt8nIkB1Y5JSVbRb4him9XdEYAU5zqn5283aHjAFGckNSpasF RJDY3/DdC3w8lVWnS79eBk5BklGpJ5m+7+2QAfc2AmUx0WOjtGjCcFVcExq0jqC5ZjtH N7cIY4uoPU5ZGnIfwEGZB93c1zeRC/NlbB+yToUhfSlkS/DQ4SBOknGCuQcJlD7PwvWV HPZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317321; x=1695922121; 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=BurSNjw3LRUUcMvXtonPsGB5QUx7CZPo8/XQKc8tXvQ=; b=EwkpJAZ74k2oCQLZWQnr3uccwdtCLBGq821SRDHS+HjBIorlPJO/kMehbHjV6F03AD vr7CDHrd48F4jJkJICu7P1dQ9Cm4dy9xMMtF6/DrPiFvm5XsTJcF1xjDjhebdCJtefFB VCwAWJ89OTZ6rpIPiBOG0GwKvtXSJsp98DKGvm9ZsQ6UDpbDtec1iYzJzDTJQzO83QpJ 1HrBodOQp2wT/qpL6QyEzBvbeqfWMh7J78TL1bu/iJckOZE5eLo2dbCWHbl0y+oSp5pR n7xLYYEbl4lHTgrZlLOVHnFn3LZx2aB2/U8siIMIlwVIM2xs/5udKjiSX4SxOqpiX3Yx otAA== X-Gm-Message-State: AOJu0YwyMy7j3x/Dx++AiqJlS5vAxFhgdee83bWh+9jtk+X+yc4H0i+L 1qhKXuLWEjeiUDizBXhdxFpfA53bTvIAA6I8lQ4uRUew X-Received: by 2002:a05:600c:2055:b0:403:cab3:b76e with SMTP id p21-20020a05600c205500b00403cab3b76emr5458870wmg.22.1695307469491; Thu, 21 Sep 2023 07:44:29 -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 s17-20020a1cf211000000b003fe2a40d287sm2125515wmc.1.2023.09.21.07.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:44:29 -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 v2 19/19] staging: iio: resolver: ad2s1210: add triggered buffer support Date: Thu, 21 Sep 2023 09:44:00 -0500 Message-Id: <20230921144400.62380-20-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921144400.62380-1-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:19:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777706391260070518 X-GMAIL-MSGID: 1777706391260070518 This adds support for triggered buffers to the AD2S1210 resolver driver. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 84 ++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index f5b8b290e860..44a2ecaeeeff 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -19,8 +19,11 @@ #include #include +#include #include #include +#include +#include #define DRV_NAME "ad2s1210" @@ -85,6 +88,12 @@ struct ad2s1210_state { unsigned long fclkin; /** The selected resolution */ enum ad2s1210_resolution resolution; + /** Scan buffer */ + struct { + __be16 chan[2]; + /* Ensure timestamp is naturally aligned. */ + s64 timestamp __aligned(8); + } scan; u8 rx[2] __aligned(IIO_DMA_MINALIGN); u8 tx[2]; }; @@ -592,18 +601,35 @@ static const struct iio_chan_spec ad2s1210_channels[] = { .type = IIO_ANGL, .indexed = 1, .channel = 0, + .scan_index = 0, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_BE, + }, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_HYSTERESIS), .info_mask_separate_available = BIT(IIO_CHAN_INFO_HYSTERESIS), + .datasheet_name = "position", }, { .type = IIO_ANGL_VEL, .indexed = 1, .channel = 0, + .scan_index = 1, + .scan_type = { + .sign = 's', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_BE, + }, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), - } + .datasheet_name = "velocity", + }, + IIO_CHAN_SOFT_TIMESTAMP(2), }; static struct attribute *ad2s1210_attributes[] = { @@ -665,6 +691,55 @@ static int ad2s1210_debugfs_reg_access(struct iio_dev *indio_dev, return ret; } +static irqreturn_t ad2s1210_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct ad2s1210_state *st = iio_priv(indio_dev); + size_t chan = 0; + int ret; + + mutex_lock(&st->lock); + + memset(&st->scan, 0, sizeof(st->scan)); + gpiod_set_value(st->sample_gpio, 1); + + if (test_bit(0, indio_dev->active_scan_mask)) { + ret = ad2s1210_set_mode(st, MOD_POS); + if (ret < 0) + goto error_ret; + + /* REVIST: we can read 3 bytes here and also get fault flags */ + ret = spi_read(st->sdev, st->rx, 2); + if (ret < 0) + goto error_ret; + + memcpy(&st->scan.chan[chan++], st->rx, 2); + } + + if (test_bit(1, indio_dev->active_scan_mask)) { + ret = ad2s1210_set_mode(st, MOD_VEL); + if (ret < 0) + goto error_ret; + + /* REVIST: we can read 3 bytes here and also get fault flags */ + ret = spi_read(st->sdev, st->rx, 2); + if (ret < 0) + goto error_ret; + + memcpy(&st->scan.chan[chan++], st->rx, 2); + } + + 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); + + return IRQ_HANDLED; +} + static const struct iio_info ad2s1210_info = { .read_raw = ad2s1210_read_raw, .read_avail = ad2s1210_read_avail, @@ -850,6 +925,13 @@ static int ad2s1210_probe(struct spi_device *spi) indio_dev->num_channels = ARRAY_SIZE(ad2s1210_channels); indio_dev->name = spi_get_device_id(spi)->name; + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, + &iio_pollfunc_store_time, + &ad2s1210_trigger_handler, NULL); + if (ret < 0) + return dev_err_probe(&spi->dev, ret, + "iio triggered buffer setup failed\n"); + return devm_iio_device_register(&spi->dev, indio_dev); }