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/init.h>
21 #include <asm/oplib.h>
25 int sunserial_current_minor
= 64;
27 EXPORT_SYMBOL(sunserial_current_minor
);
30 sunserial_console_termios(struct console
*con
)
32 char mode
[16], buf
[16], *s
;
33 char *mode_prop
= "ttyX-mode";
34 char *cd_prop
= "ttyX-ignore-cd";
35 char *dtr_prop
= "ttyX-rts-dtr-off";
36 char *ssp_console_modes_prop
= "ssp-console-modes";
37 int baud
, bits
, stop
, cflag
;
46 switch (serial_console
) {
61 nd
= prom_pathtoinode("rsc");
63 strcpy(mode
, "115200,8,n,1,-");
67 if (!prom_node_has_property(nd
, ssp_console_modes_prop
)) {
68 strcpy(mode
, "115200,8,n,1,-");
72 memset(mode
, 0, sizeof(mode
));
73 prom_getstring(nd
, ssp_console_modes_prop
, mode
, sizeof(mode
));
77 strcpy(mode
, "9600,8,n,1,-");
81 topnd
= prom_getchild(prom_root_node
);
82 nd
= prom_searchsiblings(topnd
, "options");
84 strcpy(mode
, "9600,8,n,1,-");
88 if (!prom_node_has_property(nd
, mode_prop
)) {
89 strcpy(mode
, "9600,8,n,1,-");
93 memset(mode
, 0, sizeof(mode
));
94 prom_getstring(nd
, mode_prop
, mode
, sizeof(mode
));
96 if (prom_node_has_property(nd
, cd_prop
)) {
97 memset(buf
, 0, sizeof(buf
));
98 prom_getstring(nd
, cd_prop
, buf
, sizeof(buf
));
99 if (!strcmp(buf
, "false"))
102 /* XXX: this is unused below. */
105 if (prom_node_has_property(nd
, dtr_prop
)) {
106 memset(buf
, 0, sizeof(buf
));
107 prom_getstring(nd
, dtr_prop
, buf
, sizeof(buf
));
108 if (!strcmp(buf
, "false"))
111 /* XXX: this is unused below. */
115 cflag
= CREAD
| HUPCL
| CLOCAL
;
118 baud
= simple_strtoul(s
, NULL
, 0);
120 bits
= simple_strtoul(++s
, NULL
, 0);
124 stop
= simple_strtoul(++s
, NULL
, 0);
126 /* XXX handshake is not handled here. */
129 case 150: cflag
|= B150
; break;
130 case 300: cflag
|= B300
; break;
131 case 600: cflag
|= B600
; break;
132 case 1200: cflag
|= B1200
; break;
133 case 2400: cflag
|= B2400
; break;
134 case 4800: cflag
|= B4800
; break;
135 case 9600: cflag
|= B9600
; break;
136 case 19200: cflag
|= B19200
; break;
137 case 38400: cflag
|= B38400
; break;
138 case 57600: cflag
|= B57600
; break;
139 case 115200: cflag
|= B115200
; break;
140 case 230400: cflag
|= B230400
; break;
141 case 460800: cflag
|= B460800
; break;
142 default: baud
= 9600; cflag
|= B9600
; break;
146 case 5: cflag
|= CS5
; break;
147 case 6: cflag
|= CS6
; break;
148 case 7: cflag
|= CS7
; break;
149 case 8: cflag
|= CS8
; break;
150 default: cflag
|= CS8
; break;
154 case 'o': cflag
|= (PARENB
| PARODD
); break;
155 case 'e': cflag
|= PARENB
; break;
156 case 'n': default: break;
160 case 2: cflag
|= CSTOPB
; break;
161 case 1: default: break;
167 EXPORT_SYMBOL(sunserial_console_termios
);
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)
238 static void __exit
suncore_exit(void)
242 module_init(suncore_init
);
243 module_exit(suncore_exit
);
245 MODULE_AUTHOR("Eddie C. Dost, David S. Miller");
246 MODULE_DESCRIPTION("Sun serial common layer");
247 MODULE_LICENSE("GPL");