From patchwork Wed Jun 12 21:03:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13695578 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (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 0842B126F02 for ; Wed, 12 Jun 2024 21:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226202; cv=none; b=NNlrZPc/oAFkl0Yfh+EBW9NOCK8XrLFte+fTcVDMDIgiRT1Mi1mpXEOHKeKwVe/x15MfptyjjL5TDa/UM6v6Tm3zyUOoDQbaquoSJHizEjBi0lHFWC7d2fdN5QVOxLrwfEU5lsoFq4rstWBLUPMqZxX7SfGQpjlqQ+HtTt2Q5JA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226202; c=relaxed/simple; bh=vc0wQLAQuMRAyELjvGU21hVTnrdkk+B+80Fp46TOhLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NinVmGVdagqPgoD3LB8sZON8s6upUuAiS7/dVMyxCyJAd0PdLvtBLZYwYBObb6dfQM8qSbcmV6hn+g0sEbXESGLOwE2cdGxjV0BxqqudC3805/90njL0OS9kzHt6p0Gkhjx5Xb7AGMMhEshZ9KW7ySioqt8mchw4dDdiVE6sg/4= 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=ODTpRE24; arc=none smtp.client-ip=209.85.167.171 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="ODTpRE24" Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3d227b1f4f0so111565b6e.3 for ; Wed, 12 Jun 2024 14:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718226200; x=1718831000; 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=V6phvgA6PKlI7Rsgp8QhIcT0Puar9wQt5/4QK7wk+xs=; b=ODTpRE24Yyq7TCx0ziq4zsUDnttyP4NQNmw6qjMDHu6Gmh+qcCpm3qpqCGyH4SLVcK XkRA9BnBLPzKg5Wrd5zAmyk1FqpXojUNqhEZgMNpXciNaofqqnXOTVc0nVW9lruKEs/k COQQxBMfNPcvSwbkchtOY8eMhTh+rSh/8pi/sfk7IA7ZTW8NLX6HnU2aaXmSfWY2z1/5 X/VYr0JvOekKb9MsFyJZu9Qo6gQsn/UURE48nwIXQuHLDb2FJWCxz1VZddvd7jHYJilo p6yIEQ4QLYeBxswV9FPTT1f7NFzm0RF8WdprLKvbAXdaOid34/pDmm/rcjlV6tfE0od9 Ju6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718226200; x=1718831000; 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=V6phvgA6PKlI7Rsgp8QhIcT0Puar9wQt5/4QK7wk+xs=; b=Q+ZRktn/x/hybzGAN/YguxS1z8qvbbOugCGSg2RIZb8XDXcGE9KDE4lro75im+DGT2 Ta/Xvw60eWfIbsk63F7CwE7VHuN9zmOdF/hsF9Hor6UKjKrNDdVtn3CzuWR8CU1sQWH9 9jSuaMCN8rXH2eybOC1cd02z4Vabf3x+bFv6wfPplI+MTOPOq2NJ48Gs8ny2gM+QwwfJ o0NfnQgcwmhDhzMmyXtynyL2IOACfxN13uRKfEAfcIWaCs9fCd3qZFif6x2tfmp53K3c O7NM1Z0liPeTXt+3lWRlyFyOzR/SHRy9p1BFmZWXgpg+RQKI9Gyb3QLh89xUv1FaUNzp At4g== X-Forwarded-Encrypted: i=1; AJvYcCVQPJOwp1TZq0dFoMW52cxhDa06k8DJlRuK/KqNVBahgGUIKRACQZaHFTHtBpQLjAcuLjARVIYxC531MNLKKj7F7OjNf4KsG+c/ X-Gm-Message-State: AOJu0Yx6Wt4mrdqt+6mqcFWisQ4hqHfih9Iw6TEIODl8/8yORT4CcFQ/ YPUaHTpctHlwmJqnJv/FlhTOh3OxQjFfr2CmPHnE3+PhCXzAxIO/LJISd0KfzNo= X-Google-Smtp-Source: AGHT+IEnh8HX9zJsqhJ8nU/HGtmIfcg8BsqljTsGbB9Qo4c5ZfFEkouPBvBHLlNZasDRiQIrBh4oDg== X-Received: by 2002:a05:6808:2288:b0:3d2:2334:67e5 with SMTP id 5614622812f47-3d23dfd9dd9mr3384141b6e.4.1718226200044; Wed, 12 Jun 2024 14:03:20 -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 5614622812f47-3d20b68f5a1sm2433368b6e.23.2024.06.12.14.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 14:03:19 -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 v2 1/5] iio: adc: ad7192: use devm_regulator_get_enable_read_voltage Date: Wed, 12 Jun 2024 16:03:05 -0500 Message-ID: <20240612-iio-adc-ref-supply-refactor-v2-1-fa622e7354e9@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@baylibre.com> References: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@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 Signed-off-by: David Lechner --- v2 changes: - avoid using else on return value check of "aincom" regulator - also fall back to dummy regulator on "avdd" in case of ENODEV --- drivers/iio/adc/ad7192.c | 100 +++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 65 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 0789121236d6..409c73d16460 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,52 @@ 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"); - - st->aincom_mv = 0; - } else { - ret = regulator_enable(aincom); + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "aincom"); + if (ret < 0 && ret != -ENODEV) + return dev_err_probe(&spi->dev, ret, "Failed to get AINCOM voltage\n"); + + st->aincom_mv = ret == -ENODEV ? 0 : ret / MILLI; + + /* AVDD can optionally be used as reference voltage */ + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "avdd"); + if (ret == -ENODEV || 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 dev_err_probe(&spi->dev, ret, - "Failed to enable specified AINCOM supply\n"); + "Failed to enable AVDD supply\n"); - ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, aincom); - 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; + 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; } - 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; - } - - 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 Wed Jun 12 21:03:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13695581 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (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 4FCC8127B57 for ; Wed, 12 Jun 2024 21:03:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226205; cv=none; b=Ypw5A/1TTrrgnNWcEss6gO7lWHdBAplszXGNFbrkzlNF7oh3jc1vGaGLh7X8A5W3aE+2tJ4oJuTG1PYxoLz+1w46NZAq8u7UgUvkQyG3D6omNZ/CRrXioUhQTf95GbcSibCl+pN5afytWIRK0pVYx01BjhcI5LUxHps1SSuI8vM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226205; c=relaxed/simple; bh=xZMj+Tp3hfugjb8DvqlKp+tQ02YG9Qbq10/c7lYjPNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fTNwCrb8wGIZ/APa4VvhIlmG+DlHWfqUXbOcihlxPp/WZx1dA2/edkufiIGdhBhayntPfWawjfu3nAd8qHoTW3nhl3TbldKxeBR+rbM7frbJbg50q9XtKLgdrdbNT16hsBXcJaSTCGyybEorfcTB7FYD/JGzm4pg6iiGPE4IWSE= 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=WMtQYTWP; arc=none smtp.client-ip=209.85.167.176 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="WMtQYTWP" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3d229baccc4so120943b6e.1 for ; Wed, 12 Jun 2024 14:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718226202; x=1718831002; 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=4hWOcNN+TXQI0vHdkxWXGyQx3IUvNG0BoVco9Tkt4lU=; b=WMtQYTWPPAPiKOeMyzal1EOjqkkz761SLE62WWRTdznahkKHVO7+FxLxGLxy1l3YAE C5IG36NAUu8hv2v6QT/ZsQaMoNOH2sOmwwgJMwAe98lokLT9xn+dYEhIzoTmEBaXIYps dDxueaP5Lp5fAkcSGg1tIOJYm4NFgNKyZN8da0f/OBHkg//z7WyumIhYwrJkOohKMjeZ hDL/NduMXdiDVqq8dxBEbUO3UdBoit0wPKGi4xHRnSknbaJ/e946VJXmuctqzm4hMFGP 0sbpyjBeEipjIZvgQdTQaU8ZG3S9alER5Z9QVphXlzWAP57wpTQp4gIxl1k9HpMWcgh/ Xrsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718226202; x=1718831002; 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=4hWOcNN+TXQI0vHdkxWXGyQx3IUvNG0BoVco9Tkt4lU=; b=nPWpRGeYMXnuvixdMP4E4q5bzl3M7T7UkzKbO3YIv9Rv0C+FXW0w+JLXzIBCT4UhUQ ZT1vGuR09CFDvaR9ZsoxcsHtn3fG3GiUeaWf1e6VFAbb0vyxS4V65SYF8DE2GVFYzzp7 ucs+GJOGLb2Xg8OqrbU1psPIyA34vmRFoQiPXQob8YGA7iJvke3eDxLw0RImDKnVQi2K AiYn8HriqS6kieIEvw3hG4HX76rF64cOAelXuXIqYnuOWXXOTGvq5LAmcufQkyr5Xvju Db3A7TGUZ4+2jggtqcLtGNQzwuUzXKA2sRP3+CjupC2o77sk1LCwdg17VYtgFkrJGike 0+xw== X-Forwarded-Encrypted: i=1; AJvYcCW/Q4UW7oCuZBpFkxlR7S/RfpLtnSjUiXmo5RQaV8ikE5XaOKvM15mfEyTmKkGcASCnlMgm7eZ8e6Bzn6wLYklmhPphqgSSLRrC X-Gm-Message-State: AOJu0YyVY1DN9btddsfUCEfT8iISH0/aoQrP73rve656KCuSGb/9hq/U QGrf5eTqdiGXZcRLxrvB7yamLhpYLUMZuHm5P0tax5vQRu5K3BXPdgQutV8CgK4= X-Google-Smtp-Source: AGHT+IEvviefEF6MK/t/Fpys2OCFvkv65Rxyl1H+DXe8N4+AZUg+8PjNV9RiCoXtmE2DqYHfirZ9Ug== X-Received: by 2002:a05:6808:1456:b0:3d2:303f:ff3a with SMTP id 5614622812f47-3d23e11d1d5mr4109776b6e.51.1718226200831; Wed, 12 Jun 2024 14:03:20 -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 5614622812f47-3d20b68f5a1sm2433368b6e.23.2024.06.12.14.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 14:03:20 -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 v2 2/5] iio: adc: ad7266: use devm_regulator_get_enable_read_voltage Date: Wed, 12 Jun 2024 16:03:06 -0500 Message-ID: <20240612-iio-adc-ref-supply-refactor-v2-2-fa622e7354e9@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@baylibre.com> References: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@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 --- v2 changes: - avoid else in return value check - use macro instead of comment to explain internal reference voltage --- drivers/iio/adc/ad7266.c | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c index 353a97f9c086..874d2dc34f92 100644 --- a/drivers/iio/adc/ad7266.c +++ b/drivers/iio/adc/ad7266.c @@ -23,9 +23,10 @@ #include +#define AD7266_INTERNAL_REF_MV 2500 + struct ad7266_state { struct spi_device *spi; - struct regulator *reg; unsigned long vref_mv; struct spi_transfer single_xfer[3]; @@ -377,11 +378,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 +392,11 @@ 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; + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0 && ret != -ENODEV) + 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 */ - st->vref_mv = 2500; - } + st->vref_mv = ret == -ENODEV ? AD7266_INTERNAL_REF_MV : ret / 1000; if (pdata) { st->fixed_addr = pdata->fixed_addr; From patchwork Wed Jun 12 21:03:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13695580 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (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 AB0AA126F1E for ; Wed, 12 Jun 2024 21:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226205; cv=none; b=o9SWV3OHux7zSiJmkDQxlMXYcRNbKRm5Gonr0tWUmv8+vriq00hWSFilCLEo6XP0M3ojN0PinCtqNGdLC9LMphCQd+rVmE9qiTlcT4rNM1N+wclvgHIqe8j1MCjftnr6lZIbOtihDK4UFHuIWw3nh8EKH9sUXZIcC1GIOVn0C+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226205; c=relaxed/simple; bh=RQGZCDhf9GURnEWrVzA4GpPy1QAW6p5jP0M4N6GMfTg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kkRhEHmfm0sh7ra0Z+Z7H0xvqT5XfzFtUCwh5uBKEyHWJHS7Gi9aP9UtmlRiaH73675qTWF+e4u28bw2wJFlwnjBuZ3rvtSexcF5+JWf3zmvhBHj12mdqwNnWPa6G82p0sgPWXboK3FUyEcATboS1MlglNY5EUI4heDwpjEJ2GE= 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=ahG1CHFT; arc=none smtp.client-ip=209.85.167.181 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="ahG1CHFT" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3cabac56b38so119216b6e.3 for ; Wed, 12 Jun 2024 14:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718226202; x=1718831002; 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=60rjWI/eWg2WwJP9vLG2m5CtLQt8gZzyCnXFhPgOW24=; b=ahG1CHFTLv1cMBkeRGAN6HmYwxuGvKVaMkZVj8BABDx1q1O6FS1hAaMcLB/l0+UkTY MONxVwfWjVDRr64R9AONQMRFnuEOXjsNMEPLRNf4uNwrnkCKA+fmxXHcbqFSoY4E3/GG 8Wecwu4446N7co19eN58KP4N+dArpMuMIVqCMca+0GleulfxSxJ/KkTyiptWjXdF915Y 0jEdSNW0Pb7L4sxqwrRNmjdR+4AXKOUnwxoymWkNR72FiH6j5/Tj6R54R6vEZXuB7r+m asK1eaIJ4knItwiuut80MX3Uk/lPORZ8qHRN80Jd0nkpOJ0q8aLVd+LYzRL7/i3Ozwih jPQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718226202; x=1718831002; 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=60rjWI/eWg2WwJP9vLG2m5CtLQt8gZzyCnXFhPgOW24=; b=WI28QGyHhqm87qvDSkb0bZ4dKLHHiAXN6xFqoX9eRtyVqF91qYIQMpu26talgztcFD D6VD+/RumL1k0dGKoN3brrU5oAFC1sDSqCqipcyvEhqg1EiJNPMtsjU+2S7Dcm7YMSth Fpybeot5ABLz+oWLE/cgUg/H65LO5MFOfef5AO/kObIsvVvk7hdBYnEsFlXLccOGjul6 dZoT5o9ycXv05e3G/ZLJmLfpDxbDNdAH01oR4bCWxDOAn+3USg0acg8gJz44nrEk7z/N kuM4CAGWGMeRhFuXjTbDD+ECA8st0r5C9BuKr3Ei/inUe+ZDgO9YqA+u4/3Ny5uWmq80 PM9A== X-Forwarded-Encrypted: i=1; AJvYcCX3UR93TJAsV7WCpl4GUeTbN6jZ+MFUthUDi3JPfyGMhUobF5wK6GfDn6auzhmOykzWq4QDnCHtcxOs1lG96RWmQ8iNzjQ332vV X-Gm-Message-State: AOJu0YxddYlph/5Qv6l9+QBUBxFb2nuts9AvlI3MDMnewqmxMkVC0DgP b9OsIxCAv7QM9o01BObE1xKUBag5DdiA8uptKqmRcjeS7fNUct9rS2D7BYFV45M= X-Google-Smtp-Source: AGHT+IGENQe4ez4Gwyda3rsmnSjRQps4X8hzl0vGRVzINVJNtM7Np1gleBLWblptPg91hq9vLRK58g== X-Received: by 2002:a05:6808:1b11:b0:3d2:231e:4b30 with SMTP id 5614622812f47-3d23dfdef65mr3638602b6e.13.1718226201601; Wed, 12 Jun 2024 14:03:21 -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 5614622812f47-3d20b68f5a1sm2433368b6e.23.2024.06.12.14.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 14:03:21 -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 v2 3/5] iio: adc: ad7292: use devm_regulator_get_enable_read_voltage Date: Wed, 12 Jun 2024 16:03:07 -0500 Message-ID: <20240612-iio-adc-ref-supply-refactor-v2-3-fa622e7354e9@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@baylibre.com> References: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@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 --- v2 changes: * avoid else in return value check * use macro instead of comment to document internal reference voltage --- drivers/iio/adc/ad7292.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c index 6aadd14f459d..87ffe66058a1 100644 --- a/drivers/iio/adc/ad7292.c +++ b/drivers/iio/adc/ad7292.c @@ -17,6 +17,8 @@ #define ADI_VENDOR_ID 0x0018 +#define AD7292_INTERNAL_REF_MV 1250 + /* AD7292 registers definition */ #define AD7292_REG_VENDOR_ID 0x00 #define AD7292_REG_CONF_BANK 0x05 @@ -79,7 +81,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 +251,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 +271,11 @@ 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; + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0 && ret == -ENODEV) + return ret; - st->vref_mv = ret / 1000; - } else { - /* Use the internal voltage reference. */ - st->vref_mv = 1250; - } + st->vref_mv = ret == -ENODEV ? AD7292_INTERNAL_REF_MV : ret / 1000; indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; From patchwork Wed Jun 12 21:03:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13695579 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (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 630B754F87 for ; Wed, 12 Jun 2024 21:03:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226204; cv=none; b=IMpCnS3KaYGuyuN+MhiRqDdt//BdHKhYgTGq+8lKZA5yTSbegaN3ug5hgvj/SLTlBcd2MboXZKGNqpHJ+blqaCvBZQIQxSNpjpUdUV9RMMbjXdq6+H469GIqzOGQFE2WCoMq21go/GGhFGtiLjq7mUzJk7wY6rVEpOf/f7ktDD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226204; c=relaxed/simple; bh=sezQ4w6PZZve8U3ILWq1Xq5i5J6FPy2Gc64TgHqk4/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lO6tlpJh4HGoMIE0HgbCzHtJzVlxP05Y4vAkGda8Zb/vyPwTqqyKFN7OyeNYmVG90ti1VA1eiWzq61ak+B3eNerwf2oIQlqeqenEf6mAH7G0h0CdJBoraryMspJtP5PsWVIuAkNpZFtKdm0k3Rz5tZxYQRD+FzRRuraXc8+e5og= 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=YRsdl3nn; arc=none smtp.client-ip=209.85.167.174 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="YRsdl3nn" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3c9cc681e4fso108377b6e.0 for ; Wed, 12 Jun 2024 14:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718226202; x=1718831002; 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=2w2EhrQZ4+BmCMfRs36lFVBfa5pXsiS+VLdsM94tNmk=; b=YRsdl3nncMccG/IArtSdxOuiHewELH9I3v7S2k8Up3fEH+vc2rsZ6uxFu/biQi9zxd //JQioJIOhBrs66ud2SwArFWtR9pWGyuRUk8KS4ZIRQZhZdqKwv6rRQNMeHieowSnVIc KqcDBfZ9hY0U6vRNHphZBXIj1rywQgQ0yxIZIXUr9Kufv1lTGPmGLoc39rZ8QVevIBIY p3t8DZW/TgASb5xBWcc/9xwqvHgw1ftw1AfxJ5y9B4zpPkImL8j9SV80TOMH+gTW0xSy vJ/Vo68iW96AlJUV7xH9VW/FqXuGctlaEb+yezYqvd9TkOByl+eM8lvilX84VvALUrJl 7R2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718226202; x=1718831002; 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=2w2EhrQZ4+BmCMfRs36lFVBfa5pXsiS+VLdsM94tNmk=; b=bvOTHVc5XIFzTN24doPxCiZJITJxUhpm+QLrGoQrOFDdvUZC8FQh35Y1xkrtK0LPoa OCTY4kuXRBaA98WM06dPi8MnrosgaEkwFJsqoIguTpInncXcfO97JkrSoK4ZbADnetXZ ByjwT01tM0+cO4MTlKd7EVjvWZCWQG+EFUykfckB8jFkILRBQxpCaLOHw09E26COHUI8 eDR/Bgqkp1SaxkGJNY4PU1wbgQbN9+LzoywNSvrt4fLWmW0P0+kTDpsi5X708kP8RRW9 t89hdkyp7FYn9fcdHoVFX0Sg/E1iOXcWxQmtYZ+oV0Ngk9cZrBLkNfu1z4P+RH7VIaqN dfJw== X-Forwarded-Encrypted: i=1; AJvYcCVwEG5sGQNXdVHRZYNryFh+3pv+jm7kMrTnBVELb8IrBhIZ1URAseNRm4Wb9Ju6gw8O9QRc5vSri3ENtAJs7Fq/EjadEwh/op4Q X-Gm-Message-State: AOJu0Yyy7NhE8oWCb/zedaKYfvbbu2iCaVwn/w+P/04UrVGjl4VSqoIM WT+2WRKBx38BRIrInxW6cz07OpK8ePY26CyAF1hRPRN6M7dtqrAxWicQqgXOTvo= X-Google-Smtp-Source: AGHT+IH+n9V+MzaCy4aZHHNtHPMSXI+bS8hlK5eCVyi4DOF1NPWgoBSrSmEm04QGkU67m4l1Ly1jZw== X-Received: by 2002:a05:6808:1282:b0:3d2:304c:982e with SMTP id 5614622812f47-3d23e0800a9mr4381718b6e.42.1718226202413; Wed, 12 Jun 2024 14:03:22 -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 5614622812f47-3d20b68f5a1sm2433368b6e.23.2024.06.12.14.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 14:03:22 -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 v2 4/5] iio: adc: ad7793: use devm_regulator_get_enable_read_voltage Date: Wed, 12 Jun 2024 16:03:08 -0500 Message-ID: <20240612-iio-adc-ref-supply-refactor-v2-4-fa622e7354e9@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@baylibre.com> References: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@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 --- v2 changes: none --- 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 Wed Jun 12 21:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13695582 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (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 41EFA12A14C for ; Wed, 12 Jun 2024 21:03:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226205; cv=none; b=S6Y1NOTgD8mMt55kw54KQHjVLB97jK3E4CiV8vhM7V2q0J4Gsu4WWi7WAYOJub97HMp4TY0hF1i21bve7nYM4bBv69ZbmAB3XF6xOmkSgwvN8Ed7Uk+J1Q4LIo90PfI208t1Sms8KHdJzsjZxKdJZ9qEBT6MIGT64mZy8iDF0BY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226205; c=relaxed/simple; bh=LHX54IPohUPO/ja4UGsPmeS+kesms5VmpdxF3oWqNgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fv/QCKg2vhS6VzRZGFseRBC3RKRIQuAM+boGiquNMJeWDC09OLZ3T2CnKJ8UdGtub71l3NlRfzIzSTCRhWOz6hmDuUttiS0kHt4yRwGVtmRb7BC5gocMvQ5jovoegYbWPN9qL54/Gmb26Y52rPKVu9h79y6ccxIcYidLR5Zm1oc= 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=Y8bxFewT; arc=none smtp.client-ip=209.85.167.179 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="Y8bxFewT" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3c9c36db8eeso119458b6e.0 for ; Wed, 12 Jun 2024 14:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718226203; x=1718831003; 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=cfd4KKhAKeSc8nJGyWlf0fHOe2Cz1V6aByHicOapUF8=; b=Y8bxFewTnYQT8RbeWQtF4iyaxR/XkICY/Mn4/LwcGymSLG6kemamvCxN8mCvEmjU27 P33Qr+UYB81awreVVQDCGnBdU25JTCeOhYCf/V6N7apxZ2Dp5cdBqWMWh+/S+iXE36lH aVJB3CxhXe0yv1LaQ7rMHZK4i6uTjz5XD5/7RoYlSBvsaWM3V4tyY+7PBVsibWaYng+v CRDbA6J2l/fqYcwzfcTbQA27kwaBUdKZjeWw/Zn/Yhavi6vpTC/l8GhFfuG0aPGwULmz FOLugfIl6huzseIBcI1mFwMEdqCrP2wMgeEfTz75G2uTJXerkta/BRpcO2DtLMP831JF MK8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718226203; x=1718831003; 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=cfd4KKhAKeSc8nJGyWlf0fHOe2Cz1V6aByHicOapUF8=; b=s4CpWCQfPBMudQ2tW+KSNygBvK9gYoWTmq0VIUjyRwLgyj3bg/17BziTRDd7XFfFYP JC0p1CxDz0ujd0ks+futTWiZ8eSzh7j6tqNYLTQ7zLFgD0Db1rgXEAW6Dp4BB4GHUqxF 4JBLDmyhXt5s2yhZccUvm2RZVXYh5cQAYOP0IpRP0TQOXH9iLkx+NW5lW+gy4AfRqTqs 3W6phAFuHox2Y+KxSHyYyGxrai0eZ1+ZNpJvjhM7c5goImIHF1Sq4bPM1DTqi3aroCu7 OtVo6NG7Ugpee2q0/3O8MxLYnhR/Hr17X87SVe+N8ER16D4SCvmAddTUpxwxb+WDWaU1 rytQ== X-Forwarded-Encrypted: i=1; AJvYcCWT7B1IXgQuubeEynnjhIKGtcdP89kKNTughMuivrcOQy0K8xME0BvLezfZtk1wr58g/cQ2uhVYb72RajkE1Snkgkxt1SOePdfn X-Gm-Message-State: AOJu0YwFN6vCvyDVaBfOsqjQaTlgdkKNCgW82A7ALrhOAD1BcUYiGsLt LvlJKmJS0LgZrCgF+X7Fagu1S6UxVaH8XrcVcg2l6CJY1jRjAeRoGQFDeJQ08vE= X-Google-Smtp-Source: AGHT+IFqU/5rjB/9qgNYmiXyV9btPuQJBs/CvDCI2j8yxhXc9NcK7vXOFCo903edhIGqelGT2FOyeg== X-Received: by 2002:a05:6808:2f0e:b0:3d2:1cfa:94d3 with SMTP id 5614622812f47-3d23e108174mr3327209b6e.47.1718226203250; Wed, 12 Jun 2024 14:03:23 -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 5614622812f47-3d20b68f5a1sm2433368b6e.23.2024.06.12.14.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 14:03:22 -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 v2 5/5] iio: adc: ad7944: use devm_regulator_get_enable_read_voltage Date: Wed, 12 Jun 2024 16:03:09 -0500 Message-ID: <20240612-iio-adc-ref-supply-refactor-v2-5-fa622e7354e9@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@baylibre.com> References: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@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 --- v2 changes: - don't read voltage from refin regulator - avoid else in return value checks --- drivers/iio/adc/ad7944.c | 54 +++++++++++------------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c index e2cb64cef476..f8bf03feba07 100644 --- a/drivers/iio/adc/ad7944.c +++ b/drivers/iio/adc/ad7944.c @@ -464,23 +464,17 @@ 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; + bool have_refin; struct iio_chan_spec *chain_chan; unsigned long *chain_scan_masks; u32 n_chain_dev; - int ret; + int ret, ref_mv; indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); if (!indio_dev) @@ -531,47 +525,23 @@ 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"); + ret = devm_regulator_get_enable_read_voltage(dev, "ref"); + if (ret < 0 && ret != -ENODEV) + return dev_err_probe(dev, ret, "failed to get REF voltage\n"); - ref = NULL; - } + ref_mv = ret == -ENODEV ? 0 : 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"); + if (ret < 0 && ret == -ENODEV) + return dev_err_probe(dev, ret, "failed to get REFIN voltage\n"); + + have_refin = ret != -ENODEV; - if (have_refin && ref) + if (have_refin && ref_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 */ - adc->ref_mv = AD7944_INTERNAL_REF_MV; - } + adc->ref_mv = ref_mv ?: AD7944_INTERNAL_REF_MV; adc->cnv = devm_gpiod_get_optional(dev, "cnv", GPIOD_OUT_LOW); if (IS_ERR(adc->cnv))