aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorPeter Chen <peter.chen@freescale.com>2015-03-05 21:36:03 -0500
committerFelipe Balbi <balbi@ti.com>2015-03-19 12:26:03 -0400
commit628ef0d273a69d889669a459fb4675c678ae0418 (patch)
tree959599b38d2934aec388b53c086a3ab4f38baeba /drivers/usb/gadget
parentdfea9c94837d27e38c8cc85a3c1c7c268973c3c2 (diff)
usb: udc: add usb_udc_vbus_handler
This commit updates udc core vbus status, and try to connect or disconnect gadget. Signed-off-by: Peter Chen <peter.chen@freescale.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/udc/udc-core.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
index bf7ed777a87d..d69c35558f68 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -35,6 +35,8 @@
35 * @dev - the child device to the actual controller 35 * @dev - the child device to the actual controller
36 * @gadget - the gadget. For use by the class code 36 * @gadget - the gadget. For use by the class code
37 * @list - for use by the udc class driver 37 * @list - for use by the udc class driver
38 * @vbus - for udcs who care about vbus status, this value is real vbus status;
39 * for udcs who do not care about vbus status, this value is always true
38 * 40 *
39 * This represents the internal data structure which is used by the UDC-class 41 * This represents the internal data structure which is used by the UDC-class
40 * to hold information about udc driver and gadget together. 42 * to hold information about udc driver and gadget together.
@@ -44,6 +46,7 @@ struct usb_udc {
44 struct usb_gadget *gadget; 46 struct usb_gadget *gadget;
45 struct device dev; 47 struct device dev;
46 struct list_head list; 48 struct list_head list;
49 bool vbus;
47}; 50};
48 51
49static struct class *udc_class; 52static struct class *udc_class;
@@ -145,6 +148,34 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state);
145 148
146/* ------------------------------------------------------------------------- */ 149/* ------------------------------------------------------------------------- */
147 150
151static void usb_udc_connect_control(struct usb_udc *udc)
152{
153 if (udc->vbus)
154 usb_gadget_connect(udc->gadget);
155 else
156 usb_gadget_disconnect(udc->gadget);
157}
158
159/**
160 * usb_udc_vbus_handler - updates the udc core vbus status, and try to
161 * connect or disconnect gadget
162 * @gadget: The gadget which vbus change occurs
163 * @status: The vbus status
164 *
165 * The udc driver calls it when it wants to connect or disconnect gadget
166 * according to vbus status.
167 */
168void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status)
169{
170 struct usb_udc *udc = gadget->udc;
171
172 if (udc) {
173 udc->vbus = status;
174 usb_udc_connect_control(udc);
175 }
176}
177EXPORT_SYMBOL_GPL(usb_udc_vbus_handler);
178
148/** 179/**
149 * usb_gadget_udc_reset - notifies the udc core that bus reset occurs 180 * usb_gadget_udc_reset - notifies the udc core that bus reset occurs
150 * @gadget: The gadget which bus reset occurs 181 * @gadget: The gadget which bus reset occurs
@@ -278,6 +309,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
278 goto err4; 309 goto err4;
279 310
280 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); 311 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
312 udc->vbus = true;
281 313
282 mutex_unlock(&udc_lock); 314 mutex_unlock(&udc_lock);
283 315
@@ -381,7 +413,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
381 driver->unbind(udc->gadget); 413 driver->unbind(udc->gadget);
382 goto err1; 414 goto err1;
383 } 415 }
384 usb_gadget_connect(udc->gadget); 416 usb_udc_connect_control(udc);
385 417
386 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 418 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
387 return 0; 419 return 0;