From patchwork Wed Mar 27 23:18:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13607638 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.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 916B8154C0F for ; Wed, 27 Mar 2024 23:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581547; cv=none; b=GWGV3XXYxufcNqrohGlSvStYaCC4M4+0OtFriHs++b65RIDaTN8SiTb22YjFDSxmP3h37zRsFUOsu1gQnD7riT3GdJq4IOapngIK+CQqp+e4WbaNJPzOLH+AjmKgeWSbldJuleh8becD1/DJ5QC01Hhan1edvFpiqKhzuVmFKIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581547; c=relaxed/simple; bh=ly8n7SxGz9Lf2EUP25mArGs3mqGcGcPAZGBiTMozfFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n1eILeSpmkjrgwcfvrnGUsL9f/8dvCGuCIJMscDrNpsMLNn0l7oBWuTkKkXiJhdXVNZMo2jtqqXILq2kRoT+Vt3AY0YquaUWbtylNZDU8GunkCXS3sNDCVNi5N267m5Q6dvhVSiqaNfq0W5X8V+JtVKO5C6Sre9lDVc3nHHyIt8= 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=gdYn2HNs; arc=none smtp.client-ip=209.85.160.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="gdYn2HNs" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-221e6bf537dso253423fac.1 for ; Wed, 27 Mar 2024 16:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1711581544; x=1712186344; 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=PE6UqUKX3G/FV5HVYmxMOtqukpZG7UeidX96eu+NYsg=; b=gdYn2HNs6K4qNEtXCegpSeDGvDV8ACFqhl6Vw7p9/9Zn5KL7U7CJyRzv4oEUP2PMR5 AKCmYlJhBTSAEsxYPxJ86q1ivvhTcUFZgFSuV1IOS2YTJQbS6t4gfXZsaVYvLW/gd4V3 +BaPLv351a9TJ3oTxqqzPeBLOMFKo/+DCu++5GtOZgLvE4O+LnX8bKtlgWbIofTNmSrR WFdGNJqz2nZWysZ1zrflE6XVoa8EvSoGsQmeFNaYFRevPflnCftuprK54+Sjn4WRyxG3 p7QvTOg4/8kuwS5Y2OKt/x6LHKoBihgpkdzBouj2haJea7QiHmCDPVHWIBMJGbX7EyDr Jy2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711581544; x=1712186344; 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=PE6UqUKX3G/FV5HVYmxMOtqukpZG7UeidX96eu+NYsg=; b=TSdeQ2eb5/bO5Sylu2MrKvnirxx306FzUsVpY45Eb5YgXB4qMLnIohvvu8F1OSsG/D RkQRgE7OpJgNRQVQgn+c/rnycHngfnxSQ8lUnoN8ujMA02CyBEccvUXmmi+vQkqPQlIX sJzfhPxVVxNvJTKzRsW+mEMo20QWfhDELaCn1hSruRDLO0EaRmswo9enjGRHH/i1XZJk 1OKen21P9oD8q/D5eHzj0tdsXI258QXBFjdzdPJVBbRQG3uTmLzPPJ+ECg1jRS//RW+k Qph2tGd6kOk1mbywv8ZC6OdsAQGgwgJzm0yRsGRfKVG2w1awF4DfaoD1DTruRlmaS3Pe S2TA== X-Forwarded-Encrypted: i=1; AJvYcCV9Z5yrlk+3R1z0qg4+2Ok3Tb0YElqynH/9SshZOddOzsi0oEQEDt3yFy26qb2XoJxszjmnebuL7xrcuRDrdoiYYeSuVHXU4Conrt8= X-Gm-Message-State: AOJu0YwEa5LRZ0m31GYqGQMLOaHeVi5/QEBspSU4HlfUUGgPyFxlCjOR 8aM6Lx77XRrMcJVFsqKrtemMyOsWz8cFZ9urVzVeXdO7C0mJyTZMJ2wA4aKeN/I= X-Google-Smtp-Source: AGHT+IEoTHHATEQkuJa2BbeiTLbiTgSE1yaSMq5ULG3gGF3llvbq0XtMCg26/o3L5+Q/P6Gnym6iXw== X-Received: by 2002:a05:6870:7d19:b0:22a:5690:f056 with SMTP id os25-20020a0568707d1900b0022a5690f056mr1316238oab.44.1711581543700; Wed, 27 Mar 2024 16:19:03 -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 js3-20020a056870bac300b0022a0519183csm81381oab.2.2024.03.27.16.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:19:03 -0700 (PDT) From: David Lechner To: Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov Cc: David Lechner , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: [PATCH RFC 1/7] regulator: devres: add APIs for reference supplies Date: Wed, 27 Mar 2024 18:18:50 -0500 Message-ID: <20240327-regulator-get-enable-get-votlage-v1-1-5f4517faa059@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 A common use case for regulators is to supply a reference voltage to an analog input or output device. This adds two new devres APIs to get, enable, and get the voltage in a single call. This allows eliminating boilerplate code in drivers that use reference supplies in this way. devm_regulator_get_enable_get_voltage() is intended for cases where the supply is required to provide an external reference voltage. devm_regulator_get_optional_enable_get_voltage() is intended for cases where the supply is optional and device typically uses an internal reference voltage if the supply is not available. Signed-off-by: David Lechner --- Documentation/driver-api/driver-model/devres.rst | 2 + drivers/regulator/devres.c | 83 ++++++++++++++++++++++++ include/linux/regulator/consumer.h | 14 ++++ 3 files changed, 99 insertions(+) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index 7be8b8dd5f00..fd954d09e13c 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -433,9 +433,11 @@ REGULATOR devm_regulator_bulk_put() devm_regulator_get() devm_regulator_get_enable() + devm_regulator_get_enable_get_voltage() devm_regulator_get_enable_optional() devm_regulator_get_exclusive() devm_regulator_get_optional() + devm_regulator_get_optional_enable_get_voltage() devm_regulator_irq_helper() devm_regulator_put() devm_regulator_register() diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c index 90bb0d178885..e240926defc5 100644 --- a/drivers/regulator/devres.c +++ b/drivers/regulator/devres.c @@ -145,6 +145,89 @@ struct regulator *devm_regulator_get_optional(struct device *dev, } EXPORT_SYMBOL_GPL(devm_regulator_get_optional); +static int _devm_regulator_get_enable_get_voltage(struct device *dev, + const char *id, + bool silent_enodev) +{ + struct regulator *r; + int ret; + + /* + * Since we need a real voltage, we use devm_regulator_get_optional() + * here to avoid getting a dummy regulator if the supply is not present. + */ + r = devm_regulator_get_optional(dev, id); + if (silent_enodev && PTR_ERR(r) == -ENODEV) + return -ENODEV; + if (IS_ERR(r)) + return dev_err_probe(dev, PTR_ERR(r), + "failed to get regulator '%s'\n", id); + + ret = regulator_enable(r); + if (ret) + return dev_err_probe(dev, ret, + "failed to enable regulator '%s'\n", id); + + ret = devm_add_action_or_reset(dev, regulator_action_disable, r); + if (ret) + return dev_err_probe(dev, ret, + "failed to add disable action for regulator '%s'\n", + id); + + ret = regulator_get_voltage(r); + if (ret < 0) + return dev_err_probe(dev, ret, + "failed to get voltage for regulator '%s'\n", + id); + + return ret; +} + +/** + * devm_regulator_get_enable_get_voltage - Resource managed regulator get and + * enable that returns the voltage + * @dev: device to supply + * @id: supply name or regulator ID. + * + * Get and enable regulator for duration of the device life-time. + * regulator_disable() and regulator_put() are automatically called on driver + * detach. See regulator_get_optional(), regulator_enable(), and + * regulator_get_voltage() for more information. + * + * This is a convenience function for supplies that provide a reference voltage + * where the consumer driver just needs to know the voltage and keep the + * regulator enabled. Also, as a convenience, this prints error messages on + * failure. + * + * Returns: voltage in microvolts on success, or an error code on failure. + */ +int devm_regulator_get_enable_get_voltage(struct device *dev, const char *id) +{ + return _devm_regulator_get_enable_get_voltage(dev, id, false); +} +EXPORT_SYMBOL_GPL(devm_regulator_get_enable_get_voltage); + +/** + * devm_regulator_get_optional_enable_get_voltage - Resource managed regulator + * get and enable that returns + * the voltage + * @dev: device to supply + * @id: supply name or regulator ID. + * + * This function is identical to devm_regulator_get_enable_get_voltage() except + * that it does not print an error message in the case of -ENODEV. Callers are + * expected to handle -ENODEV as a special case instead of passing it on as an + * error. + * + * Returns: voltage in microvolts on success, or an error code on failure. + */ +int devm_regulator_get_optional_enable_get_voltage(struct device *dev, + const char *id) +{ + return _devm_regulator_get_enable_get_voltage(dev, id, true); +} +EXPORT_SYMBOL_GPL(devm_regulator_get_optional_enable_get_voltage); + static int devm_regulator_match(struct device *dev, void *res, void *data) { struct regulator **r = res; diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 4660582a3302..35596db521a0 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -164,6 +164,8 @@ struct regulator *__must_check devm_regulator_get_optional(struct device *dev, const char *id); int devm_regulator_get_enable(struct device *dev, const char *id); int devm_regulator_get_enable_optional(struct device *dev, const char *id); +int devm_regulator_get_enable_get_voltage(struct device *dev, const char *id); +int devm_regulator_get_optional_enable_get_voltage(struct device *dev, const char *id); void regulator_put(struct regulator *regulator); void devm_regulator_put(struct regulator *regulator); @@ -329,6 +331,18 @@ static inline int devm_regulator_get_enable_optional(struct device *dev, return -ENODEV; } +static inline int devm_regulator_get_enable_get_voltage(struct device *dev, + const char *id) +{ + return -ENODEV; +} + +static inline int devm_regulator_get_optional_enable_get_voltage(struct device *dev, + const char *id) +{ + return -ENODEV; +} + static inline struct regulator *__must_check regulator_get_optional(struct device *dev, const char *id) { From patchwork Wed Mar 27 23:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13607639 Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.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 B1C4E1552EB for ; Wed, 27 Mar 2024 23:19:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581548; cv=none; b=Y7gIoiVq9dUPyzp03bDmQOnxthljDy9EzdaHROzldFzma4gq0bYvOG//nPDgwp7/FaNuZPQSme5f8kcTepA7L5H0Lv9Nnm4aEaJpl/jzgT8t4xNl4Evb6j2AceS7FTTc3ANgf4W+W9iEPKzuEobIduXETwAoNmVMyZO24n55kY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581548; c=relaxed/simple; bh=neFzT6HqcboqV4+7wZk9fLD3RdDZfPvFuSLluIe7M0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FZ7uxG86rYvE9uy2pPqGI59DqWWmon+2HQAYPhcsLnHU6B85TGJas/hffGUQvLgRWL0wah63lJwYrPE651JiHDAibGGSjFc5raPlBh3iTtbKBk3TS3aEqH9ZHV8Zk0UK+PmhI26/6iTquhet9c4rHi+YzxUz8wb1t5FzictjGDA= 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=2s3jI1+/; arc=none smtp.client-ip=209.85.160.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="2s3jI1+/" Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-22963f0e12cso216339fac.1 for ; Wed, 27 Mar 2024 16:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1711581545; x=1712186345; 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=uDy4pTWnkpzbrflLHcGNvhZoR/MRYIqFIu3bxWkx5Ws=; b=2s3jI1+/GCM9mQFPftY+sTaEasxKfga3EUkxNyQvN9MMdfwPS/IngP/TfwuOCXPybF DDEJ8iKgLcWsmM4cSrdHss9GS0rcRdazB3VAUzBy2OH2o3U8aHL+0LLBk+Qp9zPw3Rs0 uEtsxhOsRr1EgKFVa5BKQCxkJKyckZXiwZ4WSvLOFwECuRPoOiOnG8K5hMsoSePxE2Wn c+Ilaf9yTdI5Icf1VdFkKU6ex+pENSR6HVEl3TDp2Ram2tFIN0gas3q/5kGPsKQrG8o3 vb80700kjoRYS98SLOaeCMfKRUiDqC7D+Ijq3JAeB0KVfeyZ1MVEiz8q1XJ7d8u1YFkN MtBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711581545; x=1712186345; 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=uDy4pTWnkpzbrflLHcGNvhZoR/MRYIqFIu3bxWkx5Ws=; b=HK8FsEyaNg4F+/eDv4ilWlvmeGQg79ffU79iMrL4waOCm4ua35IhY23yWyoGnI8/Zx 9eD9xYC/hmaJvCpNKMbdg4omvIdS/a9+PReVc9Ad0Ak+jcwDSIr/buQeGehbpIhz+F9V DN3XTgSKWO2WGf2oro56VrO6jNAOCek8DGkE4xrul4vhH5FAEaEZK4SjCsRhjlcW057k fI4KHV7hfh5gkxlrNK1IyoCpoxdeRaKSojQCy3Dl1wzJ/J4fnt6+atzFJ6MGIkORrDj1 FPZ6rfskbyHKeSXYqME4G5j8T3HafAgCik/Cl9OGMvhSjddmaxpDDSnQ7LOV6k9vUZxk /wvQ== X-Forwarded-Encrypted: i=1; AJvYcCXxvA9IRJApAFmfN49yrK4AGDxgSy8UWX0sQGPp09pdrCIrvpHg1NnajJA1D7EPu5UWltRMdlsFdxi0yUkarzXrTc3EiA49OltmhGI= X-Gm-Message-State: AOJu0YzKbXVbSvdxg2+/ouLD+4MQ62BzsVrCnnpteQ47TfRQ8SoEiFt5 qu87yXnLa0jurd2HsfJdBLo8fx4+UTpbinpSRh4I+bQ/Pb/C5QQqa8Yc8XROA7U= X-Google-Smtp-Source: AGHT+IGRFIewUZzJjdav0VooP65bH9hr9ECiT789M34rqrspoxpzTHpgVb/U1H59dfHvPYlK2YUMpA== X-Received: by 2002:a05:6871:29a:b0:221:b27a:2bab with SMTP id i26-20020a056871029a00b00221b27a2babmr1185697oae.55.1711581544880; Wed, 27 Mar 2024 16:19:04 -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 js3-20020a056870bac300b0022a0519183csm81381oab.2.2024.03.27.16.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:19:04 -0700 (PDT) From: David Lechner To: Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov Cc: David Lechner , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: [PATCH RFC 2/7] hwmon: (adc128d818) Use devm_regulator_get_optional_enable_get_voltage() Date: Wed, 27 Mar 2024 18:18:51 -0500 Message-ID: <20240327-regulator-get-enable-get-votlage-v1-2-5f4517faa059@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 We can reduce boilerplate code and eliminate the driver remove() function by using devm_regulator_get_optional_enable_get_voltage(). A new external_vref flag is added since we no longer have the handle to the regulator to check if it is present. Signed-off-by: David Lechner Reviewed-by: Jonathan Cameron --- drivers/hwmon/adc128d818.c | 55 ++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c index 46e3c8c50765..119e2841720f 100644 --- a/drivers/hwmon/adc128d818.c +++ b/drivers/hwmon/adc128d818.c @@ -58,7 +58,6 @@ static const u8 num_inputs[] = { 7, 8, 4, 6 }; struct adc128_data { struct i2c_client *client; - struct regulator *regulator; int vref; /* Reference voltage in mV */ struct mutex update_lock; u8 mode; /* Operation mode */ @@ -389,7 +388,7 @@ static int adc128_detect(struct i2c_client *client, struct i2c_board_info *info) return 0; } -static int adc128_init_client(struct adc128_data *data) +static int adc128_init_client(struct adc128_data *data, bool external_vref) { struct i2c_client *client = data->client; int err; @@ -408,7 +407,7 @@ static int adc128_init_client(struct adc128_data *data) regval |= data->mode << 1; /* If external vref is selected, configure the chip to use it */ - if (data->regulator) + if (external_vref) regval |= 0x01; /* Write advanced configuration register */ @@ -430,30 +429,25 @@ static int adc128_init_client(struct adc128_data *data) static int adc128_probe(struct i2c_client *client) { struct device *dev = &client->dev; - struct regulator *regulator; struct device *hwmon_dev; struct adc128_data *data; - int err, vref; + bool external_vref; + int err; data = devm_kzalloc(dev, sizeof(struct adc128_data), GFP_KERNEL); if (!data) return -ENOMEM; /* vref is optional. If specified, is used as chip reference voltage */ - regulator = devm_regulator_get_optional(dev, "vref"); - if (!IS_ERR(regulator)) { - data->regulator = regulator; - err = regulator_enable(regulator); - if (err < 0) - return err; - vref = regulator_get_voltage(regulator); - if (vref < 0) { - err = vref; - goto error; - } - data->vref = DIV_ROUND_CLOSEST(vref, 1000); - } else { + err = devm_regulator_get_optional_enable_get_voltage(dev, "vref"); + if (err == -ENODEV) { + external_vref = false; data->vref = 2560; /* 2.56V, in mV */ + } else if (err < 0) { + return err; + } else { + external_vref = true; + data->vref = DIV_ROUND_CLOSEST(err, 1000); } /* Operation mode is optional. If unspecified, keep current mode */ @@ -461,13 +455,12 @@ static int adc128_probe(struct i2c_client *client) if (data->mode > 3) { dev_err(dev, "invalid operation mode %d\n", data->mode); - err = -EINVAL; - goto error; + return -EINVAL; } } else { err = i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG_ADV); if (err < 0) - goto error; + return err; data->mode = (err >> 1) & ADC128_REG_MASK; } @@ -476,31 +469,18 @@ static int adc128_probe(struct i2c_client *client) mutex_init(&data->update_lock); /* Initialize the chip */ - err = adc128_init_client(data); + err = adc128_init_client(data, external_vref); if (err < 0) - goto error; + return err; hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, data, adc128_groups); if (IS_ERR(hwmon_dev)) { err = PTR_ERR(hwmon_dev); - goto error; + return err; } return 0; - -error: - if (data->regulator) - regulator_disable(data->regulator); - return err; -} - -static void adc128_remove(struct i2c_client *client) -{ - struct adc128_data *data = i2c_get_clientdata(client); - - if (data->regulator) - regulator_disable(data->regulator); } static const struct i2c_device_id adc128_id[] = { @@ -522,7 +502,6 @@ static struct i2c_driver adc128_driver = { .of_match_table = of_match_ptr(adc128_of_match), }, .probe = adc128_probe, - .remove = adc128_remove, .id_table = adc128_id, .detect = adc128_detect, .address_list = normal_i2c, From patchwork Wed Mar 27 23:18:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13607640 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (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 C825B155318 for ; Wed, 27 Mar 2024 23:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581550; cv=none; b=Mnp183bGCgwv0UXV0MAjEUSzkIXVgBdScE6MBR5oC5NEJjD+riThIIfMiH4J7dEaKlM1geoqXWxVux+BOu93VzT6Ms/hncMRKIJf8//HDdquJohHjlpnBgyFTQW8M6LsA5WJp7nHPfy07lrw25DiWaaH2XHYafDFTsS3a5guktY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581550; c=relaxed/simple; bh=A4uSmS5u3AK9wMfER4kmGXxo9e/XTrxNUtjD7xNvI4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=suu0n4N1bZ45yM0y0bUqtb0Wg7bR1b15rp2pMVfk+TJTXQI4GYEplbU3g8Fn3cfoF5mZ70CHnolClOM0u3hGWjYUM+/u7dikI7F2dVirkrJdJHC2qQt5/cnvhqTuBiTYzavyu8BdhWk2Jw1mfC+2ORE1FCLe+R4zMFdbVBRulZM= 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=FLsxfZAK; arc=none smtp.client-ip=209.85.167.170 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="FLsxfZAK" Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3bbbc6b4ed1so212119b6e.2 for ; Wed, 27 Mar 2024 16:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1711581546; x=1712186346; 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=TOfZtVlJMTFXxAc7ahXTmKHh36zHepITVD/rnFowmPs=; b=FLsxfZAKh8BjbYm+W01YP6N9iWrZlkBqSxRPHWnUHgqpCx5D+hoSXzK58imousK9Jb tMT6sFicqC9WDhjTchTLsmOeEhxFR0aobDj0WnMsS05W3QTJ+28lAoCS2bUWPQUbk/jj hqnQLOV9/Gfmbl0VHuHvpyHP1Xe+rMMvo/xfRog1B9w89nZ3Q8P3CbslgVTf60lgYg19 UthiN4N8FT07gmwWjRlNc7tMtY2+QV46a5pGHH9a6/L2cDgzcFKMsTCvfBPmoT5uA0nq 4+jDkN0qHK9647BPUdLTfN1ZeygEkUzjwHfHh8r3ovZd6bw5W1AV1Aqy6ujpS8qh4AEE gjQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711581546; x=1712186346; 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=TOfZtVlJMTFXxAc7ahXTmKHh36zHepITVD/rnFowmPs=; b=WNbLkI2h9CxYaHZbga+jBpABQj6qmxlU9yolAsqMHOeUUg2qaVZV0vI5c8sZHBba2C CBSK/NEzjhEFSRueAtLGWCy7AgV8rV6VONaUBax+D1iOHZM6/WXRlaEJUpIrH2EDCXRL 8n1LRVEYHpSFtkUBurNfgTa0WXHVTFi0eeObhG0Vbt6B30/BXYK05W0R+XZUV+aINBHZ tBcYxAL4L/c7GOetekrxGmXQP9fJPyNoHVRr1lJMmU0CBg6vkEXowC56f7YipE1BLu5D N5aFg1Rn6O4S4j4Ro6+ZYsPP+IN1wHlWXxgL0SyB5kDssV1TmtKg37trpr1Ov9MKihDn 75wA== X-Forwarded-Encrypted: i=1; AJvYcCV0FTmEBlkz1eQF+lZ5Xr1umlVZMnRMel1WlPeoo5aZbsy/J7WoiVQMZGP3oBxK/xy9cPme2O0ixLw9w/qzAldFW05Q6Ho0ro4KlHg= X-Gm-Message-State: AOJu0YzRDYiRJJNocWSdDYTnlntZ3FRI5M7hE+zil8Y2BpZxvccWbRq0 S6IQj/mTCGxjpgzTKlls3sZNnxH7xUQq2rInfGk4GnGbuaxIioxeqtcBu5A1B1k= X-Google-Smtp-Source: AGHT+IHDalMeGbYz9hAS9r44V5EAC6s0DOMiI1r9BYhrkzsEOWfvPSTNn7XD4XpPvS+TyN3y5eBfbA== X-Received: by 2002:a05:6870:d14a:b0:22a:4e4e:4d9d with SMTP id f10-20020a056870d14a00b0022a4e4e4d9dmr1284999oac.11.1711581545937; Wed, 27 Mar 2024 16:19:05 -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 js3-20020a056870bac300b0022a0519183csm81381oab.2.2024.03.27.16.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:19:05 -0700 (PDT) From: David Lechner To: Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov Cc: David Lechner , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: [PATCH RFC 3/7] hwmon: (da9052) Use devm_regulator_get_enable_get_voltage() Date: Wed, 27 Mar 2024 18:18:52 -0500 Message-ID: <20240327-regulator-get-enable-get-votlage-v1-3-5f4517faa059@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 We can reduce boilerplate code by using devm_regulator_get_enable_get_voltage(). Signed-off-by: David Lechner Reviewed-by: Jonathan Cameron --- drivers/hwmon/da9052-hwmon.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/hwmon/da9052-hwmon.c b/drivers/hwmon/da9052-hwmon.c index 2bd7ae8100d7..70e7bc72e980 100644 --- a/drivers/hwmon/da9052-hwmon.c +++ b/drivers/hwmon/da9052-hwmon.c @@ -26,7 +26,6 @@ struct da9052_hwmon { struct mutex hwmon_lock; bool tsi_as_adc; int tsiref_mv; - struct regulator *tsiref; struct completion tsidone; }; @@ -414,32 +413,19 @@ static int da9052_hwmon_probe(struct platform_device *pdev) device_property_read_bool(pdev->dev.parent, "dlg,tsi-as-adc"); if (hwmon->tsi_as_adc) { - hwmon->tsiref = devm_regulator_get(pdev->dev.parent, "tsiref"); - if (IS_ERR(hwmon->tsiref)) { - err = PTR_ERR(hwmon->tsiref); - dev_err(&pdev->dev, "failed to get tsiref: %d", err); + err = devm_regulator_get_enable_get_voltage(pdev->dev.parent, + "tsiref"); + if (err < 0) return err; - } - - err = regulator_enable(hwmon->tsiref); - if (err) - return err; - - hwmon->tsiref_mv = regulator_get_voltage(hwmon->tsiref); - if (hwmon->tsiref_mv < 0) { - err = hwmon->tsiref_mv; - goto exit_regulator; - } /* convert from microvolt (DT) to millivolt (hwmon) */ - hwmon->tsiref_mv /= 1000; + hwmon->tsiref_mv = err / 1000; /* TSIREF limits from datasheet */ if (hwmon->tsiref_mv < 1800 || hwmon->tsiref_mv > 2600) { dev_err(hwmon->da9052->dev, "invalid TSIREF voltage: %d", hwmon->tsiref_mv); - err = -ENXIO; - goto exit_regulator; + return -ENXIO; } /* disable touchscreen features */ @@ -456,7 +442,7 @@ static int da9052_hwmon_probe(struct platform_device *pdev) if (err) { dev_err(&pdev->dev, "Failed to register TSIRDY IRQ: %d", err); - goto exit_regulator; + return err; } } @@ -472,9 +458,6 @@ static int da9052_hwmon_probe(struct platform_device *pdev) exit_irq: if (hwmon->tsi_as_adc) da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon); -exit_regulator: - if (hwmon->tsiref) - regulator_disable(hwmon->tsiref); return err; } @@ -483,10 +466,8 @@ static void da9052_hwmon_remove(struct platform_device *pdev) { struct da9052_hwmon *hwmon = platform_get_drvdata(pdev); - if (hwmon->tsi_as_adc) { + if (hwmon->tsi_as_adc) da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon); - regulator_disable(hwmon->tsiref); - } } static struct platform_driver da9052_hwmon_driver = { From patchwork Wed Mar 27 23:18:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13607641 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (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 16DC2155394 for ; Wed, 27 Mar 2024 23:19:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581551; cv=none; b=lKgib5XKptS5nFdSxxD7ZdN8/iwkeD0qmOpNGeVuaiNRDkpyOIe5dErLSUe93q3ONYQ12bb02CTW7ejeQvueDv6BkPgwwJ0sropjX7Nou/nnAW5hV4uEG5KTx7+ILxsEC2SbdXe5UqwgM8u0906SvHQOAfdCgQxj/Bh07V0qMvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581551; c=relaxed/simple; bh=m3bHOTwCtpGjb4KTDA27x15GCtpMS/P661zbUhfKKAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IA/epLE3rZA/cN0DmP6E5gLUj3sqOwPKvMSXEJbnjXDNrCXnZiritiRm8AUDDCcjmpBHMl0obZ94LV3CQyGRC+QsUAAiejT3WG00DDzifg1nhFfk8kSoBE53SB2JKxVlzdu15QI3CUyvDN9bB9VuzTIQ2F6uuFlMZ2+cwdjZ504= 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=3MBuSFOf; arc=none smtp.client-ip=209.85.160.42 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="3MBuSFOf" Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-222c0572eedso233973fac.3 for ; Wed, 27 Mar 2024 16:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1711581547; x=1712186347; 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=5hg1dHpRYZjEho4rhJz+qSTgS0nJB4BPNbR6dsgqeqo=; b=3MBuSFOfpS+fPoYdwlmYLFjL8VMaVgYuenjL9Tlox/H3N8RxgoDSy3BZYC3zMKtl+1 RxtIb8FoS/c/4EiMMEmT4W5gZR79EzGFeQx7l/VYH00fQCeNObyjUY4IefVVL8xefach x4ityzMfV/spe6lcmtLxicztH/cJi+pbgxB0MadC7xuVdvyw9zl3ffCQb4wy/frTO4ql mRErsQAfWYe0D5uprmJO4RLhd83rmzbXnRehMp+LiEqeow6xyKMnNhNwUOgW+xZ1FV1U 0wSL5TC+B4308ishEAtcpfIiK6ffMhuwOKwwluK4hvjRUKMGrjsSjJKlHSUdCtOiKtY9 7n1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711581547; x=1712186347; 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=5hg1dHpRYZjEho4rhJz+qSTgS0nJB4BPNbR6dsgqeqo=; b=bgKmDNVYFP/YLBgBbcYUWV9LiSQLAQTcgmUFb+GREj2iRm/zykcSQHdaVlmPIq01H0 Nr5bWus0H3L/TaNsIvP2KZVR+Q6GK/sm2X6Qe5R41MzAiko6BFfLSSnE7Xst6ZuUPnPe fultZD3kUbjuDwsGYTF+dya2cZoIJSuATRe3JHKeaOvkjwoQDlfDunEn2KXKmTfkPI6+ i4f7sr1D9mntUDCg1ntjtxJGUxyopIZbotSij2Wjl14BtPq3Kem5wnbvJRYOtaPS40rD k5Parvo8nxPP6uToOSkt4GBorw5yP3ROVBv5kPld3Lf4eIP+NgD3PzM/dTNCpVwsyTHz 5dLg== X-Forwarded-Encrypted: i=1; AJvYcCWWpL3Pe1VlD3wXQMx1Ihu3hTmkJ7iwX4T+VMWEaXcgtqgFpTA9y9l7rrEKFSZX+0jTiOs25PhZzlYiJB1NBZJs/hhVU63ubUagODY= X-Gm-Message-State: AOJu0YwwR3jluJPhCzmbhWvnTtG9xr1bBsCl1LQ3NLYaeruyjp2QHwHk vvivat0DOSmL0RwvJe0y00paovgifeaWjeU8IfXiTwGpTaRWViJkvAhTojfHSZo= X-Google-Smtp-Source: AGHT+IHk3eSdmsSABjkDyaK0jauAUum2pB/dkonw6qcHUydV0+mxlwiPUnWMWCTRhHhYGOh0khoS/A== X-Received: by 2002:a05:6870:5cc4:b0:222:63e2:aba3 with SMTP id et4-20020a0568705cc400b0022263e2aba3mr1314518oab.8.1711581547039; Wed, 27 Mar 2024 16:19:07 -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 js3-20020a056870bac300b0022a0519183csm81381oab.2.2024.03.27.16.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:19:06 -0700 (PDT) From: David Lechner To: Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov Cc: David Lechner , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: [PATCH RFC 4/7] iio: addac: ad74115: Use devm_regulator_get_enable_get_voltage() Date: Wed, 27 Mar 2024 18:18:53 -0500 Message-ID: <20240327-regulator-get-enable-get-votlage-v1-4-5f4517faa059@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 We can reduce boilerplate code by using devm_regulator_get_enable_get_voltage(). Signed-off-by: David Lechner --- drivers/iio/addac/ad74115.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/drivers/iio/addac/ad74115.c b/drivers/iio/addac/ad74115.c index e6bc5eb3788d..01073d7de6aa 100644 --- a/drivers/iio/addac/ad74115.c +++ b/drivers/iio/addac/ad74115.c @@ -199,7 +199,6 @@ struct ad74115_state { struct spi_device *spi; struct regmap *regmap; struct iio_trigger *trig; - struct regulator *avdd; /* * Synchronize consecutive operations when doing a one-shot @@ -1672,14 +1671,6 @@ static int ad74115_setup(struct iio_dev *indio_dev) if (ret) return ret; - if (val == AD74115_DIN_THRESHOLD_MODE_AVDD) { - ret = regulator_get_voltage(st->avdd); - if (ret < 0) - return ret; - - st->avdd_mv = ret / 1000; - } - st->din_threshold_mode = val; ret = ad74115_apply_fw_prop(st, &ad74115_dac_bipolar_fw_prop, &val); @@ -1788,11 +1779,6 @@ static int ad74115_reset(struct ad74115_state *st) return 0; } -static void ad74115_regulator_disable(void *data) -{ - regulator_disable(data); -} - static int ad74115_setup_trigger(struct iio_dev *indio_dev) { struct ad74115_state *st = iio_priv(indio_dev); @@ -1855,19 +1841,11 @@ static int ad74115_probe(struct spi_device *spi) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &ad74115_info; - st->avdd = devm_regulator_get(dev, "avdd"); - if (IS_ERR(st->avdd)) - return PTR_ERR(st->avdd); - - ret = regulator_enable(st->avdd); - if (ret) { - dev_err(dev, "Failed to enable avdd regulator\n"); + ret = devm_regulator_get_enable_get_voltage(dev, "avdd"); + if (ret < 0) return ret; - } - ret = devm_add_action_or_reset(dev, ad74115_regulator_disable, st->avdd); - if (ret) - return ret; + st->avdd_mv = ret / 1000; ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), regulator_names); From patchwork Wed Mar 27 23:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13607642 Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) (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 B254A1553BC for ; Wed, 27 Mar 2024 23:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581552; cv=none; b=FF1f6z526BPKS/zs1ovTq80swFOKCBgx8TPN2VfZMkZyH/R+jvMvOXYe+DqB8LzKaFFHtMD+EwzIaqHx2X3uUc8Gbe/ZIAFfB61zVkdxJWZDfPWNabhPxlKOnVp4c6ucPrxR3E5mpmQJ3lqQrG+ULHsTnbdzVDk3Zt+mmXbn6HM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581552; c=relaxed/simple; bh=sBLswoaOXaPOvtO52rKuqYQNWurR1XJ6O1U4h0zvPkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T1TIw5PXi4WszMd95WA//qISRZ1bK7PJudQBmBu56QnZQfut3C53jN9UwMWkNGWGbhSWyuo6VW1x/K+2fSFeRMdW2+Iko0UkIA/3SDPsO8qYQIrptR+/HcsSfafqjyGj1GZ0dU2/NqXRR08psSF1OW4iytKRD1zhQkmcGOi+8/M= 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=GmmK8IK0; arc=none smtp.client-ip=209.85.160.51 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="GmmK8IK0" Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-22a1e72f683so272672fac.0 for ; Wed, 27 Mar 2024 16:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1711581548; x=1712186348; 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=KaNlrVh6YX+OdjnoPnmjQwMmZEJRJLFsRjLteQznSUU=; b=GmmK8IK0iivL2FmUdS13hA2ENWWXIW/hTaQCILNCGBPXTotcgGrCDpOC97OcLwlTx7 RjCYu7tM39lZj8lveTnDWDIq7Dutz2w1TLDeBW+DbwB9uhUvdRfXEWWvPfzug7y1Ytzu PTnQ2sml8lwNfbC1P17OM9gmRYaiVBtzqUdLpw+Zvt3muIbaAXtj2wGtov1D7EK3W9za Yg7HqRkYl69oLtY5zMGyXTZtOMXlMCu0abdCIy9IT1SMIzgvLEHbW2tO/ynV8sYIYp5Q BL6lUb3wH99jD/7VsdFRpXvkLefTGV/D29VUY0ZI6vt2PJwoAqd+n7cyJooGmG88yqXt vI9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711581548; x=1712186348; 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=KaNlrVh6YX+OdjnoPnmjQwMmZEJRJLFsRjLteQznSUU=; b=BA1qgWaZ/heN1NpsqfK1tP1TcZkstXHANQpvxsQkRcMiyhBkcKGQPqKhwoabpdMTmm OzR4uh02GgXqB37eB0S85dnkSl6QcJ5YAKLH5+35jeUbhoIz11gUdD0OEDfFQGgnFbjH VOY8nMki8qqO0ATdIWHzpeFiJbOdkjpOyYBXDNKVfgvjHrcc/UrrNNfShG2niiiWPPD7 jmirOheuQi3kEhRdio+wZ/8lzuTOBYm30c+JatstZICD5CgqVtkHtOn8j2TwYYrYsa7L h04GPRSofLwm7a3RvCbO4aDWCEI2JeUoI2vD80H6mQbR6/40lExLCM/3LmakJBjMfOlC xjMg== X-Forwarded-Encrypted: i=1; AJvYcCWVauIUYM3hZBj4ymqTHPgfRQqJpPbhMKeAc4UJ+uTiKj/UXCk/4dR5sfB48kGFmvC1M3EFb7qikIahlbqN/mpAD0mzqR5Y5KodnI4= X-Gm-Message-State: AOJu0YylXQgejQK4WkvStqrndPidUYsDCJdGpcdFx7N/LOUSnEFxxtJK hqQdqGXWWNyOslEgs0gbGnLBUe9+FZewXWuxZTrDIvov3R5QlnD2jf0aCerOeeU= X-Google-Smtp-Source: AGHT+IFWJbt2/BUKuKdpJqTrO3Ps0Zm4Bbiulso5ad2yHWD7/eCmYh93EbMlYQB/kOSN+Tatt1jIOQ== X-Received: by 2002:a05:6871:a913:b0:22a:1399:a781 with SMTP id wn19-20020a056871a91300b0022a1399a781mr1281622oab.23.1711581548121; Wed, 27 Mar 2024 16:19:08 -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 js3-20020a056870bac300b0022a0519183csm81381oab.2.2024.03.27.16.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:19:07 -0700 (PDT) From: David Lechner To: Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov Cc: David Lechner , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: [PATCH RFC 5/7] iio: frequency: admv1013: Use devm_regulator_get_enable_get_voltage() Date: Wed, 27 Mar 2024 18:18:54 -0500 Message-ID: <20240327-regulator-get-enable-get-votlage-v1-5-5f4517faa059@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 We can reduce boilerplate code by using devm_regulator_get_enable_get_voltage(). The common mode voltage is now passed as a parameter in the init functions so we can avoid adding a state member that is only used during init. Signed-off-by: David Lechner Reviewed-by: Jonathan Cameron --- drivers/iio/frequency/admv1013.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/drivers/iio/frequency/admv1013.c b/drivers/iio/frequency/admv1013.c index 92923074f930..b0aa3cc27ea9 100644 --- a/drivers/iio/frequency/admv1013.c +++ b/drivers/iio/frequency/admv1013.c @@ -95,7 +95,6 @@ struct admv1013_state { struct clk *clkin; /* Protect against concurrent accesses to the device and to data */ struct mutex lock; - struct regulator *reg; struct notifier_block nb; unsigned int input_mode; unsigned int quad_se_mode; @@ -342,14 +341,9 @@ static int admv1013_update_quad_filters(struct admv1013_state *st) FIELD_PREP(ADMV1013_QUAD_FILTERS_MSK, filt_raw)); } -static int admv1013_update_mixer_vgate(struct admv1013_state *st) +static int admv1013_update_mixer_vgate(struct admv1013_state *st, int vcm) { unsigned int mixer_vgate; - int vcm; - - vcm = regulator_get_voltage(st->reg); - if (vcm < 0) - return vcm; if (vcm <= 1800000) mixer_vgate = (2389 * vcm / 1000000 + 8100) / 100; @@ -443,7 +437,7 @@ static const struct iio_chan_spec admv1013_channels[] = { ADMV1013_CHAN_CALIB(1, Q), }; -static int admv1013_init(struct admv1013_state *st) +static int admv1013_init(struct admv1013_state *st, int vcm_uv) { int ret; unsigned int data; @@ -483,7 +477,7 @@ static int admv1013_init(struct admv1013_state *st) if (ret) return ret; - ret = admv1013_update_mixer_vgate(st); + ret = admv1013_update_mixer_vgate(st, vcm_uv); if (ret) return ret; @@ -498,11 +492,6 @@ static int admv1013_init(struct admv1013_state *st) st->input_mode); } -static void admv1013_reg_disable(void *data) -{ - regulator_disable(data); -} - static void admv1013_powerdown(void *data) { unsigned int enable_reg, enable_reg_msk; @@ -557,11 +546,6 @@ static int admv1013_properties_parse(struct admv1013_state *st) else return -EINVAL; - st->reg = devm_regulator_get(&spi->dev, "vcm"); - if (IS_ERR(st->reg)) - return dev_err_probe(&spi->dev, PTR_ERR(st->reg), - "failed to get the common-mode voltage\n"); - ret = devm_regulator_bulk_get_enable(&st->spi->dev, ARRAY_SIZE(admv1013_vcc_regs), admv1013_vcc_regs); @@ -578,7 +562,7 @@ static int admv1013_probe(struct spi_device *spi) { struct iio_dev *indio_dev; struct admv1013_state *st; - int ret; + int ret, vcm_uv; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) @@ -597,16 +581,11 @@ static int admv1013_probe(struct spi_device *spi) if (ret) return ret; - ret = regulator_enable(st->reg); - if (ret) { - dev_err(&spi->dev, "Failed to enable specified Common-Mode Voltage!\n"); + ret = devm_regulator_get_enable_get_voltage(&spi->dev, "vcm"); + if (ret < 0) return ret; - } - ret = devm_add_action_or_reset(&spi->dev, admv1013_reg_disable, - st->reg); - if (ret) - return ret; + vcm_uv = ret; st->clkin = devm_clk_get_enabled(&spi->dev, "lo_in"); if (IS_ERR(st->clkin)) @@ -620,7 +599,7 @@ static int admv1013_probe(struct spi_device *spi) mutex_init(&st->lock); - ret = admv1013_init(st); + ret = admv1013_init(st, vcm_uv); if (ret) { dev_err(&spi->dev, "admv1013 init failed\n"); return ret; From patchwork Wed Mar 27 23:18:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13607643 Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.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 8BDF7155308 for ; Wed, 27 Mar 2024 23:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581553; cv=none; b=csXd7Sqo0qvAQmEhXdc9lYW1z/etSmSJhj7A+KOSl68pXq8jq0syXO+AAYDp3A7EXSZAyGM7FIswt7rLHphzA30Z+fcxr5n6YQcxX2a0j90CqnZlhGkF6ASGj63ETxydbdcRl1LDmUdX14EyPRSNstKVtenUqF/ZTKM6AynKLng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581553; c=relaxed/simple; bh=xlOFHnY+VUAHimj0/6CI3uzJ6CONg5CROD3tFFJ2TF4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rP6Tv3YMTA/9tXdFC781T3mjnk/Wclm32jgm7inJZ3wY9qLnAj+aW5TydohA4rKmqLpMpfII/+n2Udt5p0buSFkllOD3xXCx2KIDTP/XAmYUQLI+BeKl6ldpIjnlsyL1RDGVCh5ivyD/08DQ3Z3ZP7orQHYoiRhkiRax0RlZ4SI= 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=AZe/5H+P; arc=none smtp.client-ip=209.85.160.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="AZe/5H+P" Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-2218a0f55e1so217042fac.1 for ; Wed, 27 Mar 2024 16:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1711581549; x=1712186349; 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=CBx5yqCcIG/deXybWASqoKrfUt47GVVbdT7E/yXEMkE=; b=AZe/5H+Pjy5tCOeoAALOzNVLm6n1Q05iv9SH37MheVT1+g0TMz85zs6kL0vLUX5hRI gkaVoES9vc1z7jptM736If8A1nvpdcEZJb3ylbLRrEBcGud7KoJoDk6rPvt61ysRhnKb bKczNZLbrIb07MnkGyjqTJB7Q5+iT+PAxDnNA/AYFSNU8P8CR7Kkkwnn7y3eG9VoyJbZ Z1FzV9DRwmCFD+ccxbCVFv6cxwpJz6Cvl5PqQLZS3ch5H7fQm2jzuTTS1ylPJXX9BKTH qCwFjwoPgkRFzZS23CN9bn5BfO5lXQrGT0gyO94Lll+G1k3THkzdh0dGAFF6QxnGMKTz Og/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711581549; x=1712186349; 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=CBx5yqCcIG/deXybWASqoKrfUt47GVVbdT7E/yXEMkE=; b=HGiasjjmSxyo4/V6MYfynIFPmmXWckHsC9CRfT1zjul5bDumJNE7iuHQXi7vNdLpbW RO1gavYykF0hxpClI7k8pcV3+Ip6pQLXP7CUsgm6rLNedkpMD3V6KbQUQgdRhlD1b8NV dMMy828tudoirFRH0+fDHXofscMiGo67evWG96fcxVFiQzmWX/R/6A8yCtZL9TIcpk8A dE6a/rCmHfm6ptpDh2bR2g4ROudu8sb1dfQIiZSJHvWCu+B1hpFk1QA6sLiLH1euMbO1 wLn3tzT0P0uRsV89HRJ3ec0h/OOlGnagaYtR3JW6R2yePd7rzpza7hIBvkZsDlL2deZM Vvyg== X-Forwarded-Encrypted: i=1; AJvYcCWOt8Ss/zasqfQ2FC3S3ZqLC8naPtGpJxa/cjna5q6Cplwex+JH1ueJ+W///tAGjRuIGh0RXsQiuvWL5ADIEJUmYUuq5YEp9MkZN64= X-Gm-Message-State: AOJu0YwskLHGKUul1iw9U6fg4PpuOe0Le0LMB2QzPwEf1oVL6Ux0eB/L xZLpneTP8aR7YR3x075LEbzHu5HCPFM7kypspT9uq+jrwxZvNQZPjzrjvCJr894= X-Google-Smtp-Source: AGHT+IFXU8zmzWmrbkxOxvW7wtT9Hq/b5rbtfGnHI6ZuQs2D4otmJCIrbq7hVTyLaL9P54g4uvOwbQ== X-Received: by 2002:a05:6870:b14b:b0:229:fa5a:2fec with SMTP id a11-20020a056870b14b00b00229fa5a2fecmr1265617oal.54.1711581549199; Wed, 27 Mar 2024 16:19:09 -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 js3-20020a056870bac300b0022a0519183csm81381oab.2.2024.03.27.16.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:19:08 -0700 (PDT) From: David Lechner To: Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov Cc: David Lechner , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: [PATCH RFC 6/7] staging: iio: impedance-analyzer: admv1013: Use devm_regulator_get_enable_get_voltage() Date: Wed, 27 Mar 2024 18:18:55 -0500 Message-ID: <20240327-regulator-get-enable-get-votlage-v1-6-5f4517faa059@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 We can reduce boilerplate code by using devm_regulator_get_enable_get_voltage(). Signed-off-by: David Lechner Reviewed-by: Jonathan Cameron --- drivers/staging/iio/impedance-analyzer/ad5933.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index 9149d41fe65b..e4942833b793 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -84,7 +84,6 @@ struct ad5933_state { struct i2c_client *client; - struct regulator *reg; struct clk *mclk; struct delayed_work work; struct mutex lock; /* Protect sensor state */ @@ -660,13 +659,6 @@ static void ad5933_work(struct work_struct *work) } } -static void ad5933_reg_disable(void *data) -{ - struct ad5933_state *st = data; - - regulator_disable(st->reg); -} - static int ad5933_probe(struct i2c_client *client) { const struct i2c_device_id *id = i2c_client_get_device_id(client); @@ -685,21 +677,7 @@ static int ad5933_probe(struct i2c_client *client) mutex_init(&st->lock); - st->reg = devm_regulator_get(&client->dev, "vdd"); - if (IS_ERR(st->reg)) - return PTR_ERR(st->reg); - - ret = regulator_enable(st->reg); - if (ret) { - dev_err(&client->dev, "Failed to enable specified VDD supply\n"); - return ret; - } - - ret = devm_add_action_or_reset(&client->dev, ad5933_reg_disable, st); - if (ret) - return ret; - - ret = regulator_get_voltage(st->reg); + ret = devm_regulator_get_enable_get_voltage(&client->dev, "vdd"); if (ret < 0) return ret; From patchwork Wed Mar 27 23:18:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13607644 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.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 4D2751553AC for ; Wed, 27 Mar 2024 23:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581555; cv=none; b=Ah2CKGBCZ2OxcMT6Z0piDUJmawSOojWNjp3wbYoROZuyKIk6g0X3Kw7rQz1Ub0E+MMnhH3M3yL/TDsyxMLS2POSbUVzWAh6XsuuedM9gQxPXtDRywoypt6gQoox+sENWr13MjMCFaR7Cs3VyrB0MSxUKkqzw0t0+K3JlB5iAuSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581555; c=relaxed/simple; bh=h9SozZx07F/ieSA3Tkw6/3vSYWM+YqSBRP3PPQIUB78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s01TXp27sYLAMs0U+5l1UzKVTnZu/7Xq2d7mctZZP7s78/hDu9FtYGJVz+s8Dfry10XrUci3LrXvhVlk+A17PB+gaLjERwTPnAg+uXLMbNSVvWcR+0Je8YirTPJPqx6sxlpRIe2IuQMhYV2ZjcIprmk090Xa2gsr924/qrAht5Q= 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=eAqfAphT; arc=none smtp.client-ip=209.85.160.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 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="eAqfAphT" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-229cbc52318so225218fac.2 for ; Wed, 27 Mar 2024 16:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1711581550; x=1712186350; 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=CJZsj0mH5Na8/6xZVfDNraoADX8hsL14D7DbLT7TMPI=; b=eAqfAphTCe5xMLO7IDsfaBpiCj4b/x+7v8ccb8ODULuM2G7hkEN25kFJncN2sx/fvG QqUtlTjU4y695H2BTg3WTXcN767DuqbeSF6kh71SM1I0HU3UoyK8Q8jlsJwuNGAUdaqX v3y9v/LDcuEfFDJ4KrGbQzJPSwxGrC0/1sCznd7hZFChgt5v4WDZzdU2UoIMUeDGcrs/ PvpmycHNdqEKepsxWgg5WbEUrtho04hZf5xJ9rtPoZYW5V2jgvQTNy3hKTKqqAXl9uw2 AZCTB49zFOmtYTVDnDYwbARUFzNRGtTcij9x4iAXUwJ5fZatOfL/jouVCMKin9BmsZnq WBCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711581550; x=1712186350; 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=CJZsj0mH5Na8/6xZVfDNraoADX8hsL14D7DbLT7TMPI=; b=XdrnrfALbHBxViM/juaDJi2iI19o5WtKcxMYdnMf2GXna+Fo/b/A24sRZ+GJtf7Pr7 s0TmlHfWpzayx81qHRmgBXCzjaipzOVAKWVaF5q7pEnSRgNwoQsFbHFXFTwYTsrJOg/Z xDPO0BBcHyZAqTRTZz5ufoSAcZHM7vOb4Y55DzzZqITvk0542XgDiq8XqZUKx7RsRNgP jQK3J2LZ+340csW5cb6AvZPaZCdlrABkcwGC1lImYlQujfihgs99EM8HhTrlJvjDWu+w 6wCVa0U3Sf2XHhr7qTxQcctI1/67zMNgjTLEW+dAZ9nmRJXjvrfcml/Gc32GipxQ327G 80yQ== X-Forwarded-Encrypted: i=1; AJvYcCWbzKAlj72vK3tqQUHgxZ8q8HHw1W2oVvn+26exrcaiJhUZ82FwpSARAnj35RWMDXtMeyeWlu7Mcn2/EYwOYakU+Hd733AIGoNQmtU= X-Gm-Message-State: AOJu0YyvXwvUgOKpEIEkFBx3RnoUD8ykuzwX22JmVS3iMHavo0Rqx+n8 64zAAffXeqlx8TgpCc8wgkOivBB7OdkRBOVC/QZi/uP2LGUcqL85F7vFA+oawno= X-Google-Smtp-Source: AGHT+IFF6sA3ju+9mCH35rHh1zhgVOle14esmb64OwmiwIjcccCZ+Gff/k0HvFE6jlRCad9wpwZTGw== X-Received: by 2002:a05:6871:3a14:b0:221:9013:d783 with SMTP id pu20-20020a0568713a1400b002219013d783mr1213589oac.34.1711581550253; Wed, 27 Mar 2024 16:19:10 -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 js3-20020a056870bac300b0022a0519183csm81381oab.2.2024.03.27.16.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:19:09 -0700 (PDT) From: David Lechner To: Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov Cc: David Lechner , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: [PATCH RFC 7/7] Input: mpr121: Use devm_regulator_get_enable_get_voltage() Date: Wed, 27 Mar 2024 18:18:56 -0500 Message-ID: <20240327-regulator-get-enable-get-votlage-v1-7-5f4517faa059@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 We can reduce boilerplate code by using devm_regulator_get_enable_get_voltage(). Signed-off-by: David Lechner Reviewed-by: Jonathan Cameron --- drivers/input/keyboard/mpr121_touchkey.c | 45 +++----------------------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index d434753afab1..c59e7451f3cd 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -82,42 +82,6 @@ static const struct mpr121_init_register init_reg_table[] = { { AUTO_CONFIG_CTRL_ADDR, 0x0b }, }; -static void mpr121_vdd_supply_disable(void *data) -{ - struct regulator *vdd_supply = data; - - regulator_disable(vdd_supply); -} - -static struct regulator *mpr121_vdd_supply_init(struct device *dev) -{ - struct regulator *vdd_supply; - int err; - - vdd_supply = devm_regulator_get(dev, "vdd"); - if (IS_ERR(vdd_supply)) { - dev_err(dev, "failed to get vdd regulator: %ld\n", - PTR_ERR(vdd_supply)); - return vdd_supply; - } - - err = regulator_enable(vdd_supply); - if (err) { - dev_err(dev, "failed to enable vdd regulator: %d\n", err); - return ERR_PTR(err); - } - - err = devm_add_action_or_reset(dev, mpr121_vdd_supply_disable, - vdd_supply); - if (err) { - dev_err(dev, "failed to add disable regulator action: %d\n", - err); - return ERR_PTR(err); - } - - return vdd_supply; -} - static void mpr_touchkey_report(struct input_dev *dev) { struct mpr121_touchkey *mpr121 = input_get_drvdata(dev); @@ -233,7 +197,6 @@ static int mpr121_phys_init(struct mpr121_touchkey *mpr121, static int mpr_touchkey_probe(struct i2c_client *client) { struct device *dev = &client->dev; - struct regulator *vdd_supply; int vdd_uv; struct mpr121_touchkey *mpr121; struct input_dev *input_dev; @@ -241,11 +204,9 @@ static int mpr_touchkey_probe(struct i2c_client *client) int error; int i; - vdd_supply = mpr121_vdd_supply_init(dev); - if (IS_ERR(vdd_supply)) - return PTR_ERR(vdd_supply); - - vdd_uv = regulator_get_voltage(vdd_supply); + vdd_uv = devm_regulator_get_enable_get_voltage(dev, "vdd"); + if (vdd_uv < 0) + return vdd_uv; mpr121 = devm_kzalloc(dev, sizeof(*mpr121), GFP_KERNEL); if (!mpr121)