devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matt Ranostay <matt@ranostay.consulting>
To: linux-pm@vger.kernel.org, devicetree@vger.kernel.org
Cc: sre@kernel.org, tony@atomide.com,
	Matt Ranostay <matt@ranostay.consulting>
Subject: [PATCH v3 3/7] power: power_supply: add battery info platform data retrieval
Date: Tue, 10 Jan 2017 22:19:59 -0800	[thread overview]
Message-ID: <20170111062003.10110-4-matt@ranostay.consulting> (raw)
In-Reply-To: <20170111062003.10110-1-matt@ranostay.consulting>

Add power_supply_get_battery_info() to get battery platform data

Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
 drivers/power/supply/power_supply_core.c | 31 +++++++++++++++++++++++++++++++
 include/linux/power_supply.h             |  4 ++++
 2 files changed, 35 insertions(+)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 1e0960b646e8..08ddf3020658 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,36 @@ 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,
+				  const char *property)
+{
+	struct device_node *np = psy->of_node;
+	struct device_node *power_supply_battery_info_np;
+	int ret;
+
+	if (!np)
+		return -ENXIO;
+
+	power_supply_battery_info_np = of_parse_phandle(np, property, 0);
+	if (!power_supply_battery_info_np)
+		return -ENODEV;
+
+	ret = of_property_read_u32(power_supply_battery_info_np,
+				   "nominal-microvolt", &info->nominal_voltage);
+	if (ret < 0)
+		return ret;
+
+	ret = of_property_read_u32(power_supply_battery_info_np,
+				   "design-microwatt-hours", &info->energy);
+	if (ret < 0)
+		return ret;
+
+	return of_property_read_u32(power_supply_battery_info_np,
+				   "design-microamp-hours", &info->power);
+}
+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 59674a257d5e..859d0e7f9b6a 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -318,6 +318,10 @@ 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,
+					 const char *property);
 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.10.2


  parent reply	other threads:[~2017-01-11  6:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-11  6:19 [PATCH v3 0/7] power: bq27xxx: add support for NVRAM R/W access Matt Ranostay
2017-01-11  6:19 ` [PATCH v3 2/7] power: power_supply: add battery information struct Matt Ranostay
2017-01-11  6:19 ` Matt Ranostay [this message]
     [not found] ` <20170111062003.10110-1-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-11  6:19   ` [PATCH v3 1/7] devicetree: power: add battery state machine documentation Matt Ranostay
     [not found]     ` <20170111062003.10110-2-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-13 17:23       ` Rob Herring
2017-01-13 18:33     ` Sebastian Reichel
2017-01-11  6:20   ` [PATCH v3 4/7] power: bq27xxx_battery: add BQ27425 chip id Matt Ranostay
2017-01-11  6:20   ` [PATCH v3 5/7] power: bq27xxx_battery: add i2c bulk read/write functions Matt Ranostay
2017-01-11  6:20   ` [PATCH v3 7/7] power: bq27xxx_battery: add initial state machine support Matt Ranostay
2017-01-11  6:20 ` [PATCH v3 6/7] devicetree: power: bq27xxx: add monitored battery documentation Matt Ranostay
     [not found]   ` <20170111062003.10110-7-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-13 17:28     ` Rob Herring
2017-01-14  6:07       ` Matt Ranostay
     [not found]         ` <CAJ_EiSRnU1q8QPKO43hk3ajS=RaAtQ2tVJ-060GcmPoPA6Ranw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-17  0:59           ` Sebastian Reichel

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=20170111062003.10110-4-matt@ranostay.consulting \
    --to=matt@ranostay.consulting \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=tony@atomide.com \
    /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).