/* Advance the srr dqp maintained by SW */ staticvoid srr_dqp_index_advc(struct bdc *bdc, u32 srr_num)
{ struct srr *srr;
srr = &bdc->srr;
dev_dbg_ratelimited(bdc->dev, "srr->dqp_index:%d\n", srr->dqp_index);
srr->dqp_index++; /* rollback to 0 if we are past the last */ if (srr->dqp_index == NUM_SR_ENTRIES)
srr->dqp_index = 0;
}
/* connect sr */ staticvoid bdc_uspc_connected(struct bdc *bdc)
{
u32 speed, temp;
u32 usppms; int ret;
dev_dbg(bdc->dev, "%s\n", __func__); /* * Only stop ep0 from here, rest of the endpoints will be disabled * from gadget_disconnect
*/
ep = bdc->bdc_ep_array[1]; if (ep && (ep->flags & BDC_EP_ENABLED)) /* if enabled then stop and remove requests */
bdc_ep_disable(ep);
dev_dbg(bdc->dev, "%s\n", __func__);
spin_lock_irqsave(&bdc->lock, flags); /* * Check if host has started transferring on endpoints * FUNC_WAKE_ISSUED is cleared when transfer has started after resume
*/ if (bdc->devstatus & FUNC_WAKE_ISSUED) {
dev_dbg(bdc->dev, "FUNC_WAKE_ISSUED FLAG IS STILL SET\n"); /* flag is still set, so again send func wake */
bdc_function_wake_fh(bdc, 0);
schedule_delayed_work(&bdc->func_wake_notify,
msecs_to_jiffies(BDC_TNOTIFY));
}
spin_unlock_irqrestore(&bdc->lock, flags);
}
/* handler for Link state change condition */ staticvoid handle_link_state_change(struct bdc *bdc, u32 uspc)
{
u32 link_state;
dev_dbg(bdc->dev, "Link state change");
link_state = BDC_PST(uspc); switch (link_state) { case BDC_LINK_STATE_U3: if ((bdc->gadget.speed != USB_SPEED_UNKNOWN) &&
bdc->gadget_driver->suspend) {
dev_dbg(bdc->dev, "Entered Suspend mode\n");
spin_unlock(&bdc->lock);
bdc->devstatus |= DEVICE_SUSPENDED;
bdc->gadget_driver->suspend(&bdc->gadget);
spin_lock(&bdc->lock);
} break; case BDC_LINK_STATE_U0: if (bdc->devstatus & REMOTE_WAKEUP_ISSUED) {
bdc->devstatus &= ~REMOTE_WAKEUP_ISSUED; if (bdc->gadget.speed == USB_SPEED_SUPER) {
bdc_function_wake_fh(bdc, 0);
bdc->devstatus |= FUNC_WAKE_ISSUED; /* * Start a Notification timer and check if the * Host transferred anything on any of the EPs, * if not then send function wake again every * TNotification secs until host initiates * transfer to BDC, USB3 spec Table 8.13
*/
schedule_delayed_work(
&bdc->func_wake_notify,
msecs_to_jiffies(BDC_TNOTIFY));
dev_dbg(bdc->dev, "sched func_wake_notify\n");
}
} break;
case BDC_LINK_STATE_RESUME:
dev_dbg(bdc->dev, "Resumed from Suspend\n"); if (bdc->devstatus & DEVICE_SUSPENDED) {
bdc->gadget_driver->resume(&bdc->gadget);
bdc->devstatus &= ~DEVICE_SUSPENDED;
} break; default:
dev_dbg(bdc->dev, "link state:%d\n", link_state);
}
}
/* Port connect changed */ if (uspc & BDC_PCC) { /* Vbus not present, and not connected to Downstream port */ if ((uspc & BDC_VBC) && !(uspc & BDC_VBS) && !(uspc & BDC_PCS))
disconn = true; elseif ((uspc & BDC_PCS) && !BDC_PST(uspc))
connected = true;
clear_flags |= BDC_PCC;
}
/* Change in VBus and VBus is present */ if ((uspc & BDC_VBC) && (uspc & BDC_VBS)) { if (bdc->pullup) {
dev_dbg(bdc->dev, "Do a softconnect\n"); /* Attached state, do a softconnect */
bdc_softconn(bdc);
usb_gadget_set_state(&bdc->gadget, USB_STATE_POWERED);
}
clear_flags |= BDC_VBC;
} elseif ((uspc & BDC_PRS) || (uspc & BDC_PRC) || disconn) { /* Hot reset, warm reset, 2.0 bus reset or disconn */
dev_dbg(bdc->dev, "Port reset or disconn\n");
bdc_uspc_disconnected(bdc, disconn);
clear_flags |= BDC_PRC;
} elseif ((uspc & BDC_PSC) && (uspc & BDC_PCS)) { /* Change in Link state */
handle_link_state_change(bdc, uspc);
clear_flags |= BDC_PSC;
}
/* * In SS we might not have PRC bit set before connection, but in 2.0 * the PRC bit is set before connection, so moving this condition out * of bus reset to handle both SS/2.0 speeds.
*/ if (connected) { /* This is the connect event for U0/L0 */
dev_dbg(bdc->dev, "Connected\n");
bdc_uspc_connected(bdc);
bdc->devstatus &= ~(DEVICE_SUSPENDED);
}
uspc = bdc_readl(bdc->regs, BDC_USPC);
uspc &= (~BDC_USPSC_RW);
dev_dbg(bdc->dev, "uspc=%x\n", uspc);
bdc_writel(bdc->regs, BDC_USPC, clear_flags);
}
dev_dbg(bdc->dev, "%s()\n", __func__);
spin_lock_irqsave(&bdc->lock, flags); if (bdc->gadget_driver) {
dev_err(bdc->dev, "%s is already bound to %s\n",
bdc->gadget.name,
bdc->gadget_driver->driver.name);
ret = -EBUSY; goto err;
} /* * Run the controller from here and when BDC is connected to * Host then driver will receive a USPC SR with VBUS present * and then driver will do a softconnect.
*/
ret = bdc_run(bdc); if (ret) {
dev_err(bdc->dev, "%s bdc run fail\n", __func__); goto err;
}
bdc->gadget_driver = driver;
bdc->gadget.dev.driver = &driver->driver;
err:
spin_unlock_irqrestore(&bdc->lock, flags);
dev_dbg(bdc->dev, "%s() is_on:%d\n", __func__, is_on); if (!gadget) return -EINVAL;
spin_lock_irqsave(&bdc->lock, flags); if (!is_on) {
bdc_softdisconn(bdc);
bdc->pullup = false;
} else { /* * For a self powered device, we need to wait till we receive * a VBUS change and Vbus present event, then if pullup flag * is set, then only we present the Termintation.
*/
bdc->pullup = true; /* * Check if BDC is already connected to Host i.e Vbus=1, * if yes, then present TERM now, this is typical for bus * powered devices.
*/
uspc = bdc_readl(bdc->regs, BDC_USPC); if (uspc & BDC_VBS)
bdc_softconn(bdc);
}
spin_unlock_irqrestore(&bdc->lock, flags);
bdc->gadget.name = BRCM_BDC_NAME;
ret = devm_request_irq(bdc->dev, bdc->irq, bdc_udc_interrupt,
IRQF_SHARED, BRCM_BDC_NAME, bdc); if (ret) {
dev_err(bdc->dev, "failed to request irq #%d %d\n",
bdc->irq, ret); return ret;
}
ret = bdc_init_ep(bdc); if (ret) {
dev_err(bdc->dev, "bdc init ep fail: %d\n", ret); return ret;
}
ret = usb_add_gadget_udc(bdc->dev, &bdc->gadget); if (ret) {
dev_err(bdc->dev, "failed to register udc\n"); goto err0;
}
usb_gadget_set_state(&bdc->gadget, USB_STATE_NOTATTACHED);
bdc->bdc_ep_array[1]->desc = &bdc_gadget_ep0_desc; /* * Allocate bd list for ep0 only, ep0 will be enabled on connect * status report when the speed is known
*/
ret = bdc_ep_enable(bdc->bdc_ep_array[1]); if (ret) {
dev_err(bdc->dev, "fail to enable %s\n",
bdc->bdc_ep_array[1]->name); goto err1;
}
INIT_DELAYED_WORK(&bdc->func_wake_notify, bdc_func_wake_timer); /* Enable Interrupts */
temp = bdc_readl(bdc->regs, BDC_BDCSC);
temp |= BDC_GIE;
bdc_writel(bdc->regs, BDC_BDCSC, temp); return 0;
err1:
usb_del_gadget_udc(&bdc->gadget);
err0:
bdc_free_ep(bdc);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.