]> xenbits.xensource.com Git - people/aperard/xen-arm.git/commitdiff
arndale: UART implementation.
authorAnthony PERARD <anthony.perard@citrix.com>
Wed, 16 Jan 2013 14:49:05 +0000 (14:49 +0000)
committerAnthony PERARD <anthony.perard@citrix.com>
Mon, 28 Jan 2013 15:55:20 +0000 (15:55 +0000)
config/arm32.mk
xen/arch/arm/setup.c
xen/drivers/char/Makefile
xen/drivers/char/exynos5-uart.c [new file with mode: 0644]
xen/include/xen/serial.h

index f64f0c1c831cda859953db39d3d92ef3a72ab96b..a1068e5cdb3155af5de1a96e544794a50e302c43 100644 (file)
@@ -8,6 +8,7 @@ CONFIG_ARM_$(XEN_OS) := y
 CFLAGS += -marm
 
 HAS_PL011 := y
+HAS_EXYNOS5 := y
 
 # Use only if calling $(LD) directly.
 #LDFLAGS_DIRECT_OpenBSD = _obsd
index e1ab7f642a1d69f6e6c41cf8b115b5bbd306954f..ecadc0caff520960bd9beb264167f9b99e98e784 100644 (file)
@@ -352,7 +352,11 @@ void __init start_xen(unsigned long boot_phys_offset,
 
 #ifdef EARLY_UART_ADDRESS
     /* TODO Need to get device tree or command line for UART address */
+#ifdef MACH_VEXPRESS
     pl011_init(0, FIXMAP_ADDR(FIXMAP_CONSOLE));
+#elif defined MACH_EXYNOS5
+    exynos5_uart_init(2, FIXMAP_ADDR(FIXMAP_CONSOLE));
+#endif
     console_init_preirq();
 #endif
 
index ab2246d61d0d14041964f575400643c412477893..0a900aa51f7657ab86b5e5d5b0b5d86f3912f177 100644 (file)
@@ -1,5 +1,6 @@
 obj-y += console.o
 obj-$(HAS_NS16550) += ns16550.o
 obj-$(HAS_PL011) += pl011.o
+obj-$(HAS_EXYNOS5) += exynos5-uart.o
 obj-$(HAS_EHCI) += ehci-dbgp.o
 obj-y += serial.o
diff --git a/xen/drivers/char/exynos5-uart.c b/xen/drivers/char/exynos5-uart.c
new file mode 100644 (file)
index 0000000..bbb9f14
--- /dev/null
@@ -0,0 +1,263 @@
+/*
+ * xen/drivers/char/exynos5-uart.c
+ *
+ * Driver for ARM PrimeCell PL011 UART.
+ *
+ * Anthony PERARD <anthony.perard@citrix.com>
+ * Copyright (c) 2012 Citrix Systems.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/config.h>
+#include <xen/console.h>
+#include <xen/serial.h>
+#include <xen/init.h>
+#include <xen/irq.h>
+
+static struct exynos5_uart {
+    unsigned int baud, clock_hz, data_bits, parity, stop_bits, irq;
+    volatile uint32_t *regs;
+    struct irqaction irqaction;
+    unsigned int fifo;
+} exynos5_com[4] = {{0}};
+
+/* register addresses */
+#define ULCON     (0x00/4)
+#define UCON      (0x04/4)
+#define UFCON     (0x08/4)
+#define UMCON     (0x0c/4)
+#define UTRSTAT   (0x10/4)
+#define UERSTAT   (0x14/4)
+#define UFSTAT    (0x18/4)
+#define UMSTAT    (0x1c/4)
+#define UTXH      (0x20/4)
+#define URXH      (0x24/4)
+#define UBRDIV    (0x28/4)
+#define UFRACVAL  (0x2c/4)
+#define UINTP     (0x30/4)
+#define UINTS     (0x34/4)
+#define UINTM     (0x38/4)
+
+/* ULCON */
+#define RXIRQ (0x1<<0)
+#define RXDMA (0x2<<0)
+#define TXIRQ (0x1<<2)
+#define TXDMA (0x2<<2)
+
+/* UFCON */
+#define FIFO_EN   (0x1<<0)
+
+/* UMCON */
+#define INT_EN (1<<3)
+
+/* UTRSTAT */
+#define TXE     (1<<2)
+#define TXFE    (1<<1)
+#define RXDR    (1<<0)
+
+/* Interrupt bits (UINTP, UINTS, UINTM) */
+#define MODEM   (1<<3)
+#define TXD     (1<<2)
+#define ERROR   (1<<1)
+#define RXD     (1<<0)
+#define ALLI    (MODEM|TXD|ERROR|RXD)
+
+/* These parity settings can be ORed directly into the ULCON. */
+#define PARITY_NONE  (0)
+#define PARITY_ODD   (0x4)
+#define PARITY_EVEN  (0x5)
+#define FORCED_CHECKED_AS_ONE (0x6)
+#define FORCED_CHECKED_AS_ZERO (0x7)
+
+static void exynos5_uart_interrupt(int irq, void *data, struct cpu_user_regs *regs)
+{
+    struct serial_port *port = data;
+    struct exynos5_uart *uart = port->uart;
+    unsigned int status = uart->regs[UINTP];
+
+    if ( status )
+    {
+        do
+        {
+            // clear all pending interrept
+            // but should take care of ERROR and MODEM
+            uart->regs[UINTP] = ALLI;
+
+            if ( status & (RXD) )
+                serial_rx_interrupt(port, regs);
+
+            if ( status & (TXD) )
+                serial_tx_interrupt(port, regs);
+
+            status = uart->regs[UINTP];
+        } while (status != 0);
+    }
+}
+
+static void __init exynos5_uart_init_preirq(struct serial_port *port)
+{
+    struct exynos5_uart *uart = port->uart;
+    unsigned int divisor;
+
+    /* reset, TX/RX disables */
+    uart->regs[UCON] = 0x0;
+
+    /* No Interrupt, auto flow control */
+    uart->regs[UMCON] = 0x0;
+
+    /* Line control and baud-rate generator. */
+    if ( uart->baud != BAUD_AUTO )
+    {
+        /* Baud rate specified: program it into the divisor latch. */
+        // div_val = ubrdiv + ufracval/16
+        // or
+        // div_val = (clock_uart/(baud*16))-1
+        divisor = ((uart->clock_hz) / (uart->baud)) - 1;
+        // FIXME will use a hacked divisor, assuming the src clock and bauds
+        uart->regs[UFRACVAL] = 53;
+        uart->regs[UBRDIV] = 4;
+        /* uart->regs[UFRACVAL] = divisor & 0xf; */
+        /* uart->regs[UBRDIV] = divisor >> 4; */
+    }
+    else
+    {
+        // TODO, should be updated
+        /* Baud rate already set: read it out from the divisor latch. */
+        //divisor = (uart->regs[IBRD] << 6) | uart->regs[FBRD];
+        //uart->baud = (uart->clock_hz << 2) / divisor;
+    }
+    uart->regs[ULCON] = ( (uart->data_bits - 5) << 0
+                          | ((uart->stop_bits - 1) << 2)
+                          | uart->parity << 3 );
+
+    /* Mask and clear the interrupts */
+    uart->regs[UINTM] = ALLI;
+    uart->regs[UINTP] = ALLI;
+
+    /* disable FIFO */
+    uart->regs[UFCON] = 0; //FIFO_EN;
+
+    /* Enable the UART for RX and TX */
+    uart->regs[UCON] = RXIRQ|TXIRQ;
+}
+
+static void __init exynos5_uart_init_postirq(struct serial_port *port)
+{
+    struct exynos5_uart *uart = port->uart;
+    int rc;
+
+    if ( uart->irq > 0 )
+    {
+        uart->irqaction.handler = exynos5_uart_interrupt;
+        uart->irqaction.name    = "exynos5_uart";
+        uart->irqaction.dev_id  = port;
+        if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
+            printk("ERROR: Failed to allocate exynos5_uart IRQ %d\n", uart->irq);
+    }
+
+    /* Clear pending error interrupts */
+    uart->regs[UINTP] = ALLI;
+
+    /* Unmask interrupts */
+    uart->regs[UINTM] = 0;
+
+    /* Enable interrupts */
+    uart->regs[UMCON] |= INT_EN;
+}
+
+static void exynos5_uart_suspend(struct serial_port *port)
+{
+    BUG(); // XXX
+}
+
+static void exynos5_uart_resume(struct serial_port *port)
+{
+    BUG(); // XXX
+}
+
+static unsigned int exynos5_uart_tx_ready(struct serial_port *port)
+{
+    struct exynos5_uart *uart = port->uart;
+    // return fifo size
+    return uart->regs[UTRSTAT] & TXFE ? 16 : 0;
+}
+
+static void exynos5_uart_putc(struct serial_port *port, char c)
+{
+    struct exynos5_uart *uart = port->uart;
+    uart->regs[UTXH] = (uint32_t) (unsigned char) c;
+}
+
+static int exynos5_uart_getc(struct serial_port *port, char *pc)
+{
+    struct exynos5_uart *uart = port->uart;
+
+    if ( !(uart->regs[UTRSTAT] & RXDR) )
+        return 0;
+
+    *pc = uart->regs[URXH] & 0xff;
+    return 1;
+}
+
+static int __init exynos5_uart_irq(struct serial_port *port)
+{
+    struct exynos5_uart *uart = port->uart;
+    if ( uart->irq > 0 )
+        return uart->irq;
+    else
+        return -1;
+}
+
+static struct uart_driver __read_mostly exynos5_uart_driver = {
+    .init_preirq  = exynos5_uart_init_preirq,
+    .init_postirq = exynos5_uart_init_postirq,
+    .endboot      = NULL,
+    .suspend      = exynos5_uart_suspend,
+    .resume       = exynos5_uart_resume,
+    .tx_ready     = exynos5_uart_tx_ready,
+    .putc         = exynos5_uart_putc,
+    .getc         = exynos5_uart_getc,
+    .irq          = exynos5_uart_irq
+};
+
+void __init exynos5_uart_init(int index, unsigned long register_base_address)
+{
+    // in device tree: compatible = "samsung,exynos4210-uart"
+    // node: serial@
+    struct exynos5_uart *uart;
+
+    if ( (index < 0) || (index > 4) )
+        return;
+
+    uart = &exynos5_com[index];
+
+    /* uart->clock_hz  = 0x16e3600; */
+    uart->baud      = BAUD_AUTO;//115200;
+    uart->data_bits = 8;
+    uart->parity    = PARITY_NONE;
+    uart->stop_bits = 1;
+    uart->irq       = 51 + index; /* TODO Need to find this from devicetree */
+    uart->regs      = (uint32_t *) register_base_address;
+    uart->fifo      = 0; // FIFO disabled
+
+    /* Register with generic serial driver. */
+    serial_register_uart(uart - exynos5_com, &exynos5_uart_driver, uart);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index f817ccd566f1d9bba60d2b0b44e57f86baae21b6..daa532d7d63575b751d14e8791642a08402f2506 100644 (file)
@@ -151,6 +151,7 @@ void ns16550_init(int index, struct ns16550_defaults *defaults);
 void ehci_dbgp_init(void);
 
 void pl011_init(int index, unsigned long register_base_address);
+void exynos5_uart_init(int index, unsigned long register_base_address);
 
 struct physdev_dbgp_op;
 int dbgp_op(const struct physdev_dbgp_op *);