Commit d16ab536 authored by Peter Chen's avatar Peter Chen

usb: chipidea: udc: add new API ci_hdrc_gadget_connect

This API is used enable device function, it is called at below
situations:
- VBUS is connected during boots up
- Hot plug occurs during runtime
Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
Signed-off-by: default avatarJun Li <jun.li@nxp.com>
parent a079973f
...@@ -1524,23 +1524,13 @@ static const struct usb_ep_ops usb_ep_ops = { ...@@ -1524,23 +1524,13 @@ static const struct usb_ep_ops usb_ep_ops = {
/****************************************************************************** /******************************************************************************
* GADGET block * GADGET block
*****************************************************************************/ *****************************************************************************/
static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) /**
* ci_hdrc_gadget_connect: caller makes sure gadget driver is binded
*/
static void ci_hdrc_gadget_connect(struct usb_gadget *_gadget, int is_active)
{ {
struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
unsigned long flags;
int gadget_ready = 0;
spin_lock_irqsave(&ci->lock, flags);
ci->vbus_active = is_active;
if (ci->driver)
gadget_ready = 1;
spin_unlock_irqrestore(&ci->lock, flags);
if (ci->usb_phy)
usb_phy_set_charger_state(ci->usb_phy, is_active ?
USB_CHARGER_PRESENT : USB_CHARGER_ABSENT);
if (gadget_ready) {
if (is_active) { if (is_active) {
pm_runtime_get_sync(&_gadget->dev); pm_runtime_get_sync(&_gadget->dev);
hw_device_reset(ci); hw_device_reset(ci);
...@@ -1559,7 +1549,26 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) ...@@ -1559,7 +1549,26 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
pm_runtime_put_sync(&_gadget->dev); pm_runtime_put_sync(&_gadget->dev);
usb_gadget_set_state(_gadget, USB_STATE_NOTATTACHED); usb_gadget_set_state(_gadget, USB_STATE_NOTATTACHED);
} }
} }
static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
{
struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
unsigned long flags;
int gadget_ready = 0;
spin_lock_irqsave(&ci->lock, flags);
ci->vbus_active = is_active;
if (ci->driver)
gadget_ready = 1;
spin_unlock_irqrestore(&ci->lock, flags);
if (ci->usb_phy)
usb_phy_set_charger_state(ci->usb_phy, is_active ?
USB_CHARGER_PRESENT : USB_CHARGER_ABSENT);
if (gadget_ready)
ci_hdrc_gadget_connect(_gadget, is_active);
return 0; return 0;
} }
...@@ -1785,18 +1794,10 @@ static int ci_udc_start(struct usb_gadget *gadget, ...@@ -1785,18 +1794,10 @@ static int ci_udc_start(struct usb_gadget *gadget,
return retval; return retval;
} }
pm_runtime_get_sync(&ci->gadget.dev); if (ci->vbus_active)
if (ci->vbus_active) { ci_hdrc_gadget_connect(gadget, 1);
hw_device_reset(ci); else
} else {
usb_udc_vbus_handler(&ci->gadget, false); usb_udc_vbus_handler(&ci->gadget, false);
pm_runtime_put_sync(&ci->gadget.dev);
return retval;
}
retval = hw_device_state(ci, ci->ep0out->qh.dma);
if (retval)
pm_runtime_put_sync(&ci->gadget.dev);
return retval; return retval;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment