Skip to contentSkip to conversation

ns16550: Fix DM serial operation with non-DM SPL

PATCH In review Andre Przywara 3 participants 12 messages Jan 17, 2023 – Jan 18, 2023 Arm/Allwinner sunXi SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ns16550: Fix DM serial operation with non-DM SPL

Commit 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig") moved some NS16550 configuration variables into Kconfig. Among those there is CONFIG_SYS_NS16550_REG_SIZE, which used to be only defined for SPL build runs, but now is always set (thanks for Kconfig). However this breaks the gating logic in ns16550.h, where we *override* this variable for DM build, as we learn this setting from the DT instead.

As a consequence, we did the register shift twice: once when building the register struct (as required for non-DM SPL builds), but then also again in the driver after we parsed the reg-shift DT property.

Change the logic to match what the comment says: only observe CONFIG_SYS_NS16550_REG_SIZE when not using DM, and ignore it otherwise.

This fixes U-Boot proper for all sunxi boards, since they are relying on this driver being build non-DM for the SPL, but DM for U-Boot proper.

Fixes 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig")

---
Hi,

this is admittedly a quick fix, to get sunxi booting again. This whole code around the register access looks somewhat bonkers, to be honest, but at the moment I don't have time to rework this.
Another possible "quicker fix" would be use a separate variable for the register shift, so that we don't have to redefine a Kconfig variable. Another idea would be to get rid of the struct for the registers altogether, to remove the hacks about when to shift.

Cheers,
Andre

 include/ns16550.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/ns16550.h +2 -1
index 243226fc3d9..e9e2aeedd16 100644
@@ -26,11 +26,12 @@
 
 #include <linux/types.h>
 
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif
 
Signature · 1 line
2.25.1
#1 lore raw

include/ns16550.h line 36

Quoted 9 lines · Andre Przywara
include/ns16550.h +2 -1
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif

What if I have DM_SERIAL and a 16550 UART with 32-bit registers? Before 9591b63531fa the register size of 8 was enforced for DM_SERIAL.

#2 lore raw

On Tue, 17 Jan 2023 16:12:54 +0300
Sergei Antonov <[email protected]> wrote:

Hi Sergei,

Quoted 13 lines · Andre Przywara

include/ns16550.h line 36

Quoted 10 lines
include/ns16550.h +2 -1
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif  

What if I have DM_SERIAL and a 16550 UART with 32-bit registers?

So does that break for you?
Because it should still work, I think, since (as the comment says) we just use the struct to get the register *number*. The actual register size is worked out from the DT, and multiplied in later.

Quoted 1 line

Before 9591b63531fa the register size of 8 was enforced for DM_SERIAL.

8? Or 4?
What does your reg-shift DT property say? Is that in your DT?

Cheers,
Andre

#3 lore raw
Quoted 20 lines · Andre Przywara

On Tue, 17 Jan 2023 16:12:54 +0300
Sergei Antonov <[email protected]> wrote:

Hi Sergei,

Quoted 13 lines · Andre Przywara

include/ns16550.h line 36

Quoted 10 lines
include/ns16550.h +2 -1
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif

What if I have DM_SERIAL and a 16550 UART with 32-bit registers?

Quoted 8 lines

So does that break for you?
Because it should still work, I think, since (as the comment says) we just use the struct to get the register *number*. The actual register size is worked out from the DT, and multiplied in later.

Quoted 1 line

Before 9591b63531fa the register size of 8 was enforced for DM_SERIAL.

8? Or 4?

Oh, I meant 8-bit. So under DM_SERIAL:
CONFIG_SYS_NS16550_REG_SIZE is -1
UART_REG(x) is unsigned char x

Quoted 1 line

What does your reg-shift DT property say? Is that in your DT?

I did not have "reg-shift" property. Thanks for telling about it. Now that I have these properties in DT my UART works.
reg-io-width = <4>;
reg-shift = <2>;

I also had to add this config parameter to make debug uart work:
CONFIG_DEBUG_UART_SHIFT=2

Thanks!

#4 lore raw
In reply to Sergei Antonov
Quoted 14 lines · Sergei Antonov

include/ns16550.h line 36

Quoted 9 lines · Andre Przywara
include/ns16550.h +2 -1
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif

What if I have DM_SERIAL and a 16550 UART with 32-bit registers? Before 9591b63531fa the register size of 8 was enforced for DM_SERIAL.

Note that right now, there are some broken cases still, which is why I made:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
but that doesn't fix _this_ case, either. Can you test the above patch on your platform however? Thanks!

Signature · 1 line
Tom
#5 lore raw
In reply to Andre Przywara
Quoted 43 lines · Andre Przywara

Commit 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig") moved some NS16550 configuration variables into Kconfig. Among those there is CONFIG_SYS_NS16550_REG_SIZE, which used to be only defined for SPL build runs, but now is always set (thanks for Kconfig). However this breaks the gating logic in ns16550.h, where we *override* this variable for DM build, as we learn this setting from the DT instead.

As a consequence, we did the register shift twice: once when building the register struct (as required for non-DM SPL builds), but then also again in the driver after we parsed the reg-shift DT property.

Change the logic to match what the comment says: only observe CONFIG_SYS_NS16550_REG_SIZE when not using DM, and ignore it otherwise.

This fixes U-Boot proper for all sunxi boards, since they are relying on this driver being build non-DM for the SPL, but DM for U-Boot proper.

Fixes 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig")

---
Hi,

this is admittedly a quick fix, to get sunxi booting again. This whole code around the register access looks somewhat bonkers, to be honest, but at the moment I don't have time to rework this.
Another possible "quicker fix" would be use a separate variable for the register shift, so that we don't have to redefine a Kconfig variable. Another idea would be to get rid of the struct for the registers altogether, to remove the hacks about when to shift.

Cheers,
Andre

 include/ns16550.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/ns16550.h +0 -0
index 243226fc3d9..e9e2aeedd16 100644
@@ -26,11 +26,12 @@
 
 #include <linux/types.h>

include/ns16550.h line 36

Quoted 10 lines
include/ns16550.h +2 -1
 
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
work for you as well?

Signature · 1 line
Tom
#6 lore raw
Quoted 46 lines · Tom Rini
Quoted 44 lines · Andre Przywara

Commit 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig") moved some NS16550 configuration variables into Kconfig. Among those there is CONFIG_SYS_NS16550_REG_SIZE, which used to be only defined for SPL build runs, but now is always set (thanks for Kconfig). However this breaks the gating logic in ns16550.h, where we *override* this variable for DM build, as we learn this setting from the DT instead.

As a consequence, we did the register shift twice: once when building the register struct (as required for non-DM SPL builds), but then also again in the driver after we parsed the reg-shift DT property.

Change the logic to match what the comment says: only observe CONFIG_SYS_NS16550_REG_SIZE when not using DM, and ignore it otherwise.

This fixes U-Boot proper for all sunxi boards, since they are relying on this driver being build non-DM for the SPL, but DM for U-Boot proper.

Fixes 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig")

---
Hi,

this is admittedly a quick fix, to get sunxi booting again. This whole code around the register access looks somewhat bonkers, to be honest, but at the moment I don't have time to rework this.
Another possible "quicker fix" would be use a separate variable for the register shift, so that we don't have to redefine a Kconfig variable. Another idea would be to get rid of the struct for the registers altogether, to remove the hacks about when to shift.

Cheers,
Andre

 include/ns16550.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/ns16550.h +0 -0
index 243226fc3d9..e9e2aeedd16 100644
@@ -26,11 +26,12 @@
 
 #include <linux/types.h>
 
Quoted 13 lines

include/ns16550.h line 36

Quoted 9 lines
include/ns16550.h +2 -1
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
work for you as well?

This got me to double check why my pine64 wasn't in CI, again, and now I see that no, this patch doesn't solve that case.

Signature · 1 line
Tom
#7 lore raw
In reply to Tom Rini

On Tue, 17 Jan 2023 08:15:18 -0500
Tom Rini <[email protected]> wrote:

Hi Tom,

Quoted 46 lines · Andre Przywara
Quoted 45 lines

Commit 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig") moved some NS16550 configuration variables into Kconfig. Among those there is CONFIG_SYS_NS16550_REG_SIZE, which used to be only defined for SPL build runs, but now is always set (thanks for Kconfig). However this breaks the gating logic in ns16550.h, where we *override* this variable for DM build, as we learn this setting from the DT instead.

As a consequence, we did the register shift twice: once when building the register struct (as required for non-DM SPL builds), but then also again in the driver after we parsed the reg-shift DT property.

Change the logic to match what the comment says: only observe CONFIG_SYS_NS16550_REG_SIZE when not using DM, and ignore it otherwise.

This fixes U-Boot proper for all sunxi boards, since they are relying on this driver being build non-DM for the SPL, but DM for U-Boot proper.

Fixes 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig")

---
Hi,

this is admittedly a quick fix, to get sunxi booting again. This whole code around the register access looks somewhat bonkers, to be honest, but at the moment I don't have time to rework this.
Another possible "quicker fix" would be use a separate variable for the register shift, so that we don't have to redefine a Kconfig variable. Another idea would be to get rid of the struct for the registers altogether, to remove the hacks about when to shift.

Cheers,
Andre

 include/ns16550.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/ns16550.h +0 -0
index 243226fc3d9..e9e2aeedd16 100644
@@ -26,11 +26,12 @@
 
 #include <linux/types.h>
 
Quoted 13 lines

include/ns16550.h line 36

Quoted 9 lines
include/ns16550.h +2 -1
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif  

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
work for you as well?

Unfortunately not. This changed condition there does not trigger for sunxi. If I hack it that it applies, but only to the proper build, it works, though. But I don't feel like adding to this #if even more ;-)

Cheers,
Andre

#8 lore raw
Quoted 65 lines · Andre Przywara

On Tue, 17 Jan 2023 08:15:18 -0500
Tom Rini <[email protected]> wrote:

Hi Tom,

Quoted 46 lines · Andre Przywara
Quoted 45 lines

Commit 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig") moved some NS16550 configuration variables into Kconfig. Among those there is CONFIG_SYS_NS16550_REG_SIZE, which used to be only defined for SPL build runs, but now is always set (thanks for Kconfig). However this breaks the gating logic in ns16550.h, where we *override* this variable for DM build, as we learn this setting from the DT instead.

As a consequence, we did the register shift twice: once when building the register struct (as required for non-DM SPL builds), but then also again in the driver after we parsed the reg-shift DT property.

Change the logic to match what the comment says: only observe CONFIG_SYS_NS16550_REG_SIZE when not using DM, and ignore it otherwise.

This fixes U-Boot proper for all sunxi boards, since they are relying on this driver being build non-DM for the SPL, but DM for U-Boot proper.

Fixes 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig")

---
Hi,

this is admittedly a quick fix, to get sunxi booting again. This whole code around the register access looks somewhat bonkers, to be honest, but at the moment I don't have time to rework this.
Another possible "quicker fix" would be use a separate variable for the register shift, so that we don't have to redefine a Kconfig variable. Another idea would be to get rid of the struct for the registers altogether, to remove the hacks about when to shift.

Cheers,
Andre

 include/ns16550.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/ns16550.h +0 -0
index 243226fc3d9..e9e2aeedd16 100644
@@ -26,11 +26,12 @@
 
 #include <linux/types.h>
 
Quoted 13 lines

include/ns16550.h line 36

Quoted 9 lines
include/ns16550.h +2 -1
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif  

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
work for you as well?

Quoted 3 lines

Unfortunately not. This changed condition there does not trigger for sunxi. If I hack it that it applies, but only to the proper build, it works, though. But I don't feel like adding to this #if even more ;-)

I've got a version that does work, now, on my pine64 plus, and I've asked Quentin to test his Rockchip platform that was also broken, before I post a new version there.

A better long term fix would likely start by seeing which non-DM_SERIAL cases we have, and what they need, still.

Signature · 1 line
Tom
#9 lore raw
Quoted 66 lines · On Tue, 17 Jan 2023 11:14:35 -0500 Tom Rini <[email protected]> wrote:
Quoted 65 lines · Andre Przywara

On Tue, 17 Jan 2023 08:15:18 -0500
Tom Rini <[email protected]> wrote:

Hi Tom,

Quoted 59 lines · Andre Przywara
Quoted 44 lines

Commit 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig") moved some NS16550 configuration variables into Kconfig. Among those there is CONFIG_SYS_NS16550_REG_SIZE, which used to be only defined for SPL build runs, but now is always set (thanks for Kconfig). However this breaks the gating logic in ns16550.h, where we *override* this variable for DM build, as we learn this setting from the DT instead.

As a consequence, we did the register shift twice: once when building the register struct (as required for non-DM SPL builds), but then also again in the driver after we parsed the reg-shift DT property.

Change the logic to match what the comment says: only observe CONFIG_SYS_NS16550_REG_SIZE when not using DM, and ignore it otherwise.

This fixes U-Boot proper for all sunxi boards, since they are relying on this driver being build non-DM for the SPL, but DM for U-Boot proper.

Fixes 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig")

---
Hi,

this is admittedly a quick fix, to get sunxi booting again. This whole code around the register access looks somewhat bonkers, to be honest, but at the moment I don't have time to rework this.
Another possible "quicker fix" would be use a separate variable for the register shift, so that we don't have to redefine a Kconfig variable. Another idea would be to get rid of the struct for the registers altogether, to remove the hacks about when to shift.

Cheers,
Andre

 include/ns16550.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/ns16550.h +0 -0
index 243226fc3d9..e9e2aeedd16 100644
@@ -26,11 +26,12 @@
 
 #include <linux/types.h>

include/ns16550.h line 36

Quoted 10 lines
include/ns16550.h +2 -1
 
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif    

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
work for you as well?

Quoted 7 lines
Quoted 3 lines

Unfortunately not. This changed condition there does not trigger for sunxi. If I hack it that it applies, but only to the proper build, it works, though. But I don't feel like adding to this #if even more ;-)

I've got a version that does work, now, on my pine64 plus, and I've asked Quentin to test his Rockchip platform that was also broken, before I post a new version there.

Is it something like this:

include/ns16550.h +0 -1
index 243226fc3d9..74e619e0614 100644
@@ -26,15 +26,12 @@
 
 #include <linux/types.h>
 
-#if CONFIG_IS_ENABLED(DM_SERIAL) &&

!defined(CONFIG_SYS_NS16550_REG_SIZE) /*
* For driver model we always use one byte per register, and sort out
the
* differences in the driver
*/
-#define CONFIG_SYS_NS16550_REG_SIZE (-1)
-#endif
-
-#if defined(CONFIG_NS16550_DYNAMIC) || defined(CONFIG_DEBUG_UART) +#if CONFIG_IS_ENABLED(DM_SERIAL) || defined(CONFIG_NS16550_DYNAMIC)

||	\
+    defined(CONFIG_DEBUG_UART)

#define UART_REG(x) unsigned char x
#else
#if !defined(CONFIG_SYS_NS16550_REG_SIZE) ||
(CONFIG_SYS_NS16550_REG_SIZE == 0)

Cheers,
Andre

Quoted 3 lines

A better long term fix would likely start by seeing which non-DM_SERIAL cases we have, and what they need, still.

#10 lore raw
Quoted 100 lines · Andre Przywara
Quoted 66 lines · On Tue, 17 Jan 2023 11:14:35 -0500 Tom Rini <[email protected]> wrote:
Quoted 65 lines · Andre Przywara

On Tue, 17 Jan 2023 08:15:18 -0500
Tom Rini <[email protected]> wrote:

Hi Tom,

Quoted 59 lines · Andre Przywara
Quoted 44 lines

Commit 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig") moved some NS16550 configuration variables into Kconfig. Among those there is CONFIG_SYS_NS16550_REG_SIZE, which used to be only defined for SPL build runs, but now is always set (thanks for Kconfig). However this breaks the gating logic in ns16550.h, where we *override* this variable for DM build, as we learn this setting from the DT instead.

As a consequence, we did the register shift twice: once when building the register struct (as required for non-DM SPL builds), but then also again in the driver after we parsed the reg-shift DT property.

Change the logic to match what the comment says: only observe CONFIG_SYS_NS16550_REG_SIZE when not using DM, and ignore it otherwise.

This fixes U-Boot proper for all sunxi boards, since they are relying on this driver being build non-DM for the SPL, but DM for U-Boot proper.

Fixes 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig")

---
Hi,

this is admittedly a quick fix, to get sunxi booting again. This whole code around the register access looks somewhat bonkers, to be honest, but at the moment I don't have time to rework this.
Another possible "quicker fix" would be use a separate variable for the register shift, so that we don't have to redefine a Kconfig variable. Another idea would be to get rid of the struct for the registers altogether, to remove the hacks about when to shift.

Cheers,
Andre

 include/ns16550.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/ns16550.h +0 -0
index 243226fc3d9..e9e2aeedd16 100644
@@ -26,11 +26,12 @@
 
 #include <linux/types.h>

include/ns16550.h line 36

Quoted 10 lines
include/ns16550.h +2 -1
 
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif    

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
work for you as well?

Quoted 7 lines
Quoted 3 lines

Unfortunately not. This changed condition there does not trigger for sunxi. If I hack it that it applies, but only to the proper build, it works, though. But I don't feel like adding to this #if even more ;-)

I've got a version that does work, now, on my pine64 plus, and I've asked Quentin to test his Rockchip platform that was also broken, before I post a new version there.

Is it something like this:

include/ns16550.h +0 -1
index 243226fc3d9..74e619e0614 100644
@@ -26,15 +26,12 @@
 
 #include <linux/types.h>
 
-#if CONFIG_IS_ENABLED(DM_SERIAL) &&

!defined(CONFIG_SYS_NS16550_REG_SIZE) /*
* For driver model we always use one byte per register, and sort out
the
* differences in the driver
*/

include/ns16550.h +1 -4
-#define CONFIG_SYS_NS16550_REG_SIZE (-1)
-#endif
-
-#if defined(CONFIG_NS16550_DYNAMIC) || defined(CONFIG_DEBUG_UART)
+#if CONFIG_IS_ENABLED(DM_SERIAL) || defined(CONFIG_NS16550_DYNAMIC)
||	\
+    defined(CONFIG_DEBUG_UART)
Quoted 4 lines

#define UART_REG(x) unsigned char x
#else
#if !defined(CONFIG_SYS_NS16550_REG_SIZE) ||
(CONFIG_SYS_NS16550_REG_SIZE == 0)

Yes, I just cc'd you on it (crossed messages I do believe) with a comment.

Signature · 1 line
Tom
#11 lore raw
Quoted 100 lines · On Tue, 17 Jan 2023 17:23:57 -0500 Tom Rini <[email protected]> wrote:
Quoted 99 lines · Andre Przywara
Quoted 66 lines · On Tue, 17 Jan 2023 11:14:35 -0500 Tom Rini <[email protected]> wrote:
Quoted 65 lines · Andre Przywara

On Tue, 17 Jan 2023 08:15:18 -0500
Tom Rini <[email protected]> wrote:

Hi Tom,

Quoted 59 lines · Andre Przywara
Quoted 44 lines

Commit 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig") moved some NS16550 configuration variables into Kconfig. Among those there is CONFIG_SYS_NS16550_REG_SIZE, which used to be only defined for SPL build runs, but now is always set (thanks for Kconfig). However this breaks the gating logic in ns16550.h, where we *override* this variable for DM build, as we learn this setting from the DT instead.

As a consequence, we did the register shift twice: once when building the register struct (as required for non-DM SPL builds), but then also again in the driver after we parsed the reg-shift DT property.

Change the logic to match what the comment says: only observe CONFIG_SYS_NS16550_REG_SIZE when not using DM, and ignore it otherwise.

This fixes U-Boot proper for all sunxi boards, since they are relying on this driver being build non-DM for the SPL, but DM for U-Boot proper.

Fixes 9591b63531fa ("Convert CONFIG_SYS_NS16550_MEM32 et al to Kconfig")

---
Hi,

this is admittedly a quick fix, to get sunxi booting again. This whole code around the register access looks somewhat bonkers, to be honest, but at the moment I don't have time to rework this.
Another possible "quicker fix" would be use a separate variable for the register shift, so that we don't have to redefine a Kconfig variable. Another idea would be to get rid of the struct for the registers altogether, to remove the hacks about when to shift.

Cheers,
Andre

 include/ns16550.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/ns16550.h +0 -0
index 243226fc3d9..e9e2aeedd16 100644
@@ -26,11 +26,12 @@
 
 #include <linux/types.h>

include/ns16550.h line 36

Quoted 10 lines
include/ns16550.h +2 -1
 
-#if CONFIG_IS_ENABLED(DM_SERIAL) && !defined(CONFIG_SYS_NS16550_REG_SIZE)
+#if CONFIG_IS_ENABLED(DM_SERIAL)
 /*
  * For driver model we always use one byte per register, and sort out the
  * differences in the driver
  */
+#undef CONFIG_SYS_NS16550_REG_SIZE
 #define CONFIG_SYS_NS16550_REG_SIZE (-1)
 #endif      

Does:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
work for you as well?

Quoted 7 lines
Quoted 3 lines

Unfortunately not. This changed condition there does not trigger for sunxi. If I hack it that it applies, but only to the proper build, it works, though. But I don't feel like adding to this #if even more ;-)

I've got a version that does work, now, on my pine64 plus, and I've asked Quentin to test his Rockchip platform that was also broken, before I post a new version there.

Is it something like this:

include/ns16550.h +0 -1
index 243226fc3d9..74e619e0614 100644
@@ -26,15 +26,12 @@
 
 #include <linux/types.h>
 
-#if CONFIG_IS_ENABLED(DM_SERIAL) &&

!defined(CONFIG_SYS_NS16550_REG_SIZE) /*
* For driver model we always use one byte per register, and sort out
the
* differences in the driver
*/

include/ns16550.h +1 -4
-#define CONFIG_SYS_NS16550_REG_SIZE (-1)
-#endif
-
-#if defined(CONFIG_NS16550_DYNAMIC) || defined(CONFIG_DEBUG_UART)
+#if CONFIG_IS_ENABLED(DM_SERIAL) || defined(CONFIG_NS16550_DYNAMIC)

|| \

Quoted 8 lines
Quoted 5 lines

+ defined(CONFIG_DEBUG_UART)
#define UART_REG(x) unsigned char x
#else
#if !defined(CONFIG_SYS_NS16550_REG_SIZE) ||
(CONFIG_SYS_NS16550_REG_SIZE == 0)

Yes, I just cc'd you on it (crossed messages I do believe) with a comment.

Yeah, that's the five minutes I wrote and tested this ;-) Looks good, replied there.

Thanks!
Andre

Quoted 1 line