All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linaro.org>
To: balbi@ti.com, gregkh@linuxfoundation.org, sre@kernel.org,
	dbaryshkov@gmail.com, dwmw2@infradead.org
Cc: peter.chen@freescale.com, stern@rowland.harvard.edu,
	r.baldyga@samsung.com, yoshihiro.shimoda.uh@renesas.com,
	lee.jones@linaro.org, broonie@kernel.org,
	ckeepax@opensource.wolfsonmicro.com,
	patches@opensource.wolfsonmicro.com, baolin.wang@linaro.org,
	linux-pm@vger.kernel.org, linux-usb@vger.kernel.org,
	device-mainlining@lists.linuxfoundation.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v7 3/4] gadget: Integrate with the usb gadget supporting for usb charger
Date: Tue,  8 Dec 2015 16:36:03 +0800	[thread overview]
Message-ID: <52ff0259aac20c001087d57ab17a3babd2853414.1449562597.git.baolin.wang@linaro.org> (raw)
In-Reply-To: <cover.1449562597.git.baolin.wang@linaro.org>
In-Reply-To: <cover.1449562597.git.baolin.wang@linaro.org>

When the usb gadget supporting for usb charger is ready, the usb charger
should get the type by the 'get_charger_type' callback which is implemented
by the usb gadget operations, and get the usb charger pointer from struct
'usb_gadget'.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/usb/gadget/charger.c |   43 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
index 82a9973..76e1a6f 100644
--- a/drivers/usb/gadget/charger.c
+++ b/drivers/usb/gadget/charger.c
@@ -272,7 +272,11 @@ EXPORT_SYMBOL_GPL(usb_charger_unregister_notify);
 enum usb_charger_type
 usb_charger_detect_type(struct usb_charger *uchger)
 {
-	if (uchger->psy) {
+	if (uchger->gadget && uchger->gadget->ops
+	    && uchger->gadget->ops->get_charger_type) {
+		uchger->type =
+			uchger->gadget->ops->get_charger_type(uchger->gadget);
+	} else if (uchger->psy) {
 		union power_supply_propval val;
 
 		power_supply_get_property(uchger->psy,
@@ -479,6 +483,29 @@ 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 (!uchger)
+		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);
@@ -635,6 +662,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 = ugadget->state;
 
 	/* register a new usb charger */
@@ -655,7 +683,18 @@ fail:
 
 int usb_charger_exit(struct usb_gadget *ugadget)
 {
-	return 0;
+	struct usb_charger *uchger = ugadget->charger;
+
+	if (!uchger)
+		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_sysfs_init(void)
-- 
1.7.9.5


  parent reply	other threads:[~2015-12-08  8:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-08  8:36 [PATCH v7 0/4] Introduce usb charger framework to deal with the usb gadget power negotation Baolin Wang
2015-12-08  8:36 ` Baolin Wang
2015-12-08  8:36 ` [PATCH v7 1/4] gadget: Introduce the usb charger framework Baolin Wang
2015-12-08  8:36 ` [PATCH v7 2/4] gadget: Support for " Baolin Wang
2015-12-08 15:54   ` kbuild test robot
2015-12-08 15:54     ` kbuild test robot
2015-12-08  8:36 ` Baolin Wang [this message]
2015-12-08  8:36 ` [PATCH v7 4/4] power: wm831x_power: Support USB charger current limit management Baolin Wang
2016-01-04  3:04 [PATCH v7 0/4] Introduce usb charger framework to deal with the usb gadget power negotation Baolin Wang
2016-01-04  3:04 ` [PATCH v7 3/4] gadget: Integrate with the usb gadget supporting for usb charger Baolin Wang
2016-03-16 11:46 [PATCH v7 0/4] Introduce usb charger framework to deal with the usb gadget power negotation Baolin Wang
2016-03-16 11:46 ` [PATCH v7 3/4] gadget: Integrate with the usb gadget supporting for usb charger Baolin Wang

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=52ff0259aac20c001087d57ab17a3babd2853414.1449562597.git.baolin.wang@linaro.org \
    --to=baolin.wang@linaro.org \
    --cc=balbi@ti.com \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=dbaryshkov@gmail.com \
    --cc=device-mainlining@lists.linuxfoundation.org \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=peter.chen@freescale.com \
    --cc=r.baldyga@samsung.com \
    --cc=sre@kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=yoshihiro.shimoda.uh@renesas.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.