12ac4ad2aSVineet Gupta /* 22ac4ad2aSVineet Gupta * ARC On-Chip(fpga) UART Driver 32ac4ad2aSVineet Gupta * 42ac4ad2aSVineet Gupta * Copyright (C) 2010-2012 Synopsys, Inc. (www.synopsys.com) 52ac4ad2aSVineet Gupta * 62ac4ad2aSVineet Gupta * This program is free software; you can redistribute it and/or modify 72ac4ad2aSVineet Gupta * it under the terms of the GNU General Public License version 2 as 82ac4ad2aSVineet Gupta * published by the Free Software Foundation. 92ac4ad2aSVineet Gupta * 102ac4ad2aSVineet Gupta * vineetg: July 10th 2012 112ac4ad2aSVineet Gupta * -Decoupled the driver from arch/arc 122ac4ad2aSVineet Gupta * +Using platform_get_resource() for irq/membase (thx to bfin_uart.c) 132ac4ad2aSVineet Gupta * +Using early_platform_xxx() for early console (thx to mach-shmobile/xxx) 142ac4ad2aSVineet Gupta * 152ac4ad2aSVineet Gupta * Vineetg: Aug 21st 2010 162ac4ad2aSVineet Gupta * -Is uart_tx_stopped() not done in tty write path as it has already been 172ac4ad2aSVineet Gupta * taken care of, in serial core 182ac4ad2aSVineet Gupta * 192ac4ad2aSVineet Gupta * Vineetg: Aug 18th 2010 202ac4ad2aSVineet Gupta * -New Serial Core based ARC UART driver 212ac4ad2aSVineet Gupta * -Derived largely from blackfin driver albiet with some major tweaks 222ac4ad2aSVineet Gupta * 232ac4ad2aSVineet Gupta * TODO: 242ac4ad2aSVineet Gupta * -check if sysreq works 252ac4ad2aSVineet Gupta */ 262ac4ad2aSVineet Gupta 272ac4ad2aSVineet Gupta #if defined(CONFIG_SERIAL_ARC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 282ac4ad2aSVineet Gupta #define SUPPORT_SYSRQ 292ac4ad2aSVineet Gupta #endif 302ac4ad2aSVineet Gupta 312ac4ad2aSVineet Gupta #include <linux/module.h> 322ac4ad2aSVineet Gupta #include <linux/serial.h> 332ac4ad2aSVineet Gupta #include <linux/console.h> 342ac4ad2aSVineet Gupta #include <linux/sysrq.h> 352ac4ad2aSVineet Gupta #include <linux/platform_device.h> 362ac4ad2aSVineet Gupta #include <linux/tty.h> 372ac4ad2aSVineet Gupta #include <linux/tty_flip.h> 382ac4ad2aSVineet Gupta #include <linux/serial_core.h> 392ac4ad2aSVineet Gupta #include <linux/io.h> 402ac4ad2aSVineet Gupta 412ac4ad2aSVineet Gupta /************************************* 422ac4ad2aSVineet Gupta * ARC UART Hardware Specs 432ac4ad2aSVineet Gupta ************************************/ 442ac4ad2aSVineet Gupta #define ARC_UART_TX_FIFO_SIZE 1 452ac4ad2aSVineet Gupta 462ac4ad2aSVineet Gupta /* 472ac4ad2aSVineet Gupta * UART Register set (this is not a Standards Compliant IP) 482ac4ad2aSVineet Gupta * Also each reg is Word aligned, but only 8 bits wide 492ac4ad2aSVineet Gupta */ 502ac4ad2aSVineet Gupta #define R_ID0 0 512ac4ad2aSVineet Gupta #define R_ID1 4 522ac4ad2aSVineet Gupta #define R_ID2 8 532ac4ad2aSVineet Gupta #define R_ID3 12 542ac4ad2aSVineet Gupta #define R_DATA 16 552ac4ad2aSVineet Gupta #define R_STS 20 562ac4ad2aSVineet Gupta #define R_BAUDL 24 572ac4ad2aSVineet Gupta #define R_BAUDH 28 582ac4ad2aSVineet Gupta 592ac4ad2aSVineet Gupta /* Bits for UART Status Reg (R/W) */ 602ac4ad2aSVineet Gupta #define RXIENB 0x04 /* Receive Interrupt Enable */ 612ac4ad2aSVineet Gupta #define TXIENB 0x40 /* Transmit Interrupt Enable */ 622ac4ad2aSVineet Gupta 632ac4ad2aSVineet Gupta #define RXEMPTY 0x20 /* Receive FIFO Empty: No char receivede */ 642ac4ad2aSVineet Gupta #define TXEMPTY 0x80 /* Transmit FIFO Empty, thus char can be written into */ 652ac4ad2aSVineet Gupta 662ac4ad2aSVineet Gupta #define RXFULL 0x08 /* Receive FIFO full */ 672ac4ad2aSVineet Gupta #define RXFULL1 0x10 /* Receive FIFO has space for 1 char (tot space=4) */ 682ac4ad2aSVineet Gupta 692ac4ad2aSVineet Gupta #define RXFERR 0x01 /* Frame Error: Stop Bit not detected */ 702ac4ad2aSVineet Gupta #define RXOERR 0x02 /* OverFlow Err: Char recv but RXFULL still set */ 712ac4ad2aSVineet Gupta 722ac4ad2aSVineet Gupta /* Uart bit fiddling helpers: lowest level */ 732ac4ad2aSVineet Gupta #define RBASE(uart, reg) (uart->port.membase + reg) 742ac4ad2aSVineet Gupta #define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r)) 752ac4ad2aSVineet Gupta #define UART_REG_GET(u, r) readb(RBASE(u, r)) 762ac4ad2aSVineet Gupta 772ac4ad2aSVineet Gupta #define UART_REG_OR(u, r, v) UART_REG_SET(u, r, UART_REG_GET(u, r) | (v)) 782ac4ad2aSVineet Gupta #define UART_REG_CLR(u, r, v) UART_REG_SET(u, r, UART_REG_GET(u, r) & ~(v)) 792ac4ad2aSVineet Gupta 802ac4ad2aSVineet Gupta /* Uart bit fiddling helpers: API level */ 812ac4ad2aSVineet Gupta #define UART_SET_DATA(uart, val) UART_REG_SET(uart, R_DATA, val) 822ac4ad2aSVineet Gupta #define UART_GET_DATA(uart) UART_REG_GET(uart, R_DATA) 832ac4ad2aSVineet Gupta 842ac4ad2aSVineet Gupta #define UART_SET_BAUDH(uart, val) UART_REG_SET(uart, R_BAUDH, val) 852ac4ad2aSVineet Gupta #define UART_SET_BAUDL(uart, val) UART_REG_SET(uart, R_BAUDL, val) 862ac4ad2aSVineet Gupta 872ac4ad2aSVineet Gupta #define UART_CLR_STATUS(uart, val) UART_REG_CLR(uart, R_STS, val) 882ac4ad2aSVineet Gupta #define UART_GET_STATUS(uart) UART_REG_GET(uart, R_STS) 892ac4ad2aSVineet Gupta 902ac4ad2aSVineet Gupta #define UART_ALL_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, RXIENB|TXIENB) 912ac4ad2aSVineet Gupta #define UART_RX_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, RXIENB) 922ac4ad2aSVineet Gupta #define UART_TX_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, TXIENB) 932ac4ad2aSVineet Gupta 942ac4ad2aSVineet Gupta #define UART_ALL_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, RXIENB|TXIENB) 952ac4ad2aSVineet Gupta #define UART_RX_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, RXIENB) 962ac4ad2aSVineet Gupta #define UART_TX_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, TXIENB) 972ac4ad2aSVineet Gupta 982ac4ad2aSVineet Gupta #define ARC_SERIAL_DEV_NAME "ttyARC" 992ac4ad2aSVineet Gupta 1002ac4ad2aSVineet Gupta struct arc_uart_port { 1012ac4ad2aSVineet Gupta struct uart_port port; 1022ac4ad2aSVineet Gupta unsigned long baud; 1032ac4ad2aSVineet Gupta int is_emulated; /* H/w vs. Instruction Set Simulator */ 1042ac4ad2aSVineet Gupta }; 1052ac4ad2aSVineet Gupta 1062ac4ad2aSVineet Gupta #define to_arc_port(uport) container_of(uport, struct arc_uart_port, port) 1072ac4ad2aSVineet Gupta 1082ac4ad2aSVineet Gupta static struct arc_uart_port arc_uart_ports[CONFIG_SERIAL_ARC_NR_PORTS]; 1092ac4ad2aSVineet Gupta 1102ac4ad2aSVineet Gupta #ifdef CONFIG_SERIAL_ARC_CONSOLE 1112ac4ad2aSVineet Gupta static struct console arc_console; 1122ac4ad2aSVineet Gupta #endif 1132ac4ad2aSVineet Gupta 1142ac4ad2aSVineet Gupta #define DRIVER_NAME "arc-uart" 1152ac4ad2aSVineet Gupta 1162ac4ad2aSVineet Gupta static struct uart_driver arc_uart_driver = { 1172ac4ad2aSVineet Gupta .owner = THIS_MODULE, 1182ac4ad2aSVineet Gupta .driver_name = DRIVER_NAME, 1192ac4ad2aSVineet Gupta .dev_name = ARC_SERIAL_DEV_NAME, 1202ac4ad2aSVineet Gupta .major = 0, 1212ac4ad2aSVineet Gupta .minor = 0, 1222ac4ad2aSVineet Gupta .nr = CONFIG_SERIAL_ARC_NR_PORTS, 1232ac4ad2aSVineet Gupta #ifdef CONFIG_SERIAL_ARC_CONSOLE 1242ac4ad2aSVineet Gupta .cons = &arc_console, 1252ac4ad2aSVineet Gupta #endif 1262ac4ad2aSVineet Gupta }; 1272ac4ad2aSVineet Gupta 1282ac4ad2aSVineet Gupta static void arc_serial_stop_rx(struct uart_port *port) 1292ac4ad2aSVineet Gupta { 1302ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 1312ac4ad2aSVineet Gupta 1322ac4ad2aSVineet Gupta UART_RX_IRQ_DISABLE(uart); 1332ac4ad2aSVineet Gupta } 1342ac4ad2aSVineet Gupta 1352ac4ad2aSVineet Gupta static void arc_serial_stop_tx(struct uart_port *port) 1362ac4ad2aSVineet Gupta { 1372ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 1382ac4ad2aSVineet Gupta 1392ac4ad2aSVineet Gupta while (!(UART_GET_STATUS(uart) & TXEMPTY)) 1402ac4ad2aSVineet Gupta cpu_relax(); 1412ac4ad2aSVineet Gupta 1422ac4ad2aSVineet Gupta UART_TX_IRQ_DISABLE(uart); 1432ac4ad2aSVineet Gupta } 1442ac4ad2aSVineet Gupta 1452ac4ad2aSVineet Gupta /* 1462ac4ad2aSVineet Gupta * Return TIOCSER_TEMT when transmitter is not busy. 1472ac4ad2aSVineet Gupta */ 1482ac4ad2aSVineet Gupta static unsigned int arc_serial_tx_empty(struct uart_port *port) 1492ac4ad2aSVineet Gupta { 1502ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 1512ac4ad2aSVineet Gupta unsigned int stat; 1522ac4ad2aSVineet Gupta 1532ac4ad2aSVineet Gupta stat = UART_GET_STATUS(uart); 1542ac4ad2aSVineet Gupta if (stat & TXEMPTY) 1552ac4ad2aSVineet Gupta return TIOCSER_TEMT; 1562ac4ad2aSVineet Gupta 1572ac4ad2aSVineet Gupta return 0; 1582ac4ad2aSVineet Gupta } 1592ac4ad2aSVineet Gupta 1602ac4ad2aSVineet Gupta /* 1612ac4ad2aSVineet Gupta * Driver internal routine, used by both tty(serial core) as well as tx-isr 1622ac4ad2aSVineet Gupta * -Called under spinlock in either cases 1632ac4ad2aSVineet Gupta * -also tty->stopped / tty->hw_stopped has already been checked 1642ac4ad2aSVineet Gupta * = by uart_start( ) before calling us 1652ac4ad2aSVineet Gupta * = tx_ist checks that too before calling 1662ac4ad2aSVineet Gupta */ 1672ac4ad2aSVineet Gupta static void arc_serial_tx_chars(struct arc_uart_port *uart) 1682ac4ad2aSVineet Gupta { 1692ac4ad2aSVineet Gupta struct circ_buf *xmit = &uart->port.state->xmit; 1702ac4ad2aSVineet Gupta int sent = 0; 1712ac4ad2aSVineet Gupta unsigned char ch; 1722ac4ad2aSVineet Gupta 1732ac4ad2aSVineet Gupta if (unlikely(uart->port.x_char)) { 1742ac4ad2aSVineet Gupta UART_SET_DATA(uart, uart->port.x_char); 1752ac4ad2aSVineet Gupta uart->port.icount.tx++; 1762ac4ad2aSVineet Gupta uart->port.x_char = 0; 1772ac4ad2aSVineet Gupta sent = 1; 1782ac4ad2aSVineet Gupta } else if (xmit->tail != xmit->head) { /* TODO: uart_circ_empty */ 1792ac4ad2aSVineet Gupta ch = xmit->buf[xmit->tail]; 1802ac4ad2aSVineet Gupta xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 1812ac4ad2aSVineet Gupta uart->port.icount.tx++; 1822ac4ad2aSVineet Gupta while (!(UART_GET_STATUS(uart) & TXEMPTY)) 1832ac4ad2aSVineet Gupta cpu_relax(); 1842ac4ad2aSVineet Gupta UART_SET_DATA(uart, ch); 1852ac4ad2aSVineet Gupta sent = 1; 1862ac4ad2aSVineet Gupta } 1872ac4ad2aSVineet Gupta 1882ac4ad2aSVineet Gupta /* 1892ac4ad2aSVineet Gupta * If num chars in xmit buffer are too few, ask tty layer for more. 1902ac4ad2aSVineet Gupta * By Hard ISR to schedule processing in software interrupt part 1912ac4ad2aSVineet Gupta */ 1922ac4ad2aSVineet Gupta if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 1932ac4ad2aSVineet Gupta uart_write_wakeup(&uart->port); 1942ac4ad2aSVineet Gupta 1952ac4ad2aSVineet Gupta if (sent) 1962ac4ad2aSVineet Gupta UART_TX_IRQ_ENABLE(uart); 1972ac4ad2aSVineet Gupta } 1982ac4ad2aSVineet Gupta 1992ac4ad2aSVineet Gupta /* 2002ac4ad2aSVineet Gupta * port is locked and interrupts are disabled 2012ac4ad2aSVineet Gupta * uart_start( ) calls us under the port spinlock irqsave 2022ac4ad2aSVineet Gupta */ 2032ac4ad2aSVineet Gupta static void arc_serial_start_tx(struct uart_port *port) 2042ac4ad2aSVineet Gupta { 2052ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 2062ac4ad2aSVineet Gupta 2072ac4ad2aSVineet Gupta arc_serial_tx_chars(uart); 2082ac4ad2aSVineet Gupta } 2092ac4ad2aSVineet Gupta 2102ac4ad2aSVineet Gupta static void arc_serial_rx_chars(struct arc_uart_port *uart) 2112ac4ad2aSVineet Gupta { 2122ac4ad2aSVineet Gupta struct tty_struct *tty = tty_port_tty_get(&uart->port.state->port); 2132ac4ad2aSVineet Gupta unsigned int status, ch, flg = 0; 2142ac4ad2aSVineet Gupta 2152ac4ad2aSVineet Gupta if (!tty) 2162ac4ad2aSVineet Gupta return; 2172ac4ad2aSVineet Gupta 2182ac4ad2aSVineet Gupta /* 2192ac4ad2aSVineet Gupta * UART has 4 deep RX-FIFO. Driver's recongnition of this fact 2202ac4ad2aSVineet Gupta * is very subtle. Here's how ... 2212ac4ad2aSVineet Gupta * Upon getting a RX-Intr, such that RX-EMPTY=0, meaning data available, 2222ac4ad2aSVineet Gupta * driver reads the DATA Reg and keeps doing that in a loop, until 2232ac4ad2aSVineet Gupta * RX-EMPTY=1. Multiple chars being avail, with a single Interrupt, 2242ac4ad2aSVineet Gupta * before RX-EMPTY=0, implies some sort of buffering going on in the 2252ac4ad2aSVineet Gupta * controller, which is indeed the Rx-FIFO. 2262ac4ad2aSVineet Gupta */ 2272ac4ad2aSVineet Gupta while (!((status = UART_GET_STATUS(uart)) & RXEMPTY)) { 2282ac4ad2aSVineet Gupta 2292ac4ad2aSVineet Gupta ch = UART_GET_DATA(uart); 2302ac4ad2aSVineet Gupta uart->port.icount.rx++; 2312ac4ad2aSVineet Gupta 2322ac4ad2aSVineet Gupta if (unlikely(status & (RXOERR | RXFERR))) { 2332ac4ad2aSVineet Gupta if (status & RXOERR) { 2342ac4ad2aSVineet Gupta uart->port.icount.overrun++; 2352ac4ad2aSVineet Gupta flg = TTY_OVERRUN; 2362ac4ad2aSVineet Gupta UART_CLR_STATUS(uart, RXOERR); 2372ac4ad2aSVineet Gupta } 2382ac4ad2aSVineet Gupta 2392ac4ad2aSVineet Gupta if (status & RXFERR) { 2402ac4ad2aSVineet Gupta uart->port.icount.frame++; 2412ac4ad2aSVineet Gupta flg = TTY_FRAME; 2422ac4ad2aSVineet Gupta UART_CLR_STATUS(uart, RXFERR); 2432ac4ad2aSVineet Gupta } 2442ac4ad2aSVineet Gupta } else 2452ac4ad2aSVineet Gupta flg = TTY_NORMAL; 2462ac4ad2aSVineet Gupta 2472ac4ad2aSVineet Gupta if (unlikely(uart_handle_sysrq_char(&uart->port, ch))) 2482ac4ad2aSVineet Gupta goto done; 2492ac4ad2aSVineet Gupta 2502ac4ad2aSVineet Gupta uart_insert_char(&uart->port, status, RXOERR, ch, flg); 2512ac4ad2aSVineet Gupta 2522ac4ad2aSVineet Gupta done: 2532ac4ad2aSVineet Gupta tty_flip_buffer_push(tty); 2542ac4ad2aSVineet Gupta } 2552ac4ad2aSVineet Gupta 2562ac4ad2aSVineet Gupta tty_kref_put(tty); 2572ac4ad2aSVineet Gupta } 2582ac4ad2aSVineet Gupta 2592ac4ad2aSVineet Gupta /* 2602ac4ad2aSVineet Gupta * A note on the Interrupt handling state machine of this driver 2612ac4ad2aSVineet Gupta * 2622ac4ad2aSVineet Gupta * kernel printk writes funnel thru the console driver framework and in order 2632ac4ad2aSVineet Gupta * to keep things simple as well as efficient, it writes to UART in polled 2642ac4ad2aSVineet Gupta * mode, in one shot, and exits. 2652ac4ad2aSVineet Gupta * 2662ac4ad2aSVineet Gupta * OTOH, Userland output (via tty layer), uses interrupt based writes as there 2672ac4ad2aSVineet Gupta * can be undeterministic delay between char writes. 2682ac4ad2aSVineet Gupta * 2692ac4ad2aSVineet Gupta * Thus Rx-interrupts are always enabled, while tx-interrupts are by default 2702ac4ad2aSVineet Gupta * disabled. 2712ac4ad2aSVineet Gupta * 2722ac4ad2aSVineet Gupta * When tty has some data to send out, serial core calls driver's start_tx 2732ac4ad2aSVineet Gupta * which 2742ac4ad2aSVineet Gupta * -checks-if-tty-buffer-has-char-to-send 2752ac4ad2aSVineet Gupta * -writes-data-to-uart 2762ac4ad2aSVineet Gupta * -enable-tx-intr 2772ac4ad2aSVineet Gupta * 2782ac4ad2aSVineet Gupta * Once data bits are pushed out, controller raises the Tx-room-avail-Interrupt. 2792ac4ad2aSVineet Gupta * The first thing Tx ISR does is disable further Tx interrupts (as this could 2802ac4ad2aSVineet Gupta * be the last char to send, before settling down into the quiet polled mode). 2812ac4ad2aSVineet Gupta * It then calls the exact routine used by tty layer write to send out any 2822ac4ad2aSVineet Gupta * more char in tty buffer. In case of sending, it re-enables Tx-intr. In case 2832ac4ad2aSVineet Gupta * of no data, it remains disabled. 2842ac4ad2aSVineet Gupta * This is how the transmit state machine is dynamically switched on/off 2852ac4ad2aSVineet Gupta */ 2862ac4ad2aSVineet Gupta 2872ac4ad2aSVineet Gupta static irqreturn_t arc_serial_isr(int irq, void *dev_id) 2882ac4ad2aSVineet Gupta { 2892ac4ad2aSVineet Gupta struct arc_uart_port *uart = dev_id; 2902ac4ad2aSVineet Gupta unsigned int status; 2912ac4ad2aSVineet Gupta 2922ac4ad2aSVineet Gupta status = UART_GET_STATUS(uart); 2932ac4ad2aSVineet Gupta 2942ac4ad2aSVineet Gupta /* 2952ac4ad2aSVineet Gupta * Single IRQ for both Rx (data available) Tx (room available) Interrupt 2962ac4ad2aSVineet Gupta * notifications from the UART Controller. 2972ac4ad2aSVineet Gupta * To demultiplex between the two, we check the relevant bits 2982ac4ad2aSVineet Gupta */ 2992ac4ad2aSVineet Gupta if ((status & RXIENB) && !(status & RXEMPTY)) { 3002ac4ad2aSVineet Gupta 3012ac4ad2aSVineet Gupta /* already in ISR, no need of xx_irqsave */ 3022ac4ad2aSVineet Gupta spin_lock(&uart->port.lock); 3032ac4ad2aSVineet Gupta arc_serial_rx_chars(uart); 3042ac4ad2aSVineet Gupta spin_unlock(&uart->port.lock); 3052ac4ad2aSVineet Gupta } 3062ac4ad2aSVineet Gupta 3072ac4ad2aSVineet Gupta if ((status & TXIENB) && (status & TXEMPTY)) { 3082ac4ad2aSVineet Gupta 3092ac4ad2aSVineet Gupta /* Unconditionally disable further Tx-Interrupts. 3102ac4ad2aSVineet Gupta * will be enabled by tx_chars() if needed. 3112ac4ad2aSVineet Gupta */ 3122ac4ad2aSVineet Gupta UART_TX_IRQ_DISABLE(uart); 3132ac4ad2aSVineet Gupta 3142ac4ad2aSVineet Gupta spin_lock(&uart->port.lock); 3152ac4ad2aSVineet Gupta 3162ac4ad2aSVineet Gupta if (!uart_tx_stopped(&uart->port)) 3172ac4ad2aSVineet Gupta arc_serial_tx_chars(uart); 3182ac4ad2aSVineet Gupta 3192ac4ad2aSVineet Gupta spin_unlock(&uart->port.lock); 3202ac4ad2aSVineet Gupta } 3212ac4ad2aSVineet Gupta 3222ac4ad2aSVineet Gupta return IRQ_HANDLED; 3232ac4ad2aSVineet Gupta } 3242ac4ad2aSVineet Gupta 3252ac4ad2aSVineet Gupta static unsigned int arc_serial_get_mctrl(struct uart_port *port) 3262ac4ad2aSVineet Gupta { 3272ac4ad2aSVineet Gupta /* 3282ac4ad2aSVineet Gupta * Pretend we have a Modem status reg and following bits are 3292ac4ad2aSVineet Gupta * always set, to satify the serial core state machine 3302ac4ad2aSVineet Gupta * (DSR) Data Set Ready 3312ac4ad2aSVineet Gupta * (CTS) Clear To Send 3322ac4ad2aSVineet Gupta * (CAR) Carrier Detect 3332ac4ad2aSVineet Gupta */ 3342ac4ad2aSVineet Gupta return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; 3352ac4ad2aSVineet Gupta } 3362ac4ad2aSVineet Gupta 3372ac4ad2aSVineet Gupta static void arc_serial_set_mctrl(struct uart_port *port, unsigned int mctrl) 3382ac4ad2aSVineet Gupta { 3392ac4ad2aSVineet Gupta /* MCR not present */ 3402ac4ad2aSVineet Gupta } 3412ac4ad2aSVineet Gupta 3422ac4ad2aSVineet Gupta /* Enable Modem Status Interrupts */ 3432ac4ad2aSVineet Gupta 3442ac4ad2aSVineet Gupta static void arc_serial_enable_ms(struct uart_port *port) 3452ac4ad2aSVineet Gupta { 3462ac4ad2aSVineet Gupta /* MSR not present */ 3472ac4ad2aSVineet Gupta } 3482ac4ad2aSVineet Gupta 3492ac4ad2aSVineet Gupta static void arc_serial_break_ctl(struct uart_port *port, int break_state) 3502ac4ad2aSVineet Gupta { 3512ac4ad2aSVineet Gupta /* ARC UART doesn't support sending Break signal */ 3522ac4ad2aSVineet Gupta } 3532ac4ad2aSVineet Gupta 3542ac4ad2aSVineet Gupta static int arc_serial_startup(struct uart_port *port) 3552ac4ad2aSVineet Gupta { 3562ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 3572ac4ad2aSVineet Gupta 3582ac4ad2aSVineet Gupta /* Before we hook up the ISR, Disable all UART Interrupts */ 3592ac4ad2aSVineet Gupta UART_ALL_IRQ_DISABLE(uart); 3602ac4ad2aSVineet Gupta 3612ac4ad2aSVineet Gupta if (request_irq(uart->port.irq, arc_serial_isr, 0, "arc uart rx-tx", 3622ac4ad2aSVineet Gupta uart)) { 3632ac4ad2aSVineet Gupta dev_warn(uart->port.dev, "Unable to attach ARC UART intr\n"); 3642ac4ad2aSVineet Gupta return -EBUSY; 3652ac4ad2aSVineet Gupta } 3662ac4ad2aSVineet Gupta 3672ac4ad2aSVineet Gupta UART_RX_IRQ_ENABLE(uart); /* Only Rx IRQ enabled to begin with */ 3682ac4ad2aSVineet Gupta 3692ac4ad2aSVineet Gupta return 0; 3702ac4ad2aSVineet Gupta } 3712ac4ad2aSVineet Gupta 3722ac4ad2aSVineet Gupta /* This is not really needed */ 3732ac4ad2aSVineet Gupta static void arc_serial_shutdown(struct uart_port *port) 3742ac4ad2aSVineet Gupta { 3752ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 3762ac4ad2aSVineet Gupta free_irq(uart->port.irq, uart); 3772ac4ad2aSVineet Gupta } 3782ac4ad2aSVineet Gupta 3792ac4ad2aSVineet Gupta static void 3802ac4ad2aSVineet Gupta arc_serial_set_termios(struct uart_port *port, struct ktermios *new, 3812ac4ad2aSVineet Gupta struct ktermios *old) 3822ac4ad2aSVineet Gupta { 3832ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 3842ac4ad2aSVineet Gupta unsigned int baud, uartl, uarth, hw_val; 3852ac4ad2aSVineet Gupta unsigned long flags; 3862ac4ad2aSVineet Gupta 3872ac4ad2aSVineet Gupta /* 3882ac4ad2aSVineet Gupta * Use the generic handler so that any specially encoded baud rates 3892ac4ad2aSVineet Gupta * such as SPD_xx flags or "%B0" can be handled 3902ac4ad2aSVineet Gupta * Max Baud I suppose will not be more than current 115K * 4 3912ac4ad2aSVineet Gupta * Formula for ARC UART is: hw-val = ((CLK/(BAUD*4)) -1) 3922ac4ad2aSVineet Gupta * spread over two 8-bit registers 3932ac4ad2aSVineet Gupta */ 3942ac4ad2aSVineet Gupta baud = uart_get_baud_rate(port, new, old, 0, 460800); 3952ac4ad2aSVineet Gupta 3962ac4ad2aSVineet Gupta hw_val = port->uartclk / (uart->baud * 4) - 1; 3972ac4ad2aSVineet Gupta uartl = hw_val & 0xFF; 3982ac4ad2aSVineet Gupta uarth = (hw_val >> 8) & 0xFF; 3992ac4ad2aSVineet Gupta 4002ac4ad2aSVineet Gupta /* 4012ac4ad2aSVineet Gupta * UART ISS(Instruction Set simulator) emulation has a subtle bug: 4022ac4ad2aSVineet Gupta * A existing value of Baudh = 0 is used as a indication to startup 4032ac4ad2aSVineet Gupta * it's internal state machine. 4042ac4ad2aSVineet Gupta * Thus if baudh is set to 0, 2 times, it chokes. 4052ac4ad2aSVineet Gupta * This happens with BAUD=115200 and the formaula above 4062ac4ad2aSVineet Gupta * Until that is fixed, when running on ISS, we will set baudh to !0 4072ac4ad2aSVineet Gupta */ 4082ac4ad2aSVineet Gupta if (uart->is_emulated) 4092ac4ad2aSVineet Gupta uarth = 1; 4102ac4ad2aSVineet Gupta 4112ac4ad2aSVineet Gupta spin_lock_irqsave(&port->lock, flags); 4122ac4ad2aSVineet Gupta 4132ac4ad2aSVineet Gupta UART_ALL_IRQ_DISABLE(uart); 4142ac4ad2aSVineet Gupta 4152ac4ad2aSVineet Gupta UART_SET_BAUDL(uart, uartl); 4162ac4ad2aSVineet Gupta UART_SET_BAUDH(uart, uarth); 4172ac4ad2aSVineet Gupta 4182ac4ad2aSVineet Gupta UART_RX_IRQ_ENABLE(uart); 4192ac4ad2aSVineet Gupta 4202ac4ad2aSVineet Gupta /* 4212ac4ad2aSVineet Gupta * UART doesn't support Parity/Hardware Flow Control; 4222ac4ad2aSVineet Gupta * Only supports 8N1 character size 4232ac4ad2aSVineet Gupta */ 4242ac4ad2aSVineet Gupta new->c_cflag &= ~(CMSPAR|CRTSCTS|CSIZE); 4252ac4ad2aSVineet Gupta new->c_cflag |= CS8; 4262ac4ad2aSVineet Gupta 4272ac4ad2aSVineet Gupta if (old) 4282ac4ad2aSVineet Gupta tty_termios_copy_hw(new, old); 4292ac4ad2aSVineet Gupta 4302ac4ad2aSVineet Gupta /* Don't rewrite B0 */ 4312ac4ad2aSVineet Gupta if (tty_termios_baud_rate(new)) 4322ac4ad2aSVineet Gupta tty_termios_encode_baud_rate(new, baud, baud); 4332ac4ad2aSVineet Gupta 4342ac4ad2aSVineet Gupta uart_update_timeout(port, new->c_cflag, baud); 4352ac4ad2aSVineet Gupta 4362ac4ad2aSVineet Gupta spin_unlock_irqrestore(&port->lock, flags); 4372ac4ad2aSVineet Gupta } 4382ac4ad2aSVineet Gupta 4392ac4ad2aSVineet Gupta static const char *arc_serial_type(struct uart_port *port) 4402ac4ad2aSVineet Gupta { 4412ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 4422ac4ad2aSVineet Gupta 4432ac4ad2aSVineet Gupta return uart->port.type == PORT_ARC ? DRIVER_NAME : NULL; 4442ac4ad2aSVineet Gupta } 4452ac4ad2aSVineet Gupta 4462ac4ad2aSVineet Gupta static void arc_serial_release_port(struct uart_port *port) 4472ac4ad2aSVineet Gupta { 4482ac4ad2aSVineet Gupta } 4492ac4ad2aSVineet Gupta 4502ac4ad2aSVineet Gupta static int arc_serial_request_port(struct uart_port *port) 4512ac4ad2aSVineet Gupta { 4522ac4ad2aSVineet Gupta return 0; 4532ac4ad2aSVineet Gupta } 4542ac4ad2aSVineet Gupta 4552ac4ad2aSVineet Gupta /* 4562ac4ad2aSVineet Gupta * Verify the new serial_struct (for TIOCSSERIAL). 4572ac4ad2aSVineet Gupta */ 4582ac4ad2aSVineet Gupta static int 4592ac4ad2aSVineet Gupta arc_serial_verify_port(struct uart_port *port, struct serial_struct *ser) 4602ac4ad2aSVineet Gupta { 4612ac4ad2aSVineet Gupta if (port->type != PORT_UNKNOWN && ser->type != PORT_ARC) 4622ac4ad2aSVineet Gupta return -EINVAL; 4632ac4ad2aSVineet Gupta 4642ac4ad2aSVineet Gupta return 0; 4652ac4ad2aSVineet Gupta } 4662ac4ad2aSVineet Gupta 4672ac4ad2aSVineet Gupta /* 4682ac4ad2aSVineet Gupta * Configure/autoconfigure the port. 4692ac4ad2aSVineet Gupta */ 4702ac4ad2aSVineet Gupta static void arc_serial_config_port(struct uart_port *port, int flags) 4712ac4ad2aSVineet Gupta { 4722ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 4732ac4ad2aSVineet Gupta 4742ac4ad2aSVineet Gupta if (flags & UART_CONFIG_TYPE) 4752ac4ad2aSVineet Gupta uart->port.type = PORT_ARC; 4762ac4ad2aSVineet Gupta } 4772ac4ad2aSVineet Gupta 4782ac4ad2aSVineet Gupta #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_ARC_CONSOLE) 4792ac4ad2aSVineet Gupta 4802ac4ad2aSVineet Gupta static void arc_serial_poll_putchar(struct uart_port *port, unsigned char chr) 4812ac4ad2aSVineet Gupta { 4822ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 4832ac4ad2aSVineet Gupta 4842ac4ad2aSVineet Gupta while (!(UART_GET_STATUS(uart) & TXEMPTY)) 4852ac4ad2aSVineet Gupta cpu_relax(); 4862ac4ad2aSVineet Gupta 4872ac4ad2aSVineet Gupta UART_SET_DATA(uart, chr); 4882ac4ad2aSVineet Gupta } 4892ac4ad2aSVineet Gupta #endif 4902ac4ad2aSVineet Gupta 4912ac4ad2aSVineet Gupta #ifdef CONFIG_CONSOLE_POLL 4922ac4ad2aSVineet Gupta static int arc_serial_poll_getchar(struct uart_port *port) 4932ac4ad2aSVineet Gupta { 4942ac4ad2aSVineet Gupta struct arc_uart_port *uart = to_arc_port(port); 4952ac4ad2aSVineet Gupta unsigned char chr; 4962ac4ad2aSVineet Gupta 4972ac4ad2aSVineet Gupta while (!(UART_GET_STATUS(uart) & RXEMPTY)) 4982ac4ad2aSVineet Gupta cpu_relax(); 4992ac4ad2aSVineet Gupta 5002ac4ad2aSVineet Gupta chr = UART_GET_DATA(uart); 5012ac4ad2aSVineet Gupta return chr; 5022ac4ad2aSVineet Gupta } 5032ac4ad2aSVineet Gupta #endif 5042ac4ad2aSVineet Gupta 5052ac4ad2aSVineet Gupta static struct uart_ops arc_serial_pops = { 5062ac4ad2aSVineet Gupta .tx_empty = arc_serial_tx_empty, 5072ac4ad2aSVineet Gupta .set_mctrl = arc_serial_set_mctrl, 5082ac4ad2aSVineet Gupta .get_mctrl = arc_serial_get_mctrl, 5092ac4ad2aSVineet Gupta .stop_tx = arc_serial_stop_tx, 5102ac4ad2aSVineet Gupta .start_tx = arc_serial_start_tx, 5112ac4ad2aSVineet Gupta .stop_rx = arc_serial_stop_rx, 5122ac4ad2aSVineet Gupta .enable_ms = arc_serial_enable_ms, 5132ac4ad2aSVineet Gupta .break_ctl = arc_serial_break_ctl, 5142ac4ad2aSVineet Gupta .startup = arc_serial_startup, 5152ac4ad2aSVineet Gupta .shutdown = arc_serial_shutdown, 5162ac4ad2aSVineet Gupta .set_termios = arc_serial_set_termios, 5172ac4ad2aSVineet Gupta .type = arc_serial_type, 5182ac4ad2aSVineet Gupta .release_port = arc_serial_release_port, 5192ac4ad2aSVineet Gupta .request_port = arc_serial_request_port, 5202ac4ad2aSVineet Gupta .config_port = arc_serial_config_port, 5212ac4ad2aSVineet Gupta .verify_port = arc_serial_verify_port, 5222ac4ad2aSVineet Gupta #ifdef CONFIG_CONSOLE_POLL 5232ac4ad2aSVineet Gupta .poll_put_char = arc_serial_poll_putchar, 5242ac4ad2aSVineet Gupta .poll_get_char = arc_serial_poll_getchar, 5252ac4ad2aSVineet Gupta #endif 5262ac4ad2aSVineet Gupta }; 5272ac4ad2aSVineet Gupta 528*9671f099SBill Pemberton static int 5292ac4ad2aSVineet Gupta arc_uart_init_one(struct platform_device *pdev, struct arc_uart_port *uart) 5302ac4ad2aSVineet Gupta { 5312ac4ad2aSVineet Gupta struct resource *res, *res2; 5322ac4ad2aSVineet Gupta unsigned long *plat_data; 5332ac4ad2aSVineet Gupta 5342ac4ad2aSVineet Gupta if (pdev->id < 0 || pdev->id >= CONFIG_SERIAL_ARC_NR_PORTS) { 5352ac4ad2aSVineet Gupta dev_err(&pdev->dev, "Wrong uart platform device id.\n"); 5362ac4ad2aSVineet Gupta return -ENOENT; 5372ac4ad2aSVineet Gupta } 5382ac4ad2aSVineet Gupta 5392ac4ad2aSVineet Gupta plat_data = ((unsigned long *)(pdev->dev.platform_data)); 5402ac4ad2aSVineet Gupta uart->baud = plat_data[0]; 5412ac4ad2aSVineet Gupta 5422ac4ad2aSVineet Gupta res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 5432ac4ad2aSVineet Gupta if (!res) 5442ac4ad2aSVineet Gupta return -ENODEV; 5452ac4ad2aSVineet Gupta 5462ac4ad2aSVineet Gupta res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 5472ac4ad2aSVineet Gupta if (!res2) 5482ac4ad2aSVineet Gupta return -ENODEV; 5492ac4ad2aSVineet Gupta 5502ac4ad2aSVineet Gupta uart->port.mapbase = res->start; 5512ac4ad2aSVineet Gupta uart->port.membase = ioremap_nocache(res->start, resource_size(res)); 5522ac4ad2aSVineet Gupta if (!uart->port.membase) 5532ac4ad2aSVineet Gupta /* No point of dev_err since UART itself is hosed here */ 5542ac4ad2aSVineet Gupta return -ENXIO; 5552ac4ad2aSVineet Gupta 5562ac4ad2aSVineet Gupta uart->port.irq = res2->start; 5572ac4ad2aSVineet Gupta uart->port.dev = &pdev->dev; 5582ac4ad2aSVineet Gupta uart->port.iotype = UPIO_MEM; 5592ac4ad2aSVineet Gupta uart->port.flags = UPF_BOOT_AUTOCONF; 5602ac4ad2aSVineet Gupta uart->port.line = pdev->id; 5612ac4ad2aSVineet Gupta uart->port.ops = &arc_serial_pops; 5622ac4ad2aSVineet Gupta 5632ac4ad2aSVineet Gupta uart->port.uartclk = plat_data[1]; 5642ac4ad2aSVineet Gupta uart->port.fifosize = ARC_UART_TX_FIFO_SIZE; 5652ac4ad2aSVineet Gupta 5662ac4ad2aSVineet Gupta /* 5672ac4ad2aSVineet Gupta * uart_insert_char( ) uses it in decideding whether to ignore a 5682ac4ad2aSVineet Gupta * char or not. Explicitly setting it here, removes the subtelty 5692ac4ad2aSVineet Gupta */ 5702ac4ad2aSVineet Gupta uart->port.ignore_status_mask = 0; 5712ac4ad2aSVineet Gupta 5722ac4ad2aSVineet Gupta /* Real Hardware vs. emulated to work around a bug */ 5732ac4ad2aSVineet Gupta uart->is_emulated = !!plat_data[2]; 5742ac4ad2aSVineet Gupta 5752ac4ad2aSVineet Gupta return 0; 5762ac4ad2aSVineet Gupta } 5772ac4ad2aSVineet Gupta 5782ac4ad2aSVineet Gupta #ifdef CONFIG_SERIAL_ARC_CONSOLE 5792ac4ad2aSVineet Gupta 580*9671f099SBill Pemberton static int arc_serial_console_setup(struct console *co, char *options) 5812ac4ad2aSVineet Gupta { 5822ac4ad2aSVineet Gupta struct uart_port *port; 5832ac4ad2aSVineet Gupta int baud = 115200; 5842ac4ad2aSVineet Gupta int bits = 8; 5852ac4ad2aSVineet Gupta int parity = 'n'; 5862ac4ad2aSVineet Gupta int flow = 'n'; 5872ac4ad2aSVineet Gupta 5882ac4ad2aSVineet Gupta if (co->index < 0 || co->index >= CONFIG_SERIAL_ARC_NR_PORTS) 5892ac4ad2aSVineet Gupta return -ENODEV; 5902ac4ad2aSVineet Gupta 5912ac4ad2aSVineet Gupta /* 5922ac4ad2aSVineet Gupta * The uart port backing the console (e.g. ttyARC1) might not have been 5932ac4ad2aSVineet Gupta * init yet. If so, defer the console setup to after the port. 5942ac4ad2aSVineet Gupta */ 5952ac4ad2aSVineet Gupta port = &arc_uart_ports[co->index].port; 5962ac4ad2aSVineet Gupta if (!port->membase) 5972ac4ad2aSVineet Gupta return -ENODEV; 5982ac4ad2aSVineet Gupta 5992ac4ad2aSVineet Gupta if (options) 6002ac4ad2aSVineet Gupta uart_parse_options(options, &baud, &parity, &bits, &flow); 6012ac4ad2aSVineet Gupta 6022ac4ad2aSVineet Gupta /* 6032ac4ad2aSVineet Gupta * Serial core will call port->ops->set_termios( ) 6042ac4ad2aSVineet Gupta * which will set the baud reg 6052ac4ad2aSVineet Gupta */ 6062ac4ad2aSVineet Gupta return uart_set_options(port, co, baud, parity, bits, flow); 6072ac4ad2aSVineet Gupta } 6082ac4ad2aSVineet Gupta 6092ac4ad2aSVineet Gupta static void arc_serial_console_putchar(struct uart_port *port, int ch) 6102ac4ad2aSVineet Gupta { 6112ac4ad2aSVineet Gupta arc_serial_poll_putchar(port, (unsigned char)ch); 6122ac4ad2aSVineet Gupta } 6132ac4ad2aSVineet Gupta 6142ac4ad2aSVineet Gupta /* 6152ac4ad2aSVineet Gupta * Interrupts are disabled on entering 6162ac4ad2aSVineet Gupta */ 6172ac4ad2aSVineet Gupta static void arc_serial_console_write(struct console *co, const char *s, 6182ac4ad2aSVineet Gupta unsigned int count) 6192ac4ad2aSVineet Gupta { 6202ac4ad2aSVineet Gupta struct uart_port *port = &arc_uart_ports[co->index].port; 6212ac4ad2aSVineet Gupta unsigned long flags; 6222ac4ad2aSVineet Gupta 6232ac4ad2aSVineet Gupta spin_lock_irqsave(&port->lock, flags); 6242ac4ad2aSVineet Gupta uart_console_write(port, s, count, arc_serial_console_putchar); 6252ac4ad2aSVineet Gupta spin_unlock_irqrestore(&port->lock, flags); 6262ac4ad2aSVineet Gupta } 6272ac4ad2aSVineet Gupta 6282ac4ad2aSVineet Gupta static struct console arc_console = { 6292ac4ad2aSVineet Gupta .name = ARC_SERIAL_DEV_NAME, 6302ac4ad2aSVineet Gupta .write = arc_serial_console_write, 6312ac4ad2aSVineet Gupta .device = uart_console_device, 6322ac4ad2aSVineet Gupta .setup = arc_serial_console_setup, 6332ac4ad2aSVineet Gupta .flags = CON_PRINTBUFFER, 6342ac4ad2aSVineet Gupta .index = -1, 6352ac4ad2aSVineet Gupta .data = &arc_uart_driver 6362ac4ad2aSVineet Gupta }; 6372ac4ad2aSVineet Gupta 6382ac4ad2aSVineet Gupta static __init void early_serial_write(struct console *con, const char *s, 6392ac4ad2aSVineet Gupta unsigned int n) 6402ac4ad2aSVineet Gupta { 6412ac4ad2aSVineet Gupta struct uart_port *port = &arc_uart_ports[con->index].port; 6422ac4ad2aSVineet Gupta unsigned int i; 6432ac4ad2aSVineet Gupta 6442ac4ad2aSVineet Gupta for (i = 0; i < n; i++, s++) { 6452ac4ad2aSVineet Gupta if (*s == '\n') 6462ac4ad2aSVineet Gupta arc_serial_poll_putchar(port, '\r'); 6472ac4ad2aSVineet Gupta arc_serial_poll_putchar(port, *s); 6482ac4ad2aSVineet Gupta } 6492ac4ad2aSVineet Gupta } 6502ac4ad2aSVineet Gupta 6512ac4ad2aSVineet Gupta static struct __initdata console arc_early_serial_console = { 6522ac4ad2aSVineet Gupta .name = "early_ARCuart", 6532ac4ad2aSVineet Gupta .write = early_serial_write, 6542ac4ad2aSVineet Gupta .flags = CON_PRINTBUFFER | CON_BOOT, 6552ac4ad2aSVineet Gupta .index = -1 6562ac4ad2aSVineet Gupta }; 6572ac4ad2aSVineet Gupta 658*9671f099SBill Pemberton static int arc_serial_probe_earlyprintk(struct platform_device *pdev) 6592ac4ad2aSVineet Gupta { 6602ac4ad2aSVineet Gupta arc_early_serial_console.index = pdev->id; 6612ac4ad2aSVineet Gupta 6622ac4ad2aSVineet Gupta arc_uart_init_one(pdev, &arc_uart_ports[pdev->id]); 6632ac4ad2aSVineet Gupta 6642ac4ad2aSVineet Gupta arc_serial_console_setup(&arc_early_serial_console, NULL); 6652ac4ad2aSVineet Gupta 6662ac4ad2aSVineet Gupta register_console(&arc_early_serial_console); 6672ac4ad2aSVineet Gupta return 0; 6682ac4ad2aSVineet Gupta } 6692ac4ad2aSVineet Gupta #else 670*9671f099SBill Pemberton static int arc_serial_probe_earlyprintk(struct platform_device *pdev) 6712ac4ad2aSVineet Gupta { 6722ac4ad2aSVineet Gupta return -ENODEV; 6732ac4ad2aSVineet Gupta } 6742ac4ad2aSVineet Gupta #endif /* CONFIG_SERIAL_ARC_CONSOLE */ 6752ac4ad2aSVineet Gupta 676*9671f099SBill Pemberton static int arc_serial_probe(struct platform_device *pdev) 6772ac4ad2aSVineet Gupta { 6782ac4ad2aSVineet Gupta struct arc_uart_port *uart; 6792ac4ad2aSVineet Gupta int rc; 6802ac4ad2aSVineet Gupta 6812ac4ad2aSVineet Gupta if (is_early_platform_device(pdev)) 6822ac4ad2aSVineet Gupta return arc_serial_probe_earlyprintk(pdev); 6832ac4ad2aSVineet Gupta 6842ac4ad2aSVineet Gupta uart = &arc_uart_ports[pdev->id]; 6852ac4ad2aSVineet Gupta rc = arc_uart_init_one(pdev, uart); 6862ac4ad2aSVineet Gupta if (rc) 6872ac4ad2aSVineet Gupta return rc; 6882ac4ad2aSVineet Gupta 6892ac4ad2aSVineet Gupta return uart_add_one_port(&arc_uart_driver, &uart->port); 6902ac4ad2aSVineet Gupta } 6912ac4ad2aSVineet Gupta 6922ac4ad2aSVineet Gupta static int __devexit arc_serial_remove(struct platform_device *pdev) 6932ac4ad2aSVineet Gupta { 6942ac4ad2aSVineet Gupta /* This will never be called */ 6952ac4ad2aSVineet Gupta return 0; 6962ac4ad2aSVineet Gupta } 6972ac4ad2aSVineet Gupta 6982ac4ad2aSVineet Gupta static struct platform_driver arc_platform_driver = { 6992ac4ad2aSVineet Gupta .probe = arc_serial_probe, 7002d47b716SBill Pemberton .remove = arc_serial_remove, 7012ac4ad2aSVineet Gupta .driver = { 7022ac4ad2aSVineet Gupta .name = DRIVER_NAME, 7032ac4ad2aSVineet Gupta .owner = THIS_MODULE, 7042ac4ad2aSVineet Gupta }, 7052ac4ad2aSVineet Gupta }; 7062ac4ad2aSVineet Gupta 7072ac4ad2aSVineet Gupta #ifdef CONFIG_SERIAL_ARC_CONSOLE 7082ac4ad2aSVineet Gupta /* 7092ac4ad2aSVineet Gupta * Register an early platform driver of "earlyprintk" class. 7102ac4ad2aSVineet Gupta * ARCH platform code installs the driver and probes the early devices 7112ac4ad2aSVineet Gupta * The installation could rely on user specifying earlyprintk=xyx in cmd line 7122ac4ad2aSVineet Gupta * or it could be done independently, for all "earlyprintk" class drivers. 7132ac4ad2aSVineet Gupta * [see arch/arc/plat-arcfpga/platform.c] 7142ac4ad2aSVineet Gupta */ 7152ac4ad2aSVineet Gupta early_platform_init("earlyprintk", &arc_platform_driver); 7162ac4ad2aSVineet Gupta 7172ac4ad2aSVineet Gupta #endif /* CONFIG_SERIAL_ARC_CONSOLE */ 7182ac4ad2aSVineet Gupta 7192ac4ad2aSVineet Gupta static int __init arc_serial_init(void) 7202ac4ad2aSVineet Gupta { 7212ac4ad2aSVineet Gupta int ret; 7222ac4ad2aSVineet Gupta 7232ac4ad2aSVineet Gupta ret = uart_register_driver(&arc_uart_driver); 7242ac4ad2aSVineet Gupta if (ret) 7252ac4ad2aSVineet Gupta return ret; 7262ac4ad2aSVineet Gupta 7272ac4ad2aSVineet Gupta ret = platform_driver_register(&arc_platform_driver); 7282ac4ad2aSVineet Gupta if (ret) 7292ac4ad2aSVineet Gupta uart_unregister_driver(&arc_uart_driver); 7302ac4ad2aSVineet Gupta 7312ac4ad2aSVineet Gupta return ret; 7322ac4ad2aSVineet Gupta } 7332ac4ad2aSVineet Gupta 7342ac4ad2aSVineet Gupta static void __exit arc_serial_exit(void) 7352ac4ad2aSVineet Gupta { 7362ac4ad2aSVineet Gupta platform_driver_unregister(&arc_platform_driver); 7372ac4ad2aSVineet Gupta uart_unregister_driver(&arc_uart_driver); 7382ac4ad2aSVineet Gupta } 7392ac4ad2aSVineet Gupta 7402ac4ad2aSVineet Gupta module_init(arc_serial_init); 7412ac4ad2aSVineet Gupta module_exit(arc_serial_exit); 7422ac4ad2aSVineet Gupta 7432ac4ad2aSVineet Gupta MODULE_LICENSE("GPL"); 7442ac4ad2aSVineet Gupta MODULE_ALIAS("plat-arcfpga/uart"); 7452ac4ad2aSVineet Gupta MODULE_AUTHOR("Vineet Gupta"); 7462ac4ad2aSVineet Gupta MODULE_DESCRIPTION("ARC(Synopsys) On-Chip(fpga) serial driver"); 747