udbg_16550.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * udbg for for NS16550 compatable serial ports
  3. *
  4. * Copyright (C) 2001-2005 PPC 64 Team, IBM Corp
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/types.h>
  13. #include <asm/ppcdebug.h>
  14. #include <asm/processor.h>
  15. #include <asm/naca.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/machdep.h>
  18. #include <asm/io.h>
  19. #include <asm/prom.h>
  20. extern u8 real_readb(volatile u8 __iomem *addr);
  21. extern void real_writeb(u8 data, volatile u8 __iomem *addr);
  22. struct NS16550 {
  23. /* this struct must be packed */
  24. unsigned char rbr; /* 0 */
  25. unsigned char ier; /* 1 */
  26. unsigned char fcr; /* 2 */
  27. unsigned char lcr; /* 3 */
  28. unsigned char mcr; /* 4 */
  29. unsigned char lsr; /* 5 */
  30. unsigned char msr; /* 6 */
  31. unsigned char scr; /* 7 */
  32. };
  33. #define thr rbr
  34. #define iir fcr
  35. #define dll rbr
  36. #define dlm ier
  37. #define dlab lcr
  38. #define LSR_DR 0x01 /* Data ready */
  39. #define LSR_OE 0x02 /* Overrun */
  40. #define LSR_PE 0x04 /* Parity error */
  41. #define LSR_FE 0x08 /* Framing error */
  42. #define LSR_BI 0x10 /* Break */
  43. #define LSR_THRE 0x20 /* Xmit holding register empty */
  44. #define LSR_TEMT 0x40 /* Xmitter empty */
  45. #define LSR_ERR 0x80 /* Error */
  46. static volatile struct NS16550 __iomem *udbg_comport;
  47. static void udbg_550_putc(unsigned char c)
  48. {
  49. if (udbg_comport) {
  50. while ((in_8(&udbg_comport->lsr) & LSR_THRE) == 0)
  51. /* wait for idle */;
  52. out_8(&udbg_comport->thr, c);
  53. if (c == '\n')
  54. udbg_550_putc('\r');
  55. }
  56. }
  57. static int udbg_550_getc_poll(void)
  58. {
  59. if (udbg_comport) {
  60. if ((in_8(&udbg_comport->lsr) & LSR_DR) != 0)
  61. return in_8(&udbg_comport->rbr);
  62. else
  63. return -1;
  64. }
  65. return -1;
  66. }
  67. static unsigned char udbg_550_getc(void)
  68. {
  69. if (udbg_comport) {
  70. while ((in_8(&udbg_comport->lsr) & LSR_DR) == 0)
  71. /* wait for char */;
  72. return in_8(&udbg_comport->rbr);
  73. }
  74. return 0;
  75. }
  76. void udbg_init_uart(void __iomem *comport, unsigned int speed)
  77. {
  78. u16 dll = speed ? (115200 / speed) : 12;
  79. if (comport) {
  80. udbg_comport = (struct NS16550 __iomem *)comport;
  81. out_8(&udbg_comport->lcr, 0x00);
  82. out_8(&udbg_comport->ier, 0xff);
  83. out_8(&udbg_comport->ier, 0x00);
  84. out_8(&udbg_comport->lcr, 0x80); /* Access baud rate */
  85. out_8(&udbg_comport->dll, dll & 0xff); /* 1 = 115200, 2 = 57600,
  86. 3 = 38400, 12 = 9600 baud */
  87. out_8(&udbg_comport->dlm, dll >> 8); /* dll >> 8 which should be zero
  88. for fast rates; */
  89. out_8(&udbg_comport->lcr, 0x03); /* 8 data, 1 stop, no parity */
  90. out_8(&udbg_comport->mcr, 0x03); /* RTS/DTR */
  91. out_8(&udbg_comport->fcr ,0x07); /* Clear & enable FIFOs */
  92. udbg_putc = udbg_550_putc;
  93. udbg_getc = udbg_550_getc;
  94. udbg_getc_poll = udbg_550_getc_poll;
  95. }
  96. }
  97. #ifdef CONFIG_PPC_MAPLE
  98. void udbg_maple_real_putc(unsigned char c)
  99. {
  100. if (udbg_comport) {
  101. while ((real_readb(&udbg_comport->lsr) & LSR_THRE) == 0)
  102. /* wait for idle */;
  103. real_writeb(c, &udbg_comport->thr); eieio();
  104. if (c == '\n')
  105. udbg_maple_real_putc('\r');
  106. }
  107. }
  108. void udbg_init_maple_realmode(void)
  109. {
  110. udbg_comport = (volatile struct NS16550 __iomem *)0xf40003f8;
  111. udbg_putc = udbg_maple_real_putc;
  112. udbg_getc = NULL;
  113. udbg_getc_poll = NULL;
  114. }
  115. #endif /* CONFIG_PPC_MAPLE */