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 2/4] gadget: Support for the usb charger framework
Date: Mon, 4 Jan 2016 11:04:28 +0800 [thread overview]
Message-ID: <6eaa0db83cff5eaffa2e10fe51f5b3e47b1dd4c3.1451876014.git.baolin.wang@linaro.org> (raw)
In-Reply-To: <cover.1451876014.git.baolin.wang@linaro.org>
In-Reply-To: <cover.1451876014.git.baolin.wang@linaro.org>
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.
It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.
Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
drivers/usb/gadget/udc/udc-core.c | 11 +++++++++++
include/linux/usb/gadget.h | 11 +++++++++++
2 files changed, 22 insertions(+)
diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
index f660afb..2727f01 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
#include <linux/usb.h>
+#include <linux/usb/usb_charger.h>
/**
* struct usb_udc - describes one usb device controller
@@ -226,6 +227,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
+ /* when the gadget state is changed, then report to USB charger */
+ usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(&udc->dev.kobj, NULL, "state");
}
@@ -405,8 +409,14 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
mutex_unlock(&udc_lock);
+ ret = usb_charger_init(gadget);
+ if (ret)
+ goto err5;
+
return 0;
+err5:
+ device_del(&udc->dev);
err4:
list_del(&udc->list);
mutex_unlock(&udc_lock);
@@ -481,6 +491,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
flush_work(&gadget->work);
device_unregister(&udc->dev);
+ usb_charger_exit(gadget);
device_unregister(&gadget->dev);
}
EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 3d583a1..52c19b1 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
#include <linux/types.h>
#include <linux/workqueue.h>
#include <linux/usb/ch9.h>
+#include <linux/usb/usb_charger.h>
struct usb_ep;
@@ -560,6 +561,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+ enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
};
/**
@@ -632,6 +634,8 @@ struct usb_gadget {
unsigned out_epnum;
unsigned in_epnum;
struct usb_otg_caps *otg_caps;
+ /* negotiate the power with the usb charger */
+ struct usb_charger *charger;
unsigned sg_supported:1;
unsigned is_otg:1;
@@ -836,10 +840,17 @@ static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget)
* reporting how much power the device may consume. For example, this
* could affect how quickly batteries are recharged.
*
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
* Returns zero on success, else negative errno.
*/
static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
{
+ if (gadget->charger)
+ usb_charger_set_cur_limit_by_type(gadget->charger,
+ usb_charger_detect_type(gadget->charger), mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
--
1.7.9.5
next prev parent reply other threads:[~2016-01-04 3:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
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 1/4] gadget: Introduce the usb charger framework Baolin Wang
2016-01-04 3:04 ` Baolin Wang [this message]
2016-01-04 3:04 ` [PATCH v7 3/4] gadget: Integrate with the usb gadget supporting for usb charger Baolin Wang
2016-01-04 3:04 ` [PATCH v7 4/4] power: wm831x_power: Support USB charger current limit management Baolin Wang
2016-01-04 5:21 ` kbuild test robot
[not found] ` <CAGjg+kHzt7pxxU=OdTd3sLWETiA7P6iMBmNs6dNvSCzFZiwv4w@mail.gmail.com>
2016-01-07 11:54 ` [PATCH v7 0/4] Introduce usb charger framework to deal with the usb gadget power negotation Baolin Wang
2016-01-25 3:44 ` Greg KH
2016-01-25 4:14 ` Baolin Wang
2016-02-29 14:22 ` Mark Brown
2016-03-15 16:39 ` Mark Brown
2016-03-16 11:05 ` Felipe Balbi
2016-03-16 11:20 ` Mark Brown
2016-03-16 11:27 ` Baolin Wang
-- strict thread matches above, loose matches on Subject: below --
2016-03-16 11:46 Baolin Wang
2016-03-16 11:46 ` [PATCH v7 2/4] gadget: Support for the usb charger framework Baolin Wang
2016-03-16 12:50 ` kbuild test robot
2016-03-16 20:19 ` kbuild test robot
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 ` [PATCH v7 2/4] gadget: Support for the usb charger framework Baolin Wang
2015-12-08 15:54 ` kbuild test robot
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=6eaa0db83cff5eaffa2e10fe51f5b3e47b1dd4c3.1451876014.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 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®