From patchwork Wed Jan 17 12:51:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan X-Patchwork-Id: 763794 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 7909E1EA95; Wed, 17 Jan 2024 12:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705495897; cv=none; b=h6ocaOXCi8hYlGnab+NOZGJ+0sT95ZXIGZmG8bAJSCsaMuMN5V/lWGns1i19ZX2+4gljKhFOvkcm3KlHcaXRUf7dW2hOiYhc6/yKcXuBYwI83ueIrsSNnimT37btaf40Pc2mcMulFDeonLCWDWcQvm0ptmguHrzW9cmwfLEUqi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705495897; c=relaxed/simple; bh=lL9tEj72B8RLSGVKGJnXqHrnROs1OMlmSlpmLn/ellk=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; b=c4xuRiqx2dW9Mtn1Dj0KkwzHUS5c0P1e5K/tmayp6+zIrIJwT8gbn5K8CopqyiTTwyYFVK4EBtuAhpy+AjphNo7yxprO5jZp60wqq5ZwlchR0+OYN1K+IDDyLJ647AkvUV5jjrNs3yCIyOjngeEeKxP3mGDmkNDeA0DoiE1F6J8= 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=Mh+I5iMv; arc=none smtp.client-ip=209.85.208.41 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="Mh+I5iMv" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-559edcf25b5so206676a12.1; Wed, 17 Jan 2024 04:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705495894; x=1706100694; 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=Mh+I5iMvSNvaY4REwTAi4lnbDxCjABKEcLYsWUKlmDNMEx/rodjVgMyRjNTqVDP8P+ qvnVkmDFKEBS1ZgIzUs/ES0612miz1RtqkVz5UiHkhvPK6lWPs20JNbALhU3w7PVfaEr jJ7i6WT5dVuyI5+VVFZekNJlh5s5J3dy8PPCT8zUC2nT78cCCafXNRtGQNiuemUDycxG +O0kwFBibcvWuotngoZ/0sQ4YtnsWB9KNR135P3XbOMLpaTtE4pYQw+ep8o9LmNHV+X5 ZgcplO6TNWZCceSyCOtU6+fmWnq+BfEDsUfdpVzZGSiT1EZ9vxMh1fLABtih7y9SC7ub Rdcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705495894; x=1706100694; 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=OohkMb1giU49+RIx5NQjZyl9O92Q1re7q2Ycast2XK7AH4PMqHmN9EOWXKGDhfPdzW g1zVJsA1ITHcwOgVPr7UwuygL00yZxbPbtYdUSv1T5yTwcaPemIblVX21hHGjy/3/NjJ wKiaUCCcZ9JE2ToqbeipDKL8oLbfCUt2RtOYaiu4Khec8eXR2QeIvoMgCdfrkWtpZa2G 8K26bFzRXdICrS67lO725EJ4b/RLal7nRnKcIsp6a973lkC2gS86MHrFBX8UVdtIP3oN HkJkYno+ub5rO3HawDQgniXb7u+baqDxqJrOY7d7dh81pwukTERpS12KdyOEHBbfMjo6 nQwg== X-Gm-Message-State: AOJu0Yy+XI1QOsdKDApk+2CjoiMB8ZyRCcXDUmwO3vOKaQqz60YVPz7P jQiaSPra84IZTFyaXIkhzYA= X-Google-Smtp-Source: AGHT+IHCYD0OV4UlkBBgtGc+mENZgOUND0+EF1UV+VhL+oGPuJHBHlps3jyx1H7klHTDKCqQuBvAog== X-Received: by 2002:a17:907:c9a9:b0:a28:e3b6:a199 with SMTP id uj41-20020a170907c9a900b00a28e3b6a199mr3982628ejc.38.1705495893577; Wed, 17 Jan 2024 04:51:33 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id t13-20020a17090616cd00b00a2ea45637desm1277247ejd.112.2024.01.17.04.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 04:51:33 -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 v4 1/5] dt-bindings: iio: hmc425a: add conditional GPIO array size constraints Date: Wed, 17 Jan 2024 14:51:10 +0200 Message-ID: <20240117125124.8326-2-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240117125124.8326-1-mitrutzceclan@gmail.com> References: <20240117125124.8326-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: devicetree@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 Wed Jan 17 12:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan X-Patchwork-Id: 763387 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.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 E5CD11EB39; Wed, 17 Jan 2024 12:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705495899; cv=none; b=RRJuFWcbA5lpXLlWKRKdo8nPRQiaLWt4hgcPTeAFUI2YsTsH96RFJEb6j3/pRpqI5jykfR3LejOkyQlpmY5irgm3+7IELCzcPIDJdm4LOpTfjzBskvQ0dhAomRpAuMEpywychPcYpt3klunFdUsgpEK5DKDV9Y5UldogadiXen0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705495899; c=relaxed/simple; bh=WsaD/EyThPxR9x3pk2tU6dkPvkHaD1C0ZLhbybr6sC8=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; b=eitDcGQQrz+cZ5JpGAPKgCuZTQLzm3YOrGUk8B0vvw3LtcW4qltnE7KqzExKfbthSz0aKXzDIpC8dH3q5F4qmqPEkLdBuOR/OfDO/XMfb6IObL566t3huFuFpT6km3mm+RapBSfHBn+tzN4g9rGOukoVHR74YVF05wGzvy2hlOY= 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=Ezcnxrcm; arc=none smtp.client-ip=209.85.218.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="Ezcnxrcm" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a2e0be86878so489861366b.1; Wed, 17 Jan 2024 04:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705495895; x=1706100695; 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=Ezcnxrcm8C2PaFJePxqnLErqaae777cBo8yW/kX3vbWpR03EiH2N7Rl+fPfyTwVIhF iHPzPHvpK7ckaudSbp8SuqPTQHf95i34j1d3RmjMNb2PVFnxv1rqYM1pmAPHVXgJkAVY VrLeP8cCpUERuCbovwfIN0GFCxflA5UpHJy0zDqBdm9fl3q9Wyci8+25EELIEXmNbKj7 2FGiPlXqonIkWpTJ8jMSU1mWu0xyrYVGYkc1Xbrd5sLMnz9krEiX1gmv8/hr6UkbWY4W gLoLGWC4RZCxhCMG7bAzXBNvpQ0x2KwshYCCTaI0yJr3OPaYvG5OERN8zJJKYbYaD317 7bcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705495895; x=1706100695; 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=s42DPfl42ISZQm3hnbiA09plA1ti5BnEGxpGhrq91dW96WeP+/hMkdZhhAMt4daHrK +1raY/IAYDdJhri7bXtVXqPNNy7IKWdI68FeVrZlvzaWd9vxQK4Qk1gn761nCGDXxgze hS6l8Kd2gVxaU+nxu5Tj5MP//mIsQDOSL/FO2kb3497cIDISsNn88wD4mgr9WPD/OYbM rNPoHVld0VInZAIxNfqJMpGx4cYJRlLgphgoWqOljlbjjTC5Jrz5MdTdwTeh2FHQv0qe mQVFLDTZkbif427PKw2B0chCVK9GjjQRb2CNxtIw7U28gy8BfkmfyX+jsy5LIKIaaVOB bfMg== X-Gm-Message-State: AOJu0YxYWnJX6J+t/eYwQ2dDx5GJm/mRINQDmNnjAXhS7g1A1w94M6XQ RkrkLtDMpr/dT9Umm5rBjDk3o7zrnQ7dIg== X-Google-Smtp-Source: AGHT+IHT7ZR7hb7FwVUmmfAEiayM5v1oUdDFzCTlbUkFL2t57UwstfbSYx8w9x/i2xHFcv68G7WcBA== X-Received: by 2002:a17:906:a188:b0:a2c:a9c3:e407 with SMTP id s8-20020a170906a18800b00a2ca9c3e407mr769102ejy.29.1705495895158; Wed, 17 Jan 2024 04:51:35 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id t13-20020a17090616cd00b00a2ea45637desm1277247ejd.112.2024.01.17.04.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 04:51:34 -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 v4 2/5] dt-bindings: iio: hmc425a: add entry for LTC6373 Date: Wed, 17 Jan 2024 14:51:11 +0200 Message-ID: <20240117125124.8326-3-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240117125124.8326-1-mitrutzceclan@gmail.com> References: <20240117125124.8326-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: devicetree@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 Wed Jan 17 12:51:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan X-Patchwork-Id: 763793 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 47A891F606; Wed, 17 Jan 2024 12:51:38 +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=1705495899; cv=none; b=VyncjEBSnVOc4YI0JkWuzbWSLiZrt9J2tyqA6jOTztAQsrYjnTNJ4KdYn+FJ5Uqb7zgD26jPAGf4yqS+m+XBSkSAQ49QGq+NrifHHsC7tfH10JJMpJWShO1+lxJZ3NVYn2Tu5ltTPcYIqMVcZKw3dxq21JwC2hKJfRVmjGZ31eM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705495899; c=relaxed/simple; bh=rZdXxZyCEnWFR8TyQNWm4yjCaV4aXUlaTR3kIo+Mdm8=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; b=oB0gIxvdKwfHinL6yLFHIwRT0mm0cRR+we6KeXj6fD3kYuipi9cDauAdMf2PPwlkdWIAi7RTPsIrnz0KxT4D3E3zXOanZbyt4uWL6JE3/1f9k3i++60ZgWcVe94R4XwG6I8lVn31c1Zmai/QN+h8LV6mlzajxSnHoeVb29Q0zhc= 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=NVeGgeS5; 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="NVeGgeS5" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a2cea0563cbso756315366b.3; Wed, 17 Jan 2024 04:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705495896; x=1706100696; 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=L5ZLiXR5kdUypmrHIYtLlSib8TGB/r6oX4cgy4GCPvM=; b=NVeGgeS5vcNO1UBliZCo2INJvYokLcPWcDfRPBv5SEqmC5WhsAuV71dQUK82LI4Vvr +wF18fZKqXg7JnTPKcO/pJ37X4Dg5J6HBFVAtrof+Q2PivqA2YXI76weNZZ0S53JXntK ujaIw/DEUTv1aFzeKDn3awklYmvvfnepyIKkjK5AxMu3cUP6uHuWKWZg4mqGs0Yhb1zE 15AZJqU1xOjGEaqaH9Fswixx5fZ3L8edgCeX7kGh3jufQ+SjCUdc6l1ppcoP1FslKYVx CM7gbpVO6tbBytcZbCFeaO00y0EQXGP9VBOJ+kLlHaI4WdeYuqXo+aDD0hpKZP+ALBjQ HF/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705495896; x=1706100696; 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=L5ZLiXR5kdUypmrHIYtLlSib8TGB/r6oX4cgy4GCPvM=; b=vNaJfudphuQ/XjYXFOglG1RPerCylx/6ig2WsuLiKcJ93eURm7aE0ANjdUgVzHWA89 Xs/42RL8y6Fwj8ZO1MfPSHt7oQQxukBj2HBGWxAu9T/Ocwuklrt0BbeAObeMKppzNBfO YLKwoUDdRozFyxAzAjug/HzuUaoE5/4U3Qvj3Sn+JvjvMhDRwrdOAwoNfaOa+eD7cmja jWkvBOLLyQxK3VICQYdlC0o1GthOfksU0vlHKoWGDIw10CJt83ZEUb+R1Y6B856gP99l CJ+J3crvyA5l20YVifKojkgRKLAddrteW0mphcDW3Nn1d6c+zM+ZFYZmLnaSnyEivBKO NrRw== X-Gm-Message-State: AOJu0YzdquyFb4GpSfW7LzKYYOmXCbiuRB7pyVdpHvxbSStT0jnHhPed 9K3wDxlJkrCXePP5N+H1PInDUrwG4Fc/jw== X-Google-Smtp-Source: AGHT+IF9r/nZwOZ6mVkIlgUhmh2o3dTQNnudOztLr/ghUY3RPJs3BsEw0t1t/thmpn2iH4xPC+l9Dg== X-Received: by 2002:a17:906:30c2:b0:a2c:1061:c648 with SMTP id b2-20020a17090630c200b00a2c1061c648mr4343059ejb.9.1705495896169; Wed, 17 Jan 2024 04:51:36 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id t13-20020a17090616cd00b00a2ea45637desm1277247ejd.112.2024.01.17.04.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 04:51:35 -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 v4 3/5] iio: amplifiers: hmc425a: move conversion logic Date: Wed, 17 Jan 2024 14:51:12 +0200 Message-ID: <20240117125124.8326-4-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240117125124.8326-1-mitrutzceclan@gmail.com> References: <20240117125124.8326-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: devicetree@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 hmc425a_gain_dB_to_code() and hmc425a_code_to_gain_dB(). Signed-off-by: Dumitru Ceclan --- drivers/iio/amplifiers/hmc425a.c | 102 ++++++++++++++++++------------- 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c index ed4d72922696..e1162a500daf 100644 --- a/drivers/iio/amplifiers/hmc425a.c +++ b/drivers/iio/amplifiers/hmc425a.c @@ -56,35 +56,72 @@ static int hmc425a_write(struct iio_dev *indio_dev, u32 value) return 0; } +static int hmc425a_gain_dB_to_code(struct hmc425a_state *st, int val, int val2, int *code) +{ + struct hmc425a_chip_info *inf = st->chip_info; + int gain, temp; + + 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); + return 0; + case ID_HMC540S: + *code = ~((abs(gain) / 1000) & 0xF); + return 0; + case ID_ADRF5740: + temp = (abs(gain) / 2000) & 0xF; + *code = temp & BIT(3) ? temp | BIT(2) : temp; + return 0; + default: + return -EINVAL; + } +} + +static int hmc425a_code_to_gain_dB(struct hmc425a_state *st, int *val, int *val2) +{ + int code, gain; + + code = st->gain; + switch (st->type) { + case ID_HMC425A: + gain = ~code * -500; + break; + case ID_HMC540S: + gain = ~code * -1000; + break; + case ID_ADRF5740: + code = code & BIT(3) ? code & ~BIT(2) : code; + gain = code * -2000; + break; + } + + *val = gain / 1000; + *val2 = (gain % 1000) * 1000; + + return 0; +} + static int hmc425a_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, 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 = hmc425a_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 +137,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 = hmc425a_gain_dB_to_code(st, val, val2, &code); + if (ret) + break; st->gain = code; - ret = hmc425a_write(indio_dev, st->gain); break; default: From patchwork Wed Jan 17 12:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan X-Patchwork-Id: 763386 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 A07831F934; Wed, 17 Jan 2024 12:51:39 +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=1705495901; cv=none; b=bJ7adSoXCMpg2WB1XYIHryKAXDRtiAiZoTrxBfXqmSHBeLdZn2B0JyIOe3niPTdVEJC8IHcPawyq+MyGWzLMce0ltBfA9xtYIHsoiFCLPcmHX+Fk3Fntdy91Y0aRJsQxbyq3rfs4hVJhBH99PgqXg+d3EzinAtCKggE3phRjV1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705495901; c=relaxed/simple; bh=H/rbY7Fk59oQE+dmC0993b4QcnhAD+ZNBlllja1G44A=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; b=jzKJuRcdwekjCkGcUeZNmPT2YXhlGdz9JSZ8i0GqF1I9HhaqSkeRgjKmahFJvACB31Wf0CUFzYzQ7zspXEujV5n1oSw/GktYPOYvkQ/Ajkf+FJ0yDasiAmzZRYAYQaacX6tHQ2CmTFLYMhseyCq70/0HDnt98RkD0VqeDpcl0m4= 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=i1tfevLO; arc=none smtp.client-ip=209.85.167.47 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="i1tfevLO" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-50edf4f478eso9642264e87.3; Wed, 17 Jan 2024 04:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705495897; x=1706100697; 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=Dxr/9CTeqKC0kqg27NYuTzJNXMtNwRstnFwO4ZakeEs=; b=i1tfevLO65lZYhjTUdU+jRL3Jgnf6U4HGzqgW0sX7vkgp0YUaggslAvLqcdkvN5pOa e80OtNA9giqrmPB7ROWOvA0EBxQ59+1kQ05qrImiRJb+p8uU+yV1K8yDAPrkuTGQG7Zk krGg7JKl60g2cPQO+UxdmcbogWIH3RL5WRLM+Mxi0IbQ+xcdBxZZTyM7LTDzhfTXT2Hz Qqk4sMq5nZhq3V6/SQIc732+4tXM7ZJeXbXcYQXPidGrpipTbRk+w4QoAqemehxR36ze Vim7D/wYBmCHgmmzpBylVoqs6GR2Bod1UjAlhxXM0KUXwTm30UrzbL2GHulhGAP29QwU yvKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705495897; x=1706100697; 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=Dxr/9CTeqKC0kqg27NYuTzJNXMtNwRstnFwO4ZakeEs=; b=sraO3M0xvd2fQGwGY0BllUAaGSGZIOom1YO7imN4Ny4OY2G08bkCLvBGtcQ3R2DE2t otY6J9MZGD2yVpY8lIzgsbJygR9YJaYRsbXMN+MCuNnNz04EvltQarZW1KWBY5ovAEW5 NbqQqTzf0XvLSt4UN9irZbmHzuXKZN4lMpKGBdf2PVdBMCjsuLQRM9mWs1+yupNLRxdb GAlw1ovnUHiTPnZOuLyeffexinhBw1ofVxm5rhDU0MTg/CZAOxeefezjjVnFg9SOrcoY v2IAf+AUKuxDm7iQW1ytNHI1CGedWcjUuBgdq70+sKc7kQm9kLDa+7nsypcrh0c5WDRm sIXg== X-Gm-Message-State: AOJu0YxAdwRe5JSMJTFTq+uEFz5d0cmgF5SUSuChAbiIK3uKSoVqRHiI 6flGFgnrKaE9p+AVrL6P6JYCRSIQphkd/g== X-Google-Smtp-Source: AGHT+IFICzlmz3O5aD9LZKZC1UolRUKxilZ8fz0+2YuV5GXF0TnqIzMceEEHZ7RAPrSgse9mGDeAVQ== X-Received: by 2002:a05:6512:1316:b0:50e:bf2f:cfe9 with SMTP id x22-20020a056512131600b0050ebf2fcfe9mr4642193lfu.90.1705495897342; Wed, 17 Jan 2024 04:51:37 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id t13-20020a17090616cd00b00a2ea45637desm1277247ejd.112.2024.01.17.04.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 04:51:36 -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 v4 4/5] iio: amplifiers: hmc425a: use pointers in match table Date: Wed, 17 Jan 2024 14:51:13 +0200 Message-ID: <20240117125124.8326-5-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240117125124.8326-1-mitrutzceclan@gmail.com> References: <20240117125124.8326-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Change the match table to use pointers instead of device ids. Alignment of the hmc425a_state was changed because of the const specifier for hmc425a_chip_info. Signed-off-by: Dumitru Ceclan --- drivers/iio/amplifiers/hmc425a.c | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c index e1162a500daf..b116b54e4206 100644 --- a/drivers/iio/amplifiers/hmc425a.c +++ b/drivers/iio/amplifiers/hmc425a.c @@ -37,11 +37,11 @@ struct hmc425a_chip_info { }; struct hmc425a_state { - struct mutex lock; /* protect sensor state */ - struct hmc425a_chip_info *chip_info; - struct gpio_descs *gpios; - enum hmc425a_type type; - u32 gain; + struct mutex lock; /* protect sensor state */ + const struct hmc425a_chip_info *chip_info; + struct gpio_descs *gpios; + enum hmc425a_type type; + u32 gain; }; static int hmc425a_write(struct iio_dev *indio_dev, u32 value) @@ -58,7 +58,7 @@ static int hmc425a_write(struct iio_dev *indio_dev, u32 value) static int hmc425a_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, temp; if (val < 0) @@ -187,15 +187,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", @@ -226,6 +217,18 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { }, }; +/* 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 int hmc425a_probe(struct platform_device *pdev) { struct iio_dev *indio_dev; @@ -237,14 +240,16 @@ 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; st->gain = st->chip_info->default_gain; + /* Compute index of the acquired chip info in the array */ + st->type = st->chip_info - hmc425a_chip_info_tbl; + st->gpios = devm_gpiod_get_array(&pdev->dev, "ctrl", GPIOD_OUT_LOW); if (IS_ERR(st->gpios)) return dev_err_probe(&pdev->dev, PTR_ERR(st->gpios), From patchwork Wed Jan 17 12:51:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan X-Patchwork-Id: 763792 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 3078C200A6; Wed, 17 Jan 2024 12:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705495901; cv=none; b=WKJQziRUH073/4dLZsMdWYEL220Fh76EA8LkVGb0aTZDcRyU64j8o2T+OKJSG6bPPCe6GE5xpd3vCAUQrEzR7zmObHR2k6ymuWG4DUw4/0q7OZgtIfzj0E3/DjXD8s7QZk5AvhvLku2LM0j5laZyC1nLd3mW7/4mdO+Os2sd76I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705495901; c=relaxed/simple; bh=xXLlIP7osWnXSX7nf/88IxxEVdS3vDPA432NiT+QTnM=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; b=WBJYAitzpeIK64lAJ1tXUE875MjTjqp/rnd3+5R0ZNgYlvlRY1JbQLB6OfqA8q8DJNHYG1UBYCqu1ovbCZX/xx8So4kTizKNPfnaQGsLr0luZ6/HQr+kOmxfdbUKc1i5+0uloGUl8OGJM2Fssj8mqVnKyFAcH67lMSv+5+ooaU0= 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=SnPW4ZHB; arc=none smtp.client-ip=209.85.208.45 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="SnPW4ZHB" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-557dcb0f870so10928181a12.2; Wed, 17 Jan 2024 04:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705495898; x=1706100698; 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=X/bvLckPY/B6iV2JgYPRYCAJR1OfXTgLpwfT8b63pic=; b=SnPW4ZHBDHYVBEH40lGEU8f8+ii8sjrEbrYfufUV0B+U/oLPkDtBjYRnIZ9PKP2itc OsETXdxZhL543Wo/ioOL4zYrCXY7PY3ADJlmGIcbGESHZCFJxYqfggUHnkfVNulbP/1A FCi1wr4DNZhvM7V2tFg7Jk0uN+NotRExRMHzoZulhA3+uAd5LETfK1M+0nIqT0EHpr0+ rKbYKhU1scNyqse0U7of9zTCMTxilq+v8laFItKbpuj2c6dzlL+6GGByFUxc0+Y3NUun ToMvAefYGRWTKyCyuwHtUL/0W5CvUbh9CVNDbwBsHGbaGgyeQuR/CQJfHX8S82B7p1J1 yOgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705495898; x=1706100698; 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=X/bvLckPY/B6iV2JgYPRYCAJR1OfXTgLpwfT8b63pic=; b=dvd9GeIgTk5tTZHmiUFSa/R94HDyuptDpW8xAHb2FeHdzdT+7EsZgo2EDQkNFz5SzH LpFXR5DUTRpWLeUXPLz/HOWYc/wkem1BYnC7zX6lUQsVKoN/locLT5TC5DV9tLm1AlEh Vw0cxzBT4yh81Oc9YbDsYRQUZjnNhfdbleXBrXCC7dyvYiAm7xZI9oNTM3Rm6+dnWmG+ iWhHFyFV2L1o+8rl2fk8+XWm002ieVqH8qtvZeCJ1NJb7LcQ2Aa+zFEwyNfz2gPMvWVN qk7f3iZboAvlt5DVeXz2UZ69Foyih+N/yDKEqbk3FwbmOpRSNqClMyDIDfUpXtj5wgN9 tG5g== X-Gm-Message-State: AOJu0Yx/WbcAK1gWgkgipI4Qo5nzaoHNCkde0NyA/9Cj4EPlqkCbwbRa M5d3Cq+0IkKW6XgN2dyeDNM= X-Google-Smtp-Source: AGHT+IHzcBZTFl7/R4qH13jyO+4HXHx+ZcDfvAqmcfLITq5pCz36dHkbFJlw8S61Cf3tHls37k3nhw== X-Received: by 2002:a17:906:6a12:b0:a2b:1a20:e634 with SMTP id qw18-20020a1709066a1200b00a2b1a20e634mr5226175ejc.11.1705495898408; Wed, 17 Jan 2024 04:51:38 -0800 (PST) Received: from HYB-hhAwRlzzMZb.ad.analog.com ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id t13-20020a17090616cd00b00a2ea45637desm1277247ejd.112.2024.01.17.04.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 04:51:38 -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 v4 5/5] iio: amplifiers: hmc425a: add support for LTC6373 Instrumentation Amplifier Date: Wed, 17 Jan 2024 14:51:14 +0200 Message-ID: <20240117125124.8326-6-mitrutzceclan@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240117125124.8326-1-mitrutzceclan@gmail.com> References: <20240117125124.8326-1-mitrutzceclan@gmail.com> Precedence: bulk X-Mailing-List: devicetree@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 --- drivers/iio/amplifiers/hmc425a.c | 118 +++++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 4 deletions(-) diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c index b116b54e4206..e7f425677fd3 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, 2023 Analog Devices Inc. */ +#include #include #include #include @@ -20,10 +21,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 +49,8 @@ struct hmc425a_chip_info { int gain_min; int gain_max; int default_gain; + int powerdown_val; + bool has_powerdown; }; struct hmc425a_state { @@ -42,6 +59,7 @@ struct hmc425a_state { struct gpio_descs *gpios; enum hmc425a_type type; u32 gain; + bool powerdown; }; static int hmc425a_write(struct iio_dev *indio_dev, u32 value) @@ -80,6 +98,17 @@ static int hmc425a_gain_dB_to_code(struct hmc425a_state *st, int val, int val2, temp = (abs(gain) / 2000) & 0xF; *code = temp & BIT(3) ? temp | BIT(2) : temp; return 0; + case ID_LTC6373: + if (st->powerdown) + return -EPERM; + + /* add half of the value for rounding */ + temp = LTC6373_CONVERSION_CONSTANT / 2; + if (val < 0) + temp *= -1; + *code = ~((gain + temp) / LTC6373_CONVERSION_CONSTANT + 3) + & LTC6373_CONVERSION_MASK; + return 0; default: return -EINVAL; } @@ -101,6 +130,12 @@ static int hmc425a_code_to_gain_dB(struct hmc425a_state *st, int *val, int *val2 code = code & BIT(3) ? code & ~BIT(2) : code; gain = code * -2000; break; + case ID_LTC6373: + if (st->powerdown) + return -EPERM; + gain = ((~code & LTC6373_CONVERSION_MASK) - 3) * + LTC6373_CONVERSION_CONSTANT; + break; } *val = gain / 1000; @@ -174,6 +209,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; + ret = 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, \ @@ -183,10 +260,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", @@ -215,6 +306,18 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { .gain_max = 0, .default_gain = 0xF, /* set default gain -22.0db*/ }, + [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, + }, + }; /* Match table for of_platform binding */ @@ -225,6 +328,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); @@ -270,8 +375,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); }