Skip to content

Commit

Permalink
[SERIAL] kernel console should send CRLF not LFCR
Browse files Browse the repository at this point in the history
Glen Turner reported that writing LFCR rather than the more
traditional CRLF causes issues with some terminals.

Since this aflicts many serial drivers, extract the common code
to a library function (uart_console_write) and arrange for each
driver to supply a "putchar" function.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Russell King authored and Russell King committed Mar 20, 2006
1 parent 7705a87 commit d358788
Show file tree
Hide file tree
Showing 25 changed files with 190 additions and 301 deletions.
19 changes: 7 additions & 12 deletions drivers/serial/21285.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,23 +375,18 @@ static void serial21285_setup_ports(void)
}

#ifdef CONFIG_SERIAL_21285_CONSOLE
static void serial21285_console_putchar(struct uart_port *port, int ch)
{
while (*CSR_UARTFLG & 0x20)
barrier();
*CSR_UARTDR = ch;
}

static void
serial21285_console_write(struct console *co, const char *s,
unsigned int count)
{
int i;

for (i = 0; i < count; i++) {
while (*CSR_UARTFLG & 0x20)
barrier();
*CSR_UARTDR = s[i];
if (s[i] == '\n') {
while (*CSR_UARTFLG & 0x20)
barrier();
*CSR_UARTDR = '\r';
}
}
uart_console_write(&serial21285_port, s, count, serial21285_console_putchar);
}

static void __init
Expand Down
26 changes: 9 additions & 17 deletions drivers/serial/8250.c
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,14 @@ static inline void wait_for_xmitr(struct uart_8250_port *up, int bits)
}
}

static void serial8250_console_putchar(struct uart_port *port, int ch)
{
struct uart_8250_port *up = (struct uart_8250_port *)port;

wait_for_xmitr(up, UART_LSR_THRE);
serial_out(up, UART_TX, ch);
}

/*
* Print a string to the serial port trying not to disturb
* any possible real use of the port...
Expand All @@ -2193,7 +2201,6 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
{
struct uart_8250_port *up = &serial8250_ports[co->index];
unsigned int ier;
int i;

touch_nmi_watchdog();

Expand All @@ -2207,22 +2214,7 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
else
serial_out(up, UART_IER, 0);

/*
* Now, do each character
*/
for (i = 0; i < count; i++, s++) {
wait_for_xmitr(up, UART_LSR_THRE);

/*
* Send the character out.
* If a LF, also do CR...
*/
serial_out(up, UART_TX, *s);
if (*s == 10) {
wait_for_xmitr(up, UART_LSR_THRE);
serial_out(up, UART_TX, 13);
}
}
uart_console_write(&up->port, s, count, serial8250_console_putchar);

/*
* Finally, wait for transmitter to become empty
Expand Down
9 changes: 2 additions & 7 deletions drivers/serial/8250_early.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void __init wait_for_xmitr(struct uart_port *port)
}
}

static void __init putc(struct uart_port *port, unsigned char c)
static void __init putc(struct uart_port *port, int c)
{
wait_for_xmitr(port);
serial_out(port, UART_TX, c);
Expand All @@ -89,12 +89,7 @@ static void __init early_uart_write(struct console *console, const char *s, unsi
ier = serial_in(port, UART_IER);
serial_out(port, UART_IER, 0);

while (*s && count-- > 0) {
putc(port, *s);
if (*s == '\n')
putc(port, '\r');
s++;
}
uart_console_write(port, s, count, putc);

/* Wait for transmitter to become empty and restore the IER */
wait_for_xmitr(port);
Expand Down
24 changes: 8 additions & 16 deletions drivers/serial/amba-pl010.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,34 +591,26 @@ static struct uart_amba_port amba_ports[UART_NR] = {

#ifdef CONFIG_SERIAL_AMBA_PL010_CONSOLE

static void pl010_console_putchar(struct uart_port *port, int ch)
{
while (!UART_TX_READY(UART_GET_FR(port)))
barrier();
UART_PUT_CHAR(port, ch);
}

static void
pl010_console_write(struct console *co, const char *s, unsigned int count)
{
struct uart_port *port = &amba_ports[co->index].port;
unsigned int status, old_cr;
int i;

/*
* First save the CR then disable the interrupts
*/
old_cr = UART_GET_CR(port);
UART_PUT_CR(port, UART01x_CR_UARTEN);

/*
* Now, do each character
*/
for (i = 0; i < count; i++) {
do {
status = UART_GET_FR(port);
} while (!UART_TX_READY(status));
UART_PUT_CHAR(port, s[i]);
if (s[i] == '\n') {
do {
status = UART_GET_FR(port);
} while (!UART_TX_READY(status));
UART_PUT_CHAR(port, '\r');
}
}
uart_console_write(port, s, count, pl010_console_putchar);

/*
* Finally, wait for transmitter to become empty
Expand Down
20 changes: 5 additions & 15 deletions drivers/serial/amba-pl011.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,12 @@ static struct uart_amba_port *amba_ports[UART_NR];

#ifdef CONFIG_SERIAL_AMBA_PL011_CONSOLE

static inline void
pl011_console_write_char(struct uart_amba_port *uap, char ch)
static void pl011_console_putchar(struct uart_port *port, int ch)
{
unsigned int status;
struct uart_amba_port *uap = (struct uart_amba_port *)port;

do {
status = readw(uap->port.membase + UART01x_FR);
} while (status & UART01x_FR_TXFF);
while (readw(uap->port.membase + UART01x_FR) & UART01x_FR_TXFF)
barrier();
writew(ch, uap->port.membase + UART01x_DR);
}

Expand All @@ -603,7 +601,6 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
{
struct uart_amba_port *uap = amba_ports[co->index];
unsigned int status, old_cr, new_cr;
int i;

clk_enable(uap->clk);

Expand All @@ -615,14 +612,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
new_cr |= UART01x_CR_UARTEN | UART011_CR_TXE;
writew(new_cr, uap->port.membase + UART011_CR);

/*
* Now, do each character
*/
for (i = 0; i < count; i++) {
pl011_console_write_char(uap, s[i]);
if (s[i] == '\n')
pl011_console_write_char(uap, '\r');
}
uart_console_write(&uap->port, s, count, pl011_console_putchar);

/*
* Finally, wait for transmitter to become empty
Expand Down
24 changes: 8 additions & 16 deletions drivers/serial/at91_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,36 +711,28 @@ void __init at91_register_uart(int idx, int port)
}

#ifdef CONFIG_SERIAL_AT91_CONSOLE
static void at91_console_putchar(struct uart_port *port, int ch)
{
while (!(UART_GET_CSR(port) & AT91_US_TXRDY))
barrier();
UART_PUT_CHAR(port, ch);
}

/*
* Interrupts are disabled on entering
*/
static void at91_console_write(struct console *co, const char *s, u_int count)
{
struct uart_port *port = at91_ports + co->index;
unsigned int status, i, imr;
unsigned int status, imr;

/*
* First, save IMR and then disable interrupts
*/
imr = UART_GET_IMR(port); /* get interrupt mask */
UART_PUT_IDR(port, AT91_US_RXRDY | AT91_US_TXRDY);

/*
* Now, do each character
*/
for (i = 0; i < count; i++) {
do {
status = UART_GET_CSR(port);
} while (!(status & AT91_US_TXRDY));
UART_PUT_CHAR(port, s[i]);
if (s[i] == '\n') {
do {
status = UART_GET_CSR(port);
} while (!(status & AT91_US_TXRDY));
UART_PUT_CHAR(port, '\r');
}
}
uart_console_write(port, s, count, at91_console_putchar);

/*
* Finally, wait for transmitter to become empty
Expand Down
26 changes: 9 additions & 17 deletions drivers/serial/au1x00_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,14 @@ static inline void wait_for_xmitr(struct uart_8250_port *up)
}
}

static void au1x00_console_putchar(struct uart_port *port, int ch)
{
struct uart_8250_port *up = (struct uart_8250_port *)port;

wait_for_xmitr(up);
serial_out(up, UART_TX, ch);
}

/*
* Print a string to the serial port trying not to disturb
* any possible real use of the port...
Expand All @@ -1132,30 +1140,14 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
{
struct uart_8250_port *up = &serial8250_ports[co->index];
unsigned int ier;
int i;

/*
* First save the UER then disable the interrupts
*/
ier = serial_in(up, UART_IER);
serial_out(up, UART_IER, 0);

/*
* Now, do each character
*/
for (i = 0; i < count; i++, s++) {
wait_for_xmitr(up);

/*
* Send the character out.
* If a LF, also do CR...
*/
serial_out(up, UART_TX, *s);
if (*s == 10) {
wait_for_xmitr(up);
serial_out(up, UART_TX, 13);
}
}
uart_console_write(&up->port, s, count, au1x00_console_putchar);

/*
* Finally, wait for transmitter to become empty
Expand Down
24 changes: 8 additions & 16 deletions drivers/serial/clps711x.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ static struct uart_port clps711x_ports[UART_NR] = {
};

#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
static void clps711xuart_console_putchar(struct uart_port *port, int ch)
{
while (clps_readl(SYSFLG(port)) & SYSFLG_UTXFF)
barrier();
clps_writel(ch, UARTDR(port));
}

/*
* Print a string to the serial port trying not to disturb
* any possible real use of the port...
Expand All @@ -438,29 +445,14 @@ clps711xuart_console_write(struct console *co, const char *s,
{
struct uart_port *port = clps711x_ports + co->index;
unsigned int status, syscon;
int i;

/*
* Ensure that the port is enabled.
*/
syscon = clps_readl(SYSCON(port));
clps_writel(syscon | SYSCON_UARTEN, SYSCON(port));

/*
* Now, do each character
*/
for (i = 0; i < count; i++) {
do {
status = clps_readl(SYSFLG(port));
} while (status & SYSFLG_UTXFF);
clps_writel(s[i], UARTDR(port));
if (s[i] == '\n') {
do {
status = clps_readl(SYSFLG(port));
} while (status & SYSFLG_UTXFF);
clps_writel('\r', UARTDR(port));
}
}
uart_console_write(port, s, count, clps711xuart_console_putchar);

/*
* Finally, wait for transmitter to become empty
Expand Down
12 changes: 5 additions & 7 deletions drivers/serial/dz.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,12 @@ static void dz_reset(struct dz_port *dport)
}

#ifdef CONFIG_SERIAL_DZ_CONSOLE
static void dz_console_put_char(struct dz_port *dport, unsigned char ch)
static void dz_console_putchar(struct uart_port *port, int ch)
{
struct dz_port *dport = (struct dz_port *)uport;
unsigned long flags;
int loops = 2500;
unsigned short tmp = ch;
unsigned short tmp = (unsigned char)ch;
/* this code sends stuff out to serial device - spinning its
wheels and waiting. */

Expand All @@ -694,6 +695,7 @@ static void dz_console_put_char(struct dz_port *dport, unsigned char ch)

spin_unlock_irqrestore(&dport->port.lock, flags);
}

/*
* -------------------------------------------------------------------
* dz_console_print ()
Expand All @@ -710,11 +712,7 @@ static void dz_console_print(struct console *cons,
#ifdef DEBUG_DZ
prom_printf((char *) str);
#endif
while (count--) {
if (*str == '\n')
dz_console_put_char(dport, '\r');
dz_console_put_char(dport, *str++);
}
uart_console_write(&dport->port, str, count, dz_console_putchar);
}

static int __init dz_console_setup(struct console *co, char *options)
Expand Down
Loading

0 comments on commit d358788

Please sign in to comment.