From patchwork Thu Mar 20 08:21:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 14023502 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 22C4920B81E; Thu, 20 Mar 2025 08:21:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742458898; cv=none; b=DUs98vbx/C7bHlNIYCgkhDg3Ki/tikvtv43ByiZZ62KWsWpWC6N/SnGrWUDzWTx4HfhjCrskOlUbaz/lCgTmEEoX4avdZWbAolyFv4us9WkLgwEVmjWKqRJcdD5yEz14z1/DsIBLajKxaQDs1wCmq0SaN3FvsYJKwVEE5BYsrio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742458898; c=relaxed/simple; bh=5s+1olZvrfDepZYolF+XZxcPNp0eu1iVp32/XZsDt88=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eeSbEsES1b46Ca//NNDNLApt5W1ndsrh7hmSKmECPBBBkpWVzy7zKBHvV4pyiwe5MVz1mquTH17AdpOnoYjtUuX0dEmNORHCtzWh6kmkYKVG6HzRo37LMaG7NTxZ6aEC4uRctxuhWHtQjHdMGF+9U8JrNYq9qlOtPlOYt8xFUNI= 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=dxPQQWuK; arc=none smtp.client-ip=209.85.167.53 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="dxPQQWuK" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5493b5bc6e8so543117e87.2; Thu, 20 Mar 2025 01:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742458894; x=1743063694; 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=PHn5LS6QjK1roaVwIQAN41urQFISbkKM+favVVAYAjs=; b=dxPQQWuKBxmMbsteRZTGx6KFuFzeHnrVyQJWCdEYi2AmeKCnNMr2wh+Pkve8LFCMH7 OVuelnY7mJyKSrCMJfeMyeKrEDBhYJXcHyZezOVtCnIyUewZ5lNKF29kGm1HfNPJZtZb S+gGEqbTkBv2oPyOsNZrdRAVy3OwOYL8rBKCxbsDo6GE00UUJo1DgRxlSNpWiPbWrgBn +96v1D71nYGOvW67gdpvgJ/gzy/k00B+ObxP8XzDBmzBT/Jyy15HTSoqqcOTcLDbDNDL umB3EX1pVr7DDMADmwRNmVejaBBoS1fbkg8cCT8xFIGSiz7YzmkWMZ8drWpNnsJ29927 XjGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742458894; x=1743063694; 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=PHn5LS6QjK1roaVwIQAN41urQFISbkKM+favVVAYAjs=; b=AxaUBmKf+g48ZJEfZoyMmcEPQUezw/p3wI05pcAakP6cpaZ7fFT2yLXMOZxS+lB+ZP OQ5/zcjwLEifsTvaEd0wn/fh3KWr1s7UiHTVB657RnUvYNf9uVC6L7ol83SB86/uj8kc +aya6QuYOE1L7aS8wizWHrvjehT1vktlEKd8IheigINzdnoFo6td3VDigz4PwbknQiVM dc7RGnkf4zFYl/7xiLQreBvwO/aGAwfYwWVFIV1HsfGH7JMrhMLsejgKG7F1mdTpjXHa SJlu8+lL7Dpo0LCHjlHBWNWNxD20Z7OnzpUTnH89krocYt8nNnRGgTYxz95LkkKxZHDi M7fA== X-Forwarded-Encrypted: i=1; AJvYcCUW9k3xE2n1MZYmaEJJNSw8UEvjUED01cXLOm+BQPR+tw7VBIg7Fopb3P59AnrELDg0re4g3eb+aOU=@vger.kernel.org, AJvYcCWglMllZ/iJHVkGF5q7RGjRF5DZSFNNn6Yic1PyQMEFUUEyyy+XQtsrIMnpnbgIO5ow0lJUVQAzXrkZcGV9Kv7jfa0=@vger.kernel.org, AJvYcCXrrvDmVjg7CKFgosPIFvFfQV7S75s+x4TGDEU1OnRCBiImITw6SpLOyVlOk4fWZX4MbfAvcUMN1r71fCOB@vger.kernel.org X-Gm-Message-State: AOJu0YzTKnwCZavWXwzmYLafuocyKT+Ktv+AaSL8jybBzuLj8CC1Bhzj LD0g0a8MOEioy3NaSLZm3gmLoAWhQTkCKssWtypEvhRvsl+1kihC X-Gm-Gg: ASbGncv11X7R6eUPi/XLk9u7FlM3Vgy6aEMfrw8hvL+SFcXHWkmpVZbEdLiJ8zUTrC2 hYmN5JlQTpf8a48zOfCS6vatV3/ZtBcYpf6jpptcflekzDK4NSiafyCxpgywC9HSVUAuaSYuH/t pcyN9KEE+JHF5/STX9drzN25H5kWeXQ/Xzn8HFrwPL2AsbIAf8qgV2Hyzcdz2fCrkXIJfwnk90H eANYdsv4WTpeAn1xkl8F5UhmG2uEL1XgXkNPAm2QKr1pQcHXmiPd0j7yHz5kIOagQN1tFnvaDA9 eaON8zY+lKlN5UV0mXl0T/cs57A8qN1DJcEbmho0uB4Anz3i0r0= X-Google-Smtp-Source: AGHT+IH6fqyrgkSGKtXPSSRg+UaxhjJDwQO8+OiM1mUCfcH7FhAMZW5Tt3ZymhgCuqoN+F+bt02DKA== X-Received: by 2002:a05:6512:39c7:b0:549:2ae5:99db with SMTP id 2adb3069b0e04-54ad068651fmr788267e87.45.1742458893832; Thu, 20 Mar 2025 01:21:33 -0700 (PDT) Received: from mva-rohm ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba7a86c1sm2209974e87.21.2025.03.20.01.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 01:21:32 -0700 (PDT) Date: Thu, 20 Mar 2025 10:21:28 +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 v9 4/8] iio: adc: rzg2l_adc: Use adc-helpers Message-ID: <9a3a11561dbd3d5023da2da05cf2190793738242.1742457420.git.mazziesaccount@gmail.com> 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_se() -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" -properties 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 Reviewed-by: Andy Shevchenko Tested-by: Claudiu Beznea Reviewed-by: Claudiu Beznea --- NOTE: This change now drops a print "no channel children" which used to be printed if no channel nodes were found. It also changes the return value from -ENODEV to -ENOENT. Revision history: v8 => - No changes v7 => v8: - drop explicit "no channels check". It is now done inside the devm_iio_adc_device_alloc_chaninfo_se(). v6 => v7: - Fix function name in the commit message v5 => v6: - Commit message typofix 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 | 39 +++++++++++++++---------------------- 2 files changed, 17 insertions(+), 23 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..8097e59da516 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,48 +325,39 @@ 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); - if (!num_channels) - return dev_err_probe(&pdev->dev, -ENODEV, "no channel children\n"); + 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 > hw_params->num_channels) 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; + for (i = 0; i < num_channels; i++) { + int channel = chan_array[i].channel; - 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; - - 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 +618,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");