linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
Cc: Loic Poulain <loic.poulain@linaro.org>,
	Robert Foss <robert.foss@linaro.org>,
	Wolfram Sang <wsa@kernel.org>,
	linux-i2c@vger.kernel.org, linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH 8/9] i2c: qcom-cci: add support of optional vbus-supply regulators
Date: Fri, 4 Feb 2022 10:21:30 -0800	[thread overview]
Message-ID: <Yf1uqi/lzF5N1txV@ripper> (raw)
In-Reply-To: <20220203164711.1712090-1-vladimir.zapolskiy@linaro.org>

On Thu 03 Feb 08:47 PST 2022, Vladimir Zapolskiy wrote:

> The change adds handling of optional vbus regulators in the driver.
> 
> Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
> ---
>  drivers/i2c/busses/i2c-qcom-cci.c | 49 +++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
> index 775945f7b4cd..2fc7f1f2616f 100644
> --- a/drivers/i2c/busses/i2c-qcom-cci.c
> +++ b/drivers/i2c/busses/i2c-qcom-cci.c
> @@ -11,6 +11,7 @@
>  #include <linux/of.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/regulator/consumer.h>
>  
>  #define CCI_HW_VERSION				0x0
>  #define CCI_RESET_CMD				0x004
> @@ -480,6 +481,20 @@ static void cci_disable_clocks(struct cci *cci)
>  static int __maybe_unused cci_suspend_runtime(struct device *dev)
>  {
>  	struct cci *cci = dev_get_drvdata(dev);
> +	struct regulator *bus_regulator;
> +	unsigned int i;
> +
> +	for (i = 0; i < cci->data->num_masters; i++) {
> +		if (!cci->master[i].cci)
> +			continue;
> +
> +		bus_regulator = cci->master[i].adap.bus_regulator;
> +		if (!bus_regulator)
> +			continue;
> +
> +		if (regulator_is_enabled(bus_regulator) > 0)
> +			regulator_disable(bus_regulator);
> +	}
>  
>  	cci_disable_clocks(cci);
>  	return 0;
> @@ -488,12 +503,30 @@ static int __maybe_unused cci_suspend_runtime(struct device *dev)
>  static int __maybe_unused cci_resume_runtime(struct device *dev)
>  {
>  	struct cci *cci = dev_get_drvdata(dev);
> +	struct regulator *bus_regulator;
> +	unsigned int i;
>  	int ret;
>  
>  	ret = cci_enable_clocks(cci);
>  	if (ret)
>  		return ret;
>  
> +	for (i = 0; i < cci->data->num_masters; i++) {
> +		if (!cci->master[i].cci)
> +			continue;
> +
> +		bus_regulator = cci->master[i].adap.bus_regulator;
> +		if (!bus_regulator)
> +			continue;
> +
> +		if (!regulator_is_enabled(bus_regulator)) {

regulator_is_enabled() tests if the regulator is enabled, not if you
have enabled it. So if this is a shared regulator you might learn that
it's already on, skip your regulator_enable() and then the other
consumer turns it off behind your back.

If you want the regulator to be on, you should regulator_enable().

> +			ret = regulator_enable(bus_regulator);
> +			if (ret)
> +				dev_err(dev, "failed to enable regulator: %d\n",
> +					ret);
> +		}
> +	}
> +
>  	cci_init(cci);
>  	return 0;
>  }
> @@ -593,6 +626,7 @@ static int cci_probe(struct platform_device *pdev)
>  	dev_dbg(dev, "CCI HW version = 0x%08x", val);
>  
>  	for_each_available_child_of_node(dev->of_node, child) {
> +		struct regulator *bus_regulator;
>  		struct cci_master *master;
>  		u32 idx;
>  
> @@ -637,6 +671,21 @@ static int cci_probe(struct platform_device *pdev)
>  			master->cci = NULL;
>  			goto error_i2c;
>  		}
> +
> +		/*
> +		 * It might be possible to find an optional vbus supply, but
> +		 * it requires to pass the registration of an I2C adapter
> +		 * device and its association with a bus device tree node.
> +		 */

I'm afraid that I don't understand this comment. The regulator is
optional because most of the time we don't control it explicitly.

So a comment like "Control of IO supply is optional" seems more
relevant.

Regards,
Bjorn

> +		bus_regulator = devm_regulator_get_optional(&master->adap.dev,
> +							    "vbus");
> +		if (IS_ERR(bus_regulator)) {
> +			ret = PTR_ERR(bus_regulator);
> +			if (ret == -EPROBE_DEFER)
> +				goto error_i2c;
> +			bus_regulator = NULL;
> +		}
> +		master->adap.bus_regulator = bus_regulator;
>  	}
>  
>  	ret = cci_reset(cci);
> -- 
> 2.33.0
> 

  parent reply	other threads:[~2022-02-04 18:21 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 16:46 [PATCH 0/9] i2c: qcom-cci: fixes and updates Vladimir Zapolskiy
2022-02-03 16:46 ` [PATCH 1/9] dt-bindings: i2c: qcom-cci: add QCOM SM8450 compatible Vladimir Zapolskiy
2022-02-04 11:04   ` Robert Foss
2022-02-11 14:12   ` Rob Herring
2022-02-18  9:02   ` Wolfram Sang
2022-02-03 16:46 ` [PATCH 2/9] dt-bindings: i2c: qcom-cci: add description of a vbus-supply property Vladimir Zapolskiy
2022-02-04 11:06   ` Robert Foss
2022-02-04 18:05   ` Bjorn Andersson
2022-02-04 18:42     ` Mark Brown
2022-02-04 19:02       ` Bjorn Andersson
2022-02-04 19:32         ` Mark Brown
2022-02-07 14:08           ` Vladimir Zapolskiy
2022-02-07 14:39             ` Mark Brown
2022-02-07 18:31               ` Vladimir Zapolskiy
2022-02-08 12:55                 ` Mark Brown
2022-02-10 15:33                   ` Dmitry Baryshkov
2022-02-10 15:44                     ` Mark Brown
2022-02-10 17:32                       ` Dmitry Baryshkov
2022-02-10 17:36                         ` Mark Brown
2022-02-10 18:21                           ` Dmitry Baryshkov
2022-02-10 18:26                             ` Mark Brown
2022-02-10 19:02                               ` Dmitry Baryshkov
2022-02-03 16:47 ` [PATCH 3/9] i2c: qcom-cci: don't delete an unregistered adapter Vladimir Zapolskiy
2022-02-04 10:05   ` Robert Foss
2022-02-04 18:08   ` Bjorn Andersson
2022-02-11 17:45     ` Wolfram Sang
2022-02-11 17:43   ` Wolfram Sang
2022-02-03 16:47 ` [PATCH 4/9] i2c: qcom-cci: don't put a device tree node before i2c_add_adapter() Vladimir Zapolskiy
2022-02-04 10:17   ` Robert Foss
2022-02-04 18:11   ` Bjorn Andersson
2022-02-11 17:44   ` Wolfram Sang
2022-02-03 16:47 ` [PATCH 5/9] i2c: qcom-cci: initialize CCI controller after registration of adapters Vladimir Zapolskiy
2022-02-03 17:29   ` Loic Poulain
2022-02-03 18:45     ` Vladimir Zapolskiy
2022-02-04 11:18       ` Loic Poulain
2022-02-04 18:31   ` Bjorn Andersson
2022-02-03 16:47 ` [PATCH 6/9] i2c: qcom-cci: simplify probe by removing one loop over busses Vladimir Zapolskiy
2022-02-04 10:20   ` Robert Foss
2022-02-03 16:47 ` [PATCH 7/9] i2c: qcom-cci: simplify access to bus data structure Vladimir Zapolskiy
2022-02-04 10:21   ` Robert Foss
2022-02-03 16:47 ` [PATCH 8/9] i2c: qcom-cci: add support of optional vbus-supply regulators Vladimir Zapolskiy
2022-02-04 11:03   ` Robert Foss
2022-02-04 11:41     ` Loic Poulain
2022-02-04 18:28       ` Bjorn Andersson
2022-02-10 15:37       ` Dmitry Baryshkov
2022-02-04 18:21   ` Bjorn Andersson [this message]
2022-02-03 16:47 ` [PATCH 9/9] i2c: qcom-cci: add sm8450 compatible Vladimir Zapolskiy
2022-02-04 11:03   ` Robert Foss
2022-02-18  9:02   ` Wolfram Sang
2022-02-11 17:49 ` [PATCH 0/9] i2c: qcom-cci: fixes and updates Wolfram Sang
2022-02-11 19:46   ` Vladimir Zapolskiy
2022-02-11 20:43     ` Wolfram Sang
2022-02-17 19:57 ` Wolfram Sang
2022-02-17 21:47   ` Vladimir Zapolskiy
2022-02-18  9:05     ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yf1uqi/lzF5N1txV@ripper \
    --to=bjorn.andersson@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=robert.foss@linaro.org \
    --cc=vladimir.zapolskiy@linaro.org \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).