mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] PBL: console: Make independent of DEBUG_LL
@ 2015-07-29 10:15 Sascha Hauer
  2015-07-29 10:15 ` [PATCH 2/2] ARM: i.MX: make early UART functions " Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2015-07-29 10:15 UTC (permalink / raw)
  To: Barebox List

With more stuff being done in PBL regular console support gets more and more
useful. This makes the PBL console independent of DEBUG_LL which is only
meant for early debugging but not regular output.
To use the regular PBL console a board must call pbl_set_putc() which stores
a pointer to the putc function to be used.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Kconfig    | 23 +++++++++++------------
 include/console.h |  2 ++
 pbl/console.c     | 50 +++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 56 insertions(+), 19 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 983d305..9af0a54 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -594,6 +594,17 @@ config CONSOLE_ACTIVATE_NONE
 
 endchoice
 
+config PBL_CONSOLE
+	depends on PBL_IMAGE
+	depends on !CONSOLE_NONE
+	bool "Enable console support in PBL"
+	help
+	  This enables printf/pr_* support in the PBL to get more
+	  informational output earlier during startup. Note that
+	  printf/pr_* need a valid C environment, so the binary
+	  must be running at the address it's linked at and bss must
+	  be cleared. On ARM that would be after setup_c().
+
 config PARTITION
 	bool
 	prompt "Enable Partitions"
@@ -935,18 +946,6 @@ config DEBUG_INITCALLS
 	help
 	  If enabled this will print initcall traces.
 
-config PBL_CONSOLE
-	depends on PBL_IMAGE
-	depends on DEBUG_LL
-	depends on !CONSOLE_NONE
-	bool "Enable console support in PBL"
-	help
-	  This enables printf/pr_* support in the PBL to get more
-	  informational output earlier during startup. Note that
-	  printf/pr_* need a valid C environment, so the binary
-	  must be running at the address it's linked at and bss must
-	  be cleared. On ARM that would be after setup_c().
-
 endmenu
 
 config HAS_DEBUG_LL
diff --git a/include/console.h b/include/console.h
index 839ec17..bdf3a7d 100644
--- a/include/console.h
+++ b/include/console.h
@@ -83,4 +83,6 @@ unsigned console_get_active(struct console_device *cdev);
 int console_set_baudrate(struct console_device *cdev, unsigned baudrate);
 unsigned console_get_baudrate(struct console_device *cdev);
 
+void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx);
+
 #endif
diff --git a/pbl/console.c b/pbl/console.c
index a9859ad..3574753 100644
--- a/pbl/console.c
+++ b/pbl/console.c
@@ -1,6 +1,47 @@
 #include <common.h>
 #include <debug_ll.h>
 
+static void (*__putc)(void *ctx, int c);
+static void *putc_ctx;
+
+/**
+ * pbl_set_putc() - setup UART used for PBL console
+ * @putc: The putc function.
+ * @ctx: The context pointer passed back to putc
+ *
+ * This sets the putc function which is afterwards used to output
+ * characters in the PBL.
+ */
+void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx)
+{
+	__putc = putcf;
+	putc_ctx = ctx;
+}
+
+void console_putc(unsigned int ch, char c)
+{
+	if (!__putc)
+		putc_ll(c);
+	else
+		__putc(putc_ctx, c);
+}
+
+int console_puts(unsigned int ch, const char *str)
+{
+	int n = 0;
+
+	while (*str) {
+		if (*str == '\n')
+			putc_ll('\r');
+
+		console_putc(CONSOLE_STDOUT, *str);
+		str++;
+		n++;
+	}
+
+	return n;
+}
+
 int printf(const char *fmt, ...)
 {
 	va_list args;
@@ -11,7 +52,7 @@ int printf(const char *fmt, ...)
 	i = vsprintf(printbuffer, fmt, args);
 	va_end(args);
 
-	puts_ll(printbuffer);
+	console_puts(CONSOLE_STDOUT, printbuffer);
 
 	return i;
 }
@@ -26,7 +67,7 @@ int pr_print(int level, const char *fmt, ...)
 	i = vsprintf(printbuffer, fmt, args);
 	va_end(args);
 
-	puts_ll(printbuffer);
+	console_puts(CONSOLE_STDOUT, printbuffer);
 
 	return i;
 }
@@ -35,8 +76,3 @@ int ctrlc(void)
 {
 	return 0;
 }
-
-void console_putc(unsigned int ch, char c)
-{
-	putc_ll(c);
-}
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/2] ARM: i.MX: make early UART functions independent of DEBUG_LL
  2015-07-29 10:15 [PATCH 1/2] PBL: console: Make independent of DEBUG_LL Sascha Hauer
@ 2015-07-29 10:15 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2015-07-29 10:15 UTC (permalink / raw)
  To: Barebox List

We have functions to setup the i.MX uart for early use, but these all
depend on DEBUG_LL. Move them to imx-uart.h to make them usable for
the regular PBL console.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/include/mach/debug_ll.h | 47 +++++--------------------------
 include/serial/imx-uart.h                 | 40 ++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/debug_ll.h b/arch/arm/mach-imx/include/mach/debug_ll.h
index ab939b3..fb170fe 100644
--- a/arch/arm/mach-imx/include/mach/debug_ll.h
+++ b/arch/arm/mach-imx/include/mach/debug_ll.h
@@ -21,33 +21,6 @@
 #define __IMX_UART_BASE(soc, num) soc##_UART##num##_BASE_ADDR
 #define IMX_UART_BASE(soc, num) __IMX_UART_BASE(soc, num)
 
-static inline void imx_uart_setup_ll(void __iomem *uartbase,
-				     unsigned int refclock)
-{
-	writel(0x00000000, uartbase + UCR1);
-
-	writel(UCR2_IRTS | UCR2_WS | UCR2_TXEN | UCR2_RXEN | UCR2_SRST,
-	       uartbase + UCR2);
-	writel(UCR3_DSR | UCR3_DCD | UCR3_RI | UCR3_ADNIMP | UCR3_RXDMUXSEL,
-	       uartbase + UCR3);
-	writel((0b10 << UFCR_TXTL_SHF) | UFCR_RFDIV1 | (1 << UFCR_RXTL_SHF),
-	       uartbase + UFCR);
-
-	writel(baudrate_to_ubir(CONFIG_BAUDRATE),
-	       uartbase + UBIR);
-	writel(refclock_to_ubmr(refclock),
-	       uartbase + UBMR);
-
-	writel(UCR1_UARTEN, uartbase + UCR1);
-}
-
-#define __imx_uart_setup_ll(refclock)					\
-	do {								\
-		imx_uart_setup_ll(IOMEM(IMX_UART_BASE(IMX_DEBUG_SOC,	\
-						      CONFIG_DEBUG_IMX_UART_PORT)), \
-				  refclock);				\
-	} while(0)
-
 #ifdef CONFIG_DEBUG_IMX1_UART
 #define IMX_DEBUG_SOC MX1
 #elif defined CONFIG_DEBUG_IMX21_UART
@@ -72,12 +45,16 @@ static inline void imx_uart_setup_ll(void __iomem *uartbase,
 
 static inline void imx51_uart_setup_ll(void)
 {
-	__imx_uart_setup_ll(54000000);
+	void *base = IOMEM(IMX_UART_BASE(IMX_DEBUG_SOC, CONFIG_DEBUG_IMX_UART_PORT));
+
+	imx51_uart_setup(base);
 }
 
 static inline void imx6_uart_setup_ll(void)
 {
-	__imx_uart_setup_ll(80000000);
+	void *base = IOMEM(IMX_UART_BASE(IMX_DEBUG_SOC, CONFIG_DEBUG_IMX_UART_PORT));
+
+	imx6_uart_setup(base);
 }
 
 static inline void PUTC_LL(int c)
@@ -88,20 +65,10 @@ static inline void PUTC_LL(int c)
 	if (!base)
 		return;
 
-	if (!(readl(base + UCR1) & UCR1_UARTEN))
-		return;
-
-	while (!(readl(base + USR2) & USR2_TXDC));
-
-	writel(c, base + URTX0);
+	imx_uart_putc(base, c);
 }
 #else
 
-static inline void imx_uart_setup_ll(void __iomem *uartbase,
-				     unsigned int refclock)
-{
-}
-
 static inline void imx51_uart_setup_ll(void) {}
 static inline void imx6_uart_setup_ll(void)  {}
 
diff --git a/include/serial/imx-uart.h b/include/serial/imx-uart.h
index 7275e6a..d0e5bcc 100644
--- a/include/serial/imx-uart.h
+++ b/include/serial/imx-uart.h
@@ -125,4 +125,44 @@ static inline int refclock_to_ubmr(int clock_hz)
 	return clock_hz / 1600 - 1;
 }
 
+static inline void imx_uart_setup(void __iomem *uartbase,
+				     unsigned int refclock)
+{
+	writel(0x00000000, uartbase + UCR1);
+
+	writel(UCR2_IRTS | UCR2_WS | UCR2_TXEN | UCR2_RXEN | UCR2_SRST,
+	       uartbase + UCR2);
+	writel(UCR3_DSR | UCR3_DCD | UCR3_RI | UCR3_ADNIMP | UCR3_RXDMUXSEL,
+	       uartbase + UCR3);
+	writel((0b10 << UFCR_TXTL_SHF) | UFCR_RFDIV1 | (1 << UFCR_RXTL_SHF),
+	       uartbase + UFCR);
+
+	writel(baudrate_to_ubir(CONFIG_BAUDRATE),
+	       uartbase + UBIR);
+	writel(refclock_to_ubmr(refclock),
+	       uartbase + UBMR);
+
+	writel(UCR1_UARTEN, uartbase + UCR1);
+}
+
+static inline void imx51_uart_setup(void __iomem *uartbase)
+{
+	imx_uart_setup(uartbase, 54000000);
+}
+
+static inline void imx6_uart_setup(void __iomem *uartbase)
+{
+	imx_uart_setup(uartbase, 80000000);
+}
+
+static inline void imx_uart_putc(void *base, int c)
+{
+	if (!(readl(base + UCR1) & UCR1_UARTEN))
+		return;
+
+	while (!(readl(base + USR2) & USR2_TXDC));
+
+	writel(c, base + URTX0);
+}
+
 #endif	/* __IMX_UART_H__ */
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2015-07-29 10:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-29 10:15 [PATCH 1/2] PBL: console: Make independent of DEBUG_LL Sascha Hauer
2015-07-29 10:15 ` [PATCH 2/2] ARM: i.MX: make early UART functions " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox