32 #include <linux/module.h>
33 #include <linux/tty.h>
37 #include <linux/serial.h>
40 #include <linux/device.h>
51 #include <asm/delay.h>
55 #if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
59 #include <linux/serial_core.h>
60 #include <linux/kernel.h>
74 #define HW_BUF_SPD_THRESHOLD 2400
96 pr_debug(
"CPM uart[%d]:tx_empty: %d\n", port->
line, ret);
101 static void cpm_uart_set_mctrl(
struct uart_port *
port,
unsigned int mctrl)
112 static unsigned int cpm_uart_get_mctrl(
struct uart_port *port)
143 static void cpm_uart_stop_tx(
struct uart_port *port)
152 clrbits8(&smcp->smc_smcm,
SMCM_TX);
160 static void cpm_uart_start_tx(
struct uart_port *port)
176 if (cpm_uart_tx_pump(port) != 0) {
178 setbits8(&smcp->smc_smcm,
SMCM_TX);
188 static void cpm_uart_stop_rx(
struct uart_port *port)
197 clrbits8(&smcp->smc_smcm,
SMCM_RX);
205 static void cpm_uart_enable_ms(
struct uart_port *port)
213 static void cpm_uart_break_ctl(
struct uart_port *port,
int break_state)
217 pr_debug(
"CPM uart[%d]:break ctrl, break_state: %d\n", port->
line,
229 static void cpm_uart_int_tx(
struct uart_port *port)
233 cpm_uart_tx_pump(port);
236 #ifdef CONFIG_CONSOLE_POLL
237 static int serial_polled;
243 static void cpm_uart_int_rx(
struct uart_port *port)
261 #ifdef CONFIG_CONSOLE_POLL
268 status =
in_be16(&bdp->cbd_sc);
285 cp = cpm2cpu_addr(
in_be32(&bdp->cbd_bufaddr), pinfo);
298 #ifdef CONFIG_CONSOLE_POLL
305 tty_insert_flip_char(tty, ch, flg);
312 setbits16(&bdp->cbd_sc, BD_SC_EMPTY);
346 if (status & BD_SC_BR)
348 else if (status & BD_SC_PR)
350 else if (status & BD_SC_FR)
354 if (status & BD_SC_OV) {
382 events =
in_8(&smcp->smc_smce);
383 out_8(&smcp->smc_smce, events);
385 uart_handle_break(port);
387 cpm_uart_int_rx(port);
389 cpm_uart_int_tx(port);
391 events =
in_be16(&sccp->scc_scce);
394 uart_handle_break(port);
396 cpm_uart_int_rx(port);
398 cpm_uart_int_tx(port);
403 static int cpm_uart_startup(
struct uart_port *port)
415 clrbits8(&pinfo->
smcp->smc_smcm, SMCM_RX);
418 clrbits16(&pinfo->
sccp->scc_sccm, UART_SCCM_RX);
420 cpm_uart_initbd(pinfo);
424 retval =
request_irq(port->
irq, cpm_uart_int, 0,
"cpm_uart", port);
430 setbits8(&pinfo->
smcp->smc_smcm, SMCM_RX);
433 setbits16(&pinfo->
sccp->scc_sccm, UART_SCCM_RX);
449 static void cpm_uart_shutdown(
struct uart_port *port)
461 while(!cpm_uart_tx_empty(port)) {
473 clrbits8(&smcp->smc_smcm, SMCM_RX |
SMCM_TX);
477 clrbits16(&sccp->scc_sccm,
UART_SCCM_TX | UART_SCCM_RX);
489 cpm_uart_initbd(pinfo);
493 static void cpm_uart_set_termios(
struct uart_port *port,
499 u16 cval, scval, prev_mode;
510 (pinfo->
port.state && pinfo->
port.state->port.tty->low_latency))
520 maxidl = baud / 2400;
579 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
640 out_be16(&sccp->scc_psmr, (sbits << 12) | scval);
646 cpm_set_brg(pinfo->
brg - 1, baud);
647 spin_unlock_irqrestore(&port->
lock, flags);
650 static const char *cpm_uart_type(
struct uart_port *port)
660 static int cpm_uart_verify_port(
struct uart_port *port,
679 static int cpm_uart_tx_pump(
struct uart_port *port)
692 p = cpm2cpu_addr(
in_be32(&bdp->cbd_bufaddr), pinfo);
711 cpm_uart_stop_tx(port);
721 p = cpm2cpu_addr(
in_be32(&bdp->cbd_bufaddr), pinfo);
722 while (count < pinfo->tx_fifosize) {
744 cpm_uart_stop_tx(port);
768 for (i = 0; i < (pinfo->
rx_nrfifos - 1); i++, bdp++) {
769 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo));
774 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo));
783 for (i = 0; i < (pinfo->
tx_nrfifos - 1); i++, bdp++) {
784 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo));
789 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo));
813 cpm_set_scc_fcr(sup);
874 #if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
903 out_8(&sp->smc_smcm, 0);
904 out_8(&sp->smc_smce, 0xff);
913 static int cpm_uart_request_port(
struct uart_port *port)
924 clrbits8(&pinfo->
smcp->smc_smcm, SMCM_RX |
SMCM_TX);
936 cpm_uart_initbd(pinfo);
938 cpm_uart_init_smc(pinfo);
940 cpm_uart_init_scc(pinfo);
945 static void cpm_uart_release_port(
struct uart_port *port)
956 static void cpm_uart_config_port(
struct uart_port *port,
int flags)
962 cpm_uart_request_port(port);
966 #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_CPM_CONSOLE)
971 static void cpm_uart_early_write(
struct uart_cpm_port *pinfo,
972 const char *
string,
u_int count)
976 unsigned char *cpm_outp_addr;
989 for (i = 0; i <
count; i++,
string++) {
1001 cpm_outp_addr = cpm2cpu_addr(
in_be32(&bdp->cbd_bufaddr),
1003 *cpm_outp_addr = *
string;
1014 if (*
string == 10) {
1018 cpm_outp_addr = cpm2cpu_addr(
in_be32(&bdp->cbd_bufaddr),
1020 *cpm_outp_addr = 13;
1043 #ifdef CONFIG_CONSOLE_POLL
1048 #define GDB_BUF_SIZE 512
1050 static char poll_buf[GDB_BUF_SIZE];
1052 static int poll_chars;
1054 static int poll_wait_key(
char *obuf,
struct uart_cpm_port *pinfo)
1057 volatile cbd_t *bdp;
1063 while (bdp->
cbd_sc & BD_SC_EMPTY)
1077 bdp->
cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV |
BD_SC_ID);
1089 static int cpm_get_poll_char(
struct uart_port *port)
1093 if (!serial_polled) {
1097 if (poll_chars <= 0) {
1098 poll_chars = poll_wait_key(poll_buf, pinfo);
1105 static void cpm_put_poll_char(
struct uart_port *port,
1112 cpm_uart_early_write(pinfo, ch, 1);
1116 static struct uart_ops cpm_uart_pops = {
1117 .tx_empty = cpm_uart_tx_empty,
1118 .set_mctrl = cpm_uart_set_mctrl,
1119 .get_mctrl = cpm_uart_get_mctrl,
1120 .stop_tx = cpm_uart_stop_tx,
1121 .start_tx = cpm_uart_start_tx,
1122 .stop_rx = cpm_uart_stop_rx,
1123 .enable_ms = cpm_uart_enable_ms,
1124 .break_ctl = cpm_uart_break_ctl,
1125 .startup = cpm_uart_startup,
1126 .shutdown = cpm_uart_shutdown,
1127 .set_termios = cpm_uart_set_termios,
1128 .type = cpm_uart_type,
1129 .release_port = cpm_uart_release_port,
1130 .request_port = cpm_uart_request_port,
1131 .config_port = cpm_uart_config_port,
1132 .verify_port = cpm_uart_verify_port,
1133 #ifdef CONFIG_CONSOLE_POLL
1134 .poll_get_char = cpm_get_poll_char,
1135 .poll_put_char = cpm_put_poll_char,
1141 static int cpm_uart_init_port(
struct device_node *np,
1158 if (!data || len != 4) {
1160 "fsl,cpm-brg property.\n", np->
name);
1167 if (!data || len != 4) {
1169 "fsl,cpm-command property.\n", np->
name);
1203 pinfo->
port.mapbase = (
unsigned long)mem;
1205 pinfo->
port.ops = &cpm_uart_pops,
1217 pinfo->
gpios[i] = of_get_gpio(np, i);
1219 #ifdef CONFIG_PPC_EARLY_DEBUG_CPM
1223 return cpm_uart_request_port(&pinfo->
port);
1232 #ifdef CONFIG_SERIAL_CPM_CONSOLE
1239 static void cpm_uart_console_write(
struct console *co,
const char *
s,
1243 unsigned long flags;
1252 cpm_uart_early_write(pinfo, s, count);
1257 spin_unlock_irqrestore(&pinfo->
port.lock, flags);
1291 }
while (i++ != co->
index);
1296 port = &pinfo->
port;
1298 ret = cpm_uart_init_port(np, pinfo);
1306 if ((baud = uart_baudrate()) == -1)
1313 clrbits8(&pinfo->
smcp->smc_smcm, SMCM_RX |
SMCM_TX);
1327 cpm_uart_initbd(pinfo);
1330 cpm_uart_init_smc(pinfo);
1332 cpm_uart_init_scc(pinfo);
1341 static struct console cpm_scc_uart_console = {
1343 .write = cpm_uart_console_write,
1345 .setup = cpm_uart_console_setup,
1351 static int __init cpm_uart_console_init(
void)
1359 #define CPM_UART_CONSOLE &cpm_scc_uart_console
1361 #define CPM_UART_CONSOLE NULL
1366 .driver_name =
"ttyCPM",
1367 .dev_name =
"ttyCPM",
1374 static int probe_index;
1378 int index = probe_index++;
1390 pinfo->
port.dev = &ofdev->
dev;
1392 ret = cpm_uart_init_port(ofdev->
dev.of_node, pinfo);
1407 .compatible =
"fsl,cpm1-smc-uart",
1410 .compatible =
"fsl,cpm1-scc-uart",
1413 .compatible =
"fsl,cpm2-smc-uart",
1416 .compatible =
"fsl,cpm2-scc-uart",
1425 .of_match_table = cpm_uart_match,
1427 .probe = cpm_uart_probe,
1428 .remove = cpm_uart_remove,
1431 static int __init cpm_uart_init(
void)
1444 static void __exit cpm_uart_exit(
void)