<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><div>Hi, </div><div><br></div><div>This is my first post. I&#39;ve an interesting finding to share with you. I&#39;m using AT91RM9200 with an old kernel 2.4.21-rmk1. Recently, I found that the kernel would hang at times when calling open(&quot;/dev/ttySX&quot;) in order to initialize an RS232 port, IRDA port or other serial device. In fact, it got stuck at an infinite while loop here:</div>
<div><br></div><div>[drivers/at91/serial/at91_serial.c, at91_change_speed()]</div><div><br></div><div>......</div><div>    /* first, disable interrupts and drain transmitter */</div><div>    local_irq_save(flags);</div><div>
    imr = UART_GET_IMR(uart);   /* get interrupt mask */</div><div>    UART_PUT_IDR(uart, -1);     /* disable all interrupts */</div><div>    local_irq_restore(flags);</div><div><br></div><div>    while (!(UART_GET_CSR(uart) &amp; AT91C_US_TXEMPTY)) { barrier(); }</div>
<div>......</div><div>    UART_PUT_BRGR(uart, quot);</div><div><br></div><div>------------------------------------------</div><div>It didn&#39;t stand to reason that a byte sent to the shift register could never trasmitted. After painstaking investigation, I found that US_BRGR (clock divisor) was 0 when the loop was being executed, which means the clock was disabled. The reason there was data to be transmitted during the open call was that by default the ttyS device has the ECHO c_lflag on and there was some initial noise generated from the serial devices, causing the noise received to be transmitted soon after the transmitted was enabled during. If the noise happened to arrive just before the loop was executed, the kernel would be trapped. That explains the randomness. If US_BRGR was set to some non-zero value, the problem would disappear. It seems even in the latest kernel, the while loop still precedes setting the US_BRGR. I wonder if this is a potential kernel bug, or if it&#39;s just my responsibility to ensure that there is no noise or ECHO turned off as default for non-terminal devices?</div>
<div><br></div><div>Regards,</div><div>Sammy</div><div><br></div><div>----------------</div><div>Sammy Chan</div><font color="#888888"><div><a href="mailto:csammy@gmail.com" target="_blank" style="color: rgb(42, 93, 176); ">csammy@gmail.com</a></div>
</font></span>