From: Jenny TC <jenny.tc@intel.com>
To: myungjoo.ham@samsung.com, cw00.choi@samsung.com,
linux-kernel@vger.kernel.org
Cc: jenny.tc@intel.com
Subject: [PATCH] extcon : register for cable interest by cable name
Date: Wed, 10 Oct 2012 15:50:48 +0530 [thread overview]
Message-ID: <1349864448-21276-1-git-send-email-jenny.tc@intel.com> (raw)
There are some scnearios where a driver/framework needs to register
interest for a particular cable without specifying the extcon device
name. One such scenario is charger notifications. The platform will
have charger cabel which will be bound to any extcon device. It's
not mandatory for the charger driver to know which extcon device
it should use. This patch enables the support for registering
interest for a cable just by cable name wihtout specifying the
extcon device name
Signed-off-by: Jenny TC <jenny.tc@intel.com>
---
drivers/extcon/extcon-class.c | 52 +++++++++++++++++++++++++++++++++++++++++
include/linux/extcon.h | 3 +++
2 files changed, 55 insertions(+)
diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
index 946a318..3d8e825 100644
--- a/drivers/extcon/extcon-class.c
+++ b/drivers/extcon/extcon-class.c
@@ -485,6 +485,58 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,
}
/**
+ * extcon_register_interest_cable_byname() - Register a notifier for a state
+ * change of a specific cable, on any extcon device
+ * extcon device.
+ * @obj: an empty extcon_specific_cable_nb object to be returned.
+ * @cable_name: the target cable name.
+ * @nb: the notifier block to get notified.
+ *
+ * Provide an empty extcon_specific_cable_nb.
+ * extcon_register_interest_cable_name() sets the struct for you.
+ *
+ * extcon_register_cable_interest is a helper function for those who want to get
+ * notification for a single specific cable's status change without knowing the
+ * extcon device name.
+ *
+ * Note : This will register the interest with the first extcon device which
+ * reports the status for the cable. If multiple extcon devices reports the
+ * same cable name, this API will register interest with the first extcon device
+ */
+
+struct extcon_dev *register_interest_cable_byname
+ (struct extcon_specific_cable_nb *extcon_dev,
+ const char *cable_name, struct notifier_block *nb)
+{
+ struct class_dev_iter iter;
+ struct device *dev;
+ struct extcon_dev *extd = NULL;
+
+ /* Identify the extcon device which supports the cable and register
+ * interest.
+ */
+ if (extcon_class == NULL)
+ return NULL;
+ class_dev_iter_init(&iter, extcon_class, NULL, NULL);
+ while ((dev = class_dev_iter_next(&iter))) {
+ extd = (struct extcon_dev *)dev_get_drvdata(dev);
+ /* check for cable support */
+ if (extcon_find_cable_index(extd, cable_name) < 0) {
+ extd = NULL;
+ continue;
+ }
+
+ if (extcon_register_interest(extcon_dev, extd->name,
+ cable_name, nb) < 0) {
+ extd = NULL;
+ continue;
+ }
+ }
+ class_dev_iter_exit(&iter);
+ return extd;
+}
+
+/**
* extcon_unregister_interest() - Unregister the notifier registered by
* extcon_register_interest().
* @obj: the extcon_specific_cable_nb object returned by
diff --git a/include/linux/extcon.h b/include/linux/extcon.h
index 7443a56..9be8286 100644
--- a/include/linux/extcon.h
+++ b/include/linux/extcon.h
@@ -222,6 +222,9 @@ extern int extcon_register_interest(struct extcon_specific_cable_nb *obj,
const char *extcon_name,
const char *cable_name,
struct notifier_block *nb);
+extern struct extcon_dev *register_interest_cable_byname
+ (struct extcon_specific_cable_nb *extcon_dev,
+ const char *cable_name, struct notifier_block *nb);
extern int extcon_unregister_interest(struct extcon_specific_cable_nb *nb);
/*
--
1.7.9.5
next reply other threads:[~2012-10-10 4:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-10 10:20 Jenny TC [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-10-10 6:52 MyungJoo Ham
2012-10-11 10:37 ` Tc, Jenny
2012-10-15 14:53 ` MyungJoo Ham
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=1349864448-21276-1-git-send-email-jenny.tc@intel.com \
--to=jenny.tc@intel.com \
--cc=cw00.choi@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=myungjoo.ham@samsung.com \
/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
all inboxes | Powered by JetHome®