Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp456364lqe; Sat, 6 Apr 2024 08:04:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnHxuZKjvxwEqMgerti1gskI7AbfnmpV0/KcRazJPTsc0uUGtveRdi2+0OTEMFQ9rbLP5UlROY/0SeUDFDzf4T/KCCBbUzi7rbyLZ28g== X-Google-Smtp-Source: AGHT+IHEJ8uRkPSJTT5KSaXxQ2M2tacOCEKdlz5fcJKmSncnlVUED6unkyrbo82bJQxLvLcqLR5e X-Received: by 2002:a17:90a:ca03:b0:2a2:672f:ef6d with SMTP id x3-20020a17090aca0300b002a2672fef6dmr3215319pjt.49.1712415854187; Sat, 06 Apr 2024 08:04:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712415854; cv=pass; d=google.com; s=arc-20160816; b=DjZ59Yxx3rAB/ceOnopwxXIiKcZwHYq2Qd4mfBcwiYXSU7+Byhk9ATcv9nIF+yghml NlYLnI/2uvGjQqcXBo1wUjDsV10TK9pP4zOnGfpBOn1Wy1mxyzfmvMFeKk/+sMDkt+d+ vQ0ErP5+qYv0Lkx2fTQG1LRrmBi8kMxDq1hRngEqRbtByEH69QRyvhv1OVtJSs3dT0QO aVtGIlRSNLT4SjXHpKOqK+ehsEDIFdwfZn/fpX4u8rnXB9r1DznNqV28eXOuzLjoVg6g enPXFwecmriR/vJIbILNzfB/ElbujjqLwqxH/x7u4YM9AIulRapNaLKr/Qb2UMXwYpjf HNSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=lTikDKdAbFH59YJX35LGqsqdvp9ZrtXncvCIkV0V8pg=; fh=Z1yqB6kQLbNjYjFlAchr83Xu527pXgW6bvteIzypziA=; b=ICEAh1CXwm9ajvesjLXOff5cDiBoZuZnNgoosqQHEWSZy4JH3M0shiNr3GsZpc4W1R W7ZfbhD9bP7dlr441ervVf1tcai3CSm3oh3qBPANwJoLz3/ijEIPA1MhDsT8nt6ysV/g 2bPEJIfM9WbQP1s0Aq7J9w/O1wBzsM5/uBFln+mAXcAvsv4EA9L/N9H5g8pm+YF2Arw/ Sy/QNX7hB7mTWu+9MUt+hr3I/hsPYzi3FbqobeMrQwT42FGHnQMY4muRAJrMZLn9c4+r btb8wHb0ckYC+46y1sX1caWRKQtDWxb7SVMmvPgSdtB8MwAe7jWaMt8jJnYd43mRTd4r xm9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CKXUGwO9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-133963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133963-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i1-20020a17090acf8100b0029b9c61d76esi3232691pju.105.2024.04.06.08.04.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 08:04:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CKXUGwO9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-133963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133963-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 D4007282000 for ; Sat, 6 Apr 2024 15:04:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C912739856; Sat, 6 Apr 2024 15:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CKXUGwO9" 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 E61531CFB9; Sat, 6 Apr 2024 15:04:05 +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=1712415846; cv=none; b=damCFc6IQp+lL/j15s2Tl9CO97jWoLbSWypVUjFoqq4biQlCi1S3eKP42eD9pqvQ61vYmp4arrfJPcGL0+cRuiNTroRiEScnBIXErwRro+00kjyzxxidATgs08lMSVEqFqXOQWMuhzgHZkvJYtJIcDfGk6Q46O06KztQG1Eau+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712415846; c=relaxed/simple; bh=MmwmhbXSkaRYOLQIxgZS7orKIHrXbyGxfV1A4cAr9nI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WeHxrse+L/L6QwCO1ukj5FulMu+C/V6oX3uSp39Xo/lMNUlZQ/s4VMuU7WKEV8+gL6R8FUljuheyP+mlU3dwfAXlcorl4tFgurbBi7nWSTlozFfbrc72qpsn3OmriamGUjLBt0toIjgG2g0/xWF6NsPXvz7B4l5zzbAexH+A464= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CKXUGwO9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C34EDC433F1; Sat, 6 Apr 2024 15:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712415845; bh=MmwmhbXSkaRYOLQIxgZS7orKIHrXbyGxfV1A4cAr9nI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CKXUGwO9CRl2f6/YUmp/d+Aue2N0RLDMIwWxjrZQugnV6lDXzlWlY7h0e5akqAWvh 5fg3G4ZkYU7NjAEC0MFguDziH/AFWSIM+hYqT0yjTBClTW6s/UMa9YrA3jrfIAJfrZ DGBD0V4qATOgjIhGmECcPmH9ZCarAQNLo/qwusuPttjkck2FOWCLOCbNWwO4egnyT5 RSKC8F/FiE9gbm+uS8A1OFmZWFtSOQhHgR3L1D96YJVSsmT2wUJqzPOGGMSN/RbiPn vwUNHs/wcYKQW4KtvbI0NZaVFV9zs9Ep82jH0nQA9KWGxdOcKBLoyqkocHNsuxbj9m pc51UVPr4trdw== Date: Sat, 6 Apr 2024 16:03:50 +0100 From: Jonathan Cameron To: Dumitru Ceclan via B4 Relay Cc: dumitru.ceclan@analog.com, Lars-Peter Clausen , Michael Hennerich , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan Subject: Re: [PATCH 4/6] iio: adc: ad7173: refactor ain and vref selection Message-ID: <20240406160350.751d23ae@jic23-huawei> In-Reply-To: <20240401-ad4111-v1-4-34618a9cc502@analog.com> References: <20240401-ad4111-v1-0-34618a9cc502@analog.com> <20240401-ad4111-v1-4-34618a9cc502@analog.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 01 Apr 2024 18:32:22 +0300 Dumitru Ceclan via B4 Relay wrote: > From: Dumitru Ceclan > > Move validation of analog inputs and reference voltage selection to > separate functions. > > Signed-off-by: Dumitru Ceclan A few line wrapping comments inline. > --- > drivers/iio/adc/ad7173.c | 59 +++++++++++++++++++++++++++++++++--------------- > 1 file changed, 41 insertions(+), 18 deletions(-) > > diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c > index 699bc6970790..bf5a5b384fe2 100644 > --- a/drivers/iio/adc/ad7173.c > +++ b/drivers/iio/adc/ad7173.c > @@ -910,6 +910,41 @@ static int ad7173_register_clk_provider(struct iio_dev *indio_dev) > &st->int_clk_hw); > } > > +static int ad7173_validate_voltage_ain_inputs(struct ad7173_state *st, > + unsigned int ain[2]) > +{ > + struct device *dev = &st->sd.spi->dev; > + > + if (ain[0] >= st->info->num_inputs || > + ain[1] >= st->info->num_inputs) No need to line wrap the above - its under 80 chars on one line with the new reduced indent due to factoring this out. > + return dev_err_probe(dev, -EINVAL, > + "Input pin number out of range for pair (%d %d).\n", > + ain[0], ain[1]); > + > + return 0; > +} > + > +static int ad7173_validate_reference(struct ad7173_state *st, int ref_sel) > +{ > + struct device *dev = &st->sd.spi->dev; > + int ret; > + > + if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF && !st->info->has_int_ref) > + return dev_err_probe(dev, -EINVAL, > + "Internal reference is not available on current model.\n"); > + > + if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) > + return dev_err_probe(dev, -EINVAL, > + "External reference 2 is not available on current model.\n"); > + > + ret = ad7173_get_ref_voltage_milli(st, ref_sel); > + if (ret < 0) > + return dev_err_probe(dev, ret, > + "Cannot use reference %u\n", ref_sel); Can pull the string to previous line and then align ref_sel just after ( whilst still remaining under 80 chars and end up a little prettier. > + > + return 0; > +} > + > static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) > { > struct ad7173_channel *chans_st_arr, *chan_st_priv; > @@ -970,11 +1005,9 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) > if (ret) > return ret; > > - if (ain[0] >= st->info->num_inputs || > - ain[1] >= st->info->num_inputs) > - return dev_err_probe(dev, -EINVAL, > - "Input pin number out of range for pair (%d %d).\n", > - ain[0], ain[1]); > + ret = ad7173_validate_voltage_ain_inputs(st, ain); > + if (ret) > + return ret; > > ret = fwnode_property_match_property_string(child, > "adi,reference-select", > @@ -985,19 +1018,9 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) > else > ref_sel = ret; > > - if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF && > - !st->info->has_int_ref) > - return dev_err_probe(dev, -EINVAL, > - "Internal reference is not available on current model.\n"); > - > - if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) > - return dev_err_probe(dev, -EINVAL, > - "External reference 2 is not available on current model.\n"); > - > - ret = ad7173_get_ref_voltage_milli(st, ref_sel); > - if (ret < 0) > - return dev_err_probe(dev, ret, > - "Cannot use reference %u\n", ref_sel); > + ret = ad7173_validate_reference(st, ref_sel); > + if (ret) > + return ret; > > if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF) > st->adc_mode |= AD7173_ADC_MODE_REF_EN; >