All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel]  [PATCH] ns16550: Add ACPI support
@ 2020-01-17  3:40 Wei Xu
  2020-01-17  8:33 ` Jan Beulich
  0 siblings, 1 reply; 5+ messages in thread
From: Wei Xu @ 2020-01-17  3:40 UTC (permalink / raw)
  To: julien, sstabellini, Andrew Cooper, George Dunlap, Ian Jackson,
	Jan Beulich, Konrad Rzeszutek Wilk, Wei Liu, xen-devel
  Cc: prime.zeng, shameerali.kolothum.thodi, xuwei5, linuxarm

Parse the ACPI SPCR table and initialize the 16550 compatible
serial port.

Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
---
 xen/drivers/char/ns16550.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index aa87c57..eb32891 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -1620,6 +1620,61 @@ DT_DEVICE_START(ns16550, "NS16550 UART", DEVICE_SERIAL)
 DT_DEVICE_END
 
 #endif /* HAS_DEVICE_TREE */
+
+#ifdef CONFIG_ACPI
+#include <xen/acpi.h>
+
+static int __init ns16550_acpi_uart_init(const void *data)
+{
+    struct acpi_table_spcr *spcr = NULL;
+    acpi_status status;
+    struct ns16550 *uart;
+
+    status = acpi_get_table(ACPI_SIG_SPCR, 0,
+                            (struct acpi_table_header **)&spcr);
+
+    if ( ACPI_FAILURE(status) )
+    {
+        printk("ns16550: Failed to get SPCR table\n");
+        return -EINVAL;
+    }
+
+    uart = &ns16550_com[0];
+
+    ns16550_init_common(uart);
+
+    uart->baud      = BAUD_AUTO;
+    uart->data_bits = 8;
+    uart->parity    = spcr->parity;
+    uart->stop_bits = spcr->stop_bits;
+    uart->io_base = spcr->serial_port.address;
+    uart->io_size = 8;
+    uart->reg_shift = spcr->serial_port.bit_offset;
+    uart->reg_width = 1;
+
+    /* trigger/polarity information is not available in spcr */
+    irq_set_type(spcr->interrupt, IRQ_TYPE_LEVEL_HIGH);
+    uart->irq = spcr->interrupt;
+
+    uart->vuart.base_addr = uart->io_base;
+    uart->vuart.size = uart->io_size;
+    uart->vuart.data_off = UART_THR << uart->reg_shift;
+    uart->vuart.status_off = UART_LSR << uart->reg_shift;
+    uart->vuart.status = UART_LSR_THRE | UART_LSR_TEMT;
+
+    /*  Register with generic serial driver. */
+    serial_register_uart(uart - ns16550_com, &ns16550_driver, uart);
+
+    return 0;
+}
+
+ACPI_DEVICE_START(ans16550, "NS16550 UART", DEVICE_SERIAL)
+    .class_type = ACPI_DBG2_16550_COMPATIBLE,
+    .init = ns16550_acpi_uart_init,
+ACPI_DEVICE_END
+
+#endif /* CONFIG_ACPI */
+
 /*
  * Local variables:
  * mode: C
-- 
2.8.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-01-21  3:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-17  3:40 [Xen-devel] [PATCH] ns16550: Add ACPI support Wei Xu
2020-01-17  8:33 ` Jan Beulich
2020-01-18 12:32   ` Julien Grall
2020-01-20  8:38     ` Jan Beulich
2020-01-21  3:28       ` Wei Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.