Skip to contentSkip to conversation

sunxi: Fix A33 memory initialization

PATCH New Shyam Saini 4 participants 8 messages Mar 18, 2019 – Apr 9, 2019

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

PATCH v3 1/3 sunxi: Fix A33 memory initialization

From: Michael Trimarchi <[email protected]>

While the exact problem is not known, based on discussion between Philipp Tomsich and André Przywara it is guessed that exit self-refresh timing is not set with correct value. There may be implicit enter or exit Self-Refresh anywhere as part of some training phase.

In ZynqMP register guide [1], which is close to the various Allwinner DRAM controllers, tXSDLL is bits [14:8], while the non-DLL tXS is bits [6:0]: Self refresh exit delay. So it could be safely increased and it only affects the time after the self-refresh “exit”, which happens only after (re-)initialisation.

There was no document for cpu in question so based on oscilloscope readings [2][3] and observed result by comparing allwinner architecture. So set it same as Allwinner H5 silicon.

Before this patch, failure rate of was 7%.

This was tested on A33 allwinner cpu, dual rank connection connected with two MT41K512M16HA-125:A memory model. Memory is configured as DDR3 1.5V

[1] https://www.xilinx.com/html_docs/registers/ug1087/ddrc___dramtmg8.html
[2] https://ibb.co/R70zmyS
[3] https://ibb.co/HVVCGQ8

---
Changelogs:

	   V1->V2: adjust commit message
           V2->V3: Adjust commit message based on V2 Discussion
---
 arch/arm/mach-sunxi/dram_sun8i_a33.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-sunxi/dram_sun8i_a33.c +1 -1
index 1da2727f9874..5da01922bfaf 100644
@@ -152,7 +152,7 @@ static void auto_set_timing_para(struct dram_para *para)
 	reg_val &= ~(0xff << 8);
 	reg_val &= ~(0xff << 0);
 	reg_val |= (0x33 << 8);
-	reg_val |= (0x8 << 0);
+	reg_val |= (0x10 << 0);
 	writel(reg_val, &mctl_ctl->dramtmg8);
 	/* Set phy interface time */
 	reg_val = (0x2 << 24) | (t_rdata_en << 16) | (0x1 << 8)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 2/3 sunxi: Don't change the rank in dram size detection in A33

From: Michael Trimarchi <[email protected]>

Change the size create a glitch in the clken signal on second bank. According to the ddr manual the clken need to be sent accros the reset signal coming the cpu. The rank is calculated just before this function is called and the mctl_set_cr should not change this value anymore

---
Changelogs:

	   V1->V2: Adjust commit description
	   V2->V3: None
---
 arch/arm/mach-sunxi/dram_sun8i_a33.c | 3 ---
 1 file changed, 3 deletions(-)
arch/arm/mach-sunxi/dram_sun8i_a33.c +0 -3
index 5da01922bfaf..63e18f17d0db 100644
@@ -45,14 +45,12 @@ static void mctl_set_cr(struct dram_para *para)
 
 static void auto_detect_dram_size(struct dram_para *para)
 {
-	u8 orig_rank = para->rank;
 	int rows, columns;
 
 	/* Row detect */
 	para->page_size = 512;
 	para->seq = 1;
 	para->rows = 16;
-	para->rank = 1;
 	mctl_set_cr(para);
 	for (rows = 11 ; rows < 16 ; rows++) {
 		if (mctl_mem_matches(1 << (rows + 9))) /* row-column */
@@ -69,7 +67,6 @@ static void auto_detect_dram_size(struct dram_para *para)
 	}
 
 	para->seq = 0;
-	para->rank = orig_rank;
 	para->rows = rows;
 	para->page_size = 1 << columns;
 	mctl_set_cr(para);
Signature · 1 line
2.11.0
#2 lore raw

PATCH v4 3/3 sunxi: Use clrsetbits_le32 instead of multiple instruction

In reply to Shyam Saini

From: Michael Trimarchi <[email protected]>

This will improve code readabilty

---
Changelogs:

	   V1->V2: none
	   V2->V3: Fix use of clrsetbits_le32 and setbits_le32 functions
	   V3->V4: Rebase to original series's patch 2 and 3
---
 arch/arm/mach-sunxi/dram_sun8i_a33.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/arm/mach-sunxi/dram_sun8i_a33.c +2 -5
index 63e18f17d0db..9fe4c88bd87f 100644
@@ -145,11 +145,8 @@ static void auto_set_timing_para(struct dram_para *para)
 	reg_val = (tcksrx << 24) | (tcksre << 16) | (tckesr << 8) | (tcke << 0);
 	writel(reg_val, &mctl_ctl->dramtmg5);
 	/* Set two rank timing and exit self-refresh timing */
-	reg_val = readl(&mctl_ctl->dramtmg8);
-	reg_val &= ~(0xff << 8);
-	reg_val &= ~(0xff << 0);
-	reg_val |= (0x33 << 8);
-	reg_val |= (0x10 << 0);
+	clrsetbits_le32(&mctl_ctl->dramtmg8, (0xff << 8) | (0xff << 0));
+	setbits_le32(&mctl_ctl->dramtmg8, (0x33 << 8) | (0x10 << 0));
 	writel(reg_val, &mctl_ctl->dramtmg8);
 	/* Set phy interface time */
 	reg_val = (0x2 << 24) | (t_rdata_en << 16) | (0x1 << 8)
Signature · 1 line
2.11.0
#3 lore raw

PATCH v4 3/3 sunxi: Use clrsetbits_le32 instead of multiple instruction

On Mon, 18 Mar 2019 15:17:47 +0530
Shyam Saini <[email protected]> wrote:

Hi,

Quoted 3 lines

From: Michael Trimarchi <[email protected]>

This will improve code readabilty

Somehow this patch looks horribly wrong, it doesn't even compile. See below. Are you sure you sent the right version?

Quoted 16 lines

---
Changelogs:

	   V1->V2: none
	   V2->V3: Fix use of clrsetbits_le32 and setbits_le32 functions
	   V3->V4: Rebase to original series's patch 2 and 3
---
 arch/arm/mach-sunxi/dram_sun8i_a33.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/arm/mach-sunxi/dram_sun8i_a33.c +0 -0
index 63e18f17d0db..9fe4c88bd87f 100644

arch/arm/mach-sunxi/dram_sun8i_a33.c static void auto_set_timing_para(struct dram_para *para) · line 149

Quoted 10 lines
arch/arm/mach-sunxi/dram_sun8i_a33.c +2 -5
@@ -145,11 +145,8 @@ static void auto_set_timing_para(struct dram_para *para)
 	reg_val = (tcksrx << 24) | (tcksre << 16) | (tckesr << 8) | (tcke << 0);
 	writel(reg_val, &mctl_ctl->dramtmg5);
 	/* Set two rank timing and exit self-refresh timing */
-	reg_val = readl(&mctl_ctl->dramtmg8);
-	reg_val &= ~(0xff << 8);
-	reg_val &= ~(0xff << 0);
-	reg_val |= (0x33 << 8);
-	reg_val |= (0x10 << 0);
+	clrsetbits_le32(&mctl_ctl->dramtmg8, (0xff << 8) | (0xff << 0));
+	setbits_le32(&mctl_ctl->dramtmg8, (0x33 << 8) | (0x10 << 0));

That should just be one call to clrsetbits_le32().

arch/arm/mach-sunxi/dram_sun8i_a33.c static void auto_set_timing_para(struct dram_para *para) · line 150

Quoted 1 line
arch/arm/mach-sunxi/dram_sun8i_a33.c +0 -0
 	writel(reg_val, &mctl_ctl->dramtmg8);

And you need to remove this line, of course, otherwise you write the value of dramtmg5 into dramtmg8.

Cheers,
Andre.

Quoted 2 lines
arch/arm/mach-sunxi/dram_sun8i_a33.c +0 -0
 	/* Set phy interface time */
 	reg_val = (0x2 << 24) | (t_rdata_en << 16) | (0x1 << 8)
#4 lore raw

PATCH v4 3/3 sunxi: Use clrsetbits_le32 instead of multiple instruction

Hi

Quoted 42 lines · Andre Przywara

On Mon, 18 Mar 2019 15:17:47 +0530
Shyam Saini <[email protected]> wrote:

Hi,

Quoted 3 lines

From: Michael Trimarchi <[email protected]>

This will improve code readabilty

Somehow this patch looks horribly wrong, it doesn't even compile. See below. Are you sure you sent the right version?

Quoted 16 lines

---
Changelogs:

         V1->V2: none
         V2->V3: Fix use of clrsetbits_le32 and setbits_le32 functions
         V3->V4: Rebase to original series's patch 2 and 3
---
 arch/arm/mach-sunxi/dram_sun8i_a33.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/arm/mach-sunxi/dram_sun8i_a33.c +0 -0
index 63e18f17d0db..9fe4c88bd87f 100644

arch/arm/mach-sunxi/dram_sun8i_a33.c static void auto_set_timing_para(struct dram_para *para) · line 149

Quoted 10 lines
arch/arm/mach-sunxi/dram_sun8i_a33.c +2 -5
@@ -145,11 +145,8 @@ static void auto_set_timing_para(struct dram_para *para)
      reg_val = (tcksrx << 24) | (tcksre << 16) | (tckesr << 8) | (tcke << 0);
      writel(reg_val, &mctl_ctl->dramtmg5);
      /* Set two rank timing and exit self-refresh timing */
-     reg_val = readl(&mctl_ctl->dramtmg8);
-     reg_val &= ~(0xff << 8);
-     reg_val &= ~(0xff << 0);
-     reg_val |= (0x33 << 8);
-     reg_val |= (0x10 << 0);
+     clrsetbits_le32(&mctl_ctl->dramtmg8, (0xff << 8) | (0xff << 0));
+     setbits_le32(&mctl_ctl->dramtmg8, (0x33 << 8) | (0x10 << 0));

That should just be one call to clrsetbits_le32().

Quoted 4 lines

arch/arm/mach-sunxi/dram_sun8i_a33.c static void auto_set_timing_para(struct dram_para *para) · line 150

Quoted 1 line
arch/arm/mach-sunxi/dram_sun8i_a33.c +0 -0
      writel(reg_val, &mctl_ctl->dramtmg8);

And you need to remove this line, of course, otherwise you write the value of dramtmg5 into dramtmg8.

Agree, I prefer the patchset original order and it should work

Thank Andre

Michael

Quoted 6 lines

Cheers,
Andre.

Quoted 2 lines
arch/arm/mach-sunxi/dram_sun8i_a33.c +0 -0
      /* Set phy interface time */
      reg_val = (0x2 << 24) | (t_rdata_en << 16) | (0x1 << 8)
Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#5 lore raw

PATCH v3 1/3 sunxi: Fix A33 memory initialization

In reply to Shyam Saini

Hi Philippe and Andre'

Quoted 18 lines · Shyam Saini

From: Michael Trimarchi <[email protected]>

While the exact problem is not known, based on discussion between Philipp Tomsich and André Przywara it is guessed that exit self-refresh timing is not set with correct value. There may be implicit enter or exit Self-Refresh anywhere as part of some training phase.

In ZynqMP register guide [1], which is close to the various Allwinner DRAM controllers, tXSDLL is bits [14:8], while the non-DLL tXS is bits [6:0]: Self refresh exit delay. So it could be safely increased and it only affects the time after the self-refresh “exit”, which happens only after (re-)initialisation.

There was no document for cpu in question so based on oscilloscope readings [2][3] and observed result by comparing allwinner architecture. So set it same as Allwinner H5 silicon.

Quoted 6 lines

Before this patch, failure rate of was 7%.

This was tested on A33 allwinner cpu, dual rank connection connected with two MT41K512M16HA-125:A memory model. Memory is configured as DDR3 1.5V

Are you happy with this description?

Michael

Quoted 30 lines

[1] https://www.xilinx.com/html_docs/registers/ug1087/ddrc___dramtmg8.html
[2] https://ibb.co/R70zmyS
[3] https://ibb.co/HVVCGQ8

---
Changelogs:

           V1->V2: adjust commit message
           V2->V3: Adjust commit message based on V2 Discussion
---
 arch/arm/mach-sunxi/dram_sun8i_a33.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-sunxi/dram_sun8i_a33.c +1 -2
index 1da2727f9874..5da01922bfaf 100644
@@ -152,7 +152,7 @@ static void auto_set_timing_para(struct dram_para *para)
        reg_val &= ~(0xff << 8);
        reg_val &= ~(0xff << 0);
        reg_val |= (0x33 << 8);
-       reg_val |= (0x8 << 0);
+       reg_val |= (0x10 << 0);
        writel(reg_val, &mctl_ctl->dramtmg8);
        /* Set phy interface time */
        reg_val = (0x2 << 24) | (t_rdata_en << 16) | (0x1 << 8)
--

2.11.0

Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#6 lore raw

PATCH v3 1/3 sunxi: Fix A33 memory initialization

In reply to Shyam Saini
Quoted 28 lines · Shyam Saini

From: Michael Trimarchi <[email protected]>

While the exact problem is not known, based on discussion between Philipp Tomsich and André Przywara it is guessed that exit self-refresh timing is not set with correct value. There may be implicit enter or exit Self-Refresh anywhere as part of some training phase.

In ZynqMP register guide [1], which is close to the various Allwinner DRAM controllers, tXSDLL is bits [14:8], while the non-DLL tXS is bits [6:0]: Self refresh exit delay. So it could be safely increased and it only affects the time after the self-refresh “exit”, which happens only after (re-)initialisation.

There was no document for cpu in question so based on oscilloscope readings [2][3] and observed result by comparing allwinner architecture. So set it same as Allwinner H5 silicon.

Before this patch, failure rate of was 7%.

This was tested on A33 allwinner cpu, dual rank connection connected with two MT41K512M16HA-125:A memory model. Memory is configured as DDR3 1.5V

[1] https://www.xilinx.com/html_docs/registers/ug1087/ddrc___dramtmg8.html
[2] https://ibb.co/R70zmyS
[3] https://ibb.co/HVVCGQ8

Quoted 7 lines

---
Changelogs:

           V1->V2: adjust commit message
           V2->V3: Adjust commit message based on V2 Discussion

---

#7 lore raw

PATCH v3 1/3 sunxi: Fix A33 memory initialization

Quoted 39 lines · Jagan Teki
Quoted 28 lines · Shyam Saini

From: Michael Trimarchi <[email protected]>

While the exact problem is not known, based on discussion between Philipp Tomsich and André Przywara it is guessed that exit self-refresh timing is not set with correct value. There may be implicit enter or exit Self-Refresh anywhere as part of some training phase.

In ZynqMP register guide [1], which is close to the various Allwinner DRAM controllers, tXSDLL is bits [14:8], while the non-DLL tXS is bits [6:0]: Self refresh exit delay. So it could be safely increased and it only affects the time after the self-refresh “exit”, which happens only after (re-)initialisation.

There was no document for cpu in question so based on oscilloscope readings [2][3] and observed result by comparing allwinner architecture. So set it same as Allwinner H5 silicon.

Before this patch, failure rate of was 7%.

This was tested on A33 allwinner cpu, dual rank connection connected with two MT41K512M16HA-125:A memory model. Memory is configured as DDR3 1.5V

[1] https://www.xilinx.com/html_docs/registers/ug1087/ddrc___dramtmg8.html
[2] https://ibb.co/R70zmyS
[3] https://ibb.co/HVVCGQ8

Quoted 7 lines

---
Changelogs:

           V1->V2: adjust commit message
           V2->V3: Adjust commit message based on V2 Discussion

---

Quoted 1 line

Applied to u-boot-sunxi/master