Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp450344lqh; Thu, 28 Mar 2024 07:00:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUFhYmXIkHdWR06QE+S4qi50RPrlIfbNAchTBWn059p17K1UgYgwkqlpIKbtp2qYJqFk2uNXq5KjGWP2BeYf5DAQCW0yeAFxaDnUiSKg== X-Google-Smtp-Source: AGHT+IHq38A8avAb9B/hdp9hbtTQL9wIX0yd3EbO78qIKXd2JgyH5yHy12BDM0qRkmhYkUlkZ8/V X-Received: by 2002:a05:6358:5728:b0:182:1e69:da7 with SMTP id a40-20020a056358572800b001821e690da7mr2434871rwf.31.1711634422864; Thu, 28 Mar 2024 07:00:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711634422; cv=pass; d=google.com; s=arc-20160816; b=pwcwy3FEAMAiV/owpTkeACsfP7VqMGnE94Z74QCmTkSy5IqH6EjBC6OkvsLokOTgN7 5ioRXz4mwkQdGLMSXb1y/G8GrsZy6iY/+/WdSWm6evCyLHoR5pwR1KMoCkh1PkU8qhc5 yOJKTx0xac6ti5eIOHI/MiL2s/KIe4m3DWMtoL4sUiYXVqSOCHNzzNKBtihcaq+N7wRg C1la8mTzL87EzyGf0T0PEEPCpsCHjy34orr0PUKqOoXe1TqXJMX9f60PDgmL/vYuVu/k HsMdgzIflpdOSlJaIQz/r2YzfZ2umjPhy4eJe5rrj1tAdJZ5UMtV8j0fe+emQKMrIvp1 JYfw== 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=ORFfujoMzxKc/SZZiXD3dlrEMhFwe4qQ7pquLUrdQ/k=; fh=NbtzYSGyln1NBy3dwjrRwMhypQlB/UwbJ7oBc05rlIE=; b=lU5IIq2DGwsadWKkj/ENiTnT20Ymc7gfhSAyhq0JqZLF1xVYdcq6YNyxk/DR50I5vD OeycRxTt3AVmp6ibZjf2ECHG52N3T/QARpDi/DQZcLO48eSdjp155Qlp4SNKBqpTC3Iq YtstErXgZtnxnHhJ4/qSUygPvsy3BIZ+8MvPluypw9uw9sMZu3WvTvyjQd5X7tBU2ps/ o3vQbe6Dy0z7iJaevifc/Ok0Mnl1YxUHBmwP8N/mvMR5+tFMgpKgTrPcQK+2OYaxpdTA cLQIOvwxej/FIgGDMb6avO6KyTyRaUiFLAT5M2s9YWinm/8LMwkBXmSXrVvh2pZsNk3z N/9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ijk/u6/e"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123008-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id by6-20020a056a02058600b005f057f3d721si1671798pgb.789.2024.03.28.07.00.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 07:00:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ijk/u6/e"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123008-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E323BB23A85 for ; Thu, 28 Mar 2024 13:58:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C53C481AC1; Thu, 28 Mar 2024 13:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ijk/u6/e" 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 DD95D847C; Thu, 28 Mar 2024 13:58:27 +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=1711634308; cv=none; b=f92cR0R/7LZCJcpp3EeTVIzjSlAfuCWBiMPNWPkrOi9OGuNI1uwoeNEs0+7gzf74HG19QQ/J5Hb4pzuXjTW157KJImFqYAbPSvGtVquvKTU4JO4YzMbExC2kMxgTk6QRWlYwPAPfGD0UeYNeMXWvqws0NT9Nmy3KgBMGVHWNlYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711634308; c=relaxed/simple; bh=bI2xEoV9PU+GOHtJWeJ4LDOmjUoV6Fg9c+kVebNAsUo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Pyqw8PJrNwD5n+wFoKn2j8KyNP0IYuXcWl9HoI7fBrMibYJvhul3TiLiN+q8ddHEswV3uoxd9DZ/z9vEgf6MUOidQb192tgxJlWbNK2cIX+ZpU4pxH3bPRIjKGyVFgUfVWxiW28jlaF3hstwb9DLRKVYpMLMjyIIh9VBb4BCP30= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ijk/u6/e; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF513C433C7; Thu, 28 Mar 2024 13:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711634307; bh=bI2xEoV9PU+GOHtJWeJ4LDOmjUoV6Fg9c+kVebNAsUo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ijk/u6/eIMs0lJPAUjxbsR8WiYAYiZVl1UkN1qf+SvK29HyDnofHeu6+55lPtof+t sUFuhEnV8CCDhb5a4PAh7lrPKW7HKjsUMo1lGUrKAel7cu3vKppeHMf84JQx6cI1KG l3NIX4jVBSWljSlAzrdcskx2mC4ZlrtXRq7pZGvfbU9IeFjoHf6e7vEknJH3zCOVqW YlFjMye65+sZbqjb161UUfvWQZtFZqy4dQpJD6Z5qcz5Wty5wqkaNcqcVEQG6wgLY0 QH4btS1yAf/GCJr44H857zWNTPOcpX6IyS/dxm1TQok+PchHzVM9dNTXLW828yPNlU nORfpvBzYSquw== Date: Thu, 28 Mar 2024 13:58:08 +0000 From: Jonathan Cameron To: David Lechner Cc: Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: Re: [PATCH RFC 4/7] iio: addac: ad74115: Use devm_regulator_get_enable_get_voltage() Message-ID: <20240328135808.7aff4fb5@jic23-huawei> In-Reply-To: <20240327-regulator-get-enable-get-votlage-v1-4-5f4517faa059@baylibre.com> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> <20240327-regulator-get-enable-get-votlage-v1-4-5f4517faa059@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 Wed, 27 Mar 2024 18:18:53 -0500 David Lechner wrote: > We can reduce boilerplate code by using > devm_regulator_get_enable_get_voltage(). There is a change in behaviour in this one. I'd like some explanation in the patch title for why it is always safe to get the voltage of avdd_mv when previously it wasn't. There seems to me to be a corner case where a DTS is not providing the entry because it's always powered on so we get a stub regulator but that doesn't matter because we aren't in DIN_THRESHOLD_MOD_AVDD. After this change that dts is broken as now we read the voltage whatever. You could use the optional form and then fail the probe if in a mode where the value will be used? > > Signed-off-by: David Lechner > --- > drivers/iio/addac/ad74115.c | 28 +++------------------------- > 1 file changed, 3 insertions(+), 25 deletions(-) > > diff --git a/drivers/iio/addac/ad74115.c b/drivers/iio/addac/ad74115.c > index e6bc5eb3788d..01073d7de6aa 100644 > --- a/drivers/iio/addac/ad74115.c > +++ b/drivers/iio/addac/ad74115.c > @@ -199,7 +199,6 @@ struct ad74115_state { > struct spi_device *spi; > struct regmap *regmap; > struct iio_trigger *trig; > - struct regulator *avdd; > > /* > * Synchronize consecutive operations when doing a one-shot > @@ -1672,14 +1671,6 @@ static int ad74115_setup(struct iio_dev *indio_dev) > if (ret) > return ret; > > - if (val == AD74115_DIN_THRESHOLD_MODE_AVDD) { > - ret = regulator_get_voltage(st->avdd); > - if (ret < 0) > - return ret; > - > - st->avdd_mv = ret / 1000; > - } > - > st->din_threshold_mode = val; > > ret = ad74115_apply_fw_prop(st, &ad74115_dac_bipolar_fw_prop, &val); > @@ -1788,11 +1779,6 @@ static int ad74115_reset(struct ad74115_state *st) > return 0; > } > > -static void ad74115_regulator_disable(void *data) > -{ > - regulator_disable(data); > -} > - > static int ad74115_setup_trigger(struct iio_dev *indio_dev) > { > struct ad74115_state *st = iio_priv(indio_dev); > @@ -1855,19 +1841,11 @@ static int ad74115_probe(struct spi_device *spi) > indio_dev->modes = INDIO_DIRECT_MODE; > indio_dev->info = &ad74115_info; > > - st->avdd = devm_regulator_get(dev, "avdd"); > - if (IS_ERR(st->avdd)) > - return PTR_ERR(st->avdd); > - > - ret = regulator_enable(st->avdd); > - if (ret) { > - dev_err(dev, "Failed to enable avdd regulator\n"); > + ret = devm_regulator_get_enable_get_voltage(dev, "avdd"); > + if (ret < 0) > return ret; > - } > > - ret = devm_add_action_or_reset(dev, ad74115_regulator_disable, st->avdd); > - if (ret) > - return ret; > + st->avdd_mv = ret / 1000; > > ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), > regulator_names); >