Skip to contentSkip to conversation

Add UART support and arch timer initialization for OMAP5

PATCH Superseded Chen Baozi 3 participants 11 messages Aug 7, 2013

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Chen Baozi

author
#0 lore raw

v2 cover Add UART support and arch timer initialization for OMAP5

Since OMAP UART has a few distinct features than common 8250 UART, I re-implemented its driver rather than porting it based on ns16550.c. There are mainly two big differences between the implementations. First, OMAP UART introduces the concept of register access mode, which divides the register map into seperated space. Switching the access mode is then necessary when configuring it. Second, THRE interrupt needs to be disable after finished transmission and enabled once transmission started. This is because the semantic of THRE interrupt differs from common 8250 in TI's implementation, which would be generated if TX FIFO below trigger level and cannot be cleared by simply write to THR once.

Besides UART driver, arch timer initialization for OMAP5432 platform is also done in this patch series.

Chen Baozi (5):
xen: rename ns16550-uart.h to 8250-uart.h and fix some typos xen/arm: add 8250 compatible UART support for early_printk xen/arm: Add the new OMAP UART driver.
xen/arm: Introduce platform recognition codes for the OMAP5 xen/arm: Add OMAP5 architected timer initialization codes.

 config/arm32.mk                                 |   1 +
 docs/misc/arm/early-printk.txt                  |   1 +
 xen/arch/arm/Rules.mk                           |   4 +
 xen/arch/arm/arm32/debug-8250.inc               |  41 +++
 xen/arch/arm/platforms/Makefile                 |   1 +
 xen/arch/arm/platforms/omap5.c                  | 113 ++++++++
 xen/arch/arm/time.c                             |   7 +-
 xen/drivers/char/Makefile                       |   1 +
 xen/drivers/char/ns16550.c                      |   2 +-
 xen/drivers/char/omap-uart.c                    | 358 ++++++++++++++++++++++++
 xen/include/asm-arm/platforms/omap5.h           |  38 +++
 xen/include/xen/{ns16550-uart.h => 8250-uart.h} |  98 ++++++-
 12 files changed, 651 insertions(+), 14 deletions(-)
 create mode 100644 xen/arch/arm/arm32/debug-8250.inc
 create mode 100644 xen/arch/arm/platforms/omap5.c
 create mode 100644 xen/drivers/char/omap-uart.c
 create mode 100644 xen/include/asm-arm/platforms/omap5.h
 rename xen/include/xen/{ns16550-uart.h => 8250-uart.h} (52%)
Signature · 1 line
1.8.1.4
author
#1 lore raw

PATCH v2 1/5 xen: rename ns16550-uart.h to 8250-uart.h and fix some typos

Since UARTs on OMAP5 & Allwinner's SoC are not ns16550 but only 8250 compatible, rename ns16550-uart.h to 8250-uart.h, which is a more pervasive name. At the same time, fix some typos, which have redundance UART_ prefixes in some macros.

---
 xen/drivers/char/ns16550.c     |   2 +-
 xen/include/xen/8250-uart.h    | 104 +++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/ns16550-uart.h | 104 -----------------------------------------
 3 files changed, 105 insertions(+), 105 deletions(-)
 create mode 100644 xen/include/xen/8250-uart.h
 delete mode 100644 xen/include/xen/ns16550-uart.h
xen/drivers/char/ns16550.c +1 -1
index e085a64..6082c85 100644
@@ -19,7 +19,7 @@
 #include <xen/iocap.h>
 #include <xen/pci.h>
 #include <xen/pci_regs.h>
-#include <xen/ns16550-uart.h>
+#include <xen/8250-uart.h>
 #include <asm/io.h>
 #ifdef CONFIG_X86
 #include <asm/fixmap.h>
xen/include/xen/8250-uart.h new file +104 -0

104 lines not on this page · raw message

xen/include/xen/ns16550-uart.h deleted +0 -104

104 lines not on this page · raw message

Signature · 1 line
1.8.1.4
author
#2 lore raw

PATCH v2 2/5 xen/arm: add 8250 compatible UART support for early_printk

In reply to Chen Baozi

Both OMAP5 and sun6i SoCs share this UART driver for early_printk.

---
 docs/misc/arm/early-printk.txt    |  2 ++
 xen/arch/arm/Rules.mk             |  8 ++++++++
 xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++
 xen/include/xen/8250-uart.h       |  4 ++++
 4 files changed, 55 insertions(+)
 create mode 100644 xen/arch/arm/arm32/debug-8250.inc
docs/misc/arm/early-printk.txt +2 -0
index fbc3208..f24c6c0 100644
@@ -13,6 +13,8 @@ where mach is the name of the machine:
   - exynos5250: printk with the second UART
   - midway: printk with the pl011 on Calxeda Midway processors
   - fastmodel: printk on ARM Fastmodel software emulators
+  - omap5432: printk with UART3 on TI OMAP5432 processors
+  - sun6i: printk with 8250 on Allwinner A31 processors
 
 The base address and baud rate is hardcoded in xen/arch/arm/Rules.mk,
 see there when adding support for new machines.
xen/arch/arm/Rules.mk +8 -0
index a18e7fd..7f11e5c 100644
@@ -64,6 +64,14 @@ EARLY_PRINTK_INC := pl011
 EARLY_PRINTK_BAUD := 115200
 EARLY_UART_BASE_ADDRESS := 0xfff36000
 endif
+ifeq ($(CONFIG_EARLY_PRINTK), omap5432)
+EARLY_PRINTK_INC := 8250
+EARLY_UART_BASE_ADDRESS := 0x48020000
+endif
+ifeq ($(CONFIG_EARLY_PRINTK), sun6i)
+EARLY_PRINTK_INC := 8250
+EARLY_UART_BASE_ADDRESS := 0x01c28000
+endif
 
 ifneq ($(EARLY_PRINTK_INC),)
 EARLY_PRINTK := y
xen/arch/arm/arm32/debug-8250.inc new file +41 -0

41 lines not on this page · raw message

xen/include/xen/8250-uart.h +4 -0
index 7287364..33daa6d 100644
@@ -22,6 +22,10 @@
 #ifndef __XEN_8250_UART_H__
 #define __XEN_8250_UART_H__
 
+#ifdef CONFIG_ARM
+#define REG_SHIFT         2
+#endif
+
 /* Register offsets */
 #define UART_RBR          0x00    /* receive buffer       */
 #define UART_THR          0x00    /* transmit holding     */
Signature · 1 line
1.8.1.4
author
#3 lore raw

PATCH v2 2/5 xen/arm: add OMAP5432 UART support for early_printk

In reply to Chen Baozi
---
 docs/misc/arm/early-printk.txt    |  1 +
 xen/arch/arm/Rules.mk             |  4 ++++
 xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++
 xen/include/xen/8250-uart.h       |  6 ++++++
 4 files changed, 52 insertions(+)
 create mode 100644 xen/arch/arm/arm32/debug-8250.inc
docs/misc/arm/early-printk.txt +1 -0
index fbc3208..874488f 100644
@@ -13,6 +13,7 @@ where mach is the name of the machine:
   - exynos5250: printk with the second UART
   - midway: printk with the pl011 on Calxeda Midway processors
   - fastmodel: printk on ARM Fastmodel software emulators
+  - omap5432: printk with UART3 on TI OMAP5432 processors
 
 The base address and baud rate is hardcoded in xen/arch/arm/Rules.mk,
 see there when adding support for new machines.
xen/arch/arm/Rules.mk +4 -0
index a18e7fd..346c824 100644
@@ -64,6 +64,10 @@ EARLY_PRINTK_INC := pl011
 EARLY_PRINTK_BAUD := 115200
 EARLY_UART_BASE_ADDRESS := 0xfff36000
 endif
+ifeq ($(CONFIG_EARLY_PRINTK), omap5432)
+EARLY_PRINTK_INC := 8250
+EARLY_UART_BASE_ADDRESS := 0x48020000
+endif
 
 ifneq ($(EARLY_PRINTK_INC),)
 EARLY_PRINTK := y
xen/arch/arm/arm32/debug-8250.inc new file +41 -0

41 lines not on this page · raw message

xen/include/xen/8250-uart.h +6 -0
index 7287364..0e6c6bd 100644
@@ -22,6 +22,12 @@
 #ifndef __XEN_8250_UART_H__
 #define __XEN_8250_UART_H__
 
+#ifdef CONFIG_ARM
+#define REG_SHIFT         2
+#else
+#define REG_SHIFT         0
+#endif
+
 /* Register offsets */
 #define UART_RBR          0x00    /* receive buffer       */
 #define UART_THR          0x00    /* transmit holding     */
Signature · 1 line
1.8.1.4
author
#8 lore raw

PATCH v2 3/5 xen/arm: Add the new OMAP UART driver.

In reply to Chen Baozi

TI OMAP UART introduces some features such as register access modes, which makes its configuration and interrupt handling differs from 8250 compatible UART. Thus, we seperate this driver from ns16550's implementation.

---
 config/arm32.mk               |   1 +
 xen/common/device_tree.c      |  15 ++
 xen/drivers/char/Makefile     |   1 +
 xen/drivers/char/omap-uart.c  | 352 ++++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/8250-uart.h   |  59 ++++++-
 xen/include/xen/device_tree.h |   6 +
 6 files changed, 431 insertions(+), 3 deletions(-)
 create mode 100644 xen/drivers/char/omap-uart.c
config/arm32.mk +1 -0
index 8e21158..76e229d 100644
@@ -11,6 +11,7 @@ CFLAGS += -marm
 
 HAS_PL011 := y
 HAS_EXYNOS4210 := y
+HAS_OMAP := y
 
 # Use only if calling $(LD) directly.
 LDFLAGS_DIRECT += -EL
xen/common/device_tree.c +15 -0
index 84d704d..b392c60 100644
@@ -574,6 +574,21 @@ const void *dt_get_property(const struct dt_device_node *np,
     return pp ? pp->value : NULL;
 }
 
+int dt_property_read_u32(const struct dt_device_node *np,
+                            const char *name, u32 *out_value)
+{
+    u32 len;
+    const __be32 *val;
+
+    val = dt_get_property(np, name, &len);
+    if ( !val || len > 4 )
+        return 1;
+
+    *out_value = be32_to_cpup(val);
+
+    return 0;
+}
+
 bool_t dt_device_is_compatible(const struct dt_device_node *device,
                                const char *compat)
 {
xen/drivers/char/Makefile +1 -0
index 37543f0..911b788 100644
@@ -2,6 +2,7 @@ obj-y += console.o
 obj-$(HAS_NS16550) += ns16550.o
 obj-$(HAS_PL011) += pl011.o
 obj-$(HAS_EXYNOS4210) += exynos4210-uart.o
+obj-$(HAS_OMAP) += omap-uart.o
 obj-$(HAS_EHCI) += ehci-dbgp.o
 obj-$(CONFIG_ARM) += dt-uart.o
 obj-y += serial.o
xen/drivers/char/omap-uart.c new file +352 -0

352 lines not on this page · raw message

xen/include/xen/8250-uart.h +56 -3

81 lines not on this page · raw message

xen/include/xen/device_tree.h +6 -0
index 5a2a5c6..ab21a81 100644
@@ -300,6 +300,12 @@ const void *dt_get_property(const struct dt_device_node *np,
                             const char *name, u32 *lenp);
 
 /**
+ * dt_property_read_u32 - Helper to read a u32 property.
+ */
+int dt_property_read_u32(const struct dt_device_node *np,
+			 const char *name, u32 *out_value);
+
+/**
  * Checks if the given "compat" string matches one of the strings in
  * the device's "compatible" property
  */
Signature · 1 line
1.8.1.4
author
#9 lore raw

PATCH v2 4/5 xen/arm: Introduce platform recognition codes for the OMAP5

In reply to Chen Baozi
---
 xen/arch/arm/platforms/Makefile       |  1 +
 xen/arch/arm/platforms/omap5.c        | 41 +++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/platforms/omap5.h | 13 +++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 xen/arch/arm/platforms/omap5.c
 create mode 100644 xen/include/asm-arm/platforms/omap5.h
xen/arch/arm/platforms/Makefile +1 -0
index ff2b65b..90ddcb1 100644
@@ -1,2 +1,3 @@
 obj-y += vexpress.o
 obj-y += exynos5.o
+obj-y += omap5.o
xen/arch/arm/platforms/omap5.c new file +41 -0

41 lines not on this page · raw message

xen/include/asm-arm/platforms/omap5.h new file +13 -0
new file mode 100644
index 0000000..ff07d95
@@ -0,0 +1,13 @@
+#ifndef __ASM_ARM_PLATFORMS_OMAP5_H
+#define __ASM_ASM_PLATFORMS_OMAP5_H
+
+#endif /* __ASM_ARM_PLATFORMS_OMAP5_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
1.8.1.4
author
#10 lore raw

PATCH v2 5/5 xen/arm: Add OMAP5 architected timer initialization codes.

In reply to Chen Baozi
---
 xen/arch/arm/platforms/omap5.c        | 72 +++++++++++++++++++++++++++++++++++
 xen/arch/arm/time.c                   |  7 +++-
 xen/include/asm-arm/platforms/omap5.h | 12 ++++++
 3 files changed, 90 insertions(+), 1 deletion(-)
xen/arch/arm/platforms/omap5.c +72 -0
index 084e211..4791366 100644
@@ -20,6 +20,77 @@
 #include <xen/config.h>
 #include <asm/platform.h>
 #include <asm/platforms/omap5.h>
+#include <xen/mm.h>
+#include <xen/vmap.h>
+
+static uint16_t num_den[8][2] = {
+    {         0,          0 },  /* not used */
+    {  26 *  64,  26 *  125 },  /* 12.0 Mhz */
+    {   2 * 768,   2 * 1625 },  /* 13.0 Mhz */
+    {         0,          0 },  /* not used */
+    { 130 *   8, 130 *   25 },  /* 19.2 Mhz */
+    {   2 * 384,   2 * 1625 },  /* 26.0 Mhz */
+    {   3 * 256,   3 * 1125 },  /* 27.0 Mhz */
+    { 130 *   4, 130 *   25 },  /* 38.4 Mhz */
+};
+
+/*
+ * The realtime counter also called master counter, is a free-running
+ * counter, which is related to real time. It produces the count used
+ * by the CPU local timer peripherals in teh MPU cluster. The timer counts
+ * at a rate of 6.144 MHz. Because the device operates on different clocks
+ * in different power modes, the master counter shifts operation between
+ * clocks, adjusting the increment per clock in hardware accordingly to
+ * maintain a constant count rate.
+ */
+static int omap5_init_time(void)
+{
+    void __iomem *ckgen_prm_base;
+    void __iomem *rt_ct_base;
+    unsigned int sys_clksel;
+    unsigned int num, den, frac1, frac2;
+
+    ckgen_prm_base = ioremap_attr(OMAP5_CKGEN_PRM_BASE,
+                                  0x20, PAGE_HYPERVISOR_NOCACHE);
+    if (!ckgen_prm_base) {
+        dprintk(XENLOG_ERR, "%s: PRM_BASE ioremap failed\n", __func__);
+        return -ENOMEM;
+    }
+
+    sys_clksel = ioreadl(ckgen_prm_base + OMAP5_CM_CLKSEL_SYS) &
+        ~SYS_CLKSEL_MASK;
+
+    iounmap(ckgen_prm_base);
+
+    rt_ct_base = ioremap_attr(REALTIME_COUNTER_BASE,
+                              0x20, PAGE_HYPERVISOR_NOCACHE);
+    if (!rt_ct_base) {
+        dprintk(XENLOG_ERR, "%s: REALTIME_COUNTER_BASE ioremap failed\n", __func__);
+        return -ENOMEM;
+    }
+
+    frac1 = ioreadl(rt_ct_base + INCREMENTER_NUMERATOR_OFFSET);
+    num = frac1 & ~NUMERATOR_DENUMERATOR_MASK;
+    if (num_den[sys_clksel][0] != num) {
+        frac1 &= NUMERATOR_DENUMERATOR_MASK;
+        frac1 |= num_den[sys_clksel][0];
+    }
+
+    frac2 = ioreadl(rt_ct_base + INCREMENTER_DENUMERATOR_RELOAD_OFFSET);
+    den = frac2 & ~NUMERATOR_DENUMERATOR_MASK;
+    if (num_den[sys_clksel][1] != num) {
+        frac2 &= NUMERATOR_DENUMERATOR_MASK;
+        frac2 |= num_den[sys_clksel][1];
+    }
+
+    iowritel(rt_ct_base + INCREMENTER_NUMERATOR_OFFSET, frac1);
+    iowritel(rt_ct_base + INCREMENTER_DENUMERATOR_RELOAD_OFFSET,
+             frac2 | PRM_FRAC_INCREMENTER_DENUMERATOR_RELOAD);
+
+    iounmap(rt_ct_base);
+
+    return 0;
+}
 
 static const char const *omap5_dt_compat[] __initdata =
 {
@@ -29,6 +100,7 @@ static const char const *omap5_dt_compat[] __initdata =
 
 PLATFORM_START(omap5, "TI OMAP5")
     .compatible = omap5_dt_compat,
+    .init_time = omap5_init_time,
 PLATFORM_END
 
 /*
xen/arch/arm/time.c +6 -1
index 4ed7882..fd48a4b 100644
@@ -104,6 +104,7 @@ int __init init_xen_time(void)
     struct dt_device_node *dev;
     int res;
     unsigned int i;
+    u32 rate;
 
     dev = dt_find_compatible_node(NULL, NULL, "arm,armv7-timer");
     if ( !dev )
@@ -134,7 +135,11 @@ int __init init_xen_time(void)
     if ( !cpu_has_gentimer )
         panic("CPU does not support the Generic Timer v1 interface.\n");
 
-    cpu_khz = READ_SYSREG32(CNTFRQ_EL0) / 1000;
+    res = dt_property_read_u32(dev, "clock-frequency", &rate);
+    if ( !res )
+	cpu_khz = rate / 1000;
+    else
+        cpu_khz = READ_SYSREG32(CNTFRQ_EL0) / 1000;
 
     boot_count = READ_SYSREG64(CNTPCT_EL0);
     printk("Using generic timer at %lu KHz\n", cpu_khz);
xen/include/asm-arm/platforms/omap5.h +12 -0
index ff07d95..c657bae 100644
@@ -1,6 +1,18 @@
 #ifndef __ASM_ARM_PLATFORMS_OMAP5_H
 #define __ASM_ASM_PLATFORMS_OMAP5_H
 
+#define REALTIME_COUNTER_BASE                 0x48243200
+#define INCREMENTER_NUMERATOR_OFFSET          0x10
+#define INCREMENTER_DENUMERATOR_RELOAD_OFFSET 0x14
+#define NUMERATOR_DENUMERATOR_MASK            0xfffff000
+#define PRM_FRAC_INCREMENTER_DENUMERATOR_RELOAD 0x00010000
+
+#define OMAP5_L4_WKUP                         0x4AE00000
+#define OMAP5_PRM_BASE                        (OMAP5_L4_WKUP + 0x6000)
+#define OMAP5_CKGEN_PRM_BASE                  (OMAP5_PRM_BASE + 0x100)
+#define OMAP5_CM_CLKSEL_SYS                   0x10
+#define SYS_CLKSEL_MASK                       0xfffffff8
+
 #endif /* __ASM_ARM_PLATFORMS_OMAP5_H */
 
 /*
Signature · 1 line
1.8.1.4
author
#4 lore raw

Re: [PATCH 2/5] xen/arm: add OMAP5432 UART support for early_printk

In reply to Chen Baozi
Quoted 8 lines · Chen Baozi

---

docs/misc/arm/early-printk.txt    |  1 +
xen/arch/arm/Rules.mk             |  4 ++++
xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++
xen/include/xen/8250-uart.h       |  6 ++++++
4 files changed, 52 insertions(+)

create mode 100644 xen/arch/arm/arm32/debug-8250.inc

Sorry, I resent the previous version by mistake. Please ignore it.

Baozi

#5 lore raw

Re: [PATCH 2/5] xen/arm: add OMAP5432 UART support for early_printk

Quoted 11 lines · Chen Baozi
Quoted 8 lines · Chen Baozi

---

docs/misc/arm/early-printk.txt    |  1 +
xen/arch/arm/Rules.mk             |  4 ++++
xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++
xen/include/xen/8250-uart.h       |  6 ++++++
4 files changed, 52 insertions(+)

create mode 100644 xen/arch/arm/arm32/debug-8250.inc

Quoted 1 line

Sorry, I resent the previous version by mistake. Please ignore it.

The whole series and not just this one patch, right?

Quoted 2 lines

Baozi

author
#6 lore raw

Re: [PATCH 2/5] xen/arm: add OMAP5432 UART support for early_printk

Quoted 12 lines · Ian Campbell
Quoted 11 lines · Chen Baozi
Quoted 8 lines · Chen Baozi

---

docs/misc/arm/early-printk.txt    |  1 +
xen/arch/arm/Rules.mk             |  4 ++++
xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++
xen/include/xen/8250-uart.h       |  6 ++++++
4 files changed, 52 insertions(+)

create mode 100644 xen/arch/arm/arm32/debug-8250.inc

Quoted 3 lines
Quoted 1 line

Sorry, I resent the previous version by mistake. Please ignore it.

The whole series and not just this one patch, right?

Actually, the cover page and this one.

I'll resend the whole series again. Sorry for the noisy.

Quoted 5 lines
Quoted 3 lines

Baozi

#7 lore raw

Re: [PATCH 2/5] xen/arm: add OMAP5432 UART support for early_printk

Quoted 15 lines · Chen Baozi
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Chen Baozi
Quoted 8 lines · Chen Baozi

---

docs/misc/arm/early-printk.txt    |  1 +
xen/arch/arm/Rules.mk             |  4 ++++
xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++
xen/include/xen/8250-uart.h       |  6 ++++++
4 files changed, 52 insertions(+)

create mode 100644 xen/arch/arm/arm32/debug-8250.inc

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Sorry, I resent the previous version by mistake. Please ignore it.

The whole series and not just this one patch, right?

Actually, the cover page and this one.

I'll resend the whole series again. Sorry for the noisy.

As you resend this patch series, can you specify the different changes for each patches?

Signature · 1 line
Julien