23 #if defined(CONFIG_SERIAL_SA1100_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
27 #include <linux/module.h>
33 #include <linux/tty.h>
35 #include <linux/serial_core.h>
36 #include <linux/serial.h>
40 #include <mach/hardware.h>
41 #include <mach/irqs.h>
45 #define SERIAL_SA1100_MAJOR 204
50 #define SA1100_ISR_PASS_LIMIT 256
55 #define SM_TO_UTSR0(x) ((x) & 0xff)
56 #define SM_TO_UTSR1(x) ((x) >> 8)
57 #define UTSR0_TO_SM(x) ((x))
58 #define UTSR1_TO_SM(x) ((x) << 8)
60 #define UART_GET_UTCR0(sport) __raw_readl((sport)->port.membase + UTCR0)
61 #define UART_GET_UTCR1(sport) __raw_readl((sport)->port.membase + UTCR1)
62 #define UART_GET_UTCR2(sport) __raw_readl((sport)->port.membase + UTCR2)
63 #define UART_GET_UTCR3(sport) __raw_readl((sport)->port.membase + UTCR3)
64 #define UART_GET_UTSR0(sport) __raw_readl((sport)->port.membase + UTSR0)
65 #define UART_GET_UTSR1(sport) __raw_readl((sport)->port.membase + UTSR1)
66 #define UART_GET_CHAR(sport) __raw_readl((sport)->port.membase + UTDR)
68 #define UART_PUT_UTCR0(sport,v) __raw_writel((v),(sport)->port.membase + UTCR0)
69 #define UART_PUT_UTCR1(sport,v) __raw_writel((v),(sport)->port.membase + UTCR1)
70 #define UART_PUT_UTCR2(sport,v) __raw_writel((v),(sport)->port.membase + UTCR2)
71 #define UART_PUT_UTCR3(sport,v) __raw_writel((v),(sport)->port.membase + UTCR3)
72 #define UART_PUT_UTSR0(sport,v) __raw_writel((v),(sport)->port.membase + UTSR0)
73 #define UART_PUT_UTSR1(sport,v) __raw_writel((v),(sport)->port.membase + UTSR1)
74 #define UART_PUT_CHAR(sport,v) __raw_writel((v),(sport)->port.membase + UTDR)
79 #define UART_PORT_SIZE 0x24
87 #define MCTRL_TIMEOUT (250*HZ/1000)
98 static void sa1100_mctrl_check(
struct sa1100_port *sport)
102 status = sport->
port.ops->get_mctrl(&sport->
port);
111 sport->
port.icount.rng++;
113 sport->
port.icount.dsr++;
126 static void sa1100_timeout(
unsigned long data)
131 if (sport->
port.state) {
133 sa1100_mctrl_check(sport);
134 spin_unlock_irqrestore(&sport->
port.lock, flags);
192 unsigned int status, ch, flg;
199 sport->
port.icount.rx++;
209 sport->
port.icount.parity++;
211 sport->
port.icount.frame++;
213 sport->
port.icount.overrun++;
215 status &= sport->
port.read_status_mask;
223 sport->
port.sysrq = 0;
239 static void sa1100_tx_chars(
struct sa1100_port *sport)
243 if (sport->
port.x_char) {
245 sport->
port.icount.tx++;
246 sport->
port.x_char = 0;
254 sa1100_mctrl_check(sport);
257 sa1100_stop_tx(&sport->
port);
268 sport->
port.icount.tx++;
277 sa1100_stop_tx(&sport->
port);
283 unsigned int status, pass_counter = 0;
285 spin_lock(&sport->
port.lock);
293 sa1100_rx_chars(sport);
301 sport->
port.icount.brk++;
304 uart_handle_break(&sport->
port);
307 sa1100_tx_chars(sport);
314 spin_unlock(&sport->
port.lock);
334 static void sa1100_set_mctrl(
struct uart_port *
port,
unsigned int mctrl)
341 static void sa1100_break_ctl(
struct uart_port *
port,
int break_state)
349 if (break_state == -1)
354 spin_unlock_irqrestore(&sport->
port.lock, flags);
357 static int sa1100_startup(
struct uart_port *port)
366 "sa11x0-uart", sport);
379 spin_lock_irq(&sport->
port.lock);
380 sa1100_enable_ms(&sport->
port);
381 spin_unlock_irq(&sport->
port.lock);
386 static void sa1100_shutdown(
struct uart_port *port)
412 unsigned int utcr0, old_utcr3,
baud, quot;
449 sport->
port.read_status_mask |=
452 sport->
port.read_status_mask |=
458 sport->
port.ignore_status_mask = 0;
460 sport->
port.ignore_status_mask |=
463 sport->
port.ignore_status_mask |=
470 sport->
port.ignore_status_mask |=
506 sa1100_enable_ms(&sport->
port);
508 spin_unlock_irqrestore(&sport->
port.lock, flags);
511 static const char *sa1100_type(
struct uart_port *port)
521 static void sa1100_release_port(
struct uart_port *port)
531 static int sa1100_request_port(
struct uart_port *port)
542 static void sa1100_config_port(
struct uart_port *port,
int flags)
547 sa1100_request_port(&sport->
port) == 0)
564 if (sport->
port.irq != ser->
irq)
572 if (sport->
port.iobase != ser->
port)
579 static struct uart_ops sa1100_pops = {
580 .tx_empty = sa1100_tx_empty,
581 .set_mctrl = sa1100_set_mctrl,
582 .get_mctrl = sa1100_get_mctrl,
583 .stop_tx = sa1100_stop_tx,
584 .start_tx = sa1100_start_tx,
585 .stop_rx = sa1100_stop_rx,
586 .enable_ms = sa1100_enable_ms,
587 .break_ctl = sa1100_break_ctl,
588 .startup = sa1100_startup,
589 .shutdown = sa1100_shutdown,
590 .set_termios = sa1100_set_termios,
592 .release_port = sa1100_release_port,
593 .request_port = sa1100_request_port,
594 .config_port = sa1100_config_port,
595 .verify_port = sa1100_verify_port,
612 static void __init sa1100_init_ports(
void)
614 static int first = 1;
622 sa1100_ports[
i].port.uartclk = 3686400;
623 sa1100_ports[
i].port.ops = &sa1100_pops;
624 sa1100_ports[
i].port.fifosize = 8;
625 sa1100_ports[
i].port.line =
i;
628 sa1100_ports[
i].timer.function = sa1100_timeout;
629 sa1100_ports[
i].timer.data = (
unsigned long)&sa1100_ports[i];
647 sa1100_pops.
pm = fns->
pm;
686 #ifdef CONFIG_SERIAL_SA1100_CONSOLE
687 static void sa1100_console_putchar(
struct uart_port *port,
int ch)
700 sa1100_console_write(
struct console *co,
const char *
s,
unsigned int count)
703 unsigned int old_utcr3,
status;
720 }
while (status & UTSR1_TBY);
729 sa1100_console_get_options(
struct sa1100_port *sport,
int *baud,
730 int *parity,
int *
bits)
737 unsigned int utcr0, quot;
756 *baud = sport->
port.uartclk / (16 * (quot + 1));
776 sport = &sa1100_ports[co->
index];
781 sa1100_console_get_options(sport, &baud, &parity, &bits);
787 static struct console sa1100_console = {
789 .write = sa1100_console_write,
791 .setup = sa1100_console_setup,
797 static int __init sa1100_rs_console_init(
void)
805 #define SA1100_CONSOLE &sa1100_console
807 #define SA1100_CONSOLE NULL
812 .driver_name =
"ttySA",
822 struct sa1100_port *sport = platform_get_drvdata(dev);
832 struct sa1100_port *sport = platform_get_drvdata(dev);
854 sa1100_ports[
i].port.dev = &dev->
dev;
856 platform_set_drvdata(dev, &sa1100_ports[i]);
866 struct sa1100_port *sport = platform_get_drvdata(pdev);
868 platform_set_drvdata(pdev,
NULL);
877 .probe = sa1100_serial_probe,
878 .remove = sa1100_serial_remove,
879 .suspend = sa1100_serial_suspend,
880 .resume = sa1100_serial_resume,
882 .name =
"sa11x0-uart",
887 static int __init sa1100_serial_init(
void)
904 static void __exit sa1100_serial_exit(
void)