1 Index: linux-2.6.30.8/drivers/serial/Kconfig
2 ===================================================================
3 --- linux-2.6.30.8.orig/drivers/serial/Kconfig 2009-09-24 17:28:02.000000000 +0200
4 +++ linux-2.6.30.8/drivers/serial/Kconfig 2009-10-19 21:31:32.000000000 +0200
7 Support for Console on the NWP serial ports.
10 + bool "IFXMips serial driver"
13 + select SERIAL_CORE_CONSOLE
15 + Driver for the ifxmipss built in ASC hardware
18 tristate "Freescale QUICC Engine serial port support"
19 depends on QUICC_ENGINE
20 Index: linux-2.6.30.8/drivers/serial/Makefile
21 ===================================================================
22 --- linux-2.6.30.8.orig/drivers/serial/Makefile 2009-09-24 17:28:02.000000000 +0200
23 +++ linux-2.6.30.8/drivers/serial/Makefile 2009-10-19 21:31:32.000000000 +0200
25 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
26 obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
27 obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
28 +obj-$(CONFIG_SERIAL_IFXMIPS) += ifxmips_asc.o
29 Index: linux-2.6.30.8/drivers/serial/ifxmips_asc.c
30 ===================================================================
31 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
32 +++ linux-2.6.30.8/drivers/serial/ifxmips_asc.c 2009-10-19 21:41:27.000000000 +0200
35 + * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
37 + * This program is free software; you can redistribute it and/or modify
38 + * it under the terms of the GNU General Public License as published by
39 + * the Free Software Foundation; either version 2 of the License, or
40 + * (at your option) any later version.
42 + * This program is distributed in the hope that it will be useful,
43 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 + * GNU General Public License for more details.
47 + * You should have received a copy of the GNU General Public License
48 + * along with this program; if not, write to the Free Software
49 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
51 + * Copyright (C) 2004 Infineon IFAP DC COM CPE
52 + * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
53 + * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
56 +#include <linux/module.h>
57 +#include <linux/errno.h>
58 +#include <linux/signal.h>
59 +#include <linux/sched.h>
60 +#include <linux/interrupt.h>
61 +#include <linux/tty.h>
62 +#include <linux/tty_flip.h>
63 +#include <linux/major.h>
64 +#include <linux/string.h>
65 +#include <linux/fcntl.h>
66 +#include <linux/ptrace.h>
67 +#include <linux/ioport.h>
68 +#include <linux/mm.h>
69 +#include <linux/slab.h>
70 +#include <linux/init.h>
71 +#include <linux/circ_buf.h>
72 +#include <linux/serial.h>
73 +#include <linux/serial_core.h>
74 +#include <linux/console.h>
75 +#include <linux/sysrq.h>
76 +#include <linux/irq.h>
77 +#include <linux/platform_device.h>
78 +#include <linux/io.h>
79 +#include <linux/uaccess.h>
80 +#include <linux/bitops.h>
82 +#include <asm/system.h>
85 +#include <ifxmips_irq.h>
87 +#define PORT_IFXMIPSASC 111
89 +#include <linux/serial_core.h>
91 +#define UART_DUMMY_UER_RX 1
93 +static void ifxmipsasc_tx_chars(struct uart_port *port);
94 +extern void prom_printf(const char *fmt, ...);
95 +static struct uart_port ifxmipsasc_port[2];
96 +static struct uart_driver ifxmipsasc_reg;
97 +extern unsigned int ifxmips_get_fpi_hz(void);
99 +static void ifxmipsasc_stop_tx(struct uart_port *port)
104 +static void ifxmipsasc_start_tx(struct uart_port *port)
106 + unsigned long flags;
107 + local_irq_save(flags);
108 + ifxmipsasc_tx_chars(port);
109 + local_irq_restore(flags);
113 +static void ifxmipsasc_stop_rx(struct uart_port *port)
115 + ifxmips_w32(ASCWHBSTATE_CLRREN, port->membase + IFXMIPS_ASC_WHBSTATE);
118 +static void ifxmipsasc_enable_ms(struct uart_port *port)
122 +#include <linux/version.h>
124 +static void ifxmipsasc_rx_chars(struct uart_port *port)
126 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 26))
127 + struct tty_struct *tty = port->info->port.tty;
129 + struct tty_struct *tty = port->info->tty;
131 + unsigned int ch = 0, rsr = 0, fifocnt;
133 + fifocnt = ifxmips_r32(port->membase + IFXMIPS_ASC_FSTAT) & ASCFSTAT_RXFFLMASK;
134 + while (fifocnt--) {
135 + u8 flag = TTY_NORMAL;
136 + ch = ifxmips_r32(port->membase + IFXMIPS_ASC_RBUF);
137 + rsr = (ifxmips_r32(port->membase + IFXMIPS_ASC_STATE) & ASCSTATE_ANY) | UART_DUMMY_UER_RX;
138 + tty_flip_buffer_push(tty);
142 + * Note that the error handling code is
143 + * out of the main execution path
145 + if (rsr & ASCSTATE_ANY) {
146 + if (rsr & ASCSTATE_PE) {
147 + port->icount.parity++;
148 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_WHBSTATE) | ASCWHBSTATE_CLRPE, port->membase + IFXMIPS_ASC_WHBSTATE);
149 + } else if (rsr & ASCSTATE_FE) {
150 + port->icount.frame++;
151 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_WHBSTATE) | ASCWHBSTATE_CLRFE, port->membase + IFXMIPS_ASC_WHBSTATE);
153 + if (rsr & ASCSTATE_ROE) {
154 + port->icount.overrun++;
155 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_WHBSTATE) | ASCWHBSTATE_CLRROE, port->membase + IFXMIPS_ASC_WHBSTATE);
158 + rsr &= port->read_status_mask;
160 + if (rsr & ASCSTATE_PE)
162 + else if (rsr & ASCSTATE_FE)
166 + if ((rsr & port->ignore_status_mask) == 0)
167 + tty_insert_flip_char(tty, ch, flag);
169 + if (rsr & ASCSTATE_ROE)
171 + * Overrun is special, since it's reported
172 + * immediately, and doesn't affect the current
175 + tty_insert_flip_char(tty, 0, TTY_OVERRUN);
178 + tty_flip_buffer_push(tty);
183 +static void ifxmipsasc_tx_chars(struct uart_port *port)
185 + struct circ_buf *xmit = &port->info->xmit;
186 + if (uart_tx_stopped(port)) {
187 + ifxmipsasc_stop_tx(port);
191 + while (((ifxmips_r32(port->membase + IFXMIPS_ASC_FSTAT) & ASCFSTAT_TXFFLMASK)
192 + >> ASCFSTAT_TXFFLOFF) != TXFIFO_FULL) {
193 + if (port->x_char) {
194 + ifxmips_w32(port->x_char, port->membase + IFXMIPS_ASC_TBUF);
200 + if (uart_circ_empty(xmit))
203 + ifxmips_w32(port->info->xmit.buf[port->info->xmit.tail], port->membase + IFXMIPS_ASC_TBUF);
204 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
208 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
209 + uart_write_wakeup(port);
212 +static irqreturn_t ifxmipsasc_tx_int(int irq, void *_port)
214 + struct uart_port *port = (struct uart_port *)_port;
215 + ifxmips_w32(ASC_IRNCR_TIR, port->membase + IFXMIPS_ASC_IRNCR);
216 + ifxmipsasc_start_tx(port);
217 + ifxmips_mask_and_ack_irq(irq);
218 + return IRQ_HANDLED;
221 +static irqreturn_t ifxmipsasc_er_int(int irq, void *_port)
223 + struct uart_port *port = (struct uart_port *)_port;
224 + /* clear any pending interrupts */
225 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_WHBSTATE) | ASCWHBSTATE_CLRPE |
226 + ASCWHBSTATE_CLRFE | ASCWHBSTATE_CLRROE, port->membase + IFXMIPS_ASC_WHBSTATE);
227 + return IRQ_HANDLED;
230 +static irqreturn_t ifxmipsasc_rx_int(int irq, void *_port)
232 + struct uart_port *port = (struct uart_port *)_port;
233 + ifxmips_w32(ASC_IRNCR_RIR, port->membase + IFXMIPS_ASC_IRNCR);
234 + ifxmipsasc_rx_chars((struct uart_port *)port);
235 + ifxmips_mask_and_ack_irq(irq);
236 + return IRQ_HANDLED;
239 +static unsigned int ifxmipsasc_tx_empty(struct uart_port *port)
242 + status = ifxmips_r32(port->membase + IFXMIPS_ASC_FSTAT) & ASCFSTAT_TXFFLMASK;
243 + return status ? 0 : TIOCSER_TEMT;
246 +static unsigned int ifxmipsasc_get_mctrl(struct uart_port *port)
248 + return TIOCM_CTS | TIOCM_CAR | TIOCM_DSR;
251 +static void ifxmipsasc_set_mctrl(struct uart_port *port, u_int mctrl)
255 +static void ifxmipsasc_break_ctl(struct uart_port *port, int break_state)
259 +static int ifxmipsasc_startup(struct uart_port *port)
261 + unsigned long flags;
264 + port->uartclk = ifxmips_get_fpi_hz();
266 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CLC) & ~IFXMIPS_ASC_CLC_DISS, port->membase + IFXMIPS_ASC_CLC);
267 + ifxmips_w32(((ifxmips_r32(port->membase + IFXMIPS_ASC_CLC) & ~ASCCLC_RMCMASK)) | (1 << ASCCLC_RMCOFFSET), port->membase + IFXMIPS_ASC_CLC);
268 + ifxmips_w32(0, port->membase + IFXMIPS_ASC_PISEL);
269 + ifxmips_w32(((TXFIFO_FL << ASCTXFCON_TXFITLOFF) & ASCTXFCON_TXFITLMASK) | ASCTXFCON_TXFEN | ASCTXFCON_TXFFLU, port->membase + IFXMIPS_ASC_TXFCON);
270 + ifxmips_w32(((RXFIFO_FL << ASCRXFCON_RXFITLOFF) & ASCRXFCON_RXFITLMASK) | ASCRXFCON_RXFEN | ASCRXFCON_RXFFLU, port->membase + IFXMIPS_ASC_RXFCON);
272 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) | ASCCON_M_8ASYNC | ASCCON_FEN | ASCCON_TOEN | ASCCON_ROEN, port->membase + IFXMIPS_ASC_CON);
274 + local_irq_save(flags);
276 + retval = request_irq(port->irq, ifxmipsasc_tx_int, IRQF_DISABLED, "asc_tx", port);
278 + printk(KERN_ERR "failed to request ifxmipsasc_tx_int\n");
282 + retval = request_irq(port->irq + 2, ifxmipsasc_rx_int, IRQF_DISABLED, "asc_rx", port);
284 + printk(KERN_ERR "failed to request ifxmipsasc_rx_int\n");
288 + retval = request_irq(port->irq + 3, ifxmipsasc_er_int, IRQF_DISABLED, "asc_er", port);
290 + printk(KERN_ERR "failed to request ifxmipsasc_er_int\n");
294 + ifxmips_w32(ASC_IRNREN_RX_BUF | ASC_IRNREN_TX_BUF | ASC_IRNREN_ERR | ASC_IRNREN_TX, port->membase + IFXMIPS_ASC_IRNREN);
296 + local_irq_restore(flags);
300 + free_irq(port->irq + 2, port);
302 + free_irq(port->irq, port);
303 + local_irq_restore(flags);
307 +static void ifxmipsasc_shutdown(struct uart_port *port)
309 + free_irq(port->irq, port);
310 + free_irq(port->irq + 2, port);
311 + free_irq(port->irq + 3, port);
313 + ifxmips_w32(0, port->membase + IFXMIPS_ASC_CON);
314 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_RXFCON) | ASCRXFCON_RXFFLU, port->membase + IFXMIPS_ASC_RXFCON);
315 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_RXFCON) & ~ASCRXFCON_RXFEN, port->membase + IFXMIPS_ASC_RXFCON);
316 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_TXFCON) | ASCTXFCON_TXFFLU, port->membase + IFXMIPS_ASC_TXFCON);
317 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_TXFCON) & ~ASCTXFCON_TXFEN, port->membase + IFXMIPS_ASC_TXFCON);
320 +static void ifxmipsasc_set_termios(struct uart_port *port, struct ktermios *new, struct ktermios *old)
322 + unsigned int cflag;
323 + unsigned int iflag;
326 + unsigned int con = 0;
327 + unsigned long flags;
329 + cflag = new->c_cflag;
330 + iflag = new->c_iflag;
332 + switch (cflag & CSIZE) {
334 + con = ASCCON_M_7ASYNC;
340 + con = ASCCON_M_8ASYNC;
344 + if (cflag & CSTOPB)
347 + if (cflag & PARENB) {
348 + if (!(cflag & PARODD))
349 + con &= ~ASCCON_ODD;
354 + port->read_status_mask = ASCSTATE_ROE;
356 + port->read_status_mask |= ASCSTATE_FE | ASCSTATE_PE;
358 + port->ignore_status_mask = 0;
359 + if (iflag & IGNPAR)
360 + port->ignore_status_mask |= ASCSTATE_FE | ASCSTATE_PE;
362 + if (iflag & IGNBRK) {
364 + * If we're ignoring parity and break indicators,
365 + * ignore overruns too (for real raw support).
367 + if (iflag & IGNPAR)
368 + port->ignore_status_mask |= ASCSTATE_ROE;
371 + if ((cflag & CREAD) == 0)
372 + port->ignore_status_mask |= UART_DUMMY_UER_RX;
374 + /* set error signals - framing, parity and overrun, enable receiver */
375 + con |= ASCCON_FEN | ASCCON_TOEN | ASCCON_ROEN;
377 + local_irq_save(flags);
380 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) | con, port->membase + IFXMIPS_ASC_CON);
382 + /* Set baud rate - take a divider of 2 into account */
383 + baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16);
384 + quot = uart_get_divisor(port, baud);
385 + quot = quot / 2 - 1;
387 + /* disable the baudrate generator */
388 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) & ~ASCCON_R, port->membase + IFXMIPS_ASC_CON);
390 + /* make sure the fractional divider is off */
391 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) & ~ASCCON_FDE, port->membase + IFXMIPS_ASC_CON);
393 + /* set up to use divisor of 2 */
394 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) & ~ASCCON_BRS, port->membase + IFXMIPS_ASC_CON);
396 + /* now we can write the new baudrate into the register */
397 + ifxmips_w32(quot, port->membase + IFXMIPS_ASC_BG);
399 + /* turn the baudrate generator back on */
400 + ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) | ASCCON_R, port->membase + IFXMIPS_ASC_CON);
403 + ifxmips_w32(ASCWHBSTATE_SETREN, port->membase + IFXMIPS_ASC_WHBSTATE);
405 + local_irq_restore(flags);
408 +static const char *ifxmipsasc_type(struct uart_port *port)
410 + if (port->type == PORT_IFXMIPSASC) {
411 + if (port->membase == (void *)IFXMIPS_ASC_BASE_ADDR)
420 +static void ifxmipsasc_release_port(struct uart_port *port)
424 +static int ifxmipsasc_request_port(struct uart_port *port)
429 +static void ifxmipsasc_config_port(struct uart_port *port, int flags)
431 + if (flags & UART_CONFIG_TYPE) {
432 + port->type = PORT_IFXMIPSASC;
433 + ifxmipsasc_request_port(port);
437 +static int ifxmipsasc_verify_port(struct uart_port *port, struct serial_struct *ser)
440 + if (ser->type != PORT_UNKNOWN && ser->type != PORT_IFXMIPSASC)
442 + if (ser->irq < 0 || ser->irq >= NR_IRQS)
444 + if (ser->baud_base < 9600)
449 +static struct uart_ops ifxmipsasc_pops = {
450 + .tx_empty = ifxmipsasc_tx_empty,
451 + .set_mctrl = ifxmipsasc_set_mctrl,
452 + .get_mctrl = ifxmipsasc_get_mctrl,
453 + .stop_tx = ifxmipsasc_stop_tx,
454 + .start_tx = ifxmipsasc_start_tx,
455 + .stop_rx = ifxmipsasc_stop_rx,
456 + .enable_ms = ifxmipsasc_enable_ms,
457 + .break_ctl = ifxmipsasc_break_ctl,
458 + .startup = ifxmipsasc_startup,
459 + .shutdown = ifxmipsasc_shutdown,
460 + .set_termios = ifxmipsasc_set_termios,
461 + .type = ifxmipsasc_type,
462 + .release_port = ifxmipsasc_release_port,
463 + .request_port = ifxmipsasc_request_port,
464 + .config_port = ifxmipsasc_config_port,
465 + .verify_port = ifxmipsasc_verify_port,
468 +static struct uart_port ifxmipsasc_port[2] = {
470 + .membase = (void *)IFXMIPS_ASC_BASE_ADDR,
471 + .mapbase = IFXMIPS_ASC_BASE_ADDR,
472 + .iotype = SERIAL_IO_MEM,
473 + .irq = IFXMIPSASC_TIR(0),
476 + .type = PORT_IFXMIPSASC,
477 + .ops = &ifxmipsasc_pops,
478 + .flags = ASYNC_BOOT_AUTOCONF,
481 + .membase = (void *)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_BASE_DIFF),
482 + .mapbase = IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_BASE_DIFF,
483 + .iotype = SERIAL_IO_MEM,
484 + .irq = IFXMIPSASC_TIR(1),
487 + .type = PORT_IFXMIPSASC,
488 + .ops = &ifxmipsasc_pops,
489 + .flags = ASYNC_BOOT_AUTOCONF,
494 +static void ifxmipsasc_console_write(struct console *co, const char *s, u_int count)
496 + int port = co->index;
498 + unsigned long flags;
499 + local_irq_save(flags);
500 + for (i = 0; i < count; i++) {
502 + fifocnt = (ifxmips_r32((u32 *)(IFXMIPS_ASC_BASE_ADDR + (port * IFXMIPS_ASC_BASE_DIFF) + IFXMIPS_ASC_FSTAT)) & ASCFSTAT_TXFFLMASK)
503 + >> ASCFSTAT_TXFFLOFF;
504 + } while (fifocnt == TXFIFO_FULL);
509 + if (s[i] == '\n') {
510 + ifxmips_w32('\r', (u32 *)(IFXMIPS_ASC_BASE_ADDR + (port * IFXMIPS_ASC_BASE_DIFF) + IFXMIPS_ASC_TBUF));
512 + fifocnt = (ifxmips_r32((u32 *)(IFXMIPS_ASC_BASE_ADDR + (port * IFXMIPS_ASC_BASE_DIFF) + IFXMIPS_ASC_FSTAT)) & ASCFSTAT_TXFFLMASK)
513 + >> ASCFSTAT_TXFFLOFF;
514 + } while (fifocnt == TXFIFO_FULL);
516 + ifxmips_w32(s[i], (u32 *)(IFXMIPS_ASC_BASE_ADDR + (port * IFXMIPS_ASC_BASE_DIFF) + IFXMIPS_ASC_TBUF));
519 + local_irq_restore(flags);
522 +static int __init ifxmipsasc_console_setup(struct console *co, char *options)
524 + int port = co->index;
529 + ifxmipsasc_port[port].uartclk = ifxmips_get_fpi_hz();
530 + ifxmipsasc_port[port].type = PORT_IFXMIPSASC;
532 + uart_parse_options(options, &baud, &parity, &bits, &flow);
533 + return uart_set_options(&ifxmipsasc_port[port], co, baud, parity, bits, flow);
536 +static struct console ifxmipsasc_console[2] =
540 + .write = ifxmipsasc_console_write,
541 + .device = uart_console_device,
542 + .setup = ifxmipsasc_console_setup,
543 + .flags = CON_PRINTBUFFER,
545 + .data = &ifxmipsasc_reg,
548 + .write = ifxmipsasc_console_write,
549 + .device = uart_console_device,
550 + .setup = ifxmipsasc_console_setup,
551 + .flags = CON_PRINTBUFFER,
553 + .data = &ifxmipsasc_reg,
557 +static int __init ifxmipsasc_console_init(void)
559 + register_console(&ifxmipsasc_console[0]);
560 + register_console(&ifxmipsasc_console[1]);
563 +console_initcall(ifxmipsasc_console_init);
565 +static struct uart_driver ifxmipsasc_reg = {
566 + .owner = THIS_MODULE,
567 + .driver_name = "serial",
568 + .dev_name = "ttyS",
569 + .major = TTY_MAJOR,
572 + .cons = &ifxmipsasc_console[1],
575 +int __init ifxmipsasc_init(void)
578 + uart_register_driver(&ifxmipsasc_reg);
579 + ret = uart_add_one_port(&ifxmipsasc_reg, &ifxmipsasc_port[0]);
580 + ret = uart_add_one_port(&ifxmipsasc_reg, &ifxmipsasc_port[1]);
584 +void __exit ifxmipsasc_exit(void)
586 + uart_unregister_driver(&ifxmipsasc_reg);
589 +module_init(ifxmipsasc_init);
590 +module_exit(ifxmipsasc_exit);
592 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
593 +MODULE_DESCRIPTION("MIPS IFXMips serial port driver");
594 +MODULE_LICENSE("GPL");