From patchwork Fri Jun 21 22:11:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708123 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 CC65BC27C78 for ; Fri, 21 Jun 2024 22:12:51 +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=YU5eFUTN0Hk2LWl03tYr+7EwkXmonIPdLeN7oZJP5hY=; b=pGsjTSoP3JTI6PiTvK4SW4HT7w muFVc2y688Aw6twmE3+l4K+RF/418IiuJ44WZDFoOKceGkeDcNblhWya6TE8PAovLYPGQb27wWAz8 o7YCBdIT9l9Kf4ceYSacdP/GIcNzJbOYQrTqyPhbGxS3FqzxApfGO/ztfcdWvnZsxVhZOA92Yz4si L0PXqiENhklhH4TxJF9pF106lmS5P/ZDjrv6VDkWfaOyCJ0IiUcQjeJIU1yIroUxctBWu+gx6+ABQ vrE7nkn+eZR2GmKmthnnshVp6dHW7vd9Asu3+pmZg+Nb/UH5W1pZ0nmjSTgyBlV+K2p/AlHeI8+VN ZeTSGd7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUl-0000000AiQG-3d2L; Fri, 21 Jun 2024 22:12:35 +0000 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUM-0000000Ai5t-2cce for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:12 +0000 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-5c1cabcb0c1so1133517eaf.0 for ; Fri, 21 Jun 2024 15:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719007929; x=1719612729; 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=YU5eFUTN0Hk2LWl03tYr+7EwkXmonIPdLeN7oZJP5hY=; b=hZPTZv9oiFsT9AtrUnla0VJQURNAClplHwbeZItiVkh+1XUPgO9XxqZjQFaWrtBDSD Ges7RUBOi8rRtDegcREb4RUL7BILq4gcErHcdVy7xuiAhiUcb13lwMBFC7IdvAM3Rtfm UoBsGhkglGg/WbDIeZFvbojPFbQpO5pZcYTuMgSIFMWM9XqZ7Df+UWO4v8NC/XSxJ+kG hWUAb2MNWobdQvB6x9OdXWYjhl7TByaf2FbTIKNUTCcWuD4mxNLQnekEoUv6CA0OIR+y rJufoRCw18yBhhOgtTtiiy2kvGQt+C3RBvsM/CJVHNbRRUVT1A68lUxsvaQhu02Gg2EH bj1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007929; x=1719612729; 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=YU5eFUTN0Hk2LWl03tYr+7EwkXmonIPdLeN7oZJP5hY=; b=W5U0v6WzGscTTCy0TMumsiShwVh//GgDiW2OtrI2DZyncdWoC4hNO3gFMb/LDim5W4 Lr0qrTqQoiEGGg2FSGr2P33U5fy0eZIRI8YxJF3d6Ulu9wU9HHJfDnWjGCIP5xK1cpIv xUwUUzy46uWIZhQ1EGZeUetR8Lj6a+WI0fB6nd7WvJsvWw0x4Z7ib8sdoMQBvP48dG4x A4MUJ8MMHxJdibf8CsXIkvY0+zePWhPBFVC8b3GvQ544tuu1RBC1OfzP3B0T/JTFqxlC 2H+XRQkhZtzhqZxuSFxEPqnYdq9nmFTY7BAUV4EeTRs5i5zgO/vhRfNkGUSwJUkLZeXb rdkA== X-Forwarded-Encrypted: i=1; AJvYcCWhWXSMsJaoLiCNvmIIrNw7L18UzbDtnETsDV4XWdsbsKdGP+Cw4/jGXSM8LkB4RQSqZEB5oGgvan4pzs+Dn/prWAaJsj7v4VNaK9Acy0GPWEE/IQE= X-Gm-Message-State: AOJu0YyvrifUxTwBuVSbVa3d4sUYZRAirC4ry7NK1w+rcaWlgChmUmjh sXbjLBNYfvOGSV8nDQWfzkKHk9njAucRpAK7JHHn6Zub1jNuA0OOr8jdbCYZ2Yc= X-Google-Smtp-Source: AGHT+IEKaEnaN52GJyDtdHtvEb/BI9UwWkmlr8jo82XfbDm4o52uxvo39sqUISJ/G4+mET8wMIvNRQ== X-Received: by 2002:a4a:240f:0:b0:5bb:79d:1c6e with SMTP id 006d021491bc7-5c1adc06d8bmr10632688eaf.8.1719007929621; Fri, 21 Jun 2024 15:12:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:09 -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 08/10] iio: adc: ti-ads8688: use devm_regulator_get_enable_read_voltage() Date: Fri, 21 Jun 2024 17:11:55 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-8-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_151210_707939_749C15F2 X-CRM114-Status: GOOD ( 14.77 ) 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. Signed-off-by: David Lechner --- drivers/iio/adc/ti-ads8688.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c index 9440a268a78c..fca3032c59d9 100644 --- a/drivers/iio/adc/ti-ads8688.c +++ b/drivers/iio/adc/ti-ads8688.c @@ -65,7 +65,6 @@ struct ads8688_state { struct mutex lock; const struct ads8688_chip_info *chip_info; struct spi_device *spi; - struct regulator *reg; unsigned int vref_mv; enum ads8688_range range[8]; union { @@ -423,21 +422,11 @@ static int ads8688_probe(struct spi_device *spi) st = iio_priv(indio_dev); - st->reg = devm_regulator_get_optional(&spi->dev, "vref"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - return ret; - - ret = regulator_get_voltage(st->reg); - if (ret < 0) - goto err_regulator_disable; + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0 && ret != -ENODEV) + return ret; - st->vref_mv = ret / 1000; - } else { - /* Use internal reference */ - st->vref_mv = ADS8688_VREF_MV; - } + st->vref_mv = ret == -ENODEV ? ADS8688_VREF_MV : ret / 1000; st->chip_info = &ads8688_chip_info_tbl[spi_get_device_id(spi)->driver_data]; @@ -460,7 +449,7 @@ static int ads8688_probe(struct spi_device *spi) ret = iio_triggered_buffer_setup(indio_dev, NULL, ads8688_trigger_handler, NULL); if (ret < 0) { dev_err(&spi->dev, "iio triggered buffer setup failed\n"); - goto err_regulator_disable; + return ret; } ret = iio_device_register(indio_dev); @@ -472,23 +461,15 @@ static int ads8688_probe(struct spi_device *spi) err_buffer_cleanup: iio_triggered_buffer_cleanup(indio_dev); -err_regulator_disable: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); - return ret; } static void ads8688_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ads8688_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); iio_triggered_buffer_cleanup(indio_dev); - - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); } static const struct spi_device_id ads8688_id[] = {