Received: by 2002:a05:7208:2202:b0:86:316c:7444 with SMTP id s2csp671411rbb; Fri, 31 May 2024 14:20:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUy6LpVTDPdTPQRoePeRaJzRh9dZfTLYxQWWt5taWZipt179FRdgaqETGq7C4vsdr8OssE0UOgOAzvD+wAbnZK7M/tf5bozS2ipfi8hHQ== X-Google-Smtp-Source: AGHT+IHSUs9s+hRoSS+dNDKOiC9mFAqRJEIRkM/Edp1AcZCx2olIpo/q/XIAOPkrs7zEhusipuv2 X-Received: by 2002:a17:902:d484:b0:1f4:5f66:895 with SMTP id d9443c01a7336-1f6370c30d1mr34779505ad.68.1717190423192; Fri, 31 May 2024 14:20:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717190423; cv=pass; d=google.com; s=arc-20160816; b=ZODY8Q/wf4rwya7Jy7Y9qwS9Gd/zrulBhqzFcWUTasFhQp+JBTPkuWngHPSy7Mn8k6 okTM97I5uF3s4uZuRDExuuCimWVlDd5zK+JE+fWnb9ZXhMHC7WCZo+2TuMbDi6NcvjrJ xuKkHI1t7+tFZ0NtiwIB9XdzoQZzDXbQLdqkZjroNeAzi2c7NhZwBFVvDf4TV8u9eHw1 kETyQNnHngqty2fc+9xD8M7wXM6JDUhwNYaJbByU5iEShTe5yeKffNMJxBQk30akZJD0 Y6tYAdrFVFtQsxgtrxzIP/L3k4dRb8wNZIwlLLMn7k0dzH1qLqXy3gvBKmRDkkUW+vt4 /sXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ckX290zz5uu8jKssyQCBCI0FA48FwJ1fiAxtXMtJpto=; fh=1Vabx4dJ5MqdWV9pFGBGXqxWDp2jwR1Kjw878q2aAhs=; b=iPUTCyG3LNF9qAE6IAKHijTIC2RkFCtkYkHjIcUK49ahU+SNh7JEMYcBv2P1a+so4C JRvXNmLbjvqxgAjqmVW25Fi4J5Pd1pljWC3q+xzAGlGOiFNKWY7qNGk7A1T6Q+PwPvEu UkxsEGMdyfwkzA45PFuRylfrpeMnCha7HmFQ1AtNCjibBZ0gMiOueoAspbEo/3GyZE36 CkvZhc7PBcnCAeI/c+lxI8T9AwpeXcDFRVZzSfAXUmLUgJ6Piv8S/3Pl4I4tG6Hacsi1 TUWI2zjgCt7O7e26augciWzGipukIVGgHsejvzBkU62EVklnklmjcrkE28RzvVNI0hKt Mjsg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=aEqPs0Z1; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-197497-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197497-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f63235f9c2si12612805ad.154.2024.05.31.14.20.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 14:20:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197497-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=aEqPs0Z1; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-197497-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197497-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 13E5D283E6C for ; Fri, 31 May 2024 21:20:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EAAD81AA5; Fri, 31 May 2024 21:19:48 +0000 (UTC) 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: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (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 4E3F63BB48 for ; Fri, 31 May 2024 21:19:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190387; cv=none; b=IgAgLe32VbxeFxhZ2cyPPnKUBKj8YcnzUHKYF8hP5rbznPpsGZ366Wx85Vv17xLZJF7VpwSekaEociqZ8ucpT/cWnFcv4i3wFIQ2uj3GbT9kUbVN/aNs7Twg63PBmiW6MzEbiZX5Bwzd/ECenFpjqeqi0c8c4Dr6iauDEfnotAA= 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.49 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 Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-6f12eb91ec7so1387433a34.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=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=r8syvUIBo2DPTlNs7Hs9OdXh0e3UNCyxxe9tmGl7PdpRQo/PIESdeE/lenB112mFdK 9mVjqCA0sWidt6duc7I/s4ik3F6V25TYP48lYbkSz3EiVpvnihpNspcUVqIKyThSohvg n6ro+bvBYQzF5u342ks+4TgbMxoR4qN6iYl3VfB0rUJFhci08iFaqn0pw4LeaD1xbv81 nQp0kB9/xobisUvXBILtjkln2zkKUbr1/8hy3OEUHV1MMvqZPNnaOekat8Lsq8O5W+wt zYEghaUHcIKIyp3xyovUcOVKpbNnWoFSsBq/KmshzSdLUEv0/oDQeKKT97xZW70A1/Co yxPw== X-Forwarded-Encrypted: i=1; AJvYcCVqMEXGLtSqOCgYZadoka9tFEgfFqVqBF+rmppEoJQgkV7WeGZ0S4ER17kdZ+9p97ybejjNm4QKczCRB3L+8JhwCZl0mK9aKJQQecWF X-Gm-Message-State: AOJu0YwTSxShMkX7YYdHrI/8p15vxf1HaC/B6SuZn5X1H79MKXbeABwv 9BAr17gXUh0JniFMqixq9TNpM1oaMQpS5+GSDeVCd44LpBxzOGZW9WH/Tx8vjuS3L6TUKxmfk4L / 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: 8bit 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; -- 2.45.1