Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1691202lqa; Mon, 29 Apr 2024 16:49:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXDAeu6BAW4gKnTxe+4KKC5WdddnTNDxDw6W0WIg+h+vwkkirwcBMVRcTtfGS12H2jynSxmr1aTGBUs8IhmDc51kKXJyhMoAOYFLzi/g== X-Google-Smtp-Source: AGHT+IH+0+BxWOq3Dv1THoPoJOdjmzUBrP7FC8rk9JbFxpBNbsCKZG12CzOOp9KWlGiRLy8G2xOY X-Received: by 2002:a17:902:6bca:b0:1ea:201:5843 with SMTP id m10-20020a1709026bca00b001ea02015843mr1280019plt.6.1714434577679; Mon, 29 Apr 2024 16:49:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714434577; cv=pass; d=google.com; s=arc-20160816; b=cktaDsvm2UPiws7UnjqPCCMhNCZeVTRgKx5loPQRflFPl7g+ua4mHUxuu3u90ut3bz rPig6e8Iu7RLWNvTj1XnCC1SvK07QdpmX69Hj3AY/iShwI4AanJQhVsyrmoAGJfgaFIm 4DXPig9WIyGLnfzcY1UMChJBgPJBUauxpTQNNzkY1IQ28PVUbjoBGYIpoGhmMkdN9Mdj XelrARHnrtjijCVlyRD4fSQjnXdLQMly23aRrXZQaal8kiu5I70tJ2S24CmrXn97KHpz Oqc6zPlxHb+Ft3ZcaQG2NXCiQPfjS3A7vm4XTf8u/zGPZVH8gI5F5Uro3NFwznMwD+bY 9M+g== 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 :date:subject:cc:to:from:dkim-signature; bh=cMPnK0ZmMp+orXBCVZaO6rHB522p+A6Oq1x+E+/WEkw=; fh=Nrc+XEWNlwCcaFTgtTIin1AZ9m3Z+de0pPgiznb60D8=; b=vIl4XcRHRqlNjf2cmqCfx12O/6QBRDGYjLod8AM1u3DWzQ+xA6+c3vq4g1A13ruX+6 E2GGXT2XUyh6mLRkq0dFUKDxDNF3up+ymwU8OL1ALMzWFp3iZqL+OCzBww+jbutw/V9k DfpSTw9EKhdh+La7YND5uvEGe21lRPt/E5Bujm6ooxwzAh+Uo3zYwdFe51oQfTKSPMdI szQ5Kx+Ljyhvg+ghtDZVrcEwSGkPoFN8d1NNmBVzkbnNyyw71rjGFWulZIJ+knx6KF/V pJWN4FO6R7XA1125BCbQQVbDUE8PQzcdTZiWdu42wF7rIiyFZ++OU411VSm/MSavIPP8 aH1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=ZMCOsu5f; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-163163-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163163-linux.lists.archive=gmail.com@vger.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 k9-20020a170902760900b001e54743decfsi19693247pll.152.2024.04.29.16.49.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 16:49:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163163-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=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=ZMCOsu5f; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-163163-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163163-linux.lists.archive=gmail.com@vger.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 7A8A0B2386F for ; Mon, 29 Apr 2024 23:42:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07A571A0B1F; Mon, 29 Apr 2024 23:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ZMCOsu5f" Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.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 5E95319DF48 for ; Mon, 29 Apr 2024 23:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714434042; cv=none; b=uZkAfst4M9y2/HHWOBRl/GsEH0z7OKu+80X2iyH84/OPfSVTvxhSg39HnWefExaIM9PMCW0twMvW8adknfOaSUtsrnN5k1i7XYpFxBAcwPLpw0nJHp1tBNmhp+VoUwFG0PfHYSAo3j6Huj21x1HGmb+CDGAh3awhkwYErkU0lQs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714434042; c=relaxed/simple; bh=3hilpxNXGTNYNV/psPrPfqfzf4YMNvFNvehwsbDVqf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YVuY8fsxz9HiZ0HifZzhhvAdYzoMYKM3Ol0ukx+svMENJHkVPugY0TBvSkpWuzKRbS4xJANvk6A7iuWTeWzrEXbvAdMIGKtUn56M34dqvDcJIIjbxb8rJt5x/9jsNOG8l6728fOv84O1ywMCeIKQu15C2i3yJRT7VM3weFAAiWA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=ZMCOsu5f; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5aa2a74c238so3697147eaf.3 for ; Mon, 29 Apr 2024 16:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1714434038; x=1715038838; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cMPnK0ZmMp+orXBCVZaO6rHB522p+A6Oq1x+E+/WEkw=; b=ZMCOsu5f6QifjuBcTkNswzU6fvqPP4XkmOabRxJdPiS+zDnyExIufYLwXOdpirCtYM gD2TVZw31Px3KB/AuKMxwl5RVLLr/QbLSr94jz9fxHV558z++ITEdStCZgv0NXqSO1BY 7fmkysQiz/OoREErE7ojaKN7mlDqhuSaqhhX9PsjTGzWNOKAuPBr5+T8yRc3U67SuFUs 4lU/eg05dyWDqxSyLdb0+TFIetpuLH25q/ipuFFKbP8nmH/LZGDV699Pn89Ch+A64d9M GCf2HYaZa8A75WBI0/k4lDJBQ2Wrl9mDV8SxcFgJy9NVOn/2KfHtkPGCNj2fn06afMkM 0cVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714434038; x=1715038838; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cMPnK0ZmMp+orXBCVZaO6rHB522p+A6Oq1x+E+/WEkw=; b=Fy7vpkWydpwA/ZM5R7bxikehNWGM2Dg6eVXCc0Stxf1pJLkGMeA+CaLJv9P3JZmb2b VuPJUD3lH93zpIA1xfSiBsA9bCBhVzeufq0qdjQsO8GQsAheu+srbkFxY7hJOT+178dv HpFivpVgVIhsYFaHTsJcwXn6poQkNnO6M2CnvPvUmIpnMGuTp99V4wHUl8U6dy/irMRL 9+gTajLc0Ov0kCd8FmMn8VWJyj6kP4hSUxM2V8uYG/h58KmIh0TNbiDvu8f5EWTRBDd+ hsKLUJHEHGkAbrhsieu++WvomRkKDJg1EZSlr7lSVR8G3H2wpVJ8B4wBkDP4jZapt4tV 416A== X-Forwarded-Encrypted: i=1; AJvYcCVXRBz2EpAJfF/nGyk2iv+SJcKUjgCdmIO6LvoQGr4NmGrOBx478NbhcOhGG0rhsngLkwIHSSJTGSgtb4AxTUUNFT50EYz29EKnJIUY X-Gm-Message-State: AOJu0Yw5sIyxrD/uk7aYqfxsYQLP9a5TReR1up6DH8crKzljq7dv/JFF xCu36NlvikQutpjwIGpmPogGxUedGfcYOK0xf4W3A6bwY6lJOmp6/w7ywf9tUFw= X-Received: by 2002:a05:6870:9a1b:b0:23c:9f74:f6d4 with SMTP id fo27-20020a0568709a1b00b0023c9f74f6d4mr1370575oab.52.1714434038300; Mon, 29 Apr 2024 16:40:38 -0700 (PDT) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id hp22-20020a0568709a9600b0023b58aa20afsm2144508oab.25.2024.04.29.16.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 16:40:37 -0700 (PDT) From: David Lechner To: Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Jonathan Cameron , Dmitry Torokhov Cc: David Lechner , Jonathan Corbet , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Antoniu Miclaus , Greg Kroah-Hartman , 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: [PATCH v2 4/7] iio: addac: ad74115: Use devm_regulator_get_enable_read_voltage() Date: Mon, 29 Apr 2024 18:40:12 -0500 Message-ID: <20240429-regulator-get-enable-get-votlage-v2-4-b1f11ab766c1@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240429-regulator-get-enable-get-votlage-v2-0-b1f11ab766c1@baylibre.com> References: <20240429-regulator-get-enable-get-votlage-v2-0-b1f11ab766c1@baylibre.com> 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" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: 8bit We can reduce boilerplate code by using devm_regulator_get_enable_read_voltage(). To maintain backwards compatibility in the case a DT does not provide an avdd-supply, we fall back to calling devm_regulator_get_enable() so that there is no change in user-facing behavior (e.g. dummy regulator will still be in sysfs). Also add an informative error message when we failed to get the voltage and knowing the voltage is required while we are touching this. Signed-off-by: David Lechner --- v2 changes: * renamed to devm_regulator_get_enable_read_voltage() * restored error message on failure * restored validation check in ad74115_setup() and added error message * added fallback call to devm_regulator_get_enable() for compatibility --- drivers/iio/addac/ad74115.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/drivers/iio/addac/ad74115.c b/drivers/iio/addac/ad74115.c index e6bc5eb3788d..12dc43d487b4 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,13 +1671,9 @@ 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; - } + if (val == AD74115_DIN_THRESHOLD_MODE_AVDD && !st->avdd_mv) + return dev_err_probe(dev, -EINVAL, + "AVDD voltage is required for digital input threshold mode AVDD\n"); st->din_threshold_mode = val; @@ -1788,11 +1783,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,20 +1845,20 @@ 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"); - return ret; + ret = devm_regulator_get_enable_read_voltage(dev, "avdd"); + if (ret < 0) { + /* + * Since this is both a power supply and only optionally a + * reference voltage, make sure to enable it even when the + * voltage is not available. + */ + ret = devm_regulator_get_enable(dev, "avdd"); + if (ret) + return dev_err_probe(dev, ret, "failed to enable avdd\n"); + } else { + st->avdd_mv = ret / 1000; } - ret = devm_add_action_or_reset(dev, ad74115_regulator_disable, st->avdd); - if (ret) - return ret; - ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), regulator_names); if (ret) -- 2.43.2