From nobody Tue Nov 26 00:29:54 2024 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 700DE204943 for ; Wed, 23 Oct 2024 23:55:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727704; cv=none; b=WuPFGyj8mEU3BYmQhOjAO8OTyVhDG40yYNmVmb9PzvmC3aSzgYl8nM153veAKnwfmoEv/6/5S4JA4e0RYrzhM7Zf1qFALBInwcd1In7EDjsNniuCyrplmauiSBUc9p4vh5ftUfc4AL3s79gQl4zhjkLF1HRV41ST5k7PZ9yRs4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727704; c=relaxed/simple; bh=hksfyNtvI8c0zcSVYvltOkcB7HflUdZ/dnRTHZtLyNc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EobAyvE4FHRDjzHi9sZ9nWJO7siJtR2RCgXWfQwRVv/wMS9RyCPtFCRFlwthYDtAAGZyBXsKOPJ+zytD9YIYtQ3eFhKXvtWSZzrose1fos2Qtej2Dud6jtqQdJQ/tcuYgFG8XJdSKRuhAM270F3/ayywpqbV0BSim6djbsDAqIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=z2VZ0kpt; arc=none smtp.client-ip=209.85.161.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="z2VZ0kpt" Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5eb73ec1e1aso153273eaf.2 for ; Wed, 23 Oct 2024 16:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727700; x=1730332500; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zXgjcYC4V8hToJDHO7m0/QEhFcbQteqE49QtIsCR78Q=; b=z2VZ0kptcjguzXDG5NWkuGrpzlLQfk5BQU5/g6SD1qalZysxGHX5GZ0GxrkK/0o3Kd MeTodPAZrGgyrf7TwUmKswcDYAcTeAM5ze/wGbV9BLA24BvoclYqpEaRR55lmoZJY7AC V3bgL1d6rWo8OR02PxxsL/dnSyPw5xuMycDMXELGE2AjmjXUSIn+oZD0bDYqHvWxeypZ Zqu4bZ7hwphxFxRVBLuyaEPn7hYO8wfuT9MqBddNvgG6IChXUsLHY9mjo+bbL+E1X68w 7yFShwdO1DN5NDg2QZ1UySZUHf+83lRywDL0gBgEn0LNKkXB8DLjV3Jtw5EbHnVEB7aQ MSFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727700; x=1730332500; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zXgjcYC4V8hToJDHO7m0/QEhFcbQteqE49QtIsCR78Q=; b=uYCxEzkiCLLYo+s44GeOK/0nBEakUwHr6QIm71RPkGno3bZUIYJQwxqqzD5VaKJNSL u5YN5DTHz4DJJ44yquSeufVt2l/DZK8ZQIxCE5t0XYIHN/pFFgYqkpRNuPJztrq394hT /FugqHJSrXQ8apn84PzV2gXr9Lft6/nNbgQyNs/pJyM99zHtCha7sP6XHiRHmZy1PXPo BCfNNH+re4CbGQBGbcKZErltJ9Osd1SksSSO+SmtHokWtIuQCchuAmwYDeIRsGpYKkl1 2fELnxxLUo+rBj6f7oxdcHeZE5Jx32AEI3NQOmkiF9Ga7Pk8bqwmpFTm0kSpNTefYc3J 9KEQ== X-Forwarded-Encrypted: i=1; AJvYcCW19H4pdTPU2IJtpwR8WGylD30KFue/jWGIU1nKZ7eU4JE7QgYjVZPB+pOdU/29L54Z2w3WhfUhvyM68hM=@vger.kernel.org X-Gm-Message-State: AOJu0YzEukfAHCI/7Ek7q3EOTEcJ/NLFlFOLdSlZ27D8j2hnysiu0qje yBN4V7O0whTSq5099Lfe53m4jfSLOOxUwugut2WZFd67/UVRwudkfkfWAoBRsiTjMX6AA7D5nsH p X-Google-Smtp-Source: AGHT+IHX8HP07MxzT6bYrvS2Paasp659iMVaVElKbts9GaB7FyQn3FIL5fyqdvanLn34LceSDDaHRA== X-Received: by 2002:a05:6820:1c8f:b0:5e7:cb2e:e01e with SMTP id 006d021491bc7-5ebee8fb6ebmr3022145eaf.7.1729727700604; Wed, 23 Oct 2024 16:55:00 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:59 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:13 -0500 Subject: [PATCH 09/11] iio: dac: ad5761: use devm_regulator_get_enable_read_voltage() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-9-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Simplify the code by using devm_regulator_get_enable_read_voltage(). Error returns are updated to use dev_err_probe(). Signed-off-by: David Lechner --- drivers/iio/dac/ad5761.c | 100 +++++++++++--------------------------------= ---- 1 file changed, 23 insertions(+), 77 deletions(-) diff --git a/drivers/iio/dac/ad5761.c b/drivers/iio/dac/ad5761.c index 6aa1a068adb0..55e33cf5806e 100644 --- a/drivers/iio/dac/ad5761.c +++ b/drivers/iio/dac/ad5761.c @@ -53,7 +53,6 @@ enum ad5761_supported_device_ids { /** * struct ad5761_state - driver instance specific data * @spi: spi_device - * @vref_reg: reference voltage regulator * @use_intref: true when the internal voltage reference is used * @vref: actual voltage reference in mVolts * @range: output range mode used @@ -62,7 +61,6 @@ enum ad5761_supported_device_ids { */ struct ad5761_state { struct spi_device *spi; - struct regulator *vref_reg; struct mutex lock; =20 bool use_intref; @@ -287,63 +285,6 @@ static const struct ad5761_chip_info ad5761_chip_infos= [] =3D { }, }; =20 -static int ad5761_get_vref(struct ad5761_state *st, - const struct ad5761_chip_info *chip_info) -{ - int ret; - - st->vref_reg =3D devm_regulator_get_optional(&st->spi->dev, "vref"); - if (PTR_ERR(st->vref_reg) =3D=3D -ENODEV) { - /* Use Internal regulator */ - if (!chip_info->int_vref) { - dev_err(&st->spi->dev, - "Voltage reference not found\n"); - return -EIO; - } - - st->use_intref =3D true; - st->vref =3D chip_info->int_vref; - return 0; - } - - if (IS_ERR(st->vref_reg)) { - dev_err(&st->spi->dev, - "Error getting voltage reference regulator\n"); - return PTR_ERR(st->vref_reg); - } - - ret =3D regulator_enable(st->vref_reg); - if (ret) { - dev_err(&st->spi->dev, - "Failed to enable voltage reference\n"); - return ret; - } - - ret =3D regulator_get_voltage(st->vref_reg); - if (ret < 0) { - dev_err(&st->spi->dev, - "Failed to get voltage reference value\n"); - goto disable_regulator_vref; - } - - if (ret < 2000000 || ret > 3000000) { - dev_warn(&st->spi->dev, - "Invalid external voltage ref. value %d uV\n", ret); - ret =3D -EIO; - goto disable_regulator_vref; - } - - st->vref =3D ret / 1000; - st->use_intref =3D false; - - return 0; - -disable_regulator_vref: - regulator_disable(st->vref_reg); - st->vref_reg =3D NULL; - return ret; -} - static int ad5761_probe(struct spi_device *spi) { struct iio_dev *iio_dev; @@ -363,9 +304,27 @@ static int ad5761_probe(struct spi_device *spi) st->spi =3D spi; spi_set_drvdata(spi, iio_dev); =20 - ret =3D ad5761_get_vref(st, chip_info); - if (ret) - return ret; + ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0 && ret !=3D -ENODEV) + return dev_err_probe(&spi->dev, ret, + "Failed to get voltage reference value\n"); + if (ret =3D=3D -ENODEV) { + /* Use Internal regulator */ + if (!chip_info->int_vref) + return dev_err_probe(&spi->dev, -EIO, + "Voltage reference not found\n"); + + st->use_intref =3D true; + st->vref =3D chip_info->int_vref; + } else { + if (ret < 2000000 || ret > 3000000) + return dev_err_probe(&spi->dev, -EIO, + "Invalid external voltage ref. value %d uV\n", + ret); + + st->use_intref =3D false; + st->vref =3D ret / 1000; + } =20 if (pdata) voltage_range =3D pdata->voltage_range; @@ -374,35 +333,22 @@ static int ad5761_probe(struct spi_device *spi) =20 ret =3D ad5761_spi_set_range(st, voltage_range); if (ret) - goto disable_regulator_err; + return ret; =20 iio_dev->info =3D &ad5761_info; iio_dev->modes =3D INDIO_DIRECT_MODE; iio_dev->channels =3D &chip_info->channel; iio_dev->num_channels =3D 1; iio_dev->name =3D spi_get_device_id(st->spi)->name; - ret =3D iio_device_register(iio_dev); - if (ret) - goto disable_regulator_err; =20 - return 0; - -disable_regulator_err: - if (!IS_ERR_OR_NULL(st->vref_reg)) - regulator_disable(st->vref_reg); - - return ret; + return iio_device_register(iio_dev); } =20 static void ad5761_remove(struct spi_device *spi) { struct iio_dev *iio_dev =3D spi_get_drvdata(spi); - struct ad5761_state *st =3D iio_priv(iio_dev); =20 iio_device_unregister(iio_dev); - - if (!IS_ERR_OR_NULL(st->vref_reg)) - regulator_disable(st->vref_reg); } =20 static const struct spi_device_id ad5761_id[] =3D { --=20 2.43.0