ns16550.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * COM1 NS16550 support
  3. */
  4. #include <linux/config.h>
  5. #include <linux/types.h>
  6. #include <linux/serial.h>
  7. #include <linux/serial_reg.h>
  8. #include <asm/serial.h>
  9. #if defined(CONFIG_XILINX_VIRTEX)
  10. #include <platforms/4xx/xparameters/xparameters.h>
  11. #endif
  12. #include "nonstdio.h"
  13. #include "serial.h"
  14. #define SERIAL_BAUD 9600
  15. extern unsigned long ISA_io;
  16. static struct serial_state rs_table[RS_TABLE_SIZE] = {
  17. SERIAL_PORT_DFNS /* Defined in <asm/serial.h> */
  18. };
  19. static int shift;
  20. unsigned long serial_init(int chan, void *ignored)
  21. {
  22. unsigned long com_port, base_baud;
  23. unsigned char lcr, dlm;
  24. /* We need to find out which type io we're expecting. If it's
  25. * 'SERIAL_IO_PORT', we get an offset from the isa_io_base.
  26. * If it's 'SERIAL_IO_MEM', we can the exact location. -- Tom */
  27. switch (rs_table[chan].io_type) {
  28. case SERIAL_IO_PORT:
  29. com_port = rs_table[chan].port;
  30. break;
  31. case SERIAL_IO_MEM:
  32. com_port = (unsigned long)rs_table[chan].iomem_base;
  33. break;
  34. default:
  35. /* We can't deal with it. */
  36. return -1;
  37. }
  38. /* How far apart the registers are. */
  39. shift = rs_table[chan].iomem_reg_shift;
  40. /* Base baud.. */
  41. base_baud = rs_table[chan].baud_base;
  42. /* save the LCR */
  43. lcr = inb(com_port + (UART_LCR << shift));
  44. /* Access baud rate */
  45. outb(com_port + (UART_LCR << shift), 0x80);
  46. dlm = inb(com_port + (UART_DLM << shift));
  47. /*
  48. * Test if serial port is unconfigured.
  49. * We assume that no-one uses less than 110 baud or
  50. * less than 7 bits per character these days.
  51. * -- paulus.
  52. */
  53. if ((dlm <= 4) && (lcr & 2))
  54. /* port is configured, put the old LCR back */
  55. outb(com_port + (UART_LCR << shift), lcr);
  56. else {
  57. /* Input clock. */
  58. outb(com_port + (UART_DLL << shift),
  59. (base_baud / SERIAL_BAUD) & 0xFF);
  60. outb(com_port + (UART_DLM << shift),
  61. (base_baud / SERIAL_BAUD) >> 8);
  62. /* 8 data, 1 stop, no parity */
  63. outb(com_port + (UART_LCR << shift), 0x03);
  64. /* RTS/DTR */
  65. outb(com_port + (UART_MCR << shift), 0x03);
  66. }
  67. /* Clear & enable FIFOs */
  68. outb(com_port + (UART_FCR << shift), 0x07);
  69. return (com_port);
  70. }
  71. void
  72. serial_putc(unsigned long com_port, unsigned char c)
  73. {
  74. while ((inb(com_port + (UART_LSR << shift)) & UART_LSR_THRE) == 0)
  75. ;
  76. outb(com_port, c);
  77. }
  78. unsigned char
  79. serial_getc(unsigned long com_port)
  80. {
  81. while ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) == 0)
  82. ;
  83. return inb(com_port);
  84. }
  85. int
  86. serial_tstc(unsigned long com_port)
  87. {
  88. return ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) != 0);
  89. }