3 * Common SUN serial routines. Based entirely
4 * upon drivers/sbus/char/sunserial.c which is:
6 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
8 * Adaptation to new UART layer is:
10 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
13 #include <linux/kernel.h>
14 #include <linux/console.h>
15 #include <linux/tty.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
18 #include <linux/serial_core.h>
19 #include <linux/sunserialcore.h>
20 #include <linux/init.h>
25 static int sunserial_current_minor = 64;
27 int sunserial_register_minors(struct uart_driver *drv, int count)
31 drv->minor = sunserial_current_minor;
33 /* Register the driver on the first call */
35 err = uart_register_driver(drv);
37 sunserial_current_minor += count;
38 drv->tty_driver->name_base = drv->minor - 64;
42 EXPORT_SYMBOL(sunserial_register_minors);
44 void sunserial_unregister_minors(struct uart_driver *drv, int count)
47 sunserial_current_minor -= count;
50 uart_unregister_driver(drv);
52 EXPORT_SYMBOL(sunserial_unregister_minors);
54 int sunserial_console_match(struct console *con, struct device_node *dp,
55 struct uart_driver *drv, int line, bool ignore_line)
62 if (of_console_device != dp)
68 if (of_console_options &&
69 *of_console_options == 'b')
72 if ((line & 1) != off)
76 if (!console_set_on_cmdline) {
78 add_preferred_console(con->name, line, NULL);
82 EXPORT_SYMBOL(sunserial_console_match);
84 void sunserial_console_termios(struct console *con, struct device_node *uart_dp)
87 char mode_prop[] = "ttyX-mode";
88 int baud, bits, stop, cflag;
91 if (!strcmp(uart_dp->name, "rsc") ||
92 !strcmp(uart_dp->name, "rsc-console") ||
93 !strcmp(uart_dp->name, "rsc-control")) {
94 mode = of_get_property(uart_dp,
95 "ssp-console-modes", NULL);
97 mode = "115200,8,n,1,-";
98 } else if (!strcmp(uart_dp->name, "lom-console")) {
99 mode = "9600,8,n,1,-";
101 struct device_node *dp;
105 if (of_console_options)
106 c = *of_console_options;
110 dp = of_find_node_by_path("/options");
111 mode = of_get_property(dp, mode_prop, NULL);
113 mode = "9600,8,n,1,-";
117 cflag = CREAD | HUPCL | CLOCAL;
120 baud = simple_strtoul(s, NULL, 0);
122 bits = simple_strtoul(++s, NULL, 0);
126 stop = simple_strtoul(++s, NULL, 0);
128 /* XXX handshake is not handled here. */
131 case 150: cflag |= B150; break;
132 case 300: cflag |= B300; break;
133 case 600: cflag |= B600; break;
134 case 1200: cflag |= B1200; break;
135 case 2400: cflag |= B2400; break;
136 case 4800: cflag |= B4800; break;
137 case 9600: cflag |= B9600; break;
138 case 19200: cflag |= B19200; break;
139 case 38400: cflag |= B38400; break;
140 case 57600: cflag |= B57600; break;
141 case 115200: cflag |= B115200; break;
142 case 230400: cflag |= B230400; break;
143 case 460800: cflag |= B460800; break;
144 default: baud = 9600; cflag |= B9600; break;
148 case 5: cflag |= CS5; break;
149 case 6: cflag |= CS6; break;
150 case 7: cflag |= CS7; break;
151 case 8: cflag |= CS8; break;
152 default: cflag |= CS8; break;
156 case 'o': cflag |= (PARENB | PARODD); break;
157 case 'e': cflag |= PARENB; break;
158 case 'n': default: break;
162 case 2: cflag |= CSTOPB; break;
163 case 1: default: break;
169 /* Sun serial MOUSE auto baud rate detection. */
170 static struct mouse_baud_cflag {
173 } mouse_baud_table[] = {
182 unsigned int suncore_mouse_baud_cflag_next(unsigned int cflag, int *new_baud)
186 for (i = 0; mouse_baud_table[i].baud != -1; i++)
187 if (mouse_baud_table[i].cflag == (cflag & CBAUD))
191 if (mouse_baud_table[i].baud == -1)
194 *new_baud = mouse_baud_table[i].baud;
195 return mouse_baud_table[i].cflag;
198 EXPORT_SYMBOL(suncore_mouse_baud_cflag_next);
200 /* Basically, when the baud rate is wrong the mouse spits out
203 int suncore_mouse_baud_detection(unsigned char ch, int is_break)
205 static int mouse_got_break = 0;
209 /* Let a few normal bytes go by before we jump the gun
210 * and say we need to try another baud rate.
212 if (mouse_got_break && ctr < 8)
215 /* Ok, we need to try another baud. */
220 if (mouse_got_break) {
223 /* Correct baud rate determined. */
231 EXPORT_SYMBOL(suncore_mouse_baud_detection);
233 static int __init suncore_init(void)
237 device_initcall(suncore_init);
239 #if 0 /* ..def MODULE ; never supported as such */
240 MODULE_AUTHOR("Eddie C. Dost, David S. Miller");
241 MODULE_DESCRIPTION("Sun serial common layer");
242 MODULE_LICENSE("GPL");