From: Rhyland Klein <rklein@nvidia.com>
To: Anton Vorontsov <cbou@mail.ru>, Grant Likely <grant.likely@secretlab.ca>
Cc: David Woodhouse <dwmw2@infradead.org>,
linux-kernel@vger.kernel.org,
devicetree-discuss@lists.ozlabs.org, linux-tegra@vger.kernel.org,
Rhyland Klein <rklein@nvidia.com>
Subject: [PATCH V2 2/3] power: power_supply: Add core support for supplied_from
Date: Mon, 1 Apr 2013 17:45:54 -0400 [thread overview]
Message-ID: <1364852755-17425-3-git-send-email-rklein@nvidia.com> (raw)
In-Reply-To: <1364852755-17425-1-git-send-email-rklein@nvidia.com>
This patch adds support for supplies to register a list of char *'s
which represent the list of supplies which supply them. This is the
opposite as the supplied_to list.
This change maintains support for supplied_to until all drivers which
make use of it already are converted.
Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
v2:
- changed __power_supply_is_supplied_by to a boolean function
- fixed up return paths with correct return values
- moved loop invariant checks outside of loops
v1:
- changed from RFC v2 -> patch v1
- removed list logic and instead added supplied_from char ** array and
num_supplies field
v2 (RFC):
- changed from struct device_node * contained in suppliers to a list
stored in the supplies.
- changed logic for the is_supplied_by check to handle the entire loop
as the array structure is difference between the 2 paths.
drivers/power/power_supply_core.c | 47 +++++++++++++++++++++++++++----------
include/linux/power_supply.h | 3 +++
2 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 5deac43..d843cc9 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -26,17 +26,42 @@ EXPORT_SYMBOL_GPL(power_supply_class);
static struct device_type power_supply_dev_type;
+static bool __power_supply_is_supplied_by(struct power_supply *supplier,
+ struct power_supply *supply)
+{
+ int i;
+
+ if (!supply->supplied_from && !supplier->supplied_to)
+ return false;
+
+ /* Support both supplied_to and supplied_from modes */
+ if (supply->supplied_from) {
+ if (!supplier->name)
+ return false;
+ for (i = 0; i < supply->num_supplies; i++)
+ if (!strcmp(supplier->name, supply->supplied_from[i]))
+ return true;
+ } else {
+ if (!supply->name)
+ return false;
+ for (i = 0; i < supplier->num_supplicants; i++)
+ if (!strcmp(supplier->supplied_to[i], supply->name))
+ return true;
+ }
+
+ return false;
+}
+
static int __power_supply_changed_work(struct device *dev, void *data)
{
struct power_supply *psy = (struct power_supply *)data;
struct power_supply *pst = dev_get_drvdata(dev);
- int i;
- for (i = 0; i < psy->num_supplicants; i++)
- if (!strcmp(psy->supplied_to[i], pst->name)) {
- if (pst->external_power_changed)
- pst->external_power_changed(pst);
- }
+ if (__power_supply_is_supplied_by(psy, pst)) {
+ if (pst->external_power_changed)
+ pst->external_power_changed(pst);
+ }
+
return 0;
}
@@ -68,17 +93,13 @@ static int __power_supply_am_i_supplied(struct device *dev, void *data)
union power_supply_propval ret = {0,};
struct power_supply *psy = (struct power_supply *)data;
struct power_supply *epsy = dev_get_drvdata(dev);
- int i;
- for (i = 0; i < epsy->num_supplicants; i++) {
- if (!strcmp(epsy->supplied_to[i], psy->name)) {
- if (epsy->get_property(epsy,
- POWER_SUPPLY_PROP_ONLINE, &ret))
- continue;
+ if (__power_supply_is_supplied_by(epsy, psy))
+ if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) {
if (ret.intval)
return ret.intval;
}
- }
+
return 0;
}
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 002a99f..c1cbd5e 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -171,6 +171,9 @@ struct power_supply {
char **supplied_to;
size_t num_supplicants;
+ char **supplied_from;
+ size_t num_supplies;
+
int (*get_property)(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val);
--
1.7.9.5
next prev parent reply other threads:[~2013-04-01 21:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-01 21:45 [PATCH V2 0/3] Add DT Binding for Power-Supply power-supplies property Rhyland Klein
[not found] ` <1364852755-17425-1-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-04-01 21:45 ` [PATCH V2 1/3] power_supply: Define Binding for power-supplies Rhyland Klein
2013-04-01 21:45 ` Rhyland Klein [this message]
[not found] ` <1364852755-17425-3-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-04-02 21:31 ` [PATCH V2 2/3] power: power_supply: Add core support for supplied_from Stephen Warren
[not found] ` <515B4E32.8080006-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-04-17 1:55 ` Anton Vorontsov
2013-04-01 21:45 ` [PATCH V2 3/3] power: power_supply_core: Add " Rhyland Klein
2013-04-17 1:55 ` Anton Vorontsov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364852755-17425-3-git-send-email-rklein@nvidia.com \
--to=rklein@nvidia.com \
--cc=cbou@mail.ru \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=dwmw2@infradead.org \
--cc=grant.likely@secretlab.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).