Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1085556lqj; Mon, 3 Jun 2024 09:40:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUE4lZ5G/jp3xijE6zj75JmSIli6buDbKDm05J/087IhdL7pA4cXTV0Qo76+icL4fMMZPbBA8gnTl0SsPEghosUuWSu0RRKR1gQb3jsKA== X-Google-Smtp-Source: AGHT+IFiyEr4nL2dGLCwR3N8Hr+aubySrsg5/MWfnQeuJutFzQeA2Er3hkFt8ezFuU1U2AXTpm04 X-Received: by 2002:a9d:69cc:0:b0:6f0:e8a9:9143 with SMTP id 46e09a7af769-6f911f23043mr9697594a34.4.1717432801840; Mon, 03 Jun 2024 09:40:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717432801; cv=pass; d=google.com; s=arc-20160816; b=Hoq46WlNRqoEzndmDAANr8d2yDAb94O0q5+e4DoG5RNFseIx1FjFl68wFNZgSIQxnp 34vsgqI8rDHADRVNa1XUdM3OhkVj5cpkCHyF0Hkd310/P7TxpN1VPjV1KiRPmEUno7ng BTiCUovDeD60sZCWgxETQP7WbrrAhBCxgKUz78/G0LWlrTnoDk6/2lVw8+3Bi0f4RbM5 4J6TT5OP5j9rN12fXANBaMnTCkVMjEtrP3jsX+GNOvMvnxJMBjONy/J342QhUi9zy5vR AUVeeY7dqpMkasLDxbRBbBI1fQIXUalVtI2x0hFfN9zxQld4g8CuK4AM/PycXXslGa8o 6/bw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=NmucZefJaS9oSAR+UXzx3NPh83JYXnJgaWeSAXKZsFg=; fh=yquV9LZrpf0t7QX8ndxybs7jEcThmlu+DoXawgzATWY=; b=b4FG13vC8MohlgUmbQMjX/Yx9ZjzPQSJKRPRQxdeb13YvEqkqQehjoQN/MTJzLXM2h UN/rMOP+YCJ5ACPn5RPE4PyhHLR+7RwKviebJixLt1tGdwiPCKbxyMQp81mXjIh7hTMf iujad3ZL7Z7Uqy30hFE5xPEq9K9mWNdCRhOTt2Do13pOeAEkHrO7AtRk7r1pjjkfcoFY uO9X5GW3ST7ctpYdeOc/U3ui7Hv8y5iEbmLq0oROib6h2/YE5QJEQic2skox446dbCgN cUhPQkm+kcqr1LBBAV32bEQP4N7aPj22rWFW7OwL5hCviTdytAsTfzJ0MYN8Hpa5pw88 uT7g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F+nZAGOD; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-199455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43ff259e2a8si83791401cf.660.2024.06.03.09.40.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 09:40:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F+nZAGOD; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-199455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7C3441C217B9 for ; Mon, 3 Jun 2024 16:40:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3AF91369A1; Mon, 3 Jun 2024 16:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F+nZAGOD" Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0052B7E8; Mon, 3 Jun 2024 16:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717432792; cv=none; b=tjfqosIEUNuf8mMR6OxWy5k5lKEHawc4O9hZ1ReXzM8Eq+zCMaTpQbJhzIK6TBEkCZt4Jnz27D7qq6TDVK3Q3XB//Hpi7qZcrrQCOY4586rxgCW0jfz3JVck1nyD37ga4H6eVA7NdsGwF7CZqjxJ7pjU8+jm2EbdSpAJMUtY2ko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717432792; c=relaxed/simple; bh=rnR5iPB01lsns52vG/tA2Gfh3HK2RdIOyDH7P6NAYdU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pIZ6bRUZLARwp4N/iN12xD68atgD/Xhiue0w1JPLPa0daXUgR2HU/qhOjHevepAVG6synkl678CaSONQnuYXFOW4rfyz29+I8OdmnfvTT5RdmqC+nrf6X9U78m2Jujvbqo/tJExVmwkZbPcHP69e3HkfYALz2yTMQFT5ks5D7j8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F+nZAGOD; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4214053918aso263935e9.2; Mon, 03 Jun 2024 09:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717432789; x=1718037589; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=NmucZefJaS9oSAR+UXzx3NPh83JYXnJgaWeSAXKZsFg=; b=F+nZAGODw+dZ4N83cBoS4/Kz/rB4mJNKsiH6/YAJk4uhn+ORGGb6281YlTdb33S++i ioie4XX2Dyi2B19WAZDHKucliax/JM/tsUSQAds4lDNxnVkwrBYftdYDpbKOd9ZrXUiP IgayVKv3aJmyxHPpLa8msZ5iLAXI7QxMEWH2hP1w807ArI7vGChm1emT0sSJxeiLw5LW sAhAW2LtRJrPEdFmhhmioklUYvkEGGogbA34zRzZwEiMNyYu6GqM0+UgoUyzWJcp6Wvt rWOjKT9spjf9mbYjTmYIttra5L6ME9Q8xvxGdawiSF7LyOGcUxsCB414SmbDISuESjJe VJeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717432789; x=1718037589; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NmucZefJaS9oSAR+UXzx3NPh83JYXnJgaWeSAXKZsFg=; b=HvYGYJMdlo8jP0SKAarQEMNSg/42iWojNaCtkLI/lVDrn2kiDXnTxv0A9Y5uW8wYMf tA8WygIlrqBTa9SAlNv1uhm9nhRzxHoiQDz1RgdhFIMJzg5h/hwCMrcxjcR30corZMOj Db3mzBUr2ps7wMzdTrRvN51bWCgqB7waXnvaniiS86+A/561pvXYF0kU0kqB9m6o6Y7m 5sKHnbzjKfx29TD6/R41456v+oSWWASsMaGYMdMLp7l3hyFI2J7bwPs2Soyh8X70X+H/ bXjq5yZYglpeC5tlhOPr3nwAj+e6J7fPLD+vFya1qUS6+2MemGI/D/UjXtDRxj/joAjK atHQ== X-Forwarded-Encrypted: i=1; AJvYcCUndehoYcLG/SfGYbyzNSjXKt5QYmhgaObTIwOPtzq5wl5ObYpi2w/P5bwgvmNcGVQCPZwSQ3wwq3Hva73Lj7+pXKnXAKnZJ4sq7Wf9BjE+Q0shrvj6v+qX+mUXFsKKdAdSTBwMmzNpPc7iUWajLw4QfG+PLkaFc6moQ12gCsBsgpGP0w== X-Gm-Message-State: AOJu0Ywnbpo8gZzjCRVB6CT77kozyWnU60HNVy2nMrr46s80aa3EG6g7 FqFFGr4k+KPBn6pU+so5STAzjtaW/xe52Qw3roZLUbTV5z04coJ2 X-Received: by 2002:a05:600c:4f13:b0:421:418d:8f7 with SMTP id 5b1f17b1804b1-421418d0be6mr10237555e9.12.1717432788875; Mon, 03 Jun 2024 09:39:48 -0700 (PDT) Received: from [192.168.242.235] ([109.166.154.147]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd04c0e8fsm9168075f8f.2.2024.06.03.09.39.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 Jun 2024 09:39:48 -0700 (PDT) Message-ID: <64fd8918-0c5e-462d-8ffe-964ed6404bde@gmail.com> Date: Mon, 3 Jun 2024 19:39:46 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 3/6] iio: adc: ad7173: refactor ain and vref selection To: David Lechner , =?UTF-8?Q?Nuno_S=C3=A1?= , Jonathan Cameron , Dumitru Ceclan via B4 Relay Cc: dumitru.ceclan@analog.com, Lars-Peter Clausen , Michael Hennerich , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240531-ad4111-v4-0-64607301c057@analog.com> <20240531-ad4111-v4-3-64607301c057@analog.com> <20240601194925.23123071@jic23-huawei> <2df46968-ff5f-43bc-98fd-506840c1aaa9@baylibre.com> Content-Language: en-US From: "Ceclan, Dumitru" In-Reply-To: <2df46968-ff5f-43bc-98fd-506840c1aaa9@baylibre.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 03/06/2024 19:00, David Lechner wrote: > On 6/3/24 8:08 AM, Ceclan, Dumitru wrote: >> On 03/06/2024 16:00, Nuno Sá wrote: >>> On Sat, 2024-06-01 at 19:49 +0100, Jonathan Cameron wrote: >>>> On Fri, 31 May 2024 22:42:29 +0300 >>>> Dumitru Ceclan via B4 Relay wrote: >>>> >>>>> From: Dumitru Ceclan >>>>> >>>>> Move validation of analog inputs and reference voltage selection to >>>>> separate functions to reduce the size of the channel config parsing >>>>> function and improve readability. >>>>> Add defines for the number of analog inputs in a channel. >>>>> >>>>> Reviewed-by: David Lechner >>>>> Signed-off-by: Dumitru Ceclan >>>>> --- >>>>>  drivers/iio/adc/ad7173.c | 71 ++++++++++++++++++++++++++++++++++-------------- >>>>>  1 file changed, 50 insertions(+), 21 deletions(-) >>>>> >>>>> diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c >>>>> index 6e249628bc64..a20831d99aa5 100644 >>>>> --- a/drivers/iio/adc/ad7173.c >>>>> +++ b/drivers/iio/adc/ad7173.c >>>>> @@ -60,6 +60,7 @@ >>>>>  #define AD7173_CH_SETUP_AINPOS_MASK GENMASK(9, 5) >>>>>  #define AD7173_CH_SETUP_AINNEG_MASK GENMASK(4, 0) >>>>>   >>>>> +#define AD7173_NO_AINS_PER_CHANNEL 2 >>>>>  #define AD7173_CH_ADDRESS(pos, neg) \ >>>>>   (FIELD_PREP(AD7173_CH_SETUP_AINPOS_MASK, pos) | \ >>>>>   FIELD_PREP(AD7173_CH_SETUP_AINNEG_MASK, neg)) >>>>> @@ -623,6 +624,7 @@ static int ad7173_setup(struct iio_dev *indio_dev) >>>>>  static unsigned int ad7173_get_ref_voltage_milli(struct ad7173_state *st, >>>>>   u8 reference_select) >>>>>  { >>>>> + struct device *dev = &st->sd.spi->dev; >>>>>   int vref; >>>>>   >>>>>   switch (reference_select) { >>>>> @@ -646,9 +648,11 @@ static unsigned int ad7173_get_ref_voltage_milli(struct >>>>> ad7173_state *st, >>>>>   return -EINVAL; >>>>>   } >>>>>   >>>>> - if (vref < 0) >>>>> + if (vref < 0) { >>>>> + dev_err(dev, "Cannot use reference %u. Error:%d\n", >>>>> + reference_select, vref); >>>>>   return vref; >>>>> - >>>>> + } >>>>>   return vref / (MICRO / MILLI); >>>>>  } >>>>>   >>>>> @@ -905,13 +909,50 @@ 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, >>>>> +       const unsigned int >>>>> ain[AD7173_NO_AINS_PER_CHANNEL]) >>>> I was late to the game in replying to previous thread. >>>> >>>> This is neater without the loop and with 2 parameters.  Anyhow see reply to v3. >>>> >>> >>> Yeps, even more given that we're passing/copying the complete array which always >>> fells awkward to me :) >>> >>> - Nuno Sá >>> >>> >> >> I rewrote the function, but it feels a bit awkward, perhaps I could get a bit of >> advice before sending V5: > > Maybe we could make this easier to read with macros? > >> >> static int ad7173_validate_voltage_ain_inputs(struct ad7173_state *st, >> unsigned int ain0, unsigned int ain1) >> { >> struct device *dev = &st->sd.spi->dev; >> bool special_input0, special_input1; >> >> special_input0 = ain0 == AD7173_AIN_REF_POS || ain0 == AD7173_AIN_REF_NEG || >> ((ain0 == AD7173_AIN_COM_IN_POS || ain0 == AD7173_AIN_COM_IN_NEG) && >> (st->info->has_common_input)) || ain0 == AD4111_VINCOM_INPUT; >> special_input1 = (ain1 == AD7173_AIN_REF_POS || ain1 == AD7173_AIN_REF_NEG) || >> ((ain1 == AD7173_AIN_COM_IN_POS || ain1 == AD7173_AIN_COM_IN_NEG) && >> (st->info->has_common_input)) || ain1 == AD4111_VINCOM_INPUT; >> > > special_input0 = AD7173_IS_SPECIAL_INPUT(ain0); > special_input1 = AD7173_IS_SPECIAL_INPUT(ain1); > >> if (st->info->has_vincom_input) { >> if (ain0 == AD4111_VINCOM_INPUT && >> ain1 < st->info->num_voltage_in && /* Normal input */ >> ain1 >= st->info->num_voltage_in_div) /* Input without divider */ >> return dev_err_probe(dev, -EINVAL, >> "VINCOM must be paired with inputs having divider.\n"); >> >> if (ain1 == AD4111_VINCOM_INPUT && >> ain0 < st->info->num_voltage_in && /* Normal input */ >> ain0 >= st->info->num_voltage_in_div) /* Input without divider */ >> return dev_err_probe(dev, -EINVAL, >> "VINCOM must be paired with inputs having divider.\n"); > > if (AD7173_IS_VINCOM_MISMATCH(ain0, ain1) || > AD7173_IS_VINCOM_MISMATCH(ain1, ain0)) { > return dev_err_probe(dev, -EINVAL, > "VINCOM must be paired with inputs having divider.\n"); > >> } >> >> if ((ain0 >= st->info->num_voltage_in && !special_input0) || >> (ain1 >= st->info->num_voltage_in && !special_input1)) >> return dev_err_probe(dev, -EINVAL, >> "Input pin number out of range for pair (%d %d).\n", >> ain0, ain1); >> >> if (!special_input0 && !special_input1 && >> ((ain0 >= st->info->num_voltage_in_div) != >> (ain1 >= st->info->num_voltage_in_div))) >> return dev_err_probe(dev, -EINVAL, >> "Both inputs must either have a voltage divider or not have: (%d %d).\n", >> ain0, ain1); > > These last two don't seem so bad. > >> Thanks for the quick review :)