Received: by 2002:a05:7208:2202:b0:86:316c:7444 with SMTP id s2csp671865rbb; Fri, 31 May 2024 14:21:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVG3tcsKUZ66UhEQL1EucXlYC+Xm24eoWRa3ZbzoxtyWRbkHX8LWvYIAF1D+bnXH8oN/JX/yQ283GF3U9V09CwH11bHm0D8R5a60NfLNA== X-Google-Smtp-Source: AGHT+IFBBTTw6J8wojRlh9seS8kRDVkGNwGy8Ft0NCfC9/WXUsszBP80AeduzaCPPxu6mKjQypg9 X-Received: by 2002:a05:6e02:1a2f:b0:36d:acb4:8c02 with SMTP id e9e14a558f8ab-3748b96ece8mr37988435ab.6.1717190495719; Fri, 31 May 2024 14:21:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717190495; cv=pass; d=google.com; s=arc-20160816; b=gr4iyM1gBWfOq1P7FdrcHL0oEc0t+79XPKJnK7XG2SM5lOGxRts1NDQHRlhA7vb7Sv nPl2sTLnhIgooo6eu0rT01MD8Bti4XViDwQPc1vraxIUeyX16IWEnZROb2VBOT4hOXPV G5d2Q2OF4rSotf3rAHS3qOoiVXOH6UoB00z8NQYsQQhJ3BzrzC9y9mCJxanuSq3hcxgu O6o9RYQERzWecifC2P5DBN1jHWJlC9JWt3UauIy5WDFcnqx+4mxHZdrV4SZcutztSbyT WEWsMXgDz9n1d8lTAkCweRJewDuurmhIFPOF5oCwJgzCC3zsV6brDq9jQr+r7pXm17zn H2Xg== 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=9A//l2lq6uILJm9YAojX9V6DCWgOioR04paBfYh0fho=; fh=KAVP949rx40sItHTwyWfOgUJ4sCs3+zsV/gaXJaMNAA=; b=ZqdGmEY9EHmbfSEcNq8YgzpIahV/DbhDLP1L06t5eRzQKafnAoulm1+BTKp8+VULcE yKAPp3VWZBfgGsPlWDAOdsmSKK05Hlb/p9BfZStCRQwnV85PxVXJkzBjBgvB1xC1777Z jaFccjAgaNQ3/Gakpq9cvygulIPXuhPgjYa+3yCGOG17FcpfUu0vLCyMx8yqV0m0TFfA RfDk/hHRH/XOPDXOKPDSEKYDuynj+z1aLl12zEb5cWyGgb2kOkqYvSnJFcIaXomMFtJj goN8ZIDHHRdJvCkXTGvlUpAPOCebqywaBbwk1cO0A8+/hpiCEYr8zv37GvQtZhqWBRTi +5WA==; 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=107lfdKu; 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-197499-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197499-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 41be03b00d2f7-6c3540fae6esi2208198a12.13.2024.05.31.14.21.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 14:21:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197499-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=107lfdKu; 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-197499-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197499-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 B901728357E for ; Fri, 31 May 2024 21:21:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08DAB84DE4; Fri, 31 May 2024 21:19:50 +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="107lfdKu" Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 4776E78C6F for ; Fri, 31 May 2024 21:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190389; cv=none; b=jjXx7Q6K3V30t64Z7KT5VAj8z24d5zwlVb0KI8h55pShOb9t9Fc3RsfS7S8cBwBCsogqGTM/ibhP6ixyD52ThEMP2uTi8P8DWHwkp2w3Rns4Gd8NR2I8v94BUkIWGogpdaH36eH1gP5L639y2x7Vr75PWU3yRENxkYKitS0ulGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717190389; c=relaxed/simple; bh=Rk5dJF2+TsUg7IjzcoRV/lfTyzQjoNRqKiXdm3UK0Cs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E0Slq3R/qcEzJYnxwI3PNl09+QG9th5is09lj1igDEUnvCotHLk84De+BV9hUBuFGhLPNhlGOIL1FO9Z7OvEF9T72DadJsx0NxhckMr87DsZz/uM4TySX9DkgbAicHQLHqEIhEvqWViF2xnsQrS55Gvze1jdjq8fVxhaozFEYKg= 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.48 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-f48.google.com with SMTP id 46e09a7af769-6f8da5e4850so1361608a34.0 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=exKTE6o/qfTmznHQnOA2JbL6yQI6jfwVsyD0nt09bHzemhNdDjRFbB+TbXr4XuEyon sEhHVZ+4j9MIcuAbEyrpOKWhTvk52vmCC21wOhC7++G3C3pvM5wpTOD0yYJqNvU27hzi eT+eBgiE2U9rG8tfVjBlj4ksrClE5Ox6VNwWRi0G7ZSdkINk3jisrDEIJjUjcHewIstF Kc3p3Spwj4y6DDgICB5nwn1LW4SMYugJZBkQnSxL8cl5Pnn7OdK6hsrTBo6OOADGwXtV xbouBMz0SYtCiBdz09bn6+HaVFErIt+8ej8dPQDozqmXlKl5dEaGhuVf2+l2kzXIN4wB VMmQ== X-Forwarded-Encrypted: i=1; AJvYcCXcDbPDFolpde8OhiJ4+NNOLffGxf9GMlo1wnZWQJYfD7EkRXsSj79TT3P3jSpLA0mzUcsdsyaFh4I80fC0Q52pvL0EckIJzJipzIkr X-Gm-Message-State: AOJu0YxjAzU3lDrKB/R6e7Uwr1CSG4UgNdwsDmF6tO0IXtY6CJzA5+yV OIBpYXa2yNMy8LrnX4JLq2y65krHl9P7U5+6Htq2lZDCE80QS6l4AI4EoeREOEA= 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-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. Signed-off-by: David Lechner --- 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; -- 2.45.1