From patchwork Fri May 31 21:19:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13682186 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 3DDB9208DA for ; Fri, 31 May 2024 21:19:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190387; cv=none; b=RTDPlRmXOFoQKx3uKCA2AgRBwB3qDj8E9/LORuLHMdXibYuEbf9eVLHgqMGIKAa25YYz9DynkPtKEXOqiT54tTQCtQ80w+tSONmKMAbFSEWVbFi6ZqQIRbbl8uIdFU1RaLXch5NhLiFrFc0Kv30qw7WPI67Fse0ESkvE9jXAoFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190387; c=relaxed/simple; bh=Qz8pW8yq0GC1/ubfC/aOUI5AKdBL3VfpTv0r8bnNztA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=galnx4tG2hbixSw3Y9MoT4xIPj1HMiPdoFbpmfWFLYMIs7H+db0FntYG2ORPa1aHzawd1gh2HbrGnOvN6p95zUR+Q0lkb1Nzox9/1d4FdipVL3FnU1Yt7Cx2l6l252RC7+km6NB6PxDeflm8cQe8v8Ntb+KxSlGg/t75UxqDCFI= 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=aEqPs0Z1; arc=none smtp.client-ip=209.85.210.54 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="aEqPs0Z1" Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6f8f56a30a4so1264633a34.0 for ; Fri, 31 May 2024 14:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717190384; x=1717795184; darn=vger.kernel.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=ckX290zz5uu8jKssyQCBCI0FA48FwJ1fiAxtXMtJpto=; b=aEqPs0Z11iMwdJcHZZjYcJRw/XhfVKHRqQATw6W9+u77wJ7hqXbaSfCVp34qYAjtJM vG2130og96zqUnX4/26gaAN0G10WNiiqRM1UP8Q+kYTrtiPXAiqgpZwdsn9Yb5OEG9Qj lTFS/vaIrJ9Me2Eb4D3DGZWqZ0cXQ948GpflQuWDIP4h1Usc4tYuz2MU9nFEDCSKMBZN eO9vh78TaY9bq2hmTWj4DKmIt5DCI1OUclod04OH43vdLoygwH2YhOBHAx9Ns2c4YTbQ t+N74neSsR7KVLgswYeBlNjfkqBEsFUMz9vlJt7wwi7OoNybUCn1isr75V1UaW7LKZ+3 9UWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717190384; x=1717795184; 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=ckX290zz5uu8jKssyQCBCI0FA48FwJ1fiAxtXMtJpto=; b=dztg9AkTSNUveBXBqNfoNqiKqjdY7LeSlD/jUkQeRkVMAF9i/mKKqKQSn1MWPQq8Gh xyyapHx4If60cssmnJdf7QspgMl5+LXPjlabknALjG/M/lO07htd09y4qL67iZQlVpka QVQZ1wBkDiGqix/YnLlw7Y632zPIEoZkxaAJJqJTO9qPRBNPmrv9IuYXDShphTZiaHoO FhacRYNXmdRDIsZ+JlmbmPt3NmU9NGn5dXD8CJfxQ4VkVxcNabsx2iypCaiTqDbmGFdS IplCZ3IyRr032mhOQmcY8oLwzS5kDI1KW1rHdUkWi9S9SkVg+XBSFlXbnUsovcdpzqoa keiA== X-Forwarded-Encrypted: i=1; AJvYcCWvbhiSDJck+DhVpF6LbU8zlus0BeFwDiPEQxIShVYtA/TsxnxY8FbTwEmUUpy0TNFTFXrHVBFIsCEWT1PkvXyOU/pdHgZbAHmX X-Gm-Message-State: AOJu0YwBxxiMEH9DTfszp1tfU6IoLUKIIk7Pb8LX6+bBEGV+gfhGqVfN lbYgYOE238KVkQeh3fvENRTK+WSYsa/vlgrwqZc7R8PoDiF9IZN+S/xxvKxpW0o= X-Google-Smtp-Source: AGHT+IEau7lS2dPKfMn6MIumlMT/ZA8JQPuE5qugKldj0LRxpSaUAlV7RFTk4iq5sKbMb8HEHld1VA== X-Received: by 2002:a9d:6548:0:b0:6f0:cf72:5d80 with SMTP id 46e09a7af769-6f911f9fa84mr2949949a34.30.1717190384232; Fri, 31 May 2024 14:19:44 -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 46e09a7af769-6f91054f6c5sm470176a34.38.2024.05.31.14.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 14:19:43 -0700 (PDT) From: David Lechner To: Jonathan Cameron Cc: David Lechner , Marcelo Schmitt , =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , Mark Brown , Liam Girdwood , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] iio: adc: ad7192: use devm_regulator_get_enable_read_voltage Date: Fri, 31 May 2024 16:19:32 -0500 Message-ID: <20240531-iio-adc-ref-supply-refactor-v1-1-4b313c0615ad@baylibre.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> References: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This makes use of the new devm_regulator_get_enable_read_voltage() function to reduce boilerplate code. Error messages have changed slightly since there are now fewer places where we print an error. The rest of the logic of selecting which supply to use as the reference voltage remains the same. Also 1000 is replaced by MILLI in a few places for consistency. Signed-off-by: David Lechner --- drivers/iio/adc/ad7192.c | 98 +++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 63 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 0789121236d6..e08bf066b3f6 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -200,8 +200,6 @@ struct ad7192_chip_info { struct ad7192_state { const struct ad7192_chip_info *chip_info; - struct regulator *avdd; - struct regulator *vref; struct clk *mclk; u16 int_vref_mv; u32 aincom_mv; @@ -1189,17 +1187,11 @@ static const struct ad7192_chip_info ad7192_chip_info_tbl[] = { }, }; -static void ad7192_reg_disable(void *reg) -{ - regulator_disable(reg); -} - static int ad7192_probe(struct spi_device *spi) { struct ad7192_state *st; struct iio_dev *indio_dev; - struct regulator *aincom; - int ret; + int ret, avdd_mv; if (!spi->irq) { dev_err(&spi->dev, "no IRQ?\n"); @@ -1219,74 +1211,54 @@ static int ad7192_probe(struct spi_device *spi) * Newer firmware should provide a zero volt fixed supply if wired to * ground. */ - aincom = devm_regulator_get_optional(&spi->dev, "aincom"); - if (IS_ERR(aincom)) { - if (PTR_ERR(aincom) != -ENODEV) - return dev_err_probe(&spi->dev, PTR_ERR(aincom), - "Failed to get AINCOM supply\n"); - + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "aincom"); + if (ret == -ENODEV) st->aincom_mv = 0; - } else { - ret = regulator_enable(aincom); - if (ret) - return dev_err_probe(&spi->dev, ret, - "Failed to enable specified AINCOM supply\n"); + else if (ret < 0) + return dev_err_probe(&spi->dev, ret, "Failed to get AINCOM voltage\n"); + else + st->aincom_mv = ret / MILLI; - ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, aincom); + /* AVDD can optionally be used as reference voltage */ + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "avdd"); + if (ret == -EINVAL) { + /* + * We get -EINVAL if avdd is a supply with unknown voltage. We + * still need to enable it since it is also a power supply. + */ + ret = devm_regulator_get_enable(&spi->dev, "avdd"); if (ret) - return ret; - - ret = regulator_get_voltage(aincom); - if (ret < 0) return dev_err_probe(&spi->dev, ret, - "Device tree error, AINCOM voltage undefined\n"); - st->aincom_mv = ret / MILLI; - } + "Failed to enable AVDD supply\n"); - st->avdd = devm_regulator_get(&spi->dev, "avdd"); - if (IS_ERR(st->avdd)) - return PTR_ERR(st->avdd); - - ret = regulator_enable(st->avdd); - if (ret) { - dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); - return ret; + avdd_mv = 0; + } else if (ret < 0) { + return dev_err_probe(&spi->dev, ret, "Failed to get AVDD voltage\n"); + } else { + avdd_mv = ret / MILLI; } - ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->avdd); - if (ret) - return ret; ret = devm_regulator_get_enable(&spi->dev, "dvdd"); if (ret) return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVdd supply\n"); - st->vref = devm_regulator_get_optional(&spi->dev, "vref"); - if (IS_ERR(st->vref)) { - if (PTR_ERR(st->vref) != -ENODEV) - return PTR_ERR(st->vref); - - ret = regulator_get_voltage(st->avdd); - if (ret < 0) - return dev_err_probe(&spi->dev, ret, - "Device tree error, AVdd voltage undefined\n"); + /* + * This is either REFIN1 or REFIN2 depending on adi,refin2-pins-enable. + * If this supply is not present, fall back to AVDD as reference. + */ + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret == -ENODEV) { + if (avdd_mv == 0) + return dev_err_probe(&spi->dev, -ENODEV, + "No reference voltage available\n"); + + st->int_vref_mv = avdd_mv; + } else if (ret < 0) { + return ret; } else { - ret = regulator_enable(st->vref); - if (ret) { - dev_err(&spi->dev, "Failed to enable specified Vref supply\n"); - return ret; - } - - ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->vref); - if (ret) - return ret; - - ret = regulator_get_voltage(st->vref); - if (ret < 0) - return dev_err_probe(&spi->dev, ret, - "Device tree error, Vref voltage undefined\n"); + st->int_vref_mv = ret / MILLI; } - st->int_vref_mv = ret / 1000; st->chip_info = spi_get_device_match_data(spi); indio_dev->name = st->chip_info->name; From patchwork Fri May 31 21:19:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13682187 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 75AAA78276 for ; Fri, 31 May 2024 21:19:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190388; cv=none; b=ks4zEhtGMo/9G7qwOASC3euYtRh+bezrA9JfsoEEbxFgEv/hk2a+6KaIfte2LlFZmhMyWFSvgcZwDAxKYCegg+c6BwNTVzfv315HsSAYBdhXhACP2nZgFI+TC5rDOg5xYg8sUV35A5sjl1amoDH6oNEp69IPfHCLs2uq0OCRA+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190388; c=relaxed/simple; bh=Js0YVyBPm/E3WxsjG5z4McvboiBRBwpr7xybmk/0tP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=grQlP8QagM6XG6wGDd03DUnVfQUHSnvJUwF3Mrod1WYYRpiACzSSS6K0KewIs/T/XX5azj/KvbXBZN7S3WO6A/OEu6gjivu2zb+R064DKixgj3ychAiFi1gOdFYo3eEyVsmag0xIfTgFR+8HaqVyS6cldoGA9OVrBND9Hym7Wk8= 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=TagLpnQC; arc=none smtp.client-ip=209.85.210.45 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="TagLpnQC" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6f8d2ec8652so1504670a34.3 for ; Fri, 31 May 2024 14:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717190385; x=1717795185; darn=vger.kernel.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=h6K6MHKU/orn8S+VKImZw/DZY35U7Zc26RBfAXI+Msw=; b=TagLpnQCDNYhpxS3acth5vPJhgVXybe8PVEs3xxaFsMZEry4W5oOfAQ4lLWzlA5UgH 4LP88Gj+SmwKcd8dA7TamR9BKdUvo/j72PEyq988UxC/ycnpa+aWdMC3QgMC96g0SMDf yZQiqddRzSwWS6bEtmVBPdULaF9ooJkRyir7UYqAxlnpzPfvvusleZM3kZtimTkrpxmz TPDMovmw0ZJJkzKOVcxvexKiyqII/iK1BcYfH0wsPUH/x+lwpRwg4EHrOHUgsOjq5lvU Op7MP7oyvf4v+U4VvtWAP3GVg2FkBQ22IcNSiB+uQPlOZo2lcDfUEp0YrKEVzP/fUU9I ZsSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717190385; x=1717795185; 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=h6K6MHKU/orn8S+VKImZw/DZY35U7Zc26RBfAXI+Msw=; b=ZjmZOjalcv8QIAAC5jklQOJRRugpeYoXpWvdKIGHZo1Fn2Ov2eZdA1dXKVXtoOul0/ 6CgkjiZgdTNFhusmHtUmfFJRc8VkVCqUzfZ9zOYHT6aInXiZyiMS+1i1xKdvKxNindLj Og9dkbRV8afXScgEgGlVvpkD366yPl5aYm4VhX/5E9qiD9izCC7tf4Yb2NVYkoLDItFR tWWcSSY2EpvT6K0uFxqR5q2m/j3fUjFkBtEP8uE7xIzBhLy7uEWhs6QiOhs4Vw9JdDbA NtikNIlm5Epu0LKELPoToNxQ3upaXg7PLTYPdaYaROz0pJn9AVxI03rvt1f23Hzrc3p6 juqA== X-Forwarded-Encrypted: i=1; AJvYcCXivcL2XZyGrYN+OjxHR2trY12ooXPdaUSg+weNYI4PYOAsrOfTJriw1KEiMItJ+i1MCg8HkSJI6X/I9KcaMsg6doqbYm1IMBIn X-Gm-Message-State: AOJu0YzDfTZQpOPp5fxu5TJMO7k3AbIY2AW9w34HR8JdnCyd796tN6H1 LbyjckjkdfmFuN9sfhdZcigOTUB3DqDA29M7vA44ihGJ4Mx7b5S/Q/LTHlywoSk= X-Google-Smtp-Source: AGHT+IE0Vyt+zzbJTkqMnIXs9WS274qnPNRombwHnz/DhsObFIFbFv8rZmMnOeEGBJQY3G9nmBrm3Q== X-Received: by 2002:a9d:6206:0:b0:6f0:e4b1:587a with SMTP id 46e09a7af769-6f911f23d9bmr3449349a34.8.1717190385136; Fri, 31 May 2024 14:19:45 -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 46e09a7af769-6f91054f6c5sm470176a34.38.2024.05.31.14.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 14:19:44 -0700 (PDT) From: David Lechner To: Jonathan Cameron Cc: David Lechner , Marcelo Schmitt , =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , Mark Brown , Liam Girdwood , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] iio: adc: ad7266: use devm_regulator_get_enable_read_voltage Date: Fri, 31 May 2024 16:19:33 -0500 Message-ID: <20240531-iio-adc-ref-supply-refactor-v1-2-4b313c0615ad@baylibre.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> References: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This makes use of the new devm_regulator_get_enable_read_voltage() function to reduce boilerplate code. Signed-off-by: David Lechner --- drivers/iio/adc/ad7266.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c index 353a97f9c086..026db1bedc0a 100644 --- a/drivers/iio/adc/ad7266.c +++ b/drivers/iio/adc/ad7266.c @@ -25,7 +25,6 @@ struct ad7266_state { struct spi_device *spi; - struct regulator *reg; unsigned long vref_mv; struct spi_transfer single_xfer[3]; @@ -377,11 +376,6 @@ static const char * const ad7266_gpio_labels[] = { "ad0", "ad1", "ad2", }; -static void ad7266_reg_disable(void *reg) -{ - regulator_disable(reg); -} - static int ad7266_probe(struct spi_device *spi) { struct ad7266_platform_data *pdata = spi->dev.platform_data; @@ -396,28 +390,17 @@ static int ad7266_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 = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg); - if (ret) - return ret; - - ret = regulator_get_voltage(st->reg); - if (ret < 0) - return ret; - - st->vref_mv = ret / 1000; - } else { - /* Any other error indicates that the regulator does exist */ - if (PTR_ERR(st->reg) != -ENODEV) - return PTR_ERR(st->reg); - /* Use internal reference */ + /* + * Use external reference from vref if present, otherwise use 2.5V + * internal reference. + */ + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret == -ENODEV) st->vref_mv = 2500; - } + else if (ret < 0) + return ret; + else + st->vref_mv = ret / 1000; if (pdata) { st->fixed_addr = pdata->fixed_addr; From patchwork Fri May 31 21:19:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13682188 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 2698F78C91 for ; Fri, 31 May 2024 21:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190388; cv=none; b=PLwGZx44a+cSbAfugXeB3lZ3lFYHVWbKiRZzo8dyd+GU80QuGI+lys5cJOrvc0K6Ky5JBqz0/pcPQ8+jjP34aK7LjgmFLHpuh0/G5vaElKAVjGb+hjep+5OhwPcwXdWplaNW5UWIYQMaS2JoOFIos6PAanmaDxm8HjkwbjL5cow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190388; c=relaxed/simple; bh=Rk5dJF2+TsUg7IjzcoRV/lfTyzQjoNRqKiXdm3UK0Cs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jTnOwvu9/NREAKxcSPH+dMJzs0zHtsbCfClHiUM/U5iBU5Y2GLbG8/EdiUhufZPGBDRzWSu9tKu78p0cRdZhNix7U62rBJP3OQ73Vrw6CjWHVmq36dcWaMtWwFFh2sVpZeRFeklFxUoH+veG2HEXs2hDV7r/6UG6EZal8JP9isI= 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=107lfdKu; arc=none smtp.client-ip=209.85.210.52 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="107lfdKu" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-6f12ff2da3fso1374726a34.3 for ; Fri, 31 May 2024 14:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717190386; x=1717795186; darn=vger.kernel.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=9A//l2lq6uILJm9YAojX9V6DCWgOioR04paBfYh0fho=; b=107lfdKuw0FJ0OAefK4gEdmGxm68DVH97Usj30qV9cLCS3ZPsiJgJLf2+Lu20P5czW L2hrB5cKF+oK3itpwoQXLTFhbn8bG4PiECdOozsUgYjqqEFIfs9+j78oOWzS1HaIvQUW aBz6s7qo2xrwztNqN/zY5fsShCFPK4v7mXfI2rAD3RIn6Kb3KUaihDrqhMBPGVRtZfoy kYFJmExIcbb0jw53hykMFWbs+1rQ2OnVolRd5eNYf6JmQY4ndWdq8qFXZQ40VMji/e9G u23EGuR+X8qcw01f2H/ew9xSNZJD2eQDE7lV4HXf1NqK1us7fmMUdQe6asYwNl7wD/7s r6sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717190386; x=1717795186; 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=9A//l2lq6uILJm9YAojX9V6DCWgOioR04paBfYh0fho=; b=JT9sSXEMSu/j08MtmDCK0HWsfMaoNH1VDfy22dsK0dgxCA3ivoq9LduyNHZ6QljGuf 5lFaswhdDFcUW9pzIGqlNl37vjh3rf0dK8z8TzdlSBlzeWO2z24oFaPioP8tQaR/YSCE 6CxPccWatDuFf7GTl0tGmCMxZB2RekaDKgqluDukAm/385EFT99tcEj2Fxp7Yc7Fm4Ny rVQT6/wQ3Jm24zb8oQeJTqiVWaYYtF+LzEZt2dUN6ycDGD4rTH6L3zrk9kusN85WFfM7 O/NEVpDK3VkZhTvQE6JET8KDjgSpLmBuzwmQyfO/vtwoAqGhCjdOzzTC23wpPNPnvtM6 GoWg== X-Forwarded-Encrypted: i=1; AJvYcCX67lf7PY1l2VrkVkELodJHOVxTBm3ixsPexWbTCqaDNE4h9trviCd6mWeHROvXJsDJWEWq9Dlfy6+4Xk2mZkMViwB/ghq9rJSi X-Gm-Message-State: AOJu0Yx7likGdkoZPf6cA2UmzsKHAAuMGCg+y8sllGeQJLXXNggoQ1mg v8I2Q4WD2bSDnVfeXoWlXmaSZslIyM2zz1qm7gwmGjFgk4ae1oLJYMPj5kGD1yM= X-Google-Smtp-Source: AGHT+IFZqCqnS3kUd3hk3iucp3Cuy8ZZvP7npz4Meb1RMFDg8tPygLXtuWL/5NNZMCRB8EHI2oNxdw== X-Received: by 2002:a9d:66c5:0:b0:6f8:f355:8c08 with SMTP id 46e09a7af769-6f911f3fe70mr3122093a34.21.1717190386027; Fri, 31 May 2024 14:19:46 -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 46e09a7af769-6f91054f6c5sm470176a34.38.2024.05.31.14.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 14:19:45 -0700 (PDT) From: David Lechner To: Jonathan Cameron Cc: David Lechner , Marcelo Schmitt , =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , Mark Brown , Liam Girdwood , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] iio: adc: ad7292: use devm_regulator_get_enable_read_voltage Date: Fri, 31 May 2024 16:19:34 -0500 Message-ID: <20240531-iio-adc-ref-supply-refactor-v1-3-4b313c0615ad@baylibre.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> References: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This makes use of the new devm_regulator_get_enable_read_voltage() function to reduce boilerplate code. Signed-off-by: David Lechner Reviewed-by: Marcelo Schmitt --- drivers/iio/adc/ad7292.c | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c index 6aadd14f459d..aad4b782a3d2 100644 --- a/drivers/iio/adc/ad7292.c +++ b/drivers/iio/adc/ad7292.c @@ -79,7 +79,6 @@ static const struct iio_chan_spec ad7292_channels_diff[] = { struct ad7292_state { struct spi_device *spi; - struct regulator *reg; unsigned short vref_mv; __be16 d16 __aligned(IIO_DMA_MINALIGN); @@ -250,13 +249,6 @@ static const struct iio_info ad7292_info = { .read_raw = ad7292_read_raw, }; -static void ad7292_regulator_disable(void *data) -{ - struct ad7292_state *st = data; - - regulator_disable(st->reg); -} - static int ad7292_probe(struct spi_device *spi) { struct ad7292_state *st; @@ -277,29 +269,17 @@ static int ad7292_probe(struct spi_device *spi) return -EINVAL; } - st->reg = devm_regulator_get_optional(&spi->dev, "vref"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) { - dev_err(&spi->dev, - "Failed to enable external vref supply\n"); - return ret; - } - - ret = devm_add_action_or_reset(&spi->dev, - ad7292_regulator_disable, st); - if (ret) - return ret; - - ret = regulator_get_voltage(st->reg); - if (ret < 0) - return ret; - - st->vref_mv = ret / 1000; - } else { - /* Use the internal voltage reference. */ + /* + * Use external reference from vref if present, otherwise use 1.25V + * internal reference. + */ + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret == -ENODEV) st->vref_mv = 1250; - } + else if (ret < 0) + return ret; + else + st->vref_mv = ret / 1000; indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; From patchwork Fri May 31 21:19:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13682189 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (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 EBDB381207 for ; Fri, 31 May 2024 21:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190389; cv=none; b=prVkeHBeHKPlimZdaOYEX1ysyWwqnr2TKyLUh6wcaK2Tz+LtChnnVtRlDeaOwGSyU05ZHFPul4Hjo6AYRCyzLipm9AKggYFhPWDf+5ZtHfEdYUQe4YLzJF1SDGvXeCtZer+ylF/udr8m/RbxAiNbEKV8wufZ6aow9qesJUPH7vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190389; c=relaxed/simple; bh=djS+IstEEdXks4E5EEDzjApEn0V5RdWip5LOqYcuvWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ahYN551rLe5vGDbHU4Fe4fdXtP6VkijD17jerhNJ2BcBrhzklogwWF4SV36HVQJrXSb6liKrA59jtU0BrKzYt720/rNZaDLYzFYGF1Wkr8ZqrlMPN0xagGXEtAoagoODr4EapgEYH7pCy1kvqyasElgsbdO6h5XrYKenfj0gvV4= 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=tSRAnerk; arc=none smtp.client-ip=209.85.210.43 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="tSRAnerk" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6f8d0a1e500so1932614a34.3 for ; Fri, 31 May 2024 14:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717190387; x=1717795187; darn=vger.kernel.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=YbruLAt03fLjpCxeoEnwGhqppmXvGlKTLyJ4VcLSIfs=; b=tSRAnerk5KRJEGjFE5vM/YlwMV836v+xL2j3odbVfO+oWstKhUHtnx0u1G/ZP7Zx7g rSA4oVy9z7Kp/mYpeJfDhBIiga2sYY7V79kZ9QSIWiHTYuABQIDKlEuLq8pd6uY3ZgXb s3Wjnuyt6Df6tvSX4vSmDHK9jLjC22p4Dji0zYTPJJziwfcOpiWx9B4OA9SLQchiz+NY 0qkjCqqpbUPDWGuiRggXxZs+lig9hKmvzxRVEjBOsxgAooLS/NBjRjpJrNMm6eeONmnJ maWYQvHWPj9BoC40kgtlsFrL2qq7399K1WrihnZXqZx6MQaDdstqA7bXkQ11tVHBemNc uM8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717190387; x=1717795187; 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=YbruLAt03fLjpCxeoEnwGhqppmXvGlKTLyJ4VcLSIfs=; b=fpaWmg3Dc1FePasf2CwqSlSc0YezhPymTAfFuLR2FGfkz1Q8B6BUZRgdSwwJyCZd01 mqOuUB9uYuxpRgjgM3jXSlUS7QK22UVuOrLnL/IwX/u4wHN5HsC8EonFMJzZLn2w+rIe +q54Vr7rrNvCWDI+R/RPXdJ2j8qPchfUF3w2f/UUTmWZVI0POi1XxdWEuFdG+cROAsUo HKl4kAQgXx4DbB2Tl/mplwfN8hH58Hml6vBhtV4GNFFVrJkHZ+rxpklqd5f6u6aBRoR+ GB6zKaNbQ7y4lAK8UVo0yoiaVi2rk4/Q7oVP+csVT9W2qnRSE1di72rlYzJO8jg5Vltq 1JEA== X-Forwarded-Encrypted: i=1; AJvYcCXIP8yNR1ILwp0kyzRp68wNI1xcTDh4QxjsWHSgc9gz2r+9lgW+eSsXAYi8vYE4zS6SGilPIqolruRTICfWPoeKXU0hyB+Y3GoT X-Gm-Message-State: AOJu0YxeZyMfZT78Z6WVto6etY3qzk2uAH5VDrk8zDIsT2Tf9kBRrUE+ Qm/P6b+04yjPhxQvRPzv37GRWm1fmFnqAG4nAVKSblX1HFQyDUha3LT4zU4pDJQ= X-Google-Smtp-Source: AGHT+IFkz+cdXrbneX907Jl5UcLu0PioPNnv+0/npiT6mmWiF18kZTPeeLG91XQTRcQYGozZr/qoBw== X-Received: by 2002:a05:6830:1e52:b0:6f0:6864:eee6 with SMTP id 46e09a7af769-6f911f2fea3mr3079003a34.10.1717190387135; Fri, 31 May 2024 14:19:47 -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 46e09a7af769-6f91054f6c5sm470176a34.38.2024.05.31.14.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 14:19:46 -0700 (PDT) From: David Lechner To: Jonathan Cameron Cc: David Lechner , Marcelo Schmitt , =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , Mark Brown , Liam Girdwood , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] iio: adc: ad7793: use devm_regulator_get_enable_read_voltage Date: Fri, 31 May 2024 16:19:35 -0500 Message-ID: <20240531-iio-adc-ref-supply-refactor-v1-4-4b313c0615ad@baylibre.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> References: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This makes use of the new devm_regulator_get_enable_read_voltage() function to reduce boilerplate code. Signed-off-by: David Lechner --- drivers/iio/adc/ad7793.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c index 5f8cb9aaac70..d4ad7e0b515a 100644 --- a/drivers/iio/adc/ad7793.c +++ b/drivers/iio/adc/ad7793.c @@ -152,7 +152,6 @@ struct ad7793_chip_info { struct ad7793_state { const struct ad7793_chip_info *chip_info; - struct regulator *reg; u16 int_vref_mv; u16 mode; u16 conf; @@ -769,11 +768,6 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = { }, }; -static void ad7793_reg_disable(void *reg) -{ - regulator_disable(reg); -} - static int ad7793_probe(struct spi_device *spi) { const struct ad7793_platform_data *pdata = spi->dev.platform_data; @@ -800,23 +794,11 @@ static int ad7793_probe(struct spi_device *spi) ad_sd_init(&st->sd, indio_dev, spi, &ad7793_sigma_delta_info); if (pdata->refsel != AD7793_REFSEL_INTERNAL) { - st->reg = devm_regulator_get(&spi->dev, "refin"); - if (IS_ERR(st->reg)) - return PTR_ERR(st->reg); - - ret = regulator_enable(st->reg); - if (ret) - return ret; - - ret = devm_add_action_or_reset(&spi->dev, ad7793_reg_disable, st->reg); - if (ret) + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "refin"); + if (ret < 0) return ret; - vref_mv = regulator_get_voltage(st->reg); - if (vref_mv < 0) - return vref_mv; - - vref_mv /= 1000; + vref_mv = ret / 1000; } else { vref_mv = 1170; /* Build-in ref */ } From patchwork Fri May 31 21:19:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13682190 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.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 034768248C for ; Fri, 31 May 2024 21:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190390; cv=none; b=Lxv4z7x9YXZ4zdO62MidXJqgyKm+x9wrHFXviNwxLY70vCgA/VggZX5GDcAIPRB2t1kLsgVrmhHphKoSW/MXENJ9+r5m9rBkRI+54j/O2e2KWXvZKkDDCRsCUCuUjUagAMyKrtItW+QnPH/s5gHGZoaU42vrf50xKF/7hw3Cwl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190390; c=relaxed/simple; bh=cTiNyK1ys4ahQNaXNuf6ikv8kxy/TxXonMWyDgt/QB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uMLAJE57TaVtW0LUae8TaBIFzyuUzSUk01QX9wlRdBuysTc4+3xA6bAA+9mWgMmYwY63i39wVRxfO+MsAZjCgVv5ZUDQDXQ4BHVJCIFc+YakYF0DM0S4LIwgE13Mo6Cvm8kRAYmrXQrzbOM61856Jc8TKLrSO9B2kqlukmslN9o= 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=dmRLypdA; arc=none smtp.client-ip=209.85.210.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="dmRLypdA" Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6f12ff2da3fso1374739a34.3 for ; Fri, 31 May 2024 14:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717190388; x=1717795188; darn=vger.kernel.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=qx10f6FDnpDWXmsP3ksz4V0Ywa+gZQfSKGlvjoHLNnA=; b=dmRLypdA+V/mDE1CFkoDEtGHeMt499zJ6SlLgJG0P78ZREWzY9dU959JQEQiclukIn T7Jhv0v8qUKab9EpxpdlUQj0VfCjGXcQBYTvhKNcx3d5vtpZHoPpwgA6jSie8s64ryFk 7l6tZfqA+s/FmedYqerBP/elAd5oQ2y2FacPlPCkZMOwvKT/iL1Uf7zYxscxBHaKLdiT +YEPrDT7EpkLiu0O5QP38Xi/sZnHZYbsqQ5eMSnPet/7KblQz8nphDEGWIRAl4Vdl/7h owBlz0z5EKmjUp9JbwCUIJxCz6Kext8AXb0/ocnj7VCyS7g6hnHoG6R/kIf+Wm99iZjm N7hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717190388; x=1717795188; 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=qx10f6FDnpDWXmsP3ksz4V0Ywa+gZQfSKGlvjoHLNnA=; b=NjSwxwGkHfBkxZYgEqkHsyYK0CW4e4had//p3V7H4tLy+0iljDEprwRG1GwlZ0fgLA wyskMpZBZrfEI4JEjp853plIYQ/50+VXtNmk9LDC6pxa1b4wKGMQU6MU7VZvZTSHUiwR u88uJa5jzEVrGcYsvjZhVN7D87XdJIXSigQUVkqwE5HwKG/aab8PG+fb5iLp37SNzfAC yT8mO65evHa2W83mjPP9tzdvmG9BG/kL3jvRP7woaxhUDUsQ59WTVG9vzgtPZ2We46On SjfEaVFCim0Cmy+fiYDWOhLYnu4FOMkb4cOtF43FnIslu3YqA+FteRiyWEWLaFnjaHZc xJJg== X-Forwarded-Encrypted: i=1; AJvYcCUwrUSHv1mJamSQnJzoNDjNYXtGHH32N5oltMfGu1mIB1PU4w9an58gpu+GdgF788Qbyye+fGbpbcHD9QYOdZsSPTqz96z5Hmsa X-Gm-Message-State: AOJu0YwjElPHKxHXe6wOGQXsHDsupc/sd7qMIGg+yKea/Zv5tXL/Z0dp s3m1DIJDBkPBsEJNBcElEJ/UyO2nV4G5+4ggIsLpjnmncm1MTAJZ07xpj53nGH0= X-Google-Smtp-Source: AGHT+IHecu+MAUNmrjh2sKi9JnDPh/FwFOg+MlU6Ki9NaEl1LqgtU9wELvhFrSYdVexLapJxPEZI9Q== X-Received: by 2002:a05:6830:151:b0:6f0:5cd9:d5de with SMTP id 46e09a7af769-6f911f3fe26mr3085558a34.18.1717190388071; Fri, 31 May 2024 14:19:48 -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 46e09a7af769-6f91054f6c5sm470176a34.38.2024.05.31.14.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 14:19:47 -0700 (PDT) From: David Lechner To: Jonathan Cameron Cc: David Lechner , Marcelo Schmitt , =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , Mark Brown , Liam Girdwood , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] iio: adc: ad7944: use devm_regulator_get_enable_read_voltage Date: Fri, 31 May 2024 16:19:36 -0500 Message-ID: <20240531-iio-adc-ref-supply-refactor-v1-5-4b313c0615ad@baylibre.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> References: <20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This makes use of the new devm_regulator_get_enable_read_voltage() function to reduce boilerplate code. Signed-off-by: David Lechner --- drivers/iio/adc/ad7944.c | 62 +++++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c index e2cb64cef476..42bbcb904778 100644 --- a/drivers/iio/adc/ad7944.c +++ b/drivers/iio/adc/ad7944.c @@ -464,23 +464,16 @@ static const char * const ad7944_power_supplies[] = { "avdd", "dvdd", "bvdd", "vio" }; -static void ad7944_ref_disable(void *ref) -{ - regulator_disable(ref); -} - static int ad7944_probe(struct spi_device *spi) { const struct ad7944_chip_info *chip_info; struct device *dev = &spi->dev; struct iio_dev *indio_dev; struct ad7944_adc *adc; - bool have_refin = false; - struct regulator *ref; struct iio_chan_spec *chain_chan; unsigned long *chain_scan_masks; u32 n_chain_dev; - int ret; + int ret, ref_mv, refin_mv; indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); if (!indio_dev) @@ -531,47 +524,30 @@ static int ad7944_probe(struct spi_device *spi) * - external reference: REF is connected, REFIN is not connected */ - ref = devm_regulator_get_optional(dev, "ref"); - if (IS_ERR(ref)) { - if (PTR_ERR(ref) != -ENODEV) - return dev_err_probe(dev, PTR_ERR(ref), - "failed to get REF supply\n"); - - ref = NULL; - } + ret = devm_regulator_get_enable_read_voltage(dev, "ref"); + if (ret == -ENODEV) + ref_mv = 0; + else if (ret < 0) + return dev_err_probe(dev, ret, "failed to get REF voltage\n"); + else + ref_mv = ret / 1000; - ret = devm_regulator_get_enable_optional(dev, "refin"); - if (ret == 0) - have_refin = true; - else if (ret != -ENODEV) - return dev_err_probe(dev, ret, - "failed to get and enable REFIN supply\n"); + ret = devm_regulator_get_enable_read_voltage(dev, "refin"); + if (ret == -ENODEV) + refin_mv = 0; + else if (ret < 0) + return dev_err_probe(dev, ret, "failed to get REFIN voltage\n"); + else + refin_mv = ret / 1000; - if (have_refin && ref) + if (ref_mv && refin_mv) return dev_err_probe(dev, -EINVAL, "cannot have both refin and ref supplies\n"); - if (ref) { - ret = regulator_enable(ref); - if (ret) - return dev_err_probe(dev, ret, - "failed to enable REF supply\n"); - - ret = devm_add_action_or_reset(dev, ad7944_ref_disable, ref); - if (ret) - return ret; - - ret = regulator_get_voltage(ref); - if (ret < 0) - return dev_err_probe(dev, ret, - "failed to get REF voltage\n"); - - /* external reference */ - adc->ref_mv = ret / 1000; - } else { - /* internal reference */ + if (ref_mv) + adc->ref_mv = ref_mv; + else adc->ref_mv = AD7944_INTERNAL_REF_MV; - } adc->cnv = devm_gpiod_get_optional(dev, "cnv", GPIOD_OUT_LOW); if (IS_ERR(adc->cnv))