From patchwork Tue Oct 7 10:58:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonghwa Lee X-Patchwork-Id: 5045051 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DB3A4C11AB for ; Tue, 7 Oct 2014 10:59:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F2460201F7 for ; Tue, 7 Oct 2014 10:59:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E60A7201F4 for ; Tue, 7 Oct 2014 10:59:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753766AbaJGK7i (ORCPT ); Tue, 7 Oct 2014 06:59:38 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:14259 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753075AbaJGK6t (ORCPT ); Tue, 7 Oct 2014 06:58:49 -0400 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0ND200ADAMHZ93C0@mailout1.samsung.com>; Tue, 07 Oct 2014 19:58:47 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.112]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id DA.BB.17016.667C3345; Tue, 07 Oct 2014 19:58:47 +0900 (KST) X-AuditID: cbfee68d-f79296d000004278-93-5433c766518c Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 39.B5.20081.667C3345; Tue, 07 Oct 2014 19:58:46 +0900 (KST) Received: from localhost.localdomain ([10.252.82.199]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0ND2005MCMHVXNB0@mmp2.samsung.com>; Tue, 07 Oct 2014 19:58:46 +0900 (KST) From: Jonghwa Lee To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, anton@enomsg.org, pavel@ucw.cz, jenny.tc@intel.com, Jonghwa Lee Subject: [PATCH 1/3] power: core: Add generic interface to get battery specification. Date: Tue, 07 Oct 2014 19:58:36 +0900 Message-id: <1412679518-21499-2-git-send-email-jonghwa3.lee@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1412679518-21499-1-git-send-email-jonghwa3.lee@samsung.com> References: <1412679518-21499-1-git-send-email-jonghwa3.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsWyRsSkQDf9uHGIwXQHi4NbNS0mPXnPbDFx 5WRmi7Vfe9gtOs8+Yba4vGsOm8Xn3iOMFndPHWWzOL27xIHTY0L/J0aPnbPusntsXqHlsXjP SyaPTas62Tz6tqxi9Fix+ju7x+dNcgEcUVw2Kak5mWWpRfp2CVwZ22ZzFZxTqrjQu4qxgfGm bBcjJ4eEgInEx32djBC2mMSFe+vZuhi5OIQEljJK9Bx+zwpT9Of9FxaIxHRGiVVn10JVtTFJ HP42hQ2kik1AR+L/vpvsILaIgILE5t5nYN3MAtsZJeZ+SgaxhQXCJToOtjKD2CwCqhJv5iwH W80r4CFx+O8KIJsDaJuCxJxJNiBhTgFPicbb7SwgthBQyaIHb1lB9koI7GKX2LRlGxPEHAGJ b5MPsUD0ykpsOsAMcbSkxMEVN1gmMAovYGRYxSiaWpBcUJyUXmSoV5yYW1yal66XnJ+7iREY D6f/PevdwXj7gPUhRgEORiUe3hVaxiFCrIll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7StQB4Y1hb0zf TP1ndlHpfPnuBkWFU23LA7adFlh/bgF74JX2GeWnZn8N5hGYznbv06Jskc13xO1qhYoTbzOe tOj4ocRSnJFoqMVcVJwIAOHLmK/NAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY, URIBL_RHS_DOB autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In power supply system, battery specification's dealt as static information regardless of battery chainging. And it often assumed fuelgauge's role to hold battery specification even same driver is used with different batteries. To make subsystem handles above cases properly, this patch adds helper functions to manager the battery specification. Signed-off-by: Jonghwa Lee --- drivers/power/power_supply_core.c | 91 +++++++++++++++++++++++++++++++++++++ include/linux/power_supply.h | 7 +++ 2 files changed, 98 insertions(+) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 078afd6..59207d9 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -653,6 +653,97 @@ static void __exit power_supply_class_exit(void) subsys_initcall(power_supply_class_init); module_exit(power_supply_class_exit); +/**************************************************************** + * Battery information interface * + ****************************************************************/ + +ATOMIC_NOTIFIER_HEAD(psy_battery_info_notifier); +static LIST_HEAD(psy_battery_info_list); + +struct psy_battery_info { + struct list_head entry; + struct power_supply_info *info; +}; + +enum battery_info_notifier_events { + PSY_BATT_INFO_REGISTERED, + PSY_BATT_INFO_UNREGISTERED, +}; + +int psy_battery_info_notifier_register(struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&psy_battery_info_notifier, nb); +} +EXPORT_SYMBOL_GPL(psy_battery_info_notifier_register); + +void psy_battery_info_notifier_unregister(struct notifier_block *nb) +{ + atomic_notifier_chain_unregister(&psy_battery_info_notifier, nb); +} +EXPORT_SYMBOL_GPL(psy_battery_info_notifier_unregister); + +struct power_supply_info *psy_get_battery_info(const char *name) +{ + struct psy_battery_info *battery; + + /* Sanity check */ + if (!name) + goto err_out; + + list_for_each_entry(battery, &psy_battery_info_list, entry) { + if (!strcmp(battery->info->name, name)) + return battery->info; + } + +err_out: + return NULL; +} +EXPORT_SYMBOL(psy_get_battery_info); + +int psy_register_battery_info(struct power_supply_info *info) +{ + struct psy_battery_info *battery; + + /* Sanity check */ + if (!info->name) + return -EINVAL; + + /* Check if same data is existed */ + list_for_each_entry(battery, &psy_battery_info_list, entry) + if (!strcmp(battery->info->name, info->name)) + return -EEXIST; + + battery = kzalloc(sizeof(*battery), GFP_KERNEL); + if (!battery) + return -ENOMEM; + + battery->info = info; + list_add_tail(&battery->entry, &psy_battery_info_list); + + atomic_notifier_call_chain(&psy_battery_info_notifier, + PSY_BATT_INFO_REGISTERED, info); + + return 0; +} +EXPORT_SYMBOL(psy_register_battery_info); + +void psy_unregister_battery_info(struct power_supply_info *info) +{ + struct psy_battery_info *battery, *tmp; + + list_for_each_entry_safe(battery, tmp, &psy_battery_info_list, entry) { + if (battery->info == info) { + list_del(&battery->entry); + kfree(battery); + return; + } + } + + atomic_notifier_call_chain(&psy_battery_info_notifier, + PSY_BATT_INFO_UNREGISTERED, info); +} +EXPORT_SYMBOL(psy_unregister_battery_info); + MODULE_DESCRIPTION("Universal power supply monitor class"); MODULE_AUTHOR("Ian Molton , " "Szabolcs Gyurko, " diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index f3dea41..99306aa 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -276,6 +276,13 @@ extern int power_supply_powers(struct power_supply *psy, struct device *dev); /* For APM emulation, think legacy userspace. */ extern struct class *power_supply_class; +/* Battery information helper */ +extern int psy_battery_info_notifier_register(struct notifier_block *); +extern void psy_battery_info_notifier_unregister(struct notifier_block *); +extern struct power_supply_info *psy_get_battery_info(const char *); +extern int psy_register_battery_info(struct power_supply_info *); +extern void psy_unregister_battery_info(struct power_supply_info *); + static inline bool power_supply_is_amp_property(enum power_supply_property psp) { switch (psp) {