Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 BE9682701CF for ; Fri, 5 Sep 2025 09:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757065488; cv=none; b=pWEfAYk2Pv97IJ/UQ1jUsKEgHxPaK4p/20PvigRB1SL4CT/KFGlTnW7BcxOznpcQz8tohSyhSGm32gKcPev86PKokvpPF6alo6qhQt5l1grF7JKGumXrB8cQN9sN25wrvE7vuMg9A/T/Dwy95mrTDHzkrTbPQ0yJ95ILr8JhXFk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757065488; c=relaxed/simple; bh=6rMxYhDmqs/v7kj6WGuLgYVPHayU1LenJFACJct8AbQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Bkj509QPPYPb4PgjhILTnAOB7buRQ3YtZYN0vzdohbZQ6PHK2usW8At3ODOHufbESYiuIdBbm5PL9pvYIkYB0F3FqJeybV94xTfX/mv28f2IHwV/PgOINEfEkq3KV45Mp3MJMKbuEVyVNpUv2zDU5ENBtxfX0mfup7gLS8n1Q/Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=xiTfp4+Y; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xiTfp4+Y" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3d1bf79d758so1729931f8f.1 for ; Fri, 05 Sep 2025 02:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1757065485; x=1757670285; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=vg+TuI+bOQ+/K0B+1sySJ2VK4abRlS/VZd6mZadbe2g=; b=xiTfp4+YeasCu5odA010ly5KiKT9EEKcqYRTXMkgiaKb/FCblnUNXhZ0JhJ68h2n6a auuNVTjrRc/Ml9aIGBk+/Vkdwe3czPSBbuLJvBsAKrqqcK2sT8Vduyb5CIiWMfWCXR3H 60SkkMbFQguQbuwydon7K7ZSTRQeigsdfwXkLPxGyQWrZe2tBdzE+IoBGTJLoTyT7czm J11wjX7fs4eu4QYyFNnyEPAShVwEwMpddAdN6eY0SJ+TORjvA8BKzXuQEO2taS8IATjN g7DdrKYdOrhCzcNh6H8JCxAIaKpl/VtjGeZviTetgBWQOyzLTerjXQTTZC/Ju2J7dVsi 3DzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757065485; x=1757670285; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vg+TuI+bOQ+/K0B+1sySJ2VK4abRlS/VZd6mZadbe2g=; b=iDlFshXBy+iFxX+7rxDOBd04wH+u6V/Ocl50WiG5msdEdasmGBQmHpEkpxJvC1WQQR RwulzLdPjYl2Rle/tkuyQBmFNpZgJ91jWVXHao0ju8mt7OQJZ5e4gB6BHt+7OFuXan79 kp5977gDk83asAs/NMGkxahHKPZHC8ttnzCE9FjQEAAA15ohXqlBBlYx2TAaJ/Nmt8ln eYn9mPM011Gbq8eU78tgPt4QfXYWhk0yl6lJdB8bhvLP97NnmCw8PLV/CBUQj8AeprAf JrUt4+uaJ6l4ZtDPkMOBwHffU7ezzyxeTauKQF+CXhZJbBmiO+yROi6xZxTNMaTROzMo S22Q== X-Forwarded-Encrypted: i=1; AJvYcCU0Nv9qh5kZcrwQ2+jlTbQ5lTAp/s0wxDTNPeyPlMbjAuFe5LWd2IywSkbYeLrO9sGTgWM6aIF2fu0H@vger.kernel.org X-Gm-Message-State: AOJu0Yzh8xR2ryNUgWDR7/9KajT8rDRw3kwad7+bigmoDdAOg/xOgJTY FmBWY08rLX5YDqqYzo8gTSioeYruuffKebl/StcVneYcnmKqHr/VYrGi7E53MRq7J3o= X-Gm-Gg: ASbGncuDspAB9LiWLbHPriRw8bfpDLbiDUv8Cu+alKRYceZ2XGrjgQnvBRuEy9RtiUu QJi8HXQgk8O/JY+wUe4fjquadd3i7+VMZCgE2DSVNEDhuk/F1H+OPHx94xWo7zZrNBptunHT+Ya H9y8CngzpxhuEpeXoF/VGO+bUHxiWIZT3TWBivcH/tq4/TM7gK3/vSeuJ2oudl/0QkmVgCfcqyP s8w9y0k/RLt11Pe/alehcvguIW1JGQ/0q/mC399Ar2Yp6YZx3mDBcmwcktQH7QxXGSjHdd0yyBS YQcn0fp6er0WcYtEArIOI4DP/jRE8rZa6xNp4JQ2RdyvPEsmVsL4vH+iSrZLDJnhBdApJuDI5ON HEBZKMKZ9JD+mVABlrk847CcpwxH+bi4qTReHMMtrYFhD57rxnj2BSKGKsxIhKJ5tVY4vX7pt2D nOCMNL841sYZWE X-Google-Smtp-Source: AGHT+IFodgj442lDLbVLMi4njhpRzF0c5s/MBO2AX5hxfzUKZQkDG+LP5IKBwiCAYGAM+uTD1n1Odw== X-Received: by 2002:a05:6000:250d:b0:3d6:b35b:153b with SMTP id ffacd0b85a97d-3d6b35b2262mr15384906f8f.26.1757065485080; Fri, 05 Sep 2025 02:44:45 -0700 (PDT) Received: from ?IPV6:2a05:6e02:1041:c10:43b0:7b3b:e0d9:6992? ([2a05:6e02:1041:c10:43b0:7b3b:e0d9:6992]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3e2f6af9791sm2928315f8f.26.2025.09.05.02.44.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Sep 2025 02:44:44 -0700 (PDT) Message-ID: Date: Fri, 5 Sep 2025 11:44:43 +0200 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms To: David Lechner , =?UTF-8?Q?Nuno_S=C3=A1?= , jic23@kernel.org, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, conor+dt@kernel.org, krzk+dt@kernel.org Cc: linux-iio@vger.kernel.org, s32@nxp.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, chester62515@gmail.com, mbrugger@suse.com, ghennadi.procopciuc@oss.nxp.com References: <20250903102756.1748596-1-daniel.lezcano@linaro.org> <20250903102756.1748596-3-daniel.lezcano@linaro.org> <0bfce1eb-69f1-4dae-b461-234eb98ffce1@linaro.org> Content-Language: en-US From: Daniel Lezcano In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 04/09/2025 19:49, David Lechner wrote: > On 9/4/25 12:40 PM, Daniel Lezcano wrote: >> >> Hi Nuno, >> >> On 03/09/2025 13:20, Nuno Sá wrote: >>> On Wed, 2025-09-03 at 12:27 +0200, Daniel Lezcano wrote: >>>> From: Stefan-Gabriel Mirea >>>> >>>> The NXP S32G2 and S32G3 platforms integrate a successive approximation >>>> register (SAR) ADC. Two instances are available, each providing 8 >>>> multiplexed input channels with 12-bit resolution. The conversion rate >>>> is up to 1 Msps depending on the configuration and sampling window. >>>> >>>> The SAR ADC supports raw, buffer, and trigger modes. It can operate >>>> in both single-shot and continuous conversion modes, with optional >>>> hardware triggering through the cross-trigger unit (CTU) or external >>>> events. An internal prescaler allows adjusting the sampling clock, >>>> while per-channel programmable sampling times provide fine-grained >>>> trade-offs between accuracy and latency. Automatic calibration is >>>> performed at probe time to minimize offset and gain errors. >>>> >>>> The driver is derived from the BSP implementation and has been partly >>>> rewritten to comply with upstream requirements. For this reason, all >>>> contributors are listed as co-developers, while the author refers to >>>> the initial BSP driver file creator. >>>> >>>> All modes have been validated on the S32G274-RDB2 platform using an >>>> externally generated square wave captured by the ADC. Tests covered >>>> buffered streaming via IIO, trigger synchronization, and accuracy >>>> verification against a precision laboratory signal source. >>>> >>>> Co-developed-by: Alexandru-Catalin Ionita >>>> Signed-off-by: Alexandru-Catalin Ionita >>>> Co-developed-by: Ciprian Costea >>>> Signed-off-by: Ciprian Costea >>>> Co-developed-by: Radu Pirea (NXP OSS) >>>> Signed-off-by: Radu Pirea (NXP OSS) >>>> Signed-off-by: Stefan-Gabriel Mirea >>>> Co-developed-by: Daniel Lezcano >>>> Signed-off-by: Daniel Lezcano >>>> --- >> >> [ ... ] >> >>> The above needs some discussion at the very least. Have you considered the IIO >>> DMA buffer interface? It should be extendable to accommodate any particularity >>> of your usecase (or we should at least discuss it). >>> >>> With it, you also gain a userspace interface where you can actually share DMA >>> buffers in a zero copy fashion. You can also share these buffers with USB >>> gadgets. For instance, with libiio, you would be able to fetch samples from your >>> host machine (through USB) in a very fast way (zero copy between IIO and USB). >>> >>> Setting up DMA to then "having" to push it to a SW buffer and needing a syscall >>> to retrieve the data seems counter-productive. >> >> I've read a bit about the DMA engine. It is unclear how to use it and there are very few examples in the different drivers to refer to. >> >> This proposed driver supports the RAW, BUFFER and TRIGGERED. >> >> Shall I create an IIO device with the modes: >> >> indio_dev->modes = >>     INDIO_DIRECT_MODE | > > Only INDIO_DIRECT_MODE needs to be set here. > >>     INDIO_BUFFER_HARDWARE | >>     INDIO_BUFFER_TRIGGERED >> >> And then use: >> >> devm_iio_triggered_buffer_setup() > > Yes, use this and it will add INDIO_BUFFER_TRIGGERED to the flags. > >> >> and >> >> devm_iio_dmaengine_buffer_setup_with_handle > > Likewise, this will add INDIO_BUFFER_HARDWARE. > > And you likely only need to call devm_iio_dmaengine_buffer_setup() which will > save some boilerplate code. What is still unclear for me is the trigger and the dma modes. If the dma engine is supported, I should use devm_iio_dmaengine_buffer_setup_with_handle(), but will the trigger mode be supported also automatically (I don't see a clear answer in the documentation neither in the drivers) ? If not, shall I call devm_iio_triggered_buffer_setup() and devm_iio_dmaengine_buffer_setup_with_handle() ? -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog