From patchwork Sun Nov 24 16:49:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 3226751 Return-Path: X-Original-To: patchwork-linux-omap@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 4E9B0C0C5E for ; Sun, 24 Nov 2013 16:50:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 782C9205B4 for ; Sun, 24 Nov 2013 16:50:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8ADB2205B8 for ; Sun, 24 Nov 2013 16:50:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753322Ab3KXQt6 (ORCPT ); Sun, 24 Nov 2013 11:49:58 -0500 Received: from ring0.de ([91.143.88.219]:60803 "EHLO smtp.ring0.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753232Ab3KXQtw (ORCPT ); Sun, 24 Nov 2013 11:49:52 -0500 Received: from comu.ring0.de (unknown [127.0.0.1]) by smtp.ring0.de (Postfix) with ESMTP id 222372C58EAA; Sun, 24 Nov 2013 17:49:50 +0100 (CET) Received: (from spamd@localhost) by comu.ring0.de (8.13.8/8.13.8/Submit) id rAOGncTU007835; Sun, 24 Nov 2013 17:49:38 +0100 X-Authentication-Warning: comu.ring0.de: spamd set sender to sre@ring0.de using -f X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 From: Sebastian Reichel To: Sebastian Reichel , Anton Vorontsov , David Woodhouse Cc: Rob Herring , Pawel Moll , Mark Rutland , Stephen Warren , Ian Campbell , Rob Landley , linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, devicetree@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= , freemangordon@abv.bg, aaro.koskinen@iki.fi, pavel@ucw.cz, Sebastian Reichel Subject: [PATCH 1/3] power_supply: add power_supply_get_by_phandle Date: Sun, 24 Nov 2013 17:49:29 +0100 Message-Id: <1385311771-447-2-git-send-email-sre@debian.org> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1385311771-447-1-git-send-email-sre@debian.org> References: <1385311771-447-1-git-send-email-sre@debian.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add method to get power supply by device tree phandle. Signed-off-by: Sebastian Reichel Reviewed-by: Pavel Machek --- drivers/power/power_supply_core.c | 24 ++++++++++++++++++++++++ include/linux/power_supply.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 08bce22..99e4b41 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -340,6 +340,30 @@ struct power_supply *power_supply_get_by_name(const char *name) } EXPORT_SYMBOL_GPL(power_supply_get_by_name); +static int power_supply_match_device_node(struct device *dev, const void *data) +{ + return dev->parent && dev->parent->of_node == data; +} + +struct power_supply *power_supply_get_by_phandle(struct device_node *np, + const char *property) +{ + struct device_node *power_supply_np; + struct device *dev; + + power_supply_np = of_parse_phandle(np, property, 0); + if (!power_supply_np) + return ERR_PTR(-ENODEV); + + dev = class_find_device(power_supply_class, NULL, power_supply_np, + power_supply_match_device_node); + + of_node_put(power_supply_np); + + return dev ? dev_get_drvdata(dev) : NULL; +} +EXPORT_SYMBOL_GPL(power_supply_get_by_phandle); + int power_supply_powers(struct power_supply *psy, struct device *dev) { return sysfs_create_link(&psy->dev->kobj, &dev->kobj, "powers"); diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index c6f52c0..4d0e0b4 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -246,6 +246,8 @@ 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 struct power_supply *power_supply_get_by_phandle(struct device_node *np, + 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);