promcon.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * PROM console for Cobalt Raq2
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 1995, 1996, 1997 by Ralf Baechle
  9. * Copyright (C) 2001 by Liam Davies (ldavies@agile.tv)
  10. *
  11. */
  12. #include <linux/init.h>
  13. #include <linux/console.h>
  14. #include <linux/kdev_t.h>
  15. #include <linux/serial_reg.h>
  16. #include <asm/delay.h>
  17. #include <asm/serial.h>
  18. #include <asm/io.h>
  19. static unsigned long port = 0xc800000;
  20. static __inline__ void ns16550_cons_put_char(char ch, unsigned long ioaddr)
  21. {
  22. char lsr;
  23. do {
  24. lsr = inb(ioaddr + UART_LSR);
  25. } while ((lsr & (UART_LSR_TEMT | UART_LSR_THRE)) != (UART_LSR_TEMT | UART_LSR_THRE));
  26. outb(ch, ioaddr + UART_TX);
  27. }
  28. static __inline__ char ns16550_cons_get_char(unsigned long ioaddr)
  29. {
  30. while ((inb(ioaddr + UART_LSR) & UART_LSR_DR) == 0)
  31. udelay(1);
  32. return inb(ioaddr + UART_RX);
  33. }
  34. void ns16550_console_write(struct console *co, const char *s, unsigned count)
  35. {
  36. char lsr, ier;
  37. unsigned i;
  38. ier = inb(port + UART_IER);
  39. outb(0x00, port + UART_IER);
  40. for (i=0; i < count; i++, s++) {
  41. if(*s == '\n')
  42. ns16550_cons_put_char('\r', port);
  43. ns16550_cons_put_char(*s, port);
  44. }
  45. do {
  46. lsr = inb(port + UART_LSR);
  47. } while ((lsr & (UART_LSR_TEMT | UART_LSR_THRE)) != (UART_LSR_TEMT | UART_LSR_THRE));
  48. outb(ier, port + UART_IER);
  49. }
  50. char getDebugChar(void)
  51. {
  52. return ns16550_cons_get_char(port);
  53. }
  54. void putDebugChar(char kgdb_char)
  55. {
  56. ns16550_cons_put_char(kgdb_char, port);
  57. }
  58. static struct console ns16550_console = {
  59. .name = "prom",
  60. .setup = NULL,
  61. .write = ns16550_console_write,
  62. .flags = CON_PRINTBUFFER,
  63. .index = -1,
  64. };
  65. static int __init ns16550_setup_console(void)
  66. {
  67. register_console(&ns16550_console);
  68. return 0;
  69. }
  70. console_initcall(ns16550_setup_console);