From patchwork Fri Jun 21 22:11:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 546F0C2D0CE for ; Fri, 21 Jun 2024 22:12:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hVRdFKhvRMw+/o8IRTEZqQPsLylWpccjPYBus1uBROU=; b=sHfe+9OIDhL8xiK5y0d3mpgJ77 rQHafIMxVW1jb0P94VePGsV7F3/oO1YiceKyOiTdLYil+QAG3AGJ71yV5J2qSICi8CsVnfhUlJrEs qBK8ID02sqwAx8heKEkjVP8Tl/XHGQWFFKU1zPxtv6UK+WeGEVvvqQH/+KAYNZ3s5jwftd9pUPgxy BCZ1PjQQFBTJk24TTGlGQbBjyuqPK5+HrnKzUaPtD9Yrb+BdJlIuzsAdyHgQJeRFkhPd+sMI/GZ0b gxJYaWHHqzLdj/SiyHANsD8+xZhSwEDtTe/fxtrnZBOTlALGcvDUF67LTxSK8pBTnMPrqmnynA7t4 u1o9FarQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUN-0000000Ai6Z-1SOk; Fri, 21 Jun 2024 22:12:11 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUG-0000000Ai2N-3f6U for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:06 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5b9778bb7c8so1227964eaf.3 for ; Fri, 21 Jun 2024 15:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719007923; x=1719612723; darn=lists.infradead.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=hVRdFKhvRMw+/o8IRTEZqQPsLylWpccjPYBus1uBROU=; b=P5aeaHLY49DnlsdDdlp5+trkV3nvSz339eGSvlGvl9qEqewqOOyzLwmmjn8UzKYGgu HAzHz0vLXQ9xbNw+IRYDlW1E3TP/rATz8rc8Sq4m87A9OsDrliewmFhDleTgaPs/GL96 5k+YIqbqMvOg+sNi5PbO/W+hp3lDQjcL1hs6L9yG9zc89pmDRPtkZ/3o0R7Gv2WxtD+F FB74hpo7jRyHVjuDwh9p3DdQ5MDYcWQUuzfCgHIYOMEhxYegsqGsStrx1+gU2zHNiwfn C4C9E1JO3+sBDrMti8VvhJxxchvjNgAATcFloku3lRaUECrEXrkBN3yTxkYLbw8VRQCt A9Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007923; x=1719612723; 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=hVRdFKhvRMw+/o8IRTEZqQPsLylWpccjPYBus1uBROU=; b=L6IJGWF7cbEfi8h1IJNe9btiuFlgqf5uSlT0oJkOd/urrAaHUUwwjSgp7Wg/typMED YOvzkXdA5nPxhhsJzjdNDfuX4MyrpHX9MarDpREqIfgXT4EpYhryVAsuXRJ7Wf7ktlSS 9kkYDoMIpejkHWhj4zbt4uTiBYjJoNqdHQPdxoHK7WlfSGjhtNL7XNGPtQqvPQ6EHVAy 3v4VB87bnc6KOnieotGpmtpKVnUioWVCrKU2/wEi9AOPsttAdyGPs/4OK7RdY1ZzdiMw w5UfV08XEm4+jR0uNATkE+G0yhKaaVCm2Nj3We+5F+CpYRLvTsivkpptZBug+SkRvfZ7 1/1A== X-Forwarded-Encrypted: i=1; AJvYcCXQBO7o+1Dks377Ru9mEDbgNHNIVFqMOLe2AjBNK7Ko23a2Yo52fStXgVLD1VKQQ2hGmYJbQB6SHj5IvrGzYVIa6gi3KFaPYf+WetmK4iBlKaqT6ic= X-Gm-Message-State: AOJu0YzLwWPA2Gk6iuhvnrG408bl97J6DAlYtcaoimm3fv/WdNUrqATA tthQIQHmJueZI2zOieyBvQFVeZ3XBB/y1CLG3GQxNEtE0SXLjBeJ2y8h2MTGY+c= X-Google-Smtp-Source: AGHT+IEAf590qHVXQF6WIVmoewi4OMSB/t6gCupkb1CE8LPyqCFfpCApy+8JHvS/R19jM823AhGK8A== X-Received: by 2002:a4a:ea0a:0:b0:5c1:b998:a861 with SMTP id 006d021491bc7-5c1b998a905mr8204856eaf.5.1719007923356; Fri, 21 Jun 2024 15:12:03 -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 006d021491bc7-5c1d94fb2a4sm329837eaf.10.2024.06.21.15.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:03 -0700 (PDT) From: David Lechner To: Jonathan Cameron Cc: David Lechner , Joel Stanley , Andrew Jeffery , Liam Girdwood , Mark Brown , Andreas Klinger , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/10] iio: adc: aspeed_adc: use devm_regulator_get_enable_read_voltage() Date: Fri, 21 Jun 2024 17:11:48 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-1-49e50cd0b99a@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240621-iio-regulator-refactor-round-2-v1-0-49e50cd0b99a@baylibre.com> References: <20240621-iio-regulator-refactor-round-2-v1-0-49e50cd0b99a@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_151204_932926_BEC88DB9 X-CRM114-Status: GOOD ( 16.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This makes use of the devm_regulator_get_enable_read_voltage() helper function to simplify the code. The error return is moved closer to the function call to make it easier to follow the logic. And a few blank lines are added for readability. Signed-off-by: David Lechner Reviewed-by: Andrew Jeffery --- drivers/iio/adc/aspeed_adc.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c index 998e8bcc06e1..090416c0d622 100644 --- a/drivers/iio/adc/aspeed_adc.c +++ b/drivers/iio/adc/aspeed_adc.c @@ -108,7 +108,6 @@ struct adc_gain { struct aspeed_adc_data { struct device *dev; const struct aspeed_adc_model_data *model_data; - struct regulator *regulator; void __iomem *base; spinlock_t clk_lock; struct clk_hw *fixed_div_clk; @@ -404,13 +403,6 @@ static void aspeed_adc_power_down(void *data) priv_data->base + ASPEED_REG_ENGINE_CONTROL); } -static void aspeed_adc_reg_disable(void *data) -{ - struct regulator *reg = data; - - regulator_disable(reg); -} - static int aspeed_adc_vref_config(struct iio_dev *indio_dev) { struct aspeed_adc_data *data = iio_priv(indio_dev); @@ -423,18 +415,14 @@ static int aspeed_adc_vref_config(struct iio_dev *indio_dev) } adc_engine_control_reg_val = readl(data->base + ASPEED_REG_ENGINE_CONTROL); - data->regulator = devm_regulator_get_optional(data->dev, "vref"); - if (!IS_ERR(data->regulator)) { - ret = regulator_enable(data->regulator); - if (ret) - return ret; - ret = devm_add_action_or_reset( - data->dev, aspeed_adc_reg_disable, data->regulator); - if (ret) - return ret; - data->vref_mv = regulator_get_voltage(data->regulator); - /* Conversion from uV to mV */ - data->vref_mv /= 1000; + + ret = devm_regulator_get_enable_read_voltage(data->dev, "vref"); + if (ret < 0 && ret != -ENODEV) + return ret; + + if (ret != -ENODEV) { + data->vref_mv = ret / 1000; + if ((data->vref_mv >= 1550) && (data->vref_mv <= 2700)) writel(adc_engine_control_reg_val | FIELD_PREP( @@ -453,8 +441,6 @@ static int aspeed_adc_vref_config(struct iio_dev *indio_dev) return -EOPNOTSUPP; } } else { - if (PTR_ERR(data->regulator) != -ENODEV) - return PTR_ERR(data->regulator); data->vref_mv = 2500000; of_property_read_u32(data->dev->of_node, "aspeed,int-vref-microvolt",