Skip to contentSkip to conversation

Add support for Marvell Armada 3700 SoC

PATCH New Amit Singh Tomar 3 participants 13 messages Apr 5, 2018 – Apr 6, 2018

lore
Share & tools
lore
#0 lore raw

cover Add support for Marvell Armada 3700 SoC

This patch-set enables XEN booting[1] on ESPRESSObin board based on Marvell Armada 3700 SoC.

I would like to Thanks Andre for helping on this.

[1]https://wiki.xen.org/wiki/Xen_ARM_with_Virtualization_Extensions/ESPRESSObin

Amit Singh Tomar (2):
xen/arm: Add MVEBU UART driver for Marvell Armada 3700 SoC xen/arm: Add Marvell ARMADA 3700 early printk support

 docs/misc/arm/early-printk.txt     |   1 +
 xen/arch/arm/Rules.mk              |   1 +
 xen/arch/arm/arm64/debug-mvebu.inc |  50 +++++++
 xen/drivers/char/Kconfig           |   8 +
 xen/drivers/char/Makefile          |   1 +
 xen/drivers/char/mvebu-uart.c      | 296 +++++++++++++++++++++++++++++++++++++
 6 files changed, 357 insertions(+)
 create mode 100644 xen/arch/arm/arm64/debug-mvebu.inc
 create mode 100644 xen/drivers/char/mvebu-uart.c

--
1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw

PATCH v3 1/2 xen/arm: Add MVEBU UART driver for Marvell Armada 3700 SoC

This patch adds driver for UART controller found on Armada 3700 SoC.

There is no reference manuals available for 3700 SoC in public and it is derived by looking at Linux driver[1].

[1]https://github.com/torvalds/linux/blob/master/drivers/tty/serial/mvebu-uart.c

---
Changes since v2:
* Addressed Andre's comments.
Changes since v1:
* Addressed Wei Liu's comments
* Addressed Andre's comments.
Changes since RFC:
* Addressed Julien's comments.

---
 xen/drivers/char/Kconfig      |   8 ++
 xen/drivers/char/Makefile     |   1 +
 xen/drivers/char/mvebu-uart.c | 296 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 305 insertions(+)
 create mode 100644 xen/drivers/char/mvebu-uart.c
xen/drivers/char/Kconfig +8 -0
index fb53dd8..04a4087 100644
@@ -12,6 +12,14 @@ config HAS_CADENCE_UART
 	  This selects the Xilinx Zynq Cadence UART. If you have a Xilinx Zynq
 	  based board, say Y.
 
+config HAS_MVEBU
+    bool
+    default y
+    depends on ARM_64
+    help
+      This selects the Marvell MVEBU UART. If you have a ARMADA 3700
+      based board, say Y.
+
 config HAS_PL011
 	bool
 	default y
xen/drivers/char/Makefile +1 -0
index 0d48b16..b68c330 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_HAS_NS16550) += ns16550.o
 obj-$(CONFIG_HAS_CADENCE_UART) += cadence-uart.o
 obj-$(CONFIG_HAS_PL011) += pl011.o
 obj-$(CONFIG_HAS_EXYNOS4210) += exynos4210-uart.o
+obj-$(CONFIG_HAS_MVEBU) += mvebu-uart.o
 obj-$(CONFIG_HAS_OMAP) += omap-uart.o
 obj-$(CONFIG_HAS_SCIF) += scif-uart.o
 obj-$(CONFIG_HAS_EHCI) += ehci-dbgp.o
xen/drivers/char/mvebu-uart.c new file +296 -0

296 lines not on this page · raw message

--
1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] xen/arm: Add MVEBU UART driver for Marvell Armada 3700 SoC

Hi,

Quoted 29 lines · Amit Singh Tomar

This patch adds driver for UART controller found on Armada 3700 SoC.

There is no reference manuals available for 3700 SoC in public and it is derived by looking at Linux driver[1].

[1]https://github.com/torvalds/linux/blob/master/drivers/tty/serial/mvebu-uart.c

---
Changes since v2:
* Addressed Andre's comments.
Changes since v1:
* Addressed Wei Liu's comments
* Addressed Andre's comments.
Changes since RFC:
* Addressed Julien's comments.

---
 xen/drivers/char/Kconfig      |   8 ++
 xen/drivers/char/Makefile     |   1 +
 xen/drivers/char/mvebu-uart.c | 296 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 305 insertions(+)
 create mode 100644 xen/drivers/char/mvebu-uart.c
xen/drivers/char/Kconfig +0 -0
index fb53dd8..04a4087 100644
@@ -12,6 +12,14 @@ config HAS_CADENCE_UART
 	  This selects the Xilinx Zynq Cadence UART. If you have a Xilinx Zynq

xen/drivers/char/Kconfig config HAS_CADENCE_UART · line 22

Quoted 10 lines
xen/drivers/char/Kconfig +8 -0
 	  based board, say Y.
 
+config HAS_MVEBU
+    bool
+    default y
+    depends on ARM_64
+    help
+      This selects the Marvell MVEBU UART. If you have a ARMADA 3700
+      based board, say Y.
+

That still looks wrong.

Quoted 57 lines
xen/drivers/char/Kconfig +0 -0
 config HAS_PL011
 	bool
 	default y
xen/drivers/char/Makefile +1 -0
index 0d48b16..b68c330 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_HAS_NS16550) += ns16550.o
 obj-$(CONFIG_HAS_CADENCE_UART) += cadence-uart.o
 obj-$(CONFIG_HAS_PL011) += pl011.o
 obj-$(CONFIG_HAS_EXYNOS4210) += exynos4210-uart.o
+obj-$(CONFIG_HAS_MVEBU) += mvebu-uart.o
 obj-$(CONFIG_HAS_OMAP) += omap-uart.o
 obj-$(CONFIG_HAS_SCIF) += scif-uart.o
 obj-$(CONFIG_HAS_EHCI) += ehci-dbgp.o
xen/drivers/char/mvebu-uart.c new file +36 -0
new file mode 100644
index 0000000..1561a50
@@ -0,0 +1,296 @@
+/*
+ * xen/drivers/char/mvebu3700-uart.c
+ *
+ * Driver for Marvell MVEBU UART.
+ *
+ * Copyright (c) 2018, Amit Singh Tomar <[email protected]>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/irq.h>
+#include <xen/serial.h>
+#include <xen/vmap.h>
+#include <asm/io.h>
+
+/* Register offsets */
+#define UART_RX_REG             0x00
+
+#define UART_TX_REG             0x04
+
+#define UART_CTRL_REG           0x08
+#define CTRL_TXFIFO_RST         BIT(15)
+#define CTRL_RXFIFO_RST         BIT(14)
+#define CTRL_TX_RDY_INT         BIT(5)
+#define CTRL_RX_RDY_INT         BIT(4)
+#define CTRL_BRK_DET_INT        BIT(3)

xen/drivers/char/mvebu-uart.c line 46

Quoted 10 lines
xen/drivers/char/mvebu-uart.c new file +10 -0
+#define CTRL_FRM_ERR_INT        BIT(2)
+#define CTRL_PAR_ERR_INT        BIT(1)
+#define CTRL_OVR_ERR_INT        BIT(0)
+#define CTRL_ERR_INT            (CTRL_BRK_DET_INT | CTRL_FRM_ERR_INT | \
+                                 CTRL_PAR_ERR_INT | CTRL_OVR_ERR_INT)
+
+#define UART_STATUS_REG         0x0c
+#define STATUS_TXFIFO_EMP       BIT(13)
+#define STAT_TX_FIFO_FUL        BIT(11)
+#define STAT_TX_FIFO_HFL        BIT(10)

Nit: those names should be consistent.

Quoted 149 lines
xen/drivers/char/mvebu-uart.c new file +149 -0
+#define STATUS_TX_RDY           BIT(5)
+#define STATUS_RX_RDY           BIT(4)
+#define STATUS_BRK_DET          BIT(3)
+#define STATUS_FRM_ERR          BIT(2)
+#define STATUS_PAR_ERR          BIT(1)
+#define STATUS_OVR_ERR          BIT(0)
+#define STATUS_BRK_ERR          (STATUS_BRK_DET | STATUS_FRM_ERR | \
+                                 STATUS_PAR_ERR | STATUS_OVR_ERR)
+
+#define TX_FIFO_SIZE            32
+
+static struct mvebu3700_uart {
+    unsigned int irq;
+    void __iomem *regs;
+    struct irqaction irqaction;
+    struct vuart_info vuart;
+} mvebu3700_com = {0};
+
+#define mvebu3700_read(uart, off)           readl((uart)->regs + off)
+#define mvebu3700_write(uart, off, val)     writel(val, (uart->regs) + off)
+
+static void mvebu3700_uart_interrupt(int irq, void *data,
+                                     struct cpu_user_regs *regs)
+{
+    struct serial_port *port = data;
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t st = mvebu3700_read(uart, UART_STATUS_REG);
+
+    if ( st & (STATUS_RX_RDY | STATUS_OVR_ERR | STATUS_FRM_ERR |
+               STATUS_BRK_DET) )
+        serial_rx_interrupt(port, regs);
+
+    if ( st & STATUS_TX_RDY )
+        serial_tx_interrupt(port, regs);
+}
+
+static void __init mvebu3700_uart_init_preirq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= (CTRL_TXFIFO_RST | CTRL_RXFIFO_RST);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+
+    /* Before we make IRQ request, clear the error bits of state register. */
+    reg = mvebu3700_read(uart, UART_STATUS_REG);
+    reg |= STATUS_BRK_ERR;
+    mvebu3700_write(uart, UART_STATUS_REG, reg);
+
+    /* Clear error interrupts. */
+    mvebu3700_write(uart, UART_CTRL_REG, CTRL_ERR_INT);
+
+    /* Disable Rx/Tx interrupts. */
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg &= ~(CTRL_RX_RDY_INT | CTRL_TX_RDY_INT);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void __init mvebu3700_uart_init_postirq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    if ( uart->irq > 0 )
+    {
+        uart->irqaction.handler = mvebu3700_uart_interrupt;
+        uart->irqaction.name    = "mvebu3700_uart";
+        uart->irqaction.dev_id  = port;
+    }
+
+    if ( setup_irq(uart->irq, 0, &uart->irqaction) != 0 )
+    {
+        printk("Failed to allocated mvebu3700_uart IRQ %d\n", uart->irq);
+        return;
+    }
+
+    /* Make sure Rx/Tx interrupts are enabled now */
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= (CTRL_RX_RDY_INT | CTRL_TX_RDY_INT);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void mvebu3700_uart_suspend(struct serial_port *port)
+{
+    BUG();
+}
+
+static void mvebu3700_uart_resume(struct serial_port *port)
+{
+    BUG();
+}
+
+static void mvebu3700_uart_putc(struct serial_port *port, char c)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    mvebu3700_write(uart, UART_TX_REG, c);
+}
+
+static int mvebu3700_uart_getc(struct serial_port *port, char *c)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    if ( !(mvebu3700_read(uart, UART_STATUS_REG) & STATUS_RX_RDY) )
+        return 0;
+
+    *c = mvebu3700_read(uart, UART_RX_REG) & 0xff;
+
+    return 1;
+}
+
+static int __init mvebu3700_irq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    return (uart->irq > 0) ? uart->irq : -1;
+}
+
+static const struct vuart_info *mvebu3700_vuart_info(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    return &uart->vuart;
+}
+
+static void mvebu3700_uart_stop_tx(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg &= ~CTRL_TX_RDY_INT;
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void mvebu3700_uart_start_tx(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= CTRL_TX_RDY_INT;
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static int mvebu3700_uart_tx_ready(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;

xen/drivers/char/mvebu-uart.c line 205

Quoted 10 lines
xen/drivers/char/mvebu-uart.c new file +10 -0
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_STATUS_REG);
+
+    if ( reg & STATUS_TXFIFO_EMP )
+        return TX_FIFO_SIZE;
+    if ( reg & STAT_TX_FIFO_FUL )
+        return 0;
+    if ( reg & STAT_TX_FIFO_HFL )
+        return TX_FIFO_SIZE / 2;

... and here of course.

But given that those are nits or can be fixed at commit:

I successfully tested a very similar version yesterday evening. I will add my Tested-by: once I get my hands on the board again in a few hours.

Cheers,
Andre.

Quoted 92 lines
xen/drivers/char/mvebu-uart.c new file +91 -1
+
+    /* if we reach here, we don't know the number of free char in FIFO
+     * but we are sure that neither the FIFO is full nor empty.
+     * So, let's just return at least 1.
+     */
+    return 1;
+}
+
+static struct uart_driver __read_mostly mvebu3700_uart_driver = {
+    .init_preirq  = mvebu3700_uart_init_preirq,
+    .init_postirq = mvebu3700_uart_init_postirq,
+    .endboot      = NULL,
+    .suspend      = mvebu3700_uart_suspend,
+    .resume       = mvebu3700_uart_resume,
+    .putc         = mvebu3700_uart_putc,
+    .getc         = mvebu3700_uart_getc,
+    .tx_ready     = mvebu3700_uart_tx_ready,
+    .stop_tx      = mvebu3700_uart_stop_tx,
+    .start_tx     = mvebu3700_uart_start_tx,
+    .irq          = mvebu3700_irq,
+    .vuart_info   = mvebu3700_vuart_info,
+};
+
+static int __init mvebu_uart_init(struct dt_device_node *dev, const void *data)
+{
+    const char *config = data;
+    struct mvebu3700_uart *uart;
+    int res;
+    u64 addr, size;
+
+    if ( strcmp(config, "") )
+        printk("WARNING: UART configuration is not supported\n");
+
+    uart = &mvebu3700_com;
+
+    res = dt_device_get_address(dev, 0, &addr, &size);
+    if ( res )
+    {
+        printk("mvebu3700: Unable to retrieve the base address of the UART\n");
+        return res;
+    }
+
+    res = platform_get_irq(dev, 0);
+    if ( res < 0 )
+    {
+        printk("mvebu3700: Unable to retrieve the IRQ\n");
+        return -EINVAL;
+    }
+
+    uart->irq  = res;
+
+    uart->regs = ioremap_nocache(addr, size);
+    if ( !uart->regs )
+    {
+        printk("mvebu3700: Unable to map the UART memory\n");
+        return -ENOMEM;
+    }
+
+    uart->vuart.base_addr = addr;
+    uart->vuart.size = size;
+    uart->vuart.data_off = UART_CTRL_REG;
+    uart->vuart.status_off = UART_STATUS_REG;
+    uart->vuart.status = STATUS_TX_RDY | STATUS_RX_RDY;
+
+    /* Register with generic serial driver. */
+    serial_register_uart(SERHND_DTUART, &mvebu3700_uart_driver, uart);
+
+    dt_device_set_used_by(dev, DOMID_XEN);
+
+    return 0;
+}
+
+static const struct dt_device_match mvebu_dt_match[] __initconst =
+{
+    DT_MATCH_COMPATIBLE("marvell,armada-3700-uart"),
+    { /* sentinel */ },
+};
+
+DT_DEVICE_START(mvebu, "Marvell Armada-3700 UART", DEVICE_SERIAL)
+    .dt_match = mvebu_dt_match,
+    .init = mvebu_uart_init,
+DT_DEVICE_END
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
Quoted 2 lines

1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Tested-by on v3 1/2
#3 lore raw

Re: [PATCH v3 1/2] xen/arm: Add MVEBU UART driver for Marvell Armada 3700 SoC

In reply to Amit Singh Tomar
Quoted 8 lines · Amit Singh Tomar

This patch adds driver for UART controller found on Armada 3700 SoC.

There is no reference manuals available for 3700 SoC in public and it is derived by looking at Linux driver[1].

[1]https://github.com/torvalds/linux/blob/master/drivers/tty/serial/mvebu-uart.c

Works like a charm, can log into Dom0, Xen console works as well. So in addition to my Reviewed-by:

Cheers,
Andre.

Quoted 349 lines

---
Changes since v2:
* Addressed Andre's comments.
Changes since v1:
* Addressed Wei Liu's comments
* Addressed Andre's comments.
Changes since RFC:
* Addressed Julien's comments.

---
 xen/drivers/char/Kconfig      |   8 ++
 xen/drivers/char/Makefile     |   1 +
 xen/drivers/char/mvebu-uart.c | 296 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 305 insertions(+)
 create mode 100644 xen/drivers/char/mvebu-uart.c
xen/drivers/char/Kconfig +8 -0
index fb53dd8..04a4087 100644
@@ -12,6 +12,14 @@ config HAS_CADENCE_UART
 	  This selects the Xilinx Zynq Cadence UART. If you have a Xilinx Zynq
 	  based board, say Y.
 
+config HAS_MVEBU
+    bool
+    default y
+    depends on ARM_64
+    help
+      This selects the Marvell MVEBU UART. If you have a ARMADA 3700
+      based board, say Y.
+
 config HAS_PL011
 	bool
 	default y
xen/drivers/char/Makefile +1 -0
index 0d48b16..b68c330 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_HAS_NS16550) += ns16550.o
 obj-$(CONFIG_HAS_CADENCE_UART) += cadence-uart.o
 obj-$(CONFIG_HAS_PL011) += pl011.o
 obj-$(CONFIG_HAS_EXYNOS4210) += exynos4210-uart.o
+obj-$(CONFIG_HAS_MVEBU) += mvebu-uart.o
 obj-$(CONFIG_HAS_OMAP) += omap-uart.o
 obj-$(CONFIG_HAS_SCIF) += scif-uart.o
 obj-$(CONFIG_HAS_EHCI) += ehci-dbgp.o
xen/drivers/char/mvebu-uart.c new file +296 -1
new file mode 100644
index 0000000..1561a50
@@ -0,0 +1,296 @@
+/*
+ * xen/drivers/char/mvebu3700-uart.c
+ *
+ * Driver for Marvell MVEBU UART.
+ *
+ * Copyright (c) 2018, Amit Singh Tomar <[email protected]>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/irq.h>
+#include <xen/serial.h>
+#include <xen/vmap.h>
+#include <asm/io.h>
+
+/* Register offsets */
+#define UART_RX_REG             0x00
+
+#define UART_TX_REG             0x04
+
+#define UART_CTRL_REG           0x08
+#define CTRL_TXFIFO_RST         BIT(15)
+#define CTRL_RXFIFO_RST         BIT(14)
+#define CTRL_TX_RDY_INT         BIT(5)
+#define CTRL_RX_RDY_INT         BIT(4)
+#define CTRL_BRK_DET_INT        BIT(3)
+#define CTRL_FRM_ERR_INT        BIT(2)
+#define CTRL_PAR_ERR_INT        BIT(1)
+#define CTRL_OVR_ERR_INT        BIT(0)
+#define CTRL_ERR_INT            (CTRL_BRK_DET_INT | CTRL_FRM_ERR_INT | \
+                                 CTRL_PAR_ERR_INT | CTRL_OVR_ERR_INT)
+
+#define UART_STATUS_REG         0x0c
+#define STATUS_TXFIFO_EMP       BIT(13)
+#define STAT_TX_FIFO_FUL        BIT(11)
+#define STAT_TX_FIFO_HFL        BIT(10)
+#define STATUS_TX_RDY           BIT(5)
+#define STATUS_RX_RDY           BIT(4)
+#define STATUS_BRK_DET          BIT(3)
+#define STATUS_FRM_ERR          BIT(2)
+#define STATUS_PAR_ERR          BIT(1)
+#define STATUS_OVR_ERR          BIT(0)
+#define STATUS_BRK_ERR          (STATUS_BRK_DET | STATUS_FRM_ERR | \
+                                 STATUS_PAR_ERR | STATUS_OVR_ERR)
+
+#define TX_FIFO_SIZE            32
+
+static struct mvebu3700_uart {
+    unsigned int irq;
+    void __iomem *regs;
+    struct irqaction irqaction;
+    struct vuart_info vuart;
+} mvebu3700_com = {0};
+
+#define mvebu3700_read(uart, off)           readl((uart)->regs + off)
+#define mvebu3700_write(uart, off, val)     writel(val, (uart->regs) + off)
+
+static void mvebu3700_uart_interrupt(int irq, void *data,
+                                     struct cpu_user_regs *regs)
+{
+    struct serial_port *port = data;
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t st = mvebu3700_read(uart, UART_STATUS_REG);
+
+    if ( st & (STATUS_RX_RDY | STATUS_OVR_ERR | STATUS_FRM_ERR |
+               STATUS_BRK_DET) )
+        serial_rx_interrupt(port, regs);
+
+    if ( st & STATUS_TX_RDY )
+        serial_tx_interrupt(port, regs);
+}
+
+static void __init mvebu3700_uart_init_preirq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= (CTRL_TXFIFO_RST | CTRL_RXFIFO_RST);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+
+    /* Before we make IRQ request, clear the error bits of state register. */
+    reg = mvebu3700_read(uart, UART_STATUS_REG);
+    reg |= STATUS_BRK_ERR;
+    mvebu3700_write(uart, UART_STATUS_REG, reg);
+
+    /* Clear error interrupts. */
+    mvebu3700_write(uart, UART_CTRL_REG, CTRL_ERR_INT);
+
+    /* Disable Rx/Tx interrupts. */
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg &= ~(CTRL_RX_RDY_INT | CTRL_TX_RDY_INT);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void __init mvebu3700_uart_init_postirq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    if ( uart->irq > 0 )
+    {
+        uart->irqaction.handler = mvebu3700_uart_interrupt;
+        uart->irqaction.name    = "mvebu3700_uart";
+        uart->irqaction.dev_id  = port;
+    }
+
+    if ( setup_irq(uart->irq, 0, &uart->irqaction) != 0 )
+    {
+        printk("Failed to allocated mvebu3700_uart IRQ %d\n", uart->irq);
+        return;
+    }
+
+    /* Make sure Rx/Tx interrupts are enabled now */
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= (CTRL_RX_RDY_INT | CTRL_TX_RDY_INT);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void mvebu3700_uart_suspend(struct serial_port *port)
+{
+    BUG();
+}
+
+static void mvebu3700_uart_resume(struct serial_port *port)
+{
+    BUG();
+}
+
+static void mvebu3700_uart_putc(struct serial_port *port, char c)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    mvebu3700_write(uart, UART_TX_REG, c);
+}
+
+static int mvebu3700_uart_getc(struct serial_port *port, char *c)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    if ( !(mvebu3700_read(uart, UART_STATUS_REG) & STATUS_RX_RDY) )
+        return 0;
+
+    *c = mvebu3700_read(uart, UART_RX_REG) & 0xff;
+
+    return 1;
+}
+
+static int __init mvebu3700_irq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    return (uart->irq > 0) ? uart->irq : -1;
+}
+
+static const struct vuart_info *mvebu3700_vuart_info(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    return &uart->vuart;
+}
+
+static void mvebu3700_uart_stop_tx(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg &= ~CTRL_TX_RDY_INT;
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void mvebu3700_uart_start_tx(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= CTRL_TX_RDY_INT;
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static int mvebu3700_uart_tx_ready(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_STATUS_REG);
+
+    if ( reg & STATUS_TXFIFO_EMP )
+        return TX_FIFO_SIZE;
+    if ( reg & STAT_TX_FIFO_FUL )
+        return 0;
+    if ( reg & STAT_TX_FIFO_HFL )
+        return TX_FIFO_SIZE / 2;
+
+    /* if we reach here, we don't know the number of free char in FIFO
+     * but we are sure that neither the FIFO is full nor empty.
+     * So, let's just return at least 1.
+     */
+    return 1;
+}
+
+static struct uart_driver __read_mostly mvebu3700_uart_driver = {
+    .init_preirq  = mvebu3700_uart_init_preirq,
+    .init_postirq = mvebu3700_uart_init_postirq,
+    .endboot      = NULL,
+    .suspend      = mvebu3700_uart_suspend,
+    .resume       = mvebu3700_uart_resume,
+    .putc         = mvebu3700_uart_putc,
+    .getc         = mvebu3700_uart_getc,
+    .tx_ready     = mvebu3700_uart_tx_ready,
+    .stop_tx      = mvebu3700_uart_stop_tx,
+    .start_tx     = mvebu3700_uart_start_tx,
+    .irq          = mvebu3700_irq,
+    .vuart_info   = mvebu3700_vuart_info,
+};
+
+static int __init mvebu_uart_init(struct dt_device_node *dev, const void *data)
+{
+    const char *config = data;
+    struct mvebu3700_uart *uart;
+    int res;
+    u64 addr, size;
+
+    if ( strcmp(config, "") )
+        printk("WARNING: UART configuration is not supported\n");
+
+    uart = &mvebu3700_com;
+
+    res = dt_device_get_address(dev, 0, &addr, &size);
+    if ( res )
+    {
+        printk("mvebu3700: Unable to retrieve the base address of the UART\n");
+        return res;
+    }
+
+    res = platform_get_irq(dev, 0);
+    if ( res < 0 )
+    {
+        printk("mvebu3700: Unable to retrieve the IRQ\n");
+        return -EINVAL;
+    }
+
+    uart->irq  = res;
+
+    uart->regs = ioremap_nocache(addr, size);
+    if ( !uart->regs )
+    {
+        printk("mvebu3700: Unable to map the UART memory\n");
+        return -ENOMEM;
+    }
+
+    uart->vuart.base_addr = addr;
+    uart->vuart.size = size;
+    uart->vuart.data_off = UART_CTRL_REG;
+    uart->vuart.status_off = UART_STATUS_REG;
+    uart->vuart.status = STATUS_TX_RDY | STATUS_RX_RDY;
+
+    /* Register with generic serial driver. */
+    serial_register_uart(SERHND_DTUART, &mvebu3700_uart_driver, uart);
+
+    dt_device_set_used_by(dev, DOMID_XEN);
+
+    return 0;
+}
+
+static const struct dt_device_match mvebu_dt_match[] __initconst =
+{
+    DT_MATCH_COMPATIBLE("marvell,armada-3700-uart"),
+    { /* sentinel */ },
+};
+
+DT_DEVICE_START(mvebu, "Marvell Armada-3700 UART", DEVICE_SERIAL)
+    .dt_match = mvebu_dt_match,
+    .init = mvebu_uart_init,
+DT_DEVICE_END
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
Quoted 2 lines

1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [PATCH v3 1/2] xen/arm: Add MVEBU UART driver for Marvell Armada 3700 SoC

In reply to Amit Singh Tomar

(+Juergen)

Hi,

Quoted 16 lines · Amit Singh Tomar

This patch adds driver for UART controller found on Armada 3700 SoC.

There is no reference manuals available for 3700 SoC in public and it is derived by looking at Linux driver[1].

[1]https://github.com/torvalds/linux/blob/master/drivers/tty/serial/mvebu-uart.c

---
Changes since v2:
* Addressed Andre's comments.
Changes since v1:
* Addressed Wei Liu's comments
* Addressed Andre's comments.
Changes since RFC:
* Addressed Julien's comments.

Quoted 4 lines
---
  xen/drivers/char/Kconfig      |   8 ++
  xen/drivers/char/Makefile     |   1 +
  xen/drivers/char/mvebu-uart.c | 296 ++++++++++++++++++++++++++++++++++++++++++

As I said on the first version, I think this should fold under "ARM" as all the arch specific UART driver (PL011 & co).

I was expecting this patch to modify MAINTAINERS. I would be ok to commit like that but please send a patch to address this issue as soon as possible.

[...]

Quoted 7 lines
xen/drivers/char/mvebu-uart.c new file +7 -0
+static void __init mvebu3700_uart_init_postirq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    if ( uart->irq > 0 )
+    {

xen/drivers/char/mvebu-uart.c line 122

Quoted 10 lines
xen/drivers/char/mvebu-uart.c new file +10 -0
+        uart->irqaction.handler = mvebu3700_uart_interrupt;
+        uart->irqaction.name    = "mvebu3700_uart";
+        uart->irqaction.dev_id  = port;
+    }
+
+    if ( setup_irq(uart->irq, 0, &uart->irqaction) != 0 )
+    {
+        printk("Failed to allocated mvebu3700_uart IRQ %d\n", uart->irq);
+        return;
+    }

This code looks wrong. You only setup the action when uart->irq is > 0, but you unconditionally call setup_irq.

Other drivers are calling setup_irq(...) when uart->irq > 0.

However, this driver seems to assume the interrupt will always be there as you enable the interrupt below and the initialized would bail out if platform_irq() fails.

So I think you want to drop uart->irq.

[...]

xen/drivers/char/mvebu-uart.c line 163

Quoted 5 lines
xen/drivers/char/mvebu-uart.c new file +5 -0
+static int __init mvebu3700_irq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    return (uart->irq > 0) ? uart->irq : -1;

Same remark here.

[...]

Quoted 5 lines
xen/drivers/char/mvebu-uart.c new file +5 -0
+static int mvebu3700_uart_tx_ready(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+

xen/drivers/char/mvebu-uart.c line 207

Quoted 10 lines
xen/drivers/char/mvebu-uart.c new file +10 -0
+    reg = mvebu3700_read(uart, UART_STATUS_REG);
+
+    if ( reg & STATUS_TXFIFO_EMP )
+        return TX_FIFO_SIZE;
+    if ( reg & STAT_TX_FIFO_FUL )
+        return 0;
+    if ( reg & STAT_TX_FIFO_HFL )
+        return TX_FIFO_SIZE / 2;
+
+    /* if we reach here, we don't know the number of free char in FIFO

Coding style:

/*
*
*/

The rest of the code looks good. Please resend the patch with that addressed.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

Re: [PATCH v3 1/2] xen/arm: Add MVEBU UART driver for Marvell Armada 3700 SoC

Quoted 28 lines · Julien Grall

(+Juergen)

Hi,

Quoted 9 lines · Amit Singh Tomar

This patch adds driver for UART controller found on Armada 3700 SoC.

There is no reference manuals available for 3700 SoC in public and it is derived by looking at Linux driver[1].

[1]https://github.com/torvalds/linux/blob/master/drivers/tty/serial/mvebu-uart.c

Quoted 13 lines

---
Changes since v2:
     * Addressed Andre's comments.
Changes since v1:
     * Addressed Wei Liu's comments
     * Addressed Andre's comments.
Changes since RFC:
     * Addressed Julien's comments.
---
  xen/drivers/char/Kconfig      |   8 ++
  xen/drivers/char/Makefile     |   1 +
  xen/drivers/char/mvebu-uart.c | 296
++++++++++++++++++++++++++++++++++++++++++

Quoted 3 lines

As I said on the first version, I think this should fold under "ARM" as all the arch specific UART driver (PL011 & co).

I was expecting this patch to modify MAINTAINERS. I would be ok to commit like that but please send a patch to address this issue as soon as possible.

It sounds like there are confusion on what I requested here. AFAICT, the MVEBU driver is exclusively used by Arm. So this could be maintained by Stefano and I.

So we could add an entry for that file under "ARM (W/ VIRTUALIZATION EXTENSIONS) ARCHITECTURE" in MAINTAINERS file.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw

Re: [PATCH v3 1/2] xen/arm: Add MVEBU UART driver for Marvell Armada 3700 SoC

In reply to Amit Singh Tomar

Hi,

Quoted 6 lines · Amit Singh Tomar

This patch adds driver for UART controller found on Armada 3700 SoC.

There is no reference manuals available for 3700 SoC in public and it is derived by looking at Linux driver[1].

[1]https://github.com/torvalds/linux/blob/master/drivers/tty/serial/mvebu-uart.c

Another comment.

I forgot to mention. Please give the exact commit you based on. This will be helpful to see what changes between the version you derived and future version.

Cheers,

Quoted 353 lines

---
Changes since v2:
* Addressed Andre's comments.
Changes since v1:
* Addressed Wei Liu's comments
* Addressed Andre's comments.
Changes since RFC:
* Addressed Julien's comments.

---
  xen/drivers/char/Kconfig      |   8 ++
  xen/drivers/char/Makefile     |   1 +
  xen/drivers/char/mvebu-uart.c | 296 ++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 305 insertions(+)

create mode 100644 xen/drivers/char/mvebu-uart.c

xen/drivers/char/Kconfig +8 -0
index fb53dd8..04a4087 100644
@@ -12,6 +12,14 @@ config HAS_CADENCE_UART
  	  This selects the Xilinx Zynq Cadence UART. If you have a Xilinx Zynq
  	  based board, say Y.
 
+config HAS_MVEBU
+    bool
+    default y
+    depends on ARM_64
+    help
+      This selects the Marvell MVEBU UART. If you have a ARMADA 3700
+      based board, say Y.
+
  config HAS_PL011
  	bool
  	default y
xen/drivers/char/Makefile +1 -0
index 0d48b16..b68c330 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_HAS_NS16550) += ns16550.o
  obj-$(CONFIG_HAS_CADENCE_UART) += cadence-uart.o
  obj-$(CONFIG_HAS_PL011) += pl011.o
  obj-$(CONFIG_HAS_EXYNOS4210) += exynos4210-uart.o
+obj-$(CONFIG_HAS_MVEBU) += mvebu-uart.o
  obj-$(CONFIG_HAS_OMAP) += omap-uart.o
  obj-$(CONFIG_HAS_SCIF) += scif-uart.o
  obj-$(CONFIG_HAS_EHCI) += ehci-dbgp.o
xen/drivers/char/mvebu-uart.c new file +296 -1
new file mode 100644
index 0000000..1561a50
@@ -0,0 +1,296 @@
+/*
+ * xen/drivers/char/mvebu3700-uart.c
+ *
+ * Driver for Marvell MVEBU UART.
+ *
+ * Copyright (c) 2018, Amit Singh Tomar <[email protected]>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/irq.h>
+#include <xen/serial.h>
+#include <xen/vmap.h>
+#include <asm/io.h>
+
+/* Register offsets */
+#define UART_RX_REG             0x00
+
+#define UART_TX_REG             0x04
+
+#define UART_CTRL_REG           0x08
+#define CTRL_TXFIFO_RST         BIT(15)
+#define CTRL_RXFIFO_RST         BIT(14)
+#define CTRL_TX_RDY_INT         BIT(5)
+#define CTRL_RX_RDY_INT         BIT(4)
+#define CTRL_BRK_DET_INT        BIT(3)
+#define CTRL_FRM_ERR_INT        BIT(2)
+#define CTRL_PAR_ERR_INT        BIT(1)
+#define CTRL_OVR_ERR_INT        BIT(0)
+#define CTRL_ERR_INT            (CTRL_BRK_DET_INT | CTRL_FRM_ERR_INT | \
+                                 CTRL_PAR_ERR_INT | CTRL_OVR_ERR_INT)
+
+#define UART_STATUS_REG         0x0c
+#define STATUS_TXFIFO_EMP       BIT(13)
+#define STAT_TX_FIFO_FUL        BIT(11)
+#define STAT_TX_FIFO_HFL        BIT(10)
+#define STATUS_TX_RDY           BIT(5)
+#define STATUS_RX_RDY           BIT(4)
+#define STATUS_BRK_DET          BIT(3)
+#define STATUS_FRM_ERR          BIT(2)
+#define STATUS_PAR_ERR          BIT(1)
+#define STATUS_OVR_ERR          BIT(0)
+#define STATUS_BRK_ERR          (STATUS_BRK_DET | STATUS_FRM_ERR | \
+                                 STATUS_PAR_ERR | STATUS_OVR_ERR)
+
+#define TX_FIFO_SIZE            32
+
+static struct mvebu3700_uart {
+    unsigned int irq;
+    void __iomem *regs;
+    struct irqaction irqaction;
+    struct vuart_info vuart;
+} mvebu3700_com = {0};
+
+#define mvebu3700_read(uart, off)           readl((uart)->regs + off)
+#define mvebu3700_write(uart, off, val)     writel(val, (uart->regs) + off)
+
+static void mvebu3700_uart_interrupt(int irq, void *data,
+                                     struct cpu_user_regs *regs)
+{
+    struct serial_port *port = data;
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t st = mvebu3700_read(uart, UART_STATUS_REG);
+
+    if ( st & (STATUS_RX_RDY | STATUS_OVR_ERR | STATUS_FRM_ERR |
+               STATUS_BRK_DET) )
+        serial_rx_interrupt(port, regs);
+
+    if ( st & STATUS_TX_RDY )
+        serial_tx_interrupt(port, regs);
+}
+
+static void __init mvebu3700_uart_init_preirq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= (CTRL_TXFIFO_RST | CTRL_RXFIFO_RST);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+
+    /* Before we make IRQ request, clear the error bits of state register. */
+    reg = mvebu3700_read(uart, UART_STATUS_REG);
+    reg |= STATUS_BRK_ERR;
+    mvebu3700_write(uart, UART_STATUS_REG, reg);
+
+    /* Clear error interrupts. */
+    mvebu3700_write(uart, UART_CTRL_REG, CTRL_ERR_INT);
+
+    /* Disable Rx/Tx interrupts. */
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg &= ~(CTRL_RX_RDY_INT | CTRL_TX_RDY_INT);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void __init mvebu3700_uart_init_postirq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    if ( uart->irq > 0 )
+    {
+        uart->irqaction.handler = mvebu3700_uart_interrupt;
+        uart->irqaction.name    = "mvebu3700_uart";
+        uart->irqaction.dev_id  = port;
+    }
+
+    if ( setup_irq(uart->irq, 0, &uart->irqaction) != 0 )
+    {
+        printk("Failed to allocated mvebu3700_uart IRQ %d\n", uart->irq);
+        return;
+    }
+
+    /* Make sure Rx/Tx interrupts are enabled now */
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= (CTRL_RX_RDY_INT | CTRL_TX_RDY_INT);
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void mvebu3700_uart_suspend(struct serial_port *port)
+{
+    BUG();
+}
+
+static void mvebu3700_uart_resume(struct serial_port *port)
+{
+    BUG();
+}
+
+static void mvebu3700_uart_putc(struct serial_port *port, char c)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    mvebu3700_write(uart, UART_TX_REG, c);
+}
+
+static int mvebu3700_uart_getc(struct serial_port *port, char *c)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    if ( !(mvebu3700_read(uart, UART_STATUS_REG) & STATUS_RX_RDY) )
+        return 0;
+
+    *c = mvebu3700_read(uart, UART_RX_REG) & 0xff;
+
+    return 1;
+}
+
+static int __init mvebu3700_irq(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    return (uart->irq > 0) ? uart->irq : -1;
+}
+
+static const struct vuart_info *mvebu3700_vuart_info(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+
+    return &uart->vuart;
+}
+
+static void mvebu3700_uart_stop_tx(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg &= ~CTRL_TX_RDY_INT;
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static void mvebu3700_uart_start_tx(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_CTRL_REG);
+    reg |= CTRL_TX_RDY_INT;
+    mvebu3700_write(uart, UART_CTRL_REG, reg);
+}
+
+static int mvebu3700_uart_tx_ready(struct serial_port *port)
+{
+    struct mvebu3700_uart *uart = port->uart;
+    uint32_t reg;
+
+    reg = mvebu3700_read(uart, UART_STATUS_REG);
+
+    if ( reg & STATUS_TXFIFO_EMP )
+        return TX_FIFO_SIZE;
+    if ( reg & STAT_TX_FIFO_FUL )
+        return 0;
+    if ( reg & STAT_TX_FIFO_HFL )
+        return TX_FIFO_SIZE / 2;
+
+    /* if we reach here, we don't know the number of free char in FIFO
+     * but we are sure that neither the FIFO is full nor empty.
+     * So, let's just return at least 1.
+     */
+    return 1;
+}
+
+static struct uart_driver __read_mostly mvebu3700_uart_driver = {
+    .init_preirq  = mvebu3700_uart_init_preirq,
+    .init_postirq = mvebu3700_uart_init_postirq,
+    .endboot      = NULL,
+    .suspend      = mvebu3700_uart_suspend,
+    .resume       = mvebu3700_uart_resume,
+    .putc         = mvebu3700_uart_putc,
+    .getc         = mvebu3700_uart_getc,
+    .tx_ready     = mvebu3700_uart_tx_ready,
+    .stop_tx      = mvebu3700_uart_stop_tx,
+    .start_tx     = mvebu3700_uart_start_tx,
+    .irq          = mvebu3700_irq,
+    .vuart_info   = mvebu3700_vuart_info,
+};
+
+static int __init mvebu_uart_init(struct dt_device_node *dev, const void *data)
+{
+    const char *config = data;
+    struct mvebu3700_uart *uart;
+    int res;
+    u64 addr, size;
+
+    if ( strcmp(config, "") )
+        printk("WARNING: UART configuration is not supported\n");
+
+    uart = &mvebu3700_com;
+
+    res = dt_device_get_address(dev, 0, &addr, &size);
+    if ( res )
+    {
+        printk("mvebu3700: Unable to retrieve the base address of the UART\n");
+        return res;
+    }
+
+    res = platform_get_irq(dev, 0);
+    if ( res < 0 )
+    {
+        printk("mvebu3700: Unable to retrieve the IRQ\n");
+        return -EINVAL;
+    }
+
+    uart->irq  = res;
+
+    uart->regs = ioremap_nocache(addr, size);
+    if ( !uart->regs )
+    {
+        printk("mvebu3700: Unable to map the UART memory\n");
+        return -ENOMEM;
+    }
+
+    uart->vuart.base_addr = addr;
+    uart->vuart.size = size;
+    uart->vuart.data_off = UART_CTRL_REG;
+    uart->vuart.status_off = UART_STATUS_REG;
+    uart->vuart.status = STATUS_TX_RDY | STATUS_RX_RDY;
+
+    /* Register with generic serial driver. */
+    serial_register_uart(SERHND_DTUART, &mvebu3700_uart_driver, uart);
+
+    dt_device_set_used_by(dev, DOMID_XEN);
+
+    return 0;
+}
+
+static const struct dt_device_match mvebu_dt_match[] __initconst =
+{
+    DT_MATCH_COMPATIBLE("marvell,armada-3700-uart"),
+    { /* sentinel */ },
+};
+
+DT_DEVICE_START(mvebu, "Marvell Armada-3700 UART", DEVICE_SERIAL)
+    .dt_match = mvebu_dt_match,
+    .init = mvebu_uart_init,
+DT_DEVICE_END
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--

1.9.1

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#8 lore raw

PATCH v3 2/2 xen/arm: Add Marvell ARMADA 3700 early printk support

In reply to Amit Singh Tomar

---
Changes since v2:
* Addressed Andre's comments.
Changes since v1:
* Removed header file dependency.

---
 docs/misc/arm/early-printk.txt     |  1 +
 xen/arch/arm/Rules.mk              |  1 +
 xen/arch/arm/arm64/debug-mvebu.inc | 50 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 xen/arch/arm/arm64/debug-mvebu.inc
docs/misc/arm/early-printk.txt +1 -0
index 20a8af8..f765f59 100644
@@ -41,6 +41,7 @@ the name of the machine:
   - juno: printk with pl011 on Juno platform
   - lager: printk with SCIF0 on Renesas R-Car H2 processors
   - midway: printk with the pl011 on Calxeda Midway processors
+  - mvebu: printk with the MVEBU for Marvell Armada 3700 SoCs
   - omap5432: printk with UART3 on TI OMAP5432 processors
   - rcar3: printk with SCIF2 on Renesas R-Car Gen3 processors
   - seattle: printk with pl011 for AMD Seattle processor
xen/arch/arm/Rules.mk +1 -0
index b66c19f..f264592 100644
@@ -36,6 +36,7 @@ EARLY_PRINTK_hikey960       := pl011,0xfff32000
 EARLY_PRINTK_juno           := pl011,0x7ff80000
 EARLY_PRINTK_lager          := scif,0xe6e60000
 EARLY_PRINTK_midway         := pl011,0xfff36000
+EARLY_PRINTK_mvebu          := mvebu,0xd0012000
 EARLY_PRINTK_omap5432       := 8250,0x48020000,2
 EARLY_PRINTK_rcar3          := scif,0xe6e88000
 EARLY_PRINTK_seattle        := pl011,0xe1010000
xen/arch/arm/arm64/debug-mvebu.inc new file +50 -0

50 lines not on this page · raw message

--
1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v3 2/2
#9 lore raw

Re: [PATCH v3 2/2] xen/arm: Add Marvell ARMADA 3700 early printk support

Hi,

Quoted 1 line · Amit Singh Tomar

Cheers,
Andre.

Quoted 93 lines

---
Changes since v2:
* Addressed Andre's comments.
Changes since v1:
* Removed header file dependency.

---
 docs/misc/arm/early-printk.txt     |  1 +
 xen/arch/arm/Rules.mk              |  1 +
 xen/arch/arm/arm64/debug-mvebu.inc | 50 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 xen/arch/arm/arm64/debug-mvebu.inc
docs/misc/arm/early-printk.txt +1 -0
index 20a8af8..f765f59 100644
@@ -41,6 +41,7 @@ the name of the machine:
   - juno: printk with pl011 on Juno platform
   - lager: printk with SCIF0 on Renesas R-Car H2 processors
   - midway: printk with the pl011 on Calxeda Midway processors
+  - mvebu: printk with the MVEBU for Marvell Armada 3700 SoCs
   - omap5432: printk with UART3 on TI OMAP5432 processors
   - rcar3: printk with SCIF2 on Renesas R-Car Gen3 processors
   - seattle: printk with pl011 for AMD Seattle processor
xen/arch/arm/Rules.mk +1 -0
index b66c19f..f264592 100644
@@ -36,6 +36,7 @@ EARLY_PRINTK_hikey960       := pl011,0xfff32000
 EARLY_PRINTK_juno           := pl011,0x7ff80000
 EARLY_PRINTK_lager          := scif,0xe6e60000
 EARLY_PRINTK_midway         := pl011,0xfff36000
+EARLY_PRINTK_mvebu          := mvebu,0xd0012000
 EARLY_PRINTK_omap5432       := 8250,0x48020000,2
 EARLY_PRINTK_rcar3          := scif,0xe6e88000
 EARLY_PRINTK_seattle        := pl011,0xe1010000
xen/arch/arm/arm64/debug-mvebu.inc new file +50 -1
new file mode 100644
index 0000000..3579ea6
@@ -0,0 +1,50 @@
+/*
+ * xen/arch/arm/arm64/debug-mvebu.inc
+ *
+ * MVEBU specific debug code.
+ *
+ * Copyright (c) 2018, Amit Singh Tomar <[email protected]>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define UART_STATUS_REG     0x0c
+#define UART_TX_REG         0x04
+
+/*
+ * MVEBU UART wait UART to be ready to transmit
+ * xb: register which contains the UART base address
+ * c: scratch register
+ */
+.macro early_uart_ready xb c
+1:
+        ldrh   w\c, [\xb, #UART_STATUS_REG]  /* status register */
+        tst    w\c, #(1 << 11)		         /* Check TXFIFO FULL bit */
+        b.ne   1b                            /* Wait for the UART to be ready */
+.endm
+
+/*
+ * MVEBU UART transmit character
+ * xb: register which contains the UART base address
+ * wt: register which contains the character to transmit
+ */
+.macro early_uart_transmit xb wt
+	strb  \wt, [\xb, #UART_TX_REG]
+.endm
+
+/*
+ * Local variables:
+ * mode: ASM
+ * indent-tabs-mode: nil
+ * End:
+ */
--
Quoted 2 lines

1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Tested-by on v3 2/2
#10 lore raw

Re: [PATCH v3 2/2] xen/arm: Add Marvell ARMADA 3700 early printk support

In reply to Amit Singh Tomar
Quoted 1 line · Amit Singh Tomar

Compiled with CONFIG_EARLY_PRINTK=mvebu, I see Xen's pre-DT boot messages. In addition to my Reviewed-by:

Cheers,
Andre.

Quoted 93 lines

---
Changes since v2:
* Addressed Andre's comments.
Changes since v1:
* Removed header file dependency.

---
 docs/misc/arm/early-printk.txt     |  1 +
 xen/arch/arm/Rules.mk              |  1 +
 xen/arch/arm/arm64/debug-mvebu.inc | 50 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 xen/arch/arm/arm64/debug-mvebu.inc
docs/misc/arm/early-printk.txt +1 -0
index 20a8af8..f765f59 100644
@@ -41,6 +41,7 @@ the name of the machine:
   - juno: printk with pl011 on Juno platform
   - lager: printk with SCIF0 on Renesas R-Car H2 processors
   - midway: printk with the pl011 on Calxeda Midway processors
+  - mvebu: printk with the MVEBU for Marvell Armada 3700 SoCs
   - omap5432: printk with UART3 on TI OMAP5432 processors
   - rcar3: printk with SCIF2 on Renesas R-Car Gen3 processors
   - seattle: printk with pl011 for AMD Seattle processor
xen/arch/arm/Rules.mk +1 -0
index b66c19f..f264592 100644
@@ -36,6 +36,7 @@ EARLY_PRINTK_hikey960       := pl011,0xfff32000
 EARLY_PRINTK_juno           := pl011,0x7ff80000
 EARLY_PRINTK_lager          := scif,0xe6e60000
 EARLY_PRINTK_midway         := pl011,0xfff36000
+EARLY_PRINTK_mvebu          := mvebu,0xd0012000
 EARLY_PRINTK_omap5432       := 8250,0x48020000,2
 EARLY_PRINTK_rcar3          := scif,0xe6e88000
 EARLY_PRINTK_seattle        := pl011,0xe1010000
xen/arch/arm/arm64/debug-mvebu.inc new file +50 -1
new file mode 100644
index 0000000..3579ea6
@@ -0,0 +1,50 @@
+/*
+ * xen/arch/arm/arm64/debug-mvebu.inc
+ *
+ * MVEBU specific debug code.
+ *
+ * Copyright (c) 2018, Amit Singh Tomar <[email protected]>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define UART_STATUS_REG     0x0c
+#define UART_TX_REG         0x04
+
+/*
+ * MVEBU UART wait UART to be ready to transmit
+ * xb: register which contains the UART base address
+ * c: scratch register
+ */
+.macro early_uart_ready xb c
+1:
+        ldrh   w\c, [\xb, #UART_STATUS_REG]  /* status register */
+        tst    w\c, #(1 << 11)		         /* Check TXFIFO FULL bit */
+        b.ne   1b                            /* Wait for the UART to be ready */
+.endm
+
+/*
+ * MVEBU UART transmit character
+ * xb: register which contains the UART base address
+ * wt: register which contains the character to transmit
+ */
+.macro early_uart_transmit xb wt
+	strb  \wt, [\xb, #UART_TX_REG]
+.endm
+
+/*
+ * Local variables:
+ * mode: ASM
+ * indent-tabs-mode: nil
+ * End:
+ */
--
Quoted 2 lines

1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v3 2/2
#12 lore raw

Re: [PATCH v3 2/2] xen/arm: Add Marvell ARMADA 3700 early printk support

In reply to Amit Singh Tomar

Hi,

Quoted 1 line · Amit Singh Tomar

With one change (see below):

[...]

xen/arch/arm/arm64/debug-mvebu.inc line 32

Quoted 9 lines
xen/arch/arm/arm64/debug-mvebu.inc new file +9 -0
+/*
+ * MVEBU UART wait UART to be ready to transmit
+ * xb: register which contains the UART base address
+ * c: scratch register
+ */
+.macro early_uart_ready xb c
+1:
+        ldrh   w\c, [\xb, #UART_STATUS_REG]  /* status register */
+        tst    w\c, #(1 << 11)		         /* Check TXFIFO FULL bit */

This is using hard tabulation. Xen coding style request to use soft tab.

I will fix that on commit.

Quoted 8 lines
xen/arch/arm/arm64/debug-mvebu.inc new file +8 -0
+        b.ne   1b                            /* Wait for the UART to be ready */
+.endm
+
+/*
+ * MVEBU UART transmit character
+ * xb: register which contains the UART base address
+ * wt: register which contains the character to transmit
+ */

xen/arch/arm/arm64/debug-mvebu.inc line 50

Quoted 10 lines
xen/arch/arm/arm64/debug-mvebu.inc new file +10 -0
+.macro early_uart_transmit xb wt
+	strb  \wt, [\xb, #UART_TX_REG]
+.endm
+
+/*
+ * Local variables:
+ * mode: ASM
+ * indent-tabs-mode: nil
+ * End:
+ */

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel