@@ -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)
@@ -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);
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(+)