wdenk | 717b5aa | 2002-04-27 11:09:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * NS16550 Serial Port |
| 3 | * originally from linux source (arch/ppc/boot/ns16550.h) |
| 4 | * modified slightly to |
| 5 | * have addresses as offsets from CFG_ISA_BASE |
| 6 | * added a few more definitions |
| 7 | * added prototypes for ns16550.c |
| 8 | * reduced no of com ports to 2 |
| 9 | * modifications (c) Rob Taylor, Flying Pig Systems. 2000. |
| 10 | */ |
| 11 | |
| 12 | #if (CFG_NS16550_REG_SIZE == 1) |
| 13 | struct NS16550 { |
| 14 | unsigned char rbr; /* 0 */ |
| 15 | unsigned char ier; /* 1 */ |
| 16 | unsigned char fcr; /* 2 */ |
| 17 | unsigned char lcr; /* 3 */ |
| 18 | unsigned char mcr; /* 4 */ |
| 19 | unsigned char lsr; /* 5 */ |
| 20 | unsigned char msr; /* 6 */ |
| 21 | unsigned char scr; /* 7 */ |
wdenk | e3a0680 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 22 | #if defined(CONFIG_OMAP730) |
| 23 | unsigned char mdr1; /* 8 */ |
| 24 | unsigned char reg9; /* 9 */ |
| 25 | unsigned char regA; /* A */ |
| 26 | unsigned char regB; /* B */ |
| 27 | unsigned char regC; /* C */ |
| 28 | unsigned char regD; /* D */ |
| 29 | unsigned char regE; /* E */ |
| 30 | unsigned char regF; /* F */ |
| 31 | unsigned char reg10; /* 10 */ |
| 32 | unsigned char ssr; /* 11*/ |
| 33 | #endif |
wdenk | 717b5aa | 2002-04-27 11:09:31 +0000 | [diff] [blame] | 34 | } __attribute__ ((packed)); |
| 35 | #elif (CFG_NS16550_REG_SIZE == 2) |
| 36 | struct NS16550 { |
| 37 | unsigned short rbr; /* 0 */ |
| 38 | unsigned short ier; /* 1 */ |
| 39 | unsigned short fcr; /* 2 */ |
| 40 | unsigned short lcr; /* 3 */ |
| 41 | unsigned short mcr; /* 4 */ |
| 42 | unsigned short lsr; /* 5 */ |
| 43 | unsigned short msr; /* 6 */ |
| 44 | unsigned short scr; /* 7 */ |
| 45 | } __attribute__ ((packed)); |
| 46 | #elif (CFG_NS16550_REG_SIZE == 4) |
| 47 | struct NS16550 { |
Wolfgang Denk | 4b416fe | 2006-03-12 01:21:19 +0100 | [diff] [blame^] | 48 | unsigned long rbr; /* 0 r */ |
| 49 | unsigned long ier; /* 1 rw */ |
| 50 | unsigned long fcr; /* 2 w */ |
| 51 | unsigned long lcr; /* 3 rw */ |
| 52 | unsigned long mcr; /* 4 rw */ |
| 53 | unsigned long lsr; /* 5 r */ |
| 54 | unsigned long msr; /* 6 r */ |
| 55 | unsigned long scr; /* 7 rw */ |
| 56 | }; /* No need to pack an already aligned struct */ |
wdenk | 717b5aa | 2002-04-27 11:09:31 +0000 | [diff] [blame] | 57 | #elif (CFG_NS16550_REG_SIZE == -4) |
| 58 | struct NS16550 { |
| 59 | unsigned char rbr; /* 0 */ |
| 60 | int pad1:24; |
| 61 | unsigned char ier; /* 1 */ |
| 62 | int pad2:24; |
| 63 | unsigned char fcr; /* 2 */ |
| 64 | int pad3:24; |
| 65 | unsigned char lcr; /* 3 */ |
| 66 | int pad4:24; |
| 67 | unsigned char mcr; /* 4 */ |
| 68 | int pad5:24; |
| 69 | unsigned char lsr; /* 5 */ |
| 70 | int pad6:24; |
| 71 | unsigned char msr; /* 6 */ |
| 72 | int pad7:24; |
| 73 | unsigned char scr; /* 7 */ |
| 74 | int pad8:24; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 75 | #if defined(CONFIG_OMAP) |
wdenk | f6f96f7 | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 76 | unsigned char mdr1; /* mode select reset TL16C750*/ |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 77 | #endif |
| 78 | #ifdef CONFIG_OMAP1510 |
wdenk | f6f96f7 | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 79 | int pad9:24; |
| 80 | unsigned long pad[10]; |
| 81 | unsigned char osc_12m_sel; |
| 82 | int pad10:24; |
| 83 | #endif |
wdenk | 717b5aa | 2002-04-27 11:09:31 +0000 | [diff] [blame] | 84 | } __attribute__ ((packed)); |
| 85 | #else |
| 86 | #error "Please define NS16550 registers size." |
| 87 | #endif |
| 88 | |
| 89 | #define thr rbr |
| 90 | #define iir fcr |
| 91 | #define dll rbr |
| 92 | #define dlm ier |
| 93 | |
| 94 | typedef volatile struct NS16550 *NS16550_t; |
| 95 | |
| 96 | #define FCR_FIFO_EN 0x01 /* Fifo enable */ |
| 97 | #define FCR_RXSR 0x02 /* Receiver soft reset */ |
| 98 | #define FCR_TXSR 0x04 /* Transmitter soft reset */ |
| 99 | |
| 100 | #define MCR_DTR 0x01 |
| 101 | #define MCR_RTS 0x02 |
| 102 | #define MCR_DMA_EN 0x04 |
| 103 | #define MCR_TX_DFR 0x08 |
| 104 | |
Wolfgang Denk | 4b416fe | 2006-03-12 01:21:19 +0100 | [diff] [blame^] | 105 | #define LCR_WLS_MSK 0x03 /* character length select mask */ |
wdenk | 717b5aa | 2002-04-27 11:09:31 +0000 | [diff] [blame] | 106 | #define LCR_WLS_5 0x00 /* 5 bit character length */ |
| 107 | #define LCR_WLS_6 0x01 /* 6 bit character length */ |
| 108 | #define LCR_WLS_7 0x02 /* 7 bit character length */ |
| 109 | #define LCR_WLS_8 0x03 /* 8 bit character length */ |
| 110 | #define LCR_STB 0x04 /* Number of stop Bits, off = 1, on = 1.5 or 2) */ |
| 111 | #define LCR_PEN 0x08 /* Parity eneble */ |
| 112 | #define LCR_EPS 0x10 /* Even Parity Select */ |
| 113 | #define LCR_STKP 0x20 /* Stick Parity */ |
| 114 | #define LCR_SBRK 0x40 /* Set Break */ |
| 115 | #define LCR_BKSE 0x80 /* Bank select enable */ |
| 116 | |
| 117 | #define LSR_DR 0x01 /* Data ready */ |
| 118 | #define LSR_OE 0x02 /* Overrun */ |
| 119 | #define LSR_PE 0x04 /* Parity error */ |
| 120 | #define LSR_FE 0x08 /* Framing error */ |
| 121 | #define LSR_BI 0x10 /* Break */ |
| 122 | #define LSR_THRE 0x20 /* Xmit holding register empty */ |
| 123 | #define LSR_TEMT 0x40 /* Xmitter empty */ |
| 124 | #define LSR_ERR 0x80 /* Error */ |
| 125 | |
wdenk | f6f96f7 | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 126 | #ifdef CONFIG_OMAP1510 |
| 127 | #define OSC_12M_SEL 0x01 /* selects 6.5 * current clk div */ |
| 128 | #endif |
| 129 | |
wdenk | 717b5aa | 2002-04-27 11:09:31 +0000 | [diff] [blame] | 130 | /* useful defaults for LCR */ |
| 131 | #define LCR_8N1 0x03 |
| 132 | |
| 133 | void NS16550_init (NS16550_t com_port, int baud_divisor); |
| 134 | void NS16550_putc (NS16550_t com_port, char c); |
| 135 | char NS16550_getc (NS16550_t com_port); |
| 136 | int NS16550_tstc (NS16550_t com_port); |
| 137 | void NS16550_reinit (NS16550_t com_port, int baud_divisor); |