From nobody Mon Nov 25 02:44:11 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 27F081EBA05 for ; Wed, 30 Oct 2024 13:44:41 +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=1730295884; cv=none; b=oW9yywTxMXnGx6XVWu8XJcH1TvMM2OBboqiNwaWYaIjJ1o+TCfST8EdKMqNB01TeghJ3gzypYQ3+tnDhqgUnPYlfKgwXwiOUwRYxipbz6lyNiIeRCoS4ZDfOPxNR22TUgF9psKai62iIl/QZcGzT0ezqfiX2xbfC7Vtk+BwyOBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295884; c=relaxed/simple; bh=XNOgRI6/E6rGpPVTM4KwhIdeiFUpPLgi+/tTI3E/mjA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gzGc2U/TKVm3rVBEWFcIO3bnw4+3yHNYPMKk6a7q2zEkEr806SP2lTU20Bnh278G8ej3CaauwVaPqbl9FI5UpadlvcvUyoAQZ4ehKAzU8bxH0AHSu0fAiNgfpvfneDOv8BWpunm516gj3654waAhNzcMOqxrQ/iwlnAY/B7ePx8= 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=NJgrbFoZ; 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="NJgrbFoZ" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-539e3f35268so7977196e87.3 for ; Wed, 30 Oct 2024 06:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1730295879; x=1730900679; 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=Iaf1l+bnhiCTU8hwXRtL4ts0yRz9+4XKZaoBPuLyVFc=; b=NJgrbFoZaYdjj8sNviivkqclZWcWxkT8mIMfnT4owrkmUCV3njsySksQG/aHN5Nait hCkgkb9awLRHD67aoayKoLBuTxQ0HsEY6/vQHc+33oKRZ3fzW+EJrs4/Dgft6nfDqoTl pETF+xztHgGKZilDJN8zkIvtQ3vfL3U8+0sWZupuXLcRpqR9z3m0noI3ib3I3AXqhiC/ 0TBnv8x2DdbaOqmlCQeY1b/DLPz+wdXDbD6Z7MXa07vLAzri0RCuUwb+dCNzcfemSbvI fQJxWL130x7toFYbYLJcTMXRUYcs/LoP+HvPM7Y98ovFuXKtB79lc/2TtudIDiBPFS5r dXkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730295879; x=1730900679; 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=Iaf1l+bnhiCTU8hwXRtL4ts0yRz9+4XKZaoBPuLyVFc=; b=nYZpXiSDfI24YKMzq+s4By4TVwcn63GaJjQDA0qVgy99udIkkLeQgozeFSJrRGLWNV +UG/rsYXVhWUykv75xEnxPFfUDvpdmrIviU5GEmiezwa4wWWLnInJiRihBpBWsGPOuzs LNrOCtgRj70ksqU5XLVs6K2bTZ3mDmwgVqwvNiYbkG2HdM0tbwFwXgEoL8hCr6y/6qpQ NU/fvBlUoPFdo5ZJdPOAVBSbUzS63ChRuIVZaVW36p55njaGPbTv3cABfaTR+zybE7NC ofX0bvncaqJg03OiYLSFCv5WiwQLjhON8W4zBA+C9Z0v0tDhUWjKytVeXCtdJtlS/lMT qSPA== X-Forwarded-Encrypted: i=1; AJvYcCWodRYxa2cv5SdrSUNPrJW/QWfH1Ug6HJ87cWGgbdUHHNxI0bssV0PyBZKwRahoQAkQASqALTz+fJdd3Xg=@vger.kernel.org X-Gm-Message-State: AOJu0Yxk8m/WFDO1f8K/GSLsi/JoTM/ZANFLw7T6+Kx4B85dD24+jRWm rxLC0M1V/wXUB+rjB1MaqUkzPMiavAAMeQYEYqSeGcjjuXY7DmkQHWjvbvNuPQU= X-Google-Smtp-Source: AGHT+IG8QJmX7y8D32rgtAy+irk49ns3+RygZ88fAcd7W5ZJEonrfo6aEX0LrZEQ1zKIpX7vAIosBw== X-Received: by 2002:ac2:4e0b:0:b0:536:741a:6bad with SMTP id 2adb3069b0e04-53b348c1086mr7961575e87.12.1730295878920; Wed, 30 Oct 2024 06:44:38 -0700 (PDT) Received: from [192.168.1.62] (2a02-842a-d52e-6101-6f8f-5617-c4b6-8627.rev.sfr.net. [2a02:842a:d52e:6101:6f8f:5617:c4b6:8627]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd97d693sm22135175e9.24.2024.10.30.06.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 06:44:38 -0700 (PDT) From: Julien Stephan Date: Wed, 30 Oct 2024 14:44:25 +0100 Subject: [PATCH v4 1/5] dt-bindings: iio: adc: ad7380: add adaq4370-4 and adaq4380-4 compatible parts 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: <20241030-ad7380-add-adaq4380-4-support-v4-1-864ff02babae@baylibre.com> References: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> In-Reply-To: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , David Lechner , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Julien Stephan , Conor Dooley X-Mailer: b4 0.14.2 adaq4370-4 (2MSPS) and adaq4380-4 (4MSPS) are quad-channel precision data acquisition signal chain =CE=BCModule solutions compatible with the ad738x family, with the following differences: - pin selectable gain in front of each 4 adc - internal reference is 3V derived from refin-supply (5V) - additional supplies To select the gain a new patternProperties is added to describe each channel. It is restricted to adaq devices. Reviewed-by: Conor Dooley Signed-off-by: Julien Stephan Reviewed-by: David Lechner --- .../devicetree/bindings/iio/adc/adi,ad7380.yaml | 120 +++++++++++++++++= ++++ 1 file changed, 120 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad7380.yaml index 0065d650882489e21b952bb9fb25f1e3a070ee68..ada08005b3cd1ce7ba13f96484a= 33fdee0e83a1c 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml @@ -25,6 +25,8 @@ description: | * https://www.analog.com/en/products/ad7386-4.html * https://www.analog.com/en/products/ad7387-4.html * https://www.analog.com/en/products/ad7388-4.html + * https://www.analog.com/en/products/adaq4370-4.html + * https://www.analog.com/en/products/adaq4380-4.html =20 =20 $ref: /schemas/spi/spi-peripheral-props.yaml# @@ -46,6 +48,8 @@ properties: - adi,ad7386-4 - adi,ad7387-4 - adi,ad7388-4 + - adi,adaq4370-4 + - adi,adaq4380-4 =20 reg: maxItems: 1 @@ -70,6 +74,20 @@ properties: refin-supply: description: A 2.5V to 3.3V supply for external reference voltage, for ad7380-4 o= nly. + For adaq devices, a 5V supply voltage. A 3.3V internal reference is + derived from it. Connect to vs-p-supply for normal operation. + + vs-p-supply: + description: + Amplifiers positive supply. + + vs-n-supply: + description: + Amplifiers negative supply. + + ldo-supply: + description: + LDO supply. Connect to vs-p-supply or a 3.6 to 5.5 V supply. =20 aina-supply: description: @@ -97,12 +115,45 @@ properties: specify the ALERT interrupt. maxItems: 1 =20 + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + required: - compatible - reg - vcc-supply - vlogic-supply =20 +patternProperties: + "^channel@[0-3]$": + $ref: adc.yaml + type: object + + properties: + reg: + description: + The channel number. From 0 to 3 corresponding to channels A,B,C,D + minimum: 0 + maximum: 3 + + adi,gain-milli: + description: + The hardware gain applied to the ADC input (in milli units). + If not present, default to 1000 (no actual gain applied). + Refer to the typical connection diagrams section of the datashee= t for + pin wiring. + $ref: /schemas/types.yaml#/definitions/uint16 + enum: [300, 600, 1000, 1600] + default: 1000 + + required: + - reg + + additionalProperties: false + unevaluatedProperties: false =20 allOf: @@ -140,6 +191,7 @@ allOf: aind-supply: false =20 # ad7380-4 uses refin-supply as external reference. + # adaq devices use internal reference only, derived from refin-supply # All other chips from ad738x family use refio as optional external refe= rence. # When refio-supply is omitted, internal reference is used. - if: @@ -147,6 +199,8 @@ allOf: compatible: enum: - adi,ad7380-4 + - adi,adaq4370-4 + - adi,adaq4380-4 then: properties: refio-supply: false @@ -156,6 +210,27 @@ allOf: properties: refin-supply: false =20 + # adaq devices need more supplies and using channel to declare gain prop= erty + # only applies to adaq devices + - if: + properties: + compatible: + enum: + - adi,adaq4370-4 + - adi,adaq4380-4 + then: + required: + - vs-p-supply + - vs-n-supply + - ldo-supply + else: + properties: + vs-p-supply: false + vs-n-supply: false + ldo-supply: false + patternProperties: + "^channel@[0-3]$": false + examples: - | #include @@ -180,3 +255,48 @@ examples: refio-supply =3D <&supply_2_5V>; }; }; + + - | + #include + + spi { + #address-cells =3D <1>; + #size-cells =3D <0>; + + adc@0 { + compatible =3D "adi,adaq4380-4"; + reg =3D <0>; + + spi-cpol; + spi-cpha; + spi-max-frequency =3D <80000000>; + + interrupts =3D <27 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent =3D <&gpio0>; + + vcc-supply =3D <&supply_3_3V>; + vlogic-supply =3D <&supply_3_3V>; + refin-supply =3D <&supply_5V>; + vs-p-supply =3D <&supply_5V>; + vs-n-supply =3D <&supply_0V>; + ldo-supply =3D <&supply_5V>; + + #address-cells =3D <1>; + #size-cells =3D <0>; + + channel@0 { + reg =3D <0>; + adi,gain-milli =3D /bits/ 16 <300>; + }; + + channel@2 { + reg =3D <2>; + adi,gain-milli =3D /bits/ 16 <600>; + }; + + channel@3 { + reg =3D <3>; + adi,gain-milli =3D /bits/ 16 <1000>; + }; + }; + }; --=20 2.47.0 From nobody Mon Nov 25 02:44:11 2024 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 5D3A41EBA1A for ; Wed, 30 Oct 2024 13:44:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295884; cv=none; b=QRCTb0RV3GPnmBgrdbOcp6xN2XoEl4c2SwR5w6JX3I6To/Mz13HZsQ3SzQmPOdjODhuvM4NBuvbA+yHAP3hSPrE8RMHC8HdGFBA6IweKhZ8cuzCW4uBibYSq2qE77snnkulFfzDQkRTfMAkEx0KJ48j8/WBcnh3qJT8n0pkWtzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295884; c=relaxed/simple; bh=V5Iv60vRstuniFfHpYRmwvvIRs3G4BEePM0L/f0it8Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rLVpDtwJYHuTk8Y0ep8nWgwZQ8/rUKPmS19a8O/aStHkIcIYYzepaY4OAaRI8AGi1uViat/azR5cl/Rpk9dr5yax8Y8Sqla67njlEG9nLZ5BOex0NHab7jE5T5UcDFOE2vTUqly1ACiv+Tt2B3TtnI/viNTMsd0BVwvl+Fobs4g= 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=AcDjtabi; arc=none smtp.client-ip=209.85.128.50 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="AcDjtabi" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4314fa33a35so61785535e9.1 for ; Wed, 30 Oct 2024 06:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1730295880; x=1730900680; 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=1x3VtH5eamsZnRB9P+0wcD4ahBXtjl9ZuFAd+0mooPI=; b=AcDjtabi+j/r5gutsbhnadFvlNR6VJzYD/Pzh0+QXhNO9dHtZbWWITG39CxKLbWjyx XjzeJhQwIbRYgZ3cn2Nzcq49tzJP0uxdFyFQ0b9rMjZS3dGJmJAbNZ8XD9LeDcvhYQ65 PYwWYxw4k6v/FP6PGhRdZ+Lf1KUixBaoQzVpWEqgmfKSCDRJMPkkgY+tkfwxtPp2yJO7 qb1USmwKnlGLRoMg+3jhcBb3VhOmFBR4simtAaki20pEB1qa+WdCT6HTeeNreXOQWQkR 1oDI0xwDWgcE4F9b68T1sfgpiks5XEA9ozHwetjVmsN7ja+mwhut9aOBtqVkoYJ9uh6g mYtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730295880; x=1730900680; 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=1x3VtH5eamsZnRB9P+0wcD4ahBXtjl9ZuFAd+0mooPI=; b=P+qgbmwc9rIXlYL3CCwUz5Z7d95Al+G7VJJaPEscucVljWBbH2oZTeyVhU2clHSFWp T/sSLxJf7YlFgj55ARy4nOYZrP6E+SPLe3575HsOeuvLLIa1BYtg0PC+mqL0dglkq2wJ IHlIn4A7ClFkykEGVQ5Gl/YJhZTIp0k1GMCGCsckfouxEiIWDP/dW45FstQgZcBQdr3B 92K+fQOtQQaZ0LhR9vvFJ3gi5fI9kXUFJXOjDj1fw+XecIpTmgGV7fYDB/WICFS+6yad 2CmowpVEjj6XNFECMWbPSalGMSskfA2Pc+KxN0IBZgYkGP/Q3I6NTqVqQE35XcdvMnKM C74Q== X-Forwarded-Encrypted: i=1; AJvYcCWIqOgXgCVUaid4w5pCzstMFjYR2+cKfNYFBo1ODcFRsEOVV1Z9I01x1bb155bjQGl0+fJnzMJczz3YDFM=@vger.kernel.org X-Gm-Message-State: AOJu0YxsUbULfJYpyqilOmH7emJjyAr30xC+Y7EfPONscjBaoQqIaP/F WljBPH/aBXhL5DlqoDrUkCK0G8WqInlhEyEq7tKJMUXtahvTCXOkAjQb0pPlH00= X-Google-Smtp-Source: AGHT+IGFUMsRBJAN9nu2cZNxyckXM2rlQCdrl015AwDjfeG7ISymyh7aGHVpQf5SgmRCqWeI1nTmMg== X-Received: by 2002:a05:600c:4691:b0:431:2460:5574 with SMTP id 5b1f17b1804b1-431bb9d1425mr27612325e9.27.1730295879769; Wed, 30 Oct 2024 06:44:39 -0700 (PDT) Received: from [192.168.1.62] (2a02-842a-d52e-6101-6f8f-5617-c4b6-8627.rev.sfr.net. [2a02:842a:d52e:6101:6f8f:5617:c4b6:8627]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd97d693sm22135175e9.24.2024.10.30.06.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 06:44:39 -0700 (PDT) From: Julien Stephan Date: Wed, 30 Oct 2024 14:44:26 +0100 Subject: [PATCH v4 2/5] iio: adc: ad7380: fix oversampling formula 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: <20241030-ad7380-add-adaq4380-4-support-v4-2-864ff02babae@baylibre.com> References: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> In-Reply-To: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , David Lechner , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Julien Stephan X-Mailer: b4 0.14.2 The formula in the datasheet for oversampling time conversion seems to be valid when device is at full speed using the maximum number of SDO lines. The driver currently support only 1 SDO line. The correct formula is: t_convert =3D T_CONVERT_0_NS + T_CONVERT_X_NS*(x - 1)*num_channel/number_of_sdo_lines. It will produce larger delays than what is currently set, but some devices actually require it. Signed-off-by: Julien Stephan Reviewed-by: David Lechner --- drivers/iio/adc/ad7380.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index fb728570debe6432d5f991595cb35e9e7af8b740..e5eececaaf501cda8f51d801c08= 9e593111df714 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -77,6 +77,12 @@ #define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */ #define T_POWERUP_US 5000 /* Power up */ =20 +/* + * AD738x support several SDO lines to increase throughput, but driver cur= rently + * supports only 1 SDO line (standard SPI transaction) + */ +#define AD7380_NUM_SDO_LINES 1 + struct ad7380_timing_specs { const unsigned int t_csh_ns; /* CS minimum high time */ }; @@ -649,7 +655,8 @@ static int ad7380_set_ch(struct ad7380_state *st, unsig= ned int ch) =20 if (st->oversampling_ratio > 1) xfer.delay.value =3D T_CONVERT_0_NS + - T_CONVERT_X_NS * (st->oversampling_ratio - 1); + T_CONVERT_X_NS * (st->oversampling_ratio - 1) * + st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES; =20 return spi_sync_transfer(st->spi, &xfer, 1); } @@ -672,7 +679,8 @@ static void ad7380_update_xfers(struct ad7380_state *st, */ if (st->oversampling_ratio > 1) t_convert =3D T_CONVERT_0_NS + T_CONVERT_X_NS * - (st->oversampling_ratio - 1); + (st->oversampling_ratio - 1) * + st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES; =20 if (st->seq) { xfer[0].delay.value =3D xfer[1].delay.value =3D t_convert; @@ -1021,7 +1029,8 @@ static int ad7380_init(struct ad7380_state *st, bool = external_ref_en) /* SPI 1-wire mode */ return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2, AD7380_CONFIG2_SDO, - FIELD_PREP(AD7380_CONFIG2_SDO, 1)); + FIELD_PREP(AD7380_CONFIG2_SDO, + AD7380_NUM_SDO_LINES)); } =20 static int ad7380_probe(struct spi_device *spi) --=20 2.47.0 From nobody Mon Nov 25 02:44:11 2024 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 65C061EBFFB for ; Wed, 30 Oct 2024 13:44:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295885; cv=none; b=WxGSbPD1VPdHBl++/Q7We4yHRDfOEfzkce8wep8a46FymqbpuRC9jj8tjANYSVG3UYBfDDi9jOgGsseGoPAHwa5Uj/tIE6Ws2YlF7vmnewf5SxlspwqrHct5A9aE2YOqPIn+PXFK7pVWXwneQvRrC48pk3C5Tlq7deRHZTeyLGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295885; c=relaxed/simple; bh=RO9hGOKZEvxMEHLVRYfaOYF08wLVGpI7aOsmLqLjRtM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nB+9dcH7JF0MyN3Il+qRksUjsFixvUwiDb61B/7gEzlvDCZbpQQn9RPe2dbL0VMTDBrgEBUNs8GDPK04az6ihrXE/aOsRvK/qSXPy+bUsNDqV7sw3HUVsHOHqFjRxdNCHpPtqA+qgl8ZPYHPVTFjJGcqCb1becdn1UJ2dNWivZY= 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=bKJQAbIG; arc=none smtp.client-ip=209.85.128.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="bKJQAbIG" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-43158625112so64299285e9.3 for ; Wed, 30 Oct 2024 06:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1730295881; x=1730900681; 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=8BjJ2M207dDw7Til612ivS6L47An/FajkZsL4QTnDEc=; b=bKJQAbIGjBPe4iS983eJ78eVNlPZltni+bIIZh6tMortUtEK0FOkkJI+RsNB2ZkJZj Gao0cmxA0wecIq3nXV4+JB0Amf1klyOlpxQCTRhNZ4od+U8If4+sPxv9USAtLvQ9ghuS WjS77wKgTP5XaRQgp3gfrvsjefStH1oTmfHshCgqT4UiPZZk8AerIFUbkBx4kIMGqpAM gPyKkSH5STYVraBBICcut3RdYiKvQxIlIGmi/sX7TgBbcz+ZkoeErnivj6y/N8hZqcfd RJ6nevKobTqikTAUme945dWGVdH/VI+Jrd5/yq5GgcxXv6fGDG86HE/qUtFvpScMn+xz Qb1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730295881; x=1730900681; 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=8BjJ2M207dDw7Til612ivS6L47An/FajkZsL4QTnDEc=; b=RPGVAuuAUDfZe2cjUT+PzAJ8PnGvLvaUt0D8O63Gxpk9T0BmExehmWWg9ggwzD5NZy /5GT2drJmu1d7pMu6Vkh2e7aP/pcx8pBgcfyQ5NycbPdRr9rV9nJbCdcARbpkZlLJMRx y6iqEH4Wlzn9TifqLPzlFj5lRCrqK3F6zHLYUN8FTyG6MY2CMa95ypOZ3QOAMJXuAySf qbZzwsUXCvnY41Wr418S4OrA4DF9aaEMczS+bzSdZEAPcyMokCdoD0bAQ67wqD7b4lTg SOa/fuhT0P1TP8sKPksewicVlBSHvuTwfDFaLd+6JvXyS+OHNS6kntuZMBpk8yuQX9dc 1JWQ== X-Forwarded-Encrypted: i=1; AJvYcCUnQ2D127Ipf54V4+V6mNLexvQMy+y9hdqLQwNtgpM7HESVw3XgGo28PHylvGSI1L5r1FHag0egVfG/UjE=@vger.kernel.org X-Gm-Message-State: AOJu0YwAyRd124fx38b8vvzEhhfhoyouynacsdXoIlMyl8WgRZ6BH4Ty adRJlOm9o8Iu0Zosd0u0uWq0wienXR3NH0ErlZEm8H6pleqWeEJikRLUSbc0zCo= X-Google-Smtp-Source: AGHT+IEqWScIHhC8tPglxlTqg9bpzau4UkxRE+2yBiH6NV8VeDBBJkoxE09TQc+ilKeht4wWRnPEFw== X-Received: by 2002:a05:600c:4711:b0:431:586e:7e7 with SMTP id 5b1f17b1804b1-4319ac6e818mr145719855e9.1.1730295880634; Wed, 30 Oct 2024 06:44:40 -0700 (PDT) Received: from [192.168.1.62] (2a02-842a-d52e-6101-6f8f-5617-c4b6-8627.rev.sfr.net. [2a02:842a:d52e:6101:6f8f:5617:c4b6:8627]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd97d693sm22135175e9.24.2024.10.30.06.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 06:44:40 -0700 (PDT) From: Julien Stephan Date: Wed, 30 Oct 2024 14:44:27 +0100 Subject: [PATCH v4 3/5] iio: adc: ad7380: use local dev variable to shorten long lines 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: <20241030-ad7380-add-adaq4380-4-support-v4-3-864ff02babae@baylibre.com> References: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> In-Reply-To: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , David Lechner , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Julien Stephan X-Mailer: b4 0.14.2 Use local dev variable in the probe function to shorten long lines. Signed-off-by: Julien Stephan Reviewed-by: David Lechner --- drivers/iio/adc/ad7380.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index e5eececaaf501cda8f51d801c089e593111df714..206c894953f057acca20805fb30= 185cb7ab8a902 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -1035,12 +1035,13 @@ static int ad7380_init(struct ad7380_state *st, boo= l external_ref_en) =20 static int ad7380_probe(struct spi_device *spi) { + struct device *dev =3D &spi->dev; struct iio_dev *indio_dev; struct ad7380_state *st; bool external_ref_en; int ret, i; =20 - indio_dev =3D devm_iio_device_alloc(&spi->dev, sizeof(*st)); + indio_dev =3D devm_iio_device_alloc(dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; =20 @@ -1048,21 +1049,20 @@ static int ad7380_probe(struct spi_device *spi) st->spi =3D spi; st->chip_info =3D spi_get_device_match_data(spi); if (!st->chip_info) - return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n"); + return dev_err_probe(dev, -EINVAL, "missing match data\n"); =20 - ret =3D devm_regulator_bulk_get_enable(&spi->dev, st->chip_info->num_supp= lies, + ret =3D devm_regulator_bulk_get_enable(dev, st->chip_info->num_supplies, st->chip_info->supplies); =20 if (ret) - return dev_err_probe(&spi->dev, ret, + return dev_err_probe(dev, ret, "Failed to enable power supplies\n"); fsleep(T_POWERUP_US); =20 if (st->chip_info->external_ref_only) { - ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, - "refin"); + ret =3D devm_regulator_get_enable_read_voltage(dev, "refin"); if (ret < 0) - return dev_err_probe(&spi->dev, ret, + return dev_err_probe(dev, ret, "Failed to get refin regulator\n"); =20 st->vref_mv =3D ret / 1000; @@ -1074,10 +1074,9 @@ static int ad7380_probe(struct spi_device *spi) * If there is no REFIO supply, then it means that we are using * the internal reference, otherwise REFIO is reference voltage. */ - ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, - "refio"); + ret =3D devm_regulator_get_enable_read_voltage(dev, "refio"); if (ret < 0 && ret !=3D -ENODEV) - return dev_err_probe(&spi->dev, ret, + return dev_err_probe(dev, ret, "Failed to get refio regulator\n"); =20 external_ref_en =3D ret !=3D -ENODEV; @@ -1085,7 +1084,7 @@ static int ad7380_probe(struct spi_device *spi) } =20 if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv)) - return dev_err_probe(&spi->dev, -EINVAL, + return dev_err_probe(dev, -EINVAL, "invalid number of VCM supplies\n"); =20 /* @@ -1095,18 +1094,18 @@ static int ad7380_probe(struct spi_device *spi) for (i =3D 0; i < st->chip_info->num_vcm_supplies; i++) { const char *vcm =3D st->chip_info->vcm_supplies[i]; =20 - ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, vcm); + ret =3D devm_regulator_get_enable_read_voltage(dev, vcm); if (ret < 0) - return dev_err_probe(&spi->dev, ret, + return dev_err_probe(dev, ret, "Failed to get %s regulator\n", vcm); =20 st->vcm_mv[i] =3D ret / 1000; } =20 - st->regmap =3D devm_regmap_init(&spi->dev, NULL, st, &ad7380_regmap_confi= g); + st->regmap =3D devm_regmap_init(dev, NULL, st, &ad7380_regmap_config); if (IS_ERR(st->regmap)) - return dev_err_probe(&spi->dev, PTR_ERR(st->regmap), + return dev_err_probe(dev, PTR_ERR(st->regmap), "failed to allocate register map\n"); =20 /* @@ -1157,7 +1156,7 @@ static int ad7380_probe(struct spi_device *spi) indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->available_scan_masks =3D st->chip_info->available_scan_masks; =20 - ret =3D devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, + ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time, ad7380_trigger_handler, &ad7380_buffer_setup_ops); @@ -1168,7 +1167,7 @@ static int ad7380_probe(struct spi_device *spi) if (ret) return ret; =20 - return devm_iio_device_register(&spi->dev, indio_dev); + return devm_iio_device_register(dev, indio_dev); } =20 static const struct of_device_id ad7380_of_match_table[] =3D { --=20 2.47.0 From nobody Mon Nov 25 02:44:11 2024 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 70C851EE036 for ; Wed, 30 Oct 2024 13:44:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295887; cv=none; b=BR5b0WgLy94cdkP//NLuUbgcSnZOL+HOQeUfKQyzQ2hg2fqtCxjN84nCYCiAJewWPJh9NpcYGCFMggkmAej0ong6CkqQUD2i85kW7SXsY34mtIzREEfsXV6hUA0YP5/LmFkt1drWsjS760IOAWYcLqqAib+CStHLVkTh/OSCJ7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295887; c=relaxed/simple; bh=0ttDZj2ZkhjsaK1OSdKhg8Gk7/t274r5Lr3eaZacvx8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dvNFlxnGEmD+S3NJry/iKTw5GpFaST9bKZejTF/deCKV8xJeXN6Fbsd1514m1nBG85uhBsfPCwgB4gOy1AbRJUR/G0GiJRzp6FyrJS88M/Z5nv/uGiBtWQoBVLPi+tWToZmevFVxuzru1r4S9BbjRjqr/J6QHrGJAz9PHntSWk0= 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=crKWKW6l; arc=none smtp.client-ip=209.85.128.54 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="crKWKW6l" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-43169902057so61890005e9.0 for ; Wed, 30 Oct 2024 06:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1730295882; x=1730900682; 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=6/zZXJm1iv61pxbZuPv42modR1pl77w3Mk/LfpLxIz0=; b=crKWKW6l51z4fW0N7DEeEm6Ec5Eec6DEs8fCmuYEuBZY/DEQKeyckg0fAZ6129ucxN 6SPowolOgosrZKIYg6G6wsM1FXNwNaIwBDqnNKkkfdOK4IJiMoySzw7RMKkOu1eQV784 molvM+Lv90UN0zLUQolAjNRTxDsR+l+U07jCOPuPWHDvXNa+cdrvJFWgNvT0dJJYNav0 7LD7HOhXQbwqabW7VkG0wjD65tqeQJkBW0hdxOs9BCiA9MOvG8vhK1QhMSiS+1pBR5oH 3nQ1za+zIaxA1CXvABXqxuj+LtmbpRwqQhhloyxXOn0zw704QkKF/tGL8wONKho1rl/Y F8Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730295882; x=1730900682; 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=6/zZXJm1iv61pxbZuPv42modR1pl77w3Mk/LfpLxIz0=; b=iAs+/dOf2nbHj1vl8pX5TfAFNUDeHmgP0LSOsvkdsQiFtDZZINmrld89UIqcgNBlwN 64DuQgLc66WimT0kKxFR3tTLL4LT4Qk+DFrXEjRP1HTzZ4osjF33+9bJZYVwnmO9pCSe lg3s2BoOoMS47+xoFEP+5F2xoJ+NhtOBcMh3oiURtlbZ7z/E0KMYSyAoby2GablWNtmi pCBVCXidjJgY2R8gvpqWJhAAQvJr5bePFNgEru/0cD9yhwEWo84/D+OPEMdsbw8h99rm BEuom7eraSt87+Sv3tbZTs/HTIIDQvEF+eS70lUlUGEAlKL8Fn9Wm4SE3FdDWWCOSrGi 5l6Q== X-Forwarded-Encrypted: i=1; AJvYcCVqq5vTUN7GUP5icUIPcAt2OUy72OnqULoRlqw8uJV+RPtQfr9fHsFsEhyNrxJF2mM1dNdJ56cyNs+y2nE=@vger.kernel.org X-Gm-Message-State: AOJu0YzJ2C9jdhrRe4bVJRKWEq2UyOhL65/ddSZbTa80e8vnRgj1J0fc uepHxG1VwF4RwJvmAXkU39P6xxm4ZBRNIWa2GONYtjv9gmtj7amHk0iMts98nX0= X-Google-Smtp-Source: AGHT+IH17rOSoL/+Lmy1UYoEUw7+laWLknanbEqrYmHEt8FE6IyYxVCDW16e7fLc+z+VlUPugQo25Q== X-Received: by 2002:a05:600c:1f82:b0:430:57f2:bae2 with SMTP id 5b1f17b1804b1-431bb9d14afmr24830055e9.23.1730295881538; Wed, 30 Oct 2024 06:44:41 -0700 (PDT) Received: from [192.168.1.62] (2a02-842a-d52e-6101-6f8f-5617-c4b6-8627.rev.sfr.net. [2a02:842a:d52e:6101:6f8f:5617:c4b6:8627]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd97d693sm22135175e9.24.2024.10.30.06.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 06:44:41 -0700 (PDT) From: Julien Stephan Date: Wed, 30 Oct 2024 14:44:28 +0100 Subject: [PATCH v4 4/5] iio: adc: ad7380: add support for adaq4370-4 and adaq4380-4 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: <20241030-ad7380-add-adaq4380-4-support-v4-4-864ff02babae@baylibre.com> References: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> In-Reply-To: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , David Lechner , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Julien Stephan X-Mailer: b4 0.14.2 adaq4370-4 (2MSPS) and adaq4380-4 (4MSPS) are quad-channel precision data acquisition signal chain =CE=BCModule solutions compatible with the ad738x family, with the following differences: - pin selectable gain in front of each 4 adc - internal reference is 3V derived from refin-supply (5V) - additional supplies This implies that IIO_CHAN_INFO_SCALE can not be shared by type for these new devices. Signed-off-by: Julien Stephan Reviewed-by: David Lechner --- drivers/iio/adc/ad7380.c | 130 +++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 126 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index 206c894953f057acca20805fb30185cb7ab8a902..4f32cb22f140442b831dc9a4f27= 5e88e4ab2388e 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -13,6 +13,8 @@ * ad7381-4 : https://www.analog.com/media/en/technical-documentation/data= -sheets/ad7381-4.pdf * ad7383/4-4 : https://www.analog.com/media/en/technical-documentation/da= ta-sheets/ad7383-4-ad7384-4.pdf * ad7386/7/8-4 : https://www.analog.com/media/en/technical-documentation/= data-sheets/ad7386-4-7387-4-7388-4.pdf + * adaq4370-4 : https://www.analog.com/media/en/technical-documentation/da= ta-sheets/adaq4370-4.pdf + * adaq4380-4 : https://www.analog.com/media/en/technical-documentation/da= ta-sheets/adaq4380-4.pdf */ =20 #include @@ -22,11 +24,14 @@ #include #include #include +#include #include #include #include #include #include +#include +#include =20 #include #include @@ -36,6 +41,8 @@ #define MAX_NUM_CHANNELS 8 /* 2.5V internal reference voltage */ #define AD7380_INTERNAL_REF_MV 2500 +/* 3.3V internal reference voltage for ADAQ */ +#define ADAQ4380_INTERNAL_REF_MV 3300 =20 /* reading and writing registers is more reliable at lower than max speed = */ #define AD7380_REG_WR_SPEED_HZ 10000000 @@ -82,6 +89,7 @@ * supports only 1 SDO line (standard SPI transaction) */ #define AD7380_NUM_SDO_LINES 1 +#define AD7380_DEFAULT_GAIN_MILLI 1000 =20 struct ad7380_timing_specs { const unsigned int t_csh_ns; /* CS minimum high time */ @@ -92,10 +100,12 @@ struct ad7380_chip_info { const struct iio_chan_spec *channels; unsigned int num_channels; unsigned int num_simult_channels; + bool has_hardware_gain; bool has_mux; const char * const *supplies; unsigned int num_supplies; bool external_ref_only; + bool adaq_internal_ref_only; const char * const *vcm_supplies; unsigned int num_vcm_supplies; const unsigned long *available_scan_masks; @@ -187,11 +197,12 @@ static const struct iio_scan_type ad7380_scan_type_16= _u[] =3D { }, }; =20 -#define AD7380_CHANNEL(index, bits, diff, sign) { \ +#define _AD7380_CHANNEL(index, bits, diff, sign, gain) { \ .type =3D IIO_VOLTAGE, \ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | \ + ((gain) ? BIT(IIO_CHAN_INFO_SCALE) : 0) | \ ((diff) ? 0 : BIT(IIO_CHAN_INFO_OFFSET)), \ - .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_SCALE) | \ + .info_mask_shared_by_type =3D ((gain) ? 0 : BIT(IIO_CHAN_INFO_SCALE)) | \ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ .info_mask_shared_by_type_available =3D \ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ @@ -205,6 +216,12 @@ static const struct iio_scan_type ad7380_scan_type_16_= u[] =3D { .num_ext_scan_type =3D ARRAY_SIZE(ad7380_scan_type_##bits##_##sign), \ } =20 +#define AD7380_CHANNEL(index, bits, diff, sign) \ + _AD7380_CHANNEL(index, bits, diff, sign, false) + +#define ADAQ4380_CHANNEL(index, bits, diff, sign) \ + _AD7380_CHANNEL(index, bits, diff, sign, true) + #define DEFINE_AD7380_2_CHANNEL(name, bits, diff, sign) \ static const struct iio_chan_spec name[] =3D { \ AD7380_CHANNEL(0, bits, diff, sign), \ @@ -221,6 +238,15 @@ static const struct iio_chan_spec name[] =3D { \ IIO_CHAN_SOFT_TIMESTAMP(4), \ } =20 +#define DEFINE_ADAQ4380_4_CHANNEL(name, bits, diff, sign) \ +static const struct iio_chan_spec name[] =3D { \ + ADAQ4380_CHANNEL(0, bits, diff, sign), \ + ADAQ4380_CHANNEL(1, bits, diff, sign), \ + ADAQ4380_CHANNEL(2, bits, diff, sign), \ + ADAQ4380_CHANNEL(3, bits, diff, sign), \ + IIO_CHAN_SOFT_TIMESTAMP(4), \ +} + #define DEFINE_AD7380_8_CHANNEL(name, bits, diff, sign) \ static const struct iio_chan_spec name[] =3D { \ AD7380_CHANNEL(0, bits, diff, sign), \ @@ -239,6 +265,7 @@ DEFINE_AD7380_2_CHANNEL(ad7380_channels, 16, 1, s); DEFINE_AD7380_2_CHANNEL(ad7381_channels, 14, 1, s); DEFINE_AD7380_4_CHANNEL(ad7380_4_channels, 16, 1, s); DEFINE_AD7380_4_CHANNEL(ad7381_4_channels, 14, 1, s); +DEFINE_ADAQ4380_4_CHANNEL(adaq4380_4_channels, 16, 1, s); /* pseudo differential */ DEFINE_AD7380_2_CHANNEL(ad7383_channels, 16, 0, s); DEFINE_AD7380_2_CHANNEL(ad7384_channels, 14, 0, s); @@ -257,6 +284,10 @@ static const char * const ad7380_supplies[] =3D { "vcc", "vlogic", }; =20 +static const char * const adaq4380_supplies[] =3D { + "ldo", "vcc", "vlogic", "vs-p", "vs-n", "refin", +}; + static const char * const ad7380_2_channel_vcm_supplies[] =3D { "aina", "ainb", }; @@ -347,6 +378,11 @@ static const int ad7380_oversampling_ratios[] =3D { 1, 2, 4, 8, 16, 32, }; =20 +/* Gains stored as fractions of 1000 so they can be expressed by integers.= */ +static const int ad7380_gains[] =3D { + 300, 600, 1000, 1600, +}; + static const struct ad7380_chip_info ad7380_chip_info =3D { .name =3D "ad7380", .channels =3D ad7380_channels, @@ -516,6 +552,32 @@ static const struct ad7380_chip_info ad7388_4_chip_inf= o =3D { .timing_specs =3D &ad7380_4_timing, }; =20 +static const struct ad7380_chip_info adaq4370_4_chip_info =3D { + .name =3D "adaq4370-4", + .channels =3D adaq4380_4_channels, + .num_channels =3D ARRAY_SIZE(adaq4380_4_channels), + .num_simult_channels =3D 4, + .supplies =3D adaq4380_supplies, + .num_supplies =3D ARRAY_SIZE(adaq4380_supplies), + .adaq_internal_ref_only =3D true, + .has_hardware_gain =3D true, + .available_scan_masks =3D ad7380_4_channel_scan_masks, + .timing_specs =3D &ad7380_4_timing, +}; + +static const struct ad7380_chip_info adaq4380_4_chip_info =3D { + .name =3D "adaq4380-4", + .channels =3D adaq4380_4_channels, + .num_channels =3D ARRAY_SIZE(adaq4380_4_channels), + .num_simult_channels =3D 4, + .supplies =3D adaq4380_supplies, + .num_supplies =3D ARRAY_SIZE(adaq4380_supplies), + .adaq_internal_ref_only =3D true, + .has_hardware_gain =3D true, + .available_scan_masks =3D ad7380_4_channel_scan_masks, + .timing_specs =3D &ad7380_4_timing, +}; + struct ad7380_state { const struct ad7380_chip_info *chip_info; struct spi_device *spi; @@ -526,6 +588,7 @@ struct ad7380_state { bool seq; unsigned int vref_mv; unsigned int vcm_mv[MAX_NUM_CHANNELS]; + unsigned int gain_milli[MAX_NUM_CHANNELS]; /* xfers, message an buffer for reading sample data */ struct spi_transfer normal_xfer[2]; struct spi_message normal_msg; @@ -876,8 +939,15 @@ static int ad7380_read_raw(struct iio_dev *indio_dev, * * (2 =C3=97 VREF) / 2^N, for differential chips * * VREF / 2^N, for pseudo-differential chips * where N is the ADC resolution (i.e realbits) + * + * The gain is stored as a fraction of 1000 and, as we need to + * divide vref_mv by the gain, we invert the gain/1000 fraction. */ - *val =3D st->vref_mv; + if (st->chip_info->has_hardware_gain) + *val =3D mult_frac(st->vref_mv, MILLI, + st->gain_milli[chan->scan_index]); + else + *val =3D st->vref_mv; *val2 =3D scan_type->realbits - chan->differential; =20 return IIO_VAL_FRACTIONAL_LOG2; @@ -1059,7 +1129,19 @@ static int ad7380_probe(struct spi_device *spi) "Failed to enable power supplies\n"); fsleep(T_POWERUP_US); =20 - if (st->chip_info->external_ref_only) { + if (st->chip_info->adaq_internal_ref_only) { + /* + * ADAQ chips use fixed internal reference but still + * require a specific reference supply to power it. + * "refin" is already enabled with other power supplies + * in bulk_get_enable(). + */ + + st->vref_mv =3D ADAQ4380_INTERNAL_REF_MV; + + /* these chips don't have a register bit for this */ + external_ref_en =3D false; + } else if (st->chip_info->external_ref_only) { ret =3D devm_regulator_get_enable_read_voltage(dev, "refin"); if (ret < 0) return dev_err_probe(dev, ret, @@ -1103,6 +1185,42 @@ static int ad7380_probe(struct spi_device *spi) st->vcm_mv[i] =3D ret / 1000; } =20 + for (i =3D 0; i < MAX_NUM_CHANNELS; i++) + st->gain_milli[i] =3D AD7380_DEFAULT_GAIN_MILLI; + + if (st->chip_info->has_hardware_gain) { + device_for_each_child_node_scoped(dev, node) { + unsigned int channel, gain; + int gain_idx; + + ret =3D fwnode_property_read_u32(node, "reg", &channel); + if (ret) + return dev_err_probe(dev, ret, + "Failed to read reg property\n"); + + if (channel >=3D st->chip_info->num_channels - 1) + return dev_err_probe(dev, -EINVAL, + "Invalid channel number %i\n", + channel); + + ret =3D fwnode_property_read_u32(node, "adi,gain-milli", + &gain); + if (ret && ret !=3D -EINVAL) + return dev_err_probe(dev, ret, + "Failed to read gain for channel %i\n", + channel); + if (ret !=3D -EINVAL) { + /* + * Match gain value from dt to one of supported + * gains + */ + gain_idx =3D find_closest(gain, ad7380_gains, + ARRAY_SIZE(ad7380_gains)); + st->gain_milli[channel] =3D ad7380_gains[gain_idx]; + } + } + } + st->regmap =3D devm_regmap_init(dev, NULL, st, &ad7380_regmap_config); if (IS_ERR(st->regmap)) return dev_err_probe(dev, PTR_ERR(st->regmap), @@ -1185,6 +1303,8 @@ static const struct of_device_id ad7380_of_match_tabl= e[] =3D { { .compatible =3D "adi,ad7386-4", .data =3D &ad7386_4_chip_info }, { .compatible =3D "adi,ad7387-4", .data =3D &ad7387_4_chip_info }, { .compatible =3D "adi,ad7388-4", .data =3D &ad7388_4_chip_info }, + { .compatible =3D "adi,adaq4370-4", .data =3D &adaq4370_4_chip_info }, + { .compatible =3D "adi,adaq4380-4", .data =3D &adaq4380_4_chip_info }, { } }; =20 @@ -1203,6 +1323,8 @@ static const struct spi_device_id ad7380_id_table[] = =3D { { "ad7386-4", (kernel_ulong_t)&ad7386_4_chip_info }, { "ad7387-4", (kernel_ulong_t)&ad7387_4_chip_info }, { "ad7388-4", (kernel_ulong_t)&ad7388_4_chip_info }, + { "adaq4370-4", (kernel_ulong_t)&adaq4370_4_chip_info }, + { "adaq4380-4", (kernel_ulong_t)&adaq4380_4_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, ad7380_id_table); --=20 2.47.0 From nobody Mon Nov 25 02:44:11 2024 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 4CFA51EF09B for ; Wed, 30 Oct 2024 13:44:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295887; cv=none; b=dopu7ubF4QsIMa/40qN/+JLBv/WyBv7+GJs69QQfenElIp4R7+WkDcfCYC9+Eqk2itbN4cNRmn3XZLLDF2AOiv9cHiSAhFe/tz7+tEJwijnUCBCp0bB/0YwL6/vrB4eWKm2vFxVtdhRSJ3/CSGIaXrUtJVqvsbaNNA9vAvtiQ7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730295887; c=relaxed/simple; bh=lyFd5Qy9b/diKvMLRhapoJ8Lj/FcZgWn8uTxreNufZw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MD10mD2OtWsQ0azCvt/Suc6eQgj/h5mjvs7LBrM2H9Ip5IHIKoOe6lXWLWg/N8slSS0qGN9ucmZn20TFWKNwgnyokBOL+x95D/pZumOmSMvK8KdHhDcnXYOC1d0NAbXq2pX1nAyJ4+pjp1e2GCj0xN87C7SA7tuOep6ka0TxQRU= 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=TBgdcrxG; arc=none smtp.client-ip=209.85.128.43 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="TBgdcrxG" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4314f38d274so84629045e9.1 for ; Wed, 30 Oct 2024 06:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1730295882; x=1730900682; 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=dSM1H9kQmZbNYjD2c9OgvWRYm0lRsPAWlbXFXQCdhuI=; b=TBgdcrxGvba4ZuXK1SG4WM1YUxazRDtpDYxoXKL7TRfX6ZAiU4r7bMf8v8bqSEx0oT VmyW9rXK6aNs/UgHRK8+V/FQapyXY1yuAF/Bqqznx9muE+DCuTkU3mu/fg46W7Dk1zT/ C0WF2WjKE+6zO9W5JRvpzZo+bYhwkIi47w1G9gIILHNnhQFwS9Ych5dDtd7v0REdTV8f 6jj57+WYIC3Mt3FLU5Mcwq76dy2ClU/6DBIRbLnV6lyRx9uc6C7OibbaT3eukzI29iEw IEC+mMtjB+v5RqZ4tZWJZHEeGWLEUCGQ09GUxYq9+WaiFA3DbS4kdUJOuPWG/ZKywZJ/ 2T9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730295882; x=1730900682; 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=dSM1H9kQmZbNYjD2c9OgvWRYm0lRsPAWlbXFXQCdhuI=; b=SUg41lIG8LhCiIigoGIgSLaaHfGcWU9sozaM0L49Y2fiQ80P/l+jdQweb9Dn8MEMf0 NGiTkadHUxN01/ULkHDVMqTMBoAIneSgrfVR1mjLLrxDIqPBDF0TwAtAOK9MluZSr3S6 squXd59AIBzw5aEjEr3cELMxL44TIVBYSrsbMFXSLygmeD8VA0jKYrXyvjZU6caYSs5S TVDgHIbNZj8x9kKImMFptGFMSWUIu9BdS7uBMuGNE6BfO+8ORTN/omlphKGtjJkb1g9Q uq4Ayud8OOTCb1C1OQzjUR+sobosfzQ7GGQPScwTV8pzDrG/e+Z4qMDTwaqyAKN6lnGY vy1A== X-Forwarded-Encrypted: i=1; AJvYcCWcTwr0AO6Ixtg1C+AxNDZ8X1XLvUy9xjtnM5oD6O7w8PSu21Df0H6nkaEwPa/7UWjzO74quKgv1wbQLG4=@vger.kernel.org X-Gm-Message-State: AOJu0YzW0clU82csK4uaK3HEGPWyCOIVYcJc7FPt9EADUH+1RXxo6/xO 8c23K83B78FSTPAW3AdEiQgJyHPRI22e3CvPuVqchRWsCKllOBxocdZc4lK+5Os= X-Google-Smtp-Source: AGHT+IE2n8u+e+ZREW1BpdcgVl/9aw+yhcg+q8JpfH04yUN5XBE8lhFyGFOGAUTC9j2X67KQA3sBlg== X-Received: by 2002:a05:600c:4f4a:b0:431:4b88:d407 with SMTP id 5b1f17b1804b1-4319ac6f874mr169681245e9.5.1730295882572; Wed, 30 Oct 2024 06:44:42 -0700 (PDT) Received: from [192.168.1.62] (2a02-842a-d52e-6101-6f8f-5617-c4b6-8627.rev.sfr.net. [2a02:842a:d52e:6101:6f8f:5617:c4b6:8627]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd97d693sm22135175e9.24.2024.10.30.06.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 06:44:42 -0700 (PDT) From: Julien Stephan Date: Wed, 30 Oct 2024 14:44:29 +0100 Subject: [PATCH v4 5/5] docs: iio: ad7380: add adaq4370-4 and adaq4380-4 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: <20241030-ad7380-add-adaq4380-4-support-v4-5-864ff02babae@baylibre.com> References: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> In-Reply-To: <20241030-ad7380-add-adaq4380-4-support-v4-0-864ff02babae@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , David Lechner , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Julien Stephan X-Mailer: b4 0.14.2 Adding documentation for adaq4370-4 and adaq4380-4 supported devices. In particular, document the reference voltage mechanism and the gain parameter that are specific to adaq devices. Signed-off-by: Julien Stephan Reviewed-by: David Lechner --- Documentation/iio/ad7380.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/iio/ad7380.rst b/Documentation/iio/ad7380.rst index 6f70b49b9ef27c1ac32acaefecd1146e5c8bd6cc..1b9777c33e0c3e9e06f72d7c957= a012346d4a26a 100644 --- a/Documentation/iio/ad7380.rst +++ b/Documentation/iio/ad7380.rst @@ -27,6 +27,8 @@ The following chips are supported by this driver: * `AD7386-4 `_ * `AD7387-4 `_ * `AD7388-4 `_ +* `ADAQ4370-4 `_ +* `ADAQ4380-4 `_ =20 =20 Supported features @@ -47,6 +49,12 @@ ad7380-4 ad7380-4 supports only an external reference voltage (2.5V to 3.3V). It mu= st be declared in the device tree as ``refin-supply``. =20 +ADAQ devices +~~~~~~~~~~~~ + +adaq4370-4 and adaq4380-4 don't have an external reference, but use a 3V +internal reference derived from one of its supplies (``refin-supply``) + All other devices from ad738x family ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ =20 @@ -121,6 +129,14 @@ Example for AD7386/7/8 (2 channels parts): =20 When enabling sequencer mode, the effective sampling rate is divided by tw= o. =20 +Gain (ADAQ devices only) +~~~~~~~~~~~~~~~~~~~~~~~~ + +ADAQ devices have a pin selectable gain in front of each ADC. The appropri= ate +gain is selectable from device tree using the ``adi,gain-milli`` property. +Refer to the typical connection diagrams section of the datasheet for pin +wiring. + Unimplemented features ---------------------- =20 --=20 2.47.0