From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 729ADC19F32 for ; Sun, 2 Mar 2025 03:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Sv+PaHd1LGTBEo7gudZ2gUZ3eHBcnIDjQLr6NXCLLg8=; b=S63o40BieokAC4eho7I9vRb75p AUeAyUOFhgEZPo7/8Mh8T8263Km00F9y4GqMIYQL+5cNN0oSjRlt6v8DblHuw8meZLYBoIAigSAMX bJohtbcvgC5m/lapdwgZeowSanCSGD3jtV+JRIYf49RaSmSolmMDUEr5XC40tVhtBAm4TCNT+ta6a VNUOlZoZAzyTpPZGgh9g0Sn2hmNJBg+ESB3AzWWSIwaEX2BTyHexkLgfSK38Ago1/F+qHu0mQ+7cn aFXLOq/nU12vA1HAqqqcJfYlLdGTX17XQthHCUFJJB21NGoq/7kSGn0AJjKtddodqL1YoXovdknyL tgdE9hZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1toaLN-0000000FKov-2itO; Sun, 02 Mar 2025 03:50:21 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1toaJb-0000000FKaY-3VfF for linux-arm-kernel@lists.infradead.org; Sun, 02 Mar 2025 03:48:33 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5E4FC5C1D0A; Sun, 2 Mar 2025 03:46:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79B06C4CEE2; Sun, 2 Mar 2025 03:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740887310; bh=GCHeyfxkGkvIchus3GM+deq2n2Ej9SrlPO3hBk7T/cE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=O6var03g/VBNqQQ1++7eZs13WnPx5s47dELYpLjGcVwvwY5aQ/TMqh7dAQQpvBj0Z m59c5nbUJo7PZd+Ayy9Qt/7g3G3gzNWuLOdVJOXTwxoFPFg4GcdHRdSSCvgh3Fqmta 9+u/tQFtWSJcawg2WYQIO3Vj5Li/+4KUCstdKHj8PQkrbGaosx89c5tKozK8c8awRg 2HbrZeqNTXhpHTaMoAQwJgVmePY9dd/Og79xFsPIEYWdhEMyAz+xbpekzO0hAYq3hB 8SlC/C965imuhmwZY3tuE0w38lCFWgdFX+O7VgTTsC+D0HUOfASDWlvhy6lvWDKsY3 SC2xephK1WgMw== Date: Sun, 2 Mar 2025 03:48:07 +0000 From: Jonathan Cameron To: Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Lad Prabhakar , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hugo Villeneuve , Nuno Sa , David Lechner , Javier Carrasco , Guillaume Stols , Olivier Moysan , Dumitru Ceclan , Trevor Gamblin , Matteo Martelli , Alisa-Dariana Roman , Ramona Alexandra Nechita , AngeloGioacchino Del Regno , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: Re: [PATCH v4 03/10] iio: adc: add helpers for parsing ADC nodes Message-ID: <20250302034807.680a3971@jic23-huawei> In-Reply-To: <23f5ee3e3bf7179930d66c720d5c4c33cdbe8366.1740421248.git.mazziesaccount@gmail.com> References: <23f5ee3e3bf7179930d66c720d5c4c33cdbe8366.1740421248.git.mazziesaccount@gmail.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.48; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250301_194831_969794_779B3A24 X-CRM114-Status: GOOD ( 31.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 24 Feb 2025 20:33:16 +0200 Matti Vaittinen wrote: > There are ADC ICs which may have some of the AIN pins usable for other > functions. These ICs may have some of the AIN pins wired so that they > should not be used for ADC. > > (Preferred?) way for marking pins which can be used as ADC inputs is to > add corresponding channels@N nodes in the device tree as described in > the ADC binding yaml. > > Add couple of helper functions which can be used to retrieve the channel > information from the device node. > > Signed-off-by: Matti Vaittinen > > --- > Revision history: > v3 => v4: > - Drop diff-channel support > - Drop iio_adc_device_channels_by_property() > - Add IIO_DEVICE namespace > - Move industrialio-adc.o to top of the Makefile > - Some styling as suggested by Andy > - Re-consider included headers > v2 => v3: Mostly based on review comments by Jonathan > - Support differential and single-ended channels > - Rename iio_adc_device_get_channels() as > iio_adc_device_channels_by_property() > - Improve spelling > - Drop support for cases where DT comes from parent device's node > - Decrease loop indent by reverting node name check conditions > - Don't set 'chan->indexed' by number of channels to keep the > interface consistent no matter how many channels are connected. > - Fix ID range check and related comment > RFC v1 => v2: > - New patch > > iio: adc: helper: drop headers > --- > drivers/iio/adc/Kconfig | 3 + > drivers/iio/adc/Makefile | 2 + > drivers/iio/adc/industrialio-adc.c | 89 ++++++++++++++++++++++++++++++ > include/linux/iio/adc-helpers.h | 22 ++++++++ > 4 files changed, 116 insertions(+) > create mode 100644 drivers/iio/adc/industrialio-adc.c > create mode 100644 include/linux/iio/adc-helpers.h > > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig > index 849c90203071..37b70a65da6f 100644 > --- a/drivers/iio/adc/Kconfig > +++ b/drivers/iio/adc/Kconfig > @@ -6,6 +6,9 @@ > > menu "Analog to digital converters" > > +config IIO_ADC_HELPER > + tristate > + > config AB8500_GPADC > bool "ST-Ericsson AB8500 GPADC driver" > depends on AB8500_CORE && REGULATOR_AB8500 > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile > index ee19afba62b7..1c410f483029 100644 > --- a/drivers/iio/adc/Makefile > +++ b/drivers/iio/adc/Makefile > @@ -3,6 +3,8 @@ > # Makefile for IIO ADC drivers > # > > +obj-$(CONFIG_IIO_ADC_HELPER) += industrialio-adc.o > + > # When adding new entries keep the list in alphabetical order > obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o > obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o > diff --git a/drivers/iio/adc/industrialio-adc.c b/drivers/iio/adc/industrialio-adc.c > new file mode 100644 > index 000000000000..d8e9e6825d2b > --- /dev/null > +++ b/drivers/iio/adc/industrialio-adc.c > @@ -0,0 +1,89 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Helpers for parsing common ADC information from a firmware node. > + * > + * Copyright (c) 2025 Matti Vaittinen > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +int iio_adc_device_num_channels(struct device *dev) > +{ > + return device_get_child_node_count_named(dev, "channel"); > +} > +EXPORT_SYMBOL_GPL(iio_adc_device_num_channels); Just noticed, this isn't namespaces which is a bit odd. I'd drop the export anyway in favour of static inline but if you don't match the namespace of the next one.