From patchwork Sat Feb 4 09:15:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Breck X-Patchwork-Id: 9555547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EC51C602B7 for ; Sat, 4 Feb 2017 09:18:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FA0C27DF9 for ; Sat, 4 Feb 2017 09:18:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91CAD27F82; Sat, 4 Feb 2017 09:18:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB70827DF9 for ; Sat, 4 Feb 2017 09:18:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753785AbdBDJSk (ORCPT ); Sat, 4 Feb 2017 04:18:40 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36013 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753745AbdBDJSj (ORCPT ); Sat, 4 Feb 2017 04:18:39 -0500 Received: by mail-pg0-f67.google.com with SMTP id 75so4127813pgf.3 for ; Sat, 04 Feb 2017 01:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=HPM76R9vi3b32hWONBUCKHkd0FpTw3j2JzFksL0B5UE=; b=ksNZ7YEJRM9KdN5nYgXbl6H+nF1Mh8RKjVGuqFxDsjxF5T3TWVQKuSaJWDJ2nk5NLM ig5o+7jM7Mg2bQ8xGAmT1S/yjvlgTrmuXcY08byNpFV7YoHUpGwsdh/nh4qe9nd2pY5A 8uZupNlczLGJMKHgGQCeHWPpCHsiOqzSswE8ICPz4ADg3ji712b95q2lkNs2fe1N6qJk 2Utc4UFwL6sOzkhqL/rrucP2YG9qNdqtB7Ikw1u1Pd2ixyrcecXfXICVkrTRihKfVuRY kulh/epHjz3Z+STRFy3gaZQqKLboG+W8KI+fKP1jrEp4Xg4z0WriXL0tylvJ9GHCkarN QAhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=HPM76R9vi3b32hWONBUCKHkd0FpTw3j2JzFksL0B5UE=; b=PG9tWbg9d4W/1ALo7PUTNLBXZip3vPEnlJyQ8Aa4vphs/quCthqy0oMeyQFoVGr+83 EcXILch4fDpVny8H9CzWlBArV+dV9B6GxILbELCtyZJU7QtsWIti7BTaJtM4SLiTj8WU XhvMYD5+/jkOq+2Na+eFeekkfDikJ5yGnMgjYKbhU2QkwmaaDr+s4gN3GZFjTAH57K6e fXH/rijn/BdaKeFMZ6BupnCZusyV7B0i6QoFqJmW+xthNTJY5PdlR+mRfR4xOCdXQ+zC vfzXNWaXWX7gAUXOiS4PUTC5W2ycff/iT/xSSa60HH53zs8FNoCtZWPtLGZwFTseAt8d F59g== X-Gm-Message-State: AIkVDXKtDxkD6vvFk/CAQYKDc2QZlhy8k6J1BCsp10fBZILlQxTCowznd6CzfKax3zwnEw== X-Received: by 10.98.163.23 with SMTP id s23mr1560583pfe.60.1486199918597; Sat, 04 Feb 2017 01:18:38 -0800 (PST) Received: from localhost.localdomain (c-73-223-93-234.hsd1.ca.comcast.net. [73.223.93.234]) by smtp.gmail.com with ESMTPSA id l3sm73757118pgn.10.2017.02.04.01.18.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Feb 2017 01:18:38 -0800 (PST) From: Liam Breck To: Sebastian Reichel Cc: "Andrew F. Davis" , Matt Ranostay , linux-pm@vger.kernel.org, Liam Breck Subject: [PATCH v5 4/8] power: power_supply: Add power_supply_battery_info and API Date: Sat, 4 Feb 2017 01:15:59 -0800 Message-Id: <20170204091603.32242-5-liam@networkimprov.net> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170204091603.32242-1-liam@networkimprov.net> References: <20170204091603.32242-1-liam@networkimprov.net> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matt Ranostay From: Matt Ranostay 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 Signed-off-by: Liam Breck --- drivers/power/supply/power_supply_core.c | 43 ++++++++++++++++++++++++++++++++ include/linux/power_supply.h | 19 ++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index a74d8ca..2d564a5 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include "power_supply.h" @@ -487,6 +488,48 @@ 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; + info->voltage_max_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("fixed-battery", value)) + return -ENODEV; + + 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); + of_property_read_u32(battery_np, "voltage-max-design-microvolt", + &info->voltage_max_design_uv); + + 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..3f3fea5 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -288,6 +288,22 @@ 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 */ + int voltage_max_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 +322,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);