From nobody Wed Nov 27 14:33:35 2024 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D31218DF7D for ; Wed, 9 Oct 2024 09:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465587; cv=none; b=qkj8uEWeqSMj93KeyZh76H3ouqvFlnkdYU5lYBPjoTkFb7uCkXUrOYYrBFbvkY6kkUaV3C1WK0XpkzL6GB7Nmp+4OxYap7bPGKkuePhkzOZHgYU2P9lmEZKaJ4pekI3PshpJLQaiDNqPQlR4BTo0B5P9x3VNb801uDIvlRJY7KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465587; c=relaxed/simple; bh=i5ddTg9UYKxycz6OdhvhiiZOyT6VwY+Z1+h88aZcdf0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mdUwb4tjHwk0BVycDkmXVALSO4NED9HZkrDMPtYL7y6D/esO/h0rN4iPaHMbV//OFMpEp/4Y3ULXM/Z33PSBkwbGtHRrvuQWok8TlsNTpadx0WVQbjku9fKNETeJlJ7A8xcYZJg6pAb1N2JShHB469ICIIRHM8eqX3i2ZBw5leY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=gK4I6E0Y; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="gK4I6E0Y" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42cde6b5094so66754335e9.3 for ; Wed, 09 Oct 2024 02:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728465583; x=1729070383; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=h90tf0LvnuADZLFwaf8lb54SaNEZPrEuE8XroohvsMM=; b=gK4I6E0YXcYix3xCl0qM73jVpq9IVt1GzcItS9AMcDC01aQX/fQIJMEuakRcl8R9Aj C/EoIE+Lvl/ug3b/PfqwKIqKhbP+m/G8UyGzKVXRm39RlLcccGCV6QsoqDEaLETKHFKo gRtC1TAYE0JsSBnzP3mhUvB9D0w4VS8UShmOJuAjBZ6JAv6qQ3Q21DScXnC23Wbmxecq LRKTW62qAESP9lLc8JKRNMLbdMDCVuAAhNA/kJL2R3o8H0tPfngtCb3L5XQNLPMR0VFt olvh7Q8vxRtQ1h0B96McjDSZwbv9o43rWJHnA42Mo8OzuawnYWK7O99RRRfJ+251jd4O 5qCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728465583; x=1729070383; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h90tf0LvnuADZLFwaf8lb54SaNEZPrEuE8XroohvsMM=; b=SCIKYDNibHBbJ5H4Xz+TAAAoNh6mOz0MOF4kjkoIcKluySvqgkQtZ8i2J095jD+zl1 4n2dr/N0/JkcjYZV/OelDRxdmVEy0SicLL2QzDz0vo+xXHfHYuYXhqM7UGVxZwGRPeg1 mdbx3GlVtIVTkZPHsA5+XDc8fwpl4KgnSU4A+iLZkUALuQQYdfDF7oP1k3Z4MtaQn8zP CUQm79Y1rER2QGoYGSnD5ukgiYpRSbT6/WvcUM12v13pmAoAMjbFqT8WOkhWg1rv47mS 6wR6SouOqDld+gJw+X6R/oG26jyZjgX1bAQOQBpfxcuzFA9gh3S/Gn1lTaSkyRnmpgSD Uksg== X-Forwarded-Encrypted: i=1; AJvYcCV8dDVkf4y+lQM/Xfb0vJJqHPZ9YeftnrRI8pq0N67koP5QYcPoSEqqjBfHRt/PXzsAhD7wCtpQrZnsx+Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+S4YN9SubAxZGD+YpMcxI9nrkq/lyT/cgenzND+G9Ki1Pzw+c DxbDRvHZve8ejTYvLsiA/Q4y2mNfJAzjD4aG4Dnwe4DVAKgLjqt61/F25z73xCs= X-Google-Smtp-Source: AGHT+IElACimG+6TwjNDTM+qcNBc3k1d495Knh8En6ogCVmjdYeIRzhQPpMAN7sQDp73kLPKsUKufA== X-Received: by 2002:a05:600c:4706:b0:430:4db0:3fef with SMTP id 5b1f17b1804b1-430ccf3f49fmr12801225e9.15.1728465583009; Wed, 09 Oct 2024 02:19:43 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b1207sm13892765e9.31.2024.10.09.02.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:19:42 -0700 (PDT) From: Guillaume Stols Date: Wed, 09 Oct 2024 09:19:32 +0000 Subject: [PATCH v4 1/8] dt-bindings: iio: adc: ad7606: Remove spi-cpha from required Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-ad7606_add_iio_backend_support-v4-1-6971a8c0f1d5@baylibre.com> References: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> In-Reply-To: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, aardelean@baylibre.com, dlechner@baylibre.com, jstephan@baylibre.com, Jonathan Cameron , Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728465581; l=2087; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=i5ddTg9UYKxycz6OdhvhiiZOyT6VwY+Z1+h88aZcdf0=; b=hZz/mRsl6+YEI2LEnuZTydZWDHLywT+t6zZIl3mZJRYm4Nlr+PT1obtugBuoKOJZI5Nh/R8PN bNbeUWoN1WICT0cuTktqkFSsg//KPUKZ3rXfd9PI4AJE65MGJMxV2BU X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= The documentation is erroneously stating that spi-cpha is required, and the example is erroneously setting both spi-cpol and spi-cpha. According to the datasheet, only cpol should be set. On zedboard for instance, setting the devicetree as in the example will simply not work. Fixes: 416f882c3b40 ("dt-bindings: iio: adc: Migrate AD7606 documentation t= o yaml") Fixes: 6e33a125df66 ("dt-bindings: iio: adc: Add docs for AD7606 ADC") Reviewed-by: Rob Herring (Arm) Signed-off-by: Guillaume Stols --- Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad7606.yaml index bec7cfba52a7..47081c79a1cf 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml @@ -39,6 +39,11 @@ properties: "#size-cells": const: 0 =20 + # According to the datasheet, "Data is clocked in from SDI on the falling + # edge of SCLK, while data is clocked out on DOUTA on the rising edge of + # SCLK". Also, even if not stated textually in the datasheet, it is made + # clear on the diagrams that sclk idles at high. Subsequently, in case = SPI + # interface is used, the correct way is to only set spi-cpol. spi-cpha: true =20 spi-cpol: true @@ -168,7 +173,6 @@ patternProperties: required: - compatible - reg - - spi-cpha - avcc-supply - vdrive-supply - interrupts @@ -255,7 +259,6 @@ examples: reg =3D <0>; spi-max-frequency =3D <1000000>; spi-cpol; - spi-cpha; =20 avcc-supply =3D <&adc_vref>; vdrive-supply =3D <&vdd_supply>; @@ -288,7 +291,6 @@ examples: =20 spi-max-frequency =3D <1000000>; spi-cpol; - spi-cpha; =20 avcc-supply =3D <&adc_vref>; vdrive-supply =3D <&vdd_supply>; --=20 2.34.1 From nobody Wed Nov 27 14:33:35 2024 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 482EC18E028 for ; Wed, 9 Oct 2024 09:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465589; cv=none; b=LdAeu5ZooGkj2Kx+QAyXxBadBq0RpGe28YJw+zqy0++zXLKyNBI/1j+eHULLjm6gUMZIDN7O8KC3EJ69V4MzzctiECKwo3L924BZl1NTzaZR9qTs13rDp2LuovcVJceDDcAbnTnsQfZKf50nJvQBk/gZ9d7Pl3Z7snhtOmRmJi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465589; c=relaxed/simple; bh=cnL3eq0CvnDwIBAYvPykYoJ3Fx17pk9WK/iph6l0pIg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qyZQQd1YxPsuPef538a4HIfWgVCxN110GHkNGT6o+pI7IDvEH8+NkNHEZVRRmSSQzp2WPHWCuV/yEsTw8C4wMKdOQ9BhUjrm/OVDgi2PWz/ZU1spP0kBLBCG2WSGTDfnd3EmKgpoB7d6FnA+weIyKyT3JkKRiLrmt5oGCI7vnfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=RYAVmGOi; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="RYAVmGOi" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-53992157528so7021238e87.2 for ; Wed, 09 Oct 2024 02:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728465584; x=1729070384; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=55EhiFz0eoHIW1OIthep7nNdg0DTxW/ypPJriA4rZJE=; b=RYAVmGOiyy1ygQ618FqZjeauPDbPJbZcil/yagD3uWL36YYcc5u+Q3ugFyg8G06JHY PfOiMxQyhsSjKoc3u9soB7VHnmsXozNshFiWiGJAGjWZtehFLgWNaJ84nH3D6rVUnC73 ni3HWKa3+nafA3NUKkXCe/gLqL4NVW1hKYf8tUD+4MpXYqvZMVpN7dJsOM474bzNctcL +KdgICy7yOPz7l2ioBZyu0POn+g16vLwrKfjFKn0WHWXS5rq/Sqlw+S5G20kGn7Ce455 BhdSJGPFKHPEwIlEYgW1S+vGcaj/nXde74cGKNpbWoxEYmQQtsXFQ3g07uA0MqMH61Bn BPhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728465584; x=1729070384; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=55EhiFz0eoHIW1OIthep7nNdg0DTxW/ypPJriA4rZJE=; b=Yz2HI4BHnEIJMhDWWyVADK0Rx8QPAQXc0fv2/MzpCOpWY2uAKzYcDwVcVx0T9bSmgZ 1JpssBL4x+XpMsKfSzW/pG95aWtC6TKyasfi3YmPiaBJjl6glMz3lRiOFl9EjzKG2ZdG koggjPjcBg7+BZVPAE+65wntV3ULoWluzs9BpDghixSRd63oq9QSbZy/5+LbfPh1k9z6 hq9OVwEF2gdu9oY3CKGD8la+LyqkMQGTiznD+5vrrYUU9dJyGkurhSIXXGQ0inVqTUKl 4etNbTsmXjSVvfGcOKUM24iuuC6kwT9saGHVA5G9l03AkprEnf/IVol7xkAayQXxVm9F c8uw== X-Forwarded-Encrypted: i=1; AJvYcCWh5M6EwKCo7pTZy0CdtzylRvS8Xb4a2Fxut8yKNHEGZqNjG7RsULINAVFLxYml+a9tQxzhdeQpgRqgy60=@vger.kernel.org X-Gm-Message-State: AOJu0YwDhwMcQSLahWpJTM576jRQUfoQS9uW8yRnnPAuosqaizE9khUX Y425zv8apMLlMT7QDnItumqu8IjB3Etn3cQSPMUJkbs6c/tPVWeDe6uhEILq0gU= X-Google-Smtp-Source: AGHT+IGLNJaNIcoKiyIBWQ3zVE26ZTEfaMbdvpfKWiYWNHWxUSJ8EEVTwm8NWBLhob73R+caHhP15g== X-Received: by 2002:a05:6512:3501:b0:52f:d090:6da6 with SMTP id 2adb3069b0e04-539c49615c6mr955380e87.55.1728465583893; Wed, 09 Oct 2024 02:19:43 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b1207sm13892765e9.31.2024.10.09.02.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:19:43 -0700 (PDT) From: Guillaume Stols Date: Wed, 09 Oct 2024 09:19:33 +0000 Subject: [PATCH v4 2/8] dt-bindings: iio: adc: ad7606: Add iio backend bindings Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-ad7606_add_iio_backend_support-v4-2-6971a8c0f1d5@baylibre.com> References: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> In-Reply-To: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, aardelean@baylibre.com, dlechner@baylibre.com, jstephan@baylibre.com, Jonathan Cameron , Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728465581; l=3731; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=cnL3eq0CvnDwIBAYvPykYoJ3Fx17pk9WK/iph6l0pIg=; b=TdN3OCOIwD++z3xC2TnuMjOLsKpVwDChCeQwC/nTkT15Hpf3dRJZNCczmSej8m+ohrKAQ6pZ0 smAIWx13T0lBDkH19jK5xG4pbHbV/yd/RLfmxpm4ULFJ4eEtLaqwutG X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= Add the required properties for iio-backend support, as well as an example and the conditions to mutually exclude interruption and conversion trigger with iio-backend. The iio-backend's function is to controls the communication, and thus the interruption pin won't be available anymore. As a consequence, the conversion pin must be controlled externally since we will miss information about when every single conversion cycle (i.e conversion + data transfer) ends, hence a PWM is introduced to trigger the conversions. Reviewed-by: Rob Herring (Arm) Signed-off-by: Guillaume Stols --- .../devicetree/bindings/iio/adc/adi,ad7606.yaml | 64 ++++++++++++++++++= +++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad7606.yaml index 47081c79a1cf..0a612844029a 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml @@ -129,6 +129,29 @@ properties: assumed that the pins are hardwired to VDD. type: boolean =20 + pwms: + description: + In case the conversion is triggered by a PWM instead of a GPIO plugg= ed to + the CONVST pin, the PWM must be referenced. + The first is the PWM connected to CONVST or CONVST1 for the chips wi= th the + 2nd PWM connected to CONVST2, if CONVST2 is available and not shorte= d to + CONVST1. + minItems: 1 + maxItems: 2 + + pwm-names: + items: + - const: convst1 + - const: convst2 + + io-backends: + description: + A reference to the iio-backend, which is responsible handling the BU= SY + pin's falling edge and communication. + An example of backend can be found at + http://analogdevicesinc.github.io/hdl/library/axi_ad7606x/index.html + + patternProperties: "^channel@[1-8]$": type: object @@ -175,12 +198,22 @@ required: - reg - avcc-supply - vdrive-supply - - interrupts - - adi,conversion-start-gpios =20 allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# =20 + - oneOf: + - required: + - adi,conversion-start-gpios + - required: + - pwms + + - oneOf: + - required: + - interrupts + - required: + - io-backends + - if: properties: compatible: @@ -222,6 +255,10 @@ allOf: adi,sw-mode: false else: properties: + pwms: + maxItems: 1 + pwm-names: + maxItems: 1 adi,conversion-start-gpios: maxItems: 1 =20 @@ -247,6 +284,29 @@ allOf: unevaluatedProperties: false =20 examples: + - | + #include + iio-backend { + #address-cells =3D <1>; + #size-cells =3D <0>; + adi_adc@0 { + compatible =3D "adi,ad7606b"; + reg =3D <0>; + pwms =3D <&axi_pwm_gen 0 0>; + + avcc-supply =3D <&adc_vref>; + vdrive-supply =3D <&vdd_supply>; + + reset-gpios =3D <&gpio0 91 GPIO_ACTIVE_HIGH>; + standby-gpios =3D <&gpio0 90 GPIO_ACTIVE_LOW>; + adi,range-gpios =3D <&gpio0 89 GPIO_ACTIVE_HIGH>; + adi,oversampling-ratio-gpios =3D <&gpio0 88 GPIO_ACTIVE_HIGH + &gpio0 87 GPIO_ACTIVE_HIGH + &gpio0 86 GPIO_ACTIVE_HIGH>; + io-backends =3D <&iio_backend>; + }; + }; + - | #include #include --=20 2.34.1 From nobody Wed Nov 27 14:33:35 2024 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF20E18E02A for ; Wed, 9 Oct 2024 09:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465590; cv=none; b=fZCMxZ+THvaZGiocEQ5yvvOXdKUY7pe9iA8vR1hOFLdZ4AfFcDe1f3//DkOeq464v1/3E+9LdGOTFzV2nGcxAqI9aTxkDj1tjjc8oKrO54XbvEbieHJmR42TJ9Y7JKkx2fFg0mGhvco0BHkAaxhDrdJWVYfeGnSQwyxwv4y0zAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465590; c=relaxed/simple; bh=issnyYMdCERRxnBv+UMpQ1OQfEwMp1TWqu/h+AKGhdM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZACLHrKWCLLO/703G7lpB2k4nF3f2zJlV5ClgpOT8c+VFDG2awtfV0y2hA3AfI5jtFT7iiuCHkQT1BSSa3qIMsse0sLeju7YYBbukqyZXeKWcBGVGAW6voVKg3DMk30eviA8TDkJJ6iXxfo7FQjv/emmubuomxYvk3xm7kxvM5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=1OQkTSKI; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="1OQkTSKI" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42e748f78d6so59016665e9.0 for ; Wed, 09 Oct 2024 02:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728465585; x=1729070385; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MLAaXmEjWpRQwLJ98ZnYGrLU5C7IB5VjlX8gFYsob8k=; b=1OQkTSKI3NQF+XdbCG+ITEeI9zOSmzAW6IQ+SGwj8/SvJnSr7LY7dOeZ/GZfM0r4dS xNPEEkSq10T06pPvpFGxrE8DEsgqba76K/S8c0qbX47KVYEJbPXLolkGLFWrVEYIwc07 floBt3BG1q5AaEV6ugX7JXuV53pihjJq9VV019iUrpxAM2izPYc2hf21Cn6errR2KS+K 9wZhUP3MAD/Hd6j6DV4lZMIbJ0tDsm1HWG9ub3eekg4PCuAIg6QcKp8sIFTJiH9RWKf/ SWS191BHVtbnuQUutaIIakbFHZRAEk/d2eZ4PeKkVf724qzCk4VJCj7A1E+LRtfvO6aE vlTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728465585; x=1729070385; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MLAaXmEjWpRQwLJ98ZnYGrLU5C7IB5VjlX8gFYsob8k=; b=VUutRFB4k3j3TsXglAztev0SdDRch6Ve/7alrN1icu2MR/gl+RpRIP3P1TOfIL9BNh 5hy55XdvYvBnn2sTa7gcT0/9dNmRNiFjLJgpRuBMjen2bPrWSRnYtzG3C7+flCz77gn8 obZq6Ga/2EaFkXF9RbWUfUWg4reKqWUd0xcc4LWa8zuRj/Zpj3KpAbm8q/RCtBi2FHV+ LXlKozHLBsGr+AlVQ+t4ZjQVIJ42IuR/ZSltO9ouh0b6XprC9KBLc+g/XLvfzZEeiued Ly/T2YJ0jDbdlwW6H/KsEoAlaJUqMddttRFWxQxR5bwH2bju4OWzwclksIdJkC1CImSW UwtA== X-Forwarded-Encrypted: i=1; AJvYcCWpMMaWLoy387xUnB8X92kauUNGeg/amvXOPgGwqXGnGgNgifWH+3EapHYJVXHQDtGbxq/YpadXtQ9H/LA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4Y6ATNj9wXRgtlEgtphbG/kwPhocqQz8aCEiYo2CPhUC+oM2+ IM96NVisXRZXbAxJF4jVFP9/qQ0X57p+22d65Z8gS8CHOq/O1w7Z7TU7Uh+vQX4= X-Google-Smtp-Source: AGHT+IGUlTEo7sclngMsjwjSVZGdoDLFF1EJ5qnB7fwjfP/3CKVPQ73LhZMLC32PTpf9nOijZ0bB/A== X-Received: by 2002:a05:600c:3b9f:b0:42c:a6da:a149 with SMTP id 5b1f17b1804b1-430d6faa3cdmr11805775e9.25.1728465584877; Wed, 09 Oct 2024 02:19:44 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b1207sm13892765e9.31.2024.10.09.02.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:19:44 -0700 (PDT) From: Guillaume Stols Date: Wed, 09 Oct 2024 09:19:34 +0000 Subject: [PATCH v4 3/8] Documentation: iio: Document ad7606 driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-ad7606_add_iio_backend_support-v4-3-6971a8c0f1d5@baylibre.com> References: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> In-Reply-To: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, aardelean@baylibre.com, dlechner@baylibre.com, jstephan@baylibre.com, Jonathan Cameron , Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728465581; l=6859; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=issnyYMdCERRxnBv+UMpQ1OQfEwMp1TWqu/h+AKGhdM=; b=oTelQqwe4mpz3ws8GkoaPtVhvqWQ1G957SfIfa2zt56bvDBFx/qm6KcZO1cYhCuj52My7ijVt N0TUyY6v8CmC9aF2clnzwh68lxWDijqY21Y9Lcb/3jByy9xXgLPGfg8 X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= The Analog Devices Inc. AD7606 (and similar chips) are complex ADCs that will benefit from a detailed driver documentation. This documents the current features supported by the driver. Signed-off-by: Guillaume Stols --- Documentation/iio/ad7606.rst | 145 +++++++++++++++++++++++++++++++++++++++= ++++ Documentation/iio/index.rst | 1 + MAINTAINERS | 1 + 3 files changed, 147 insertions(+) diff --git a/Documentation/iio/ad7606.rst b/Documentation/iio/ad7606.rst new file mode 100644 index 000000000000..a1173708b489 --- /dev/null +++ b/Documentation/iio/ad7606.rst @@ -0,0 +1,145 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +AD7606 driver +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +ADC driver for Analog Devices Inc. AD7606 and similar devices. The module = name +is ``ad7606``. + +Supported devices +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The following chips are supported by this driver: + +* `AD7605 `_ +* `AD7606 `_ +* `AD7606B `_ +* `AD7616 `_ + +Supported features +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +SPI wiring modes +---------------- + +These ADCs can output data on several SDO lines (1/2/4/8). The driver +currently supports only 1 SDO line. + +Parallel wiring mode +-------------------- + +There is also a parallel interface, with 16 lines (that can be reduced to = 8 in +byte mode). The parallel interface is selected by declaring the device as +platform in the device tree (with no io-backends node defined, see below). + +IIO-backend mode +---------------- + +This mode allows to reach the best sample rates, but it requires an extern= al +hardware (eg HDL or APU) to handle the low level communication. +The backend mode is enabled when through the definition of the "io-backend= s" +property in the device tree. + +The reference configuration for the current implementation of IIO-backend = mode +is the HDL reference provided by ADI: +https://wiki.analog.com/resources/eval/user-guides/ad7606x-fmc/hdl + +This implementation embeds an IIO-backend compatible IP (adi-axi-adc) and = a PWM +connected to the conversion trigger pin. + +.. code-block:: + + +---+ +-------------------------= --- + | | +-------+ |AD76xx + | A | controls | | | + | D |-------------->| PWM |-------------->| cnvst + | 7 | | | | + | 6 | +-------+ | + | 0 | controls +-----------+-----------+ | + | 6 |---------->| | |<--| frstdata + | | | Backend | Backend |<--| busy + | D | | Driver | | | + | R | | | |-->| clk + | I | requests |+---------+| DMA | | + | V |----------->| Buffer ||<---- |<=3D>| DATA + | E | |+---------+| | | + | R | +-----------+-----------+ | + | |-------------------------------------->| reset/configuration gpios + +---+ +-------------------------= ---- + + +Software and hardware modes +--------------------------- + +While all the AD7606/AD7616 series parts can be configured using GPIOs, so= me of +them can be configured using register. + +The chips that support software mode have more values available for config= uring +the device, as well as more settings, and allow to control the range and +calibration per channel. + +The following settings are available per channel in software mode: + - Scale + +Also, there is a broader choice of oversampling ratios in software mode. + +Conversion triggering +--------------------- + +The conversion can be triggered by two distinct ways: + + - A GPIO is connected to the conversion trigger pin, and this GPIO is con= trolled + by the driver directly. In this configuration, the driver sets back the + conversion trigger pin to high as soon as it has read all the conversio= ns. + + - An external source is connected to the conversion trigger pin. In the + current implementation, it must be a PWM. In this configuration, the dr= iver + does not control directly the conversion trigger pin. Instead, it can + control the PWM's frequency. This trigger is enabled only for iio-backe= nd. + +Reference voltage +----------------- + +2 possible reference voltage sources are supported: + + - Internal reference (2.5V) + - External reference (2.5V) + +The source is determined by the device tree. If ``refin-supply`` is presen= t, +then the external reference is used, otherwise the internal reference is u= sed. + +Oversampling +------------ + +This family supports oversampling to improve SNR. +In software mode, the following ratios are available: +1 (oversampling disabled)/2/4/8/16/32/64/128/256. + +Unimplemented features +---------------------- + +- 2/4/8 SDO lines +- CRC indication +- Calibration + +Device buffers +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +IIO triggered buffer +-------------------- + +This driver supports IIO triggered buffers, with a "built in" trigger, i.e= the +trigger is allocated and linked by the driver, and a new conversion is tri= ggered +as soon as the samples are transferred, and a timestamp channel is added t= o make +up for the potential jitter induced by the delays in the interrupt handlin= g. + +IIO backend buffer +------------------ + +When IIO backend is used, the trigger is not needed, and the sample rate is +considered as stable. There is no timestamp channel. The communication is +delegated to an external logic, called a backend, and the backend's driver +handles the buffer. When this mode is enabled, the driver cannot control t= he +conversion pin, because the busy pin is bound to the backend. + diff --git a/Documentation/iio/index.rst b/Documentation/iio/index.rst index dfcf9618568a..88bc36326b74 100644 --- a/Documentation/iio/index.rst +++ b/Documentation/iio/index.rst @@ -21,6 +21,7 @@ Industrial I/O Kernel Drivers ad4000 ad4695 ad7380 + ad7606 ad7944 adis16475 adis16480 diff --git a/MAINTAINERS b/MAINTAINERS index 6011af70c12e..e5e52cfd5fe1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1561,6 +1561,7 @@ F: Documentation/ABI/testing/sysfs-bus-iio-frequency-= adf4350 F: Documentation/devicetree/bindings/iio/*/adi,* F: Documentation/devicetree/bindings/iio/adc/lltc,ltc2496.yaml F: Documentation/devicetree/bindings/iio/adc/lltc,ltc2497.yaml +F: Documentation/iio/ad7606.rst F: drivers/iio/*/ad* F: drivers/iio/adc/ltc249* F: drivers/iio/amplifiers/hmc425a.c --=20 2.34.1 From nobody Wed Nov 27 14:33:35 2024 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEB3718E04B for ; Wed, 9 Oct 2024 09:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465591; cv=none; b=NnyjY6QKh1myg8GHoHI34nrNftrRMgubZLKrWVG7v6wmX9gInxtcr9wh9DCIbZPQo181pvU1/Uos1pJK59fOijyP0snoU3XoHkwFUdb0hTzMmNLhgnd7R3b++bG5CNNigNRUJkWiv+AladATATAnxyaKROKCWAPciUwWXrs3rUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465591; c=relaxed/simple; bh=87yaVsOuc7HGTZSKrab6+fSDC6x8gEmCA8Z7AKmujmE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c2PnyJZdM0FyWCPcvhPa2xoBcNJzOjmKV1v7EZM9VctuhxL0U3xkDf+6NIfDf79ZvqNH2V7iGC7Udf/hd4AycgzfppD+/XDXKP0RhjdaNYu+L8I35GdtiLnJEub57GbT8rneB612jhUCeE6I6rLF8CllcdaB1GY7F/B7YEBaTaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=bU1czqD6; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="bU1czqD6" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-42e82f7f36aso58441185e9.0 for ; Wed, 09 Oct 2024 02:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728465586; x=1729070386; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=fPnPbKQUcTWVWOwgUqCHkavfJgSY/Vnx2IKBeygP7tg=; b=bU1czqD6eNtVHGx40L+/wqTDHxT3rQzDuYZGlyMyHhhQE4dtWQPGXmOka92XV7nHBo ujm8+06w+9spkvrSmu4jRFwWa4jfqKFiP8Q4e8xGhk0mAgMgSFpkK4ufxeBZ9NZe6sdl 2kLuJ971SfBl0idymXDkcxaciG32hmXSIW7zUUe6T2ZLodv7dOap8pIQztpD58Q4RT8b ln1EEnSWJA41lhFxDG3kxj/0ABirxqXwbYzVuz6xkOTOV/BvT5FLv11LWArnyS/7wMZ/ xK8Q/0TdRTxRjNqGuIPq6c2e142xsgkIJzC1mnSwIYuldCAoE7BthvYNrT01M2GpMiQY nMmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728465586; x=1729070386; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fPnPbKQUcTWVWOwgUqCHkavfJgSY/Vnx2IKBeygP7tg=; b=Ct0IUuCFBSiL0FfxEPJ3iByjA6ufclSi02Uv9lvPzi01TAQLlFSVySb+QePgoWDbmR HLczpG7L6os3EOMM3NzZG94wR2ZvtA7J0E4DlrmctzKo0V3oq7sMIYWnn5EK5tOjmUgS aDf+GyUuvwcLb23BMa9+LwtZCFVIyboUL3vlWzgtE6TouwpG0urLzekTlQNQinB8IuDW g7QY+wv4QhbAivE/iG4lRV4JHR9pO1LBH1PkqM6LZ7d7Q/VDtQeyQLJqdVBaWhlJ8fsc mtVjHD8K/2bKyI2S7a5GZB+2h2vxnpNn0yNg3JbXLorZOCwQz0BrpA5EpsHddnrLdiTK l+yg== X-Forwarded-Encrypted: i=1; AJvYcCVV4OYMDBGLF1tlqfRyWjXjExTEWa5c1q7lO3gAfv1aOnjDY2KpPDQuR/hN2kr5Xq8+wAiZJQQJ68J6WBg=@vger.kernel.org X-Gm-Message-State: AOJu0YxRwOqdGWYSCUArtLe2vJT955t3HvbQK33G38guMR1GGqgzPxJ5 4PTmdQPvHfWkkobklORkjrTkQLxldJrjudDv+3aMeCtfq3oZd3Ik72qfxg2GjOw= X-Google-Smtp-Source: AGHT+IHQjXOxvO6GCCTQfEOD/1CVeHFRdIgDYJWyIPnnsjAlZ8Z8xRNK7tBq0YOMzvXsYctc5Rg0tw== X-Received: by 2002:a05:600c:1c9b:b0:42c:cd88:d0f7 with SMTP id 5b1f17b1804b1-430ccf1abe0mr10699375e9.10.1728465585608; Wed, 09 Oct 2024 02:19:45 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b1207sm13892765e9.31.2024.10.09.02.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:19:45 -0700 (PDT) From: Guillaume Stols Date: Wed, 09 Oct 2024 09:19:35 +0000 Subject: [PATCH v4 4/8] iio: adc: ad7606: Add PWM support for conversion trigger Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-ad7606_add_iio_backend_support-v4-4-6971a8c0f1d5@baylibre.com> References: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> In-Reply-To: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, aardelean@baylibre.com, dlechner@baylibre.com, jstephan@baylibre.com, Jonathan Cameron , Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728465581; l=8922; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=87yaVsOuc7HGTZSKrab6+fSDC6x8gEmCA8Z7AKmujmE=; b=TbjtdjStx9zSfrvA4TJ9JfjrTLT3DF/zvBuvITXZ9HZhFZ16bmTrlCiRGXIUGo2UED3yU5sW2 3GDtDfoI/+3CWpQECMKiiN8foLtCWzvNC3fjJIl1JfRKvvF5QbAwyt7 X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= Until now, the conversion were triggered by setting high the GPIO connected to the convst pin. This commit gives the possibility to connect the convst pin to a PWM. Connecting a PWM allows to have a better control on the samplerate, but it must be handled with care, as it is completely decorrelated of the driver's busy pin handling. Hence it is not recommended to be used "as is" but must be exploited in conjunction with IIO backend, and for now only a mock functionality is enabled, i.e PWM never swings, but is used as a GPIO, i.e duty_cycle =3D=3D period equals high state, duty_cycle =3D=3D 0 equals low state. This mock functionality will be disabled after the IIO backend usecase is introduced. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.c | 143 +++++++++++++++++++++++++++++++++++++++++++= ---- drivers/iio/adc/ad7606.h | 2 + 2 files changed, 135 insertions(+), 10 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 71362eafe838..5b276d087ec3 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -13,10 +13,12 @@ #include #include #include +#include #include #include #include #include +#include #include =20 #include @@ -299,6 +301,82 @@ static int ad7606_reg_access(struct iio_dev *indio_dev, } } =20 +static int ad7606_pwm_set_high(struct ad7606_state *st) +{ + struct pwm_state cnvst_pwm_state; + int ret; + + if (!st->cnvst_pwm) + return -EINVAL; + + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); + cnvst_pwm_state.enabled =3D true; + cnvst_pwm_state.duty_cycle =3D cnvst_pwm_state.period; + + ret =3D pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); + /* sleep 2 =C2=B5S to let finish the current pulse */ + fsleep(2); + + return ret; +} + +static int ad7606_pwm_set_low(struct ad7606_state *st) +{ + struct pwm_state cnvst_pwm_state; + int ret; + + if (!st->cnvst_pwm) + return -EINVAL; + + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); + cnvst_pwm_state.enabled =3D true; + cnvst_pwm_state.duty_cycle =3D 0; + + ret =3D pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); + /* sleep 2 =C2=B5S to let finish the current pulse */ + fsleep(2); + + return ret; +} + +static bool ad7606_pwm_is_swinging(struct ad7606_state *st) +{ + struct pwm_state cnvst_pwm_state; + + if (!st->cnvst_pwm) + return false; + + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); + + return cnvst_pwm_state.duty_cycle !=3D cnvst_pwm_state.period && + cnvst_pwm_state.duty_cycle !=3D 0; +} + +static int ad7606_set_sampling_freq(struct ad7606_state *st, unsigned long= freq) +{ + struct pwm_state cnvst_pwm_state; + bool is_swinging =3D ad7606_pwm_is_swinging(st); + bool is_high; + + if (freq =3D=3D 0) + return -EINVAL; + + /* Retrieve the previous state. */ + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); + is_high =3D cnvst_pwm_state.duty_cycle =3D=3D cnvst_pwm_state.period; + + cnvst_pwm_state.period =3D DIV_ROUND_UP_ULL(NSEC_PER_SEC, freq); + cnvst_pwm_state.polarity =3D PWM_POLARITY_NORMAL; + if (is_high) + cnvst_pwm_state.duty_cycle =3D cnvst_pwm_state.period; + else if (is_swinging) + cnvst_pwm_state.duty_cycle =3D cnvst_pwm_state.period / 2; + else + cnvst_pwm_state.duty_cycle =3D 0; + + return pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); +} + static int ad7606_read_samples(struct ad7606_state *st) { unsigned int num =3D st->chip_info->num_channels - 1; @@ -325,6 +403,7 @@ static irqreturn_t ad7606_trigger_handler(int irq, void= *p) iio_trigger_notify_done(indio_dev->trig); /* The rising edge of the CONVST signal starts a new conversion. */ gpiod_set_value(st->gpio_convst, 1); + ad7606_pwm_set_high(st); =20 return IRQ_HANDLED; } @@ -337,7 +416,13 @@ static int ad7606_scan_direct(struct iio_dev *indio_de= v, unsigned int ch, const struct iio_chan_spec *chan; int ret; =20 - gpiod_set_value(st->gpio_convst, 1); + if (st->gpio_convst) { + gpiod_set_value(st->gpio_convst, 1); + } else { + ret =3D ad7606_pwm_set_high(st); + if (ret < 0) + return ret; + } ret =3D wait_for_completion_timeout(&st->completion, msecs_to_jiffies(1000)); if (!ret) { @@ -363,6 +448,11 @@ static int ad7606_scan_direct(struct iio_dev *indio_de= v, unsigned int ch, } =20 error_ret: + if (!st->gpio_convst) { + ret =3D ad7606_pwm_set_low(st); + if (ret < 0) + return ret; + } gpiod_set_value(st->gpio_convst, 0); =20 return ret; @@ -662,8 +752,9 @@ static int ad7606_request_gpios(struct ad7606_state *st) { struct device *dev =3D st->dev; =20 - st->gpio_convst =3D devm_gpiod_get(dev, "adi,conversion-start", - GPIOD_OUT_LOW); + st->gpio_convst =3D devm_gpiod_get_optional(dev, "adi,conversion-start", + GPIOD_OUT_LOW); + if (IS_ERR(st->gpio_convst)) return PTR_ERR(st->gpio_convst); =20 @@ -708,6 +799,7 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_= id) =20 if (iio_buffer_enabled(indio_dev)) { gpiod_set_value(st->gpio_convst, 0); + ad7606_pwm_set_low(st); iio_trigger_poll_nested(st->trig); } else { complete(&st->completion); @@ -732,6 +824,7 @@ static int ad7606_buffer_postenable(struct iio_dev *ind= io_dev) struct ad7606_state *st =3D iio_priv(indio_dev); =20 gpiod_set_value(st->gpio_convst, 1); + ad7606_pwm_set_high(st); =20 return 0; } @@ -741,6 +834,7 @@ static int ad7606_buffer_predisable(struct iio_dev *ind= io_dev) struct ad7606_state *st =3D iio_priv(indio_dev); =20 gpiod_set_value(st->gpio_convst, 0); + ad7606_pwm_set_low(st); =20 return 0; } @@ -874,6 +968,11 @@ static int ad7606_chan_scales_setup(struct iio_dev *in= dio_dev) return 0; } =20 +static void ad7606_pwm_disable(void *data) +{ + pwm_disable(data); +} + int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops) @@ -950,6 +1049,31 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, if (ret) return ret; =20 + /* If convst pin is not defined, setup PWM. */ + if (!st->gpio_convst) { + st->cnvst_pwm =3D devm_pwm_get(dev, NULL); + if (IS_ERR(st->cnvst_pwm)) + return PTR_ERR(st->cnvst_pwm); + + /* The PWM is initialized at 1MHz to have a fast enough GPIO emulation. = */ + ret =3D ad7606_set_sampling_freq(st, 1 * MEGA); + if (ret) + return ret; + + ret =3D ad7606_pwm_set_low(st); + if (ret) + return ret; + + /* + * PWM is not disabled when sampling stops, but instead its duty cycle i= s set + * to 0% to be sure we have a "low" state. After we unload the driver, l= et's + * disable the PWM. + */ + ret =3D devm_add_action_or_reset(dev, ad7606_pwm_disable, + st->cnvst_pwm); + if (ret) + return ret; + } st->trig =3D devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, iio_device_id(indio_dev)); @@ -963,6 +1087,12 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, return ret; =20 indio_dev->trig =3D iio_trigger_get(st->trig); + ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, + &iio_pollfunc_store_time, + &ad7606_trigger_handler, + &ad7606_buffer_ops); + if (ret) + return ret; =20 ret =3D devm_request_threaded_irq(dev, irq, NULL, @@ -972,13 +1102,6 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, if (ret) return ret; =20 - ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, - &iio_pollfunc_store_time, - &ad7606_trigger_handler, - &ad7606_buffer_ops); - if (ret) - return ret; - return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(ad7606_probe, IIO_AD7606); diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index fc05a4afa3b8..760cf5e2ecb6 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -115,6 +115,7 @@ struct ad7606_chan_scale { * @bops bus operations (SPI or parallel) * @chan_scales scale configuration for channels * @oversampling oversampling selection + * @cnvst_pwm pointer to the PWM device connected to the cnvst pin * @base_address address from where to read data in parallel operation * @sw_mode_en software mode enabled * @oversampling_avail pointer to the array which stores the available @@ -142,6 +143,7 @@ struct ad7606_state { const struct ad7606_bus_ops *bops; struct ad7606_chan_scale chan_scales[AD760X_MAX_CHANNELS]; unsigned int oversampling; + struct pwm_device *cnvst_pwm; void __iomem *base_address; bool sw_mode_en; const unsigned int *oversampling_avail; --=20 2.34.1 From nobody Wed Nov 27 14:33:35 2024 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CFB419007E for ; Wed, 9 Oct 2024 09:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465593; cv=none; b=attrfRNwEhnCY2/pdMoVTrVm58J0WpKI1AuVdXXROWtkqi0Ac9sbEaLextxvXEP0+Vz94Hcq8SQqR/C7kReSdl87KSGvzS5ZJIGtMBhmWJVNz6JqMFivnvCiKu6AxDURUOg4ugXnFRqxpk6rmykoyiRVB3ga0OOkerX1Ev/1Pq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465593; c=relaxed/simple; bh=CPz3PWgpiVCnm2N88B5NnP0FnQR617PgIv7GQdsjmHE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Jt5P/ojub8ssOwII8KP7ob1lvapq+kUgK6zzrf0Lfix4/Q4jynKh/79eCvbeKz1UY19LgiFBfg1r1AfxR5uQYkde5wLsicqHNt96FitBGgEF45V/b74Ta22TAM/9ExP88uP+LpkC81esXSXl2HIf+2tSVMKafW0n/+33C3rxb+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=gZnazfjT; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="gZnazfjT" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-53993c115cfso8492894e87.2 for ; Wed, 09 Oct 2024 02:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728465587; x=1729070387; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cyuLXUifDpa6MUr7e9IQSAngfTP4B5vgS2+NDc8RY3U=; b=gZnazfjT6rOTyujZIH3mPYdf7ZLmB+fEmMb9huEhDVFSf/1heJqAXydPK25JkHJroj /BKzejq9T0X/wuFa1CxJfAcIJb01XptTbIEk/nYGJtb6maz3QkI2RVzXtQcRx00v498Y QusYNyfgD2jVZmfMFGSq9MKAS9hD8b7CzisiRZXdZFv6nR5k/GNN95jLEkpmA7PonfxR /2Dv9GTqjFjH43thqVKsOgfbEm9q/nFu85fmggUahijTYp1fQ02g3vj9imSmeKVJXrRa b4BpY982P004TfX4nnPCKRMh5tVrRL9SdTIpppWaXIp7bJZ7MjCvaAw7684romuQkQLe sriA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728465587; x=1729070387; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cyuLXUifDpa6MUr7e9IQSAngfTP4B5vgS2+NDc8RY3U=; b=rP3S3IZ88W0zb09hhBIsHDNqQ1bZpWDIyScw3nJbkq+r7AJqtZ72x2cji//JlEShpK PBtDyaBun3XkZ7Lh3KNjVslH37+v+2xsI1VQIwqKGRre4wU4+vLjCJUEPKbftcAtP99h Fa7WyyD55zQ8Fkm3UKS77R3MTbu0JOAXHetKRVIi8Wyglge3yCRwrXnGVcIRhunKv+gd OQwq+qZPwlr2Eq3OYPuIba/DXfcQzPiFB+vg9dNAeKzjzc0VUlqf3huZrvRs2Unrh5f5 fSZ94DDpyzklFC/bgTcBCBQLQDsE7jE8UVOvE7cQYwKCTgIJv/oMCCOM6FzxFTF6RhuX qBBg== X-Forwarded-Encrypted: i=1; AJvYcCXvMMJZ7yqidRpMGJGbloiyhAIAapoX69U3ajbCx0tcfvz7TnaJ+lq9XsxK/OXkn9pd/evyX8B3YEhrnw8=@vger.kernel.org X-Gm-Message-State: AOJu0YyHpPD65tLBC5bHXqXOQRUxQZgZxJwIwGcuAvaOgjWHNjTvbL5n UmEqo4s+/SjF0GBaU63jMu9GsTNlMR55KEI49g1RQ4io3G98MEOKakxZUCgSmEM= X-Google-Smtp-Source: AGHT+IGfbQFtpUVH/1FKAg0NB1OAi0Rawb3g8UCaWRSybiwJ+pM94wXMGYhkHYaZdZYYnF9z4uwnMg== X-Received: by 2002:a05:6512:1385:b0:530:ad7d:8957 with SMTP id 2adb3069b0e04-539c4978a8amr825000e87.49.1728465586450; Wed, 09 Oct 2024 02:19:46 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b1207sm13892765e9.31.2024.10.09.02.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:19:46 -0700 (PDT) From: Guillaume Stols Date: Wed, 09 Oct 2024 09:19:36 +0000 Subject: [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-ad7606_add_iio_backend_support-v4-5-6971a8c0f1d5@baylibre.com> References: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> In-Reply-To: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, aardelean@baylibre.com, dlechner@baylibre.com, jstephan@baylibre.com, Jonathan Cameron , Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728465581; l=20771; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=CPz3PWgpiVCnm2N88B5NnP0FnQR617PgIv7GQdsjmHE=; b=a3quvNvvmjildF7gztLBMZqJ+pLE4gXvt8+OL3jCiJ3zGcjQ9FDtMDrTIgrKKnN3SuCMGFpOt GdvcGBOYQfACr1+l5eqCX7m/Fyesp0n4njKcdPrWH6ABJ27wfQnet8u X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= On the parallel version, the current implementation is only compatible with id tables and won't work with fw_nodes, this commit intends to fix it. Doing so required to declare ad7606_chip_info structures in the .h file so to make them accessible to all the driver files that can set a pointer to the corresponding chip as the driver data. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.c | 283 ++++++++++++++++++++++++---------------= ---- drivers/iio/adc/ad7606.h | 32 +++-- drivers/iio/adc/ad7606_par.c | 30 +++-- drivers/iio/adc/ad7606_spi.c | 96 +++++++++------ 4 files changed, 254 insertions(+), 187 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 5b276d087ec3..dfbdea8c28ba 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -78,6 +78,155 @@ static const unsigned int ad7616_oversampling_avail[8] = =3D { 1, 2, 4, 8, 16, 32, 64, 128, }; =20 +static const struct iio_chan_spec ad7605_channels[] =3D { + IIO_CHAN_SOFT_TIMESTAMP(4), + AD7605_CHANNEL(0), + AD7605_CHANNEL(1), + AD7605_CHANNEL(2), + AD7605_CHANNEL(3), +}; + +static const struct iio_chan_spec ad7606_channels_16bit[] =3D { + IIO_CHAN_SOFT_TIMESTAMP(8), + AD7606_CHANNEL(0, 16), + AD7606_CHANNEL(1, 16), + AD7606_CHANNEL(2, 16), + AD7606_CHANNEL(3, 16), + AD7606_CHANNEL(4, 16), + AD7606_CHANNEL(5, 16), + AD7606_CHANNEL(6, 16), + AD7606_CHANNEL(7, 16), +}; + +static const struct iio_chan_spec ad7606_channels_18bit[] =3D { + IIO_CHAN_SOFT_TIMESTAMP(8), + AD7606_CHANNEL(0, 18), + AD7606_CHANNEL(1, 18), + AD7606_CHANNEL(2, 18), + AD7606_CHANNEL(3, 18), + AD7606_CHANNEL(4, 18), + AD7606_CHANNEL(5, 18), + AD7606_CHANNEL(6, 18), + AD7606_CHANNEL(7, 18), +}; + +/* + * The current assumption that this driver makes for AD7616, is that it's + * working in Hardware Mode with Serial, Burst and Sequencer modes activat= ed. + * To activate them, following pins must be pulled high: + * -SER/PAR + * -SEQEN + * And following pins must be pulled low: + * -WR/BURST + * -DB4/SER1W + */ +static const struct iio_chan_spec ad7616_channels[] =3D { + IIO_CHAN_SOFT_TIMESTAMP(16), + AD7606_CHANNEL(0, 16), + AD7606_CHANNEL(1, 16), + AD7606_CHANNEL(2, 16), + AD7606_CHANNEL(3, 16), + AD7606_CHANNEL(4, 16), + AD7606_CHANNEL(5, 16), + AD7606_CHANNEL(6, 16), + AD7606_CHANNEL(7, 16), + AD7606_CHANNEL(8, 16), + AD7606_CHANNEL(9, 16), + AD7606_CHANNEL(10, 16), + AD7606_CHANNEL(11, 16), + AD7606_CHANNEL(12, 16), + AD7606_CHANNEL(13, 16), + AD7606_CHANNEL(14, 16), + AD7606_CHANNEL(15, 16), +}; + +static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch); +static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch); +static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch); + +const struct ad7606_chip_info ad7605_4_info =3D { + .channels =3D ad7605_channels, + .name =3D "ad7605-4", + .num_channels =3D 5, + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7605_4_info, IIO_AD7606); + +const struct ad7606_chip_info ad7606_8_info =3D { + .channels =3D ad7606_channels_16bit, + .name =3D "ad7606-8", + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7606_8_info, IIO_AD7606); + +const struct ad7606_chip_info ad7606_6_info =3D { + .channels =3D ad7606_channels_16bit, + .name =3D "ad7606-6", + .num_channels =3D 7, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7606_6_info, IIO_AD7606); + +const struct ad7606_chip_info ad7606_4_info =3D { + .channels =3D ad7606_channels_16bit, + .name =3D "ad7606-4", + .num_channels =3D 5, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606); + +const struct ad7606_chip_info ad7606b_info =3D { + .channels =3D ad7606_channels_16bit, + .name =3D "ad7606b", + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7606b_info, IIO_AD7606); + +const struct ad7606_chip_info ad7606c_16_info =3D { + .channels =3D ad7606_channels_16bit, + .name =3D "ad7606c16", + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7606c_16bit_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606); + +const struct ad7606_chip_info ad7606c_18_info =3D { + .channels =3D ad7606_channels_18bit, + .name =3D "ad7606c18", + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7606c_18bit_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7606c_18_info, IIO_AD7606); + +const struct ad7606_chip_info ad7616_info =3D { + .channels =3D ad7616_channels, + .init_delay_ms =3D 15, + .name =3D "ad7616", + .num_channels =3D 17, + .oversampling_avail =3D ad7616_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7616_oversampling_avail), + .os_req_reset =3D true, + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7616_info, IIO_AD7606); + int ad7606_reset(struct ad7606_state *st) { if (st->gpio_reset) { @@ -626,128 +775,6 @@ static const struct attribute_group ad7606_attribute_= group_range =3D { .attrs =3D ad7606_attributes_range, }; =20 -static const struct iio_chan_spec ad7605_channels[] =3D { - IIO_CHAN_SOFT_TIMESTAMP(4), - AD7605_CHANNEL(0), - AD7605_CHANNEL(1), - AD7605_CHANNEL(2), - AD7605_CHANNEL(3), -}; - -static const struct iio_chan_spec ad7606_channels_16bit[] =3D { - IIO_CHAN_SOFT_TIMESTAMP(8), - AD7606_CHANNEL(0, 16), - AD7606_CHANNEL(1, 16), - AD7606_CHANNEL(2, 16), - AD7606_CHANNEL(3, 16), - AD7606_CHANNEL(4, 16), - AD7606_CHANNEL(5, 16), - AD7606_CHANNEL(6, 16), - AD7606_CHANNEL(7, 16), -}; - -static const struct iio_chan_spec ad7606_channels_18bit[] =3D { - IIO_CHAN_SOFT_TIMESTAMP(8), - AD7606_CHANNEL(0, 18), - AD7606_CHANNEL(1, 18), - AD7606_CHANNEL(2, 18), - AD7606_CHANNEL(3, 18), - AD7606_CHANNEL(4, 18), - AD7606_CHANNEL(5, 18), - AD7606_CHANNEL(6, 18), - AD7606_CHANNEL(7, 18), -}; - -/* - * The current assumption that this driver makes for AD7616, is that it's - * working in Hardware Mode with Serial, Burst and Sequencer modes activat= ed. - * To activate them, following pins must be pulled high: - * -SER/PAR - * -SEQEN - * And following pins must be pulled low: - * -WR/BURST - * -DB4/SER1W - */ -static const struct iio_chan_spec ad7616_channels[] =3D { - IIO_CHAN_SOFT_TIMESTAMP(16), - AD7606_CHANNEL(0, 16), - AD7606_CHANNEL(1, 16), - AD7606_CHANNEL(2, 16), - AD7606_CHANNEL(3, 16), - AD7606_CHANNEL(4, 16), - AD7606_CHANNEL(5, 16), - AD7606_CHANNEL(6, 16), - AD7606_CHANNEL(7, 16), - AD7606_CHANNEL(8, 16), - AD7606_CHANNEL(9, 16), - AD7606_CHANNEL(10, 16), - AD7606_CHANNEL(11, 16), - AD7606_CHANNEL(12, 16), - AD7606_CHANNEL(13, 16), - AD7606_CHANNEL(14, 16), - AD7606_CHANNEL(15, 16), -}; - -static const struct ad7606_chip_info ad7606_chip_info_tbl[] =3D { - /* More devices added in future */ - [ID_AD7605_4] =3D { - .channels =3D ad7605_channels, - .num_channels =3D 5, - .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, - }, - [ID_AD7606_8] =3D { - .channels =3D ad7606_channels_16bit, - .num_channels =3D 9, - .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, - .oversampling_avail =3D ad7606_oversampling_avail, - .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), - }, - [ID_AD7606_6] =3D { - .channels =3D ad7606_channels_16bit, - .num_channels =3D 7, - .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, - .oversampling_avail =3D ad7606_oversampling_avail, - .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), - }, - [ID_AD7606_4] =3D { - .channels =3D ad7606_channels_16bit, - .num_channels =3D 5, - .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, - .oversampling_avail =3D ad7606_oversampling_avail, - .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), - }, - [ID_AD7606B] =3D { - .channels =3D ad7606_channels_16bit, - .num_channels =3D 9, - .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, - .oversampling_avail =3D ad7606_oversampling_avail, - .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), - }, - [ID_AD7606C_16] =3D { - .channels =3D ad7606_channels_16bit, - .num_channels =3D 9, - .scale_setup_cb =3D ad7606c_16bit_chan_scale_setup, - .oversampling_avail =3D ad7606_oversampling_avail, - .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), - }, - [ID_AD7606C_18] =3D { - .channels =3D ad7606_channels_18bit, - .num_channels =3D 9, - .scale_setup_cb =3D ad7606c_18bit_chan_scale_setup, - .oversampling_avail =3D ad7606_oversampling_avail, - .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), - }, - [ID_AD7616] =3D { - .channels =3D ad7616_channels, - .num_channels =3D 17, - .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, - .oversampling_avail =3D ad7616_oversampling_avail, - .oversampling_num =3D ARRAY_SIZE(ad7616_oversampling_avail), - .os_req_reset =3D true, - .init_delay_ms =3D 15, - }, -}; - static int ad7606_request_gpios(struct ad7606_state *st) { struct device *dev =3D st->dev; @@ -913,7 +940,7 @@ static const struct iio_trigger_ops ad7606_trigger_ops = =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 -static int ad7606_sw_mode_setup(struct iio_dev *indio_dev, unsigned int id) +static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) { struct ad7606_state *st =3D iio_priv(indio_dev); =20 @@ -974,7 +1001,7 @@ static void ad7606_pwm_disable(void *data) } =20 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, - const char *name, unsigned int id, + const struct ad7606_chip_info *chip_info, const struct ad7606_bus_ops *bops) { struct ad7606_state *st; @@ -999,7 +1026,7 @@ int ad7606_probe(struct device *dev, int irq, void __i= omem *base_address, return dev_err_probe(dev, ret, "Failed to enable specified AVcc supply\n"); =20 - st->chip_info =3D &ad7606_chip_info_tbl[id]; + st->chip_info =3D chip_info; =20 if (st->chip_info->oversampling_num) { st->oversampling_avail =3D st->chip_info->oversampling_avail; @@ -1022,7 +1049,7 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, indio_dev->info =3D &ad7606_info_no_os_or_range; } indio_dev->modes =3D INDIO_DIRECT_MODE; - indio_dev->name =3D name; + indio_dev->name =3D chip_info->name; indio_dev->channels =3D st->chip_info->channels; indio_dev->num_channels =3D st->chip_info->num_channels; =20 @@ -1041,7 +1068,7 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, st->write_scale =3D ad7606_write_scale_hw; st->write_os =3D ad7606_write_os_hw; =20 - ret =3D ad7606_sw_mode_setup(indio_dev, id); + ret =3D ad7606_sw_mode_setup(indio_dev); if (ret) return ret; =20 @@ -1098,7 +1125,7 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, NULL, &ad7606_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - name, indio_dev); + chip_info->name, indio_dev); if (ret) return ret; =20 diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 760cf5e2ecb6..d401d3ab37e0 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -69,6 +69,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_stat= e *st, /** * struct ad7606_chip_info - chip specific information * @channels: channel specification + * @name device name * @num_channels: number of channels * @scale_setup_cb: callback to setup the scales for each channel * @oversampling_avail pointer to the array which stores the available @@ -80,6 +81,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_stat= e *st, */ struct ad7606_chip_info { const struct iio_chan_spec *channels; + const char *name; unsigned int num_channels; ad7606_scale_setup_cb_t scale_setup_cb; const unsigned int *oversampling_avail; @@ -199,22 +201,30 @@ struct ad7606_bus_ops { u16 (*rd_wr_cmd)(int addr, char isWriteOp); }; =20 +/** + * struct ad7606_bus_info - agregate ad7606_chip_info and ad7606_bus_ops + * @chip_info entry in the table of chips that describes this device + * @bops bus operations (SPI or parallel) + */ +struct ad7606_bus_info { + const struct ad7606_chip_info *chip_info; + const struct ad7606_bus_ops *bops; +}; + int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, - const char *name, unsigned int id, + const struct ad7606_chip_info *info, const struct ad7606_bus_ops *bops); =20 int ad7606_reset(struct ad7606_state *st); =20 -enum ad7606_supported_device_ids { - ID_AD7605_4, - ID_AD7606_8, - ID_AD7606_6, - ID_AD7606_4, - ID_AD7606B, - ID_AD7606C_16, - ID_AD7606C_18, - ID_AD7616, -}; +extern const struct ad7606_chip_info ad7605_4_info; +extern const struct ad7606_chip_info ad7606_8_info; +extern const struct ad7606_chip_info ad7606_6_info; +extern const struct ad7606_chip_info ad7606_4_info; +extern const struct ad7606_chip_info ad7606b_info; +extern const struct ad7606_chip_info ad7606c_16_info; +extern const struct ad7606_chip_info ad7606c_18_info; +extern const struct ad7606_chip_info ad7616_info; =20 #ifdef CONFIG_PM_SLEEP extern const struct dev_pm_ops ad7606_pm_ops; diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c index d651639c45eb..b87be2f1ca04 100644 --- a/drivers/iio/adc/ad7606_par.c +++ b/drivers/iio/adc/ad7606_par.c @@ -11,6 +11,7 @@ #include #include #include +#include #include =20 #include @@ -89,12 +90,20 @@ static const struct ad7606_bus_ops ad7606_par8_bops =3D= { =20 static int ad7606_par_probe(struct platform_device *pdev) { - const struct platform_device_id *id =3D platform_get_device_id(pdev); + const struct ad7606_chip_info *chip_info; + const struct platform_device_id *id; struct resource *res; void __iomem *addr; resource_size_t remap_size; int irq; =20 + if (dev_fwnode(&pdev->dev)) { + chip_info =3D device_get_match_data(&pdev->dev); + } else { + id =3D platform_get_device_id(pdev); + chip_info =3D (const struct ad7606_chip_info *)id->driver_data; + } + irq =3D platform_get_irq(pdev, 0); if (irq < 0) return irq; @@ -105,26 +114,25 @@ static int ad7606_par_probe(struct platform_device *p= dev) =20 remap_size =3D resource_size(res); =20 - return ad7606_probe(&pdev->dev, irq, addr, - id->name, id->driver_data, + return ad7606_probe(&pdev->dev, irq, addr, chip_info, remap_size > 1 ? &ad7606_par16_bops : &ad7606_par8_bops); } =20 static const struct platform_device_id ad7606_driver_ids[] =3D { - { .name =3D "ad7605-4", .driver_data =3D ID_AD7605_4, }, - { .name =3D "ad7606-4", .driver_data =3D ID_AD7606_4, }, - { .name =3D "ad7606-6", .driver_data =3D ID_AD7606_6, }, - { .name =3D "ad7606-8", .driver_data =3D ID_AD7606_8, }, + { .name =3D "ad7605-4", .driver_data =3D (kernel_ulong_t)&ad7605_4_info, = }, + { .name =3D "ad7606-4", .driver_data =3D (kernel_ulong_t)&ad7606_4_info, = }, + { .name =3D "ad7606-6", .driver_data =3D (kernel_ulong_t)&ad7606_6_info, = }, + { .name =3D "ad7606-8", .driver_data =3D (kernel_ulong_t)&ad7606_8_info, = }, { } }; MODULE_DEVICE_TABLE(platform, ad7606_driver_ids); =20 static const struct of_device_id ad7606_of_match[] =3D { - { .compatible =3D "adi,ad7605-4" }, - { .compatible =3D "adi,ad7606-4" }, - { .compatible =3D "adi,ad7606-6" }, - { .compatible =3D "adi,ad7606-8" }, + { .compatible =3D "adi,ad7605-4", .data =3D &ad7605_4_info }, + { .compatible =3D "adi,ad7606-4", .data =3D &ad7606_4_info }, + { .compatible =3D "adi,ad7606-6", .data =3D &ad7606_6_info }, + { .compatible =3D "adi,ad7606-8", .data =3D &ad7606_8_info }, { } }; MODULE_DEVICE_TABLE(of, ad7606_of_match); diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index d12e55123888..44c6031e9e9a 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -334,7 +334,7 @@ static const struct ad7606_bus_ops ad7616_spi_bops =3D { .sw_mode_config =3D ad7616_sw_mode_config, }; =20 -static const struct ad7606_bus_ops ad7606B_spi_bops =3D { +static const struct ad7606_bus_ops ad7606b_spi_bops =3D { .read_block =3D ad7606_spi_read_block, .reg_read =3D ad7606_spi_reg_read, .reg_write =3D ad7606_spi_reg_write, @@ -352,54 +352,76 @@ static const struct ad7606_bus_ops ad7606c_18_spi_bop= s =3D { .sw_mode_config =3D ad7606c_18_sw_mode_config, }; =20 +static const struct ad7606_bus_info ad7605_4_bus_info =3D { + .chip_info =3D &ad7605_4_info, + .bops =3D &ad7606_spi_bops, +}; + +static const struct ad7606_bus_info ad7606_8_bus_info =3D { + .chip_info =3D &ad7606_8_info, + .bops =3D &ad7606_spi_bops, +}; + +static const struct ad7606_bus_info ad7606_6_bus_info =3D { + .chip_info =3D &ad7606_6_info, + .bops =3D &ad7606_spi_bops, +}; + +static const struct ad7606_bus_info ad7606_4_bus_info =3D { + .chip_info =3D &ad7606_4_info, + .bops =3D &ad7606_spi_bops, +}; + +static const struct ad7606_bus_info ad7606b_bus_info =3D { + .chip_info =3D &ad7606b_info, + .bops =3D &ad7606b_spi_bops, +}; + +static const struct ad7606_bus_info ad7606c_16_bus_info =3D { + .chip_info =3D &ad7606c_16_info, + .bops =3D &ad7606b_spi_bops, +}; + +static const struct ad7606_bus_info ad7606c_18_bus_info =3D { + .chip_info =3D &ad7606c_18_info, + .bops =3D &ad7606c_18_spi_bops, +}; + +static const struct ad7606_bus_info ad7616_bus_info =3D { + .chip_info =3D &ad7616_info, + .bops =3D &ad7616_spi_bops, +}; + static int ad7606_spi_probe(struct spi_device *spi) { - const struct spi_device_id *id =3D spi_get_device_id(spi); - const struct ad7606_bus_ops *bops; - - switch (id->driver_data) { - case ID_AD7616: - bops =3D &ad7616_spi_bops; - break; - case ID_AD7606B: - case ID_AD7606C_16: - bops =3D &ad7606B_spi_bops; - break; - case ID_AD7606C_18: - bops =3D &ad7606c_18_spi_bops; - break; - default: - bops =3D &ad7606_spi_bops; - break; - } + const struct ad7606_bus_info *bus_info =3D spi_get_device_match_data(spi); =20 return ad7606_probe(&spi->dev, spi->irq, NULL, - id->name, id->driver_data, - bops); + bus_info->chip_info, bus_info->bops); } =20 static const struct spi_device_id ad7606_id_table[] =3D { - { "ad7605-4", ID_AD7605_4 }, - { "ad7606-4", ID_AD7606_4 }, - { "ad7606-6", ID_AD7606_6 }, - { "ad7606-8", ID_AD7606_8 }, - { "ad7606b", ID_AD7606B }, - { "ad7606c-16", ID_AD7606C_16 }, - { "ad7606c-18", ID_AD7606C_18 }, - { "ad7616", ID_AD7616 }, + { "ad7605-4", (kernel_ulong_t)&ad7605_4_bus_info }, + { "ad7606-4", (kernel_ulong_t)&ad7606_4_bus_info }, + { "ad7606-6", (kernel_ulong_t)&ad7606_6_bus_info }, + { "ad7606-8", (kernel_ulong_t)&ad7606_8_bus_info }, + { "ad7606b", (kernel_ulong_t)&ad7606b_bus_info }, + { "ad7606c-16", (kernel_ulong_t)&ad7606c_16_bus_info }, + { "ad7606c-18", (kernel_ulong_t)&ad7606c_18_bus_info }, + { "ad7616", (kernel_ulong_t)&ad7616_bus_info }, { } }; MODULE_DEVICE_TABLE(spi, ad7606_id_table); =20 static const struct of_device_id ad7606_of_match[] =3D { - { .compatible =3D "adi,ad7605-4" }, - { .compatible =3D "adi,ad7606-4" }, - { .compatible =3D "adi,ad7606-6" }, - { .compatible =3D "adi,ad7606-8" }, - { .compatible =3D "adi,ad7606b" }, - { .compatible =3D "adi,ad7606c-16" }, - { .compatible =3D "adi,ad7606c-18" }, - { .compatible =3D "adi,ad7616" }, + { .compatible =3D "adi,ad7605-4", .data =3D &ad7605_4_bus_info }, + { .compatible =3D "adi,ad7606-4", .data =3D &ad7606_4_bus_info }, + { .compatible =3D "adi,ad7606-6", .data =3D &ad7606_6_bus_info }, + { .compatible =3D "adi,ad7606-8", .data =3D &ad7606_8_bus_info }, + { .compatible =3D "adi,ad7606b", .data =3D &ad7606b_bus_info }, + { .compatible =3D "adi,ad7606c-16", .data =3D &ad7606c_16_bus_info }, + { .compatible =3D "adi,ad7606c-18", .data =3D &ad7606c_18_bus_info }, + { .compatible =3D "adi,ad7616", .data =3D &ad7616_bus_info }, { } }; MODULE_DEVICE_TABLE(of, ad7606_of_match); --=20 2.34.1 From nobody Wed Nov 27 14:33:35 2024 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74C9F190662 for ; Wed, 9 Oct 2024 09:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465595; cv=none; b=dYuV7kUUDixR/9R6EyJ5fB+PT7f1ODdYnfhWo0KYdYUTu0WTpxVHzc+m/pG6XNzMVTKBWSkSgivcV/wADVPg9AtE5odLN4ZXZVba4RQ3SySchPAI/g7xjxtlQatrP+ayw/MnvQPCS8cG2yAqQsORpbCE5yZiK3bY1/rwT6Q9+/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465595; c=relaxed/simple; bh=LedlEdJCC/LMY2h2d3ZMK/XTHFaSBO06zmv+zukeWhM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=COx84WfM7DdFSlBr9EGrC6T1HnjolUSPy2M/hoxbQi5xVyTkgJqMLVz3C2XSaKqiDMeCOUvf6rqeGam7eSXhPojZoFTiPiu8jU1P+9hPdimTERb0XyBu6T1dDAh8in8w5qx7CptjHcICS/42VG+iNpGU64afwoZhY51xuRfwfx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=2dT7ax7R; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="2dT7ax7R" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5398df2c871so7201338e87.1 for ; Wed, 09 Oct 2024 02:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728465588; x=1729070388; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9sxBsvfyhV52GErg93d3TwpYRkYKpCLqLg+LjkHg/oE=; b=2dT7ax7REX8q7RSdAJNI/Ca3KxbopmB68elYRlv9A8ZCMTglcjPonJSPuGTWlqtIT6 Dzus5GDU0Jj82orq1qQ+EQ80rYCASZwh9AaJNPmEYI6g3OrUlG8XmjysfrI3nc9meMld I7akCOliqDCyjC1ri3qOyvL8ysgsRDtpfzmaoVWXG8Wza71y25YAJYZ33/h+ZYKrnx0x dmLGC1eJz2OSZoQk7QP16/BrZa3pexzfWR+TMOgzjxvYGPzsybDYkwEIbeeqaDcOT6ba 4aN8Dd68MVhyDlIe/tw4OVUFtf8x4tSLS31lvjJMnz53kQI1Tf9fFifjftJUb19LMJhI 20ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728465588; x=1729070388; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9sxBsvfyhV52GErg93d3TwpYRkYKpCLqLg+LjkHg/oE=; b=mCeR7htflatOYZ7s+a2ATeDKVzUfidztvcEG0HIPk+acS8y2oqk2FWf/2Hp2LjOQzQ ZSnk8lMCncDUUiI8mfN4G/fsboUx6sBru8i0jyNrN/J/2ycvKmW5nqYwR3/Yxo48JURR iphtbS/w5ToqSM+Hj3WaZWJF8ol9AiLgK7cFdp2HNRQ+NnBtOzwkUH0bxCQnwtDwRcpM YxdxTSSrQEP7CS67idP7KUFWutcI2vEy5tOzkEltS7zOuNs3Gk+T1ykyRfTgfzzZppkK Cpf0IjIQ2SApg/yvxCw26omUAK0PddmCoH48K3b8EpznFuHbUB+CmU1QjqGX8twMbPuL waDg== X-Forwarded-Encrypted: i=1; AJvYcCU3qCJWFiS/TC5YGTeZmvB09UA1YcaUfq7zdFlDJw93gydPCs404lDe2ij4VL5A0eX1h3kxocEKKLn4VMs=@vger.kernel.org X-Gm-Message-State: AOJu0YysXm9y4CQZLWhZi/avfIH6q4Tt6ZRp16yvgHCewOihY7vAzKmE uKLQm8JGhW8dqGczOqlMQ+a7TEK6ajGC3DpAH+PpsIlkAIxj2DWxbUJnlClpiWQ= X-Google-Smtp-Source: AGHT+IHYQG7GKXk+n7qR/3btWFErN/3GY0AZY2wR/wdZlZGQszvZ7tzxAcVmDX3/PqsYl/RTyG0tUA== X-Received: by 2002:a05:6512:3c98:b0:52c:cc2e:1c45 with SMTP id 2adb3069b0e04-539c4896e53mr1055046e87.15.1728465587930; Wed, 09 Oct 2024 02:19:47 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b1207sm13892765e9.31.2024.10.09.02.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:19:46 -0700 (PDT) From: Guillaume Stols Date: Wed, 09 Oct 2024 09:19:37 +0000 Subject: [PATCH v4 6/8] iio: adc: ad7606: Introduce num_adc_channels Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-ad7606_add_iio_backend_support-v4-6-6971a8c0f1d5@baylibre.com> References: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> In-Reply-To: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, aardelean@baylibre.com, dlechner@baylibre.com, jstephan@baylibre.com, Jonathan Cameron , Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728465581; l=4625; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=LedlEdJCC/LMY2h2d3ZMK/XTHFaSBO06zmv+zukeWhM=; b=AaS7KusQPatp8MX1pH5ToR+la3iwSdh6zB9K40z6KABcG3HpnptxYWGhiGu6BPFHN699K94Ky VYbdSYgtQV1CniJYGqxgNmLQyY9MBriUVtggF+Z40PZd+VxxD2jQDhZ X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= This variable determines how many hardware channels has the chip, oppositely to the num_channels that can contain more channels, e.g a timestamp channel in our case. Introducing this variable avoids decreasing the former num_channels variable when reading the ADC's channels, and clarifies a bit the code. Signed-off-by: Guillaume Stols Reviewed-by: Nuno Sa --- drivers/iio/adc/ad7606.c | 10 +++++++++- drivers/iio/adc/ad7606.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index dfbdea8c28ba..ec902b268388 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -150,6 +150,7 @@ static int ad7606_16bit_chan_scale_setup(struct ad7606_= state *st, const struct ad7606_chip_info ad7605_4_info =3D { .channels =3D ad7605_channels, .name =3D "ad7605-4", + .num_adc_channels =3D 4, .num_channels =3D 5, .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, }; @@ -158,6 +159,7 @@ EXPORT_SYMBOL_NS_GPL(ad7605_4_info, IIO_AD7606); const struct ad7606_chip_info ad7606_8_info =3D { .channels =3D ad7606_channels_16bit, .name =3D "ad7606-8", + .num_adc_channels =3D 8, .num_channels =3D 9, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), @@ -168,6 +170,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_8_info, IIO_AD7606); const struct ad7606_chip_info ad7606_6_info =3D { .channels =3D ad7606_channels_16bit, .name =3D "ad7606-6", + .num_adc_channels =3D 6, .num_channels =3D 7, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), @@ -178,6 +181,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_6_info, IIO_AD7606); const struct ad7606_chip_info ad7606_4_info =3D { .channels =3D ad7606_channels_16bit, .name =3D "ad7606-4", + .num_adc_channels =3D 4, .num_channels =3D 5, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), @@ -188,6 +192,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606); const struct ad7606_chip_info ad7606b_info =3D { .channels =3D ad7606_channels_16bit, .name =3D "ad7606b", + .num_adc_channels =3D 8, .num_channels =3D 9, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), @@ -198,6 +203,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606b_info, IIO_AD7606); const struct ad7606_chip_info ad7606c_16_info =3D { .channels =3D ad7606_channels_16bit, .name =3D "ad7606c16", + .num_adc_channels =3D 8, .num_channels =3D 9, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), @@ -208,6 +214,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606); const struct ad7606_chip_info ad7606c_18_info =3D { .channels =3D ad7606_channels_18bit, .name =3D "ad7606c18", + .num_adc_channels =3D 8, .num_channels =3D 9, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), @@ -219,6 +226,7 @@ const struct ad7606_chip_info ad7616_info =3D { .channels =3D ad7616_channels, .init_delay_ms =3D 15, .name =3D "ad7616", + .num_adc_channels =3D 16, .num_channels =3D 17, .oversampling_avail =3D ad7616_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7616_oversampling_avail), @@ -528,7 +536,7 @@ static int ad7606_set_sampling_freq(struct ad7606_state= *st, unsigned long freq) =20 static int ad7606_read_samples(struct ad7606_state *st) { - unsigned int num =3D st->chip_info->num_channels - 1; + unsigned int num =3D st->chip_info->num_adc_channels; =20 return st->bops->read_block(st->dev, num, &st->data); } diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index d401d3ab37e0..b26a11b2eba1 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -71,6 +71,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_stat= e *st, * @channels: channel specification * @name device name * @num_channels: number of channels + * @num_adc_channels the number of channels the ADC actually inputs. * @scale_setup_cb: callback to setup the scales for each channel * @oversampling_avail pointer to the array which stores the available * oversampling ratios. @@ -82,6 +83,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_stat= e *st, struct ad7606_chip_info { const struct iio_chan_spec *channels; const char *name; + unsigned int num_adc_channels; unsigned int num_channels; ad7606_scale_setup_cb_t scale_setup_cb; const unsigned int *oversampling_avail; --=20 2.34.1 From nobody Wed Nov 27 14:33:35 2024 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F465191494 for ; Wed, 9 Oct 2024 09:19:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465596; cv=none; b=n1njZkutnkq8AAFuEcxs4qs8yHQDb/0YKyB+YYz8iY2qUjm0ggU3b7iefLybDxLIpBu09PB68yY7HE7N1ZNpSwoSjEyHnPxWdkbUmqla+bc2rDfL2eAkWB+62jN1joxMnY6j3wg5N/zq5rSMd2OMQtMhFP7GP+RigAnqsPglgp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465596; c=relaxed/simple; bh=NHitG6+12N5Z2s64JBsIdm/tUI87xQeWy2HBHc7XLTI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QANYWXY/ekDzKa3lHcdWukUnbdkF9cctYEXqldfRCOASq3C+6jS+DwIrBTisA6jdyQldxIzFSBHh4I/bWzYZ/QAv3SBp9Y5M/b9FzZVqai2evKftK8NlxRnGFhIzwbz6zKUQzXTlmCAgHLSy6JJgh0kElYsMKe2821nikK2j0n0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=eJgDuU0j; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="eJgDuU0j" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-430ee5c9570so6006575e9.3 for ; Wed, 09 Oct 2024 02:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728465589; x=1729070389; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FTnhON9Nqit0J1dmOWBLxgrxJYKl6dl1rApggpoCod0=; b=eJgDuU0jNwt/EfYxNQZyrX8FXbg715BZP4o3035lDpu88CuI4geL6V8LcQB2kbNb60 ax1NkqG1YNtf5hZo722Z79uOMqZZX1GDuMTTKqH6ec1MiwVlHu3uFjKoT8S0cGldZ0CT RMRyC2ht4XQE+AR8/YIysl8gv5AtUpGrqiyq3FeFiycV74WryMweRNDQ7AD7da3+geR6 rkdqXLh+qcNjJ4uo+sFTeKQbl1bDqJ3taMJGm0RQAzhHbsm2fBfqOPsuCEzRW7jd4kDx tFV154XsFOq5808lvYJXtc0lZbAJK20ss0GSsmTBP/ogk0auqTbUzCsZYCChifErZXQs /fbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728465589; x=1729070389; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FTnhON9Nqit0J1dmOWBLxgrxJYKl6dl1rApggpoCod0=; b=ratwm5TOFx+RjgNST7ZnaXiKZsRr6wh/u8aa8dDTjX2KaKkqEWTv8ITymkyyAQBGS7 ZruYBHFg4q+CSr4T9RuyGxmEEwoeg/jF/ByErVNn3kYGvwshVENrNrGBRRr/wWKNvjKc NhB2FsUeDSnz1CGtJwyvnE6cGyFmxtJQLQxG5KYX9siQ/ixu8DGWX8NdvqMotJBygSPZ pGTOYpdnd07P0I4roQXnPvRr09Vu2uJ1B7x+RfUyvGa/vHp0SnqPCeFv70qwDAZDwqEb a5T6YcuVovZBLIYZr0baR1fgtMgbLU5NdwsrNljDZEuhznXNy821Hq9QHKJPmFT1t7/l n8tg== X-Forwarded-Encrypted: i=1; AJvYcCVsfj8NEMxCACMNQ7LHMaLiv6Lz7iKe4akB5/TU7pIr1cHmAwTjVQGa6FLAzaQ6RBBr70sV3QrheDMgk3Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4u4URFczHHiErELKW60cn4Qzp8XjHiZ1F4Gtm9ttXEhgT/oFG tTMvfaldlfNIYaNTZiiUJt7q+WuH9+iyfxLtQk4mtRL595LcA3jrl+uUzyhO/eE= X-Google-Smtp-Source: AGHT+IHJZAL6YVmFWdbTiVAVX91VxiT1Sc+MBFBjvbJQa4MCNbDZGpx4KHOKQI4mPUgiB07yubhZDA== X-Received: by 2002:a05:600c:1c14:b0:42c:bae0:f05f with SMTP id 5b1f17b1804b1-430ccf30d99mr17587545e9.13.1728465588735; Wed, 09 Oct 2024 02:19:48 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b1207sm13892765e9.31.2024.10.09.02.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:19:48 -0700 (PDT) From: Guillaume Stols Date: Wed, 09 Oct 2024 09:19:38 +0000 Subject: [PATCH v4 7/8] iio: adc: ad7606: Add iio-backend support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-ad7606_add_iio_backend_support-v4-7-6971a8c0f1d5@baylibre.com> References: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> In-Reply-To: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, aardelean@baylibre.com, dlechner@baylibre.com, jstephan@baylibre.com, Jonathan Cameron , Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728465581; l=16974; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=NHitG6+12N5Z2s64JBsIdm/tUI87xQeWy2HBHc7XLTI=; b=pF6urXmUs0kKQ0u0tckrLvOYQCm2mcEHw0e/+3Qz0HLdZ8RPdc7f/Eb8G2UWasHayADnMEbiK jvdwwp3RJWHCrBzQPaio78R9QkgvaWWqbP+Y08TucNYI8ADYreyhKEL X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= - Basic support for iio backend. - Supports IIO_CHAN_INFO_SAMP_FREQ R/W. - Only hardware mode is available, and that IIO_CHAN_INFO_RAW is not supported if iio-backend mode is selected. Signed-off-by: Guillaume Stols --- drivers/iio/adc/Kconfig | 2 + drivers/iio/adc/ad7606.c | 156 ++++++++++++++++++++++++++++++++++-----= ---- drivers/iio/adc/ad7606.h | 15 +++++ drivers/iio/adc/ad7606_par.c | 93 +++++++++++++++++++++++++- 4 files changed, 234 insertions(+), 32 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 85b82a708c36..9f7e9fc4b1fe 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -224,9 +224,11 @@ config AD7606_IFACE_PARALLEL tristate "Analog Devices AD7606 ADC driver with parallel interface suppor= t" depends on HAS_IOPORT select AD7606 + select IIO_BACKEND help Say yes here to build parallel interface support for Analog Devices: ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC). + It also support iio_backended devices for AD7606B. =20 To compile this driver as a module, choose M here: the module will be called ad7606_par. diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index ec902b268388..1313b5cbb0aa 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -21,6 +21,7 @@ #include #include =20 +#include #include #include #include @@ -191,6 +192,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606); =20 const struct ad7606_chip_info ad7606b_info =3D { .channels =3D ad7606_channels_16bit, + .max_samplerate =3D 800 * KILO, .name =3D "ad7606b", .num_adc_channels =3D 8, .num_channels =3D 9, @@ -496,6 +498,20 @@ static int ad7606_pwm_set_low(struct ad7606_state *st) return ret; } =20 +static int ad7606_pwm_set_swing(struct ad7606_state *st) +{ + struct pwm_state cnvst_pwm_state; + + if (!st->cnvst_pwm) + return -EINVAL; + + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); + cnvst_pwm_state.enabled =3D true; + cnvst_pwm_state.duty_cycle =3D cnvst_pwm_state.period / 2; + + return pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); +} + static bool ad7606_pwm_is_swinging(struct ad7606_state *st) { struct pwm_state cnvst_pwm_state; @@ -580,11 +596,22 @@ static int ad7606_scan_direct(struct iio_dev *indio_d= ev, unsigned int ch, if (ret < 0) return ret; } - ret =3D wait_for_completion_timeout(&st->completion, - msecs_to_jiffies(1000)); - if (!ret) { - ret =3D -ETIMEDOUT; - goto error_ret; + + /* + * If no backend, wait for the interruption on busy pin, otherwise just a= dd + * a delay to leave time for the data to be available. For now, the latter + * will not happen because IIO_CHAN_INFO_RAW is not supported for the bac= kend. + * TODO: Add support for reading a single value when the backend is used. + */ + if (!st->back) { + ret =3D wait_for_completion_timeout(&st->completion, + msecs_to_jiffies(1000)); + if (!ret) { + ret =3D -ETIMEDOUT; + goto error_ret; + } + } else { + fsleep(1); } =20 ret =3D ad7606_read_samples(st); @@ -624,6 +651,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, int ret, ch =3D 0; struct ad7606_state *st =3D iio_priv(indio_dev); struct ad7606_chan_scale *cs; + struct pwm_state cnvst_pwm_state; =20 switch (m) { case IIO_CHAN_INFO_RAW: @@ -644,6 +672,14 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *val =3D st->oversampling; return IIO_VAL_INT; + case IIO_CHAN_INFO_SAMP_FREQ: + /* + * TODO: return the real frequency intead of the requested one once + * pwm_get_state_hw comes upstream. + */ + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); + *val =3D DIV_ROUND_CLOSEST_ULL(NSEC_PER_SEC, cnvst_pwm_state.period); + return IIO_VAL_INT; } return -EINVAL; } @@ -736,6 +772,10 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, return ret; =20 return 0; + case IIO_CHAN_INFO_SAMP_FREQ: + if (val < 0 && val2 !=3D 0) + return -EINVAL; + return ad7606_set_sampling_freq(st, val); default: return -EINVAL; } @@ -905,14 +945,50 @@ static int ad7606_read_avail(struct iio_dev *indio_de= v, return -EINVAL; } =20 +static int ad7606_pwm_buffer_postenable(struct iio_dev *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + return ad7606_pwm_set_swing(st); +} + +static int ad7606_pwm_buffer_predisable(struct iio_dev *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + return ad7606_pwm_set_low(st); +} + +static int ad7606_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *scan_mask) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + /* + * The update scan mode is only for iio backend compatible drivers. + * If the specific update_scan_mode is not defined in the bus ops, + * just do nothing and return 0. + */ + if (!st->bops->update_scan_mode) + return 0; + + return st->bops->update_scan_mode(indio_dev, scan_mask); +} + static const struct iio_buffer_setup_ops ad7606_buffer_ops =3D { .postenable =3D &ad7606_buffer_postenable, .predisable =3D &ad7606_buffer_predisable, }; =20 +static const struct iio_buffer_setup_ops ad7606_pwm_buffer_ops =3D { + .postenable =3D &ad7606_pwm_buffer_postenable, + .predisable =3D &ad7606_pwm_buffer_predisable, +}; + static const struct iio_info ad7606_info_no_os_or_range =3D { .read_raw =3D &ad7606_read_raw, .validate_trigger =3D &ad7606_validate_trigger, + .update_scan_mode =3D &ad7606_update_scan_mode, }; =20 static const struct iio_info ad7606_info_os_and_range =3D { @@ -920,6 +996,7 @@ static const struct iio_info ad7606_info_os_and_range = =3D { .write_raw =3D &ad7606_write_raw, .attrs =3D &ad7606_attribute_group_os_and_range, .validate_trigger =3D &ad7606_validate_trigger, + .update_scan_mode =3D &ad7606_update_scan_mode, }; =20 static const struct iio_info ad7606_info_sw_mode =3D { @@ -928,6 +1005,7 @@ static const struct iio_info ad7606_info_sw_mode =3D { .read_avail =3D &ad7606_read_avail, .debugfs_reg_access =3D &ad7606_reg_access, .validate_trigger =3D &ad7606_validate_trigger, + .update_scan_mode =3D &ad7606_update_scan_mode, }; =20 static const struct iio_info ad7606_info_os =3D { @@ -935,6 +1013,7 @@ static const struct iio_info ad7606_info_os =3D { .write_raw =3D &ad7606_write_raw, .attrs =3D &ad7606_attribute_group_os, .validate_trigger =3D &ad7606_validate_trigger, + .update_scan_mode =3D &ad7606_update_scan_mode, }; =20 static const struct iio_info ad7606_info_range =3D { @@ -942,6 +1021,7 @@ static const struct iio_info ad7606_info_range =3D { .write_raw =3D &ad7606_write_raw, .attrs =3D &ad7606_attribute_group_range, .validate_trigger =3D &ad7606_validate_trigger, + .update_scan_mode =3D &ad7606_update_scan_mode, }; =20 static const struct iio_trigger_ops ad7606_trigger_ops =3D { @@ -1061,8 +1141,6 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, indio_dev->channels =3D st->chip_info->channels; indio_dev->num_channels =3D st->chip_info->num_channels; =20 - init_completion(&st->completion); - ret =3D ad7606_reset(st); if (ret) dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n"); @@ -1109,34 +1187,50 @@ int ad7606_probe(struct device *dev, int irq, void = __iomem *base_address, if (ret) return ret; } - st->trig =3D devm_iio_trigger_alloc(dev, "%s-dev%d", - indio_dev->name, - iio_device_id(indio_dev)); - if (!st->trig) - return -ENOMEM; =20 - st->trig->ops =3D &ad7606_trigger_ops; - iio_trigger_set_drvdata(st->trig, indio_dev); - ret =3D devm_iio_trigger_register(dev, st->trig); - if (ret) - return ret; + if (st->bops->iio_backend_config) { + /* + * If there is a backend, the PWM should not overpass the maximum sampli= ng + * frequency the chip supports. + */ + ret =3D ad7606_set_sampling_freq(st, + chip_info->max_samplerate ? : 2 * KILO); + if (ret) + return ret; =20 - indio_dev->trig =3D iio_trigger_get(st->trig); - ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, - &iio_pollfunc_store_time, - &ad7606_trigger_handler, - &ad7606_buffer_ops); - if (ret) - return ret; + ret =3D st->bops->iio_backend_config(dev, indio_dev); + if (ret) + return ret; =20 - ret =3D devm_request_threaded_irq(dev, irq, - NULL, - &ad7606_interrupt, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - chip_info->name, indio_dev); - if (ret) - return ret; + indio_dev->setup_ops =3D &ad7606_pwm_buffer_ops; + } else { + init_completion(&st->completion); + st->trig =3D devm_iio_trigger_alloc(dev, "%s-dev%d", + indio_dev->name, + iio_device_id(indio_dev)); + if (!st->trig) + return -ENOMEM; + + st->trig->ops =3D &ad7606_trigger_ops; + iio_trigger_set_drvdata(st->trig, indio_dev); + ret =3D devm_iio_trigger_register(dev, st->trig); + if (ret) + return ret; + + indio_dev->trig =3D iio_trigger_get(st->trig); + ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, + &iio_pollfunc_store_time, + &ad7606_trigger_handler, + &ad7606_buffer_ops); + if (ret) + return ret; =20 + ret =3D devm_request_threaded_irq(dev, irq, NULL, &ad7606_interrupt, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + chip_info->name, indio_dev); + if (ret) + return ret; + } return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(ad7606_probe, IIO_AD7606); diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index b26a11b2eba1..2c629a15cc33 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -61,6 +61,12 @@ =20 #define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) =20 +#define AD7606_BI_CHANNEL(num) \ + AD760X_CHANNEL(num, 0, \ + BIT(IIO_CHAN_INFO_SCALE), \ + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 16) + struct ad7606_state; =20 typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st, @@ -69,6 +75,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_stat= e *st, /** * struct ad7606_chip_info - chip specific information * @channels: channel specification + * @max_samplerate: maximum supported samplerate * @name device name * @num_channels: number of channels * @num_adc_channels the number of channels the ADC actually inputs. @@ -82,6 +89,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_stat= e *st, */ struct ad7606_chip_info { const struct iio_chan_spec *channels; + unsigned int max_samplerate; const char *name; unsigned int num_adc_channels; unsigned int num_channels; @@ -152,6 +160,7 @@ struct ad7606_state { bool sw_mode_en; const unsigned int *oversampling_avail; unsigned int num_os_ratios; + struct iio_backend *back; int (*write_scale)(struct iio_dev *indio_dev, int ch, int val); int (*write_os)(struct iio_dev *indio_dev, int val); =20 @@ -180,16 +189,21 @@ struct ad7606_state { =20 /** * struct ad7606_bus_ops - driver bus operations + * @iio_backend_config function pointer for configuring the iio_backend for + * the compatibles that use it * @read_block function pointer for reading blocks of data * @sw_mode_config: pointer to a function which configured the device * for software mode * @reg_read function pointer for reading spi register * @reg_write function pointer for writing spi register * @write_mask function pointer for write spi register with mask + * @update_scan_mode function pointer for handling the calls to iio_info's= update_scan + * mode when enabling/disabling channels. * @rd_wr_cmd pointer to the function which calculates the spi address */ struct ad7606_bus_ops { /* more methods added in future? */ + int (*iio_backend_config)(struct device *dev, struct iio_dev *indio_dev); int (*read_block)(struct device *dev, int num, void *data); int (*sw_mode_config)(struct iio_dev *indio_dev); int (*reg_read)(struct ad7606_state *st, unsigned int addr); @@ -200,6 +214,7 @@ struct ad7606_bus_ops { unsigned int addr, unsigned long mask, unsigned int val); + int (*update_scan_mode)(struct iio_dev *indio_dev, const unsigned long *s= can_mask); u16 (*rd_wr_cmd)(int addr, char isWriteOp); }; =20 diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c index b87be2f1ca04..e0de8dc5f731 100644 --- a/drivers/iio/adc/ad7606_par.c +++ b/drivers/iio/adc/ad7606_par.c @@ -2,7 +2,8 @@ /* * AD7606 Parallel Interface ADC driver * - * Copyright 2011 Analog Devices Inc. + * Copyright 2011 - 2024 Analog Devices Inc. + * Copyright 2024 BayLibre SAS. */ =20 #include @@ -14,9 +15,82 @@ #include #include =20 +#include #include + #include "ad7606.h" =20 +static const struct iio_chan_spec ad7606b_bi_channels[] =3D { + AD7606_BI_CHANNEL(0), + AD7606_BI_CHANNEL(1), + AD7606_BI_CHANNEL(2), + AD7606_BI_CHANNEL(3), + AD7606_BI_CHANNEL(4), + AD7606_BI_CHANNEL(5), + AD7606_BI_CHANNEL(6), + AD7606_BI_CHANNEL(7), +}; + +static int ad7606_bi_update_scan_mode(struct iio_dev *indio_dev, const uns= igned long *scan_mask) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + unsigned int c, ret; + + for (c =3D 0; c < indio_dev->num_channels; c++) { + if (test_bit(c, scan_mask)) + ret =3D iio_backend_chan_enable(st->back, c); + else + ret =3D iio_backend_chan_disable(st->back, c); + if (ret) + return ret; + } + + return 0; +} + +static int ad7606_bi_setup_iio_backend(struct device *dev, struct iio_dev = *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + unsigned int ret, c; + struct iio_backend_data_fmt data =3D { + .sign_extend =3D true, + .enable =3D true, + }; + + st->back =3D devm_iio_backend_get(dev, NULL); + if (IS_ERR(st->back)) + return PTR_ERR(st->back); + + /* If the device is iio_backend powered the PWM is mandatory */ + if (!st->cnvst_pwm) + return dev_err_probe(st->dev, -EINVAL, + "A PWM is mandatory when using backend.\n"); + + ret =3D devm_iio_backend_request_buffer(dev, st->back, indio_dev); + if (ret) + return ret; + + ret =3D devm_iio_backend_enable(dev, st->back); + if (ret) + return ret; + + for (c =3D 0; c < indio_dev->num_channels; c++) { + ret =3D iio_backend_data_format_set(st->back, c, &data); + if (ret) + return ret; + } + + indio_dev->channels =3D ad7606b_bi_channels; + indio_dev->num_channels =3D 8; + + return 0; +} + +static const struct ad7606_bus_ops ad7606_bi_bops =3D { + .iio_backend_config =3D ad7606_bi_setup_iio_backend, + .update_scan_mode =3D ad7606_bi_update_scan_mode, +}; + static int ad7606_par16_read_block(struct device *dev, int count, void *buf) { @@ -96,9 +170,23 @@ static int ad7606_par_probe(struct platform_device *pde= v) void __iomem *addr; resource_size_t remap_size; int irq; + struct iio_backend *back; =20 + /* + * If a firmware node is available (ACPI or DT), platform_device_id is nu= ll + * and we must use get_match_data. + */ if (dev_fwnode(&pdev->dev)) { chip_info =3D device_get_match_data(&pdev->dev); + back =3D devm_iio_backend_get(&pdev->dev, NULL); + if (!IS_ERR(back)) + /* + * If a backend is available ,call the core probe with backend + * bops, otherwise use the former bops. + */ + return ad7606_probe(&pdev->dev, 0, NULL, + chip_info, + &ad7606_bi_bops); } else { id =3D platform_get_device_id(pdev); chip_info =3D (const struct ad7606_chip_info *)id->driver_data; @@ -124,6 +212,7 @@ static const struct platform_device_id ad7606_driver_id= s[] =3D { { .name =3D "ad7606-4", .driver_data =3D (kernel_ulong_t)&ad7606_4_info, = }, { .name =3D "ad7606-6", .driver_data =3D (kernel_ulong_t)&ad7606_6_info, = }, { .name =3D "ad7606-8", .driver_data =3D (kernel_ulong_t)&ad7606_8_info, = }, + { .name =3D "ad7606b", .driver_data =3D (kernel_ulong_t)&ad7606b_info, }, { } }; MODULE_DEVICE_TABLE(platform, ad7606_driver_ids); @@ -133,6 +222,7 @@ static const struct of_device_id ad7606_of_match[] =3D { { .compatible =3D "adi,ad7606-4", .data =3D &ad7606_4_info }, { .compatible =3D "adi,ad7606-6", .data =3D &ad7606_6_info }, { .compatible =3D "adi,ad7606-8", .data =3D &ad7606_8_info }, + { .compatible =3D "adi,ad7606b", .data =3D &ad7606b_info }, { } }; MODULE_DEVICE_TABLE(of, ad7606_of_match); @@ -152,3 +242,4 @@ MODULE_AUTHOR("Michael Hennerich "); MODULE_DESCRIPTION("Analog Devices AD7606 ADC"); MODULE_LICENSE("GPL v2"); MODULE_IMPORT_NS(IIO_AD7606); +MODULE_IMPORT_NS(IIO_BACKEND); --=20 2.34.1 From nobody Wed Nov 27 14:33:35 2024 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9389B18DF9B for ; Wed, 9 Oct 2024 09:19:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465595; cv=none; b=GokAMSTQjulKhVdLLZKKCckF10QlRWUroEGSH4JrV8pqLBqVWtVzz9GT/SzIhaM+G1R2wdf+R0N7Y56A3fSCm8gt61ZnOPXcSkjVGFRjBmQSkH5e4orDJJzd6wr6Iyo0Zcu0BlQjaS+6oUQNb0Hk7g9geAZEfTCTJEeroKjrM8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728465595; c=relaxed/simple; bh=uuGWxYey7yHQCI4vU9zbNCU9qHQf1LbNNRlr2LUqzxo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kJDqg06s9Z+8BSlpA7JV+FqsqueLjKxCfAJsBD8GqNWm98jUNM/Ql6kHwxCrAdj/E1dWINYIiaBuOnUd6LtVMn5XP4Gz1XPwoex+Iqbn4xxMwurb2TzbF+T9Bmno5zLMqsoEW8JNeOZdwXTAVryulNk3yKyOlPU6CgCVl6jMCUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=PxCxKnGs; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="PxCxKnGs" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42cb806623eso62305265e9.2 for ; Wed, 09 Oct 2024 02:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728465590; x=1729070390; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ioyVQRlmSykkPScNPBSOZR4crBNY+9Ixx2TFHYTli/k=; b=PxCxKnGsGsyNr767qsbwxOovJN1orJUeIv4FY/kmUGQXkWMfLWR0m/kNddTsB+WFta SJHMTrKqOXmEELYSk/tFneYw2tZwHLXVensxxJENrgI1O4Lory99DYm+icV27ofZTuzw XosrPezouJrBdKJig2YWO7UIEp84qn5Y1Rc9hufNTImfFqZb0L6UUzOOy5CKXd5WGtY8 3S0lNh36FjFieTfg+u3q1jAMRAt50Y5R9P4fWuS419sXHnNqR30uBjGAFyT1j21fOS04 DuKzbwEZeickLw66HVHI8N3c5OfC56YqhPHKxS1nK8PIUqR2CvX6wxhCkZCfvjLs0Zud L2RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728465590; x=1729070390; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ioyVQRlmSykkPScNPBSOZR4crBNY+9Ixx2TFHYTli/k=; b=YzWDYzYqCtRv7nVBVYdboPEjfBnSpggxhHZ/khuh7ftDwZ1Cnz931in255fSmiV1bM XGOAL6dQ/Hrf1dwwq7cV6QJyU6nf09M4eDoo7sWtk+7sTWSCAbQUMtUo6weTCxP75k7g +en8c8k7X89wDW2QrK2TqOPMIjTFTyBZPgbDRoqpljgFvI68LxKb0OHZaUwu8bXRQMq4 oUNRdOnWmMNTcA34zpgmBlE5xdvvYXrUP1ytsWZAGBsvsfLB89SQNA+kW+VpAowJKvAq to/LFGSwKKjhsg0nAWbMkpPqdp7F39PQZEC/WPKZChbLZMe8DqodbK7SwOQuP928kPsn hTCw== X-Forwarded-Encrypted: i=1; AJvYcCWsGQXpFjwyIWR40T/iyv8NtA6vURDLFZCmFwgkSvSaoCEnY1w4J/0rCpoCbaydViQmadEKxsDMBGOb1bU=@vger.kernel.org X-Gm-Message-State: AOJu0YwE42RKaqRZC5kjoSKTpBWwSCAfO0f2be5A6SrxPJcLz0szRP1S csx6H8XdXanzNhK4B/z3VLqXaz6zCXjvcuPFkb5WnCoJqsvMenMa23f7vIixje0= X-Google-Smtp-Source: AGHT+IFzDIk1E+M5DMdcof+CZ5T2iitzbZ1ELPmRkmV0B9ZeNrzjpuKdiAku59JhRvy8QaHla4A/Dw== X-Received: by 2002:a05:600c:45d1:b0:42c:bfd6:9d4d with SMTP id 5b1f17b1804b1-430ccef5ff5mr13596205e9.2.1728465589561; Wed, 09 Oct 2024 02:19:49 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b1207sm13892765e9.31.2024.10.09.02.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:19:49 -0700 (PDT) From: Guillaume Stols Date: Wed, 09 Oct 2024 09:19:39 +0000 Subject: [PATCH v4 8/8] iio: adc: ad7606: Disable PWM usage for non backend version Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-ad7606_add_iio_backend_support-v4-8-6971a8c0f1d5@baylibre.com> References: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> In-Reply-To: <20241009-ad7606_add_iio_backend_support-v4-0-6971a8c0f1d5@baylibre.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, aardelean@baylibre.com, dlechner@baylibre.com, jstephan@baylibre.com, Jonathan Cameron , Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728465581; l=2292; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=uuGWxYey7yHQCI4vU9zbNCU9qHQf1LbNNRlr2LUqzxo=; b=XVLRBxAuTkn7joKpnvjCLRf6ITZ/+5ljsYb4AA/VxTsiKxFajOG4ywCjBEqxuqc7N5Gj84iTV CILkNPzUc7wC3qLzFwcRQMmXbUilFKxPRUp+MLmez4at9Rdbv+KX5sW X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= Since the pwm was introduced before backend, there was a mock use, with a GPIO emulation. Now that iio backend is introduced, the mock use can be removed. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 1313b5cbb0aa..a117206e5256 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -473,8 +473,6 @@ static int ad7606_pwm_set_high(struct ad7606_state *st) cnvst_pwm_state.duty_cycle =3D cnvst_pwm_state.period; =20 ret =3D pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); - /* sleep 2 =C2=B5S to let finish the current pulse */ - fsleep(2); =20 return ret; } @@ -492,8 +490,6 @@ static int ad7606_pwm_set_low(struct ad7606_state *st) cnvst_pwm_state.duty_cycle =3D 0; =20 ret =3D pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); - /* sleep 2 =C2=B5S to let finish the current pulse */ - fsleep(2); =20 return ret; } @@ -576,7 +572,6 @@ static irqreturn_t ad7606_trigger_handler(int irq, void= *p) iio_trigger_notify_done(indio_dev->trig); /* The rising edge of the CONVST signal starts a new conversion. */ gpiod_set_value(st->gpio_convst, 1); - ad7606_pwm_set_high(st); =20 return IRQ_HANDLED; } @@ -899,7 +894,6 @@ static int ad7606_buffer_postenable(struct iio_dev *ind= io_dev) struct ad7606_state *st =3D iio_priv(indio_dev); =20 gpiod_set_value(st->gpio_convst, 1); - ad7606_pwm_set_high(st); =20 return 0; } @@ -909,7 +903,6 @@ static int ad7606_buffer_predisable(struct iio_dev *ind= io_dev) struct ad7606_state *st =3D iio_priv(indio_dev); =20 gpiod_set_value(st->gpio_convst, 0); - ad7606_pwm_set_low(st); =20 return 0; } @@ -1204,6 +1197,12 @@ int ad7606_probe(struct device *dev, int irq, void _= _iomem *base_address, =20 indio_dev->setup_ops =3D &ad7606_pwm_buffer_ops; } else { + + /* Reserve the PWM use only for backend (force gpio_convst definition) */ + if (!st->gpio_convst) + return dev_err_probe(dev, -EINVAL, + "No backend, connect convst to a GPIO"); + init_completion(&st->completion); st->trig =3D devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, --=20 2.34.1