Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1420612 > unrolled thread

[RESEND PATCH v11 0/4] Introduce usb charger framework to deal with the usb gadget power negotation

Started byBaolin Wang <baolin.wang@linaro.org>
First post2016-06-13 10:50 +0200
Last post2016-06-13 17:20 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [RESEND PATCH v11 0/4] Introduce usb charger framework to deal with the usb gadget power negotation Baolin Wang <baolin.wang@linaro.org> - 2016-06-13 10:50 +0200
    [RESEND PATCH v11 3/4] gadget: Integrate with the usb gadget supporting for usb charger Baolin Wang <baolin.wang@linaro.org> - 2016-06-13 10:50 +0200
      RE: [RESEND PATCH v11 3/4] gadget: Integrate with the usb gadget  supporting for usb charger Jun Li <jun.li@nxp.com> - 2016-06-13 17:20 +0200

#1420612 — [RESEND PATCH v11 0/4] Introduce usb charger framework to deal with the usb gadget power negotation

FromBaolin Wang <baolin.wang@linaro.org>
Date2016-06-13 10:50 +0200
Subject[RESEND PATCH v11 0/4] Introduce usb charger framework to deal with the usb gadget power negotation
Message-ID<rJvJf-3OU-19@gated-at.bofh.it>
Currently the Linux kernel does not provide any standard integration of this
feature that integrates the USB subsystem with the system power regulation
provided by PMICs meaning that either vendors must add this in their kernels
or USB gadget devices based on Linux (such as mobile phones) may not behave
as they should. Thus provide a standard framework for doing this in kernel.

Now introduce one user with wm831x_power to support and test the usb charger,
which is pending testing. Moreover there may be other potential users will use
it in future.

Changes since v10:
 - Introduce usb_charger_get_state() function to check charger state.
 - Remove the mutex lock in usb_charger_set_cur_limit_by_type() function
 in case will be issued in atomic context.

Baolin Wang (4):
  gadget: Introduce the usb charger framework
  gadget: Support for the usb charger framework
  gadget: Integrate with the usb gadget supporting for usb charger
  power: wm831x_power: Support USB charger current limit management

 drivers/power/wm831x_power.c      |   69 ++++
 drivers/usb/gadget/Kconfig        |    7 +
 drivers/usb/gadget/udc/Makefile   |    1 +
 drivers/usb/gadget/udc/charger.c  |  807 +++++++++++++++++++++++++++++++++++++
 drivers/usb/gadget/udc/udc-core.c |   11 +
 include/linux/mfd/wm831x/pdata.h  |    3 +
 include/linux/usb/charger.h       |  191 +++++++++
 include/linux/usb/gadget.h        |   11 +
 include/uapi/linux/usb/charger.h  |   31 ++
 9 files changed, 1131 insertions(+)
 create mode 100644 drivers/usb/gadget/udc/charger.c
 create mode 100644 include/linux/usb/charger.h
 create mode 100644 include/uapi/linux/usb/charger.h

-- 
1.7.9.5

[toc] | [next] | [standalone]


#1420625 — [RESEND PATCH v11 3/4] gadget: Integrate with the usb gadget supporting for usb charger

FromBaolin Wang <baolin.wang@linaro.org>
Date2016-06-13 10:50 +0200
Subject[RESEND PATCH v11 3/4] gadget: Integrate with the usb gadget supporting for usb charger
Message-ID<rJvJg-3OU-63@gated-at.bofh.it>
In reply to#1420612
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@linaro.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

[toc] | [prev] | [next] | [standalone]


#1420978 — RE: [RESEND PATCH v11 3/4] gadget: Integrate with the usb gadget supporting for usb charger

FromJun Li <jun.li@nxp.com>
Date2016-06-13 17:20 +0200
SubjectRE: [RESEND PATCH v11 3/4] gadget: Integrate with the usb gadget supporting for usb charger
Message-ID<rJBOF-82T-19@gated-at.bofh.it>
In reply to#1420625
Hi

> -----Original Message-----
> From: linux-usb-owner@vger.kernel.org [mailto:linux-usb-
> owner@vger.kernel.org] On Behalf Of Baolin Wang
> Sent: Monday, June 13, 2016 4:47 PM
> To: balbi@kernel.org; gregkh@linuxfoundation.org; sre@kernel.org;
> dbaryshkov@gmail.com; dwmw2@infradead.org
> Cc: robh@kernel.org; m.szyprowski@samsung.com; ruslan.bilovol@gmail.com;
> 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: [RESEND PATCH v11 3/4] gadget: Integrate with the usb gadget
> supporting for usb charger
> 
> 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@linaro.org>

Reviewed-by: Li Jun <jun.li@nxp.com>
Tested-by: Li Jun <jun.li@nxp.com>

> ---
>  drivers/usb/gadget/udc/charger.c |   39
> +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 38 insertions(+), 1 deletion(-)

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web