microblaze: entry.S: Macro optimization
[linux-2.6.git] / drivers / serial / suncore.c
blob544f2e25d0e545f30f959019f4a176bdccb20af8
1 /* suncore.c
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/module.h>
14 #include <linux/kernel.h>
15 #include <linux/console.h>
16 #include <linux/tty.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
19 #include <linux/serial_core.h>
20 #include <linux/init.h>
22 #include <asm/prom.h>
24 #include "suncore.h"
26 static int sunserial_current_minor = 64;
28 int sunserial_register_minors(struct uart_driver *drv, int count)
30 int err = 0;
32 drv->minor = sunserial_current_minor;
33 drv->nr += count;
34 /* Register the driver on the first call */
35 if (drv->nr == count)
36 err = uart_register_driver(drv);
37 if (err == 0) {
38 sunserial_current_minor += count;
39 drv->tty_driver->name_base = drv->minor - 64;
41 return err;
43 EXPORT_SYMBOL(sunserial_register_minors);
45 void sunserial_unregister_minors(struct uart_driver *drv, int count)
47 drv->nr -= count;
48 sunserial_current_minor -= count;
50 if (drv->nr == 0)
51 uart_unregister_driver(drv);
53 EXPORT_SYMBOL(sunserial_unregister_minors);
55 int sunserial_console_match(struct console *con, struct device_node *dp,
56 struct uart_driver *drv, int line, bool ignore_line)
58 if (!con || of_console_device != dp)
59 return 0;
61 if (!ignore_line) {
62 int off = 0;
64 if (of_console_options &&
65 *of_console_options == 'b')
66 off = 1;
68 if ((line & 1) != off)
69 return 0;
72 con->index = line;
73 drv->cons = con;
75 if (!console_set_on_cmdline)
76 add_preferred_console(con->name, line, NULL);
78 return 1;
80 EXPORT_SYMBOL(sunserial_console_match);
82 void sunserial_console_termios(struct console *con, struct device_node *uart_dp)
84 const char *mode, *s;
85 char mode_prop[] = "ttyX-mode";
86 int baud, bits, stop, cflag;
87 char parity;
89 if (!strcmp(uart_dp->name, "rsc") ||
90 !strcmp(uart_dp->name, "rsc-console") ||
91 !strcmp(uart_dp->name, "rsc-control")) {
92 mode = of_get_property(uart_dp,
93 "ssp-console-modes", NULL);
94 if (!mode)
95 mode = "115200,8,n,1,-";
96 } else if (!strcmp(uart_dp->name, "lom-console")) {
97 mode = "9600,8,n,1,-";
98 } else {
99 struct device_node *dp;
100 char c;
102 c = 'a';
103 if (of_console_options)
104 c = *of_console_options;
106 mode_prop[3] = c;
108 dp = of_find_node_by_path("/options");
109 mode = of_get_property(dp, mode_prop, NULL);
110 if (!mode)
111 mode = "9600,8,n,1,-";
114 cflag = CREAD | HUPCL | CLOCAL;
116 s = mode;
117 baud = simple_strtoul(s, NULL, 0);
118 s = strchr(s, ',');
119 bits = simple_strtoul(++s, NULL, 0);
120 s = strchr(s, ',');
121 parity = *(++s);
122 s = strchr(s, ',');
123 stop = simple_strtoul(++s, NULL, 0);
124 s = strchr(s, ',');
125 /* XXX handshake is not handled here. */
127 switch (baud) {
128 case 150: cflag |= B150; break;
129 case 300: cflag |= B300; break;
130 case 600: cflag |= B600; break;
131 case 1200: cflag |= B1200; break;
132 case 2400: cflag |= B2400; break;
133 case 4800: cflag |= B4800; break;
134 case 9600: cflag |= B9600; break;
135 case 19200: cflag |= B19200; break;
136 case 38400: cflag |= B38400; break;
137 case 57600: cflag |= B57600; break;
138 case 115200: cflag |= B115200; break;
139 case 230400: cflag |= B230400; break;
140 case 460800: cflag |= B460800; break;
141 default: baud = 9600; cflag |= B9600; break;
144 switch (bits) {
145 case 5: cflag |= CS5; break;
146 case 6: cflag |= CS6; break;
147 case 7: cflag |= CS7; break;
148 case 8: cflag |= CS8; break;
149 default: cflag |= CS8; break;
152 switch (parity) {
153 case 'o': cflag |= (PARENB | PARODD); break;
154 case 'e': cflag |= PARENB; break;
155 case 'n': default: break;
158 switch (stop) {
159 case 2: cflag |= CSTOPB; break;
160 case 1: default: break;
163 con->cflag = cflag;
166 /* Sun serial MOUSE auto baud rate detection. */
167 static struct mouse_baud_cflag {
168 int baud;
169 unsigned int cflag;
170 } mouse_baud_table[] = {
171 { 1200, B1200 },
172 { 2400, B2400 },
173 { 4800, B4800 },
174 { 9600, B9600 },
175 { -1, ~0 },
176 { -1, ~0 },
179 unsigned int suncore_mouse_baud_cflag_next(unsigned int cflag, int *new_baud)
181 int i;
183 for (i = 0; mouse_baud_table[i].baud != -1; i++)
184 if (mouse_baud_table[i].cflag == (cflag & CBAUD))
185 break;
187 i += 1;
188 if (mouse_baud_table[i].baud == -1)
189 i = 0;
191 *new_baud = mouse_baud_table[i].baud;
192 return mouse_baud_table[i].cflag;
195 EXPORT_SYMBOL(suncore_mouse_baud_cflag_next);
197 /* Basically, when the baud rate is wrong the mouse spits out
198 * breaks to us.
200 int suncore_mouse_baud_detection(unsigned char ch, int is_break)
202 static int mouse_got_break = 0;
203 static int ctr = 0;
205 if (is_break) {
206 /* Let a few normal bytes go by before we jump the gun
207 * and say we need to try another baud rate.
209 if (mouse_got_break && ctr < 8)
210 return 1;
212 /* Ok, we need to try another baud. */
213 ctr = 0;
214 mouse_got_break = 1;
215 return 2;
217 if (mouse_got_break) {
218 ctr++;
219 if (ch == 0x87) {
220 /* Correct baud rate determined. */
221 mouse_got_break = 0;
223 return 1;
225 return 0;
228 EXPORT_SYMBOL(suncore_mouse_baud_detection);
230 static int __init suncore_init(void)
232 return 0;
235 static void __exit suncore_exit(void)
239 module_init(suncore_init);
240 module_exit(suncore_exit);
242 MODULE_AUTHOR("Eddie C. Dost, David S. Miller");
243 MODULE_DESCRIPTION("Sun serial common layer");
244 MODULE_LICENSE("GPL");