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>
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
)
35 if (!con
|| of_console_device
!= dp
)
39 if (of_console_options
&&
40 *of_console_options
== 'b')
43 if ((line
& 1) != off
)
48 add_preferred_console(con
->name
, line
, NULL
);
52 EXPORT_SYMBOL(sunserial_console_match
);
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
;
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
);
69 mode
= "115200,8,n,1,-";
74 if (of_console_options
)
75 c
= *of_console_options
;
79 mode
= of_get_property(dp
, mode_prop
, NULL
);
81 mode
= "9600,8,n,1,-";
84 cflag
= CREAD
| HUPCL
| CLOCAL
;
87 baud
= simple_strtoul(s
, NULL
, 0);
89 bits
= simple_strtoul(++s
, NULL
, 0);
93 stop
= simple_strtoul(++s
, NULL
, 0);
95 /* XXX handshake is not handled here. */
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;
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;
123 case 'o': cflag
|= (PARENB
| PARODD
); break;
124 case 'e': cflag
|= PARENB
; break;
125 case 'n': default: break;
129 case 2: cflag
|= CSTOPB
; break;
130 case 1: default: break;
136 EXPORT_SYMBOL(sunserial_console_termios
);
138 /* Sun serial MOUSE auto baud rate detection. */
139 static struct mouse_baud_cflag
{
142 } mouse_baud_table
[] = {
151 unsigned int suncore_mouse_baud_cflag_next(unsigned int cflag
, int *new_baud
)
155 for (i
= 0; mouse_baud_table
[i
].baud
!= -1; i
++)
156 if (mouse_baud_table
[i
].cflag
== (cflag
& CBAUD
))
160 if (mouse_baud_table
[i
].baud
== -1)
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
172 int suncore_mouse_baud_detection(unsigned char ch
, int is_break
)
174 static int mouse_got_break
= 0;
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)
184 /* Ok, we need to try another baud. */
189 if (mouse_got_break
) {
192 /* Correct baud rate determined. */
200 EXPORT_SYMBOL(suncore_mouse_baud_detection
);
202 static int __init
suncore_init(void)
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");