mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] serial: cadence: move register definitions into header file
@ 2020-01-13 19:37 Lucas Stach
  2020-01-13 19:37 ` [PATCH 2/3] serial: cadence: add lowlevel init and putc functions Lucas Stach
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Lucas Stach @ 2020-01-13 19:37 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/serial/serial_cadence.c | 41 ++++-----------------------------
 include/serial/cadence.h        | 37 +++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 36 deletions(-)
 create mode 100644 include/serial/cadence.h

diff --git a/drivers/serial/serial_cadence.c b/drivers/serial/serial_cadence.c
index 6454888e3c5b..416800b84723 100644
--- a/drivers/serial/serial_cadence.c
+++ b/drivers/serial/serial_cadence.c
@@ -12,47 +12,16 @@
  * GNU General Public License for more details.
  *
  */
+
 #include <common.h>
 #include <driver.h>
 #include <init.h>
-#include <malloc.h>
-#include <notifier.h>
 #include <io.h>
-#include <linux/err.h>
 #include <linux/clk.h>
-
-#define CADENCE_UART_CONTROL		0x00
-#define CADENCE_UART_MODE		0x04
-#define CADENCE_UART_BAUD_GEN		0x18
-#define CADENCE_UART_CHANNEL_STS	0x2C
-#define CADENCE_UART_RXTXFIFO		0x30
-#define CADENCE_UART_BAUD_DIV		0x34
-
-#define CADENCE_CTRL_RXRES		(1 << 0)
-#define CADENCE_CTRL_TXRES		(1 << 1)
-#define CADENCE_CTRL_RXEN		(1 << 2)
-#define CADENCE_CTRL_RXDIS		(1 << 3)
-#define CADENCE_CTRL_TXEN		(1 << 4)
-#define CADENCE_CTRL_TXDIS		(1 << 5)
-#define CADENCE_CTRL_RSTTO		(1 << 6)
-#define CADENCE_CTRL_STTBRK		(1 << 7)
-#define CADENCE_CTRL_STPBRK		(1 << 8)
-
-#define CADENCE_MODE_CLK_REF		(0 << 0)
-#define CADENCE_MODE_CLK_REF_DIV	(1 << 0)
-#define CADENCE_MODE_CHRL_6		(3 << 1)
-#define CADENCE_MODE_CHRL_7		(2 << 1)
-#define CADENCE_MODE_CHRL_8		(0 << 1)
-#define CADENCE_MODE_PAR_EVEN		(0 << 3)
-#define CADENCE_MODE_PAR_ODD		(1 << 3)
-#define CADENCE_MODE_PAR_SPACE		(2 << 3)
-#define CADENCE_MODE_PAR_MARK		(3 << 3)
-#define CADENCE_MODE_PAR_NONE		(4 << 3)
-
-#define CADENCE_STS_REMPTY		(1 << 1)
-#define CADENCE_STS_RFUL		(1 << 2)
-#define CADENCE_STS_TEMPTY		(1 << 3)
-#define CADENCE_STS_TFUL		(1 << 4)
+#include <linux/err.h>
+#include <malloc.h>
+#include <notifier.h>
+#include <serial/cadence.h>
 
 /*
  * create default values for different platforms
diff --git a/include/serial/cadence.h b/include/serial/cadence.h
new file mode 100644
index 000000000000..014fb01203a9
--- /dev/null
+++ b/include/serial/cadence.h
@@ -0,0 +1,37 @@
+#ifndef __CADENCE_UART_H__
+#define __CADENCE_UART_H__
+
+#define CADENCE_UART_CONTROL		0x00
+#define CADENCE_UART_MODE		0x04
+#define CADENCE_UART_BAUD_GEN		0x18
+#define CADENCE_UART_CHANNEL_STS	0x2C
+#define CADENCE_UART_RXTXFIFO		0x30
+#define CADENCE_UART_BAUD_DIV		0x34
+
+#define CADENCE_CTRL_RXRES		(1 << 0)
+#define CADENCE_CTRL_TXRES		(1 << 1)
+#define CADENCE_CTRL_RXEN		(1 << 2)
+#define CADENCE_CTRL_RXDIS		(1 << 3)
+#define CADENCE_CTRL_TXEN		(1 << 4)
+#define CADENCE_CTRL_TXDIS		(1 << 5)
+#define CADENCE_CTRL_RSTTO		(1 << 6)
+#define CADENCE_CTRL_STTBRK		(1 << 7)
+#define CADENCE_CTRL_STPBRK		(1 << 8)
+
+#define CADENCE_MODE_CLK_REF		(0 << 0)
+#define CADENCE_MODE_CLK_REF_DIV	(1 << 0)
+#define CADENCE_MODE_CHRL_6		(3 << 1)
+#define CADENCE_MODE_CHRL_7		(2 << 1)
+#define CADENCE_MODE_CHRL_8		(0 << 1)
+#define CADENCE_MODE_PAR_EVEN		(0 << 3)
+#define CADENCE_MODE_PAR_ODD		(1 << 3)
+#define CADENCE_MODE_PAR_SPACE		(2 << 3)
+#define CADENCE_MODE_PAR_MARK		(3 << 3)
+#define CADENCE_MODE_PAR_NONE		(4 << 3)
+
+#define CADENCE_STS_REMPTY		(1 << 1)
+#define CADENCE_STS_RFUL		(1 << 2)
+#define CADENCE_STS_TEMPTY		(1 << 3)
+#define CADENCE_STS_TFUL		(1 << 4)
+
+#endif /* __CADENCE_UART_H__ */
-- 
2.24.1


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

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

* [PATCH 2/3] serial: cadence: add lowlevel init and putc functions
  2020-01-13 19:37 [PATCH 1/3] serial: cadence: move register definitions into header file Lucas Stach
@ 2020-01-13 19:37 ` Lucas Stach
  2020-01-13 19:37 ` [PATCH 3/3] ARM: zynq: zedboard: add PBL console support Lucas Stach
  2020-01-14 11:07 ` [PATCH 1/3] serial: cadence: move register definitions into header file Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2020-01-13 19:37 UTC (permalink / raw)
  To: barebox

This allows to use the Cadence serial as a PBL console.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 include/serial/cadence.h | 55 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/include/serial/cadence.h b/include/serial/cadence.h
index 014fb01203a9..f08b5b0cba4a 100644
--- a/include/serial/cadence.h
+++ b/include/serial/cadence.h
@@ -34,4 +34,59 @@
 #define CADENCE_STS_TEMPTY		(1 << 3)
 #define CADENCE_STS_TFUL		(1 << 4)
 
+static inline void cadence_uart_init(void __iomem *uartbase)
+{
+	int baudrate = CONFIG_BAUDRATE;
+	unsigned int clk = 49999995;
+	unsigned int gen, div;
+
+	/* disable transmitter and receiver */
+	writel(0, uartbase + CADENCE_UART_CONTROL);
+
+	/* calculate and set baud clock generator parameters */
+	for (div = 4; div < 256; div++) {
+		int calc_rate, error;
+
+		gen = clk / (baudrate * (div + 1));
+
+		if (gen < 1 || gen > 65535)
+			continue;
+
+		calc_rate = clk / (gen * (div + 1));
+		error = baudrate - calc_rate;
+		if (error < 0)
+			error *= -1;
+		if (((error * 100) / baudrate) < 3)
+			break;
+	}
+
+	writel(gen, uartbase + CADENCE_UART_BAUD_GEN);
+	writel(div, uartbase + CADENCE_UART_BAUD_DIV);
+
+	/* soft-reset tx/rx paths */
+	writel(CADENCE_CTRL_RXRES | CADENCE_CTRL_TXRES,
+	       uartbase + CADENCE_UART_CONTROL);
+
+	while (readl(uartbase + CADENCE_UART_CONTROL) &
+		(CADENCE_CTRL_RXRES | CADENCE_CTRL_TXRES))
+		;
+
+	/* enable UART */
+	writel(CADENCE_MODE_CLK_REF | CADENCE_MODE_CHRL_8 |
+	       CADENCE_MODE_PAR_NONE, uartbase + CADENCE_UART_MODE);
+	writel(CADENCE_CTRL_RXEN | CADENCE_CTRL_TXEN,
+	       uartbase + CADENCE_UART_CONTROL);
+}
+
+static inline void cadence_uart_putc(void *base, int c)
+{
+	if (!(readl(base + CADENCE_UART_CONTROL) & CADENCE_CTRL_TXEN))
+		return;
+
+	while ((readl(base + CADENCE_UART_CHANNEL_STS) & CADENCE_STS_TFUL))
+		;
+
+	writel(c, base + CADENCE_UART_RXTXFIFO);
+}
+
 #endif /* __CADENCE_UART_H__ */
-- 
2.24.1


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

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

* [PATCH 3/3] ARM: zynq: zedboard: add PBL console support
  2020-01-13 19:37 [PATCH 1/3] serial: cadence: move register definitions into header file Lucas Stach
  2020-01-13 19:37 ` [PATCH 2/3] serial: cadence: add lowlevel init and putc functions Lucas Stach
@ 2020-01-13 19:37 ` Lucas Stach
  2020-01-14 11:07 ` [PATCH 1/3] serial: cadence: move register definitions into header file Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2020-01-13 19:37 UTC (permalink / raw)
  To: barebox

Allows for significantly easier debugging of PBL functions.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 arch/arm/boards/avnet-zedboard/lowlevel.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/arm/boards/avnet-zedboard/lowlevel.c b/arch/arm/boards/avnet-zedboard/lowlevel.c
index 8edc6293f210..912eb11fdac0 100644
--- a/arch/arm/boards/avnet-zedboard/lowlevel.c
+++ b/arch/arm/boards/avnet-zedboard/lowlevel.c
@@ -22,6 +22,7 @@
 #include <asm/barebox-arm-head.h>
 #include <mach/init.h>
 #include <mach/zynq7000-regs.h>
+#include <serial/cadence.h>
 
 #define DCI_DONE	(1 << 13)
 #define PLL_ARM_LOCK	(1 << 0)
@@ -279,6 +280,18 @@ static void avnet_zedboard_ps7_init(void)
 	writel(0x0000767B, ZYNQ_SLCR_LOCK);
 }
 
+static void avnet_zedboard_pbl_console_init(void)
+{
+	relocate_to_current_adr();
+	setup_c();
+	barrier();
+
+	cadence_uart_init((void *)ZYNQ_UART1_BASE_ADDR);
+	pbl_set_putc(cadence_uart_putc, (void *)ZYNQ_UART1_BASE_ADDR);
+
+	pr_debug("\nAvnet ZedBoard PBL\n");
+}
+
 ENTRY_FUNCTION(start_avnet_zedboard, r0, r1, r2)
 {
 
@@ -289,5 +302,8 @@ ENTRY_FUNCTION(start_avnet_zedboard, r0, r1, r2)
 
 	avnet_zedboard_ps7_init();
 
+	if (IS_ENABLED(CONFIG_PBL_CONSOLE))
+		avnet_zedboard_pbl_console_init();
+
 	barebox_arm_entry(0, SZ_512M, fdt);
 }
-- 
2.24.1


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

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

* Re: [PATCH 1/3] serial: cadence: move register definitions into header file
  2020-01-13 19:37 [PATCH 1/3] serial: cadence: move register definitions into header file Lucas Stach
  2020-01-13 19:37 ` [PATCH 2/3] serial: cadence: add lowlevel init and putc functions Lucas Stach
  2020-01-13 19:37 ` [PATCH 3/3] ARM: zynq: zedboard: add PBL console support Lucas Stach
@ 2020-01-14 11:07 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2020-01-14 11:07 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

On Mon, Jan 13, 2020 at 08:37:14PM +0100, Lucas Stach wrote:
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
>  drivers/serial/serial_cadence.c | 41 ++++-----------------------------
>  include/serial/cadence.h        | 37 +++++++++++++++++++++++++++++
>  2 files changed, 42 insertions(+), 36 deletions(-)
>  create mode 100644 include/serial/cadence.h

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2020-01-14 11:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-13 19:37 [PATCH 1/3] serial: cadence: move register definitions into header file Lucas Stach
2020-01-13 19:37 ` [PATCH 2/3] serial: cadence: add lowlevel init and putc functions Lucas Stach
2020-01-13 19:37 ` [PATCH 3/3] ARM: zynq: zedboard: add PBL console support Lucas Stach
2020-01-14 11:07 ` [PATCH 1/3] serial: cadence: move register definitions into header file Sascha Hauer

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