From patchwork Fri Jun 21 22:11:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708125 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 E5F14C2BBCA for ; Fri, 21 Jun 2024 22:13:00 +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=UPjR6392Ufeq3m10Ix6LPhMsFgNag95fnEsJNBcmUuQ=; b=wQ3pw1ILrlS3OB+K2MLeZF0x0P gCiMHXbP1X4apDgKKFyc23Jh/jysKlaplckMkqjOqQQcxQmK6CW6l6JvHMiGg8xmvxO6ZEs+k3dwT AVpAg4OTVHtwAD+IR7aqrgy9GGfsWSqXDcvVTpFlkKLBCTnfnopwKTPI4qm4viUpLCGlZnRBJTTjW B33m9wjudX9NXBi+WZFntkZkkvfD7djA5Zdy2kP5LeCUFUX8sZLJdCcKgVJjL7diBpaiTDX1T4Jiu eW4T7u3bSWh95rHjxUI/uWAJ6O/u+HSzsh8Jrnd6hFgzH8Rf4DcftYbnp/HIyJzOL8Yw4YfqGjzug Ie2toMlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUv-0000000AiYi-2G0M; Fri, 21 Jun 2024 22:12:45 +0000 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUO-0000000Ai77-0H1w for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:13 +0000 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5c1b27e0a34so1177581eaf.2 for ; Fri, 21 Jun 2024 15:12:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719007931; x=1719612731; 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=UPjR6392Ufeq3m10Ix6LPhMsFgNag95fnEsJNBcmUuQ=; b=vSmC98HhPxhVSsNzsH1yBTZSqgXOVS/cRBFVjLdPSTKMJI2XM6YxBbQBPOpeKWOBpL 8q8cdU7Udd3kJRDSHZr6t3z1rfsjgdb0q/3UnZZK0VsPKy9armUQ2UJBfe8WuwH+6rOl KIM6JIW40KBOyczQjn4guNbQcq8vrI0/VynIXZFxPw4wZkZIRfjUupblYnLMB3Hp8bQW mCHD0+KkAhLNC0NEW2Fmw15OPurGSauP9Wj1Shh+G5+eWJGN8+9mF1/2DJXXMuXDyGRs ajua3YPBO1NlSdiTVF85VLJmXrOhVzBodya3Csm3phGF4E4L1s6OhCpEj3O//WQF515E E5Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007931; x=1719612731; 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=UPjR6392Ufeq3m10Ix6LPhMsFgNag95fnEsJNBcmUuQ=; b=iO/DQQ8GMaTHKk2lPtGYPY+o/3MLOCWNEnQ8RB4pkCMVg33iQHroE7ExaiYM8Qfcrl u/L5wSOeQo2Rz2dic5DEn56gj7ae5yI30CaHWba2rVgZ1tYwc6owJWKXPuwGJX0z5oEy rtDtPGxZj/7m4aogMXazASgfqGNSWdwtMVDxNXo2IXC0LuZF+4BchvyJ+oFzyhZG4FZY L0tEPnPjbwYuaLIwzGENZrGuoh15hFOcEpnN4D8SWeKU6aiKGs8GyTgcJNsmQ2CNSTXx BY1YfqIqD4nV6tVaL41CvZAc1nAsW4lzT7fjhyhW+RuDQITDmqjG1iUpG3kEeMXnehSQ HQHg== X-Forwarded-Encrypted: i=1; AJvYcCXWR9HDJxeFEseXae7XdJ7LNpNGy5PyW9jP2HQg5x7QH3S4uChLc3kghxl34+iTDSyuwMmYLMKPHx4r3Pq68QNjJuRrhFH/82uhjulV0t/ae80Jmuk= X-Gm-Message-State: AOJu0YwZuA5i6S+h64ocehsv/eoRfUQqfvfJkHEbZsLiEDVX/g7PAyyx Vl6hmta/xqAC5DpCKMLPBn6MHfo6jG0GuOmK+wRUDYWtpZIkB8Uci+HNxV8u21c= X-Google-Smtp-Source: AGHT+IEZFPUw/XU0YHoyLTOHieCDVAaUFIHc6OhfOtS4ST7uXP3bkvHoDIBYZQsAHj40tSg6bAcgew== X-Received: by 2002:a4a:8685:0:b0:5bd:c0b4:cf67 with SMTP id 006d021491bc7-5c1b8b70a84mr8390692eaf.1.1719007931232; Fri, 21 Jun 2024 15:12:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:10 -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 10/10] iio: dac: ad3552r: use devm_regulator_get_enable_read_voltage() Date: Fri, 21 Jun 2024 17:11:57 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-10-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_151212_260295_04911421 X-CRM114-Status: GOOD ( 14.82 ) 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 Use devm_regulator_get_enable_read_voltage() to simplify the code. Error message is slightly changed since there is only one error return now. Signed-off-by: David Lechner Reviewed-by: Nuno Sa --- drivers/iio/dac/ad3552r.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/drivers/iio/dac/ad3552r.c b/drivers/iio/dac/ad3552r.c index ddc6c262f801..bd37d304ca70 100644 --- a/drivers/iio/dac/ad3552r.c +++ b/drivers/iio/dac/ad3552r.c @@ -857,15 +857,9 @@ static int ad3552r_configure_custom_gain(struct ad3552r_desc *dac, return 0; } -static void ad3552r_reg_disable(void *reg) -{ - regulator_disable(reg); -} - static int ad3552r_configure_device(struct ad3552r_desc *dac) { struct device *dev = &dac->spi->dev; - struct regulator *vref; int err, cnt = 0, voltage, delta = 100000; u32 vals[2], val, ch; @@ -874,30 +868,16 @@ static int ad3552r_configure_device(struct ad3552r_desc *dac) return dev_err_probe(dev, PTR_ERR(dac->gpio_ldac), "Error getting gpio ldac"); - vref = devm_regulator_get_optional(dev, "vref"); - if (IS_ERR(vref)) { - if (PTR_ERR(vref) != -ENODEV) - return dev_err_probe(dev, PTR_ERR(vref), - "Error getting vref"); + voltage = devm_regulator_get_enable_read_voltage(dev, "vref"); + if (voltage < 0 && voltage != -ENODEV) + return dev_err_probe(dev, voltage, "Error getting vref voltage\n"); + if (voltage == -ENODEV) { if (device_property_read_bool(dev, "adi,vref-out-en")) val = AD3552R_INTERNAL_VREF_PIN_2P5V; else val = AD3552R_INTERNAL_VREF_PIN_FLOATING; } else { - err = regulator_enable(vref); - if (err) { - dev_err(dev, "Failed to enable external vref supply\n"); - return err; - } - - err = devm_add_action_or_reset(dev, ad3552r_reg_disable, vref); - if (err) { - regulator_disable(vref); - return err; - } - - voltage = regulator_get_voltage(vref); if (voltage > 2500000 + delta || voltage < 2500000 - delta) { dev_warn(dev, "vref-supply must be 2.5V"); return -EINVAL;