Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1286319 > unrolled thread
| Started by | Baolin Wang <baolin.wang@linaro.org> |
|---|---|
| First post | 2015-12-08 09:40 +0100 |
| Last post | 2015-12-08 09:40 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v7 3/4] gadget: Integrate with the usb gadget supporting for usb charger Baolin Wang <baolin.wang@linaro.org> - 2015-12-08 09:40 +0100
| From | Baolin Wang <baolin.wang@linaro.org> |
|---|---|
| Date | 2015-12-08 09:40 +0100 |
| Subject | [PATCH v7 3/4] gadget: Integrate with the usb gadget supporting for usb charger |
| Message-ID | <qDlYu-8lR-13@gated-at.bofh.it> |
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top | Article view | linux.kernel
csiph-web