Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2158587lqp; Sun, 24 Mar 2024 06:02:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXW1J4XnOth3lNnzbeSGPtWaXHnVWiJ6l2+GwUd7JmRlmG6MV/AuP8VbhgqjSkqdz5VQYFETCaaxR4he/maipuY42TJ9jZhuDGilrgg8A== X-Google-Smtp-Source: AGHT+IG1hsQHsTtqs5mg81GH8DZLrAnnM606rtdxF0j8Uc7aV+y4bFNT6YmG2ANYRyLqc6dU3QNR X-Received: by 2002:a05:6a00:21d1:b0:6ea:6e72:eae8 with SMTP id t17-20020a056a0021d100b006ea6e72eae8mr4542649pfj.16.1711285322076; Sun, 24 Mar 2024 06:02:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711285322; cv=pass; d=google.com; s=arc-20160816; b=PTvdW7bj/f/4sACa3IgficmI/7tunkwK4BQ+K7BEjURP6T5a8gYlHSucI+WL6DiEsG heD8Wv7AEQKHP7gU5Qm8eZtcsR6qkbz2zvOSAHHAEffTGkccTr4ZAHaB2HX0bUdCqBSS Br6FJF/frQ8z+hJ1pKC39ZlnXq32B0bw0SXAOTdEqWaNRJwEh6InzRpZMrAmqQFXhQK8 zlj6guJs8EiTsmIDnyPOKnLbUoVXtMHL5iaR1nziPRijk4aWPRdcCuHX5TkbSul7EXIv tGFB3hefn2VKsLyhI2KSy2N5okQ9Cq1tVz6aMFmJnWP25ba9qcjnBADjSzFHaRqxYLiY IXGg== 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=ca+RZnfv2VvUREWls/DtcLaNbb6Oi4gYmIUih7i0VNs=; fh=MyNZIgpx1MSNRB2sApNtUWYmWkOO0A8hUBu4tnLlvBw=; b=lmPR7n4y3dYsX1MTG3JnkA10/6KwKlIfta2YfUvSUchDS86AxV0ktf/Dc6JkPBfU6H H7IO6f926dkmlvakIoid+yN/7nUMkyMNWEFbeMBCldfkXtlHXakNNmQX4AScKjLgYzyK u/uYcOo3nh1Kfx9iqGnjRO4OdPeAwdA4nvy/N6OVUu83aecCb8eGl8s6fg/VY0On+3Il Z+OLvE5XxRw5qFTjHKdQxhjoMqCLSSFKi9t6UYpEuGwF7119HYjNn/KAX+LsMvSZTQEC x7kQiV35Yjmo1kXy8FKSYAFTOSVxzFUevuT320FhWA+MW1qn2nbLQpmVIFuyQlIhDFzj mo3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XAenF61w; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112673-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112673-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 x20-20020a63fe54000000b005dc3d92a492si5537593pgj.39.2024.03.24.06.02.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 06:02:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112673-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=XAenF61w; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112673-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112673-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 149F728193A for ; Sun, 24 Mar 2024 13:02:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F69D17BCC; Sun, 24 Mar 2024 13:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XAenF61w" 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 A5C6C1A38DA; Sun, 24 Mar 2024 13:01:53 +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=1711285313; cv=none; b=MJOHoFLSWyfucB2rDMBgrF7detu50R6nIatHihWi61SR99+39zj35zvisSL+ZnrSIssDyWUjxCuyBMgkVPoBxCK1yRtseYPMTKhzQmeMfQ11VMSfAWgJrX3xXOuQl7vXCWcnX9j+5XPdKy6du6SJXUBsq284dkKlX/Bs+uvUzlY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711285313; c=relaxed/simple; bh=q85Z68QUuaGnDqPVcMzjbmMb/Yg73VYqgOuyBPn6h+g=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=szVqdz48piIvhm8ZneMmuwFIQRPFEvr/JThNFssA1RxbGRpnmIuOqIBtM6ussTGeJdpsGQ034nLVg5CDt2mKIsRKl8WE2GqDpiNgxqv7cAxLAaUKMZnGbOcZNK4zufRoNjXQIUS9GvA0YbJz3WbCLm9bI6BNI+WhTgjvUQKO5sg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XAenF61w; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44B53C433F1; Sun, 24 Mar 2024 13:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711285313; bh=q85Z68QUuaGnDqPVcMzjbmMb/Yg73VYqgOuyBPn6h+g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XAenF61wMVickWh1iv7exmJKA2JogTz84kcDk03KRDye2GusVxakfzWf5UwTwtNiB xwpnfP74uH0EXRULk0klKj3PTusSXg1dewC7zvlUhd8hah7vDMCgSGA5raZeU2jWNT NbW+bzXkhCKqrAlp1gKKz0sKvencOsEJjFnLJ/FRKShd4ZnR8n7FbkFJOeesVaLIu5 LbEEFDVkAOORS11GzpG4TejUD2wRNpT4YFyxqSh9y850TWEuo10hO1dlMjKoPxcisT iGoj981B+wGGZXcxGXScLMP3culVmaQOi+agpo43WpM+RFrz0uQwvp9+1VsN9GJcu0 sTYbfQhauo6fg== Date: Sun, 24 Mar 2024 13:01:35 +0000 From: Jonathan Cameron To: Julien Stephan Cc: Lars-Peter Clausen , Michael Hennerich , Nuno =?UTF-8?B?U8Oh?= , David Lechner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Subject: Re: [PATCH v5 4/7] iio: adc: ad7380: add support for pseudo-differential parts Message-ID: <20240324130135.35f4b0eb@jic23-huawei> In-Reply-To: <20240319-adding-new-ad738x-driver-v5-4-ce7df004ceb3@baylibre.com> References: <20240319-adding-new-ad738x-driver-v5-0-ce7df004ceb3@baylibre.com> <20240319-adding-new-ad738x-driver-v5-4-ce7df004ceb3@baylibre.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 Tue, 19 Mar 2024 11:11:25 +0100 Julien Stephan wrote: > From: David Lechner > > Add support for AD7383, AD7384 pseudo-differential compatible parts. > Pseudo differential parts require common mode voltage supplies so add > the support for them and add the support of IIO_CHAN_INFO_OFFSET to > retrieve the offset > > Signed-off-by: David Lechner > Signed-off-by: Julien Stephan Hi Julien, A few aditional comments inline. The one about optional regulators may be something others disagree with. Mark, perhaps you have time to comment. Is this usage of devm_regulator_get_optional() to check a real regulator is supplied (as we are going to get the voltage) sensible? Feels wrong given the regulator is the exact opposite of optional. Jonathan > struct ad7380_state { > const struct ad7380_chip_info *chip_info; > struct spi_device *spi; > struct regmap *regmap; > unsigned int vref_mv; > + unsigned int vcm_mv[2]; > /* > * DMA (thus cache coherency maintenance) requires the > * transfer buffers to live in their own cache lines. > @@ -304,6 +333,11 @@ static int ad7380_read_raw(struct iio_dev *indio_dev, > *val2 = chan->scan_type.realbits; > > return IIO_VAL_FRACTIONAL_LOG2; > + case IIO_CHAN_INFO_OFFSET: > + *val = st->vcm_mv[chan->channel] * (1 << chan->scan_type.realbits) > + / st->vref_mv; So this maths seems to be right to me, but it took me a while to figure it out. Perhaps a comment would help along the lines of this is transforming (raw * scale) + vcm_mv to (raw + vcm_mv / scale) * scale as IIO ABI says offset is applied before scale. > + > + return IIO_VAL_INT; > } > > return -EINVAL; > @@ -350,7 +384,7 @@ static int ad7380_probe(struct spi_device *spi) > struct iio_dev *indio_dev; > struct ad7380_state *st; > struct regulator *vref; > - int ret; > + int ret, i; > > indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); > if (!indio_dev) > @@ -394,6 +428,40 @@ static int ad7380_probe(struct spi_device *spi) > st->vref_mv = AD7380_INTERNAL_REF_MV; > } > > + if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv)) > + return dev_err_probe(&spi->dev, -EINVAL, > + "invalid number of VCM supplies\n"); > + > + /* > + * pseudo-differential chips have common mode supplies for the negative > + * input pin. > + */ > + for (i = 0; i < st->chip_info->num_vcm_supplies; i++) { > + struct regulator *vcm; > + > + vcm = devm_regulator_get_optional(&spi->dev, Why optional? > + st->chip_info->vcm_supplies[i]); > + if (IS_ERR(vcm)) This will fail if it's not there, so I'm guessing you are using this to avoid getting to the regulator_get_voltage? If it's not present I'd rely on that failing rather than the confusing handling here. When the read of voltage wasn't in probe this would have resulted in a problem much later than initial setup, now it is, we are just pushing it down a few lines. Arguably we could have a devm_regulator_get_not_dummy() that had same implementation to as get_optional() but whilst it's called that I think it's confusing to use like this. > + return dev_err_probe(&spi->dev, PTR_ERR(vcm), > + "Failed to get %s regulator\n", > + st->chip_info->vcm_supplies[i]); > + > + ret = regulator_enable(vcm); > + if (ret) > + return ret; > + > + ret = devm_add_action_or_reset(&spi->dev, > + ad7380_regulator_disable, vcm); > + if (ret) > + return ret; > + > + ret = regulator_get_voltage(vcm); I'd let this fail if we have a dummy regulator. > + if (ret < 0) > + return ret; > + > + st->vcm_mv[i] = ret / 1000; > + } > +