18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/serial.h>
21 #include <linux/signal.h>
22 #include <linux/sched.h>
25 #include <linux/tty.h>
28 #include <linux/string.h>
29 #include <linux/fcntl.h>
31 #include <linux/kernel.h>
33 #include <linux/reboot.h>
34 #include <linux/keyboard.h>
37 #include <linux/bitops.h>
43 #include <asm/delay.h>
44 #include <asm/uaccess.h>
50 #if defined(CONFIG_M68EZ328)
53 #if defined(CONFIG_M68VZ328)
61 #ifdef CONFIG_XCOPILOT_BUGS
75 #define USTCNT_TX_INTR_MASK (USTCNT_TXEE)
97 #if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)
98 #define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)
99 #elif defined(CONFIG_M68328)
100 #define USTCNT_RX_INTR_MASK (USTCNT_RXRE)
102 #error Please, define the Rx interrupt events for your CPU
126 #define SERIAL_MAGIC 0x5301
149 #ifdef CONFIG_M68VZ328
150 #define CONSOLE_BAUD_RATE 19200
151 #define DEFAULT_CBAUD B19200
155 #ifndef CONSOLE_BAUD_RATE
156 #define CONSOLE_BAUD_RATE 9600
157 #define DEFAULT_CBAUD B9600
161 static int m68328_console_initted = 0;
169 #ifdef SERIAL_PARANOIA_CHECK
170 static const char *badmagic =
171 "Warning: bad magic number for serial struct %s in %s\n";
172 static const char *badinfo =
173 "Warning: null m68k_serial for %s in %s\n";
176 printk(badinfo, name, routine);
180 printk(badmagic, name, routine);
191 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
192 9600, 19200, 38400, 57600, 115200, 0 };
197 unsigned long result = 115200;
199 if (
GET_FIELD(baud, UBAUD_PRESCALER) == 0x38) result = 38400;
200 result >>=
GET_FIELD(baud, UBAUD_DIVIDE);
219 if (serial_paranoia_check(info, tty->
name,
"rs_stop"))
227 static int rs_put_char(
char ch)
251 if (serial_paranoia_check(info, tty->
name,
"rs_start"))
269 unsigned char ch,
flag;
274 #ifndef CONFIG_XCOPILOT_BUGS
282 #ifdef CONFIG_MAGIC_SYSRQ
283 }
else if (ch == 0x10) {
289 }
else if (ch == 0x12) {
308 tty_insert_flip_char(tty, ch, flag);
309 #ifndef CONFIG_XCOPILOT_BUGS
325 uart->utx.b.txdata = info->
x_char;
327 goto clear_and_return;
333 goto clear_and_return;
344 goto clear_and_return;
370 receive_chars(info, tty, rx);
371 if (tx & UTX_TX_AVAIL)
372 transmit_chars(info, tty);
374 receive_chars(info, tty, rx);
424 change_speed(info, tty);
461 #ifndef CONFIG_M68VZ328
514 unsigned short ustcnt;
518 cflag = tty->termios.c_cflag;
519 if (!(port = info->
port))
522 ustcnt = uart->ustcnt;
527 i = (i & ~CBAUDEX) +
B38400;
546 #ifdef CONFIG_SERIAL_68328_RTS_CTS
556 uart->ustcnt = ustcnt;
563 static void rs_fair_output(
void)
570 if (info == 0)
return;
601 while((c=*(p++)) != 0) {
613 static void rs_set_ldisc(
struct tty_struct *tty)
617 if (serial_paranoia_check(info, tty->
name,
"rs_set_ldisc"))
625 static void rs_flush_chars(
struct tty_struct *tty)
631 if (serial_paranoia_check(info, tty->
name,
"rs_flush_chars"))
653 if (uart->utx.w & UTX_TX_AVAIL) {
664 while (!(uart->utx.w & UTX_TX_AVAIL))
udelay(5);
673 const unsigned char *
buf,
int count)
680 if (serial_paranoia_check(info, tty->
name,
"rs_write"))
718 while (!(uart->utx.w & UTX_TX_AVAIL))
udelay(5);
720 if (uart->utx.w & UTX_TX_AVAIL) {
735 static int rs_write_room(
struct tty_struct *tty)
740 if (serial_paranoia_check(info, tty->
name,
"rs_write_room"))
748 static int rs_chars_in_buffer(
struct tty_struct *tty)
752 if (serial_paranoia_check(info, tty->
name,
"rs_chars_in_buffer"))
757 static void rs_flush_buffer(
struct tty_struct *tty)
762 if (serial_paranoia_check(info, tty->
name,
"rs_flush_buffer"))
778 static void rs_throttle(
struct tty_struct * tty)
782 if (serial_paranoia_check(info, tty->
name,
"rs_throttle"))
791 static void rs_unthrottle(
struct tty_struct * tty)
795 if (serial_paranoia_check(info, tty->
name,
"rs_unthrottle"))
814 static int get_serial_info(
struct m68k_serial * info,
828 tmp.close_delay = info->
tport.close_delay;
829 tmp.closing_wait = info->
tport.closing_wait;
852 if ((new_serial.baud_base != info->
baud_base) ||
853 (new_serial.type != info->
type) ||
875 info->
type = new_serial.type;
880 retval = startup(info, tty);
896 #ifdef CONFIG_SERIAL_68328_RTS_CTS
903 #ifdef CONFIG_SERIAL_68328_RTS_CTS
931 unsigned int cmd,
unsigned long arg)
936 if (serial_paranoia_check(info, tty->
name,
"rs_ioctl"))
953 send_break(info, 250);
960 send_break(info, arg ? arg*(100) : 250);
963 return get_serial_info(info,
966 return set_serial_info(info, tty,
969 return get_lsr_info(info, (
unsigned int *) arg);
985 change_speed(info, tty);
988 !(tty->termios.c_cflag &
CRTSCTS)) {
1010 unsigned long flags;
1012 if (!info || serial_paranoia_check(info, tty->
name,
"rs_close"))
1022 if ((tty->
count == 1) && (port->
count != 1)) {
1030 printk(
"rs_close: bad serial port count; tty->count is 1, "
1031 "port->count is %d\n", port->
count);
1034 if (--port->
count < 0) {
1035 printk(
"rs_close: bad serial port count for ttyS%d: %d\n",
1059 uart->ustcnt &= ~(
USTCNT_RXEN | USTCNT_RX_INTR_MASK);
1061 shutdown(info, tty);
1062 rs_flush_buffer(tty);
1067 #warning "This is not and has never been valid so fix it"
1070 if (tty->
ldisc.close)
1071 (tty->
ldisc.close)(tty);
1073 tty->termios.c_line =
N_TTY;
1074 if (tty->
ldisc.open)
1075 (tty->
ldisc.open)(tty);
1095 if (serial_paranoia_check(info, tty->
name,
"rs_hangup"))
1098 rs_flush_buffer(tty);
1099 shutdown(info, tty);
1100 info->
tport.count = 0;
1117 info = &m68k_soft[tty->
index];
1119 if (serial_paranoia_check(info, tty->
name,
"rs_open"))
1122 info->
tport.count++;
1129 retval = startup(info, tty);
1138 static void show_serial_version(
void)
1140 printk(
"MC68328 serial driver version 1.00\n");
1147 .flush_chars = rs_flush_chars,
1148 .write_room = rs_write_room,
1149 .chars_in_buffer = rs_chars_in_buffer,
1150 .flush_buffer = rs_flush_buffer,
1152 .throttle = rs_throttle,
1153 .unthrottle = rs_unthrottle,
1154 .set_termios = rs_set_termios,
1158 .set_ldisc = rs_set_ldisc,
1168 unsigned long flags;
1172 serial_driver = alloc_tty_driver(
NR_PORTS);
1176 show_serial_version();
1181 serial_driver->
name =
"ttyS";
1196 info = &m68k_soft[
i];
1198 info->
tport.ops = &rs_port_ops;
1201 info->
irq = uart_irqs[
i];
1207 printk(
"%s%d at 0x%08x (irq = %d)", serial_driver->
name, info->
line,
1209 printk(
" is a builtin MC68328 UART\n");
1211 #ifdef CONFIG_M68VZ328
1219 "M68328_UART", info))
1220 panic(
"Unable to attach 68328 serial interrupt\n");
1239 static void m68328_set_baud(
void)
1241 unsigned short ustcnt;
1252 m68328_console_baud = 9600;
1262 m68328_console_initted = 1;
1281 m68328_console_baud =
n;
1282 m68328_console_cbaud = 0;
1284 m68328_console_cbaud |=
CBAUDEX;
1287 m68328_console_cbaud |=
i;
1298 return serial_driver;
1305 if (!m68328_console_initted)
1310 rs_put_char( *str++ );
1315 static struct console m68328_driver = {
1318 .device = m68328_console_device,
1325 static int __init m68328_console_init(
void)