From nobody Tue Nov 26 00:27:17 2024 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) (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 B0B712038B8 for ; Wed, 23 Oct 2024 23:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727698; cv=none; b=vBej1pQdHA/5w5BjW2qpseplgD0zEaTu9cONKJoOVguQ1gu3gebDrmMmYXbxCyZi5k5Tk4EmNYs9fU0KUxAb2rk5Jjsgx4hYChIdEURV+0phm8NKU2Q6MKZPHXP9U2rGvuTM+gjNyoHbm9CkBt08H3Pi6SBYEfY5eSPb6w0SjkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727698; c=relaxed/simple; bh=WXSUGzKXof4KJHuJTVmWwMUBIzaYKCOmAUkj1cLreFY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AjXfJWtPNc7r+NPM2MiYAaPUP3KLo4lmTiRoyd26cI1G7ZHJQpNSv4wCtoEBpEfyH5k2RgyFBUw9Tm5UjwONeBOEtRPvLxwZ61yBDgEcdcGQuld5XS0eacInvuyTyWOFzO3gQ+yzSihTF/yZSiKeeZFPLtqwqnG4tgrM+BDH5kI= 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=aCC6Ggem; arc=none smtp.client-ip=209.85.161.41 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="aCC6Ggem" Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5e5d0a80db4so142386eaf.3 for ; Wed, 23 Oct 2024 16:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727696; x=1730332496; 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=z/yIm2be4gnK0+kTlIbceXqBvtukZBq6O9tuHYtKMKc=; b=aCC6GgemP32ZW/IW6ShhL3kF3j5NTQnLEBUi6FMRapqVvexVVR1CUUwHcGfRSOjMF9 m7ALe7AOOpB7ldZtG56S6aLI0QCd0TLuSUu/Lpclydff5OPYt5ISpmHQnc89Ifa8nPIg zBc+0uxiJqDZhKCumf7ojIVamDftQnX3+iNaKYhBIB0oKdJ4o+mdFRGTHnDSNeUK+mbO 1kV4p9gwQHkX0f4c586sVdKwNus7Lagg1EE4m1e57FEPWzZEqsX1xsp1rcuFsgfFkNyy REhBbk6QWr8A8M1/rOJLeq3JagWiWpGRxM7FuO8HUxCDTF1YSMzFvVuEjsz0T7orn6Ec 4vng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727696; x=1730332496; 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=z/yIm2be4gnK0+kTlIbceXqBvtukZBq6O9tuHYtKMKc=; b=trciFdVk9UtSIXOGSQVVCa0DcRSnAns67s904qL5m0XcqTZZr7Gr6MOx+enlW5RX+p VdB3K2boXEaVkjy32gUUYcH7NWXK8rPu5NqcYxZnsRYMPH7Aau/DXM9Rgz1ytWeVroAr qmuNU92NK1iDqdFOkqJ4H6eYKHpHCTVlPGcHHuyZaCIfmDhA4R/G/evzyWZCqk1GMDZ2 rFiDv5m5NGGbUbybKK8EphYdh3289XJ++3JirJYwqqrW0Y/nNKCvvq8sn2/NFFx2RLNV MIUySs1ZPnXGp4sJCcok75a5ur7qrWJ70FbpZuTCXcjWkrwuH4TuR+VD2MwytD36ifJn ZGng== X-Forwarded-Encrypted: i=1; AJvYcCXakXtufQG/njBJ+1YIEBkGDXZkkqSttI1Z5rODkN5LtGk/luABqcSnGlquW69JXo4TUNRHiOYbN8dfrkk=@vger.kernel.org X-Gm-Message-State: AOJu0YyNh9TsgO501Fp9a3xGdDr/qoB6054EuXoafylNdrofdXx7anaI ZVVP2Q0NQ0VXV2suc4AHQaRsqrWX0mFXh+alzelZl5MOemByu77Dbv3Ex4UBvY0= X-Google-Smtp-Source: AGHT+IHRTb/aabdrDQ611+8RrwSHC7WNs1WZvC13QFbK4R08i5t4ZJSrfjoYNDOtfVLaC0BtrhH8CQ== X-Received: by 2002:a05:6820:2209:b0:5e1:cd24:c19c with SMTP id 006d021491bc7-5ebee2fe9b2mr3622584eaf.0.1729727695819; Wed, 23 Oct 2024 16:54:55 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:54 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:11 -0500 Subject: [PATCH 07/11] iio: dac: ad5624r: 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-7-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(). Signed-off-by: David Lechner --- drivers/iio/dac/ad5624r.h | 1 - drivers/iio/dac/ad5624r_spi.c | 62 +++++++++------------------------------= ---- 2 files changed, 13 insertions(+), 50 deletions(-) diff --git a/drivers/iio/dac/ad5624r.h b/drivers/iio/dac/ad5624r.h index 13964f3a22a4..14a439b06eb6 100644 --- a/drivers/iio/dac/ad5624r.h +++ b/drivers/iio/dac/ad5624r.h @@ -54,7 +54,6 @@ struct ad5624r_chip_info { struct ad5624r_state { struct spi_device *us; const struct ad5624r_chip_info *chip_info; - struct regulator *reg; unsigned short vref_mv; unsigned pwr_down_mask; unsigned pwr_down_mode; diff --git a/drivers/iio/dac/ad5624r_spi.c b/drivers/iio/dac/ad5624r_spi.c index 9304d0499bae..5a952b45f488 100644 --- a/drivers/iio/dac/ad5624r_spi.c +++ b/drivers/iio/dac/ad5624r_spi.c @@ -223,50 +223,27 @@ static int ad5624r_probe(struct spi_device *spi) { struct ad5624r_state *st; struct iio_dev *indio_dev; - int ret, voltage_uv =3D 0; + bool external_vref; + int ret; =20 indio_dev =3D devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; st =3D iio_priv(indio_dev); - st->reg =3D devm_regulator_get_optional(&spi->dev, "vref"); - if (!IS_ERR(st->reg)) { - ret =3D regulator_enable(st->reg); - if (ret) - return ret; - - ret =3D regulator_get_voltage(st->reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv =3D ret; - } else { - if (PTR_ERR(st->reg) !=3D -ENODEV) - return PTR_ERR(st->reg); + ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret =3D=3D -ENODEV) /* Backwards compatibility. This naming is not correct */ - st->reg =3D devm_regulator_get_optional(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret =3D regulator_enable(st->reg); - if (ret) - return ret; - - ret =3D regulator_get_voltage(st->reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv =3D ret; - } - } + ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); + if (ret < 0 && ret !=3D -ENODEV) + return ret; + + external_vref =3D ret !=3D -ENODEV; + st->vref_mv =3D external_vref ? ret / 1000 : st->chip_info->int_vref_mv; =20 spi_set_drvdata(spi, indio_dev); st->chip_info =3D &ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data]; =20 - if (voltage_uv) - st->vref_mv =3D voltage_uv / 1000; - else - st->vref_mv =3D st->chip_info->int_vref_mv; - st->us =3D spi; =20 indio_dev->name =3D spi_get_device_id(spi)->name; @@ -276,31 +253,18 @@ static int ad5624r_probe(struct spi_device *spi) indio_dev->num_channels =3D AD5624R_DAC_CHANNELS; =20 ret =3D ad5624r_spi_write(spi, AD5624R_CMD_INTERNAL_REFER_SETUP, 0, - !!voltage_uv, 16); + external_vref, 16); if (ret) - goto error_disable_reg; - - ret =3D iio_device_register(indio_dev); - if (ret) - goto error_disable_reg; - - return 0; - -error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); + return ret; =20 - return ret; + return iio_device_register(indio_dev); } =20 static void ad5624r_remove(struct spi_device *spi) { struct iio_dev *indio_dev =3D spi_get_drvdata(spi); - struct ad5624r_state *st =3D iio_priv(indio_dev); =20 iio_device_unregister(indio_dev); - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); } =20 static const struct spi_device_id ad5624r_id[] =3D { --=20 2.43.0