Part Number: AM3358
Hi,
We are developing an USB peripheral, which works fine on any USB host we tried so far, except on the Sitara AM3358, where we get Babble errors right after the host performs an USB reset, and BEFORE enumeration begins.
To rule out custom hardware issues (as Babble is supposed to be an electrical or timing problem), we have reproduced the problem on a test setup with an STM32 Nucleo-C071RB development kit which we connect to a Beaglebone Black. As far as I can tell, there are no electrical problems in terms of voltage levels, signal integrity etc. Everything looks fine on the oscilloscope.
I have two Beaglebone black boards, which are identical except for supplier and production date. They run the exact same firmware image. Both boards have the problem, but one Beaglebone black has a lot more babble issues than the other one.
- The reasonably good board has Sitara device markings AM3358BZCZ100 46AIDFW GI 962B ZCZ
- The problematic board has Sitara device markings AM3358BZCZ100 61AYTHW GI 962B ZCZ
Conclusion: the same silicon revision, so they SHOULD behave the same.
So, I started digging...
Looking at my logic analyzer, the source code, and the debug output, I came to some interesting conclusions. (Refer to /drivers/usb/musb/musb_dsps.c for the relevant code).
- If a babble interrupt occurs, the hardware interrupt flag is cleared quite soon in dsps_interrupt().
- The babble condition is handled some time later in dsps_sw_babble_control(): MUSB_BABBLE_FORCE_TX_IDLE is set, the MUSB_BABBLE_STUCK_J gets cleared, and the babble condition is handled without the need for a session restart.
- If the babble interrupt flag is set again (in hardware) between clearing the flag and handling the babble (which happens more on one board than the other?), the interrupt handler is re-executed for a second time a few microseconds after the first time it was executed. This time however, STUCK_J is not set, and the logic dictates that a session restart is required because this is a 'real' babble and not 'noise'
- If the session is restarted, then VBUS is powered off and on, USB detects a high-speed peripheral, performs and USB reset, and the cycle repeats.
- This session restart occurs 0 to about a dozen times on my problematic board. Eventually, it gets through, the device is properly enumerated, and from then on there are no more babble issues.
To fix this situation, I exerimentally patched dsps_sw_babble_control() as follows, which seems to fix this issue.
However, it doesn't feel quite right to clear for the following reasons:
- I don't know why babble occurs more on one board than the other
- I don't know what causes it to begin with, as it doesn't appear to be an electrical or timing issue (or I just can find it...)
If anyone can shed a light on this, it would be highly appreciated.
Thanks.
static bool dsps_sw_babble_control(struct musb *musb)
{
void __iomem *reg_base = musb->ctrl_base;
struct device *dev = musb->controller;
struct dsps_glue *glue = dev_get_drvdata(dev->parent);
const struct dsps_musb_wrapper *wrp = glue->wrp;
/*
* Check if interrupt flag is set when we enter this function.
* Flag should have been cleared in dsps_interrupt(), but it may
* have been set again by the time we reach this function.
*/
bool flag_at_strt = musb_readl(reg_base, wrp->coreintr_status) & MUSB_INTR_BABBLE;
u8 babble_ctl;
bool session_restart = false;
babble_ctl = musb_readb(musb->mregs, MUSB_BABBLE_CTL);
dev_dbg(musb->controller, "babble: MUSB_BABBLE_CTL value %x\n",
babble_ctl);
/*
* check line monitor flag to check whether babble is
* due to noise
*/
dev_dbg(musb->controller, "STUCK_J is %s\n",
babble_ctl & MUSB_BABBLE_STUCK_J ? "set" : "reset");
if (babble_ctl & MUSB_BABBLE_STUCK_J) {
int timeout = 10;
/*
* babble is due to noise, then set transmit idle (d7 bit)
* to resume normal operation
*/
babble_ctl = musb_readb(musb->mregs, MUSB_BABBLE_CTL);
babble_ctl |= MUSB_BABBLE_FORCE_TXIDLE;
musb_writeb(musb->mregs, MUSB_BABBLE_CTL, babble_ctl);
/* wait till line monitor flag cleared */
dev_dbg(musb->controller, "Set TXIDLE, wait J to clear\n");
do {
babble_ctl = musb_readb(musb->mregs, MUSB_BABBLE_CTL);
udelay(1);
} while ((babble_ctl & MUSB_BABBLE_STUCK_J) && timeout--);
/* check whether stuck_at_j bit cleared */
if (babble_ctl & MUSB_BABBLE_STUCK_J) {
/*
* real babble condition has occurred
* restart the controller to start the
* session again
*/
dev_dbg(musb->controller, "J not cleared, misc (%x)\n",
babble_ctl);
session_restart = true;
}
/* We have recovered from babble. Check the babble interrupt
* flag after recovering.
*/
bool flag_after_rcvry =
musb_readl(reg_base, wrp->coreintr_status) & MUSB_INTR_BABBLE;
/* Report the flags, clear it if set after recovery.*/
dev_dbg(musb->controller, "Babble flag before and after recovery: %u %u\n",
(unsigned int)flag_at_strt, (unsigned int)flag_after_rcvry);
if(flag_after_rcvry)
musb_writel(reg_base, wrp->coreintr_status, MUSB_INTR_BABBLE);
} else {
session_restart = true;
}
return session_restart;
}