+}
+
+static int
+mmio_uart_rr0( void )
+{
+ unsigned char lsr;
+
+ lsr = MMIO_READ( LSR );
+
+ if ( lsr & (UART_LSR_FE | UART_LSR_PE | UART_LSR_OE) )
+ {
+ MMIO_READ( RBR ); /* discard */
+ return 0;
+ }
+
+ return (lsr & UART_LSR_DR);
+}
+
+void lpss_uart_enable( boolean_t on_off )
+{
+ unsigned int pmcs_reg;
+
+ if (!lpss_uart_supported) {
+ return;
+ }
+
+ pmcs_reg = ml_phys_read_byte (PCI_UART2 + 0x84);
+ if (on_off == FALSE) {
+ pmcs_reg |= 0x03;
+ lpss_uart_enabled = 0;
+ } else {
+ pmcs_reg &= ~(0x03);
+ }
+
+ ml_phys_write_byte (PCI_UART2 + 0x84, pmcs_reg);
+ pmcs_reg = ml_phys_read_byte (PCI_UART2 + 0x84);
+
+ if (on_off == TRUE) {
+ lpss_uart_re_init();
+ lpss_uart_enabled = 1;
+ }
+}
+
+static void lpss_uart_re_init( void )
+{
+ uint32_t register_read;
+
+ MMIO_WRITE (RST, 0x7); /* LPSS UART2 controller out ot reset */
+ register_read = MMIO_READ (RST);
+
+ MMIO_WRITE (LCR, UART_LCR_DLAB); /* Set DLAB bit to enable reading/writing of DLL, DLH */
+ register_read = MMIO_READ (LCR);
+
+ MMIO_WRITE (DLL, 1); /* Divisor Latch Low Register */
+ register_read = MMIO_READ (DLL);
+
+ MMIO_WRITE (DLM, 0); /* Divisor Latch High Register */
+ register_read = MMIO_READ (DLM);
+
+ MMIO_WRITE (FCR, 1); /* Enable FIFO */
+ register_read = MMIO_READ (FCR);
+
+ MMIO_WRITE (LCR, UART_LCR_8BITS); /* Set 8 bits, clear DLAB */
+ register_read = MMIO_READ (LCR);
+
+ MMIO_WRITE (MCR, UART_MCR_RTS); /* Request to send */
+ register_read = MMIO_READ (MCR);
+
+ MMIO_WRITE (CLK, UART_CLK_125M_1); /* 1.25M Clock speed */
+ register_read = MMIO_READ (CLK);
+
+ MMIO_WRITE (CLK, UART_CLK_125M_2); /* 1.25M Clock speed */
+ register_read = MMIO_READ (CLK);
+}
+
+static int
+mmio_uart_rd0( void )
+{
+ return MMIO_READ( RBR );
+}
+
+static struct pe_serial_functions mmio_uart_serial_functions = {
+ .uart_init = mmio_uart_init,
+ .uart_set_baud_rate = mmio_uart_set_baud_rate,
+ .tr0 = mmio_uart_tr0,
+ .td0 = mmio_uart_td0,
+ .rr0 = mmio_uart_rr0,
+ .rd0 = mmio_uart_rd0
+};
+
+// =============================================================================
+// PCIE_MMIO UART
+// =============================================================================
+
+#define PCIE_MMIO_UART_BASE 0xFE410000
+
+#define PCIE_MMIO_WRITE(r, v) ml_phys_write_byte(pcie_mmio_uart_base + PCIE_MMIO_UART_##r, v)
+#define PCIE_MMIO_READ(r) ml_phys_read_byte(pcie_mmio_uart_base + PCIE_MMIO_UART_##r)
+
+enum {
+ PCIE_MMIO_UART_RBR = 0x0, /* receive buffer Register (R) */
+ PCIE_MMIO_UART_THR = 0x0, /* transmit holding register (W) */
+ PCIE_MMIO_UART_IER = 0x1, /* interrupt enable register */
+ PCIE_MMIO_UART_FCR = 0x2, /* fifo control register (W) */
+ PCIE_MMIO_UART_LCR = 0x4, /* line control register */
+ PCIE_MMIO_UART_MCR = 0x4, /* modem control register */
+ PCIE_MMIO_UART_LSR = 0x5, /* line status register */
+ PCIE_MMIO_UART_DLL = 0x8, /* DLAB = 1, divisor latch (LSB) */
+ PCIE_MMIO_UART_DLM = 0x9, /* DLAB = 1, divisor latch (MSB) */
+ PCIE_MMIO_UART_SCR = 0x30, /* scratch register */
+};
+
+static vm_offset_t pcie_mmio_uart_base = 0;
+
+static int
+pcie_mmio_uart_present( void )
+{
+
+ PCIE_MMIO_WRITE( SCR, 0x5a );
+ if (PCIE_MMIO_READ(SCR) != 0x5a) return 0;
+ PCIE_MMIO_WRITE( SCR, 0xa5 );
+ if (PCIE_MMIO_READ(SCR) != 0xa5) return 0;