Merge branch 'for-linus-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/mason...
[deliverable/linux.git] / drivers / tty / serial / 68328serial.c
CommitLineData
1da177e4
LT
1/* 68328serial.c: Serial port driver for 68328 microcontroller
2 *
3 * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu>
4 * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
5 * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org>
6 * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com>
7 * Copyright (C) 2002-2003 David McCullough <davidm@snapgear.com>
8 * Copyright (C) 2002 Greg Ungerer <gerg@snapgear.com>
9 *
10 * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca>
11 * Multiple UART support Daniel Potts <danielp@cse.unsw.edu.au>
12 * Power management support Daniel Potts <danielp@cse.unsw.edu.au>
13 * VZ Second Serial Port enable Phil Wilshire
14 * 2.4/2.5 port David McCullough
15 */
16
1da177e4
LT
17#include <linux/module.h>
18#include <linux/errno.h>
cea4b2ce 19#include <linux/serial.h>
1da177e4
LT
20#include <linux/signal.h>
21#include <linux/sched.h>
22#include <linux/timer.h>
23#include <linux/interrupt.h>
24#include <linux/tty.h>
25#include <linux/tty_flip.h>
1da177e4
LT
26#include <linux/major.h>
27#include <linux/string.h>
28#include <linux/fcntl.h>
29#include <linux/mm.h>
30#include <linux/kernel.h>
31#include <linux/console.h>
32#include <linux/reboot.h>
33#include <linux/keyboard.h>
34#include <linux/init.h>
35#include <linux/pm.h>
36#include <linux/bitops.h>
37#include <linux/delay.h>
5a0e3ad6 38#include <linux/gfp.h>
1da177e4
LT
39
40#include <asm/io.h>
41#include <asm/irq.h>
1da177e4
LT
42#include <asm/delay.h>
43#include <asm/uaccess.h>
44
45/* (es) */
46/* note: perhaps we can murge these files, so that you can just
47 * define 1 of them, and they can sort that out for themselves
48 */
49#if defined(CONFIG_M68EZ328)
50#include <asm/MC68EZ328.h>
51#else
52#if defined(CONFIG_M68VZ328)
53#include <asm/MC68VZ328.h>
54#else
55#include <asm/MC68328.h>
56#endif /* CONFIG_M68VZ328 */
57#endif /* CONFIG_M68EZ328 */
58
1da177e4
LT
59/* Turn off usage of real serial interrupt code, to "support" Copilot */
60#ifdef CONFIG_XCOPILOT_BUGS
61#undef USE_INTS
62#else
63#define USE_INTS
64#endif
65
1bb2687c
JS
66/*
67 * I believe this is the optimal setting that reduces the number of interrupts.
68 * At high speeds the output might become a little "bursted" (use USTCNT_TXHE
69 * if that bothers you), but in most cases it will not, since we try to
70 * transmit characters every time rs_interrupt is called. Thus, quite often
71 * you'll see that a receive interrupt occures before the transmit one.
72 * -- Vladimir Gurevich
73 */
74#define USTCNT_TX_INTR_MASK (USTCNT_TXEE)
75
76/*
77 * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special
78 * "Old data interrupt" which occures whenever the data stay in the FIFO
79 * longer than 30 bits time. This allows us to use FIFO without compromising
80 * latency. '328 does not have this feature and without the real 328-based
81 * board I would assume that RXRE is the safest setting.
82 *
83 * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of
84 * interrupts. RXFE (receive queue full) causes the system to lose data
85 * at least at 115200 baud
86 *
87 * If your board is busy doing other stuff, you might consider to use
88 * RXRE (data ready intrrupt) instead.
89 *
90 * The other option is to make these INTR masks run-time configurable, so
91 * that people can dynamically adapt them according to the current usage.
92 * -- Vladimir Gurevich
93 */
94
95/* (es) */
96#if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)
97#define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)
98#elif defined(CONFIG_M68328)
99#define USTCNT_RX_INTR_MASK (USTCNT_RXRE)
100#else
101#error Please, define the Rx interrupt events for your CPU
102#endif
103/* (/es) */
104
105/*
106 * This is our internal structure for each serial port's state.
1bb2687c
JS
107 */
108struct m68k_serial {
86264341 109 struct tty_port tport;
1bb2687c
JS
110 char is_cons; /* Is this our console. */
111 int magic;
112 int baud_base;
113 int port;
114 int irq;
1bb2687c 115 int type; /* UART type */
1bb2687c
JS
116 int custom_divisor;
117 int x_char; /* xon/xoff character */
1bb2687c 118 int line;
1bb2687c
JS
119 unsigned char *xmit_buf;
120 int xmit_head;
121 int xmit_tail;
122 int xmit_cnt;
1bb2687c
JS
123};
124
125#define SERIAL_MAGIC 0x5301
126
127/*
128 * Define the number of ports supported and their irqs.
129 */
130#define NR_PORTS 1
131
1da177e4 132static struct m68k_serial m68k_soft[NR_PORTS];
1da177e4 133
1bb2687c 134static unsigned int uart_irqs[NR_PORTS] = { UART_IRQ_NUM };
1da177e4
LT
135
136/* multiple ports are contiguous in memory */
137m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR;
138
1da177e4
LT
139struct tty_driver *serial_driver;
140
467712c9 141static void change_speed(struct m68k_serial *info, struct tty_struct *tty);
1da177e4
LT
142
143/*
144 * Setup for console. Argument comes from the boot command line.
145 */
146
f5e92c3f
CE
147/* note: this is messy, but it works, again, perhaps defined somewhere else?*/
148#ifdef CONFIG_M68VZ328
149#define CONSOLE_BAUD_RATE 19200
150#define DEFAULT_CBAUD B19200
1da177e4
LT
151#endif
152
f5e92c3f 153
1da177e4
LT
154#ifndef CONSOLE_BAUD_RATE
155#define CONSOLE_BAUD_RATE 9600
156#define DEFAULT_CBAUD B9600
157#endif
158
159
e836ed7a 160static int m68328_console_initted;
1da177e4
LT
161static int m68328_console_baud = CONSOLE_BAUD_RATE;
162static int m68328_console_cbaud = DEFAULT_CBAUD;
163
164
1da177e4
LT
165static inline int serial_paranoia_check(struct m68k_serial *info,
166 char *name, const char *routine)
167{
168#ifdef SERIAL_PARANOIA_CHECK
169 static const char *badmagic =
170 "Warning: bad magic number for serial struct %s in %s\n";
171 static const char *badinfo =
172 "Warning: null m68k_serial for %s in %s\n";
173
174 if (!info) {
175 printk(badinfo, name, routine);
176 return 1;
177 }
178 if (info->magic != SERIAL_MAGIC) {
179 printk(badmagic, name, routine);
180 return 1;
181 }
182#endif
183 return 0;
184}
185
186/*
187 * This is used to figure out the divisor speeds and the timeouts
188 */
189static int baud_table[] = {
190 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
191 9600, 19200, 38400, 57600, 115200, 0 };
192
1da177e4
LT
193/* Utility routines */
194static inline int get_baud(struct m68k_serial *ss)
195{
196 unsigned long result = 115200;
197 unsigned short int baud = uart_addr[ss->line].ubaud;
198 if (GET_FIELD(baud, UBAUD_PRESCALER) == 0x38) result = 38400;
199 result >>= GET_FIELD(baud, UBAUD_DIVIDE);
200
201 return result;
202}
203
204/*
205 * ------------------------------------------------------------
206 * rs_stop() and rs_start()
207 *
208 * This routines are called before setting or resetting tty->stopped.
209 * They enable or disable transmitter interrupts, as necessary.
210 * ------------------------------------------------------------
211 */
212static void rs_stop(struct tty_struct *tty)
213{
214 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
215 m68328_uart *uart = &uart_addr[info->line];
216 unsigned long flags;
217
218 if (serial_paranoia_check(info, tty->name, "rs_stop"))
219 return;
220
727dda80 221 local_irq_save(flags);
1da177e4 222 uart->ustcnt &= ~USTCNT_TXEN;
727dda80 223 local_irq_restore(flags);
1da177e4
LT
224}
225
09a6ffa8 226static int rs_put_char(char ch)
1da177e4 227{
107afb7a
JS
228 unsigned long flags;
229 int loops = 0;
1da177e4 230
727dda80 231 local_irq_save(flags);
1da177e4
LT
232
233 while (!(UTX & UTX_TX_AVAIL) && (loops < 1000)) {
234 loops++;
235 udelay(5);
236 }
237
238 UTX_TXDATA = ch;
239 udelay(5);
727dda80 240 local_irq_restore(flags);
09a6ffa8 241 return 1;
1da177e4
LT
242}
243
244static void rs_start(struct tty_struct *tty)
245{
246 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
247 m68328_uart *uart = &uart_addr[info->line];
248 unsigned long flags;
249
250 if (serial_paranoia_check(info, tty->name, "rs_start"))
251 return;
252
727dda80 253 local_irq_save(flags);
1da177e4
LT
254 if (info->xmit_cnt && info->xmit_buf && !(uart->ustcnt & USTCNT_TXEN)) {
255#ifdef USE_INTS
256 uart->ustcnt |= USTCNT_TXEN | USTCNT_TX_INTR_MASK;
257#else
258 uart->ustcnt |= USTCNT_TXEN;
259#endif
260 }
727dda80 261 local_irq_restore(flags);
1da177e4
LT
262}
263
6732c8bb 264static void receive_chars(struct m68k_serial *info, unsigned short rx)
1da177e4 265{
1da177e4 266 m68328_uart *uart = &uart_addr[info->line];
33f0f88f 267 unsigned char ch, flag;
1da177e4
LT
268
269 /*
270 * This do { } while() loop will get ALL chars out of Rx FIFO
271 */
272#ifndef CONFIG_XCOPILOT_BUGS
273 do {
274#endif
275 ch = GET_FIELD(rx, URX_RXDATA);
276
ba4f10ae
FV
277 if (info->is_cons) {
278 if (URX_BREAK & rx) { /* whee, break received */
1da177e4
LT
279 return;
280#ifdef CONFIG_MAGIC_SYSRQ
281 } else if (ch == 0x10) { /* ^P */
282 show_state();
7bf02ea2 283 show_free_areas(0);
1da177e4
LT
284 show_buffers();
285/* show_net_buffers(); */
286 return;
287 } else if (ch == 0x12) { /* ^R */
804ebf46 288 emergency_restart();
1da177e4
LT
289 return;
290#endif /* CONFIG_MAGIC_SYSRQ */
291 }
1da177e4
LT
292 }
293
33f0f88f
AC
294 flag = TTY_NORMAL;
295
c21e2654 296 if (rx & URX_PARITY_ERROR)
33f0f88f 297 flag = TTY_PARITY;
c21e2654 298 else if (rx & URX_OVRUN)
33f0f88f 299 flag = TTY_OVERRUN;
c21e2654 300 else if (rx & URX_FRAME_ERROR)
33f0f88f 301 flag = TTY_FRAME;
c21e2654 302
92a19f9c 303 tty_insert_flip_char(&info->tport, ch, flag);
1da177e4 304#ifndef CONFIG_XCOPILOT_BUGS
ba4f10ae 305 } while ((rx = uart->urx.w) & URX_DATA_READY);
1da177e4
LT
306#endif
307
6732c8bb 308 tty_schedule_flip(&info->tport);
1da177e4
LT
309}
310
467712c9 311static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty)
1da177e4
LT
312{
313 m68328_uart *uart = &uart_addr[info->line];
314
315 if (info->x_char) {
316 /* Send next char */
317 uart->utx.b.txdata = info->x_char;
318 info->x_char = 0;
319 goto clear_and_return;
320 }
321
467712c9 322 if ((info->xmit_cnt <= 0) || !tty || tty->stopped) {
1da177e4
LT
323 /* That's peculiar... TX ints off */
324 uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
325 goto clear_and_return;
326 }
327
328 /* Send char */
329 uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
330 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
331 info->xmit_cnt--;
332
ba4f10ae 333 if (info->xmit_cnt <= 0) {
1da177e4
LT
334 /* All done for now... TX ints off */
335 uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
336 goto clear_and_return;
337 }
338
339clear_and_return:
340 /* Clear interrupt (should be auto)*/
341 return;
342}
343
344/*
345 * This is the serial driver's generic interrupt routine
346 */
7d12e780 347irqreturn_t rs_interrupt(int irq, void *dev_id)
1da177e4 348{
25db8ad5 349 struct m68k_serial *info = dev_id;
665569d0 350 struct tty_struct *tty = tty_port_tty_get(&info->tport);
1da177e4
LT
351 m68328_uart *uart;
352 unsigned short rx;
353 unsigned short tx;
354
1da177e4
LT
355 uart = &uart_addr[info->line];
356 rx = uart->urx.w;
357
358#ifdef USE_INTS
359 tx = uart->utx.w;
360
467712c9 361 if (rx & URX_DATA_READY)
6732c8bb 362 receive_chars(info, rx);
467712c9
JS
363 if (tx & UTX_TX_AVAIL)
364 transmit_chars(info, tty);
1da177e4 365#else
6732c8bb 366 receive_chars(info, rx);
1da177e4 367#endif
665569d0
JS
368 tty_kref_put(tty);
369
1da177e4
LT
370 return IRQ_HANDLED;
371}
372
467712c9 373static int startup(struct m68k_serial *info, struct tty_struct *tty)
1da177e4
LT
374{
375 m68328_uart *uart = &uart_addr[info->line];
376 unsigned long flags;
377
a85dd82c 378 if (info->tport.flags & ASYNC_INITIALIZED)
1da177e4
LT
379 return 0;
380
381 if (!info->xmit_buf) {
382 info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
383 if (!info->xmit_buf)
384 return -ENOMEM;
385 }
386
727dda80 387 local_irq_save(flags);
1da177e4
LT
388
389 /*
390 * Clear the FIFO buffers and disable them
391 * (they will be reenabled in change_speed())
392 */
393
394 uart->ustcnt = USTCNT_UEN;
1da177e4
LT
395 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN;
396 (void)uart->urx.w;
397
398 /*
399 * Finally, enable sequencing and interrupts
400 */
401#ifdef USE_INTS
402 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN |
403 USTCNT_RX_INTR_MASK | USTCNT_TX_INTR_MASK;
404#else
405 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK;
406#endif
407
467712c9
JS
408 if (tty)
409 clear_bit(TTY_IO_ERROR, &tty->flags);
1da177e4
LT
410 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
411
412 /*
413 * and set the speed of the serial port
414 */
415
467712c9 416 change_speed(info, tty);
1da177e4 417
a85dd82c 418 info->tport.flags |= ASYNC_INITIALIZED;
727dda80 419 local_irq_restore(flags);
1da177e4
LT
420 return 0;
421}
422
423/*
424 * This routine will shutdown a serial port; interrupts are disabled, and
425 * DTR is dropped if the hangup on close termio flag is on.
426 */
467712c9 427static void shutdown(struct m68k_serial *info, struct tty_struct *tty)
1da177e4
LT
428{
429 m68328_uart *uart = &uart_addr[info->line];
430 unsigned long flags;
431
432 uart->ustcnt = 0; /* All off! */
a85dd82c 433 if (!(info->tport.flags & ASYNC_INITIALIZED))
1da177e4
LT
434 return;
435
727dda80 436 local_irq_save(flags);
1da177e4
LT
437
438 if (info->xmit_buf) {
439 free_page((unsigned long) info->xmit_buf);
440 info->xmit_buf = 0;
441 }
442
467712c9
JS
443 if (tty)
444 set_bit(TTY_IO_ERROR, &tty->flags);
1da177e4 445
a85dd82c 446 info->tport.flags &= ~ASYNC_INITIALIZED;
727dda80 447 local_irq_restore(flags);
1da177e4
LT
448}
449
450struct {
451 int divisor, prescale;
452}
453#ifndef CONFIG_M68VZ328
454 hw_baud_table[18] = {
ba4f10ae
FV
455 {0, 0}, /* 0 */
456 {0, 0}, /* 50 */
457 {0, 0}, /* 75 */
458 {0, 0}, /* 110 */
459 {0, 0}, /* 134 */
460 {0, 0}, /* 150 */
461 {0, 0}, /* 200 */
462 {7, 0x26}, /* 300 */
463 {6, 0x26}, /* 600 */
464 {5, 0x26}, /* 1200 */
465 {0, 0}, /* 1800 */
466 {4, 0x26}, /* 2400 */
467 {3, 0x26}, /* 4800 */
468 {2, 0x26}, /* 9600 */
469 {1, 0x26}, /* 19200 */
470 {0, 0x26}, /* 38400 */
471 {1, 0x38}, /* 57600 */
472 {0, 0x38}, /* 115200 */
1da177e4
LT
473};
474#else
475 hw_baud_table[18] = {
ba4f10ae
FV
476 {0, 0}, /* 0 */
477 {0, 0}, /* 50 */
478 {0, 0}, /* 75 */
479 {0, 0}, /* 110 */
480 {0, 0}, /* 134 */
481 {0, 0}, /* 150 */
482 {0, 0}, /* 200 */
483 {0, 0}, /* 300 */
484 {7, 0x26}, /* 600 */
485 {6, 0x26}, /* 1200 */
486 {0, 0}, /* 1800 */
487 {5, 0x26}, /* 2400 */
488 {4, 0x26}, /* 4800 */
489 {3, 0x26}, /* 9600 */
490 {2, 0x26}, /* 19200 */
491 {1, 0x26}, /* 38400 */
492 {0, 0x26}, /* 57600 */
493 {1, 0x38}, /* 115200 */
1da177e4
LT
494};
495#endif
496/* rate = 1036800 / ((65 - prescale) * (1<<divider)) */
497
498/*
499 * This routine is called to set the UART divisor registers to match
500 * the specified baud rate for a serial port.
501 */
467712c9 502static void change_speed(struct m68k_serial *info, struct tty_struct *tty)
1da177e4
LT
503{
504 m68328_uart *uart = &uart_addr[info->line];
505 unsigned short port;
506 unsigned short ustcnt;
507 unsigned cflag;
508 int i;
509
3dd332c5 510 cflag = tty->termios.c_cflag;
ed334c0e
GKH
511 port = info->port;
512 if (!port)
1da177e4
LT
513 return;
514
515 ustcnt = uart->ustcnt;
516 uart->ustcnt = ustcnt & ~USTCNT_TXEN;
517
518 i = cflag & CBAUD;
519 if (i & CBAUDEX) {
520 i = (i & ~CBAUDEX) + B38400;
521 }
522
1da177e4
LT
523 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
524 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
525
526 ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7);
527
528 if ((cflag & CSIZE) == CS8)
529 ustcnt |= USTCNT_8_7;
530
531 if (cflag & CSTOPB)
532 ustcnt |= USTCNT_STOP;
533
534 if (cflag & PARENB)
535 ustcnt |= USTCNT_PARITYEN;
536 if (cflag & PARODD)
537 ustcnt |= USTCNT_ODD_EVEN;
538
539#ifdef CONFIG_SERIAL_68328_RTS_CTS
540 if (cflag & CRTSCTS) {
4b7bb2b2 541 uart->utx.w &= ~UTX_NOCTS;
1da177e4
LT
542 } else {
543 uart->utx.w |= UTX_NOCTS;
544 }
545#endif
546
547 ustcnt |= USTCNT_TXEN;
548
549 uart->ustcnt = ustcnt;
550 return;
551}
552
553/*
554 * Fair output driver allows a process to speak.
555 */
556static void rs_fair_output(void)
557{
558 int left; /* Output no more than that */
559 unsigned long flags;
560 struct m68k_serial *info = &m68k_soft[0];
561 char c;
562
74013496
FE
563 if (info == NULL) return;
564 if (info->xmit_buf == NULL) return;
1da177e4 565
727dda80 566 local_irq_save(flags);
1da177e4
LT
567 left = info->xmit_cnt;
568 while (left != 0) {
569 c = info->xmit_buf[info->xmit_tail];
570 info->xmit_tail = (info->xmit_tail+1) & (SERIAL_XMIT_SIZE-1);
571 info->xmit_cnt--;
727dda80 572 local_irq_restore(flags);
1da177e4
LT
573
574 rs_put_char(c);
575
727dda80 576 local_irq_save(flags);
1da177e4
LT
577 left = min(info->xmit_cnt, left-1);
578 }
579
580 /* Last character is being transmitted now (hopefully). */
581 udelay(5);
582
727dda80 583 local_irq_restore(flags);
1da177e4
LT
584 return;
585}
586
587/*
588 * m68k_console_print is registered for printk.
589 */
590void console_print_68328(const char *p)
591{
592 char c;
593
ba4f10ae
FV
594 while ((c = *(p++)) != 0) {
595 if (c == '\n')
1da177e4
LT
596 rs_put_char('\r');
597 rs_put_char(c);
598 }
599
600 /* Comment this if you want to have a strict interrupt-driven output */
601 rs_fair_output();
602
603 return;
604}
605
606static void rs_set_ldisc(struct tty_struct *tty)
607{
608 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
609
610 if (serial_paranoia_check(info, tty->name, "rs_set_ldisc"))
611 return;
612
3dd332c5 613 info->is_cons = (tty->termios.c_line == N_TTY);
1da177e4
LT
614
615 printk("ttyS%d console mode %s\n", info->line, info->is_cons ? "on" : "off");
616}
617
618static void rs_flush_chars(struct tty_struct *tty)
619{
620 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
621 m68328_uart *uart = &uart_addr[info->line];
622 unsigned long flags;
623
624 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
625 return;
626#ifndef USE_INTS
ba4f10ae 627 for (;;) {
1da177e4
LT
628#endif
629
630 /* Enable transmitter */
727dda80 631 local_irq_save(flags);
1da177e4 632
ee797069 633 if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf) {
727dda80 634 local_irq_restore(flags);
1da177e4
LT
635 return;
636 }
637
638#ifdef USE_INTS
639 uart->ustcnt |= USTCNT_TXEN | USTCNT_TX_INTR_MASK;
640#else
641 uart->ustcnt |= USTCNT_TXEN;
642#endif
643
644#ifdef USE_INTS
645 if (uart->utx.w & UTX_TX_AVAIL) {
646#else
647 if (1) {
648#endif
649 /* Send char */
650 uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
651 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
652 info->xmit_cnt--;
653 }
654
655#ifndef USE_INTS
656 while (!(uart->utx.w & UTX_TX_AVAIL)) udelay(5);
657 }
658#endif
727dda80 659 local_irq_restore(flags);
1da177e4
LT
660}
661
2ababf9e 662extern void console_printn(const char *b, int count);
1da177e4 663
2ababf9e 664static int rs_write(struct tty_struct *tty,
1da177e4
LT
665 const unsigned char *buf, int count)
666{
667 int c, total = 0;
668 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
669 m68328_uart *uart = &uart_addr[info->line];
670 unsigned long flags;
671
672 if (serial_paranoia_check(info, tty->name, "rs_write"))
673 return 0;
674
675 if (!tty || !info->xmit_buf)
676 return 0;
677
727dda80 678 local_save_flags(flags);
1da177e4 679 while (1) {
727dda80 680 local_irq_disable();
1da177e4
LT
681 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
682 SERIAL_XMIT_SIZE - info->xmit_head));
727dda80
GU
683 local_irq_restore(flags);
684
1da177e4
LT
685 if (c <= 0)
686 break;
687
688 memcpy(info->xmit_buf + info->xmit_head, buf, c);
727dda80
GU
689
690 local_irq_disable();
1da177e4
LT
691 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
692 info->xmit_cnt += c;
727dda80 693 local_irq_restore(flags);
1da177e4
LT
694 buf += c;
695 count -= c;
696 total += c;
697 }
698
ee797069 699 if (info->xmit_cnt && !tty->stopped) {
1da177e4 700 /* Enable transmitter */
727dda80 701 local_irq_disable();
1da177e4 702#ifndef USE_INTS
ba4f10ae 703 while (info->xmit_cnt) {
1da177e4
LT
704#endif
705
706 uart->ustcnt |= USTCNT_TXEN;
707#ifdef USE_INTS
708 uart->ustcnt |= USTCNT_TX_INTR_MASK;
709#else
710 while (!(uart->utx.w & UTX_TX_AVAIL)) udelay(5);
711#endif
712 if (uart->utx.w & UTX_TX_AVAIL) {
713 uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
714 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
715 info->xmit_cnt--;
716 }
717
718#ifndef USE_INTS
719 }
720#endif
727dda80 721 local_irq_restore(flags);
1da177e4 722 }
727dda80 723
1da177e4
LT
724 return total;
725}
726
727static int rs_write_room(struct tty_struct *tty)
728{
729 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
730 int ret;
731
732 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
733 return 0;
734 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
735 if (ret < 0)
736 ret = 0;
737 return ret;
738}
739
740static int rs_chars_in_buffer(struct tty_struct *tty)
741{
742 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
743
744 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
745 return 0;
746 return info->xmit_cnt;
747}
748
749static void rs_flush_buffer(struct tty_struct *tty)
750{
751 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
727dda80 752 unsigned long flags;
1da177e4
LT
753
754 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
755 return;
727dda80 756 local_irq_save(flags);
1da177e4 757 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
727dda80 758 local_irq_restore(flags);
1da177e4
LT
759 tty_wakeup(tty);
760}
761
762/*
763 * ------------------------------------------------------------
764 * rs_throttle()
765 *
766 * This routine is called by the upper-layer tty layer to signal that
767 * incoming characters should be throttled.
768 * ------------------------------------------------------------
769 */
2ababf9e 770static void rs_throttle(struct tty_struct *tty)
1da177e4
LT
771{
772 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
773
774 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
775 return;
776
777 if (I_IXOFF(tty))
778 info->x_char = STOP_CHAR(tty);
779
780 /* Turn off RTS line (do this atomic) */
781}
782
2ababf9e 783static void rs_unthrottle(struct tty_struct *tty)
1da177e4
LT
784{
785 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
786
787 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
788 return;
789
790 if (I_IXOFF(tty)) {
791 if (info->x_char)
792 info->x_char = 0;
793 else
794 info->x_char = START_CHAR(tty);
795 }
796
797 /* Assert RTS line (do this atomic) */
798}
799
800/*
801 * ------------------------------------------------------------
802 * rs_ioctl() and friends
803 * ------------------------------------------------------------
804 */
805
2ababf9e
FV
806static int get_serial_info(struct m68k_serial *info,
807 struct serial_struct *retinfo)
1da177e4
LT
808{
809 struct serial_struct tmp;
810
811 if (!retinfo)
812 return -EFAULT;
813 memset(&tmp, 0, sizeof(tmp));
814 tmp.type = info->type;
815 tmp.line = info->line;
816 tmp.port = info->port;
817 tmp.irq = info->irq;
a85dd82c 818 tmp.flags = info->tport.flags;
1da177e4 819 tmp.baud_base = info->baud_base;
4a85b1fc
JS
820 tmp.close_delay = info->tport.close_delay;
821 tmp.closing_wait = info->tport.closing_wait;
1da177e4 822 tmp.custom_divisor = info->custom_divisor;
5d56356a
KV
823 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
824 return -EFAULT;
825
1da177e4
LT
826 return 0;
827}
828
467712c9 829static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty,
2ababf9e 830 struct serial_struct *new_info)
1da177e4 831{
4a85b1fc 832 struct tty_port *port = &info->tport;
1da177e4
LT
833 struct serial_struct new_serial;
834 struct m68k_serial old_info;
835 int retval = 0;
836
837 if (!new_info)
838 return -EFAULT;
5d56356a
KV
839 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
840 return -EFAULT;
1da177e4
LT
841 old_info = *info;
842
843 if (!capable(CAP_SYS_ADMIN)) {
844 if ((new_serial.baud_base != info->baud_base) ||
845 (new_serial.type != info->type) ||
4a85b1fc 846 (new_serial.close_delay != port->close_delay) ||
cea4b2ce 847 ((new_serial.flags & ~ASYNC_USR_MASK) !=
a85dd82c 848 (port->flags & ~ASYNC_USR_MASK)))
1da177e4 849 return -EPERM;
a85dd82c 850 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
cea4b2ce 851 (new_serial.flags & ASYNC_USR_MASK));
1da177e4
LT
852 info->custom_divisor = new_serial.custom_divisor;
853 goto check_and_exit;
854 }
855
4a85b1fc 856 if (port->count > 1)
1da177e4
LT
857 return -EBUSY;
858
859 /*
860 * OK, past this point, all the error checking has been done.
861 * At this point, we start making changes.....
862 */
863
864 info->baud_base = new_serial.baud_base;
a85dd82c 865 port->flags = ((port->flags & ~ASYNC_FLAGS) |
cea4b2ce 866 (new_serial.flags & ASYNC_FLAGS));
1da177e4 867 info->type = new_serial.type;
4a85b1fc
JS
868 port->close_delay = new_serial.close_delay;
869 port->closing_wait = new_serial.closing_wait;
1da177e4
LT
870
871check_and_exit:
467712c9 872 retval = startup(info, tty);
1da177e4
LT
873 return retval;
874}
875
876/*
877 * get_lsr_info - get line status register info
878 *
879 * Purpose: Let user call ioctl() to get info when the UART physically
880 * is emptied. On bus types like RS485, the transmitter must
881 * release the bus after transmitting. This must be done when
882 * the transmit shift register is empty, not be done when the
883 * transmit holding register is empty. This functionality
884 * allows an RS485 driver to be written in user space.
885 */
2ababf9e 886static int get_lsr_info(struct m68k_serial *info, unsigned int *value)
1da177e4
LT
887{
888#ifdef CONFIG_SERIAL_68328_RTS_CTS
889 m68328_uart *uart = &uart_addr[info->line];
890#endif
891 unsigned char status;
727dda80 892 unsigned long flags;
1da177e4 893
727dda80 894 local_irq_save(flags);
1da177e4
LT
895#ifdef CONFIG_SERIAL_68328_RTS_CTS
896 status = (uart->utx.w & UTX_CTS_STAT) ? 1 : 0;
897#else
898 status = 0;
899#endif
727dda80 900 local_irq_restore(flags);
5d56356a 901 return put_user(status, value);
1da177e4
LT
902}
903
904/*
905 * This routine sends a break character out the serial port.
906 */
2ababf9e 907static void send_break(struct m68k_serial *info, unsigned int duration)
1da177e4
LT
908{
909 m68328_uart *uart = &uart_addr[info->line];
910 unsigned long flags;
911 if (!info->port)
912 return;
727dda80 913 local_irq_save(flags);
1da177e4
LT
914#ifdef USE_INTS
915 uart->utx.w |= UTX_SEND_BREAK;
6a72c7ba 916 msleep_interruptible(duration);
1da177e4
LT
917 uart->utx.w &= ~UTX_SEND_BREAK;
918#endif
727dda80 919 local_irq_restore(flags);
1da177e4
LT
920}
921
6caa76b7 922static int rs_ioctl(struct tty_struct *tty,
1da177e4
LT
923 unsigned int cmd, unsigned long arg)
924{
2ababf9e 925 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
1da177e4
LT
926 int retval;
927
928 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
929 return -ENODEV;
930
931 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
932 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
933 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
934 if (tty->flags & (1 << TTY_IO_ERROR))
935 return -EIO;
936 }
937
938 switch (cmd) {
939 case TCSBRK: /* SVID version: non-zero arg --> no break */
940 retval = tty_check_change(tty);
941 if (retval)
942 return retval;
943 tty_wait_until_sent(tty, 0);
944 if (!arg)
6a72c7ba 945 send_break(info, 250); /* 1/4 second */
1da177e4
LT
946 return 0;
947 case TCSBRKP: /* support for POSIX tcsendbreak() */
948 retval = tty_check_change(tty);
949 if (retval)
950 return retval;
951 tty_wait_until_sent(tty, 0);
6a72c7ba 952 send_break(info, arg ? arg*(100) : 250);
1da177e4 953 return 0;
1da177e4 954 case TIOCGSERIAL:
5d56356a
KV
955 return get_serial_info(info,
956 (struct serial_struct *) arg);
1da177e4 957 case TIOCSSERIAL:
467712c9 958 return set_serial_info(info, tty,
1da177e4
LT
959 (struct serial_struct *) arg);
960 case TIOCSERGETLSR: /* Get line status register */
5d56356a 961 return get_lsr_info(info, (unsigned int *) arg);
1da177e4 962 case TIOCSERGSTRUCT:
5d56356a
KV
963 if (copy_to_user((struct m68k_serial *) arg,
964 info, sizeof(struct m68k_serial)))
1da177e4 965 return -EFAULT;
1da177e4 966 return 0;
1da177e4
LT
967 default:
968 return -ENOIOCTLCMD;
969 }
970 return 0;
971}
972
606d099c 973static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1da177e4
LT
974{
975 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
976
467712c9 977 change_speed(info, tty);
1da177e4
LT
978
979 if ((old_termios->c_cflag & CRTSCTS) &&
ee797069 980 !(tty->termios.c_cflag & CRTSCTS))
1da177e4 981 rs_start(tty);
1da177e4
LT
982
983}
984
985/*
986 * ------------------------------------------------------------
987 * rs_close()
988 *
989 * This routine is called when the serial port gets closed. First, we
990 * wait for the last remaining data to be sent. Then, we unlink its
991 * S structure from the interrupt chain if necessary, and we free
992 * that IRQ if nothing is left in the chain.
993 * ------------------------------------------------------------
994 */
2ababf9e 995static void rs_close(struct tty_struct *tty, struct file *filp)
1da177e4 996{
2ababf9e 997 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
86264341 998 struct tty_port *port = &info->tport;
1da177e4
LT
999 m68328_uart *uart = &uart_addr[info->line];
1000 unsigned long flags;
1001
9ef20d52 1002 if (serial_paranoia_check(info, tty->name, "rs_close"))
1da177e4
LT
1003 return;
1004
727dda80 1005 local_irq_save(flags);
1da177e4
LT
1006
1007 if (tty_hung_up_p(filp)) {
727dda80 1008 local_irq_restore(flags);
1da177e4
LT
1009 return;
1010 }
1011
86264341 1012 if ((tty->count == 1) && (port->count != 1)) {
1da177e4
LT
1013 /*
1014 * Uh, oh. tty->count is 1, which means that the tty
1015 * structure will be freed. Info->count should always
1016 * be one in these conditions. If it's greater than
1017 * one, we've got real problems, since it means the
1018 * serial port won't be shutdown.
1019 */
1020 printk("rs_close: bad serial port count; tty->count is 1, "
86264341
JS
1021 "port->count is %d\n", port->count);
1022 port->count = 1;
1da177e4 1023 }
86264341 1024 if (--port->count < 0) {
1da177e4 1025 printk("rs_close: bad serial port count for ttyS%d: %d\n",
86264341
JS
1026 info->line, port->count);
1027 port->count = 0;
1da177e4 1028 }
86264341 1029 if (port->count) {
727dda80 1030 local_irq_restore(flags);
1da177e4
LT
1031 return;
1032 }
a85dd82c 1033 port->flags |= ASYNC_CLOSING;
1da177e4
LT
1034 /*
1035 * Now we wait for the transmit buffer to clear; and we notify
1036 * the line discipline to only process XON/XOFF characters.
1037 */
1038 tty->closing = 1;
4a85b1fc
JS
1039 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1040 tty_wait_until_sent(tty, port->closing_wait);
1da177e4
LT
1041 /*
1042 * At this point we stop accepting input. To do this, we
1043 * disable the receive line status interrupts, and tell the
1044 * interrupt driver to stop checking the data ready bit in the
1045 * line status register.
1046 */
1047
1048 uart->ustcnt &= ~USTCNT_RXEN;
1049 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);
1050
467712c9 1051 shutdown(info, tty);
978e595f 1052 rs_flush_buffer(tty);
1da177e4
LT
1053
1054 tty_ldisc_flush(tty);
1055 tty->closing = 0;
665569d0 1056 tty_port_tty_set(&info->tport, NULL);
1da177e4
LT
1057#warning "This is not and has never been valid so fix it"
1058#if 0
1059 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1060 if (tty->ldisc.close)
1061 (tty->ldisc.close)(tty);
1062 tty->ldisc = ldiscs[N_TTY];
3dd332c5 1063 tty->termios.c_line = N_TTY;
1da177e4
LT
1064 if (tty->ldisc.open)
1065 (tty->ldisc.open)(tty);
1066 }
1067#endif
86264341 1068 if (port->blocked_open) {
4a85b1fc
JS
1069 if (port->close_delay)
1070 msleep_interruptible(jiffies_to_msecs(port->close_delay));
c26f0115 1071 wake_up_interruptible(&port->open_wait);
1da177e4 1072 }
a85dd82c 1073 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
727dda80 1074 local_irq_restore(flags);
1da177e4
LT
1075}
1076
1077/*
1078 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1079 */
1080void rs_hangup(struct tty_struct *tty)
1081{
2ababf9e 1082 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
1da177e4
LT
1083
1084 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
1085 return;
1086
1087 rs_flush_buffer(tty);
467712c9 1088 shutdown(info, tty);
86264341 1089 info->tport.count = 0;
a85dd82c 1090 info->tport.flags &= ~ASYNC_NORMAL_ACTIVE;
665569d0 1091 tty_port_tty_set(&info->tport, NULL);
c26f0115 1092 wake_up_interruptible(&info->tport.open_wait);
1da177e4
LT
1093}
1094
1da177e4
LT
1095/*
1096 * This routine is called whenever a serial port is opened. It
1097 * enables interrupts for a serial port, linking in its S structure into
1098 * the IRQ chain. It also performs the serial-specific
1099 * initialization for the tty structure.
1100 */
2ababf9e 1101int rs_open(struct tty_struct *tty, struct file *filp)
1da177e4
LT
1102{
1103 struct m68k_serial *info;
410235fd 1104 int retval;
1da177e4 1105
410235fd 1106 info = &m68k_soft[tty->index];
1da177e4
LT
1107
1108 if (serial_paranoia_check(info, tty->name, "rs_open"))
1109 return -ENODEV;
1110
86264341 1111 info->tport.count++;
1da177e4 1112 tty->driver_data = info;
665569d0 1113 tty_port_tty_set(&info->tport, tty);
1da177e4
LT
1114
1115 /*
1116 * Start up serial port
1117 */
467712c9 1118 retval = startup(info, tty);
1da177e4
LT
1119 if (retval)
1120 return retval;
1121
8e328416 1122 return tty_port_block_til_ready(&info->tport, tty, filp);
1da177e4
LT
1123}
1124
1125/* Finally, routines used to initialize the serial driver. */
1126
1127static void show_serial_version(void)
1128{
1129 printk("MC68328 serial driver version 1.00\n");
1130}
1131
b68e31d0 1132static const struct tty_operations rs_ops = {
1da177e4
LT
1133 .open = rs_open,
1134 .close = rs_close,
1135 .write = rs_write,
1136 .flush_chars = rs_flush_chars,
1137 .write_room = rs_write_room,
1138 .chars_in_buffer = rs_chars_in_buffer,
1139 .flush_buffer = rs_flush_buffer,
1140 .ioctl = rs_ioctl,
1141 .throttle = rs_throttle,
1142 .unthrottle = rs_unthrottle,
1143 .set_termios = rs_set_termios,
1144 .stop = rs_stop,
1145 .start = rs_start,
1146 .hangup = rs_hangup,
1147 .set_ldisc = rs_set_ldisc,
1148};
1149
8e328416
JS
1150static const struct tty_port_operations rs_port_ops = {
1151};
1152
1da177e4
LT
1153/* rs_init inits the driver */
1154static int __init
1155rs68328_init(void)
1156{
107afb7a
JS
1157 unsigned long flags;
1158 int i;
1da177e4
LT
1159 struct m68k_serial *info;
1160
1161 serial_driver = alloc_tty_driver(NR_PORTS);
1162 if (!serial_driver)
1163 return -ENOMEM;
1164
1165 show_serial_version();
1166
1167 /* Initialize the tty_driver structure */
1168 /* SPARC: Not all of this is exactly right for us. */
1169
1170 serial_driver->name = "ttyS";
1171 serial_driver->major = TTY_MAJOR;
1172 serial_driver->minor_start = 64;
1173 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1174 serial_driver->subtype = SERIAL_TYPE_NORMAL;
1175 serial_driver->init_termios = tty_std_termios;
1176 serial_driver->init_termios.c_cflag =
1177 m68328_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
1178 serial_driver->flags = TTY_DRIVER_REAL_RAW;
1179 tty_set_operations(serial_driver, &rs_ops);
1180
727dda80 1181 local_irq_save(flags);
1da177e4 1182
ba4f10ae 1183 for (i = 0; i < NR_PORTS; i++) {
1da177e4
LT
1184
1185 info = &m68k_soft[i];
86264341 1186 tty_port_init(&info->tport);
8e328416 1187 info->tport.ops = &rs_port_ops;
1da177e4
LT
1188 info->magic = SERIAL_MAGIC;
1189 info->port = (int) &uart_addr[i];
1da177e4
LT
1190 info->irq = uart_irqs[i];
1191 info->custom_divisor = 16;
1da177e4 1192 info->x_char = 0;
1da177e4
LT
1193 info->line = i;
1194 info->is_cons = 1; /* Means shortcuts work */
1195
1196 printk("%s%d at 0x%08x (irq = %d)", serial_driver->name, info->line,
1197 info->port, info->irq);
1198 printk(" is a builtin MC68328 UART\n");
1199
1da177e4 1200#ifdef CONFIG_M68VZ328
4b7bb2b2 1201 if (i > 0)
1da177e4
LT
1202 PJSEL &= 0xCF; /* PSW enable second port output */
1203#endif
1204
1205 if (request_irq(uart_irqs[i],
1206 rs_interrupt,
9cfb5c05 1207 0,
25db8ad5 1208 "M68328_UART", info))
1da177e4 1209 panic("Unable to attach 68328 serial interrupt\n");
b19e2ca7
JS
1210
1211 tty_port_link_device(&info->tport, serial_driver, i);
1da177e4 1212 }
727dda80 1213 local_irq_restore(flags);
b19e2ca7
JS
1214
1215 if (tty_register_driver(serial_driver)) {
1216 put_tty_driver(serial_driver);
191c5f10
JS
1217 for (i = 0; i < NR_PORTS; i++)
1218 tty_port_destroy(&m68k_soft[i].tport);
b19e2ca7
JS
1219 printk(KERN_ERR "Couldn't register serial driver\n");
1220 return -ENOMEM;
1221 }
1222
1da177e4
LT
1223 return 0;
1224}
1225
1da177e4
LT
1226module_init(rs68328_init);
1227
1228
1229
1230static void m68328_set_baud(void)
1231{
1232 unsigned short ustcnt;
1233 int i;
1234
1235 ustcnt = USTCNT;
1236 USTCNT = ustcnt & ~USTCNT_TXEN;
1237
1238again:
8b505ca8 1239 for (i = 0; i < ARRAY_SIZE(baud_table); i++)
1da177e4
LT
1240 if (baud_table[i] == m68328_console_baud)
1241 break;
8b505ca8 1242 if (i >= ARRAY_SIZE(baud_table)) {
1da177e4
LT
1243 m68328_console_baud = 9600;
1244 goto again;
1245 }
1246
1247 UBAUD = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
1248 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
1249 ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7);
1250 ustcnt |= USTCNT_8_7;
1251 ustcnt |= USTCNT_TXEN;
1252 USTCNT = ustcnt;
1253 m68328_console_initted = 1;
1254 return;
1255}
1256
1257
1258int m68328_console_setup(struct console *cp, char *arg)
1259{
1260 int i, n = CONSOLE_BAUD_RATE;
1261
1262 if (!cp)
1263 return(-1);
1264
1265 if (arg)
ba4f10ae 1266 n = simple_strtoul(arg, NULL, 0);
1da177e4 1267
8b505ca8 1268 for (i = 0; i < ARRAY_SIZE(baud_table); i++)
1da177e4
LT
1269 if (baud_table[i] == n)
1270 break;
e9a137cb 1271 if (i < ARRAY_SIZE(baud_table)) {
1da177e4
LT
1272 m68328_console_baud = n;
1273 m68328_console_cbaud = 0;
1274 if (i > 15) {
1275 m68328_console_cbaud |= CBAUDEX;
1276 i -= 15;
1277 }
1278 m68328_console_cbaud |= i;
1279 }
1280
1281 m68328_set_baud(); /* make sure baud rate changes */
5cbb457e 1282 return 0;
1da177e4
LT
1283}
1284
1285
1286static struct tty_driver *m68328_console_device(struct console *c, int *index)
1287{
1288 *index = c->index;
1289 return serial_driver;
1290}
1291
1292
1293void m68328_console_write (struct console *co, const char *str,
1294 unsigned int count)
1295{
1296 if (!m68328_console_initted)
1297 m68328_set_baud();
1298 while (count--) {
1299 if (*str == '\n')
1300 rs_put_char('\r');
4b7bb2b2 1301 rs_put_char(*str++);
1da177e4
LT
1302 }
1303}
1304
1305
1306static struct console m68328_driver = {
1307 .name = "ttyS",
1308 .write = m68328_console_write,
1309 .device = m68328_console_device,
1310 .setup = m68328_console_setup,
1311 .flags = CON_PRINTBUFFER,
1312 .index = -1,
1313};
1314
1315
1316static int __init m68328_console_init(void)
1317{
1318 register_console(&m68328_driver);
1319 return 0;
1320}
1321
1322console_initcall(m68328_console_init);
This page took 0.973492 seconds and 5 git commands to generate.