All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jernej Škrabec" <jernej.skrabec@siol.net>
To: u-boot@lists.denx.de
Subject: [linux-sunxi] [PATCH 11/17] sunxi: Add H616 DRAM support
Date: Mon, 04 Jan 2021 19:39:09 +0100	[thread overview]
Message-ID: <3515536.VdQlbGyI4E@jernej-laptop> (raw)
In-Reply-To: <af909709-ee0f-05ea-a384-780da636a6a4@sholland.org>

Dne ponedeljek, 04. januar 2021 ob 03:39:52 CET je Samuel Holland napisal(a):
> On 1/3/21 3:26 AM, Jernej Skrabec wrote:
> > Allwinner H616 supports many types of DRAM. Most notably it supports
> > LPDDR4. However, all commercially available boards at this time use
> > only DDR3, so this commit adds only DDR3 support.
> > 
> > Controller and MBUS are very similar to H6 but PHY is completely
> > unknown.
> > 
> > Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net>
> > ---
> > 
> >  arch/arm/include/asm/arch-sunxi/dram.h        |    2 +
> >  .../include/asm/arch-sunxi/dram_sun50i_h616.h |  159 +++
> >  arch/arm/mach-sunxi/Kconfig                   |   43 +
> >  arch/arm/mach-sunxi/Makefile                  |    2 +
> >  arch/arm/mach-sunxi/dram_sun50i_h616.c        | 1023 +++++++++++++++++
> >  arch/arm/mach-sunxi/dram_timings/Makefile     |    2 +
> >  .../mach-sunxi/dram_timings/h616_ddr3_1333.c  |   94 ++
> >  7 files changed, 1325 insertions(+)
> >  create mode 100644 arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> >  create mode 100644 arch/arm/mach-sunxi/dram_sun50i_h616.c
> >  create mode 100644 arch/arm/mach-sunxi/dram_timings/h616_ddr3_1333.c
> > 
> > diff --git a/arch/arm/include/asm/arch-sunxi/dram.h
> > b/arch/arm/include/asm/arch-sunxi/dram.h index 8002b7efdc19..c3b3e1f512b2
> > 100644
> > --- a/arch/arm/include/asm/arch-sunxi/dram.h
> > +++ b/arch/arm/include/asm/arch-sunxi/dram.h
> > @@ -29,6 +29,8 @@
> > 
> >  #include <asm/arch/dram_sun9i.h>
> >  #elif defined(CONFIG_MACH_SUN50I_H6)
> >  #include <asm/arch/dram_sun50i_h6.h>
> > 
> > +#elif defined(CONFIG_MACH_SUN50I_H616)
> > +#include <asm/arch/dram_sun50i_h616.h>
> > 
> >  #else
> >  #include <asm/arch/dram_sun4i.h>
> >  #endif
> > 
> > diff --git a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> > b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h new file mode 100644
> > index 000000000000..5d105afd6110
> > --- /dev/null
> > +++ b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> > @@ -0,0 +1,159 @@
> > +/*
> > + * H616 dram controller register and constant defines
> > + *
> > + * (C) Copyright 2020  Jernej Skrabec <jernej.skrabec@siol.net>
> > + *
> > + * Based on H6 one, which is:
> > + * (C) Copyright 2017  Icenowy Zheng <icenowy@aosc.io>
> > + *
> > + * SPDX-License-Identifier:	GPL-2.0+
> > + */
> > +
> > +#ifndef _SUNXI_DRAM_SUN50I_H616_H
> > +#define _SUNXI_DRAM_SUN50I_H616_H
> > +
> > +#include <stdbool.h>
> > +#ifndef __ASSEMBLY__
> > +#include <linux/bitops.h>
> > +#endif
> > +
> > +enum sunxi_dram_type {
> > +	SUNXI_DRAM_TYPE_DDR3 = 3,
> > +	SUNXI_DRAM_TYPE_DDR4,
> > +	SUNXI_DRAM_TYPE_LPDDR3 = 7,
> > +	SUNXI_DRAM_TYPE_LPDDR4
> > +};
> > +
> > +/* MBUS part is largely the same as in H6, except for one special
> > register */ +struct sunxi_mctl_com_reg {
> > +	u32 cr;			/* 0x000 control register */
> > +	u8 reserved_0x004[4];	/* 0x004 */
> > +	u32 unk_0x008;		/* 0x008 */
> > +	u32 tmr;		/* 0x00c timer register */
> > +	u8 reserved_0x010[4];	/* 0x010 */
> > +	u32 unk_0x014;		/* 0x014 */
> > +	u8 reserved_0x018[8];	/* 0x018 */
> > +	u32 maer0;		/* 0x020 master enable register 0 */
> > +	u32 maer1;		/* 0x024 master enable register 1 */
> > +	u32 maer2;		/* 0x028 master enable register 2 */
> > +	u8 reserved_0x02c[468];	/* 0x02c */
> > +	u32 bwcr;		/* 0x200 bandwidth control register */
> > +	u8 reserved_0x204[12];	/* 0x204 */
> > +	/*
> > +	 * The last master configured by BSP libdram is at 0x49x, so the
> > +	 * size of this struct array is set to 41 (0x29) now.
> > +	 */
> > +	struct {
> > +		u32 cfg0;		/* 0x0 */
> > +		u32 cfg1;		/* 0x4 */
> > +		u8 reserved_0x8[8];	/* 0x8 */
> > +	} master[41];		/* 0x210 + index * 0x10 */
> > +	u8 reserved_0x4a0[96];	/* 0x4a0 */
> > +	u32 unk_0x500;		/* 0x500 */
> > +};
> > +check_member(sunxi_mctl_com_reg, unk_0x500, 0x500);
> > +
> > +/*
> > + * Controller registers seems to be the same or at least very similar
> > + * to those in H6.
> > + */
> > +struct sunxi_mctl_ctl_reg {
> > +	u32 mstr;		/* 0x000 */
> > +	u32 statr;		/* 0x004 unused */
> > +	u32 mstr1;		/* 0x008 unused */
> > +	u32 unk_0x00c;		/* 0x00c */
> 
> This is clken (and the same on H6). It is obvious when looking at the
> standby power-down sequence.

Where is that sequence? I mostly consulted H6 and Zynq docs where this 
register is not explained. I'll update it in next revision.

Best regards,
Jernej

> 
> > +	u32 mrctrl0;		/* 0x010 unused */
> > +	u32 mrctrl1;		/* 0x014 unused */
> > +	u32 mrstatr;		/* 0x018 unused */
> > +	u32 mrctrl2;		/* 0x01c unused */
> > +	u32 derateen;		/* 0x020 unused */
> > +	u32 derateint;		/* 0x024 unused */
> > +	u8 reserved_0x028[8];	/* 0x028 */
> > +	u32 pwrctl;		/* 0x030 unused */
> > +	u32 pwrtmg;		/* 0x034 unused */
> > +	u32 hwlpctl;		/* 0x038 unused */
> > +	u8 reserved_0x03c[20];	/* 0x03c */
> > +	u32 rfshctl0;		/* 0x050 unused */
> > +	u32 rfshctl1;		/* 0x054 unused */
> > +	u8 reserved_0x058[8];	/* 0x05c */
> > +	u32 rfshctl3;		/* 0x060 */
> > +	u32 rfshtmg;		/* 0x064 */
> > +	u8 reserved_0x068[104];	/* 0x068 */
> > +	u32 init[8];		/* 0x0d0 */
> > +	u32 dimmctl;		/* 0x0f0 unused */
> > +	u32 rankctl;		/* 0x0f4 */
> > +	u8 reserved_0x0f8[8];	/* 0x0f8 */
> > +	u32 dramtmg[17];	/* 0x100 */
> > +	u8 reserved_0x144[60];	/* 0x144 */
> > +	u32 zqctl[3];		/* 0x180 */
> > +	u32 zqstat;		/* 0x18c unused */
> > +	u32 dfitmg0;		/* 0x190 */
> > +	u32 dfitmg1;		/* 0x194 */
> > +	u32 dfilpcfg[2];	/* 0x198 unused */
> > +	u32 dfiupd[3];		/* 0x1a0 */
> > +	u32 reserved_0x1ac;	/* 0x1ac */
> > +	u32 dfimisc;		/* 0x1b0 */
> > +	u32 dfitmg2;		/* 0x1b4 unused */
> > +	u32 dfitmg3;		/* 0x1b8 unused */
> > +	u32 dfistat;		/* 0x1bc */
> > +	u32 dbictl;		/* 0x1c0 */
> > +	u8 reserved_0x1c4[60];	/* 0x1c4 */
> > +	u32 addrmap[12];	/* 0x200 */
> > +	u8 reserved_0x230[16];	/* 0x230 */
> > +	u32 odtcfg;		/* 0x240 */
> > +	u32 odtmap;		/* 0x244 */
> > +	u8 reserved_0x248[8];	/* 0x248 */
> > +	u32 sched[2];		/* 0x250 */
> > +	u8 reserved_0x258[180];	/* 0x258 */
> > +	u32 dbgcmd;		/* 0x30c unused */
> > +	u32 dbgstat;		/* 0x310 unused */
> > +	u8 reserved_0x314[12];	/* 0x314 */
> > +	u32 swctl;		/* 0x320 */
> > +	u32 swstat;		/* 0x324 */
> > +	u8 reserved_0x328[7768];/* 0x328 */
> > +	u32 unk_0x2180;		/* 0x2180 */
> > +	u8 reserved_0x2184[188];/* 0x2184 */
> > +	u32 unk_0x2240;		/* 0x2240 */
> > +	u8 reserved_0x2244[3900];/* 0x2244 */
> > +	u32 unk_0x3180;		/* 0x3180 */
> > +	u8 reserved_0x3184[188];/* 0x3184 */
> > +	u32 unk_0x3240;		/* 0x3240 */
> > +	u8 reserved_0x3244[3900];/* 0x3244 */
> > +	u32 unk_0x4180;		/* 0x4180 */
> > +	u8 reserved_0x4184[188];/* 0x4184 */
> > +	u32 unk_0x4240;		/* 0x4240 */
> > +};
> > +check_member(sunxi_mctl_ctl_reg, swstat, 0x324);
> > +check_member(sunxi_mctl_ctl_reg, unk_0x4240, 0x4240);
> > +
> > +#define MSTR_DEVICETYPE_DDR3	BIT(0)
> > +#define MSTR_DEVICETYPE_LPDDR2	BIT(2)
> > +#define MSTR_DEVICETYPE_LPDDR3	BIT(3)
> > +#define MSTR_DEVICETYPE_DDR4	BIT(4)
> > +#define MSTR_DEVICETYPE_MASK	GENMASK(5, 0)
> > +#define MSTR_2TMODE		BIT(10)
> > +#define MSTR_BUSWIDTH_FULL	(0 << 12)
> > +#define MSTR_BUSWIDTH_HALF	(1 << 12)
> > +#define MSTR_ACTIVE_RANKS(x)	(((x == 2) ? 3 : 1) << 24)
> > +#define MSTR_BURST_LENGTH(x)	(((x) >> 1) << 16)
> > +
> > +struct dram_para {
> > +	u32 clk;
> > +	enum sunxi_dram_type type;
> > +	u8 cols;
> > +	u8 rows;
> > +	u8 ranks;
> > +	u8 bus_full_width;
> > +};
> > +
> > +
> > +static inline int ns_to_t(int nanoseconds)
> > +{
> > +	const unsigned int ctrl_freq = CONFIG_DRAM_CLK / 2;
> > +
> > +	return DIV_ROUND_UP(ctrl_freq * nanoseconds, 1000);
> > +}
> > +
> > +void mctl_set_timing_params(struct dram_para *para);
> > +
> > +#endif /* _SUNXI_DRAM_SUN50I_H616_H */
> > diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> > index 69ab670abf39..1a5497989f04 100644
> > --- a/arch/arm/mach-sunxi/Kconfig
> > +++ b/arch/arm/mach-sunxi/Kconfig
> > @@ -48,6 +48,46 @@ config DRAM_SUN50I_H6
> > 
> >  	  Select this dram controller driver for some sun50i platforms,
> >  	  like H6.
> > 
> > +config DRAM_SUN50I_H616
> > +	bool
> > +	help
> > +	  Select this dram controller driver for some sun50i platforms,
> > +	  like H616.
> > +
> > +if DRAM_SUN50I_H616
> > +config DRAM_SUN50I_H616_WRITE_LEVELING
> > +	bool "H616 DRAM write leveling"
> > +	---help---
> > +	  Select this when DRAM on your H616 board needs write leveling.
> > +
> > +config DRAM_SUN50I_H616_READ_CALIBRATION
> > +	bool"H616 DRAM read calibration"
> 
> Missing a space here.
> 
> > +	---help---
> > +	  Select this when DRAM on your H616 board needs read calibration.
> > +
> > +config DRAM_SUN50I_H616_READ_TRAINING
> > +	bool "H616 DRAM read training"
> > +	---help---
> > +	  Select this when DRAM on your H616 board needs read training.
> > +
> > +config DRAM_SUN50I_H616_WRITE_TRAINING
> > +	bool "H616 DRAM write training"
> > +	---help---
> > +	  Select this when DRAM on your H616 board needs write training.
> > +
> > +config DRAM_SUN50I_H616_BIT_DELAY_COMPENSATION
> > +	bool "H616 DRAM bit delay compensation"
> > +	---help---
> > +	  Select this when DRAM on your H616 board needs bit delay
> > +	  compensation.
> > +
> > +config DRAM_SUN50I_H616_UNKNOWN_FEATURE
> > +	bool "H616 DRAM unknown feature"
> > +	---help---
> > +	  Select this when DRAM on your H616 board needs this unknown
> > +	  feature.
> > +endif
> > +
> > 
> >  config SUN6I_P2WI
> >  
> >  	bool "Allwinner sun6i internal P2WI controller"
> >  	help
> > 
> > @@ -423,6 +463,7 @@ config DRAM_CLK
> > 
> >  		       MACH_SUN8I_V3S
> >  	
> >  	default 672 if MACH_SUN50I
> >  	default 744 if MACH_SUN50I_H6
> > 
> > +	default 720 if MACH_SUN50I_H616
> > 
> >  	---help---
> >  	Set the dram clock speed, valid range 240 - 480 (prior to sun9i),
> >  	must be a multiple of 24. For the sun9i (A80), the tested values
> > 
> > @@ -439,6 +480,7 @@ endif
> > 
> >  config DRAM_ZQ
> >  
> >  	int "sunxi dram zq value"
> > 
> > +	depends on !MACH_SUN50I_H616
> > 
> >  	default 123 if MACH_SUN4I || MACH_SUN5I || MACH_SUN6I || \
> >  	
> >  		       MACH_SUN8I_A23 || MACH_SUN8I_A33 || 
MACH_SUN8I_A83T
> >  	
> >  	default 127 if MACH_SUN7I
> > 
> > @@ -456,6 +498,7 @@ config DRAM_ODT_EN
> > 
> >  	default y if MACH_SUN8I_R40
> >  	default y if MACH_SUN50I
> >  	default y if MACH_SUN50I_H6
> > 
> > +	default y if MACH_SUN50I_H616
> > 
> >  	---help---
> >  	Select this to enable dram odt (on die termination).
> > 
> > diff --git a/arch/arm/mach-sunxi/Makefile b/arch/arm/mach-sunxi/Makefile
> > index b8aca43d6630..3f081d92f379 100644
> > --- a/arch/arm/mach-sunxi/Makefile
> > +++ b/arch/arm/mach-sunxi/Makefile
> > @@ -40,4 +40,6 @@ obj-$(CONFIG_SUNXI_DRAM_DW)	+= dram_sunxi_dw.o
> > 
> >  obj-$(CONFIG_SUNXI_DRAM_DW)	+= dram_timings/
> >  obj-$(CONFIG_DRAM_SUN50I_H6)	+= dram_sun50i_h6.o
> >  obj-$(CONFIG_DRAM_SUN50I_H6)	+= dram_timings/
> > 
> > +obj-$(CONFIG_DRAM_SUN50I_H616)	+= dram_sun50i_h616.o
> > +obj-$(CONFIG_DRAM_SUN50I_H616)	+= dram_timings/
> > 
> >  endif
> > 
> > diff --git a/arch/arm/mach-sunxi/dram_sun50i_h616.c
> > b/arch/arm/mach-sunxi/dram_sun50i_h616.c new file mode 100644
> > index 000000000000..0c86f54b8a73[...]

  reply	other threads:[~2021-01-04 18:39 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-03  9:26 [PATCH 00/17] sunxi: Introduce H616 support Jernej Skrabec
2021-01-03  9:26 ` [PATCH 01/17] sunxi: Add support for AXP305 PMIC Jernej Skrabec
2021-01-05 22:36   ` Jaehoon Chung
2021-01-06 10:11     ` André Przywara
2021-01-06 23:33       ` Jaehoon Chung
2021-01-07  9:49         ` André Przywara
2021-01-11  0:02   ` André Przywara
2021-01-11  1:32     ` Jaehoon Chung
2021-01-11 19:48     ` Jernej Škrabec
2021-01-03  9:26 ` [PATCH 02/17] sunxi: Introduce common symbol for H6 like SoCs Jernej Skrabec
2021-01-03 23:43   ` [linux-sunxi] " Samuel Holland
2021-01-04 10:35     ` André Przywara
2021-01-04 18:28       ` Jernej Škrabec
2021-01-11  0:13         ` André Przywara
2021-01-03  9:26 ` [PATCH 03/17] mmc: sunxi: Replace H6 ifdefs with H6 gen macro Jernej Skrabec
2021-01-11  0:13   ` André Przywara
2021-01-03  9:26 ` [PATCH 04/17] i2c: mvtwsi: sunxi: update macro Jernej Skrabec
2021-01-03 23:55   ` [linux-sunxi] " Samuel Holland
2021-01-04  5:57   ` Heiko Schocher
2021-01-03  9:26 ` [PATCH 05/17] sunxi: prcm: Add memory map for H6 like SoCs Jernej Skrabec
2021-01-04  0:03   ` [linux-sunxi] " Samuel Holland
2021-01-11 16:13     ` Jernej Škrabec
2021-01-03  9:26 ` [PATCH 06/17] sunxi: Add support for I2C on " Jernej Skrabec
2021-01-04  0:04   ` [linux-sunxi] " Samuel Holland
2021-01-03  9:26 ` [PATCH 07/17] sunxi: support loading with SPL > 32KB Jernej Skrabec
2021-01-04  2:02   ` [linux-sunxi] " Samuel Holland
2021-01-11 18:17     ` Jernej Škrabec
2021-01-03  9:26 ` [PATCH 08/17] sunxi: introduce support for H616 clocks Jernej Skrabec
2021-01-04  2:28   ` [linux-sunxi] " Samuel Holland
2021-01-03  9:26 ` [PATCH 09/17] sunxi: add support for H616 uart0 Jernej Skrabec
2021-01-04  2:30   ` [linux-sunxi] " Samuel Holland
2021-01-03  9:26 ` [PATCH 10/17] sunxi: add support for R_I2C on H616 Jernej Skrabec
2021-01-04  2:33   ` [linux-sunxi] " Samuel Holland
2021-01-04 18:36     ` Jernej Škrabec
2021-01-03  9:26 ` [PATCH 11/17] sunxi: Add H616 DRAM support Jernej Skrabec
2021-01-04  2:39   ` [linux-sunxi] " Samuel Holland
2021-01-04 18:39     ` Jernej Škrabec [this message]
2021-01-05  3:14       ` Samuel Holland
2021-01-03  9:26 ` [PATCH 12/17] sunxi: Add support for H616 SoC Jernej Skrabec
2021-01-04  2:47   ` [linux-sunxi] " Samuel Holland
2021-01-04 18:43     ` Jernej Škrabec
2021-01-03  9:26 ` [PATCH 13/17] net: sun8i-emac: Determine pinmux based on SoC, not EMAC type Jernej Skrabec
2021-01-03  9:26 ` [PATCH 14/17] arm: sunxi: add initial H616 DTSI and headers Jernej Skrabec
2021-01-03  9:26 ` [PATCH 15/17] sunxi: gpio: introduce compatible for H616 Jernej Skrabec
2021-01-11  0:36   ` André Przywara
2021-01-03  9:26 ` [PATCH 16/17] clk: sunxi: Add support for H616 clocks Jernej Skrabec
2021-01-11  0:44   ` André Przywara
2021-01-03  9:26 ` [PATCH 17/17] sunxi: Add support for OrangePi Zero2 Jernej Skrabec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3515536.VdQlbGyI4E@jernej-laptop \
    --to=jernej.skrabec@siol.net \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.