Skip to contentSkip to conversation

nios2: convert altera_uart to driver model

PATCH Superseded Thomas Chou 3 participants 7 messages Sep 18, 2015 – Sep 24, 2015 NIOS2 architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nios2: convert altera_uart to driver model

Convert altera_uart to driver model.

---
 arch/nios2/dts/3c120_devboard.dts |   1 +
 drivers/serial/Kconfig            |   6 ++
 drivers/serial/altera_uart.c      | 153 ++++++++++++++++++--------------------
 include/configs/nios2-generic.h   |   9 +--
 4 files changed, 79 insertions(+), 90 deletions(-)
arch/nios2/dts/3c120_devboard.dts +1 -0
index 7f76328..2159cfc 100644
@@ -130,6 +130,7 @@
 				interrupts = <10>;
 				current-speed = <115200>;
 				clock-frequency = <62500000>;
+				u-boot,dm-pre-reloc;
 			};
 		};
 
drivers/serial/Kconfig +6 -0
index 5a8cb3a..34195e1 100644
@@ -122,6 +122,12 @@ config ALTERA_JTAG_UART_BYPASS
 	  Bypass console output and keep going even if there is no
 	  JTAG terminal connection with the host.
 
+config ALTERA_UART
+	bool "Altera UART support"
+	depends on NIOS2 && DM_SERIAL
+	help
+	  Select this to enable an UART for Altera devices.
+
 config ROCKCHIP_SERIAL
 	bool "Rockchip on-chip UART support"
 	depends on ARCH_UNIPHIER && DM_SERIAL
drivers/serial/altera_uart.c +71 -82

203 lines not on this page · raw message

include/configs/nios2-generic.h +1 -8
index bd6d45c..dcb90de 100644
@@ -23,14 +23,7 @@
 /*
  * SERIAL
  */
-#if defined(CONFIG_ALTERA_JTAG_UART)
-#else
-# define CONFIG_SYS_NIOS_CONSOLE	CONFIG_SYS_UART_BASE
-#endif
-
-#define CONFIG_SYS_NIOS_FIXEDBAUD
-#define CONFIG_BAUDRATE		CONFIG_SYS_UART_BAUD
-#define CONFIG_SYS_BAUDRATE_TABLE	{CONFIG_BAUDRATE}
+#define CONFIG_BAUDRATE			115200
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 nios2: convert altera_uart to driver model

Quoted 4 lines · Thomas Chou

Convert altera_uart to driver model.

---

Hi!

minor nitpicks below :)

drivers/serial/altera_uart.c line 21

Quoted 8 lines
drivers/serial/altera_uart.c +1 -1
-typedef volatile struct {
+struct altera_uart_regs {
 	unsigned	rxdata;		/* Rx data reg */
 	unsigned	txdata;		/* Tx data reg */
 	unsigned	status;		/* Status reg */
 	unsigned	control;	/* Control reg */
 	unsigned	divisor;	/* Baud rate divisor reg */
 	unsigned	endofpacket;	/* End-of-packet reg */

Probably make this u32 instead of unsigned, so we're in the safe.

Quoted 2 lines
(quoted diff) +1 -1
-} nios_uart_t;
+};

[...]

Quoted 6 lines
drivers/serial/altera_uart.c +2 -3
-static int altera_serial_init(void)
+static int altera_uart_putc(struct udevice *dev, const char c)
 {
-	return 0;
-}
+	struct altera_uart_platdata *plat = dev->platdata;

drivers/serial/altera_uart.c DECLARE_GLOBAL_DATA_PTR; · line 60

Quoted 10 lines
drivers/serial/altera_uart.c +4 -4
+	struct altera_uart_regs *const regs = plat->reg;
 
-#else
+	if (!(readl(&regs->status) & NIOS_UART_TRDY))
+		return -EAGAIN;
 
-static void altera_serial_setbrg(void)
-{
-	unsigned div;
+	writel((unsigned char)c, &regs->txdata);

Is this type-cast needed ?

Quoted 8 lines
drivers/serial/altera_uart.c +2 -3
-	div = (CONFIG_SYS_CLK_FREQ/gd->baudrate)-1;
-	writel (div, &uart->divisor);
+	return 0;
 }
 
-static int altera_serial_init(void)
+static int altera_uart_pending(struct udevice *dev, bool input)
 {

drivers/serial/altera_uart.c DECLARE_GLOBAL_DATA_PTR; · line 74

Quoted 10 lines
drivers/serial/altera_uart.c +8 -2
-	serial_setbrg();
-	return 0;
+	struct altera_uart_platdata *plat = dev->platdata;
+	struct altera_uart_regs *const regs = plat->reg;
+	unsigned st = readl(&regs->status);
+
+	if (input)
+		return (st & NIOS_UART_RRDY) ? 1 : 0;
+	else
+		return (st & NIOS_UART_TMT) ? 0 : 1;

Drop the ternary please, just use return st & flag or return !(st & flag), it's not necessary to return 0 or 1, you can safely return 0 or non-zero.

Quoted 10 lines

}

drivers/serial/altera_uart.c +1 -6
-#endif /* CONFIG_SYS_NIOS_FIXEDBAUD */
-
-/*-----------------------------------------------------------------------
- * UART CONSOLE
- *---------------------------------------------------------------------*/
-static void altera_serial_putc(char c)
+static int altera_uart_getc(struct udevice *dev)
 {

drivers/serial/altera_uart.c DECLARE_GLOBAL_DATA_PTR; · line 83

Quoted 10 lines
drivers/serial/altera_uart.c +5 -5
-	if (c == '\n')
-		serial_putc ('\r');
-	while ((readl (&uart->status) & NIOS_UART_TRDY) == 0)
-		WATCHDOG_RESET ();
-	writel ((unsigned char)c, &uart->txdata);
+	struct altera_uart_platdata *plat = dev->platdata;
+	struct altera_uart_regs *const regs = plat->reg;
+
+	if (readl(&regs->status) & NIOS_UART_RRDY)
+		return (readl(&regs->rxdata) & 0xff);

Parenthesis not needed around the readl(...) & 0xff expression.

drivers/serial/altera_uart.c DECLARE_GLOBAL_DATA_PTR; · line 86

Quoted 3 lines
drivers/serial/altera_uart.c +2 -0
+	else
+		return -EAGAIN;
 }

[...]

Thanks!

#2 lore raw

PATCH 1/1 nios2: convert altera_uart to driver model

Hi,

Quoted 10 lines · Marek Vasut
Quoted 4 lines · Thomas Chou

Convert altera_uart to driver model.

---

Hi!

minor nitpicks below :)

Looks good to me also.

You might want to implement CONFIG_DEBUG_UART. It allows UART output before driver model is ready.

[snip]

Regards,
Simon

#3 lore raw

PATCH v2 1/1 nios2: convert altera_uart to driver model

In reply to Thomas Chou

Convert altera_uart to driver model.

---
v2
fix coding style as Marek suggested.

 arch/nios2/dts/3c120_devboard.dts |   1 +
 drivers/serial/Kconfig            |   6 ++
 drivers/serial/altera_uart.c      | 169 +++++++++++++++++---------------------
 include/configs/nios2-generic.h   |   9 +-
 4 files changed, 85 insertions(+), 100 deletions(-)
arch/nios2/dts/3c120_devboard.dts +1 -0
index 7f76328..2159cfc 100644
@@ -130,6 +130,7 @@
 				interrupts = <10>;
 				current-speed = <115200>;
 				clock-frequency = <62500000>;
+				u-boot,dm-pre-reloc;
 			};
 		};
 
drivers/serial/Kconfig +6 -0
index 5a8cb3a..34195e1 100644
@@ -122,6 +122,12 @@ config ALTERA_JTAG_UART_BYPASS
 	  Bypass console output and keep going even if there is no
 	  JTAG terminal connection with the host.
 
+config ALTERA_UART
+	bool "Altera UART support"
+	depends on NIOS2 && DM_SERIAL
+	help
+	  Select this to enable an UART for Altera devices.
+
 config ROCKCHIP_SERIAL
 	bool "Rockchip on-chip UART support"
 	depends on ARCH_UNIPHIER && DM_SERIAL
drivers/serial/altera_uart.c +77 -92

210 lines not on this page · raw message

include/configs/nios2-generic.h +1 -8
index bd6d45c..dcb90de 100644
@@ -23,14 +23,7 @@
 /*
  * SERIAL
  */
-#if defined(CONFIG_ALTERA_JTAG_UART)
-#else
-# define CONFIG_SYS_NIOS_CONSOLE	CONFIG_SYS_UART_BASE
-#endif
-
-#define CONFIG_SYS_NIOS_FIXEDBAUD
-#define CONFIG_BAUDRATE		CONFIG_SYS_UART_BAUD
-#define CONFIG_SYS_BAUDRATE_TABLE	{CONFIG_BAUDRATE}
+#define CONFIG_BAUDRATE			115200
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
Signature · 1 line
2.1.4
#5 lore raw

PATCH v3 1/1 nios2: convert altera_uart to driver model

In reply to Thomas Chou

Convert altera_uart to driver model.

---
v2
fix coding style as Marek suggested.

v3
add early debug uart.
fix coding style as Simon suggested.

 arch/nios2/dts/3c120_devboard.dts |   1 +
 drivers/serial/Kconfig            |  14 +++
 drivers/serial/altera_uart.c      | 198 ++++++++++++++++++++------------------
 include/configs/nios2-generic.h   |   9 +-
 4 files changed, 123 insertions(+), 99 deletions(-)
arch/nios2/dts/3c120_devboard.dts +1 -0
index 07bec69..a35f5fe 100644
@@ -130,6 +130,7 @@
 				interrupts = <10>;
 				current-speed = <115200>;
 				clock-frequency = <62500000>;
+				u-boot,dm-pre-reloc;
 			};
 		};
 
drivers/serial/Kconfig +14 -0
index 10505dc..0282883 100644
@@ -61,6 +61,13 @@ config DEBUG_UART_ALTERA_JTAGUART
 	  You will need to provide parameters to make this work. The driver will
 	  be available until the real driver model serial is running.
 
+config DEBUG_UART_ALTERA_UART
+	bool "Altera UART"
+	help
+	  Select this to enable a debug UART using the altera_uart driver.
+	  You will need to provide parameters to make this work. The driver will
+	  be available until the real driver model serial is running.
+
 config DEBUG_UART_NS16550
 	bool "ns16550"
 	help
@@ -135,6 +142,13 @@ config ALTERA_JTAG_UART_BYPASS
 	  output will wait forever until a JTAG terminal is connected. If you
 	  not are sure, say Y.
 
+config ALTERA_UART
+	bool "Altera UART support"
+	depends on DM_SERIAL
+	help
+	  Select this to enable an UART for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 config ROCKCHIP_SERIAL
 	bool "Rockchip on-chip UART support"
 	depends on ARCH_UNIPHIER && DM_SERIAL
drivers/serial/altera_uart.c +107 -91

240 lines not on this page · raw message

include/configs/nios2-generic.h +1 -8
index bd6d45c..dcb90de 100644
@@ -23,14 +23,7 @@
 /*
  * SERIAL
  */
-#if defined(CONFIG_ALTERA_JTAG_UART)
-#else
-# define CONFIG_SYS_NIOS_CONSOLE	CONFIG_SYS_UART_BASE
-#endif
-
-#define CONFIG_SYS_NIOS_FIXEDBAUD
-#define CONFIG_BAUDRATE		CONFIG_SYS_UART_BAUD
-#define CONFIG_SYS_BAUDRATE_TABLE	{CONFIG_BAUDRATE}
+#define CONFIG_BAUDRATE			115200
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
Signature · 1 line
2.1.4
#6 lore raw

PATCH v3 1/1 nios2: convert altera_uart to driver model

Quoted 13 lines · Thomas Chou

Convert altera_uart to driver model.

---
v2
fix coding style as Marek suggested.

v3
add early debug uart.
fix coding style as Simon suggested.

Quoted 5 lines
  arch/nios2/dts/3c120_devboard.dts |   1 +
  drivers/serial/Kconfig            |  14 +++
  drivers/serial/altera_uart.c      | 198 ++++++++++++++++++++------------------
  include/configs/nios2-generic.h   |   9 +-
  4 files changed, 123 insertions(+), 99 deletions(-)

Applied to u-boot-nios.