14 #if defined(CONFIG_SERIAL_SCCNXP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
18 #include <linux/module.h>
19 #include <linux/device.h>
21 #include <linux/serial_core.h>
22 #include <linux/serial.h>
24 #include <linux/tty.h>
29 #define SCCNXP_NAME "uart-sccnxp"
30 #define SCCNXP_MAJOR 204
31 #define SCCNXP_MINOR 205
33 #define SCCNXP_MR_REG (0x00)
34 # define MR0_BAUD_NORMAL (0 << 0)
35 # define MR0_BAUD_EXT1 (1 << 0)
36 # define MR0_BAUD_EXT2 (5 << 0)
37 # define MR0_FIFO (1 << 3)
38 # define MR0_TXLVL (1 << 4)
39 # define MR1_BITS_5 (0 << 0)
40 # define MR1_BITS_6 (1 << 0)
41 # define MR1_BITS_7 (2 << 0)
42 # define MR1_BITS_8 (3 << 0)
43 # define MR1_PAR_EVN (0 << 2)
44 # define MR1_PAR_ODD (1 << 2)
45 # define MR1_PAR_NO (4 << 2)
46 # define MR2_STOP1 (7 << 0)
47 # define MR2_STOP2 (0xf << 0)
48 #define SCCNXP_SR_REG (0x01)
49 #define SCCNXP_CSR_REG SCCNXP_SR_REG
50 # define SR_RXRDY (1 << 0)
51 # define SR_FULL (1 << 1)
52 # define SR_TXRDY (1 << 2)
53 # define SR_TXEMT (1 << 3)
54 # define SR_OVR (1 << 4)
55 # define SR_PE (1 << 5)
56 # define SR_FE (1 << 6)
57 # define SR_BRK (1 << 7)
58 #define SCCNXP_CR_REG (0x02)
59 # define CR_RX_ENABLE (1 << 0)
60 # define CR_RX_DISABLE (1 << 1)
61 # define CR_TX_ENABLE (1 << 2)
62 # define CR_TX_DISABLE (1 << 3)
63 # define CR_CMD_MRPTR1 (0x01 << 4)
64 # define CR_CMD_RX_RESET (0x02 << 4)
65 # define CR_CMD_TX_RESET (0x03 << 4)
66 # define CR_CMD_STATUS_RESET (0x04 << 4)
67 # define CR_CMD_BREAK_RESET (0x05 << 4)
68 # define CR_CMD_START_BREAK (0x06 << 4)
69 # define CR_CMD_STOP_BREAK (0x07 << 4)
70 # define CR_CMD_MRPTR0 (0x0b << 4)
71 #define SCCNXP_RHR_REG (0x03)
72 #define SCCNXP_THR_REG SCCNXP_RHR_REG
73 #define SCCNXP_IPCR_REG (0x04)
74 #define SCCNXP_ACR_REG SCCNXP_IPCR_REG
75 # define ACR_BAUD0 (0 << 7)
76 # define ACR_BAUD1 (1 << 7)
77 # define ACR_TIMER_MODE (6 << 4)
78 #define SCCNXP_ISR_REG (0x05)
79 #define SCCNXP_IMR_REG SCCNXP_ISR_REG
80 # define IMR_TXRDY (1 << 0)
81 # define IMR_RXRDY (1 << 1)
82 # define ISR_TXRDY(x) (1 << ((x * 4) + 0))
83 # define ISR_RXRDY(x) (1 << ((x * 4) + 1))
84 #define SCCNXP_IPR_REG (0x0d)
85 #define SCCNXP_OPCR_REG SCCNXP_IPR_REG
86 #define SCCNXP_SOP_REG (0x0e)
87 #define SCCNXP_ROP_REG (0x0f)
90 #define MCTRL_MASK(sig) (0xf << (sig))
91 #define MCTRL_IBIT(cfg, sig) ((((cfg) >> (sig)) & 0xf) - LINE_IP0)
92 #define MCTRL_OBIT(cfg, sig) ((((cfg) >> (sig)) & 0xf) - LINE_OP0)
118 #define SCCNXP_HAVE_IO 0x00000001
119 #define SCCNXP_HAVE_MR0 0x00000002
121 #ifdef CONFIG_SERIAL_SCCNXP_CONSOLE
132 return readb(base + (reg << shift));
135 static inline void sccnxp_raw_write(
void __iomem *base,
u8 reg,
u8 shift,
u8 v)
137 writeb(v, base + (reg << shift));
157 return sccnxp_read(port, (port->
line << 3) + reg);
160 static inline void sccnxp_port_write(
struct uart_port *port,
u8 reg,
u8 v)
162 sccnxp_write(port, (port->
line << 3) + reg, v);
165 static int sccnxp_update_best_err(
int a,
int b,
int *besterr)
169 if ((*besterr < 0) || (*besterr > err)) {
219 int div_std, tmp_baud, bestbaud =
baud, besterr = -1;
220 u8 i, acr = 0,
csr = 0, mr0 = 0;
223 for (i = 0; baud_std[
i].
baud && besterr; i++) {
228 if (!sccnxp_update_best_err(baud, tmp_baud, &besterr)) {
229 acr = baud_std[
i].
acr;
231 mr0 = baud_std[
i].
mr0;
247 if (baud != bestbaud)
248 dev_dbg(port->
dev,
"Baudrate desired: %i, calculated: %i\n",
254 static void sccnxp_enable_irq(
struct uart_port *port,
int mask)
258 s->
imr |= mask << (port->
line * 4);
262 static void sccnxp_disable_irq(
struct uart_port *port,
int mask)
266 s->
imr &= ~(mask << (port->
line * 4));
284 static void sccnxp_handle_rx(
struct uart_port *port)
287 unsigned int ch,
flag;
307 if (uart_handle_break(port))
309 }
else if (sr &
SR_PE)
323 else if (sr & SR_OVR)
341 static void sccnxp_handle_tx(
struct uart_port *port)
361 sccnxp_set_bit(port,
DIR_OP, 0);
394 dev_dbg(s->
port[0].dev,
"IRQ status: 0x%02x\n", isr);
396 for (i = 0; i < s->
uart.nr; i++) {
398 sccnxp_handle_rx(&s->
port[i]);
400 sccnxp_handle_tx(&s->
port[i]);
409 static void sccnxp_start_tx(
struct uart_port *port)
417 sccnxp_set_bit(port,
DIR_OP, 1);
424 static void sccnxp_stop_tx(
struct uart_port *port)
429 static void sccnxp_stop_rx(
struct uart_port *port)
438 static unsigned int sccnxp_tx_empty(
struct uart_port *port)
450 static void sccnxp_enable_ms(
struct uart_port *port)
455 static void sccnxp_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
470 static unsigned int sccnxp_get_mctrl(
struct uart_port *port)
513 static void sccnxp_break_ctl(
struct uart_port *port,
int break_state)
523 static void sccnxp_set_termios(
struct uart_port *port,
592 baud = sccnxp_set_baud(port, baud);
606 static int sccnxp_startup(
struct uart_port *port)
634 static void sccnxp_shutdown(
struct uart_port *port)
648 sccnxp_set_bit(port,
DIR_OP, 0);
653 static const char *sccnxp_type(
struct uart_port *port)
660 static void sccnxp_release_port(
struct uart_port *port)
665 static int sccnxp_request_port(
struct uart_port *port)
687 static const struct uart_ops sccnxp_ops = {
688 .tx_empty = sccnxp_tx_empty,
689 .set_mctrl = sccnxp_set_mctrl,
690 .get_mctrl = sccnxp_get_mctrl,
691 .stop_tx = sccnxp_stop_tx,
692 .start_tx = sccnxp_start_tx,
693 .stop_rx = sccnxp_stop_rx,
694 .enable_ms = sccnxp_enable_ms,
695 .break_ctl = sccnxp_break_ctl,
696 .startup = sccnxp_startup,
697 .shutdown = sccnxp_shutdown,
698 .set_termios = sccnxp_set_termios,
700 .release_port = sccnxp_release_port,
701 .request_port = sccnxp_request_port,
702 .config_port = sccnxp_config_port,
703 .verify_port = sccnxp_verify_port,
706 #ifdef CONFIG_SERIAL_SCCNXP_CONSOLE
707 static void sccnxp_console_putchar(
struct uart_port *port,
int c)
720 static void sccnxp_console_write(
struct console *co,
const char *c,
unsigned n)
730 static int sccnxp_console_setup(
struct console *co,
char *
options)
734 int baud = 9600,
bits = 8,
parity =
'n', flow =
'n';
748 int i,
ret, fifosize, freq_min, freq_max;
753 dev_err(&pdev->
dev,
"Missing memory resource data\n");
761 dev_err(&pdev->
dev,
"Error allocating port structure\n");
764 platform_set_drvdata(pdev, s);
851 dev_err(&pdev->
dev,
"Unsupported chip type %i\n", chiptype);
858 "No platform data supplied, using defaults\n");
865 dev_err(&pdev->
dev,
"Missing irq resource data\n");
871 if ((s->
pdata.frequency < freq_min) ||
872 (s->
pdata.frequency > freq_max)) {
873 dev_err(&pdev->
dev,
"Frequency out of bounds\n");
886 s->
uart.dev_name =
"ttySC";
889 #ifdef CONFIG_SERIAL_SCCNXP_CONSOLE
890 s->
uart.cons = &s->console;
892 s->
uart.cons->write = sccnxp_console_write;
893 s->
uart.cons->setup = sccnxp_console_setup;
895 s->
uart.cons->index = -1;
896 s->
uart.cons->data =
s;
901 dev_err(&pdev->
dev,
"Registering UART driver failed\n");
905 for (i = 0; i < s->
uart.nr; i++) {
910 s->
port[
i].fifosize = fifosize;
914 s->
port[
i].membase = membase;
917 s->
port[
i].ops = &sccnxp_ops;
934 dev_name(&pdev->
dev), s);
941 platform_set_drvdata(pdev,
NULL);
949 struct sccnxp_port *s = platform_get_drvdata(pdev);
953 for (i = 0; i < s->
uart.nr; i++)
957 platform_set_drvdata(pdev,
NULL);
983 .probe = sccnxp_probe,
985 .id_table = sccnxp_id_table,