From patchwork Fri Jun 21 22:11:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708120 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 84E60C2D0CE for ; Fri, 21 Jun 2024 22:12:32 +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=9VHcpSCSl+z9MULQ1sxanESbfc3kKx/Z7jY5Xhv+4kU=; b=HAlELhgbH3w1azD94nheiFFKRE MtQKif3WY5dB6t1k7ZPXiUhjHxiRKejSCdXygW4EJRfQqWaD9DWlUyM2c2WrPwq2TFN53DBQIX3N/ K96bpUPSM/7GbZzW406+jX/x94AJ2r2006RhiIU1pgBAxuBV5GBExLWNbhAdZwKXdG14f8zWdl3A1 n9hSv8jkXBLR1NWkFfEEcNeuV3oWxJocC/GB5K+E3odMHMlVULCpDUuUgNGMNW05QQpoSAmT72IA4 uRCsSKTPLa1jpN5JMwrJcTfa6h67dfyrU/Vr96qEmTgr7GRKRqwLsfZ8zNKA2WHpf42A8g7W8depA 0Eu1/IEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUV-0000000AiBa-0jj1; Fri, 21 Jun 2024 22:12:19 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUJ-0000000Ai4D-3nBR for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:09 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6fa11ac8695so1447755a34.3 for ; Fri, 21 Jun 2024 15:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719007927; x=1719612727; 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=9VHcpSCSl+z9MULQ1sxanESbfc3kKx/Z7jY5Xhv+4kU=; b=NktkQGyLhNA5jz+O8DD8PqVgE2J/IO68ZljIvFO1oKXtKDptySaSs9KEL2V4ae4Ate lVs1EUI+8tqBTn8ypFlp6R/AuJ5u1RnSQ5AmPBrPeKKeGhocThEJ9rmGMfMV7X4j0a2i NloH+trFnj8r2W/hpEmUJJg6xFsYhGh94uFMLxqM8BvNy7MDZk1Z7k3HwIL2hdYz8kbd Y+75Vr456qVlov0Wz7fWXCw2g6lomaIgir4ho8LnjVLfb/IVNRMNJPlJhyE8f2Cu1zQm KWuS2fv8zDS6gU0X1FPt2pIZax0bhn6O4Gv4cQOiwVpnlozFQZH1w1XhbIixJtf4OY9o H46w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007927; x=1719612727; 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=9VHcpSCSl+z9MULQ1sxanESbfc3kKx/Z7jY5Xhv+4kU=; b=OCtUCyvjQ858i1vdGVKPI8oLg/pLxkZszqxmCkz8zsvLHEx2mHkvIpiLY7MjoAVIfO h21VUzKaRo7axXZW5BewmwjI1PPXA1+tDXAwtQuHSEWfzrrxFCrf8u509iOXeApJxqRy kHPSwqXFHP2pa3VoxZ4BJnlgam+IzgQRPQ8LAJSjefglyaoiI6xSkAHhzBrzzSnjKI+M 2Y9407hJUGmj7zrRC36HuckhrNcgpYCl+KbBfCcU9/k+UVmKq+zBSrvxUG+mDbxlgLRS IXN+FyrW5olpaCGEf8/Vhj+l9+g1v4Vsy/gj8s8qzRwo/AhbuamVt2cU0rHoxLye0Kn9 ZWlw== X-Forwarded-Encrypted: i=1; AJvYcCUZotruGOGnSc6FCr6EilP8xQ8y549JuvlpPflLVBQvax7HG051YUce8WcfQWCRKO9y+KnK0ar2jYh96l9dfscPCBr65EmhAOG6BV/J4IyUV6llUCY= X-Gm-Message-State: AOJu0YzHiMF+GhRTk6pvvBkINPNuSevFsgenPCeTDnM9NOLFdG1GShsP f3Yoxzjb7Lgp6iS75oDkQZFpd0AagrfCYjkQ+57V1+AnETglHr9YsNHU/cjKbak= X-Google-Smtp-Source: AGHT+IH97rOzv+89TB95LIhCbolye0EdHa9Rc661ctJrvuPP++dIiPj9NzWl+Xc/RagwgCrSd0GJLg== X-Received: by 2002:a9d:7404:0:b0:6f9:7919:a33a with SMTP id 46e09a7af769-7007401b178mr10452707a34.19.1719007926913; Fri, 21 Jun 2024 15:12:06 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:06 -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 05/10] iio: adc: ltc2309: use devm_regulator_get_enable_read_voltage() Date: Fri, 21 Jun 2024 17:11:52 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-5-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_151207_969810_F5BBF304 X-CRM114-Status: GOOD ( 16.27 ) 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 changed since there is only one error return now. LTC2309_INTERNAL_REF_MV macro is added to make the internal reference voltage value self-documenting. Signed-off-by: David Lechner Reviewed-by: Nuno Sa --- drivers/iio/adc/ltc2309.c | 43 ++++++------------------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/drivers/iio/adc/ltc2309.c b/drivers/iio/adc/ltc2309.c index 8b3a89c1b840..888a71454070 100644 --- a/drivers/iio/adc/ltc2309.c +++ b/drivers/iio/adc/ltc2309.c @@ -16,6 +16,7 @@ #include #define LTC2309_ADC_RESOLUTION 12 +#define LTC2309_INTERNAL_REF_MV 4096 #define LTC2309_DIN_CH_MASK GENMASK(7, 4) #define LTC2309_DIN_SDN BIT(7) @@ -29,14 +30,12 @@ * struct ltc2309 - internal device data structure * @dev: Device reference * @client: I2C reference - * @vref: External reference source * @lock: Lock to serialize data access * @vref_mv: Internal voltage reference */ struct ltc2309 { struct device *dev; struct i2c_client *client; - struct regulator *vref; struct mutex lock; /* serialize data access */ int vref_mv; }; @@ -157,11 +156,6 @@ static const struct iio_info ltc2309_info = { .read_raw = ltc2309_read_raw, }; -static void ltc2309_regulator_disable(void *regulator) -{ - regulator_disable(regulator); -} - static int ltc2309_probe(struct i2c_client *client) { struct iio_dev *indio_dev; @@ -175,7 +169,6 @@ static int ltc2309_probe(struct i2c_client *client) ltc2309 = iio_priv(indio_dev); ltc2309->dev = &indio_dev->dev; ltc2309->client = client; - ltc2309->vref_mv = 4096; /* Default to the internal ref */ indio_dev->name = "ltc2309"; indio_dev->modes = INDIO_DIRECT_MODE; @@ -183,36 +176,12 @@ static int ltc2309_probe(struct i2c_client *client) indio_dev->num_channels = ARRAY_SIZE(ltc2309_channels); indio_dev->info = <c2309_info; - ltc2309->vref = devm_regulator_get_optional(&client->dev, "vref"); - if (IS_ERR(ltc2309->vref)) { - ret = PTR_ERR(ltc2309->vref); - if (ret == -ENODEV) - ltc2309->vref = NULL; - else - return ret; - } + ret = devm_regulator_get_enable_read_voltage(&client->dev, "vref"); + if (ret < 0 && ret != -ENODEV) + return dev_err_probe(ltc2309->dev, ret, + "failed to get vref voltage\n"); - if (ltc2309->vref) { - ret = regulator_enable(ltc2309->vref); - if (ret) - return dev_err_probe(ltc2309->dev, ret, - "failed to enable vref\n"); - - ret = devm_add_action_or_reset(ltc2309->dev, - ltc2309_regulator_disable, - ltc2309->vref); - if (ret) { - return dev_err_probe(ltc2309->dev, ret, - "failed to add regulator_disable action: %d\n", - ret); - } - - ret = regulator_get_voltage(ltc2309->vref); - if (ret < 0) - return ret; - - ltc2309->vref_mv = ret / 1000; - } + ltc2309->vref_mv = ret == -ENODEV ? LTC2309_INTERNAL_REF_MV : ret / 1000; mutex_init(<c2309->lock);