From: Jernej =?utf-8?B?xaBrcmFiZWM=?= Date: Wed, 21 Aug 2019 08:01:31 +0200 Subject: [U-Boot] [PATCH] sunxi: H6: DRAM: Add support for half DQ In-Reply-To: <4d5a5248-4fe6-a60c-19a1-15abacdee93a@arm.com> References: <20190717221617.10433-1-jernej.skrabec@siol.net> <4d5a5248-4fe6-a60c-19a1-15abacdee93a@arm.com> Message-ID: <2568558.IVZhmtY2pC@jernej-laptop> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi! Dne sreda, 21. avgust 2019 ob 02:31:04 CEST je Andr=C3=A9 Przywara napisal(= a): > On 17/07/2019 23:16, Jernej Skrabec wrote: > > Half DQ configuration seems to be very rare for H6 based boards/STBs, > > but exists nevertheless. Currently the only known product which needs > > this support is Tanix TX6 mini. > >=20 > > This commit adds support for half DQ configuration. Code was tested > > for regressions on other configurations (OrangePi 3 1 GiB/LPDDR3, Tanix > > TX6 4 GiB/DDR3) and none were found. > >=20 > > Thanks to Icenowy Zheng for help with this code. > >=20 > > Signed-off-by: Jernej Skrabec >=20 > I don't have a board with 16-bit DRAM, but can confirm that this still > works on the PineH64 and the Eachlink H6 Mini. Thanks for testing! >=20 > Aside from the one question below, the code looks alright for me. I > verified the bits set or checked below against the Zynq register > documentation. > I didn't browse through all of the register documentation to find other > bits that possibly affect the bus width. But since the code seems to > work for Jernej, I assume that's fine. Unfortunately, there is no RSR0 documentation in Zynq register manual, but = I=20 found this page: https://git.axiom-project.eu/axiom-evi-qemu/raw/ 47171dbf860af6d12c9b82997629460b77378496/hw/misc/xilinx-ddr_phy.c All RSR0 registers are defined as having QSGERR field, but there is no=20 explanation of values it can hold. BTW, I don't have board with such memory combination, but few people confir= med=20 working on Tanix TX6 mini, which it does. >=20 > > --- > >=20 > > .../include/asm/arch-sunxi/dram_sun50i_h6.h | 1 + > > arch/arm/mach-sunxi/dram_sun50i_h6.c | 74 ++++++++++++------- > > 2 files changed, 50 insertions(+), 25 deletions(-) > >=20 > > diff --git a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h6.h > > b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h6.h index > > 0a1da02376..49a8a66f7b 100644 > > --- a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h6.h > > +++ b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h6.h > > @@ -315,6 +315,7 @@ struct dram_para { > >=20 > > u8 cols; > > u8 rows; > > u8 ranks; > >=20 > > + u8 bus_full_width; > >=20 > > const u8 dx_read_delays[NR_OF_BYTE_LANES][RD_LINES_PER_BYTE_LANE]; > > const u8 dx_write_delays[NR_OF_BYTE_LANES] [WR_LINES_PER_BYTE_LANE]; > > =20 > > }; > >=20 > > diff --git a/arch/arm/mach-sunxi/dram_sun50i_h6.c > > b/arch/arm/mach-sunxi/dram_sun50i_h6.c index 2a8275da3a..0d65327d35 > > 100644 > > --- a/arch/arm/mach-sunxi/dram_sun50i_h6.c > > +++ b/arch/arm/mach-sunxi/dram_sun50i_h6.c > > @@ -201,6 +201,9 @@ static void mctl_set_addrmap(struct dram_para *para) > >=20 > > u8 rows =3D para->rows; > > u8 ranks =3D para->ranks; > >=20 > > + if (!para->bus_full_width) > > + cols -=3D 1; > > + > >=20 > > /* Ranks */ > > if (ranks =3D=3D 2) > > =09 > > mctl_ctl->addrmap[0] =3D rows + cols - 3; > >=20 > > @@ -213,6 +216,10 @@ static void mctl_set_addrmap(struct dram_para *par= a) > >=20 > > /* Columns */ > > mctl_ctl->addrmap[2] =3D 0; > > switch (cols) { > >=20 > > + case 7: > > + mctl_ctl->addrmap[3] =3D 0x1F1F1F00; > > + mctl_ctl->addrmap[4] =3D 0x1F1F; > > + break; > >=20 > > case 8: > > mctl_ctl->addrmap[3] =3D 0x1F1F0000; > > mctl_ctl->addrmap[4] =3D 0x1F1F; > >=20 > > @@ -300,13 +307,16 @@ static void mctl_com_init(struct dram_para *para) > >=20 > > reg_val =3D 0x3f00; > > =09 > > clrsetbits_le32(&mctl_com->unk_0x008, 0x3f00, reg_val); > >=20 > > - /* TODO: half DQ, DDR4 */ > > - reg_val =3D MSTR_BUSWIDTH_FULL | MSTR_BURST_LENGTH(8) | > > - MSTR_ACTIVE_RANKS(para->ranks); > > + /* TODO: DDR4 */ > > + reg_val =3D MSTR_BURST_LENGTH(8) | MSTR_ACTIVE_RANKS(para->ranks); > >=20 > > if (para->type =3D=3D SUNXI_DRAM_TYPE_LPDDR3) > > =09 > > reg_val |=3D MSTR_DEVICETYPE_LPDDR3; > > =09 > > if (para->type =3D=3D SUNXI_DRAM_TYPE_DDR3) > > =09 > > reg_val |=3D MSTR_DEVICETYPE_DDR3 | MSTR_2TMODE; > >=20 > > + if (para->bus_full_width) > > + reg_val |=3D MSTR_BUSWIDTH_FULL; > > + else > > + reg_val |=3D MSTR_BUSWIDTH_HALF; > >=20 > > writel(reg_val | BIT(31), &mctl_ctl->mstr); > > =09 > > if (para->type =3D=3D SUNXI_DRAM_TYPE_LPDDR3) > >=20 > > @@ -333,7 +343,10 @@ static void mctl_com_init(struct dram_para *para) > >=20 > > } > > writel(reg_val, &mctl_ctl->odtcfg); > >=20 > > - /* TODO: half DQ */ > > + if (!para->bus_full_width) { > > + writel(0x0, &mctl_phy->dx[2].gcr[0]); > > + writel(0x0, &mctl_phy->dx[3].gcr[0]); > > + } > >=20 > > } > > =20 > > static void mctl_bit_delay_set(struct dram_para *para) > >=20 > > @@ -514,22 +527,31 @@ static void mctl_channel_init(struct dram_para > > *para) > >=20 > > if (readl(&mctl_phy->pgsr[0]) & 0x400000) > > { > >=20 > > - /* > > - * Detect single rank. > > - * TODO: also detect half DQ. > > - */ > > + /* Check for single rank and optionally half DQ. */ > >=20 > > if ((readl(&mctl_phy->dx[0].rsr[0]) & 0x3) =3D=3D 2 && > >=20 > > - (readl(&mctl_phy->dx[1].rsr[0]) & 0x3) =3D=3D 2 && > > - (readl(&mctl_phy->dx[2].rsr[0]) & 0x3) =3D=3D 2 && > > - (readl(&mctl_phy->dx[3].rsr[0]) & 0x3) =3D=3D 2) { > > + (readl(&mctl_phy->dx[1].rsr[0]) & 0x3) =3D=3D 2) { > >=20 > > para->ranks =3D 1; > >=20 > > + > > + if ((readl(&mctl_phy->dx[2].rsr[0]) & 0x3) ! =3D 2 || > > + (readl(&mctl_phy->dx[3].rsr[0]) & 0x3) ! =3D 2) > > + para->bus_full_width =3D 0; > > + > >=20 > > /* Restart DRAM initialization from scratch.=20 */ > > mctl_core_init(para); > > return; > > =09 > > } > >=20 > > - else { > > - panic("This DRAM setup is currently not=20 supported.\n"); > > + > > + /* Check for dual rank and half DQ */ > > + if ((readl(&mctl_phy->dx[0].rsr[0]) & 0x3) =3D=3D 0 && > > + (readl(&mctl_phy->dx[1].rsr[0]) & 0x3) =3D=3D 0) { > > + para->bus_full_width =3D 0; >=20 > Mmh, aren't those bits always supposed to be 0 here, regardless of the > bus width? So we just confirm dual rank here? Can we actually say from > those error bits whether no errors in bits 16-31 mean them being masked > or whether that means the upper 16 bits are working fine? > Or is bus_fill_width always 1 at this point? But then we would need to > check dx[2].rsr[0] and dx[3].rsr[0], wouldn't we? As I already pointed out, I couldn't found useful documentation of RSR0, so= I=20 checked what libdram does and put similar check here too. They always check= =20 only two bits in all RSR0 registers. I suppose 1 and 3 can be read from=20 registers or register values may not be same. But I really have no idea wha= t=20 they mean. I would be glad if anyone can provide more information. That being said, I see what bothers you. I checked libdram logic again and = unless I missed anything, this is exactly the check libdram has. However,=20 because having dual rank and half DQ seems unlikely, we may skip this block= =20 altogether, but that would require another round of tests. Best regards, Jernej >=20 > Cheers, > Andre. >=20 > > + > > + /* Restart DRAM initialization from scratch.=20 */ > > + mctl_core_init(para); > > + return; > >=20 > > } > >=20 > > + > > + panic("This DRAM setup is currently not supported.\n"); > >=20 > > } > > =09 > > if (readl(&mctl_phy->pgsr[0]) & 0xff00000) { > >=20 > > @@ -557,11 +579,8 @@ static void mctl_channel_init(struct dram_para *pa= ra) > >=20 > > static void mctl_auto_detect_dram_size(struct dram_para *para) > > { > >=20 > > - /* TODO: non-LPDDR3, half DQ */ > > - /* > > - * Detect rank number by the code in mctl_channel_init. Furtherly > > - * when DQ detection is available it will also be executed there. > > - */ > > + /* TODO: non-(LP)DDR3 */ > > + /* Detect rank number and half DQ by the code in=20 mctl_channel_init. */ > >=20 > > mctl_core_init(para); > > =09 > > /* detect row address bits */ > >=20 > > @@ -570,8 +589,9 @@ static void mctl_auto_detect_dram_size(struct > > dram_para *para)>=20 > > mctl_core_init(para); > > =09 > > for (para->rows =3D 13; para->rows < 18; para->rows++) { > >=20 > > - /* 8 banks, 8 bit per byte and 32 bit width */ > > - if (mctl_mem_matches((1 << (para->rows + para->cols +=20 5)))) > > + /* 8 banks, 8 bit per byte and 16/32 bit width */ > > + if (mctl_mem_matches((1 << (para->rows + para->cols + > > + 4 + para- >bus_full_width)))) > >=20 > > break; > > =09 > > } > >=20 > > @@ -580,18 +600,21 @@ static void mctl_auto_detect_dram_size(struct > > dram_para *para)>=20 > > mctl_core_init(para); > > =09 > > for (para->cols =3D 8; para->cols < 11; para->cols++) { > >=20 > > - /* 8 bits per byte and 32 bit width */ > > - if (mctl_mem_matches(1 << (para->cols + 2))) > > + /* 8 bits per byte and 16/32 bit width */ > > + if (mctl_mem_matches(1 << (para->cols + 1 + > > + para- >bus_full_width))) > >=20 > > break; > > =09 > > } > > =20 > > } > > =20 > > unsigned long mctl_calc_size(struct dram_para *para) > > { > >=20 > > - /* TODO: non-LPDDR3, half DQ */ > > + u8 width =3D para->bus_full_width ? 4 : 2; > > + > > + /* TODO: non-(LP)DDR3 */ > >=20 > > - /* 8 banks, 32-bit (4 byte) data width */ > > - return (1ULL << (para->cols + para->rows + 3)) * 4 * para->ranks; > > + /* 8 banks */ > > + return (1ULL << (para->cols + para->rows + 3)) * width * para- >ranks; > >=20 > > } > > =20 > > #define SUN50I_H6_LPDDR3_DX_WRITE_DELAYS \ > >=20 > > @@ -625,6 +648,7 @@ unsigned long sunxi_dram_init(void) > >=20 > > .ranks =3D 2, > > .cols =3D 11, > > .rows =3D 14, > >=20 > > + .bus_full_width =3D 1, > >=20 > > #ifdef CONFIG_SUNXI_DRAM_H6_LPDDR3 > > =20 > > .type =3D SUNXI_DRAM_TYPE_LPDDR3, > > .dx_read_delays =3D SUN50I_H6_LPDDR3_DX_READ_DELAYS,