ns16550.c 2.4 KB

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