[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 | |
---|
[e97e0e0] | 30 | #define NS16550_STATIC static |
---|
[27045a82] | 31 | |
---|
[0737710] | 32 | /* |
---|
| 33 | * Define serial port read registers structure. |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | typedef volatile struct _SP_READ_REGISTERS { |
---|
| 37 | unsigned char ReceiveBuffer; |
---|
| 38 | unsigned char InterruptEnable; |
---|
| 39 | unsigned char InterruptId; |
---|
| 40 | unsigned char LineControl; |
---|
| 41 | unsigned char ModemControl; |
---|
| 42 | unsigned char LineStatus; |
---|
| 43 | unsigned char ModemStatus; |
---|
| 44 | unsigned char ScratchPad; |
---|
| 45 | } SP_READ_REGISTERS, *PSP_READ_REGISTERS; |
---|
| 46 | |
---|
| 47 | #define NS16550_RECEIVE_BUFFER 0 |
---|
| 48 | #define NS16550_INTERRUPT_ENABLE 1 |
---|
| 49 | #define NS16550_INTERRUPT_ID 2 |
---|
| 50 | #define NS16550_LINE_CONTROL 3 |
---|
| 51 | #define NS16550_MODEM_CONTROL 4 |
---|
| 52 | #define NS16550_LINE_STATUS 5 |
---|
| 53 | #define NS16550_MODEM_STATUS 6 |
---|
| 54 | #define NS16550_SCRATCH_PAD 7 |
---|
[aa0da6b] | 55 | |
---|
[0737710] | 56 | /* |
---|
| 57 | * Define serial port write registers structure. |
---|
| 58 | */ |
---|
| 59 | |
---|
| 60 | typedef volatile struct _SP_WRITE_REGISTERS { |
---|
| 61 | unsigned char TransmitBuffer; |
---|
| 62 | unsigned char InterruptEnable; |
---|
| 63 | unsigned char FifoControl; |
---|
| 64 | unsigned char LineControl; |
---|
| 65 | unsigned char ModemControl; |
---|
| 66 | unsigned char Reserved1; |
---|
| 67 | unsigned char ModemStatus; |
---|
| 68 | unsigned char ScratchPad; |
---|
| 69 | } SP_WRITE_REGISTERS, *PSP_WRITE_REGISTERS; |
---|
| 70 | |
---|
| 71 | #define NS16550_TRANSMIT_BUFFER 0 |
---|
| 72 | #define NS16550_FIFO_CONTROL 2 |
---|
| 73 | |
---|
| 74 | /* |
---|
| 75 | * Define serial port interrupt enable register structure. |
---|
| 76 | */ |
---|
| 77 | |
---|
[aa0da6b] | 78 | #define SP_INT_RX_ENABLE 0x01 |
---|
| 79 | #define SP_INT_TX_ENABLE 0x02 |
---|
| 80 | #define SP_INT_LS_ENABLE 0x04 |
---|
| 81 | #define SP_INT_MS_ENABLE 0x08 |
---|
[0737710] | 82 | |
---|
[70a9451] | 83 | #define NS16550_ENABLE_ALL_INTR (SP_INT_RX_ENABLE | SP_INT_TX_ENABLE) |
---|
| 84 | #define NS16550_DISABLE_ALL_INTR 0x00 |
---|
| 85 | #define NS16550_ENABLE_ALL_INTR_EXCEPT_TX (SP_INT_RX_ENABLE) |
---|
| 86 | |
---|
[0737710] | 87 | /* |
---|
| 88 | * Define serial port interrupt id register structure. |
---|
| 89 | */ |
---|
| 90 | |
---|
| 91 | typedef struct _SP_INTERRUPT_ID { |
---|
| 92 | unsigned char InterruptPending : 1; |
---|
| 93 | unsigned char Identification : 3; |
---|
| 94 | unsigned char Reserved1 : 2; |
---|
| 95 | unsigned char FifoEnabled : 2; |
---|
| 96 | } SP_INTERRUPT_ID, *PSP_INTERRUPT_ID; |
---|
| 97 | |
---|
| 98 | /* |
---|
| 99 | * Define serial port fifo control register structure. |
---|
| 100 | */ |
---|
[aa0da6b] | 101 | |
---|
| 102 | #define SP_FIFO_ENABLE 0x01 |
---|
| 103 | #define SP_FIFO_RXRST 0x02 |
---|
| 104 | #define SP_FIFO_TXRST 0x04 |
---|
| 105 | #define SP_FIFO_DMA 0x08 |
---|
| 106 | #define SP_FIFO_RXLEVEL 0xc0 |
---|
[0737710] | 107 | |
---|
| 108 | /* |
---|
| 109 | * Define serial port line control register structure. |
---|
| 110 | */ |
---|
[aa0da6b] | 111 | |
---|
| 112 | #define SP_LINE_SIZE 0x03 |
---|
| 113 | #define SP_LINE_STOP 0x04 |
---|
| 114 | #define SP_LINE_PAR 0x08 |
---|
| 115 | #define SP_LINE_ODD 0x10 |
---|
| 116 | #define SP_LINE_STICK 0x20 |
---|
| 117 | #define SP_LINE_BREAK 0x40 |
---|
| 118 | #define SP_LINE_DLAB 0x80 |
---|
[0737710] | 119 | |
---|
| 120 | /* |
---|
| 121 | * Line status register character size definitions. |
---|
| 122 | */ |
---|
[aa0da6b] | 123 | |
---|
[0737710] | 124 | #define FIVE_BITS 0x0 /* five bits per character */ |
---|
| 125 | #define SIX_BITS 0x1 /* six bits per character */ |
---|
| 126 | #define SEVEN_BITS 0x2 /* seven bits per character */ |
---|
| 127 | #define EIGHT_BITS 0x3 /* eight bits per character */ |
---|
| 128 | |
---|
| 129 | /* |
---|
| 130 | * Line speed divisor definition. |
---|
| 131 | */ |
---|
[aa0da6b] | 132 | |
---|
[df49c60] | 133 | #define NS16550_Baud(_clock, _baud_rate) \ |
---|
[1b3028c] | 134 | ((((_clock) == 0) ? 115200 : (_clock))/(_baud_rate*16)) |
---|
[0737710] | 135 | |
---|
| 136 | /* |
---|
| 137 | * Define serial port modem control register structure. |
---|
| 138 | */ |
---|
[aa0da6b] | 139 | |
---|
| 140 | #define SP_MODEM_DTR 0x01 |
---|
| 141 | #define SP_MODEM_RTS 0x02 |
---|
| 142 | #define SP_MODEM_IRQ 0x08 |
---|
| 143 | #define SP_MODEM_LOOP 0x10 |
---|
| 144 | #define SP_MODEM_DIV4 0x80 |
---|
[0737710] | 145 | |
---|
| 146 | /* |
---|
| 147 | * Define serial port line status register structure. |
---|
| 148 | */ |
---|
[aa0da6b] | 149 | |
---|
| 150 | #define SP_LSR_RDY 0x01 |
---|
| 151 | #define SP_LSR_EOVRUN 0x02 |
---|
| 152 | #define SP_LSR_EPAR 0x04 |
---|
| 153 | #define SP_LSR_EFRAME 0x08 |
---|
| 154 | #define SP_LSR_BREAK 0x10 |
---|
| 155 | #define SP_LSR_THOLD 0x20 |
---|
| 156 | #define SP_LSR_TX 0x40 |
---|
| 157 | #define SP_LSR_EFIFO 0x80 |
---|
[0737710] | 158 | |
---|
| 159 | typedef struct _ns16550_context |
---|
| 160 | { |
---|
[ee4f57d] | 161 | uint8_t ucModemCtrl; |
---|
[0737710] | 162 | } ns16550_context; |
---|
| 163 | |
---|
| 164 | /* |
---|
| 165 | * Driver functions |
---|
| 166 | */ |
---|
[aa0da6b] | 167 | |
---|
[6640459d] | 168 | NS16550_STATIC bool ns16550_probe(int minor); |
---|
[0737710] | 169 | |
---|
[27045a82] | 170 | NS16550_STATIC void ns16550_init(int minor); |
---|
[0737710] | 171 | |
---|
[27045a82] | 172 | NS16550_STATIC int ns16550_open( |
---|
[aa0da6b] | 173 | int major, |
---|
| 174 | int minor, |
---|
| 175 | void * arg |
---|
[0737710] | 176 | ); |
---|
| 177 | |
---|
[27045a82] | 178 | NS16550_STATIC int ns16550_close( |
---|
[aa0da6b] | 179 | int major, |
---|
| 180 | int minor, |
---|
| 181 | void * arg |
---|
[0737710] | 182 | ); |
---|
| 183 | |
---|
[27045a82] | 184 | NS16550_STATIC void ns16550_write_polled( |
---|
[a3d3d9a] | 185 | int minor, |
---|
[aa0da6b] | 186 | char cChar |
---|
[0737710] | 187 | ); |
---|
| 188 | |
---|
[27045a82] | 189 | NS16550_STATIC int ns16550_assert_RTS( |
---|
[aa0da6b] | 190 | int minor |
---|
[0737710] | 191 | ); |
---|
| 192 | |
---|
[27045a82] | 193 | NS16550_STATIC int ns16550_negate_RTS( |
---|
[aa0da6b] | 194 | int minor |
---|
[0737710] | 195 | ); |
---|
| 196 | |
---|
[27045a82] | 197 | NS16550_STATIC int ns16550_assert_DTR( |
---|
[aa0da6b] | 198 | int minor |
---|
[0737710] | 199 | ); |
---|
| 200 | |
---|
[27045a82] | 201 | NS16550_STATIC int ns16550_negate_DTR( |
---|
[aa0da6b] | 202 | int minor |
---|
[0737710] | 203 | ); |
---|
| 204 | |
---|
[27045a82] | 205 | NS16550_STATIC void ns16550_initialize_interrupts(int minor); |
---|
[0737710] | 206 | |
---|
[27045a82] | 207 | NS16550_STATIC int ns16550_write_support_int( |
---|
[aa0da6b] | 208 | int minor, |
---|
| 209 | const char *buf, |
---|
| 210 | int len |
---|
[0737710] | 211 | ); |
---|
| 212 | |
---|
[27045a82] | 213 | NS16550_STATIC int ns16550_write_support_polled( |
---|
[aa0da6b] | 214 | int minor, |
---|
| 215 | const char *buf, |
---|
| 216 | int len |
---|
| 217 | ); |
---|
[0737710] | 218 | |
---|
[27045a82] | 219 | NS16550_STATIC int ns16550_inbyte_nonblocking_polled( |
---|
[aa0da6b] | 220 | int minor |
---|
[0737710] | 221 | ); |
---|
| 222 | |
---|
[70a9451] | 223 | NS16550_STATIC void ns16550_enable_interrupts( |
---|
| 224 | int minor, |
---|
| 225 | int mask |
---|
| 226 | ); |
---|
| 227 | |
---|
[8739322] | 228 | NS16550_STATIC int ns16550_set_attributes( |
---|
| 229 | int minor, |
---|
| 230 | const struct termios *t |
---|
| 231 | ); |
---|
| 232 | |
---|
[0737710] | 233 | #ifdef __cplusplus |
---|
| 234 | } |
---|
| 235 | #endif |
---|
| 236 | |
---|
| 237 | #endif /* _NS16550_P_H_ */ |
---|