From patchwork Thu Sep 21 14:19:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394238 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 E3166E7D0A5 for ; Thu, 21 Sep 2023 18:10:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbjIUSK5 (ORCPT ); Thu, 21 Sep 2023 14:10:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbjIUSKk (ORCPT ); Thu, 21 Sep 2023 14:10:40 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5087C89DAE for ; Thu, 21 Sep 2023 10:52:43 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2c0179f9043so19751041fa.1 for ; Thu, 21 Sep 2023 10:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695318761; x=1695923561; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SZXK6IdVBTSXcGTIHRUU/WhDyCqjH/rftizzn5sbxAE=; b=ts5O8hB4RDvMY/iA0Ifh/ap4tvqOo2OoYrBdaaA5616xAmA08MXGHoqSfpCBiPQxfG /kgFxboiHKGuq5TlapMFn709PlsxNRgsk76WiGFXEmn/w1wkDuAKIpFEgTrEZmyRoexG SAYlOcaOZIeuoPRRlB5s5OeQ9KqiKUPdZEYXbHXlj2slQPd8LFGhXVHzsGTOptaDqjPP NiWK21JUl/K0keK+Xp96ctXkmMWZpqIjQz4OuLMh2/L5h5XlDJjnWVYx2K74sKiVDll8 f69samtZC7WQqEP7Y8wpwqfMKaYWENK02xksoQeSacflt6kAEVlTS4OWXUgW4zD4fqUI Lz0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318761; x=1695923561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SZXK6IdVBTSXcGTIHRUU/WhDyCqjH/rftizzn5sbxAE=; b=DSdz1q6Fdrbi2X6O43BRNXT4d3RnXzzOlpn3mLrnbja48mYBSayGqh4spYA6AkuKLA PfBjwo7h3RpiSqocXsqvhmpblLnaIgdJb7xtjjEYmMeQBKDsk6x4iG8SSMBYF57TfoYk fCC5jLDC4Jf4WjOf+QFwMlKSJ4s0B3M8woWcBee9torSQbwmwb+WbpbMVVSZZjuZEqWW hYZgZbcpoFrgnZWWc52Y+a6uRRzD/9VJVTGEoraXwRxoAiEGjVObY+NTXzHoxzjoi7MQ zlzQhc18ohw5P8T/NS529czECaLb7n8rSIdLM5H+cvuSpbIjzKxW8isReylZKd26Sp2a M5aw== X-Gm-Message-State: AOJu0Yx5TwGL42IxNldb9U1qjeflNaOQlsNqg3ZhJ0p0SOHu43oc0+/+ effrNzlMAdbpwHT0dJd8Wydj3V6mgJt3RLdBCmnOUxwU X-Google-Smtp-Source: AGHT+IFEoId9dhUAMXkJBPEIyyf6kDoS3FhAfCiTp3N7TsdUJvie1QeO4TIHK8ErhC7KtOLF/MPK6w== X-Received: by 2002:a5d:4292:0:b0:31f:f753:5897 with SMTP id k18-20020a5d4292000000b0031ff7535897mr4864012wrq.59.1695306150891; Thu, 21 Sep 2023 07:22:30 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:30 -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: [v2 01/19] dt-bindings: iio: resolver: add devicetree bindings for ad2s1210 Date: Thu, 21 Sep 2023 09:19:27 -0500 Message-Id: <20230921141947.57784-2-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds new 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 --- 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:19:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394457 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 29FE5E7D0AA for ; Thu, 21 Sep 2023 19:59:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbjIUT77 (ORCPT ); Thu, 21 Sep 2023 15:59:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231500AbjIUT7q (ORCPT ); Thu, 21 Sep 2023 15:59:46 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C53D43CAE for ; Thu, 21 Sep 2023 10:23:21 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id 38308e7fff4ca-2c00e1d4c08so20405211fa.3 for ; Thu, 21 Sep 2023 10:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316999; x=1695921799; 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=EKeygh4+yCldeC17x2OVoxSCsHbk+Ar5PnSDyaEmm5W9hh3PGVzZRYqb+gc/jd4bts TX9HWnwP7O6jF2OK96H6XTn1LF4It5Iu5ciwxIsSKkxKc12hEWghvcF+JaWpl+3T6FgB dizVoDfEdKvmiY9QC838/Z+9YMPZzZh833Yk+aPcAI2+hAFf0XPu0zJEiaeYoJUCEWt3 8auejeLigyRKP4kQQqCBSTUcgxFM+t3CzyLiDA/z5uFHWYiDTUF6pyzDuVSjGwF5QHPQ L6T5qT80Wlo/16S4uDabgmKnsYPtlnoHTFjYPO6vxA2EBnP+745rxuTYTolKkswg6mhh sZ/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316999; x=1695921799; 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=NQ+1BLBT6HWLaUelM3k22EhYKrIPvEPDMcJC+rg01AobqKnzaXQoqeJlBkn8xLqbzn lAegl4LuwUu2DmjRpiTMXqPzJHjdrVann+xeHNFXi9YchlXCymzrj/DJbJ7Pit3jQz5n Vqh5+zsE09XTaxQjSLkP/W8Fi6n8fXKMsP9ss8+4nbfogLBfhJ4ogTyDENJcarTgmbl8 A5qgZZjX/wbo+a3qPpX1zIyBuPbMUdGVh0QprrnVEHBJezVbPdCyCr2+1htIJK8Tv2xN 3s9ZHCT/MQxnPkfItcD+sJuzejfRyHABF/erQqoFTq/TEWAqxW9x7eCstKzQBAdsRSDe cQAw== X-Gm-Message-State: AOJu0Ywys752PLGv3QIYJeubVUP4f+G9nCt1JscJlGwCwqRqrYLBAaqW ga9R7np6PF8sF7yaBWnPx9YEL6KJ5FfKdI+UMK/8togyif0= X-Google-Smtp-Source: AGHT+IErr9vfLKcGbuaDz6p0WEc9gtQaWzHZCdYrnWpb8xs+8uWyyRU6Xrb3jaQvYbOOtHHu0seULw== X-Received: by 2002:a5d:6405:0:b0:319:6ec3:79c7 with SMTP id z5-20020a5d6405000000b003196ec379c7mr5205794wru.36.1695306152763; Thu, 21 Sep 2023 07:22:32 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:32 -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: [v2 02/19] staging: iio: Documentation: document IIO resolver AD2S1210 sysfs attributes Date: Thu, 21 Sep 2023 09:19:29 -0500 Message-Id: <20230921141947.57784-4-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds 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:19:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394123 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 EE6A1E7D0A1 for ; Thu, 21 Sep 2023 17:24:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbjIURYZ (ORCPT ); Thu, 21 Sep 2023 13:24:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbjIURYF (ORCPT ); Thu, 21 Sep 2023 13:24:05 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6C740648 for ; Thu, 21 Sep 2023 10:13:10 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-532784c8770so1463886a12.1 for ; Thu, 21 Sep 2023 10:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316386; x=1695921186; 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=2cLamBgFbuV4oHtjQATBRq3H6ggxaukolIyxrg2Kug5+HuWoJa9IAo6zGyW5lne8oA TOOJLZkcBLSxKF16epf0YBSeXLb1w86upNK13/kMiEElXus15h4Bmi2QY6sCDNKEUH5R dVDYYG7h1Kd4PH37FW6F3y0TWMk20iujbsVKbzewGCl7zq6fFkE8gOGu1Gx4LzcvNU4r HNXR/GLLms+zWEN0Le5F3CbbyKgcpHsuLLN9YZHbSYgPQzpvqZGz4V7vIFPaoMZHcL2w EYTaRRkXGlet2prTKxluMuVwgEuj4QLQsRSL97TmWoWunhlvvU07u7p0LQvaohCLBXLq 958w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316386; x=1695921186; 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=hUxjtuHXLmxAtQd2lIvXMf4XjsFk4FXKGPmW6c5jYAjwDC3w9vGkrp3vsInWRL5k2s fmOZU17gJNw97xnOQ5HnLzCUYkZZXh2cuaadtG+TIwIoonJYxbx7p6txFl1EO80UBLxh 3flN/31XL6D4n3KnIHH7WKD9rJO7ioK+VxgPZZU2r/kHXZdb74D77qYONM8ZMEdXX5jO 4BrI2NiKLyA87eMgBpyRfgjy6m53Ws9IC4zELbLQ0MgCsMcOyaEJCvW0N+vDBdKdWc45 LPN8ZlTuD7Q1sH4qpUIdc1ygM7I+/jghxO7ISNTXaoKFpiZqkvtNHi177bRpncGl1lZ4 az3Q== X-Gm-Message-State: AOJu0YyG58+y2UMTQ6SDTmGtAqrjJiAlznfwrpCpw++wNvNe+hvUxKZD 7Gj1mR4OwNtGQHpk+y0A6+Jt+jxz3kHxw9WhwCvssa2x X-Google-Smtp-Source: AGHT+IGfS13FEnLVNfJuIWeRBxS2FNjPxoFFMDKS2aE22dbReCOydRtLnM6n0AwKa1SbUdaYxLP7RA== X-Received: by 2002:a5d:4a82:0:b0:31f:ec91:39a7 with SMTP id o2-20020a5d4a82000000b0031fec9139a7mr5419502wrq.14.1695306154592; Thu, 21 Sep 2023 07:22:34 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:34 -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: [v2 03/19] staging: iio: resolver: ad2s1210: fix ad2s1210_show_fault Date: Thu, 21 Sep 2023 09:19:31 -0500 Message-Id: <20230921141947.57784-6-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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:19:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394326 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 A763AE7D0A2 for ; Thu, 21 Sep 2023 18:55:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbjIUSzu (ORCPT ); Thu, 21 Sep 2023 14:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjIUSzd (ORCPT ); Thu, 21 Sep 2023 14:55:33 -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 B07931FF3 for ; Thu, 21 Sep 2023 10:01:11 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b9338e4695so20089981fa.2 for ; Thu, 21 Sep 2023 10:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695315617; x=1695920417; 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=GXljzaDh0Cwjt9tLDOds1R0q+YtAVWorCrhoDQRUuzDnF0g4VHhq3PGabDTDErfVp9 n8dx8XTTj0safODkkFM4m048dmFmgH9g+yhKPTiYQqcL+RNslFoSmGsK08QVoaPKiIa8 8gsE46olgX9lWI1t1oxBqtp5H++ZvTFgY2BqSVtMo9/pBf3CMq+KgSipNJIxmeTwotAU Mlp/TP1iLANJa6wpdtRYjyHzqR1cQhd5rQVaoeYb4VS4B/XRyOh041kGmsZMp5Uxqs8K dC+YcckBsm6XNlRvw3B30E9XO+2GjTy9p90NUMTr+Iz8FaxT7myV6hQ6/cpcur728WCh LpQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695315617; x=1695920417; 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=Expsw4W0sYD3WGtc+Kfqf1YZgU+7f68FGo0d0BgHzmyH8Whzuw6/Kb4R0eInYnQYjy kyNT1GiyLyOM4gJ0b1WxCKwQNeM37x0nAauMgNNfjqem27UrCowH1g3dk5SZCKdOuIik 6065JQ1NZ1oymE8PvmtpQxwCE1kmnQLk1LMSnwDgpE3B4EFg/IoTN9vTCpl3B/TAfz8H b+YbVTfnWmgE2ixcmDNLsHaFnhGS4+R/yIzdtsNu7buFtTAEwMCwslhPcf2VuiQcLAz2 pcUBGNQXvjkQOeGMO+HdxtDT7RsvNcblPqFnEfxBMF1aIJTmGDJvp+By3piWcJH7xtXG XNDw== X-Gm-Message-State: AOJu0YwqiBeW8ENhpFuHU8ieX7M2bduS1ZaIg973k3py1FyvwLB4OFib krlevqqJxR0fJWLo9iaPE4zToBOk8lWVHwFCiiCo1zPh X-Google-Smtp-Source: AGHT+IFLOeeKjkZXzmrmyjj61SlCO4QtLumxRWkUp/uZ0wPGaqOzHFNXTE+bvD2TXSjNSCu16d/fHw== X-Received: by 2002:adf:fe8e:0:b0:319:f9d6:a769 with SMTP id l14-20020adffe8e000000b00319f9d6a769mr5207822wrr.45.1695306155398; Thu, 21 Sep 2023 07:22:35 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:35 -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: [v2 04/19] staging: iio: resolver: ad2s1210: fix not restoring sample gpio in channel read Date: Thu, 21 Sep 2023 09:19:32 -0500 Message-Id: <20230921141947.57784-7-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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:19:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394035 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 26F96C04AAB for ; Thu, 21 Sep 2023 16:58:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbjIUQ6S (ORCPT ); Thu, 21 Sep 2023 12:58:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjIUQ6P (ORCPT ); Thu, 21 Sep 2023 12:58:15 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BA94CDD for ; Thu, 21 Sep 2023 09:57:42 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9ae22bf33a0so520019666b.0 for ; Thu, 21 Sep 2023 09:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695315444; x=1695920244; 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=VZC9fWPW5q8m+e8zs0ascBTBE6Tlllvli5xRhvIiHNFlbDnTlENQjidpcFCicIcHio bj5Et7zcJ/GOyXIdS9MhhtkGwICvmn2xjFhE8q3AUkbTUPMvVWO4q5+b55NxohCqbCtI ps5IW66PAIQicLcSEJM5FihMJ+QxroW5f3ICguaIh6Sj2MmPMlat0e9BNfrMt5RVoq5b 9hl3KMP4Nb3qTIc1VA56ATq6ZP4Cgnmv5iJ1n2oq9z1lvzGD0cqz9ZW0d/8ktfZdC7zG hK8WYGy0qC/y0aknNsHKsb3s9j3CvsS59OIrhjNfuLYYHBoXihGxN9Mf9Ys8wm7zGeU3 Zgww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695315444; x=1695920244; 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=wGZcZ9/k4RPzR5kMbrVAQZlGmb4FUe/rKO6fv6s7kUOLe2JFujXBhwfAi3aZZrBW7v 74Fb/nHY4OKzAyV5w5KQYQXQf0/G6WC+y/7qxd69Afoy4NKZwJUwskgzeatBVtKO/trS ZgBZ64J1sW7m+A0o052qU/cOKKth7l3GTVt/yPz80jiH0WA7XEKqIuk0Fes0Ae/SouDn naKFvLXygYNLP7ddUCGNbW06btXn8+p6Vw5N86s/Npt0LCFZQ+r5RsJmf2SsI7K1iOef WotpkZVZVhdaimroBvv56vaBfXtSoNZPJHIevdhr+29YsbWI4M7Z/2/l4Ful1Qnyvjxx xvGw== X-Gm-Message-State: AOJu0YwcTaFVuLUN0LCsM4C9mS3Hqd/Kxpku11ZICvc00X3VSOdjcQHa LpAe3ON9isbuKMUFA31F4p5El7Rc38GosIyDqHvs9MDO X-Google-Smtp-Source: AGHT+IF4+sS/mDwYhthmKF77V0j/XEIKbvBHYAVm/9YBijGkzsfCBsc9F5TNf9h81eIYvejG3U+XtA== X-Received: by 2002:adf:e641:0:b0:31f:ffe3:b957 with SMTP id b1-20020adfe641000000b0031fffe3b957mr4444516wrn.31.1695306156350; Thu, 21 Sep 2023 07:22:36 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:36 -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: [v2 05/19] staging: iio: resolver: ad2s1210: fix probe Date: Thu, 21 Sep 2023 09:19:33 -0500 Message-Id: <20230921141947.57784-8-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394456 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 9A6C4E7D0A6 for ; Thu, 21 Sep 2023 19:59:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230405AbjIUT7b (ORCPT ); Thu, 21 Sep 2023 15:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbjIUT7I (ORCPT ); Thu, 21 Sep 2023 15:59:08 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CDA8AD0D for ; Thu, 21 Sep 2023 10:22:48 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-50317080342so2191688e87.2 for ; Thu, 21 Sep 2023 10:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316966; x=1695921766; 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=aVJ/pYX1o7/cDrARBoYLU7zi7SblPXI94RwGldpCWNnBIUvkL/H4H00NuprUhBp965 zbZtJ9GqYZxoqBCzBD61dzjb9LU/nYXj8Co6nMdRAye/UoizziqwoZD+gvgyVgNUImcA AYG8o0RqVO36ts9CtvXj+nxKvMfAXrvACOe1W5xtCr8T7ODVw1V6VmAbocurL7WBn5R7 putHNFHkd9bhSEC2foLsx5UsCL61NwXZ2DMTnmWXH6+X2khZc/e6FiccqrjGfkOGCROx z3cuwBXZaEeUsVlgdSHmoHBZjHcakbhpNZd0skXC2UgLQO0LLU9rvlkvswypoYZx90k8 Y3Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316966; x=1695921766; 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=SUL6Cflal4Y/z8dbBm9ZfZVVwhULA+ijg5waXD6paqB3HnDG63dCYkFLoJxfFZOPJg /E1y5cYIaveavcQvpyOHein2Gf1Q+UA2DSdQrMKEv7fHbYa5K6FJJOB6WjvtZQ4JWcsJ pKYqi4Pg5nZ0oUH9E+llFJkwgpSg022C9+6zSATylg2SVGz2ULObsgAf2FbIbYMEQq+w uhJECLgYd8WfaBHLJH3ZCX9L3oNG/YkR9Ox1BGLF7YiaNuvUlEYTYaL5NEG9rDFFG2CL 5q2Yt+G3HcYHA1QPIwoo6ZnCFXX9lyXOPZw1LVsWOgEFh7V+6pBO1/kp31Rfl3TRhe84 M6Ag== X-Gm-Message-State: AOJu0Ywtx6LaOJhW23cJHvE6p5QJ94/G9QpWgQ0UwSrc6yU9sjqmoHe8 x+iUPQzE1Xrqq4JiSIGVrg0dieVEdWIawFyRvACjW7oq X-Google-Smtp-Source: AGHT+IE4sDvMSw/UkfMczfXLxgbpckMACuzljnUTY5SM6KE9BEVvGBveVsOv+3vfUogJ5wktpvrmbA== X-Received: by 2002:a5d:6e54:0:b0:31a:e8e6:8a96 with SMTP id j20-20020a5d6e54000000b0031ae8e68a96mr5153996wrz.67.1695306157156; Thu, 21 Sep 2023 07:22:37 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:36 -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: [v2 06/19] staging: iio: resolver: ad2s1210: always use 16-bit value for raw read Date: Thu, 21 Sep 2023 09:19:34 -0500 Message-Id: <20230921141947.57784-9-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394206 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 21B08E7D0A3 for ; Thu, 21 Sep 2023 17:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229803AbjIURu1 (ORCPT ); Thu, 21 Sep 2023 13:50:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbjIURuC (ORCPT ); Thu, 21 Sep 2023 13:50:02 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00AA14E5D6 for ; Thu, 21 Sep 2023 10:17:18 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-9a58dbd5daeso149279966b.2 for ; Thu, 21 Sep 2023 10:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316637; x=1695921437; 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=BkrbnlXdBSC0/UrV1PzKcsex/2qDLgaNrdRmn/jNw+EtcnBRKaM5uScfs6O8G4YRrU 6D7ATLM1JbG30RtmDsnkqWHgNjHAyN7z63vGA9j3uLOlfbHic5P8jbDcsCDPARzQpLWL Aad73ds+1pplHPr5fIQkSdGT0Tx+XgD9oJTFq+0IklMlsHRBQmxbgFvliIM3yl2lHAZO qud6Igi5PVeou4jons9fB8bzB8RLiqDZk0MKJJGaMIxpBvnQjn/jY6uD54X9LyScDQHV ncJqlrooebv9K/VaHkbcDlay6bwpa7Xwp+RkH+DIatjDxzW3oXXCzGBZ/7yL/j7NdgVs VaCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316637; x=1695921437; 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=R5FiJew7IclNsybkbDitxa7zcuQ0JgbV8wdAXq/Cu1dEjD31vMVvXadpUPqBbjEKCF aZKryjuqsfCwwsPeulwm5qK/BeD8He3sQbovk41Gl4aPASSeYpBka3UPVIqBvgTjo09z lUwWE2/Kkx25h81z+XCgVrZAPJF5EFoKQRk6+GhFIb+oMS7Zaerk3AA7O0ysilCXXv7r OUuM1Li3jSMZfX7a4Rq0rXgtz3PzcGJUtF6JxMuGL8yU3UgB6h8ycUnJQN1CZj67jiY4 NJGMSlQ3llibcGXcj/tScFuKtUjWiTczt+miFyXt6U/LG44Fn78PpH3Q+vhy6tTwE2VY OyOw== X-Gm-Message-State: AOJu0YylUgdHc61yxHCb1kdyQzxARBcp+nAMRggi+hoqC9DpXicCQ03r +J4z+H9VyFvL5EGRUcc2kASH59ILFtpiDHmNRvQaQ023 X-Google-Smtp-Source: AGHT+IHCsgQf5YDU2b8qhjf3hqvfyriFBctb7CQVc25Wz8iRM3Vsev+NwoaLu/6Clxbuw75eKXqg8g== X-Received: by 2002:a5d:608d:0:b0:321:4b47:d1c0 with SMTP id w13-20020a5d608d000000b003214b47d1c0mr4847398wrt.71.1695306158083; Thu, 21 Sep 2023 07:22:38 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:37 -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: [v2 07/19] staging: iio: resolver: ad2s1210: implement IIO_CHAN_INFO_SCALE Date: Thu, 21 Sep 2023 09:19:35 -0500 Message-Id: <20230921141947.57784-10-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds 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:19:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394628 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 74337E7D0AB for ; Thu, 21 Sep 2023 21:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbjIUVHh (ORCPT ); Thu, 21 Sep 2023 17:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbjIUVHK (ORCPT ); Thu, 21 Sep 2023 17:07:10 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E19DF4F930 for ; Thu, 21 Sep 2023 10:15:17 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-5033918c09eso2060046e87.2 for ; Thu, 21 Sep 2023 10:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316515; x=1695921315; 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=caA/yMStDG+ZGxv6rHbXHFeZ17lO1WAal3vTk5Rl9cGD1e9LVlUmJrilX03buURBHO FyJOgyl3biZC6sRCnEVcU+xqvVm7ouE97qtxgtkW8Ut7yGrM1lSGdYaXrgO1vt0NVcni 7C7Ag1agtM7jX+Ip6YfqQntAQbSKQtOsULWD8xUtTPnksrN3cbqzQPXKSOmC9XBVWSeV 9O3M6xilBM55nQKGAoQIsJ+pfJ18i6zxEjN9+AnsRINTEuW9imCTLmQoFAEfus0p+QPI tjSt8fovzrcSsfweOipKuYVI7+GE0jh0L8mBTVuU9xhg43sKrqwFcRp3UCp569ldYU66 0Zvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316515; x=1695921315; 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=uocpyC9FxwquBcLowiA0rWGYV0U+rkenlVCLspqoaDDLJfJ703JlbkGgrvCV1MdISl xNS4RN7FBQhcmMwvQE0ckS0akW3LxtIBMfDhZRL411xY+KY9e8qimIxJYMW6I0xVAjdd 3ARR6wJyAZENn7TfJl79R/mlWCWyE7GUXFSc9zRZHZ+uDEMc0H1BfbHJUS1GyXfHzuan QxRa81rq8xglUSkPIAvOUWoXs/VhJI8cufP7DB/sTPfENZ+mArO2HV8HNM4eXcUNwv89 Nyc64C3krD1ao8JYLCDCUgJN1uILESrRBn7ZziB+26CLNv7O8IbzD9Rg2/gFfz+bPFtO U/Rw== X-Gm-Message-State: AOJu0Yy0C+M2PEIxypZdNOQ1HbOymDgtEJXeuPSX9Foae6gAuDFY5bwi N1SvMqu5o2oxk8V5W8/7wOyhzV5Pqns2bfLYBfmpBHWs X-Google-Smtp-Source: AGHT+IFPxpl1mL31xHJRVnXCLfFPLtUCE+7JOw2swmApi7DrJQIpgim9CNysuQqHjc696HN9aqGOFA== X-Received: by 2002:adf:fdc3:0:b0:321:6388:bccb with SMTP id i3-20020adffdc3000000b003216388bccbmr4781473wrs.21.1695306159013; Thu, 21 Sep 2023 07:22:39 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:38 -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: [v2 08/19] staging: iio: resolver: ad2s1210: use devicetree to get fclkin Date: Thu, 21 Sep 2023 09:19:36 -0500 Message-Id: <20230921141947.57784-11-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394489 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 87634E7D0A2 for ; Thu, 21 Sep 2023 20:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjIUUSH (ORCPT ); Thu, 21 Sep 2023 16:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjIUURm (ORCPT ); Thu, 21 Sep 2023 16:17:42 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A9A1515A5 for ; Thu, 21 Sep 2023 10:25:43 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-32157c8e4c7so1241206f8f.1 for ; Thu, 21 Sep 2023 10:25:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317139; x=1695921939; 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=NlybUepeTqztwClLKEBbjEH/KFIlskNCmG01/jZ4BDBg2Za4lwaTkwXdpxilmaLLuE PLDOyc2CTazT9B1SyntJq8jO/RbXE+rWquqFbsJsR4gaedI73+nBW79D6PFvbnFjjvon PRA9PreYLLTK1KT2DIAM6LPhsE9uf/V1FlIYrbF2fAHM7rV3aFq91JnURZoiJ/CYMqs3 mYEGJsYQxKq+6GsTWLFtWoNkVLKX6Vm7qGVBl/iHmPMwFQLPSiY8m8pbqOaJ7WN7wA6z +ajU7WZswp5rUHrC75DMwrFqB6Gw/4gV81D/u2jiU6AexrG4TcUXnwKyjGfDh4l05hsw tBlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317139; x=1695921939; 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=pPkutVbh8FniBrHWBgf0Hf3etjYKl5Lc3tcOaEfcA0qw2y5/goaU6K7DY690GNUBql y/Jp5nVxp1uPVfDYNM8jdnGjc0nSauWVZ7Px8YIz3K38LH91GoLsGdjPMZSisfxr5Djp vbXTdOwx9rAUbXeXHFcZlruRVeHNSMnG6CYzw/2i9Etc+/Bmip7ImYokjah+thpuy4d0 4CKeBdxREmKO+JwH+Fn1FRAVa+jtgxJg+LOHRW5UnB8K7b8AQ64E7c+t1uzHcxQyvsWV IfPHDOz/1r79voanSjOo57imnU4lYBOEnvs/QS8XcDPFIOZzEg29qqfjM60BxaUSFDFm IS9g== X-Gm-Message-State: AOJu0YziXQX4FLzCRzgfMMDMVD+KFUShCqJqWn1hsoT4V6eQx1p2gYHh iOLHeaNfUB4HSqkL16r/9IKNP1j5ZBJ2EtyeauRqIKlo X-Google-Smtp-Source: AGHT+IGGmEyk1OjFw9m0pn/8yG9jZBYUcbB2fnTx4NWYXyDuPq5yL654tmO33MmRV0H62lUW8r3SXw== X-Received: by 2002:adf:ea8b:0:b0:31a:e772:ddf0 with SMTP id s11-20020adfea8b000000b0031ae772ddf0mr5106504wrm.53.1695306160016; Thu, 21 Sep 2023 07:22:40 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:39 -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: [v2 09/19] staging: iio: resolver: ad2s1210: use regmap for config registers Date: Thu, 21 Sep 2023 09:19:37 -0500 Message-Id: <20230921141947.57784-12-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394504 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 3E34CE7D0A2 for ; Thu, 21 Sep 2023 20:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbjIUUV5 (ORCPT ); Thu, 21 Sep 2023 16:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbjIUUVe (ORCPT ); Thu, 21 Sep 2023 16:21:34 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBE462487F for ; Thu, 21 Sep 2023 10:11:33 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-503056c8195so2009378e87.1 for ; Thu, 21 Sep 2023 10:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316292; x=1695921092; 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=JZUaSyEDg5pbWYztWULRutAyVXeMfMa7eAV0w/GWtoX5Vkcdl+u8SfZSbydxjLrpPX 8Vxaw0AVLZ9LQ24VJUSKk7lchUHShgltP2Sq6oHenfQn3s70QKVXYFi/HHPUyCQKQsjG UzURbL5B6fAr8OLuwBhFYVdsnp8Vc2YesqEn2gsfPQJDYkN5AjlIUkK5/vaRhrud6DPy B4tUhPvHZuuHCaQCWOsDiZZ6Zq+B+GlAGdbYjyBYY9dkAcC+9SzP8ST/Gx4qpz5wX+3b OJ4Dvn9+7UXa0VxPojfRoFhV+7G8LhEOenjL2ItjUmv/IhcQ3aC1ueVJUt1ANiIykvI4 oTBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316292; x=1695921092; 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=fUpDpBBPSCB6xcgXPz1vbrzNkrxDu4S1S8eJZJ5uWt1WRjUjFaCnO1t+cS0WTHo4NE Kf4x5R+PAlJuELpeKGxM0HbHX8zMYTobiSBmtQ3CIZX8LxLOKwTSvLEsvNbuSOycKb/b PuXH/PLDiNekDy6IdjpJAeLHW7ldAeS6f6JBw4lxJOazb2K4X6VGkuL8ZEQhR4e8Iylc KX99pO4yt4k9L22up0+oc+zo3w3MUhCll7QGIbgopDKvzkbyItrxcKov92mBD18gx1D5 bAZRvDvG84iAzykb0+bhvzRS+lFhU+ORZJUhoK2fGDjv6KKlOFay6aHZL4f2yU6wxPEg 1nuQ== X-Gm-Message-State: AOJu0YyBhnvfuw5N4cJOOerU6+wVEWjcJ4ikKlejLXaAOBvJn3VpN2/V DwI26Q5yBfsQ+GpYnn6/35YOG4tuSiVDmx2Krhmvkggz X-Google-Smtp-Source: AGHT+IGgYCYV4RIyluC952QS15xlxGsYiHuw3JJvkpeLNvHhq4UFPDC/C6dReCQO1m30NxXKsPt5kw== X-Received: by 2002:a5d:4c85:0:b0:31f:a259:733 with SMTP id z5-20020a5d4c85000000b0031fa2590733mr5275304wrs.20.1695306161138; Thu, 21 Sep 2023 07:22:41 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:40 -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: [v2 10/19] staging: iio: resolver: ad2s1210: add debugfs reg access Date: Thu, 21 Sep 2023 09:19:38 -0500 Message-Id: <20230921141947.57784-13-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394207 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 4E51EE7D0A7 for ; Thu, 21 Sep 2023 17:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230102AbjIURuq (ORCPT ); Thu, 21 Sep 2023 13:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbjIURuL (ORCPT ); Thu, 21 Sep 2023 13:50:11 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52BA893F8 for ; Thu, 21 Sep 2023 10:11:07 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-533352059fdso1345971a12.0 for ; Thu, 21 Sep 2023 10:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316266; x=1695921066; 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=kZc8b54ix9KUxGGb2ZdGJdyu3A+qYMt0l1YflMMs9NBzAbdRbB+0/8PcfvLQvm7GR1 kBMyCDf8MhPaa5Cxo38DC+kn7HB2uWB+TbhUD49xEMu/jXfxSQ3O5y8k2vOAyN71CuAT H6+zQWdDXXWRNM3uz1tQZMRpLdABS7raI6ovZIi7BO0Xz5tZUGXkiY0tZq1IbAj3+jYM B3jTGEqZxlnAYT3LKo2As5j7AErqeSJhA4Zglmzn+avRQ7N7cKHE3PIQuWgjurRx0Ufj KfCHPEXRm3vrcSD2d5VQYH0FaYxJsHGHGRPSpIT26r7gMrZlkqI50wD3b5R/0JnK+ahi J//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316266; x=1695921066; 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=shlMQ69bHzlHPRFybGzxz0gu7+olF7ZxpTJjSj1Jnb4Up1fRGjgxBTKhfLwvkS89/C vA/9xNBqqV+tUwCEywAp4MFLI/Nwe8nahI2BX31eerqZMABqr0j41qWziBzatD3Y/+9i ky5nsf15ut/lE+Yo6lr0LR9MRYMhQjIWH2QsH+6aPax9k4VajcDUDb7fSso0e5msR/CS kjc6nEajS0fcIdJQSxTiaxdFogezvPVzliCdB1XbNcL5IIJ6o+nCbG+Sp9kStMqd9tcP z61+M99dWrPvW3XFBiwGuPLJEaRmSa/KLTz1n5QYu3xcrS8Orw0jucoF7NHF+vUfWj80 qAkQ== X-Gm-Message-State: AOJu0YwSSku/U3UzJL68mW1XeP6VVQz193OaGkY0C8VN/3BnqDXtXTK3 FGawPjOMbCBKLtQIq8lAmpuQ1xxvXaE4OTOLeTKQiV73 X-Google-Smtp-Source: AGHT+IErIr8HYB39hw00Tn3dC53NPjDauGkjswbrG4/MJD7OhSd2tta9YfBeev9o1GBCz+kjzTcBFw== X-Received: by 2002:a05:600c:1d1d:b0:405:336b:8307 with SMTP id l29-20020a05600c1d1d00b00405336b8307mr1536343wms.7.1695306162032; Thu, 21 Sep 2023 07:22:42 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:41 -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: [v2 11/19] staging: iio: resolver: ad2s1210: remove config attribute Date: Thu, 21 Sep 2023 09:19:39 -0500 Message-Id: <20230921141947.57784-14-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394478 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 263C2E7D0A6 for ; Thu, 21 Sep 2023 20:12:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbjIUUMR (ORCPT ); Thu, 21 Sep 2023 16:12:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230462AbjIUUMF (ORCPT ); Thu, 21 Sep 2023 16:12:05 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 617DE51F72 for ; Thu, 21 Sep 2023 10:17:05 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-9ae22bf33a0so525997766b.0 for ; Thu, 21 Sep 2023 10:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316623; x=1695921423; 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=uBzdZHogL6jyN5hfcii1FzufCCmp8yTnWbEsR0PU1NoPgG7WZLNEdXRUvYeH3ew9/S vrDDUPtjKKNmQ05xRmxuEGrtlK4GTLtf3YFdcEOn+bwtzE8Q8/Hs8agxuYvLmRsh2zAg Hk22vOHhmq7yzIW1tEXoxMxt2sYLVrtCqTm65CUWIIvGQkA92pBkXHp1oAvGZ+9f0h4X 81qr8XswqtSM40gYceL8qiqcrEKo5zsvvBIBQBblBMBVocmepbb0FNwp9Z9Ls8445Qg7 HF/TXAQEnuuhxBij4UYvXG7gV8X8sFsZ6O0UsLaKryqaYD59kiJbQpXAX/gUUQQyHg2J 6wAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316623; x=1695921423; 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=rKhotXXPp597PfSaolADPyr094/+3uzDAmQPGa7ExdU2LAMlzy2RRXo8weZniR9itM y8Dteoyug7ZFXntArY8UfbbgbWig2CLXyPr94K7Inaj7gQP3x0zmeiW6dmf9Uq6rG0RS qFdEIyprOovH+NXfKMC1gYoEZcjBCZcNq4b1+4jkUp3E9FqgzYvSnd8kLsDAw0LDLXF2 TeVR7jjbf8LrbDoso4LSN+gSEpYrYgaSmn+2t6DVfyVxo4KVwv6jE307klM+qLZvYyRB SCAX1O5RsvUUsaEFg57Mk4IN8AvfHAqw1mK+o6AwAJyFPIAxx0hgN4gbjptJuCCq9MSs APSw== X-Gm-Message-State: AOJu0YyfNog1uHhxez9jBGxtF2aBFpmSnSQAJAlQQUVn6rWQ43mIqdK7 627diF5coYKtA4VODPXyji4NbD5RE3DwuYW+OvNd4pEq X-Google-Smtp-Source: AGHT+IFLAailNSfpLWCmoZinfeHn+u6645WDTA+4EEZgkEmo5Zeo7s9f1tFWyiN0QMRZgSvQMKO0kw== X-Received: by 2002:adf:d0cc:0:b0:31f:ebb5:cd51 with SMTP id z12-20020adfd0cc000000b0031febb5cd51mr4695038wrh.33.1695306162905; Thu, 21 Sep 2023 07:22:42 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:42 -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: [v2 12/19] staging: iio: resolver: ad2s1210: rework gpios Date: Thu, 21 Sep 2023 09:19:40 -0500 Message-Id: <20230921141947.57784-15-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org - 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:19:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13394453 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 0FC15E7D0A6 for ; Thu, 21 Sep 2023 19:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231139AbjIUT6l (ORCPT ); Thu, 21 Sep 2023 15:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbjIUT6Y (ORCPT ); Thu, 21 Sep 2023 15:58:24 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FF7C2D231 for ; Thu, 21 Sep 2023 10:26:45 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-530bc7c5bc3so1531227a12.1 for ; Thu, 21 Sep 2023 10:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317202; x=1695922002; 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=hExfSzeGdtxiUjEsl0W+5T27uSaea2hs6eqJVUoK8qa+gEEtH8airvhOZaI9m+o63H OXK8euyoF006N0sIhpn3Dnxf316GO4S72bxRUv+ZKdGwgQegmLb3fRrbMjco4x6SmiwT TUdW8Ng/DEJEI119GtLvpbHVjzeMIhLq/Bm+t0iQxmEpiCwy9KCa4Pknc1V85q0b4rcN h0TAA/7nWNhIIcasVVJC1Pb9wCiKA90YW0U4D9OOTUcIujbuUCV0UkMIhNnPpq1eT/4P ZiUV2RgKsYKNktKevsb9KCZ5UnRrtJ4t3hECNPm+7Ov7vizniCr/ZBfh7GHO85C/38EI s08A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317202; x=1695922002; 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=M+WP5W/DdM7vezTw+McCy3F9YGzSy/SEtu53nNOw/JWtrAtzFiL6SYUP6/VFGT/KDf A3u3abF26XyGkZAmx5eJbA9PxlNVWOwVMx6iLMOVXPRJ5X3C0tp5EZ9VEKYEAog9GzcI xSTciyCL7OualalUNBqap2hcxHILmISzdO3XVsbw7HgvHSPL0ACKFXxuf62gZ/GS22BR FUf48QkAW+MTdqBrfb6gKM0hKPPgkVSTv5FhJDRcDobHqW0tsJoFyqBNCS8RiykeodPK kHkqbTYOx57Mk4IOfwaKf9qAyeH7fQhrnIDTJZpLpYy84+bhXp5GlYTe/sJNw0ZO9eQ5 OSfQ== X-Gm-Message-State: AOJu0Yyiy8HLxDWFpeLQfpnjcuzGp31JEG0cryOtwk5Mw6Gbs9m2sPfH TUOdNZI+ZxpK3L/r2nkxBEDLGNRkX25m/q5CR5keqsid X-Google-Smtp-Source: AGHT+IEc+ToK/YlPl4OhhuhcmW2i+TTG/k1yEvY4gVlKSX7pGRedYf1SANoITpOQbOK/u1re+CP3BA== X-Received: by 2002:adf:f68c:0:b0:320:b1b:86a9 with SMTP id v12-20020adff68c000000b003200b1b86a9mr5129294wrp.24.1695306163828; Thu, 21 Sep 2023 07:22:43 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:43 -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: [v2 13/19] staging: iio: resolver: ad2s1210: implement hysteresis as channel attr Date: Thu, 21 Sep 2023 09:19:41 -0500 Message-Id: <20230921141947.57784-16-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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:19: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: 13394663 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 9037DE7D0AA for ; Thu, 21 Sep 2023 21:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231497AbjIUVUt (ORCPT ); Thu, 21 Sep 2023 17:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232637AbjIUVOc (ORCPT ); Thu, 21 Sep 2023 17:14:32 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CFB95BBE for ; Thu, 21 Sep 2023 10:08:54 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-99de884ad25so148392666b.3 for ; Thu, 21 Sep 2023 10:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316132; x=1695920932; 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=q07ZfFYdIk2e4t8Wt6QxjCcWOHY/5NXBDrj0IqELgZeFv/5aeQul9OGw6rl5N8iqVq 3q9o/D3vOQ6bPLY9t524V16rdY+/SXw55dK3D+aDB4PqL2Sf6cNadQLU9yxIvW21Gzkr 96a0Tw0OYo9NVXhOGMGNDjEGjJx5QNUO8/VyTDpwmPbAPzb9BMBOfDqpEnTbLt/DJa2N fFntFFbv30dSy46BYAr27K04yTEVq2L8tUsC1omC2SomPT/8XRV+4PvwxJDok+c9ULtc oyaEgr1h40l1gWiXB4Td7blafx9hL+63T9PLtcVfdsJ50AsJk3fZjpvBcs9TbRTfBBcz +s0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316132; x=1695920932; 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=Ld1vauOCps4KcyzVsOFrBULqH5zr4fLs2ASUtGGsP7cn91v6WkIrf+jF6M+VQ2w4ef yD52dg+VhCnlWN2S0uHL3O95W5AN1cXrOEH4hyQsnPfkzDjkPzsVRZsep2HWs/pantjk zZL05oSUO2pFVz0rcW4ihAokQOYe43tzdw4Qv0g33TJixXKhTmKcaEROwEmTRktbJktr AYu1dB2SxxvWjTLYhjzzEFOTchDzEMpxuxc321n0vVBoOgPNzTj0QMb+9+F/3cDicIHY K5l5Nyd9+Cs7hOlo+cgCr9AStIlQoVoKjV03dFc1Ju/+tEWMtXmXNCxK10W+KxkZdjIr 520g== X-Gm-Message-State: AOJu0Ywwf8hG3bOsQxKgY3bXjM9MlYmgazE8Mn5J1Wo59ZD3u4riloDI OKXj1za2Tg5wWf5hlYsMlBN15pCoqzvZDLhVNbrpJhkt X-Google-Smtp-Source: AGHT+IGRjZhp2R5sxkFWDdwbOa90jJSgYK4eOmJzrC4HUjAJ3wveQwXoDeexC2vjkJhYZNOJkJ9DkA== X-Received: by 2002:a5d:5192:0:b0:320:9e2:b3a2 with SMTP id k18-20020a5d5192000000b0032009e2b3a2mr4841480wrv.33.1695306164753; Thu, 21 Sep 2023 07:22:44 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:44 -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: [v2 14/19] staging: iio: resolver: ad2s1210: refactor setting excitation frequency Date: Thu, 21 Sep 2023 09:19:42 -0500 Message-Id: <20230921141947.57784-17-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19: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: 13394124 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 64E67E7D0A4 for ; Thu, 21 Sep 2023 17:27:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230071AbjIUR1J (ORCPT ); Thu, 21 Sep 2023 13:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbjIUR0s (ORCPT ); Thu, 21 Sep 2023 13:26:48 -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 99D55CF0 for ; Thu, 21 Sep 2023 10:01:14 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-32172f8a5dbso1144851f8f.3 for ; Thu, 21 Sep 2023 10:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695315621; x=1695920421; 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=1LQEIWrWPgYVvFOfMJ/DdBamYItOVN+hx687qgsPSYuQ67lTbBPCtyIOqZt2261h/y eNCWL8c21gGATxZ4Q6NTAr7sjhzCC4E36M+ytA0z1fg+xX8bQZkmrhtCWthBFjGVC8L5 f5hE6dzFWVVtg1Xb+/jdSCGgPkG2EX+tc6o2aMEwGHl+67ygqpWQcL2kU6GBgW7mrKm5 AV7NQkeriEcFCI/hg+N1JPCtXoFzxEl+//v6x92RL21L/KOk1cgokfEDSWXKaZsSeFS5 kyt2uN2JOP6a7+EwW+ECooNKVfL1ZYCPAhRkXFyJHMLepZzm+Dnkae7Zigc6WqOtdit9 UWEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695315621; x=1695920421; 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=KPg19uYEBdceUjF44tIKrYu6fQs7VATzhACTQNKhu+I4lCdAjVpyYdAD3+zKJ5xu2L SbrYq2hEOppQSwTDWkyTdpyX6vSgkQ+UxuEVVgKURPaSCPphuwLsgvHxh6iLHvc0bXUv pWOE+IK4hdKiOVLP0JV8QHY9H77wlvqfvMHuCov30vPaV9oiMISgL1tQP3YQNySHI33s CV1hgflUg3W3Zt/Dyvy+8846ZQPtx1qYe2RFBYNrsAk4wZA341oZoVgZwI+hQCOl540k WE0kIlOGL2wklZajPM1vz+e4W8n89bplv9K+JkRyok/QPp29urEh2D9ITkCisFp4Y75Y 2XHA== X-Gm-Message-State: AOJu0Yxkhm55Uspj1g74T8uZPWGupvqqB4dJRFiY//Q3JaHNW6jzxJdk //eLQ5xSRFXq6bKshejQr/7owT50Rp7mNjsvBtAhUpzu X-Google-Smtp-Source: AGHT+IEuEQ+yHcKXMmNkfUgwvUgJV0TYHVRrMSBE2WgINBdiZLHbPgjRXkTk6HjPHk2lj+d6o1Or/w== X-Received: by 2002:adf:fb47:0:b0:316:fc63:dfed with SMTP id c7-20020adffb47000000b00316fc63dfedmr3915975wrs.39.1695306165716; Thu, 21 Sep 2023 07:22:45 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:45 -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: [v2 15/19] staging: iio: resolver: ad2s1210: read excitation frequency from control register Date: Thu, 21 Sep 2023 09:19:43 -0500 Message-Id: <20230921141947.57784-18-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19: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: 13394503 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 12D80E7D0A2 for ; Thu, 21 Sep 2023 20:21:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbjIUUVe (ORCPT ); Thu, 21 Sep 2023 16:21:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231674AbjIUUU4 (ORCPT ); Thu, 21 Sep 2023 16:20:56 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C473B43CA2 for ; Thu, 21 Sep 2023 10:31:40 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-50308217223so2092872e87.3 for ; Thu, 21 Sep 2023 10:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317496; x=1695922296; 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=la2QrKF/QOTLv9Xl6vpk/AtMY/ONZdAaZu+qx6RtmnnPSI+Sgly6VuQeLB/YdyXxda gcXI58IuoSFm6OQhfUEQ82P0v1r8XmhPWtQhahFsemM6hGYmfBNxqaC+2RNhCwXgPknA iUHCCZvYdfRaDlH2/e2KLtpAqgkn4+Ty648QGK1K4XXUwZA8MBSPJJQdWKBR0S/sGQnG vCr8VuytnRpSuGUyEq2HGFUmGlv3Jwtc2ZUy+RmEKht32REI2ldxn8nmyVJClepoxElm C2MLRYKiWJC7Q/v7MogMsKimn+I44RoVo8x6ahQD9tg7maoFzFAxm3FLOXPKxNayHv5a wlig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317496; x=1695922296; 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=aqlNsoXa+TEGFkXN+1iwE9TKTlea4whseM2jgfb0vHIwi++/WSlRsPhY6smq+wP6rc D3FpCzUnCN04A/ls+K1xAYWVC5L3tgiYqpOOH9BZJ2qD7Ks25PNqEQrv6yY63CSfC9Tg Wbo1FXxHXAzvmWwgfmwR750ZxGDhzmzEOZirXh4zIPSnOLEPLEdv6r/4qvOqI7HNz7T9 eOfbPMC6MgFRXKOMrygQDPBeViGj+XW2yyKsIyZ3ok5rzFms3ghc0tZQttHbBU50pBag HUu30t/CD7Axsi5rDhMvjmiRlSNgHq3bn7cqvUtD9D85/Xp9/2pgY/LQGSfvv3slXImW LhNg== X-Gm-Message-State: AOJu0YwnLlOFJ/v6EvpbQqs2KjGf7Z7na6JI44CpDAy2h5pHjbslA2O9 GuKf/ejoq2Z24uWK62lhnJ3E3d9+UZTbAqTLqALpamU5 X-Google-Smtp-Source: AGHT+IFu1F25pmyaAgzXYF1qsHUDXBwQ437AiaWnWjMjwmw80fpRWTPc2ECeCGljKdTfsMbdgIq1Yg== X-Received: by 2002:a1c:ed08:0:b0:405:1bbd:aa9c with SMTP id l8-20020a1ced08000000b004051bbdaa9cmr5515593wmh.34.1695306166581; Thu, 21 Sep 2023 07:22:46 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:46 -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: [v2 16/19] staging: iio: resolver: ad2s1210: rename fexcit attribute Date: Thu, 21 Sep 2023 09:19:44 -0500 Message-Id: <20230921141947.57784-19-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This 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:19: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: 13394610 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 93667E7D0AB for ; Thu, 21 Sep 2023 21:03:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232526AbjIUVDV (ORCPT ); Thu, 21 Sep 2023 17:03:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232269AbjIUVC7 (ORCPT ); Thu, 21 Sep 2023 17:02:59 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A634858C21 for ; Thu, 21 Sep 2023 10:19:41 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-53348be3fe1so934538a12.2 for ; Thu, 21 Sep 2023 10:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695316780; x=1695921580; 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=vVFmofR2N9fdmlmIL3EKO1/nnkc0UGLMz7afIAuqgwlCNwAUp+iO7FTN8PGjBBVqcy zjPuhmm3GxikCKRb5LU6ONrzwSU1/dfINpI9Bd2O4WdR7n3O/n2hvL+LM6WSGil7vHYM zziimWdao4Z2wp/rWcPCHhh+3mvZ2WP9TQTjKL9SaUySahLCx55y3Jsrg1Sx8wguP7kh 4rBMQP4FhBWS7mUiXx6erWNVkBWPk3OY03FQoiLxn39buVgC5MTRtRNO+0aC0JXQ+mm8 PI/mMy1R3AR3DDLoj12pPZkwLHYVHjY7r9vUWTJ9aC0av7zXOQZRBLyI9ZYCLpPuq9mW 5g0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695316780; x=1695921580; 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=SODoeKpduVsLLp2rg3PQVF/1x8n1Up2GYkESkS8GvyqFwcdQjSIoiGZL9a+/AX3NCC Tq8ngc3r5TSD+aaJYNKM6KLotr7e1o5pyulmnWsMgjb8PqI2YXM6FeLfWecz0y6try4D TgHxWadAcqSHK86PcHjfprwH6pZkUW/fYpy13d7RMpxHhmjpjZom+VF7RSXsLMKrJqI/ TmP6M/FvsSAC+z1Nl6Hv5VTUGW7WLZP5OHE/cqTHQk9CAa7bEp1Wnx4kgS4nM18EEhnp HW0JBckRAFPyMMxL+7Kzb0voBzvg/y4yscNma2bVwMmwBWbBw7j/mSigTihZXLc5U0nl zWUQ== X-Gm-Message-State: AOJu0YylMhR9V7bXD29F4obyyp4tT4DuUehTkZPt6n52RVU8xgVNtnOP 0OT5OsQw6G9erXyQv664hcw6yN+xv/BOOvWng4E09Fpy X-Google-Smtp-Source: AGHT+IFP4MOcE7E2V9WBBp93krIW5ELA1JqtXyr+E6QkCDPSXWbGg/ybS0qM51T45avLvC8CEMIykQ== X-Received: by 2002:a1c:f204:0:b0:404:fc5c:15ed with SMTP id s4-20020a1cf204000000b00404fc5c15edmr4949109wmc.35.1695306167586; Thu, 21 Sep 2023 07:22:47 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:47 -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: [v2 17/19] staging: iio: resolver: ad2s1210: convert resolution to devicetree property Date: Thu, 21 Sep 2023 09:19:45 -0500 Message-Id: <20230921141947.57784-20-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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:19: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: 13394502 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 15862E7D0AC for ; Thu, 21 Sep 2023 20:20:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230337AbjIUUUT (ORCPT ); Thu, 21 Sep 2023 16:20:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjIUUTn (ORCPT ); Thu, 21 Sep 2023 16:19:43 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8A5F4065A for ; Thu, 21 Sep 2023 10:24:21 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-31dd10c2b8bso1223636f8f.3 for ; Thu, 21 Sep 2023 10:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695317060; x=1695921860; 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=RF/VbRCCSuidjQPkl1zidhwGpSVeN+RbHW0GSBtD6f1uH7lpYVVHXIC0mT39nCHNSH B80z6vu1RbBkbQtZ1pupQsymocDPdK3D7eZdbfF+BHpiZu2mUnHQn2aSbXcG/f0dQUZw 78cWtuQiyUFfbDcYKHotdVGipvKXvwAoD8/ZqyFajoqmDvbUZsvUy1+WmblYDQQWJ1Q7 q5a4D/zESzfh8sMOIy1BjSbbF2qgBNKFIOcMYgXxgML29mnlBiA5XsNWXTmj88aJmVIS EWgj3zfhOp8NXYvy7hWg3pcAYecxtVcTLx74S8r+yAc4rNiaAICe/PSPaBUcSI/KReF4 zoYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317060; x=1695921860; 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=S03bwRbu2l+LzsCK1nqEz4cfRFH2wlJNFCnfFIK+/DJNfteLcud+olNi47OjuSHu1i 2aCcNNd+MYjVB1gdzRJFzI0Wqnpjg2eu8pp1ZWlwCdYTHtnUdjfpGwZ0JRvuDOKw+tI4 YEhPK7FFsJ5C3zqgtxy5RG7LtmS5eqkqHVs1tMEabdkcbuK42x28LQBacBcKQhJMAfV2 o8laHtNix+XCFRoEGiyzF0OCuw4I31rKXPnHs3jiEMDjVmjxN7bf6CJyexAK9a81ORUO egKvDrMn9oZ0qgVRhb6UmjFvx5sEhmmS1G/3H1EmSORVyFliIqQh6Ks+LD68LTh1qLZy VoEQ== X-Gm-Message-State: AOJu0YwETOehvApAHGjJP3mjiq4mEhchPdmdRj+Y6h/iRfUtQi/gSQ4C NKmBiYkCpJAbbG68mSzRyqntxAqMoFI/NT3pJeszEGXs X-Google-Smtp-Source: AGHT+IGCZngJGw2TLbVAmHBkA5Ct02TLdu6cufs/nlp002BSIPnQTHy4JPAWFAoql4McGwV/17mztQ== X-Received: by 2002:a05:600c:2117:b0:3fe:e7b2:c97f with SMTP id u23-20020a05600c211700b003fee7b2c97fmr5472970wml.36.1695306168409; Thu, 21 Sep 2023 07:22:48 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:48 -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: [v2 18/19] staging: iio: resolver: ad2s1210: add phase_lock_range attributes Date: Thu, 21 Sep 2023 09:19:46 -0500 Message-Id: <20230921141947.57784-21-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds new phase_lock_range and phase_lock_range_available attributes to the ad2s1210 resolver driver. These attributes allow the user to set the phase lock range bit in the control register to modify the behavior of the resolver to digital converter. Signed-off-by: David Lechner --- drivers/staging/iio/resolver/ad2s1210.c | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 71f0913b7e2e..f5b8b290e860 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -259,6 +259,60 @@ static ssize_t excitation_frequency_store(struct device *dev, return ret; } +static ssize_t phase_lock_range_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + int ret; + + mutex_lock(&st->lock); + ret = regmap_test_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_PHASE_LOCK_RANGE_44); + if (ret < 0) + goto error_ret; + + ret = sprintf(buf, "%d\n", ret ? 44 : 360); + +error_ret: + mutex_unlock(&st->lock); + return ret; +} + +static ssize_t phase_lock_range_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); + u16 udata; + int ret; + + ret = kstrtou16(buf, 10, &udata); + if (ret < 0 || (udata != 44 && udata != 360)) + return -EINVAL; + + mutex_lock(&st->lock); + + ret = regmap_update_bits(st->regmap, AD2S1210_REG_CONTROL, + AD2S1210_PHASE_LOCK_RANGE_44, + udata == 44 ? AD2S1210_PHASE_LOCK_RANGE_44 : 0); + if (ret < 0) + goto error_ret; + + ret = len; + +error_ret: + mutex_unlock(&st->lock); + return ret; +} + +static ssize_t phase_lock_range_available_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "44 360\n"); +} + /* read the fault register since last sample */ static ssize_t ad2s1210_show_fault(struct device *dev, struct device_attribute *attr, char *buf) @@ -506,6 +560,8 @@ static int ad2s1210_write_raw(struct iio_dev *indio_dev, } static IIO_DEVICE_ATTR_RW(excitation_frequency, 0); +static IIO_DEVICE_ATTR_RW(phase_lock_range, 0); +static IIO_DEVICE_ATTR_RO(phase_lock_range_available, 0); static IIO_DEVICE_ATTR(fault, 0644, ad2s1210_show_fault, ad2s1210_clear_fault, 0); @@ -552,6 +608,8 @@ static const struct iio_chan_spec ad2s1210_channels[] = { static struct attribute *ad2s1210_attributes[] = { &iio_dev_attr_excitation_frequency.dev_attr.attr, + &iio_dev_attr_phase_lock_range.dev_attr.attr, + &iio_dev_attr_phase_lock_range_available.dev_attr.attr, &iio_dev_attr_fault.dev_attr.attr, &iio_dev_attr_los_thrd.dev_attr.attr, &iio_dev_attr_dos_ovr_thrd.dev_attr.attr, From patchwork Thu Sep 21 14:19: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: 13394061 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 33B6AE7109A for ; Thu, 21 Sep 2023 17:09:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230097AbjIURJL (ORCPT ); Thu, 21 Sep 2023 13:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbjIURIw (ORCPT ); Thu, 21 Sep 2023 13:08:52 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48E305FC7 for ; Thu, 21 Sep 2023 10:05:18 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-503065c4b25so2018330e87.1 for ; Thu, 21 Sep 2023 10:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695315866; x=1695920666; 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=FTKhmdRKziNVonAqV1tS+yANcIBLFlvcT8TzgRhZaoz4OEW49UpItsU6gTm2Gdikfe v4vwWjU3nu+v5avjWqrQlN0cJOJmxO5WPH1CTfHP4pvjWQfu4FDI7qWvINIRymkA1NFZ 5aUk8gh0Ru5fNHzrVdYvNHsTMlN+0D2l35Db0t20YVyBsUVe8RPm0Sh+0yIB4rG1M9xy D0OLf1cLcjrX+Eu5uJ2k4aNNBX4fg3cTUmSOYnPF6MsgOzLHyuJ/rlNik9zi5K72Ccrq mu58FnPMkjo7T9tjthbluhSd3qEbpWBrm6Z/iZfn74Vv3N3Er46GlLdw4VaTLBE77iws obZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695315866; x=1695920666; 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=toKFXh5nKuA1Vv74zwQB3yds9PSpiY0pfUOwDeHv1oIspbTTyZbPdRARNuBduA2umq nSlisuUQl2hD7Vx0kVJpQL5bt5Hwf9l4zZtcvpD7F+g0LfuXJWAV6Dhn97udltEUWKn1 c7LLlaJUgk9ehLCHE6w2jrfm3DPwCHv+zHIkpgTyHwNWn3x7ZwwfPqlPLdBM/3GuIkSu flit9bwU2OZBzPUcHFsIAp+//eYIR9Gkxoe4PNc/4uWP6DpJe28GztSRM5V3RlYpv8KQ wrapFzaryqkU8avYKcM5t1kfRSEq1lcD6oWk1n70MMG4oDQpin7pVvAux3bGRHtIC7WW w/qg== X-Gm-Message-State: AOJu0Yz9TGJgIrgIKZJUCD93yizAKgoor7eg7nSgn/3500fl19+38vOX c3an6U9tAZyV9CbRZxVHJ3/rHwe56P5Y/8x4MOI8flep X-Google-Smtp-Source: AGHT+IE3B+SaoX0g3CMJ9V5Y/q70jyzL1xViK2W3Iiv0NWLiHVmRrng5O6gT7YrWiM082uoyEj3L0A== X-Received: by 2002:a05:600c:152:b0:404:2dbb:8943 with SMTP id w18-20020a05600c015200b004042dbb8943mr5663278wmm.2.1695306169283; Thu, 21 Sep 2023 07:22:49 -0700 (PDT) Received: from localhost.localdomain (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id n11-20020a5d4c4b000000b0031fbbe347ebsm1901426wrt.22.2023.09.21.07.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 07:22:49 -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: [v2 19/19] staging: iio: resolver: ad2s1210: add triggered buffer support Date: Thu, 21 Sep 2023 09:19:47 -0500 Message-Id: <20230921141947.57784-22-dlechner@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921141947.57784-1-dlechner@baylibre.com> References: <20230921141947.57784-1-dlechner@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds 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); }