[0737710] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 1998 by Radstone Technology |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * THIS FILE IS PROVIDED TO YOU, THE USER, "AS IS", WITHOUT WARRANTY OF ANY |
---|
| 6 | * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 7 | * IMPLIED WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK |
---|
| 8 | * AS TO THE QUALITY AND PERFORMANCE OF ALL CODE IN THIS FILE IS WITH YOU. |
---|
| 9 | * |
---|
| 10 | * You are hereby granted permission to use, copy, modify, and distribute |
---|
| 11 | * this file, provided that this notice, plus the above copyright notice |
---|
| 12 | * and disclaimer, appears in all copies. Radstone Technology will provide |
---|
| 13 | * no support for this code. |
---|
| 14 | * |
---|
[aa0da6b] | 15 | * $Id$ |
---|
[0737710] | 16 | */ |
---|
| 17 | |
---|
| 18 | #ifndef _NS16550_P_H_ |
---|
| 19 | #define _NS16550_P_H_ |
---|
| 20 | |
---|
| 21 | #ifdef __cplusplus |
---|
| 22 | extern "C" { |
---|
| 23 | #endif |
---|
[aa0da6b] | 24 | |
---|
[27045a82] | 25 | /* |
---|
| 26 | * Define NS16550_STATIC to nothing while debugging so the entry points |
---|
| 27 | * will show up in the symbol table. |
---|
| 28 | */ |
---|
| 29 | |
---|
[d1e10fe6] | 30 | #define NS16550_STATIC |
---|
[27045a82] | 31 | |
---|
[0737710] | 32 | #define NS16550_RECEIVE_BUFFER 0 |
---|
[ec5d4505] | 33 | #define NS16550_TRANSMIT_BUFFER 0 |
---|
[0737710] | 34 | #define NS16550_INTERRUPT_ENABLE 1 |
---|
| 35 | #define NS16550_INTERRUPT_ID 2 |
---|
[ec5d4505] | 36 | #define NS16550_FIFO_CONTROL 2 |
---|
[0737710] | 37 | #define NS16550_LINE_CONTROL 3 |
---|
| 38 | #define NS16550_MODEM_CONTROL 4 |
---|
| 39 | #define NS16550_LINE_STATUS 5 |
---|
| 40 | #define NS16550_MODEM_STATUS 6 |
---|
| 41 | #define NS16550_SCRATCH_PAD 7 |
---|
[aa0da6b] | 42 | |
---|
[0737710] | 43 | /* |
---|
| 44 | * Define serial port interrupt enable register structure. |
---|
| 45 | */ |
---|
| 46 | |
---|
[aa0da6b] | 47 | #define SP_INT_RX_ENABLE 0x01 |
---|
| 48 | #define SP_INT_TX_ENABLE 0x02 |
---|
| 49 | #define SP_INT_LS_ENABLE 0x04 |
---|
| 50 | #define SP_INT_MS_ENABLE 0x08 |
---|
[0737710] | 51 | |
---|
[70a9451] | 52 | #define NS16550_ENABLE_ALL_INTR (SP_INT_RX_ENABLE | SP_INT_TX_ENABLE) |
---|
| 53 | #define NS16550_DISABLE_ALL_INTR 0x00 |
---|
| 54 | #define NS16550_ENABLE_ALL_INTR_EXCEPT_TX (SP_INT_RX_ENABLE) |
---|
| 55 | |
---|
[0737710] | 56 | /* |
---|
[ec5d4505] | 57 | * Define serial port interrupt ID register structure. |
---|
[0737710] | 58 | */ |
---|
| 59 | |
---|
[ec5d4505] | 60 | #define SP_IID_0 0x01 |
---|
| 61 | #define SP_IID_1 0x02 |
---|
| 62 | #define SP_IID_2 0x04 |
---|
| 63 | #define SP_IID_3 0x08 |
---|
[0737710] | 64 | |
---|
| 65 | /* |
---|
| 66 | * Define serial port fifo control register structure. |
---|
| 67 | */ |
---|
[aa0da6b] | 68 | |
---|
| 69 | #define SP_FIFO_ENABLE 0x01 |
---|
| 70 | #define SP_FIFO_RXRST 0x02 |
---|
| 71 | #define SP_FIFO_TXRST 0x04 |
---|
| 72 | #define SP_FIFO_DMA 0x08 |
---|
| 73 | #define SP_FIFO_RXLEVEL 0xc0 |
---|
[0737710] | 74 | |
---|
[ec5d4505] | 75 | #define SP_FIFO_SIZE 16 |
---|
| 76 | |
---|
[0737710] | 77 | /* |
---|
| 78 | * Define serial port line control register structure. |
---|
| 79 | */ |
---|
[aa0da6b] | 80 | |
---|
| 81 | #define SP_LINE_SIZE 0x03 |
---|
| 82 | #define SP_LINE_STOP 0x04 |
---|
| 83 | #define SP_LINE_PAR 0x08 |
---|
| 84 | #define SP_LINE_ODD 0x10 |
---|
| 85 | #define SP_LINE_STICK 0x20 |
---|
| 86 | #define SP_LINE_BREAK 0x40 |
---|
| 87 | #define SP_LINE_DLAB 0x80 |
---|
[0737710] | 88 | |
---|
| 89 | /* |
---|
| 90 | * Line status register character size definitions. |
---|
| 91 | */ |
---|
[aa0da6b] | 92 | |
---|
[0737710] | 93 | #define FIVE_BITS 0x0 /* five bits per character */ |
---|
| 94 | #define SIX_BITS 0x1 /* six bits per character */ |
---|
| 95 | #define SEVEN_BITS 0x2 /* seven bits per character */ |
---|
| 96 | #define EIGHT_BITS 0x3 /* eight bits per character */ |
---|
| 97 | |
---|
| 98 | /* |
---|
| 99 | * Line speed divisor definition. |
---|
| 100 | */ |
---|
[aa0da6b] | 101 | |
---|
[df49c60] | 102 | #define NS16550_Baud(_clock, _baud_rate) \ |
---|
[1b3028c] | 103 | ((((_clock) == 0) ? 115200 : (_clock))/(_baud_rate*16)) |
---|
[0737710] | 104 | |
---|
| 105 | /* |
---|
| 106 | * Define serial port modem control register structure. |
---|
| 107 | */ |
---|
[aa0da6b] | 108 | |
---|
| 109 | #define SP_MODEM_DTR 0x01 |
---|
| 110 | #define SP_MODEM_RTS 0x02 |
---|
| 111 | #define SP_MODEM_IRQ 0x08 |
---|
| 112 | #define SP_MODEM_LOOP 0x10 |
---|
| 113 | #define SP_MODEM_DIV4 0x80 |
---|
[0737710] | 114 | |
---|
| 115 | /* |
---|
| 116 | * Define serial port line status register structure. |
---|
| 117 | */ |
---|
[aa0da6b] | 118 | |
---|
| 119 | #define SP_LSR_RDY 0x01 |
---|
| 120 | #define SP_LSR_EOVRUN 0x02 |
---|
| 121 | #define SP_LSR_EPAR 0x04 |
---|
| 122 | #define SP_LSR_EFRAME 0x08 |
---|
| 123 | #define SP_LSR_BREAK 0x10 |
---|
| 124 | #define SP_LSR_THOLD 0x20 |
---|
| 125 | #define SP_LSR_TX 0x40 |
---|
| 126 | #define SP_LSR_EFIFO 0x80 |
---|
[0737710] | 127 | |
---|
[ec5d4505] | 128 | typedef struct { |
---|
| 129 | uint8_t ucModemCtrl; |
---|
| 130 | int transmitFifoChars; |
---|
[0737710] | 131 | } ns16550_context; |
---|
| 132 | |
---|
| 133 | /* |
---|
| 134 | * Driver functions |
---|
| 135 | */ |
---|
[aa0da6b] | 136 | |
---|
[27045a82] | 137 | NS16550_STATIC void ns16550_init(int minor); |
---|
[0737710] | 138 | |
---|
[27045a82] | 139 | NS16550_STATIC int ns16550_open( |
---|
[aa0da6b] | 140 | int major, |
---|
| 141 | int minor, |
---|
| 142 | void * arg |
---|
[0737710] | 143 | ); |
---|
| 144 | |
---|
[27045a82] | 145 | NS16550_STATIC int ns16550_close( |
---|
[aa0da6b] | 146 | int major, |
---|
| 147 | int minor, |
---|
| 148 | void * arg |
---|
[0737710] | 149 | ); |
---|
| 150 | |
---|
[27045a82] | 151 | NS16550_STATIC void ns16550_write_polled( |
---|
[a3d3d9a] | 152 | int minor, |
---|
[aa0da6b] | 153 | char cChar |
---|
[0737710] | 154 | ); |
---|
| 155 | |
---|
[27045a82] | 156 | NS16550_STATIC int ns16550_assert_RTS( |
---|
[aa0da6b] | 157 | int minor |
---|
[0737710] | 158 | ); |
---|
| 159 | |
---|
[27045a82] | 160 | NS16550_STATIC int ns16550_negate_RTS( |
---|
[aa0da6b] | 161 | int minor |
---|
[0737710] | 162 | ); |
---|
| 163 | |
---|
[27045a82] | 164 | NS16550_STATIC int ns16550_assert_DTR( |
---|
[aa0da6b] | 165 | int minor |
---|
[0737710] | 166 | ); |
---|
| 167 | |
---|
[27045a82] | 168 | NS16550_STATIC int ns16550_negate_DTR( |
---|
[aa0da6b] | 169 | int minor |
---|
[0737710] | 170 | ); |
---|
| 171 | |
---|
[27045a82] | 172 | NS16550_STATIC void ns16550_initialize_interrupts(int minor); |
---|
[0737710] | 173 | |
---|
[fbf7e58] | 174 | NS16550_STATIC void ns16550_cleanup_interrupts(int minor); |
---|
| 175 | |
---|
[3ed964f9] | 176 | NS16550_STATIC ssize_t ns16550_write_support_int( |
---|
[aa0da6b] | 177 | int minor, |
---|
| 178 | const char *buf, |
---|
[3ed964f9] | 179 | size_t len |
---|
[0737710] | 180 | ); |
---|
| 181 | |
---|
[3ed964f9] | 182 | NS16550_STATIC ssize_t ns16550_write_support_polled( |
---|
[aa0da6b] | 183 | int minor, |
---|
| 184 | const char *buf, |
---|
[3ed964f9] | 185 | size_t len |
---|
[aa0da6b] | 186 | ); |
---|
[0737710] | 187 | |
---|
[27045a82] | 188 | NS16550_STATIC int ns16550_inbyte_nonblocking_polled( |
---|
[aa0da6b] | 189 | int minor |
---|
[0737710] | 190 | ); |
---|
| 191 | |
---|
[70a9451] | 192 | NS16550_STATIC void ns16550_enable_interrupts( |
---|
| 193 | int minor, |
---|
| 194 | int mask |
---|
| 195 | ); |
---|
| 196 | |
---|
[8739322] | 197 | NS16550_STATIC int ns16550_set_attributes( |
---|
| 198 | int minor, |
---|
| 199 | const struct termios *t |
---|
| 200 | ); |
---|
| 201 | |
---|
[0737710] | 202 | #ifdef __cplusplus |
---|
| 203 | } |
---|
| 204 | #endif |
---|
| 205 | |
---|
| 206 | #endif /* _NS16550_P_H_ */ |
---|