41 #undef USE_CTRL_O_SYSRQ
43 #include <linux/module.h>
44 #include <linux/tty.h>
48 #include <linux/string.h>
49 #include <linux/fcntl.h>
51 #include <linux/kernel.h>
55 #include <linux/adb.h>
56 #include <linux/pmu.h>
57 #include <linux/bitops.h>
60 #include <asm/sections.h>
64 #ifdef CONFIG_PPC_PMAC
66 #include <asm/machdep.h>
72 #define of_machine_is_compatible(x) (0)
75 #if defined (CONFIG_SERIAL_PMACZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
79 #include <linux/serial.h>
80 #include <linux/serial_core.h>
92 #ifdef CONFIG_SERIAL_PMACZILOG_TTYS
93 #define PMACZILOG_MAJOR TTY_MAJOR
94 #define PMACZILOG_MINOR 64
95 #define PMACZILOG_NAME "ttyS"
97 #define PMACZILOG_MAJOR 204
98 #define PMACZILOG_MINOR 192
99 #define PMACZILOG_NAME "ttyPZ"
102 #define pmz_debug(fmt, arg...) pr_debug("ttyPZ%d: " fmt, uap->port.line, ## arg)
103 #define pmz_error(fmt, arg...) pr_err("ttyPZ%d: " fmt, uap->port.line, ## arg)
104 #define pmz_info(fmt, arg...) pr_info("ttyPZ%d: " fmt, uap->port.line, ## arg)
111 static int pmz_ports_count;
132 for (i = 0; i < 1000; i++) {
133 unsigned char stat = read_zsreg(uap,
R1);
150 write_zsreg(uap,
R4, regs[
R4]);
153 write_zsreg(uap,
R10, regs[
R10]);
161 write_zsreg(uap,
R7, regs[
R7P]);
167 write_zsreg(uap,
R6, regs[
R6]);
168 write_zsreg(uap,
R7, regs[
R7]);
174 write_zsreg(uap,
R11, regs[
R11]);
177 write_zsreg(uap,
R12, regs[
R12]);
178 write_zsreg(uap,
R13, regs[
R13]);
181 write_zsreg(uap,
R14, regs[
R14]);
188 write_zsreg(uap,
R3, regs[
R3]);
189 write_zsreg(uap,
R5, regs[
R5]);
192 write_zsreg(uap,
R1, regs[
R1]);
195 write_zsreg(uap,
R9, regs[
R9]);
212 pmz_debug(
"pmz: maybe_update_regs: updating\n");
213 pmz_load_zsregs(uap, uap->
curregs);
239 (
void)read_zsdata(uap);
242 tty = uap->
port.state->port.tty;
248 r1 = read_zsreg(uap,
R1);
249 ch = read_zsdata(uap);
261 #if defined(CONFIG_MAGIC_SYSRQ) && defined(CONFIG_SERIAL_CORE_CONSOLE)
262 #ifdef USE_CTRL_O_SYSRQ
269 if (uap->
port.sysrq) {
271 spin_unlock(&uap->
port.lock);
273 spin_lock(&uap->
port.lock);
284 uap->
port.icount.rx++;
291 uap->
port.icount.brk++;
292 if (uart_handle_break(&uap->
port))
296 uap->
port.icount.parity++;
298 uap->
port.icount.frame++;
300 uap->
port.icount.overrun++;
301 r1 &= uap->
port.read_status_mask;
304 else if (r1 & PAR_ERR)
306 else if (r1 & CRC_ERR)
310 if (uap->
port.ignore_status_mask == 0xff ||
311 (r1 & uap->
port.ignore_status_mask) == 0) {
312 tty_insert_flip_char(tty, ch, flag);
324 if ((++loops) > 1000)
326 ch = read_zsreg(uap,
R0);
333 pmz_interrupt_control(uap, 0);
342 status = read_zsreg(uap,
R0);
348 uap->
port.icount.dsr++;
365 if (status & BRK_ABRT)
376 unsigned char status = read_zsreg(uap,
R0);
393 pmz_load_zsregs(uap, uap->
curregs);
413 if (uap->
port.x_char) {
415 write_zsdata(uap, uap->
port.x_char);
417 uap->
port.icount.tx++;
418 uap->
port.x_char = 0;
424 xmit = &uap->
port.state->xmit;
429 if (uart_tx_stopped(&uap->
port))
433 write_zsdata(uap, xmit->
buf[xmit->
tail]);
437 uap->
port.icount.tx++;
459 uap_a = pmz_get_port_A(uap);
462 spin_lock(&uap_a->
port.lock);
463 r3 = read_zsreg(uap_a,
R3);
472 pmz_debug(
"ChanA interrupt while not open !\n");
478 pmz_status_handle(uap_a);
480 tty = pmz_receive_chars(uap_a);
482 pmz_transmit_chars(uap_a);
486 spin_unlock(&uap_a->
port.lock);
493 spin_lock(&uap_b->
port.lock);
497 pmz_debug(
"ChanB interrupt while not open !\n");
503 pmz_status_handle(uap_b);
505 tty = pmz_receive_chars(uap_b);
507 pmz_transmit_chars(uap_b);
511 spin_unlock(&uap_b->
port.lock);
528 status = read_zsreg(uap,
R0);
529 spin_unlock_irqrestore(&uap->
port.lock, flags);
542 status = pmz_peek_status(
to_pmz(port));
554 static void pmz_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
566 set_bits = clear_bits = 0;
584 pmz_debug(
"pmz_set_mctrl: set bits: %x, clear bits: %x -> %x\n",
594 static unsigned int pmz_get_mctrl(
struct uart_port *port)
600 status = read_zsreg(uap,
R0);
605 if (status & SYNC_HUNT)
618 static void pmz_stop_tx(
struct uart_port *port)
627 static void pmz_start_tx(
struct uart_port *port)
637 status = read_zsreg(uap,
R0);
647 write_zsdata(uap, port->
x_char);
654 write_zsdata(uap, xmit->
buf[xmit->
tail]);
671 static void pmz_stop_rx(
struct uart_port *port)
679 pmz_maybe_update_regs(uap);
688 static void pmz_enable_ms(
struct uart_port *port)
691 unsigned char new_reg;
708 static void pmz_break_ctl(
struct uart_port *port,
int break_state)
711 unsigned char set_bits, clear_bits, new_reg;
714 set_bits = clear_bits = 0;
729 spin_unlock_irqrestore(&port->
lock, flags);
732 #ifdef CONFIG_PPC_PMAC
746 rc = pmac_call_feature(
747 PMAC_FTR_SCC_ENABLE, uap->node, uap->
port_type, 1);
748 pmz_debug(
"port power on result: %d\n", rc);
750 rc = pmac_call_feature(
751 PMAC_FTR_MODEM_ENABLE, uap->node, 0, 1);
753 pmz_debug(
"modem power result: %d\n", rc);
760 rc = pmac_call_feature(
761 PMAC_FTR_MODEM_ENABLE, uap->node, 0, 0);
762 pmz_debug(
"port power off result: %d\n", rc);
764 pmac_call_feature(PMAC_FTR_SCC_ENABLE, uap->node, uap->
port_type, 0);
771 static int pmz_set_scc_power(
struct uart_pmac_port *uap,
int state)
807 write_zsreg(uap, 3,
Rx8);
808 write_zsreg(uap, 5,
Tx8 |
RTS);
809 write_zsreg(uap, 9,
NV);
811 write_zsreg(uap, 12, 0);
812 write_zsreg(uap, 13, 0);
825 write_zsreg(uap, 9,
NV);
827 write_zsreg(uap, 3,
Rx8);
829 while (read_zsreg(uap, 0) &
Rx_CH_AV) {
830 (
void)read_zsreg(uap, 8);
849 pwr_delay = pmz_set_scc_power(uap, 1);
852 pmz_fix_zero_bug_scc(uap);
859 write_zsreg(uap, 9, 0);
863 write_zsreg(uap,
R1, 0);
885 pmz_load_zsregs(uap, uap->
curregs);
905 spin_unlock_irqrestore(&uap->
port.lock, flags);
912 spin_unlock_irqrestore(&uap->
port.lock, flags);
920 static int pmz_startup(
struct uart_port *port)
935 pwr_delay = __pmz_startup(uap);
936 spin_unlock_irqrestore(&port->
lock, flags);
941 pmz_error(
"Unable to register zs interrupt handler.\n");
942 pmz_set_scc_power(uap, 0);
949 if (pwr_delay != 0) {
950 pmz_debug(
"pmz: delaying %d ms\n", pwr_delay);
960 pmz_interrupt_control(uap, 1);
961 spin_unlock_irqrestore(&port->
lock, flags);
968 static void pmz_shutdown(
struct uart_port *port)
978 pmz_interrupt_control(uap, 0);
987 pmz_maybe_update_regs(uap);
990 spin_unlock_irqrestore(&port->
lock, flags);
1000 pmz_set_scc_power(uap, 0);
1002 spin_unlock_irqrestore(&port->
lock, flags);
1011 unsigned int iflag,
unsigned long baud)
1053 switch (cflag &
CSIZE) {
1090 uap->
port.read_status_mask = Rx_OVR;
1094 uap->
port.read_status_mask |= BRK_ABRT;
1096 uap->
port.ignore_status_mask = 0;
1098 uap->
port.ignore_status_mask |= CRC_ERR |
PAR_ERR;
1105 if ((cflag &
CREAD) == 0)
1106 uap->
port.ignore_status_mask = 0xff;
1113 static void pmz_irda_setup(
struct uart_pmac_port *uap,
unsigned long *baud)
1158 while ((read_zsreg(uap,
R0) & Tx_BUF_EMP) == 0
1159 || (read_zsreg(uap,
R1) &
ALL_SNT) == 0) {
1161 pmz_error(
"transmitter didn't drain\n");
1169 (
void)read_zsdata(uap);
1170 (
void)read_zsdata(uap);
1171 (
void)read_zsdata(uap);
1189 pmz_convert_to_zs(uap,
CS8, 0, 19200);
1190 pmz_load_zsregs(uap, uap->
curregs);
1194 write_zsdata(uap, 1);
1196 while ((read_zsreg(uap,
R0) & Rx_CH_AV) == 0) {
1198 pmz_error(
"irda_setup timed out on get_version byte\n");
1203 version = read_zsdata(uap);
1206 pmz_info(
"IrDA: dongle version %d not supported\n", version);
1211 write_zsdata(uap, cmdbyte);
1213 while ((read_zsreg(uap,
R0) & Rx_CH_AV) == 0) {
1215 pmz_error(
"irda_setup timed out on speed mode byte\n");
1220 t = read_zsdata(uap);
1222 pmz_error(
"irda_setup speed mode byte = %x (%x)\n", t, cmdbyte);
1224 pmz_info(
"IrDA setup for %ld bps, dongle version: %d\n",
1227 (
void)read_zsdata(uap);
1228 (
void)read_zsdata(uap);
1229 (
void)read_zsdata(uap);
1237 (
void)read_zsdata(uap);
1238 (
void)read_zsdata(uap);
1239 (
void)read_zsdata(uap);
1263 pmz_debug(
"pmz: switch IRDA to %ld bauds\n", baud);
1265 pmz_irda_setup(uap, &baud);
1267 pmz_convert_to_zs(uap, termios->
c_cflag, termios->
c_iflag, baud);
1268 pmz_load_zsregs(uap, uap->
curregs);
1272 pmz_convert_to_zs(uap, termios->
c_cflag, termios->
c_iflag, baud);
1283 pmz_maybe_update_regs(uap);
1287 pmz_debug(
"pmz: set_termios() done.\n");
1295 unsigned long flags;
1300 pmz_interrupt_control(uap, 0);
1303 __pmz_set_termios(port, termios, old);
1307 pmz_interrupt_control(uap, 1);
1309 spin_unlock_irqrestore(&port->
lock, flags);
1312 static const char *pmz_type(
struct uart_port *port)
1317 return "Z85c30 ESCC - Infrared port";
1319 return "Z85c30 ESCC - Internal modem";
1320 return "Z85c30 ESCC - Serial port";
1326 static void pmz_release_port(
struct uart_port *port)
1330 static int pmz_request_port(
struct uart_port *port)
1336 static void pmz_config_port(
struct uart_port *port,
int flags)
1346 #ifdef CONFIG_CONSOLE_POLL
1348 static int pmz_poll_get_char(
struct uart_port *port)
1354 if ((read_zsreg(uap,
R0) & Rx_CH_AV) != 0)
1355 return read_zsdata(uap);
1363 static void pmz_poll_put_char(
struct uart_port *port,
unsigned char c)
1368 while ((read_zsreg(uap,
R0) & Tx_BUF_EMP) == 0)
1370 write_zsdata(uap, c);
1375 static struct uart_ops pmz_pops = {
1376 .tx_empty = pmz_tx_empty,
1377 .set_mctrl = pmz_set_mctrl,
1378 .get_mctrl = pmz_get_mctrl,
1379 .stop_tx = pmz_stop_tx,
1380 .start_tx = pmz_start_tx,
1381 .stop_rx = pmz_stop_rx,
1382 .enable_ms = pmz_enable_ms,
1383 .break_ctl = pmz_break_ctl,
1384 .startup = pmz_startup,
1385 .shutdown = pmz_shutdown,
1386 .set_termios = pmz_set_termios,
1388 .release_port = pmz_release_port,
1389 .request_port = pmz_request_port,
1390 .config_port = pmz_config_port,
1391 .verify_port = pmz_verify_port,
1392 #ifdef CONFIG_CONSOLE_POLL
1393 .poll_get_char = pmz_poll_get_char,
1394 .poll_put_char = pmz_poll_put_char,
1398 #ifdef CONFIG_PPC_PMAC
1409 const struct slot_names_prop {
1414 struct resource r_ports, r_rxdma, r_txdma;
1421 uap->
port.mapbase = r_ports.start;
1439 uap->tx_dma_regs =
ioremap(r_txdma.start, 0x100);
1440 if (uap->tx_dma_regs ==
NULL) {
1444 uap->rx_dma_regs =
ioremap(r_rxdma.start, 0x100);
1445 if (uap->rx_dma_regs ==
NULL) {
1447 uap->tx_dma_regs =
NULL;
1462 if (conn && (
strcmp(conn,
"infrared") == 0))
1481 if (mid)
switch(*mid) {
1492 of_node_put(i2c_modem);
1504 uap->
port.fifosize = 1;
1505 uap->
port.ops = &pmz_pops;
1507 uap->
port.flags = 0;
1515 if (uap->
port.irq == 0 &&
1528 pmz_convert_to_zs(uap,
CS8, 0, 9600);
1560 if (pmz_ports[i].
node == mdev->ofdev.
dev.of_node)
1562 if (i >= MAX_ZS_PORTS)
1566 uap = &pmz_ports[
i];
1568 uap->
port.dev = &mdev->ofdev.dev;
1576 ", port still active\n",
1588 static int pmz_detach(
struct macio_dev *mdev)
1609 static int pmz_suspend(
struct macio_dev *mdev,
pm_message_t pm_state)
1614 printk(
"HRM... pmz_suspend with NULL uap\n");
1624 static int pmz_resume(
struct macio_dev *mdev)
1642 static int __init pmz_probe(
void)
1644 struct device_node *node_p, *node_a, *node_b, *np;
1658 node_a = node_b =
NULL;
1661 node_a = of_node_get(np);
1663 node_b = of_node_get(np);
1665 if (!node_a && !node_b) {
1666 of_node_put(node_a);
1667 of_node_put(node_b);
1669 (!node_a) ?
'a' :
'b', node_p->
full_name);
1676 if (node_b !=
NULL) {
1677 pmz_ports[
count].mate = &pmz_ports[count+1];
1678 pmz_ports[count+1].mate = &pmz_ports[
count];
1681 pmz_ports[
count].node = node_a;
1682 pmz_ports[count+1].node = node_b;
1684 pmz_ports[count+1].port.line = count+1;
1689 rc = pmz_init_port(&pmz_ports[count]);
1690 if (rc == 0 && node_b !=
NULL)
1691 rc = pmz_init_port(&pmz_ports[count+1]);
1693 of_node_put(node_a);
1694 of_node_put(node_b);
1703 pmz_ports_count =
count;
1719 if (!r_ports || !irq)
1725 uap->
port.irq = irq;
1727 uap->
port.fifosize = 1;
1728 uap->
port.ops = &pmz_pops;
1730 uap->
port.flags = 0;
1736 pmz_convert_to_zs(uap,
CS8, 0, 9600);
1741 static int __init pmz_probe(
void)
1745 pmz_ports_count = 0;
1747 pmz_ports[0].port.line = 0;
1750 err = pmz_init_port(&pmz_ports[0]);
1755 pmz_ports[0].mate = &pmz_ports[1];
1756 pmz_ports[1].mate = &pmz_ports[0];
1757 pmz_ports[1].port.line = 1;
1758 pmz_ports[1].flags = 0;
1760 err = pmz_init_port(&pmz_ports[1]);
1779 for (i = 0; i < pmz_ports_count; i++)
1780 if (pmz_ports[i].pdev == pdev)
1782 if (i >= pmz_ports_count)
1785 uap = &pmz_ports[
i];
1787 platform_set_drvdata(pdev, uap);
1801 platform_set_drvdata(pdev,
NULL);
1809 #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
1811 static void pmz_console_write(
struct console *
con,
const char *
s,
unsigned int count);
1814 static struct console pmz_console = {
1816 .write = pmz_console_write,
1818 .setup = pmz_console_setup,
1821 .data = &pmz_uart_reg,
1824 #define PMACZILOG_CONSOLE &pmz_console
1826 #define PMACZILOG_CONSOLE (NULL)
1833 static int __init pmz_register(
void)
1835 pmz_uart_reg.
nr = pmz_ports_count;
1844 #ifdef CONFIG_PPC_PMAC
1858 static struct macio_driver pmz_driver = {
1860 .name =
"pmac_zilog",
1862 .of_match_table = pmz_match,
1864 .probe = pmz_attach,
1865 .remove = pmz_detach,
1866 .suspend = pmz_suspend,
1867 .resume = pmz_resume,
1882 static int __init init_pmz(
void)
1894 if (pmz_ports_count == 0)
1900 if (pmz_ports_count == 0)
1906 rc = pmz_register();
1909 "pmac_zilog: Error registering serial device, disabling pmac_zilog.\n"
1910 "pmac_zilog: Did another serial driver already claim the minors?\n");
1912 for (i=0; i < pmz_ports_count; i++)
1913 pmz_dispose_port(&pmz_ports[i]);
1920 #ifdef CONFIG_PPC_PMAC
1927 static void __exit exit_pmz(
void)
1931 #ifdef CONFIG_PPC_PMAC
1938 for (i = 0; i < pmz_ports_count; i++) {
1940 #ifdef CONFIG_PPC_PMAC
1941 if (uport->node !=
NULL)
1942 pmz_dispose_port(uport);
1945 pmz_dispose_port(uport);
1952 #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
1954 static void pmz_console_putchar(
struct uart_port *port,
int ch)
1959 while ((read_zsreg(uap,
R0) & Tx_BUF_EMP) == 0)
1961 write_zsdata(uap, ch);
1968 static void pmz_console_write(
struct console *
con,
const char *
s,
unsigned int count)
1971 unsigned long flags;
1985 spin_unlock_irqrestore(&uap->
port.lock, flags);
1999 unsigned long pwr_delay;
2014 if (co->
index >= pmz_ports_count)
2016 uap = &pmz_ports[co->
index];
2017 #ifdef CONFIG_PPC_PMAC
2018 if (uap->node ==
NULL)
2039 pwr_delay = __pmz_startup(uap);
2049 static int __init pmz_console_init(
void)