iPXE
ns16550.h
Go to the documentation of this file.
1#ifndef _IPXE_NS16550_H
2#define _IPXE_NS16550_H
3
4/** @file
5 *
6 * 16550-compatible UART
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
12#include <ipxe/uart.h>
13
14/** Length of register region */
15#define NS16550_LEN 8
16
17/** Transmitter holding register */
18#define NS16550_THR 0x00
19
20/** Receiver buffer register */
21#define NS16550_RBR 0x00
22
23/** Interrupt enable register */
24#define NS16550_IER 0x01
25
26/** FIFO control register */
27#define NS16550_FCR 0x02
28#define NS16550_FCR_FE 0x01 /**< FIFO enable */
29
30/** Line control register */
31#define NS16550_LCR 0x03
32#define NS16550_LCR_WLS0 0x01 /**< Word length select bit 0 */
33#define NS16550_LCR_WLS1 0x02 /**< Word length select bit 1 */
34#define NS16550_LCR_STB 0x04 /**< Number of stop bits */
35#define NS16550_LCR_PEN 0x08 /**< Parity enable */
36#define NS16550_LCR_EPS 0x10 /**< Even parity select */
37#define NS16550_LCR_DLAB 0x80 /**< Divisor latch access bit */
38
39#define NS16550_LCR_WORD_LEN(x) ( ( (x) - 5 ) << 0 ) /**< Word length */
40#define NS16550_LCR_STOP_BITS(x) ( ( (x) - 1 ) << 2 ) /**< Stop bits */
41#define NS16550_LCR_PARITY(x) ( ( (x) - 0 ) << 3 ) /**< Parity */
42
43/**
44 * Calculate line control register value
45 *
46 * @v word_len Word length (5-8)
47 * @v parity Parity (0=none, 1=odd, 3=even)
48 * @v stop_bits Stop bits (1-2)
49 * @ret lcr Line control register value
50 */
51#define NS16550_LCR_WPS( word_len, parity, stop_bits ) \
52 ( NS16550_LCR_WORD_LEN ( (word_len) ) | \
53 NS16550_LCR_PARITY ( (parity) ) | \
54 NS16550_LCR_STOP_BITS ( (stop_bits) ) )
55
56/** Default LCR value: 8 data bits, no parity, one stop bit */
57#define NS16550_LCR_8N1 NS16550_LCR_WPS ( 8, 0, 1 )
58
59/** Modem control register */
60#define NS16550_MCR 0x04
61#define NS16550_MCR_DTR 0x01 /**< Data terminal ready */
62#define NS16550_MCR_RTS 0x02 /**< Request to send */
63
64/** Line status register */
65#define NS16550_LSR 0x05
66#define NS16550_LSR_DR 0x01 /**< Data ready */
67#define NS16550_LSR_THRE 0x20 /**< Transmitter holding reg. empty */
68#define NS16550_LSR_TEMT 0x40 /**< Transmitter empty */
69
70/** Scratch register */
71#define NS16550_SCR 0x07
72
73/** Divisor latch (least significant byte) */
74#define NS16550_DLL 0x00
75
76/** Divisor latch (most significant byte) */
77#define NS16550_DLM 0x01
78
79/** A 16550-compatible UART */
81 /** Register base address */
82 void *base;
83 /** Register shift */
84 unsigned int shift;
85 /** Input clock frequency */
86 unsigned int clock;
87 /** Baud rate divisor */
89};
90
91/** Post-division clock cycles per data bit */
92#define NS16550_CLK_BIT 16
93
94/** Default input clock rate (1.8432 MHz) */
95#define NS16550_CLK_DEFAULT 1843200
96
97#include <bits/ns16550.h>
98
99/** Dummy COM1 UART for non-x86 platforms
100 *
101 * The architecture-independent config/serial.h header has long
102 * included the line
103 *
104 * #define COMCONSOLE COM1
105 *
106 * which is meaningless on non-x86 platforms where there is no COM1
107 * port. Allow COM1 to be treated as equivalent to "no UART" on
108 * non-x86 platforms, to avoid breaking existing build configurations.
109 */
110#ifndef COM1
111#define COM1 NULL
112#endif
113
114void ns16550_write ( struct ns16550_uart *ns16550, unsigned int address,
115 uint8_t data );
116uint8_t ns16550_read ( struct ns16550_uart *ns16550, unsigned int address );
117
119
120#endif /* _IPXE_NS16550_H */
unsigned short uint16_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:10
16550-compatible UART
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint64_t address
Base address.
Definition ena.h:13
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
uint8_t ns16550_read(struct ns16550_uart *ns16550, unsigned int address)
void ns16550_write(struct ns16550_uart *ns16550, unsigned int address, uint8_t data)
Dummy COM1 UART for non-x86 platforms.
struct uart_operations ns16550_operations
16550 UART operations
Definition ns16550.c:171
A 16550-compatible UART.
Definition ns16550.h:80
unsigned int clock
Input clock frequency.
Definition ns16550.h:86
unsigned int shift
Register shift.
Definition ns16550.h:84
void * base
Register base address.
Definition ns16550.h:82
uint16_t divisor
Baud rate divisor.
Definition ns16550.h:88
UART operations.
Definition uart.h:35
Generic UART.