From nobody Tue Dec 16 22:01:50 2025 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 ECBA124F5B2 for ; Mon, 10 Feb 2025 16:12:48 +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=1739203971; cv=none; b=raIxJUV1/ZcEL3txPAemctsdmb6YG0GCrpwX0QFyoYfh0FWM7NVTz2xaOmd+IN50NP5M4lozxZ8BJ0r4X4fX+EyeLUtyOBoJGECmC8CEHZQdI7An93nbNXR3P0yWet/par41m91e7K2PbHxr8n8xUNz9cYhH0LO0P2VhCQrKLu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203971; c=relaxed/simple; bh=kwXNLzhFPFgyK/MlGtAAE9ABab95SL1ZniFztnA4y0g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZOLR6PJ7IuEq9xfH5PxgoEoArpvl2o6tweAdu/Ns0S/2f9pN6i5bXiuQNe/l3KeuWYUmZfeLhzk9Cv+u7eUqMjmk+PhimTQ0QIQstuUg1MCOwwtpCuOxCbPTRXcA7i9Q8I5opS6hwf9Wwy9VL1KaFaVpj5oA66eeowdmfjOBg4g= 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=BfCR18ZN; 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="BfCR18ZN" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4361b0ec57aso45659875e9.0 for ; Mon, 10 Feb 2025 08:12:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203967; x=1739808767; 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=ZV+Yf08/wUq3PiOCJhJtefxQLfQ45hPPGLK7YrRpA/4=; b=BfCR18ZN+/VahWFxZEkkPQ7vTz3nomWVCEmKo5x839hXSXPVGXug3glceg3q85fjp1 AdoaG+PjVHD0T64PnowERzm5+962Hq2Wb2LMrwN+/dol3K7sa8GVrIv8JihPiwnl+3Gb S8MJ5N5j0OqP8X9N/y0/vHjpNtU6lXbKJwpWGe04RX4eTpP66ZSzUhL1FbB35Dv0gMJK iLuTMDS0fKTdnX31i0vUcn5kcSel2EHaL/rDAcBTIp1ff2f8NMmOFUh5l1McNCXhuVol Ib1EVxZn/OkdZQvJRcqE9eSdxa+6vrPVARagPU/n93KY0Rgomf4+Y60/YO3GY/Pypuh+ 2qhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203967; x=1739808767; 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=ZV+Yf08/wUq3PiOCJhJtefxQLfQ45hPPGLK7YrRpA/4=; b=gL89L9jQxrPjh+8BDgi07mJU1uJ6s5+PzKomsnXqGH4D8Af0TRdQkBc03rx0mJKeLv 8Ay3PvfEjFggybQbwQcGfAgYcb4ad0xKq1X7t8dyinDqCSkPVLyaXwLdm4raZ8GoSjyq VP+oG5ODkxDnOds26SrLA+ie3WVMH3H7vpFij+QyOmvFOJsdJMQdK38jj+IljcXozJoM VdAcMSyPJyF0G7SoLsAM6weFGtS5qFSVJrGm/Z+ZLcy/Wmai1283TxKRlcBQ6P+Bbeyi gNrkpernsBQQ9VLRA1LkdWEDDrCoascdqoRzLL1vvl5N3/hWueK2x1r4xRE6EqmJrYF7 U+DA== X-Forwarded-Encrypted: i=1; AJvYcCUbyKl1OFXgWGPyxgeURHUhppp7+V6q3/AnDEiick6g4bYTj3nUwpJXC1owhafKkUoXWxO4VJYLwNnxBHs=@vger.kernel.org X-Gm-Message-State: AOJu0Yyn6ZAdKWpjwJ4BX5kVPdxyGVXzJK+E/EZ/ptZKP3rIRnglANSS uNMi5HeQvoNm3IX30CRVNXiiwsKFtRS0tAyfegAy1auneE/qxMUnTPQC6KWE5Po= X-Gm-Gg: ASbGncvEiI6E1sQRuEoYNMjvGRyKU7TSZqfsv46t+do6OqNGXi1Ye0owDXV64pfgUne g5jleg7prgm7hwPX3Q3DupEFvJasBuWq1dV8tB+4eh6GdpcftM9nOOtu7EsluWHh2qKDO4qTT8o lGnsyVFIgsvZAkvBo8kd8ULlFFUHD/6wLoseB51z2hlZJaKWl3txnnrcHaB3VlO70Xl1kNgnQrH eIgAgCaySVJUgqBUJpmD9E+tDNfjXJrKz/loIRxkwHUA6Qgl8647n6i/CDh/itOw9318hskk4KN IgWq05Uohxs5TkO/VYfKKs2YEzWSxjmNuxKomFki4I5bMZX3MxbpWtwOjK6qK50= X-Google-Smtp-Source: AGHT+IGgyxX44rjF1KJGAip5mLP3aLFiEOhklfEJtIQ41ZzowIfjzJkIh5pN6a37Asl7/w2ldYJ5SA== X-Received: by 2002:a05:600c:1e25:b0:436:17e4:ad4c with SMTP id 5b1f17b1804b1-43924972ce9mr111412145e9.6.1739203967218; Mon, 10 Feb 2025 08:12:47 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:46 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:51 +0100 Subject: [PATCH v4 1/9] dt-bindings: iio: dac: adi-axi-adc: add ad7606 variant Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-1-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Guillaume Stols A new compatible is added to reflect the specialized version of the HDL. We use the parallel interface to write the ADC's registers, and accessing this interface requires to use ADI_AXI_REG_CONFIG_RD, ADI_AXI_REG_CONFIG_WR and ADI_AXI_REG_CONFIG_CTRL in a custom fashion. Reviewed-by: Rob Herring (Arm) Signed-off-by: Guillaume Stols Co-developed-by: Angelo Dureghello Signed-off-by: Angelo Dureghello --- .../devicetree/bindings/iio/adc/adi,axi-adc.yaml | 70 ++++++++++++++++++= +++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/D= ocumentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml index e1f450b80db2..4fa82dcf6fc9 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml @@ -17,13 +17,23 @@ description: | interface for the actual ADC, while this IP core will interface to the data-lines of the ADC and handle the streaming of data into memory via DMA. + In some cases, the AXI ADC interface is used to perform specialized + operation to a particular ADC, e.g access the physical bus through + specific registers to write ADC registers. + In this case, we use a different compatible which indicates the target + IP core's name. + The following IP is currently supported: + - AXI AD7606x: specialized version of the IP core for all the chips fr= om + the ad7606 family. =20 https://wiki.analog.com/resources/fpga/docs/axi_adc_ip + http://analogdevicesinc.github.io/hdl/library/axi_ad7606x/index.html =20 properties: compatible: enum: - adi,axi-adc-10.0.a + - adi,axi-ad7606x =20 reg: maxItems: 1 @@ -47,17 +57,48 @@ properties: '#io-backend-cells': const: 0 =20 + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + "^adc@[0-9a-f]+$": + type: object + properties: + reg: + maxItems: 1 + additionalProperties: true + required: + - compatible + - reg + required: - compatible - dmas - reg - clocks =20 +allOf: + - if: + properties: + compatible: + not: + contains: + const: adi,axi-ad7606x + then: + properties: + '#address-cells': false + '#size-cells': false + patternProperties: + "^adc@[0-9a-f]+$": false + additionalProperties: false =20 examples: - | - axi-adc@44a00000 { + adc@44a00000 { compatible =3D "adi,axi-adc-10.0.a"; reg =3D <0x44a00000 0x10000>; dmas =3D <&rx_dma 0>; @@ -65,4 +106,31 @@ examples: clocks =3D <&axi_clk>; #io-backend-cells =3D <0>; }; + - | + #include + parallel_bus_controller@44a00000 { + compatible =3D "adi,axi-ad7606x"; + reg =3D <0x44a00000 0x10000>; + dmas =3D <&rx_dma 0>; + dma-names =3D "rx"; + clocks =3D <&ext_clk>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + adc@0 { + compatible =3D "adi,ad7606b"; + reg =3D <0>; + pwms =3D <&axi_pwm_gen 0 0>; + pwm-names =3D "convst1"; + avcc-supply =3D <&adc_vref>; + vdrive-supply =3D <&vdd_supply>; + reset-gpios =3D <&gpio0 91 GPIO_ACTIVE_HIGH>; + standby-gpios =3D <&gpio0 90 GPIO_ACTIVE_LOW>; + adi,range-gpios =3D <&gpio0 89 GPIO_ACTIVE_HIGH>; + adi,oversampling-ratio-gpios =3D <&gpio0 88 GPIO_ACTIVE_HIGH + &gpio0 87 GPIO_ACTIVE_HIGH + &gpio0 86 GPIO_ACTIVE_HIGH>; + io-backends =3D <¶llel_bus_controller>; + }; + }; ... --=20 2.47.0 From nobody Tue Dec 16 22:01:50 2025 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 9E79E24FC04 for ; Mon, 10 Feb 2025 16:12: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=1739203972; cv=none; b=LHMVK31Uuq3oJHPA0r00sw/m4gHHxpfjoaCxokKdrTOAQ3IS3FYBvtQfVb++O2oK6RMa010pJtOXq7A687eOx6N3qHeHfmIQ3iQveGN9YcQwmeuUnkmNB0tkNewDN2jo3jl5FujhVseXUaAAzr/uTnOfzwbPaKxqnqgkFTCmv3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203972; c=relaxed/simple; bh=dioqZv2txBsr2G2NsI3KTjuvSsHBK1WMQvxJwpSgCpc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iwGa1TTnSxsgRjbjpwqXRDGAcbjiL8ru6ku/ZIhMq8sFj3A36gObdOYjaKFedWpxfWje+fMmgZXdCOhDZozp/FFKACuol50Ch8K7ba3tEpeUPbM2j9+Jf9Mk0ODIjYxT0YKgUTn0fSpIv6817tF2gu/zcnznKwkQYpke9J9/CNQ= 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=b9y3MuMF; 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="b9y3MuMF" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-439473da55aso6259945e9.2 for ; Mon, 10 Feb 2025 08:12:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203969; x=1739808769; 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=wlrP600R/ci5wFmyR+m1ecPzb5qUkdneDDlwcUEYxOc=; b=b9y3MuMFXdZk5UnwGNkzL3tGF/UoguHHXLfUTzvSVsX3Z+eXGBM6cMqME+9CxFlEzF fKfuWy5VdEs5/+vZXnMVsSKxzqQ1s4zbMGIZozZyfSzY/sIo+WPGsR90me2vjhRZwzmA otljs5BZR4bFEfYmXUh39yhIO8QwBREXOYTFF4P4kWBmXG8xU2zSGTfwlheccqBUSs81 5LtR5Dd+BY3425MXiqANpHcBoNoHADAqfyJNYQiTc+FDQ890bIThjMxELGhLQQvf9lmq fJal8c3qgAeAfif2zwBvOx6OeCZvqUeZJ0pUCrGnpaSC2Zvifo858zHBUuML9MZ5pQtk YSZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203969; x=1739808769; 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=wlrP600R/ci5wFmyR+m1ecPzb5qUkdneDDlwcUEYxOc=; b=NLAOCBCYC+SQaoIlU7wHD3aHPfEZpUE91JDZhj8zKlb4edos1K1B/NddRoFvFt9BfO yNLmsJSPrZYmu3l2GcGIJ5QV71TLNgMeFRysBvkDS6j/C2rL+SeIU8ALoxyW+3VM6KCb gHgR8HeDmw7uwe9N48QTXq8vRfhGoDNsOfZ722shbSDmC7kInoCxId+HNgyNGtcMNLBN re/Y8jsMiExkAWQ6sGWnGqX6qV4qGX7d6utsq1/UGFz3oKkmvMBJfZu/zmOOXMJRb+lp 24ySn8XEL+hCa36epSe794PMckfM1bPcVc8vMD/RgtmpfRippPPzkd9tcTDvzFJbHnet WD2Q== X-Forwarded-Encrypted: i=1; AJvYcCVmKwGFSibywlMWzJQg2tARTMmmohfQUXpArtZlxkiW1W75wJEFJw3m/qHb6KCuYtBDMaCXbTXhmIWzY/c=@vger.kernel.org X-Gm-Message-State: AOJu0Yz50jutb6COZnE9vbnGz7HiUcVBmkPQnYofoDxjolgAg1ygQ7g0 ic6XjTDna2v8pp55iHfjdwpdcqFbGVZNUNcWT8VST0oOfU6ttyfsV2LclY9DaD4= X-Gm-Gg: ASbGncuPzUT/Wu7kFen3lEgqeU5U010sWvOsqbCng23rqWLQV6A/nWyvAC0XfnqI/pO VVVm/yZl1zAAu5q+Fsgt43f71h1Up0+BFlgXczhVW+lN3O+z2icLkQFpIwEf4o6MalId8emLmEf YNxHQKOmr0RO/Sbi60ymEexzvUzHC0bZrzcI41zHHL7WUJIpn8z95olsRXiS+VVZIM+mmzTtsTW EkA1pojv6UwawLn4q9AzIRFLxFNT09Fs9Xh4aOfoHQLtnqMgHKadAcohk6GgYLeQfrodMZjGrnE JxJv+AV6SOO7n7KL52Ik2an2ZCSUBbpIjzTmDVg3ZmbtipdtmH6IVhL3J8wzSUk= X-Google-Smtp-Source: AGHT+IGQ20TR8IqLo3bvMy0IcaAnfycl4PjoyxaTBZPLOGAxAxi90IcCYacmnO7KRYC2/BYvJFVsqQ== X-Received: by 2002:a05:600c:6dd7:b0:439:31e0:d9a2 with SMTP id 5b1f17b1804b1-43931e0dfeamr74180395e9.3.1739203968869; Mon, 10 Feb 2025 08:12:48 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:48 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:52 +0100 Subject: [PATCH v4 2/9] iio: adc: ad7606: move the software mode configuration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-2-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Guillaume Stols This is a preparation for the intoduction of the sofware functions in the iio backend version of the driver. The software mode configuration must be executed once the channels are configured, and the number of channels is known. This is not the case before iio-backend's configuration is called, and iio backend version of the driver does not have a timestamp channel. Also the sw_mode_config callback is configured during the iio-backend configuration. For clarity purpose, I moved the entire block instead of just the concerned function calls. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index d39354afd539..376c808df11c 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -1246,17 +1246,6 @@ int ad7606_probe(struct device *dev, int irq, void _= _iomem *base_address, return -ERESTARTSYS; } =20 - st->write_scale =3D ad7606_write_scale_hw; - st->write_os =3D ad7606_write_os_hw; - - ret =3D ad7606_sw_mode_setup(indio_dev); - if (ret) - return ret; - - ret =3D ad7606_chan_scales_setup(indio_dev); - if (ret) - return ret; - /* If convst pin is not defined, setup PWM. */ if (!st->gpio_convst) { st->cnvst_pwm =3D devm_pwm_get(dev, NULL); @@ -1334,6 +1323,17 @@ int ad7606_probe(struct device *dev, int irq, void _= _iomem *base_address, return ret; } =20 + st->write_scale =3D ad7606_write_scale_hw; + st->write_os =3D ad7606_write_os_hw; + + ret =3D ad7606_sw_mode_setup(indio_dev); + if (ret) + return ret; + + ret =3D ad7606_chan_scales_setup(indio_dev); + if (ret) + return ret; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(ad7606_probe, "IIO_AD7606"); --=20 2.47.0 From nobody Tue Dec 16 22:01:50 2025 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 6415D2500AA for ; Mon, 10 Feb 2025 16:12: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=1739203975; cv=none; b=EmW0jG6eGz989KFRWvG7iV4yIZTmdhTq7qod081b2ltnt0uW7K9qxYzT5vT0bNPc8CAMy7le8j4AnNZ1WJDauLQwHa8pQfb46qehyutY6Y3GeNc2U31XORF76xq85lAFMQkd66zHrWrJcJbtIBhMh3rvc0c0+u4tah1TRjZOUxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203975; c=relaxed/simple; bh=85OlqVH97K7F9YU3PJts40Anjk8hAqk1vgt8dqfrDhg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tweSDEqIkWjb4qAPBAnW/tAqkc1OidPwesL12ZfZ0tj8N9ymAIFSJn6WmWXwisEC239pr5j1AOJubzsD9aIrUGk9Ig5ycN7C/erFFUdDOwqQnbvn8HUpfdBjeWoT871NBufb1kwQud8sl/6X+BaXbsF6XQwbQYaqQuM2iJ/Diww= 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=w1E4V1zf; 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="w1E4V1zf" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4361815b96cso30640635e9.1 for ; Mon, 10 Feb 2025 08:12:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203970; x=1739808770; 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=pHAR9w6iE1kUg7TAE0D6ak7vDA8Cy7dNc7XiaEG+akw=; b=w1E4V1zfJlJxhGABcYGFjouItPAzFYSBoDMnT9vo7iDLUq/K2hSfi9I7xkD6vkG8s4 8vwXFHEvlRJCUQ21ML3d7pcjMVlqxkZ2U3gX0aOhfCVYYlstFlD1t5UPqcoNN2aediYr P0jdApLzJpxmD8yjbazyQWpdcq/UJeWwkJ2m7lstvF4Gn6ZkEjyK5RxB6dkyFkNyGaEh VwIveq1mxCG+NqcLpZkwy9VfaO+4FPJGwzkLksMUkgHvptL3XxJgtLiU5clTSTrPShf9 x6OgqFdMIz5m4Omv08IAsH9ETVeyhA3g4NBR7B2CuS1TKJQf1oHukDathLf+747rw4H+ dy0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203970; x=1739808770; 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=pHAR9w6iE1kUg7TAE0D6ak7vDA8Cy7dNc7XiaEG+akw=; b=pNjfI0LWWARHKhcQfxChzv3sFcQagbHSNwLK75Da2Y1K+Ug+rjrbypu0/8MGEEq5HS GbTZCL5atYjWSo4c/OYJFH+JOWNjpnh0/rM8ulMIHZtPy6p9q0sV61f+O1TwISF4/1XU 4exw4uO68JDZHvDD/pTbMr5mgXmu+RKrc7gn/869TZ2oiws1W+OJFylLZIjVR2xEh4vN awQemuq38srnMqbIo+yTFQAP8WF1ypuowCm1YoyIal5wPdlpH6hOx2aixWdxBphGr1Ht a7sRokbkvcIiynTuq6NZN+m+F2aZBD+n2VQ8HGLu6S205E7vSragiMMLGwR3xeGgx49V q5iQ== X-Forwarded-Encrypted: i=1; AJvYcCVQkqJ6mTtER0RkL37LxlPj2nraAaXoF6UeuF548K234jQf4Q8Gw6TYb2Vjha8mQboFyVo+QD3IFlAIN7s=@vger.kernel.org X-Gm-Message-State: AOJu0YyNTWabB63WrAvrLSYiXSeNoZJIiZeV469qpLMvCPERRH8Lukx+ q2Nujtj3DQn+SNQHnKDMJFf9uroNKH92Had784PpFlAvCCV7tYbRJ8ZobKSEuOk= X-Gm-Gg: ASbGncshcjirIMxo7Ln+dsteY2SIcOfVWi0DqRXZZp757SyhdMrG+Ea+eFzgY+G8nGF dd4TxZyed76Kcs9eIyqrcbr68joGJ0cqm+/v2dGXUZaKvROYFrAW9PDCHLJljwSHDs4HQ2wYf9S 3WZ9dopiFNDCrI8cogTYx3Mb+AMoZNrdmoyNOFOmmoKrQnJlde1pRwzFp0cAK7TOO1L99bciFyF IKtbuPz6aZQh64waL42bZRjwAOwwGDTgEwJxoNmdDSgauqOtG6235jjhS2EZHl3zo2oCmFOQ7Gk W2ufpH2bxLDjUMAQ9VnpyqCVIC96gOsNxbn4J2h6V1deqxGfuTaESpKZ6DJTF3s= X-Google-Smtp-Source: AGHT+IEV/J/l3kWpoez/mnDzBaDqKAIqApnhQuGJarUSLFt2ZXMVprbdk/y4/kiDnr/31xIdIpbucA== X-Received: by 2002:a05:6000:1561:b0:38d:e38a:5910 with SMTP id ffacd0b85a97d-38de38a59bfmr975462f8f.28.1739203970449; Mon, 10 Feb 2025 08:12:50 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:50 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:53 +0100 Subject: [PATCH v4 3/9] iio: adc: ad7606: move software functions into common file Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-3-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Guillaume Stols Since the register are always the same, whatever bus is used, moving the software functions into the main file avoids the code to be duplicated in both SPI and parallel version of the driver. Signed-off-by: Guillaume Stols Co-developed-by: Angelo Dureghello Signed-off-by: Angelo Dureghello --- drivers/iio/adc/ad7606.c | 133 ++++++++++++++++++++++++++++++++++++++-= -- drivers/iio/adc/ad7606.h | 37 ++++++++++-- drivers/iio/adc/ad7606_spi.c | 137 +--------------------------------------= ---- 3 files changed, 158 insertions(+), 149 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 376c808df11c..7985570ed152 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -85,6 +85,10 @@ static const unsigned int ad7606_oversampling_avail[7] = =3D { 1, 2, 4, 8, 16, 32, 64, }; =20 +static const unsigned int ad7606b_oversampling_avail[9] =3D { + 1, 2, 4, 8, 16, 32, 64, 128, 256, +}; + static const unsigned int ad7616_oversampling_avail[8] =3D { 1, 2, 4, 8, 16, 32, 64, 128, }; @@ -187,6 +191,8 @@ static int ad7608_chan_scale_setup(struct iio_dev *indi= o_dev, struct iio_chan_spec *chan, int ch); static int ad7609_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); +static int ad7616_sw_mode_setup(struct iio_dev *indio_dev); +static int ad7606b_sw_mode_setup(struct iio_dev *indio_dev); =20 const struct ad7606_chip_info ad7605_4_info =3D { .channels =3D ad7605_channels, @@ -239,6 +245,7 @@ const struct ad7606_chip_info ad7606b_info =3D { .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, + .sw_setup_cb =3D ad7606b_sw_mode_setup, }; EXPORT_SYMBOL_NS_GPL(ad7606b_info, "IIO_AD7606"); =20 @@ -250,6 +257,7 @@ const struct ad7606_chip_info ad7606c_16_info =3D { .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), .scale_setup_cb =3D ad7606c_16bit_chan_scale_setup, + .sw_setup_cb =3D ad7606b_sw_mode_setup, }; EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, "IIO_AD7606"); =20 @@ -294,6 +302,7 @@ const struct ad7606_chip_info ad7606c_18_info =3D { .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), .scale_setup_cb =3D ad7606c_18bit_chan_scale_setup, + .sw_setup_cb =3D ad7606b_sw_mode_setup, }; EXPORT_SYMBOL_NS_GPL(ad7606c_18_info, "IIO_AD7606"); =20 @@ -307,6 +316,7 @@ const struct ad7606_chip_info ad7616_info =3D { .oversampling_num =3D ARRAY_SIZE(ad7616_oversampling_avail), .os_req_reset =3D true, .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, + .sw_setup_cb =3D ad7616_sw_mode_setup, }; EXPORT_SYMBOL_NS_GPL(ad7616_info, "IIO_AD7606"); =20 @@ -1138,16 +1148,118 @@ static const struct iio_trigger_ops ad7606_trigger= _ops =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 -static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) +static int ad7606_write_mask(struct ad7606_state *st, unsigned int addr, + unsigned long mask, unsigned int val) +{ + int readval; + + readval =3D st->bops->reg_read(st, addr); + if (readval < 0) + return readval; + + readval &=3D ~mask; + readval |=3D val; + + return st->bops->reg_write(st, addr, readval); +} + +static int ad7616_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) { struct ad7606_state *st =3D iio_priv(indio_dev); + unsigned int ch_addr, mode, ch_index; =20 - st->sw_mode_en =3D st->bops->sw_mode_config && - device_property_present(st->dev, "adi,sw-mode"); - if (!st->sw_mode_en) - return 0; + /* + * Ad7616 has 16 channels divided in group A and group B. + * The range of channels from A are stored in registers with address 4 + * while channels from B are stored in register with address 6. + * The last bit from channels determines if it is from group A or B + * because the order of channels in iio is 0A, 0B, 1A, 1B... + */ + ch_index =3D ch >> 1; + + ch_addr =3D AD7616_RANGE_CH_ADDR(ch_index); + + if ((ch & 0x1) =3D=3D 0) /* channel A */ + ch_addr +=3D AD7616_RANGE_CH_A_ADDR_OFF; + else /* channel B */ + ch_addr +=3D AD7616_RANGE_CH_B_ADDR_OFF; + + /* 0b01 for 2.5v, 0b10 for 5v and 0b11 for 10v */ + mode =3D AD7616_RANGE_CH_MODE(ch_index, ((val + 1) & 0b11)); =20 - indio_dev->info =3D &ad7606_info_sw_mode; + return ad7606_write_mask(st, ch_addr, AD7616_RANGE_CH_MSK(ch_index), + mode); +} + +static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + return ad7606_write_mask(st, AD7616_CONFIGURATION_REGISTER, + AD7616_OS_MASK, val << 2); +} + +static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + return ad7606_write_mask(st, AD7606_RANGE_CH_ADDR(ch), + AD7606_RANGE_CH_MSK(ch), + AD7606_RANGE_CH_MODE(ch, val)); +} + +static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + return st->bops->reg_write(st, AD7606_OS_MODE, val); +} + +static int ad7616_sw_mode_setup(struct iio_dev *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + int ret; + + /* + * Scale can be configured individually for each channel + * in software mode. + */ + + st->write_scale =3D ad7616_write_scale_sw; + st->write_os =3D &ad7616_write_os_sw; + + ret =3D st->bops->sw_mode_config(indio_dev); + if (ret) + return ret; + + /* Activate Burst mode and SEQEN MODE */ + return ad7606_write_mask(st, AD7616_CONFIGURATION_REGISTER, + AD7616_BURST_MODE | AD7616_SEQEN_MODE, + AD7616_BURST_MODE | AD7616_SEQEN_MODE); +} + +static int ad7606b_sw_mode_setup(struct iio_dev *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + DECLARE_BITMAP(os, 3); + + bitmap_fill(os, 3); + /* + * Software mode is enabled when all three oversampling + * pins are set to high. If oversampling gpios are defined + * in the device tree, then they need to be set to high, + * otherwise, they must be hardwired to VDD + */ + if (st->gpio_os) { + gpiod_set_array_value(st->gpio_os->ndescs, st->gpio_os->desc, + st->gpio_os->info, os); + } + /* OS of 128 and 256 are available only in software mode */ + st->oversampling_avail =3D ad7606b_oversampling_avail; + st->num_os_ratios =3D ARRAY_SIZE(ad7606b_oversampling_avail); + + st->write_scale =3D ad7606_write_scale_sw; + st->write_os =3D &ad7606_write_os_sw; =20 return st->bops->sw_mode_config(indio_dev); } @@ -1326,9 +1438,12 @@ int ad7606_probe(struct device *dev, int irq, void _= _iomem *base_address, st->write_scale =3D ad7606_write_scale_hw; st->write_os =3D ad7606_write_os_hw; =20 - ret =3D ad7606_sw_mode_setup(indio_dev); - if (ret) - return ret; + st->sw_mode_en =3D st->chip_info->sw_setup_cb && + device_property_present(st->dev, "adi,sw-mode"); + if (st->sw_mode_en) { + indio_dev->info =3D &ad7606_info_sw_mode; + st->chip_info->sw_setup_cb(indio_dev); + } =20 ret =3D ad7606_chan_scales_setup(indio_dev); if (ret) diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 8778ffe515b3..7a044b499cfe 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -10,6 +10,36 @@ =20 #define AD760X_MAX_CHANNELS 16 =20 +#define AD7616_CONFIGURATION_REGISTER 0x02 +#define AD7616_OS_MASK GENMASK(4, 2) +#define AD7616_BURST_MODE BIT(6) +#define AD7616_SEQEN_MODE BIT(5) +#define AD7616_RANGE_CH_A_ADDR_OFF 0x04 +#define AD7616_RANGE_CH_B_ADDR_OFF 0x06 +/* + * Range of channels from a group are stored in 2 registers. + * 0, 1, 2, 3 in a register followed by 4, 5, 6, 7 in second register. + * For channels from second group(8-15) the order is the same, only with + * an offset of 2 for register address. + */ +#define AD7616_RANGE_CH_ADDR(ch) ((ch) >> 2) +/* The range of the channel is stored in 2 bits */ +#define AD7616_RANGE_CH_MSK(ch) (0b11 << (((ch) & 0b11) * 2)) +#define AD7616_RANGE_CH_MODE(ch, mode) ((mode) << ((((ch) & 0b11)) * 2)) + +#define AD7606_CONFIGURATION_REGISTER 0x02 +#define AD7606_SINGLE_DOUT 0x00 + +/* + * Range for AD7606B channels are stored in registers starting with addres= s 0x3. + * Each register stores range for 2 channels(4 bits per channel). + */ +#define AD7606_RANGE_CH_MSK(ch) (GENMASK(3, 0) << (4 * ((ch) & 0x1))) +#define AD7606_RANGE_CH_MODE(ch, mode) \ + ((GENMASK(3, 0) & (mode)) << (4 * ((ch) & 0x1))) +#define AD7606_RANGE_CH_ADDR(ch) (0x03 + ((ch) >> 1)) +#define AD7606_OS_MODE 0x08 + #define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ @@ -71,6 +101,7 @@ struct ad7606_state; =20 typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); +typedef int (*ad7606_sw_setup_cb_t)(struct iio_dev *indio_dev); =20 /** * struct ad7606_chip_info - chip specific information @@ -80,6 +111,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *i= ndio_dev, * @num_channels: number of channels * @num_adc_channels the number of channels the ADC actually inputs. * @scale_setup_cb: callback to setup the scales for each channel + * @sw_setup_cb: callback to setup the software mode if available. * @oversampling_avail pointer to the array which stores the available * oversampling ratios. * @oversampling_num number of elements stored in oversampling_avail array @@ -94,6 +126,7 @@ struct ad7606_chip_info { unsigned int num_adc_channels; unsigned int num_channels; ad7606_scale_setup_cb_t scale_setup_cb; + ad7606_sw_setup_cb_t sw_setup_cb; const unsigned int *oversampling_avail; unsigned int oversampling_num; bool os_req_reset; @@ -206,10 +239,6 @@ struct ad7606_bus_ops { int (*reg_write)(struct ad7606_state *st, unsigned int addr, unsigned int val); - int (*write_mask)(struct ad7606_state *st, - unsigned int addr, - unsigned long mask, - unsigned int val); int (*update_scan_mode)(struct iio_dev *indio_dev, const unsigned long *s= can_mask); u16 (*rd_wr_cmd)(int addr, char isWriteOp); }; diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index e2c147525706..885bf0b68e77 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -15,36 +15,6 @@ =20 #define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */ =20 -#define AD7616_CONFIGURATION_REGISTER 0x02 -#define AD7616_OS_MASK GENMASK(4, 2) -#define AD7616_BURST_MODE BIT(6) -#define AD7616_SEQEN_MODE BIT(5) -#define AD7616_RANGE_CH_A_ADDR_OFF 0x04 -#define AD7616_RANGE_CH_B_ADDR_OFF 0x06 -/* - * Range of channels from a group are stored in 2 registers. - * 0, 1, 2, 3 in a register followed by 4, 5, 6, 7 in second register. - * For channels from second group(8-15) the order is the same, only with - * an offset of 2 for register address. - */ -#define AD7616_RANGE_CH_ADDR(ch) ((ch) >> 2) -/* The range of the channel is stored in 2 bits */ -#define AD7616_RANGE_CH_MSK(ch) (0b11 << (((ch) & 0b11) * 2)) -#define AD7616_RANGE_CH_MODE(ch, mode) ((mode) << ((((ch) & 0b11)) * 2)) - -#define AD7606_CONFIGURATION_REGISTER 0x02 -#define AD7606_SINGLE_DOUT 0x00 - -/* - * Range for AD7606B channels are stored in registers starting with addres= s 0x3. - * Each register stores range for 2 channels(4 bits per channel). - */ -#define AD7606_RANGE_CH_MSK(ch) (GENMASK(3, 0) << (4 * ((ch) & 0x1))) -#define AD7606_RANGE_CH_MODE(ch, mode) \ - ((GENMASK(3, 0) & mode) << (4 * ((ch) & 0x1))) -#define AD7606_RANGE_CH_ADDR(ch) (0x03 + ((ch) >> 1)) -#define AD7606_OS_MODE 0x08 - static const struct iio_chan_spec ad7616_sw_channels[] =3D { IIO_CHAN_SOFT_TIMESTAMP(16), AD7616_CHANNEL(0), @@ -89,10 +59,6 @@ static const struct iio_chan_spec ad7606c_18_sw_channels= [] =3D { AD7606_SW_CHANNEL(7, 18), }; =20 -static const unsigned int ad7606B_oversampling_avail[9] =3D { - 1, 2, 4, 8, 16, 32, 64, 128, 256 -}; - static u16 ad7616_spi_rd_wr_cmd(int addr, char isWriteOp) { /* @@ -194,118 +160,20 @@ static int ad7606_spi_reg_write(struct ad7606_state = *st, return spi_write(spi, &st->d16[0], sizeof(st->d16[0])); } =20 -static int ad7606_spi_write_mask(struct ad7606_state *st, - unsigned int addr, - unsigned long mask, - unsigned int val) -{ - int readval; - - readval =3D st->bops->reg_read(st, addr); - if (readval < 0) - return readval; - - readval &=3D ~mask; - readval |=3D val; - - return st->bops->reg_write(st, addr, readval); -} - -static int ad7616_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) -{ - struct ad7606_state *st =3D iio_priv(indio_dev); - unsigned int ch_addr, mode, ch_index; - - - /* - * Ad7616 has 16 channels divided in group A and group B. - * The range of channels from A are stored in registers with address 4 - * while channels from B are stored in register with address 6. - * The last bit from channels determines if it is from group A or B - * because the order of channels in iio is 0A, 0B, 1A, 1B... - */ - ch_index =3D ch >> 1; - - ch_addr =3D AD7616_RANGE_CH_ADDR(ch_index); - - if ((ch & 0x1) =3D=3D 0) /* channel A */ - ch_addr +=3D AD7616_RANGE_CH_A_ADDR_OFF; - else /* channel B */ - ch_addr +=3D AD7616_RANGE_CH_B_ADDR_OFF; - - /* 0b01 for 2.5v, 0b10 for 5v and 0b11 for 10v */ - mode =3D AD7616_RANGE_CH_MODE(ch_index, ((val + 1) & 0b11)); - return st->bops->write_mask(st, ch_addr, AD7616_RANGE_CH_MSK(ch_index), - mode); -} - -static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val) -{ - struct ad7606_state *st =3D iio_priv(indio_dev); - - return st->bops->write_mask(st, AD7616_CONFIGURATION_REGISTER, - AD7616_OS_MASK, val << 2); -} - -static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) -{ - struct ad7606_state *st =3D iio_priv(indio_dev); - - return ad7606_spi_write_mask(st, - AD7606_RANGE_CH_ADDR(ch), - AD7606_RANGE_CH_MSK(ch), - AD7606_RANGE_CH_MODE(ch, val)); -} - -static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val) -{ - struct ad7606_state *st =3D iio_priv(indio_dev); - - return ad7606_spi_reg_write(st, AD7606_OS_MODE, val); -} - static int ad7616_sw_mode_config(struct iio_dev *indio_dev) { - struct ad7606_state *st =3D iio_priv(indio_dev); - /* * Scale can be configured individually for each channel * in software mode. */ indio_dev->channels =3D ad7616_sw_channels; =20 - st->write_scale =3D ad7616_write_scale_sw; - st->write_os =3D &ad7616_write_os_sw; - - /* Activate Burst mode and SEQEN MODE */ - return st->bops->write_mask(st, - AD7616_CONFIGURATION_REGISTER, - AD7616_BURST_MODE | AD7616_SEQEN_MODE, - AD7616_BURST_MODE | AD7616_SEQEN_MODE); + return 0; } =20 static int ad7606B_sw_mode_config(struct iio_dev *indio_dev) { struct ad7606_state *st =3D iio_priv(indio_dev); - DECLARE_BITMAP(os, 3); - - bitmap_fill(os, 3); - /* - * Software mode is enabled when all three oversampling - * pins are set to high. If oversampling gpios are defined - * in the device tree, then they need to be set to high, - * otherwise, they must be hardwired to VDD - */ - if (st->gpio_os) { - gpiod_set_array_value(st->gpio_os->ndescs, - st->gpio_os->desc, st->gpio_os->info, os); - } - /* OS of 128 and 256 are available only in software mode */ - st->oversampling_avail =3D ad7606B_oversampling_avail; - st->num_os_ratios =3D ARRAY_SIZE(ad7606B_oversampling_avail); - - st->write_scale =3D ad7606_write_scale_sw; - st->write_os =3D &ad7606_write_os_sw; =20 /* Configure device spi to output on a single channel */ st->bops->reg_write(st, @@ -350,7 +218,6 @@ static const struct ad7606_bus_ops ad7616_spi_bops =3D { .read_block =3D ad7606_spi_read_block, .reg_read =3D ad7606_spi_reg_read, .reg_write =3D ad7606_spi_reg_write, - .write_mask =3D ad7606_spi_write_mask, .rd_wr_cmd =3D ad7616_spi_rd_wr_cmd, .sw_mode_config =3D ad7616_sw_mode_config, }; @@ -359,7 +226,6 @@ static const struct ad7606_bus_ops ad7606b_spi_bops =3D= { .read_block =3D ad7606_spi_read_block, .reg_read =3D ad7606_spi_reg_read, .reg_write =3D ad7606_spi_reg_write, - .write_mask =3D ad7606_spi_write_mask, .rd_wr_cmd =3D ad7606B_spi_rd_wr_cmd, .sw_mode_config =3D ad7606B_sw_mode_config, }; @@ -368,7 +234,6 @@ static const struct ad7606_bus_ops ad7606c_18_spi_bops = =3D { .read_block =3D ad7606_spi_read_block18to32, .reg_read =3D ad7606_spi_reg_read, .reg_write =3D ad7606_spi_reg_write, - .write_mask =3D ad7606_spi_write_mask, .rd_wr_cmd =3D ad7606B_spi_rd_wr_cmd, .sw_mode_config =3D ad7606c_18_sw_mode_config, }; --=20 2.47.0 From nobody Tue Dec 16 22:01:50 2025 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3832259489 for ; Mon, 10 Feb 2025 16:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203976; cv=none; b=sCSWHtf58KAMeSR3ygEvb7IeMy5fpUBbfQiFeu3/2FmCoq2WAV0hrSuvvb82C7QnyT1h6rbLyqfVFf5cVM1N4IPh7YbGD940zzE9TybTs180B+ji7qxr6fM81XLzcc6nJhIa+3ZDr+RrWtsdsEnh1AE+Op+As8by78n9jXdo+lQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203976; c=relaxed/simple; bh=B5IY8sIP4gGC//Ma1JKc6dnncjGjGxHJYxsumbltiUQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mwIbDeVFQZREiIk0xSnkCCQfhoRu7HSurrtzPC2Yf+5FQ3sMNXPIaB2RJPAoJCqCmKOcnsJnaASMmIZr+dbCu55Q/3fC6SjMJarKXy99p6dbBM+bHbj4ZZ52ecnrBlw70v7ScuxDGG/mzSKx/FgnLMmKjgIcxwvy+d9x5X1vclw= 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=j0JhJKw3; arc=none smtp.client-ip=209.85.128.51 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="j0JhJKw3" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-43948f77f1aso5290705e9.0 for ; Mon, 10 Feb 2025 08:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203972; x=1739808772; 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=4Hn2hao0NOkqkUCBDvG2L0twm52DR6qAULRA/ZirsiU=; b=j0JhJKw3rHKQAYaUPOhF6c8VCvo1BGkIlKzayN51CZwL3jjhu30VV/JTaiFI7z5Z/E 3deJWkLLfsDS20i3SKN9ARONKLXivNQZLFPKiJAzWRZ+jZG0AQpTUmGQM6II6L6fZvFV iJSRvYuHOLdGH1oLoEYVbNj63hY2XwONdtrk6eUYmESGQo+C+k5IjJqS4iZRJRnModAm rnSb5bNXIjNByGbCfdWly9TLmc+aPYoPVvdJHzcvsKB/S2bcy9o0/CVpsOSGQ2I0xJ5c edRiIkCG+Rtwh9bf9BhdTCamec/6tflorYkOYifmtGpnDwlNUk/x1cFuYAtFzbmGLh1E 9xjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203972; x=1739808772; 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=4Hn2hao0NOkqkUCBDvG2L0twm52DR6qAULRA/ZirsiU=; b=YQdehDMs0wpDonBL1KUPdGnQaZQ5RpUZZ3nepSYvR8fOF/mi6M0/gpHs3qDZbkVpFq +UVCLOvcyTKF1RzK6GsbBGeL6Imm5DUCwhrgK47nRy6YVo0VwUbAMMD18iyyuaJ38WIS opVDw/3pF0ecXGZyCHngQhcHJPCX273xVzpmcAsdUgBeyrgUTH6YRKR7jiMiW114D88N SoOytzu20OTF9AQRlvIfWwV4oQf5ixkhDNJWe1Nd9blbcP317FH0+6Rw9tRPwujCah37 N/isJzGirutkMaXaa/fdWj5717sWScZpAer8LCYgJjOfH1hxMPVZx8Gj8QWBMJQvoWYv IcgQ== X-Forwarded-Encrypted: i=1; AJvYcCUsxRF2T6so8gVlzAq75dfLdxOYd6/28/BaG3hqWQHlsIS2pn9jwYR5PxkLa3VfQJyWLE3Hc1VrvOHDMGU=@vger.kernel.org X-Gm-Message-State: AOJu0YzHCKEJ19Zs3ogPvZL0wmI0ngQLAeiu+RZ5BnWMDq/+I08FigeW GDUfMY1XKDtTGRymE4Dle+PXNJ+AC1f79KsR7Bc9/RnymkJ6yyE7CYfc1mphPIc= X-Gm-Gg: ASbGncsqkG1siA69Vl10nbd8K6b4OLYbxLVJ1/MkDdnF+hRibRLkxS9dsu0fNmlnm0y KjgXbix3m2UjLEM3yCATIvvVdzI8j5V7Et3yGsyp1Dx65ilLHCtXp5g4XjEgNfGo+c4NT5fNJdA opimZqmNt8W+tkkxQAAAQSwYUYJU0BPSojtb3OEKWU9oTlge/pl8k/6EtOP4yam7A3pmeMRv3sV JWbKwSAZTUBpsVEbtru4KNV1r17sK7cmandn4fQQlq4hi7zNFqopKfG6k/dKHyxTAnVdenJYMcG UeZosJYxC3QNoAjSKAaT7zsaZkZa1qHonfaX5t8tVgQWe5q8ByIEVat/Pb5E2yc= X-Google-Smtp-Source: AGHT+IG+Ta5SefNzrXZQv8f47DmZIQzG6z/VRvRAiXpN5x26tdYC8T+sHD2dKTEKhoPsudvtdFOnHA== X-Received: by 2002:a05:600c:3b1a:b0:439:44eb:2d84 with SMTP id 5b1f17b1804b1-43944eb3121mr33206385e9.9.1739203972062; Mon, 10 Feb 2025 08:12:52 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:51 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:54 +0100 Subject: [PATCH v4 4/9] iio: adc: adi-axi-adc: add struct axi_adc_info Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-4-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Add struct axi_adc_info to allow different axi-adc compatibles that can be added to this generic implementation. Signed-off-by: Angelo Dureghello --- drivers/iio/adc/adi-axi-adc.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index c7357601f0f8..b38e8a27af94 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -80,7 +80,16 @@ ADI_AXI_REG_CHAN_CTRL_FMT_EN | \ ADI_AXI_REG_CHAN_CTRL_ENABLE) =20 +struct axi_adc_info { + unsigned int version; + const struct iio_backend_info *backend_info; + bool has_child_nodes; + const void *pdata; + unsigned int pdata_sz; +}; + struct adi_axi_adc_state { + const struct axi_adc_info *info; struct regmap *regmap; struct device *dev; /* lock to protect multiple accesses to the device registers */ @@ -348,7 +357,6 @@ static const struct iio_backend_info adi_axi_adc_generi= c =3D { =20 static int adi_axi_adc_probe(struct platform_device *pdev) { - const unsigned int *expected_ver; struct adi_axi_adc_state *st; void __iomem *base; unsigned int ver; @@ -370,8 +378,8 @@ static int adi_axi_adc_probe(struct platform_device *pd= ev) return dev_err_probe(&pdev->dev, PTR_ERR(st->regmap), "failed to init register map\n"); =20 - expected_ver =3D device_get_match_data(&pdev->dev); - if (!expected_ver) + st->info =3D device_get_match_data(&pdev->dev); + if (!st->info) return -ENODEV; =20 clk =3D devm_clk_get_enabled(&pdev->dev, NULL); @@ -391,12 +399,13 @@ static int adi_axi_adc_probe(struct platform_device *= pdev) if (ret) return ret; =20 - if (ADI_AXI_PCORE_VER_MAJOR(ver) !=3D ADI_AXI_PCORE_VER_MAJOR(*expected_v= er)) { + if (ADI_AXI_PCORE_VER_MAJOR(ver) !=3D + ADI_AXI_PCORE_VER_MAJOR(st->info->version)) { dev_err(&pdev->dev, "Major version mismatch. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n", - ADI_AXI_PCORE_VER_MAJOR(*expected_ver), - ADI_AXI_PCORE_VER_MINOR(*expected_ver), - ADI_AXI_PCORE_VER_PATCH(*expected_ver), + ADI_AXI_PCORE_VER_MAJOR(st->info->version), + ADI_AXI_PCORE_VER_MINOR(st->info->version), + ADI_AXI_PCORE_VER_PATCH(st->info->version), ADI_AXI_PCORE_VER_MAJOR(ver), ADI_AXI_PCORE_VER_MINOR(ver), ADI_AXI_PCORE_VER_PATCH(ver)); @@ -416,11 +425,14 @@ static int adi_axi_adc_probe(struct platform_device *= pdev) return 0; } =20 -static unsigned int adi_axi_adc_10_0_a_info =3D ADI_AXI_PCORE_VER(10, 0, '= a'); +static const struct axi_adc_info adc_generic =3D { + .version =3D ADI_AXI_PCORE_VER(10, 0, 'a'), + .backend_info =3D &adi_axi_adc_generic, +}; =20 /* Match table for of_platform binding */ static const struct of_device_id adi_axi_adc_of_match[] =3D { - { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adi_axi_adc_10_0_a_inf= o }, + { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adc_generic }, { /* end of list */ } }; MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match); --=20 2.47.0 From nobody Tue Dec 16 22:01:50 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 879CC1F4618 for ; Mon, 10 Feb 2025 16:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203978; cv=none; b=a6uRnapsqVzsXc1nTZ1kDUCO0lCSOVlaQy6knctFw3jC+TorV0sPPRVZlVmFfmtVnhxJAoJbvU+3UDy0SCSaGjO5PIhGtet85VlMHA6TZGTIQIhfkmvQnKxo5WCjdS/4P8SGUNh8iHWp7j4ajA1kDopsP8lPzf3zHJRPO8Evzz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203978; c=relaxed/simple; bh=y7IjFtUIINl7cRYxyBtc6keo4179kmfVu625qHuoAp8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LpRcjBi6mYvQDrJ93X7+eFwERE8DN2Q/pUO60DIzhX9P0sF2I6rJWT5LYfJSwwoMnIGDUD/t43GZtf57Sfavk3BrIxUdnse7sqSMRRa74R3ppiAgqaajMq7+1PwN+Re7f3lgXkwTpBpU0wgQNjTg3cjNT7q9ClND7E6GKbUD/fk= 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=2rJneaiX; arc=none smtp.client-ip=209.85.128.42 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="2rJneaiX" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4394c192285so2352925e9.0 for ; Mon, 10 Feb 2025 08:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203974; x=1739808774; 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=SVE2q3k6JdjZ4UFWVjIakaD9BHRuhH1Hcjnsp1m4Lmk=; b=2rJneaiXYkNjglL16S9xgk7vlN4F8+gkSOPikaxLqhmHsIOUneKK5tL27aW6KnCefH B7wo6RL4vt7yLkr84BP7h7iWDgcj2H1yUkWNTKYrOt0X23rtrGTSBOU1J4G46/rWTzCG HVQFS4qc/4+O30n3itfx0yX5saqOWeP11DH6sunTVGe8C+kg2Hrnz0XPF++NH/Q23zHk bwxBcfKtcjqCeJlBVxo7rcofUwPFLAqn87ivd0umJ/emQrEbB0qfOYfdt558OIAGD0kV xFNo3RvoJ8si/FJ3rirOFhKTJjSg0JUcid/Fr7HpVzJrz2gUlfZjQ95UnpEps1C2Inpf OVXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203974; x=1739808774; 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=SVE2q3k6JdjZ4UFWVjIakaD9BHRuhH1Hcjnsp1m4Lmk=; b=R0SEMqIcbRUbOS/9v5dOYC5WEMvAiGFJBaXyO9GlZ/8FjbhnH118fTwxcEXFeaB8Br IusYjAfOO5M2xKfaN6SlPAsZcbrCTT7t1JabLu1RcFgVEtaxXYapgQLqlijANdUJyNJV IcPN3Jr2EjcPW8MJl+boBXA+SY6kneFSmxVLZBoMcZO7ocGMB/TtAu67nPHLNyhYcTVG mieynweY5OMgml/ExLc5BMg5sH8f+lxB2pyCEf/8T7N9VcGfn1SCEHxVBeuyZidBtkWQ p3cjJLGp2Q0wQJV7171sLsvusSKZVG/EPlst0gXyj/8Of2+cmHOe00cwifbtMVY1F1EI ae+A== X-Forwarded-Encrypted: i=1; AJvYcCUcG4MZ/s393flLN/leVytKbTZ5oRo7GBK7yonZh8ql315SjuCKjTMqdmx/hW+KWkQF6fH0/fULRdRdRsU=@vger.kernel.org X-Gm-Message-State: AOJu0YwikCDAip3utnBZixqKZUCBrhy7XTjS+1p2Y30JJT8nilSjezKb l3fBEWxoz8nTw+0o4h/5RK8sEwp3rDB+k2oGTfNE6xrQJ8UBed5opRhNFLWrm1A= X-Gm-Gg: ASbGncvXdqVywbjV1KtO+H6veev6jpPCAqbfhNdYOqNMr9BkKPWHQrKPJ4zgDhEN9ek XsD5NxppVPe8G+3RNkE6yXxm4oFy3q9CDQA/ZmmWwdcXhi8740OcDxlRCyDhZKohRGVnMZUY5RQ 0fFfXgOjFd+7HI8unTkcxMTPkWdZlKFjkIpaDxumoOPLR1fsrzRO7EYe9CLE+piThUAmz7IqHPe yrIFNflYcgrxTklI5ODL5R5BEHRuQCgDUGry/P1NkWyPcz+wWAzbIZr5cdt9qNceCrXUIeeRj79 VV1ZcmpTKgHaZOF7F/IHAGxVQHn43846C42sUeC8fxRZFHFFKnVjZ1wKO1w6s9c= X-Google-Smtp-Source: AGHT+IGzddC47+pjDSvR9mwpmYyJVcplPKxTatIFBpfXmDpOUncoCIJE66zoIcUqHQlugsyEqtyVjA== X-Received: by 2002:a05:600c:4650:b0:439:403a:6b77 with SMTP id 5b1f17b1804b1-439403a6d76mr56761835e9.10.1739203973800; Mon, 10 Feb 2025 08:12:53 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:53 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:55 +0100 Subject: [PATCH v4 5/9] iio: adc: adi-axi-adc: add platform children support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-5-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello This is a preparation for the next commit adding support for register read and write functions on AD7606. Since sometimes a bus will be used, it has been agreed during ad3552's driver implementation that the device's driver bus is the backend, whose device node will be a child node. To provide the special callbacks for setting the register, axi-adc needs to pass them to the child device's driver through platform data. Signed-off-by: Angelo Dureghello --- drivers/iio/adc/ad7606_bus_iface.h | 16 ++++++++++ drivers/iio/adc/adi-axi-adc.c | 65 ++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 81 insertions(+) diff --git a/drivers/iio/adc/ad7606_bus_iface.h b/drivers/iio/adc/ad7606_bu= s_iface.h new file mode 100644 index 000000000000..f2c979a9b7f3 --- /dev/null +++ b/drivers/iio/adc/ad7606_bus_iface.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2010-2024 Analog Devices Inc. + * Copyright (c) 2025 Baylibre, SAS + */ +#ifndef __LINUX_PLATFORM_DATA_AD7606_H__ +#define __LINUX_PLATFORM_DATA_AD7606_H__ + +struct iio_backend; + +struct ad7606_platform_data { + int (*bus_reg_read)(struct iio_backend *back, u32 reg, u32 *val); + int (*bus_reg_write)(struct iio_backend *back, u32 reg, u32 val); +}; + +#endif /* __LINUX_PLATFORM_DATA_AD7606_H__ */ diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index b38e8a27af94..3e1a997ace76 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -334,6 +334,36 @@ static const struct regmap_config axi_adc_regmap_confi= g =3D { .reg_stride =3D 4, }; =20 +static void axi_adc_child_remove(void *data) +{ + platform_device_unregister(data); +} + +static int axi_adc_create_platform_device(struct adi_axi_adc_state *st, + struct fwnode_handle *child) +{ + struct platform_device_info pi =3D { + .parent =3D st->dev, + .name =3D fwnode_get_name(child), + .id =3D PLATFORM_DEVID_AUTO, + .fwnode =3D child, + .data =3D st->info->pdata, + .size_data =3D st->info->pdata_sz, + }; + struct platform_device *pdev; + int ret; + + pdev =3D platform_device_register_full(&pi); + if (IS_ERR(pdev)) + return PTR_ERR(pdev); + + ret =3D devm_add_action_or_reset(st->dev, axi_adc_child_remove, pdev); + if (ret) + return ret; + + return 0; +} + static const struct iio_backend_ops adi_axi_adc_ops =3D { .enable =3D axi_adc_enable, .disable =3D axi_adc_disable, @@ -417,6 +447,28 @@ static int adi_axi_adc_probe(struct platform_device *p= dev) return dev_err_probe(&pdev->dev, ret, "failed to register iio backend\n"); =20 + device_for_each_child_node_scoped(&pdev->dev, child) { + int val; + + if (!st->info->has_child_nodes) + return dev_err_probe(&pdev->dev, -EINVAL, + "invalid fdt axi-dac compatible."); + + /* Processing only reg 0 node */ + ret =3D fwnode_property_read_u32(child, "reg", &val); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "invalid reg property."); + if (val !=3D 0) + return dev_err_probe(&pdev->dev, -EINVAL, + "invalid node address."); + + ret =3D axi_adc_create_platform_device(st, child); + if (ret) + return dev_err_probe(&pdev->dev, -EINVAL, + "cannot create device."); + } + dev_info(&pdev->dev, "AXI ADC IP core (%d.%.2d.%c) probed\n", ADI_AXI_PCORE_VER_MAJOR(ver), ADI_AXI_PCORE_VER_MINOR(ver), @@ -430,6 +482,19 @@ static const struct axi_adc_info adc_generic =3D { .backend_info =3D &adi_axi_adc_generic, }; =20 +static const struct ad7606_platform_data ad7606_pdata =3D { + .bus_reg_read =3D ad7606_bus_reg_read, + .bus_reg_write =3D ad7606_bus_reg_write, +}; + +static const struct axi_adc_info adc_ad7606 =3D { + .version =3D ADI_AXI_PCORE_VER(10, 0, 'a'), + .backend_info =3D &adi_axi_adc_generic, + .pdata =3D &ad7606_pdata, + .pdata_sz =3D sizeof(ad7606_pdata), + .has_child_nodes =3D true, +}; + /* Match table for of_platform binding */ static const struct of_device_id adi_axi_adc_of_match[] =3D { { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adc_generic }, --=20 2.47.0 From nobody Tue Dec 16 22:01:50 2025 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 56E6F1F4629 for ; Mon, 10 Feb 2025 16:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203979; cv=none; b=T1P4gC8ZU+2jCP0RvAMxjZiE+uIfptBt4nbwIAk60HTYkoz2FivFQ6vZbTmGdPMohIEo0x/Rm3gbJga2aUCnJCi0reoaxMfsNZAL4KiWmfmkEu8LmhJ1JstlEffez3LksUWT5nZFgYgPsVeKxM+uaxEmxPOtLsz51a4E7YapLEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203979; c=relaxed/simple; bh=kcGcQmYrsxutulGmVDS42pWg73BmAmjH7DDLdDu+NPQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cyv8o0+7Syg1ja5XSr9b/uHmXRAFggy0Vra0sy068/BvIiBUXicYv+QHqUgQpPh7UZ/GBnpMwwWpVwV0TQGQdSOGWZUoWqS0UAp1qvomhKC9XizmZSf4RSHXprnsTVD5TKByYZl+4s/sdd6n5RZfp8VgDA3i6YEk3BBTdV0PZHo= 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=EiuXY6i/; arc=none smtp.client-ip=209.85.128.44 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="EiuXY6i/" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43948021a45so8005475e9.1 for ; Mon, 10 Feb 2025 08:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203975; x=1739808775; 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=1C+if+YKEqJpi1bYoVHKAsnjMOtHNz/pBwh9W+PhPBw=; b=EiuXY6i/MRFwPgPw4skFo9Q7OhEaJRxvQogcqEGt1pdU9NPkt+t4v0bvwiQZb3vp46 H5AXLbvuknVzR+g88sWG0FW8i1i4VeQld15fqcomcDFh/whYdUt/nDdwPFbZFU0fL0gR J45/XDXCw4Hyt/1wSvggHlTPgUAqchuCAO2OQyCs8GRBtrAGIuFDL7D2W+Fso0P/EkVP KYBaZv8cInOmb7jptQ5NqdPvU0X2g23Czs0EVqbzIU9Lu39XDnc67RNxxjS/i9+cm5Em gNpUGFZPlIvWE6YeHy/HHvoeUQSgpD+Qv5pq1CwDIdpLb32SfavLihXiEmyqOzKV6Ewp LNcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203975; x=1739808775; 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=1C+if+YKEqJpi1bYoVHKAsnjMOtHNz/pBwh9W+PhPBw=; b=RrF0yJ6WQiyqOXmiRDQCelzRgP1m5O5WwbUcjE+O9rvlBCIFJtJFepCOzRJls76xJC wyb2m0gjrI84sto/Ake3ZwBMgViGbHu56Abzd5G7DqqHB7PtjqZ2kHr5mqHwrfel9aIy zb/WnO6LCp6I3J3xcrH3RMuMjkfEQysEMhtiF+mjxzgYN6P5TUdaLJGvMW+qcP1Jksdf RuqEeb5cHNdk3d9tbRPbk7oCtaRCZAq7HOONFrQ3G2Hde592pDuG8mwurBVxtRqNYrZK joMwkYEW9yNWXBj+8Yhd14qhsjQCh+p0xodZgWDKsLMStQ5w8WdAZ7fQe6ihyPu8c7EP 88ug== X-Forwarded-Encrypted: i=1; AJvYcCVUFTQX/s+x5lAxgfDX9gRjqm7tWJcfkCuveXM1Y64HJLI79HiwxHXq3dKiICtrVbbZsAnkgYJIKGTJYC0=@vger.kernel.org X-Gm-Message-State: AOJu0YwogsHtinBaPdg5YOO5Ww+6eOxstgIkXtuDBJJEn78MxokBT3M9 1+KclVblHj974x+t/ld8naImfwJvBGB4m+Y4oHskKMasNTAn1btDNnWJS/Sh66U= X-Gm-Gg: ASbGnct5/8nYbVLyIKQAXQr1Waj1b+LCAhRh2VF0i9/5eZwBwKiOhEigH8kDvuUMfuM NJc78diddtZzCigyUluBT0uB6SK2bPROrvPBAYSM0r8ZNK89I6uksxWFrz+CscD6Nn12negSeHd ucDR5ot29wnEJcLQ+CuGLF03TA6D4H5Y9Je6faztNSi27DpuUJm0D71ji6cSzWzLBiE5aAloGax YKgiOLT+lWk60mg5BZdcNLTwBye2v+p7WiG/rIE31cwF1b9+XpFZDsQ3GE2JdFauXcvkpaDx5Qb PqxlilRa9YC4YlZlyzHoIfNdtNSsQrzoPsKXh9AJVXe44JvebaE6+Io4Xa+sloo= X-Google-Smtp-Source: AGHT+IGuGl/koZTTMgPYM0KjMaUoO3aLh+70LVpTD0ygQeKoCwymAreIkWoD/pXb0RvkUatuAU1IoQ== X-Received: by 2002:a05:600c:1da8:b0:434:a75b:5f59 with SMTP id 5b1f17b1804b1-43924971286mr113884265e9.3.1739203975266; Mon, 10 Feb 2025 08:12:55 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:54 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:56 +0100 Subject: [PATCH v4 6/9] iio: adc: adi-axi-adc: add support for AD7606 register writing Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-6-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Guillaume Stols Since we must access the bus parallel bus using a custom procedure, let's add a specialized compatible, and define specialized callbacks for writing the registers using the parallel interface. Signed-off-by: Guillaume Stols Co-developed-by: Angelo Dureghello Signed-off-by: Angelo Dureghello --- drivers/iio/adc/adi-axi-adc.c | 81 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 81 insertions(+) diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index 3e1a997ace76..225ea0497ba9 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -27,6 +27,7 @@ #include #include =20 +#include "ad7606_bus_iface.h" /* * Register definitions: * https://wiki.analog.com/resources/fpga/docs/axi_adc_ip#register_map @@ -73,6 +74,12 @@ #define ADI_AXI_ADC_REG_DELAY(l) (0x0800 + (l) * 0x4) #define AXI_ADC_DELAY_CTRL_MASK GENMASK(4, 0) =20 +#define ADI_AXI_REG_CONFIG_WR 0x0080 +#define ADI_AXI_REG_CONFIG_RD 0x0084 +#define ADI_AXI_REG_CONFIG_CTRL 0x008c +#define ADI_AXI_REG_CONFIG_CTRL_READ 0x03 +#define ADI_AXI_REG_CONFIG_CTRL_WRITE 0x01 + #define ADI_AXI_ADC_MAX_IO_NUM_LANES 15 =20 #define ADI_AXI_REG_CHAN_CTRL_DEFAULTS \ @@ -80,6 +87,10 @@ ADI_AXI_REG_CHAN_CTRL_FMT_EN | \ ADI_AXI_REG_CHAN_CTRL_ENABLE) =20 +#define ADI_AXI_REG_READ_BIT 0x8000 +#define ADI_AXI_REG_ADDRESS_MASK 0xff00 +#define ADI_AXI_REG_VALUE_MASK 0x00ff + struct axi_adc_info { unsigned int version; const struct iio_backend_info *backend_info; @@ -311,6 +322,75 @@ static struct iio_buffer *axi_adc_request_buffer(struc= t iio_backend *back, return iio_dmaengine_buffer_setup(st->dev, indio_dev, dma_name); } =20 +static int axi_adc_raw_write(struct iio_backend *back, u32 val) +{ + struct adi_axi_adc_state *st =3D iio_backend_get_priv(back); + + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_WR, val); + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, + ADI_AXI_REG_CONFIG_CTRL_WRITE); + fsleep(100); + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, 0x00); + fsleep(100); + + return 0; +} + +static int axi_adc_raw_read(struct iio_backend *back, u32 *val) +{ + struct adi_axi_adc_state *st =3D iio_backend_get_priv(back); + + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, + ADI_AXI_REG_CONFIG_CTRL_READ); + fsleep(100); + regmap_read(st->regmap, ADI_AXI_REG_CONFIG_RD, val); + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, 0x00); + fsleep(100); + + return 0; +} + +static int ad7606_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val) +{ + struct adi_axi_adc_state *st =3D iio_backend_get_priv(back); + int addr; + + guard(mutex)(&st->lock); + + /* + * The address is written on the highest weight byte, and the MSB set + * at 1 indicates a read operation. + */ + addr =3D FIELD_PREP(ADI_AXI_REG_ADDRESS_MASK, reg) | ADI_AXI_REG_READ_BIT; + axi_adc_raw_write(back, addr); + axi_adc_raw_read(back, val); + + /* Write 0x0 on the bus to get back to ADC mode */ + axi_adc_raw_write(back, 0); + + return 0; +} + +static int ad7606_bus_reg_write(struct iio_backend *back, u32 reg, u32 val) +{ + struct adi_axi_adc_state *st =3D iio_backend_get_priv(back); + u32 buf; + + guard(mutex)(&st->lock); + + /* Write any register to switch to register mode */ + axi_adc_raw_write(back, 0xaf00); + + buf =3D FIELD_PREP(ADI_AXI_REG_ADDRESS_MASK, reg) | + FIELD_PREP(ADI_AXI_REG_VALUE_MASK, val); + axi_adc_raw_write(back, buf); + + /* Write 0x0 on the bus to get back to ADC mode */ + axi_adc_raw_write(back, 0); + + return 0; +} + static void axi_adc_free_buffer(struct iio_backend *back, struct iio_buffer *buffer) { @@ -498,6 +578,7 @@ static const struct axi_adc_info adc_ad7606 =3D { /* Match table for of_platform binding */ static const struct of_device_id adi_axi_adc_of_match[] =3D { { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adc_generic }, + { .compatible =3D "adi,axi-ad7606x", .data =3D &adc_ad7606 }, { /* end of list */ } }; MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match); --=20 2.47.0 From nobody Tue Dec 16 22:01:50 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 6B99B1F4613 for ; Mon, 10 Feb 2025 16:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203981; cv=none; b=SD7l7l+i7gs8eUAg+pjHNGANhXQTkkCp3ph8SLO10OcbtdHyaVGdRC9VluNiwHIVtG2vZoZPT2J+jhqQ/w3KDkG2/3N0fsng0VMBULICRBvJ3n6pnpn3OP4PT76Ek40KOF4UrNmEqtaapcssTMq2s0YvurgVi1i45kP5/TBxILU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203981; c=relaxed/simple; bh=EYN2jmjQpt0Relr6D6FUdK13M4l5zeXDuBWC3e77YUw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Lq+tArS2qgZUJfMdDuTuOq/13f0Imk+aGKhDxAiRrgflL346E9CG4cdEsQte+DjBsrM0OVc/Pg6PnzDQumB/xc7k1KJ7wRMlnTom9+0atMoAkkDGe2W97l8fh8QqHmHDyHahh462YRczOseiVtHiNmWbiuGhNsX/s5zIM5mahmg= 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=FPHLrmhX; arc=none smtp.client-ip=209.85.221.48 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="FPHLrmhX" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-38dd9b3419cso893117f8f.0 for ; Mon, 10 Feb 2025 08:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203977; x=1739808777; 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=iIjPfuFGXuMmM5B5bh3vlcOXqvUxOsdFQdpkLRhWYHE=; b=FPHLrmhX4ts/LCgk7/x3bYH2HAsnyNptf+3hs4tl/l0O/vXV98N6bdaJEht7+q2MHd 3wv3vg7xXFzhXXQHV7y/pMariaIkHuHrQAlYbBXr9/uFmnIJlTyBw7hOLguJNEp555MS cq8woka8YhtXvjRiC+n2PPo3OhHyKy3EuFB2UnSZTkrZfmaIUKnQS8cX3Xe3P5JGVFju 3l6xIk6/c34RuOSrdbu1N51TKCxYrhSLz+elkzbExhfvWjax/zRQPt+Vs7pFXaixf0wD JG5KmNcKQyhAVDSbRGnkzNrA3+2b69hwxcDFdAusbkM67pmSjar7GnH8oqb/0oc/mvN0 NDCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203977; x=1739808777; 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=iIjPfuFGXuMmM5B5bh3vlcOXqvUxOsdFQdpkLRhWYHE=; b=k7EkJXzugHWgjKV9JDA0IZno0phMW0GR92eq8ZjTtzO37pdQQv5I53243PBjRzvwUI sSBChRPN6VvBGkkWI6MCJuGp5xzg0X33zIqT8S2KtDPaS+8toC0XWOpnj8NipBiZFdoj zfQjmPs3L29R7SXp1f6J66vGdkRVtJP6d/qpsCRamTx73Gjnr4KlRTvFPbZPMFXDSRvo UnyVTRoKdUjAbzSVt0F+8fT1yIFxkduy/oGJU5+5R6TZDqPQ4uZ/Jeu6SyID0kLDr4pT SOHofu9Ydose+bTJofXQquCupSvVZuzLQaeqh6ML03QidCUzkrL1SKhHJUSoX+fLPAm5 Nmfg== X-Forwarded-Encrypted: i=1; AJvYcCVQBRDxHmnC3963v2DRNSOY6pWvOhzKMloH9Cvsamv3dqDbK9jjc2iC8BMwftB1AKGLTzc31tbnIWkzWAo=@vger.kernel.org X-Gm-Message-State: AOJu0YzKKmbB1ykS6UujjstgYWBT5oBFUgrGateQRvG4iNuClcVrOQDm LpG78ATy0XGmDJUg6cDSp16JgYJrMy8qYGhlgPPkIkvVQ4gclvpWdARwozf1eOQ= X-Gm-Gg: ASbGnctj9QqoMwEHx6HzKjmsi5J6ZCvGEzKokBiZYVvhd7KupGDhxmQTzvZgYFhvK09 f+YxbGg00wAH76nodyLiiozQqYXERApkxWOKgLH/skcIaEZ1yZo1JgaqBHc6yAKkVd+6LSeW29q rge5l6Ug3cmTJ92oqr+vETVQ3js9Xq1ImiX+gBfV9xi2n9wSnUyUhFbhjftJF1f/15vNpxW2Rny b6e3iYzBP8JLBPBfo1m6LgAOwy/UL7gAWWksF0ssz8ogjYY28SKdp6mD2zUGrzdhT8kVk+EwJ3J rBh5Q/561dJ66nQmI55GBTGt6lq99ZaW0WdSmMsW9mDABOK1jDpQPvbZ298JDGg= X-Google-Smtp-Source: AGHT+IF8U4g+gzBJ/cIqcckdV7LgaRgLDwbSHf1t/ZRLRiATW6wIMx/g/+6UZw2NAefFPk2iWnxLJw== X-Received: by 2002:a05:6000:1787:b0:38d:ae82:e5ed with SMTP id ffacd0b85a97d-38de41c3d17mr166768f8f.51.1739203976810; Mon, 10 Feb 2025 08:12:56 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:56 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:57 +0100 Subject: [PATCH v4 7/9] iio: adc: ad7606: protect register access Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-7-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Protect register (and bus) access from concurrent read / write. Needed in the backend operating mode. Signed-off-by: Angelo Dureghello --- drivers/iio/adc/ad7606.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 7985570ed152..07656fdd602e 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -862,7 +862,12 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, } val =3D (val * MICRO) + val2; i =3D find_closest(val, scale_avail_uv, cs->num_scales); + + ret =3D iio_device_claim_direct_mode(indio_dev); + if (ret < 0) + return ret; ret =3D st->write_scale(indio_dev, ch, i + cs->reg_offset); + iio_device_release_direct_mode(indio_dev); if (ret < 0) return ret; cs->range =3D i; @@ -873,7 +878,12 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, return -EINVAL; i =3D find_closest(val, st->oversampling_avail, st->num_os_ratios); + + ret =3D iio_device_claim_direct_mode(indio_dev); + if (ret < 0) + return ret; ret =3D st->write_os(indio_dev, i); + iio_device_release_direct_mode(indio_dev); if (ret < 0) return ret; st->oversampling =3D st->oversampling_avail[i]; --=20 2.47.0 From nobody Tue Dec 16 22:01:50 2025 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36CCA2566E1 for ; Mon, 10 Feb 2025 16:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203982; cv=none; b=QKaDEP2jtIApP/Xx8pZvNxhIG9x1WR+ZoqUIx7zRkWEFx1vx4/0siZGomtvjLIlfqxDYa+E3kAVQTI2sRU17F4aJ8jaJVqmtkTT2aqyD8oq8VShiAEc5T5Fr7H4tYEXI1oGiqO43MzGLYhsNUMNuLwxvJQaPWH5oZUo4fSPC5Hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203982; c=relaxed/simple; bh=3NUUx15Y02eAxw+Z9yWc/3djPoH5Ry3lT7zOZkK3n3A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=knD8gX+3M8ta+H8yMH2jiHqhOkKBv4aU6RryQoZ+jDKUolauV8X14zE2s1xh/m/qxbImiWarDYTVG8vodXSHhOZFvWIRwegVarlMtuCcyM/kGx5Be2Yc6xbNHW5vM8YGnaZVlPDEVlJbT8ztJnXgfG+xG21NHNxICxUCQ1pe0tw= 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=SGO92Vj7; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="SGO92Vj7" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-436345cc17bso31581845e9.0 for ; Mon, 10 Feb 2025 08:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203978; x=1739808778; 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=vN8F20QDO3HQKLIA661OKCUheq7UYLkLcdweF7Jz39U=; b=SGO92Vj75AVvK5gTOo+5OX4/xiKGRksBD2WkNDiY8nnGVEKsP0XW5Nn7BVVSRgXG2G /aeCgRVQy0JyyZOP1VC4IuOF1letySh2sZ2FFJx2nTbLJPO0uQgqcElS7nPZtRy+4wyI KagCTQCuTHzsRXAAeg/j5C7TEKjW3s7H9DDndnFfDmonuhAWcLIEaX9SYU04qz4w9YlT jsIVDMLxpmaj3EkdYwDYdUZKn63UNnHERNZkhpO+LuEzum6n95GIH3WI/1Ikuq8H5iJE PaLg3MJ5jzCUpc9ChfL/nOJ+mWvgxJTHtzYmD+ZoqA/PJvQYxuIVA9fjayX3ulgszl8N KUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203978; x=1739808778; 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=vN8F20QDO3HQKLIA661OKCUheq7UYLkLcdweF7Jz39U=; b=uUYwqpK9Xow7wPLAzA9Ee1wAGFbVE+Z718zD3M8MIFf5ljmqZsZUSWYDhzijfaaJTd r7iXWv+FfVvWsf2SAAkeTkYYE2CYsofYDdlJ9XFr2Q/GkLM/YcKlb0iFdUM7pwM0rcfU hjXQIpx/H5Q4G+0tgNXfjndfirPC/N/g9zsj78D9V3/743rXCCP+xPaTAbTRzGikjp2o bRmFsqEoeUG5ikM6EaXN1418vFEndxjd6vTIxJcV/81uLc98MPSd2R8I29xPiKN0M3Pn pjvi9e5e9/rtF3Lx2bEhmv97HGiloWPjr6Qh3oxPCIh0P5eq5VzBQv9dbucwFl/LNj0S G+lg== X-Forwarded-Encrypted: i=1; AJvYcCV835lrPi2BBXA02E3ZIEcRkehaHxLG1mTd/Iz/WOhG34bEeWlGdQiYlZYFqr59ddxQmvQ6BeMDJlYZkZg=@vger.kernel.org X-Gm-Message-State: AOJu0YyAomD1omi6Fb9KpYP5cVMc7REo68Y05QtKN8SSgXAxxbphf1wg h2aRtkQ7H7qLF7X6E+RXbrXmYYRfBmQjaf3cSHdjVkxJszWv1w2XaHQvjHqRRy0= X-Gm-Gg: ASbGncstFz8UbXQ/r17fA2bny2uueYdUqWLxsXJaA+0lA5cM5tDnt0GPXEU4fNFkuYd 6sI9zB+QwKr0PxIYd57LSZ/zxMo4MJKUTP4LL+9jmoo439+GreqhTQY8agMH0hoCGQq0lcpwiyp GsWz9O5I4jIj0uhLr8HpNgoRW8XzgPCQwMITZ4M1IHYpMLFafLGfG+UO/6SYtLUf2taoixoyA8n EGc6qV3xQ5ehDhfePjPcCF94ARYsArW3V4vGP7Mgp9uLcCXx6EqtipOHJuvaAADh/3TOTemmHae KJbHxAEn+RocABN/T1q7DSHV+WFMajmdKUyDGjbkwwcWrW75F2gXfL5d4nwqBDk= X-Google-Smtp-Source: AGHT+IG6o5ZREGcR3FZz87qZP85Jb0UcLM1o8sU4230MxIIzFZQjtotZMxY+b32r+NX9bZ4tcPkzxw== X-Received: by 2002:a05:600c:510c:b0:434:a4b3:5ebe with SMTP id 5b1f17b1804b1-4394c847ad4mr3624905e9.24.1739203978447; Mon, 10 Feb 2025 08:12:58 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:57 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:58 +0100 Subject: [PATCH v4 8/9] iio: adc: ad7606: change channel macros parameters Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-8-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Guillaume Stols Add the possibility to pass the *_available parameters to the main macro. This is a preparation to add the new channels for software mode and hardware mode in iio backend mode more easily. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.h | 51 ++++++++++++++++++++++++--------------------= ---- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 7a044b499cfe..a35b526f3915 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -40,37 +40,19 @@ #define AD7606_RANGE_CH_ADDR(ch) (0x03 + ((ch) >> 1)) #define AD7606_OS_MODE 0x08 =20 -#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ +#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, \ + mask_sep_avail, mask_all_avail, bits) { \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ .channel =3D num, \ .address =3D num, \ .info_mask_separate =3D mask_sep, \ + .info_mask_separate_available =3D \ + mask_sep_avail, \ .info_mask_shared_by_type =3D mask_type, \ .info_mask_shared_by_all =3D mask_all, \ - .scan_index =3D num, \ - .scan_type =3D { \ - .sign =3D 's', \ - .realbits =3D (bits), \ - .storagebits =3D (bits) > 16 ? 32 : 16, \ - .endianness =3D IIO_CPU, \ - }, \ -} - -#define AD7606_SW_CHANNEL(num, bits) { \ - .type =3D IIO_VOLTAGE, \ - .indexed =3D 1, \ - .channel =3D num, \ - .address =3D num, \ - .info_mask_separate =3D \ - BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_separate_available =3D \ - BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_shared_by_all =3D \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ .info_mask_shared_by_all_available =3D \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + mask_all_avail, \ .scan_index =3D num, \ .scan_type =3D { \ .sign =3D 's', \ @@ -80,14 +62,30 @@ }, \ } =20 +#define AD7606_SW_CHANNEL(num, bits) \ + AD760X_CHANNEL(num, \ + /* mask separate */ \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + /* mask type */ \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + /* mask all */ \ + 0, \ + /* mask separate available */ \ + BIT(IIO_CHAN_INFO_SCALE), \ + /* mask all available */ \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + bits) + #define AD7605_CHANNEL(num) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ - BIT(IIO_CHAN_INFO_SCALE), 0, 16) + BIT(IIO_CHAN_INFO_SCALE), 0, 0, 0, 16) =20 #define AD7606_CHANNEL(num, bits) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ BIT(IIO_CHAN_INFO_SCALE), \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + 0, 0, bits) =20 #define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) =20 @@ -95,7 +93,8 @@ AD760X_CHANNEL(num, 0, \ BIT(IIO_CHAN_INFO_SCALE), \ BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 16) + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + 0, 0, 16) =20 struct ad7606_state; =20 --=20 2.47.0 From nobody Tue Dec 16 22:01:50 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE893257424 for ; Mon, 10 Feb 2025 16:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203984; cv=none; b=qPLbJXXd3d8GOSCVsbMhgbbOl0FC768hzMEUiPZCFBp9x/SYaa4i97gfxEoS0jVknNlhRbrlkBRm0NVJ1fZIJfeB6x6glGHfvXZdT8HNKq2tdDZoCyNOCpDDatOsgsq4aSKkCu/6GuWlR34MusM04M+2MsIksGG6GgSCGRr5qyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203984; c=relaxed/simple; bh=oXABJ0HRSJUsqBxjQdzjmuSA2Zskw28HlIrTxxdX42Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ppFjjEUZtbVeEVxgBvuUHWiLnErNM6eV4s6RSovVjEezOMfDqSp+c+7gpfX6oQ5f2aEZz4vTGF2D+mLXj1z+wzFaUOdhe/wzhUklUWUzkfDsBUqqUozuRbTRvU5GHj7g3MLQT2g5P/W5gPI8TZceUPcC4mfz7VWIYGAp7vAAQI4= 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=tik90vAc; arc=none smtp.client-ip=209.85.128.46 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="tik90vAc" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-43948021a45so8006565e9.1 for ; Mon, 10 Feb 2025 08:13:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1739203980; x=1739808780; 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=eyom0qjvxfr0PUA0BRn3wccZvWvBCP/teSac2W2vzoA=; b=tik90vAcy+RxqL5CV/R71IdcYZdoghkq6KHkA0ol1xpFDU+yc5Xms/E1J30sGUPQX6 S5UPbiNNjY/idtUNiokvcy7qCBSeNCUDVbaQby2S1cbgsNQhSMPUL3Q60Lkd9U8X2KNm N9HAsPgClRGZ4c3O9ekS4A0u1Bco651eTuEpK+58cj0k6fHUuXsYzAkWSWTD1pEbrBq6 iocfkHFktzlvkebERSz1Kd62GVM9XmPlzkEnFx4YDfzakwFta9BIPDqYOARQ4ogBqeYq j+0Ae/N8zJK2QbNxWudiITcvLEdbFdv6zNFdmTUIW/yK3Hgfi4RfD83O7noQ+iVR2W08 8ZPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739203980; x=1739808780; 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=eyom0qjvxfr0PUA0BRn3wccZvWvBCP/teSac2W2vzoA=; b=hVH4FoYtGniIM8gpG0ORRa5kpjjLRZotBcG9QjzIRN8rkxkTC/9yIyppyRbRsZvGct 2myNjUmeHj07SLB83focA31ftHA38DDsE5kRLTxB+Ik6EeqO6fE2P3M+saX3IcIFp2u/ lyNWWmZYWYxTli1cpnEudvTz1eGuIUBLBXyo3ZiZ59kSKlHkKlF5fKtmZDsGPgXviIVD KFxBP/ukrWdQeWiwL5zDIu1wZ5aEqw7hh0AMXBSV23+uVtdJ3WvxbGPwJOWRUQwVmL+Q cZEu3URQizkhA/7dRPLpEpovdvJxQUt3KwTOvw4mORMuHUp+yFZmBiygkJ+M7Hu+dbCV uDxw== X-Forwarded-Encrypted: i=1; AJvYcCUM/NrZIWO7lpRO2aJUazFvP8h7JdsHKJFwjg40C3K/KegFuPREfZ61nARCW5/si5lZ3lP6ENcK5+PtDAs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxe8+O/YC2oCyGpgPbwKkIeBlm5lcUqbEq3yAIrVgmZhEdm1fgd o8wi8w2Tb3dckbP82WFlK9ePqgnDG1/eWioJoiJRu56OH6RaGwPm5ZIyNynEJSg= X-Gm-Gg: ASbGncsrooliSq+KXPywzQ9PW328D4TOTNLE8pd3lsm/NqYYukcF32uFxTVMmSsWCTU sBqU2pNOCFqnZhh2dSb6UIN2tlL7U769D1zjfp3YTkLNd4SLlKq0IsaBoAcgN2bxooi0R+JUVcW pXtYmKXgRtl7LQoiuOE/hgofyYaMKVHy0DdLWTPfA19uWXDp82x7bAzTOf2H6lYNd3OXCuA/0NM 6IjUBW615rX+F0KkvcYmT3syvBqP4NJPtK8FIBq/g3noLchUnN/2LALJEIuQPE9XKUduDeezlyJ 71KzDGr1ZM0FolDVF/1SdK5FSzNEWD8iGBMw5muO+Lijcj2yJOnlHHRKEzdDeUk= X-Google-Smtp-Source: AGHT+IFHtByCSdx1O2bm7wTfO3oeSSWSD9kC3YKcmPVh+qEYF/LbA5lZmoVVo4nuzwDXSawJXU4XQw== X-Received: by 2002:a05:600c:3c84:b0:435:32e:8270 with SMTP id 5b1f17b1804b1-43924991e0cmr117634675e9.14.1739203979907; Mon, 10 Feb 2025 08:12:59 -0800 (PST) Received: from [127.0.1.1] (host-87-8-15-130.retail.telecomitalia.it. [87.8.15.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dc9ffcdsm146637945e9.15.2025.02.10.08.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:12:59 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Mon, 10 Feb 2025 17:10:59 +0100 Subject: [PATCH v4 9/9] iio: adc: ad7606: add support for writing registers when using backend Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-9-160df18b1da7@baylibre.com> References: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> In-Reply-To: <20250210-wip-bl-ad7606_add_backend_sw_mode-v4-0-160df18b1da7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Guillaume Stols Add the logic for effectively enabling the software mode for the iio-backend, i.e. enabling the software mode channel configuration and implementing the register writing functions. Signed-off-by: Guillaume Stols Co-developed-by: Angelo Dureghello Signed-off-by: Angelo Dureghello --- drivers/iio/adc/ad7606.h | 15 +++++++++++++ drivers/iio/adc/ad7606_par.c | 52 ++++++++++++++++++++++++++++++++++++++++= ---- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index a35b526f3915..71a30525eaab 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -96,6 +96,21 @@ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 0, 0, 16) =20 +#define AD7606_BI_SW_CHANNEL(num) \ + AD760X_CHANNEL(num, \ + /* mask separate */ \ + BIT(IIO_CHAN_INFO_SCALE), \ + /* mask type */ \ + 0, \ + /* mask all */ \ + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + /* mask separate available */ \ + BIT(IIO_CHAN_INFO_SCALE), \ + /* mask all available */ \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + 16) + struct ad7606_state; =20 typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev, diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c index 64733b607aa8..335fb481bfde 100644 --- a/drivers/iio/adc/ad7606_par.c +++ b/drivers/iio/adc/ad7606_par.c @@ -19,6 +19,7 @@ #include =20 #include "ad7606.h" +#include "ad7606_bus_iface.h" =20 static const struct iio_chan_spec ad7606b_bi_channels[] =3D { AD7606_BI_CHANNEL(0), @@ -31,7 +32,19 @@ static const struct iio_chan_spec ad7606b_bi_channels[] = =3D { AD7606_BI_CHANNEL(7), }; =20 -static int ad7606_bi_update_scan_mode(struct iio_dev *indio_dev, const uns= igned long *scan_mask) +static const struct iio_chan_spec ad7606b_bi_sw_channels[] =3D { + AD7606_BI_SW_CHANNEL(0), + AD7606_BI_SW_CHANNEL(1), + AD7606_BI_SW_CHANNEL(2), + AD7606_BI_SW_CHANNEL(3), + AD7606_BI_SW_CHANNEL(4), + AD7606_BI_SW_CHANNEL(5), + AD7606_BI_SW_CHANNEL(6), + AD7606_BI_SW_CHANNEL(7), +}; + +static int ad7606_par_bus_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *scan_mask) { struct ad7606_state *st =3D iio_priv(indio_dev); unsigned int c, ret; @@ -48,7 +61,8 @@ static int ad7606_bi_update_scan_mode(struct iio_dev *ind= io_dev, const unsigned return 0; } =20 -static int ad7606_bi_setup_iio_backend(struct device *dev, struct iio_dev = *indio_dev) +static int ad7606_par_bus_setup_iio_backend(struct device *dev, + struct iio_dev *indio_dev) { struct ad7606_state *st =3D iio_priv(indio_dev); unsigned int ret, c; @@ -86,9 +100,39 @@ static int ad7606_bi_setup_iio_backend(struct device *d= ev, struct iio_dev *indio return 0; } =20 +static int ad7606_par_bus_reg_read(struct ad7606_state *st, unsigned int a= ddr) +{ + struct ad7606_platform_data *pdata =3D st->dev->platform_data; + int val, ret; + + ret =3D pdata->bus_reg_read(st->back, addr, &val); + if (ret) + return ret; + + return val; +} + +static int ad7606_par_bus_reg_write(struct ad7606_state *st, unsigned int = addr, + unsigned int val) +{ + struct ad7606_platform_data *pdata =3D st->dev->platform_data; + + return pdata->bus_reg_write(st->back, addr, val); +} + +static int ad7606_par_bus_sw_mode_config(struct iio_dev *indio_dev) +{ + indio_dev->channels =3D ad7606b_bi_sw_channels; + + return 0; +} + static const struct ad7606_bus_ops ad7606_bi_bops =3D { - .iio_backend_config =3D ad7606_bi_setup_iio_backend, - .update_scan_mode =3D ad7606_bi_update_scan_mode, + .iio_backend_config =3D ad7606_par_bus_setup_iio_backend, + .update_scan_mode =3D ad7606_par_bus_update_scan_mode, + .reg_read =3D ad7606_par_bus_reg_read, + .reg_write =3D ad7606_par_bus_reg_write, + .sw_mode_config =3D ad7606_par_bus_sw_mode_config, }; =20 static int ad7606_par16_read_block(struct device *dev, --=20 2.47.0