Re: [PATCH 03/31] nds32: Support early_printk

2017-11-08 Thread Greentime Hu
2017-11-08 17:47 GMT+08:00 Tobias Klauser :
> On 2017-11-08 at 06:54:51 +0100, Greentime Hu  wrote:
>> From: Greentime Hu 
>>
>> Signed-off-by: Rick Chen 
>> Signed-off-by: Greentime Hu 
>> ---
>>  arch/nds32/kernel/early_printk.c |  124 
>> ++
>>  1 file changed, 124 insertions(+)
>>  create mode 100644 arch/nds32/kernel/early_printk.c
>>
>> diff --git a/arch/nds32/kernel/early_printk.c 
>> b/arch/nds32/kernel/early_printk.c
>> new file mode 100644
>> index 000..269c3cd
>> --- /dev/null
>> +++ b/arch/nds32/kernel/early_printk.c
>
> Could be implemented using earlycon (the 8250 drivers already supports
> it) instead of duplicating functionality in arch/nds32?  See e.g. the
> nios2 port for how this could be done, specifically commit e118c3fec9c0
> ("nios2: remove custom early console implementation").

Thanks.
I will try to use earlycon in the next version patch.
I will remove this patch if earlycon is able to be used in nds32.


Re: [PATCH 03/31] nds32: Support early_printk

2017-11-08 Thread Greentime Hu
2017-11-08 17:47 GMT+08:00 Tobias Klauser :
> On 2017-11-08 at 06:54:51 +0100, Greentime Hu  wrote:
>> From: Greentime Hu 
>>
>> Signed-off-by: Rick Chen 
>> Signed-off-by: Greentime Hu 
>> ---
>>  arch/nds32/kernel/early_printk.c |  124 
>> ++
>>  1 file changed, 124 insertions(+)
>>  create mode 100644 arch/nds32/kernel/early_printk.c
>>
>> diff --git a/arch/nds32/kernel/early_printk.c 
>> b/arch/nds32/kernel/early_printk.c
>> new file mode 100644
>> index 000..269c3cd
>> --- /dev/null
>> +++ b/arch/nds32/kernel/early_printk.c
>
> Could be implemented using earlycon (the 8250 drivers already supports
> it) instead of duplicating functionality in arch/nds32?  See e.g. the
> nios2 port for how this could be done, specifically commit e118c3fec9c0
> ("nios2: remove custom early console implementation").

Thanks.
I will try to use earlycon in the next version patch.
I will remove this patch if earlycon is able to be used in nds32.


Re: [PATCH 03/31] nds32: Support early_printk

2017-11-08 Thread Tobias Klauser
On 2017-11-08 at 06:54:51 +0100, Greentime Hu  wrote:
> From: Greentime Hu 
> 
> Signed-off-by: Rick Chen 
> Signed-off-by: Greentime Hu 
> ---
>  arch/nds32/kernel/early_printk.c |  124 
> ++
>  1 file changed, 124 insertions(+)
>  create mode 100644 arch/nds32/kernel/early_printk.c
> 
> diff --git a/arch/nds32/kernel/early_printk.c 
> b/arch/nds32/kernel/early_printk.c
> new file mode 100644
> index 000..269c3cd
> --- /dev/null
> +++ b/arch/nds32/kernel/early_printk.c

Could be implemented using earlycon (the 8250 drivers already supports
it) instead of duplicating functionality in arch/nds32?  See e.g. the
nios2 port for how this could be done, specifically commit e118c3fec9c0
("nios2: remove custom early console implementation").


Re: [PATCH 03/31] nds32: Support early_printk

2017-11-08 Thread Tobias Klauser
On 2017-11-08 at 06:54:51 +0100, Greentime Hu  wrote:
> From: Greentime Hu 
> 
> Signed-off-by: Rick Chen 
> Signed-off-by: Greentime Hu 
> ---
>  arch/nds32/kernel/early_printk.c |  124 
> ++
>  1 file changed, 124 insertions(+)
>  create mode 100644 arch/nds32/kernel/early_printk.c
> 
> diff --git a/arch/nds32/kernel/early_printk.c 
> b/arch/nds32/kernel/early_printk.c
> new file mode 100644
> index 000..269c3cd
> --- /dev/null
> +++ b/arch/nds32/kernel/early_printk.c

Could be implemented using earlycon (the 8250 drivers already supports
it) instead of duplicating functionality in arch/nds32?  See e.g. the
nios2 port for how this could be done, specifically commit e118c3fec9c0
("nios2: remove custom early console implementation").


[PATCH 03/31] nds32: Support early_printk

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/kernel/early_printk.c |  124 ++
 1 file changed, 124 insertions(+)
 create mode 100644 arch/nds32/kernel/early_printk.c

diff --git a/arch/nds32/kernel/early_printk.c b/arch/nds32/kernel/early_printk.c
new file mode 100644
index 000..269c3cd
--- /dev/null
+++ b/arch/nds32/kernel/early_printk.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+extern void __iomem *early_io_map(phys_addr_t phys);
+static void __iomem *early_base;
+static void (*printch) (char ch);
+
+/*
+ * 8250/16550 (8-bit aligned registers) single character TX.
+ */
+static void uart8250_8bit_printch(char ch)
+{
+   while (!(readb(early_base + UART_LSR) & UART_LSR_THRE)) ;
+   writeb(ch, early_base + UART_TX);
+}
+
+/*
+ * 8250/16550 (32-bit aligned registers) single character TX.
+ */
+static void uart8250_32bit_printch(char ch)
+{
+   while (!(readl(early_base + (UART_LSR << 2)) & UART_LSR_THRE)) ;
+   writel(ch, early_base + (UART_TX << 2));
+}
+
+struct earlycon_match {
+   const char *name;
+   void (*printch) (char ch);
+};
+
+static const struct earlycon_match earlycon_match[] __initconst = {
+   {.name = "uart8250-8bit",.printch = uart8250_8bit_printch,},
+   {.name = "uart8250-32bit",.printch = uart8250_32bit_printch,},
+   {}
+};
+
+static void early_write(struct console *con, const char *s, unsigned n)
+{
+   while (n-- > 0) {
+   if (*s == '\n')
+   printch('\r');
+   printch(*s);
+   s++;
+   }
+}
+
+static struct console early_console_dev = {
+   .name = "earlycon",
+   .write = early_write,
+   .flags = CON_PRINTBUFFER | CON_BOOT,
+   .index = -1,
+};
+
+/*
+ * Parse earlyprintk=... parameter in the format:
+ *
+ *   [,][,]
+ *
+ * and register the early console. It is assumed that the UART has been
+ * initialised by the bootloader already.
+ */
+static int __init setup_early_printk(char *buf)
+{
+   const struct earlycon_match *match = earlycon_match;
+   phys_addr_t paddr = 0;
+
+   if (!buf) {
+   pr_warning("No earlyprintk arguments passed.\n");
+   return 0;
+   }
+
+   while (match->name) {
+   size_t len = strlen(match->name);
+   if (!strncmp(buf, match->name, len)) {
+   buf += len;
+   break;
+   }
+   match++;
+   }
+   if (!match->name) {
+   pr_warning("Unknown earlyprintk arguments: %s\n", buf);
+   return 0;
+   }
+
+   /* I/O address */
+   if (!strncmp(buf, ",0x", 3)) {
+   char *e;
+   paddr = simple_strtoul(buf + 1, , 16);
+   buf = e;
+   }
+
+   if (paddr)
+   early_base = early_io_map(paddr);
+
+   if (!strcmp(CONFIG_NDS32_BUILTIN_DTB, "ae3xx"))
+   early_base += 32;
+
+   printch = match->printch;
+   register_console(_console_dev);
+
+   return 0;
+}
+
+early_param("earlyprintk", setup_early_printk);
-- 
1.7.9.5



[PATCH 03/31] nds32: Support early_printk

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/kernel/early_printk.c |  124 ++
 1 file changed, 124 insertions(+)
 create mode 100644 arch/nds32/kernel/early_printk.c

diff --git a/arch/nds32/kernel/early_printk.c b/arch/nds32/kernel/early_printk.c
new file mode 100644
index 000..269c3cd
--- /dev/null
+++ b/arch/nds32/kernel/early_printk.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+extern void __iomem *early_io_map(phys_addr_t phys);
+static void __iomem *early_base;
+static void (*printch) (char ch);
+
+/*
+ * 8250/16550 (8-bit aligned registers) single character TX.
+ */
+static void uart8250_8bit_printch(char ch)
+{
+   while (!(readb(early_base + UART_LSR) & UART_LSR_THRE)) ;
+   writeb(ch, early_base + UART_TX);
+}
+
+/*
+ * 8250/16550 (32-bit aligned registers) single character TX.
+ */
+static void uart8250_32bit_printch(char ch)
+{
+   while (!(readl(early_base + (UART_LSR << 2)) & UART_LSR_THRE)) ;
+   writel(ch, early_base + (UART_TX << 2));
+}
+
+struct earlycon_match {
+   const char *name;
+   void (*printch) (char ch);
+};
+
+static const struct earlycon_match earlycon_match[] __initconst = {
+   {.name = "uart8250-8bit",.printch = uart8250_8bit_printch,},
+   {.name = "uart8250-32bit",.printch = uart8250_32bit_printch,},
+   {}
+};
+
+static void early_write(struct console *con, const char *s, unsigned n)
+{
+   while (n-- > 0) {
+   if (*s == '\n')
+   printch('\r');
+   printch(*s);
+   s++;
+   }
+}
+
+static struct console early_console_dev = {
+   .name = "earlycon",
+   .write = early_write,
+   .flags = CON_PRINTBUFFER | CON_BOOT,
+   .index = -1,
+};
+
+/*
+ * Parse earlyprintk=... parameter in the format:
+ *
+ *   [,][,]
+ *
+ * and register the early console. It is assumed that the UART has been
+ * initialised by the bootloader already.
+ */
+static int __init setup_early_printk(char *buf)
+{
+   const struct earlycon_match *match = earlycon_match;
+   phys_addr_t paddr = 0;
+
+   if (!buf) {
+   pr_warning("No earlyprintk arguments passed.\n");
+   return 0;
+   }
+
+   while (match->name) {
+   size_t len = strlen(match->name);
+   if (!strncmp(buf, match->name, len)) {
+   buf += len;
+   break;
+   }
+   match++;
+   }
+   if (!match->name) {
+   pr_warning("Unknown earlyprintk arguments: %s\n", buf);
+   return 0;
+   }
+
+   /* I/O address */
+   if (!strncmp(buf, ",0x", 3)) {
+   char *e;
+   paddr = simple_strtoul(buf + 1, , 16);
+   buf = e;
+   }
+
+   if (paddr)
+   early_base = early_io_map(paddr);
+
+   if (!strcmp(CONFIG_NDS32_BUILTIN_DTB, "ae3xx"))
+   early_base += 32;
+
+   printch = match->printch;
+   register_console(_console_dev);
+
+   return 0;
+}
+
+early_param("earlyprintk", setup_early_printk);
-- 
1.7.9.5