From patchwork Tue Nov 19 10:18:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 3200841 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 21ED69F26C for ; Tue, 19 Nov 2013 10:23:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0A44F2030B for ; Tue, 19 Nov 2013 10:23:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D14FD20306 for ; Tue, 19 Nov 2013 10:22:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751848Ab3KSKWH (ORCPT ); Tue, 19 Nov 2013 05:22:07 -0500 Received: from mail-wg0-f53.google.com ([74.125.82.53]:55208 "EHLO mail-wg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751730Ab3KSKWF (ORCPT ); Tue, 19 Nov 2013 05:22:05 -0500 Received: by mail-wg0-f53.google.com with SMTP id b13so7419364wgh.8 for ; Tue, 19 Nov 2013 02:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=5JIsKrPppXwHOWmNeiCWIqs19KZUgYmUtOTEq16dtNs=; b=heFdX+47avxwqOgJE3E337Ms8dL4gomAi4cF2EIOKB6Jj+ys+gwQ/7g846MuROhh70 P9b4BIpm5spEBHdLeQbGTJqvjt9viqyMMuhXLVLcjWw+n4lKLVoC894Mq70i3lClUwbd +qlx8YPD/LuNWG/2kAJTL+naeKBDeB3MXF7+F3ck8Qs9zBngSZOQMg0qWy57uLVTsjH9 UonJAtN7z/eZMDqOp8DKe0KJr4tc35T5peRK8X3zWzz4bYSllbd7wGvBT/zteC1Fz5sf REusAUll/Is0L2tl/v4rU0hHm7VbLSK3YwZ7BTY/bXdCoZzD9JjvG+75KvdCxY6MwOA+ 4wpA== X-Received: by 10.194.193.4 with SMTP id hk4mr51119wjc.71.1384856524188; Tue, 19 Nov 2013 02:22:04 -0800 (PST) Received: from Pali-EliteBook.kolej.mff.cuni.cz (pali.kolej.mff.cuni.cz. [78.128.193.202]) by mx.google.com with ESMTPSA id fu1sm4175598wib.8.2013.11.19.02.22.02 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Nov 2013 02:22:03 -0800 (PST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Anton Vorontsov , David Woodhouse , Tony Lindgren , Russell King Cc: linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, freemangordon@abv.bg, aaro.koskinen@iki.fi, pavel@ucw.cz, =?UTF-8?q?Pali=20Roh=C3=A1r?= , Jenny TC Subject: [PATCH v2 1/3] power_supply: Add power_supply notifier Date: Tue, 19 Nov 2013 11:18:03 +0100 Message-Id: <1384856285-19593-2-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1384856285-19593-1-git-send-email-pali.rohar@gmail.com> References: <1378630239-10006-1-git-send-email-pali.rohar@gmail.com> <1384856285-19593-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY 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 This patch adds a notifier chain to the power_supply. This notifier helps drivers in other subsystem to listen to changes in power supply subsystem. This would help to take some actions in those drivers on changing the power supply properties. One such scenario is to increase/decrease system performance based on the battery capacity/voltage. Another scenario is to adjust the h/w peak current detection voltage/current thresholds based on battery voltage/capacity. The notifier helps drivers to listen to changes in power_suppy susbystem without polling the power_supply properties Signed-off-by: Jenny TC Signed-off-by: Pali Rohár Reviewed-by: Pavel Machek Tested-By: Sebastian Reichel Acked-by: Jenny TC --- drivers/power/power_supply_core.c | 17 +++++++++++++++++ include/linux/power_supply.h | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 00e6672..08bce22 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -24,6 +24,9 @@ struct class *power_supply_class; EXPORT_SYMBOL_GPL(power_supply_class); +ATOMIC_NOTIFIER_HEAD(power_supply_notifier); +EXPORT_SYMBOL_GPL(power_supply_notifier); + static struct device_type power_supply_dev_type; static bool __power_supply_is_supplied_by(struct power_supply *supplier, @@ -80,6 +83,8 @@ static void power_supply_changed_work(struct work_struct *work) class_for_each_device(power_supply_class, NULL, psy, __power_supply_changed_work); power_supply_update_leds(psy); + atomic_notifier_call_chain(&power_supply_notifier, + PSY_EVENT_PROP_CHANGED, psy); kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); spin_lock_irqsave(&psy->changed_lock, flags); } @@ -347,6 +352,18 @@ static void power_supply_dev_release(struct device *dev) kfree(dev); } +int power_supply_reg_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&power_supply_notifier, nb); +} +EXPORT_SYMBOL_GPL(power_supply_reg_notifier); + +void power_supply_unreg_notifier(struct notifier_block *nb) +{ + atomic_notifier_chain_unregister(&power_supply_notifier, nb); +} +EXPORT_SYMBOL_GPL(power_supply_unreg_notifier); + #ifdef CONFIG_THERMAL static int power_supply_read_temp(struct thermal_zone_device *tzd, unsigned long *temp) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 5c26006..c6f52c0 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -158,6 +158,13 @@ enum power_supply_type { POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */ }; +enum power_supply_notifier_events { + PSY_EVENT_NONE, + PSY_EVENT_PROP_CHANGED, + PSY_EVENT_BATTERY, + PSY_EVENT_CABLE, +}; + union power_supply_propval { int intval; const char *strval; @@ -235,6 +242,9 @@ struct power_supply_info { int use_for_apm; }; +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); extern struct power_supply *power_supply_get_by_name(const char *name); extern void power_supply_changed(struct power_supply *psy); extern int power_supply_am_i_supplied(struct power_supply *psy);