Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2513472lqo; Tue, 14 May 2024 00:24:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVX5D3gzqn8f9r4AUbBnvX9PUKvcbobWujDL9WeBGtx1Gmpc9GzZrnliOJQVLJ1EAoG8+GrX/En3VM5I45vm1Mclgx+RiMxs2194qH1jQ== X-Google-Smtp-Source: AGHT+IFKQpxDSQXt8e8yk24lrEUJzN3fhUkMbbIAOXnEeSRAQRR6CxZSGaBsGQ45V5/NznA3kYYo X-Received: by 2002:a17:906:684a:b0:a59:a64d:c5b9 with SMTP id a640c23a62f3a-a5a2d67635fmr1091784766b.76.1715671488926; Tue, 14 May 2024 00:24:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715671488; cv=pass; d=google.com; s=arc-20160816; b=jSKs97HsBzg+Ofd+SWy7sRc9ZKXQj7l5D/UtFL+l9kUrxBHzN85I5qhmLHSWF9TLpU 6wJMPeKAPFK4XuXSmrAxZt1VGz23yTa5keg2Rbx+H2UtogLPdF1bPX+404vOYYFHpqcO YS21nA0MArcX/gZ+IkKgyVLvuHGfWrH450eLjIZko0Y9WI0RGfC2FnPJTgNJ35nZoG0t 5j12QaVqVhSzNF+kqw1zfJZg4qgz817B6PKZtkYMIacPSlmZG037bKr1USig5ckAHA5g h+pG1kCSu6GO/j5C08E+FXaCQqRf+hQNAeNly0WFBCDfjPxsn23yoM05WOJsdDKVvUBj foQA== 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=PGcEaN6KTRtiRqqn4/Wt4ITRkGtYjG84V+vQpOi7+YU=; fh=IfiM2EKDZyid5GkCO7huf92vha/Z8VYlvAsd3R8yV00=; b=AWH2dHEzwISZzO5gvXc/WDogbamnBpI/oNFTK2KxC2uCdsVBlp08oUOI87rmXWPpMl jxM9EZ+8BEjmRmHjD4w9j9hEcCBs7Y7zqAiE0s8eRsQJR2tkuJA3BJwZSZpUspp93HJ1 5f/ab9FmrGfCrRUHzWxSRRbHm6A0PhBHfPrleSnkigjdJvssv4evC2TxM9GYJE2S3RcY Bkd3RtUl8Y+Ad5YhQMRD0KSgp2F/vo6IeC8dKzebGZsqChcf3+CKcpmAi+UXjcFp+v7K xdOQLSY8riTFok6v0xG6q9KzHgeHrJy0Z4Oan59uPiLYycrFv2myjDMokhB2W6w3Mlu0 2lmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oPWbEGHy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-178381-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178381-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 a640c23a62f3a-a5a3e0392c9si420678866b.647.2024.05.14.00.24.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:24:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178381-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=oPWbEGHy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-178381-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178381-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 7C75A1F21B8E for ; Tue, 14 May 2024 07:24:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11E43374E9; Tue, 14 May 2024 07:23:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oPWbEGHy" 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 F135820DD3; Tue, 14 May 2024 07:23:18 +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=1715671399; cv=none; b=ONr/mnZ07AgSYSGuQCsnfD6eZagpdEmsvRBdLBa2TTGgEHqdoe7HdrDY7EqZyYF4Rtw7Jr2eI3aFApcWX4i95uFJpU/O5a8SJBCZPSGO5yXcuoCzz/oSUFbAzkJ3MSUGW2HVPVcQz+l3eXBwoSgB6qq0bXdWQmUC3gvzOgC9QfM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671399; c=relaxed/simple; bh=fijWPI5Ec9mEIeEHh6gbcrhWz9IcjE4n8o8vNnEa8uM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YDPrMBSWsXaRLB/jnBlWAErJLFQDY8l0cafWVAiWgFYP/u41hzvtROnffwnZQNmw0xF0vzVUF088UvBjXS/pjurIQRI/CI79tvHyyz5+Qpm+qmC0sjaXJZb1Z0spmcjLcQ6lciNGl50VJ6DAKCxPUmLGN9rComIy212w1tBYU8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oPWbEGHy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 5CBBCC4AF12; Tue, 14 May 2024 07:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715671398; bh=fijWPI5Ec9mEIeEHh6gbcrhWz9IcjE4n8o8vNnEa8uM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=oPWbEGHyoeP73p0zqQ755sVGAjS+QMEh3EczsCgUZ67D65CkSD1ujiFawo495BlId UFjfv57/PL51MYQiB10gRE4sBWFgkS3msMimaB1+iokNIrqX6a1V2IMsgEbjgH4imf dWBC3eKAmg7zzhD0K1//YwLoxtGbVFmrxWKHQNeDZ38TB09jwtztjXnvLhTIhYqNdX sk3SMtqNbU3mA58wXcuTFbJWydLdoKRgdhEnIL90jPa9n200ZU0AVPu8mOBJNf4T67 vpngU6EONr3X0OccFP11Hpe9zvWYy1OUSk2WiLMZSGGOpdJHtYcIW60WMUv70jtKt2 hyBDTqluc7iGg== 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 495CCC25B78; Tue, 14 May 2024 07:23:18 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Tue, 14 May 2024 10:22:48 +0300 Subject: [PATCH v2 3/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: <20240514-ad4111-v2-3-29be6a55efb5@analog.com> References: <20240514-ad4111-v2-0-29be6a55efb5@analog.com> In-Reply-To: <20240514-ad4111-v2-0-29be6a55efb5@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 X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715671396; l=2349; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=NkOJfDpfW75y+yj/rbukNrI85PrmYYK7YW9pUZT9xYs=; b=1QSxLACQYvSmI8UU/HN9sUKQoXeoAz1ee8CiXOpj8RlV25aQV31ZkXXmhUaf3ToUv+Sj8bl96 krrGPH2nXvGDIPl5vzWnxO1AJvV9aDD9ZsPmsl59Z0VgrPD9KsVcNw7 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 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 850574437bda..d5ad3f01dec7 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -918,7 +918,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); @@ -1013,7 +1029,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]; @@ -1072,16 +1087,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