From patchwork Thu Aug 22 12:45:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Esteban Blanc X-Patchwork-Id: 13773311 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.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 677701C9DFF for ; Thu, 22 Aug 2024 12:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330751; cv=none; b=DkqF6/tlixPlvafzcjiPxOzfhB9SH8Ao3s8Ap7IwbxzM5noGiwjoQjMoKltGaK69hSysRNPGw1zJ0dBkSCvQ67PvoZpXd9uvmUDyYyZECkjmrmPR+GsHLQMiaS9InMSyc1XCTeE0J0SMvVeCXlxrm9COyIZGCjfesYKkNlkasII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330751; c=relaxed/simple; bh=fyqXqsZjJrEeXJfQiseBAtwVBgxOvF2ECKQScWgEPdw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=frXWhdNM1PrQRME90qCKl4MMrf/3qwfPu7uRbwU2no97zlX+40vSA2VCUgQKqQJYILQweWXqiXNj8dxkm2yh3melDcz32rj5V3cxENc2YZ2HBGmwnXN8F0A38sfzTmQK8cOieRsJK8Fbcx0WVTXTnhyv/KeqZq4h5KJgIoUfQuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=sezSUqo5; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="sezSUqo5" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42809d6e719so5441365e9.3 for ; Thu, 22 Aug 2024 05:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724330748; x=1724935548; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rBGPvhHLvlJuvRIFNEnpskRGdh1NE27Q73tLCnC4f40=; b=sezSUqo5dUTHtUFXhoYWecCnSb+hJVoHVMUcxbwNnxoDHSZEtRVKr9p+g/06f/StWw hP9upJfvd532zEgpQiXrWGXx9TvHDugQ0kZw8OTbh+8hb6wkSeG4eL1zlsXwkdMHa6yq 3ftrf+bUpEaA77b86v0+ZAFE9T6H/4zyNR6ngsdI7IqfVHQusTkim38xXRd4jcfQCZ5E Q2LO9ri1D35rqmkMbAjuw6zkGeRFPhtqte526iYzJZaTg1DZyj7S2rN55z/OURdYrbmD Gqkc3t4h13/sCYX49Ym1nmxUmSlQjOdrp9Y7I6C6i+NUWEl1+JseQUfwabJM6yNCXn3C Nvcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724330748; x=1724935548; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rBGPvhHLvlJuvRIFNEnpskRGdh1NE27Q73tLCnC4f40=; b=rjOkhiv7TnurrkmmT15L6CD7pMqmncgc7ECcCdTXhx2kFXNn2NCZYwQvMAKxnz66Ex 20u5rdlJd2Mhull4Nc2k49+ZBrj2IAUNobJGNKRejd25Im5k64HbNGIaT9JkylRx0gQs r7dBbUQZcz9joVf7gAdhso6RCgwp+ux+0CXGDIf6EHalCvHWWSBaSPZHhLW7OZdWvTNv ZRE5yRs60fyzTaBFlQFrcyXs8DsgR9Bcg0kZOVY+b2uUJeZlzjLfnmYgVOBqcUFkGfFz 5Vga8kxMyoTt1F2FlY4adiRFWbFqK6ci+SiVQ5DPWc7UB3YnTfYEl/PMxlwrIV2vtISf fP1w== X-Forwarded-Encrypted: i=1; AJvYcCXemcGbCxQ4iw/ijcrkM/6PUG+16+1nMcmschtbNz0A7mdi+AfYuyOFYdgjRbfe2gJ5Qsd9JiQq4lc=@vger.kernel.org X-Gm-Message-State: AOJu0YyWzDkyeq7B7leOHCuv+ZqiBmh7aposIoIDLOIyCZ+1qo7ZrKFp 101y62bgZUv0+p1SK5E033+serAaAcfkkxL4tUfkNnS3Yrx6nfUrsw0KT1+Tq5Q= X-Google-Smtp-Source: AGHT+IGLddsqdBqwYxq4wvo0WyS+Tg8NBcgZQmI1jPpH0BHxiDNsCxrgTGTIbmcMHWcZGs8SoH6vsg== X-Received: by 2002:a05:600c:b4c:b0:428:2433:1a07 with SMTP id 5b1f17b1804b1-42abd264786mr37820265e9.34.1724330747784; Thu, 22 Aug 2024 05:45:47 -0700 (PDT) Received: from [127.0.0.1] ([2a01:e0a:448:76e0:8da6:6d6d:c8ed:16c5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac514e269sm24032195e9.2.2024.08.22.05.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 05:45:47 -0700 (PDT) From: Esteban Blanc Date: Thu, 22 Aug 2024 14:45:17 +0200 Subject: [PATCH 1/6] dt-bindings: iio: adc: add ADI ad4030, ad4630 and ad4632 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240822-eblanc-ad4630_v1-v1-1-5c68f3327fdd@baylibre.com> References: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> In-Reply-To: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nuno Sa , Jonathan Corbet Cc: Michael Hennerich , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner , linux-doc@vger.kernel.org, Esteban Blanc X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openssh-sha256; t=1724330730; l=4807; i=eblanc@baylibre.com; s=yubikey; h=from:subject:message-id; bh=fyqXqsZjJrEeXJfQiseBAtwVBgxOvF2ECKQScWgEPdw=; b=U1NIU0lHAAAAAQAAAhcAAAAHc3NoLXJzYQAAAAMBAAEAAAIBALJZcW6pLD4ksSdWnXd5r65Ze 5Qc5pH7+DmmbKJasOXeVYRPFEmnORS7pwhURG11AMVFmnCVYWj+wPYrbCEeM7XKfO4oQzc66kYB 7y0RrFwjoWKofytjI026zV5b2pn1JAItgu0Ijth+TSa6KVOTSXqqiVzOTDM1WL0hAIIzpkhE3Vt AVJrFDsh/nWed9OpeSS+S6e3ZxyJtlnhqbVIemcDmjwMihtFgTKeJWlxP7KGY/RQKPF/Ef7pS+O AckOrxuqGKvpOiNVCmuQEUQM0+r4uvwtja4zRSl+huqW+g1nLyReoZPzFwfJWREd+89dtTJTXN7 xmmFNdX6KzRKBLVw1RY/R3mhAd+MkrdiNaRNKj+LO1QIxPoW90cPG9WpdVDUZf1VxhdciB6Hlxn lfEDFuCxU0n5H+kC4eiZvw+c9D4xX7iVdjPTMEaE6GBQNnMncdljBwA5NVN8WcaUhnAQnq7qhcz 85L2Br7MPqe3q3J/PHIe0nHO56j7tTY6cFFs/ckqcQSTJigh2rA7InN1d7GqZFLzlewRTGaCY+M 93d7DCIuxTxJWRpVm7NW1FBeX6d00+dAcQ/dS+jmA3kcdRoWtH160jmmYYvOgrsQTcMIQrPtK+B rULRmmIvEIJMF5UfNmxruWmWn6MM/xeejTNszoKqrORpbr7q3BnkKt2y/KdAAAABnBhdGF0dAAA AAAAAAAGc2hhNTEyAAACFAAAAAxyc2Etc2hhMi01MTIAAAIAj1q4EMIcf1j8mI9ZLN/B2YN8M0n 7krasqxgoc5GlCcQDKWm3N4Flp8PDc9j0e5w6bNV0XPDkeSypx9SoLCQZOFZb6LUTDgPGpjSZtJ YEc1uGWQk5b+nOwBtLw9HP3yryUY9DqD2aC9jvU9fl/T2wRBW9E6D+9on0JD0MBtx+KaaeMBhE/ 5U0UuzKrbHsXiXx4EffqorAeDmu8ZB0Q8/CPTCk8+xDKXkSpHXTgv+1fG+8M1O8b58Qc/P19U0l Lv6j2JEd6l52SIoFO2UNZW9eWZ10pTKfdckx1KGCbKm2vPUX2FhWunBphKn4zDYDO5hZRedBIuu bxf84MGZWf+rulgNBbbhWdGW6YvOCCpfj5glnTpT+alb1jTmwESlkD0/R++U4rfE+8jWJ4xT8SL LHafmaYUI60z1MJOJAQmuT811M5tiHFvCRvB1hgSnpRv+c+Yvhg5WSDta+gLDdU3Ahazen2RouP gGhHYPrRPHoEyqQYfHn5MWBbPVVGFEhBCyjE+MO5aZn21zbZfkuNVwfOdHNbLbBJJXH6OovedCl cbboaFyh4TQhNdS7EjYk5Qja/M6EBxMnrwg4bE4qKmbLq5S6uqB7k6M0zz9pQjXw9fnPxwdDsa5 KgADJ2K+hVrCBjh54bUEtuvYEuBtmvEFjh8WGmrpNJbyNNMvKtwEP3mI= X-Developer-Key: i=eblanc@baylibre.com; a=openssh; fpr=SHA256:LOxhPHcL6HLuSaOVHuI2Yq7hvD2blbngN1ohWi2rJOw This adds a binding specification for the Analog Devices Inc. AD4030, AD4630 and AD4632 families of ADCs. - ad4030-24 is a 1 channel SAR ADC with 24 bits of precision and a sampling rate of 2M samples per second - ad4630-16 is a 2 channels SAR ADC with 16 bits of precision and a sampling rate of 2M samples per second - ad4630-24 is a 2 channels SAR ADC with 24 bits of precision and a sampling rate of 2M samples per second - ad4632-16 is a 2 channels SAR ADC with 16 bits of precision and a sampling rate of 500K samples per second - ad4632-24 is a 2 channels SAR ADC with 24 bits of precision and a sampling rate of 500K samples per second Signed-off-by: Esteban Blanc Reviewed-by: Conor Dooley --- .../devicetree/bindings/iio/adc/adi,ad4030.yaml | 113 +++++++++++++++++++++ MAINTAINERS | 8 ++ 2 files changed, 121 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml new file mode 100644 index 000000000000..7957c0c0ac7a --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml @@ -0,0 +1,113 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2024 Analog Devices Inc. +# Copyright 2024 BayLibre, SAS. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad4030.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD4030 and AD4630 ADC family device driver + +maintainers: + - Nuno Sa + - Michael Hennerich + +description: | + Analog Devices AD4030 single channel and AD4630 dual channel precision SAR ADC + family + + * https://www.analog.com/media/en/technical-documentation/data-sheets/ad4030-24-4032-24.pdf + * https://www.analog.com/media/en/technical-documentation/data-sheets/ad4630-24_ad4632-24.pdf + * https://www.analog.com/media/en/technical-documentation/data-sheets/ad4630-16-4632-16.pdf + +properties: + + compatible: + enum: + - adi,ad4030-24 + - adi,ad4630-16 + - adi,ad4630-24 + - adi,ad4632-16 + - adi,ad4632-24 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 100000000 + + spi-rx-bus-width: + enum: [1, 2, 4] + + vdd-5v-supply: true + vdd-1v8-supply: true + vio-supply: true + + ref-supply: + description: + Optional External unbuffered reference. Used when refin-supply is not + connected. + + refin-supply: + description: + Internal buffered Reference. Used when ref-supply is not connected. + + cnv-gpio: + description: + The Convert Input (CNV). It initiates the sampling conversions. + maxItems: 1 + + reset-gpio: + description: + Reset Input (Active Low). Used for asynchronous device reset. + maxItems: 1 + + interrupts: + description: + The BUSY pin is used to signal that the conversions results are available + to be transferred when in SPI Clocking Mode. This nodes should be connected + to an interrupt that is triggered when the BUSY line goes low. + maxItems: 1 + + interrupt-names: + const: busy + +required: + - compatible + - reg + - vdd-5v-supply + - vdd-1v8-supply + - vio-supply + - cnv-gpio + +oneOf: + - required: + - ref-supply + - required: + - refin-supply + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include + + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "adi,ad4030-24"; + reg = <0>; + spi-max-frequency = <80000000>; + vdd-5v-supply = <&supply_5V>; + vdd-1v8-supply = <&supply_1_8V>; + vio-supply = <&supply_1_8V>; + ref-supply = <&supply_5V>; + cnv-gpio = <&gpio0 0 GPIO_ACTIVE_HIGH>; + }; + }; + diff --git a/MAINTAINERS b/MAINTAINERS index 417c6751c0dc..f17c42bea19c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -413,6 +413,14 @@ S: Maintained W: https://parisc.wiki.kernel.org/index.php/AD1889 F: sound/pci/ad1889.* +AD4030 ADC DRIVER (AD4030-24/AD4630-16/AD4630-24/AD4632-16/AD4632-24) +M: Michael Hennerich +M: Nuno Sá +R: Esteban Blanc +S: Supported +W: https://ez.analog.com/linux-software-drivers +F: Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml + AD5110 ANALOG DEVICES DIGITAL POTENTIOMETERS DRIVER M: Mugilraj Dhavachelvan L: linux-iio@vger.kernel.org From patchwork Thu Aug 22 12:45:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Esteban Blanc X-Patchwork-Id: 13773312 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 8EFB81C9EAE for ; Thu, 22 Aug 2024 12:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330753; cv=none; b=tdJriGUesxvcMwTGT8E5QsqBBc4onTuY4/RlNsjLkIYMGv7yeZMtBp93oZnc51p9k/dk8DqtsvPuT4l2I1SlLa6bzRgXfnGczik6qjL/d+UvEFEdp1eLpPSnqZWPsCm+ZmxL+442NIL2OwAQcE5ucViLON8xIEb/RyN5tsX2XIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330753; c=relaxed/simple; bh=yRyg3WPDghvOIfKYS356DIuYwiqS1518lafwZ5v4wcg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Rv1G6ID7kYjk8XMMvfc+4c564y+8av1/fH8HJ5VbemVYCOOrMujMIfaB2rHMf6F9xB6iQUrEEYKXCyVXjEkPt8RC29xXGs95Jg1PG9N5pMsSmhtydCwCC1ynPFQIv1ibz0MOV5FcDoYUJgBqBhIW/OHCmFPQaLOvWfZm4ghmCq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=ulQ3y3UH; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ulQ3y3UH" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-429da8b5feaso7372605e9.2 for ; Thu, 22 Aug 2024 05:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724330749; x=1724935549; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=kiIalCgwee3Bs3pglHLhaIRZpjh3/ZJ9xJG7vpjdGFg=; b=ulQ3y3UHpuI2LCuEW3aDpa+ASkhVMY3SrhLrbacSbDHPRP/Czd/YoGkpcwacirazJr THiki4qAC8HvESbZYDORI72bQDBX+eW3mnIdDsN8mSbDd9XH2fL8xtrvfHCKi0+7Uf3r BfJz/4cFVCXki2U9K9rZzBlNac6hOIx+z7Dsk3sTSOXQqnbFXHBzRbrKaRSjqDQnco7c xl8vYvMlc+ILQRmq/Qf3DtEbA81Z/xflOrPZPuLON1bX6YjTbzwPa5v++16cfVDdJ+cH 5gujlcep3XpbxanjXz3HfP5DXJNzRK3vMTzIFvM9DO9lrKKVdddUQYlPMV5b4AHK2C8Q kWUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724330749; x=1724935549; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kiIalCgwee3Bs3pglHLhaIRZpjh3/ZJ9xJG7vpjdGFg=; b=Er4Aqi2aQ4a+I7pqD3AtNk9INWEOUPMPJlRt1K1eU3TJZNP1SQTY0ZAlx/s/5ZrWUh VbO5bKxn3EXru6ifPWkAvrI5LXMd47E9ZJivkl/CMxmWbwBjgwBkEnlHbuCREdLLYBBh OhbLcztGMfs4YU94A9vZcdlP8ZkN4j4nFUmBTwGqLw0v+2kblmCybzX0sQG+BuBWuzMr ir6YL7UcNqDbfre+BiX9AdVd/6VCs5Hxyd5DGudrekHNYf+LMn11Q1k7ERt93FDkqIBh YOAesoGqRrLuMYKfXoPQvnEhGb6LSBd5CYV/r/QHo0TpReExNJ+nQ0/Ynhxlz/vA9JrB XXDw== X-Forwarded-Encrypted: i=1; AJvYcCVajfnuWGLkHYj+aOq8MqgX6Q6ZBOHnv0avKXvpVsyjcJQc7QWMXMrkXfG6i57amf6g72U2pAhtjDs=@vger.kernel.org X-Gm-Message-State: AOJu0YxfNZqBIv4do7BwTOj9pVzpwqeQy+5/tkaP3FmHU/srCu7TQFVj fH5Rb4ahzJ/3iC8IV5J6EH4rN7AUmdb6jhoAAjagjIVL6D7TMYb8mx95I+Cm3u0= X-Google-Smtp-Source: AGHT+IHePOnuBACU1QNRLeZdPr5JHplOIGiBCANPSNUQu/wcp9XqzQdNDj3J3wPgjoLkDbRtraUStw== X-Received: by 2002:a05:600c:358a:b0:428:e820:37b6 with SMTP id 5b1f17b1804b1-42ac5635d94mr15895085e9.31.1724330748805; Thu, 22 Aug 2024 05:45:48 -0700 (PDT) Received: from [127.0.0.1] ([2a01:e0a:448:76e0:8da6:6d6d:c8ed:16c5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac514e269sm24032195e9.2.2024.08.22.05.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 05:45:48 -0700 (PDT) From: Esteban Blanc Date: Thu, 22 Aug 2024 14:45:18 +0200 Subject: [PATCH 2/6] iio: adc: ad4030: add driver for ad4030-24 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240822-eblanc-ad4630_v1-v1-2-5c68f3327fdd@baylibre.com> References: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> In-Reply-To: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nuno Sa , Jonathan Corbet Cc: Michael Hennerich , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner , linux-doc@vger.kernel.org, Esteban Blanc X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openssh-sha256; t=1724330734; l=27046; i=eblanc@baylibre.com; s=yubikey; h=from:subject:message-id; bh=yRyg3WPDghvOIfKYS356DIuYwiqS1518lafwZ5v4wcg=; b=U1NIU0lHAAAAAQAAAhcAAAAHc3NoLXJzYQAAAAMBAAEAAAIBALJZcW6pLD4ksSdWnXd5r65Ze 5Qc5pH7+DmmbKJasOXeVYRPFEmnORS7pwhURG11AMVFmnCVYWj+wPYrbCEeM7XKfO4oQzc66kYB 7y0RrFwjoWKofytjI026zV5b2pn1JAItgu0Ijth+TSa6KVOTSXqqiVzOTDM1WL0hAIIzpkhE3Vt AVJrFDsh/nWed9OpeSS+S6e3ZxyJtlnhqbVIemcDmjwMihtFgTKeJWlxP7KGY/RQKPF/Ef7pS+O AckOrxuqGKvpOiNVCmuQEUQM0+r4uvwtja4zRSl+huqW+g1nLyReoZPzFwfJWREd+89dtTJTXN7 xmmFNdX6KzRKBLVw1RY/R3mhAd+MkrdiNaRNKj+LO1QIxPoW90cPG9WpdVDUZf1VxhdciB6Hlxn lfEDFuCxU0n5H+kC4eiZvw+c9D4xX7iVdjPTMEaE6GBQNnMncdljBwA5NVN8WcaUhnAQnq7qhcz 85L2Br7MPqe3q3J/PHIe0nHO56j7tTY6cFFs/ckqcQSTJigh2rA7InN1d7GqZFLzlewRTGaCY+M 93d7DCIuxTxJWRpVm7NW1FBeX6d00+dAcQ/dS+jmA3kcdRoWtH160jmmYYvOgrsQTcMIQrPtK+B rULRmmIvEIJMF5UfNmxruWmWn6MM/xeejTNszoKqrORpbr7q3BnkKt2y/KdAAAABnBhdGF0dAAA AAAAAAAGc2hhNTEyAAACFAAAAAxyc2Etc2hhMi01MTIAAAIAaJ5APycqj704M8gFxD0EbCkVLbr 1U5GfyPJe5bWj44U0ycMoG1/0kV2l3MlyLGUw6oGV0Amok1HvcQuG0nU7Qa4NRmWKQMxcHZUb5O z/Q7Qdduv8OVdTPad6ki+YWRkoPaz3VG/m5MUbD1xmJ8A62KUsm1lGymrrQJ9P+B6XXd2zIShpY mbOrlQ7RhE6T1zSqhJWSj+s4boAKotWuT2Ai5rYcrBiTGOwnsShA00GfheHSGRRV68QVjCJoyzr fyF9Grlp4GraJcoiu0LXof9LpDNhdrEqNzMEb4X3fcorWjBu1acckOhFZ6kUpenlXlp7E/oNMdN issvQ+DD9I2o8PSuSVkR5dHyYZ6NZZFP2jrnYzvSGuLp/op6XIW5uRLZQgzaNT1iRZJJ5hR1D9D 7xQ419OfZjDcQyJGUZxVlETmVE4TabPcsgvUhcZdOduoiLcouHUSHjJLwaKb/qcKUvN/nOCTNSv gMF4q3ZTUX9XYQFr+ZF5wj22P5D+PGKDq0zXBer/rgytWrndlem8c/qNnSfZtV1D8J5JCcdoXFu pOIi4Lc3IVDIj4BCbWDnZoEhNPs6MX4EGyCdYvqhzYU/mBvtcmbndq4IbVYnf8oIQsHfqD7LVVu u76MgityDiWSuelEAsVI1G1Q5GmiZOBHOXGhB7ebvmVo0SoHSClVWRtw= X-Developer-Key: i=eblanc@baylibre.com; a=openssh; fpr=SHA256:LOxhPHcL6HLuSaOVHuI2Yq7hvD2blbngN1ohWi2rJOw This adds a new driver for the Analog Devices INC. AD4030-24 ADC. The driver implements basic support for the AD4030-24 1 channel differential ADC with hardware gain and offset control. Signed-off-by: Esteban Blanc --- MAINTAINERS | 1 + drivers/iio/adc/Kconfig | 13 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ad4030.c | 854 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 869 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index f17c42bea19c..6a5a0e7b7a51 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -420,6 +420,7 @@ R: Esteban Blanc S: Supported W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml +F: drivers/iio/adc/ad4030.c AD5110 ANALOG DEVICES DIGITAL POTENTIOMETERS DRIVER M: Mugilraj Dhavachelvan diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 88e8ce2e78b3..f4bd05780f6f 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -33,6 +33,19 @@ config AD4000 To compile this driver as a module, choose M here: the module will be called ad4000. +config AD4030 + tristate "Analog Device AD4630 ADC Driver" + depends on SPI + depends on GPIOLIB + select REGMAP_SPI + select IIO_BUFFER + help + Say yes here to build support for Analog Devices AD4030 and AD4630 high speed + SPI analog to digital converters (ADC). + + To compile this driver as a module, choose M here: the module will be + called ad4030. + config AD4130 tristate "Analog Device AD4130 ADC Driver" depends on SPI diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 8b80664c6d6b..0e4f833abf0b 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o obj-$(CONFIG_AD4000) += ad4000.o +obj-$(CONFIG_AD4030) += ad4030.o obj-$(CONFIG_AD4130) += ad4130.o obj-$(CONFIG_AD4695) += ad4695.o obj-$(CONFIG_AD7091R) += ad7091r-base.o diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c new file mode 100644 index 000000000000..a981dce988e5 --- /dev/null +++ b/drivers/iio/adc/ad4030.c @@ -0,0 +1,854 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Analog Devices AD4030 and AD4630 ADC family driver. + * + * Copyright 2024 Analog Devices, Inc. + * Copyright 2024 BayLibre, SAS + * + * based on code from: + * Analog Devices, Inc. + * Sergiu Cuciurean + * Nuno Sa + * Marcelo Schmitt + * Liviu Adace + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AD4030_REG_INTERFACE_CONFIG_A 0x00 +#define AD4030_REG_INTERFACE_CONFIG_A_SW_RESET (BIT(0) | BIT(7)) +#define AD4030_REG_INTERFACE_CONFIG_B 0x01 +#define AD4030_REG_DEVICE_CONFIG 0x02 +#define AD4030_REG_CHIP_TYPE 0x03 +#define AD4030_REG_PRODUCT_ID_L 0x04 +#define AD4030_REG_PRODUCT_ID_H 0x05 +#define AD4030_REG_CHIP_GRADE 0x06 +#define AD4030_REG_CHIP_GRADE_AD4030_24_GRADE 0x10 +#define AD4030_REG_CHIP_GRADE_MASK_CHIP_GRADE GENMASK(7, 3) +#define AD4030_REG_SCRATCH_PAD 0x0A +#define AD4030_REG_SPI_REVISION 0x0B +#define AD4030_REG_VENDOR_L 0x0C +#define AD4030_REG_VENDOR_H 0x0D +#define AD4030_REG_STREAM_MODE 0x0E +#define AD4030_REG_INTERFACE_CONFIG_C 0x10 +#define AD4030_REG_INTERFACE_STATUS_A 0x11 +#define AD4030_REG_EXIT_CFG_MODE 0x14 +#define AD4030_REG_EXIT_CFG_MODE_EXIT_MSK BIT(0) +#define AD4030_REG_AVG 0x15 +#define AD4030_REG_AVG_MASK_AVG_SYNC BIT(7) +#define AD4030_REG_AVG_MASK_AVG_VAL GENMASK(4, 0) +#define AD4030_REG_OFFSET_X0_0 0x16 +#define AD4030_REG_OFFSET_X0_1 0x17 +#define AD4030_REG_OFFSET_X0_2 0x18 +#define AD4030_REG_OFFSET_X1_0 0x19 +#define AD4030_REG_OFFSET_X1_1 0x1A +#define AD4030_REG_OFFSET_X1_2 0x1B +#define AD4030_REG_OFFSET_BYTES_NB 3 +#define AD4030_REG_OFFSET_CHAN(ch) (AD4030_REG_OFFSET_X0_2 + \ + (AD4030_REG_OFFSET_BYTES_NB * \ + (ch))) +#define AD4030_REG_GAIN_X0_LSB 0x1C +#define AD4030_REG_GAIN_X0_MSB 0x1D +#define AD4030_REG_GAIN_X1_LSB 0x1E +#define AD4030_REG_GAIN_X1_MSB 0x1F +#define AD4030_REG_GAIN_MAX_GAIN 1999970 +#define AD4030_REG_GAIN_BYTES_NB 2 +#define AD4030_REG_GAIN_CHAN(ch) (AD4030_REG_GAIN_X0_MSB + \ + (AD4030_REG_GAIN_BYTES_NB * \ + (ch))) +#define AD4030_REG_MODES 0x20 +#define AD4030_REG_MODES_MASK_OUT_DATA_MODE GENMASK(2, 0) +#define AD4030_REG_MODES_MASK_LANE_MODE GENMASK(7, 6) +#define AD4030_REG_OSCILATOR 0x21 +#define AD4030_REG_IO 0x22 +#define AD4030_REG_IO_MASK_IO2X BIT(1) +#define AD4030_REG_PAT0 0x23 +#define AD4030_REG_PAT1 0x24 +#define AD4030_REG_PAT2 0x25 +#define AD4030_REG_PAT3 0x26 +#define AD4030_REG_DIG_DIAG 0x34 +#define AD4030_REG_DIG_ERR 0x35 + +/* Sequence starting with "1 0 1" to enable reg access */ +#define AD4030_REG_ACCESS 0xa0 + +#define AD4030_MAX_IIO_SAMPLE_SIZE_BUFFERED BITS_TO_BYTES(64) +#define AD4030_MAX_HARDWARE_CHANNEL_NB 2 +#define AD4030_MAX_IIO_CHANNEL_NB 5 +#define AD4030_COMMON_BYTE_CHANNELS_FILTER 0xA +/* + * This accounts for for 1 sample per channel plus one u64 for the timestamp, + * aligned on a u64 boundary + */ +#define AD4030_MAXIMUM_RX_BUFFER_SIZE \ + ALIGN(AD4030_MAX_IIO_SAMPLE_SIZE_BUFFERED * \ + AD4030_MAX_HARDWARE_CHANNEL_NB, \ + sizeof(u64)) + sizeof(u64) + +#define AD4030_VREF_MIN_UV (4096 * MILLI) +#define AD4030_VREF_MAX_UV (5000 * MILLI) +#define AD4030_VIO_THRESHOLD_UV (1400 * MILLI) + +#define AD4030_SPI_MAX_XFER_LEN 8 +#define AD4030_SPI_MAX_REG_XFER_SPEED (80 * MEGA) +#define AD4030_TCNVH_NS 10 +#define AD4030_TCNVL_NS 20 +#define AD4030_TCYC_NS 500 +#define AD4030_TCYC_ADJUSTED_NS (AD4030_TCYC_NS - AD4030_TCNVL_NS) +#define AD4030_TRESET_PW_NS 50 +#define AD4030_TRESET_COM_DELAY_MS 750 + +enum ad4030_out_mode { + AD4030_OUT_DATA_MD_16_DIFF = 0x00, + AD4030_OUT_DATA_MD_24_DIFF = 0x00, + AD4030_OUT_DATA_MD_16_DIFF_8_COM = 0x01, + AD4030_OUT_DATA_MD_24_DIFF_8_COM = 0x02, + AD4030_OUT_DATA_MD_30_AVERAGED_DIFF = 0x03, + AD4030_OUT_DATA_MD_32_PATTERN = 0x04 +}; + +struct ad4030_chip_info { + const char *name; + const unsigned long *available_masks; + unsigned int available_masks_len; + const struct iio_chan_spec channels[AD4030_MAX_IIO_CHANNEL_NB]; + u8 grade; + u8 precision_bits; + /* Number of hardware channels */ + int num_channels; + unsigned int tcyc; +}; + +struct ad4030_state { + struct spi_device *spi; + struct regmap *regmap; + const struct ad4030_chip_info *chip; + struct gpio_desc *cnv_gpio; + int vref_uv; + int vio_uv; + int offset_avail[3]; + u32 conversion_speed_hz; + enum ad4030_out_mode mode; + + /* + * DMA (thus cache coherency maintenance) requires the transfer buffers + * to live in their own cache lines. + */ + u8 tx_data[AD4030_SPI_MAX_XFER_LEN] __aligned(IIO_DMA_MINALIGN); + struct { + union { + u8 raw[AD4030_MAXIMUM_RX_BUFFER_SIZE]; + struct { + s32 val; + u32 common; + } __packed buffered[AD4030_MAX_HARDWARE_CHANNEL_NB]; + }; + } rx_data __aligned(IIO_DMA_MINALIGN); +}; + +#define AD4030_CHAN_CMO(_idx) { \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = _idx * 2 + 2, \ + .scan_index = _idx * 2 + 1, \ + .extend_name = "Channel" #_idx " common byte part", \ + .scan_type = { \ + .sign = 'u', \ + .storagebits = 32, \ + .realbits = 8, \ + .endianness = IIO_BE, \ + }, \ +} + +#define AD4030_CHAN_IN(_idx, _storage, _real, _shift) { \ + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_CALIBSCALE) | \ + BIT(IIO_CHAN_INFO_CALIBBIAS) | \ + BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_separate_available = BIT(IIO_CHAN_INFO_CALIBBIAS) | \ + BIT(IIO_CHAN_INFO_CALIBSCALE), \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = _idx * 2, \ + .channel2 = _idx * 2 + 1, \ + .scan_index = _idx * 2, \ + .extend_name = "Channel" #_idx " differential part", \ + .differential = true, \ + .scan_type = { \ + .sign = 's', \ + .storagebits = _storage, \ + .realbits = _real, \ + .shift = _shift, \ + .endianness = IIO_BE, \ + }, \ +} + +static int ad4030_spi_read(void *context, const void *reg, size_t reg_size, + void *val, size_t val_size) +{ + struct ad4030_state *st = context; + + struct spi_transfer xfer = { + .tx_buf = st->tx_data, + .rx_buf = st->rx_data.raw, + .len = reg_size + val_size, + }; + int ret; + + memcpy(st->tx_data, reg, reg_size); + + /* + * This should use spi_write_the_read but when doing so, CS never get + * deasserted. + */ + ret = spi_sync_transfer(st->spi, &xfer, 1); + if (ret) + return ret; + + memcpy(val, &st->rx_data.raw[reg_size], val_size); + + return ret; +} + +static int ad4030_spi_write(void *context, const void *data, size_t count) +{ + const struct ad4030_state *st = context; + + return spi_write(st->spi, data, count); +} + +static const struct regmap_bus ad4030_regmap_bus = { + .read = ad4030_spi_read, + .write = ad4030_spi_write, + .reg_format_endian_default = REGMAP_ENDIAN_BIG, +}; + +static const struct regmap_range ad4030_regmap_rd_range[] = { + regmap_reg_range(AD4030_REG_INTERFACE_CONFIG_A, AD4030_REG_CHIP_GRADE), + regmap_reg_range(AD4030_REG_SCRATCH_PAD, AD4030_REG_STREAM_MODE), + regmap_reg_range(AD4030_REG_INTERFACE_CONFIG_C, AD4030_REG_INTERFACE_STATUS_A), + regmap_reg_range(AD4030_REG_EXIT_CFG_MODE, AD4030_REG_PAT3), + regmap_reg_range(AD4030_REG_DIG_DIAG, AD4030_REG_DIG_ERR), +}; + +static const struct regmap_range ad4030_regmap_wr_range[] = { + regmap_reg_range(AD4030_REG_CHIP_TYPE, AD4030_REG_CHIP_GRADE), + regmap_reg_range(AD4030_REG_SPI_REVISION, AD4030_REG_VENDOR_H), +}; + +static const struct regmap_access_table ad4030_regmap_rd_table = { + .yes_ranges = ad4030_regmap_rd_range, + .n_yes_ranges = ARRAY_SIZE(ad4030_regmap_rd_range), +}; + +static const struct regmap_access_table ad4030_regmap_wr_table = { + .no_ranges = ad4030_regmap_wr_range, + .n_no_ranges = ARRAY_SIZE(ad4030_regmap_wr_range), +}; + +static const struct regmap_config ad4030_regmap_config = { + .reg_bits = 16, + .val_bits = 8, + .read_flag_mask = 0x80, + .rd_table = &ad4030_regmap_rd_table, + .wr_table = &ad4030_regmap_wr_table, + .max_register = AD4030_REG_DIG_ERR, +}; + +static int ad4030_enter_config_mode(struct ad4030_state *st) +{ + st->rx_data.raw[0] = AD4030_REG_ACCESS; + + return spi_write(st->spi, st->rx_data.raw, 1); +} + +static int ad4030_exit_config_mode(struct ad4030_state *st) +{ + return regmap_write(st->regmap, AD4030_REG_EXIT_CFG_MODE, + AD4030_REG_EXIT_CFG_MODE_EXIT_MSK); +} + +static int ad4030_get_chan_gain(struct iio_dev *indio_dev, int ch, int *val, + int *val2) +{ + struct ad4030_state *st = iio_priv(indio_dev); + u16 gain; + int ret; + + ret = regmap_bulk_read(st->regmap, AD4030_REG_GAIN_CHAN(ch), + st->rx_data.raw, AD4030_REG_GAIN_BYTES_NB); + if (ret) + return ret; + + gain = be16_to_cpu(*(u16 *)st->rx_data.raw); + + /* From datasheet: multiplied output = input × gain word/0x8000 */ + *val = gain / 0x8000; + *val2 = mul_u64_u32_div(gain % 0x8000, MICRO, 0x8000); + + return 0; +} + +/* + * @brief Returns the offset where 1 LSB = (VREF/2^precision_bits - 1)/gain + */ +static int ad4030_get_chan_offset(struct iio_dev *indio_dev, int ch, int *val) +{ + struct ad4030_state *st = iio_priv(indio_dev); + int ret; + + ret = regmap_bulk_read(st->regmap, AD4030_REG_OFFSET_CHAN(ch), + st->rx_data.raw, AD4030_REG_OFFSET_BYTES_NB); + if (ret) + return ret; + + switch (st->chip->precision_bits) { + case 16: + *val = sign_extend32(get_unaligned_be16(st->rx_data.raw), 15); + break; + + case 24: + *val = sign_extend32(get_unaligned_be24(st->rx_data.raw), 23); + break; + + default: + return -EINVAL; + } + + return 0; +} + +static int ad4030_set_chan_gain(struct iio_dev *indio_dev, int ch, int gain_int, + int gain_frac) +{ + struct ad4030_state *st = iio_priv(indio_dev); + __be16 *val = (__be16 *)st->rx_data.raw; + u64 gain; + + gain = mul_u32_u32(gain_int, MICRO) + gain_frac; + + if (gain > AD4030_REG_GAIN_MAX_GAIN) + return -EINVAL; + + *val = cpu_to_be16(DIV_ROUND_CLOSEST_ULL(gain * 0x8000, MICRO)); + + return regmap_bulk_write(st->regmap, AD4030_REG_GAIN_CHAN(ch), val, + AD4030_REG_GAIN_BYTES_NB); +} + +static int ad4030_set_chan_offset(struct iio_dev *indio_dev, int ch, int offset) +{ + struct ad4030_state *st = iio_priv(indio_dev); + + if (offset < st->offset_avail[0] || offset > st->offset_avail[2]) + return -EINVAL; + + switch (st->chip->precision_bits) { + case 16: + put_unaligned_be16(offset, st->rx_data.raw); + break; + + case 24: + put_unaligned_be24(offset, st->rx_data.raw); + break; + + default: + return -EINVAL; + } + + return regmap_bulk_write(st->regmap, AD4030_REG_OFFSET_CHAN(ch), + st->rx_data.raw, AD4030_REG_OFFSET_BYTES_NB); +} + +static bool ad4030_is_common_byte_asked(struct ad4030_state *st, + unsigned int mask) +{ + /* Common byte channel is after the "real" differential sample channel */ + return mask & AD4030_COMMON_BYTE_CHANNELS_FILTER; +} + +static int ad4030_set_mode(struct iio_dev *indio_dev, unsigned long mask) +{ + struct ad4030_state *st = iio_priv(indio_dev); + + if (ad4030_is_common_byte_asked(st, mask)) + st->mode = AD4030_OUT_DATA_MD_24_DIFF_8_COM; + else + st->mode = AD4030_OUT_DATA_MD_24_DIFF; + + return regmap_update_bits(st->regmap, AD4030_REG_MODES, + AD4030_REG_MODES_MASK_OUT_DATA_MODE, + st->mode); +} + +static int ad4030_conversion(struct ad4030_state *st, + const struct iio_chan_spec *chan) +{ + unsigned int bytes_to_read; + unsigned char byte_index; + unsigned int i; + int ret; + + /* Number of bytes for one differential channel */ + bytes_to_read = BITS_TO_BYTES(chan->scan_type.realbits); + /* Add one byte if we are using a differential + common byte mode */ + bytes_to_read += (st->mode == AD4030_OUT_DATA_MD_24_DIFF_8_COM || + st->mode == AD4030_OUT_DATA_MD_16_DIFF_8_COM) ? 1 : 0; + /* Mulitiply by the number of hardware channels */ + bytes_to_read *= st->chip->num_channels; + + gpiod_set_value_cansleep(st->cnv_gpio, 1); + ndelay(AD4030_TCNVH_NS); + gpiod_set_value_cansleep(st->cnv_gpio, 0); + ndelay(st->chip->tcyc); + + ret = spi_read(st->spi, st->rx_data.raw, bytes_to_read); + if (ret) + return ret; + + if (st->mode != AD4030_OUT_DATA_MD_24_DIFF_8_COM) + return 0; + + byte_index = BITS_TO_BYTES(chan->scan_type.realbits); + for (i = 0; i < st->chip->num_channels; i++) + st->rx_data.buffered[i].common = ((u8 *)&st->rx_data.buffered[i].val)[byte_index]; + + return 0; +} + +static int ad4030_single_conversion(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, int *val) +{ + struct ad4030_state *st = iio_priv(indio_dev); + int ret; + + ret = ad4030_set_mode(indio_dev, BIT(chan->channel)); + if (ret) + return ret; + + ret = ad4030_exit_config_mode(st); + if (ret) + goto out_exit_config_mode_error; + + ret = ad4030_conversion(st, chan); + if (ret) + goto out_error; + + if (chan->channel % 2) + *val = st->rx_data.buffered[chan->channel / 2].common; + else + *val = st->rx_data.buffered[chan->channel / 2].val; + +out_error: + ad4030_enter_config_mode(st); + +out_exit_config_mode_error: + + if (ret) + return ret; + + return IIO_VAL_INT; +} + +static irqreturn_t ad4030_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct ad4030_state *st = iio_priv(indio_dev); + int ret; + + ret = ad4030_conversion(st, indio_dev->channels); + if (ret) + goto out; + + iio_push_to_buffers_with_timestamp(indio_dev, st->rx_data.raw, + pf->timestamp); + +out: + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + +static const int *ad4030_get_offset_avail(struct ad4030_state *st) +{ + return st->offset_avail; +} + +static const int ad4030_gain_avail[3][2] = { + { 0, 0 }, + { 0, 30 }, + { 1, 999969 }, +}; + +static int ad4030_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, + const int **vals, int *type, + int *length, long mask) +{ + struct ad4030_state *st = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_CALIBBIAS: + *vals = ad4030_get_offset_avail(st); + *type = IIO_VAL_INT; + return IIO_AVAIL_RANGE; + + case IIO_CHAN_INFO_CALIBSCALE: + *vals = (void *)ad4030_gain_avail; + *type = IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_RANGE; + + default: + return -EINVAL; + } +} + +static int ad4030_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long info) +{ + struct ad4030_state *st = iio_priv(indio_dev); + int ret; + + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { + switch (info) { + case IIO_CHAN_INFO_RAW: + return ad4030_single_conversion(indio_dev, chan, val); + + case IIO_CHAN_INFO_SCALE: + *val = (st->vref_uv * 2) / MILLI; + *val2 = st->chip->precision_bits; + return IIO_VAL_FRACTIONAL_LOG2; + + case IIO_CHAN_INFO_CALIBSCALE: + ret = ad4030_get_chan_gain(indio_dev, chan->channel, + val, val2); + if (ret) + return ret; + return IIO_VAL_INT_PLUS_MICRO; + + case IIO_CHAN_INFO_CALIBBIAS: + ret = ad4030_get_chan_offset(indio_dev, chan->channel, + val); + if (ret) + return ret; + return IIO_VAL_INT; + + default: + return -EINVAL; + } + } + + unreachable(); +} + +static int ad4030_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + int val2, long info) +{ + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { + switch (info) { + case IIO_CHAN_INFO_CALIBSCALE: + return ad4030_set_chan_gain(indio_dev, chan->channel, + val, val2); + + case IIO_CHAN_INFO_CALIBBIAS: + return ad4030_set_chan_offset(indio_dev, chan->channel, + val); + + default: + return -EINVAL; + } + } + + unreachable(); +} + +static int ad4030_reg_access(struct iio_dev *indio_dev, unsigned int reg, + unsigned int writeval, unsigned int *readval) +{ + const struct ad4030_state *st = iio_priv(indio_dev); + + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { + if (readval) + return regmap_read(st->regmap, reg, readval); + + return regmap_write(st->regmap, reg, writeval); + } + + unreachable(); +} + +static const struct iio_info ad4030_iio_info = { + .read_avail = ad4030_read_avail, + .read_raw = ad4030_read_raw, + .write_raw = ad4030_write_raw, + .debugfs_reg_access = ad4030_reg_access, +}; + +static int ad4030_buffer_preenable(struct iio_dev *indio_dev) +{ + struct ad4030_state *st = iio_priv(indio_dev); + int ret; + + ret = ad4030_set_mode(indio_dev, *indio_dev->active_scan_mask); + if (ret) + return ret; + + ret = ad4030_exit_config_mode(st); + if (ret) + return ret; + + /* Restore SPI max speed for conversion */ + st->spi->max_speed_hz = st->conversion_speed_hz; + + return 0; +} + +static int ad4030_buffer_postdisable(struct iio_dev *indio_dev) +{ + struct ad4030_state *st = iio_priv(indio_dev); + + /* Make sure the SPI clock is within range to read register */ + st->spi->max_speed_hz = min(st->spi->max_speed_hz, + AD4030_SPI_MAX_REG_XFER_SPEED); + + return ad4030_enter_config_mode(st); +} + +static const struct iio_buffer_setup_ops ad4030_buffer_setup_ops = { + .preenable = ad4030_buffer_preenable, + .postdisable = ad4030_buffer_postdisable, +}; + +static int ad4030_regulators_get(struct ad4030_state *st) +{ + struct device *dev = &st->spi->dev; + static const char * const ids[] = { "vdd-5v", "vdd-1v8" }; + int ret; + + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(ids), ids); + if (ret) + return dev_err_probe(dev, ret, "Failed to enable regulators\n"); + + st->vio_uv = devm_regulator_get_enable_read_voltage(dev, "vio"); + if (st->vio_uv < 0) + return dev_err_probe(dev, st->vio_uv, + "Failed to enable and read vio voltage\n"); + + st->vref_uv = devm_regulator_get_enable_read_voltage(dev, "ref"); + if (st->vref_uv < 0) { + if (st->vref_uv != -ENODEV) + return dev_err_probe(dev, st->vref_uv, + "Failed to read vref voltage\n"); + + /* if not using optional REF, the internal REFIN must be used */ + st->vref_uv = devm_regulator_get_enable_read_voltage(dev, "refin"); + if (st->vref_uv < 0) + return dev_err_probe(dev, st->vref_uv, + "Failed to read vrefin voltage\n"); + } + + if (st->vref_uv < AD4030_VREF_MIN_UV || st->vref_uv > AD4030_VREF_MAX_UV) + return dev_err_probe(dev, -EINVAL, + "vref(%d) must be in the range [%lu %lu]\n", + st->vref_uv, AD4030_VREF_MIN_UV, + AD4030_VREF_MAX_UV); + + return 0; +} + +static int ad4030_reset(struct ad4030_state *st) +{ + struct device *dev = &st->spi->dev; + struct gpio_desc *reset; + int ret; + + /* Use GPIO if available ... */ + reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(reset)) + return dev_err_probe(dev, PTR_ERR(reset), + "Failed to get reset GPIO\n"); + + if (reset) { + ndelay(50); + gpiod_set_value_cansleep(reset, 0); + } else { + /* ... falback to software reset otherwise */ + ret = ad4030_enter_config_mode(st); + if (ret) + return ret; + + ret = regmap_write(st->regmap, AD4030_REG_INTERFACE_CONFIG_A, + AD4030_REG_INTERFACE_CONFIG_A_SW_RESET); + if (ret) + return ret; + } + + /* Wait for reset to complete before communicating to it */ + fsleep(AD4030_TRESET_COM_DELAY_MS); + + /* After reset, conversion mode is enabled. Switch to reg access */ + return ad4030_enter_config_mode(st); +} + +static int ad4030_detect_chip_info(const struct ad4030_state *st) +{ + unsigned int grade; + int ret; + + ret = regmap_read(st->regmap, AD4030_REG_CHIP_GRADE, &grade); + if (ret) + return ret; + + grade = FIELD_GET(AD4030_REG_CHIP_GRADE_MASK_CHIP_GRADE, grade); + if (grade != st->chip->grade) + return dev_err_probe(&st->spi->dev, -EINVAL, + "Unknown grade(0x%x) for %s\n", grade, + st->chip->name); + + return 0; +} + +static int ad4030_config(struct ad4030_state *st) +{ + st->offset_avail[0] = (int)BIT(st->chip->precision_bits - 1) * -1; + st->offset_avail[1] = 1; + st->offset_avail[2] = BIT(st->chip->precision_bits - 1) - 1; + + if (st->vio_uv < AD4030_VIO_THRESHOLD_UV) + return regmap_write(st->regmap, AD4030_REG_IO, + AD4030_REG_IO_MASK_IO2X); + + return 0; +} + +static int ad4030_probe(struct spi_device *spi) +{ + struct device *dev = &spi->dev; + struct iio_dev *indio_dev; + struct ad4030_state *st; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); + if (!indio_dev) + return -ENOMEM; + + st = iio_priv(indio_dev); + st->spi = spi; + + /* Make sure the SPI clock is within range to read register */ + st->conversion_speed_hz = min(spi->max_speed_hz, + AD4030_SPI_MAX_REG_XFER_SPEED); + + st->regmap = devm_regmap_init(dev, &ad4030_regmap_bus, st, + &ad4030_regmap_config); + if (IS_ERR(st->regmap)) + dev_err_probe(dev, PTR_ERR(st->regmap), + "Failed to initialize regmap\n"); + + st->chip = spi_get_device_match_data(spi); + if (!st->chip) + return -EINVAL; + + ret = ad4030_regulators_get(st); + if (ret) + return ret; + + ret = ad4030_reset(st); + if (ret) + return ret; + + ret = ad4030_detect_chip_info(st); + if (ret) + return ret; + + ret = ad4030_config(st); + if (ret) + return ret; + + st->cnv_gpio = devm_gpiod_get(dev, "cnv", GPIOD_OUT_LOW); + if (IS_ERR(st->cnv_gpio)) + return dev_err_probe(dev, PTR_ERR(st->cnv_gpio), + "Failed to get cnv gpio\n"); + + /* + * One hardware channel is split in two software channels when using + * common byte mode. Add one more channel for the timestamp. + */ + indio_dev->num_channels = 2 * st->chip->num_channels + 1; + indio_dev->name = st->chip->name; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &ad4030_iio_info; + indio_dev->channels = st->chip->channels; + indio_dev->available_scan_masks = st->chip->available_masks; + indio_dev->masklength = st->chip->available_masks_len; + + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + ad4030_trigger_handler, + &ad4030_buffer_setup_ops); + if (ret) + return dev_err_probe(dev, ret, "Failed to setup triggered buffer\n"); + + return devm_iio_device_register(dev, indio_dev); +} + +static const unsigned long ad4030_channel_masks[] = { + /* Differential only */ + BIT(0), + /* Differential with common byte */ + GENMASK(1, 0), + 0, +}; + +static const struct ad4030_chip_info ad4030_24_chip_info = { + .name = "ad4030-24", + .available_masks = ad4030_channel_masks, + .available_masks_len = ARRAY_SIZE(ad4030_channel_masks), + .channels = { + AD4030_CHAN_IN(0, 32, 24, 8), + AD4030_CHAN_CMO(0), + IIO_CHAN_SOFT_TIMESTAMP(2), + }, + .grade = AD4030_REG_CHIP_GRADE_AD4030_24_GRADE, + .precision_bits = 24, + .num_channels = 1, + .tcyc = AD4030_TCYC_ADJUSTED_NS, +}; + +static const struct spi_device_id ad4030_id_table[] = { + { "ad4030-24", (kernel_ulong_t)&ad4030_24_chip_info }, + {} +}; +MODULE_DEVICE_TABLE(spi, ad4030_id_table); + +static const struct of_device_id ad4030_of_match[] = { + { .compatible = "adi,ad4030-24", .data = &ad4030_24_chip_info }, + {} +}; +MODULE_DEVICE_TABLE(of, ad4030_of_match); + +static struct spi_driver ad4030_driver = { + .driver = { + .name = "ad4030", + .of_match_table = ad4030_of_match, + }, + .probe = ad4030_probe, + .id_table = ad4030_id_table, +}; +module_spi_driver(ad4030_driver); + +MODULE_AUTHOR("Esteban Blanc "); +MODULE_DESCRIPTION("Analog Devices AD4630 ADC family driver"); +MODULE_LICENSE("GPL"); From patchwork Thu Aug 22 12:45:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esteban Blanc X-Patchwork-Id: 13773313 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.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 BF57D1C9EC6 for ; Thu, 22 Aug 2024 12:45:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330754; cv=none; b=mszy9cHF8h1VkuU2Z1Mlf5kSGhiZJBkX3LCWJ60P+gGYaUSwIMf1uV1SG2kiqdgvEeNFGIOLTNJtqArkXk4IAM9Rt9o51sgrM02ePJbwEGuBeZz5LXvM8iz6Op5c2h/YEYyj5O5LbTBhW/XNSwGz8HUS50xx4Oi3mfzG+UX+a/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330754; c=relaxed/simple; bh=QQzxiUQhyAjTwORKWLJ575locEhWjGN2ZSGTCOKvTGs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hzKG8k6qbOwYfOBRZJH2rTKCnrFYUKjtA7xsI3PvVJ88PsS/5z3oqdQNNsuUBXsNopqUMri6axDWfOlT7iZuP7AQK72ZNOug563oKsnqNyVZ9P4CZshyb7kQJqQ24Jil147AJWkLJkU8wVhFixIANX87RZnlJoLatGU3V9qbU0M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=vsvGvgt9; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="vsvGvgt9" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4280bca3960so5363065e9.3 for ; Thu, 22 Aug 2024 05:45:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724330750; x=1724935550; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=bRPlCQp+NpDCCX834clff8Ifmye/gtR+4GSDVcARXB8=; b=vsvGvgt9R9HN7w4Ui9iLroP6NWvnBTzumPG9nh9yG7wh12r5S9a/UWuMaTZLKgEPnF KjmYIjbdkUCzcDFp3+dnr1dRhAY/QQ/4GAoIcydxvgAYdnXu8MxsZWw0IaEArDcfd2Yu 7C+qkfTVV4agQ0V08xEYZ9y/ZLhmwL8X0yBE+1Hd+WrHg1mOYjnRTtGa7XkYAzUssLqt yf4KV/gNPFDSUJcqDmL3JOtySg2K5un8DesCX1+9nrL6y5fuAYq7iYgyIedKtG0oq1y4 P0FBLVvUFW0W9nrq2U4oO3oqjSabT45GitGDGHx3Odsbep3CqbxVOpHcmW4wmn+6P34Z rlwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724330750; x=1724935550; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bRPlCQp+NpDCCX834clff8Ifmye/gtR+4GSDVcARXB8=; b=suKnrNJJlkwLl91Eno4StpjUKBk2VI22nFnrUk/1rvpBUfXLad2SOVd/oCcr2KkQQ9 BnVKhgAh3nhJV99rSeB3Y4sX+/ApDp8nOWoKHTxWBeu/HCqgTJ6II3h5eXY6J91VJ6Hb pCCHj529IRuN3CJ65hlh6cZNPzpAnyOG/2ApHkdhvvOwM/3lOG6Uxvg59dowrmYQKwbU FQY3gwDeZSDeUk6lYypM8T3FGM91J+ibKXkyyWajSbSzrDXtw+R84c1VCsAaJwZACSlc 2pL0zXRC2a9s4nLmr804ublmxqMrd1UJqZtd1RTDNoDKiMO4T0JQZBUL2/IBvgeyZqIM xBaQ== X-Forwarded-Encrypted: i=1; AJvYcCVcyYwG8PQ6axhjakb8uygP6KNEtDfw4YeC5fvpAbh05+QizeuE7HtTQtM0I4UAKaQcJslas0DhFm0=@vger.kernel.org X-Gm-Message-State: AOJu0YxYOzKUOaztND1naQo4FwN72FB0hXtRFtzQ7TTZe2EskJJ9OFKY NVRIlbl/UStPCMHS+CweAMTI4XwOlLBt8bBqinr8EDecoR9wvRIu3fX6b+vCuKo= X-Google-Smtp-Source: AGHT+IEGHpxGCCMyTr36umtwScsf7Z2ndM00qZRQ7np90qMZEjz1NT2EFZbQhjmYpCe4Im2bZDYAKQ== X-Received: by 2002:a05:600c:3507:b0:428:10d7:a4b1 with SMTP id 5b1f17b1804b1-42abf087a08mr33553965e9.25.1724330749927; Thu, 22 Aug 2024 05:45:49 -0700 (PDT) Received: from [127.0.0.1] ([2a01:e0a:448:76e0:8da6:6d6d:c8ed:16c5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac514e269sm24032195e9.2.2024.08.22.05.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 05:45:49 -0700 (PDT) From: Esteban Blanc Date: Thu, 22 Aug 2024 14:45:19 +0200 Subject: [PATCH 3/6] iio: adc: ad4030: add averaging support Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240822-eblanc-ad4630_v1-v1-3-5c68f3327fdd@baylibre.com> References: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> In-Reply-To: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nuno Sa , Jonathan Corbet Cc: Michael Hennerich , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner , linux-doc@vger.kernel.org, Esteban Blanc X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openssh-sha256; t=1724330735; l=7845; i=eblanc@baylibre.com; s=yubikey; h=from:subject:message-id; bh=QQzxiUQhyAjTwORKWLJ575locEhWjGN2ZSGTCOKvTGs=; b=U1NIU0lHAAAAAQAAAhcAAAAHc3NoLXJzYQAAAAMBAAEAAAIBALJZcW6pLD4ksSdWnXd5r65Ze 5Qc5pH7+DmmbKJasOXeVYRPFEmnORS7pwhURG11AMVFmnCVYWj+wPYrbCEeM7XKfO4oQzc66kYB 7y0RrFwjoWKofytjI026zV5b2pn1JAItgu0Ijth+TSa6KVOTSXqqiVzOTDM1WL0hAIIzpkhE3Vt AVJrFDsh/nWed9OpeSS+S6e3ZxyJtlnhqbVIemcDmjwMihtFgTKeJWlxP7KGY/RQKPF/Ef7pS+O AckOrxuqGKvpOiNVCmuQEUQM0+r4uvwtja4zRSl+huqW+g1nLyReoZPzFwfJWREd+89dtTJTXN7 xmmFNdX6KzRKBLVw1RY/R3mhAd+MkrdiNaRNKj+LO1QIxPoW90cPG9WpdVDUZf1VxhdciB6Hlxn lfEDFuCxU0n5H+kC4eiZvw+c9D4xX7iVdjPTMEaE6GBQNnMncdljBwA5NVN8WcaUhnAQnq7qhcz 85L2Br7MPqe3q3J/PHIe0nHO56j7tTY6cFFs/ckqcQSTJigh2rA7InN1d7GqZFLzlewRTGaCY+M 93d7DCIuxTxJWRpVm7NW1FBeX6d00+dAcQ/dS+jmA3kcdRoWtH160jmmYYvOgrsQTcMIQrPtK+B rULRmmIvEIJMF5UfNmxruWmWn6MM/xeejTNszoKqrORpbr7q3BnkKt2y/KdAAAABnBhdGF0dAAA AAAAAAAGc2hhNTEyAAACFAAAAAxyc2Etc2hhMi01MTIAAAIARmk6JXjFJueN6HQQPJ1uFe0G8IM ixRik//ogrfAlxjmcSK4lrQkY/3ZllZWrqYNFJRaII3Y58+STobfoE7E1wRCwFmD1D+RRfVv9rH re6pZvHc+rj+WnrJxB+WCmVYV5DAgoih12l7GxF2GcAB7Miac33vJ1EgxeAQmqmlsgdHwp8sqAD /QEKjM1kKOzL3+NZfOyzYx/sTxsxAdUUC06QJn65iVFdbAz3Q28r1a49URg40hoJ+amxoXL/52h wAmooIaFWsxsgZc3N1+ObPqqDVTnNcCqyD+4NevGfRTZcS6sTMwB3J7Hju5+bwaj7EKOnCHVISO yQlaJk3smo7ovg+kciXGx8Dbe8IJJ8DkOKNYyjFHdn9AKHRLXk253z7zpcNBPzdfkNl3rCwzX3e MSPcfPJ4LhpA00xwkAUP0mrBHhZPwHDpShHoCuHlQk653h7teKMu9hx7w27Jw3LV6ovxorRWhlr imGWMV0YNamEttcPvX0fVoBO7PlLh3Ev5bzzj5yozHwLFm5Arehap+ssY5znv+oWuaLga81Vh/q hlulydn1uTLj265e9Og9qOikneeqIqz9i6kNZCAfJFgKvlNZ4Ak09zSus0Iuu7mVeWDyhGOULiN ZkiXCvwd5T5ydw7KZcx+zaA0Wtsr3AtQ7LRC4TgOSuWJ9fow/Y7Od6sk= X-Developer-Key: i=eblanc@baylibre.com; a=openssh; fpr=SHA256:LOxhPHcL6HLuSaOVHuI2Yq7hvD2blbngN1ohWi2rJOw This add support for the averaging mode of AD4030 using oversampling IIO attribute Signed-off-by: Esteban Blanc --- drivers/iio/adc/ad4030.c | 126 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 111 insertions(+), 15 deletions(-) diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c index a981dce988e5..e1e1dbf0565c 100644 --- a/drivers/iio/adc/ad4030.c +++ b/drivers/iio/adc/ad4030.c @@ -115,6 +115,18 @@ enum ad4030_out_mode { AD4030_OUT_DATA_MD_32_PATTERN = 0x04 }; +enum { + AD4030_LANE_MD_1_PER_CH, + AD4030_LANE_MD_2_PER_CH, + AD4030_LANE_MD_4_PER_CH, + AD4030_LANE_MD_INTERLEAVED = 0b11, +}; + +enum { + AD4030_SCAN_TYPE_NORMAL, + AD4030_SCAN_TYPE_AVG, +}; + struct ad4030_chip_info { const char *name; const unsigned long *available_masks; @@ -135,6 +147,7 @@ struct ad4030_state { int vref_uv; int vio_uv; int offset_avail[3]; + unsigned int avg_len; u32 conversion_speed_hz; enum ad4030_out_mode mode; @@ -169,8 +182,11 @@ struct ad4030_state { }, \ } -#define AD4030_CHAN_IN(_idx, _storage, _real, _shift) { \ - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), \ +#define AD4030_CHAN_IN(_idx, _scan_type) { \ + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_shared_by_all_available = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ .info_mask_separate = BIT(IIO_CHAN_INFO_CALIBSCALE) | \ BIT(IIO_CHAN_INFO_CALIBBIAS) | \ BIT(IIO_CHAN_INFO_RAW), \ @@ -183,15 +199,16 @@ struct ad4030_state { .scan_index = _idx * 2, \ .extend_name = "Channel" #_idx " differential part", \ .differential = true, \ - .scan_type = { \ - .sign = 's', \ - .storagebits = _storage, \ - .realbits = _real, \ - .shift = _shift, \ - .endianness = IIO_BE, \ - }, \ + .has_ext_scan_type = 1, \ + .ext_scan_type = _scan_type, \ + .num_ext_scan_type = ARRAY_SIZE(_scan_type), \ } +static const int ad4030_average_modes[] = { + 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, + 32768, 65536 +}; + static int ad4030_spi_read(void *context, const void *reg, size_t reg_size, void *val, size_t val_size) { @@ -327,6 +344,13 @@ static int ad4030_get_chan_offset(struct iio_dev *indio_dev, int ch, int *val) return 0; } +static int ad4030_get_avg_frame_len(struct iio_dev *dev) +{ + const struct ad4030_state *st = iio_priv(dev); + + return 1L << st->avg_len; +} + static int ad4030_set_chan_gain(struct iio_dev *indio_dev, int ch, int gain_int, int gain_frac) { @@ -369,6 +393,22 @@ static int ad4030_set_chan_offset(struct iio_dev *indio_dev, int ch, int offset) st->rx_data.raw, AD4030_REG_OFFSET_BYTES_NB); } +static int ad4030_set_avg_frame_len(struct iio_dev *dev, unsigned int avg_len) +{ + struct ad4030_state *st = iio_priv(dev); + unsigned int avg_val = ilog2(avg_len); + int ret; + + ret = regmap_write(st->regmap, AD4030_REG_AVG, AD4030_REG_AVG_MASK_AVG_SYNC | + FIELD_PREP(AD4030_REG_AVG_MASK_AVG_VAL, avg_val)); + if (ret) + return ret; + + st->avg_len = avg_val; + + return 0; +} + static bool ad4030_is_common_byte_asked(struct ad4030_state *st, unsigned int mask) { @@ -380,7 +420,9 @@ static int ad4030_set_mode(struct iio_dev *indio_dev, unsigned long mask) { struct ad4030_state *st = iio_priv(indio_dev); - if (ad4030_is_common_byte_asked(st, mask)) + if (st->avg_len) + st->mode = AD4030_OUT_DATA_MD_30_AVERAGED_DIFF; + else if (ad4030_is_common_byte_asked(st, mask)) st->mode = AD4030_OUT_DATA_MD_24_DIFF_8_COM; else st->mode = AD4030_OUT_DATA_MD_24_DIFF; @@ -394,6 +436,7 @@ static int ad4030_conversion(struct ad4030_state *st, const struct iio_chan_spec *chan) { unsigned int bytes_to_read; + unsigned long cnv_nb = 1UL << st->avg_len; unsigned char byte_index; unsigned int i; int ret; @@ -406,10 +449,12 @@ static int ad4030_conversion(struct ad4030_state *st, /* Mulitiply by the number of hardware channels */ bytes_to_read *= st->chip->num_channels; - gpiod_set_value_cansleep(st->cnv_gpio, 1); - ndelay(AD4030_TCNVH_NS); - gpiod_set_value_cansleep(st->cnv_gpio, 0); - ndelay(st->chip->tcyc); + for (i = 0; i < cnv_nb; i++) { + gpiod_set_value_cansleep(st->cnv_gpio, 1); + ndelay(AD4030_TCNVH_NS); + gpiod_set_value_cansleep(st->cnv_gpio, 0); + ndelay(st->chip->tcyc); + } ret = spi_read(st->spi, st->rx_data.raw, bytes_to_read); if (ret) @@ -508,6 +553,12 @@ static int ad4030_read_avail(struct iio_dev *indio_dev, *type = IIO_VAL_INT_PLUS_MICRO; return IIO_AVAIL_RANGE; + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *vals = ad4030_average_modes; + *type = IIO_VAL_INT; + *length = ARRAY_SIZE(ad4030_average_modes); + return IIO_AVAIL_LIST; + default: return -EINVAL; } @@ -544,6 +595,10 @@ static int ad4030_read_raw(struct iio_dev *indio_dev, return ret; return IIO_VAL_INT; + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *val = ad4030_get_avg_frame_len(indio_dev); + return IIO_VAL_INT; + default: return -EINVAL; } @@ -566,6 +621,9 @@ static int ad4030_write_raw(struct iio_dev *indio_dev, return ad4030_set_chan_offset(indio_dev, chan->channel, val); + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + return ad4030_set_avg_frame_len(indio_dev, val); + default: return -EINVAL; } @@ -589,11 +647,20 @@ static int ad4030_reg_access(struct iio_dev *indio_dev, unsigned int reg, unreachable(); } +static int ad4030_get_current_scan_type(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct ad4030_state *st = iio_priv(indio_dev); + + return st->avg_len ? AD4030_SCAN_TYPE_AVG : AD4030_SCAN_TYPE_NORMAL; +} + static const struct iio_info ad4030_iio_info = { .read_avail = ad4030_read_avail, .read_raw = ad4030_read_raw, .write_raw = ad4030_write_raw, .debugfs_reg_access = ad4030_reg_access, + .get_current_scan_type = ad4030_get_current_scan_type, }; static int ad4030_buffer_preenable(struct iio_dev *indio_dev) @@ -626,9 +693,21 @@ static int ad4030_buffer_postdisable(struct iio_dev *indio_dev) return ad4030_enter_config_mode(st); } +static bool ad4030_validate_scan_mask(struct iio_dev *indio_dev, const unsigned long *scan_mask) +{ + struct ad4030_state *st = iio_priv(indio_dev); + + /* Asking for both common channels and averaging */ + if (st->avg_len && ad4030_is_common_byte_asked(st, *scan_mask)) + return false; + + return true; +} + static const struct iio_buffer_setup_ops ad4030_buffer_setup_ops = { .preenable = ad4030_buffer_preenable, .postdisable = ad4030_buffer_postdisable, + .validate_scan_mask = ad4030_validate_scan_mask, }; static int ad4030_regulators_get(struct ad4030_state *st) @@ -812,12 +891,29 @@ static const unsigned long ad4030_channel_masks[] = { 0, }; +static const struct iio_scan_type ad4030_24_scan_types[] = { + [AD4030_SCAN_TYPE_NORMAL] = { + .sign = 's', + .storagebits = 32, + .realbits = 24, + .shift = 8, + .endianness = IIO_BE, + }, + [AD4030_SCAN_TYPE_AVG] = { + .sign = 's', + .storagebits = 32, + .realbits = 30, + .shift = 2, + .endianness = IIO_BE, + }, +}; + static const struct ad4030_chip_info ad4030_24_chip_info = { .name = "ad4030-24", .available_masks = ad4030_channel_masks, .available_masks_len = ARRAY_SIZE(ad4030_channel_masks), .channels = { - AD4030_CHAN_IN(0, 32, 24, 8), + AD4030_CHAN_IN(0, ad4030_24_scan_types), AD4030_CHAN_CMO(0), IIO_CHAN_SOFT_TIMESTAMP(2), }, From patchwork Thu Aug 22 12:45:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esteban Blanc X-Patchwork-Id: 13773314 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95BCB1C9EA5 for ; Thu, 22 Aug 2024 12:45:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330755; cv=none; b=P0q7f0kdOO7DAKTF5iC9HefW8qKtOJ9vrpSWWjJGsy+b6AZ9EJ5knGzlJUVbNonT29v52VNjMYoW5bZbgUu/dZEYNxmGydDktZL89A3GVIqF/QJbWbwhYz87q6nDcU+XNcl2qewixYK1eooqvdC/sXigcacdmxuLfveSlW5ZtKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330755; c=relaxed/simple; bh=BQq3yuuLfkThDJna9D1JgPWyr017caa7OeVp4BQHD4k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iz7+MsSkaUZzq+46B5I8DthCrcvfWk27GcESyYa/ch8LsSa9FNO4ax7vmaQejW5Dt+r2qBX1DoPywbcLta0iLXmbvtUfYICiLeL84vsdDApaFA5yIOtyvU5iamr4NU0dlAeacIJZnbHjptes1RnPQfnibn4kYNlnsozIk3M7rTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=yVQM6Brg; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="yVQM6Brg" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-428243f928fso7506305e9.0 for ; Thu, 22 Aug 2024 05:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724330751; x=1724935551; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=iHCgooAFPvkDFxrFb/inVvNGAyeXJRZBZky/8+Lq9uc=; b=yVQM6BrgIts+/bwAD6Ft9qvc7ACds6HFhfeBkPLswX81IbgsgmLiCcr5OGxZYGIYSw qZt7zyKIvtNuil7j4cmTSZXkz9E+gNdzksO7wsJ+WA6rtpdhnbXSaJMJ9IQa9RT4WfxZ izY2tehAo9ipu8yFr8CO6lGMugUM9tmSIfBcb8ZP3rBZBh9yzj6oNR0/MyaZHWRg8x70 S10bPG5KmBCsgOjKAJvmpJV02+bO0mkM4OV2glbB9MuBWnI+jwGUwMqQmiFTNTz9u2Fn uMoMdGoBHvulgFhCo8ZmHRC5hUvndR7NcaAKPm5K/SCsDAg55BQBA2J8thXV2GU1Nd8z 0t3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724330751; x=1724935551; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iHCgooAFPvkDFxrFb/inVvNGAyeXJRZBZky/8+Lq9uc=; b=B8/f0t7H6A61zVsgEGEuJEwRl2H5l9YkxiFwqOQwKm32tPHB+9sQ6A+s8vDkN8PhUT 9Akp8OuBl89VX8W4OK8GPcB4lKWYog9NuO03FwoJ7CVdcIUSdBm2CkmdaSadv39r3CX2 tUw5ouhapzGldPYVYVj4JGGtbBcwL/R3XztGxZv/Z038c3lzemG+b/gWS6YW3jCvTWh7 YP2iP4pHeqtoJUF/qJWK+0ToRAmtJ3s6PpL+i0G4gjESlappf2Xw33E0SQMUOnJvK9DC Zre1Wvpa1UBXdtS3Gq+rlyTtVeoaYgUIgwcJLs2UVKpOSm8oO2Rb1WQHhwlwQx2sXPIc THOw== X-Forwarded-Encrypted: i=1; AJvYcCXR47YH3gh4BCheF7uMqtNFzKRWdVIBvHSd7SvzqDs5KQ4PSWAEPAN/Do0MXaYDEunQvtzrdfpYIBM=@vger.kernel.org X-Gm-Message-State: AOJu0YzKCKOm8yZ+MKQpGpJvBUqFwAZR/nUqIlUGSWXW/7CoiVqsLo6L OBDJr95cr5W5hy8JthVQNZ0k95RbkY5Q6XN1REmteeUvUXl5O/3XyDH4kZxEc78= X-Google-Smtp-Source: AGHT+IEFXpryc30XDQogMGJVEBcxhb70P0zXx9O7V7kIQu5RfgvrvoyjomL/2qgxblaDKslhKnP+2w== X-Received: by 2002:a05:600c:1c28:b0:428:e30:fa8d with SMTP id 5b1f17b1804b1-42ac55b274amr15841305e9.6.1724330750977; Thu, 22 Aug 2024 05:45:50 -0700 (PDT) Received: from [127.0.0.1] ([2a01:e0a:448:76e0:8da6:6d6d:c8ed:16c5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac514e269sm24032195e9.2.2024.08.22.05.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 05:45:50 -0700 (PDT) From: Esteban Blanc Date: Thu, 22 Aug 2024 14:45:20 +0200 Subject: [PATCH 4/6] iio: adc: ad4030: add support for ad4630-24 and ad4630-16 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240822-eblanc-ad4630_v1-v1-4-5c68f3327fdd@baylibre.com> References: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> In-Reply-To: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nuno Sa , Jonathan Corbet Cc: Michael Hennerich , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner , linux-doc@vger.kernel.org, Esteban Blanc X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openssh-sha256; t=1724330738; l=10594; i=eblanc@baylibre.com; s=yubikey; h=from:subject:message-id; bh=BQq3yuuLfkThDJna9D1JgPWyr017caa7OeVp4BQHD4k=; b=U1NIU0lHAAAAAQAAAhcAAAAHc3NoLXJzYQAAAAMBAAEAAAIBALJZcW6pLD4ksSdWnXd5r65Ze 5Qc5pH7+DmmbKJasOXeVYRPFEmnORS7pwhURG11AMVFmnCVYWj+wPYrbCEeM7XKfO4oQzc66kYB 7y0RrFwjoWKofytjI026zV5b2pn1JAItgu0Ijth+TSa6KVOTSXqqiVzOTDM1WL0hAIIzpkhE3Vt AVJrFDsh/nWed9OpeSS+S6e3ZxyJtlnhqbVIemcDmjwMihtFgTKeJWlxP7KGY/RQKPF/Ef7pS+O AckOrxuqGKvpOiNVCmuQEUQM0+r4uvwtja4zRSl+huqW+g1nLyReoZPzFwfJWREd+89dtTJTXN7 xmmFNdX6KzRKBLVw1RY/R3mhAd+MkrdiNaRNKj+LO1QIxPoW90cPG9WpdVDUZf1VxhdciB6Hlxn lfEDFuCxU0n5H+kC4eiZvw+c9D4xX7iVdjPTMEaE6GBQNnMncdljBwA5NVN8WcaUhnAQnq7qhcz 85L2Br7MPqe3q3J/PHIe0nHO56j7tTY6cFFs/ckqcQSTJigh2rA7InN1d7GqZFLzlewRTGaCY+M 93d7DCIuxTxJWRpVm7NW1FBeX6d00+dAcQ/dS+jmA3kcdRoWtH160jmmYYvOgrsQTcMIQrPtK+B rULRmmIvEIJMF5UfNmxruWmWn6MM/xeejTNszoKqrORpbr7q3BnkKt2y/KdAAAABnBhdGF0dAAA AAAAAAAGc2hhNTEyAAACFAAAAAxyc2Etc2hhMi01MTIAAAIARSGYQiEfzNlBinOirRbYcf/6B5L eMUq/St2pr4Kv8iM82PQFDDcJ+J60VUxyFCHin1YmHprOJZXOjDkmaUw+Hvabdn4j7cm1rXCxux pdZundtgtAXaY1VzoTVXJr5xg2RimwQPwj81kKwdAeUtkUu51srUMRUdPa5TAU1/T+x1bTNYHBV DoBH5ioIZznbgD9TITLV/kxx5bpt+xpIvUHGGNFDX9mtFCMarZRHX1mQpJcNjsn4sckSwbme7qT S/TOTmfqMGavFvr3nKKUmeMK0TN+swvGP5+vYdPw2wR9IULLJaS80tWYPjMTnCk/L7Y1QmsmbRH n062FJfqrCycZvYttDRzMsOv9ud9s7bPL3K1k/xKtjeOQaTnIdLPNMXh7eTRtnSmMfsZirB+VVU +Xn32Lq8T1d6W8o7D1pMZmnD3+wLJerhlDC9ng8VxNO8DsXIIvyfJjmLrS92AHRP6hSX6rJKCP/ Lo4iOdIY58viwFwrGeTAxd6Zsxeqk17NemyOmSHiTclEsoSaxhFww0Uj7TkqpGdq5LiGuqA2q60 ulfNMJA2ICm0Cqp7KeO9aGYiJUK0t0z60qd/9rY/eYxkbv4t7M26UIopchdw/wmm5/TpUYa5moS 8kxUShJpe0TGaIZ/njifD3v35z/gH4hjPabCeURzLzeXWAW56zPamYyM= X-Developer-Key: i=eblanc@baylibre.com; a=openssh; fpr=SHA256:LOxhPHcL6HLuSaOVHuI2Yq7hvD2blbngN1ohWi2rJOw AD4630-24 and AD4630-16 are 2 channels ADCs. Both channels are interleaved bit per bit on SDO line. Signed-off-by: Esteban Blanc --- drivers/iio/adc/ad4030.c | 197 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 173 insertions(+), 24 deletions(-) diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c index e1e1dbf0565c..dbba5287b630 100644 --- a/drivers/iio/adc/ad4030.c +++ b/drivers/iio/adc/ad4030.c @@ -32,6 +32,8 @@ #define AD4030_REG_PRODUCT_ID_H 0x05 #define AD4030_REG_CHIP_GRADE 0x06 #define AD4030_REG_CHIP_GRADE_AD4030_24_GRADE 0x10 +#define AD4030_REG_CHIP_GRADE_AD4630_16_GRADE 0x03 +#define AD4030_REG_CHIP_GRADE_AD4630_24_GRADE 0x00 #define AD4030_REG_CHIP_GRADE_MASK_CHIP_GRADE GENMASK(7, 3) #define AD4030_REG_SCRATCH_PAD 0x0A #define AD4030_REG_SPI_REVISION 0x0B @@ -159,10 +161,14 @@ struct ad4030_state { struct { union { u8 raw[AD4030_MAXIMUM_RX_BUFFER_SIZE]; - struct { - s32 val; - u32 common; - } __packed buffered[AD4030_MAX_HARDWARE_CHANNEL_NB]; + union { + s32 diff[AD4030_MAX_HARDWARE_CHANNEL_NB]; + struct { + s32 diff; + u32 common; + } __packed + buffered_common[AD4030_MAX_HARDWARE_CHANNEL_NB]; + }; }; } rx_data __aligned(IIO_DMA_MINALIGN); }; @@ -171,7 +177,7 @@ struct ad4030_state { .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .type = IIO_VOLTAGE, \ .indexed = 1, \ - .channel = _idx * 2 + 2, \ + .channel = _idx * 3 + 2, \ .scan_index = _idx * 2 + 1, \ .extend_name = "Channel" #_idx " common byte part", \ .scan_type = { \ @@ -194,8 +200,8 @@ struct ad4030_state { BIT(IIO_CHAN_INFO_CALIBSCALE), \ .type = IIO_VOLTAGE, \ .indexed = 1, \ - .channel = _idx * 2, \ - .channel2 = _idx * 2 + 1, \ + .channel = _idx * 3, \ + .channel2 = _idx * 3 + 1, \ .scan_index = _idx * 2, \ .extend_name = "Channel" #_idx " differential part", \ .differential = true, \ @@ -412,7 +418,7 @@ static int ad4030_set_avg_frame_len(struct iio_dev *dev, unsigned int avg_len) static bool ad4030_is_common_byte_asked(struct ad4030_state *st, unsigned int mask) { - /* Common byte channel is after the "real" differential sample channel */ + /* Common byte channels are after each differential channel */ return mask & AD4030_COMMON_BYTE_CHANNELS_FILTER; } @@ -420,18 +426,69 @@ static int ad4030_set_mode(struct iio_dev *indio_dev, unsigned long mask) { struct ad4030_state *st = iio_priv(indio_dev); - if (st->avg_len) + if (st->avg_len) { st->mode = AD4030_OUT_DATA_MD_30_AVERAGED_DIFF; - else if (ad4030_is_common_byte_asked(st, mask)) - st->mode = AD4030_OUT_DATA_MD_24_DIFF_8_COM; - else + } else if (ad4030_is_common_byte_asked(st, mask)) { + switch (st->chip->precision_bits) { + case 16: + st->mode = AD4030_OUT_DATA_MD_16_DIFF_8_COM; + break; + + case 24: + st->mode = AD4030_OUT_DATA_MD_24_DIFF_8_COM; + break; + + default: + return -EINVAL; + } + } else { st->mode = AD4030_OUT_DATA_MD_24_DIFF; + } return regmap_update_bits(st->regmap, AD4030_REG_MODES, AD4030_REG_MODES_MASK_OUT_DATA_MODE, st->mode); } +/* + * @brief Descramble 2 32bits numbers out of a 64bits. The bits are interleaved: + * 1 bit for first number, 1 bit for the second, and so on... + */ +static void ad4030_extract_interleaved(u8 *src, u32 *ch0, u32 *ch1) +{ + u8 h0, h1, l0, l1; + u32 out0, out1; + u8 *out0_raw = (u8 *)&out0; + u8 *out1_raw = (u8 *)&out1; + + for (int i = 0; i < 4; i++) { + h0 = src[i * 2]; + l1 = src[i * 2 + 1]; + h1 = h0 << 1; + l0 = l1 >> 1; + + h0 &= 0xAA; + l0 &= 0x55; + h1 &= 0xAA; + l1 &= 0x55; + + h0 = (h0 | h0 << 001) & 0xCC; + h1 = (h1 | h1 << 001) & 0xCC; + l0 = (l0 | l0 >> 001) & 0x33; + l1 = (l1 | l1 >> 001) & 0x33; + h0 = (h0 | h0 << 002) & 0xF0; + h1 = (h1 | h1 << 002) & 0xF0; + l0 = (l0 | l0 >> 002) & 0x0F; + l1 = (l1 | l1 >> 002) & 0x0F; + + out0_raw[i] = h0 | l0; + out1_raw[i] = h1 | l1; + } + + *ch0 = out0; + *ch1 = out1; +} + static int ad4030_conversion(struct ad4030_state *st, const struct iio_chan_spec *chan) { @@ -460,12 +517,21 @@ static int ad4030_conversion(struct ad4030_state *st, if (ret) return ret; - if (st->mode != AD4030_OUT_DATA_MD_24_DIFF_8_COM) + if (st->chip->num_channels == 2) + ad4030_extract_interleaved(st->rx_data.raw, + &st->rx_data.diff[0], + &st->rx_data.diff[1]); + + if (st->mode != AD4030_OUT_DATA_MD_16_DIFF_8_COM && + st->mode != AD4030_OUT_DATA_MD_24_DIFF_8_COM) return 0; byte_index = BITS_TO_BYTES(chan->scan_type.realbits); - for (i = 0; i < st->chip->num_channels; i++) - st->rx_data.buffered[i].common = ((u8 *)&st->rx_data.buffered[i].val)[byte_index]; + /* Doing it backward to avoid overlap when reordering */ + for (i = st->chip->num_channels - 1; i > 0; i--) { + st->rx_data.buffered_common[i].diff = st->rx_data.diff[i]; + st->rx_data.buffered_common[i].common = ((u8 *)&st->rx_data.diff[i])[byte_index]; + } return 0; } @@ -489,9 +555,9 @@ static int ad4030_single_conversion(struct iio_dev *indio_dev, goto out_error; if (chan->channel % 2) - *val = st->rx_data.buffered[chan->channel / 2].common; + *val = st->rx_data.buffered_common[chan->channel / 2].common; else - *val = st->rx_data.buffered[chan->channel / 2].val; + *val = st->rx_data.diff[chan->channel / 2]; out_error: ad4030_enter_config_mode(st); @@ -582,14 +648,17 @@ static int ad4030_read_raw(struct iio_dev *indio_dev, return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_CALIBSCALE: - ret = ad4030_get_chan_gain(indio_dev, chan->channel, - val, val2); + ret = ad4030_get_chan_gain(indio_dev, + chan->scan_index / 2, + val, + val2); if (ret) return ret; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_CALIBBIAS: - ret = ad4030_get_chan_offset(indio_dev, chan->channel, + ret = ad4030_get_chan_offset(indio_dev, + chan->scan_index / 2, val); if (ret) return ret; @@ -614,11 +683,14 @@ static int ad4030_write_raw(struct iio_dev *indio_dev, iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { switch (info) { case IIO_CHAN_INFO_CALIBSCALE: - return ad4030_set_chan_gain(indio_dev, chan->channel, - val, val2); + return ad4030_set_chan_gain(indio_dev, + chan->scan_index / 2, + val, + val2); case IIO_CHAN_INFO_CALIBBIAS: - return ad4030_set_chan_offset(indio_dev, chan->channel, + return ad4030_set_chan_offset(indio_dev, + chan->scan_index / 2, val); case IIO_CHAN_INFO_OVERSAMPLING_RATIO: @@ -801,10 +873,24 @@ static int ad4030_detect_chip_info(const struct ad4030_state *st) static int ad4030_config(struct ad4030_state *st) { + int ret; + u8 reg_modes; + st->offset_avail[0] = (int)BIT(st->chip->precision_bits - 1) * -1; st->offset_avail[1] = 1; st->offset_avail[2] = BIT(st->chip->precision_bits - 1) - 1; + if (st->chip->num_channels > 1) + reg_modes = FIELD_PREP(AD4030_REG_MODES_MASK_LANE_MODE, + AD4030_LANE_MD_INTERLEAVED); + else + reg_modes = FIELD_PREP(AD4030_REG_MODES_MASK_LANE_MODE, + AD4030_LANE_MD_1_PER_CH); + + ret = regmap_write(st->regmap, AD4030_REG_MODES, reg_modes); + if (ret) + return ret; + if (st->vio_uv < AD4030_VIO_THRESHOLD_UV) return regmap_write(st->regmap, AD4030_REG_IO, AD4030_REG_IO_MASK_IO2X); @@ -891,8 +977,16 @@ static const unsigned long ad4030_channel_masks[] = { 0, }; +static const unsigned long ad4630_channel_masks[] = { + /* Differential only */ + BIT(0) | BIT(2), + /* Differential with common byte */ + GENMASK(3, 0), + 0, +}; + static const struct iio_scan_type ad4030_24_scan_types[] = { - [AD4030_SCAN_TYPE_NORMAL] = { + [AD4030_OUT_DATA_MD_24_DIFF] = { .sign = 's', .storagebits = 32, .realbits = 24, @@ -908,6 +1002,23 @@ static const struct iio_scan_type ad4030_24_scan_types[] = { }, }; +static const struct iio_scan_type ad4030_16_scan_types[] = { + [AD4030_SCAN_TYPE_NORMAL] = { + .sign = 's', + .storagebits = 32, + .realbits = 16, + .shift = 16, + .endianness = IIO_BE, + }, + [AD4030_SCAN_TYPE_AVG] = { + .sign = 's', + .storagebits = 32, + .realbits = 30, + .shift = 2, + .endianness = IIO_BE, + } +}; + static const struct ad4030_chip_info ad4030_24_chip_info = { .name = "ad4030-24", .available_masks = ad4030_channel_masks, @@ -923,14 +1034,52 @@ static const struct ad4030_chip_info ad4030_24_chip_info = { .tcyc = AD4030_TCYC_ADJUSTED_NS, }; +static const struct ad4030_chip_info ad4630_16_chip_info = { + .name = "ad4630-16", + .available_masks = ad4630_channel_masks, + .available_masks_len = ARRAY_SIZE(ad4630_channel_masks), + .channels = { + AD4030_CHAN_IN(0, ad4030_16_scan_types), + AD4030_CHAN_CMO(0), + AD4030_CHAN_IN(1, ad4030_16_scan_types), + AD4030_CHAN_CMO(1), + IIO_CHAN_SOFT_TIMESTAMP(4), + }, + .grade = AD4030_REG_CHIP_GRADE_AD4630_16_GRADE, + .precision_bits = 16, + .num_channels = 2, + .tcyc = AD4030_TCYC_ADJUSTED_NS, +}; + +static const struct ad4030_chip_info ad4630_24_chip_info = { + .name = "ad4630-24", + .available_masks = ad4630_channel_masks, + .available_masks_len = ARRAY_SIZE(ad4630_channel_masks), + .channels = { + AD4030_CHAN_IN(0, ad4030_24_scan_types), + AD4030_CHAN_CMO(0), + AD4030_CHAN_IN(1, ad4030_24_scan_types), + AD4030_CHAN_CMO(1), + IIO_CHAN_SOFT_TIMESTAMP(4), + }, + .grade = AD4030_REG_CHIP_GRADE_AD4630_24_GRADE, + .precision_bits = 24, + .num_channels = 2, + .tcyc = AD4030_TCYC_ADJUSTED_NS, +}; + static const struct spi_device_id ad4030_id_table[] = { { "ad4030-24", (kernel_ulong_t)&ad4030_24_chip_info }, + { "ad4630-16", (kernel_ulong_t)&ad4630_16_chip_info }, + { "ad4630-24", (kernel_ulong_t)&ad4630_24_chip_info }, {} }; MODULE_DEVICE_TABLE(spi, ad4030_id_table); static const struct of_device_id ad4030_of_match[] = { { .compatible = "adi,ad4030-24", .data = &ad4030_24_chip_info }, + { .compatible = "adi,ad4630-16", .data = &ad4630_16_chip_info }, + { .compatible = "adi,ad4630-24", .data = &ad4630_24_chip_info }, {} }; MODULE_DEVICE_TABLE(of, ad4030_of_match); From patchwork Thu Aug 22 12:45:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esteban Blanc X-Patchwork-Id: 13773315 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 B78571C9EAC for ; Thu, 22 Aug 2024 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330757; cv=none; b=sdOwcmph3T61y5SvG8iZot2rKo3Ug4Q7AViax17MlIN2jkr7Nq1Pf51jDbN5Bqv80+QYt+p0ZPSxiwHJrkHB7s5UTZYY/+RpQ6ChUYDpRkGpRMcaVrVa6cUBlcvZz3O/NtBfzf4FVnBITM4y3hy0dulwpZBI4nYuPY26fviuj9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330757; c=relaxed/simple; bh=5Bnt/F7jZXraT4H2FCJtEpXLhOhHhx7d/lVi5Mpg1Hw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RUhnU3BBNwk1tb32aFtBNd7hkM0ipiB1q25rDUycjjLIBFnLo65WuLtPHGKFJHpetBbYMRJcMy85F0D2fqS1ozpYFH7CNTNYrnskQ2VsL4XIEtIZWMdHAyaeLXGu/nQWy7wjPdOKKjyz171qp9RllrhoZ8PZouBXnNcSkZAVPDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=pnnK3CSK; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="pnnK3CSK" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4280ee5f1e3so5980055e9.0 for ; Thu, 22 Aug 2024 05:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724330752; x=1724935552; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=TePZx7uKybl8XWIbq7pzYvS9pX2NJvAwXyQoj0R4xAI=; b=pnnK3CSK8NrahRtgcaFb2yudiQY8wNB13uCQpYhZw7zkCrMv9P/xonI17FM51+J2zT 1oPo571oP6N/O7aT7RF2KHiGjLllua/bogvWdLVTi7MwjaGQfZhFK0sR7QkiPVC+EBdC yE9mwrKfUgybuq9pu20KBlhbALGQksncmj0JP7PRXX4efMfJwsx11qUjzcPr3I/NxKJK iLcS07rwvN48bOnUCeS2Ida3/SnqJy5ydZEfIBhlNrUBoPinLWe5E24eeXdHc5Iigb+Z 3vgQI21k1do2t5jUJxACe7rWjjcda0T9Rc1SUbgGpj+Gy9q2SJukO+qpOntpRQm/p/7j nvbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724330752; x=1724935552; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TePZx7uKybl8XWIbq7pzYvS9pX2NJvAwXyQoj0R4xAI=; b=CtQvMelUPIGejD9676seS7K608qK+Sh8VbnSARBfCkMSyvKbWL5BgNkp0sWyS4/U0C uxDnx0UCVCzBr1GusmO9NKmytrSAal3F4vW3ecNYoV8xmlVLSF6D8VhxsOl3UPMT2Zjz 4CnnxRS3Dan4OLSTplgzimIvV9wNmNZPNInfB7dNxxoPUSdHarki38QnIkhla6BvyJas RW9w8XxYe6/9FuC3EtADZGlg7tyVJ8qrxYf9Z937lNCcRGtcgATvGghO5eCLYb39A1/5 Y+dkKsfHYD5vi8DHkkpCWZcKv6gSCuVatVBtbxWEnMTQEysjJEXf5FJpq/2i/aXNiI3c XHyg== X-Forwarded-Encrypted: i=1; AJvYcCXEe7y+HDhfyeYku3jY+8hqu8+oYG2mWft0tkOduf5xN7vYv0HKFGhrJak+13P2YFHdCzaxz/zzy00=@vger.kernel.org X-Gm-Message-State: AOJu0YxLElLIv2+I9YmdqNFYEkP0E3KsNg0J3/vQQS/VPmq/n9CbAnpP lwtkZy1V/S0950Msqs7TeVR2acZl2xeIW1tP8tyHiD/GjxEQocueksR9rUOQj3I= X-Google-Smtp-Source: AGHT+IHmD9FFC4YM754r2z9rl+k4CgBL3hfNKSxSwu05zkktDBZ0VY0xQhB1R8q8P3KAkFjy5lKPQA== X-Received: by 2002:a05:600c:310c:b0:428:ec2a:8c94 with SMTP id 5b1f17b1804b1-42abd11e2famr46875155e9.10.1724330752027; Thu, 22 Aug 2024 05:45:52 -0700 (PDT) Received: from [127.0.0.1] ([2a01:e0a:448:76e0:8da6:6d6d:c8ed:16c5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac514e269sm24032195e9.2.2024.08.22.05.45.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 05:45:51 -0700 (PDT) From: Esteban Blanc Date: Thu, 22 Aug 2024 14:45:21 +0200 Subject: [PATCH 5/6] iio: adc: ad4030: add support for ad4632-16 and ad4632-24 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240822-eblanc-ad4630_v1-v1-5-5c68f3327fdd@baylibre.com> References: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> In-Reply-To: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nuno Sa , Jonathan Corbet Cc: Michael Hennerich , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner , linux-doc@vger.kernel.org, Esteban Blanc X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openssh-sha256; t=1724330740; l=3466; i=eblanc@baylibre.com; s=yubikey; h=from:subject:message-id; bh=5Bnt/F7jZXraT4H2FCJtEpXLhOhHhx7d/lVi5Mpg1Hw=; b=U1NIU0lHAAAAAQAAAhcAAAAHc3NoLXJzYQAAAAMBAAEAAAIBALJZcW6pLD4ksSdWnXd5r65Ze 5Qc5pH7+DmmbKJasOXeVYRPFEmnORS7pwhURG11AMVFmnCVYWj+wPYrbCEeM7XKfO4oQzc66kYB 7y0RrFwjoWKofytjI026zV5b2pn1JAItgu0Ijth+TSa6KVOTSXqqiVzOTDM1WL0hAIIzpkhE3Vt AVJrFDsh/nWed9OpeSS+S6e3ZxyJtlnhqbVIemcDmjwMihtFgTKeJWlxP7KGY/RQKPF/Ef7pS+O AckOrxuqGKvpOiNVCmuQEUQM0+r4uvwtja4zRSl+huqW+g1nLyReoZPzFwfJWREd+89dtTJTXN7 xmmFNdX6KzRKBLVw1RY/R3mhAd+MkrdiNaRNKj+LO1QIxPoW90cPG9WpdVDUZf1VxhdciB6Hlxn lfEDFuCxU0n5H+kC4eiZvw+c9D4xX7iVdjPTMEaE6GBQNnMncdljBwA5NVN8WcaUhnAQnq7qhcz 85L2Br7MPqe3q3J/PHIe0nHO56j7tTY6cFFs/ckqcQSTJigh2rA7InN1d7GqZFLzlewRTGaCY+M 93d7DCIuxTxJWRpVm7NW1FBeX6d00+dAcQ/dS+jmA3kcdRoWtH160jmmYYvOgrsQTcMIQrPtK+B rULRmmIvEIJMF5UfNmxruWmWn6MM/xeejTNszoKqrORpbr7q3BnkKt2y/KdAAAABnBhdGF0dAAA AAAAAAAGc2hhNTEyAAACFAAAAAxyc2Etc2hhMi01MTIAAAIAYQUVgYxurWVlK4Gg1qDL7Af2K8n qYuGQDk5lFtyEfY0t6BNYTQOTvjfvUHSSDFSisTmuugQPCt7Rrw/8TAS+bgGwGvgGOmt5+eFq5K J7lZ+NQES8Q1DUeVtmJRs90RDjnS6z5IqjH1Z6M3k/Sf4dUjrdLRVbMAR3ZGKBenru/z2eDF0gQ lSNnDxeZhkNy56xXLuNnUFH9tNePzS4qbMyxw3fod/vmvO84pUVtG7nUCxOzA7i4ZE16f/fRzq+ Vw6B8v/fKkaNj+gvngxNF4DyAmq2vfZyROiVkoKevi4Ie/CISr7aKfzjgUagPKTXK+qfvW6lrYI DPRnM6/0j5f0yMPP1MtdhBFEpH0qQBSI029gTLRZMyZs4/YhmagyqTm0MyQ5LKAPzvfeHtoXsB+ 3+qMKDAgp84nxkLlaZJWShHLv/sMDtRyauh73M7QjWEVw1B0d64MMuLqdGzY9CheP1iQYTM3fuI XsIF5VReIv8YNVY+2XTLsY4n9YYa1XiTU24GLSih/lv9UHEUWrzKlKXiii95DDQrdApzRtZNlJm UFqCaH/uW4thqBerFOLlGRJ5yj4rkV88ua0z6YNzBtB5sL54gc8GxhzJqcRWq3L0uRrNXnPxkzt k8EhRRW8XcXiohAZvB1G8pOjg8eaz/Z8ccTZgqvcwBhmXiTPvxaejUF8= X-Developer-Key: i=eblanc@baylibre.com; a=openssh; fpr=SHA256:LOxhPHcL6HLuSaOVHuI2Yq7hvD2blbngN1ohWi2rJOw AD4632-24 and AD4632-16 are 2 channels ADCs. Both channels are interleaved bit per bit on SDO line. Both of them do not have evaluation board. As such, the support added here can't be tested. Support is provided as best effort until someone get their hands on one. Signed-off-by: Esteban Blanc --- drivers/iio/adc/ad4030.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c index dbba5287b630..d42eb53b5e56 100644 --- a/drivers/iio/adc/ad4030.c +++ b/drivers/iio/adc/ad4030.c @@ -34,6 +34,8 @@ #define AD4030_REG_CHIP_GRADE_AD4030_24_GRADE 0x10 #define AD4030_REG_CHIP_GRADE_AD4630_16_GRADE 0x03 #define AD4030_REG_CHIP_GRADE_AD4630_24_GRADE 0x00 +#define AD4030_REG_CHIP_GRADE_AD4632_16_GRADE 0x05 +#define AD4030_REG_CHIP_GRADE_AD4632_24_GRADE 0x02 #define AD4030_REG_CHIP_GRADE_MASK_CHIP_GRADE GENMASK(7, 3) #define AD4030_REG_SCRATCH_PAD 0x0A #define AD4030_REG_SPI_REVISION 0x0B @@ -106,6 +108,8 @@ #define AD4030_TCYC_NS 500 #define AD4030_TCYC_ADJUSTED_NS (AD4030_TCYC_NS - AD4030_TCNVL_NS) #define AD4030_TRESET_PW_NS 50 +#define AD4632_TCYC_NS 2000 +#define AD4632_TCYC_ADJUSTED_NS (AD4632_TCYC_NS - AD4030_TCNVL_NS) #define AD4030_TRESET_COM_DELAY_MS 750 enum ad4030_out_mode { @@ -1068,10 +1072,46 @@ static const struct ad4030_chip_info ad4630_24_chip_info = { .tcyc = AD4030_TCYC_ADJUSTED_NS, }; +static const struct ad4030_chip_info ad4632_16_chip_info = { + .name = "ad4632-16", + .available_masks = ad4630_channel_masks, + .available_masks_len = ARRAY_SIZE(ad4630_channel_masks), + .channels = { + AD4030_CHAN_IN(0, ad4030_16_scan_types), + AD4030_CHAN_CMO(0), + AD4030_CHAN_IN(1, ad4030_16_scan_types), + AD4030_CHAN_CMO(1), + IIO_CHAN_SOFT_TIMESTAMP(4), + }, + .grade = AD4030_REG_CHIP_GRADE_AD4632_16_GRADE, + .precision_bits = 16, + .num_channels = 2, + .tcyc = AD4632_TCYC_ADJUSTED_NS, +}; + +static const struct ad4030_chip_info ad4632_24_chip_info = { + .name = "ad4632-24", + .available_masks = ad4630_channel_masks, + .available_masks_len = ARRAY_SIZE(ad4630_channel_masks), + .channels = { + AD4030_CHAN_IN(0, ad4030_24_scan_types), + AD4030_CHAN_CMO(0), + AD4030_CHAN_IN(1, ad4030_24_scan_types), + AD4030_CHAN_CMO(1), + IIO_CHAN_SOFT_TIMESTAMP(4), + }, + .grade = AD4030_REG_CHIP_GRADE_AD4632_24_GRADE, + .precision_bits = 24, + .num_channels = 2, + .tcyc = AD4632_TCYC_ADJUSTED_NS, +}; + static const struct spi_device_id ad4030_id_table[] = { { "ad4030-24", (kernel_ulong_t)&ad4030_24_chip_info }, { "ad4630-16", (kernel_ulong_t)&ad4630_16_chip_info }, { "ad4630-24", (kernel_ulong_t)&ad4630_24_chip_info }, + { "ad4632-16", (kernel_ulong_t)&ad4632_16_chip_info }, + { "ad4632-24", (kernel_ulong_t)&ad4632_24_chip_info }, {} }; MODULE_DEVICE_TABLE(spi, ad4030_id_table); @@ -1080,6 +1120,8 @@ static const struct of_device_id ad4030_of_match[] = { { .compatible = "adi,ad4030-24", .data = &ad4030_24_chip_info }, { .compatible = "adi,ad4630-16", .data = &ad4630_16_chip_info }, { .compatible = "adi,ad4630-24", .data = &ad4630_24_chip_info }, + { .compatible = "adi,ad4632-16", .data = &ad4632_16_chip_info }, + { .compatible = "adi,ad4632-24", .data = &ad4632_24_chip_info }, {} }; MODULE_DEVICE_TABLE(of, ad4030_of_match); From patchwork Thu Aug 22 12:45:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esteban Blanc X-Patchwork-Id: 13773316 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1887B1CB144 for ; Thu, 22 Aug 2024 12:45:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330757; cv=none; b=tCjFwIDlivo6bGfzCLGUFJ33l+mB/OzDzcH1kcVXwYzJPQg/8egFPxKLYKnKv/rSmjxXDgkBheBxmlMZjvkkoMhwM6tdsDuHiu3e5kXnHqzvCukiKIUNgujsopL6d7BLrzrNtGW1SLiOjrcIbgNeYLaGQ5sbRZ7BDuLtLXvJ/nI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724330757; c=relaxed/simple; bh=8/hV1jC5oxgrduJTHz/yn/jLU0aRf8ZOOhyI5NvtZNI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nby+5vU36KmbcWMNAO3fqYmZvqwgIuiEbfUPcGXDuS5GXNQZN3slLNTyrrXhWrflyIFlF8lv6kojpAkl0Gw/ezr7iqxBTNq7/kojEv5ZZGxe9wrd3rJqVFMzNfamgLyPCQmViOab+gxAVPIJNpnQ4aduzKisQnOHI8KfW+t6III= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=NNfYv65j; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="NNfYv65j" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-42ab880b73eso5798655e9.0 for ; Thu, 22 Aug 2024 05:45:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724330753; x=1724935553; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=e+KcG1T4hXzL+mbqT29U2Wh5Iq2V0XC85Ca2zKoID7Y=; b=NNfYv65joLPmUDKwQFbagWedyX2y6WMOwXJll9g98u09fOiZ24nZgWXLyJz1Lg+thD A0+0NCfZPllDYTqURoCVMj0XJdhvjO/8ZCd0XjJYhPpmSQEFR+d0LLxCcO+1ijM/vvc4 Lb7CxCURDXL7gOjKrvyKc3o+y/QilN2i2IhqsAJHrxqH4lXKbccHc8z33JaooJgyND8o 2gFqUbMTZqHPjuBxsi3rL9vGVFWh7cNbx7d+mwGY2hDqvWmfQqXJxO4Rsdc65h5tgeYU WZEWBdVcZqN2vTB5lxbckFwOhvPKgkfsCFVwukkAC+NU1Kr8uPut4veo1xd4U3pVxV1V HKHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724330753; x=1724935553; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e+KcG1T4hXzL+mbqT29U2Wh5Iq2V0XC85Ca2zKoID7Y=; b=xKVl5VkJTRSQghc3ZLIa07q/GzKZvZ2gL+ZhnQoOYyMybGKifGdIgMqbu0rCymRF84 UgpCLiUZFdhBWybgmbBWqTG0VRRKRIGfFIZWxp3T85X0qVQvg8yTfX4T3oa1OUtHluL5 s6QBpDLuPqi1MWoCHPBbDn0ZlMtkEoqIMcmOB143orTslbKFvtetf8FZTaKI0fKM6j69 1YbnIdIgnTMOf2HSbOZrvFTK4AWdkZBXJmy+zFLsAmDDjQ562ZMcZ/zdpi50X2+shQHu njiTIwQua/AzxywZzucafaPVC6iCkxHXRHj6kEfPZEdtDd8BECvPK5hVKdGCOgC54lOC fjug== X-Forwarded-Encrypted: i=1; AJvYcCVYmwAkMrmrxg0f6toaoP1aUDg6siOdgrh5A7HZxrk/XGZPU/s07/k0mV5/wrrb1X6ER+ayb1kXLTo=@vger.kernel.org X-Gm-Message-State: AOJu0YwcTGYsX0OLxHj072wv6AyxD1RTpBh0HCjs77DsvzqP9jwSgrna 5NesPwkffJcdopLczR8E0u1jsxUbyLPKU3jegFnCYHsc7/jPB6FUTbj10Pe+er4= X-Google-Smtp-Source: AGHT+IGlidXYZzGZq7cpWwep1Kgg7I/ZWcxTht8w0og0Bna8uCzD9WVBMLjbnb3evDSrrrv3V8wIwA== X-Received: by 2002:a05:600c:3c9e:b0:427:98b4:624b with SMTP id 5b1f17b1804b1-42abd2459f5mr43794195e9.24.1724330753046; Thu, 22 Aug 2024 05:45:53 -0700 (PDT) Received: from [127.0.0.1] ([2a01:e0a:448:76e0:8da6:6d6d:c8ed:16c5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac514e269sm24032195e9.2.2024.08.22.05.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 05:45:52 -0700 (PDT) From: Esteban Blanc Date: Thu, 22 Aug 2024 14:45:22 +0200 Subject: [PATCH 6/6] docs: iio: ad4030: add documentation Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240822-eblanc-ad4630_v1-v1-6-5c68f3327fdd@baylibre.com> References: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> In-Reply-To: <20240822-eblanc-ad4630_v1-v1-0-5c68f3327fdd@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nuno Sa , Jonathan Corbet Cc: Michael Hennerich , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner , linux-doc@vger.kernel.org, Esteban Blanc X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openssh-sha256; t=1724330743; l=5098; i=eblanc@baylibre.com; s=yubikey; h=from:subject:message-id; bh=8/hV1jC5oxgrduJTHz/yn/jLU0aRf8ZOOhyI5NvtZNI=; b=U1NIU0lHAAAAAQAAAhcAAAAHc3NoLXJzYQAAAAMBAAEAAAIBALJZcW6pLD4ksSdWnXd5r65Ze 5Qc5pH7+DmmbKJasOXeVYRPFEmnORS7pwhURG11AMVFmnCVYWj+wPYrbCEeM7XKfO4oQzc66kYB 7y0RrFwjoWKofytjI026zV5b2pn1JAItgu0Ijth+TSa6KVOTSXqqiVzOTDM1WL0hAIIzpkhE3Vt AVJrFDsh/nWed9OpeSS+S6e3ZxyJtlnhqbVIemcDmjwMihtFgTKeJWlxP7KGY/RQKPF/Ef7pS+O AckOrxuqGKvpOiNVCmuQEUQM0+r4uvwtja4zRSl+huqW+g1nLyReoZPzFwfJWREd+89dtTJTXN7 xmmFNdX6KzRKBLVw1RY/R3mhAd+MkrdiNaRNKj+LO1QIxPoW90cPG9WpdVDUZf1VxhdciB6Hlxn lfEDFuCxU0n5H+kC4eiZvw+c9D4xX7iVdjPTMEaE6GBQNnMncdljBwA5NVN8WcaUhnAQnq7qhcz 85L2Br7MPqe3q3J/PHIe0nHO56j7tTY6cFFs/ckqcQSTJigh2rA7InN1d7GqZFLzlewRTGaCY+M 93d7DCIuxTxJWRpVm7NW1FBeX6d00+dAcQ/dS+jmA3kcdRoWtH160jmmYYvOgrsQTcMIQrPtK+B rULRmmIvEIJMF5UfNmxruWmWn6MM/xeejTNszoKqrORpbr7q3BnkKt2y/KdAAAABnBhdGF0dAAA AAAAAAAGc2hhNTEyAAACFAAAAAxyc2Etc2hhMi01MTIAAAIABSG0ktK7ZMQWGu1+uSw9h2ii21j AVWCVke/PehbapdM+q0HpQM8j6sz/URuLO6KYA7uig2Vdv1VzuVht/FGJsJMDTJs5Rb2AUw3qsy cDwGbfgqzyE7d2mVIEB50mTBBt0/lOF3CAQpN98V4UyD98xSHcUoGyhdF+Qnpd04+a5Ve5X//1Z m/1nU5h5kESF0XkJoxdSDwe2NNDwbW/8Q0JCCEK+Tt93cutNi63ls9LAtWc+k1aUyfznGA2NrvK tWkU0eMTo6po/wj3WVpzZbDZ41kNcbyLorgnv5YW8leff7SxhuNCQjhR72gpVIyTTYDz+V6x/Dq EFxWjMcCu2ZXlDLrHm9e3fjV+totUj+0X2T8cST3aQKfRj/CpZoAJZMpgv2R8y62LRwhNKKHr8f O8YSDCZFzvO08T0GDu382O7Xqxw91nFNP0TWLExb2texbpQ82S1hurl719p7/2SGdk5QZ5nPrP/ rS3houvJLoU1c+L+/dmaUhvrB/s+TgMBXyinWtnB8gYrlPbbB2FT+3lER43j2/RP0G3gAP9O0e4 EH7by0UcwliEsa3vmhoB8HY1DQIL1edvo5nQ+2kyKY/iBsis1oXWb4dIaU0fGY/DnF1Wt8CUryD OXH6B4u6HCByXi/R8wRC0+2ZJr9nQWCFBYlbO/4Eqczzwihbl8XYZU10= X-Developer-Key: i=eblanc@baylibre.com; a=openssh; fpr=SHA256:LOxhPHcL6HLuSaOVHuI2Yq7hvD2blbngN1ohWi2rJOw This adds a new page to document how to use the ad4030 ADC driver Signed-off-by: Esteban Blanc --- Documentation/iio/ad4030.rst | 129 +++++++++++++++++++++++++++++++++++++++++++ Documentation/iio/index.rst | 1 + MAINTAINERS | 1 + 3 files changed, 131 insertions(+) diff --git a/Documentation/iio/ad4030.rst b/Documentation/iio/ad4030.rst new file mode 100644 index 000000000000..56e0ba58b127 --- /dev/null +++ b/Documentation/iio/ad4030.rst @@ -0,0 +1,129 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +============= +AD4030 driver +============= + +ADC driver for Analog Devices Inc. AD4030 and similar devices. The module name +is ``ad4030``. + + +Supported devices +================= + +The following chips are supported by this driver: + +* `AD4030-24 `_ +* `AD4630-16 `_ +* `AD4630-24 `_ +* `AD4632-16 `_ +* `AD4632-24 `_ + +IIO channels +============ + +Each "device" channel as described in the datasheet is split in 2 IIO channels, +in the following order: + +- One channel for the differential data +- One channel for the common byte. + +Supported features +================== + +SPI wiring modes +---------------- + +The driver currently supports the following SPI wiring configurations: + +One lane mode +^^^^^^^^^^^^^ + +In this mode, each channel has its own SDO line to send the conversion results. +At the moment this mode can only be used on AD4030 which has one channel so only +one SDO line is used. + +.. code-block:: + + +-------------+ +-------------+ + | ADC | | HOST | + | | | | + | CNV |<--------| CNV | + | CS |<--------| CS | + | SDI |<--------| SDO | + | SDO0 |-------->| SDI | + | SCLK |<--------| SCLK | + +-------------+ +-------------+ + +Interleaved mode +^^^^^^^^^^^^^^^^ + +In this mode, both channels conversion results are bit interleaved one SDO line. +As such the wiring is the same as `One lane mode`. + +SPI Clock mode +-------------- + +Only the SPI clocking mode is supported. + +Output modes +------------ + +There is more exposed IIO channels than channels as describe in the devices +datasheet. This is due to the `Differential data + 8-bit common-mode` encoding +2 types of information in one conversion result. As such a "device" channel +provides 2 IIO channels, one for the differential data and one for the common +byte. + +Differential data +^^^^^^^^^^^^^^^^^ + +This mode is selected when: + +- Only differential channels are selected +- Oversampling attribute is set to 1 + +Differential data + common-mode +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This mode is selected when: + +- Differential and common-mode channels are selected +- Oversampling attribute is set to 1 + +For the 24-bits chips, this mode is also available with 16-bits differential +data but is not selectable yet. + +Averaged differential data +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This mode is selected when: + +- Only differential channels are selected +- Oversampling attribute is greater than 1 + +Reference voltage +----------------- + +The chip supports an external reference voltage via the ``REF`` input or an +internal buffered reference voltage via the ``REFIN`` input. The driver looks +at the device tree to determine which is being used. If ``ref-supply`` is +present, then the external reference voltage is used and the internal buffer is +disabled. If ``refin-supply`` is present, then the internal buffered reference +voltage is used. + +Reset +----- + +Both hardware and software reset are supported. The driver looks first at the +device tree to see if the `reset-gpio` is populated. If not present, the driver +will fallback to a software reset by wiring to the device's registers. + +Unimplemented features +---------------------- + +- ``BUSY`` indication +- Additional wiring modes +- Additional clock modes +- Differential data 16-bits + common-mode for 24-bits chips + diff --git a/Documentation/iio/index.rst b/Documentation/iio/index.rst index dfcf9618568a..61faf3a60da6 100644 --- a/Documentation/iio/index.rst +++ b/Documentation/iio/index.rst @@ -19,6 +19,7 @@ Industrial I/O Kernel Drivers :maxdepth: 1 ad4000 + ad4030 ad4695 ad7380 ad7944 diff --git a/MAINTAINERS b/MAINTAINERS index 6a5a0e7b7a51..4a076a48648a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -420,6 +420,7 @@ R: Esteban Blanc S: Supported W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml +F: Documentation/iio/ad4030.c F: drivers/iio/adc/ad4030.c AD5110 ANALOG DEVICES DIGITAL POTENTIOMETERS DRIVER