arch: mips: ralink: add tty detection
Subsystems (2)
PATCH v2 4/9 arch: mips: ralink: add tty detection
MT7688 has several uarts that can be used for console. There are several boards in the wild, that use ttyS1 or ttyS2. This patch applies a simply autodetection routine to figure out which ttyS the bootloader used as console. The uarts come up in 6 bit mode by default. The bootloader will have set 8 bit mode on the console. Find that 8bit tty and use it.
---
Changes in V2:
* remove superflous inline definition
arch/mips/ralink/early_printk.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
arch/mips/ralink/early_printk.c +26 -0
@@ -25,11 +25,13 @@#define MT7628_CHIP_NAME1 0x20203832#define UART_REG_TX 0x04 +#define UART_REG_LCR 0x0c#define UART_REG_LSR 0x14#define UART_REG_LSR_RT2880 0x1cstatic __iomem void *uart_membase = (__iomem void *)KSEG1ADDR (EARLY_UART_BASE );static __iomem void *chipid_membase = (__iomem void *)KSEG1ADDR (CHIPID_BASE ); +static int init_complete;static inline void uart_w32 (u32 val,unsigned reg) {
@@ -47,8 +49,32 @@ static inline int soc_is_mt7628(void) (__raw_readl (chipid_membase) ==MT7628_CHIP_NAME1 ); } +static void find_uart_base (void ) +{ +int i; + +if (!soc_is_mt7628 ()) +return ; + +for (i =0 ; i <3 ; i++) { +u32 reg =uart_r32 (UART_REG_LCR + (0x100 * i)); + +if (!reg) +continue ; + + uart_membase = (__iomem void *)KSEG1ADDR (EARLY_UART_BASE + + (0x100 * i)); +break ; + } +} +void prom_putchar (unsigned char ch) { +if (!init_complete) { +find_uart_base (); + init_complete =1 ; + } +if (IS_ENABLED (CONFIG_SOC_MT7621 ) ||soc_is_mt7628 ()) {uart_w32 (ch,UART_TX );while ((uart_r32 (UART_REG_LSR ) &UART_LSR_THRE ) ==0 )
Signature · 1 line
1.7.10.4
Hello.
Quoted 18 lines · John Crispin
MT7688 has several uarts that can be used for console. There are several boards in the wild, that use ttyS1 or ttyS2. This patch applies a simply autodetection routine to figure out which ttyS the bootloader used as console. The uarts come up in 6 bit mode by default. The bootloader will have set 8 bit mode on the console. Find that 8bit tty and use it.
Signed-off-by John Crispin <[email protected]>---
Changes in V2:
* remove superflous inline definitionarch/mips/ralink/early_printk.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)arch/mips/ralink/early_printk.c +0
-0
[...]
arch/mips/ralink/early_printk.c static inline int soc_is_mt7628(void) · line 60
Quoted 13 lines
arch/mips/ralink/early_printk.c +9
-0@@ -47,8 +49,32 @@ static inline int soc_is_mt7628(void) (__raw_readl (chipid_membase) ==MT7628_CHIP_NAME1 ); } +static void find_uart_base (void ) +{ +int i; + +if (!soc_is_mt7628 ()) +return ; + +for (i =0 ; i <3 ; i++) { +u32 reg =uart_r32 (UART_REG_LCR + (0x100 * i));
Inner parens not needed, the operator precedence is natural.
arch/mips/ralink/early_printk.c static inline int soc_is_mt7628(void) · line 66
Quoted 6 lines
arch/mips/ralink/early_printk.c +6
-0+ +if (!reg) +continue ; + + uart_membase = (__iomem void *)KSEG1ADDR (EARLY_UART_BASE + + (0x100 * i));
Likewise.
Sorry for not noticing this before.
MBR, Sergei
John Crispin
maintainerHi,
Quoted 28 lines · Sergei Shtylyov
Hello.
Quoted 19 lines · John Crispin
MT7688 has several uarts that can be used for console. There are several boards in the wild, that use ttyS1 or ttyS2. This patch applies a simply autodetection routine to figure out which ttyS the bootloader used as console. The uarts come up in 6 bit mode by default. The bootloader will have set 8 bit mode on the console. Find that 8bit tty and use it.
Signed-off-by John Crispin <[email protected]>---
Changes in V2:
* remove superflous inline definitionarch/mips/ralink/early_printk.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)arch/mips/ralink/early_printk.c +0
-0[...]
Quoted 4 lines
arch/mips/ralink/early_printk.c +0
-0@@ -47,8 +49,32 @@ static inline int soc_is_mt7628(void) (__raw_readl (chipid_membase) ==MT7628_CHIP_NAME1 ); }
Quoted 12 lines
arch/mips/ralink/early_printk.c static inline int soc_is_mt7628(void) · line 60
Quoted 9 lines
arch/mips/ralink/early_printk.c +9
-0+static void find_uart_base (void ) +{ +int i; + +if (!soc_is_mt7628 ()) +return ; + +for (i =0 ; i <3 ; i++) { +u32 reg =uart_r32 (UART_REG_LCR + (0x100 * i));Inner parens not needed, the operator precedence is natural.
"not needed" means "should be removed" or "not needed".
checkpatch.pl certainly did not complain and a quick look around instantly yielded lots of places in the kernel where this is done. imho the brackets make it more readable
John
Quoted 13 lines
arch/mips/ralink/early_printk.c static inline int soc_is_mt7628(void) · line 66
Quoted 6 lines
arch/mips/ralink/early_printk.c +6
-0+ +if (!reg) +continue ; + + uart_membase = (__iomem void *)KSEG1ADDR (EARLY_UART_BASE + + (0x100 * i));Likewise.
Sorry for not noticing this before.MBR, Sergei
Quoted 37 lines · John Crispin
Quoted 24 lines
Quoted 19 lines
MT7688 has several uarts that can be used for console. There are several boards in the wild, that use ttyS1 or ttyS2. This patch applies a simply autodetection routine to figure out which ttyS the bootloader used as console. The uarts come up in 6 bit mode by default. The bootloader will have set 8 bit mode on the console. Find that 8bit tty and use it.
Signed-off-by John Crispin <[email protected]>---
Changes in V2:
* remove superflous inline definitionarch/mips/ralink/early_printk.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)arch/mips/ralink/early_printk.c +0
-0[...]
Quoted 4 lines
arch/mips/ralink/early_printk.c +0
-0@@ -47,8 +49,32 @@ static inline int soc_is_mt7628(void) (__raw_readl (chipid_membase) ==MT7628_CHIP_NAME1 ); }Quoted 12 lines
arch/mips/ralink/early_printk.c static inline int soc_is_mt7628(void) · line 60
Quoted 9 lines
arch/mips/ralink/early_printk.c +9
-0+static void find_uart_base (void ) +{ +int i; + +if (!soc_is_mt7628 ()) +return ; + +for (i =0 ; i <3 ; i++) { +u32 reg =uart_r32 (UART_REG_LCR + (0x100 * i));Inner parens not needed, the operator precedence is natural.
Quoted 1 line
"not needed" means "should be removed" or "not needed".
That's completely up to you.
Quoted 3 lines
checkpatch.pl certainly did not complain and a quick look around instantly yielded lots of places in the kernel where this is done. imho the brackets make it more readable
Do you really always write 2 + (3 * 4) when you e.g. use scientific
calculator?
[...]
MBR, Sergei
Quoted 44 lines · Sergei Shtylyov
Quoted 40 lines · John Crispin
Quoted 27 lines
Quoted 22 lines
MT7688 has several uarts that can be used for console. There are several
boards in the wild, that use ttyS1 or ttyS2. This patch applies a simply
autodetection routine to figure out which ttyS the bootloader used as console. The uarts come up in 6 bit mode by default. The bootloader will
have set 8 bit mode on the console. Find that 8bit tty and use it.Signed-off-by John Crispin <[email protected]>---
Changes in V2:
* remove superflous inline definitionarch/mips/ralink/early_printk.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)arch/mips/ralink/early_printk.c +0
-0[...]
Quoted 4 lines
arch/mips/ralink/early_printk.c +0
-0@@ -47,8 +49,32 @@ static inline int soc_is_mt7628(void) (__raw_readl (chipid_membase) ==MT7628_CHIP_NAME1 ); }Quoted 12 lines
arch/mips/ralink/early_printk.c static inline int soc_is_mt7628(void) · line 60
Quoted 9 lines
arch/mips/ralink/early_printk.c +9
-0+static void find_uart_base (void ) +{ +int i; + +if (!soc_is_mt7628 ()) +return ; + +for (i =0 ; i <3 ; i++) { +u32 reg =uart_r32 (UART_REG_LCR + (0x100 * i));Inner parens not needed, the operator precedence is natural.
Quoted 1 line
"not needed" means "should be removed" or "not needed".
Quoted 8 lines
That's completely up to you.
Quoted 3 lines
checkpatch.pl certainly did not complain and a quick look around instantly yielded lots of places in the kernel where this is done. imho the brackets make it more readable
Do you really always write 2 + (3 * 4) when you e.g. use scientific
calculator?
no that would be silly. when using a calculator i know what i am typing. unless there is someone looking over my shoulder i am the only one that needs to understand.
when i write software that others are supposed to read which has "register + (bank * bank offset)" constructs in it then i tend to add brackets.
John
Quoted 4 lines
[...]
MBR, Sergei