18 #if defined(CONFIG_SERIAL_MSM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
19 # define SUPPORT_SYSRQ
23 #include <linux/hrtimer.h>
24 #include <linux/module.h>
30 #include <linux/tty.h>
32 #include <linux/serial_core.h>
33 #include <linux/serial.h>
56 while ((msm_read(port,
UART_ISR) & bits) != bits)
92 static void handle_rx_dm(
struct uart_port *
port,
unsigned int misr)
129 if (uart_handle_break(port))
135 tty_insert_flip_string(tty, (
char *) &c,
136 (count > 4) ? 4 : count);
141 if (misr & (UART_IMR_RXSTALE))
147 static void handle_rx(
struct uart_port *port)
156 if ((msm_read(port,
UART_SR) & UART_SR_OVERRUN)) {
163 while ((sr = msm_read(port,
UART_SR)) & UART_SR_RX_READY) {
169 if (sr & UART_SR_RX_BREAK) {
171 if (uart_handle_break(port))
173 }
else if (sr & UART_SR_PAR_FRAME_ERR) {
182 if (sr & UART_SR_RX_BREAK) {
184 }
else if (sr & UART_SR_PAR_FRAME_ERR) {
189 tty_insert_flip_char(tty, c, flag);
195 static void reset_dm_count(
struct uart_port *port)
201 static void handle_tx(
struct uart_port *port)
209 reset_dm_count(port);
211 msm_write(port, port->
x_char,
218 reset_dm_count(port);
227 msm_write(port, xmit->
buf[xmit->
tail],
231 reset_dm_count(port);
242 static void handle_delta_cts(
struct uart_port *port)
255 spin_lock(&port->
lock);
261 handle_rx_dm(port, misr);
268 handle_delta_cts(port);
271 spin_unlock(&port->
lock);
276 static unsigned int msm_tx_empty(
struct uart_port *port)
281 static unsigned int msm_get_mctrl(
struct uart_port *port)
287 static void msm_reset(
struct uart_port *port)
313 static void msm_break_ctl(
struct uart_port *port,
int break_ctl)
321 static int msm_set_baud_rate(
struct uart_port *port,
unsigned int baud)
323 unsigned int baud_code, rxstale, watermark;
382 msm_write(port, baud_code,
UART_CSR);
388 msm_write(port, watermark,
UART_IPR);
391 watermark = (port->
fifosize * 3) / 4;
407 static void msm_init_clock(
struct uart_port *port)
412 if (!IS_ERR(msm_port->
pclk))
417 static int msm_startup(
struct uart_port *port)
420 unsigned int data, rfr_level;
424 "msm_serial%d", port->
line);
427 msm_port->
name, port);
431 msm_init_clock(port);
462 msm_write(port, data,
UART_CR);
482 static void msm_shutdown(
struct uart_port *port)
498 unsigned int baud, mr;
504 baud = msm_set_baud_rate(port, baud);
566 spin_unlock_irqrestore(&port->
lock, flags);
569 static const char *msm_type(
struct uart_port *port)
574 static void msm_release_port(
struct uart_port *port)
585 size = resource_size(uart_resource);
601 size = resource_size(gsbi_resource);
608 static int msm_request_port(
struct uart_port *port)
621 size = resource_size(uart_resource);
629 goto fail_release_port;
635 size = resource_size(gsbi_resource);
640 goto fail_release_port;
646 goto fail_release_gsbi;
659 static void msm_config_port(
struct uart_port *port,
int flags)
665 ret = msm_request_port(port);
685 unsigned int oldstate)
692 if (!IS_ERR(msm_port->
pclk))
697 if (!IS_ERR(msm_port->
pclk))
705 static struct uart_ops msm_uart_pops = {
706 .tx_empty = msm_tx_empty,
708 .get_mctrl = msm_get_mctrl,
709 .stop_tx = msm_stop_tx,
710 .start_tx = msm_start_tx,
711 .stop_rx = msm_stop_rx,
712 .enable_ms = msm_enable_ms,
713 .break_ctl = msm_break_ctl,
714 .startup = msm_startup,
715 .shutdown = msm_shutdown,
716 .set_termios = msm_set_termios,
718 .release_port = msm_release_port,
719 .request_port = msm_request_port,
720 .config_port = msm_config_port,
721 .verify_port = msm_verify_port,
725 static struct msm_port msm_uart_ports[] = {
729 .ops = &msm_uart_pops,
738 .ops = &msm_uart_pops,
747 .ops = &msm_uart_pops,
755 #define UART_NR ARRAY_SIZE(msm_uart_ports)
757 static inline struct uart_port *get_port_from_line(
unsigned int line)
762 #ifdef CONFIG_SERIAL_MSM_CONSOLE
764 static void msm_console_putchar(
struct uart_port *port,
int c)
769 reset_dm_count(port);
771 while (!(msm_read(port,
UART_SR) & UART_SR_TX_READY))
776 static void msm_console_write(
struct console *co,
const char *
s,
780 struct msm_port *msm_port;
784 port = get_port_from_line(co->
index);
787 spin_lock(&port->
lock);
789 spin_unlock(&port->
lock);
795 struct msm_port *msm_port;
801 port = get_port_from_line(co->
index);
807 msm_init_clock(port);
818 if (baud < 300 || baud > 115200)
820 msm_set_baud_rate(port, baud);
836 static struct console msm_console = {
838 .write = msm_console_write,
840 .setup = msm_console_setup,
843 .data = &msm_uart_driver,
846 #define MSM_CONSOLE (&msm_console)
849 #define MSM_CONSOLE NULL
854 .driver_name =
"msm_serial",
855 .dev_name =
"ttyMSM",
864 struct msm_port *msm_port;
877 port = get_port_from_line(pdev->
id);
896 return PTR_ERR(msm_port->
clk);
915 platform_set_drvdata(pdev, port);
922 struct msm_port *msm_port = platform_get_drvdata(pdev);
930 { .compatible =
"qcom,msm-uart" },
935 .remove = msm_serial_remove,
937 .name =
"msm_serial",
939 .of_match_table = msm_match_table,
943 static int __init msm_serial_init(
void)
960 static void __exit msm_serial_exit(
void)
962 #ifdef CONFIG_SERIAL_MSM_CONSOLE