Add UART support and arch timer initialization for OMAP5
v6 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.
v6 <- v5:
- Add EARLY_UART_REG_SHIFT and remove REG_SHIFT in 8250-uart.h
- Define REG_SHIFT in omap-uart.c rather than 8250-uart.h, since Linux also uses hardcoded regshift in omap-uart driver and there is no reg-shift of UART defined in OMAP5's DT.
- Separate dt_property_read_u32 introduction into a single patch.
- Fix some typos.
v5 <- v4:
- Separate dt specified arch_timer clkfrq setup into patch #4.
v4 <- v3:
- Merege #4 and #5 in v3 into one patch.
- Fix some coding-style and comments.
v3 <- v2:
- [3/5] Use bool_t as the return type of dt_property_read_u32.
- [3/5] Use sizeof(*out_value) instead of hardcoded value in dt_property_read_u32.
- [3/5] Fix some coding-style problems and some typos.
v2 <- v1:
- [2/5] Add early printk support for sun6i.
- [3/5] Introduce dt_property_read_u32() helper to get clock-frequency.
- [3/5] Use ioreadl/iowritel instead of uart->regs[...] in OMAP UART driver.
- [3/5] Change do-while structure to while in OMAP UART interrupt handler.
- [3/5] Use hardcoded value when setting up OMAP UART.
- [3/5] Won't enable IRQ if setup failed in init_postirq().
- [3/5] Fix coding-style problems and some typos.
- [3/5] Remove unnecessary define.
- [4/5] Remove the macros that would be used in future.
- [5/5] Use dt_property_read_u32() helper to get clock-frequency.
- [5/5] Remove unused define.
Chen Baozi (6):
xen: rename ns16550-uart.h to 8250-uart.h and fix some typos xen/arm: add 8250 compatible UART support for early_printk
xen: Introduce a helper to read a u32 property in device tree. xen/arm: Add the new OMAP UART driver.
xen/arm: Add support for device tree specified arch_timer clock
frequency.
xen/arm: Platform recognition and initialize arch_timer for the OMAP5
config/arm32.mk | 1 +
docs/misc/arm/early-printk.txt | 3 +
xen/arch/arm/Rules.mk | 16 ++
xen/arch/arm/arm32/debug-8250.inc | 41 +++
xen/arch/arm/platforms/Makefile | 1 +
xen/arch/arm/platforms/omap5.c | 117 ++++++++
xen/arch/arm/time.c | 7 +-
xen/common/device_tree.c | 15 +
xen/drivers/char/Makefile | 1 +
xen/drivers/char/ns16550.c | 2 +-
xen/drivers/char/omap-uart.c | 354 ++++++++++++++++++++++++
xen/include/asm-arm/platforms/omap5.h | 25 ++
xen/include/xen/{ns16550-uart.h => 8250-uart.h} | 69 ++++-
xen/include/xen/device_tree.h | 11 +
14 files changed, 652 insertions(+), 11 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} (63%)Signature · 1 line
1.8.1.4
PATCH v6 1/6 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/{ns16550-uart.h => 8250-uart.h} | 18 +++++++++---------
2 files changed, 10 insertions(+), 10 deletions(-)
rename xen/include/xen/{ns16550-uart.h => 8250-uart.h} (89%)xen/drivers/char/ns16550.c +1 -1
@@ -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 renamed from xen/include/xen/ns16550-uart.h +9 -9
@@ -1,5 +1,5 @@/* -* xen/include/xen/ns16550-uart.h +* xen/include/xen/8250-uart.h * * This header is extracted from driver/char/ns16550.c *
@@ -19,8 +19,8 @@* GNU General Public License for more details. */ -#ifndef __XEN_NS16550_UART_H__ -#define __XEN_NS16550_UART_H__ +#ifndef __XEN_8250_UART_H__ +#define __XEN_8250_UART_H__/* Register offsets */ #define UART_RBR 0x00/* receive buffer */
@@ -43,11 +43,11 @@/* Interrupt Identificatiegister */ #define UART_IIR_NOINT 0x01/* no interrupt pending */ -#define UART_UART_IIR_IMA 0x06/* interrupt identity: */ -#define UART_UART_IIR_LSI 0x06/* - rx line status */ -#define UART_UART_IIR_RDA 0x04/* - rx data recv'd */ -#define UART_UART_IIR_THR 0x02/* - tx reg. empty */ -#define UART_UART_IIR_MSI 0x00/* - MODEM status */ +#define UART_IIR_IMA 0x06/* interrupt identity: */ +#define UART_IIR_LSI 0x06/* - rx line status */ +#define UART_IIR_RDA 0x04/* - rx data recv'd */ +#define UART_IIR_THR 0x02/* - tx reg. empty */ +#define UART_IIR_MSI 0x00/* - MODEM status */ /* FIFO Control Register */ #define UART_FCR_ENABLE 0x01/* enable FIFO */
@@ -92,7 +92,7 @@#define RESUME_DELAY MILLISECS(10)#define RESUME_RETRIES 100 -#endif /* __XEN_NS16550_UART_H__ */ +#endif /* __XEN_8250_UART_H__ */ /* * Local variables:
Signature · 1 line
1.8.1.4
PATCH v6 2/6 xen/arm: add 8250 compatible UART support for early_printk
In reply to Chen BaoziBoth OMAP5 and sun6i/sun7i SoCs share this UART driver for early_printk.
--- docs/misc/arm/early-printk.txt | 3 +++ xen/arch/arm/Rules.mk | 16 +++++++++++++++ xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 xen/arch/arm/arm32/debug-8250.inc
docs/misc/arm/early-printk.txt +3 -0
@@ -13,6 +13,9 @@ 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 + - sun7i: printk with 8250 on Allwinner A20 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 +16 -0
@@ -64,6 +64,21 @@ 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 +EARLY_UART_REG_SHIFT := 2 +endif +ifeq ($(CONFIG_EARLY_PRINTK), sun6i) +EARLY_PRINTK_INC := 8250 +EARLY_UART_BASE_ADDRESS := 0x01c28000 +EARLY_UART_REG_SHIFT := 2 +endif +ifeq ($(CONFIG_EARLY_PRINTK), sun7i) +EARLY_PRINTK_INC := 8250 +EARLY_UART_BASE_ADDRESS := 0x01c28000 +EARLY_UART_REG_SHIFT := 2 +endif ifneq ($(EARLY_PRINTK_INC),) EARLY_PRINTK := y
@@ -74,4 +89,5 @@ CFLAGS-$(EARLY_PRINTK_INIT_UART) += -DEARLY_PRINTK_INIT_UART CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_INC=\"debug-$(EARLY_PRINTK_INC).inc\" CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_BAUD=$(EARLY_PRINTK_BAUD) CFLAGS-$(EARLY_PRINTK) += -DEARLY_UART_BASE_ADDRESS=$(EARLY_UART_BASE_ADDRESS) +CFLAGS-$(EARLY_PRINTK) += -DEARLY_UART_REG_SHIFT=$(EARLY_UART_REG_SHIFT) endif
xen/arch/arm/arm32/debug-8250.inc new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v6 3/6 xen: Introduce a helper to read a u32 property in device tree.
In reply to Chen Baozi--- xen/common/device_tree.c | 15 +++++++++++++++ xen/include/xen/device_tree.h | 11 +++++++++++ 2 files changed, 26 insertions(+)
xen/common/device_tree.c +15 -0
@@ -574,6 +574,21 @@ const void *dt_get_property(const struct dt_device_node *np,return pp ? pp->value :NULL ; } +bool_t 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 >sizeof (*out_value) ) +return 0 ; + + *out_value =be32_to_cpup (val); + +return 1 ; +} +bool_t dt_device_is_compatible (const struct dt_device_node *device,const char *compat) {
xen/include/xen/device_tree.h +11 -0
@@ -300,6 +300,17 @@ 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. +* @np: node to get the value +* @name: name of the property +* @out_value: pointer to return value +* +* Return true if get the desired value. +*/ +bool_t 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
PATCH v6 4/6 xen/arm: Add the new OMAP UART driver.
In reply to Chen BaoziTI 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/drivers/char/Makefile | 1 + xen/drivers/char/omap-uart.c | 354 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/8250-uart.h | 51 +++++++ 4 files changed, 407 insertions(+) create mode 100644 xen/drivers/char/omap-uart.c
config/arm32.mk +1 -0
@@ -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/drivers/char/Makefile +1 -0
@@ -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 +354 -0
354 lines not on this page · raw message
xen/include/xen/8250-uart.h +51 -0
71 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v6 5/6 xen/arm: Add support for device tree specified arch_timer clock frequency.
In reply to Chen Baozi--- xen/arch/arm/time.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/arm/time.c +6 -1
@@ -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);
Signature · 1 line
1.8.1.4
PATCH v6 6/6 xen/arm: Platform recognition and initialize arch_timer for the OMAP5
In reply to Chen Baozi--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/omap5.c | 117 ++++++++++++++++++++++++++++++++++ xen/include/asm-arm/platforms/omap5.h | 25 ++++++++ 3 files changed, 143 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
@@ -1,2 +1,3 @@ obj-y += vexpress.o obj-y += exynos5.o +obj-y += omap5.o
xen/arch/arm/platforms/omap5.c new file +117 -0
117 lines not on this page · raw message
xen/include/asm-arm/platforms/omap5.h new file +25 -0
@@ -0,0 +1,25 @@ +#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 */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.8.1.4
Re: [PATCH v6 2/6] xen/arm: add 8250 compatible UART support for early_printk
In reply to Chen BaoziQuoted 37 lines · Chen Baozi
Both OMAP5 and sun6i/sun7i SoCs share this UART driver for
early_printk.Signed-off-by Chen Baozi <[email protected]>--- docs/misc/arm/early-printk.txt | 3 +++ xen/arch/arm/Rules.mk | 16 +++++++++++++++ xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 xen/arch/arm/arm32/debug-8250.incdocs/misc/arm/early-printk.txt +3
-0@@ -13,6 +13,9 @@ 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 + - sun7i: printk with 8250 on Allwinner A20 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 +5
-0@@ -64,6 +64,21 @@ 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 +EARLY_UART_REG_SHIFT := 2 +endif
xen/arch/arm/Rules.mk EARLY_PRINTK_INC := pl011 · line 81
Quoted 10 lines
xen/arch/arm/Rules.mk +10
-0+ifeq ($(CONFIG_EARLY_PRINTK), sun6i) +EARLY_PRINTK_INC := 8250 +EARLY_UART_BASE_ADDRESS := 0x01c28000 +EARLY_UART_REG_SHIFT := 2 +endif +ifeq ($(CONFIG_EARLY_PRINTK), sun7i) +EARLY_PRINTK_INC := 8250 +EARLY_UART_BASE_ADDRESS := 0x01c28000 +EARLY_UART_REG_SHIFT := 2 +endif
If the shift is the same for all UART based on 8250, you can simply define EARLY_UART_... in debug-8250.inc.
Quoted 56 lines
xen/arch/arm/Rules.mk +1
-0ifneq ($(EARLY_PRINTK_INC),) EARLY_PRINTK := y@@ -74,4 +89,5 @@ CFLAGS-$(EARLY_PRINTK_INIT_UART) += -DEARLY_PRINTK_INIT_UART CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_INC=\"debug-$(EARLY_PRINTK_INC).inc\" CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_BAUD=$(EARLY_PRINTK_BAUD) CFLAGS-$(EARLY_PRINTK) += -DEARLY_UART_BASE_ADDRESS=$(EARLY_UART_BASE_ADDRESS) +CFLAGS-$(EARLY_PRINTK) += -DEARLY_UART_REG_SHIFT=$(EARLY_UART_REG_SHIFT) endifxen/arch/arm/arm32/debug-8250.inc new file +41
-0@@ -0,0 +1,41 @@ +/* + * xen/arch/arm/arm32/debug-8250.inc + * + * 8250 specific debug code + * + * 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/8250-uart.h> + +/* 8250 UART wait UART to be ready to transmit + * rb: register which contains the UART base address + * rc: scratch register */ +.macro early_uart_ready rb rc +1: + ldr \rc, [\rb, #(UART_LSR << EARLY_UART_REG_SHIFT)] /* Read LSR */ + tst \rc, #UART_LSR_THRE /* Check Xmit holding register flag */ + beq 1b /* Wait for the UART to be ready */ +.endm + +/* 8250 UART transmit character + * rb: register which contains the UART base address + * rt: register which contains the character to transmit */ +.macro early_uart_transmit rb rt + str \rt, [\rb, #UART_THR] /* Write Transmit buffer */ +.endm + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */
Signature · 1 line
Julien Grall
Re: [PATCH v6 3/6] xen: Introduce a helper to read a u32 property in device tree.
In reply to Chen BaoziQuoted 1 line · Chen Baozi
Signed-off-by Chen Baozi <[email protected]>
Quoted 54 lines
--- xen/common/device_tree.c | 15 +++++++++++++++ xen/include/xen/device_tree.h | 11 +++++++++++ 2 files changed, 26 insertions(+)xen/common/device_tree.c +15
-0@@ -574,6 +574,21 @@ const void *dt_get_property(const struct dt_device_node *np,return pp ? pp->value :NULL ; } +bool_t 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 >sizeof (*out_value) ) +return 0 ; + + *out_value =be32_to_cpup (val); + +return 1 ; +} +bool_t dt_device_is_compatible (const struct dt_device_node *device,const char *compat) {xen/include/xen/device_tree.h +11
-0@@ -300,6 +300,17 @@ 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. +* @np: node to get the value +* @name: name of the property +* @out_value: pointer to return value +* +* Return true if get the desired value. +*/ +bool_t 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
Julien Grall
Re: [PATCH v6 3/6] xen: Introduce a helper to read a u32 property in device tree.
Quoted 16 lines · Julien Grall
Quoted 1 line · Chen Baozi
Signed-off-by Chen Baozi <[email protected]>Acked-by Julien Grall <[email protected]>Quoted 13 lines
--- xen/common/device_tree.c | 15 +++++++++++++++ xen/include/xen/device_tree.h | 11 +++++++++++ 2 files changed, 26 insertions(+)xen/common/device_tree.c +0
-0@@ -574,6 +574,21 @@ const void *dt_get_property(const struct dt_device_node *np,return pp ? pp->value :NULL ; }
Quoted 9 lines
xen/common/device_tree.c const void *dt_get_property(const struct dt_device_node *np, · line 585
Quoted 9 lines
xen/common/device_tree.c +9
-0+bool_t 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 >sizeof (*out_value) ) +return 0 ;
Hum .. I have just noticed that the check is wrong.
Len must be greater or equal to sizeof (*out_value). Otherwise you can read random bytes.
Quoted 36 lines
Quoted 22 lines
xen/common/device_tree.c +6
-0+ + *out_value =be32_to_cpup (val); + +return 1 ; +} +bool_t dt_device_is_compatible (const struct dt_device_node *device,const char *compat) {xen/include/xen/device_tree.h +4
-0@@ -300,6 +300,17 @@ 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. +* @np: node to get the value +* @name: name of the property +* @out_value: pointer to return value xen/include/xen/device_tree.h const void *dt_get_property(const struct dt_device_node *np, · line 316
Quoted 10 lines
xen/include/xen/device_tree.h +7
-0+* +* Return true if get the desired value. +*/ +bool_t 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 */ --
Julien Grall
Signature · 1 line
Julien Grall
Re: [PATCH v6 4/6] xen/arm: Add the new OMAP UART driver.
In reply to Chen BaoziQuoted 67 lines · 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.
Signed-off-by Chen Baozi <[email protected]>--- config/arm32.mk | 1 + xen/drivers/char/Makefile | 1 + xen/drivers/char/omap-uart.c | 354 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/8250-uart.h | 51 +++++++ 4 files changed, 407 insertions(+) create mode 100644 xen/drivers/char/omap-uart.cconfig/arm32.mk +1
-0@@ -11,6 +11,7 @@ CFLAGS += -marm HAS_PL011 := y HAS_EXYNOS4210 := y +HAS_OMAP := y # Use only if calling $(LD) directly. LDFLAGS_DIRECT += -ELxen/drivers/char/Makefile +1
-0@@ -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.oxen/drivers/char/omap-uart.c new file +24
-0@@ -0,0 +1,354 @@ +/* +* omap-uart.c +* Based on drivers/char/ns16550.c +* +* Driver for OMAP-UART controller +* +* Copyright (C) 2013, Chen Baozi <[email protected]> +* +* Note: This driver is made separate from 16550-series UART driver as +* omap platform has some specific configurations +*/ + +#include <xen/config.h> +#include <xen/console.h> +#include <xen/serial.h> +#include <xen/init.h> +#include <xen/irq.h> +#include <asm/early_printk.h> +#include <xen/device_tree.h> +#include <asm/device.h> +#include <xen/errno.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <xen/8250-uart.h>
xen/drivers/char/omap-uart.c line 34
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ +#define REG_SHIFT 2 + +#define omap_read (uart, off) ioreadl((uart)->regs + (off<<REG_SHIFT)) +#define omap_write (uart, off, val) iowritel((uart)->regs + (off<<REG_SHIFT), (val)) + +static struct omap_uart { + u32 baud, clock_hz, data_bits, parity, stop_bits, fifo_size; + struct dt_irq irq; + void __iomem *regs;
I have noticed that I also use void * on the other drivers, but it's a gcc extension
(http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html).
It's better to use unsigned char *.
Quoted 185 lines
xen/drivers/char/omap-uart.c new file +185
-0+struct irqaction irqaction; +} omap_com = {0}; + +static void omap_uart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +{ +struct serial_port *port = data; +struct omap_uart *uart = port->uart; +u32 lsr; + +while ( !(omap_read (uart,UART_IIR ) &UART_IIR_NOINT ) ) + { + lsr =omap_read (uart,UART_LSR ) &0xff ; +if ( lsr &UART_LSR_THRE ) +serial_tx_interrupt (port, regs); +if ( lsr &UART_LSR_DR ) +serial_rx_interrupt (port, regs); + +if ( port->txbufc == port->txbufp ) +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ELSI ); + }; +} + +static void baud_protocol_setup (struct omap_uart *uart) +{ +u32 dll, dlh, efr; +unsigned int divisor; + + divisor = uart->clock_hz / (uart->baud <<4 ); + dll = divisor &0xff ; + dlh = divisor >>8 ; + +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable access to the UART_IER[7:4] bit field. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register operation mode to access the UART_IER register. +*/ +omap_write (uart,UART_LCR ,0 ); +/* +* Clear the UART_IER register (set the UART_IER[4] SLEEP_MODE bit +* to 0 to change the UART_DLL and UART_DLM register). Set the +* UART_IER register value to 0x0000. +*/ +omap_write (uart,UART_IER ,0 ); +/* +* Switch to register configuartion mode B to access the UART_DLL and +* UART_DLM registers. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load divisor value. +*/ +omap_write (uart,UART_DLL , dll); +omap_write (uart,UART_DLM , dlh); +/* +* Restore the UART_OMAP_EFR +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Load the new protocol formatting (parity, stop-bit, character length) +* and switch to register operational mode. +*/ +omap_write (uart,UART_LCR , (uart->data_bits -5 ) | + ((uart->stop_bits -1 ) <<2 ) | uart->parity); +} + +static void fifo_setup (struct omap_uart *uart) +{ +u32 lcr, efr, mcr; +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ + lcr =omap_read (uart,UART_LCR ); +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register +*/ + mcr =omap_read (uart,UART_MCR ); +omap_write (uart,UART_MCR , mcr|UART_MCR_TCRTLR ); +/* +* Enable the FIFO; load the new FIFO trigger and the new DMA mode. +*/ +omap_write (uart,UART_FCR ,UART_FCR_R_TRIG_01 | +UART_FCR_T_TRIG_10 |UART_FCR_ENABLE ); +/* +* Switch to register configuration mode B to access the UART_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load the new FIFO triggers and the new DMA mode bit. +*/ +omap_write (uart,UART_OMAP_SCR ,OMAP_UART_SCR_RX_TRIG_GRANU1_MASK ); +/* +* Restore the UART_OMAP_EFR[4] value. +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Restore UART_MCR[6] value. +*/ +omap_write (uart,UART_MCR , mcr); +/* +* Restore UART_LCR value. +*/ +omap_write (uart,UART_LCR , lcr); + + uart->fifo_size =64 ; +} + +static void __init omap_uart_init_preirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +/* +* Clear the FIFO buffers. +*/ +omap_write (uart,UART_FCR ,UART_FCR_ENABLE ); +omap_write (uart,UART_FCR ,UART_FCR_ENABLE |UART_FCR_CLRX |UART_FCR_CLTX ); +omap_write (uart,UART_FCR ,0 ); + +/* +* The TRM says the mode should be disabled while UART_DLL and UART_DHL +* are being changed so we disable before setup, then enable. +*/ +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_DISABLE ); + +/* Baud rate & protocol format setup */ +baud_protocol_setup (uart); + +/* FIFO setup */ +fifo_setup (uart); + +/* No flow control */ +omap_write (uart,UART_MCR ,UART_MCR_DTR |UART_MCR_RTS ); + +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_16X_MODE ); +} + +static void __init omap_uart_init_postirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + + uart->irqaction.handler = omap_uart_interrupt; + uart->irqaction.name ="omap_uart" ; + uart->irqaction.dev_id = port; + +if (setup_dt_irq (&uart->irq, &uart->irqaction) !=0 ) + { +dprintk (XENLOG_ERR ,"Failed to allocated omap_uart IRQ %d\n" , + uart->irq.irq); +return ; + } + +/* Enable interrupts */ +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI ); +} + +static void omap_uart_suspend (struct serial_port *port) +{ +BUG (); +} +
xen/drivers/char/omap-uart.c line 229
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+static void omap_uart_resume (struct serial_port *port) +{ +BUG (); +} + +static unsigned int omap_uart_tx_ready (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI );
Why do you need to enable unmask interrupt here? Xen is just asking if the UART is ready to transmit another character.
Quoted 36 lines
xen/drivers/char/omap-uart.c new file +36
-0+return omap_read (uart,UART_LSR ) &UART_LSR_THRE ? uart->fifo_size :0 ; +} + +static void omap_uart_putc (struct serial_port *port,char c) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_THR , (uint32_t )(unsigned char )c); +} + +static int omap_uart_getc (struct serial_port *port,char *pc) +{ +struct omap_uart *uart = port->uart; + +if ( !(omap_read (uart,UART_LSR ) &UART_LSR_DR ) ) +return 0 ; + + *pc =omap_read (uart,UART_RBR ) &0xff ; +return 1 ; +} + +static int __init omap_uart_irq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +return ((uart->irq.irq >0 ) ? uart->irq.irq :-1 ); +} + +static const struct dt_irq __init *omap_uart_dt_irq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +return &uart->irq; +} + +static struct uart_driver __read_mostly omap_uart_driver = {
xen/drivers/char/omap-uart.c line 276
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ .init_preirq = omap_uart_init_preirq, + .init_postirq = omap_uart_init_postirq, + .endboot = NULL, + .suspend = omap_uart_suspend, + .resume = omap_uart_resume, + .tx_ready = omap_uart_tx_ready, + .putc = omap_uart_putc, + .getc = omap_uart_getc, + .irq = omap_uart_irq, + .dt_irq_get = omap_uart_dt_irq,
Can you implement vuart_info callback? It's used to partially emulate UART for Linux early printk.
For an example, you can look at xen/drivers/char/exynos4210.c
Quoted 49 lines
xen/drivers/char/omap-uart.c new file +49
-0+}; + +static int __init omap_uart_init (struct dt_device_node *dev, +const void *data) +{ +const char *config = data; +struct omap_uart *uart; +u32 clkspec; +int res; +u64 addr, size; + +if (strcmp (config,"" ) ) +early_printk ("WARNING: UART configuration is not supported\n" ); + + uart = &omap_com; + + res =dt_property_read_u32 (dev,"clock-frequency" , &clkspec); +if ( !res ) + { +early_printk ("omap-uart: Unable to retrieve the clock frequency\n" ); +return -EINVAL ; + } + + uart->clock_hz = clkspec; + uart->baud =115200 ; + uart->data_bits =8 ; + uart->parity =UART_PARITY_NONE ; + uart->stop_bits =1 ; + res =dt_device_get_address (dev,0 , &addr, &size); +if ( res ) + { +early_printk ("omap-uart: Unable to retrieve the base" +" address of the UART\n" ); +return res; + } + + uart->regs =ioremap_attr (addr, size,PAGE_HYPERVISOR_NOCACHE ); +if ( !uart->regs ) + { +early_printk ("omap-uart: Unable to map the UART memory\n" ); +return -ENOMEM ; + } + + res =dt_device_get_irq (dev,0 , &uart->irq); +if ( res ) + { +early_printk ("omap-uart: Unable to retrieve the IRQ\n" ); +return res; + }
xen/drivers/char/omap-uart.c line 336
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ +/* Register with generic serial driver */ +serial_register_uart (SERHND_DTUART , &omap_uart_driver, uart); + +dt_device_set_used_by (dev,DOMID_XEN ); + +return 0 ; +} + +static const char const *omap_uart_dt_compat[] __initdata =
const char * const.
Quoted 95 lines
xen/drivers/char/omap-uart.c new file +18
-0+{ +"ti,omap4-uart" , +NULL +}; + +DT_DEVICE_START (omap_uart,"OMAP UART" ,DEVICE_SERIAL ) + .compatible = omap_uart_dt_compat, + .init = omap_uart_init, +DT_DEVICE_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/xen/8250-uart.h +51
-0@@ -59,14 +59,45 @@#define UART_FCR_TRG8 0x80/* Rx FIFO trig lev 8 */ #define UART_FCR_TRG14 0xc0/* Rx FIFO trig lev 14 */ +/* +* Note: The FIFO trigger levels are chip specific: +* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 +* PC16550D: 1 4 8 14 xx xx xx xx +* TI16C550A: 1 4 8 14 xx xx xx xx +* TI16C550C: 1 4 8 14 xx xx xx xx +* ST16C550: 1 4 8 14 xx xx xx xx +* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 +* NS16C552: 1 4 8 14 xx xx xx xx +* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 +* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 +* TI16C752: 8 16 56 60 8 16 32 56 +* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA +*/ +#define UART_FCR_R_TRIG_00 0x00 +#define UART_FCR_R_TRIG_01 0x40 +#define UART_FCR_R_TRIG_10 0x80 +#define UART_FCR_R_TRIG_11 0xc0 +#define UART_FCR_T_TRIG_00 0x00 +#define UART_FCR_T_TRIG_01 0x10 +#define UART_FCR_T_TRIG_10 0x20 +#define UART_FCR_T_TRIG_11 0x30 +/* Line Control Register */ #define UART_LCR_DLAB 0x80/* Divisor Latch Access */ +/* +* Access to some registers depends on register access / configuration +* mode. +*/ +#define UART_LCR_CONF_MODE_A UART_LCR_DLAB/* Configuration mode A */ +#define UART_LCR_CONF_MODE_B 0xBF/* Configuration mode B */ +/* Modem Control Register */ #define UART_MCR_DTR 0x01/* Data Terminal Ready */ #define UART_MCR_RTS 0x02/* Request to Send */ #define UART_MCR_OUT2 0x08/* OUT2: interrupt mask */ #define UART_MCR_LOOP 0x10/* Enable loopback test mode */ +#define UART_MCR_TCRTLR 0x40/* Access TCR/TLR (TI16C752, EFR[4]=1) */ /* Line Status Register */ #define UART_LSR_DR 0x01/* Data ready */ @@ -92,6 +123,26 @@#define RESUME_DELAY MILLISECS(10)#define RESUME_RETRIES 100 +/* Enhanced feature register */ +#define UART_OMAP_EFR 0x02 + +#define UART_OMAP_EFR_ECB 0x10/* Enhanced control bit */ + +/* Mode definition register 1 */ +#define UART_OMAP_MDR1 0x08 + +/* +* These are the definitions for the MDR1 register +*/ +#define UART_OMAP_MDR1_16X_MODE 0x00/* UART 16x mode */ +#define UART_OMAP_MDR1_DISABLE 0x07/* Disable (default state) */ + +/* Supplementary control register */ +#define UART_OMAP_SCR 0x10 + +/* SCR register bitmasks */ +#define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7) +#endif /* __XEN_8250_UART_H__ */ /*
Signature · 1 line
Julien Grall
Re: [PATCH v6 3/6] xen: Introduce a helper to read a u32 property in device tree.
In reply to Julien GrallQuoted 17 lines · Julien Grall
Quoted 16 lines · Julien Grall
Quoted 1 line · Chen Baozi
Signed-off-by Chen Baozi <[email protected]>Acked-by Julien Grall <[email protected]>Quoted 13 lines
---
xen/common/device_tree.c| 15 +++++++++++++++xen/include/xen/device_tree.h| 11 +++++++++++2 files changed, 26 insertions(+)xen/common/device_tree.c +0
-0@@ -574,6 +574,21 @@ const void *dt_get_property(const struct dt_device_node *np,return pp ? pp->value :NULL ; }
Quoted 13 lines
Quoted 9 lines
xen/common/device_tree.c const void *dt_get_property(const struct dt_device_node *np, · line 585
Quoted 9 lines
xen/common/device_tree.c +9
-0+bool_t 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 >sizeof (*out_value) ) +return 0 ;Hum .. I have just noticed that the check is wrong.
Len must be greater or equal to sizeof (*out_value). Otherwise you can read random bytes.
Oops... I think I mixed up the "len" between linux codes and this.
Thanks for catching it out!
Baozi
Quoted 43 lines
Quoted 38 lines
Quoted 24 lines
xen/common/device_tree.c +6
-0+ + *out_value =be32_to_cpup (val); + +return 1 ; +} +bool_t dt_device_is_compatible (const struct dt_device_node *device,const char *compat) {xen/include/xen/device_tree.h +4
-0@@ -300,6 +300,17 @@ 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. +* @np: node to get the value +* @name: name of the property +* @out_value: pointer to return value xen/include/xen/device_tree.h const void *dt_get_property(const struct dt_device_node *np, · line 316
Quoted 10 lines
xen/include/xen/device_tree.h +7
-0+* +* Return true if get the desired value. +*/ +bool_t 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 */ --
Julien GrallSignature · 1 line
Julien Grall
Re: [PATCH v6 2/6] xen/arm: add 8250 compatible UART support for early_printk
In reply to Julien GrallQuoted 43 lines · Julien Grall
Quoted 42 lines · Chen Baozi
Both OMAP5 and sun6i/sun7i SoCs share this UART driver for
early_printk.Signed-off-by Chen Baozi <[email protected]>---
docs/misc/arm/early-printk.txt | 3 +++ xen/arch/arm/Rules.mk | 16 +++++++++++++++ xen/arch/arm/arm32/debug-8250.inc | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+)create mode 100644 xen/arch/arm/arm32/debug-8250.inc
docs/misc/arm/early-printk.txt +3
-0@@ -13,6 +13,9 @@ 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 + - sun7i: printk with 8250 on Allwinner A20 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 +0
-0@@ -64,6 +64,21 @@ EARLY_PRINTK_INC := pl011
EARLY_PRINTK_BAUD:= 115200EARLY_UART_BASE_ADDRESS:=0xfff36000
endifxen/arch/arm/Rules.mk +10
-0+ifeq ($(CONFIG_EARLY_PRINTK), omap5432) +EARLY_PRINTK_INC := 8250 +EARLY_UART_BASE_ADDRESS := 0x48020000 +EARLY_UART_REG_SHIFT := 2 +endif +ifeq ($(CONFIG_EARLY_PRINTK), sun6i) +EARLY_PRINTK_INC := 8250 +EARLY_UART_BASE_ADDRESS := 0x01c28000 +EARLY_UART_REG_SHIFT := 2 +endif
Quoted 8 lines
xen/arch/arm/Rules.mk EARLY_PRINTK_INC := pl011 · line 81
Quoted 5 lines
xen/arch/arm/Rules.mk +5
-0+ifeq ($(CONFIG_EARLY_PRINTK), sun7i) +EARLY_PRINTK_INC := 8250 +EARLY_UART_BASE_ADDRESS := 0x01c28000 +EARLY_UART_REG_SHIFT := 2 +endifIf the shift is the same for all UART based on 8250, you can simply define
EARLY_UART_... in debug-8250.inc.
Though the shifts are all 2 so far, I cannot make sure that all UART based on 8250 are the same, considering the original 8250 doesn't need the shift...
Quoted 61 lines
Quoted 57 lines
ifneq ($(EARLY_PRINTK_INC),)
EARLY_PRINTK:= yxen/arch/arm/Rules.mk +0
-0@@ -74,4 +89,5 @@ CFLAGS-$(EARLY_PRINTK_INIT_UART) += -DEARLY_PRINTK_INIT_UARTCFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_INC=\"debug-$(EARLY_PRINTK_INC).inc\" CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_BAUD=$(EARLY_PRINTK_BAUD) CFLAGS-$(EARLY_PRINTK) += -DEARLY_UART_BASE_ADDRESS=$(EARLY_UART_BASE_ADDRESS) +CFLAGS-$(EARLY_PRINTK) += -DEARLY_UART_REG_SHIFT=$(EARLY_UART_REG_SHIFT) endif
xen/arch/arm/arm32/debug-8250.inc new file +41
-0@@ -0,0 +1,41 @@ +/* + * xen/arch/arm/arm32/debug-8250.inc + * + * 8250 specific debug code + * + * 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/8250-uart.h> + +/* 8250 UART wait UART to be ready to transmit + * rb: register which contains the UART base address + * rc: scratch register */ +.macro early_uart_ready rb rc +1: + ldr \rc, [\rb, #(UART_LSR << EARLY_UART_REG_SHIFT)] /* Read LSR */ + tst \rc, #UART_LSR_THRE /* Check Xmit holding register flag */ + beq 1b /* Wait for the UART to be ready */ +.endm + +/* 8250 UART transmit character + * rb: register which contains the UART base address + * rt: register which contains the character to transmit */ +.macro early_uart_transmit rb rt + str \rt, [\rb, #UART_THR] /* Write Transmit buffer */ +.endm + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */Signature · 1 line
Julien Grall
Re: [PATCH v6 4/6] xen/arm: Add the new OMAP UART driver.
In reply to Julien GrallQuoted 274 lines · Julien Grall
Quoted 67 lines · 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.
Signed-off-by Chen Baozi <[email protected]>---
config/arm32.mk | 1 + xen/drivers/char/Makefile | 1 + xen/drivers/char/omap-uart.c | 354 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/8250-uart.h | 51 +++++++ 4 files changed, 407 insertions(+)create mode 100644
xen/drivers/char/omap-uart.cconfig/arm32.mk +0
-0@@ -11,6 +11,7 @@ CFLAGS += -marm
HAS_PL011:= yHAS_EXYNOS4210:= y
+HAS_OMAP := y# Use only if calling $(LD) directly.
LDFLAGS_DIRECT+= -ELxen/drivers/char/Makefile +0
-0@@ -2,6 +2,7 @@ obj-y += console.oobj-$(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.oxen/drivers/char/omap-uart.c new file +24
-0@@ -0,0 +1,354 @@ +/* +* omap-uart.c +* Based on drivers/char/ns16550.c +* +* Driver for OMAP-UART controller +* +* Copyright (C) 2013, Chen Baozi <[email protected]> +* +* Note: This driver is made separate from 16550-series UART driver as +* omap platform has some specific configurations +*/ + +#include <xen/config.h> +#include <xen/console.h> +#include <xen/serial.h> +#include <xen/init.h> +#include <xen/irq.h> +#include <asm/early_printk.h> +#include <xen/device_tree.h> +#include <asm/device.h> +#include <xen/errno.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <xen/8250-uart.h> xen/drivers/char/omap-uart.c line 34
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ +#define REG_SHIFT 2 + +#define omap_read (uart, off) ioreadl((uart)->regs + (off<<REG_SHIFT)) +#define omap_write (uart, off, val) iowritel((uart)->regs + (off<<REG_SHIFT), (val)) + +static struct omap_uart { + u32 baud, clock_hz, data_bits, parity, stop_bits, fifo_size; + struct dt_irq irq; + void __iomem *regs;I have noticed that I also use void * on the other drivers, but it's a gcc extension
(http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html).
It's better to use unsigned char *.Quoted 190 lines
xen/drivers/char/omap-uart.c new file +190
-0+struct irqaction irqaction; +} omap_com = {0}; + +static void omap_uart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +{ +struct serial_port *port = data; +struct omap_uart *uart = port->uart; +u32 lsr; + +while ( !(omap_read (uart,UART_IIR ) &UART_IIR_NOINT ) ) + { + lsr =omap_read (uart,UART_LSR ) &0xff ; +if ( lsr &UART_LSR_THRE ) +serial_tx_interrupt (port, regs); +if ( lsr &UART_LSR_DR ) +serial_rx_interrupt (port, regs); + +if ( port->txbufc == port->txbufp ) +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ELSI ); + }; +} + +static void baud_protocol_setup (struct omap_uart *uart) +{ +u32 dll, dlh, efr; +unsigned int divisor; + + divisor = uart->clock_hz / (uart->baud <<4 ); + dll = divisor &0xff ; + dlh = divisor >>8 ; + +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable access to the UART_IER[7:4] bit field. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register operation mode to access the UART_IER register. +*/ +omap_write (uart,UART_LCR ,0 ); +/* +* Clear the UART_IER register (set the UART_IER[4] SLEEP_MODE bit +* to 0 to change the UART_DLL and UART_DLM register). Set the +* UART_IER register value to 0x0000. +*/ +omap_write (uart,UART_IER ,0 ); +/* +* Switch to register configuartion mode B to access the UART_DLL and +* UART_DLM registers. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load divisor value. +*/ +omap_write (uart,UART_DLL , dll); +omap_write (uart,UART_DLM , dlh); +/* +* Restore the UART_OMAP_EFR +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Load the new protocol formatting (parity, stop-bit, character length) +* and switch to register operational mode. +*/ +omap_write (uart,UART_LCR , (uart->data_bits -5 ) | + ((uart->stop_bits -1 ) <<2 ) | uart->parity); +} + +static void fifo_setup (struct omap_uart *uart) +{ +u32 lcr, efr, mcr; +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ + lcr =omap_read (uart,UART_LCR ); +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register +*/ + mcr =omap_read (uart,UART_MCR ); +omap_write (uart,UART_MCR , mcr|UART_MCR_TCRTLR ); +/* +* Enable the FIFO; load the new FIFO trigger and the new DMA mode. +*/ +omap_write (uart,UART_FCR ,UART_FCR_R_TRIG_01 | +UART_FCR_T_TRIG_10 |UART_FCR_ENABLE ); +/* +* Switch to register configuration mode B to access the UART_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load the new FIFO triggers and the new DMA mode bit. +*/ +omap_write (uart,UART_OMAP_SCR ,OMAP_UART_SCR_RX_TRIG_GRANU1_MASK ); +/* +* Restore the UART_OMAP_EFR[4] value. +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Restore UART_MCR[6] value. +*/ +omap_write (uart,UART_MCR , mcr); +/* +* Restore UART_LCR value. +*/ +omap_write (uart,UART_LCR , lcr); + + uart->fifo_size =64 ; +} + +static void __init omap_uart_init_preirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +/* +* Clear the FIFO buffers. +*/ +omap_write (uart,UART_FCR ,UART_FCR_ENABLE ); +omap_write (uart,UART_FCR ,UART_FCR_ENABLE |UART_FCR_CLRX |UART_FCR_CLTX ); +omap_write (uart,UART_FCR ,0 ); + +/* +* The TRM says the mode should be disabled while UART_DLL and UART_DHL +* are being changed so we disable before setup, then enable. +*/ +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_DISABLE ); + +/* Baud rate & protocol format setup */ +baud_protocol_setup (uart); + +/* FIFO setup */ +fifo_setup (uart); + +/* No flow control */ +omap_write (uart,UART_MCR ,UART_MCR_DTR |UART_MCR_RTS ); + +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_16X_MODE ); +} + +static void __init omap_uart_init_postirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + + uart->irqaction.handler = omap_uart_interrupt; + uart->irqaction.name ="omap_uart" ; + uart->irqaction.dev_id = port; + +if (setup_dt_irq (&uart->irq, &uart->irqaction) !=0 ) + { +dprintk (XENLOG_ERR ,"Failed to allocated omap_uart IRQ %d\n" , + uart->irq.irq); +return ; + } + +/* Enable interrupts */ +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI ); +} + +static void omap_uart_suspend (struct serial_port *port) +{ +BUG (); +} + +static void omap_uart_resume (struct serial_port *port) +{ +BUG (); +} +
Quoted 8 lines
xen/drivers/char/omap-uart.c line 229
Quoted 5 lines
xen/drivers/char/omap-uart.c new file +5
-0+static unsigned int omap_uart_tx_ready (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI );Why do you need to enable unmask interrupt here? Xen is just asking if the UART is ready to transmit another character.
Well, it is because we need to mask THRE interrupt after tx completes and unmake it once it starts to tx. This is one of main differences between OMAP UART and common 8250, since the THRE interrupt won't be cleared by writing to THR or reading IIR in OMAP UART.
In Linux, there are .start_tx and .stop_tx callbacks for UART driver. Since we don't have that mechanism on Xen, I added it here.
Quoted 105 lines
Quoted 37 lines
xen/drivers/char/omap-uart.c new file +36
-0+return omap_read (uart,UART_LSR ) &UART_LSR_THRE ? uart->fifo_size :0 ; +} + +static void omap_uart_putc (struct serial_port *port,char c) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_THR , (uint32_t )(unsigned char )c); +} + +static int omap_uart_getc (struct serial_port *port,char *pc) +{ +struct omap_uart *uart = port->uart; + +if ( !(omap_read (uart,UART_LSR ) &UART_LSR_DR ) ) +return 0 ; + + *pc =omap_read (uart,UART_RBR ) &0xff ; +return 1 ; +} + +static int __init omap_uart_irq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +return ((uart->irq.irq >0 ) ? uart->irq.irq :-1 ); +} + +static const struct dt_irq __init *omap_uart_dt_irq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +return &uart->irq; +} + +static struct uart_driver __read_mostly omap_uart_driver = {xen/drivers/char/omap-uart.c line 276
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ .init_preirq = omap_uart_init_preirq, + .init_postirq = omap_uart_init_postirq, + .endboot = NULL, + .suspend = omap_uart_suspend, + .resume = omap_uart_resume, + .tx_ready = omap_uart_tx_ready, + .putc = omap_uart_putc, + .getc = omap_uart_getc, + .irq = omap_uart_irq, + .dt_irq_get = omap_uart_dt_irq,Can you implement
vuart_infocallback? It's used to partially emulate UART for Linux early printk.For an example, you can look at
xen/drivers/char/exynos4210.cQuoted 53 lines
xen/drivers/char/omap-uart.c new file +53
-0+}; + +static int __init omap_uart_init (struct dt_device_node *dev, +const void *data) +{ +const char *config = data; +struct omap_uart *uart; +u32 clkspec; +int res; +u64 addr, size; + +if (strcmp (config,"" ) ) +early_printk ("WARNING: UART configuration is not supported\n" ); + + uart = &omap_com; + + res =dt_property_read_u32 (dev,"clock-frequency" , &clkspec); +if ( !res ) + { +early_printk ("omap-uart: Unable to retrieve the clock frequency\n" ); +return -EINVAL ; + } + + uart->clock_hz = clkspec; + uart->baud =115200 ; + uart->data_bits =8 ; + uart->parity =UART_PARITY_NONE ; + uart->stop_bits =1 ; + res =dt_device_get_address (dev,0 , &addr, &size); +if ( res ) + { +early_printk ("omap-uart: Unable to retrieve the base" +" address of the UART\n" ); +return res; + } + + uart->regs =ioremap_attr (addr, size,PAGE_HYPERVISOR_NOCACHE ); +if ( !uart->regs ) + { +early_printk ("omap-uart: Unable to map the UART memory\n" ); +return -ENOMEM ; + } + + res =dt_device_get_irq (dev,0 , &uart->irq); +if ( res ) + { +early_printk ("omap-uart: Unable to retrieve the IRQ\n" ); +return res; + } + +/* Register with generic serial driver */ +serial_register_uart (SERHND_DTUART , &omap_uart_driver, uart); +
Quoted 8 lines
xen/drivers/char/omap-uart.c line 336
Quoted 6 lines
xen/drivers/char/omap-uart.c new file +6
-0+dt_device_set_used_by (dev,DOMID_XEN ); + +return 0 ; +} + +static const char const *omap_uart_dt_compat[] __initdata =const char * const.
Hmmm, I just followed exynos4210-uart.c and pl011.c here...
Quoted 99 lines
Quoted 96 lines
xen/drivers/char/omap-uart.c new file +18
-0+{ +"ti,omap4-uart" , +NULL +}; + +DT_DEVICE_START (omap_uart,"OMAP UART" ,DEVICE_SERIAL ) + .compatible = omap_uart_dt_compat, + .init = omap_uart_init, +DT_DEVICE_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/xen/8250-uart.h +51
-0@@ -59,14 +59,45 @@#define UART_FCR_TRG8 0x80/* Rx FIFO trig lev 8 */ #define UART_FCR_TRG14 0xc0/* Rx FIFO trig lev 14 */ +/* +* Note: The FIFO trigger levels are chip specific: +* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 +* PC16550D: 1 4 8 14 xx xx xx xx +* TI16C550A: 1 4 8 14 xx xx xx xx +* TI16C550C: 1 4 8 14 xx xx xx xx +* ST16C550: 1 4 8 14 xx xx xx xx +* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 +* NS16C552: 1 4 8 14 xx xx xx xx +* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 +* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 +* TI16C752: 8 16 56 60 8 16 32 56 +* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA +*/ +#define UART_FCR_R_TRIG_00 0x00 +#define UART_FCR_R_TRIG_01 0x40 +#define UART_FCR_R_TRIG_10 0x80 +#define UART_FCR_R_TRIG_11 0xc0 +#define UART_FCR_T_TRIG_00 0x00 +#define UART_FCR_T_TRIG_01 0x10 +#define UART_FCR_T_TRIG_10 0x20 +#define UART_FCR_T_TRIG_11 0x30 +/* Line Control Register */ #define UART_LCR_DLAB 0x80/* Divisor Latch Access */ +/* +* Access to some registers depends on register access / configuration +* mode. +*/ +#define UART_LCR_CONF_MODE_A UART_LCR_DLAB/* Configuration mode A */ +#define UART_LCR_CONF_MODE_B 0xBF/* Configuration mode B */ +/* Modem Control Register */ #define UART_MCR_DTR 0x01/* Data Terminal Ready */ #define UART_MCR_RTS 0x02/* Request to Send */ #define UART_MCR_OUT2 0x08/* OUT2: interrupt mask */ #define UART_MCR_LOOP 0x10/* Enable loopback test mode */ +#define UART_MCR_TCRTLR 0x40/* Access TCR/TLR (TI16C752, EFR[4]=1) */ /* Line Status Register */ #define UART_LSR_DR 0x01/* Data ready */ @@ -92,6 +123,26 @@#define RESUME_DELAY MILLISECS(10)#define RESUME_RETRIES 100 +/* Enhanced feature register */ +#define UART_OMAP_EFR 0x02 + +#define UART_OMAP_EFR_ECB 0x10/* Enhanced control bit */ + +/* Mode definition register 1 */ +#define UART_OMAP_MDR1 0x08 + +/* +* These are the definitions for the MDR1 register +*/ +#define UART_OMAP_MDR1_16X_MODE 0x00/* UART 16x mode */ +#define UART_OMAP_MDR1_DISABLE 0x07/* Disable (default state) */ + +/* Supplementary control register */ +#define UART_OMAP_SCR 0x10 + +/* SCR register bitmasks */ +#define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7) +#endif /* __XEN_8250_UART_H__ */ /* Signature · 1 line
Julien Grall
Re: [PATCH v6 4/6] xen/arm: Add the new OMAP UART driver.
In reply to Julien GrallQuoted 332 lines · Julien Grall
Quoted 67 lines · 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.
Signed-off-by Chen Baozi <[email protected]>--- config/arm32.mk | 1 + xen/drivers/char/Makefile | 1 + xen/drivers/char/omap-uart.c | 354 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/8250-uart.h | 51 +++++++ 4 files changed, 407 insertions(+) create mode 100644 xen/drivers/char/omap-uart.cconfig/arm32.mk +1
-0@@ -11,6 +11,7 @@ CFLAGS += -marm HAS_PL011 := y HAS_EXYNOS4210 := y +HAS_OMAP := y # Use only if calling $(LD) directly. LDFLAGS_DIRECT += -ELxen/drivers/char/Makefile +1
-0@@ -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.oxen/drivers/char/omap-uart.c new file +24
-0@@ -0,0 +1,354 @@ +/* +* omap-uart.c +* Based on drivers/char/ns16550.c +* +* Driver for OMAP-UART controller +* +* Copyright (C) 2013, Chen Baozi <[email protected]> +* +* Note: This driver is made separate from 16550-series UART driver as +* omap platform has some specific configurations +*/ + +#include <xen/config.h> +#include <xen/console.h> +#include <xen/serial.h> +#include <xen/init.h> +#include <xen/irq.h> +#include <asm/early_printk.h> +#include <xen/device_tree.h> +#include <asm/device.h> +#include <xen/errno.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <xen/8250-uart.h> xen/drivers/char/omap-uart.c line 34
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ +#define REG_SHIFT 2 + +#define omap_read (uart, off) ioreadl((uart)->regs + (off<<REG_SHIFT)) +#define omap_write (uart, off, val) iowritel((uart)->regs + (off<<REG_SHIFT), (val)) + +static struct omap_uart { + u32 baud, clock_hz, data_bits, parity, stop_bits, fifo_size; + struct dt_irq irq; + void __iomem *regs;I have noticed that I also use void * on the other drivers, but it's a gcc extension
(http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html).
It's better to use unsigned char *.Quoted 185 lines
xen/drivers/char/omap-uart.c new file +185
-0+struct irqaction irqaction; +} omap_com = {0}; + +static void omap_uart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +{ +struct serial_port *port = data; +struct omap_uart *uart = port->uart; +u32 lsr; + +while ( !(omap_read (uart,UART_IIR ) &UART_IIR_NOINT ) ) + { + lsr =omap_read (uart,UART_LSR ) &0xff ; +if ( lsr &UART_LSR_THRE ) +serial_tx_interrupt (port, regs); +if ( lsr &UART_LSR_DR ) +serial_rx_interrupt (port, regs); + +if ( port->txbufc == port->txbufp ) +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ELSI ); + }; +} + +static void baud_protocol_setup (struct omap_uart *uart) +{ +u32 dll, dlh, efr; +unsigned int divisor; + + divisor = uart->clock_hz / (uart->baud <<4 ); + dll = divisor &0xff ; + dlh = divisor >>8 ; + +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable access to the UART_IER[7:4] bit field. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register operation mode to access the UART_IER register. +*/ +omap_write (uart,UART_LCR ,0 ); +/* +* Clear the UART_IER register (set the UART_IER[4] SLEEP_MODE bit +* to 0 to change the UART_DLL and UART_DLM register). Set the +* UART_IER register value to 0x0000. +*/ +omap_write (uart,UART_IER ,0 ); +/* +* Switch to register configuartion mode B to access the UART_DLL and +* UART_DLM registers. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load divisor value. +*/ +omap_write (uart,UART_DLL , dll); +omap_write (uart,UART_DLM , dlh); +/* +* Restore the UART_OMAP_EFR +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Load the new protocol formatting (parity, stop-bit, character length) +* and switch to register operational mode. +*/ +omap_write (uart,UART_LCR , (uart->data_bits -5 ) | + ((uart->stop_bits -1 ) <<2 ) | uart->parity); +} + +static void fifo_setup (struct omap_uart *uart) +{ +u32 lcr, efr, mcr; +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ + lcr =omap_read (uart,UART_LCR ); +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register +*/ + mcr =omap_read (uart,UART_MCR ); +omap_write (uart,UART_MCR , mcr|UART_MCR_TCRTLR ); +/* +* Enable the FIFO; load the new FIFO trigger and the new DMA mode. +*/ +omap_write (uart,UART_FCR ,UART_FCR_R_TRIG_01 | +UART_FCR_T_TRIG_10 |UART_FCR_ENABLE ); +/* +* Switch to register configuration mode B to access the UART_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load the new FIFO triggers and the new DMA mode bit. +*/ +omap_write (uart,UART_OMAP_SCR ,OMAP_UART_SCR_RX_TRIG_GRANU1_MASK ); +/* +* Restore the UART_OMAP_EFR[4] value. +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Restore UART_MCR[6] value. +*/ +omap_write (uart,UART_MCR , mcr); +/* +* Restore UART_LCR value. +*/ +omap_write (uart,UART_LCR , lcr); + + uart->fifo_size =64 ; +} + +static void __init omap_uart_init_preirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +/* +* Clear the FIFO buffers. +*/ +omap_write (uart,UART_FCR ,UART_FCR_ENABLE ); +omap_write (uart,UART_FCR ,UART_FCR_ENABLE |UART_FCR_CLRX |UART_FCR_CLTX ); +omap_write (uart,UART_FCR ,0 ); + +/* +* The TRM says the mode should be disabled while UART_DLL and UART_DHL +* are being changed so we disable before setup, then enable. +*/ +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_DISABLE ); + +/* Baud rate & protocol format setup */ +baud_protocol_setup (uart); + +/* FIFO setup */ +fifo_setup (uart); + +/* No flow control */ +omap_write (uart,UART_MCR ,UART_MCR_DTR |UART_MCR_RTS ); + +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_16X_MODE ); +} + +static void __init omap_uart_init_postirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + + uart->irqaction.handler = omap_uart_interrupt; + uart->irqaction.name ="omap_uart" ; + uart->irqaction.dev_id = port; + +if (setup_dt_irq (&uart->irq, &uart->irqaction) !=0 ) + { +dprintk (XENLOG_ERR ,"Failed to allocated omap_uart IRQ %d\n" , + uart->irq.irq); +return ; + } + +/* Enable interrupts */ +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI ); +} + +static void omap_uart_suspend (struct serial_port *port) +{ +BUG (); +} +xen/drivers/char/omap-uart.c line 229
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+static void omap_uart_resume (struct serial_port *port) +{ +BUG (); +} + +static unsigned int omap_uart_tx_ready (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI );Why do you need to enable unmask interrupt here? Xen is just asking if the UART is ready to transmit another character.
Quoted 36 lines
xen/drivers/char/omap-uart.c new file +36
-0+return omap_read (uart,UART_LSR ) &UART_LSR_THRE ? uart->fifo_size :0 ; +} + +static void omap_uart_putc (struct serial_port *port,char c) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_THR , (uint32_t )(unsigned char )c); +} + +static int omap_uart_getc (struct serial_port *port,char *pc) +{ +struct omap_uart *uart = port->uart; + +if ( !(omap_read (uart,UART_LSR ) &UART_LSR_DR ) ) +return 0 ; + + *pc =omap_read (uart,UART_RBR ) &0xff ; +return 1 ; +} + +static int __init omap_uart_irq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +return ((uart->irq.irq >0 ) ? uart->irq.irq :-1 ); +} + +static const struct dt_irq __init *omap_uart_dt_irq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +return &uart->irq; +} + +static struct uart_driver __read_mostly omap_uart_driver = {xen/drivers/char/omap-uart.c line 276
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ .init_preirq = omap_uart_init_preirq, + .init_postirq = omap_uart_init_postirq, + .endboot = NULL, + .suspend = omap_uart_suspend, + .resume = omap_uart_resume, + .tx_ready = omap_uart_tx_ready, + .putc = omap_uart_putc, + .getc = omap_uart_getc, + .irq = omap_uart_irq, + .dt_irq_get = omap_uart_dt_irq,Can you implement
vuart_infocallback? It's used to partially emulate UART for Linux early printk.
Quoted 1 line
For an example, you can look at
xen/drivers/char/exynos4210.c
I rebased my tree to the latest master branch to get the vuart_info. However, after rebasing to the master, I cannot build xen successfully. It would always failed building with the message:
arm-linux-gnueabihf-gcc -O1 -fno-omit-frame-pointer -marm -g -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable
-Wno-unused-local-typedefs -fno-builtin -fno-common -Wredundant-decls
-iwithprefix include -Werror -Wno-pointer-arith -pipe -I/home/cbz/src/xen/xen/include -fno-stack-protector -fno-exceptions -Wnested-externs -msoft-float -mcpu=cortex-a15 -DGCC_HAS_VISIBILITY_ATTRIBUTE -fno-optimize-sibling-calls -DEARLY_PRINTK -DEARLY_PRINTK_INC=\"debug-8250.inc\" -DEARLY_PRINTK_BAUD= -DEARLY_UART_BASE_ADDRESS=0x48020000 -DEARLY_UART_REG_SHIFT=2 -g -D__XEN__ -include /home/cbz/src/xen/xen/include/xen/config.h -DVERBOSE -fno-omit-frame-pointer -DCONFIG_FRAME_POINTER -MMD -MF .cpu.o.d -c cpu.c -o cpu.o
make[4]: *** No rule to make target vpl011.h', needed by domain.o'. Stop. make[4]: Leaving directory /home/cbz/src/xen/xen/arch/arm' make[3]: *** [/home/cbz/src/xen/xen/arch/arm/built_in.o] Error 2 make[3]: Leaving directory /home/cbz/src/xen/xen/arch/arm' make[2]: *** [/home/cbz/src/xen/xen/xen] Error 2
make[2]: Leaving directory `/home/cbz/src/xen/xen'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/home/cbz/src/xen/xen'
make: *** [install-xen] Error 2
Quoted 161 lines
Quoted 50 lines
xen/drivers/char/omap-uart.c new file +49
-0+}; + +static int __init omap_uart_init (struct dt_device_node *dev, +const void *data) +{ +const char *config = data; +struct omap_uart *uart; +u32 clkspec; +int res; +u64 addr, size; + +if (strcmp (config,"" ) ) +early_printk ("WARNING: UART configuration is not supported\n" ); + + uart = &omap_com; + + res =dt_property_read_u32 (dev,"clock-frequency" , &clkspec); +if ( !res ) + { +early_printk ("omap-uart: Unable to retrieve the clock frequency\n" ); +return -EINVAL ; + } + + uart->clock_hz = clkspec; + uart->baud =115200 ; + uart->data_bits =8 ; + uart->parity =UART_PARITY_NONE ; + uart->stop_bits =1 ; + res =dt_device_get_address (dev,0 , &addr, &size); +if ( res ) + { +early_printk ("omap-uart: Unable to retrieve the base" +" address of the UART\n" ); +return res; + } + + uart->regs =ioremap_attr (addr, size,PAGE_HYPERVISOR_NOCACHE ); +if ( !uart->regs ) + { +early_printk ("omap-uart: Unable to map the UART memory\n" ); +return -ENOMEM ; + } + + res =dt_device_get_irq (dev,0 , &uart->irq); +if ( res ) + { +early_printk ("omap-uart: Unable to retrieve the IRQ\n" ); +return res; + }xen/drivers/char/omap-uart.c line 336
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ +/* Register with generic serial driver */ +serial_register_uart (SERHND_DTUART , &omap_uart_driver, uart); + +dt_device_set_used_by (dev,DOMID_XEN ); + +return 0 ; +} + +static const char const *omap_uart_dt_compat[] __initdata =const char * const.
Quoted 95 lines
xen/drivers/char/omap-uart.c new file +18
-0+{ +"ti,omap4-uart" , +NULL +}; + +DT_DEVICE_START (omap_uart,"OMAP UART" ,DEVICE_SERIAL ) + .compatible = omap_uart_dt_compat, + .init = omap_uart_init, +DT_DEVICE_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/xen/8250-uart.h +51
-0@@ -59,14 +59,45 @@#define UART_FCR_TRG8 0x80/* Rx FIFO trig lev 8 */ #define UART_FCR_TRG14 0xc0/* Rx FIFO trig lev 14 */ +/* +* Note: The FIFO trigger levels are chip specific: +* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 +* PC16550D: 1 4 8 14 xx xx xx xx +* TI16C550A: 1 4 8 14 xx xx xx xx +* TI16C550C: 1 4 8 14 xx xx xx xx +* ST16C550: 1 4 8 14 xx xx xx xx +* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 +* NS16C552: 1 4 8 14 xx xx xx xx +* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 +* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 +* TI16C752: 8 16 56 60 8 16 32 56 +* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA +*/ +#define UART_FCR_R_TRIG_00 0x00 +#define UART_FCR_R_TRIG_01 0x40 +#define UART_FCR_R_TRIG_10 0x80 +#define UART_FCR_R_TRIG_11 0xc0 +#define UART_FCR_T_TRIG_00 0x00 +#define UART_FCR_T_TRIG_01 0x10 +#define UART_FCR_T_TRIG_10 0x20 +#define UART_FCR_T_TRIG_11 0x30 +/* Line Control Register */ #define UART_LCR_DLAB 0x80/* Divisor Latch Access */ +/* +* Access to some registers depends on register access / configuration +* mode. +*/ +#define UART_LCR_CONF_MODE_A UART_LCR_DLAB/* Configuration mode A */ +#define UART_LCR_CONF_MODE_B 0xBF/* Configuration mode B */ +/* Modem Control Register */ #define UART_MCR_DTR 0x01/* Data Terminal Ready */ #define UART_MCR_RTS 0x02/* Request to Send */ #define UART_MCR_OUT2 0x08/* OUT2: interrupt mask */ #define UART_MCR_LOOP 0x10/* Enable loopback test mode */ +#define UART_MCR_TCRTLR 0x40/* Access TCR/TLR (TI16C752, EFR[4]=1) */ /* Line Status Register */ #define UART_LSR_DR 0x01/* Data ready */ @@ -92,6 +123,26 @@#define RESUME_DELAY MILLISECS(10)#define RESUME_RETRIES 100 +/* Enhanced feature register */ +#define UART_OMAP_EFR 0x02 + +#define UART_OMAP_EFR_ECB 0x10/* Enhanced control bit */ + +/* Mode definition register 1 */ +#define UART_OMAP_MDR1 0x08 + +/* +* These are the definitions for the MDR1 register +*/ +#define UART_OMAP_MDR1_16X_MODE 0x00/* UART 16x mode */ +#define UART_OMAP_MDR1_DISABLE 0x07/* Disable (default state) */ + +/* Supplementary control register */ +#define UART_OMAP_SCR 0x10 + +/* SCR register bitmasks */ +#define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7) +#endif /* __XEN_8250_UART_H__ */ /* Signature · 1 line
Julien Grall
Re: [PATCH v6 4/6] xen/arm: Add the new OMAP UART driver.
Quoted 354 lines · Chen Baozi
Quoted 332 lines · Julien Grall
Quoted 67 lines · 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.
Signed-off-by Chen Baozi <[email protected]>--- config/arm32.mk | 1 + xen/drivers/char/Makefile | 1 + xen/drivers/char/omap-uart.c | 354 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/8250-uart.h | 51 +++++++ 4 files changed, 407 insertions(+) create mode 100644 xen/drivers/char/omap-uart.cconfig/arm32.mk +1
-0@@ -11,6 +11,7 @@ CFLAGS += -marm HAS_PL011 := y HAS_EXYNOS4210 := y +HAS_OMAP := y # Use only if calling $(LD) directly. LDFLAGS_DIRECT += -ELxen/drivers/char/Makefile +1
-0@@ -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.oxen/drivers/char/omap-uart.c new file +24
-0@@ -0,0 +1,354 @@ +/* +* omap-uart.c +* Based on drivers/char/ns16550.c +* +* Driver for OMAP-UART controller +* +* Copyright (C) 2013, Chen Baozi <[email protected]> +* +* Note: This driver is made separate from 16550-series UART driver as +* omap platform has some specific configurations +*/ + +#include <xen/config.h> +#include <xen/console.h> +#include <xen/serial.h> +#include <xen/init.h> +#include <xen/irq.h> +#include <asm/early_printk.h> +#include <xen/device_tree.h> +#include <asm/device.h> +#include <xen/errno.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <xen/8250-uart.h> xen/drivers/char/omap-uart.c line 34
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ +#define REG_SHIFT 2 + +#define omap_read (uart, off) ioreadl((uart)->regs + (off<<REG_SHIFT)) +#define omap_write (uart, off, val) iowritel((uart)->regs + (off<<REG_SHIFT), (val)) + +static struct omap_uart { + u32 baud, clock_hz, data_bits, parity, stop_bits, fifo_size; + struct dt_irq irq; + void __iomem *regs;I have noticed that I also use void * on the other drivers, but it's a gcc extension
(http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html).
It's better to use unsigned char *.Quoted 185 lines
xen/drivers/char/omap-uart.c new file +185
-0+struct irqaction irqaction; +} omap_com = {0}; + +static void omap_uart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +{ +struct serial_port *port = data; +struct omap_uart *uart = port->uart; +u32 lsr; + +while ( !(omap_read (uart,UART_IIR ) &UART_IIR_NOINT ) ) + { + lsr =omap_read (uart,UART_LSR ) &0xff ; +if ( lsr &UART_LSR_THRE ) +serial_tx_interrupt (port, regs); +if ( lsr &UART_LSR_DR ) +serial_rx_interrupt (port, regs); + +if ( port->txbufc == port->txbufp ) +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ELSI ); + }; +} + +static void baud_protocol_setup (struct omap_uart *uart) +{ +u32 dll, dlh, efr; +unsigned int divisor; + + divisor = uart->clock_hz / (uart->baud <<4 ); + dll = divisor &0xff ; + dlh = divisor >>8 ; + +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable access to the UART_IER[7:4] bit field. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register operation mode to access the UART_IER register. +*/ +omap_write (uart,UART_LCR ,0 ); +/* +* Clear the UART_IER register (set the UART_IER[4] SLEEP_MODE bit +* to 0 to change the UART_DLL and UART_DLM register). Set the +* UART_IER register value to 0x0000. +*/ +omap_write (uart,UART_IER ,0 ); +/* +* Switch to register configuartion mode B to access the UART_DLL and +* UART_DLM registers. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load divisor value. +*/ +omap_write (uart,UART_DLL , dll); +omap_write (uart,UART_DLM , dlh); +/* +* Restore the UART_OMAP_EFR +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Load the new protocol formatting (parity, stop-bit, character length) +* and switch to register operational mode. +*/ +omap_write (uart,UART_LCR , (uart->data_bits -5 ) | + ((uart->stop_bits -1 ) <<2 ) | uart->parity); +} + +static void fifo_setup (struct omap_uart *uart) +{ +u32 lcr, efr, mcr; +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ + lcr =omap_read (uart,UART_LCR ); +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register +*/ + mcr =omap_read (uart,UART_MCR ); +omap_write (uart,UART_MCR , mcr|UART_MCR_TCRTLR ); +/* +* Enable the FIFO; load the new FIFO trigger and the new DMA mode. +*/ +omap_write (uart,UART_FCR ,UART_FCR_R_TRIG_01 | +UART_FCR_T_TRIG_10 |UART_FCR_ENABLE ); +/* +* Switch to register configuration mode B to access the UART_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load the new FIFO triggers and the new DMA mode bit. +*/ +omap_write (uart,UART_OMAP_SCR ,OMAP_UART_SCR_RX_TRIG_GRANU1_MASK ); +/* +* Restore the UART_OMAP_EFR[4] value. +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Restore UART_MCR[6] value. +*/ +omap_write (uart,UART_MCR , mcr); +/* +* Restore UART_LCR value. +*/ +omap_write (uart,UART_LCR , lcr); + + uart->fifo_size =64 ; +} + +static void __init omap_uart_init_preirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +/* +* Clear the FIFO buffers. +*/ +omap_write (uart,UART_FCR ,UART_FCR_ENABLE ); +omap_write (uart,UART_FCR ,UART_FCR_ENABLE |UART_FCR_CLRX |UART_FCR_CLTX ); +omap_write (uart,UART_FCR ,0 ); + +/* +* The TRM says the mode should be disabled while UART_DLL and UART_DHL +* are being changed so we disable before setup, then enable. +*/ +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_DISABLE ); + +/* Baud rate & protocol format setup */ +baud_protocol_setup (uart); + +/* FIFO setup */ +fifo_setup (uart); + +/* No flow control */ +omap_write (uart,UART_MCR ,UART_MCR_DTR |UART_MCR_RTS ); + +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_16X_MODE ); +} + +static void __init omap_uart_init_postirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + + uart->irqaction.handler = omap_uart_interrupt; + uart->irqaction.name ="omap_uart" ; + uart->irqaction.dev_id = port; + +if (setup_dt_irq (&uart->irq, &uart->irqaction) !=0 ) + { +dprintk (XENLOG_ERR ,"Failed to allocated omap_uart IRQ %d\n" , + uart->irq.irq); +return ; + } + +/* Enable interrupts */ +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI ); +} + +static void omap_uart_suspend (struct serial_port *port) +{ +BUG (); +} +xen/drivers/char/omap-uart.c line 229
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+static void omap_uart_resume (struct serial_port *port) +{ +BUG (); +} + +static unsigned int omap_uart_tx_ready (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI );Why do you need to enable unmask interrupt here? Xen is just asking if the UART is ready to transmit another character.
Quoted 36 lines
xen/drivers/char/omap-uart.c new file +36
-0+return omap_read (uart,UART_LSR ) &UART_LSR_THRE ? uart->fifo_size :0 ; +} + +static void omap_uart_putc (struct serial_port *port,char c) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_THR , (uint32_t )(unsigned char )c); +} + +static int omap_uart_getc (struct serial_port *port,char *pc) +{ +struct omap_uart *uart = port->uart; + +if ( !(omap_read (uart,UART_LSR ) &UART_LSR_DR ) ) +return 0 ; + + *pc =omap_read (uart,UART_RBR ) &0xff ; +return 1 ; +} + +static int __init omap_uart_irq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +return ((uart->irq.irq >0 ) ? uart->irq.irq :-1 ); +} + +static const struct dt_irq __init *omap_uart_dt_irq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +return &uart->irq; +} + +static struct uart_driver __read_mostly omap_uart_driver = {xen/drivers/char/omap-uart.c line 276
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ .init_preirq = omap_uart_init_preirq, + .init_postirq = omap_uart_init_postirq, + .endboot = NULL, + .suspend = omap_uart_suspend, + .resume = omap_uart_resume, + .tx_ready = omap_uart_tx_ready, + .putc = omap_uart_putc, + .getc = omap_uart_getc, + .irq = omap_uart_irq, + .dt_irq_get = omap_uart_dt_irq,Can you implement
vuart_infocallback? It's used to partially emulate UART for Linux early printk.Quoted 1 line
For an example, you can look at
xen/drivers/char/exynos4210.cI rebased my tree to the latest master branch to get the
vuart_info. However, after rebasing to the master, I cannot build xen successfully. It would always failed building with the message:arm-linux-gnueabihf-gcc -O1 -fno-omit-frame-pointer -marm -g
(quoted diff) +0
-10-fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs -fno-builtin -fno-common -Wredundant-decls -iwithprefix include -Werror -Wno-pointer-arith -pipe -I/home/cbz/src/xen/xen/include -fno-stack-protector -fno-exceptions -Wnested-externs -msoft-float -mcpu=cortex-a15 -DGCC_HAS_VISIBILITY_ATTRIBUTE -fno-optimize-sibling-calls -DEARLY_PRINTK -DEARLY_PRINTK_INC=\"debug-8250.inc\" -DEARLY_PRINTK_BAUD= -DEARLY_UART_BASE_ADDRESS=0x48020000 -DEARLY_UART_REG_SHIFT=2 -g -D__XEN__ -include
/home/cbz/src/xen/xen/include/xen/config.h-DVERBOSE(quoted diff) +0
-2-fno-omit-frame-pointer -DCONFIG_FRAME_POINTER -MMD -MF .cpu.o.d -c cpu.c -o cpu.omake[4]: *** No rule to make target
vpl011.h', needed bydomain.o'. Stop.
Quoted 8 lines
make[4]: Leaving directory
/home/cbz/src/xen/xen/arch/arm' make[3]: *** [/home/cbz/src/xen/xen/arch/arm/built_in.o] Error 2 make[3]: Leaving directory/home/cbz/src/xen/xen/arch/arm' make[2]: *** [/home/cbz/src/xen/xen/xen] Error 2 make[2]: Leaving directory `/home/cbz/src/xen/xen' make[1]: *** [install] Error 2
make[1]: Leaving directory `/home/cbz/src/xen/xen'
make: *** [install-xen] Error 2
Well, I should have added "XEN_TARGET_ARCH=arm32" when "make clean" the tree...
Now it is fine.
Quoted 162 lines
Quoted 162 lines
Quoted 51 lines
xen/drivers/char/omap-uart.c new file +49
-0+}; + +static int __init omap_uart_init (struct dt_device_node *dev, +const void *data) +{ +const char *config = data; +struct omap_uart *uart; +u32 clkspec; +int res; +u64 addr, size; + +if (strcmp (config,"" ) ) +early_printk ("WARNING: UART configuration is not supported\n" ); + + uart = &omap_com; + + res =dt_property_read_u32 (dev,"clock-frequency" , &clkspec); +if ( !res ) + { +early_printk ("omap-uart: Unable to retrieve the clock frequency\n" ); +return -EINVAL ; + } + + uart->clock_hz = clkspec; + uart->baud =115200 ; + uart->data_bits =8 ; + uart->parity =UART_PARITY_NONE ; + uart->stop_bits =1 ; + res =dt_device_get_address (dev,0 , &addr, &size); +if ( res ) + { +early_printk ("omap-uart: Unable to retrieve the base" +" address of the UART\n" ); +return res; + } + + uart->regs =ioremap_attr (addr, size,PAGE_HYPERVISOR_NOCACHE ); +if ( !uart->regs ) + { +early_printk ("omap-uart: Unable to map the UART memory\n" ); +return -ENOMEM ; + } + + res =dt_device_get_irq (dev,0 , &uart->irq); +if ( res ) + { +early_printk ("omap-uart: Unable to retrieve the IRQ\n" ); +return res; + }xen/drivers/char/omap-uart.c line 336
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ +/* Register with generic serial driver */ +serial_register_uart (SERHND_DTUART , &omap_uart_driver, uart); + +dt_device_set_used_by (dev,DOMID_XEN ); + +return 0 ; +} + +static const char const *omap_uart_dt_compat[] __initdata =const char * const.
Quoted 95 lines
xen/drivers/char/omap-uart.c new file +18
-0+{ +"ti,omap4-uart" , +NULL +}; + +DT_DEVICE_START (omap_uart,"OMAP UART" ,DEVICE_SERIAL ) + .compatible = omap_uart_dt_compat, + .init = omap_uart_init, +DT_DEVICE_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/xen/8250-uart.h +51
-0@@ -59,14 +59,45 @@#define UART_FCR_TRG8 0x80/* Rx FIFO trig lev 8 */ #define UART_FCR_TRG14 0xc0/* Rx FIFO trig lev 14 */ +/* +* Note: The FIFO trigger levels are chip specific: +* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 +* PC16550D: 1 4 8 14 xx xx xx xx +* TI16C550A: 1 4 8 14 xx xx xx xx +* TI16C550C: 1 4 8 14 xx xx xx xx +* ST16C550: 1 4 8 14 xx xx xx xx +* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 +* NS16C552: 1 4 8 14 xx xx xx xx +* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 +* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 +* TI16C752: 8 16 56 60 8 16 32 56 +* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA +*/ +#define UART_FCR_R_TRIG_00 0x00 +#define UART_FCR_R_TRIG_01 0x40 +#define UART_FCR_R_TRIG_10 0x80 +#define UART_FCR_R_TRIG_11 0xc0 +#define UART_FCR_T_TRIG_00 0x00 +#define UART_FCR_T_TRIG_01 0x10 +#define UART_FCR_T_TRIG_10 0x20 +#define UART_FCR_T_TRIG_11 0x30 +/* Line Control Register */ #define UART_LCR_DLAB 0x80/* Divisor Latch Access */ +/* +* Access to some registers depends on register access / configuration +* mode. +*/ +#define UART_LCR_CONF_MODE_A UART_LCR_DLAB/* Configuration mode A */ +#define UART_LCR_CONF_MODE_B 0xBF/* Configuration mode B */ +/* Modem Control Register */ #define UART_MCR_DTR 0x01/* Data Terminal Ready */ #define UART_MCR_RTS 0x02/* Request to Send */ #define UART_MCR_OUT2 0x08/* OUT2: interrupt mask */ #define UART_MCR_LOOP 0x10/* Enable loopback test mode */ +#define UART_MCR_TCRTLR 0x40/* Access TCR/TLR (TI16C752, EFR[4]=1) */ /* Line Status Register */ #define UART_LSR_DR 0x01/* Data ready */ @@ -92,6 +123,26 @@#define RESUME_DELAY MILLISECS(10)#define RESUME_RETRIES 100 +/* Enhanced feature register */ +#define UART_OMAP_EFR 0x02 + +#define UART_OMAP_EFR_ECB 0x10/* Enhanced control bit */ + +/* Mode definition register 1 */ +#define UART_OMAP_MDR1 0x08 + +/* +* These are the definitions for the MDR1 register +*/ +#define UART_OMAP_MDR1_16X_MODE 0x00/* UART 16x mode */ +#define UART_OMAP_MDR1_DISABLE 0x07/* Disable (default state) */ + +/* Supplementary control register */ +#define UART_OMAP_SCR 0x10 + +/* SCR register bitmasks */ +#define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7) +#endif /* __XEN_8250_UART_H__ */ /* Signature · 1 line
Julien Grall
Re: [PATCH v6 4/6] xen/arm: Add the new OMAP UART driver.
In reply to Chen BaoziQuoted 127 lines · Chen Baozi
Quoted 124 lines · Julien Grall
Quoted 67 lines · 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.
Signed-off-by Chen Baozi <[email protected]>---
config/arm32.mk | 1 + xen/drivers/char/Makefile | 1 + xen/drivers/char/omap-uart.c | 354 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/8250-uart.h | 51 +++++++ 4 files changed, 407 insertions(+)create mode 100644
xen/drivers/char/omap-uart.cconfig/arm32.mk +0
-0@@ -11,6 +11,7 @@ CFLAGS += -marm
HAS_PL011:= yHAS_EXYNOS4210:= y
+HAS_OMAP := y# Use only if calling $(LD) directly.
LDFLAGS_DIRECT+= -ELxen/drivers/char/Makefile +0
-0@@ -2,6 +2,7 @@ obj-y += console.oobj-$(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.oxen/drivers/char/omap-uart.c new file +24
-0@@ -0,0 +1,354 @@ +/* +* omap-uart.c +* Based on drivers/char/ns16550.c +* +* Driver for OMAP-UART controller +* +* Copyright (C) 2013, Chen Baozi <[email protected]> +* +* Note: This driver is made separate from 16550-series UART driver as +* omap platform has some specific configurations +*/ + +#include <xen/config.h> +#include <xen/console.h> +#include <xen/serial.h> +#include <xen/init.h> +#include <xen/irq.h> +#include <asm/early_printk.h> +#include <xen/device_tree.h> +#include <asm/device.h> +#include <xen/errno.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <xen/8250-uart.h> xen/drivers/char/omap-uart.c line 34
Quoted 10 lines
xen/drivers/char/omap-uart.c new file +10
-0+ +#define REG_SHIFT 2 + +#define omap_read (uart, off) ioreadl((uart)->regs + (off<<REG_SHIFT)) +#define omap_write (uart, off, val) iowritel((uart)->regs + (off<<REG_SHIFT), (val)) + +static struct omap_uart { + u32 baud, clock_hz, data_bits, parity, stop_bits, fifo_size; + struct dt_irq irq; + void __iomem *regs;I have noticed that I also use void * on the other drivers, but it's a gcc extension
(http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html).
It's better to use unsigned char *.Quoted 40 lines
xen/drivers/char/omap-uart.c new file +40
-0+struct irqaction irqaction; +} omap_com = {0}; + +static void omap_uart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +{ +struct serial_port *port = data; +struct omap_uart *uart = port->uart; +u32 lsr; + +while ( !(omap_read (uart,UART_IIR ) &UART_IIR_NOINT ) ) + { + lsr =omap_read (uart,UART_LSR ) &0xff ; +if ( lsr &UART_LSR_THRE ) +serial_tx_interrupt (port, regs); +if ( lsr &UART_LSR_DR ) +serial_rx_interrupt (port, regs); + +if ( port->txbufc == port->txbufp ) +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ELSI ); + }; +} + +static void baud_protocol_setup (struct omap_uart *uart) +{ +u32 dll, dlh, efr; +unsigned int divisor; + + divisor = uart->clock_hz / (uart->baud <<4 ); + dll = divisor &0xff ; + dlh = divisor >>8 ; + +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable access to the UART_IER[7:4] bit field. +*/ + efr =omap_read (uart,UART_OMAP_EFR );
Quoted 8 lines
Quoted 8 lines
xen/drivers/char/omap-uart.c line 82
Quoted 8 lines
xen/drivers/char/omap-uart.c new file +8
-0+omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register operation mode to access the UART_IER register. +*/ +omap_write (uart,UART_LCR ,0 ); +/* +* Clear the UART_IER register (set the UART_IER[4] SLEEP_MODE bit +* to 0 to change the UART_DLL and UART_DLM register). Set the
->>> + * UART_IER register value to 0x0000.
Quoted 150 lines
Quoted 141 lines
Quoted 141 lines
xen/drivers/char/omap-uart.c new file +141
-0+*/ +omap_write (uart,UART_IER ,0 ); +/* +* Switch to register configuartion mode B to access the UART_DLL and +* UART_DLM registers. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load divisor value. +*/ +omap_write (uart,UART_DLL , dll); +omap_write (uart,UART_DLM , dlh); +/* +* Restore the UART_OMAP_EFR +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Load the new protocol formatting (parity, stop-bit, character length) +* and switch to register operational mode. +*/ +omap_write (uart,UART_LCR , (uart->data_bits -5 ) | + ((uart->stop_bits -1 ) <<2 ) | uart->parity); +} + +static void fifo_setup (struct omap_uart *uart) +{ +u32 lcr, efr, mcr; +/* +* Switch to register configuration mode B to access the UART_OMAP_EFR +* register. +*/ + lcr =omap_read (uart,UART_LCR ); +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register. +*/ + efr =omap_read (uart,UART_OMAP_EFR ); +omap_write (uart,UART_OMAP_EFR , efr|UART_OMAP_EFR_ECB ); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Enable register submode TCR_TLR to access the UART_OMAP_TLR register +*/ + mcr =omap_read (uart,UART_MCR ); +omap_write (uart,UART_MCR , mcr|UART_MCR_TCRTLR ); +/* +* Enable the FIFO; load the new FIFO trigger and the new DMA mode. +*/ +omap_write (uart,UART_FCR ,UART_FCR_R_TRIG_01 | +UART_FCR_T_TRIG_10 |UART_FCR_ENABLE ); +/* +* Switch to register configuration mode B to access the UART_EFR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_B ); +/* +* Load the new FIFO triggers and the new DMA mode bit. +*/ +omap_write (uart,UART_OMAP_SCR ,OMAP_UART_SCR_RX_TRIG_GRANU1_MASK ); +/* +* Restore the UART_OMAP_EFR[4] value. +*/ +omap_write (uart,UART_OMAP_EFR , efr); +/* +* Switch to register configuration mode A to access the UART_MCR +* register. +*/ +omap_write (uart,UART_LCR ,UART_LCR_CONF_MODE_A ); +/* +* Restore UART_MCR[6] value. +*/ +omap_write (uart,UART_MCR , mcr); +/* +* Restore UART_LCR value. +*/ +omap_write (uart,UART_LCR , lcr); + + uart->fifo_size =64 ; +} + +static void __init omap_uart_init_preirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +/* +* Clear the FIFO buffers. +*/ +omap_write (uart,UART_FCR ,UART_FCR_ENABLE ); +omap_write (uart,UART_FCR ,UART_FCR_ENABLE |UART_FCR_CLRX |UART_FCR_CLTX ); +omap_write (uart,UART_FCR ,0 ); + +/* +* The TRM says the mode should be disabled while UART_DLL and UART_DHL +* are being changed so we disable before setup, then enable. +*/ +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_DISABLE ); + +/* Baud rate & protocol format setup */ +baud_protocol_setup (uart); + +/* FIFO setup */ +fifo_setup (uart); + +/* No flow control */ +omap_write (uart,UART_MCR ,UART_MCR_DTR |UART_MCR_RTS ); + +omap_write (uart,UART_OMAP_MDR1 ,UART_OMAP_MDR1_16X_MODE ); +} + +static void __init omap_uart_init_postirq (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + + uart->irqaction.handler = omap_uart_interrupt; + uart->irqaction.name ="omap_uart" ; + uart->irqaction.dev_id = port; + +if (setup_dt_irq (&uart->irq, &uart->irqaction) !=0 ) + { +dprintk (XENLOG_ERR ,"Failed to allocated omap_uart IRQ %d\n" , + uart->irq.irq); +return ; + } + +/* Enable interrupts */ +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI ); +} + +static void omap_uart_suspend (struct serial_port *port) +{ +BUG (); +} + +static void omap_uart_resume (struct serial_port *port) +{ +BUG (); +} +Quoted 8 lines
xen/drivers/char/omap-uart.c line 229
Quoted 5 lines
xen/drivers/char/omap-uart.c new file +5
-0+static unsigned int omap_uart_tx_ready (struct serial_port *port) +{ +struct omap_uart *uart = port->uart; + +omap_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI |UART_IER_ELSI );Why do you need to enable unmask interrupt here? Xen is just asking if the UART is ready to transmit another character.
Quoted 7 lines
Well, it is because we need to mask THRE interrupt after tx completes and unmake it once it starts to tx. This is one of main differences between OMAP UART and common 8250, since the THRE interrupt won't be cleared by writing to THR or reading IIR in OMAP UART.
In Linux, there are .start_tx and .stop_tx callbacks for UART driver. Since we don't have that mechanism on Xen, I added it here.
If you need to only enable THRE interrupt, please only enable THRE interrupt. You can't assume that *_ERDAI, *_ELSI are already set.
I think something like that is better:
reg = omap_read(uart, UART_IER);omap_write(uart, UART_IER, reg | UART_IER);
This comment is the same for every place you play with the interrupt mask.
Quoted 5 lines
Quoted 3 lines
xen/drivers/char/omap-uart.c line 336
Quoted 1 line
xen/drivers/char/omap-uart.c new file +1
-0+static const char const *omap_uart_dt_compat[] __initdata =const char * const.
Hmmm, I just followed
exynos4210-uart.candpl011.chere...
Actually, this is an "issue" in the other drivers. const char * has the same meaning as char const *. So one of the const was useless.
Cheers,
Signature · 1 line
Julien Grall