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", From patchwork Fri Jun 21 22:11:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708118 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 27222C27C78 for ; Fri, 21 Jun 2024 22:12:29 +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=cA2vZ5H4zhrRVMGC41BbSeo0sgv1/DHDpLqlssCbQtI=; b=sNBuFAfTfvouU2F4Ehe6NlIVxT VTiiI9DB3V4Bu+BYlBDHVtWsGZW1F0P2XwGoNuObUgOtPRJusIcUjTKbG/4nLzofXzItvTWWZCEUd 8lO/jWtSeLF7xX5aY3QZaG9kI3BH1NbIDlRPf5y4qUyWxwr9itBFFZ5v8k030wR8iDMAG8aZLazG7 M0CrYwWS6+3bfscC/C5AgR0JlvwSYdrveN+xOUjA6yCWko7fF9C4dKwOIgtHkR/zrHHLgcuAierpX 1eTOdOWx/piYeNQF5vEGnZuKMQYHYwRP4FVIuelp71vY+reawy+QZEFBzoOrjfb7+En5k94bvB2mR 67wXaRjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUP-0000000Ai83-2BcV; Fri, 21 Jun 2024 22:12:13 +0000 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUH-0000000Ai2f-1VvT for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:07 +0000 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5b970a97e8eso1389238eaf.1 for ; Fri, 21 Jun 2024 15:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719007924; x=1719612724; 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=cA2vZ5H4zhrRVMGC41BbSeo0sgv1/DHDpLqlssCbQtI=; b=fkCvG2IKxLJ5e6hU676N3v+RuZJOzYf8kxM1J/hlg4/lvR878MBFgLLAKOR5jIx217 AVdxjniK+nNp/pw7wMaiCWKDHusd1yj5e1QbvtpPC28j1AqU+hE/l2FS1wqrWv/yw0uL Fz9Fygt1KQ5ykqH+Gg9QScpWYGff18IRAZWShDl2tko4bpgX4C/Hu8sdza20TC8j9e8B Y3eRk3cNzse8D2auGEG94YHEPn5nD5vm1ZLB2CUKs1Jbbc/11FjXzkTaommLOG2SMAIn tVngXVUitlxr7ryTuy6c6++OaR5+1Ou4h/SQPez0D/RkFQCL6VNmDmwFyO7N97RO7iX7 PfJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007924; x=1719612724; 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=cA2vZ5H4zhrRVMGC41BbSeo0sgv1/DHDpLqlssCbQtI=; b=bXMJ2vJsaQBw/t7+V91ckHwDKdUsneO/AJhYePO/d+1fWiZvpdJWzMKE4vheExgu/V HjXjq+jZNDcmwJLisZYcMi4n3IfNbPlqqHYqw4SOPimGdkKdW07Gey4KXt7pAn6r+bvP P3+RAQWIkmqbZ/wnG5GtGmsUmRClyA/hksAmpAqhCTWyjBVoUXP+7dp+ZD8V9TGpysb8 aleFqMbyq4V3vUNd/8KRCHH5Yhl9YzaG9DK2HEkFcfM1Gr6dqwpbUCn9CgrF93AApp+p Mz+Rmn1ju488t8064DOwIX9iWDdLKzj2KiYm7fJGOpYV/U2WqXtjPx2QiDcS6lRF7EK5 J14A== X-Forwarded-Encrypted: i=1; AJvYcCXWfTmzf7pXXv1QPnj+8cGyrA0aG7NxPIwuuCE6YQSQrxM/JPumg6oqV2EmebSg5QWjXXZGMHZ73SbhS/drcE2IuzKRLmv4FbSHCi+k9JxAYyZZIUU= X-Gm-Message-State: AOJu0Yx697YBwmUNrn3ZCpPPPXXoUhdc7eqQVRqde08DqjIk+8yfefyP pUd6V5O73P8NMYKgZwYc7qpJzngKMXRFgOQMboHUPSh1+v9AdqWtzqRDjRBpqrQ= X-Google-Smtp-Source: AGHT+IGPEjYzZuYy0PUyybo/Jr5W5tkGRhnX5VFZ0jGpJucieHOIXpFu0GRrOvhhGuVkoDgVWKm7XQ== X-Received: by 2002:a4a:7619:0:b0:5bb:288:e955 with SMTP id 006d021491bc7-5c1adc6fb4emr9863944eaf.8.1719007924414; Fri, 21 Jun 2024 15:12:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:04 -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 02/10] iio: adc: hx711: use devm_regulator_get_enable_read_voltage() Date: Fri, 21 Jun 2024 17:11:49 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-2-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_151205_432070_FDE75A6B X-CRM114-Status: GOOD ( 15.97 ) 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 the devm_regulator_get_enable_read_voltage() helper to simplify the code. Signed-off-by: David Lechner Reviewed-by: Andreas Klinger --- drivers/iio/adc/hx711.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index fef97c1d226a..6efdc971689c 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -80,7 +80,6 @@ struct hx711_data { struct device *dev; struct gpio_desc *gpiod_pd_sck; struct gpio_desc *gpiod_dout; - struct regulator *reg_avdd; int gain_set; /* gain set on device */ int gain_chan_a; /* gain for channel A */ struct mutex lock; @@ -497,11 +496,7 @@ static int hx711_probe(struct platform_device *pdev) return PTR_ERR(hx711_data->gpiod_dout); } - hx711_data->reg_avdd = devm_regulator_get(dev, "avdd"); - if (IS_ERR(hx711_data->reg_avdd)) - return PTR_ERR(hx711_data->reg_avdd); - - ret = regulator_enable(hx711_data->reg_avdd); + ret = devm_regulator_get_enable_read_voltage(dev, "avdd"); if (ret < 0) return ret; @@ -517,9 +512,6 @@ static int hx711_probe(struct platform_device *pdev) * approximately to fit into a 32 bit number: * 1 LSB = (AVDD * 100) / GAIN / 1678 [10^-9 mV] */ - ret = regulator_get_voltage(hx711_data->reg_avdd); - if (ret < 0) - goto error_regulator; /* we need 10^-9 mV */ ret *= 100; @@ -559,7 +551,7 @@ static int hx711_probe(struct platform_device *pdev) hx711_trigger, NULL); if (ret < 0) { dev_err(dev, "setup of iio triggered buffer failed\n"); - goto error_regulator; + return ret; } ret = iio_device_register(indio_dev); @@ -573,25 +565,17 @@ static int hx711_probe(struct platform_device *pdev) error_buffer: iio_triggered_buffer_cleanup(indio_dev); -error_regulator: - regulator_disable(hx711_data->reg_avdd); - return ret; } static void hx711_remove(struct platform_device *pdev) { - struct hx711_data *hx711_data; struct iio_dev *indio_dev; indio_dev = platform_get_drvdata(pdev); - hx711_data = iio_priv(indio_dev); iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - - regulator_disable(hx711_data->reg_avdd); } static const struct of_device_id of_hx711_match[] = { From patchwork Fri Jun 21 22:11:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708117 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 62B2EC2D0CE for ; Fri, 21 Jun 2024 22:12:29 +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=TqnA463lWGmo1DkYd27gIKH1c3eeWL6q+1Fm9JrS/t8=; b=ddKol0nPevvlwmaimq/V+705Qx lN67GXM4+5PaoHizOBj66s2muB9fJAcLnV0JzF80QqJowWBTZZlRA6edD5K39TZGrSPyxkC9zwmE1 Mj+mZrEMsGgRlDGuYnxK/Iwz5YRwDlEXHumBGybmFcBB/G9LIj4EAX+vXg7alUUCVxWU11OL9QtvN BntuvSs5itLazg3U38kcsuPuFxoDT559/FWJ2LtMAvkRcmz7gB5qZiFY/RW6zA0RLhbJ44dAyr9y1 fDY0seD9sdrvNRDfBflGAoX/9zXuuqlbA2+93Ih6o1ZmXdmc/YiiFwxwuhRsdhU1U7YGCwXUr8VNs 21NX4zXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUR-0000000Ai8v-23E7; Fri, 21 Jun 2024 22:12:15 +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 1sKmUI-0000000Ai3E-0GYL for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:07 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5c1b27e0a34so1177556eaf.2 for ; Fri, 21 Jun 2024 15:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719007925; x=1719612725; 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=TqnA463lWGmo1DkYd27gIKH1c3eeWL6q+1Fm9JrS/t8=; b=R3TTaeEXdqYWJuYrKguCFCJ1beKPE+m/r8iqzQdPQJ041miuYtF+rlguOUXzd1Tei+ l+Mabr8W5b942mbhxghyAUEU8wCEEVT1DvZ9j3Vcs1442iy2KMp1AhSyuE7oGq+kr45h DZ3Oj2Z4o1RTLg380rEeaEC2DYi38qSqdW6OZmc2jVblv4dtcSyz52VZPAYqgdoJq/SF 7v2gnIFw/2T+sWy16IMd0RQjePl4ETHRiDitz82so1Hk1bjR3uPGUGB/5kVSDaA73lmU E1qWbbe72f8rG2kfjQR4xabitLdaaQh3qFlCrmUNDmyL8p3mt7OMp60t4F9kMDBlyXtH vUFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007925; x=1719612725; 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=TqnA463lWGmo1DkYd27gIKH1c3eeWL6q+1Fm9JrS/t8=; b=gZz3Gwa78+JJs0PcMs1qwwy+n+wz6tINl15tFzYpm4ZNDBPyDTIth1gsy0/z0YZGxC WpBfJrSDTUz3/ZnUKvIF8qazBC64y2fVfmCOwh58PBPWJDL6t7YoYRK2O0L0uq5tjIyt k92tzXIjDOMSw3ZcNuSVO1Gp44HwzUVT9xBlwEtpB91n1MZh0rBbNz+Qor/akBhH1Bou Ja3ZLNttfwrAj+m/yWQBWBAIpZyGlVbBlrmM31Qt9afMz2N0jxvclmJkdPm3dZGhKH6/ oJGXVX8gZUEDK5y/AG3ggO2qx81VbnkQR+oZ3lymjLkX256z8LsLhuL7a7ElJehiL9f4 THIQ== X-Forwarded-Encrypted: i=1; AJvYcCVeAuhB9oFQSVVRb3FuNN+KzDcdNGN+4s29Md3cIbCF0mQdJNlyOV9GO5LvjOy0QuEgE4XUzRC3XWXs6ayPQtPIdUaBUkrMDmzebMULg3H5+DtB8DY= X-Gm-Message-State: AOJu0YyqAlPZOxQS4nmUDf0iBrU0n3CPiNn0ZB7o4yOlmcF3Kr43ZdgV 36jpIIHupWj8vumaqMLKwgR1rJk4B+08VrhJFYRRxXn6MkXTNKJqOx5waCUPSN8= X-Google-Smtp-Source: AGHT+IGyOuPixSMNWTrgJ93EOZnRr5Mc7Ev97HbXaH84J6/Bv30RS8z/PVagDiDtAkY5vq1kH6S7MA== X-Received: by 2002:a4a:6251:0:b0:5bf:aa53:2de7 with SMTP id 006d021491bc7-5c1adbca083mr9462944eaf.5.1719007925247; Fri, 21 Jun 2024 15:12:05 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:04 -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 03/10] iio: adc: hx711: remove hx711_remove() Date: Fri, 21 Jun 2024 17:11:50 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-3-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_151206_131223_A4C85E42 X-CRM114-Status: GOOD ( 16.21 ) 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 By using a few more devm_ functions, we can remove the hx711_remove() function in the hx711 driver. platform_set_drvdata() is also removed since there are no more callers of platform_get_drvdata(). Signed-off-by: David Lechner Reviewed-by: Andreas Klinger --- drivers/iio/adc/hx711.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 6efdc971689c..8461b1fe6bad 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -539,43 +539,27 @@ static int hx711_probe(struct platform_device *pdev) hx711_data->data_ready_delay_ns = 1000000000 / hx711_data->clock_frequency; - platform_set_drvdata(pdev, indio_dev); - indio_dev->name = "hx711"; indio_dev->info = &hx711_iio_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = hx711_chan_spec; indio_dev->num_channels = ARRAY_SIZE(hx711_chan_spec); - ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time, - hx711_trigger, NULL); + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + hx711_trigger, NULL); if (ret < 0) { dev_err(dev, "setup of iio triggered buffer failed\n"); return ret; } - ret = iio_device_register(indio_dev); + ret = devm_iio_device_register(dev, indio_dev); if (ret < 0) { dev_err(dev, "Couldn't register the device\n"); - goto error_buffer; + return ret; } return 0; - -error_buffer: - iio_triggered_buffer_cleanup(indio_dev); - - return ret; -} - -static void hx711_remove(struct platform_device *pdev) -{ - struct iio_dev *indio_dev; - - indio_dev = platform_get_drvdata(pdev); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); } static const struct of_device_id of_hx711_match[] = { @@ -587,7 +571,6 @@ MODULE_DEVICE_TABLE(of, of_hx711_match); static struct platform_driver hx711_driver = { .probe = hx711_probe, - .remove_new = hx711_remove, .driver = { .name = "hx711-gpio", .of_match_table = of_hx711_match, From patchwork Fri Jun 21 22:11:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708119 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 A8C03C2BBCA for ; Fri, 21 Jun 2024 22:12:31 +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=PD+YDF/bIrSJ5as8z+S1ghdz1Anzvn+XbfX57fqHPgE=; b=R+l1UeGtf9pGcdnSDsxluDWL8G n+v2wXVnaWYeG53WV+S7hwJLPEr5oyH4y/ndcEk+d29A/+z7YQ5k6HLoMiheb/ncMgvA7I7g5OgOs a803Walr3JxzC13zCMnnW04gSBX3pqIEzkMDzbvwKXrrVCI33PRF9kymalkOFJBD1Udj1es/5vdVY kyoJY6lFY01m4vJ1iPmX7AJmQdy9bh0LrxStwiBU7pZM8OReNLOewf9fRACAORwfbBRuLqLvGKxTN MGC6hajzNf7iiPQCMmySJg+mi9NgyHvMWHWyg68NKHYnvR3U6+fsrIMAv3huvudZci+ly19Ed4eDi WWI5gWOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUS-0000000Ai9b-1RLH; Fri, 21 Jun 2024 22:12:16 +0000 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUJ-0000000Ai3b-09f6 for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:08 +0000 Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-5c1acd482e4so1366652eaf.3 for ; Fri, 21 Jun 2024 15:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719007926; x=1719612726; 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=PD+YDF/bIrSJ5as8z+S1ghdz1Anzvn+XbfX57fqHPgE=; b=WXqUlZsV7n9toEWxzHc41iBhAXn4YCSUyMWOIBqybeCtJD2Uu/jVMBew8Es+Wt3be1 nH55OmJ+Ld9sKOtK3SajA9P/sjeY+yVG3rJEzCMAZn/wMDosarRQfn4/sFIKEjfJrumM AEqjgAPcaGN2GWNJHSHU3FWqHCSwOdZuzA9GcKKdJnPwaqCIuapt0YaaptPm4F8QfNeL Aqm68yhZb/zgEFT/YtwXbOvZNitdOWgWCl3kH66lrR2BXg3ZMGsU9WURRhwlODrQNCOR ueOc1k+2hbQW+b/WD5DC0V0xf8FHOPJnE0ls/oFyRYPvbDjKkNpgTVFad4KxnnKP5QPd PF8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007926; x=1719612726; 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=PD+YDF/bIrSJ5as8z+S1ghdz1Anzvn+XbfX57fqHPgE=; b=o0uXTB59KLr2zR/5jX8Onw/PKiOQnREAw2Xexq5fEO6zgPQlOgm7EDKhq73a/ZpAto uEgW+nbRHx2tgYvYQgF031BmXf9VU0UAO4ROBavXvL4l77Kx83Jrn0djJsyQjs7dRSTE rPG0jjCAHBPT6MiwmXpWgD3Gqd/VkZf0HuXluEzsWNH4zJhhwtb5SZ3SYykQHPmZt5Mc Jl31SKlqUKe367tyfIDDxjkCmSvYIDUJB12iwLG14rRDFGezWzW+hEOTVKWwT0v5hFSi X9w9x9OM0cCzI5p7G42zxX6nmXoNY6Axs4bJUtQn+N3prkUw3lQ4wmdc4ZDiifSvpHGb ZqQQ== X-Forwarded-Encrypted: i=1; AJvYcCXJG4M0dF2kCBhthCuZmOTMLYbE9aQPqMpao5n9BX2bVfcS7iW+/BxwVwrgE/Z+0sQsSzN7YTSHS3bwNizewiAXJxC4HHyhjP76P1CV6fC4LIqGtks= X-Gm-Message-State: AOJu0Yyk6hy5FA98q7z0axUQM+o83D47LOfJX2UMGTnEHMWEnrE+2QJe ZE/Z8LjBQbgNcgZFYpwWz/c9dIKNw2In07IbA09eUHWyMdE5MQ0nNQc17lrLjgQ= X-Google-Smtp-Source: AGHT+IG8VExe3m+Cltyn4mwfelEWS/KdStFcap+oMybDTEkuUDcJh0MBpt38tdnWmKzNqDCnxsogbA== X-Received: by 2002:a4a:dcd7:0:b0:5ba:ffcb:c756 with SMTP id 006d021491bc7-5c1b8b70a91mr8440535eaf.1.1719007926083; 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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:05 -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 04/10] iio: adc: hx711: use dev_err_probe() Date: Fri, 21 Jun 2024 17:11:51 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-4-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_100626_882AF59E X-CRM114-Status: GOOD ( 14.54 ) 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 dev_err_probe() to simplify error returns in the probe function. Signed-off-by: David Lechner Reviewed-by: Andreas Klinger --- drivers/iio/adc/hx711.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 8461b1fe6bad..b3372ccff7d5 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -464,10 +464,8 @@ static int hx711_probe(struct platform_device *pdev) int i; indio_dev = devm_iio_device_alloc(dev, sizeof(struct hx711_data)); - if (!indio_dev) { - dev_err(dev, "failed to allocate IIO device\n"); - return -ENOMEM; - } + if (!indio_dev) + return dev_err_probe(dev, -ENOMEM, "failed to allocate IIO device\n"); hx711_data = iio_priv(indio_dev); hx711_data->dev = dev; @@ -479,22 +477,18 @@ static int hx711_probe(struct platform_device *pdev) * in the driver it is an output */ hx711_data->gpiod_pd_sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW); - if (IS_ERR(hx711_data->gpiod_pd_sck)) { - dev_err(dev, "failed to get sck-gpiod: err=%ld\n", - PTR_ERR(hx711_data->gpiod_pd_sck)); - return PTR_ERR(hx711_data->gpiod_pd_sck); - } + if (IS_ERR(hx711_data->gpiod_pd_sck)) + return dev_err_probe(dev, PTR_ERR(hx711_data->gpiod_pd_sck), + "failed to get sck-gpiod\n"); /* * DOUT stands for serial data output of HX711 * for the driver it is an input */ hx711_data->gpiod_dout = devm_gpiod_get(dev, "dout", GPIOD_IN); - if (IS_ERR(hx711_data->gpiod_dout)) { - dev_err(dev, "failed to get dout-gpiod: err=%ld\n", - PTR_ERR(hx711_data->gpiod_dout)); - return PTR_ERR(hx711_data->gpiod_dout); - } + if (IS_ERR(hx711_data->gpiod_dout)) + return dev_err_probe(dev, PTR_ERR(hx711_data->gpiod_dout), + "failed to get dout-gpiod\n"); ret = devm_regulator_get_enable_read_voltage(dev, "avdd"); if (ret < 0) @@ -548,16 +542,13 @@ static int hx711_probe(struct platform_device *pdev) ret = devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time, hx711_trigger, NULL); - if (ret < 0) { - dev_err(dev, "setup of iio triggered buffer failed\n"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, + "setup of iio triggered buffer failed\n"); ret = devm_iio_device_register(dev, indio_dev); - if (ret < 0) { - dev_err(dev, "Couldn't register the device\n"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Couldn't register the device\n"); return 0; } 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); From patchwork Fri Jun 21 22:11:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708121 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 C7EF4C27C78 for ; Fri, 21 Jun 2024 22:12:39 +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=x480k30HvbgguxGycHu5EFcSQYfeSDwQqt26z/bkWhw=; b=j7UQXMltr2kOxFhcY/O4FDFKoh W5l7iKtdaVfkYwXBEzjszpAZYGqk3QuSC+qJ3tPSk9TiI+jusFyGWmfKXukqmD0X44jHhe33VHr5g crkQ99I4TgQgdQ2jFgRvAPhGXccovpIrCor9kK8oIMfpaRvcADhHHa2fFoEez8LQ6Ib8tvJhVq4db iNiYLNqhc1pM96o2etzbSAeKKCEFfRWBKnenbynIur9C1TqVaG9B8Bin3amVOy1nnRKK/D5py/BXQ y3PfoHFkeLz9/ls1CjUD9AZaAZop9x8sE/MtYVxt4MexOLZEcdFhONyehGjazJrZSW+hG4bOG86AA 9D5K2Ufw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUZ-0000000AiFh-2DvC; Fri, 21 Jun 2024 22:12:23 +0000 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUK-0000000Ai4g-3Ce5 for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:10 +0000 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-5c1d6064557so699838eaf.2 for ; Fri, 21 Jun 2024 15:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719007928; x=1719612728; 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=x480k30HvbgguxGycHu5EFcSQYfeSDwQqt26z/bkWhw=; b=W7rNmIkaQyJ9fKqfMckqzfDFDAo8y38OAR9uy4YvPur4PDfRKMFVUcoaH0zPKNBQSj Fonv1RhAahNZ23qLiE84pW14/adwPNtMOojgmXOD61129EPDeUMVyCTv03++wT+Crh3g H8lvB1l4b0NVLI9k2oyIdj05dCxYMl0sXJZqQmpnuIzk14SIIWp/WttftBYIwOiqaRfQ KBhq58nUJlweTunTRR678f2guNzbH2MiM/ohviWSiNdY4xmgePE2aWsd8+3IAp64xASH UxL8v55PyLy9K+rEAIsEMy96+1mL3neexh2QKQd7SgwbfRxDeYqvJtWMCtIArUjFw9xL 2jng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007928; x=1719612728; 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=x480k30HvbgguxGycHu5EFcSQYfeSDwQqt26z/bkWhw=; b=MZqhIewuKVZxLmZIF7h9jFcYUgaAEsXaowq/8dLi1KZo5c8d/qL/Q22MuD9E9GRh3c cm6h1D0skQQUEKd1VUWUkonUtoOOYGMfNA0slECr0FUHg8Aiz5o1VNuVRivqBwgFq3xG 6JfvRh6yfyMNQZsx0te8nzTaoWywdbbBY4OUHrzt0B771k0a6YNsOM52JQ+P+xAui27r l6WVLrlp8EZ6xqWWiwl6bIGEkZtewcv2rUNj8UezSjkcUBIr5KQaRpVZEUl516o3R8dM r27RYg6OM9kimfEFKulsH3sK+pR2Ss1S2rngAQwXjlAVajomQYo3T1buoiex/SexQvOA Bv8g== X-Forwarded-Encrypted: i=1; AJvYcCVbxryB8uKJyO98e2PxpUrxM60F4usazy2lrneyemez9b/b9f9+fiL9hiRTkJOmYcxgPkV8G1lN6BalrWv6slIBAxrQ+A4NdAB0W7rLaQidOu2ylgo= X-Gm-Message-State: AOJu0YxadVbq4hbX90pNATCEmNr9pvOliY5rOcaAT5yGsgn9vdPUP/5n /5CQaoW8OKPwuO3McGDnLiKhogZtxUQc+Ugx8SDr1HbFcJXpkPpoUWMBijQlBEc= X-Google-Smtp-Source: AGHT+IG+VM3BqlCHEFeC4J9E/NMCgNrxfHHKT6M7Y8Cy0YuF/8Q782d8FLdKsjcTjtElrN8SZRNxMQ== X-Received: by 2002:a4a:3c1e:0:b0:5bd:b100:8ab1 with SMTP id 006d021491bc7-5c1adbeb0e3mr9929583eaf.7.1719007927729; Fri, 21 Jun 2024 15:12:07 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:07 -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 06/10] iio: adc: max1363: use devm_regulator_get_enable_read_voltage() Date: Fri, 21 Jun 2024 17:11:53 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-6-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_151208_920142_D3087D61 X-CRM114-Status: GOOD ( 13.32 ) 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 Reviewed-by: Nuno Sa --- drivers/iio/adc/max1363.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 8b5bc96cb9fb..bf4b6dc53fd2 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -1561,18 +1561,12 @@ static const struct of_device_id max1363_of_match[] = { }; MODULE_DEVICE_TABLE(of, max1363_of_match); -static void max1363_reg_disable(void *reg) -{ - regulator_disable(reg); -} - static int max1363_probe(struct i2c_client *client) { const struct i2c_device_id *id = i2c_client_get_device_id(client); int ret; struct max1363_state *st; struct iio_dev *indio_dev; - struct regulator *vref; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(struct max1363_state)); @@ -1589,26 +1583,12 @@ static int max1363_probe(struct i2c_client *client) st->chip_info = i2c_get_match_data(client); st->client = client; - st->vref_uv = st->chip_info->int_vref_mv * 1000; - vref = devm_regulator_get_optional(&client->dev, "vref"); - if (!IS_ERR(vref)) { - int vref_uv; - - ret = regulator_enable(vref); - if (ret) - return ret; - - ret = devm_add_action_or_reset(&client->dev, max1363_reg_disable, vref); - if (ret) - return ret; + ret = devm_regulator_get_enable_read_voltage(&client->dev, "vref"); + if (ret < 0 && ret != -ENODEV) + return ret; - st->vref = vref; - vref_uv = regulator_get_voltage(vref); - if (vref_uv <= 0) - return -EINVAL; - st->vref_uv = vref_uv; - } + st->vref_uv = ret == -ENODEV ? st->chip_info->int_vref_mv * 1000 : ret; if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { st->send = i2c_master_send; From patchwork Fri Jun 21 22:11:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708122 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 EFFB7C27C78 for ; Fri, 21 Jun 2024 22:12:46 +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=so6aBU+eDqnCDSaguZCLxm5y7z6KxLSHynmcPlHhQSc=; b=b6GiZ5GU7UgubDryiEA2jLSbQ0 9CSh5HZ0/zmzITprbI+2/G4HmhMU4Ej7pScGaPUzdbKEuP3cz0QqcB9waGlQ2fumnGratj0QelaKi io7ChyWlPw6Oi8+miVF4H5JxhDvyhMcEazRjwj9EFCWN6CzV50qkZKkxVX8KDsHaYCRbldHNvi8dW ooiF+FNC8fiAVAyzI+rK97LbHtsZQBdwZHWp4kcp7aJsvaajb5jQvG4ugYaG7jHESK6F6oOkJY56P xqGhvHc9MKpzdQCu8JrYc/dQPjaCQ4yldby7hzoRmsJSACafVipqaVV7u3eYSP4ES+kz1EdLd8/kX ZsmLVomg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUi-0000000AiNd-2VVD; Fri, 21 Jun 2024 22:12:32 +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 1sKmUL-0000000Ai5A-3NBs for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:11 +0000 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5babfde1c04so1116193eaf.2 for ; Fri, 21 Jun 2024 15:12:09 -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=so6aBU+eDqnCDSaguZCLxm5y7z6KxLSHynmcPlHhQSc=; b=NLxfOKV6KhKMKKLmkyFWP+Cl9NaAb+hoixhes9nKJEBWJ213H/Qwyw9pw7iuIMFvnq cteoxweqaOVYCgVv+aONQUelUY4zmaNKW7NdomCD/COHyKDFL+dFjA2QBoHnB0h5uBxt rGETjcoHTBHT6LFIPomfvuTQBLONZkZY5kyPRzQMlObHiEcWtOg1dh471OrIcCNUYdOd eNci5Mr8k4+9XmKVb/67O96NyTADAvltTxxSXtdJvCTG2FSSL8oYJ1i1PP82olKwv6j+ fAKlUQphDoPBlEMmYEFmMbFCKu1OciYfEefwJ3SNl9k9owfE2VYnQWUrXwDultnpMPem hc9A== 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=so6aBU+eDqnCDSaguZCLxm5y7z6KxLSHynmcPlHhQSc=; b=lVU1IS5CwmCjy6FEZX90zvsOtmLmtx20cipyzmuCLCRz3FWlVAPqdHapkwi5zIcVNl Hlh+j0EqoRc58JkssHI6GRmXR29T1MwzfbO4OOOlVt50Mp6Bx2uG8CkV8s7aThLx3wRZ JeguQvmqxidrH3Q95lEqj6PtH2OMKjVj+PFovHPJo+QOo+l7lIWqLrtaxU83CNNz17MQ 6ISMyHEpfDEduFxHnpRFHkhD3DzT/3XT1bkERiqZZr0phhG4m7mObDI0bUEGvzY4UQh4 /lEnRaJmCxXBe5c0btgfv0rqOTee/nYCERqy7mdIpoQiteJNmKGhNhLpHOPZ7sYC5hNv Rv5Q== X-Forwarded-Encrypted: i=1; AJvYcCW0kbT5+6xcAYndoLzffAhlgzjED/9QeE639IDe/xXjyyZIlIsaGLEhsKebuvtertAhUtZ8aTATM4nZ9gYgtPy08FVwc6yrXukcCrjw/qKmNB96HfY= X-Gm-Message-State: AOJu0Yx/2PLTH0nEQ8fJXpq/EO9SnWYOyAfbmaFySA1+SzC1mFHxe7f5 a5NVi1ms0fEnZXYuQFWEb+x1fGoo01wCzY6MAi+KhQhXpb0jYg5n+34/FFKYZII= X-Google-Smtp-Source: AGHT+IGCM/8sRsLCLqFNICTMywqS3PsKIuS/B/sed5essCH1YgcxL2TzQancR7MJmS3Wfz2Pkd4FGg== X-Received: by 2002:a4a:3c5b:0:b0:5bb:294a:cb90 with SMTP id 006d021491bc7-5c1adbf1d68mr9897886eaf.5.1719007928519; Fri, 21 Jun 2024 15:12:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 15:12:08 -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 07/10] iio: adc: ti-adc108s102: use devm_regulator_get_enable_read_voltage() Date: Fri, 21 Jun 2024 17:11:54 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-7-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_151209_977586_8613296E X-CRM114-Status: GOOD ( 14.57 ) 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-adc108s102.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/drivers/iio/adc/ti-adc108s102.c b/drivers/iio/adc/ti-adc108s102.c index 69fcbbc7e418..9758ac801310 100644 --- a/drivers/iio/adc/ti-adc108s102.c +++ b/drivers/iio/adc/ti-adc108s102.c @@ -58,7 +58,6 @@ struct adc108s102_state { struct spi_device *spi; - struct regulator *reg; u32 va_millivolt; /* SPI transfer used by triggered buffer handler*/ struct spi_transfer ring_xfer; @@ -216,11 +215,6 @@ static const struct iio_info adc108s102_info = { .update_scan_mode = &adc108s102_update_scan_mode, }; -static void adc108s102_reg_disable(void *reg) -{ - regulator_disable(reg); -} - static int adc108s102_probe(struct spi_device *spi) { struct adc108s102_state *st; @@ -236,25 +230,9 @@ static int adc108s102_probe(struct spi_device *spi) if (ACPI_COMPANION(&spi->dev)) { st->va_millivolt = ADC108S102_VA_MV_ACPI_DEFAULT; } else { - st->reg = devm_regulator_get(&spi->dev, "vref"); - if (IS_ERR(st->reg)) - return PTR_ERR(st->reg); - - ret = regulator_enable(st->reg); - if (ret < 0) { - dev_err(&spi->dev, "Cannot enable vref regulator\n"); - return ret; - } - ret = devm_add_action_or_reset(&spi->dev, adc108s102_reg_disable, - st->reg); - if (ret) - return ret; - - ret = regulator_get_voltage(st->reg); - if (ret < 0) { - dev_err(&spi->dev, "vref get voltage failed\n"); - return ret; - } + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0) + return dev_err_probe(&spi->dev, ret, "failed get vref voltage\n"); st->va_millivolt = ret / 1000; } 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[] = { From patchwork Fri Jun 21 22:11:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13708124 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 0F790C2D0CE for ; Fri, 21 Jun 2024 22:12:54 +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=oTLhWXGcYPpFvPhVLNSGQecQSX/f3kZ7bOMANlmHk/s=; b=hrShJNoDkmpDg5VnCIJ2za2mJd g75U/7CodZWVP07sV++lxTv4OZy/RwQQibvp0DQrzgEIfXYPZlszXdVHUvbxMUwHO41XuWexGl6Z+ FxrU5p+SuUgP/wiL0TKfdhXFFoiUyphwK4GT0j/wJR8249gC/VjEIg1p9whFYOHBWPRUyd7gY7w1C N6vCewyQwK5Re4kPwlY5uMqJChvEfGmGqr69aYmLdcCaZDZ8Y091MNCAMPnpKjTJpdZ90FKYTry/J 7h0NirBFZZI5FSwTNkhMaOt4ZeY3rYqw/ar1bOvkHGySoG9rGyqIBAJXrUh9tv1G5lVhw8QhnpNpa 8gidqk/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUq-0000000AiUm-4BwD; Fri, 21 Jun 2024 22:12:41 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKmUN-0000000Ai6P-1abY for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 22:12:12 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6f8d0a00a35so2307962a34.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=1719007930; x=1719612730; 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=oTLhWXGcYPpFvPhVLNSGQecQSX/f3kZ7bOMANlmHk/s=; b=hZLfz1sO6Zg9oqCR5NQqsYaRBWGJUVpSnrV26+xRAHN4nLcZHaKYr1XdFR/GHcvMRh hfHeglxHTzXkSeLZY4e0KVv1uJxVbDumgCncErWVcXu2QWnTycK2/lM1/vTuE2nc9sbC 0wM/0zD1fYC0g3+O3nyZMqKz0Hz83gGcKkTjmGz4t5AgCcDtpHv5rMbInjHjDDNaSrmd +EPPtatIxR6LqEZGAEcnb+rlg1Vonq7/34yH0AwsudP84AUAX4r0xTaJFHpgJVF/6Pzp fYkTrTZRNnj7jus7szk7ogeRedT5sG20ctg3L7tPqQV44L8GZIeP0CWLrfWWbLwuU+V9 zUoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719007930; x=1719612730; 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=oTLhWXGcYPpFvPhVLNSGQecQSX/f3kZ7bOMANlmHk/s=; b=xKgMmgW2nosrs+F007NZIwOqXfAY1fiVGeD1jx7B1ShuA86sXA6xnxaSp/x1j0c14S Jcw+peVHWlmXqRhY5/mPGnSU07WRVQSBARWcpf+Q1ISpsAd/bDGT+Bkp0l0460OfEsM0 Uz2Pm13KvI/Akx8mpV0P/pzaXJrxTgV96W43kh3v9nj7oiLdsyMhQ/oFGF/83p1FUZHn /etXpqDWQqKkveQn1XqRbORQKBMm1br3zwnFl7gGI/yRWzkoyfHqkhv7TgP9JmuVKmGq VbPACULJH6Nxt4tiI0WPWqVol1WD24B/K8C6r3cdwo5I2XoAZAV6Kp7CMT066Le4oylJ +Stw== X-Forwarded-Encrypted: i=1; AJvYcCUlB4j4HCaCSUz6q7Kkgle+BG1GG/H7aUmy2MLDBEH6ap5gWzOrp5Uwon+PgwEVHf1un7GKjtkUu3Uz/XpazDezIiulv5CwNxVCc+77rjF6/XZEgMA= X-Gm-Message-State: AOJu0Yxfhl74D0YeWpI/+eg72NWs9AuTCLadlMt9aJ5JrCCPQqjKMid8 CUWNmVzih1VFQ0wkkQ8kDawB7SIphS/Q+E14NekhgHYPONEymPGUdWZP1j50qlM= X-Google-Smtp-Source: AGHT+IF2SgOBJxuK1mN8+m/jYX05pEOQGH/eglbTypLzjQRP70yZxGSEzwMMU70XpDgEFsNdBCoitQ== X-Received: by 2002:a05:6830:4121:b0:6fb:d9b0:c17e with SMTP id 46e09a7af769-700767308a6mr11026891a34.35.1719007930440; Fri, 21 Jun 2024 15:12:10 -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.09 (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 09/10] iio: adc: ti-ads8688: drop ads8688_remove() Date: Fri, 21 Jun 2024 17:11:56 -0500 Message-ID: <20240621-iio-regulator-refactor-round-2-v1-9-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_151211_552460_44F34FE3 X-CRM114-Status: GOOD ( 14.90 ) 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 By using a few devm_ functions, we can simplify the driver and remove the ads8688_remove() function. spi_set_drvdata() is removed since there are no more callers of spi_get_drvdata(). Also use dev_err_probe() to simplify error return. Signed-off-by: David Lechner --- drivers/iio/adc/ti-ads8688.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c index fca3032c59d9..7a79f0cebfbf 100644 --- a/drivers/iio/adc/ti-ads8688.c +++ b/drivers/iio/adc/ti-ads8688.c @@ -432,8 +432,6 @@ static int ads8688_probe(struct spi_device *spi) spi->mode = SPI_MODE_1; - spi_set_drvdata(spi, indio_dev); - st->spi = spi; indio_dev->name = spi_get_device_id(spi)->name; @@ -446,30 +444,13 @@ static int ads8688_probe(struct spi_device *spi) mutex_init(&st->lock); - 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"); - return ret; - } - - ret = iio_device_register(indio_dev); - if (ret) - goto err_buffer_cleanup; - - return 0; - -err_buffer_cleanup: - iio_triggered_buffer_cleanup(indio_dev); - - return ret; -} - -static void ads8688_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, + ads8688_trigger_handler, NULL); + if (ret < 0) + return dev_err_probe(&spi->dev, ret, + "iio triggered buffer setup failed\n"); - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ads8688_id[] = { @@ -492,7 +473,6 @@ static struct spi_driver ads8688_driver = { .of_match_table = ads8688_of_match, }, .probe = ads8688_probe, - .remove = ads8688_remove, .id_table = ads8688_id, }; module_spi_driver(ads8688_driver); 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;