diff mbox

[3/4] S5P: Serial: Add fdt support to driver

Message ID 1363343929-6190-4-git-send-email-rajeshwari.s@samsung.com
State New
Headers show

Commit Message

Rajeshwari Shinde March 15, 2013, 10:38 a.m. UTC
This patch adds FDT support to the serial s5p driver.
At present disabling the serial console (from the device tree) crashes
U-Boot. Add checks for this case, so that execution can continue without
a serial console.
It also enables the serial_s5p driver recognize the silent_console option.

Signed-off-by: Abhilash Kesavan <a.kesavan@samsung.com>
Signed-off-by: Gabe Black <gabeblack@google.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
---
Changes in V2:
        - None
Changes in V3:
	- Moved driver config structure to data section. 
	- Changed silent_console to silent-console.
	- Did put a check for base address before doing fdt decoding.
 drivers/serial/serial_s5p.c |   78 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)

Comments

Rajeshwari Birje March 15, 2013, 10:39 a.m. UTC | #1
Please ignore this mail.
Sorry for spamming

On Fri, Mar 15, 2013 at 4:08 PM, Rajeshwari Shinde
<rajeshwari.s@samsung.com> wrote:
> This patch adds FDT support to the serial s5p driver.
> At present disabling the serial console (from the device tree) crashes
> U-Boot. Add checks for this case, so that execution can continue without
> a serial console.
> It also enables the serial_s5p driver recognize the silent_console option.
>
> Signed-off-by: Abhilash Kesavan <a.kesavan@samsung.com>
> Signed-off-by: Gabe Black <gabeblack@google.com>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
> ---
> Changes in V2:
>         - None
> Changes in V3:
>         - Moved driver config structure to data section.
>         - Changed silent_console to silent-console.
>         - Did put a check for base address before doing fdt decoding.
>  drivers/serial/serial_s5p.c |   78 +++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 78 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c
> index 3c41242..55ef2bf 100644
> --- a/drivers/serial/serial_s5p.c
> +++ b/drivers/serial/serial_s5p.c
> @@ -24,16 +24,28 @@
>  #include <common.h>
>  #include <linux/compiler.h>
>  #include <asm/io.h>
> +#include <fdtdec.h>
>  #include <asm/arch/uart.h>
>  #include <asm/arch/clk.h>
>  #include <serial.h>
>
>  DECLARE_GLOBAL_DATA_PTR;
>
> +/* Information about a serial port */
> +struct fdt_serial {
> +       u32 base_addr;  /* address of registers in physical memory */
> +       u8 port_id;     /* uart port number */
> +       u8 enabled;     /* 1 if enabled, 0 if disabled */
> +} config __attribute__ ((section(".data")));
> +
>  static inline struct s5p_uart *s5p_get_base_uart(int dev_index)
>  {
> +#ifdef CONFIG_OF_CONTROL
> +       return (struct s5p_uart *)(config.base_addr);
> +#else
>         u32 offset = dev_index * sizeof(struct s5p_uart);
>         return (struct s5p_uart *)(samsung_get_base_uart() + offset);
> +#endif
>  }
>
>  /*
> @@ -69,6 +81,9 @@ void serial_setbrg_dev(const int dev_index)
>         u32 baudrate = gd->baudrate;
>         u32 val;
>
> +       if (!config.enabled)
> +               return;
> +
>         val = uclk / baudrate;
>
>         writel(val / 16 - 1, &uart->ubrdiv);
> @@ -87,6 +102,16 @@ int serial_init_dev(const int dev_index)
>  {
>         struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
>
> +#if defined(CONFIG_SILENT_CONSOLE) && \
> +               defined(CONFIG_OF_CONTROL) && \
> +               !defined(CONFIG_SPL_BUILD)
> +       if (fdtdec_get_config_int(gd->fdt_blob, "silent_console", 0))
> +               gd->flags |= GD_FLG_SILENT;
> +#endif
> +
> +       if (!config.enabled)
> +               return 0;
> +
>         /* reset and enable FIFOs, set triggers to the maximum */
>         writel(0, &uart->ufcon);
>         writel(0, &uart->umcon);
> @@ -129,6 +154,9 @@ int serial_getc_dev(const int dev_index)
>  {
>         struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
>
> +       if (!config.enabled)
> +               return 0;
> +
>         /* wait for character to arrive */
>         while (!(readl(&uart->utrstat) & 0x1)) {
>                 if (serial_err_check(dev_index, 0))
> @@ -145,6 +173,9 @@ void serial_putc_dev(const char c, const int dev_index)
>  {
>         struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
>
> +       if (!config.enabled)
> +               return;
> +
>         /* wait for room in the tx FIFO */
>         while (!(readl(&uart->utrstat) & 0x2)) {
>                 if (serial_err_check(dev_index, 1))
> @@ -165,6 +196,9 @@ int serial_tstc_dev(const int dev_index)
>  {
>         struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
>
> +       if (!config.enabled)
> +               return 0;
> +
>         return (int)(readl(&uart->utrstat) & 0x1);
>  }
>
> @@ -207,8 +241,51 @@ DECLARE_S5P_SERIAL_FUNCTIONS(3);
>  struct serial_device s5p_serial3_device =
>         INIT_S5P_SERIAL_STRUCTURE(3, "s5pser3");
>
> +#ifdef CONFIG_OF_CONTROL
> +int fdtdec_decode_console(int *index, struct fdt_serial *uart)
> +{
> +       const void *blob = gd->fdt_blob;
> +       int node;
> +
> +       node = fdt_path_offset(blob, "console");
> +       if (node < 0)
> +               return node;
> +
> +       uart->base_addr = fdtdec_get_addr(blob, node, "reg");
> +       if (uart->base_addr == FDT_ADDR_T_NONE)
> +               return -FDT_ERR_NOTFOUND;
> +
> +       uart->port_id = fdtdec_get_int(blob, node, "id", -1);
> +       uart->enabled = fdtdec_get_is_enabled(blob, node);
> +
> +       return 0;
> +}
> +#endif
> +
>  __weak struct serial_device *default_serial_console(void)
>  {
> +#ifdef CONFIG_OF_CONTROL
> +       int index = 0;
> +
> +       if ((!config.base_addr) && (fdtdec_decode_console(&index, &config))) {
> +               debug("Cannot decode default console node\n");
> +               return NULL;
> +       }
> +
> +       if (config.port_id == 0)
> +               return &s5p_serial0_device;
> +       else if (config.port_id == 1)
> +               return &s5p_serial1_device;
> +       else if (config.port_id == 2)
> +               return &s5p_serial2_device;
> +       else if (config.port_id == 3)
> +               return &s5p_serial3_device;
> +       else
> +               debug("Unknown config.port_id: %d", config.port_id);
> +
> +       return NULL;
> +#else
> +       config.enabled = 1;
>  #if defined(CONFIG_SERIAL0)
>         return &s5p_serial0_device;
>  #elif defined(CONFIG_SERIAL1)
> @@ -220,6 +297,7 @@ __weak struct serial_device *default_serial_console(void)
>  #else
>  #error "CONFIG_SERIAL? missing."
>  #endif
> +#endif
>  }
>
>  void s5p_serial_initialize(void)
> --
> 1.7.4.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
diff mbox

Patch

diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c
index 3c41242..55ef2bf 100644
--- a/drivers/serial/serial_s5p.c
+++ b/drivers/serial/serial_s5p.c
@@ -24,16 +24,28 @@ 
 #include <common.h>
 #include <linux/compiler.h>
 #include <asm/io.h>
+#include <fdtdec.h>
 #include <asm/arch/uart.h>
 #include <asm/arch/clk.h>
 #include <serial.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
+/* Information about a serial port */
+struct fdt_serial {
+	u32 base_addr;  /* address of registers in physical memory */
+	u8 port_id;     /* uart port number */
+	u8 enabled;     /* 1 if enabled, 0 if disabled */
+} config __attribute__ ((section(".data")));
+
 static inline struct s5p_uart *s5p_get_base_uart(int dev_index)
 {
+#ifdef CONFIG_OF_CONTROL
+	return (struct s5p_uart *)(config.base_addr);
+#else
 	u32 offset = dev_index * sizeof(struct s5p_uart);
 	return (struct s5p_uart *)(samsung_get_base_uart() + offset);
+#endif
 }
 
 /*
@@ -69,6 +81,9 @@  void serial_setbrg_dev(const int dev_index)
 	u32 baudrate = gd->baudrate;
 	u32 val;
 
+	if (!config.enabled)
+		return;
+
 	val = uclk / baudrate;
 
 	writel(val / 16 - 1, &uart->ubrdiv);
@@ -87,6 +102,16 @@  int serial_init_dev(const int dev_index)
 {
 	struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
 
+#if defined(CONFIG_SILENT_CONSOLE) && \
+		defined(CONFIG_OF_CONTROL) && \
+		!defined(CONFIG_SPL_BUILD)
+	if (fdtdec_get_config_int(gd->fdt_blob, "silent_console", 0))
+		gd->flags |= GD_FLG_SILENT;
+#endif
+
+	if (!config.enabled)
+		return 0;
+
 	/* reset and enable FIFOs, set triggers to the maximum */
 	writel(0, &uart->ufcon);
 	writel(0, &uart->umcon);
@@ -129,6 +154,9 @@  int serial_getc_dev(const int dev_index)
 {
 	struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
 
+	if (!config.enabled)
+		return 0;
+
 	/* wait for character to arrive */
 	while (!(readl(&uart->utrstat) & 0x1)) {
 		if (serial_err_check(dev_index, 0))
@@ -145,6 +173,9 @@  void serial_putc_dev(const char c, const int dev_index)
 {
 	struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
 
+	if (!config.enabled)
+		return;
+
 	/* wait for room in the tx FIFO */
 	while (!(readl(&uart->utrstat) & 0x2)) {
 		if (serial_err_check(dev_index, 1))
@@ -165,6 +196,9 @@  int serial_tstc_dev(const int dev_index)
 {
 	struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
 
+	if (!config.enabled)
+		return 0;
+
 	return (int)(readl(&uart->utrstat) & 0x1);
 }
 
@@ -207,8 +241,51 @@  DECLARE_S5P_SERIAL_FUNCTIONS(3);
 struct serial_device s5p_serial3_device =
 	INIT_S5P_SERIAL_STRUCTURE(3, "s5pser3");
 
+#ifdef CONFIG_OF_CONTROL
+int fdtdec_decode_console(int *index, struct fdt_serial *uart)
+{
+	const void *blob = gd->fdt_blob;
+	int node;
+
+	node = fdt_path_offset(blob, "console");
+	if (node < 0)
+		return node;
+
+	uart->base_addr = fdtdec_get_addr(blob, node, "reg");
+	if (uart->base_addr == FDT_ADDR_T_NONE)
+		return -FDT_ERR_NOTFOUND;
+
+	uart->port_id = fdtdec_get_int(blob, node, "id", -1);
+	uart->enabled = fdtdec_get_is_enabled(blob, node);
+
+	return 0;
+}
+#endif
+
 __weak struct serial_device *default_serial_console(void)
 {
+#ifdef CONFIG_OF_CONTROL
+	int index = 0;
+
+	if ((!config.base_addr) && (fdtdec_decode_console(&index, &config))) {
+		debug("Cannot decode default console node\n");
+		return NULL;
+	}
+
+	if (config.port_id == 0)
+		return &s5p_serial0_device;
+	else if (config.port_id == 1)
+		return &s5p_serial1_device;
+	else if (config.port_id == 2)
+		return &s5p_serial2_device;
+	else if (config.port_id == 3)
+		return &s5p_serial3_device;
+	else
+		debug("Unknown config.port_id: %d", config.port_id);
+
+	return NULL;
+#else
+	config.enabled = 1;
 #if defined(CONFIG_SERIAL0)
 	return &s5p_serial0_device;
 #elif defined(CONFIG_SERIAL1)
@@ -220,6 +297,7 @@  __weak struct serial_device *default_serial_console(void)
 #else
 #error "CONFIG_SERIAL? missing."
 #endif
+#endif
 }
 
 void s5p_serial_initialize(void)