From patchwork Mon Mar 3 11:32:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13998638 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 6CCB01FBEA6; Mon, 3 Mar 2025 11:32:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741001561; cv=none; b=AR0cw8q5g1PiBrDuX2CfkTAsnwugQ+puzbGkR+w0QfusXUrtFl2yjK6mKFPtMgN/0h2HS4MnsFzA0cQV7v+5sk/9ThJdY9rO3vHCNhfW619XJE97d6RWN26VD2xCoGx0ItBi579a3turEqsos4e28VT3Zp+jfrSMLZNs9OiI8Ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741001561; c=relaxed/simple; bh=5Jo5imvp//ymQAHKsP7TsaZmdx0IGxFyllbskQnm8zQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pZMj+tpCVOJKZpQ1XJTNbqHRGtAZ208BzR6BxssYO2IffjVAy1+tfnMjp0HD7vVwNVtWVuTH/KGe6q8nKvnlxrKBS6tTe1rcXPolM/naL99E6nE/oJPzbgxslwFzaC3A9vlBZjmcypwQkWXtHclf31LFU9euHn5sYdBXHASoVSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ne+RNNp8; arc=none smtp.client-ip=209.85.208.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ne+RNNp8" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-30bae572157so15349551fa.3; Mon, 03 Mar 2025 03:32:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741001557; x=1741606357; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=gD6SrAlWl3wCZz8bVhVbWlCcSCnWlJIW+5H7Xm1tBYc=; b=Ne+RNNp8xJF08BS1RlH4Q1OSU3hX5Q3OlXUZYF3UNiFbfofzGMgw3csB2n0XVJGZEr U1nc5lkvLg4vdzgh6umUZH3Nf/zm9G4l/B9Og4rJLkDH02H8TiTUcPoODZNO/EBbxVpI nSoe4UCPDG90PFuyeXRSCnyAZPVi7DYVx8FA0TFKgmGNWbFJh5ySzexdzjn8ABjk4wdz iyg8cUP8/KmdiuT9Q4UONW2ZIPBvJ+i0WAIq+FKZkZG/BHaf3+zoPN03gpGUyz4dY9MM vs1LvxxgCYjCHZjOG4uIoQaZ2N8cvvR+eTrUicWwM8IK0XVT3EtaFSIogxA3btdMR8eH s3BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741001557; x=1741606357; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gD6SrAlWl3wCZz8bVhVbWlCcSCnWlJIW+5H7Xm1tBYc=; b=gVLkzzARp2PwLhABIvwCWDaMABRef/BWe4xVAxnLIzGcBusBreG0th4iiGn26/3M+K clSoL8R8ewwND1Aj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8lcLIuG vqDWUCuggprU= X-Google-Smtp-Source: AGHT+IFn4ltod1VzU04f++mdV7LEwmx/Dhosdu103RiT+cuTpsuc+ht1g6mmZsgINc2fxQBSHduAiQ== X-Received: by 2002:a05:651c:198a:b0:30b:a100:7cff with SMTP id 38308e7fff4ca-30ba1007d72mr38094521fa.5.1741001557124; Mon, 03 Mar 2025 03:32:37 -0800 (PST) Received: from mva-rohm (mobile-access-2e8451-125.dhcp.inet.fi. [46.132.81.125]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30b9ba54a07sm9569871fa.52.2025.03.03.03.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 03:32:36 -0800 (PST) Date: Mon, 3 Mar 2025 13:32:29 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Matti Vaittinen , Lad Prabhakar , Chen-Yu Tsai , David Lechner , Javier Carrasco , Guillaume Stols , Olivier Moysan , Dumitru Ceclan , Trevor Gamblin , Matteo Martelli , Alisa-Dariana Roman , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v5 04/10] iio: adc: rzg2l_adc: Use adc-helpers Message-ID: References: Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The new devm_iio_adc_device_alloc_chaninfo() -helper is intended to help drivers avoid open-coding the for_each_node -loop for getting the channel IDs. The helper provides standard way to detect the ADC channel nodes (by the node name), and a standard way to convert the "reg" -propereties to channel identification numbers, used in the struct iio_chan_spec. Furthermore, the helper can optionally check the found channel IDs are smaller than given maximum. This is useful for callers which later use the IDs for example for indexing a channel data array. The original driver treated all found child nodes as channel nodes. The new helper requires channel nodes to be named channel[@N]. This should help avoid problems with devices which may contain also other but ADC child nodes. Quick grep from arch/* with the rzg2l_adc's compatible string didn't reveal any in-tree .dts with channel nodes named otherwise. Also, same grep shows all the .dts seem to have channel IDs between 0..num of channels. Use the new helper. Signed-off-by: Matti Vaittinen --- Revision history: v4 => v5: - Drop the diff-channel stuff from the commit message v3 => v4: - Adapt to 'drop diff-channel support' changes to ADC-helpers - select ADC helpers in the Kconfig - Rebased to 6.14-rc3 => channel type can no longer come from the template. v2 => v3: - New patch The change is compile tested only!! Testing before applying is highly appreciated (as always!). --- drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/rzg2l_adc.c | 38 +++++++++++++++++-------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 37b70a65da6f..e4933de0c366 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -1222,6 +1222,7 @@ config RICHTEK_RTQ6056 config RZG2L_ADC tristate "Renesas RZ/G2L ADC driver" depends on ARCH_RZG2L || COMPILE_TEST + select IIO_ADC_HELPER help Say yes here to build support for the ADC found in Renesas RZ/G2L family. diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c index 883c167c0670..51c87b1bdc98 100644 --- a/drivers/iio/adc/rzg2l_adc.c +++ b/drivers/iio/adc/rzg2l_adc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -324,21 +325,30 @@ static irqreturn_t rzg2l_adc_isr(int irq, void *dev_id) return IRQ_HANDLED; } +static const struct iio_chan_spec rzg2l_adc_chan_template = { + .indexed = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), +}; + static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l_adc *adc) { const struct rzg2l_adc_hw_params *hw_params = adc->hw_params; struct iio_chan_spec *chan_array; struct rzg2l_adc_data *data; - unsigned int channel; int num_channels; - int ret; u8 i; data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; - num_channels = device_get_child_node_count(&pdev->dev); + num_channels = devm_iio_adc_device_alloc_chaninfo_se(&pdev->dev, + &rzg2l_adc_chan_template, + hw_params->num_channels - 1, + &chan_array); + if (num_channels < 0) + return num_channels; + if (!num_channels) return dev_err_probe(&pdev->dev, -ENODEV, "no channel children\n"); @@ -346,26 +356,11 @@ static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l return dev_err_probe(&pdev->dev, -EINVAL, "num of channel children out of range\n"); - chan_array = devm_kcalloc(&pdev->dev, num_channels, sizeof(*chan_array), - GFP_KERNEL); - if (!chan_array) - return -ENOMEM; - - i = 0; - device_for_each_child_node_scoped(&pdev->dev, fwnode) { - ret = fwnode_property_read_u32(fwnode, "reg", &channel); - if (ret) - return ret; - - if (channel >= hw_params->num_channels) - return -EINVAL; + for (i = 0; i < num_channels; i++) { + int channel = chan_array[i].channel; - chan_array[i].type = rzg2l_adc_channels[channel].type; - chan_array[i].indexed = 1; - chan_array[i].channel = channel; - chan_array[i].info_mask_separate = BIT(IIO_CHAN_INFO_RAW); chan_array[i].datasheet_name = rzg2l_adc_channels[channel].name; - i++; + chan_array[i].type = rzg2l_adc_channels[channel].type; } data->num_channels = num_channels; @@ -626,3 +621,4 @@ module_platform_driver(rzg2l_adc_driver); MODULE_AUTHOR("Lad Prabhakar "); MODULE_DESCRIPTION("Renesas RZ/G2L ADC driver"); MODULE_LICENSE("GPL v2"); +MODULE_IMPORT_NS("IIO_DRIVER");