Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp672824lqh; Fri, 31 May 2024 12:43:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVG00NpfyC+3s7SSlB9xlyHwa2GWCYEL+DOCo324VZP1DZEEi6FI6rYj/+HtMjIzhd7zpf/6cLjrMwp3Xx+O/7du04c9naHWXTlfQz7ig== X-Google-Smtp-Source: AGHT+IHZUJVIZjqK9noqhv4zbqjshlof1IFLaSXnIO2E8G9Byn0nLxQe9ME4XHP+MMDCwPyr3xtr X-Received: by 2002:a50:8e59:0:b0:578:64c3:e3e5 with SMTP id 4fb4d7f45d1cf-57a3658b7e1mr1888115a12.38.1717184620897; Fri, 31 May 2024 12:43:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717184620; cv=pass; d=google.com; s=arc-20160816; b=x/E4WXSPwsZaNulrb8Xq3geogdctSQFoUy9hLSxWJM1TMk0QehQEVpqcD3vhZ9WZSd Va1Hn26AQnppIShIrykhn3owUuRtbCFwbNtjMdu6nsXlP+qsDYQoZ00GDFyEcRQnpUYM Rh9hQkw13Ler0g6uX8xjjki1MmW7ePHr5V10fGfThA6lm/rwejF5l7C2kviMwigV8wPe bL77J4DzC8SsvkpVuCz2W61gLD/m5PKiFOGPhCLFiBarVTsTLXgbGQ1r6WDd0gZK57xf yZVOsn5wn4XFm2oJTi/RB3L5es0tvZk9hUR90q4EPLn7HQLyND884zWl9LlRsCagd+Hl SC9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=3eWtr2txsOg5CAxzWTNiEnTUdUe0IO+PscxjdAe3Kq8=; fh=EQEg2uMdVKc1N2B2kh6FDQLTEZ7OCf3UIFXvCCFTBso=; b=sozzDvB632T185uA9hnGl8jo35rFGdapTTizgsWeO3RXMQTjTcfjKxijGRUlJBnXDl A0UxxQwM8RZDF2+JiDDbfTlTLqnz4CnQdgPN9bapzoyDf+G3+YMVPKdRyNw3PYAVrNzr 3/M8X4GFCoaJJuZ2nts41dYZoQvWTFXudzWbmarq03LnYvIzCXocOYcV9MQ7bFXZ5oEt 4p8HUjQsDOPk8Cfw7HUQv2w9e7egCaQMu5I06zfjMorJ0MfS3TMIvuN0ZCDIGk+LK3KM CtEDnF+7oZpzYP78dHSAIhgWA03lrGnQn5yUXyHmXbnwGAp5JzluwjJVQkEeMV2JUmRY h0MQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mhzkntFP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197390-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31c62cfbsi1260287a12.276.2024.05.31.12.43.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 12:43:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mhzkntFP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197390-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7F7D21F28DF0 for ; Fri, 31 May 2024 19:43:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CA0B17F4F6; Fri, 31 May 2024 19:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mhzkntFP" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96BAD17C223; Fri, 31 May 2024 19:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717184571; cv=none; b=tRmi+FxPNbkS2fzs8cEwW+fyL4C4HpFlPx81S5QHKwOIV4/GtZQNrtfAbbqAXzRjJmedVHbUuGSZk70nzqcPaaKDPjbznU8MFbcp8GoQpYklzX8KGUGc7FpwF0uFvRZIfnyhU1VlnEgqQfTI70+NuKCDQ7tBXrEJNImo07D0gok= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717184571; c=relaxed/simple; bh=sLlNh5KM9caSYG90x2iutDPvdP6uUJqRbn814aBoYIk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dcUFBx6ujXUe6hCJKTFudoR6GvRzsltxcjgY4G6z51sZ8kW8mk4NosoztE2GREq5PlQafYq5m/1FeLVTmiJ8UqnRJWrYvj8nKyNSKbt5WEXzhV49ksCxWDKq1VIbG9uFZARBc9glleH4qE8UrVOu8IU3esqSsaEaC/jdUMGXtTk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mhzkntFP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 3C246C4AF0B; Fri, 31 May 2024 19:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717184571; bh=sLlNh5KM9caSYG90x2iutDPvdP6uUJqRbn814aBoYIk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mhzkntFP1mcEZ1D0J+hIEC2PpjFdQrYvZozm33tPdlxZrQNTjD+rZPCj+XNy+0XwA jlmbQqwbNmYCk62FvvPP17sUPaFIwKm3AnA1WAwqZ2UJo/MWGa5wsQZgYR4vItjfiU S7lXZKc8lJJhzJQiXY3EM5Rw0JLnXccOCy7k0lkS5kbrMVuPXMaaMFrDUGA7w8JgoK rGgxExlfkkbSWNvB9inTIDNFhivYdAl6hJI2bJgbxlWXQTv/AHWbaaIH69FZI8YRs4 0Ep6FCasPZI8/eCIj1ohPJP4a9aBt2vJ2SlD1+yCVY/+k9BFH52uZ7zpZW/KsWB771 bUn7etG72ddvA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F891C25B7C; Fri, 31 May 2024 19:42:51 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Fri, 31 May 2024 22:42:28 +0300 Subject: [PATCH v4 2/6] iio: adc: ad7173: refactor channel configuration parsing 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: 7bit Message-Id: <20240531-ad4111-v4-2-64607301c057@analog.com> References: <20240531-ad4111-v4-0-64607301c057@analog.com> In-Reply-To: <20240531-ad4111-v4-0-64607301c057@analog.com> To: Ceclan Dumitru Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan , Jonathan Cameron , Nuno Sa X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1717184569; l=2390; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=tyfIBjq9+3kqvLQ3iYrfTDEdse1O9TimBWVFOmM0qog=; b=DTeTcfTX5k8OZQ8f3AaMWc5IifhiebXkxIwsMzcSHA4ddZchb5XI0DLAlSwkAD0LyjeiBUbfj 5Ly49LIRkrEAqDUjwvn2wCJDyP4Oaa9F82xwpoWLSIo09YbRUT66myh X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan Move configurations regarding number of channels from *_fw_parse_device_config to *_fw_parse_channel_config. Suggested-by: Jonathan Cameron Link: https://lore.kernel.org/all/20240303162148.3ad91aa2@jic23-huawei/ Reviewed-by: David Lechner Reviewed-by: Nuno Sa Signed-off-by: Dumitru Ceclan --- drivers/iio/adc/ad7173.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index 638e2468efbf..6e249628bc64 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -912,7 +912,23 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) struct device *dev = indio_dev->dev.parent; struct iio_chan_spec *chan_arr, *chan; unsigned int ain[2], chan_index = 0; - int ref_sel, ret; + int ref_sel, ret, num_channels; + + num_channels = device_get_child_node_count(dev); + + if (st->info->has_temp) + num_channels++; + + if (num_channels == 0) + return dev_err_probe(dev, -ENODATA, "No channels specified\n"); + + if (num_channels > st->info->num_channels) + return dev_err_probe(dev, -EINVAL, + "Too many channels specified. Maximum is %d, not including temperature channel if supported.\n", + st->info->num_channels); + + indio_dev->num_channels = num_channels; + st->num_channels = num_channels; chan_arr = devm_kcalloc(dev, sizeof(*indio_dev->channels), st->num_channels, GFP_KERNEL); @@ -1007,7 +1023,6 @@ static int ad7173_fw_parse_device_config(struct iio_dev *indio_dev) { struct ad7173_state *st = iio_priv(indio_dev); struct device *dev = indio_dev->dev.parent; - unsigned int num_channels; int ret; st->regulators[0].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_EXT_REF]; @@ -1066,16 +1081,6 @@ static int ad7173_fw_parse_device_config(struct iio_dev *indio_dev) ad7173_sigma_delta_info.irq_line = ret; - num_channels = device_get_child_node_count(dev); - - if (st->info->has_temp) - num_channels++; - - if (num_channels == 0) - return dev_err_probe(dev, -ENODATA, "No channels specified\n"); - indio_dev->num_channels = num_channels; - st->num_channels = num_channels; - return ad7173_fw_parse_channel_config(indio_dev); } -- 2.43.0