From patchwork Tue Feb 20 15:34:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ceclan, Dumitru" X-Patchwork-Id: 13564174 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 F28E1762C1; Tue, 20 Feb 2024 15:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443363; cv=none; b=R0cO1Z1WUAW7RwDDxQ2OeOHuyLhD2QJNmxSyFHmtK1g2W1tu8b9sFKCYZ5VpKGYjgXD02exe4xGAvM+P9KypXWaeUDOihXxz8Xlo7pCVGMH6Qke/74/vWtBxvRN6mYgv87xuVUmSCROOxphx4HEMQhsZYygPDiFqEkBqtXGLBto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443363; c=relaxed/simple; bh=lL9tEj72B8RLSGVKGJnXqHrnROs1OMlmSlpmLn/ellk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MBTPNhUEUpAjuBPpZT2DTU6n5QxExUr9pgkPvJX83wYuyHrzqbeQVSuGcppMceU9KomN02ePremnEBXhoRU+jF5JjIpcuabKp2jje8kX/QTkjBq3iP/mKY88PN20pTJHXowEHCRj+sOmLdh2tAGt1tY78U2LCkc1/Ds6DHkHwqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kTqAR25f; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kTqAR25f" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a3d5e77cfbeso976900066b.0; Tue, 20 Feb 2024 07:36:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708443360; x=1709048160; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6wlAJ3HOeN+i9mwkmiHE0QT6wa1Z9g6FI4uNkE/zgM8=; b=kTqAR25ffcg+gyYO1uYasAd1ngFZxToWo+jE9VEm0+RP8JGl63dKbsJKexDPYKG74T dj33VKV0T2PhTwICCNiWm1TJUq23NA8qX2SMZ6nBCvX+oqPY5OYdSLBXLdKymPgeH0lb Twzshfqsgd82kc3GlfjJ5AvHaHZqD90lH+9Rv77g794bEZsEfcdrglIMLTZQAIX3G5BG JSkOmzDnRg7nRPkJ9heD3Bj3CIKfkPseUj0XzFMI/iYa4Z6E3Uv1v3wWrUqGsobb6oXM uf+dgLTzeloiD5o2CjEp/a6pwQpIUjhVL2KIjbDnggRCZ981XbOB7uO8pmW0tklSdtLa be/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708443360; x=1709048160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6wlAJ3HOeN+i9mwkmiHE0QT6wa1Z9g6FI4uNkE/zgM8=; b=qfLov3+xtxWORa62ZbgVzSiVFK3hfxp9GmSPECYz65ZG0WTej4PlBPr2mYJJ033XVO wESAdGeMH/ytPiJvQzUqBwbibE9nIq3wwqhBsoq3FzeE8zdD/zpX7L+laWd1UHolUsMX 9PnVPvvwNawhq4H9oL3YYsPHfwmXd8f4tbzb3G1hSsotym6dZAoWHgpEvQrFnHocwQjo kFZrLqtMNkG81ZIDumyfL08nSBcHIYPSzjnu95jaXGIcp/jzvRlrkmRicBoxVI2xKyH3 58pMp6tdVaQVpWDBYDh4mZxSSsW6dO8bjzO7Br+TcjK6UpN0n1T2nIqTmUgCBZCiXH2s Cr7g== X-Forwarded-Encrypted: i=1; AJvYcCU0OxMBCDnZ0PxRggrjKGnDf0TUDFFwKm/4iFAc8HWbzhz63iSbGN+BpG0tDsh4ZKmYkOPU2/sdzj7ML8fQfhoNAnXOz9/PoLCTI7lWMdnmXfSiZ1tX6bgHrzzYyrz3rlVqHhDTFOW/bJp7P3tHfxsr+CAI/o9fakQSwRF77a9sCt9KEw== X-Gm-Message-State: AOJu0YxrvpRN+Gu71As4bb+Gb/n4rvcYm9Vfy4zp3yWt5iNaYHD+EHBa hrVwHiJlMuCYtQQD97eMQT8j4kqaabML98ieT1ixd94fK5S8Jm/F X-Google-Smtp-Source: AGHT+IEaEVLVkF6Ocqna7U7WUPQHf22hyEVx9loZfFpXuZ8kcIk2TziFTViujCaF6lqxII4o1vR26A== X-Received: by 2002:a17:906:2786:b0:a3f:1cd:69a5 with SMTP id j6-20020a170906278600b00a3f01cd69a5mr1739507ejc.5.1708443360224; Tue, 20 Feb 2024 07:36:00 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id r22-20020a170906281600b00a3d777aa8fesm4039024ejc.69.2024.02.20.07.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:35:59 -0800 (PST) From: Dumitru Ceclan To: Cc: Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Ceclan Dumitru , Dumitru Ceclan , Conor Dooley Subject: [PATCH v5 1/5] dt-bindings: iio: hmc425a: add conditional GPIO array size constraints Date: Tue, 20 Feb 2024 17:34:50 +0200 Message-ID: <20240220153553.2432-3-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240220153553.2432-1-mitrutzceclan@gmail.com> References: <20240220153553.2432-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ADRF5740 and HMC540S have a 4 bit parallel interface. Update ctrl-gpios description and min/maxItems values depending on the matched compatible to correctly reflect the hardware properties. Fixes: 79f2ff6461e7 ("dt-bindings: iio: hmc425a: add entry for ADRF5740 Attenuator") Fixes: 20f87a9a26be ("dt-bindings: iio: hmc425a: add entry for HMC540S") Acked-by: Conor Dooley Signed-off-by: Dumitru Ceclan --- .../bindings/iio/amplifiers/adi,hmc425a.yaml | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml b/Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml index 67de9d4e3a1d..a434cb8ddcc9 100644 --- a/Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml +++ b/Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml @@ -33,11 +33,38 @@ properties: ctrl-gpios: description: - Must contain an array of 6 GPIO specifiers, referring to the GPIO pins - connected to the control pins V1-V6. - minItems: 6 + Must contain an array of GPIO specifiers, referring to the GPIO pins + connected to the control pins. + ADRF5740 - 4 GPIO connected to D2-D5 + HMC540S - 4 GPIO connected to V1-V4 + HMC425A - 6 GPIO connected to V1-V6 + minItems: 1 maxItems: 6 +allOf: + - if: + properties: + compatible: + contains: + const: adi,hmc425a + then: + properties: + ctrl-gpios: + minItems: 6 + maxItems: 6 + - if: + properties: + compatible: + contains: + anyOf: + - const: adi,adrf5740 + - const: adi,hmc540s + then: + properties: + ctrl-gpios: + minItems: 4 + maxItems: 4 + required: - compatible - ctrl-gpios From patchwork Tue Feb 20 15:34:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ceclan, Dumitru" X-Patchwork-Id: 13564176 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.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 920AA76C82; Tue, 20 Feb 2024 15:36:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443366; cv=none; b=Ja1u6kB4Px/0W9mICEF9AHAYoKrBCCvQzyLocBreEnU4pO5l8mgGYYYeC+Kr3Tho7hB1Z26NJ9ytG92cVsNyhOqykkDaFO+a3d2C1z4u0RV3q4+hGtKo6U7Iwx/zOXtQ2G2AR9vmPOhrQOIBL+KAt6K1IMgHxWSErglZcIsaPcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443366; c=relaxed/simple; bh=WsaD/EyThPxR9x3pk2tU6dkPvkHaD1C0ZLhbybr6sC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jiAh1UBS1/qjdLxbh+6RwHzvGXcsDmIDHsMpenChwuWcl79dosp/LfnlQ5dCFzHVwhRsbeviIpRpjv3kfmRbQy0aGCrzjl2A9eCIJwa6NKAFBTsBxxbBCgE2BzKIQALgCd0I8VkIn0uO2XroXjs0U7FNLeKpx4GBCKnuyklxpFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K7B7vVGk; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K7B7vVGk" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a3e72ec566aso316192366b.2; Tue, 20 Feb 2024 07:36:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708443363; x=1709048163; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3IfByO+2rIcCGnCKsv3npkbJVqHFL3ale3i7+O8UKFk=; b=K7B7vVGkwjptlWsnJ6eRbsJCVdmHsE6imX8jBoM1tEEfCQ9wvkX3Pm6Or+M4lgOUx1 K5JwtHyhJQyANBJe+oyoqTjHzQqLZbtqg5MaBub3svpqY+tim+Sb5YqSnbbxIaidtG7J eiU1HMJ1yg2vzDb/52ci+inAb/d4egVzdU5Ve6rpdhff5IhvT3XpFDIlYwG0s7R6npLE F6/rOJO8UNeujnxp2z59nZCGESfj0UZICRxjYOE+ZvR7QrISHwESRkSV3GhHfylQPomp X6gbHBiTVWNR0ujIlYSDXmnaKm2d97qGLBgak+Ez0rvSby+jXZYGl55qs2yF+6uAs2bl y+iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708443363; x=1709048163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3IfByO+2rIcCGnCKsv3npkbJVqHFL3ale3i7+O8UKFk=; b=KO6WKFyhK4Wj/PPqVIa42PDbUVjbJCdut0sC6YRjrkpO2gZDwQKWqzj+mfNPJLiavN NBvGIXbMKRgPmHxjCDXHMFF4FxarKVdecswdxTRRqlj1sUkWT/jrVjIPSek3yTRnuSVc nvwVsLQoSjfSGP4khAfGo1U9UVVMttFk+ckEVSzxwxLcxzjsWR1T4QdyROVYC2lcJ2qZ aNDmI4jXYOwNpU8cpK1qz7v6+H6WkYTw3BCvSMNaVRIBdrGa1TKAmoIYLy7l3uc+rVQh j9qGgR3PgIjgdT8XuYM/JAL5RKe/kqejHf2yq4X6fqWPjpPIGE8/4d53aFZSEULIHz+o KtDg== X-Forwarded-Encrypted: i=1; AJvYcCW7lBffQMn+fA/IfIrdxzoNR6YMxNVIsr0UZJ0oktbdRivLxL78ALS6Zc0ZcVPiAOOfbN/e4eSg0c/EfXQlGusd3Eal2+KfpQVD5oJUiLifQ8M0s42UQzGngVGJFMEn5fQWUL31m9I0aFgmua8AN5D0VfBMdhEsBU3YLZ3zbxI7miOSBw== X-Gm-Message-State: AOJu0YyXPksqluRfWdHMCZFg2rwncjS99i+JFXlxpIPqH+nv/F2EDbnh Vh7EZwOgaHrsfalZaQ+GEYOZZMDQ8j5tpc4LRXlqc5HY5FlyRSwf X-Google-Smtp-Source: AGHT+IGUTtfOYGzuOrHJz19AccjYRiQJVfFTdBpbx8ugPcjvRuC6KUt66v/WR1iRLaV2gG2IT9Fw3w== X-Received: by 2002:a17:906:55ca:b0:a3e:4c8f:2340 with SMTP id z10-20020a17090655ca00b00a3e4c8f2340mr4633651ejp.61.1708443362727; Tue, 20 Feb 2024 07:36:02 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id r22-20020a170906281600b00a3d777aa8fesm4039024ejc.69.2024.02.20.07.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:36:02 -0800 (PST) From: Dumitru Ceclan To: Cc: Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Ceclan Dumitru , Dumitru Ceclan , Conor Dooley Subject: [PATCH v5 2/5] dt-bindings: iio: hmc425a: add entry for LTC6373 Date: Tue, 20 Feb 2024 17:34:52 +0200 Message-ID: <20240220153553.2432-5-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240220153553.2432-1-mitrutzceclan@gmail.com> References: <20240220153553.2432-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The LTC6373 is a silicon, 3-bit Fully-Differential digital instrumentation amplifier that supports the following programmable gains (Vout/Vin): G = 0.25, 0.5, 1, 2, 4, 8, 16 + Shutdown. Acked-by: Conor Dooley Signed-off-by: Dumitru Ceclan --- .../bindings/iio/amplifiers/adi,hmc425a.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml b/Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml index a434cb8ddcc9..3a470459b965 100644 --- a/Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml +++ b/Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml @@ -21,6 +21,8 @@ description: | HMC540S 1 dB LSB Silicon MMIC 4-Bit Digital Positive Control Attenuator, 0.1 - 8 GHz https://www.analog.com/media/en/technical-documentation/data-sheets/hmc540s.pdf + LTC6373 is a 3-Bit precision instrumentation amplifier with fully differential outputs + https://www.analog.com/media/en/technical-documentation/data-sheets/ltc6373.pdf properties: compatible: @@ -28,6 +30,7 @@ properties: - adi,adrf5740 - adi,hmc425a - adi,hmc540s + - adi,ltc6373 vcc-supply: true @@ -38,6 +41,7 @@ properties: ADRF5740 - 4 GPIO connected to D2-D5 HMC540S - 4 GPIO connected to V1-V4 HMC425A - 6 GPIO connected to V1-V6 + LTC6373 - 3 GPIO connected to A0-A2 minItems: 1 maxItems: 6 @@ -64,6 +68,16 @@ allOf: ctrl-gpios: minItems: 4 maxItems: 4 + - if: + properties: + compatible: + contains: + const: adi,ltc6373 + then: + properties: + ctrl-gpios: + minItems: 3 + maxItems: 3 required: - compatible From patchwork Tue Feb 20 15:34:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ceclan, Dumitru" X-Patchwork-Id: 13564173 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.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 4A00576031; Tue, 20 Feb 2024 15:36:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443363; cv=none; b=Cb3VEZo0+ywVQTTxEcHWKtBeQjby964oLqK0t3pGsbs7NDMI+86AxoFB/WMF5zxZ+Xd/BxytNAV1D+k666kOvfWbHLXW3I3GRwr2uWjdU+cLG3R4c09RsOBPvlNP8BNOO5TxeGIsmkv2KmykX6sj3zNfRxZmThkOWaogLtzexHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443363; c=relaxed/simple; bh=Ci1c8M5BZkBhBCDvDrK0yrzanN8h67rkNcr/H4t+X34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lMlT82sZ6AAFE5X4fTltjudRylJuZ/nSxOJd8Ce2Nk0sfEyUJZeyby0gI+5GH9JmpxSXSdRGngTT+XLlnNIgflJy2CYzKeYzp++zYJONCqVgexwzaGqPKPjti9pEYYMww2px8lMUeXSHGp/fT6D3V70Zo94cH3v+cxNTgGJgD9s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LMLxWeq7; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LMLxWeq7" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-512b42b6697so2643479e87.1; Tue, 20 Feb 2024 07:36:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708443359; x=1709048159; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DrQxLajP2KRm+hEcTrLRUd6tk//QuwVaoXrLr/ObD7Y=; b=LMLxWeq79yiPso0QKr2EENtf9qwtoaZsI37ipBv17BAMXXyI6gWnZJ11LFVLjM+CMG 4Y8wItNStMa5lkp2eDeZD0ZULlqYAMwVFfYc0A5S3+aoB251Itq0E/zmM6TG39uKhLJl 4C1WreEjZ99kDWhPvls2sXcN1If4J2mHPyJaiVBOy42hUsC2Oq9wLoLHSOGovcphLCrx p/PVyUIREgv//OEDQe7iQv/Y6+fKfQut9csdMEXfT8jkeq5l1h84Z4mW54eJ6Vtf3u6n cGpiEZ9dX8dLcBWZviIPULcFCQZJ6mJekiRl9e7oKVZdXYBBMpdgziUW+4olclEqwx6J EdZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708443359; x=1709048159; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DrQxLajP2KRm+hEcTrLRUd6tk//QuwVaoXrLr/ObD7Y=; b=wzTYb/Fqd4Vyi+uCkRe3cat9ySG+m4ofddlvkCM1rU44XncGQAQaAJpNtjOaFO3Rge oIsFu/wCtyoPQ7bYdOvExumcFIQSMeSKUyaHFtuNa4BP5NzA1hmJQcSiA6R9lSwY1Wp2 3qpAlhrrP0xd7RTo1MfXDnnq+ndzJoU8xCLBdXXg0VhEVWLO5RBpsCTEhSY09hxWfI3N TkO3smpqFKhfFQqbU9cq5lPHldqpiMmaO4qceZS6sdvz9KVPYDQQ1P9cYAq4lBsLlATv LcMQ/7aSl5ZIrQIH8U8vhJiN0h4yVlsd6MS8+6/Ib1C3MyiE1MuXy48cSQWIeWV4B+aH 6Zfw== X-Forwarded-Encrypted: i=1; AJvYcCX39Dp23xN3dV8zTwnFkFFfgUTiVDVWrGE/20x6GozGz06sjHQ1Wl8dNXEkC2lbLZqgi7UjDx5l7eF1tTgvGe0fT189/vmYVl/cZF5aoXyoBmILq4j5fHDy/RfVpmSpqdojMAdiQg23uk0iQb9Oq1s2xgvK5v2bkhsD7MuzUlYEN9VQ+g== X-Gm-Message-State: AOJu0YzdkY2fmeLuF9rNceOHSNASixjaRLyLGno9xeq6ZAQHEXc4nGdj HFeTtirxbCjm6wkle+F8LzRJvjDwiF+tPP2VJTC5puBjXL9ywBhK X-Google-Smtp-Source: AGHT+IGRWNUV75vSG1KgSddGcHi0L+Lpflmoqp0Sc3b66p2c5wGhchaY3zWjTWl5DCO7wrtz97LPGQ== X-Received: by 2002:a05:6512:200d:b0:512:8a57:d0b5 with SMTP id a13-20020a056512200d00b005128a57d0b5mr8675777lfb.16.1708443358826; Tue, 20 Feb 2024 07:35:58 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id r22-20020a170906281600b00a3d777aa8fesm4039024ejc.69.2024.02.20.07.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:35:58 -0800 (PST) From: Dumitru Ceclan To: Cc: Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Ceclan Dumitru , Dumitru Ceclan Subject: [PATCH v5 3/5] iio: amplifiers: hmc425a: move conversion logic Date: Tue, 20 Feb 2024 17:34:49 +0200 Message-ID: <20240220153553.2432-2-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240220153553.2432-1-mitrutzceclan@gmail.com> References: <20240220153553.2432-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move gain-dB<->code conversion logic from read_raw and write_raw to chip_info callbacks. Signed-off-by: Dumitru Ceclan Reviewed-by: Nuno Sa --- drivers/iio/amplifiers/hmc425a.c | 126 ++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 43 deletions(-) diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c index ed4d72922696..13e018a59637 100644 --- a/drivers/iio/amplifiers/hmc425a.c +++ b/drivers/iio/amplifiers/hmc425a.c @@ -34,6 +34,9 @@ struct hmc425a_chip_info { int gain_min; int gain_max; int default_gain; + + int (*gain_dB_to_code)(int gain, int *code); + int (*code_to_gain_dB)(int code, int *val, int *val2); }; struct hmc425a_state { @@ -44,6 +47,74 @@ struct hmc425a_state { u32 gain; }; +static int gain_dB_to_code(struct hmc425a_state *st, int val, int val2, int *code) +{ + struct hmc425a_chip_info *inf = st->chip_info; + int gain; + + if (val < 0) + gain = (val * 1000) - (val2 / 1000); + else + gain = (val * 1000) + (val2 / 1000); + + if (gain > inf->gain_max || gain < inf->gain_min) + return -EINVAL; + + return st->chip_info->gain_dB_to_code(gain, code); +} + +static int hmc425a_gain_dB_to_code(int gain, int *code) +{ + *code = ~((abs(gain) / 500) & 0x3F); + return 0; +} + +static int hmc540s_gain_dB_to_code(int gain, int *code) +{ + *code = ~((abs(gain) / 1000) & 0xF); + return 0; +} + +static int adrf5740_gain_dB_to_code(int gain, int *code) +{ + int temp = (abs(gain) / 2000) & 0xF; + + /* Bit [0-3]: 2dB 4dB 8dB 8dB */ + *code = temp & BIT(3) ? temp | BIT(2) : temp; + return 0; +} + +static int code_to_gain_dB(struct hmc425a_state *st, int *val, int *val2) +{ + return st->chip_info->code_to_gain_dB(st->gain, val, val2); +} + +static int hmc425a_code_to_gain_dB(int code, int *val, int *val2) +{ + *val = (~code * -500) / 1000; + *val2 = ((~code * -500) % 1000) * 1000; + return 0; +} + +static int hmc540s_code_to_gain_dB(int code, int *val, int *val2) +{ + *val = (~code * -1000) / 1000; + *val2 = ((~code * -1000) % 1000) * 1000; + return 0; +} + +static int adrf5740_code_to_gain_dB(int code, int *val, int *val2) +{ + /* + * Bit [0-3]: 2dB 4dB 8dB 8dB + * When BIT(3) is set, unset BIT(2) and use 3 as double the place value + */ + code = code & BIT(3) ? code & ~BIT(2) : code; + *val = (code * -2000) / 1000; + *val2 = ((code * -2000) % 1000) * 1000; + return 0; +} + static int hmc425a_write(struct iio_dev *indio_dev, u32 value) { struct hmc425a_state *st = iio_priv(indio_dev); @@ -61,30 +132,14 @@ static int hmc425a_read_raw(struct iio_dev *indio_dev, int *val2, long m) { struct hmc425a_state *st = iio_priv(indio_dev); - int code, gain = 0; int ret; mutex_lock(&st->lock); switch (m) { case IIO_CHAN_INFO_HARDWAREGAIN: - code = st->gain; - - switch (st->type) { - case ID_HMC425A: - gain = ~code * -500; - break; - case ID_HMC540S: - gain = ~code * -1000; + ret = code_to_gain_dB(st, val, val2); + if (ret) break; - case ID_ADRF5740: - code = code & BIT(3) ? code & ~BIT(2) : code; - gain = code * -2000; - break; - } - - *val = gain / 1000; - *val2 = (gain % 1000) * 1000; - ret = IIO_VAL_INT_PLUS_MICRO_DB; break; default: @@ -100,36 +155,15 @@ static int hmc425a_write_raw(struct iio_dev *indio_dev, int val2, long mask) { struct hmc425a_state *st = iio_priv(indio_dev); - struct hmc425a_chip_info *inf = st->chip_info; - int code = 0, gain; - int ret; - - if (val < 0) - gain = (val * 1000) - (val2 / 1000); - else - gain = (val * 1000) + (val2 / 1000); - - if (gain > inf->gain_max || gain < inf->gain_min) - return -EINVAL; - - switch (st->type) { - case ID_HMC425A: - code = ~((abs(gain) / 500) & 0x3F); - break; - case ID_HMC540S: - code = ~((abs(gain) / 1000) & 0xF); - break; - case ID_ADRF5740: - code = (abs(gain) / 2000) & 0xF; - code = code & BIT(3) ? code | BIT(2) : code; - break; - } + int code = 0, ret; mutex_lock(&st->lock); switch (mask) { case IIO_CHAN_INFO_HARDWAREGAIN: + ret = gain_dB_to_code(st, val, val2, &code); + if (ret) + break; st->gain = code; - ret = hmc425a_write(indio_dev, st->gain); break; default: @@ -189,6 +223,8 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { .gain_min = -31500, .gain_max = 0, .default_gain = -0x40, /* set default gain -31.5db*/ + .gain_dB_to_code = hmc425a_gain_dB_to_code, + .code_to_gain_dB = hmc425a_code_to_gain_dB, }, [ID_HMC540S] = { .name = "hmc540s", @@ -198,6 +234,8 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { .gain_min = -15000, .gain_max = 0, .default_gain = -0x10, /* set default gain -15.0db*/ + .gain_dB_to_code = hmc540s_gain_dB_to_code, + .code_to_gain_dB = hmc540s_code_to_gain_dB, }, [ID_ADRF5740] = { .name = "adrf5740", @@ -207,6 +245,8 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { .gain_min = -22000, .gain_max = 0, .default_gain = 0xF, /* set default gain -22.0db*/ + .gain_dB_to_code = adrf5740_gain_dB_to_code, + .code_to_gain_dB = adrf5740_code_to_gain_dB, }, }; From patchwork Tue Feb 20 15:34:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ceclan, Dumitru" X-Patchwork-Id: 13564175 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 8691A76C68; Tue, 20 Feb 2024 15:36:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443365; cv=none; b=jfjXeE8T+10NEKBdFUn4qTHBGwobmv3WH2XgU+r4w75yRna4MyHevysaB96uL0R4biUOSUWybXlT+afadq6Iqq+Sb+k52hZPSlIiOj/J2dBjkxCFkkt8nuUgHgZuow2pFGBpYMVi0V+GxNnbL6XV8VZhGkgydthMBdBZrJxTW8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443365; c=relaxed/simple; bh=IiDK8yjRUxAAf2eafMvrRy3vAP1cD3YZP0awk3yNZro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QMSyGj2e/kcOeV8afhoHnFGFxxIs631KMkdtWESZNefxBI3X+NvnfNsWfmvvV8b6Z+KG2+f1cUWvXJCRhwoUW9p7tEXKKOSSejt6BiGbTdfT4ezO7Y8vf9vPo7XFbYrEMQQYbevfzZP8oR36soy0nZbSqCOsB2Hrz3Zyi99Ci0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bYsQRekN; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bYsQRekN" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a3e8c1e4aa7so247033166b.2; Tue, 20 Feb 2024 07:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708443362; x=1709048162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sSirVdQH3Tykgt6W5khgr86vPv5b/vVw8tafLC16Tz8=; b=bYsQRekNegqaLcx5k2y/G9jVKd55Pp4MnUD+lErY0k23fkE9LJ6nufjgiz2P7oYrYa 873AAP3Vnp0GOpR+YLd/S2m6ZCbuVRa+N5I2eSMZImlUxZ4qG0vVYz268Y37fYuhWWjY fjmqVX49eTV7HUACwwcF6flMjVhIpv8CyqsiJV3n2POR6gOxCRRZVVNaMs7gHnfK7Vg+ jZSaofI7PCkz+HZjvAGfktvGmeVnsgNBzwxOQStKBkqQwZT8SIgDMSUCHWuKukUovUbI BbEf/b5GjE0eXrSqEbVwwQ7PWuGShTwNwHp7p5br7PtVIOjH2ZJsBCZN/JYRoyBXJhVB MPLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708443362; x=1709048162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sSirVdQH3Tykgt6W5khgr86vPv5b/vVw8tafLC16Tz8=; b=erhYpvcRVJfQPVyv/6dTf1ihO1C0zbqeQ64JpY0dHCBOv0wQMnSk0cyVBSvCMxMgFb igxSqgwkM2tLGuBNmmO6qVPkCHKi/LTK4wkuoJVAuBFCwvOp1SjOXjgDtBnKOiJxgSO3 JOEHyYrvOM1mixALRXaZxHi+yEEoZ8zVc5cvku/qrztgpiJcDFxJQGDnu/zthrx9MRyb 8eUMQ9aYLZkqyNGE+LbFpzzB7BOqReVVocOtmdbn4acYnhmmLIL3C3saqUDLjQfvX5Rt c19mDjXprLcgbxsNTJAMy6O97v1ziZbpnYQfckhxzcx4b424Fvwdt3vAlOjCG8ITM0bZ QteQ== X-Forwarded-Encrypted: i=1; AJvYcCXqNx4yvio74leN/N8JVxFqtFwc6j7nLSs03QmPx0a+8uVWqenBbPm3GJN4aKRp2KK9XO1rhu6WbR+mpr/ZHEmnE3jOcBx0UYG6ZvILk9+xh30WOkZUmlZcS1Yqt2fAhwuzTihMr22zlB6f8ZF8wwXuhKMQP6Sl3HApmUtRZSqO2dbUmw== X-Gm-Message-State: AOJu0YzGswmT3+QdFWB1S7mZPQVybW/Q7GWftUK0VhGuppZwQmkUsFJA TND3sMromm8IvoOoEkDUHdXaXEkZecPhIwZrZ2XH1AbxmmFYXDTYyJiHeGbSI35RurRa X-Google-Smtp-Source: AGHT+IHRV+GuDs3DqGt4SME+xZgCY62LQ+Goz0qze+WwzKZBwCPcFmieVPunxTRVi7O1WAixQyzshg== X-Received: by 2002:a17:906:7f1a:b0:a3f:c10:4355 with SMTP id d26-20020a1709067f1a00b00a3f0c104355mr1275849ejr.26.1708443361447; Tue, 20 Feb 2024 07:36:01 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id r22-20020a170906281600b00a3d777aa8fesm4039024ejc.69.2024.02.20.07.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:36:01 -0800 (PST) From: Dumitru Ceclan To: Cc: Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Ceclan Dumitru , Dumitru Ceclan Subject: [PATCH v5 4/5] iio: amplifiers: hmc425a: use pointers in match table Date: Tue, 20 Feb 2024 17:34:51 +0200 Message-ID: <20240220153553.2432-4-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240220153553.2432-1-mitrutzceclan@gmail.com> References: <20240220153553.2432-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Change the match table to use pointers instead of device ids. Remove type from state as it is not used anymore. Signed-off-by: Dumitru Ceclan Reviewed-by: Nuno Sa --- drivers/iio/amplifiers/hmc425a.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c index 13e018a59637..77872e2dfdfe 100644 --- a/drivers/iio/amplifiers/hmc425a.c +++ b/drivers/iio/amplifiers/hmc425a.c @@ -41,15 +41,14 @@ struct hmc425a_chip_info { struct hmc425a_state { struct mutex lock; /* protect sensor state */ - struct hmc425a_chip_info *chip_info; + const struct hmc425a_chip_info *chip_info; struct gpio_descs *gpios; - enum hmc425a_type type; u32 gain; }; static int gain_dB_to_code(struct hmc425a_state *st, int val, int val2, int *code) { - struct hmc425a_chip_info *inf = st->chip_info; + const struct hmc425a_chip_info *inf = st->chip_info; int gain; if (val < 0) @@ -205,15 +204,6 @@ static const struct iio_chan_spec hmc425a_channels[] = { HMC425A_CHAN(0), }; -/* Match table for of_platform binding */ -static const struct of_device_id hmc425a_of_match[] = { - { .compatible = "adi,hmc425a", .data = (void *)ID_HMC425A }, - { .compatible = "adi,hmc540s", .data = (void *)ID_HMC540S }, - { .compatible = "adi,adrf5740", .data = (void *)ID_ADRF5740 }, - {}, -}; -MODULE_DEVICE_TABLE(of, hmc425a_of_match); - static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { [ID_HMC425A] = { .name = "hmc425a", @@ -261,9 +251,8 @@ static int hmc425a_probe(struct platform_device *pdev) return -ENOMEM; st = iio_priv(indio_dev); - st->type = (uintptr_t)device_get_match_data(&pdev->dev); - st->chip_info = &hmc425a_chip_info_tbl[st->type]; + st->chip_info = device_get_match_data(&pdev->dev); indio_dev->num_channels = st->chip_info->num_channels; indio_dev->channels = st->chip_info->channels; indio_dev->name = st->chip_info->name; @@ -295,6 +284,18 @@ static int hmc425a_probe(struct platform_device *pdev) return devm_iio_device_register(&pdev->dev, indio_dev); } +/* Match table for of_platform binding */ +static const struct of_device_id hmc425a_of_match[] = { + { .compatible = "adi,hmc425a", + .data = &hmc425a_chip_info_tbl[ID_HMC425A]}, + { .compatible = "adi,hmc540s", + .data = &hmc425a_chip_info_tbl[ID_HMC540S]}, + { .compatible = "adi,adrf5740", + .data = &hmc425a_chip_info_tbl[ID_ADRF5740]}, + {} +}; +MODULE_DEVICE_TABLE(of, hmc425a_of_match); + static struct platform_driver hmc425a_driver = { .driver = { .name = KBUILD_MODNAME, From patchwork Tue Feb 20 15:34:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ceclan, Dumitru" X-Patchwork-Id: 13564177 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.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 2938E77625; Tue, 20 Feb 2024 15:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443368; cv=none; b=HUGkIu8NLKXKggUyHN2IwPXcdvGB/4lIn0p54p0zYwW0PYFQfvgT4iq7wxh7RjMlinhOxZvCAFTRpPwBEN0VxRMrAgb/ZNQoxmXKDsW6roncZGoAErxnJ3ldH5HYrlIKQlJMo4XME97OEYk1oaWCwaS3kyg+AO0MZbcagBaYub4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443368; c=relaxed/simple; bh=yngViWPOAMHAODTTAwgLH5RffJRA3vHYGb/gjQx44BA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QN7GKtoX+dGvsHYMkcGA8hxRL7bacb9StkJDJoXCa5Mmj4KhQKu+fSEEuGMSzE5/XbqJTFvLcf1vtBhh4tteC2wUw38tAk3YToWQ5GrdiCMpylsApjX28D5vsBNvIVnWFc0/qoD1cqpg72kGCUlq7YfpcNduyRmNSsRrvbMzx6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=e+DntWSc; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e+DntWSc" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-564d9b0e96dso706754a12.2; Tue, 20 Feb 2024 07:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708443364; x=1709048164; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=geyL8OfscOjPv2YlXwfaUvMZU6dkavwR22sE4+gZy1A=; b=e+DntWScsguJci0a0JpZECFHbaTgHAckoXtbSdNvSMvbmRL/SrH218OgmAdETxiofY K3+8lLN0XV4k8n0fNgSXjPS8S+muVjlPiEOgT03meAPZuvBb7JG2Apu30+w4ozZg2kSW u6rAisvA2HnczDzJF9KUbNV94IwiTocpcer94ZWZmyWd+HNGudSqw8npYubNlnzii5We ckCs2G1Ly5FFUq5mXOCFFfXAkKnB8tIVLtQg+HDrtN9oKNsSInm+DQ9sBj1k5/ir0ae8 5HsoLekMEdJIO0tCuGOc/lDvznwJyWxWNkovi25VNuqCDd+aQhpxrc/7Rmh1j8tGfcuH KQRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708443364; x=1709048164; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=geyL8OfscOjPv2YlXwfaUvMZU6dkavwR22sE4+gZy1A=; b=Epf/jzBqEi0qrBilTsD1fVWSMOA5TkQpJKkEqznh8F2F8NuD0IbnCo2rRfCPmfDKTa ZKpUFt8TtEuhC3Z8dWAipmHiUI+QR8NrvP4dl2vjT0EE1IW15vych1MnVmgxtr47qAhF 8mMmkb4cWD1/8m5p8abNc/eAX4TpNmACsI8Dvruke/6FOTlpS9XMzZZSWWYhoUmo8xVe l0qCpEes5y7PriCto2GFAvUmuZw8Ol2SqzC8mYcctriaV4tRBH7T08V+lTJTpmrGIo7p LHmJQOv+RP4uZF8WIB0Ph5guCcsouMdMAhOmWXo+TO7TqP2GRKfXXOP0Wx3uLnKQdVLV 94Pw== X-Forwarded-Encrypted: i=1; AJvYcCUBDsJPsvPVAKNU79NNaRL2n8C64YQTmUHXjoYpl1WLKkBxywxMvkRfzAwnXn3B5sjTloOecXNHth0Pe+dpPFtJqZma+6nSsuHS/0eWxgJIdm0kpcUyeGJa3Pu8zOkV2XfHDAj0RFuwdTC9QCjRt3Ob1d9BbzDbIh8eS+/hHbVfemFeJA== X-Gm-Message-State: AOJu0YzaiXbphNxr/8DUqJC5VV4bY8XJnRFS/MkpAWJjzBPbNmVLgQ9u k5MjuTuQMaY8VH7VhTctMtDOfV1xwaQg3yADrnb4uIQYuFSiuiorod7LEGqQUa+h3hIY X-Google-Smtp-Source: AGHT+IGLMDm3ARrwgLRHtJQorhTGCrr++X65+2urQqfqV1DRT2pDJexdtFgo/FBtACLc10UWEePyIA== X-Received: by 2002:a17:906:2a90:b0:a3e:1a96:a22c with SMTP id l16-20020a1709062a9000b00a3e1a96a22cmr6049808eje.38.1708443364117; Tue, 20 Feb 2024 07:36:04 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id r22-20020a170906281600b00a3d777aa8fesm4039024ejc.69.2024.02.20.07.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:36:03 -0800 (PST) From: Dumitru Ceclan To: Cc: Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Ceclan Dumitru , Dumitru Ceclan Subject: [PATCH v5 5/5] iio: amplifiers: hmc425a: add support for LTC6373 Instrumentation Amplifier Date: Tue, 20 Feb 2024 17:34:53 +0200 Message-ID: <20240220153553.2432-6-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240220153553.2432-1-mitrutzceclan@gmail.com> References: <20240220153553.2432-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This adds support for LTC6373 36 V Fully-Differential Programmable-Gain Instrumentation Amplifier with 25 pA Input Bias Current. The user can program the gain to one of seven available settings through a 3-bit parallel interface (A2 to A0). Signed-off-by: Dumitru Ceclan Reviewed-by: Nuno Sa --- drivers/iio/amplifiers/hmc425a.c | 124 ++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 4 deletions(-) diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c index 77872e2dfdfe..50c86c2d28d7 100644 --- a/drivers/iio/amplifiers/hmc425a.c +++ b/drivers/iio/amplifiers/hmc425a.c @@ -2,9 +2,10 @@ /* * HMC425A and similar Gain Amplifiers * - * Copyright 2020 Analog Devices Inc. + * Copyright 2020, 2024 Analog Devices Inc. */ +#include #include #include #include @@ -12,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -20,10 +22,24 @@ #include #include +/* + * The LTC6373 amplifier supports configuring gain using GPIO's with the following + * values (OUTPUT_V / INPUT_V): 0(shutdown), 0.25, 0.5, 1, 2, 4, 8, 16 + * + * Except for the shutdown value, all can be converted to dB using 20 * log10(x) + * From here, it is observed that all values are multiples of the '2' gain setting, + * with the correspondent of 6.020dB. + */ +#define LTC6373_CONVERSION_CONSTANT 6020 +#define LTC6373_MIN_GAIN_CODE 0x6 +#define LTC6373_CONVERSION_MASK GENMASK(2, 0) +#define LTC6373_SHUTDOWN GENMASK(2, 0) + enum hmc425a_type { ID_HMC425A, ID_HMC540S, - ID_ADRF5740 + ID_ADRF5740, + ID_LTC6373, }; struct hmc425a_chip_info { @@ -34,6 +50,8 @@ struct hmc425a_chip_info { int gain_min; int gain_max; int default_gain; + int powerdown_val; + bool has_powerdown; int (*gain_dB_to_code)(int gain, int *code); int (*code_to_gain_dB)(int code, int *val, int *val2); @@ -44,6 +62,7 @@ struct hmc425a_state { const struct hmc425a_chip_info *chip_info; struct gpio_descs *gpios; u32 gain; + bool powerdown; }; static int gain_dB_to_code(struct hmc425a_state *st, int val, int val2, int *code) @@ -58,6 +77,8 @@ static int gain_dB_to_code(struct hmc425a_state *st, int val, int val2, int *cod if (gain > inf->gain_max || gain < inf->gain_min) return -EINVAL; + if (st->powerdown) + return -EPERM; return st->chip_info->gain_dB_to_code(gain, code); } @@ -83,8 +104,17 @@ static int adrf5740_gain_dB_to_code(int gain, int *code) return 0; } +static int ltc6373_gain_dB_to_code(int gain, int *code) +{ + *code = ~(DIV_ROUND_CLOSEST(gain, LTC6373_CONVERSION_CONSTANT) + 3) + & LTC6373_CONVERSION_MASK; + return 0; +} + static int code_to_gain_dB(struct hmc425a_state *st, int *val, int *val2) { + if (st->powerdown) + return -EPERM; return st->chip_info->code_to_gain_dB(st->gain, val, val2); } @@ -114,6 +144,16 @@ static int adrf5740_code_to_gain_dB(int code, int *val, int *val2) return 0; } +static int ltc6373_code_to_gain_dB(int code, int *val, int *val2) +{ + int gain = ((~code & LTC6373_CONVERSION_MASK) - 3) * + LTC6373_CONVERSION_CONSTANT; + + *val = gain / 1000; + *val2 = (gain % 1000) * 1000; + return 0; +} + static int hmc425a_write(struct iio_dev *indio_dev, u32 value) { struct hmc425a_state *st = iio_priv(indio_dev); @@ -191,6 +231,48 @@ static const struct iio_info hmc425a_info = { .write_raw_get_fmt = &hmc425a_write_raw_get_fmt, }; +static ssize_t ltc6373_read_powerdown(struct iio_dev *indio_dev, + uintptr_t private, + const struct iio_chan_spec *chan, + char *buf) +{ + struct hmc425a_state *st = iio_priv(indio_dev); + + return sysfs_emit(buf, "%d\n", st->powerdown); +} + +static ssize_t ltc6373_write_powerdown(struct iio_dev *indio_dev, + uintptr_t private, + const struct iio_chan_spec *chan, + const char *buf, + size_t len) +{ + struct hmc425a_state *st = iio_priv(indio_dev); + bool powerdown; + int code, ret; + + ret = kstrtobool(buf, &powerdown); + if (ret) + return ret; + + mutex_lock(&st->lock); + st->powerdown = powerdown; + code = (powerdown) ? LTC6373_SHUTDOWN : st->gain; + hmc425a_write(indio_dev, code); + mutex_unlock(&st->lock); + return len; +} + +static const struct iio_chan_spec_ext_info ltc6373_ext_info[] = { + { + .name = "powerdown", + .read = ltc6373_read_powerdown, + .write = ltc6373_write_powerdown, + .shared = IIO_SEPARATE, + }, + {} +}; + #define HMC425A_CHAN(_channel) \ { \ .type = IIO_VOLTAGE, \ @@ -200,10 +282,24 @@ static const struct iio_info hmc425a_info = { .info_mask_separate = BIT(IIO_CHAN_INFO_HARDWAREGAIN), \ } +#define LTC6373_CHAN(_channel) \ +{ \ + .type = IIO_VOLTAGE, \ + .output = 1, \ + .indexed = 1, \ + .channel = _channel, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_HARDWAREGAIN), \ + .ext_info = ltc6373_ext_info, \ +} + static const struct iio_chan_spec hmc425a_channels[] = { HMC425A_CHAN(0), }; +static const struct iio_chan_spec ltc6373_channels[] = { + LTC6373_CHAN(0), +}; + static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { [ID_HMC425A] = { .name = "hmc425a", @@ -238,6 +334,19 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { .gain_dB_to_code = adrf5740_gain_dB_to_code, .code_to_gain_dB = adrf5740_code_to_gain_dB, }, + [ID_LTC6373] = { + .name = "ltc6373", + .channels = ltc6373_channels, + .num_channels = ARRAY_SIZE(ltc6373_channels), + .num_gpios = 3, + .gain_min = -12041, /* gain setting x0.25*/ + .gain_max = 24082, /* gain setting x16 */ + .default_gain = LTC6373_MIN_GAIN_CODE, + .powerdown_val = LTC6373_SHUTDOWN, + .has_powerdown = true, + .gain_dB_to_code = ltc6373_gain_dB_to_code, + .code_to_gain_dB = ltc6373_code_to_gain_dB, + }, }; static int hmc425a_probe(struct platform_device *pdev) @@ -278,8 +387,13 @@ static int hmc425a_probe(struct platform_device *pdev) indio_dev->info = &hmc425a_info; indio_dev->modes = INDIO_DIRECT_MODE; - /* Set default gain */ - hmc425a_write(indio_dev, st->gain); + if (st->chip_info->has_powerdown) { + st->powerdown = true; + hmc425a_write(indio_dev, st->chip_info->powerdown_val); + } else { + /* Set default gain */ + hmc425a_write(indio_dev, st->gain); + } return devm_iio_device_register(&pdev->dev, indio_dev); } @@ -292,6 +406,8 @@ static const struct of_device_id hmc425a_of_match[] = { .data = &hmc425a_chip_info_tbl[ID_HMC540S]}, { .compatible = "adi,adrf5740", .data = &hmc425a_chip_info_tbl[ID_ADRF5740]}, + { .compatible = "adi,ltc6373", + .data = &hmc425a_chip_info_tbl[ID_LTC6373]}, {} }; MODULE_DEVICE_TABLE(of, hmc425a_of_match);