rockchip: rk3368: add DRAM controller driver with DRAM initialisation

This adds a DRAM controller driver for the RK3368 and places it in
drivers/ram/rockchip (where the other DM-enabled DRAM controller
drivers for rockchip devices should also be moved eventually).

At this stage, only the following feature-set is supported:
 - DDR3
 - 32-bit configuration (i.e. fully populated)
 - dual-rank (i.e. no auto-detection of ranks)
 - DDR3-1600K speed-bin

This driver expects to run from a TPL stage that will later return to
the RK3368 BROM.  It communicates with later stages through the
os_reg2 in the pmugrf (i.e. using the same mechanism as Rockchip's DDR
init code).

Unlike other DMC drivers for RK32xx and RK33xx parts, the required
timings are calculated within the driver based on a target frequency
and a DDR3 speed-bin (only the DDR3-1600K speed-bin is support at this
time).

The RK3368 also has the DDRC0_CON0 (DDR ch. 0, control-register 0)
register for controlling the operation of its (single-channel) DRAM
controller in the GRF block.  This provides for selecting DDR3, mobile
DDR modes, and control low-power operation.
As part of this change, DDRC0_CON0 is also added to the GRF structure
definition (at offset 0x600).

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
master
Philipp Tomsich 7 years ago
parent 832567d5aa
commit 403e9cbcd5
  1. 187
      arch/arm/include/asm/arch-rockchip/ddr_rk3368.h
  2. 3
      arch/arm/include/asm/arch-rockchip/grf_rk3368.h
  3. 1
      arch/arm/mach-rockchip/rk3368/Makefile
  4. 60
      arch/arm/mach-rockchip/rk3368/sdram_rk3368.c
  5. 67
      doc/device-tree-bindings/clock/rockchip,rk3368-dmc.txt
  6. 2
      drivers/ram/Makefile
  7. 7
      drivers/ram/rockchip/Makefile
  8. 1007
      drivers/ram/rockchip/dmc-rk3368.c
  9. 30
      include/dt-bindings/memory/rk3368-dmc.h

@ -0,0 +1,187 @@
/*
* (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
*
* SPDX-License-Identifier: GPL-2.0
*/
#ifndef __ASM_ARCH_DDR_RK3368_H__
#define __ASM_ARCH_DDR_RK3368_H__
/*
* The RK3368 DDR PCTL differs from the incarnation in the RK3288 only
* in a few details. Most notably, it has an additional field to track
* tREFI in controller cycles (i.e. trefi_mem_ddr3).
*/
struct rk3368_ddr_pctl {
u32 scfg;
u32 sctl;
u32 stat;
u32 intrstat;
u32 reserved0[12];
u32 mcmd;
u32 powctl;
u32 powstat;
u32 cmdtstat;
u32 cmdtstaten;
u32 reserved1[3];
u32 mrrcfg0;
u32 mrrstat0;
u32 mrrstat1;
u32 reserved2[4];
u32 mcfg1;
u32 mcfg;
u32 ppcfg;
u32 mstat;
u32 lpddr2zqcfg;
u32 reserved3;
u32 dtupdes;
u32 dtuna;
u32 dtune;
u32 dtuprd0;
u32 dtuprd1;
u32 dtuprd2;
u32 dtuprd3;
u32 dtuawdt;
u32 reserved4[3];
u32 togcnt1u;
u32 tinit;
u32 trsth;
u32 togcnt100n;
u32 trefi;
u32 tmrd;
u32 trfc;
u32 trp;
u32 trtw;
u32 tal;
u32 tcl;
u32 tcwl;
u32 tras;
u32 trc;
u32 trcd;
u32 trrd;
u32 trtp;
u32 twr;
u32 twtr;
u32 texsr;
u32 txp;
u32 txpdll;
u32 tzqcs;
u32 tzqcsi;
u32 tdqs;
u32 tcksre;
u32 tcksrx;
u32 tcke;
u32 tmod;
u32 trstl;
u32 tzqcl;
u32 tmrr;
u32 tckesr;
u32 tdpd;
u32 trefi_mem_ddr3;
u32 reserved5[45];
u32 dtuwactl;
u32 dturactl;
u32 dtucfg;
u32 dtuectl;
u32 dtuwd0;
u32 dtuwd1;
u32 dtuwd2;
u32 dtuwd3;
u32 dtuwdm;
u32 dturd0;
u32 dturd1;
u32 dturd2;
u32 dturd3;
u32 dtulfsrwd;
u32 dtulfsrrd;
u32 dtueaf;
u32 dfitctrldelay;
u32 dfiodtcfg;
u32 dfiodtcfg1;
u32 dfiodtrankmap;
u32 dfitphywrdata;
u32 dfitphywrlat;
u32 reserved7[2];
u32 dfitrddataen;
u32 dfitphyrdlat;
u32 reserved8[2];
u32 dfitphyupdtype0;
u32 dfitphyupdtype1;
u32 dfitphyupdtype2;
u32 dfitphyupdtype3;
u32 dfitctrlupdmin;
u32 dfitctrlupdmax;
u32 dfitctrlupddly;
u32 reserved9;
u32 dfiupdcfg;
u32 dfitrefmski;
u32 dfitctrlupdi;
u32 reserved10[4];
u32 dfitrcfg0;
u32 dfitrstat0;
u32 dfitrwrlvlen;
u32 dfitrrdlvlen;
u32 dfitrrdlvlgateen;
u32 dfiststat0;
u32 dfistcfg0;
u32 dfistcfg1;
u32 reserved11;
u32 dfitdramclken;
u32 dfitdramclkdis;
u32 dfistcfg2;
u32 dfistparclr;
u32 dfistparlog;
u32 reserved12[3];
u32 dfilpcfg0;
u32 reserved13[3];
u32 dfitrwrlvlresp0;
u32 dfitrwrlvlresp1;
u32 dfitrwrlvlresp2;
u32 dfitrrdlvlresp0;
u32 dfitrrdlvlresp1;
u32 dfitrrdlvlresp2;
u32 dfitrwrlvldelay0;
u32 dfitrwrlvldelay1;
u32 dfitrwrlvldelay2;
u32 dfitrrdlvldelay0;
u32 dfitrrdlvldelay1;
u32 dfitrrdlvldelay2;
u32 dfitrrdlvlgatedelay0;
u32 dfitrrdlvlgatedelay1;
u32 dfitrrdlvlgatedelay2;
u32 dfitrcmd;
u32 reserved14[46];
u32 ipvr;
u32 iptr;
};
check_member(rk3368_ddr_pctl, iptr, 0x03fc);
struct rk3368_ddrphy {
u32 reg[0x100];
};
check_member(rk3368_ddrphy, reg[0xff], 0x03fc);
struct rk3368_msch {
u32 coreid;
u32 revisionid;
u32 ddrconf;
u32 ddrtiming;
u32 ddrmode;
u32 readlatency;
u32 reserved1[8];
u32 activate;
u32 devtodev;
};
check_member(rk3368_msch, devtodev, 0x003c);
/* GRF_SOC_CON0 */
enum {
NOC_RSP_ERR_STALL = BIT(9),
MOBILE_DDR_SEL = BIT(4),
DDR0_16BIT_EN = BIT(3),
MSCH0_MAINDDR3_DDR3 = BIT(2),
MSCH0_MAINPARTIALPOP = BIT(1),
UPCTL_C_ACTIVE = BIT(0),
};
#endif

@ -76,8 +76,11 @@ struct rk3368_grf {
u32 soc_con15;
u32 soc_con16;
u32 soc_con17;
u32 reserved5[0x6e];
u32 ddrc0_con0;
};
check_member(rk3368_grf, soc_con17, 0x444);
check_member(rk3368_grf, ddrc0_con0, 0x600);
struct rk3368_pmu_grf {
u32 gpio0a_iomux;

@ -5,5 +5,4 @@
#
obj-y += clk_rk3368.o
obj-y += rk3368.o
obj-y += sdram_rk3368.o
obj-y += syscon_rk3368.o

@ -1,60 +0,0 @@
/*
* (C) Copyright 2016 Rockchip Electronics Co., Ltd.
*
* SPDX-License-Identifier: GPL-2.0
*/
#include <common.h>
#include <dm.h>
#include <ram.h>
#include <syscon.h>
#include <asm/arch/clock.h>
#include <asm/arch/grf_rk3368.h>
#include <asm/arch/sdram_common.h>
DECLARE_GLOBAL_DATA_PTR;
struct dram_info {
struct ram_info info;
struct rk3368_pmu_grf *pmugrf;
};
static int rk3368_dmc_probe(struct udevice *dev)
{
struct dram_info *priv = dev_get_priv(dev);
priv->pmugrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF);
debug("%s: grf=%p\n", __func__, priv->pmugrf);
priv->info.base = CONFIG_SYS_SDRAM_BASE;
priv->info.size = rockchip_sdram_size(
(phys_addr_t)&priv->pmugrf->os_reg[2]);
return 0;
}
static int rk3368_dmc_get_info(struct udevice *dev, struct ram_info *info)
{
struct dram_info *priv = dev_get_priv(dev);
*info = priv->info;
return 0;
}
static struct ram_ops rk3368_dmc_ops = {
.get_info = rk3368_dmc_get_info,
};
static const struct udevice_id rk3368_dmc_ids[] = {
{ .compatible = "rockchip,rk3368-dmc" },
{ }
};
U_BOOT_DRIVER(dmc_rk3368) = {
.name = "rockchip_rk3368_dmc",
.id = UCLASS_RAM,
.of_match = rk3368_dmc_ids,
.ops = &rk3368_dmc_ops,
.probe = rk3368_dmc_probe,
.priv_auto_alloc_size = sizeof(struct dram_info),
};

@ -0,0 +1,67 @@
RK3368 dynamic memory controller driver
=======================================
The RK3368 DMC (dynamic memory controller) driver supports setup/initialisation
during TPL using configuration data from the DTS (i.e. OF_PLATDATA), based on
the following key configuration data:
(a) a target-frequency (i.e. operating point) for the memory operation
(b) a speed-bin (as defined in JESD-79) for the DDR3 used in hardware
(c) a memory-schedule (i.e. mapping from physical addresses to the address
pins of the memory bus)
Required properties
-------------------
- compatible: "rockchip,rk3368-dmc"
- reg
protocol controller (PCTL) address and PHY controller (DDRPHY) address
- rockchip,ddr-speed-bin
the DDR3 device's speed-bin (as specified according to JESD-79)
DDR3_800D (5-5-5)
DDR3_800E (6-6-6)
DDR3_1066E (6-6-6)
DDR3_1066F (7-7-7)
DDR3_1066G (8-8-8)
DDR3_1333F (7-7-7)
DDR3_1333G (8-8-8)
DDR3_1333H (9-9-9)
DDR3_1333J (10-10-10)
DDR3_1600G (8-8-8)
DDR3_1600H (9-9-9)
DDR3_1600J (10-10-10)
DDR3_1600K (11-11-11)
DDR3_1866J (10-10-10)
DDR3_1866K (11-11-11)
DDR3_1866L (12-12-12)
DDR3_1866M (13-13-13)
DDR3_2133K (11-11-11)
DDR3_2133L (12-12-12)
DDR3_2133M (13-13-13)
DDR3_2133N (14-14-14)
- rockchip,ddr-frequency:
target DDR clock frequency in Hz (not all frequencies may be supported,
as there's some cooperation from the clock-driver required)
- rockchip,memory-schedule:
controls the decoding of physical addresses to DRAM addressing (i.e. how
the physical address maps onto the address pins/chip-select of the device)
DMC_MSCH_CBDR: column -> bank -> device -> row
DMC_MSCH_CBRD: column -> band -> row -> device
DMC_MSCH_CRBD: column -> row -> band -> device
Example (for DDR3-1600K and 800MHz)
-----------------------------------
#include <dt-bindings/memory/rk3368-dmc.h>
dmc: dmc@ff610000 {
u-boot,dm-pre-reloc;
compatible = "rockchip,rk3368-dmc";
reg = <0 0xff610000 0 0x400
0 0xff620000 0 0x400>;
};
&dmc {
rockchip,ddr-speed-bin = <DDR3_1600K>;
rockchip,ddr-frequency = <800000000>;
rockchip,memory-schedule = <DMC_MSCH_CBRD>;
};

@ -8,3 +8,5 @@ obj-$(CONFIG_RAM) += ram-uclass.o
obj-$(CONFIG_SANDBOX) += sandbox_ram.o
obj-$(CONFIG_STM32_SDRAM) += stm32_sdram.o
obj-$(CONFIG_ARCH_BMIPS) += bmips_ram.o
obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/

@ -0,0 +1,7 @@
#
# Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
#
# SPDX-License-Identifier: GPL-2.0+
#
obj-$(CONFIG_ROCKCHIP_RK3368) = dmc-rk3368.o

File diff suppressed because it is too large Load Diff

@ -0,0 +1,30 @@
#ifndef DT_BINDINGS_RK3368_DMC_H
#define DT_BINDINGS_RK3368_DMC_H
#define DMC_MSCH_CBDR 0x0
#define DMC_MSCH_CBRD 0x1
#define DMC_MSCH_CRBD 0x2
#define DDR3_800D 0
#define DDR3_800E 1
#define DDR3_1066E 2
#define DDR3_1066F 3
#define DDR3_1066G 4
#define DDR3_1333F 5
#define DDR3_1333G 6
#define DDR3_1333H 7
#define DDR3_1333J 8
#define DDR3_1600G 9
#define DDR3_1600H 10
#define DDR3_1600J 11
#define DDR3_1600K 12
#define DDR3_1866J 13
#define DDR3_1866K 14
#define DDR3_1866L 15
#define DDR3_1866M 16
#define DDR3_2133K 17
#define DDR3_2133L 18
#define DDR3_2133M 19
#define DDR3_2133N 20
#endif
Loading…
Cancel
Save