Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp97468lqh; Wed, 27 Mar 2024 16:20:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXiUaokvE8Hzcvk07PJsZPGC4VCF8EPHqJD5h4ZCPkyNklcuSV/dKw0r4/pm0o6ZkYk5s/qjBgUE4oaZVa6nlVdR2mlPdYLxb0OqX4ErA== X-Google-Smtp-Source: AGHT+IH3RiHNfmY0RlaBZ2s8A9D4gwIr/DgNgDf5UeWiRFUSgt8uuvV/iyyGuL4rLfMJhG7FtzTW X-Received: by 2002:a05:6a00:9098:b0:6ea:d792:b69d with SMTP id jo24-20020a056a00909800b006ead792b69dmr204214pfb.14.1711581655752; Wed, 27 Mar 2024 16:20:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711581655; cv=pass; d=google.com; s=arc-20160816; b=Dwh6SWZAbEEHs4pqOfYZcaChOdvp6aoC/Uk5/l/RtdhreuSNTfZ5nnG2BdcdtG6Bkv xJ3zCTwyIOLdffVIyCcyH173Z6mIUrzbztN145dzhJHX+l1+YrmWhQS5pSeXMWeTFFtK VBC7qB/tuFEYvL0M20KBM4haTLFLkbuf5G/jzln0IiWkYWj8Ho/CSD8T5dcdB2098K5j JciJRIS8vNhAYNg3Lghl4J/ZxWkUDixjyzNa7yXwDYYkaLU9VSYlfiZGDEIzkqBdMJT1 FGrxjNBt1cGT4jFvZVE6ZEUfGt+aEL4EWfr/2qG0SUMQWyUxaw0W1pZ8kw2VBrKqqOHI h33g== 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=TOfZtVlJMTFXxAc7ahXTmKHh36zHepITVD/rnFowmPs=; fh=hg4nK2bD9VIu4gQucjcVjJNh6ifrlCAfISnddQnVVxs=; b=PmnyTQRuC5LBYzqW9/+aOz3MiBQh4raMwGWsBFJI07DIlMi0g4iYS+pgsrvaK68cjQ 3Y3IsJb1ZIuhVfzS26GcPg2bOjAkJR6gnLtQG0jhkNT9oTdjKv/FlgXjY6/yO8fJMV8/ Kn1J0CG0UhqOWU4yG569t0wp5lxyhcjmB8+hSf1wtxp0vqcsPY7WLPf4gRRtp971bNy5 oACXJzgAjo7lT5vhnlMSIE8o74WDCCeEXfBnWmZOAy6lSinqEXO8SxNpSVaFN8QarYdm +ccysq2tIyO3wKM2fzWcXKngxmP1UDmE26FaIz8svgnY1FBukaOYSl2zsfp2LJ62FYC5 QKGg==; 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=FLsxfZAK; 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-122158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122158-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id jc22-20020a056a006c9600b006eaa2134e44si197854pfb.56.2024.03.27.16.20.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:20:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=FLsxfZAK; 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-122158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122158-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7621EB21BC0 for ; Wed, 27 Mar 2024 23:20:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18E9E156654; Wed, 27 Mar 2024 23:19:12 +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="FLsxfZAK" Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (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 B3BAA155310 for ; Wed, 27 Mar 2024 23:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581549; cv=none; b=F42Kw7uV8jTzwFDWytkcgY0MHzonD/QdNA60wDMWI+4h9G8sNEKp8OHi3icV9fKmfg8FpnHuvrQZlTJsi25udWZ6DWHLrgTyI9rD2fLkU1/hGqmNsEdKfclIlcZcDFA/i2uXYYYFIMtuWcLMQiAyOA2/y3fwInl0ryiKTYPm78E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581549; c=relaxed/simple; bh=A4uSmS5u3AK9wMfER4kmGXxo9e/XTrxNUtjD7xNvI4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wwk/QS5uZi9uLvXR0PvN5OT40F5c86MHZaHoCYJaOh6q1oFNRrTWuADQCjBQAzAzf8HiCJnzLF4pUsiKUr43jTWJdjkoj9yFv6IXgCrtpMIVJRXYKptdKJUzkTXzEfBTPOJEa+gUN2oBcTGg93XdIw5FP26vnzN5mDoiBwttdMo= 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.160.53 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-oa1-f53.google.com with SMTP id 586e51a60fabf-221e6bf537dso253440fac.1 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=mGGPXHU6pu4IpRyhIbBrpKSLY+vFX3gkYCnvZ2zFZ3JuymrVEiKLJFEfTBaBRsyk7w 9T4N4qN9yVmIqlpJH06XbofJ9V1BCd2A76G4S/D0I4HAA+fSuPco+dbksU/tdyEofp+Q /JES+UtaEFpGqARyLnVNG+heDrEymAibcA156zOn8sPPPIsF4yQ+0CJ5AWkipwt/IioX EYz8pMarmtSA2f83QFBivFGd85W9D9mzj7L5v6nCeX2SOFOhSItMaq6anugK+qww+n1x PsHRvFiaW6POOMV3TuuWymxBj7iRfPl2RkE65yqdulrfhZpf+RMaq48TBQ9aZLZR4QdM CozQ== X-Forwarded-Encrypted: i=1; AJvYcCWFEZAzSyRNBO+fa9mo5iT+oJT+DfjBm5MaXJhCrkWR+JxLL6tj3QJ+tumwlf8Bm0EDnqajrEPWrJ7OBNA2wQnAqmkSWNO3bXFrx7i/ X-Gm-Message-State: AOJu0Yzj+YjpYox5mrcuzexCWv0s4lBm294nrntLGy9v1tuxxCWLywCr mvFCSks6vG+yS1AoskSQDFmTIutmej7XVkvvgk0fvblWyV7Inxaa68QANt+44ag= 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-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 We can reduce boilerplate code by using devm_regulator_get_enable_get_voltage(). Signed-off-by: David Lechner --- 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 = { -- 2.43.2