Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1075989lqj; Mon, 3 Jun 2024 09:24:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXF73D5mv0GQEea6BJWGNoQzMSLiIw5Z4aE5TQhPD1Mi4I9BCn5GXKE8MGFgLmota3/S/fTOjU1/Kq7/OorqI+8OCrM1ndOgAQD0dZufw== X-Google-Smtp-Source: AGHT+IFWdP8zY/dN6U22hAvr5bL8AaPWFlseKOSkvSKBusP8Goxb2YF28Eo+KkwjHftlwtNq7paF X-Received: by 2002:a17:902:dac8:b0:1f4:5fe5:74d1 with SMTP id d9443c01a7336-1f636fe8b2amr111815585ad.18.1717431890029; Mon, 03 Jun 2024 09:24:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717431890; cv=pass; d=google.com; s=arc-20160816; b=GX/e9/eGLg5CpXwJwRptac3cw/4O5ZCfjwG0hazSLPXTDdpbCEp9EbLXkx625lfhpk qVabwPxMoldNTwU/rRaoyyFBupLidy608VxC4AddGv6T2xcVmfjkPmqpZLSn8I2WOw2q BOL29mrPHEgssoMCbaRzpp+bNMBo4zT9IJEyXBVnGK5lgWtB6S/uMgwdRwoz0hzMVYlZ +XIHsMXhWUumwLxUe09Ara2S/UIDLwdXYlV2AUWU+u7uKk0dHV6HTaJQ1ji/f3wZd8Z5 HYCVkbE/TDd+xhvP0nSkqxKmk6LDtJIq5Gras76Jd2RgSJZgVNClDF8u9HkLf/HZw4yt aWaw== 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=uRHz/N58Q/UA+Ce+N1Oi803VzjSDNRbsABK+ks+caAWiruvBJbKbuFr+XN6dAfkdk6 cLUYQupKx7Kc7FFYLk4oo7Zf+6SdJ7BG8iyBGCS8bbNVvsd7DApiKbfLH8nvduOlC9sq EFQ7zJUAjz/wmXMB771wqPnMvQu8cDSOGBClyKX6eTC0buAs0B7f3uNoK15ncgabCIvH GsMVzX2NrVouGysrPkJAU0ZqV+zco/bYdzMFq5NGdG3oMbuPIQyUIEywNjFpdcqCHnu8 YKhsrhDmpM/UFtkAJ7UQ3S4ju9FsKME0yKVy9zH4g+2J0d3xeNUmuhCUJVhgtE247kIL BFDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Yzp+MLvz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-199438-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6323de8b2si54473715ad.215.2024.06.03.09.24.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 09:24:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199438-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Yzp+MLvz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-199438-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199438-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AC59928150D for ; Mon, 3 Jun 2024 16:24:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A690E13A244; Mon, 3 Jun 2024 16:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Yzp+MLvz" 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 841BE13667E; Mon, 3 Jun 2024 16:23:14 +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=1717431794; cv=none; b=u5qu1Wd+gMNGmiQl4wijrnbU/uWjCa507dI6CC9L5Tr/eChaxGab8U3GQn41avA7Y0lGdTQgObetYhBf9oC9PrnRv7Ej1D2EdJO5qpHZvHDQeRND5CnSyvzbYFwMF9NKCIZ7gU5apuPhb698TlryQhkiGxyxk1u9s2qWLtk5YYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717431794; c=relaxed/simple; bh=I8QhRMMTY7Sn7kVFggQi6xZH1k/ZS+7ezVgehAwwnKs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bfc0CPVI3aMPyexTNJOp0RJTi5KH6qATPrbjjTLuMXQ0JbPTDcqYUNv5ufgycIXwAKcDivO0t2TUmkofZ5mzWwIaq3qlnfbY/0KVa6r4n3sW0iePEjz0JzFsFW8ceut1pqSvwWvmSBJv0avCIGpIVGO1pgx/CNyJeaXXQUk1b8E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yzp+MLvz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 12A97C4AF10; Mon, 3 Jun 2024 16:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717431794; bh=I8QhRMMTY7Sn7kVFggQi6xZH1k/ZS+7ezVgehAwwnKs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Yzp+MLvz/1+AKuvbZMxjMzYav3rNGSIk9OWgtjwvjMsGeNeaRXv15YZ5PObnEDFvL l+9rC4k4YMKedbTdcHx2dBBjAC10P3AytpPfK1ZiZf0/SolrAzu6Q87jq2cmUdgxEj vPlpM8TFEayt5JePGm4Mlm0pg5TyXOil6kHfREIQ/tYOlxOV3tzPx6qUvMezmOKFS1 3ZaSwr6qlK99VuG86Ejq6FXVT2YEg1D/nC73BcwIs/nFrPbIAiNRuxdCa6G8H+moXR irMpL8PJcCnE2Xz25Tkz8sGRkO+GjigMAAJ7TZyFE+deRCi8jP+2LhMe56Kv1zmFgo 27JE6R1aKroYg== 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 087DEC25B75; Mon, 3 Jun 2024 16:23:14 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Mon, 03 Jun 2024 19:23:02 +0300 Subject: [PATCH v5 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: <20240603-ad4111-v5-4-9a9c54d9ac78@analog.com> References: <20240603-ad4111-v5-0-9a9c54d9ac78@analog.com> In-Reply-To: <20240603-ad4111-v5-0-9a9c54d9ac78@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=1717431792; l=2390; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=Rvmh4+bkvyAlbEsr4U+b9e6sWYI3MMB6i+yP4e+zyrY=; b=A+l8j0a41zaOrEM4XS2ldwdp1GgMMCXdpzf4NGi07wbU7HoISZJbpQOagUhCOXNXR5XY7O2cK 2bTOAsUgvjsBpfX4Jka8QZrY0+UTP4b6DSIKVMm+oCnL/5uw2PIbFVs 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