Skip to contentSkip to conversation

MIPS: loongson1: enable to run from spi flash

PATCH New Du Huanpeng 2 participants 7 messages Sep 11, 2020 – Sep 25, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: loongson1: enable to run from spi flash

initial pll, ddr2 controller, calculate perscale divisor for uart.

---
 arch/mips/boards/loongson-ls1b/lowlevel.S          |  33 ++++-
 arch/mips/mach-loongson/include/mach/debug_ll.h    |   1 +
 .../include/mach/debug_ll_loongson1.h              |  15 ++
 .../include/mach/pbl_ll_init_loongson1.h           | 162 +++++++++++++++++++++
 arch/mips/mach-loongson/include/mach/pbl_macros.h  |  81 +++++++++++
 5 files changed, 291 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/mach-loongson/include/mach/debug_ll_loongson1.h
 create mode 100644 arch/mips/mach-loongson/include/mach/pbl_ll_init_loongson1.h
 create mode 100644 arch/mips/mach-loongson/include/mach/pbl_macros.h
arch/mips/boards/loongson-ls1b/lowlevel.S +32 -1
index c533df3..af6ad54 100644
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * Copyright (C) 2014 Antony Pavlov <[email protected]>
+ * Copyright (C) 2020 Du Huanpeng <[email protected]>
  */
 
 #define BOARD_PBL_START start_loongson_ls1b
@@ -11,15 +12,45 @@
 #include <asm/pbl_nmon.h>
 #include <linux/sizes.h>
 
+#include <mach/pbl_macros.h>
+#include <mach/pbl_ll_init_loongson1.h>
+
+
 ENTRY_FUNCTION(BOARD_PBL_START)
 
 	mips_barebox_10h
 
 	mips_disable_interrupts
 
-	debug_ll_ns16550_init
+	pbl_blt 0xbf000000 168f t0
 
+	pbl_loongson1_pll
+
+	pbl_loongson1_uart_enable
+	pbl_loongson1_calc_prescale 115200
+	move	a0, v0
+	debug_ll_ns16550_init
+	debug_ll_ns16550_outnl
 	debug_ll_outc '.'
 	debug_ll_ns16550_outnl
+	debug_ll_outc '1'
+
+	pbl_loongson1_remap
+	debug_ll_outc '2'
+
+	pbl_loongson1_ddr2_init
+	pbl_probe_mem t0, t1, KSEG1
+	bne     t0, t1, .
+	nop
+
+	debug_ll_outc '3'
+
+	mips_cache_reset
+	dcache_enable
+	debug_ll_outc '4'
+
+168:
+	debug_ll_outc '5'
+	debug_ll_ns16550_outnl
 
 ENTRY_FUNCTION_END(BOARD_PBL_START, loongson_ls1b, SZ_64M)
arch/mips/mach-loongson/include/mach/debug_ll.h +1 -0
index c2d6edb..39d791a 100644
@@ -9,6 +9,7 @@
 /** @file
  *  This File contains declaration for early output support
  */
+#include <mach/debug_ll_loongson1.h>
 #include <asm/debug_ll_ns16550.h>
 
 #endif /* __MACH_LOONGSON_DEBUG_LL__ */
arch/mips/mach-loongson/include/mach/debug_ll_loongson1.h new file +15 -0
new file mode 100644
index 0000000..6043690
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2020 Du Huanpeng <[email protected]>
+ */
+
+#ifndef __INCLUDE_DEBUG_LL_LOONGSON1_H__
+#define __INCLUDE_DEBUG_LL_LOONGSON1_H__
+
+#include <mach/loongson1.h>
+
+#define DEBUG_LL_UART_ADDR	0xBFE48000
+#define DEBUG_LL_UART_SHIFT	0
+#define DEBUG_LL_UART_DIVISOR	0
+
+#endif /* __INCLUDE_DEBUG_LL_LOONGSON1_H__ */
arch/mips/mach-loongson/include/mach/pbl_ll_init_loongson1.h new file +162 -0

162 lines not on this page · raw message

arch/mips/mach-loongson/include/mach/pbl_macros.h new file +81 -0

81 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/1 MIPS: DEBUG_LL_UART_DIVISOR is 0, use a0 instead

this make it possiable pass a0 as divisor to calculate uart baudrate in run time on boot.

---
 arch/mips/include/asm/debug_ll_ns16550.h | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/include/asm/debug_ll_ns16550.h +3 -0
index df58c4c..a33587a 100644
@@ -66,6 +66,9 @@ static inline void PUTC_LL(char ch)
 	sb	t1, UART_LCR(t0)		/* Write it out */
 
 	li	t1, DEBUG_LL_UART_DIVISOR
+#if DEBUG_LL_UART_DIVISOR == 0
+	move	t1, a0
+#endif
 	sb	t1, UART_DLL(t0)		/* write low order byte */
 	srl	t1, t1, 8
 	sb	t1, UART_DLM(t0)		/* write high order byte */
Signature · 7 lines
2.7.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Re: [PATCH] MIPS: DEBUG_LL_UART_DIVISOR is 0, use a0 instead

Quoted 2 lines · Du Huanpeng

this make it possiable pass a0 as divisor to calculate uart baudrate in run time on boot.

This is not Ok. Your last commit has your board pass the divisor in a0 now, but other boards, like the netgear-wg102, don't. Your change might break their UART because the code there doesn't expect that a0 needs to have a valid value. If you want to do this, you should migrate all users of this function all at once to supply a valid divisor (probably move a0, DEBUG_LL_UART_DIVISOR).

It's same thing in C. You don't add a new parameter to a function without checking that all callsites handle this correctly.

Quoted 21 lines
---
 arch/mips/include/asm/debug_ll_ns16550.h | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/include/asm/debug_ll_ns16550.h +3 -0
index df58c4c..a33587a 100644
@@ -66,6 +66,9 @@ static inline void PUTC_LL(char ch)
 	sb	t1, UART_LCR(t0)		/* Write it out */
 
 	li	t1, DEBUG_LL_UART_DIVISOR
+#if DEBUG_LL_UART_DIVISOR == 0
+	move	t1, a0
+#endif
 	sb	t1, UART_DLL(t0)		/* write low order byte */
 	srl	t1, t1, 8
 	sb	t1, UART_DLM(t0)		/* write high order byte */
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH] MIPS: DEBUG_LL_UART_DIVISOR is 0, use a0 instead

Hi, this patch should not intoduce any regression to existing boards, because:

1. pass divisor by DEBUG_LL_UART_DIVISOR

#define DEBUG_LL_UART_DIVISOR NUMBER

which the ``NUMBER'' is not ``0'' (zero). In this case, this patch has no effect and this line of code will be removed by preprocessor, before compile :)
move t1, a0

2. Pass divisor by a0

#define DEBUG_LL_UART_DIVISOR 0

recalculate the divisor is needed when the pll/div setting is changed outside of barebox. e.g. ejtag. and load barebox and run in ram.

Because 0 maybe an invalid value for a divisor, so I take this value for a hint to pass a0 as divisor. this will not conflict with other boards which pass divisor by defining DEBUG_LL_UART_DIVISOR with a valied value.

Quoted 2 lines

you should migrate all users of this function all at once to supply a valid divisor (probably move a0, DEBUG_LL_UART_DIVISOR).

MIPS use ``li'' load immediate, and move to copy inter registers. so, maybe change my patch to:

#if DEBUG_LL_UART_DIVISOR
li t1, DEBUG_LL_UART_DIVISOR

#else
	move	t1, a0

#endif

- - -
or even do a bit tricky:

arch/mips/include/asm/debug_ll_ns16550.h +1 -1
@@ -65,7 +65,7 @@ static inline void PUTC_LL(char ch)
 	li	t1, UART_LCR_DLAB		/* DLAB on */
 	sb	t1, UART_LCR(t0)		/* Write it out */
 
-	li	t1, DEBUG_LL_UART_DIVISOR
+	add	t1, zero, DEBUG_LL_UART_DIVISOR
 	sb	t1, UART_DLL(t0)		/* write low order byte */
 	srl	t1, t1, 8
 	sb	t1, UART_DLM(t0)		/* write high order byte */
Signature · 5 lines
2.7.4

this will allow to pass divisor by a number or a register.
add is a pseudo insertion can be compile to addi or add depends
on the DEBUG_LL_UART_DIVISOR is a number or a register.
Quoted 26 lines · Ahmad Fatoum
Quoted 2 lines · Du Huanpeng

this make it possiable pass a0 as divisor to calculate uart baudrate in run time on boot.

This is not Ok. Your last commit has your board pass the divisor in a0 now, but other boards, like the netgear-wg102, don't. Your change might break their UART because the code there doesn't expect that a0 needs to have a valid value. If you want to do this, you should migrate all users of this function all at once to supply a valid divisor (probably move a0, DEBUG_LL_UART_DIVISOR).

It's same thing in C. You don't add a new parameter to a function without checking that all callsites handle this correctly.

Quoted 13 lines
---
 arch/mips/include/asm/debug_ll_ns16550.h | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/include/asm/debug_ll_ns16550.h +0 -0
index df58c4c..a33587a 100644
@@ -66,6 +66,9 @@ static inline void PUTC_LL(char ch)
 	sb	t1, UART_LCR(t0)		/* Write it out */
 
Quoted 14 lines
Quoted 8 lines
arch/mips/include/asm/debug_ll_ns16550.h +3 -0
 	li	t1, DEBUG_LL_UART_DIVISOR
+#if DEBUG_LL_UART_DIVISOR == 0
+	move	t1, a0
+#endif
 	sb	t1, UART_DLL(t0)		/* write low order byte */
 	srl	t1, t1, 8
 	sb	t1, UART_DLM(t0)		/* write high order byte */
Signature · 4 lines
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 |

Regards,
duhuanpeng

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH] MIPS: DEBUG_LL_UART_DIVISOR is 0, use a0 instead

Hello,

Quoted 14 lines · Du Huanpeng

Hi, this patch should not intoduce any regression to existing boards, because:

1. pass divisor by DEBUG_LL_UART_DIVISOR

#define DEBUG_LL_UART_DIVISOR NUMBER

which the ``NUMBER'' is not ``0'' (zero). In this case, this patch has no effect and this line of code will be removed by preprocessor, before compile :)
move t1, a0

2. Pass divisor by a0

Quoted 8 lines

#define DEBUG_LL_UART_DIVISOR 0

recalculate the divisor is needed when the pll/div setting is changed outside of barebox. e.g. ejtag. and load barebox and run in ram.

Because 0 maybe an invalid value for a divisor, so I take this value for a hint to pass a0 as divisor. this will not conflict with other boards which pass divisor by defining DEBUG_LL_UART_DIVISOR with a valied value.

I guess we can agree that

debug_ll_ns16550_init(
#if DEBUG_LL_UART_DIVISOR
int a0
#endif
);

is not the best way to go about it, so why do its equivalent in assembly?

Quoted 11 lines
Quoted 2 lines

you should migrate all users of this function all at once to supply a valid divisor (probably move a0, DEBUG_LL_UART_DIVISOR).

MIPS use ``li'' load immediate, and move to copy inter registers. so, maybe change my patch to:

#if DEBUG_LL_UART_DIVISOR
li t1, DEBUG_LL_UART_DIVISOR

#else
	move	t1, a0

#endif

I'd prefer you keep it as move t1, a0 without an ifdef and move the argument passing out of debug_ll_ns16550_init.

Cheers
Ahmad

Quoted 16 lines

- - -
or even do a bit tricky:

arch/mips/include/asm/debug_ll_ns16550.h +1 -1
@@ -65,7 +65,7 @@ static inline void PUTC_LL(char ch)
 	li	t1, UART_LCR_DLAB		/* DLAB on */
 	sb	t1, UART_LCR(t0)		/* Write it out */
 
-	li	t1, DEBUG_LL_UART_DIVISOR
+	add	t1, zero, DEBUG_LL_UART_DIVISOR
 	sb	t1, UART_DLL(t0)		/* write low order byte */
 	srl	t1, t1, 8
 	sb	t1, UART_DLM(t0)		/* write high order byte */
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH] MIPS: DEBUG_LL_UART_DIVISOR is 0, use a0 instead

Hi, How about this, I send this for review, if it is ok, I will send a patch later.

I add a argument to the macro, and set a default parameter.

+.macro debug_ll_ns16550_init divisor=DEBUG_LL_UART_DIVISOR

+ /* three forms for ``call'' the macro */
pass a register name
+ debug_ll_ns16550_init v0

pass a immediate number
+ debug_ll_ns16550_init 888

use this macro as usual before
+ debug_ll_ns16550_init

----8<-----

arch/mips/boards/loongson-ls1b/lowlevel.S +7 -1
index af6ad54e1..7120d80ef 100644
@@ -28,8 +28,14 @@ ENTRY_FUNCTION(BOARD_PBL_START)
 
 	pbl_loongson1_uart_enable
 	pbl_loongson1_calc_prescale 115200
-	move	a0, v0
+
+	/* three forms for ``call'' the macro */
+	debug_ll_ns16550_init v0
+	debug_ll_ns16550_init 888
+	debug_ll_ns16550_init
+
 	debug_ll_ns16550_init
+
 	debug_ll_ns16550_outnl
 	debug_ll_outc '.'
 	debug_ll_ns16550_outnl
arch/mips/include/asm/debug_ll_ns16550.h +2 -5
index a33587a15..44f3d5976 100644
@@ -58,17 +58,14 @@ static inline void PUTC_LL(char ch)
  * Macros for use in assembly language code
  */
 
-.macro	debug_ll_ns16550_init
+.macro	debug_ll_ns16550_init divisor=DEBUG_LL_UART_DIVISOR
 #ifdef CONFIG_DEBUG_LL
 	la	t0, DEBUG_LL_UART_ADDR
 
 	li	t1, UART_LCR_DLAB		/* DLAB on */
 	sb	t1, UART_LCR(t0)		/* Write it out */
 
-	li	t1, DEBUG_LL_UART_DIVISOR
-#if DEBUG_LL_UART_DIVISOR == 0
-	move	t1, a0
-#endif
+	add	t1, zero, \divisor
 	sb	t1, UART_DLL(t0)		/* write low order byte */
 	srl	t1, t1, 8
 	sb	t1, UART_DLM(t0)		/* write high order byte */

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw

Re: [PATCH] MIPS: DEBUG_LL_UART_DIVISOR is 0, use a0 instead

Hello Du,

Quoted 6 lines · Du Huanpeng

Hi, How about this, I send this for review, if it is ok, I will send a patch later.

I add a argument to the macro, and set a default parameter.

+.macro debug_ll_ns16550_init divisor=DEBUG_LL_UART_DIVISOR

Sounds great! Much less error prone IMO.

Quoted 59 lines
arch/mips/boards/loongson-ls1b/lowlevel.S +1 -0
+	/* three forms for ``call'' the macro */

pass a register name

arch/mips/boards/loongson-ls1b/lowlevel.S +1 -0
+	debug_ll_ns16550_init v0

pass a immediate number

arch/mips/boards/loongson-ls1b/lowlevel.S +1 -0
+	debug_ll_ns16550_init 888

use this macro as usual before

(quoted diff) +1 -1
+	debug_ll_ns16550_init
 
----8<-----
arch/mips/boards/loongson-ls1b/lowlevel.S +7 -1
index af6ad54e1..7120d80ef 100644
@@ -28,8 +28,14 @@ ENTRY_FUNCTION(BOARD_PBL_START)
 
 	pbl_loongson1_uart_enable
 	pbl_loongson1_calc_prescale 115200
-	move	a0, v0
+
+	/* three forms for ``call'' the macro */
+	debug_ll_ns16550_init v0
+	debug_ll_ns16550_init 888
+	debug_ll_ns16550_init
+
 	debug_ll_ns16550_init
+
 	debug_ll_ns16550_outnl
 	debug_ll_outc '.'
 	debug_ll_ns16550_outnl
arch/mips/include/asm/debug_ll_ns16550.h +2 -5
index a33587a15..44f3d5976 100644
@@ -58,17 +58,14 @@ static inline void PUTC_LL(char ch)
  * Macros for use in assembly language code
  */
 
-.macro	debug_ll_ns16550_init
+.macro	debug_ll_ns16550_init divisor=DEBUG_LL_UART_DIVISOR
 #ifdef CONFIG_DEBUG_LL
 	la	t0, DEBUG_LL_UART_ADDR
 
 	li	t1, UART_LCR_DLAB		/* DLAB on */
 	sb	t1, UART_LCR(t0)		/* Write it out */
 
-	li	t1, DEBUG_LL_UART_DIVISOR
-#if DEBUG_LL_UART_DIVISOR == 0
-	move	t1, a0
-#endif
+	add	t1, zero, \divisor
 	sb	t1, UART_DLL(t0)		/* write low order byte */
 	srl	t1, t1, 8
 	sb	t1, UART_DLM(t0)		/* write high order byte */
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox