[PATCH] drivers/net/wireless/libertas/cmd.c: fix adapter->driver_lock dereference
[linux-2.6/mini2440.git] / drivers / serial / suncore.c
blob70a09a3d5af0ee6999b98a57d766f4420688d94c
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 int sunserial_current_minor = 64;
28 EXPORT_SYMBOL(sunserial_current_minor);
30 int sunserial_console_match(struct console *con, struct device_node *dp,
31 struct uart_driver *drv, int line)
33 int off;
35 if (!con || of_console_device != dp)
36 return 0;
38 off = 0;
39 if (of_console_options &&
40 *of_console_options == 'b')
41 off = 1;
43 if ((line & 1) != off)
44 return 0;
46 con->index = line;
47 drv->cons = con;
48 add_preferred_console(con->name, line, NULL);
50 return 1;
52 EXPORT_SYMBOL(sunserial_console_match);
54 void
55 sunserial_console_termios(struct console *con)
57 struct device_node *dp;
58 const char *od, *mode, *s;
59 char mode_prop[] = "ttyX-mode";
60 int baud, bits, stop, cflag;
61 char parity;
63 dp = of_find_node_by_path("/options");
64 od = of_get_property(dp, "output-device", NULL);
65 if (!strcmp(od, "rsc")) {
66 mode = of_get_property(of_console_device,
67 "ssp-console-modes", NULL);
68 if (!mode)
69 mode = "115200,8,n,1,-";
70 } else {
71 char c;
73 c = 'a';
74 if (of_console_options)
75 c = *of_console_options;
77 mode_prop[3] = c;
79 mode = of_get_property(dp, mode_prop, NULL);
80 if (!mode)
81 mode = "9600,8,n,1,-";
84 cflag = CREAD | HUPCL | CLOCAL;
86 s = mode;
87 baud = simple_strtoul(s, NULL, 0);
88 s = strchr(s, ',');
89 bits = simple_strtoul(++s, NULL, 0);
90 s = strchr(s, ',');
91 parity = *(++s);
92 s = strchr(s, ',');
93 stop = simple_strtoul(++s, NULL, 0);
94 s = strchr(s, ',');
95 /* XXX handshake is not handled here. */
97 switch (baud) {
98 case 150: cflag |= B150; break;
99 case 300: cflag |= B300; break;
100 case 600: cflag |= B600; break;
101 case 1200: cflag |= B1200; break;
102 case 2400: cflag |= B2400; break;
103 case 4800: cflag |= B4800; break;
104 case 9600: cflag |= B9600; break;
105 case 19200: cflag |= B19200; break;
106 case 38400: cflag |= B38400; break;
107 case 57600: cflag |= B57600; break;
108 case 115200: cflag |= B115200; break;
109 case 230400: cflag |= B230400; break;
110 case 460800: cflag |= B460800; break;
111 default: baud = 9600; cflag |= B9600; break;
114 switch (bits) {
115 case 5: cflag |= CS5; break;
116 case 6: cflag |= CS6; break;
117 case 7: cflag |= CS7; break;
118 case 8: cflag |= CS8; break;
119 default: cflag |= CS8; break;
122 switch (parity) {
123 case 'o': cflag |= (PARENB | PARODD); break;
124 case 'e': cflag |= PARENB; break;
125 case 'n': default: break;
128 switch (stop) {
129 case 2: cflag |= CSTOPB; break;
130 case 1: default: break;
133 con->cflag = cflag;
136 EXPORT_SYMBOL(sunserial_console_termios);
138 /* Sun serial MOUSE auto baud rate detection. */
139 static struct mouse_baud_cflag {
140 int baud;
141 unsigned int cflag;
142 } mouse_baud_table[] = {
143 { 1200, B1200 },
144 { 2400, B2400 },
145 { 4800, B4800 },
146 { 9600, B9600 },
147 { -1, ~0 },
148 { -1, ~0 },
151 unsigned int suncore_mouse_baud_cflag_next(unsigned int cflag, int *new_baud)
153 int i;
155 for (i = 0; mouse_baud_table[i].baud != -1; i++)
156 if (mouse_baud_table[i].cflag == (cflag & CBAUD))
157 break;
159 i += 1;
160 if (mouse_baud_table[i].baud == -1)
161 i = 0;
163 *new_baud = mouse_baud_table[i].baud;
164 return mouse_baud_table[i].cflag;
167 EXPORT_SYMBOL(suncore_mouse_baud_cflag_next);
169 /* Basically, when the baud rate is wrong the mouse spits out
170 * breaks to us.
172 int suncore_mouse_baud_detection(unsigned char ch, int is_break)
174 static int mouse_got_break = 0;
175 static int ctr = 0;
177 if (is_break) {
178 /* Let a few normal bytes go by before we jump the gun
179 * and say we need to try another baud rate.
181 if (mouse_got_break && ctr < 8)
182 return 1;
184 /* Ok, we need to try another baud. */
185 ctr = 0;
186 mouse_got_break = 1;
187 return 2;
189 if (mouse_got_break) {
190 ctr++;
191 if (ch == 0x87) {
192 /* Correct baud rate determined. */
193 mouse_got_break = 0;
195 return 1;
197 return 0;
200 EXPORT_SYMBOL(suncore_mouse_baud_detection);
202 static int __init suncore_init(void)
204 return 0;
207 static void __exit suncore_exit(void)
211 module_init(suncore_init);
212 module_exit(suncore_exit);
214 MODULE_AUTHOR("Eddie C. Dost, David S. Miller");
215 MODULE_DESCRIPTION("Sun serial common layer");
216 MODULE_LICENSE("GPL");