Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp484432lqt; Thu, 6 Jun 2024 09:08:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUM3jct1gC4tYaZkAv4phn2tSN+S1LOKKszyNcE4gxOr8fVWjJo4k07eM1mGBBzlWEqL0w6ks1JsNhKdGJ6GHhFYybGfoZv6K+59LS2dA== X-Google-Smtp-Source: AGHT+IEHTPtt8BX6u6u5lgwV9rR9UHn1bbyQ44LTIrEtqglrr34ros/frrq5OvK6e1GAqw3+hnjW X-Received: by 2002:a50:d4d9:0:b0:57c:4882:3997 with SMTP id 4fb4d7f45d1cf-57c48823a10mr797687a12.28.1717690108226; Thu, 06 Jun 2024 09:08:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717690108; cv=pass; d=google.com; s=arc-20160816; b=osaFFCVmaN4Y/ADDoKzntnzqKf3O9dO8euJS3NKvFTuMpZXMOBC/5vnStGKrIbxJSR /Gx/Z/wBOlfXrUf13GkXq5lPqqBwLZqVNfwChLyPNFEzxTqonRP3q5Gqufj2nnSj1Bfy Pk5kzNk/SSuMVCJdgIYBORr+J6xOVcwurZqV6WlsWCQBYguvBPPb0kBTNCWsTo8XY3ZC IZ0HIVDgpxqdR8DOuqqNhYcrMcZWtpEm1TZ88aW2eyu3/I2Bk/K5Jerh6ODNft0pyNiX 9UYSHJ/0r+dkZhWHJC45i8mW77m8QCMn3DpJwhFKO0+r5/ucJoPMUAdEPjX87TiJy0g6 0DaQ== 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=wyAqMtZgIEUSQJwemYV7XZ3J1TdW+hM6pD+KJ6xcmlk=; fh=EQEg2uMdVKc1N2B2kh6FDQLTEZ7OCf3UIFXvCCFTBso=; b=GfvA3heRilsbPIpoz0IBXnR4E3p3Nqy99aV6ilCSDc3dXy9P6nqWRZAw6+sfEtROgY //vu6zL1ObLljwF/anEwdbu16Vyk/5cdGvHi1zDkmjeKmXTrlSqfJUkHgjArbLCv0naO 8RimuR1jqDwo7YAITOM1po8286+t8iRd82n964+VJVKcCe0ItmUe10YY9CL8QNb6rt1a CSgwy9rJttM75Hr1kdCkEy5NEV5Sc66TMPCCE/LcjlN6URP+dp4AzPAEblYjifbVpFJR U4Ng9uHURvuQDLbVbWbo4YQXRP8ihtISwxLYD1BwjoQ/K85ZRrk6uiLxm6iOVedKx2C+ vmHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q8qVtAqW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-204644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204644-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae0c6140si848636a12.138.2024.06.06.09.08.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 09:08:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q8qVtAqW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-204644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204644-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 EB2361F22892 for ; Thu, 6 Jun 2024 16:08:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38CFA1990B0; Thu, 6 Jun 2024 16:07:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q8qVtAqW" 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 3F0DC197A98; Thu, 6 Jun 2024 16:07:42 +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=1717690062; cv=none; b=UQM1iPve54XuYS9BXu+G6bnBdxxVLvforzXWhqHLtiLsqq2O2Zn9GKZ7Fu3Z+Usr0FUu+NYjkfcXJqLvc+LqTf4SamxcpRsJPz2nzO+mTnbbvPgmHLyHPhqyLd8KS0rqb8l/TIpJPOoni8LbHLvkt5XiYyLRF+imLJywIcvNtoc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717690062; c=relaxed/simple; bh=I8QhRMMTY7Sn7kVFggQi6xZH1k/ZS+7ezVgehAwwnKs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i3TwdzvPdPA+gTEdy8qDsiFJhnxITOJpdLT0kKjK0iA6M6tz5PFs4nz4Ct4h51HJinlcFW/9XfBfU7OUb8ml3D6hOmjCxQyO+jahU7eCNInwRgl4WW/VRvX1IN1nZuZx6Mw8nNHO8GWSmAmEaDMDDciC0Vhy8+b995oMqXfgJ6M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q8qVtAqW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id D6DACC4AF11; Thu, 6 Jun 2024 16:07:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717690061; bh=I8QhRMMTY7Sn7kVFggQi6xZH1k/ZS+7ezVgehAwwnKs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=q8qVtAqWT7ozq2vn1EDvu3ITuH1Pa9Eo9GKAw7AmZ/un3g74AIoNpm15ZFyicve4d yc5gSWvYrLzRnkev81G2JWhIaO6jelRNerKr8Pmjdsfn1VdudiKfIo2i7WojvoHPbO 5QjdjDFG4StQn65glRVo/0kbuQi5SftTLSXB28uCco/Wt4E+CGZztz77HnxTk6cURC gNX4ICwEKLqQ0TS6oISsGue/FcuXpCCMUYdmzgJVs41u1dsfbyCFEBBjzaAx32lVw/ dgXvgf9c85JbpQpHaFzeJBw/gpegbw2ogBT1z+EsnwGJYqwajIDJjBzLlwwN3qy/B+ UNnqbFkxEx6Ew== 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 CC1CCC27C55; Thu, 6 Jun 2024 16:07:41 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Thu, 06 Jun 2024 19:07:43 +0300 Subject: [PATCH v6 4/9] 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: <20240606-ad4111-v6-4-573981fb3e2e@analog.com> References: <20240606-ad4111-v6-0-573981fb3e2e@analog.com> In-Reply-To: <20240606-ad4111-v6-0-573981fb3e2e@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=1717690059; l=2390; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=Rvmh4+bkvyAlbEsr4U+b9e6sWYI3MMB6i+yP4e+zyrY=; b=UKqyO0zKDzJZPGBsf0zu4eR1hFGaUeXS4kJq9dqnsbUKaCUOzcNQIeAExhCBUri1ZdS5GXnmx 6Hymx7QjILjAOUAdogTi0nzpZN0sboMB/YfnSj8Xn9j8mJr949LWw0I 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 f3088e8b4b8b..8631f218b69e 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -913,7 +913,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); @@ -1008,7 +1024,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]; @@ -1067,16 +1082,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