From patchwork Mon Apr 1 15:32:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dumitru Ceclan via B4 Relay X-Patchwork-Id: 13612819 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77AA745BEC; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; cv=none; b=gQ+MWWL9B75qEEzKzsNIl6tn9LBxr2IYLSrAxGyOyeoLwfIjfpQlXo3gwYO6i/2ApXuUrx+kxGoxTwyiNBMGs8PIZYOoGJThtEAJpC0rBA5K0buGRzHNPgHCwaeaUMV82RWO7CUwHoD5EvF41lqU/cUoZQaGcpsz9ncSGzJZvvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; c=relaxed/simple; bh=ypyseA7gjkezHNz8byQb1xroCwMnLrrumCgs2qcJ9TM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H/b9PHRqP0p/rAOhpIcR0vRGqp2AP8t2vuD7LRJXmBohdU3bylH3ZU2pWLOCJsSBxVtBGAQ04Su6estFnTMtJu0vATVBH5GRpqkoeQ96bTnyRfEIXZn+U2L/uDxl2X9Fz+5Rj8+xheMr7Js5JpUlaUVadz4XakMzl2TrZ6l71/w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kqIzWbE/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kqIzWbE/" Received: by smtp.kernel.org (Postfix) with ESMTPS id 11CEFC43390; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711984217; bh=ypyseA7gjkezHNz8byQb1xroCwMnLrrumCgs2qcJ9TM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=kqIzWbE/88Dxgs2PUcPDRr4wCvLECfF7SyBly1ZZdfPqyzF1TqIC62iPGfu6mCp1y PApzigXBT3XRaFaTC2g9yxdOfw6DmHjCy7E8zq/NTr4o3nA6ia2v5TvaNtJSqQYZPw tTW5yAbseOcyif1tIkuAFr5slgU/kGRHfKKV1+1U7z5VzoVadDC+8kq6jmwSsaczwg uMgyElTWfF/zipJXK1EJXyJ5Vq2DXJKQm3UGzMDWRLXic2ghvX6qlUoO+0wXTDbuKm WMtaj86hNbhlun4u/o3EVCslxAR8T2+A4VdSothhK6QdmIig8fFdPNlHZkuvOykNhQ TUyuz2rlxwrWQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0A84CD1288; Mon, 1 Apr 2024 15:10:16 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Mon, 01 Apr 2024 18:32:19 +0300 Subject: [PATCH 1/6] dt-bindings: adc: ad7173: add support for ad411x Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-ad4111-v1-1-34618a9cc502@analog.com> References: <20240401-ad4111-v1-0-34618a9cc502@analog.com> In-Reply-To: <20240401-ad4111-v1-0-34618a9cc502@analog.com> To: Ceclan Dumitru Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1711985550; l=4017; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=ZyRClsyDd6RKV/PtoHfGxoOfXDbJoSHfK85MVhx0ze8=; b=OVfXhcFTgH9CYNC7fhmMZbavK94vVtJeh+VDoQk2nZ9ZKe93KmREz9IS2PvDGUG6wrpoXP4TU tS58/VzjVh1AsCfd01MdgrIYEuNU+n4kbO4agDA4qQqmCt6T01rMm+d X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan Add support for: AD4111, AD4112, AD4114, AD4115, AD4116. AD411x family ADCs support a VCOM pin, dedicated for single-ended usage. AD4111/AD4112 support current channels, usage is implemented by specifying channel reg values bigger than 15. Signed-off-by: Dumitru Ceclan --- .../devicetree/bindings/iio/adc/adi,ad7173.yaml | 59 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml index ea6cfcd0aff4..bba2de0a52f3 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml @@ -19,7 +19,18 @@ description: | primarily for measurement of signals close to DC but also delivers outstanding performance with input bandwidths out to ~10kHz. + Analog Devices AD411x ADC's: + The AD411X family encompasses a series of low power, low noise, 24-bit, + sigma-delta analog-to-digital converters that offer a versatile range of + specifications. They integrate an analog front end suitable for processing + fully differential/single-ended and bipolar voltage inputs. + Datasheets for supported chips: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4111.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4112.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4114.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4115.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4116.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-2.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7173-8.pdf @@ -31,6 +42,11 @@ description: | properties: compatible: enum: + - adi,ad4111 + - adi,ad4112 + - adi,ad4114 + - adi,ad4115 + - adi,ad4116 - adi,ad7172-2 - adi,ad7172-4 - adi,ad7173-8 @@ -125,10 +141,19 @@ patternProperties: properties: reg: + description: + Reg values 16-19 are only permitted for ad4111/ad4112 current channels. minimum: 0 - maximum: 15 + maximum: 19 diff-channels: + description: + For using current channels specify only the positive channel. + (IIN2+, IIN2−) -> diff-channels = <2 0> + + Family AD411x supports a dedicated VCOM voltage input. + To select it set the second channel to 16. + (VIN2, VCOM) -> diff-channels = <2 16> items: minimum: 0 maximum: 31 @@ -166,7 +191,6 @@ allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# # Only ad7172-4, ad7173-8 and ad7175-8 support vref2 - # Other models have [0-3] channel registers - if: properties: compatible: @@ -187,6 +211,37 @@ allOf: - vref - refout-avss - avdd + + - if: + properties: + compatible: + contains: + enum: + - adi,ad4114 + - adi,ad4115 + - adi,ad4116 + - adi,ad7173-8 + - adi,ad7175-8 + then: + patternProperties: + "^channel@[0-9a-f]$": + properties: + reg: + maximum: 15 + + - if: + properties: + compatible: + contains: + enum: + - adi,ad7172-2 + - adi,ad7175-2 + - adi,ad7176-2 + - adi,ad7177-2 + then: + patternProperties: + "^channel@[0-9a-f]$": + properties: reg: maximum: 3 From patchwork Mon Apr 1 15:32:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan via B4 Relay X-Patchwork-Id: 13612820 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77A744597C; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; cv=none; b=Qn6Yd3eRUlwyxuUOYjSeHDTAolOwcUuHHpZp9KzKpWDv9aRi0QgFw/jKxQ8HPkfs4f7GNNOjp+c6mlNPJ0kfBW4W/VsSJ0+PV3Z2DuwtIBGa4FiTJV0wQZGFRYa0GJGE8bjB2EvS191Mv3kMNs2ZniSvNy/ODM7lBUQVIHk1go4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; c=relaxed/simple; bh=EPYzwoSlBrhWbb4NezRITDY2mYtpyHQZqs3oDoNIUH4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lHgNQmQeMWhMklLBecIpLlMhtC8zWucRk/Mfy+7TiV4owwKEBFfqbkXkXeS/YjCPt+7siJP7fqx5Wf1AobWUuPzkfcAF2xIan4QQRGES6qHuuRmqCBTkvpFpljIpl+5nyuQCDg3x44gL91AtbVcYzfM2h5/DEnopKOArpmruX9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eILMBCMN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eILMBCMN" Received: by smtp.kernel.org (Postfix) with ESMTPS id 21AABC433F1; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711984217; bh=EPYzwoSlBrhWbb4NezRITDY2mYtpyHQZqs3oDoNIUH4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=eILMBCMN6m8CFocOHSUI/Gr3DKl7XMR8dExHgWT8ygz9pCseIWyEY5Rpi4kuHgD0j P8wR69E2UjxXXzh+09p+2X/1UBfHEVGgbi92xT5wZWjLLQVQXcCHPANQJ46gP+CPQQ GFG6uJDEYJgEjFL/z9AxjiERPTPGFGt5eBuYzm3nR7WL/Hr5rLJG/saa3WEKAs1XpU 8aqODUV1XhaHRDKxlos+ItoUSVIcuCKVGuMGCpI0H0xmuOEs6I0grhuyGBu19au/Ok lIDZ18tUaJw5tOVOnQ43grwVXZgkJLc5Z6GoLLA3P7ndWCzyd2ggeOuTSbsfJTULKc TW6QirX16hnzg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FDDACD1294; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Mon, 01 Apr 2024 18:32:20 +0300 Subject: [PATCH 2/6] iio: adc: ad7173: fix buffers enablement for ad7176-2 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-ad4111-v1-2-34618a9cc502@analog.com> References: <20240401-ad4111-v1-0-34618a9cc502@analog.com> In-Reply-To: <20240401-ad4111-v1-0-34618a9cc502@analog.com> To: Ceclan Dumitru Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1711985550; l=3146; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=XBG3ZzeGtsb1s4sQXD5/rlIZvxQAdZt5Ft64/lEIcrg=; b=GIhyy5ER6B9DJE8fTnl0ZSa2qS3hR4RU3sEXbtJaqItmlVnIXjlgj0V9vagcODrEgKr67Uk+g cLBWvMoweiXDkkIua9dOLXVbIToruVYxFaA8JXsDO+fSrTxOkRkA+xh X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan AD7176-2 does not feature input buffers, enable buffers only on supported models. Fixes: cff259bf7274 ("iio: adc: ad7173: fix buffers enablement for ad7176-2") Signed-off-by: Dumitru Ceclan Reviewed-by: David Lechner --- drivers/iio/adc/ad7173.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index f6d29abe1d04..8a95b1391826 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -145,6 +145,7 @@ struct ad7173_device_info { unsigned int id; char *name; bool has_temp; + bool has_input_buf; bool has_int_ref; bool has_ref2; u8 num_gpios; @@ -212,6 +213,7 @@ static const struct ad7173_device_info ad7173_device_info[] = { .num_configs = 4, .num_gpios = 2, .has_temp = true, + .has_input_buf = true, .has_int_ref = true, .clock = 2 * HZ_PER_MHZ, .sinc5_data_rates = ad7173_sinc5_data_rates, @@ -224,6 +226,7 @@ static const struct ad7173_device_info ad7173_device_info[] = { .num_configs = 8, .num_gpios = 4, .has_temp = false, + .has_input_buf = true, .has_ref2 = true, .clock = 2 * HZ_PER_MHZ, .sinc5_data_rates = ad7173_sinc5_data_rates, @@ -237,6 +240,7 @@ static const struct ad7173_device_info ad7173_device_info[] = { .num_configs = 8, .num_gpios = 4, .has_temp = true, + .has_input_buf = true, .has_int_ref = true, .has_ref2 = true, .clock = 2 * HZ_PER_MHZ, @@ -251,6 +255,7 @@ static const struct ad7173_device_info ad7173_device_info[] = { .num_configs = 4, .num_gpios = 2, .has_temp = true, + .has_input_buf = true, .has_int_ref = true, .clock = 16 * HZ_PER_MHZ, .sinc5_data_rates = ad7175_sinc5_data_rates, @@ -263,6 +268,7 @@ static const struct ad7173_device_info ad7173_device_info[] = { .num_configs = 8, .num_gpios = 4, .has_temp = true, + .has_input_buf = true, .has_int_ref = true, .has_ref2 = true, .clock = 16 * HZ_PER_MHZ, @@ -289,6 +295,7 @@ static const struct ad7173_device_info ad7173_device_info[] = { .num_configs = 4, .num_gpios = 2, .has_temp = true, + .has_input_buf = true, .has_int_ref = true, .clock = 16 * HZ_PER_MHZ, .odr_start_value = AD7177_ODR_START_VALUE, @@ -932,7 +939,7 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) AD7173_CH_ADDRESS(chan_arr[chan_index].channel, chan_arr[chan_index].channel2); chan_st_priv->cfg.bipolar = false; - chan_st_priv->cfg.input_buf = true; + chan_st_priv->cfg.input_buf = st->info->has_input_buf; chan_st_priv->cfg.ref_sel = AD7173_SETUP_REF_SEL_INT_REF; st->adc_mode |= AD7173_ADC_MODE_REF_EN; @@ -989,7 +996,7 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) chan_st_priv->ain = AD7173_CH_ADDRESS(ain[0], ain[1]); chan_st_priv->chan_reg = chan_index; - chan_st_priv->cfg.input_buf = true; + chan_st_priv->cfg.input_buf = st->info->has_input_buf; chan_st_priv->cfg.odr = 0; chan_st_priv->cfg.bipolar = fwnode_property_read_bool(child, "bipolar"); From patchwork Mon Apr 1 15:32:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan via B4 Relay X-Patchwork-Id: 13612821 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8896045BF9; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; cv=none; b=dPKH/FdqjmVxvHC8QhrrM9pTOetdNnYKO1HtXi1VWWith022VC/4N1rV5HqwiMukGTHR/1s/22cQE3n7kO460WE3dYv6gVGpAJmXUkrWdVOiXSOsZVlk+4H1baDXmLm+5yFqjtOiDY+SGfaZK4tRXIoamz4qcsXQis3qn5XwLBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; c=relaxed/simple; bh=sB4XW2Iy9WrEDv3ZxInXXORojt09vA9WlbAC80dGpys=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=juYhmVwnaTKYSzHbVlvhDl5nOhge6rCrjTxsTTRAOOq76hOKexfYN5P40pyFhpaaCmCF6lAQ4bK40LugCjzpBmtxTle4qLnUBQDTNs9OyeLVlmwb9DhuWmC8VkNzkeM31s6m6+zTgfJ9e1U6WG767fpXff/PEvqOorBX5GISCxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XqdzuZ0T; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XqdzuZ0T" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2CFDCC43399; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711984217; bh=sB4XW2Iy9WrEDv3ZxInXXORojt09vA9WlbAC80dGpys=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XqdzuZ0TlU9SV1IQWTipwyCFeQFQXqkWz6PyJIVtrt9+OmKll9rWL1QY8CkKZ3BfH /fOIjjOeszDCLUsXOth8Q6GvcoM2/1Zvm0i/rxTQ46fmCQcgvdPlAYPz1nPtVg8wu2 IMHK2V8E4CUc0JkqQkjq+kaSZtpz52S+b62GeG4YXxbJaU4MLfn+lj81TjKWxw65hb m6du6HCFBiFbvE7QZ/66HFm03jp8VMDhcNBxGI9zz6yov+flZolcSbay89eVfvgHQ0 I4fhJvFE3vRgek+y5qBYd0eek7dNK6FBgsU9cL/8PUjBfSEr1sYjf3GZpVT2MJqchI 4BDSXiMrwkmkw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EB90CD1292; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Mon, 01 Apr 2024 18:32:21 +0300 Subject: [PATCH 3/6] iio: adc: ad7173: refactor channel configuration parsing Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-ad4111-v1-3-34618a9cc502@analog.com> References: <20240401-ad4111-v1-0-34618a9cc502@analog.com> In-Reply-To: <20240401-ad4111-v1-0-34618a9cc502@analog.com> To: Ceclan Dumitru Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1711985550; l=2160; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=LP925hA7l/Zq+jxivGEGAOgI2hBOHLlP0ftz5riKxwA=; b=/RbMwmYnyhC5pKQaInX3g8tTV5ka0OyCWhWopLnpDFY3wgL+e2loPLkV1ldaDbSKtknDIKhsB /+X38d8OzhKC/vKCrDsGYSh0zjHicqefIm2+JfwdgrZGF5a+ELQ9yVs X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan Move configurations regarding number of channels from *_fw_parse_device_config to *_fw_parse_channel_config. Signed-off-by: Dumitru Ceclan Reviewed-by: David Lechner --- drivers/iio/adc/ad7173.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index 8a95b1391826..699bc6970790 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -917,7 +917,23 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) struct device *dev = indio_dev->dev.parent; struct iio_chan_spec *chan_arr, *chan; unsigned int ain[2], chan_index = 0; - int ref_sel, ret; + int ref_sel, ret, num_channels; + + num_channels = device_get_child_node_count(dev); + + if (st->info->has_temp) + num_channels++; + + if (num_channels == 0) + return dev_err_probe(dev, -ENODATA, "No channels specified\n"); + + if (num_channels > st->info->num_channels) + return dev_err_probe(dev, -EINVAL, + "Too many channels specified. Maximum is %d, not including temperature channel if supported.\n", + st->info->num_channels); + + indio_dev->num_channels = num_channels; + st->num_channels = num_channels; chan_arr = devm_kcalloc(dev, sizeof(*indio_dev->channels), st->num_channels, GFP_KERNEL); @@ -1012,7 +1028,6 @@ static int ad7173_fw_parse_device_config(struct iio_dev *indio_dev) { struct ad7173_state *st = iio_priv(indio_dev); struct device *dev = indio_dev->dev.parent; - unsigned int num_channels; int ret; st->regulators[0].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_EXT_REF]; @@ -1071,16 +1086,6 @@ static int ad7173_fw_parse_device_config(struct iio_dev *indio_dev) ad7173_sigma_delta_info.irq_line = ret; - num_channels = device_get_child_node_count(dev); - - if (st->info->has_temp) - num_channels++; - - if (num_channels == 0) - return dev_err_probe(dev, -ENODATA, "No channels specified\n"); - indio_dev->num_channels = num_channels; - st->num_channels = num_channels; - return ad7173_fw_parse_channel_config(indio_dev); } From patchwork Mon Apr 1 15:32:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan via B4 Relay X-Patchwork-Id: 13612822 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B13246436; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; cv=none; b=rUBza+gBOgqHO4X3ePjcHZkffSY8tMBQdcVlE9O3mz4w3jlxotVYsKWZN1e5gWI1F+EWfUgHuU6SuDruL1zsOt6RdoCBHKgBJfI3pmv2JjSolImyvEaLS6zJg7nDuxRWBnAINoMdaMtIjRi3PBxm4nQZi0W2X8pCTL+1SofDPg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; c=relaxed/simple; bh=/ob0HLnTQN/zuJtE6XAi67E0eFBxRhaKMzO3UK+Xn68=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e7B99uwYgIN15bnjFjZxH6GSJSi6j63Dq093P5UkGzKonW+Hz+m4moMIqgKoVxcelTeBu5WGY5x9SeWqvjO94kt+WL2Dx+eAt8jfVCfHj9tZ7xPjh6naed6RxDxhde/98Dr7DnA58/q94p7P/vQOqLEtO+ddvvuC0b5sDHo0YDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GBpSmubq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GBpSmubq" Received: by smtp.kernel.org (Postfix) with ESMTPS id 35C67C43330; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711984217; bh=/ob0HLnTQN/zuJtE6XAi67E0eFBxRhaKMzO3UK+Xn68=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=GBpSmubqeCt2mIryC7viP2XlJpTmE0EsU6bk/q4u4rc9dNv7t9QjERjeiCVYPhMvZ CYbOMWN8hUsZFtiiSz3cZrlD7pE1JGdxhNh9q+S4Tw+Qpbz3fxlfZCVL8ttKOgZWmI mi4EmiAUfcL8m4P25W8Q1vFjWqsdGTSiAiaEACwpO9UAciA8n1pt5R1EuFFlBBm2me wfw8Jj/z2XqKBqSDWonu+SyPknzhitdrJeUKR9fvD6gqXuRuYBj/cu2Bo/gt3qobAo x/AsrYJJvGVl3ELwVmZipEZvoUBYL818M+7KLEfZhCIUbjYVHTqdFMkUIadtua6Cyy KEplihiqZwqJA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C686CD1297; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Mon, 01 Apr 2024 18:32:22 +0300 Subject: [PATCH 4/6] iio: adc: ad7173: refactor ain and vref selection Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-ad4111-v1-4-34618a9cc502@analog.com> References: <20240401-ad4111-v1-0-34618a9cc502@analog.com> In-Reply-To: <20240401-ad4111-v1-0-34618a9cc502@analog.com> To: Ceclan Dumitru Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1711985550; l=3122; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=ugvDBN0G/VRH37DYWBENrnCso3rjndLZ6QW6zEbTWUI=; b=TaueQ6MIGfSMUSVPoPKL8zso0+kp5S07/EPrJPg2u5mZVRd50ehgCUX28X1NL0isaqG4oYMZr 7lQoB91EPoKBBAYzUtyB1zqoW6tRzMlv0AwIaVuxj+iJ9PcbLUM0uTu X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan Move validation of analog inputs and reference voltage selection to separate functions. Signed-off-by: Dumitru Ceclan --- drivers/iio/adc/ad7173.c | 59 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index 699bc6970790..bf5a5b384fe2 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -910,6 +910,41 @@ static int ad7173_register_clk_provider(struct iio_dev *indio_dev) &st->int_clk_hw); } +static int ad7173_validate_voltage_ain_inputs(struct ad7173_state *st, + unsigned int ain[2]) +{ + struct device *dev = &st->sd.spi->dev; + + if (ain[0] >= st->info->num_inputs || + ain[1] >= st->info->num_inputs) + return dev_err_probe(dev, -EINVAL, + "Input pin number out of range for pair (%d %d).\n", + ain[0], ain[1]); + + return 0; +} + +static int ad7173_validate_reference(struct ad7173_state *st, int ref_sel) +{ + struct device *dev = &st->sd.spi->dev; + int ret; + + if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF && !st->info->has_int_ref) + return dev_err_probe(dev, -EINVAL, + "Internal reference is not available on current model.\n"); + + if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) + return dev_err_probe(dev, -EINVAL, + "External reference 2 is not available on current model.\n"); + + ret = ad7173_get_ref_voltage_milli(st, ref_sel); + if (ret < 0) + return dev_err_probe(dev, ret, + "Cannot use reference %u\n", ref_sel); + + return 0; +} + static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) { struct ad7173_channel *chans_st_arr, *chan_st_priv; @@ -970,11 +1005,9 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) if (ret) return ret; - if (ain[0] >= st->info->num_inputs || - ain[1] >= st->info->num_inputs) - return dev_err_probe(dev, -EINVAL, - "Input pin number out of range for pair (%d %d).\n", - ain[0], ain[1]); + ret = ad7173_validate_voltage_ain_inputs(st, ain); + if (ret) + return ret; ret = fwnode_property_match_property_string(child, "adi,reference-select", @@ -985,19 +1018,9 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) else ref_sel = ret; - if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF && - !st->info->has_int_ref) - return dev_err_probe(dev, -EINVAL, - "Internal reference is not available on current model.\n"); - - if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) - return dev_err_probe(dev, -EINVAL, - "External reference 2 is not available on current model.\n"); - - ret = ad7173_get_ref_voltage_milli(st, ref_sel); - if (ret < 0) - return dev_err_probe(dev, ret, - "Cannot use reference %u\n", ref_sel); + ret = ad7173_validate_reference(st, ref_sel); + if (ret) + return ret; if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF) st->adc_mode |= AD7173_ADC_MODE_REF_EN; From patchwork Mon Apr 1 15:32:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan via B4 Relay X-Patchwork-Id: 13612823 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAABA4779C; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; cv=none; b=o0xWMFrrC90G+YGQ7UvKcwsMRr/ZwbtZ9rEQCmojI8wSh1jsj0BySY1sYWpKpy2JkTzMe3bMPV5/AZccIMJK4yJertV/sCVVQOkJ2VZG1v+036t9MYhFs7OQe9Wu7fhUmJVLS+VrPRyM+UZ//shKe7AtVVcDCfaOp75+IxrqQGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; c=relaxed/simple; bh=rMNIm6FF+KZ2ZTd24xaZhI8c5F+8wLFZxJzWUcCFoE0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RWhoRTMMGm4Hpnpa8GlvF+6MSh0T+cIYRmt/M4BnKEeS3hrNxnNklB1uh6xQ1z4elWoV5SJ46guHuzQUqRJlcZhlwvlXGPYGdoOcQMIVe9o40EVtZqe7q5U9w/SKj1DHVKDtKT1XNuUGgc9FisX5hgdYUgF6M7qejly/dbWkRas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yi+2EWfO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Yi+2EWfO" Received: by smtp.kernel.org (Postfix) with ESMTPS id 42A6AC43142; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711984217; bh=rMNIm6FF+KZ2ZTd24xaZhI8c5F+8wLFZxJzWUcCFoE0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Yi+2EWfO+KGVpi7JDBs5lIvKSv+UTUhk2N3pUx7aBUI7L3F7npNPeW7U2c/gtJcBt yuffCjtV2eFE8LQufDwLWcynUvO9yUP9F1sfqv/Nth7mfI+a56+i6YGkH3G9fmtN4Z kFcDCHxqhTbJni5odIg/rGYUJ+v2DRbRJRbMVZs33HnZueYP8IwOnqowR6zWHH7qnX vigRtRTTNZVa0j281w5raiyNlX+IBYp39iQAisICf7oFZedfdns84NkRoPI8Z1YWso 2AttD8CWIMH/ZqUvokiXQ9jpz4wKNvwx+a8dlVDwM/VlHekFeGIo2/LYzwDDRAp2Jd ReTv5wHgLj7kw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B35ECD128D; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Mon, 01 Apr 2024 18:32:23 +0300 Subject: [PATCH 5/6] iio: adc: ad7173: Remove index from temp channel Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-ad4111-v1-5-34618a9cc502@analog.com> References: <20240401-ad4111-v1-0-34618a9cc502@analog.com> In-Reply-To: <20240401-ad4111-v1-0-34618a9cc502@analog.com> To: Ceclan Dumitru Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1711985550; l=697; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=BEq6V85bjOhRpMOZUvZXO8DDCT8wIyhHIFI5fumHsUQ=; b=uRtEs9PSWhwA2agYFbdIGhRPxleMz2YI6DJQGcqKWjiKcckx5OaBkgBeVypd7Pkc4k2o8EF4Z Oe/2pVoVCLyDEuuNazmWNj21SPV6BuCXgX9le+FvPpRM4d/974PE+6r X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan Temperature channel is unique per device, index is not needed. Signed-off-by: Dumitru Ceclan --- drivers/iio/adc/ad7173.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index bf5a5b384fe2..9526585e6929 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -797,7 +797,6 @@ static const struct iio_info ad7173_info = { static const struct iio_chan_spec ad7173_channel_template = { .type = IIO_VOLTAGE, - .indexed = 1, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), From patchwork Mon Apr 1 15:32:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceclan via B4 Relay X-Patchwork-Id: 13612824 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8E924778E; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; cv=none; b=JN7AC4vNzI6ZdKAbu22URQiLWm/JzjnSUs1QOnAd++aqOMvlAruaJZzzUHBB6LS4pTSxOMNvwcOkPIN2bfBKFSFdB/hwhEctuJGFxaNxmRUJp0s985Bz/5Kc4QHNNxw0WhG7s1UyRnC2Iuwmm1MFYi/2Z+IxBeOILaRLlW6hu8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711984217; c=relaxed/simple; bh=KNM3Z/xPIReDwB4TB74SR3DTpeDcKNy5Ue7Za5F40a8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ip/OgA8D0RUXi/hEdOaEoDx7h5D2SmjjscRytF1JiIoYrYiuVBIRwHeFDVsckT5W/R+60x0G2Q6bAPMneHEzvCWtpXPKEBKW7DX8ATFWwiGcs7ZUPNtOrHN/CXFjto0Kj8cHmz5DSN95hA8Uwxqnlw9nPVHazYEQfRiaz0qlJzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gRZ7U572; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gRZ7U572" Received: by smtp.kernel.org (Postfix) with ESMTPS id 55C56C41679; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711984217; bh=KNM3Z/xPIReDwB4TB74SR3DTpeDcKNy5Ue7Za5F40a8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gRZ7U572QYXVHu/OzMZAW2YGeyIoO6wR4T8Z1iYuTNJIXpLqMafJhqi9/+/pDmZDJ gknfSf4Ynj3Z2/+dDnwt0G0L07cm0QiQAB/PVrYxxKiIkC9GK1jbr9VLhWmrx1th/k jcmsSyCcvlecLzOGrriNi9T//03Sa7rREnSLiX+LNqCU09E+PL6oHh39Jemi8J7fNp afyQPq/9mIuzlnCMom6m++VAXvlQZ1F33MRJ2VVSYLoPYCqghIE+gwZdJR3hWx2yjz jGq2jujgFveQ8+fxUhBx+vEIU/l8XG0LzSS8S133N5pfuANX16mkQjtmqkP3n4dWDQ 5wxY2dc/JihwQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BF4ACD1288; Mon, 1 Apr 2024 15:10:17 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Mon, 01 Apr 2024 18:32:24 +0300 Subject: [PATCH 6/6] iio: adc: ad7173: Add support for AD411x devices Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-ad4111-v1-6-34618a9cc502@analog.com> References: <20240401-ad4111-v1-0-34618a9cc502@analog.com> In-Reply-To: <20240401-ad4111-v1-0-34618a9cc502@analog.com> To: Ceclan Dumitru Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1711985550; l=12578; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=kiHu5JNtgoCzcntlDNshNci5NsEdS6HEdpF8vTbhVrY=; b=3PzLgxXE80EKuvp129PliMgrHheZyY6v4yLLBSuo77eMS8g/Uv4fB8VlUVy9QvZYi1HQth4G/ LvW21PcLKMkA7ZlJsym0F74JH1+8fmHHi4kue5czc/a9hTLtuoQ0JPk X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan Add support for AD4111/AD4112/AD4114/AD4115/AD4116. The AD411X family encompasses a series of low power, low noise, 24-bit, sigma-delta analog-to-digital converters that offer a versatile range of specifications. This family of ADCs integrates an analog front end suitable for processing both fully differential and single-ended, bipolar voltage inputs addressing a wide array of industrial and instrumentation requirements. - All ADCs have inputs with a precision voltage divider with a division ratio of 10. - AD4116 has 5 low level inputs without a voltage divider. - AD4111 and AD4112 support current inputs (0 mA to 20 mA) using a 50ohm shunt resistor. Signed-off-by: Dumitru Ceclan --- drivers/iio/adc/ad7173.c | 224 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 210 insertions(+), 14 deletions(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index 9526585e6929..ac32bd7dbd1e 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * AD717x family SPI ADC driver + * AD717x and AD411x family SPI ADC driver * * Supported devices: + * AD4111/AD4112/AD4114/AD4115/AD4116 * AD7172-2/AD7172-4/AD7173-8/AD7175-2 * AD7175-8/AD7176-2/AD7177-2 * @@ -72,6 +73,11 @@ #define AD7175_2_ID 0x0cd0 #define AD7172_4_ID 0x2050 #define AD7173_ID 0x30d0 +#define AD4111_ID 0x30d0 +#define AD4112_ID 0x30d0 +#define AD4114_ID 0x30d0 +#define AD4116_ID 0x34d0 +#define AD4115_ID 0x38d0 #define AD7175_8_ID 0x3cd0 #define AD7177_ID 0x4fd0 #define AD7173_ID_MASK GENMASK(15, 4) @@ -120,11 +126,20 @@ #define AD7173_VOLTAGE_INT_REF_uV 2500000 #define AD7173_TEMP_SENSIIVITY_uV_per_C 477 #define AD7177_ODR_START_VALUE 0x07 +#define AD4111_SHUNT_RESISTOR_OHM 50 +#define AD4111_DIVIDER_RATIO 10 +#define AD411X_VCOM_INPUT 0X10 +#define AD4111_CURRENT_CHAN_CUTOFF 16 #define AD7173_FILTER_ODR0_MASK GENMASK(5, 0) #define AD7173_MAX_CONFIGS 8 enum ad7173_ids { + ID_AD4111, + ID_AD4112, + ID_AD4114, + ID_AD4115, + ID_AD4116, ID_AD7172_2, ID_AD7172_4, ID_AD7173_8, @@ -134,16 +149,26 @@ enum ad7173_ids { ID_AD7177_2, }; +enum ad4111_current_channels { + AD4111_CURRENT_IN0P_IN0N, + AD4111_CURRENT_IN1P_IN1N, + AD4111_CURRENT_IN2P_IN2N, + AD4111_CURRENT_IN3P_IN3N, +}; + struct ad7173_device_info { const unsigned int *sinc5_data_rates; unsigned int num_sinc5_data_rates; unsigned int odr_start_value; + unsigned int num_inputs_with_divider; unsigned int num_channels; unsigned int num_configs; unsigned int num_inputs; unsigned int clock; unsigned int id; char *name; + bool has_current_inputs; + bool has_vcom; bool has_temp; bool has_input_buf; bool has_int_ref; @@ -189,6 +214,24 @@ struct ad7173_state { #endif }; +static unsigned int ad4115_sinc5_data_rates[] = { + 24845000, 24845000, 20725000, 20725000, /* 0-3 */ + 15564000, 13841000, 10390000, 10390000, /* 4-7 */ + 4994000, 2499000, 1000000, 500000, /* 8-11 */ + 395500, 200000, 100000, 59890, /* 12-15 */ + 49920, 20000, 16660, 10000, /* 16-19 */ + 5000, 2500, 2500, /* 20-22 */ +}; + +static unsigned int ad4116_sinc5_data_rates[] = { + 12422360, 12422360, 12422360, 12422360, /* 0-3 */ + 10362690, 10362690, 7782100, 6290530, /* 4-7 */ + 5194800, 2496900, 1007600, 499900, /* 8-11 */ + 390600, 200300, 100000, 59750, /* 12-15 */ + 49840, 20000, 16650, 10000, /* 16-19 */ + 5000, 2500, 1250, /* 20-22 */ +}; + static const unsigned int ad7173_sinc5_data_rates[] = { 6211000, 6211000, 6211000, 6211000, 6211000, 6211000, 5181000, 4444000, /* 0-7 */ 3115000, 2597000, 1007000, 503800, 381000, 200300, 100500, 59520, /* 8-15 */ @@ -204,7 +247,91 @@ static const unsigned int ad7175_sinc5_data_rates[] = { 5000, /* 20 */ }; +static unsigned int ad4111_current_channel_config[] = { + [AD4111_CURRENT_IN0P_IN0N] = 0x1E8, + [AD4111_CURRENT_IN1P_IN1N] = 0x1C9, + [AD4111_CURRENT_IN2P_IN2N] = 0x1AA, + [AD4111_CURRENT_IN3P_IN3N] = 0x18B, +}; + static const struct ad7173_device_info ad7173_device_info[] = { + [ID_AD4111] = { + .id = AD4111_ID, + .num_inputs_with_divider = 8, + .num_channels = 16, + .num_configs = 8, + .num_inputs = 8, + .num_gpios = 2, + .has_temp = true, + .has_vcom = true, + .has_input_buf = true, + .has_current_inputs = true, + .has_int_ref = true, + .clock = 2 * HZ_PER_MHZ, + .sinc5_data_rates = ad7173_sinc5_data_rates, + .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), + }, + [ID_AD4112] = { + .id = AD4112_ID, + .num_inputs_with_divider = 8, + .num_channels = 16, + .num_configs = 8, + .num_inputs = 8, + .num_gpios = 2, + .has_vcom = true, + .has_temp = true, + .has_input_buf = true, + .has_current_inputs = true, + .has_int_ref = true, + .clock = 2 * HZ_PER_MHZ, + .sinc5_data_rates = ad7173_sinc5_data_rates, + .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), + }, + [ID_AD4114] = { + .id = AD4114_ID, + .num_inputs_with_divider = 16, + .num_channels = 16, + .num_configs = 8, + .num_inputs = 16, + .num_gpios = 4, + .has_vcom = true, + .has_temp = true, + .has_input_buf = true, + .has_int_ref = true, + .clock = 2 * HZ_PER_MHZ, + .sinc5_data_rates = ad7173_sinc5_data_rates, + .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), + }, + [ID_AD4115] = { + .id = AD4115_ID, + .num_inputs_with_divider = 16, + .num_channels = 16, + .num_configs = 8, + .num_inputs = 16, + .num_gpios = 4, + .has_vcom = true, + .has_temp = true, + .has_input_buf = true, + .has_int_ref = true, + .clock = 8 * HZ_PER_MHZ, + .sinc5_data_rates = ad4115_sinc5_data_rates, + .num_sinc5_data_rates = ARRAY_SIZE(ad4115_sinc5_data_rates), + }, + [ID_AD4116] = { + .id = AD4116_ID, + .num_inputs_with_divider = 11, + .num_channels = 16, + .num_configs = 8, + .num_inputs = 16, + .num_gpios = 4, + .has_vcom = true, + .has_temp = true, + .has_input_buf = true, + .has_int_ref = true, + .clock = 4 * HZ_PER_MHZ, + .sinc5_data_rates = ad4116_sinc5_data_rates, + .num_sinc5_data_rates = ARRAY_SIZE(ad4116_sinc5_data_rates), + }, [ID_AD7172_2] = { .name = "ad7172-2", .id = AD7172_2_ID, @@ -670,18 +797,34 @@ static int ad7173_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - if (chan->type == IIO_TEMP) { + + switch (chan->type) { + case IIO_TEMP: temp = AD7173_VOLTAGE_INT_REF_uV * MILLI; temp /= AD7173_TEMP_SENSIIVITY_uV_per_C; *val = temp; *val2 = chan->scan_type.realbits; - } else { + break; + case IIO_VOLTAGE: *val = ad7173_get_ref_voltage_milli(st, ch->cfg.ref_sel); *val2 = chan->scan_type.realbits - !!(ch->cfg.bipolar); + + if (chan->channel < st->info->num_inputs_with_divider) + *val *= AD4111_DIVIDER_RATIO; + break; + case IIO_CURRENT: + *val = ad7173_get_ref_voltage_milli(st, ch->cfg.ref_sel); + *val /= AD4111_SHUNT_RESISTOR_OHM; + *val2 = chan->scan_type.realbits - !!(ch->cfg.bipolar); + break; + default: + return -EINVAL; } return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_OFFSET: - if (chan->type == IIO_TEMP) { + + switch (chan->type) { + case IIO_TEMP: /* 0 Kelvin -> raw sample */ temp = -ABSOLUTE_ZERO_MILLICELSIUS; temp *= AD7173_TEMP_SENSIIVITY_uV_per_C; @@ -690,8 +833,13 @@ static int ad7173_read_raw(struct iio_dev *indio_dev, AD7173_VOLTAGE_INT_REF_uV * MILLI); *val = -temp; - } else { + break; + case IIO_VOLTAGE: + case IIO_CURRENT: *val = -BIT(chan->scan_type.realbits - 1); + break; + default: + return -EINVAL; } return IIO_VAL_INT; case IIO_CHAN_INFO_SAMP_FREQ: @@ -909,6 +1057,24 @@ static int ad7173_register_clk_provider(struct iio_dev *indio_dev) &st->int_clk_hw); } +static int ad4111_validate_current_ain(struct ad7173_state *st, + unsigned int ain[2]) +{ + struct device *dev = &st->sd.spi->dev; + + if (!st->info->has_current_inputs) + return dev_err_probe(dev, -EINVAL, + "Reg values equal to or higher than %d are restricted to models with current channels.\n", + AD4111_CURRENT_CHAN_CUTOFF); + + if (ain[1] != 0 && ain[0] >= ARRAY_SIZE(ad4111_current_channel_config)) + return dev_err_probe(dev, -EINVAL, + "For current channel diff-channels must be <[0-%d],0>\n", + ARRAY_SIZE(ad4111_current_channel_config) - 1); + + return 0; +} + static int ad7173_validate_voltage_ain_inputs(struct ad7173_state *st, unsigned int ain[2]) { @@ -951,7 +1117,7 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) struct device *dev = indio_dev->dev.parent; struct iio_chan_spec *chan_arr, *chan; unsigned int ain[2], chan_index = 0; - int ref_sel, ret, num_channels; + int ref_sel, ret, reg, num_channels; num_channels = device_get_child_node_count(dev); @@ -1004,10 +1170,20 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) if (ret) return ret; - ret = ad7173_validate_voltage_ain_inputs(st, ain); + ret = fwnode_property_read_u32(child, "reg", ®); if (ret) return ret; + if (reg >= AD4111_CURRENT_CHAN_CUTOFF) { + ret = ad4111_validate_current_ain(st, ain); + if (ret) + return ret; + } else { + ret = ad7173_validate_voltage_ain_inputs(st, ain); + if (ret) + return ret; + } + ret = fwnode_property_match_property_string(child, "adi,reference-select", ad7173_ref_sel_str, @@ -1028,15 +1204,22 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) *chan = ad7173_channel_template; chan->address = chan_index; chan->scan_index = chan_index; - chan->channel = ain[0]; - chan->channel2 = ain[1]; - chan->differential = true; - chan_st_priv->ain = AD7173_CH_ADDRESS(ain[0], ain[1]); + if (reg >= AD4111_CURRENT_CHAN_CUTOFF) { + chan->type = IIO_CURRENT; + chan->channel = ain[0]; + chan_st_priv->ain = ad4111_current_channel_config[ain[0]]; + } else { + chan->channel = ain[0]; + chan->channel2 = ain[1]; + chan->differential = true; + + chan_st_priv->ain = AD7173_CH_ADDRESS(ain[0], ain[1]); + chan_st_priv->cfg.input_buf = st->info->has_input_buf; + } + chan_st_priv->chan_reg = chan_index; - chan_st_priv->cfg.input_buf = st->info->has_input_buf; chan_st_priv->cfg.odr = 0; - chan_st_priv->cfg.bipolar = fwnode_property_read_bool(child, "bipolar"); if (chan_st_priv->cfg.bipolar) chan->info_mask_separate |= BIT(IIO_CHAN_INFO_OFFSET); @@ -1167,6 +1350,14 @@ static int ad7173_probe(struct spi_device *spi) } static const struct of_device_id ad7173_of_match[] = { + { .compatible = "ad4111", + .data = &ad7173_device_info[ID_AD4111]}, + { .compatible = "ad4112", + .data = &ad7173_device_info[ID_AD4112]}, + { .compatible = "ad4114", + .data = &ad7173_device_info[ID_AD4114]}, + { .compatible = "ad4115", + .data = &ad7173_device_info[ID_AD4115]}, { .compatible = "adi,ad7172-2", .data = &ad7173_device_info[ID_AD7172_2]}, { .compatible = "adi,ad7172-4", @@ -1186,6 +1377,11 @@ static const struct of_device_id ad7173_of_match[] = { MODULE_DEVICE_TABLE(of, ad7173_of_match); static const struct spi_device_id ad7173_id_table[] = { + { "ad4111", (kernel_ulong_t)&ad7173_device_info[ID_AD4111]}, + { "ad4112", (kernel_ulong_t)&ad7173_device_info[ID_AD4112]}, + { "ad4114", (kernel_ulong_t)&ad7173_device_info[ID_AD4114]}, + { "ad4115", (kernel_ulong_t)&ad7173_device_info[ID_AD4115]}, + { "ad4116", (kernel_ulong_t)&ad7173_device_info[ID_AD4116]}, { "ad7172-2", (kernel_ulong_t)&ad7173_device_info[ID_AD7172_2]}, { "ad7172-4", (kernel_ulong_t)&ad7173_device_info[ID_AD7172_4]}, { "ad7173-8", (kernel_ulong_t)&ad7173_device_info[ID_AD7173_8]}, @@ -1210,5 +1406,5 @@ module_spi_driver(ad7173_driver); MODULE_IMPORT_NS(IIO_AD_SIGMA_DELTA); MODULE_AUTHOR("Lars-Peter Clausen "); MODULE_AUTHOR("Dumitru Ceclan "); -MODULE_DESCRIPTION("Analog Devices AD7172/AD7173/AD7175/AD7176 ADC driver"); +MODULE_DESCRIPTION("Analog Devices AD717x and AD411x ADC driver"); MODULE_LICENSE("GPL");