All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bibby Hsieh <bibby.hsieh@mediatek.com>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Wolfram Sang <wsa@the-dreams.de>,
	linux-i2c <linux-i2c@vger.kernel.org>,
	Tomasz Figa <tfiga@chromium.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>
Subject: Re: [PATCH v9 3/4] misc: eeprom: at24: support pm_runtime control
Date: Mon, 6 Jan 2020 15:09:12 +0800	[thread overview]
Message-ID: <1578294552.7875.1.camel@mtksdaap41> (raw)
In-Reply-To: <CAMpxmJUotmLe6sJ4ZEbMMzUeLJMi-gHyamEUuDJzj6k_4JjCBg@mail.gmail.com>

On Thu, 2019-12-19 at 11:50 +0100, Bartosz Golaszewski wrote:
> pon., 16 gru 2019 o 09:04 Bibby Hsieh <bibby.hsieh@mediatek.com> napisał(a):
> >
> > Although in the most platforms, the power of eeprom are alway
> > on, some platforms disable the eeprom power in order to meet
> > low power request. This patch add the pm_runtime ops to control
> > power to support all platforms.
> >
> > Signed-off-by: Bibby Hsieh <bibby.hsieh@mediatek.com>
> > ---
> >  drivers/misc/eeprom/at24.c | 38 ++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 38 insertions(+)
> >
> > diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> > index 0681d5fdd538..6ba23a7e4da1 100644
> > --- a/drivers/misc/eeprom/at24.c
> > +++ b/drivers/misc/eeprom/at24.c
> > @@ -22,6 +22,7 @@
> >  #include <linux/nvmem-provider.h>
> >  #include <linux/regmap.h>
> >  #include <linux/pm_runtime.h>
> > +#include <linux/regulator/consumer.h>
> >  #include <linux/gpio/consumer.h>
> >
> >  /* Address pointer is 16 bit. */
> > @@ -91,6 +92,7 @@ struct at24_data {
> >
> >         struct gpio_desc *wp_gpio;
> >
> > +       struct regulator *vcc_reg;
> >         /*
> >          * Some chips tie up multiple I2C addresses; dummy devices reserve
> >          * them for us, and we'll use them with SMBus calls.
> > @@ -662,6 +664,10 @@ static int at24_probe(struct i2c_client *client)
> >         at24->client[0].client = client;
> >         at24->client[0].regmap = regmap;
> >
> > +       at24->vcc_reg = devm_regulator_get(dev, "vcc");
> > +       if (IS_ERR(at24->vcc_reg))
> > +               return PTR_ERR(at24->vcc_reg);
> > +
> >         at24->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_HIGH);
> >         if (IS_ERR(at24->wp_gpio))
> >                 return PTR_ERR(at24->wp_gpio);
> > @@ -701,6 +707,12 @@ static int at24_probe(struct i2c_client *client)
> >
> >         i2c_set_clientdata(client, at24);
> >
> > +       err = regulator_enable(at24->vcc_reg);
> > +       if (err) {
> > +               dev_err(dev, "Failed to enable vcc regulator\n");
> > +               return err;
> > +       }
> > +
> >         /* enable runtime pm */
> >         pm_runtime_set_active(dev);
> >         pm_runtime_enable(dev);
> > @@ -713,6 +725,7 @@ static int at24_probe(struct i2c_client *client)
> >         pm_runtime_idle(dev);
> >         if (err) {
> >                 pm_runtime_disable(dev);
> > +               regulator_disable(at24->vcc_reg);
> >                 return -ENODEV;
> >         }
> >
> > @@ -729,14 +742,39 @@ static int at24_probe(struct i2c_client *client)
> >  static int at24_remove(struct i2c_client *client)
> >  {
> >         pm_runtime_disable(&client->dev);
> > +       if (!pm_runtime_status_suspended(&client->dev))
> > +               regulator_disable(at24->vcc_reg);
> 
> Did you at least *try* to compile this? Because if you did, you'd
> notice it doesn't build.
> 
> Bart


Yep, I try to compile them... but I forget to enable at24 in
defconfig... Sorry, I will fix them in my next version.


Bibby
> 
> >         pm_runtime_set_suspended(&client->dev);
> >
> >         return 0;
> >  }
> >
> > +static int __maybe_unused at24_suspend(struct device *dev)
> > +{
> > +       struct i2c_client *client = to_i2c_client(dev);
> > +       struct at24_data *at24 = i2c_get_clientdata(client);
> > +
> > +       return regulator_disable(at24->vcc_reg);
> > +}
> > +
> > +static int __maybe_unused at24_resume(struct device *dev)
> > +{
> > +       struct i2c_client *client = to_i2c_client(dev);
> > +       struct at24_data *at24 = i2c_get_clientdata(client);
> > +
> > +       return regulator_enable(at24->vcc_reg);
> > +}
> > +
> > +static const struct dev_pm_ops at24_pm_ops = {
> > +       SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
> > +                               pm_runtime_force_resume)
> > +       SET_RUNTIME_PM_OPS(at24_suspend, at24_resume, NULL)
> > +};
> > +
> >  static struct i2c_driver at24_driver = {
> >         .driver = {
> >                 .name = "at24",
> > +               .pm = &at24_pm_ops,
> >                 .of_match_table = at24_of_match,
> >                 .acpi_match_table = ACPI_PTR(at24_acpi_ids),
> >         },
> > --
> > 2.18.0


  reply	other threads:[~2020-01-06  7:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-16  8:04 [PATCH v9 0/4] add power control in i2c and at24 Bibby Hsieh
2019-12-16  8:04 ` [PATCH v9 1/4] dt-binding: eeprom: at24: add vcc-supply property Bibby Hsieh
2019-12-16  8:04 ` [PATCH v9 2/4] dt-binding: i2c: add bus-supply property Bibby Hsieh
2019-12-18 14:47   ` Rob Herring
2019-12-16  8:04 ` [PATCH v9 3/4] misc: eeprom: at24: support pm_runtime control Bibby Hsieh
2019-12-19 10:50   ` Bartosz Golaszewski
2020-01-06  7:09     ` Bibby Hsieh [this message]
2019-12-16  8:04 ` [PATCH v9 4/4] i2c: core: support bus regulator controlling in adapter Bibby Hsieh
2019-12-16 11:58   ` Tomasz Figa

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=1578294552.7875.1.camel@mtksdaap41 \
    --to=bibby.hsieh@mediatek.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=devicetree@vger.kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=mark.rutland@arm.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.