34 #undef SERIAL_PARANOIA_CHECK
35 #define SERIAL_DO_RESTART
39 #undef SERIAL_DEBUG_INTR
40 #undef SERIAL_DEBUG_OPEN
41 #undef SERIAL_DEBUG_FLOW
42 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
46 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
47 #define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
48 tty->name, (info->tport.flags), serial_driver->refcount,info->count,tty->count,s)
57 #include <linux/module.h>
59 #include <linux/types.h>
60 #include <linux/serial.h>
62 static char *serial_version =
"4.30";
64 #include <linux/errno.h>
65 #include <linux/signal.h>
66 #include <linux/sched.h>
67 #include <linux/kernel.h>
70 #include <linux/tty.h>
75 #include <linux/string.h>
76 #include <linux/fcntl.h>
77 #include <linux/ptrace.h>
81 #include <linux/slab.h>
83 #include <linux/bitops.h>
86 #include <asm/setup.h>
112 #define custom amiga_custom
113 static char *serial_name =
"Amiga-builtin serial driver";
118 #define WAKEUP_CHARS 256
120 static unsigned char current_ctl_bits;
124 static void rs_wait_until_sent(
struct tty_struct *tty,
int timeout);
129 #define NR_PORTS ARRAY_SIZE(rs_table)
131 #include <asm/uaccess.h>
133 #define serial_isroot() (capable(CAP_SYS_ADMIN))
139 #ifdef SERIAL_PARANOIA_CHECK
140 static const char *badmagic =
141 "Warning: bad magic number for serial struct (%s) in %s\n";
142 static const char *badinfo =
143 "Warning: null async_struct for (%s) in %s\n";
146 printk(badinfo, name, routine);
150 printk(badmagic, name, routine);
158 #define SDR_OVRUN (1<<15)
159 #define SDR_RBF (1<<14)
160 #define SDR_TBE (1<<13)
161 #define SDR_TSRE (1<<12)
163 #define SERPER_PARENB (1<<15)
165 #define AC_SETCLR (1<<15)
166 #define AC_UARTBRK (1<<11)
168 #define SER_DTR (1<<7)
169 #define SER_RTS (1<<6)
170 #define SER_DCD (1<<5)
171 #define SER_CTS (1<<4)
172 #define SER_DSR (1<<3)
192 if (serial_paranoia_check(info, tty->
name,
"rs_stop"))
212 if (serial_paranoia_check(info, tty->
name,
"rs_start"))
216 if (info->
xmit.head != info->
xmit.tail
255 unsigned char ch,
flag;
267 if((serdatr & 0x1ff) == 0)
275 #ifdef SERIAL_DEBUG_INTR
276 printk(
"DR%02x:%02x...", ch, status);
311 if (status & (UART_LSR_BI)) {
312 #ifdef SERIAL_DEBUG_INTR
313 printk(
"handling break....");
318 }
else if (status & UART_LSR_PE)
320 else if (status & UART_LSR_FE)
322 if (status & UART_LSR_OE) {
331 tty_insert_flip_char(tty, ch, flag);
350 if (info->
xmit.head == info->
xmit.tail
351 || info->
tport.tty->stopped
352 || info->
tport.tty->hw_stopped) {
369 #ifdef SERIAL_DEBUG_INTR
372 if (info->
xmit.head == info->
xmit.tail) {
379 static void check_modem_status(
struct serial_state *info)
383 unsigned char dstatus;
387 dstatus = status ^ current_ctl_bits;
388 current_ctl_bits =
status;
397 #ifdef CONFIG_HARD_PPS
409 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
410 printk(
"ttyS%d CD now %s...", info->line,
411 (!(status & SER_DCD)) ?
"on" :
"off");
413 if (!(status & SER_DCD))
416 #ifdef SERIAL_DEBUG_OPEN
417 printk(
"doing serial hangup...");
423 if (tty_port_cts_enabled(port)) {
424 if (port->
tty->hw_stopped) {
426 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
427 printk(
"CTS tx start...");
429 port->
tty->hw_stopped = 0;
441 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
444 port->
tty->hw_stopped = 1;
465 check_modem_status(info);
473 #ifdef SERIAL_DEBUG_INTR
477 if (!info->
tport.tty)
481 #ifdef SERIAL_DEBUG_INTR
487 static irqreturn_t ser_tx_int(
int irq,
void *dev_id)
492 #ifdef SERIAL_DEBUG_INTR
496 if (!info->
tport.tty)
499 transmit_chars(info);
500 #ifdef SERIAL_DEBUG_INTR
543 info->
xmit.buf = (
unsigned char *) page;
545 #ifdef SERIAL_DEBUG_OPEN
546 printk(
"starting up ttys%d ...", info->line);
574 rtsdtr_ctrl(info->
MCR);
577 info->
xmit.head = info->
xmit.tail = 0;
594 change_speed(tty, info,
NULL);
619 #ifdef SERIAL_DEBUG_OPEN
620 printk(
"Shutting down serial port %d ....\n", info->line);
636 if (info->
xmit.buf) {
649 if (tty->termios.c_cflag &
HUPCL)
651 rtsdtr_ctrl(info->
MCR);
668 int quot = 0, baud_base,
baud;
669 unsigned cflag, cval = 0;
673 cflag = tty->termios.c_cflag;
703 quot = (2*baud_base / 269);
705 quot = baud_base /
baud;
708 if (!quot && old_termios) {
710 tty->termios.c_cflag &= ~
CBAUD;
721 quot = (2*baud_base / 269);
723 quot = baud_base /
baud;
728 quot = baud_base / 9600;
780 if ((cflag &
CREAD) == 0)
802 static int rs_put_char(
struct tty_struct *tty,
unsigned char ch)
809 if (serial_paranoia_check(info, tty->
name,
"rs_put_char"))
823 info->
xmit.buf[info->
xmit.head++] = ch;
829 static void rs_flush_chars(
struct tty_struct *tty)
834 if (serial_paranoia_check(info, tty->
name,
"rs_flush_chars"))
837 if (info->
xmit.head == info->
xmit.tail
859 if (serial_paranoia_check(info, tty->
name,
"rs_write"))
876 info->
xmit.head = ((info->
xmit.head +
c) &
884 if (info->
xmit.head != info->
xmit.tail
900 static int rs_write_room(
struct tty_struct *tty)
904 if (serial_paranoia_check(info, tty->
name,
"rs_write_room"))
909 static int rs_chars_in_buffer(
struct tty_struct *tty)
913 if (serial_paranoia_check(info, tty->
name,
"rs_chars_in_buffer"))
918 static void rs_flush_buffer(
struct tty_struct *tty)
923 if (serial_paranoia_check(info, tty->
name,
"rs_flush_buffer"))
926 info->
xmit.head = info->
xmit.tail = 0;
935 static void rs_send_xchar(
struct tty_struct *tty,
char ch)
940 if (serial_paranoia_check(info, tty->
name,
"rs_send_char"))
970 static void rs_throttle(
struct tty_struct * tty)
974 #ifdef SERIAL_DEBUG_THROTTLE
978 tty->
ldisc.chars_in_buffer(tty));
981 if (serial_paranoia_check(info, tty->
name,
"rs_throttle"))
987 if (tty->termios.c_cflag & CRTSCTS)
991 rtsdtr_ctrl(info->
MCR);
995 static void rs_unthrottle(
struct tty_struct * tty)
999 #ifdef SERIAL_DEBUG_THROTTLE
1003 tty->
ldisc.chars_in_buffer(tty));
1006 if (serial_paranoia_check(info, tty->
name,
"rs_unthrottle"))
1015 if (tty->termios.c_cflag & CRTSCTS)
1018 rtsdtr_ctrl(info->
MCR);
1042 tmp.close_delay = state->
tport.close_delay;
1043 tmp.closing_wait = state->
tport.closing_wait;
1065 if (new_serial.irq || new_serial.port != state->
port ||
1072 if ((new_serial.baud_base != state->
baud_base) ||
1083 goto check_and_exit;
1086 if (new_serial.baud_base < 9600) {
1096 state->
baud_base = new_serial.baud_base;
1115 change_speed(tty, state,
NULL);
1118 retval = startup(tty, state);
1138 unsigned long flags;
1151 static int rs_tiocmget(
struct tty_struct *tty)
1155 unsigned long flags;
1157 if (serial_paranoia_check(info, tty->
name,
"rs_ioctl"))
1162 control = info->
MCR;
1173 static int rs_tiocmset(
struct tty_struct *tty,
unsigned int set,
1177 unsigned long flags;
1179 if (serial_paranoia_check(info, tty->
name,
"rs_ioctl"))
1193 rtsdtr_ctrl(info->
MCR);
1201 static int rs_break(
struct tty_struct *tty,
int break_state)
1204 unsigned long flags;
1206 if (serial_paranoia_check(info, tty->
name,
"rs_break"))
1210 if (break_state == -1)
1225 static int rs_get_icount(
struct tty_struct *tty,
1230 unsigned long flags;
1235 icount->
cts = cnow.cts;
1236 icount->
dsr = cnow.dsr;
1237 icount->
rng = cnow.rng;
1238 icount->
dcd = cnow.dcd;
1239 icount->
rx = cnow.rx;
1240 icount->
tx = cnow.tx;
1241 icount->
frame = cnow.frame;
1242 icount->
overrun = cnow.overrun;
1243 icount->
parity = cnow.parity;
1244 icount->
brk = cnow.brk;
1251 unsigned int cmd,
unsigned long arg)
1256 unsigned long flags;
1258 if (serial_paranoia_check(info, tty->
name,
"rs_ioctl"))
1270 return get_serial_info(tty, info, argp);
1272 return set_serial_info(tty, info, argp);
1277 return get_lsr_info(info, argp);
1304 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1305 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1307 if ( ((arg &
TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1308 ((arg &
TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1309 ((arg &
TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1310 ((arg &
TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
1320 printk (
"TIOCSER?WILD ioctl obsolete, ignored.\n");
1332 unsigned long flags;
1333 unsigned int cflag = tty->termios.c_cflag;
1335 change_speed(tty, info, old_termios);
1342 rtsdtr_ctrl(info->
MCR);
1347 if (!(old_termios->
c_cflag & CBAUD) &&
1350 if (!(tty->termios.c_cflag & CRTSCTS) ||
1355 rtsdtr_ctrl(info->
MCR);
1360 if ((old_termios->
c_cflag & CRTSCTS) &&
1361 !(tty->termios.c_cflag & CRTSCTS)) {
1373 if (!(old_termios->
c_cflag & CLOCAL) &&
1374 (tty->termios.c_cflag & CLOCAL))
1394 if (serial_paranoia_check(state, tty->
name,
"rs_close"))
1420 rs_wait_until_sent(tty, state->
timeout);
1422 shutdown(tty, state);
1423 rs_flush_buffer(tty);
1434 static void rs_wait_until_sent(
struct tty_struct *tty,
int timeout)
1437 unsigned long orig_jiffies, char_time;
1440 if (serial_paranoia_check(info, tty->
name,
"rs_wait_until_sent"))
1457 char_time = char_time / 5;
1461 char_time =
min_t(
unsigned long, char_time, timeout);
1471 if (!timeout || timeout > 2*info->
timeout)
1473 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1474 printk(
"In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1475 printk(
"jiff=%lu...", jiffies);
1478 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1479 printk(
"serdatr = %d (jiff=%lu)...", lsr, jiffies);
1484 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
1489 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1490 printk(
"lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1497 static void rs_hangup(
struct tty_struct *tty)
1501 if (serial_paranoia_check(info, tty->
name,
"rs_hangup"))
1504 rs_flush_buffer(tty);
1505 shutdown(tty, info);
1506 info->
tport.count = 0;
1528 if (serial_paranoia_check(info, tty->
name,
"rs_open"))
1533 retval = startup(tty, info);
1549 unsigned long flags;
1551 seq_printf(m,
"%d: uart:amiga_builtin", line);
1561 strcat(stat_buf,
"|RTS");
1563 strcat(stat_buf,
"|CTS");
1565 strcat(stat_buf,
"|DTR");
1566 if(!(status & SER_DSR))
1567 strcat(stat_buf,
"|DSR");
1568 if(!(status & SER_DCD))
1579 if (state->
icount.parity)
1585 if (state->
icount.overrun)
1594 static int rs_proc_show(
struct seq_file *m,
void *
v)
1596 seq_printf(m,
"serinfo:1.0 driver:%s\n", serial_version);
1608 .open = rs_proc_open,
1627 static void show_serial_version(
void)
1637 .put_char = rs_put_char,
1638 .flush_chars = rs_flush_chars,
1639 .write_room = rs_write_room,
1640 .chars_in_buffer = rs_chars_in_buffer,
1641 .flush_buffer = rs_flush_buffer,
1643 .throttle = rs_throttle,
1644 .unthrottle = rs_unthrottle,
1645 .set_termios = rs_set_termios,
1648 .hangup = rs_hangup,
1649 .break_ctl = rs_break,
1650 .send_xchar = rs_send_xchar,
1651 .wait_until_sent = rs_wait_until_sent,
1652 .tiocmget = rs_tiocmget,
1653 .tiocmset = rs_tiocmset,
1654 .get_icount = rs_get_icount,
1655 .proc_fops = &rs_proc_fops,
1658 static int amiga_carrier_raised(
struct tty_port *port)
1663 static void amiga_dtr_rts(
struct tty_port *port,
int raise)
1667 unsigned long flags;
1675 rtsdtr_ctrl(info->
MCR);
1680 .carrier_raised = amiga_carrier_raised,
1681 .dtr_rts = amiga_dtr_rts,
1689 unsigned long flags;
1693 serial_driver = alloc_tty_driver(
NR_PORTS);
1697 show_serial_version();
1702 serial_driver->
name =
"ttyS";
1722 state->
tport.ops = &amiga_port_ops;
1727 goto fail_put_tty_driver;
1739 goto fail_unregister;
1742 "serial RX", state);
1765 platform_set_drvdata(pdev, state);
1773 fail_put_tty_driver:
1781 struct serial_state *state = platform_get_drvdata(pdev);
1785 printk(
"SERIAL: failed to unregister serial driver (%d)\n",
1792 platform_set_drvdata(pdev,
NULL);
1798 .remove =
__exit_p(amiga_serial_remove),
1800 .name =
"amiga-serial",
1805 static int __init amiga_serial_init(
void)
1812 static void __exit amiga_serial_exit(
void)
1820 #if defined(CONFIG_SERIAL_CONSOLE) && !defined(MODULE)
1828 static void amiga_serial_putc(
char c)
1831 while (!(
custom.serdatr & 0x2000))
1841 static void serial_console_write(
struct console *co,
const char *
s,
1844 unsigned short intena =
custom.intenar;
1850 amiga_serial_putc(
'\r');
1851 amiga_serial_putc(*s++);
1860 return serial_driver;
1863 static struct console sercons = {
1865 .write = serial_console_write,
1866 .device = serial_console_device,
1874 static int __init amiserial_console_init(
void)