X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fserial%2Fpxa.c;h=77d4568ccc3a7fdc0811783e7a1bbf52e7e1d5b9;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=082e1b552cade09c6337f0c877f88f7f9621011d;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/drivers/serial/pxa.c b/drivers/serial/pxa.c index 082e1b552..77d4568cc 100644 --- a/drivers/serial/pxa.c +++ b/drivers/serial/pxa.c @@ -25,8 +25,12 @@ */ #include + +#if defined(CONFIG_SERIAL_PXA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) +#define SUPPORT_SYSRQ +#endif + #include -#include #include #include #include @@ -35,16 +39,15 @@ #include #include #include +#include +#include +#include +#include #include #include #include - -#if defined(CONFIG_SERIAL_PXA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - -#include +#include struct uart_pxa_port { @@ -77,7 +80,7 @@ static void serial_pxa_enable_ms(struct uart_port *port) serial_out(up, UART_IER, up->ier); } -static void serial_pxa_stop_tx(struct uart_port *port, unsigned int tty_stop) +static void serial_pxa_stop_tx(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; @@ -100,25 +103,12 @@ static inline void receive_chars(struct uart_pxa_port *up, int *status, struct pt_regs *regs) { struct tty_struct *tty = up->port.info->tty; - unsigned char ch; + unsigned int ch, flag; int max_count = 256; do { - if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) { - /* - * FIXME: Deadlock can happen here if we're a - * low-latency port. We're holding the per-port - * spinlock, and we call flush_to_ldisc-> - * n_tty_receive_buf->n_tty_receive_char-> - * opost->uart_put_char. - */ - tty->flip.work.func((void *)tty); - if (tty->flip.count >= TTY_FLIPBUF_SIZE) - return; // if TTY_DONT_FLIP is set - } ch = serial_in(up, UART_RX); - *tty->flip.char_buf_ptr = ch; - *tty->flip.flag_buf_ptr = TTY_NORMAL; + flag = TTY_NORMAL; up->port.icount.rx++; if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE | @@ -157,31 +147,18 @@ receive_chars(struct uart_pxa_port *up, int *status, struct pt_regs *regs) } #endif if (*status & UART_LSR_BI) { - *tty->flip.flag_buf_ptr = TTY_BREAK; + flag = TTY_BREAK; } else if (*status & UART_LSR_PE) - *tty->flip.flag_buf_ptr = TTY_PARITY; + flag = TTY_PARITY; else if (*status & UART_LSR_FE) - *tty->flip.flag_buf_ptr = TTY_FRAME; + flag = TTY_FRAME; } + if (uart_handle_sysrq_char(&up->port, ch, regs)) goto ignore_char; - if ((*status & up->port.ignore_status_mask) == 0) { - tty->flip.flag_buf_ptr++; - tty->flip.char_buf_ptr++; - tty->flip.count++; - } - if ((*status & UART_LSR_OE) && - tty->flip.count < TTY_FLIPBUF_SIZE) { - /* - * Overrun is special, since it's reported - * immediately, and doesn't affect the current - * character. - */ - *tty->flip.flag_buf_ptr = TTY_OVERRUN; - tty->flip.flag_buf_ptr++; - tty->flip.char_buf_ptr++; - tty->flip.count++; - } + + uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag); + ignore_char: *status = serial_in(up, UART_LSR); } while ((*status & UART_LSR_DR) && (max_count-- > 0)); @@ -200,7 +177,7 @@ static void transmit_chars(struct uart_pxa_port *up) return; } if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { - serial_pxa_stop_tx(&up->port, 0); + serial_pxa_stop_tx(&up->port); return; } @@ -218,10 +195,10 @@ static void transmit_chars(struct uart_pxa_port *up) if (uart_circ_empty(xmit)) - serial_pxa_stop_tx(&up->port, 0); + serial_pxa_stop_tx(&up->port); } -static void serial_pxa_start_tx(struct uart_port *port, unsigned int tty_start) +static void serial_pxa_start_tx(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; @@ -289,14 +266,11 @@ static unsigned int serial_pxa_tx_empty(struct uart_port *port) static unsigned int serial_pxa_get_mctrl(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; - unsigned long flags; unsigned char status; unsigned int ret; return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; - spin_lock_irqsave(&up->port.lock, flags); status = serial_in(up, UART_MSR); - spin_unlock_irqrestore(&up->port.lock, flags); ret = 0; if (status & UART_MSR_DCD) @@ -376,7 +350,10 @@ static int serial_pxa_startup(struct uart_port *port) unsigned long flags; int retval; - up->mcr = 0; + if (port->line == 3) /* HWUART */ + up->mcr |= UART_MCR_AFE; + else + up->mcr = 0; /* * Allocate the IRQ @@ -470,22 +447,22 @@ serial_pxa_set_termios(struct uart_port *port, struct termios *termios, switch (termios->c_cflag & CSIZE) { case CS5: - cval = 0x00; + cval = UART_LCR_WLEN5; break; case CS6: - cval = 0x01; + cval = UART_LCR_WLEN6; break; case CS7: - cval = 0x02; + cval = UART_LCR_WLEN7; break; default: case CS8: - cval = 0x03; + cval = UART_LCR_WLEN8; break; } if (termios->c_cflag & CSTOPB) - cval |= 0x04; + cval |= UART_LCR_STOP; if (termios->c_cflag & PARENB) cval |= UART_LCR_PARITY; if (!(termios->c_cflag & PARODD)) @@ -499,8 +476,10 @@ serial_pxa_set_termios(struct uart_port *port, struct termios *termios, if ((up->port.uartclk / quot) < (2400 * 16)) fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR1; - else + else if ((up->port.uartclk / quot) < (230400 * 16)) fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR8; + else + fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR32; /* * Ok, we're now changing the port state. Do it with @@ -517,7 +496,7 @@ serial_pxa_set_termios(struct uart_port *port, struct termios *termios, /* * Update the per-port timeout. */ - uart_update_timeout(port, termios->c_cflag, quot); + uart_update_timeout(port, termios->c_cflag, baud); up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; if (termios->c_iflag & INPCK) @@ -571,14 +550,9 @@ serial_pxa_pm(struct uart_port *port, unsigned int state, unsigned int oldstate) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; - if (state) { - /* sleep */ - CKEN &= ~up->cken; - } else { - /* wake */ - CKEN |= up->cken; + pxa_set_cken(up->cken, !state); + if (!state) udelay(1); - } } static void serial_pxa_release_port(struct uart_port *port) @@ -612,8 +586,8 @@ serial_pxa_type(struct uart_port *port) #ifdef CONFIG_SERIAL_PXA_CONSOLE -extern struct uart_pxa_port serial_pxa_ports[]; -extern struct uart_driver serial_pxa_reg; +static struct uart_pxa_port serial_pxa_ports[]; +static struct uart_driver serial_pxa_reg; #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) @@ -645,6 +619,14 @@ static inline void wait_for_xmitr(struct uart_pxa_port *up) } } +static void serial_pxa_console_putchar(struct uart_port *port, int ch) +{ + struct uart_pxa_port *up = (struct uart_pxa_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... @@ -656,30 +638,14 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count) { struct uart_pxa_port *up = &serial_pxa_ports[co->index]; unsigned int ier; - int i; /* - * First save the UER then disable the interrupts + * First save the IER then disable the interrupts */ ier = serial_in(up, UART_IER); serial_out(up, UART_IER, UART_IER_UUE); - /* - * 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, serial_pxa_console_putchar); /* * Finally, wait for transmitter to become empty @@ -795,6 +761,20 @@ static struct uart_pxa_port serial_pxa_ports[] = { .ops = &serial_pxa_pops, .line = 2, }, + }, { /* HWUART */ + .name = "HWUART", + .cken = CKEN4_HWUART, + .port = { + .type = PORT_PXA, + .iotype = UPIO_MEM, + .membase = (void *)&HWUART, + .mapbase = __PREG(HWUART), + .irq = IRQ_HWUART, + .uartclk = 921600 * 16, + .fifosize = 64, + .ops = &serial_pxa_pops, + .line = 3, + }, } }; @@ -809,26 +789,75 @@ static struct uart_driver serial_pxa_reg = { .cons = PXA_CONSOLE, }; -static int __init serial_pxa_init(void) +static int serial_pxa_suspend(struct platform_device *dev, pm_message_t state) { - int i, ret; + struct uart_pxa_port *sport = platform_get_drvdata(dev); - ret = uart_register_driver(&serial_pxa_reg); - if (ret) - return ret; + if (sport) + uart_suspend_port(&serial_pxa_reg, &sport->port); + + return 0; +} - for (i = 0; i < ARRAY_SIZE(serial_pxa_ports); i++) - uart_add_one_port(&serial_pxa_reg, &serial_pxa_ports[i].port); +static int serial_pxa_resume(struct platform_device *dev) +{ + struct uart_pxa_port *sport = platform_get_drvdata(dev); + + if (sport) + uart_resume_port(&serial_pxa_reg, &sport->port); + return 0; +} + +static int serial_pxa_probe(struct platform_device *dev) +{ + serial_pxa_ports[dev->id].port.dev = &dev->dev; + uart_add_one_port(&serial_pxa_reg, &serial_pxa_ports[dev->id].port); + platform_set_drvdata(dev, &serial_pxa_ports[dev->id]); return 0; } -static void __exit serial_pxa_exit(void) +static int serial_pxa_remove(struct platform_device *dev) { - int i; + struct uart_pxa_port *sport = platform_get_drvdata(dev); - for (i = 0; i < ARRAY_SIZE(serial_pxa_ports); i++) - uart_remove_one_port(&serial_pxa_reg, &serial_pxa_ports[i].port); + platform_set_drvdata(dev, NULL); + + if (sport) + uart_remove_one_port(&serial_pxa_reg, &sport->port); + + return 0; +} + +static struct platform_driver serial_pxa_driver = { + .probe = serial_pxa_probe, + .remove = serial_pxa_remove, + + .suspend = serial_pxa_suspend, + .resume = serial_pxa_resume, + .driver = { + .name = "pxa2xx-uart", + }, +}; + +int __init serial_pxa_init(void) +{ + int ret; + + ret = uart_register_driver(&serial_pxa_reg); + if (ret != 0) + return ret; + + ret = platform_driver_register(&serial_pxa_driver); + if (ret != 0) + uart_unregister_driver(&serial_pxa_reg); + + return ret; +} + +void __exit serial_pxa_exit(void) +{ + platform_driver_unregister(&serial_pxa_driver); uart_unregister_driver(&serial_pxa_reg); }