From: Matt Ranostay <matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
To: linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org,
Matt Ranostay
<matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
Subject: [PATCH v4 4/8] power: power_supply: add battery info platform data retrieval
Date: Sat, 21 Jan 2017 23:14:00 -0800 [thread overview]
Message-ID: <20170122071404.9654-5-matt@ranostay.consulting> (raw)
In-Reply-To: <20170122071404.9654-1-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
Add power_supply_get_battery_info() to get battery platform data
Signed-off-by: Matt Ranostay <matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
---
drivers/power/supply/power_supply_core.c | 41 ++++++++++++++++++++++++++++++++
include/linux/power_supply.h | 4 ++++
2 files changed, 45 insertions(+)
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 1e0960b646e8..21490b5e233f 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,46 @@ 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;
+ struct property *p;
+ char *prefix = "fixed-battery";
+ 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;
+
+ p = of_find_property(power_supply_battery_info_np, "compatible", NULL);
+
+ if (!p || !p->value)
+ return -ENODEV;
+
+ if (strncmp(prefix, p->value, strlen(prefix)))
+ 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
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-01-22 7:14 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-22 7:13 [PATCH v4 0/8] power: bq27xxx: add support for NVRAM R/W access Matt Ranostay
2017-01-22 7:13 ` [PATCH v4 1/8] devicetree: property-units: add mWh and mAh units Matt Ranostay
2017-01-23 17:50 ` Rob Herring
2017-01-22 7:13 ` [PATCH v4 2/8] devicetree: power: add battery state machine documentation Matt Ranostay
2017-01-22 22:22 ` Liam Breck
2017-01-24 19:56 ` Liam Breck
[not found] ` <CAKvHMgS9ZxE2qxDqeAVRJFzerjkJV=io58aQjtU51j=kFzbYtw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-29 17:27 ` Sebastian Reichel
2017-01-26 6:19 ` Liam Breck
2017-01-26 7:02 ` Matt Ranostay
2017-01-29 17:20 ` Sebastian Reichel
2017-01-29 23:22 ` Liam Breck
2017-01-30 2:30 ` Sebastian Reichel
2017-01-30 10:54 ` Liam Breck
[not found] ` <CAKvHMgQi1tRyUXh0504rP8VUVkFVPt_4NnYTOrBXeO4dde6KMg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-30 21:40 ` Liam Breck
[not found] ` <20170122222212.27086-1-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-01-29 18:06 ` Sebastian Reichel
2017-01-29 23:32 ` Liam Breck
[not found] ` <CAKvHMgTrFjjEWwK-NeGOF1o6KRQPXYUvcqWcDwaW+5ZKjQ7VZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-30 2:39 ` Sebastian Reichel
2017-01-30 2:46 ` Liam Breck
2017-01-31 20:59 ` Liam Breck
[not found] ` <20170122071404.9654-1-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-22 7:13 ` [PATCH v4 3/8] power: power_supply: add battery information struct Matt Ranostay
[not found] ` <20170122071404.9654-4-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-29 18:23 ` Sebastian Reichel
2017-01-22 7:14 ` Matt Ranostay [this message]
[not found] ` <20170122071404.9654-5-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-29 18:28 ` [PATCH v4 4/8] power: power_supply: add battery info platform data retrieval Sebastian Reichel
2017-01-22 7:14 ` [PATCH v4 5/8] power: bq27xxx_battery: add BQ27425 chip id Matt Ranostay
2017-01-22 7:14 ` [PATCH v4 7/8] devicetree: power: bq27xxx: add monitored battery documentation Matt Ranostay
2017-01-22 7:14 ` [PATCH v4 6/8] power: bq27xxx_battery: add i2c bulk read/write functions Matt Ranostay
2017-01-29 18:38 ` Sebastian Reichel
2017-01-22 7:14 ` [PATCH v4 8/8] power: bq27xxx_battery: add initial state machine support Matt Ranostay
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=20170122071404.9654-5-matt@ranostay.consulting \
--to=matt-sk+vivc6flcdq+msdoja79kegs52mxvz@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.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).