public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Reichel <sre@kernel.org>
To: Liam Breck <liam@networkimprov.net>
Cc: "Andrew F. Davis" <afd@ti.com>,
	linux-pm@vger.kernel.org,
	Matt Ranostay <matt@ranostay.consulting>,
	Liam Breck <kernel@networkimprov.net>
Subject: Re: [PATCH v11 04/10] power: power_supply: Add power_supply_battery_info and API
Date: Thu, 23 Mar 2017 11:17:27 +0100	[thread overview]
Message-ID: <20170323101727.y53vc74fskqxdw34@earth> (raw)
In-Reply-To: <CAKvHMgTpRLx+8NHsjcaGpqN=W-7ujBoiXtRwm9A+JGbcNANS-w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6757 bytes --]

Hi,

On Mon, Mar 20, 2017 at 01:59:01PM -0700, Liam Breck wrote:
> On Mon, Mar 20, 2017 at 2:43 AM, Liam Breck <liam@networkimprov.net> wrote:
> > From: Liam Breck <kernel@networkimprov.net>
> >
> > power_supply_get_battery_info() reads battery data from devicetree.
> > struct power_supply_battery_info provides battery data to drivers.
> > Drivers may surface battery data in sysfs via corresponding
> > POWER_SUPPLY_PROP_* fields.
> >
> > Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
> > Signed-off-by: Liam Breck <kernel@networkimprov.net>
> > ---
> >  Documentation/power/power_supply_class.txt | 12 ++++++++
> >  drivers/power/supply/power_supply_core.c   | 45 ++++++++++++++++++++++++++++++
> >  include/linux/power_supply.h               | 18 ++++++++++++
> >  3 files changed, 75 insertions(+)
> >
> > diff --git a/Documentation/power/power_supply_class.txt b/Documentation/power/power_supply_class.txt
> > index 0c72588..dc92c77 100644
> > --- a/Documentation/power/power_supply_class.txt
> > +++ b/Documentation/power/power_supply_class.txt
> > @@ -174,6 +174,18 @@ issued by external power supply will notify supplicants via
> >  external_power_changed callback.
> >
> >
> > +Devicetree battery characteristics
> > +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > +Drivers should call power_supply_get_battery_info() to obtain battery
> > +characteristics from a devicetree battery node, defined in
> > +Documentation/devicetree/bindings/power/supply/battery.txt. This is
> > +implemented in drivers/power/supply/bq27xxx_battery.c.
> > +
> > +Properties in struct power_supply_battery_info and their counterparts in the
> > +battery node have names corresponding to elements in enum power_supply_property,
> > +for naming consistency between sysfs attributes and battery node properties.
> > +
> > +
> >  QA
> >  ~~
> >  Q: Where is POWER_SUPPLY_PROP_XYZ attribute?
> > diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> > index a74d8ca..61e20b1 100644
> > --- a/drivers/power/supply/power_supply_core.c
> > +++ b/drivers/power/supply/power_supply_core.c
> > @@ -17,6 +17,7 @@
> >  #include <linux/device.h>
> >  #include <linux/notifier.h>
> >  #include <linux/err.h>
> > +#include <linux/of.h>
> >  #include <linux/power_supply.h>
> >  #include <linux/thermal.h>
> >  #include "power_supply.h"
> > @@ -487,6 +488,50 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
> >  EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
> >  #endif /* CONFIG_OF */
> >
> > +int power_supply_get_battery_info(struct power_supply *psy,
> > +                                 struct power_supply_battery_info *info)
> > +{
> > +       struct device_node *battery_np;
> > +       const char *value;
> > +       int err;
> > +
> > +       info->energy_full_design_uwh = -EINVAL;
> > +       info->charge_full_design_uah = -EINVAL;
> > +       info->voltage_min_design_uv  = -EINVAL;
> > +
> > +       if (!psy->of_node) {
> > +               dev_warn(&psy->dev, "%s currently only supports devicetree\n",
> > +                        __func__);
> > +               return -ENXIO;
> > +       }
> > +
> > +       battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
> > +       if (!battery_np)
> > +               return -ENODEV;
> > +
> > +       err = of_property_read_string(battery_np, "compatible", &value);
> > +       if (err)
> > +               return err;
> > +
> > +       if (strcmp("simple-battery", value))
> > +               return -ENODEV;
> > +
> > +       /* The property and field names below must correspond to elements
> > +        * in enum power_supply_property. For reasoning, see
> > +        * Documentation/power/power_supply_class.txt.
> > +        */

Let's make this "should correspond".

> > +       of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
> > +                            &info->energy_full_design_uwh);
> > +       of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
> > +                            &info->charge_full_design_uah);
> > +       of_property_read_u32(battery_np, "voltage-min-design-microvolt",
> > +                            &info->voltage_min_design_uv);

> Should we also check for an acpi_handle, and use
> device_property_read_* here? Tho presumably the acpi property names
> would be different...
> 
> I wouldn't have a way to test that however.

Yes, please use device_property_read_* instead of of_property_read_*.
Apart from that you do not have to care for ACPI for now. It can be
added once needed.

> > +
> > +       return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
> > +
> >  int power_supply_get_property(struct power_supply *psy,
> >                             enum power_supply_property psp,
> >                             union power_supply_propval *val)
> > diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
> > index 3965503..e84f1d3 100644
> > --- a/include/linux/power_supply.h
> > +++ b/include/linux/power_supply.h
> > @@ -288,6 +288,21 @@ struct power_supply_info {
> >         int use_for_apm;
> >  };
> >
> > +/*
> > + * This is the recommended struct to manage static battery parameters,
> > + * populated by power_supply_get_battery_info(). Most platform drivers should
> > + * use these for consistency.
> > + * Its field names must correspond to elements in enum power_supply_property.
> > + * The default field value is -EINVAL.
> > + * Power supply class itself doesn't use this.
> > + */
> > +
> > +struct power_supply_battery_info {
> > +       int energy_full_design_uwh;     /* microWatt-hours */
> > +       int charge_full_design_uah;     /* microAmp-hours */
> > +       int voltage_min_design_uv;      /* microVolts */
> > +};
> > +
> >  extern struct atomic_notifier_head power_supply_notifier;
> >  extern int power_supply_reg_notifier(struct notifier_block *nb);
> >  extern void power_supply_unreg_notifier(struct notifier_block *nb);
> > @@ -306,6 +321,9 @@ static inline struct power_supply *
> >  devm_power_supply_get_by_phandle(struct device *dev, const char *property)
> >  { return NULL; }
> >  #endif /* CONFIG_OF */
> > +
> > +extern int power_supply_get_battery_info(struct power_supply *psy,
> > +                                        struct power_supply_battery_info *info);
> >  extern void power_supply_changed(struct power_supply *psy);
> >  extern int power_supply_am_i_supplied(struct power_supply *psy);
> >  extern int power_supply_set_battery_charged(struct power_supply *psy);
> > --
> > 2.9.3
> >

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2017-03-23 10:17 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-20  9:43 [PATCH v11 0/10] devicetree battery support and client bq27xxx_battery Liam Breck
     [not found] ` <20170320094335.19224-1-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-03-20  9:43   ` [PATCH v11 01/10] devicetree: power: Add battery.txt Liam Breck
2017-03-24 15:55     ` Rob Herring
2017-03-24 21:11       ` Liam Breck
     [not found]     ` <20170320094335.19224-2-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-03-23 10:20       ` Sebastian Reichel
2017-03-23 10:30         ` Liam Breck
2017-03-23 12:18           ` Sebastian Reichel
2017-04-07 19:23       ` Liam Breck
     [not found]         ` <CAKvHMgTxRJXgfpDgqQ_+=ErFEZAh9CodjVn5ZOoCfqPqSZWetA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-14  0:33           ` Sebastian Reichel
2017-05-01 15:09       ` Sebastian Reichel
2017-03-20  9:43   ` [PATCH v11 03/10] devicetree: power: bq27xxx: Add monitored-battery documentation Liam Breck
2017-05-01 15:10     ` Sebastian Reichel
2017-03-20  9:43 ` [PATCH v11 02/10] devicetree: property-units: Add uWh and uAh units Liam Breck
2017-05-01 15:06   ` Sebastian Reichel
2017-03-20  9:43 ` [PATCH v11 04/10] power: power_supply: Add power_supply_battery_info and API Liam Breck
2017-03-20 20:59   ` Liam Breck
2017-03-23 10:17     ` Sebastian Reichel [this message]
2017-03-25 23:19       ` Liam Breck
2017-03-29 13:50         ` Sebastian Reichel
2017-05-01 15:11   ` Sebastian Reichel
2017-03-20  9:43 ` [PATCH v11 05/10] power: bq27xxx_battery: Make error reporting consistent Liam Breck
2017-03-20 16:57   ` Andrew F. Davis
2017-03-20 17:59     ` Liam Breck
2017-03-23 10:11       ` Sebastian Reichel
2017-03-23 10:24         ` Liam Breck
2017-03-23 10:33           ` Sebastian Reichel
2017-03-23 12:49             ` Liam Breck
2017-03-20  9:43 ` [PATCH v11 06/10] power: bq27xxx_battery: Define access methods to write chip registers Liam Breck
2017-03-21 20:54   ` kbuild test robot
2017-03-22 19:56   ` Andrew F. Davis
2017-03-20  9:43 ` [PATCH v11 07/10] power: bq27xxx_battery: Keep track of specific chip id Liam Breck
2017-03-23 10:28   ` Sebastian Reichel
2017-03-23 10:35     ` Liam Breck
2017-03-23 12:30       ` Sebastian Reichel
2017-03-23 12:39         ` Liam Breck
2017-03-23 13:06           ` Sebastian Reichel
2017-03-23 14:49       ` Andrew F. Davis
2017-03-23 21:44         ` Liam Breck
2017-03-24 11:48           ` Andrew F. Davis
2017-03-24 12:20             ` Liam Breck
2017-03-20  9:43 ` [PATCH v11 08/10] power: bq27xxx_battery: Add power_supply_battery_info support Liam Breck
2017-03-20  9:43 ` [PATCH v11 09/10] power: bq27xxx_battery_i2c: Add I2C bulk read/write functions Liam Breck
2017-03-20  9:43 ` [PATCH v11 10/10] power: bq27xxx_battery: Remove duplicate register arrays Liam Breck
     [not found]   ` <CAKvHMgS9ajgE3ZpseSkT=BiW5yBL03s-8XNFeHE=V0gz7W7x3w@mail.gmail.com>
2017-03-21  8:58     ` Fwd: " Liam Breck

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=20170323101727.y53vc74fskqxdw34@earth \
    --to=sre@kernel.org \
    --cc=afd@ti.com \
    --cc=kernel@networkimprov.net \
    --cc=liam@networkimprov.net \
    --cc=linux-pm@vger.kernel.org \
    --cc=matt@ranostay.consulting \
    /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