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: 13394240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B1D0E7D0AC for ; Thu, 21 Sep 2023 18:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbjIUSMc (ORCPT ); Thu, 21 Sep 2023 14:12:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbjIUSLZ (ORCPT ); Thu, 21 Sep 2023 14:11:25 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 075858AE33 for ; Thu, 21 Sep 2023 10:41:11 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2c12fc235fbso10312401fa.0 for ; Thu, 21 Sep 2023 10:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318070; x=1695922870; 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=EKEty68rqoHb0UFaK1eA8TGkqR9CusDk0wQsjNUIf5/P1+KklA1z9GDa8cC7v8Irjd 8zqSFWDKXtI0e+G3aqbqcy3kUWmG6SGvEpkpisOyzEV5LeB5uslR81iG4sx6SdwFcP2R MzYDlRuuzW8WuDdhbMSyEif+b998g2iNIOyPJNb3lVNCVfbEThYxwyjPq7D0smzytPaN DVQYWt4AzeVnQllVzlMdn5TedreCrvV+zxg3+X3klUBCWfiD1wJtSo+9LUnV4JWFe/t8 qxpBNMzP+N6KfawNPvHZEuRxbl8J7LaqugU3vbjb/UvgYnV2E2EVbJy//Q6CdLTAZ+rv eoQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318070; x=1695922870; 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=POtiM0eSOeO3gSB0w79G8gTI7p9jm0gvaOKSabLyzVYtuObUeN8Y/lYMuzA0gFz3X/ YadOuV8sJNtCu8bxH+gH7sqTt+sUamnFVP1Y2s/nrFRMxTxCjIHwqT/u+a73oHBuyGf2 vYsTQ4DHhH8J/kN07PpMY77DgykcFz51LwO8vFt5uPozPoDRnp2mGGAZXTLHb3jhKTVJ yP3O07+iRTg1oxuOW9R3SYe+SXTPFVycs66mp5tVgLCDFbC0W+BiMf+lyOPiNFRl6Uy6 OI/VxbZpve7wcakcdBc129dk8kBdJsUm8jfvhGzZfW+QkEFYhyGH30H+9pkpJvjOYCkB XtQA== X-Gm-Message-State: AOJu0Yz2ziR/9rcZV9lugaDvdSmN8vMEwDiZ4/bh2BP8WTvLabcCJcHJ r9T5mJhZgt2HCwMV6Eyo1wEVUeLTMAnNNs5OQPtV5WHk X-Google-Smtp-Source: AGHT+IHMEHv2klXQ63wwzWGVjMOGX5bZqWdw2Z4sNl3hAMpsWXkSNUzWXIDheODJzKMZ7lJR41f9Ow== 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-iio@vger.kernel.org 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: 13394125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3391E7D0A2 for ; Thu, 21 Sep 2023 17:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230162AbjIUR26 (ORCPT ); Thu, 21 Sep 2023 13:28:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbjIUR2T (ORCPT ); Thu, 21 Sep 2023 13:28:19 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E9474BBEC for ; Thu, 21 Sep 2023 10:16:37 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id a640c23a62f3a-9ae22bf33a0so525837466b.0 for ; Thu, 21 Sep 2023 10:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316596; x=1695921396; 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=qOSnKTWNTyxDJAD/n1BeOK6v6FCdI+DmjuyOOEqw6Mvchy5xdw6KJRs2XTYGyG5lSg OKlCGBxlraNA143oCIwa/1aBJAAyE7xZu9eKLRzz7s3yzxwXlMPKcaqgwbKqjCqMvlAJ vRP/ChFihnrWREcBvQVt05CXxPoqz3nUOf5yDe/DbUWemO30yE4zGmpG1SIthErIy6bj 7vVWPutZTh+yMXzrPVb3LlUROW0jw+0pdI8MxMXLCLY/nKbjA0RAvF5yGN08XRatC/Oo ws5VHtIFLNHs3gLEhYETJpZfRVRM/i6kmm0g6Xuwz3EjazWVMPJ9u8bSUwrFjhOh97WE cyRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316596; x=1695921396; 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=iB6aWRD1cbHNhoTHrLrPWAsKSQ0XVSPiz+O+YLC3kGJmttXFJ7kSCiZ6etwr5SdMss DNfmeUxFgWQrlUeyIE5Cu6Q8hLBhVHwm8yTAJo8/nF3XWG6dGDWAzpHi57Nw4vytb1CB 1SFXhxcZ3ZvNzsRisaDjAMG7QPOnHFEsac8SMEJpCMHj3uBkTVLzI5FWNsojtb2sb2aj cTyFc7lHgaO1GSI3+kGEpJAHwa7zfHuREf9dCM9+GeeUq3yiS2ebXyLOD7SvVTxIzpBC wYzo/UKG3e2+ahvsGyuZdn2RwywgbmN0dwjE6/044Oqd5GjM9thqbSlCmTYTQJBENo8O 8GRw== X-Gm-Message-State: AOJu0YyQbA6vb6kBUalHlRqzI7R6I3h2tx6NTTUbKaOzalKbdutZq/Nn rF6ogvQdCrOVTSGrNezCdgdB24JBayPzq2W6zSu/S/49PGM= X-Google-Smtp-Source: AGHT+IFzcBipIczu0UM4gStcHPA5qOTjVF5hSW6xMiN01FgCN7Y6ZAzNQO6cw/yOKmnG0hURQ665bQ== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D112E7D0B2 for ; Thu, 21 Sep 2023 22:27:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233143AbjIUW1Y (ORCPT ); Thu, 21 Sep 2023 18:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232229AbjIUW1J (ORCPT ); Thu, 21 Sep 2023 18:27:09 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3F75A59D1 for ; Thu, 21 Sep 2023 10:59:10 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2c12ae20a5cso20084451fa.2 for ; Thu, 21 Sep 2023 10:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695319149; x=1695923949; 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=sWNn2l+mpR9EL9BRQHwoKCSva/7dx68nfcwg08GvNSh4BctD+DJZdvtU/ZAHoV2fVy 704okAtGpNzmOw1PduooCSQY3d/u9Iw/+oYjlfkIYqcjKsHmoAHj72pztP/43MK0g9nG R7hcukYkw9OEVcC2/lSIXq9wsFKpYgKI5EbkLGad2BzTt2Ul97WnvhjqoJJ8mFVZyXYV aGMJvWNg6WTJ/8XBjy7Fnlxf6Q4uJhcMmSqp5IrP0dntL0imlDnkROTbCMVI9dNNzSmu ylbFEF8i0IbC7CvScBWPSLwLPPs5neJtxmxr8b+/0Jd5DlsWUUuqDyWrvrX22nWGjxyz yWgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695319149; x=1695923949; 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=GcxkBSWJDBGyXFC/NDfWsbKDOQ2/OIlQPU1vzRY9Oqb8zOprHKKeqbtmjXytJMnoHu k4BWHm4FKizVZeWZXATZrhh4zHoaPg2+12Wf4s4l7kVS9klKpQH2r+iwL/Mv67yqaRVF R5Kn9Pj9p94enK59WXr4CxgTytSYBwfRv7iuB3XSCIX5QB6S6li8MUUjbRIuXUA6lH6I UiDlLRGNxG4r2OlkwRKZRin1OtULEHT/55GpHhdJYefYWqiBQaLbfll+csNVdDM2EOJ6 0SiA20Y6a9hXXSt95VIrvaJetDhnB+kRdrQGoY41Pq4Qw5x1ZMgHyoOpf5qswAIGtU4G V31w== X-Gm-Message-State: AOJu0YwxgBGModZk+7gRiyini1+haLEE5T6QJ8oztnxDpswsOOus/ywA qD4ovKYbzIBxwM9fWLW4A4ZWqQJBFVaoQZ57wZFtiX4n X-Google-Smtp-Source: AGHT+IEbn5IMsdjtBHEkcUJjQZ6PeFE6mcT6qeW6zrirIQz8hU6m6170Q4EKzy7+2zTNsR6rNCEY9w== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90C5BE7D0AC for ; Thu, 21 Sep 2023 20:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232209AbjIUUri (ORCPT ); Thu, 21 Sep 2023 16:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232081AbjIUUrL (ORCPT ); Thu, 21 Sep 2023 16:47:11 -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 D796A8F49C for ; Thu, 21 Sep 2023 10:45:36 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31427ddd3fbso1231198f8f.0 for ; Thu, 21 Sep 2023 10:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318335; x=1695923135; 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=eUUsSlFjHvKAE7f0sTeaSSViS1IXPGeAmrhBAPuakrxWdftwbvtRnIvoS0DxqIuMoK /8U5xVmMlkJ8EQDGJbQClMCx/X4eNL99g0RuBsPgJ+/5u7ctiddoGw/9oSXpf10EFFd9 ZW7nKQuYU/dRFk0JkaRNEROzGH4bkCK4rSXRJfy3trJj4OaEqUsz1McH8Ka5rIGPqIhJ 8slxjqVsvC3CyssyEAYCKZzAOocZhReInXWM2biD6rofNbDl5XfCRr7D6Ab0YEzmGa9V qiV/CjLR4IZQS2gXSKc/NNP5ZrhZ7cN4Kj3g2rmuKvVo8a083E8n2xMqqKATA3dylNSE Vfyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318335; x=1695923135; 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=JNM9j4J1GD61fFgQ+uT00r3OwEJxOX8+07umU4kwA3ki0+FcrHY5CiniOWKEefpYbi hlEdU2Iiawah5aZXA4x718T8bgi0269ZOpMje9O/n8G6kd9HmLZ7pgZPhGjqeeLjFaSf +Zc7uzYETV9a9hf3Zq1lJDYZiUKAdwDbBBdFXTVZBI1c6GRuLYxXoWvoeHEA2qgqYF1a +PN0ChLOOiTVdcpWiqNIL05PU76NmWe5aBzH/ymcMkGZP7F9XF2Jn4ItpTR8njBx5s7b xOjSvb3QGEomcduYRh8D2/t5jS114XDsr0J6AfHYmsCUlRWtXGMavcXFWn4kyRnmS0od N3Vw== X-Gm-Message-State: AOJu0YzNe4wJ0PYOOXAhiugOjFxwZiP7PKlnyGB35Q1fC0pS90ob9y6y sueXyImucz85m4gWOVyQrpw/98OQ+k9sy4MD0SFB3bun X-Google-Smtp-Source: AGHT+IEpFrDSoMcGwkX92bs0KANrkQRic6vkb2g8vJmtLIHbFG/3F3REKUYxWKXB+6gaHaSm9uvZwA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00576E7D0A2 for ; Thu, 21 Sep 2023 20:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbjIUUSD (ORCPT ); Thu, 21 Sep 2023 16:18:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231474AbjIUURi (ORCPT ); Thu, 21 Sep 2023 16:17:38 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85CB15AE01 for ; Thu, 21 Sep 2023 10:29:21 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9ae22bf33a0so529866466b.0 for ; Thu, 21 Sep 2023 10:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317351; x=1695922151; 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=fPov4pJEJR8vmoluOACwouZ/+kXHmDY/kV7Bk2BRvONEOnWSPR1HmDD26NE5S7wzpM zykLKW/uuPmvb1CKSa22N3sdEN+5z9qXOLG1TtpGnfjt85+i4TXLOTJOxCSx6HNK8Oir TLrZnWSnr9VQibaK8jhNJJVii/RJL72Njcha8gqWfZrLQoegOdtrjxDG87ATCv/CVRTq DvXbOgFWvr2xUkaOWHbfdzs6ebTBKMhsXoNIaYFPcKf+CAzMVd7IgHLGE/0O+61KSlsN mm3klhrRqwgkKTumKKTgPtAa2D+2ot4D35YkddpKZ1awU6dnB7M/Y8K4+fooJFPZ8otN FNsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317351; x=1695922151; 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=u6Oyy8Vft5vkYQqLGchweNeDWwWd4fgFc/OIFgO+rvmL9yfHNQaA41FuWCIl6F0cbI 4tWoUSvcv+3OSLMWp+0Z7z1EQaQ4eywLvkT9/OZJ5NCT5NwwrHjvQX3nMrKsFYg49IiG T6qU3Z3wW2bg1At6qD2oleSpAYCLXzhEbTmsWRckbWNaSeQaJnz+B2uxvjJ3KSiKOc3m 7AgSjF/7oZ+TQ/DCU/OFYHS6YFybsHreiIqHmqrdt8490qETz3MKwkm5LogCopVC9YOp 1fFs+RiOjHeEORZSbig9mLmfLFThdtFhFItIfxoxtpfQn2/OC4H1cKzky1mHHHVsV+AM K6BA== X-Gm-Message-State: AOJu0Yyjc/s5PaXLC2SGpW/ANsEAbFjktixg6koB53/ZW/T8neW4JBAh eAziJCeUjzHul3DuJ4t0RkTfVwaT/opOAz3I5tAM4+QZ X-Google-Smtp-Source: AGHT+IEeRgrsoxDfX29qrjpP91FiFRBv3vO2R0yidMQo5d2X1FKFBQlgvaBLgvFag4zdxsrc6bIIrA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9786CE7D0A6 for ; Thu, 21 Sep 2023 20:19:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbjIUUTE (ORCPT ); Thu, 21 Sep 2023 16:19:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231402AbjIUUS0 (ORCPT ); Thu, 21 Sep 2023 16:18:26 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DBE75AAB3 for ; Thu, 21 Sep 2023 10:29:20 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-99bf3f59905so150640666b.3 for ; Thu, 21 Sep 2023 10:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317350; x=1695922150; 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=F1TliWLaUbu8KINHlkXT8KssGRcrjc5tsPHvDoOxWazAcgJyhutZjJu8G9I+wK+xkh J5oK0ezlTGa4jEeHmzQw+ipxcs9LcyGE2YbdahhvuL+OmuJ5ZnO38oZ9FGqwW/fe3MMy s4TBT8UutRlqVHjwBzERvj1YKhTW92p/ySbhSJjLUjkBh2EvKgmT4fIoC91gXzxHNyre oAkn1HP9QejCxWTqAFyivxKQTi021DRO+jUMhb8FWWOU14LE35idO+ZbBUxiiAGBt5aW Fxo/QnU2C9Te91bqNoKcseonsXi5aTaFtMe2eLyM8JZF9hJNefNYmq1Q9Z8QqnjpWGpi Qq0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317350; x=1695922150; 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=s0xB1/lzfTG9DeK49Y+E8dUhdna5TsAgFNT5RaOMJ5ikRf6MPCbbRVGaztvGZNyNDg hdgl697qutfiBDqkwhV5TbnEOH4rtTGbq2eNoXNkV1iLvQdW0gYPehiCE/UOb19YfVuv 13d0Znrf8PNFrRX4zZi1GnqWMtv92E8Oxkv33BHuPniBvLfb7BYHIt1glUMO0D3jO4J9 SAKjnivWds0E0wfVNrQZeXCZrPCq5aXr1B1R6/htza7dP1F2fJW25rBuidiUydDgV5Ff B4wW+4BNZsj6PDQBTXGahQEghIJOpOX+Vmfgv+3oas6+YDH0UIGj1GAg3GD8I2NbVk/c eHdw== X-Gm-Message-State: AOJu0Ywh1uTK3XTN3NWtRCOf3jD6Czr/CGmEiPsmDwJlNthQf3XAdNZ4 Ir60e7m48yIhCLclbzH8VZbQ0g9mNID43Jd2nhiZ0s/o X-Google-Smtp-Source: AGHT+IGMZl/TatrnYES3LNioCY2DwT26zyGRXXVW2ZtQaBOVUD3PWf2yg31geciAz9PBdjwldIVOpA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70AA5E7D0A7 for ; Thu, 21 Sep 2023 20:18:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230510AbjIUUSo (ORCPT ); Thu, 21 Sep 2023 16:18:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231496AbjIUUSO (ORCPT ); Thu, 21 Sep 2023 16:18:14 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93A7C59949 for ; Thu, 21 Sep 2023 10:20:17 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-53348be3fe1so935207a12.2 for ; Thu, 21 Sep 2023 10:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316816; x=1695921616; 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=S5o2V64m472vGBlxE45OyYD3tt/c7uZMvJoVxJsUCPTzLRqGCENib31iydNBz1Ad7K hv9MX1nWXi1uYS76Mh3RvsTj6Qvw/P2edS+eTDK380z96Ig33ApqDdwkxpwJvyeqOhte NyPZQnNNNPDnaM3sN67v414l9UKz4It+nCrNGOAiwDXcN80rXuK9jW6G1feKw2RmDRkC Q3UHvYI0vmJIWKdeRcBI8+HzR/+fLDJIqOlVP0uRtDq5mTFx/wV70/Fh9tvhg9lVRmts RUtOFcvEH6jhyn7pJKqk1l6xbdPTOii4osQQzYhxEGMqK9KQ5s9Gm8TO/a20sb9FT4xc M0JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316816; x=1695921616; 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=ScQEqSKbbmuce5DENvwMocSPs55euknycpIjSZ1gLpnYMl9gKau/VvHbXrjGM5p4e/ afwiDN1pQTJozL0bo+q5fn6J0viBAYRO5gCsFWkbxkkZWqb27IpQz77AuMD0w1bLaWrn aS4a8Ov9WKpb0J2J9h4L0qZDLYMPcU+LE+4LcaqJX0AM+aRfPJWTQc7ZSERFfEtQ1Gjr 66/15kAYTS+fazBUmv4xLPmb/gqnnvhVtanrphzWEYcQz0lq6x5RSjcLLIBW06Zv6z2T LmzOoE62XyRFvHlb4RV0yMBygMl5+CiO2w31ZXDP41Cz2bwU5bXJtB0cNwB6eQHYK7pi GT1A== X-Gm-Message-State: AOJu0Yzz1RzaodQ+4yBBZqUMC13rdvEFO0joDy8E1oWRNz2tjllF5/fp my5fn6t5v74s9X7TI3lruKwbGU0C1RMKjXzp7u3X/Gae X-Google-Smtp-Source: AGHT+IH24xvDRaPHH44BwrDTbzdtwnxnkxTSk7+JyUWRFP+k6Au8hn9xlr4Gj5hf6z+Ngqc6nhucog== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E13AE7D0A2 for ; Thu, 21 Sep 2023 18:10:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230167AbjIUSK6 (ORCPT ); Thu, 21 Sep 2023 14:10:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbjIUSKk (ORCPT ); Thu, 21 Sep 2023 14:10:40 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0414484625 for ; Thu, 21 Sep 2023 10:37:31 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2c022ce8114so22052241fa.1 for ; Thu, 21 Sep 2023 10:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317850; x=1695922650; 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=fB7vXW/NhMOI6Js/N26E3xJTM2CK9dwdtonKQCa9J0L3hICLNlHTMeHnWyMCCbY0Yv IjoWJ6KbrYO/MvAYhdesR8LFbRWaqV8X4eTulB05mO/pQ6pZkmaCbmLjvj+IjW55wV81 Kce5HvWtPluOhtvOEUX0e2iGh/LkKIukXGVX8KOd4EWsGLreulEBG8sjbVnF4AW4b+i3 Kig0lxjquOt9WG2qbRuhUJiUR0cWaDy7Yi/t+88kmmEMOX4SthkWD22bhQQ5rNg+EIju eI2m3/D+Y4ZjcrnSQ+m/Ums606n8+MrX698OvL49DygcLweR+Ael+BKtdnJf3EVrlEhY 8U4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317850; x=1695922650; 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=Luz/YI+Ozm3eFBfuX4yLbt0Sc4rZvpI5SCY0dB36y5YV7n+QBvMb6TVxoxGe2Xf/Iu qQzbiyttvYxpgKJArsd40fbYLOuL8CZbcB/aPwhkRpOxae7ghrEN0IdgX3dRIX4fDPGY 4zBwhrRTaoAl+OZ1XWDpBexblKqSidRnVCwvZvEUfYH+WhAvJclPXJhfgtD6CrXdKUDc mh4qL4mzl/iB4qd9uwx+tPW3EnYJ3xQUOcpGUQoq7vvoeuZARg0AqBhOMvgOb8SkXfEo 77W3MhXxRpA+/tBS1K1zcEUJself4LthtOJ0TnKAz9bNm4fbhgd02phuXnKfOu6UZNON j3pQ== X-Gm-Message-State: AOJu0YyFvgSpSCB/0jh3zaOZtCqJgigHsOzX6P7lEh2F19PkVixxxKh/ 3rIVaNkcboimd/gsgK25zk4juDEnZIF3r8in6vaanTfK X-Google-Smtp-Source: AGHT+IFa6T7pfoopn5JTBSEWI36vfbyiw24+0AUsLx9pPvbJCm2m+UeOVaPi5jTX9jCOS8lz/+oyUg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA751E7D0AA for ; Thu, 21 Sep 2023 20:47:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232160AbjIUUre (ORCPT ); Thu, 21 Sep 2023 16:47:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232129AbjIUUrJ (ORCPT ); Thu, 21 Sep 2023 16:47:09 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6CC67BC04 for ; Thu, 21 Sep 2023 10:36:08 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-533352059fdso1377630a12.0 for ; Thu, 21 Sep 2023 10:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317767; x=1695922567; 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=OxLHxgoq+JLM16CH1zQdHJAeoYzObnyGvVAxmaCYy763XC3XTrkO2eEZF3HV6yfSNX AEP/t4Q8/QzvRgy3z8AFvNmWzSLvxYnF98YJfIzpAJkwNK3mhICpptofV6zx7yeRNdAa ho+4ct3K3PlP/GctvrSdoESaKp/wfZDxzD4o5xNIngWVpzvVZ4pbR9E76BAQm68BHyx2 7pPWhhSjw70bB8wWG5Rkg135mpOhjwWYZuLh0E8WYZaURmvByuVg3PKQyFWnW1aO5xaP HKKTfn318SCU3LE0aXsrrpYhjio7JBXpPTQp9TFMx9rpcMkMLJQSR6usRuCWssBg/EFF df1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317767; x=1695922567; 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=QX9LprqxvFEqprNSwA1CyVKfxQXXUqDig0aQchIkHKZ2queZ2EJz1eB9S136T3e+bA 9dA16pf/fCrnzHHBe1xYZjKECDJjOldF3Ke/L8e6kZEkWP/eieGRuAqulZF4MhDjPLrS 9crn6E97G0CCrTEwOcAhBwD/H9I+vg9Dnh/0qVeRFuRRIUOpPV+JU/UZjBRh2lgNcNjY VdGdh0VIj52fLto93FMypgt6Wkuy9bLQxa1BQm7ECarixqAfcIzDMY5RRLW252IehUjz oNGK/WfuILk+KviYZ1XWtd3VVCi4A4b/292knu24fz66Xzp6bTLWJhAgExtpJHj1luUx lhzg== X-Gm-Message-State: AOJu0Yy2tb+VBnxanPfQckY02mJzSW6HBOpjI+iRnHoJz3JxWtajmuNh CHe2B7gtvHFXpQC3/nYhMePjpouACpnZUU2pIKxaxB2u X-Google-Smtp-Source: AGHT+IEwh3hhciNn+4nfC8FjYHYjavgv+V8G7Z7Jx0IwjfGYAmGx3Axhwb5z/K3MHWEJROoFOAkI1g== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B572DE7D0A4 for ; Thu, 21 Sep 2023 17:52:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230221AbjIURwf (ORCPT ); Thu, 21 Sep 2023 13:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbjIURwY (ORCPT ); Thu, 21 Sep 2023 13:52:24 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B248101AE for ; Thu, 21 Sep 2023 10:30:04 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-52fe27898e9so1398869a12.0 for ; Thu, 21 Sep 2023 10:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317397; x=1695922197; 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=l/qGSxD7COvPQGWx5sqvgPWpKgAare2hW7ZQNGGMchEz2FewsGOMMzKyNTCqSq7NVr QPVWn9umasrRZujqBasThk40BQjcOK0h16erZK6Lp6JXnIOIf4qYoIz5CMH4PgTmd5Sd WmoSQDS9wNC2Sq6+0cdHTeo59cMbJaduDHgzOr5TFRlN0ALZDlp6XhFgRLfu9w2hYeS3 9nE6XqYRkplA5fz3aX+c3qJmpQWbUx1iR7hrHjSkOS+zeXzlcACjdfODBBHODBEDBqPB jFZ0DiVop1/1szGXatBnOgnI26JER9cNfrjU8BaQwaL7cJI8RUTC/jTGqY61E+xK+Hby vqBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317397; x=1695922197; 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=vLVzLHIGY81oGdU17NkogEVThAmeRNHMAUci94z0wY+FOOPmJorgmW4x9yf13/VdjG OqTNf1qmwCSPmCjCVLW7V4sTypEcNo+oV2OzuG7xl86nvDTv1+I4YP7fIAOxn5ItlUse jdJe46UcAisYxlag7q/o85eiH60lNMgqVBc04xpW1mh3okFUt+7aAxnrJncIJl5xJmtt DBPfxnSrr+nI4HPabGml78MP1q5GteoFivpvVqzOH49De1PskX4JChNCq7t3KeP+4wCm Dc0F9+sNp8/EJuOyAGSJkbaoUQxFoqR150MH+/kQHnryOsFdJa3GgsTlLDc6IMGqeubn ydoQ== X-Gm-Message-State: AOJu0YxUz2vqG9669DFURC6tBfHlH4p6Lyfp999qHEvxLrM+QKW30f5U tJnlxVDrg7ZHZs9XtX3q5tswLU3Yqp0Moh5piaVs20T4 X-Google-Smtp-Source: AGHT+IHTDD4zYuu6lV9x3Jl/iVplDBdwIifaK9LFet9fL2i2jXEx9floEa+zeO5CPOjwgUdMkMbH9g== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31F66E7D0A2 for ; Thu, 21 Sep 2023 19:47:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231339AbjIUTrC (ORCPT ); Thu, 21 Sep 2023 15:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231210AbjIUTq4 (ORCPT ); Thu, 21 Sep 2023 15:46:56 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 701A5561C7 for ; Thu, 21 Sep 2023 10:52:19 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-400a087b0bfso13032425e9.2 for ; Thu, 21 Sep 2023 10:52:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318737; x=1695923537; 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=VzQLyXUsjMOeKvBPyj07uWQGtUKOu9NSyLaaQtjtf7Uel6fd8vx5Hvr04+uf0VkirS ti/xhmEODcTODxKQVjz9aGGcsn+vzrheoA1t++M3PA+MtQ6wMdoiCkiYJQi0IjAmouz/ X/VzlrUXq5GIxI8joQug85/V14k2bcHV3WbJ7N8NP7j4/xMa5GwK+AhAwN9AGJ+KexRE NOhFrG/ZJHauk5z9eXu3FJMDyoJCltdHDLMdkbvRKOON3KTeNV/It1VgpSqv5tn9yYuz x3fxh6ApFvaee0cWp2x76o1EhgukpPhF4YurYILrx1rtivzmhLM6m+9vyHJBvDmpqgUN 2bGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318737; x=1695923537; 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=QceK4RHbADnpUGSE7/gi/eRWPmysBSUk8zke4Cl+K+HGloFnZfUPBlAxYrtsAgy3DO 7/ZIS1zcCGnQKW8BvnikOZJIbzSdUePDQrqFJTvWYgvLMWyp5B7H0RGbk1sj5Vf63Ysr Io5xFjQ6ysZGxfW2OMQ2M0911+UhcaUbnKVMkX4Rs2uyIi0Rm6Gbb3TsxCgGOZd6nBNf NIVAErcPscWqOxnHsnFF7Fm+W1e7ffTfVMUN+dIdyliWPQZ6qi/ZH36dih6LHgwGkCEc Pse0pO7hAA9RoOxq8Ja0lmXWg9oUbaBJ76EmiU8p7T/5HD7TMlMc+4wp4cgbzcpLUr9i aIsQ== X-Gm-Message-State: AOJu0YwGzh7OwixBbJSfdDW3gJZmFfPv006Fat5Uo7mIvYNo+wzFYoeX YBd8C4fweAgAWa0om9WRMHvFI8dXWeyvutX20Tzs/3Wv X-Google-Smtp-Source: AGHT+IE9ZEE6qW3Uh7F/2SHDgzRpOaJowWC7a1ZsGgdxWu4OvSFD38FqiRfJikCDKaiQeM4iFx0WXA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5CA2E7D0A2 for ; Thu, 21 Sep 2023 20:49:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231951AbjIUUtK (ORCPT ); Thu, 21 Sep 2023 16:49:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231641AbjIUUsc (ORCPT ); Thu, 21 Sep 2023 16:48:32 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E203C79E18 for ; Thu, 21 Sep 2023 10:34:36 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4053cb57f02so4285e9.1 for ; Thu, 21 Sep 2023 10:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317675; x=1695922475; 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=2YrbpNDt3gHyt0wFxrBkTF8igbOd1YJVXmjSFUQaRLdqbfrQFK9qnvRdSJR1XfWy1/ +itXKUZHtYd9KeVLVTe/U9ZRNiwwAzdXewbRI0rpLcMsIokI3BCujJIuBtWmV+aGHh/o 2em7HjIGu7afbvNB/I+5a0CWp5IHFEeGG1USwF4XmaC4OadLivHT0HQeHqDm69vnvRzW SMTYpXGBCxYItp2lgMBCDMlBWUoNT3D2pdzH1Pqo1fwGPYf1Hx4Amia7O9G6km4spU+c Qb+viydCpO86BGFSz5Q7Lj2WSKP6xhJCM8gRBxBtYWnl0CYr2jHemx+YJXT9JmTOP10s buWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317675; x=1695922475; 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=Js5umDd2oD2EaSSaTZGn91O1BtaqcaI5D2wS5bQdUOVUeEXQSyL1c86Mr7kDBZbeSv Jb6HzK/obu/mvuL0+jnKUv3NXeRlDblTfg1Mnr2V2A0lSl3ddzbOCwmltuL4vMb4lJlX pCBXHJdQ6eQC5JUJE6/Syot1EP/PA9B9ky4rvaZ2rjfI/4Yvx7FnOhwACHXTk8b7m/+N z2Cbto1styqAvVro0lL/HaGewWzznPB6F0Hab69v6VE7ENSh2M8yEjhsjmSQFVso6J4g AwcDKTo6uXD7kWlYGOWGm0W01U5PCYKgx2geTSIdmAwEAndf3Eq10G6DpgwYvPNQqnhe yyLQ== X-Gm-Message-State: AOJu0Yx2TxvoBgmKjc2PsCZA7Q6W6nxt67c8ceGcuy895RoLAx5McE9b yj74btv9/sQ+n0yzOTLjD+xiOkgZqf5dq1iDe39F6R2+ X-Google-Smtp-Source: AGHT+IFCUopE97lC+mXLOTM0jAVuUZKw4B0mX0fpS6Q9N1Bhfhwc3q0b7TASwl4gdJoses0AW6P78Q== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org - 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: 13394570 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E318BE7D0AA for ; Thu, 21 Sep 2023 20:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232238AbjIUUrN (ORCPT ); Thu, 21 Sep 2023 16:47:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232333AbjIUUq7 (ORCPT ); Thu, 21 Sep 2023 16:46:59 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D420057B0A for ; Thu, 21 Sep 2023 10:27:59 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2b9338e4695so20607591fa.2 for ; Thu, 21 Sep 2023 10:27:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317275; x=1695922075; 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=z4UObxiJhlLbYiUUrbxfXUQG0LeHK7WW/VL6d/4i7+tzfNzTL2WsrHjqIKYe+fn//i GQzKc0Xuje21djsIBDxtgKnacuKm3rvtnF44et7TUs1X4x29QCx4ajMWU1uCsYHlop/G LhyPSKX5Pe7eXf1mPOEEx/nvfKeRk9LwE72KEPPpBGvDufPqtwwitEOyhWTFIFeDBaWb 8xW+kbK3kTUmWeACnR30a3WDxm92Jr2YN3m8bves1WtQoYbBBuK8ZDTvKv7I6TFCZXgG C8XtibY8muC3zfKNd5nIt4LK0qIy3x8xIMicegVCjJ9vZBD3T2oL/mn8lljsVDD49D3K atZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317275; x=1695922075; 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=sELymDzlPBAtpkGjAYdXIy0JGr2NqFSHrveT8ZXu/2BEFEP3Ay0O6jMleQTubz2qeD MtJGd3HMFtbqXCyKmG5VLCyPR26ioH+RCL+v5DmyO2BcX1KO9TnW/MrI7uq2LKSoIT44 y1g4BADLkYoHlm0a5F8snl7G9JKWBhS0UmtMjYH7DJvaw5IGkeapit115MmIFTDlBKkx d0A6azToLErbvjK1aZMxvv/d15VoH5y+xver0giqos57Ji4UoKTftegQ6jTu2w2wbjr+ bLNLOrx6LUNuUQkHBrYG3ej/6j0xGW/Gah0OYOJq77+ZoK6qXe1KViQ6JYV6LDoUw758 wFSQ== X-Gm-Message-State: AOJu0YxU9fjOZyZCn/jIztc+0a47UK/KLt8Kwwnpt0YJxnWaaB5Cwz09 fRQ1aXjO6D9UcViZgdwhb12pYtAignVup9y//qyc75mB X-Google-Smtp-Source: AGHT+IHJfqFR4DsaCVjmdv+KrypDdY1GIjA81595SeWzOf30lcIqONwMBeav7UdV/0Pikd2g4z/zFw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED9DFE7D0A2 for ; Thu, 21 Sep 2023 20:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232239AbjIUUsp (ORCPT ); Thu, 21 Sep 2023 16:48:45 -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 S232259AbjIUUs2 (ORCPT ); Thu, 21 Sep 2023 16:48:28 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E50FD8DEDB for ; Thu, 21 Sep 2023 10:44:14 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2c022ce8114so22197841fa.1 for ; Thu, 21 Sep 2023 10:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318253; x=1695923053; 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=av2k9z8HQ7vNiD2ypt1hXtvRgk/5nUuB+TUzxXVJU/5rkCQfZ+YEZ4++CzdqJKseh2 KxEEuzQmbcGAmAYZQltrWl61eZWEiThmKMR6v2TiradjDauT6R5ztl2X5AXKgHOmycjM ar95s4QWkwS8xDdp1ErvPh5MHhK1xfVsrEUVuFVRO2YW8S6umF1DA1TPlawIEX1e2kKA esv1QUv1e+zRkvUvW86gZ4hIFQqeN3rDXmopuVlSiBAhr12jRCyHLqKv+jq1oc3UGRi+ 4VNDy9YKFpKhPJkxwRg0Ii6RZv9QKeeouow75TXLsy/Q9x5CZbknIZ5GhqlZqgtenMby QIkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318253; x=1695923053; 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=V4j1mDycWPNL7clPiPsiwce/2kRQ7Lsb13q3PkO/JnGXRGEIdVUawE0qLJLLPrJb7f KC9i2HSXW5cvq7quZM9Uua/NnSmrIdpWfPQ23HO/8DP24Hc0w/I9XxLF163d+dWpE1gG lIP6AbBdLLwTe5em/FpjpkzaOXZGpTLw5ESOM19NNGMquDXH5eTaXjZ4fPK2eY27t5cO iSzHXGgWm4+pto+WSJxdPbZ3Uxf1gaSjHMT5msRf8E2Am2d1tZPtDYpGvyNj/0Q1kBwL husRY14CXACjdVbYBkQA3i4TzYBk4c5Y6RrQeJUB0mKYj6+b7ap5UeCW4kDKkHasCBcl 8RJQ== X-Gm-Message-State: AOJu0YwsSSgmdzpUsSLPGHH9wyuwBXB1Yqg5AvspffpEsUIljlb68tMm tAk5OTumQ0TD432OS5DA+pVGUBjUJnILRtvYArR1LGmG X-Google-Smtp-Source: AGHT+IH9cj66Ps0WLbNpON2AlXKRfiUMaOxHt4FNCDCK4dpbBCjBwlo7F8l6CXuniG5eXJc7Yk/jUg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0B9FE7D0A7 for ; Thu, 21 Sep 2023 19:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbjIUTFL (ORCPT ); Thu, 21 Sep 2023 15:05:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbjIUTEM (ORCPT ); Thu, 21 Sep 2023 15:04:12 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7596D84F26 for ; Thu, 21 Sep 2023 10:53:54 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-530ea522f5eso1407927a12.3 for ; Thu, 21 Sep 2023 10:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318820; x=1695923620; 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=OggB7gl6/72NL3i52bBilcJ1EIGb43pTabE8avDOG+gePNmkYyx46/F3jZ+I7Ol1DN N6KyAzkMOdPC60A6CsNDorkp1UdwN3AXoCuDHT8bqgxIp4pSfl06YINltAxe4dkPIVY7 59Wv+4AHp5x0ioVJBXLCl50Jw33MeVCuqH/mH3fA/wTPYlDnnMnqivOsrO7qvDXqpJ3u BDuKRot0Y+q1k0MC0r6Ivw+kxnYJ6o5Y1nMU86JR/zRsc95Fp1yoO5dvoEWgjUghmLKI lAHVpqxEumv5MBSuJTdebPXTj21d+WJim+IWRRuE+di9En1gRpb7+p0JJJ+AXoOPGg13 a+Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318820; x=1695923620; 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=j3COztwPIUFC57m622Y7UkXi07gLSNM39zz/TvLydNdH+nxT9zK3ydIABZA6oFXExK YIMBtxvS0Zkd52Ss5YO9f4ZC4fFMpsPj4rjc9v/NCXeHd2VvfdOsIIepFDvKFzyQvJQU zhwQQ0fXEnLBKuGN1GemW16SCnprqQcSKDCkowTmTsMtEuV2i5P4Uga4w8XJnk/DsBOL vKPI6zRGKZFNZYn+RiaTKRFuo6bbBXXfk21ZEb1B37Vx+MDo3sZtYnJjV8enLv1egX/0 vMXlQM5vGE8VS2CLsa1YZGB1BVdj11zL04OwdmhOfU5MaFNKAGQkEM0DQ0SwRpAAM1I+ DAsw== X-Gm-Message-State: AOJu0YxU/O4komZ4E+n3l7P5PurouN/CscuNNG2WmCP1vIkPpXtAAOHb n0j5McQWXovbhfbijHjztDpjOljophwFqFbujxGb5zX2 X-Google-Smtp-Source: AGHT+IFyRSQ9sVI6svVzHUR3normBxbHxw1ADHwq9tPPMiHuaAAm+CM2HzCwtdqMZnvyJVaEdPWyUw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20E67E7D0AD for ; Thu, 21 Sep 2023 20:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231898AbjIUU0s (ORCPT ); Thu, 21 Sep 2023 16:26:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbjIUU0Z (ORCPT ); Thu, 21 Sep 2023 16:26:25 -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 B96BE8CC9D for ; Thu, 21 Sep 2023 10:42:41 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2b962c226ceso20762821fa.3 for ; Thu, 21 Sep 2023 10:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318160; x=1695922960; 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=v2j0567xHdRrAXssVj+BSI82ZPY/ApibyVeMd7TqByZgzIBWwZdiIeKnep3AsI5iNk Qo1vWx4xzvHi//SiLU4VkBGXDpzLvtlyZJGwdEjEKaC2Cdaj/nw4rLEeec+dUSM60yWe ylKz46laRj7LOqvU7A60ZtBhD5jeKWZnJanmj2VnXiG2nNp0TeHC3JOzeM5clV9gedqe yEYStLu0lApuw5TK6F/cDS5e0s0tqxFpqijHjXXLCM74oqOqOCfp4vUwKitLZyFjf9Na 1iDeT0/JjhA3l03lvIZD44vWDB+J9/NNvsiDIx7DW2nEh1PWf6HTBM6diXVkDeFaht96 Fa3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318160; x=1695922960; 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=b/t88Ss3QPNXzkdTONdn3LQFaEIuqG+UkzwgPhyuYIjHgTzXg9MgjSF/TKd06GYFcj J6pWhAD+KeF660vkXiARzIorsumNjaxf9ZqRLMkfTBVS9U+Coq1VjzaIoEaO1oo5cPob RIt0C6RsNJuN19wVuBd2+aaORKA86tjMIm26mkvRC6KXGFItpJE5bOlcUC5JSp/Qo9XK 7e7EZPowC0xUBbSRbpLIzXmdsgMbzye37uxVlmjo+XkNKky/DI1PC13tk+64mNtiWt+b 8CSLc+i1P4gWxNheD/KVH316P2qd8J0HVFigH2bdkrHNmZS6Kphn+H/BLcyOKbc393eh LKKQ== X-Gm-Message-State: AOJu0YzZNYuSJObvDSF4qWe8Ybt6/+0JzwBTIuirBsT7yx8edS1p32Th yfhf2r1Oz0n3flzSkCFBE3YAPQT8YoFXrOKppQhBV/fT X-Google-Smtp-Source: AGHT+IGzi9ygNvTFbE+Q0DTN6Dqq1DY5zH+YbCcxdTub+gBa6RSxhhAqH5GwDY9iR65TpVMFQugkOA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F184E7D0A7 for ; Thu, 21 Sep 2023 20:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231646AbjIUUV5 (ORCPT ); Thu, 21 Sep 2023 16:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbjIUUVf (ORCPT ); Thu, 21 Sep 2023 16:21:35 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB8C3101B5 for ; Thu, 21 Sep 2023 10:30:06 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-50317080342so2202305e87.2 for ; Thu, 21 Sep 2023 10:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317399; x=1695922199; 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=0WVWNZEUsJC/IyDOsqcc2vpP86x4fu9BAV2VIe3dVltc2OxW7GwYP/5ZFRjY0HmufQ QsEF23O4ws1HQgQgZ+n7xNQ6xSI1EKepGkA3etssvi+MTeav1ruteoAufLLHcQy3znRa C88M1KeO+IsN9HmU/GMTtuB6nNNAMStZFO80rbq1OwByY7h8oLoXQ7R8I7Rb9HKB2dnU RDA5ljZRtmanrkAsKasqGIQuXm9kAZfYDlP8EqxXNGFL0MVcbyZRP3iOcf7icleSHIX/ APyMgwc6Cihx2/swHPmVH6hJuo2VDYy+ENix39hmy4dNen95EE6puQO63Jh6TqHCLMdo xSuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317399; x=1695922199; 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=HGrWhgiSTEBt76B6qHd4uYxnwt4GbbgTkyhmxjhtd/5sOQ68HRkEgnjGMfgEzCNwey HiLMf5hxisyQmUJhkSL2NpJTIN8PXX/XB3OEqs0aWNzZdsMBN70/qtmy8cEdedc4MXRh ZHF0JPfcOQUx54hi7Xcn41S9drkCfE3qs2aQg6/6/i6yDDFpfFicU5z/QMz8JjSe3sXh Piwk7BV0ZQ3Dmc82uxDSqKPpHoHQUVlVHF+cR1FpGrMwLzM7NCiyovkZ4WPB1JYAHG2N 30hZoM+6yg4k7S1jvFNeqMoHXTbfDNuv0PtP/XbC5eXzpB3pyjgfqQDtL6J8cnWj0+jH poWA== X-Gm-Message-State: AOJu0Yx7eid3CP6DzO25bk/7rTVF8Hc+MWMY2jr4GbPavEbW28lwE7Lp B45fo4K0+qfYvLWHdHGp2fWixI09gfLBLDnvfcnf4zOX X-Google-Smtp-Source: AGHT+IFQ0sTrKh3A+gVntqh1ExJr1OAgV4DcRjLG5h7bF91pNN2MfZNHke1Xmsy4fIw1aiNlm9pFPg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: 13394342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83C05E7D0A6 for ; Thu, 21 Sep 2023 19:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbjIUTBr (ORCPT ); Thu, 21 Sep 2023 15:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230410AbjIUTBU (ORCPT ); Thu, 21 Sep 2023 15:01:20 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 293108D235 for ; Thu, 21 Sep 2023 10:43:20 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-32167a4adaaso1240117f8f.1 for ; Thu, 21 Sep 2023 10:43:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318198; x=1695922998; 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=j4Cm5wtHmhY0mfiofQ6MIn14iP5frMzRUoBz2OUCLUjS6R+a9rtZoxn17z5GRgLSAx OQnFHtzEBv7b4fLzPeUpDUXaljdy4n7YSeUzUFsG6Qd/iHmtErplisCGRMhRfsBZDkqT 19G6F8+hOJ6FvSnBzk62kApnRBjvbw7nMHmyAZPFtfb3PMivmcJqAuWAlGHC2FsJgx90 QLYo34CuHf9pT8QQdKpe3qUSVXA1HKIwayUbR/ynHbCvw7j48AU78lRsCXU591PmEPhP NFEyV2xvK/jo75DbfP4258yoSv/SZ+6i5/mYsotsQOxrjYebKJGtgSQcopvi2hRevI/r vRwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318198; x=1695922998; 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=bN2j/26rgvPoGLXIcyD+ovgnLCaTzL9GhtTfOG7vDgq8I7kvf8VOC2c2YMQADYo8ZF hh9cnMew/a8+YjHK4w/mBqm5VZtv0FV58YKllM05kxKQycZu1Z84XBBLM/AOf4xk3Nyg c6UkKAcOe2nujOTVtEfwP0/FyeXekP3ElmlvVXLbR4ZTfFWufkrQUfpTJLYH0cPFis25 qKG2igSFYQ8xjsSIBdpPbmAEi7PnSunk0ypvyjuNfakuiVoywZxdHICeokyEXooOoYsW yyG2rdV7MbzePeX0tZJ1VuHUk7D3TFqxZ3/ZRySt7jKBgHQp+CU/OvjrHKjvIWQYkxE/ SxeA== X-Gm-Message-State: AOJu0YxNS87PF3bbO4zlA/SRkSdGFS0F8r4ukDqZw3rnLVxKku+ILilq FE+rhDzlnBEu5kksxBKIQ4cavXw+ZWP9VzCVm/R+cWQ4 X-Google-Smtp-Source: AGHT+IH08jq16ad3p4HMe9xcyB8hweATSv5qN9lzeXRVPAWw2aoHMZLAHGaB/1pFA589xCpY6igblA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds new phase_lock_range and phase_lock_range_available attributes to the ad2s1210 resolver driver. These attributes allow the user to set the phase lock range bit in the control register to modify the behavior of the resolver to digital converter. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 71f0913b7e2e..f5b8b290e860 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -259,6 +259,60 @@ static ssize_t excitation_frequency_store(struct device *dev, return ret; } +static ssize_t phase_lock_range_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + int ret; + + mutex_lock(&st->lock); + ret = regmap_test_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_PHASE_LOCK_RANGE_44); + if (ret < 0) + goto error_ret; + + ret = sprintf(buf, "%d\n", ret ? 44 : 360); + +error_ret: + mutex_unlock(&st->lock); + return ret; +} + +static ssize_t phase_lock_range_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + u16 udata; + int ret; + + ret = kstrtou16(buf, 10, &udata); + if (ret < 0 || (udata != 44 && udata != 360)) + return -EINVAL; + + mutex_lock(&st->lock); + + ret = regmap_update_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_PHASE_LOCK_RANGE_44, + udata == 44 ? AD2S1210_PHASE_LOCK_RANGE_44 : 0); + if (ret < 0) + goto error_ret; + + ret = len; + +error_ret: + mutex_unlock(&st->lock); + return ret; +} + +static ssize_t phase_lock_range_available_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "44 360\n"); +} + /* read the fault register since last sample */ static ssize_t ad2s1210_show_fault(struct device *dev, struct device_attribute *attr, char *buf) @@ -506,6 +560,8 @@ static int ad2s1210_write_raw(struct iio_dev *indio_dev, } static IIO_DEVICE_ATTR_RW(excitation_frequency, 0); +static IIO_DEVICE_ATTR_RW(phase_lock_range, 0); +static IIO_DEVICE_ATTR_RO(phase_lock_range_available, 0); static IIO_DEVICE_ATTR(fault, 0644, ad2s1210_show_fault, ad2s1210_clear_fault, 0); @@ -552,6 +608,8 @@ static const struct iio_chan_spec ad2s1210_channels[] = { static struct attribute *ad2s1210_attributes[] = { &iio_dev_attr_excitation_frequency.dev_attr.attr, + &iio_dev_attr_phase_lock_range.dev_attr.attr, + &iio_dev_attr_phase_lock_range_available.dev_attr.attr, &iio_dev_attr_fault.dev_attr.attr, &iio_dev_attr_los_thrd.dev_attr.attr, &iio_dev_attr_dos_ovr_thrd.dev_attr.attr, 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: 13394571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C67A5E7D0AB for ; Thu, 21 Sep 2023 20:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232344AbjIUUrN (ORCPT ); Thu, 21 Sep 2023 16:47:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232346AbjIUUq7 (ORCPT ); Thu, 21 Sep 2023 16:46:59 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0F138AE2C for ; Thu, 21 Sep 2023 10:41:10 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b95d5ee18dso21102421fa.1 for ; Thu, 21 Sep 2023 10:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318069; x=1695922869; 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=3cZ51D4gP7FBkpLaXjrBoFu3+ac1iL5Ff+U4hImBPWDERjACKAMd6yUKFBCimH5DHt Tlet2mszBs54G0UnAwnbMLIkekzaUyzKhrNAtY0+7gMvvIJH/P08qpzOE7EXX2Wpf3NZ ftjhJyVnXGgN/Z/SNgdP0q1yO2AXHxIT3rmsRNJG+H5o1EZJV9Wl97wRcm+ySzZ9g6Bn GFaJi6F2AgwfLghEi1XB1Qx0cYYzdkwe13fCgwVa/J8+w3NM1J1GzJP4SmZSJGqUoE/Y HeYJN1X9BAWUPKzjkZ9H+mrPQkBbAQUjc1dHkkLy1zUpE5jy5CGCmqq64BN4hfUlcsSy 4FLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318069; x=1695922869; 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=EO9KyjKEX26oQLqo6fZ6A59n2qXCg6T1wYd6rlykqBD+XVumEq3f4O7M7v2wbU4xF2 AcjNGBBlryXQUYqznsD9pVBRHLIP7SddVrz3fSK2IukQH6Jtcx55MeSGZQg8+j8yFKwW Khpyrd19mMKVNEJ5XjsdbqSmYOTl7efZTBjj03zsPOL3QwSsNbSPDIB5FAzdKfxgfo5L KdGvfALkNaRnoGq8KC/eKr5Il7/wrpOVWeIsL4ksiqWm3ijPBH8DmXhDlK9fxPX+4pYu CIF+I2CWFbN007p/lEHo0J9lJMwuujtqkGS+UWVoaIPERFtEDyCpGVVwx/E56+feo3S6 GdBg== X-Gm-Message-State: AOJu0YwzPV2mfoLJq+jD3TasZNQkbNMCLyRlPZIHMdIpCkN5/w2uhTQP No8eqCKO+S7+mpJr1ihGs6f6C5BznuXfqn4JW0KP46/H X-Google-Smtp-Source: AGHT+IFr5GjddnPlZ/OIX1F1eX1mtogYABeYtRFcW+TA7feS7ZNjH1l9heWGXc2fqvb3clHUz2cAVg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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); }