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 17#include <asm/dbg.h> 18#include <linux/module.h> 19#include <linux/errno.h> 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> 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/pm_legacy.h> 37#include <linux/bitops.h> 38#include <linux/delay.h> 39 40#include <asm/io.h> 41#include <asm/irq.h> 42#include <asm/system.h> 43#include <asm/delay.h> 44#include <asm/uaccess.h> 45 46/* (es) */ 47/* note: perhaps we can murge these files, so that you can just 48 * define 1 of them, and they can sort that out for themselves 49 */ 50#if defined(CONFIG_M68EZ328) 51#include <asm/MC68EZ328.h> 52#else 53#if defined(CONFIG_M68VZ328) 54#include <asm/MC68VZ328.h> 55#else 56#include <asm/MC68328.h> 57#endif /* CONFIG_M68VZ328 */ 58#endif /* CONFIG_M68EZ328 */ 59 60#include "68328serial.h" 61 62/* Turn off usage of real serial interrupt code, to "support" Copilot */ 63#ifdef CONFIG_XCOPILOT_BUGS 64#undef USE_INTS 65#else 66#define USE_INTS 67#endif 68 69static struct m68k_serial m68k_soft[NR_PORTS]; 70struct m68k_serial *IRQ_ports[NR_IRQS]; 71 72static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS; 73 74/* multiple ports are contiguous in memory */ 75m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR; 76 77struct tty_struct m68k_ttys; 78struct m68k_serial *m68k_consinfo = 0; 79 80#define M68K_CLOCK (16667000) 81 82#ifdef CONFIG_CONSOLE 83extern wait_queue_head_t keypress_wait; 84#endif 85 86struct tty_driver *serial_driver; 87 88/* serial subtype definitions */ 89#define SERIAL_TYPE_NORMAL 1 90 91/* number of characters left in xmit buffer before we ask for more */ 92#define WAKEUP_CHARS 256 93 94/* Debugging... DEBUG_INTR is bad to use when one of the zs 95 * lines is your console ;( 96 */ 97#undef SERIAL_DEBUG_INTR 98#undef SERIAL_DEBUG_OPEN 99#undef SERIAL_DEBUG_FLOW 100 101#define RS_ISR_PASS_LIMIT 256 102 103static void change_speed(struct m68k_serial *info); 104 105/* 106 * Setup for console. Argument comes from the boot command line. 107 */ 108 109#if defined(CONFIG_M68EZ328ADS) || defined(CONFIG_ALMA_ANS) || \ 110 defined(CONFIG_DRAGONIXVZ) 111#define CONSOLE_BAUD_RATE 115200 112#define DEFAULT_CBAUD B115200 113#else 114 /* (es) */ 115 /* note: this is messy, but it works, again, perhaps defined somewhere else?*/ 116 #ifdef CONFIG_M68VZ328 117 #define CONSOLE_BAUD_RATE 19200 118 #define DEFAULT_CBAUD B19200 119 #endif 120 /* (/es) */ 121#endif 122 123#ifndef CONSOLE_BAUD_RATE 124#define CONSOLE_BAUD_RATE 9600 125#define DEFAULT_CBAUD B9600 126#endif 127 128 129static int m68328_console_initted = 0; 130static int m68328_console_baud = CONSOLE_BAUD_RATE; 131static int m68328_console_cbaud = DEFAULT_CBAUD; 132 133 134static inline int serial_paranoia_check(struct m68k_serial *info, 135 char *name, const char *routine) 136{ 137#ifdef SERIAL_PARANOIA_CHECK 138 static const char *badmagic = 139 "Warning: bad magic number for serial struct %s in %s\n"; 140 static const char *badinfo = 141 "Warning: null m68k_serial for %s in %s\n"; 142 143 if (!info) { 144 printk(badinfo, name, routine); 145 return 1; 146 } 147 if (info->magic != SERIAL_MAGIC) { 148 printk(badmagic, name, routine); 149 return 1; 150 } 151#endif 152 return 0; 153} 154 155/* 156 * This is used to figure out the divisor speeds and the timeouts 157 */ 158static int baud_table[] = { 159 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 160 9600, 19200, 38400, 57600, 115200, 0 }; 161 162#define BAUD_TABLE_SIZE (sizeof(baud_table)/sizeof(baud_table[0])) 163 164/* Sets or clears DTR/RTS on the requested line */ 165static inline void m68k_rtsdtr(struct m68k_serial *ss, int set) 166{ 167 if (set) { 168 /* set the RTS/CTS line */ 169 } else { 170 /* clear it */ 171 } 172 return; 173} 174 175/* Utility routines */ 176static inline int get_baud(struct m68k_serial *ss) 177{ 178 unsigned long result = 115200; 179 unsigned short int baud = uart_addr[ss->line].ubaud; 180 if (GET_FIELD(baud, UBAUD_PRESCALER) == 0x38) result = 38400; 181 result >>= GET_FIELD(baud, UBAUD_DIVIDE); 182 183 return result; 184} 185 186/* 187 * ------------------------------------------------------------ 188 * rs_stop() and rs_start() 189 * 190 * This routines are called before setting or resetting tty->stopped. 191 * They enable or disable transmitter interrupts, as necessary. 192 * ------------------------------------------------------------ 193 */ 194static void rs_stop(struct tty_struct *tty) 195{ 196 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 197 m68328_uart *uart = &uart_addr[info->line]; 198 unsigned long flags; 199 200 if (serial_paranoia_check(info, tty->name, "rs_stop")) 201 return; 202 203 local_irq_save(flags); 204 uart->ustcnt &= ~USTCNT_TXEN; 205 local_irq_restore(flags); 206} 207 208static void rs_put_char(char ch) 209{ 210 int flags, loops = 0; 211 212 local_irq_save(flags); 213 214 while (!(UTX & UTX_TX_AVAIL) && (loops < 1000)) { 215 loops++; 216 udelay(5); 217 } 218 219 UTX_TXDATA = ch; 220 udelay(5); 221 local_irq_restore(flags); 222} 223 224static void rs_start(struct tty_struct *tty) 225{ 226 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 227 m68328_uart *uart = &uart_addr[info->line]; 228 unsigned long flags; 229 230 if (serial_paranoia_check(info, tty->name, "rs_start")) 231 return; 232 233 local_irq_save(flags); 234 if (info->xmit_cnt && info->xmit_buf && !(uart->ustcnt & USTCNT_TXEN)) { 235#ifdef USE_INTS 236 uart->ustcnt |= USTCNT_TXEN | USTCNT_TX_INTR_MASK; 237#else 238 uart->ustcnt |= USTCNT_TXEN; 239#endif 240 } 241 local_irq_restore(flags); 242} 243 244/* Drop into either the boot monitor or kadb upon receiving a break 245 * from keyboard/console input. 246 */ 247static void batten_down_hatches(void) 248{ 249 /* Drop into the debugger */ 250} 251 252static void status_handle(struct m68k_serial *info, unsigned short status) 253{ 254 /* If this is console input and this is a 255 * 'break asserted' status change interrupt 256 * see if we can drop into the debugger 257 */ 258 if((status & URX_BREAK) && info->break_abort) 259 batten_down_hatches(); 260 return; 261} 262 263static void receive_chars(struct m68k_serial *info, unsigned short rx) 264{ 265 struct tty_struct *tty = info->tty; 266 m68328_uart *uart = &uart_addr[info->line]; 267 unsigned char ch, flag; 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 277 if(info->is_cons) { 278 if(URX_BREAK & rx) { /* whee, break received */ 279 status_handle(info, rx); 280 return; 281#ifdef CONFIG_MAGIC_SYSRQ 282 } else if (ch == 0x10) { /* ^P */ 283 show_state(); 284 show_free_areas(); 285 show_buffers(); 286/* show_net_buffers(); */ 287 return; 288 } else if (ch == 0x12) { /* ^R */ 289 emergency_restart(); 290 return; 291#endif /* CONFIG_MAGIC_SYSRQ */ 292 } 293 /* It is a 'keyboard interrupt' ;-) */ 294#ifdef CONFIG_CONSOLE 295 wake_up(&keypress_wait); 296#endif 297 } 298 299 if(!tty) 300 goto clear_and_exit; 301 302 flag = TTY_NORMAL; 303 304 if(rx & URX_PARITY_ERROR) { 305 flag = TTY_PARITY; 306 status_handle(info, rx); 307 } else if(rx & URX_OVRUN) { 308 flag = TTY_OVERRUN; 309 status_handle(info, rx); 310 } else if(rx & URX_FRAME_ERROR) { 311 flag = TTY_FRAME; 312 status_handle(info, rx); 313 } 314 tty_insert_flip_char(tty, ch, flag); 315#ifndef CONFIG_XCOPILOT_BUGS 316 } while((rx = uart->urx.w) & URX_DATA_READY); 317#endif 318 319 tty_schedule_flip(tty); 320 321clear_and_exit: 322 return; 323} 324 325static void transmit_chars(struct m68k_serial *info) 326{ 327 m68328_uart *uart = &uart_addr[info->line]; 328 329 if (info->x_char) { 330 /* Send next char */ 331 uart->utx.b.txdata = info->x_char; 332 info->x_char = 0; 333 goto clear_and_return; 334 } 335 336 if((info->xmit_cnt <= 0) || info->tty->stopped) { 337 /* That's peculiar... TX ints off */ 338 uart->ustcnt &= ~USTCNT_TX_INTR_MASK; 339 goto clear_and_return; 340 } 341 342 /* Send char */ 343 uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++]; 344 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1); 345 info->xmit_cnt--; 346 347 if (info->xmit_cnt < WAKEUP_CHARS) 348 schedule_work(&info->tqueue); 349 350 if(info->xmit_cnt <= 0) { 351 /* All done for now... TX ints off */ 352 uart->ustcnt &= ~USTCNT_TX_INTR_MASK; 353 goto clear_and_return; 354 } 355 356clear_and_return: 357 /* Clear interrupt (should be auto)*/ 358 return; 359} 360 361/* 362 * This is the serial driver's generic interrupt routine 363 */ 364irqreturn_t rs_interrupt(int irq, void *dev_id) 365{ 366 struct m68k_serial * info; 367 m68328_uart *uart; 368 unsigned short rx; 369 unsigned short tx; 370 371 info = IRQ_ports[irq]; 372 if(!info) 373 return IRQ_NONE; 374 375 uart = &uart_addr[info->line]; 376 rx = uart->urx.w; 377 378#ifdef USE_INTS 379 tx = uart->utx.w; 380 381 if (rx & URX_DATA_READY) receive_chars(info, rx); 382 if (tx & UTX_TX_AVAIL) transmit_chars(info); 383#else 384 receive_chars(info, rx); 385#endif 386 return IRQ_HANDLED; 387} 388 389static void do_softint(void *private) 390{ 391 struct m68k_serial *info = (struct m68k_serial *) private; 392 struct tty_struct *tty; 393 394 tty = info->tty; 395 if (!tty) 396 return; 397} 398 399/* 400 * This routine is called from the scheduler tqueue when the interrupt 401 * routine has signalled that a hangup has occurred. The path of 402 * hangup processing is: 403 * 404 * serial interrupt routine -> (scheduler tqueue) -> 405 * do_serial_hangup() -> tty->hangup() -> rs_hangup() 406 * 407 */ 408static void do_serial_hangup(void *private) 409{ 410 struct m68k_serial *info = (struct m68k_serial *) private; 411 struct tty_struct *tty; 412 413 tty = info->tty; 414 if (!tty) 415 return; 416 417 tty_hangup(tty); 418} 419 420 421static int startup(struct m68k_serial * info) 422{ 423 m68328_uart *uart = &uart_addr[info->line]; 424 unsigned long flags; 425 426 if (info->flags & S_INITIALIZED) 427 return 0; 428 429 if (!info->xmit_buf) { 430 info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL); 431 if (!info->xmit_buf) 432 return -ENOMEM; 433 } 434 435 local_irq_save(flags); 436 437 /* 438 * Clear the FIFO buffers and disable them 439 * (they will be reenabled in change_speed()) 440 */ 441 442 uart->ustcnt = USTCNT_UEN; 443 info->xmit_fifo_size = 1; 444 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN; 445 (void)uart->urx.w; 446 447 /* 448 * Finally, enable sequencing and interrupts 449 */ 450#ifdef USE_INTS 451 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | 452 USTCNT_RX_INTR_MASK | USTCNT_TX_INTR_MASK; 453#else 454 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK; 455#endif 456 457 if (info->tty) 458 clear_bit(TTY_IO_ERROR, &info->tty->flags); 459 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 460 461 /* 462 * and set the speed of the serial port 463 */ 464 465 change_speed(info); 466 467 info->flags |= S_INITIALIZED; 468 local_irq_restore(flags); 469 return 0; 470} 471 472/* 473 * This routine will shutdown a serial port; interrupts are disabled, and 474 * DTR is dropped if the hangup on close termio flag is on. 475 */ 476static void shutdown(struct m68k_serial * info) 477{ 478 m68328_uart *uart = &uart_addr[info->line]; 479 unsigned long flags; 480 481 uart->ustcnt = 0; /* All off! */ 482 if (!(info->flags & S_INITIALIZED)) 483 return; 484 485 local_irq_save(flags); 486 487 if (info->xmit_buf) { 488 free_page((unsigned long) info->xmit_buf); 489 info->xmit_buf = 0; 490 } 491 492 if (info->tty) 493 set_bit(TTY_IO_ERROR, &info->tty->flags); 494 495 info->flags &= ~S_INITIALIZED; 496 local_irq_restore(flags); 497} 498 499struct { 500 int divisor, prescale; 501} 502#ifndef CONFIG_M68VZ328 503 hw_baud_table[18] = { 504 {0,0}, /* 0 */ 505 {0,0}, /* 50 */ 506 {0,0}, /* 75 */ 507 {0,0}, /* 110 */ 508 {0,0}, /* 134 */ 509 {0,0}, /* 150 */ 510 {0,0}, /* 200 */ 511 {7,0x26}, /* 300 */ 512 {6,0x26}, /* 600 */ 513 {5,0x26}, /* 1200 */ 514 {0,0}, /* 1800 */ 515 {4,0x26}, /* 2400 */ 516 {3,0x26}, /* 4800 */ 517 {2,0x26}, /* 9600 */ 518 {1,0x26}, /* 19200 */ 519 {0,0x26}, /* 38400 */ 520 {1,0x38}, /* 57600 */ 521 {0,0x38}, /* 115200 */ 522}; 523#else 524 hw_baud_table[18] = { 525 {0,0}, /* 0 */ 526 {0,0}, /* 50 */ 527 {0,0}, /* 75 */ 528 {0,0}, /* 110 */ 529 {0,0}, /* 134 */ 530 {0,0}, /* 150 */ 531 {0,0}, /* 200 */ 532 {0,0}, /* 300 */ 533 {7,0x26}, /* 600 */ 534 {6,0x26}, /* 1200 */ 535 {0,0}, /* 1800 */ 536 {5,0x26}, /* 2400 */ 537 {4,0x26}, /* 4800 */ 538 {3,0x26}, /* 9600 */ 539 {2,0x26}, /* 19200 */ 540 {1,0x26}, /* 38400 */ 541 {0,0x26}, /* 57600 */ 542 {1,0x38}, /* 115200 */ 543}; 544#endif 545/* rate = 1036800 / ((65 - prescale) * (1<<divider)) */ 546 547/* 548 * This routine is called to set the UART divisor registers to match 549 * the specified baud rate for a serial port. 550 */ 551static void change_speed(struct m68k_serial *info) 552{ 553 m68328_uart *uart = &uart_addr[info->line]; 554 unsigned short port; 555 unsigned short ustcnt; 556 unsigned cflag; 557 int i; 558 559 if (!info->tty || !info->tty->termios) 560 return; 561 cflag = info->tty->termios->c_cflag; 562 if (!(port = info->port)) 563 return; 564 565 ustcnt = uart->ustcnt; 566 uart->ustcnt = ustcnt & ~USTCNT_TXEN; 567 568 i = cflag & CBAUD; 569 if (i & CBAUDEX) { 570 i = (i & ~CBAUDEX) + B38400; 571 } 572 573 info->baud = baud_table[i]; 574 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | 575 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale); 576 577 ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7); 578 579 if ((cflag & CSIZE) == CS8) 580 ustcnt |= USTCNT_8_7; 581 582 if (cflag & CSTOPB) 583 ustcnt |= USTCNT_STOP; 584 585 if (cflag & PARENB) 586 ustcnt |= USTCNT_PARITYEN; 587 if (cflag & PARODD) 588 ustcnt |= USTCNT_ODD_EVEN; 589 590#ifdef CONFIG_SERIAL_68328_RTS_CTS 591 if (cflag & CRTSCTS) { 592 uart->utx.w &= ~ UTX_NOCTS; 593 } else { 594 uart->utx.w |= UTX_NOCTS; 595 } 596#endif 597 598 ustcnt |= USTCNT_TXEN; 599 600 uart->ustcnt = ustcnt; 601 return; 602} 603 604/* 605 * Fair output driver allows a process to speak. 606 */ 607static void rs_fair_output(void) 608{ 609 int left; /* Output no more than that */ 610 unsigned long flags; 611 struct m68k_serial *info = &m68k_soft[0]; 612 char c; 613 614 if (info == 0) return; 615 if (info->xmit_buf == 0) return; 616 617 local_irq_save(flags); 618 left = info->xmit_cnt; 619 while (left != 0) { 620 c = info->xmit_buf[info->xmit_tail]; 621 info->xmit_tail = (info->xmit_tail+1) & (SERIAL_XMIT_SIZE-1); 622 info->xmit_cnt--; 623 local_irq_restore(flags); 624 625 rs_put_char(c); 626 627 local_irq_save(flags); 628 left = min(info->xmit_cnt, left-1); 629 } 630 631 /* Last character is being transmitted now (hopefully). */ 632 udelay(5); 633 634 local_irq_restore(flags); 635 return; 636} 637 638/* 639 * m68k_console_print is registered for printk. 640 */ 641void console_print_68328(const char *p) 642{ 643 char c; 644 645 while((c=*(p++)) != 0) { 646 if(c == '\n') 647 rs_put_char('\r'); 648 rs_put_char(c); 649 } 650 651 /* Comment this if you want to have a strict interrupt-driven output */ 652 rs_fair_output(); 653 654 return; 655} 656 657static void rs_set_ldisc(struct tty_struct *tty) 658{ 659 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 660 661 if (serial_paranoia_check(info, tty->name, "rs_set_ldisc")) 662 return; 663 664 info->is_cons = (tty->termios->c_line == N_TTY); 665 666 printk("ttyS%d console mode %s\n", info->line, info->is_cons ? "on" : "off"); 667} 668 669static void rs_flush_chars(struct tty_struct *tty) 670{ 671 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 672 m68328_uart *uart = &uart_addr[info->line]; 673 unsigned long flags; 674 675 if (serial_paranoia_check(info, tty->name, "rs_flush_chars")) 676 return; 677#ifndef USE_INTS 678 for(;;) { 679#endif 680 681 /* Enable transmitter */ 682 local_irq_save(flags); 683 684 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || 685 !info->xmit_buf) { 686 local_irq_restore(flags); 687 return; 688 } 689 690#ifdef USE_INTS 691 uart->ustcnt |= USTCNT_TXEN | USTCNT_TX_INTR_MASK; 692#else 693 uart->ustcnt |= USTCNT_TXEN; 694#endif 695 696#ifdef USE_INTS 697 if (uart->utx.w & UTX_TX_AVAIL) { 698#else 699 if (1) { 700#endif 701 /* Send char */ 702 uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++]; 703 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1); 704 info->xmit_cnt--; 705 } 706 707#ifndef USE_INTS 708 while (!(uart->utx.w & UTX_TX_AVAIL)) udelay(5); 709 } 710#endif 711 local_irq_restore(flags); 712} 713 714extern void console_printn(const char * b, int count); 715 716static int rs_write(struct tty_struct * tty, 717 const unsigned char *buf, int count) 718{ 719 int c, total = 0; 720 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 721 m68328_uart *uart = &uart_addr[info->line]; 722 unsigned long flags; 723 724 if (serial_paranoia_check(info, tty->name, "rs_write")) 725 return 0; 726 727 if (!tty || !info->xmit_buf) 728 return 0; 729 730 local_save_flags(flags); 731 while (1) { 732 local_irq_disable(); 733 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1, 734 SERIAL_XMIT_SIZE - info->xmit_head)); 735 local_irq_restore(flags); 736 737 if (c <= 0) 738 break; 739 740 memcpy(info->xmit_buf + info->xmit_head, buf, c); 741 742 local_irq_disable(); 743 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1); 744 info->xmit_cnt += c; 745 local_irq_restore(flags); 746 buf += c; 747 count -= c; 748 total += c; 749 } 750 751 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) { 752 /* Enable transmitter */ 753 local_irq_disable(); 754#ifndef USE_INTS 755 while(info->xmit_cnt) { 756#endif 757 758 uart->ustcnt |= USTCNT_TXEN; 759#ifdef USE_INTS 760 uart->ustcnt |= USTCNT_TX_INTR_MASK; 761#else 762 while (!(uart->utx.w & UTX_TX_AVAIL)) udelay(5); 763#endif 764 if (uart->utx.w & UTX_TX_AVAIL) { 765 uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++]; 766 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1); 767 info->xmit_cnt--; 768 } 769 770#ifndef USE_INTS 771 } 772#endif 773 local_irq_restore(flags); 774 } 775 776 return total; 777} 778 779static int rs_write_room(struct tty_struct *tty) 780{ 781 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 782 int ret; 783 784 if (serial_paranoia_check(info, tty->name, "rs_write_room")) 785 return 0; 786 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1; 787 if (ret < 0) 788 ret = 0; 789 return ret; 790} 791 792static int rs_chars_in_buffer(struct tty_struct *tty) 793{ 794 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 795 796 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer")) 797 return 0; 798 return info->xmit_cnt; 799} 800 801static void rs_flush_buffer(struct tty_struct *tty) 802{ 803 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 804 unsigned long flags; 805 806 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer")) 807 return; 808 local_irq_save(flags); 809 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 810 local_irq_restore(flags); 811 tty_wakeup(tty); 812} 813 814/* 815 * ------------------------------------------------------------ 816 * rs_throttle() 817 * 818 * This routine is called by the upper-layer tty layer to signal that 819 * incoming characters should be throttled. 820 * ------------------------------------------------------------ 821 */ 822static void rs_throttle(struct tty_struct * tty) 823{ 824 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 825 826 if (serial_paranoia_check(info, tty->name, "rs_throttle")) 827 return; 828 829 if (I_IXOFF(tty)) 830 info->x_char = STOP_CHAR(tty); 831 832 /* Turn off RTS line (do this atomic) */ 833} 834 835static void rs_unthrottle(struct tty_struct * tty) 836{ 837 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 838 839 if (serial_paranoia_check(info, tty->name, "rs_unthrottle")) 840 return; 841 842 if (I_IXOFF(tty)) { 843 if (info->x_char) 844 info->x_char = 0; 845 else 846 info->x_char = START_CHAR(tty); 847 } 848 849 /* Assert RTS line (do this atomic) */ 850} 851 852/* 853 * ------------------------------------------------------------ 854 * rs_ioctl() and friends 855 * ------------------------------------------------------------ 856 */ 857 858static int get_serial_info(struct m68k_serial * info, 859 struct serial_struct * retinfo) 860{ 861 struct serial_struct tmp; 862 863 if (!retinfo) 864 return -EFAULT; 865 memset(&tmp, 0, sizeof(tmp)); 866 tmp.type = info->type; 867 tmp.line = info->line; 868 tmp.port = info->port; 869 tmp.irq = info->irq; 870 tmp.flags = info->flags; 871 tmp.baud_base = info->baud_base; 872 tmp.close_delay = info->close_delay; 873 tmp.closing_wait = info->closing_wait; 874 tmp.custom_divisor = info->custom_divisor; 875 copy_to_user(retinfo,&tmp,sizeof(*retinfo)); 876 return 0; 877} 878 879static int set_serial_info(struct m68k_serial * info, 880 struct serial_struct * new_info) 881{ 882 struct serial_struct new_serial; 883 struct m68k_serial old_info; 884 int retval = 0; 885 886 if (!new_info) 887 return -EFAULT; 888 copy_from_user(&new_serial,new_info,sizeof(new_serial)); 889 old_info = *info; 890 891 if (!capable(CAP_SYS_ADMIN)) { 892 if ((new_serial.baud_base != info->baud_base) || 893 (new_serial.type != info->type) || 894 (new_serial.close_delay != info->close_delay) || 895 ((new_serial.flags & ~S_USR_MASK) != 896 (info->flags & ~S_USR_MASK))) 897 return -EPERM; 898 info->flags = ((info->flags & ~S_USR_MASK) | 899 (new_serial.flags & S_USR_MASK)); 900 info->custom_divisor = new_serial.custom_divisor; 901 goto check_and_exit; 902 } 903 904 if (info->count > 1) 905 return -EBUSY; 906 907 /* 908 * OK, past this point, all the error checking has been done. 909 * At this point, we start making changes..... 910 */ 911 912 info->baud_base = new_serial.baud_base; 913 info->flags = ((info->flags & ~S_FLAGS) | 914 (new_serial.flags & S_FLAGS)); 915 info->type = new_serial.type; 916 info->close_delay = new_serial.close_delay; 917 info->closing_wait = new_serial.closing_wait; 918 919check_and_exit: 920 retval = startup(info); 921 return retval; 922} 923 924/* 925 * get_lsr_info - get line status register info 926 * 927 * Purpose: Let user call ioctl() to get info when the UART physically 928 * is emptied. On bus types like RS485, the transmitter must 929 * release the bus after transmitting. This must be done when 930 * the transmit shift register is empty, not be done when the 931 * transmit holding register is empty. This functionality 932 * allows an RS485 driver to be written in user space. 933 */ 934static int get_lsr_info(struct m68k_serial * info, unsigned int *value) 935{ 936#ifdef CONFIG_SERIAL_68328_RTS_CTS 937 m68328_uart *uart = &uart_addr[info->line]; 938#endif 939 unsigned char status; 940 unsigned long flags; 941 942 local_irq_save(flags); 943#ifdef CONFIG_SERIAL_68328_RTS_CTS 944 status = (uart->utx.w & UTX_CTS_STAT) ? 1 : 0; 945#else 946 status = 0; 947#endif 948 local_irq_restore(flags); 949 put_user(status,value); 950 return 0; 951} 952 953/* 954 * This routine sends a break character out the serial port. 955 */ 956static void send_break(struct m68k_serial * info, unsigned int duration) 957{ 958 m68328_uart *uart = &uart_addr[info->line]; 959 unsigned long flags; 960 if (!info->port) 961 return; 962 local_irq_save(flags); 963#ifdef USE_INTS 964 uart->utx.w |= UTX_SEND_BREAK; 965 msleep_interruptible(duration); 966 uart->utx.w &= ~UTX_SEND_BREAK; 967#endif 968 local_irq_restore(flags); 969} 970 971static int rs_ioctl(struct tty_struct *tty, struct file * file, 972 unsigned int cmd, unsigned long arg) 973{ 974 int error; 975 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; 976 int retval; 977 978 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) 979 return -ENODEV; 980 981 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 982 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) && 983 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) { 984 if (tty->flags & (1 << TTY_IO_ERROR)) 985 return -EIO; 986 } 987 988 switch (cmd) { 989 case TCSBRK: /* SVID version: non-zero arg --> no break */ 990 retval = tty_check_change(tty); 991 if (retval) 992 return retval; 993 tty_wait_until_sent(tty, 0); 994 if (!arg) 995 send_break(info, 250); /* 1/4 second */ 996 return 0; 997 case TCSBRKP: /* support for POSIX tcsendbreak() */ 998 retval = tty_check_change(tty); 999 if (retval) 1000 return retval; 1001 tty_wait_until_sent(tty, 0); 1002 send_break(info, arg ? arg*(100) : 250); 1003 return 0; 1004 case TIOCGSOFTCAR: 1005 error = put_user(C_CLOCAL(tty) ? 1 : 0, 1006 (unsigned long *) arg); 1007 if (error) 1008 return error; 1009 return 0; 1010 case TIOCSSOFTCAR: 1011 get_user(arg, (unsigned long *) arg); 1012 tty->termios->c_cflag = 1013 ((tty->termios->c_cflag & ~CLOCAL) | 1014 (arg ? CLOCAL : 0)); 1015 return 0; 1016 case TIOCGSERIAL: 1017 if (access_ok(VERIFY_WRITE, (void *) arg, 1018 sizeof(struct serial_struct))) 1019 return get_serial_info(info, 1020 (struct serial_struct *) arg); 1021 return -EFAULT; 1022 case TIOCSSERIAL: 1023 return set_serial_info(info, 1024 (struct serial_struct *) arg); 1025 case TIOCSERGETLSR: /* Get line status register */ 1026 if (access_ok(VERIFY_WRITE, (void *) arg, 1027 sizeof(unsigned int))) 1028 return get_lsr_info(info, (unsigned int *) arg); 1029 return -EFAULT; 1030 case TIOCSERGSTRUCT: 1031 if (!access_ok(VERIFY_WRITE, (void *) arg, 1032 sizeof(struct m68k_serial))) 1033 return -EFAULT; 1034 copy_to_user((struct m68k_serial *) arg, 1035 info, sizeof(struct m68k_serial)); 1036 return 0; 1037 1038 default: 1039 return -ENOIOCTLCMD; 1040 } 1041 return 0; 1042} 1043 1044static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 1045{ 1046 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 1047 1048 if (tty->termios->c_cflag == old_termios->c_cflag) 1049 return; 1050 1051 change_speed(info); 1052 1053 if ((old_termios->c_cflag & CRTSCTS) && 1054 !(tty->termios->c_cflag & CRTSCTS)) { 1055 tty->hw_stopped = 0; 1056 rs_start(tty); 1057 } 1058 1059} 1060 1061/* 1062 * ------------------------------------------------------------ 1063 * rs_close() 1064 * 1065 * This routine is called when the serial port gets closed. First, we 1066 * wait for the last remaining data to be sent. Then, we unlink its 1067 * S structure from the interrupt chain if necessary, and we free 1068 * that IRQ if nothing is left in the chain. 1069 * ------------------------------------------------------------ 1070 */ 1071static void rs_close(struct tty_struct *tty, struct file * filp) 1072{ 1073 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; 1074 m68328_uart *uart = &uart_addr[info->line]; 1075 unsigned long flags; 1076 1077 if (!info || serial_paranoia_check(info, tty->name, "rs_close")) 1078 return; 1079 1080 local_irq_save(flags); 1081 1082 if (tty_hung_up_p(filp)) { 1083 local_irq_restore(flags); 1084 return; 1085 } 1086 1087 if ((tty->count == 1) && (info->count != 1)) { 1088 /* 1089 * Uh, oh. tty->count is 1, which means that the tty 1090 * structure will be freed. Info->count should always 1091 * be one in these conditions. If it's greater than 1092 * one, we've got real problems, since it means the 1093 * serial port won't be shutdown. 1094 */ 1095 printk("rs_close: bad serial port count; tty->count is 1, " 1096 "info->count is %d\n", info->count); 1097 info->count = 1; 1098 } 1099 if (--info->count < 0) { 1100 printk("rs_close: bad serial port count for ttyS%d: %d\n", 1101 info->line, info->count); 1102 info->count = 0; 1103 } 1104 if (info->count) { 1105 local_irq_restore(flags); 1106 return; 1107 } 1108 info->flags |= S_CLOSING; 1109 /* 1110 * Now we wait for the transmit buffer to clear; and we notify 1111 * the line discipline to only process XON/XOFF characters. 1112 */ 1113 tty->closing = 1; 1114 if (info->closing_wait != S_CLOSING_WAIT_NONE) 1115 tty_wait_until_sent(tty, info->closing_wait); 1116 /* 1117 * At this point we stop accepting input. To do this, we 1118 * disable the receive line status interrupts, and tell the 1119 * interrupt driver to stop checking the data ready bit in the 1120 * line status register. 1121 */ 1122 1123 uart->ustcnt &= ~USTCNT_RXEN; 1124 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK); 1125 1126 shutdown(info); 1127 if (tty->driver->flush_buffer) 1128 tty->driver->flush_buffer(tty); 1129 1130 tty_ldisc_flush(tty); 1131 tty->closing = 0; 1132 info->event = 0; 1133 info->tty = 0; 1134#warning "This is not and has never been valid so fix it" 1135 if (info->blocked_open) { 1136 if (info->close_delay) { 1137 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1138 } 1139 wake_up_interruptible(&info->open_wait); 1140 } 1141 info->flags &= ~(S_NORMAL_ACTIVE|S_CLOSING); 1142 wake_up_interruptible(&info->close_wait); 1143 local_irq_restore(flags); 1144} 1145 1146/* 1147 * rs_hangup() --- called by tty_hangup() when a hangup is signaled. 1148 */ 1149void rs_hangup(struct tty_struct *tty) 1150{ 1151 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; 1152 1153 if (serial_paranoia_check(info, tty->name, "rs_hangup")) 1154 return; 1155 1156 rs_flush_buffer(tty); 1157 shutdown(info); 1158 info->event = 0; 1159 info->count = 0; 1160 info->flags &= ~S_NORMAL_ACTIVE; 1161 info->tty = 0; 1162 wake_up_interruptible(&info->open_wait); 1163} 1164 1165/* 1166 * ------------------------------------------------------------ 1167 * rs_open() and friends 1168 * ------------------------------------------------------------ 1169 */ 1170static int block_til_ready(struct tty_struct *tty, struct file * filp, 1171 struct m68k_serial *info) 1172{ 1173 DECLARE_WAITQUEUE(wait, current); 1174 int retval; 1175 int do_clocal = 0; 1176 1177 /* 1178 * If the device is in the middle of being closed, then block 1179 * until it's done, and then try again. 1180 */ 1181 if (info->flags & S_CLOSING) { 1182 interruptible_sleep_on(&info->close_wait); 1183#ifdef SERIAL_DO_RESTART 1184 if (info->flags & S_HUP_NOTIFY) 1185 return -EAGAIN; 1186 else 1187 return -ERESTARTSYS; 1188#else 1189 return -EAGAIN; 1190#endif 1191 } 1192 1193 /* 1194 * If non-blocking mode is set, or the port is not enabled, 1195 * then make the check up front and then exit. 1196 */ 1197 if ((filp->f_flags & O_NONBLOCK) || 1198 (tty->flags & (1 << TTY_IO_ERROR))) { 1199 info->flags |= S_NORMAL_ACTIVE; 1200 return 0; 1201 } 1202 1203 if (tty->termios->c_cflag & CLOCAL) 1204 do_clocal = 1; 1205 1206 /* 1207 * Block waiting for the carrier detect and the line to become 1208 * free (i.e., not in use by the callout). While we are in 1209 * this loop, info->count is dropped by one, so that 1210 * rs_close() knows when to free things. We restore it upon 1211 * exit, either normal or abnormal. 1212 */ 1213 retval = 0; 1214 add_wait_queue(&info->open_wait, &wait); 1215 1216 info->count--; 1217 info->blocked_open++; 1218 while (1) { 1219 local_irq_disable(); 1220 m68k_rtsdtr(info, 1); 1221 local_irq_enable(); 1222 current->state = TASK_INTERRUPTIBLE; 1223 if (tty_hung_up_p(filp) || 1224 !(info->flags & S_INITIALIZED)) { 1225#ifdef SERIAL_DO_RESTART 1226 if (info->flags & S_HUP_NOTIFY) 1227 retval = -EAGAIN; 1228 else 1229 retval = -ERESTARTSYS; 1230#else 1231 retval = -EAGAIN; 1232#endif 1233 break; 1234 } 1235 if (!(info->flags & S_CLOSING) && do_clocal) 1236 break; 1237 if (signal_pending(current)) { 1238 retval = -ERESTARTSYS; 1239 break; 1240 } 1241 schedule(); 1242 } 1243 current->state = TASK_RUNNING; 1244 remove_wait_queue(&info->open_wait, &wait); 1245 if (!tty_hung_up_p(filp)) 1246 info->count++; 1247 info->blocked_open--; 1248 1249 if (retval) 1250 return retval; 1251 info->flags |= S_NORMAL_ACTIVE; 1252 return 0; 1253} 1254 1255/* 1256 * This routine is called whenever a serial port is opened. It 1257 * enables interrupts for a serial port, linking in its S structure into 1258 * the IRQ chain. It also performs the serial-specific 1259 * initialization for the tty structure. 1260 */ 1261int rs_open(struct tty_struct *tty, struct file * filp) 1262{ 1263 struct m68k_serial *info; 1264 int retval, line; 1265 1266 line = tty->index; 1267 1268 if (line >= NR_PORTS || line < 0) /* we have exactly one */ 1269 return -ENODEV; 1270 1271 info = &m68k_soft[line]; 1272 1273 if (serial_paranoia_check(info, tty->name, "rs_open")) 1274 return -ENODEV; 1275 1276 info->count++; 1277 tty->driver_data = info; 1278 info->tty = tty; 1279 1280 /* 1281 * Start up serial port 1282 */ 1283 retval = startup(info); 1284 if (retval) 1285 return retval; 1286 1287 return block_til_ready(tty, filp, info); 1288} 1289 1290/* Finally, routines used to initialize the serial driver. */ 1291 1292static void show_serial_version(void) 1293{ 1294 printk("MC68328 serial driver version 1.00\n"); 1295} 1296 1297#ifdef CONFIG_PM_LEGACY 1298/* Serial Power management 1299 * The console (currently fixed at line 0) is a special case for power 1300 * management because the kernel is so chatty. The console will be 1301 * explicitly disabled my our power manager as the last minute, so we won't 1302 * mess with it here. 1303 */ 1304static struct pm_dev *serial_pm[NR_PORTS]; 1305 1306static int serial_pm_callback(struct pm_dev *dev, pm_request_t request, void *data) 1307{ 1308 struct m68k_serial *info = (struct m68k_serial *)dev->data; 1309 1310 if(info == NULL) 1311 return -1; 1312 1313 /* special case for line 0 - pm restores it */ 1314 if(info->line == 0) 1315 return 0; 1316 1317 switch (request) { 1318 case PM_SUSPEND: 1319 shutdown(info); 1320 break; 1321 1322 case PM_RESUME: 1323 startup(info); 1324 break; 1325 } 1326 return 0; 1327} 1328 1329void shutdown_console(void) 1330{ 1331 struct m68k_serial *info = &m68k_soft[0]; 1332 1333 /* HACK: wait a bit for any pending printk's to be dumped */ 1334 { 1335 int i = 10000; 1336 while(i--); 1337 } 1338 1339 shutdown(info); 1340} 1341 1342void startup_console(void) 1343{ 1344 struct m68k_serial *info = &m68k_soft[0]; 1345 startup(info); 1346} 1347#endif /* CONFIG_PM_LEGACY */ 1348 1349 1350static const struct tty_operations rs_ops = { 1351 .open = rs_open, 1352 .close = rs_close, 1353 .write = rs_write, 1354 .flush_chars = rs_flush_chars, 1355 .write_room = rs_write_room, 1356 .chars_in_buffer = rs_chars_in_buffer, 1357 .flush_buffer = rs_flush_buffer, 1358 .ioctl = rs_ioctl, 1359 .throttle = rs_throttle, 1360 .unthrottle = rs_unthrottle, 1361 .set_termios = rs_set_termios, 1362 .stop = rs_stop, 1363 .start = rs_start, 1364 .hangup = rs_hangup, 1365 .set_ldisc = rs_set_ldisc, 1366}; 1367 1368/* rs_init inits the driver */ 1369static int __init 1370rs68328_init(void) 1371{ 1372 int flags, i; 1373 struct m68k_serial *info; 1374 1375 serial_driver = alloc_tty_driver(NR_PORTS); 1376 if (!serial_driver) 1377 return -ENOMEM; 1378 1379 show_serial_version(); 1380 1381 /* Initialize the tty_driver structure */ 1382 /* SPARC: Not all of this is exactly right for us. */ 1383 1384 serial_driver->name = "ttyS"; 1385 serial_driver->major = TTY_MAJOR; 1386 serial_driver->minor_start = 64; 1387 serial_driver->type = TTY_DRIVER_TYPE_SERIAL; 1388 serial_driver->subtype = SERIAL_TYPE_NORMAL; 1389 serial_driver->init_termios = tty_std_termios; 1390 serial_driver->init_termios.c_cflag = 1391 m68328_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL; 1392 serial_driver->flags = TTY_DRIVER_REAL_RAW; 1393 tty_set_operations(serial_driver, &rs_ops); 1394 1395 if (tty_register_driver(serial_driver)) { 1396 put_tty_driver(serial_driver); 1397 printk(KERN_ERR "Couldn't register serial driver\n"); 1398 return -ENOMEM; 1399 } 1400 1401 local_irq_save(flags); 1402 1403 for(i=0;i<NR_PORTS;i++) { 1404 1405 info = &m68k_soft[i]; 1406 info->magic = SERIAL_MAGIC; 1407 info->port = (int) &uart_addr[i]; 1408 info->tty = 0; 1409 info->irq = uart_irqs[i]; 1410 info->custom_divisor = 16; 1411 info->close_delay = 50; 1412 info->closing_wait = 3000; 1413 info->x_char = 0; 1414 info->event = 0; 1415 info->count = 0; 1416 info->blocked_open = 0; 1417 INIT_WORK(&info->tqueue, do_softint, info); 1418 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info); 1419 init_waitqueue_head(&info->open_wait); 1420 init_waitqueue_head(&info->close_wait); 1421 info->line = i; 1422 info->is_cons = 1; /* Means shortcuts work */ 1423 1424 printk("%s%d at 0x%08x (irq = %d)", serial_driver->name, info->line, 1425 info->port, info->irq); 1426 printk(" is a builtin MC68328 UART\n"); 1427 1428 IRQ_ports[info->irq] = info; /* waste of space */ 1429 1430#ifdef CONFIG_M68VZ328 1431 if (i > 0 ) 1432 PJSEL &= 0xCF; /* PSW enable second port output */ 1433#endif 1434 1435 if (request_irq(uart_irqs[i], 1436 rs_interrupt, 1437 IRQ_FLG_STD, 1438 "M68328_UART", NULL)) 1439 panic("Unable to attach 68328 serial interrupt\n"); 1440#ifdef CONFIG_PM_LEGACY 1441 serial_pm[i] = pm_register(PM_SYS_DEV, PM_SYS_COM, serial_pm_callback); 1442 if (serial_pm[i]) 1443 serial_pm[i]->data = info; 1444#endif 1445 } 1446 local_irq_restore(flags); 1447 return 0; 1448} 1449 1450module_init(rs68328_init); 1451 1452 1453 1454static void m68328_set_baud(void) 1455{ 1456 unsigned short ustcnt; 1457 int i; 1458 1459 ustcnt = USTCNT; 1460 USTCNT = ustcnt & ~USTCNT_TXEN; 1461 1462again: 1463 for (i = 0; i < sizeof(baud_table) / sizeof(baud_table[0]); i++) 1464 if (baud_table[i] == m68328_console_baud) 1465 break; 1466 if (i >= sizeof(baud_table) / sizeof(baud_table[0])) { 1467 m68328_console_baud = 9600; 1468 goto again; 1469 } 1470 1471 UBAUD = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | 1472 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale); 1473 ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7); 1474 ustcnt |= USTCNT_8_7; 1475 ustcnt |= USTCNT_TXEN; 1476 USTCNT = ustcnt; 1477 m68328_console_initted = 1; 1478 return; 1479} 1480 1481 1482int m68328_console_setup(struct console *cp, char *arg) 1483{ 1484 int i, n = CONSOLE_BAUD_RATE; 1485 1486 if (!cp) 1487 return(-1); 1488 1489 if (arg) 1490 n = simple_strtoul(arg,NULL,0); 1491 1492 for (i = 0; i < BAUD_TABLE_SIZE; i++) 1493 if (baud_table[i] == n) 1494 break; 1495 if (i < BAUD_TABLE_SIZE) { 1496 m68328_console_baud = n; 1497 m68328_console_cbaud = 0; 1498 if (i > 15) { 1499 m68328_console_cbaud |= CBAUDEX; 1500 i -= 15; 1501 } 1502 m68328_console_cbaud |= i; 1503 } 1504 1505 m68328_set_baud(); /* make sure baud rate changes */ 1506 return(0); 1507} 1508 1509 1510static struct tty_driver *m68328_console_device(struct console *c, int *index) 1511{ 1512 *index = c->index; 1513 return serial_driver; 1514} 1515 1516 1517void m68328_console_write (struct console *co, const char *str, 1518 unsigned int count) 1519{ 1520 if (!m68328_console_initted) 1521 m68328_set_baud(); 1522 while (count--) { 1523 if (*str == '\n') 1524 rs_put_char('\r'); 1525 rs_put_char( *str++ ); 1526 } 1527} 1528 1529 1530static struct console m68328_driver = { 1531 .name = "ttyS", 1532 .write = m68328_console_write, 1533 .device = m68328_console_device, 1534 .setup = m68328_console_setup, 1535 .flags = CON_PRINTBUFFER, 1536 .index = -1, 1537}; 1538 1539 1540static int __init m68328_console_init(void) 1541{ 1542 register_console(&m68328_driver); 1543 return 0; 1544} 1545 1546console_initcall(m68328_console_init); 1547