2018-03-07 20:57:14 +08:00
|
|
|
/*
|
2022-04-05 18:59:24 +08:00
|
|
|
* Copyright (C) 2018 Intel Corporation.
|
2018-03-07 20:57:14 +08:00
|
|
|
*
|
2018-05-26 01:49:13 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-07 20:57:14 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UART16550_H
|
|
|
|
#define UART16550_H
|
|
|
|
|
|
|
|
/* Register / bit definitions for 16c550 uart */
|
|
|
|
/*receive buffer register | base+00h, dlab=0b r*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_RBR 0x00U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*transmit holding register | base+00h, dlab=0b w*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_THR 0x00U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*divisor least significant byte | base+00h, dlab=1b rw*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_DLL 0x00U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*interrupt enable register | base+01h, dlab=0b rw*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_IER 0x01U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*divisor most significant byte | base+01h, dlab=1b rw*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_DLM 0x01U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*interrupt identification register | base+02h, dlab=0b r*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_IIR 0x02U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*fifo control register | base+02h, dlab=0b w*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_FCR 0x02U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*line control register | base+03h, dlab=xb rw*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_LCR 0x03U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*modem control register, only uart0 | base+04h, dlab=xb rw*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_MCR 0x04U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*line status register | base+05h, dlab=xb r*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_LSR 0x05U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*modem status register, only uart0 | base+06h, dlab=xb r*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_MSR 0x06U
|
2018-03-07 20:57:14 +08:00
|
|
|
/*scratch pad register | base+07h, dlab=xb rw*/
|
2018-07-27 16:23:09 +08:00
|
|
|
#define UART16550_SCR 0x07U
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
/* value definitions for IIR */
|
2018-06-19 18:33:58 +08:00
|
|
|
#define IIR_FIFO_MASK 0xc0U /* set if FIFOs are enabled */
|
|
|
|
#define IIR_RXTOUT 0x0cU
|
HV: vuart: support MSR and MCR
In Linux 8250 driver, it has different flags for UART ports. For COM1,
COM2 and COM3, UPF_SKIP_TEST is set, which is used to skip the loopback
test for the port. But for COM4, UPF_SKIP_TEST is not set, so when
probing COM4, the driver will access MCR and MSR registers to make sure
the port is exsit. So, add support for MSR and MCR.
Default ports info:
COM1, ttyS0, 0x3F8
COM2, ttyS1, 0x2F8
COM3, ttyS2, 0x3E8
COM4, ttyS3, 0x2E8
Tracked-On: #2987
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2019-04-29 03:34:40 +08:00
|
|
|
#define IER_EMSC 0x08U
|
2018-06-19 18:33:58 +08:00
|
|
|
#define IIR_RLS 0x06U
|
|
|
|
#define IIR_RXRDY 0x04U
|
|
|
|
#define IIR_TXRDY 0x02U
|
|
|
|
#define IIR_NOPEND 0x01U
|
|
|
|
#define IIR_MLSC 0x00U
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-06-19 18:33:58 +08:00
|
|
|
#define IER_EDSSI (0x0008U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/*enable/disable modem status interrupt*/
|
2018-06-19 18:33:58 +08:00
|
|
|
#define IER_ELSI (0x0004U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/*enable/disable receive data error interrupt*/
|
2018-06-19 18:33:58 +08:00
|
|
|
#define IER_ETBEI (0x0002U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/*enable/disable transmit data write request interrupt*/
|
2018-06-19 18:33:58 +08:00
|
|
|
#define IER_ERBFI (0x0001U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/*enable/disable receive data read request interrupt*/
|
|
|
|
|
|
|
|
/* definition for LCR */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LCR_DLAB (1U << 7U) /*DLAB THR/RBR&IER or DLL&DLM= Bit 7*/
|
|
|
|
#define LCR_SB (1U << 6U) /*break control on/off= Bit 6*/
|
|
|
|
#define LCR_SP (1U << 5U) /*Specifies the operation of parity bit*/
|
|
|
|
#define LCR_EPS (1U << 4U) /*Specifies the logic of a parity bit*/
|
|
|
|
#define LCR_PEN (1U << 3U) /*Specifies whether to add a parity bit*/
|
|
|
|
#define LCR_STB (1U << 2U) /*stop bit length*/
|
2018-06-19 18:33:58 +08:00
|
|
|
#define LCR_WL8 (0x03U) /*number of bits of serial data*/
|
|
|
|
#define LCR_WL7 (0x02U) /*number of bits of serial data*/
|
|
|
|
#define LCR_WL6 (0x01U) /*number of bits of serial data*/
|
|
|
|
#define LCR_WL5 (0x00U) /*number of bits of serial data*/
|
2018-03-07 20:57:14 +08:00
|
|
|
#define LCR_PARITY_ODD (LCR_PEN)
|
2018-06-19 18:33:58 +08:00
|
|
|
#define LCR_PARITY_NONE 0x0U
|
2018-03-07 20:57:14 +08:00
|
|
|
#define LCR_PARITY_EVEN (LCR_PEN | LCR_EPS)
|
2018-06-19 18:33:58 +08:00
|
|
|
#define LCR_NB_STOP_BITS_1 0x0U
|
2018-03-07 20:57:14 +08:00
|
|
|
#define LCR_NB_STOP_BITS_2 (LCR_STB)
|
|
|
|
|
|
|
|
/* bit definitions for LSR */
|
|
|
|
/* at least one error in data within fifo */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LSR_ERR (1U << 7U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/* Transmit data Present */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LSR_TEMT (1U << 6U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/* Transmit data write request present */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LSR_THRE (1U << 5U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/* Break interrupt data Present */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LSR_BI (1U << 4U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/* Framing Error Occurred */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LSR_FE (1U << 3U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/* Parity Error Occurred */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LSR_PE (1U << 2U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/* Overrun error */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LSR_OE (1U << 1U)
|
2018-03-07 20:57:14 +08:00
|
|
|
/* Readable received data is present */
|
2018-11-02 09:05:17 +08:00
|
|
|
#define LSR_DR (1U << 0U)
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
/* definition for MCR */
|
HV: vuart: support MSR and MCR
In Linux 8250 driver, it has different flags for UART ports. For COM1,
COM2 and COM3, UPF_SKIP_TEST is set, which is used to skip the loopback
test for the port. But for COM4, UPF_SKIP_TEST is not set, so when
probing COM4, the driver will access MCR and MSR registers to make sure
the port is exsit. So, add support for MSR and MCR.
Default ports info:
COM1, ttyS0, 0x3F8
COM2, ttyS1, 0x2F8
COM3, ttyS2, 0x3E8
COM4, ttyS3, 0x2E8
Tracked-On: #2987
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2019-04-29 03:34:40 +08:00
|
|
|
#define MCR_PRESCALE (1U << 7U) /* only available on 16650 up */
|
|
|
|
#define MCR_LOOPBACK (1U << 4U)
|
|
|
|
#define MCR_IE (1U << 3U)
|
|
|
|
#define MCR_IENABLE MCR_IE
|
|
|
|
#define MCR_DRS (1U << 2U)
|
2018-11-02 09:05:17 +08:00
|
|
|
#define MCR_RTS (1U << 1U) /* Request to Send */
|
|
|
|
#define MCR_DTR (1U << 0U) /* Data Terminal Ready */
|
2018-03-07 20:57:14 +08:00
|
|
|
|
HV: vuart: support MSR and MCR
In Linux 8250 driver, it has different flags for UART ports. For COM1,
COM2 and COM3, UPF_SKIP_TEST is set, which is used to skip the loopback
test for the port. But for COM4, UPF_SKIP_TEST is not set, so when
probing COM4, the driver will access MCR and MSR registers to make sure
the port is exsit. So, add support for MSR and MCR.
Default ports info:
COM1, ttyS0, 0x3F8
COM2, ttyS1, 0x2F8
COM3, ttyS2, 0x3E8
COM4, ttyS3, 0x2E8
Tracked-On: #2987
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2019-04-29 03:34:40 +08:00
|
|
|
/* defifor MSR */
|
|
|
|
#define MSR_DCD (1U << 7U)
|
|
|
|
#define MSR_RI (1U << 6U)
|
|
|
|
#define MSR_DSR (1U << 5U)
|
|
|
|
#define MSR_CTS (1U << 4U)
|
|
|
|
#define MSR_DDCD (1U << 3U)
|
|
|
|
#define MSR_TERI (1U << 2U)
|
|
|
|
#define MSR_DDSR (1U << 1U)
|
|
|
|
#define MSR_DCTS (1U << 0U)
|
|
|
|
|
|
|
|
#define MCR_OUT2 (1U << 3U)
|
|
|
|
#define MCR_OUT1 (1U << 2U)
|
|
|
|
|
|
|
|
#define MSR_DELTA_MASK 0x0FU
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
/* definition for FCR */
|
2018-06-19 18:33:58 +08:00
|
|
|
#define FCR_RX_MASK 0xc0U
|
2018-11-02 09:05:17 +08:00
|
|
|
#define FCR_DMA (1U << 3U)
|
|
|
|
#define FCR_TFR (1U << 2U) /* Reset Transmit Fifo */
|
|
|
|
#define FCR_RFR (1U << 1U) /* Reset Receive Fifo */
|
|
|
|
#define FCR_FIFOE (1U << 0U) /* Fifo Enable */
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-06-19 18:33:58 +08:00
|
|
|
#define UART_IER_DISABLE_ALL 0x00000000U
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-07-30 11:29:34 +08:00
|
|
|
#define BAUD_9600 9600U
|
|
|
|
#define BAUD_115200 115200U
|
|
|
|
#define BAUD_460800 460800U
|
2018-07-27 16:23:09 +08:00
|
|
|
|
2018-07-30 11:29:34 +08:00
|
|
|
/* UART oscillator clock */
|
|
|
|
#define UART_CLOCK_RATE 1843200U /* 1.8432 MHz */
|
2018-07-27 16:23:09 +08:00
|
|
|
|
2020-08-20 13:23:39 +08:00
|
|
|
enum serial_dev_type {
|
|
|
|
INVALID,
|
|
|
|
PIO,
|
|
|
|
PCI,
|
|
|
|
MMIO,
|
|
|
|
};
|
|
|
|
|
2019-07-24 17:50:27 +08:00
|
|
|
void uart16550_init(bool early_boot);
|
2018-07-27 16:23:09 +08:00
|
|
|
char uart16550_getc(void);
|
2018-09-18 17:50:26 +08:00
|
|
|
size_t uart16550_puts(const char *buf, uint32_t len);
|
2020-08-20 13:23:39 +08:00
|
|
|
void uart16550_set_property(bool enabled, enum serial_dev_type uart_type, uint64_t base_addr);
|
2019-02-19 15:22:39 +08:00
|
|
|
bool is_pci_dbg_uart(union pci_bdf bdf_value);
|
2021-05-29 00:26:55 +08:00
|
|
|
bool get_pio_dbg_uart_cfg(uint16_t *pio_address, uint32_t *nbytes);
|
2018-07-27 16:23:09 +08:00
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
#endif /* !UART16550_H */
|