All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grygorii Strashko <grygorii.strashko@ti.com>
To: Tomasz Figa <tfiga@chromium.org>
Cc: Bibby Hsieh <bibby.hsieh@mediatek.com>,
	Wolfram Sang <wsa@the-dreams.de>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	linux-i2c <linux-i2c@vger.kernel.org>,
	Nicolas Boichat <drinkcat@chromium.org>,
	srv_heupstream <srv_heupstream@mediatek.com>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-devicetree <devicetree@vger.kernel.org>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>
Subject: Re: [PATCH v15 2/2] i2c: core: support bus regulator controlling in adapter
Date: Tue, 26 May 2020 21:03:18 +0300	[thread overview]
Message-ID: <543950fa-83c0-9d3d-e64a-068be2368717@ti.com> (raw)
In-Reply-To: <CAAFQd5Bx=zgsUAg7fA2jfsV_yFyPmnotTWEBEr2V3Nn5HO8qQQ@mail.gmail.com>



On 25/05/2020 14:34, Tomasz Figa wrote:
> Hi Grygorii,
> 
> On Fri, May 22, 2020 at 7:59 PM Grygorii Strashko
> <grygorii.strashko@ti.com> wrote:
>>
>>
>>
>> On 19/05/2020 10:27, Bibby Hsieh wrote:
>>> Although in the most platforms, the bus power of i2c
>>> are alway on, some platforms disable the i2c bus power
>>> in order to meet low power request.
>>>
>>> We get and enable bulk regulator in i2c adapter device.
>>>
>>> Signed-off-by: Bibby Hsieh <bibby.hsieh@mediatek.com>
>>> ---
>>>    drivers/i2c/i2c-core-base.c | 84 +++++++++++++++++++++++++++++++++++++
>>>    include/linux/i2c.h         |  2 +
>>>    2 files changed, 86 insertions(+)
>>>
>>> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
>>> index 5cc0b0ec5570..e1cc8d46bc51 100644
>>> --- a/drivers/i2c/i2c-core-base.c
>>> +++ b/drivers/i2c/i2c-core-base.c
>>> @@ -313,12 +313,14 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client)
>>>    static int i2c_device_probe(struct device *dev)
>>>    {
>>>        struct i2c_client       *client = i2c_verify_client(dev);
>>> +     struct i2c_adapter      *adap;
>>>        struct i2c_driver       *driver;
>>>        int status;
>>>
>>>        if (!client)
>>>                return 0;
>>>
>>> +     adap = client->adapter;
>>>        driver = to_i2c_driver(dev->driver);
>>>
>>>        client->irq = client->init_irq;
>>> @@ -378,6 +380,12 @@ static int i2c_device_probe(struct device *dev)
>>>
>>>        dev_dbg(dev, "probe\n");
>>>
>>> +     status = regulator_enable(adap->bus_regulator);
>>> +     if (status < 0) {
>>> +             dev_err(&adap->dev, "Failed to enable power regulator\n");
>>> +             goto err_clear_wakeup_irq;
>>> +     }
>>> +
>>>        status = of_clk_set_defaults(dev->of_node, false);
>>>        if (status < 0)
>>>                goto err_clear_wakeup_irq;
>>> @@ -414,12 +422,14 @@ static int i2c_device_probe(struct device *dev)
>>>    static int i2c_device_remove(struct device *dev)
>>>    {
>>>        struct i2c_client       *client = i2c_verify_client(dev);
>>> +     struct i2c_adapter      *adap;
>>>        struct i2c_driver       *driver;
>>>        int status = 0;
>>>
>>>        if (!client || !dev->driver)
>>>                return 0;
>>>
>>> +     adap = client->adapter;
>>>        driver = to_i2c_driver(dev->driver);
>>>        if (driver->remove) {
>>>                dev_dbg(dev, "remove\n");
>>> @@ -427,6 +437,8 @@ static int i2c_device_remove(struct device *dev)
>>>        }
>>>
>>>        dev_pm_domain_detach(&client->dev, true);
>>> +     if (!pm_runtime_status_suspended(&client->dev))
>>> +             regulator_disable(adap->bus_regulator);
>>
>> Not sure this check is correct.
>>
>> i2c_device_probe()
>>    - regulator_enable - 1
>>
>> pm_runtime_get()
>>    - regulator_enable - 2
>>
> 
> I believe regulator_enable() wouldn't be called again, because the
> device was already active in probe. However, I've been having
> difficulties keeping track of runtime PM semantics under various
> circumstances (e.g. ACPI vs DT), so can't tell for sure anymore.

True.

I've found pretty useful:
  - CONFIG_PM_ADVANCED_DEBUG
  - bind/unbind
for such testing.

for regulators - num_users\x02 can be checked.


> 
>> i2c_device_remove()
>>    - pm_runtime_status_suspended() flase
>>      - regulator_disable() - 1 --> still active?
>>
>> Sorry, I probably missing smth.
>>
>>>
>>>        dev_pm_clear_wake_irq(&client->dev);
>>>        device_init_wakeup(&client->dev, false);
>>> @@ -438,6 +450,72 @@ static int i2c_device_remove(struct device *dev)
>>>        return status;
>>>    }
>>>
>>
>> [...]
>>
>> --
>> Best regards,
>> grygorii

-- 
Best regards,
grygorii

      reply	other threads:[~2020-05-26 18:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19  7:27 [PATCH v15 0/2] add power control in i2c Bibby Hsieh
2020-05-19  7:27 ` [PATCH v15 1/2] dt-binding: i2c: add bus-supply property Bibby Hsieh
2020-05-19  8:48   ` Wolfram Sang
2020-05-22 14:59     ` Wolfram Sang
2020-05-19  7:27 ` [PATCH v15 2/2] i2c: core: support bus regulator controlling in adapter Bibby Hsieh
2020-05-19  8:48   ` Wolfram Sang
2020-05-22 15:00     ` Wolfram Sang
2020-05-25 11:40       ` Tomasz Figa
2020-05-25 12:00         ` Wolfram Sang
2020-05-22 17:59   ` Grygorii Strashko
2020-05-25 11:34     ` Tomasz Figa
2020-05-26 18:03       ` Grygorii Strashko [this message]

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=543950fa-83c0-9d3d-e64a-068be2368717@ti.com \
    --to=grygorii.strashko@ti.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=bibby.hsieh@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robh+dt@kernel.org \
    --cc=srv_heupstream@mediatek.com \
    --cc=tfiga@chromium.org \
    --cc=wsa@the-dreams.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.