From: Baolin Wang <baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: balbi-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org
Cc: robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
jun.li-3arQi8VN3Tc@public.gmane.org,
m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
ruslan.bilovol-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org,
r.baldyga-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
grygorii.strashko-l0cyMroinI0@public.gmane.org,
yoshihiro.shimoda.uh-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org,
lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org,
baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
device-mainlining-cunTk1MwBs98uUxBSJOaYoYkZiVZrdSR2LY78lusg7I@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v12 3/4] gadget: Integrate with the usb gadget supporting for usb charger
Date: Tue, 21 Jun 2016 16:39:14 +0800 [thread overview]
Message-ID: <2f57bf9df3a5dc6cce45834eaeec4f00b25808b7.1466497506.git.baolin.wang@linaro.org> (raw)
In-Reply-To: <cover.1466497505.git.baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
In-Reply-To: <cover.1466497505.git.baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
When the usb gadget supporting for usb charger is ready, the usb charger
can implement the usb_charger_plug_by_gadget() function and usb_charger_exit()
function by getting 'struct usb_charger' from 'struct gadget'.
Signed-off-by: Baolin Wang <baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Reviewed-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
Tested-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
drivers/usb/gadget/udc/charger.c | 39 +++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/udc/charger.c b/drivers/usb/gadget/udc/charger.c
index 7be4c76..949396f 100644
--- a/drivers/usb/gadget/udc/charger.c
+++ b/drivers/usb/gadget/udc/charger.c
@@ -568,6 +568,30 @@ usb_charger_plug_by_extcon(struct notifier_block *nb,
int usb_charger_plug_by_gadget(struct usb_gadget *gadget,
unsigned long state)
{
+ struct usb_charger *uchger = gadget->charger;
+ enum usb_charger_state uchger_state;
+
+ if (WARN(!uchger, "charger can not be NULL"))
+ return -EINVAL;
+
+ /*
+ * Report event to power to setting the current limitation
+ * for this usb charger when one usb charger state is changed
+ * with detecting by usb gadget state.
+ */
+ if (uchger->old_gadget_state != state) {
+ uchger->old_gadget_state = state;
+
+ if (state >= USB_STATE_ATTACHED)
+ uchger_state = USB_CHARGER_PRESENT;
+ else if (state == USB_STATE_NOTATTACHED)
+ uchger_state = USB_CHARGER_REMOVE;
+ else
+ uchger_state = USB_CHARGER_DEFAULT;
+
+ usb_charger_notify_others(uchger, uchger_state);
+ }
+
return 0;
}
EXPORT_SYMBOL_GPL(usb_charger_plug_by_gadget);
@@ -724,6 +748,7 @@ int usb_charger_init(struct usb_gadget *ugadget)
/* register a notifier on a usb gadget device */
uchger->gadget = ugadget;
+ ugadget->charger = uchger;
uchger->old_gadget_state = USB_STATE_NOTATTACHED;
/* register a new usb charger */
@@ -744,7 +769,19 @@ fail:
int usb_charger_exit(struct usb_gadget *ugadget)
{
- return 0;
+ struct usb_charger *uchger = ugadget->charger;
+
+ if (WARN(!uchger, "charger can not be NULL"))
+ return -EINVAL;
+
+ if (uchger->extcon_dev)
+ extcon_unregister_notifier(uchger->extcon_dev,
+ EXTCON_USB,
+ &uchger->extcon_nb.nb);
+
+ ida_simple_remove(&usb_charger_ida, uchger->id);
+
+ return usb_charger_unregister(uchger);
}
static int __init usb_charger_class_init(void)
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-06-21 8:39 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-21 8:39 [PATCH v12 0/4] Introduce usb charger framework to deal with the usb gadget power negotation Baolin Wang
[not found] ` <cover.1466497505.git.baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-06-21 8:39 ` [PATCH v12 1/4] gadget: Introduce the usb charger framework Baolin Wang
2016-06-21 10:25 ` Felipe Balbi
2016-06-21 11:23 ` Baolin Wang
2016-06-21 14:50 ` Felipe Balbi
2016-06-22 1:49 ` Baolin Wang
2016-06-21 8:39 ` [PATCH v12 2/4] gadget: Support for " Baolin Wang
2016-06-21 10:27 ` Felipe Balbi
2016-06-21 11:29 ` Baolin Wang
2016-06-21 11:49 ` Felipe Balbi
[not found] ` <87twgmn4m7.fsf-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-06-21 12:05 ` Baolin Wang
2016-06-21 12:27 ` Felipe Balbi
[not found] ` <87inx2n2vs.fsf-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-06-21 12:34 ` Baolin Wang
[not found] ` <CAMz4kuKnzjPOqEr9kJY6SCnq2rszsc55X5=7mWb+ZcbL6G_8DQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-21 12:36 ` Felipe Balbi
2016-06-21 12:43 ` Baolin Wang
2016-06-21 12:53 ` Felipe Balbi
2016-06-21 12:54 ` Felipe Balbi
[not found] ` <87a8ien1o0.fsf-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-06-22 1:45 ` Baolin Wang
[not found] ` <87bn2uomzd.fsf-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-06-23 8:56 ` Baolin Wang
2016-06-29 8:20 ` Felipe Balbi
2016-06-29 8:31 ` Baolin Wang
2016-06-29 8:34 ` Felipe Balbi
2016-06-29 8:38 ` Baolin Wang
[not found] ` <CAMz4kuL9pJzNsn7xXXCp4s9Rczm5vWhuWfF7VjkuxsMUzNZXZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-29 12:06 ` Felipe Balbi
2016-06-29 12:16 ` Baolin Wang
2016-06-29 12:30 ` Felipe Balbi
2016-06-21 8:39 ` Baolin Wang [this message]
2016-06-21 8:39 ` [PATCH v12 4/4] power: wm831x_power: Support USB charger current limit management Baolin Wang
2016-06-21 10:30 ` Felipe Balbi
2016-06-21 11:03 ` Mark Brown
2016-06-21 11:45 ` Baolin Wang
2016-06-21 11:53 ` Felipe Balbi
2016-06-21 11:57 ` Baolin Wang
2016-06-21 11:50 ` Felipe Balbi
2016-06-21 14:53 ` Mark Brown
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=2f57bf9df3a5dc6cce45834eaeec4f00b25808b7.1466497506.git.baolin.wang@linaro.org \
--to=baolin.wang-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
--cc=balbi-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org \
--cc=dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=device-mainlining-cunTk1MwBs98uUxBSJOaYoYkZiVZrdSR2LY78lusg7I@public.gmane.org \
--cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=grygorii.strashko-l0cyMroinI0@public.gmane.org \
--cc=jun.li-3arQi8VN3Tc@public.gmane.org \
--cc=lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
--cc=patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org \
--cc=peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
--cc=r.baldyga-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
--cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=ruslan.bilovol-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org \
--cc=yoshihiro.shimoda.uh-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.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).