Skip to contentSkip to conversation

rockchip: ram: add common code for sdram driver

PATCH Superseded Kever Yang 1 participant 18 messages Oct 25, 2019

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kever Yang

author
#0 lore raw

v2 cover rockchip: ram: add common code for sdram driver

The sdram drivers for Rockchip SoCs was all separate, some of the SoCs has similar hardware controller and phy, so we have a change to share the flow and some of the functions between different SoCs. This patch set implement a first version common code based on PX30, other SoCs has similar hardware can migrate to this common code, eg. rk3328 and rk3399 can use this common code.

This patch set also fix some bug for rk3399 by sync code from latest rockchip vendor code.

Changes in v2:
- Split the patches into multi smaller patches for easy to maintain, review and test;
- Keep the DRAM_ROCKCHIP_DEBUG macro and enable it by default;
- Update the rockchip_sdram_size to support sys_reg3;

Kever Yang (13):
ram: rockchip: rename sdram.h to sdram_rk3288.h
ram: rockchip: rename sdram_common.c/h to sdram.c
rockchip: sdram: move cap structure and debug function to
sdram_common.h
rockchip: sdram: extend to use sys_reg3 for capacity info
rockchip: sdram: update the sys_reg to sys_reg2
ram: rockchip: add common code for sdram driver
ram: rockchip: move sdram_debug function into sdram_common
ram: rockchip: add controller code for PX30
ram: rockchip: add phy driver code for PX30
ram: rockchip: add common msch reg definition
ram: rockchip: update lpddr4 timing for rk3399
ram: rk3399: Sync the io setting from Rockchip vendor code
ram: rk3399: update calculate_stride

YouMin Chen (4):
ram: px30: add sdram driver
ram: rk3328: use common sdram driver
ram: rk3399: use common sdram driver
ram: rk3399: Sync code from rockchip vendor code

 arch/arm/dts/rk3328-sdram-ddr3-666.dtsi       |    4 +
 arch/arm/dts/rk3328-sdram-lpddr3-1600.dtsi    |    4 +
 arch/arm/dts/rk3328-sdram-lpddr3-666.dtsi     |    4 +
 arch/arm/dts/rk3399-sdram-ddr3-1333.dtsi      |    4 +
 arch/arm/dts/rk3399-sdram-ddr3-1600.dtsi      |    4 +
 arch/arm/dts/rk3399-sdram-ddr3-1866.dtsi      |    4 +
 .../arm/dts/rk3399-sdram-lpddr3-2GB-1600.dtsi |    4 +
 .../arm/dts/rk3399-sdram-lpddr3-4GB-1600.dtsi |    4 +
 .../rk3399-sdram-lpddr3-samsung-4GB-1866.dtsi |    4 +
 arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi     |    4 +
 arch/arm/include/asm/arch-rockchip/sdram.h    |  168 ++-
 .../include/asm/arch-rockchip/sdram_common.h  |  116 +-
 .../include/asm/arch-rockchip/sdram_msch.h    |   85 ++
 .../asm/arch-rockchip/sdram_pctl_px30.h       |  139 ++
 .../asm/arch-rockchip/sdram_phy_px30.h        |   62 +
 .../arch-rockchip/sdram_phy_ron_rtt_px30.h    |   59 +
 .../include/asm/arch-rockchip/sdram_px30.h    |  212 +++
 .../include/asm/arch-rockchip/sdram_rk3288.h  |  102 ++
 .../include/asm/arch-rockchip/sdram_rk3328.h  |  420 ++----
 .../include/asm/arch-rockchip/sdram_rk3399.h  |   98 +-
 arch/arm/mach-rockchip/Kconfig                |    2 +
 arch/arm/mach-rockchip/Makefile               |    2 +-
 arch/arm/mach-rockchip/rk3036/rk3036.c        |    2 +-
 arch/arm/mach-rockchip/rk3288/rk3288.c        |    2 +-
 .../mach-rockchip/{sdram_common.c => sdram.c} |   85 +-
 arch/arm/mach-rockchip/spl.c                  |    1 -
 configs/evb-rk3328_defconfig                  |    2 +-
 configs/rock64-rk3328_defconfig               |    2 +-
 drivers/ram/rockchip/Kconfig                  |   23 +-
 drivers/ram/rockchip/Makefile                 |    7 +-
 drivers/ram/rockchip/dmc-rk3368.c             |    2 +-
 .../rockchip/sdram-px30-ddr3-detect-333.inc   |   72 +
 .../rockchip/sdram-px30-ddr4-detect-333.inc   |   75 +
 drivers/ram/rockchip/sdram-px30-ddr_skew.inc  |  121 ++
 .../rockchip/sdram-px30-lpddr2-detect-333.inc |   73 +
 .../rockchip/sdram-px30-lpddr3-detect-333.inc |   74 +
 .../ram/rockchip/sdram-rk3399-lpddr4-400.inc  |   28 +-
 .../ram/rockchip/sdram-rk3399-lpddr4-800.inc  |   28 +-
 drivers/ram/rockchip/sdram_common.c           |  429 ++++++
 drivers/ram/rockchip/sdram_debug.c            |    2 +-
 drivers/ram/rockchip/sdram_pctl_px30.c        |  205 +++
 drivers/ram/rockchip/sdram_phy_px30.c         |  205 +++
 drivers/ram/rockchip/sdram_px30.c             |  669 +++++++++
 drivers/ram/rockchip/sdram_rk3128.c           |    2 +-
 drivers/ram/rockchip/sdram_rk3188.c           |    2 +-
 drivers/ram/rockchip/sdram_rk322x.c           |    2 +-
 drivers/ram/rockchip/sdram_rk3288.c           |    2 +-
 drivers/ram/rockchip/sdram_rk3328.c           |  765 +++--------
 drivers/ram/rockchip/sdram_rk3399.c           | 1213 +++++++++++------
 49 files changed, 4040 insertions(+), 1558 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_msch.h
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_pctl_px30.h
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_phy_px30.h
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_phy_ron_rtt_px30.h
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_px30.h
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_rk3288.h
 rename arch/arm/mach-rockchip/{sdram_common.c => sdram.c} (60%)
 create mode 100644 drivers/ram/rockchip/sdram-px30-ddr3-detect-333.inc
 create mode 100644 drivers/ram/rockchip/sdram-px30-ddr4-detect-333.inc
 create mode 100644 drivers/ram/rockchip/sdram-px30-ddr_skew.inc
 create mode 100644 drivers/ram/rockchip/sdram-px30-lpddr2-detect-333.inc
 create mode 100644 drivers/ram/rockchip/sdram-px30-lpddr3-detect-333.inc
 create mode 100644 drivers/ram/rockchip/sdram_common.c
 create mode 100644 drivers/ram/rockchip/sdram_pctl_px30.c
 create mode 100644 drivers/ram/rockchip/sdram_phy_px30.c
 create mode 100644 drivers/ram/rockchip/sdram_px30.c
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/17 ram: rockchip: rename sdram.h to sdram_rk3288.h

The header file sdram.h is used for rk3288 and similar SoCs, rename it to make it more understandable.

---

Changes in v2: None

 arch/arm/include/asm/arch-rockchip/{sdram.h => sdram_rk3288.h} | 0
 arch/arm/mach-rockchip/spl.c                                   | 1 -
 drivers/ram/rockchip/dmc-rk3368.c                              | 2 +-
 drivers/ram/rockchip/sdram_rk3188.c                            | 2 +-
 drivers/ram/rockchip/sdram_rk3288.c                            | 2 +-
 5 files changed, 3 insertions(+), 4 deletions(-)
 rename arch/arm/include/asm/arch-rockchip/{sdram.h => sdram_rk3288.h} (100%)
arch/arm/include/asm/arch-rockchip/sdram_rk3288.h renamed from arch/arm/include/asm/arch-rockchip/sdram.h +0 -0
similarity index 100%
rename from arch/arm/include/asm/arch-rockchip/sdram.h
rename to arch/arm/include/asm/arch-rockchip/sdram_rk3288.h
arch/arm/mach-rockchip/spl.c +0 -1
index 33137cc5ef..1c091295b4 100644
@@ -9,7 +9,6 @@
 #include <ram.h>
 #include <spl.h>
 #include <asm/arch-rockchip/bootrom.h>
-#include <asm/arch-rockchip/sdram.h>
 #include <asm/io.h>
 
 DECLARE_GLOBAL_DATA_PTR;
drivers/ram/rockchip/dmc-rk3368.c +1 -1
index e52fc3baad..16d170adf8 100644
@@ -16,7 +16,7 @@
 #include <asm/arch-rockchip/cru_rk3368.h>
 #include <asm/arch-rockchip/grf_rk3368.h>
 #include <asm/arch-rockchip/ddr_rk3368.h>
-#include <asm/arch-rockchip/sdram.h>
+#include <asm/arch-rockchip/sdram_rk3288.h>
 #include <asm/arch-rockchip/sdram_common.h>
 
 struct dram_info {
drivers/ram/rockchip/sdram_rk3188.c +1 -1
index 00e52ec949..03e34331e1 100644
@@ -20,7 +20,7 @@
 #include <asm/arch-rockchip/ddr_rk3188.h>
 #include <asm/arch-rockchip/grf_rk3188.h>
 #include <asm/arch-rockchip/pmu_rk3188.h>
-#include <asm/arch-rockchip/sdram.h>
+#include <asm/arch-rockchip/sdram_rk3288.h>
 #include <asm/arch-rockchip/sdram_common.h>
 #include <linux/err.h>
 
drivers/ram/rockchip/sdram_rk3288.c +1 -1
index 5775254007..3b6c4a050d 100644
@@ -20,7 +20,7 @@
 #include <asm/arch-rockchip/ddr_rk3288.h>
 #include <asm/arch-rockchip/grf_rk3288.h>
 #include <asm/arch-rockchip/pmu_rk3288.h>
-#include <asm/arch-rockchip/sdram.h>
+#include <asm/arch-rockchip/sdram_rk3288.h>
 #include <asm/arch-rockchip/sdram_common.h>
 #include <linux/err.h>
 #include <power/regulator.h>
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/17 ram: rockchip: rename sdram_common.c/h to sdram.c

In reply to Kever Yang

rename sdram_common.c in arch/arm/mach-rockchip to sdram.c; so that we can use the file name sdram_common.c in dram driver for better understand the code;
clean the related file who has use the header file at the same time.

---

Changes in v2: None

 .../arm/include/asm/arch-rockchip/{sdram_common.h => sdram.h} | 4 ++--
 arch/arm/mach-rockchip/Makefile                               | 2 +-
 arch/arm/mach-rockchip/rk3036/rk3036.c                        | 2 +-
 arch/arm/mach-rockchip/rk3288/rk3288.c                        | 2 +-
 arch/arm/mach-rockchip/{sdram_common.c => sdram.c}            | 2 +-
 drivers/ram/rockchip/dmc-rk3368.c                             | 2 +-
 drivers/ram/rockchip/sdram_debug.c                            | 2 +-
 drivers/ram/rockchip/sdram_rk3128.c                           | 2 +-
 drivers/ram/rockchip/sdram_rk3188.c                           | 2 +-
 drivers/ram/rockchip/sdram_rk322x.c                           | 2 +-
 drivers/ram/rockchip/sdram_rk3288.c                           | 2 +-
 drivers/ram/rockchip/sdram_rk3328.c                           | 2 +-
 drivers/ram/rockchip/sdram_rk3399.c                           | 2 +-
 13 files changed, 14 insertions(+), 14 deletions(-)
 rename arch/arm/include/asm/arch-rockchip/{sdram_common.h => sdram.h} (98%)
 rename arch/arm/mach-rockchip/{sdram_common.c => sdram.c} (99%)
arch/arm/include/asm/arch-rockchip/sdram.h renamed from arch/arm/include/asm/arch-rockchip/sdram_common.h +2 -2
similarity index 98%
rename from arch/arm/include/asm/arch-rockchip/sdram_common.h
rename to arch/arm/include/asm/arch-rockchip/sdram.h
index 8027b53636..f3933f3598 100644
@@ -3,8 +3,8 @@
  * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
  */
 
-#ifndef _ASM_ARCH_SDRAM_COMMON_H
-#define _ASM_ARCH_SDRAM_COMMON_H
+#ifndef _ASM_ARCH_SDRAM_H
+#define _ASM_ARCH_SDRAM_H
 
 enum {
 	DDR4 = 0,
arch/arm/mach-rockchip/Makefile +1 -1
index 45d9b06233..a9563ade4f 100644
@@ -25,7 +25,7 @@ obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o
 obj-$(CONFIG_MISC_INIT_R) += misc.o
 endif
 
-obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o
+obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram.o
 
 obj-$(CONFIG_ROCKCHIP_RK3036) += rk3036/
 obj-$(CONFIG_ROCKCHIP_RK3128) += rk3128/
arch/arm/mach-rockchip/rk3036/rk3036.c +1 -1
index be458cfb64..e9ada6dea3 100644
@@ -43,7 +43,7 @@ void board_debug_uart_init(void)
 #if !CONFIG_IS_ENABLED(RAM)
 /*
  * When CONFIG_RAM is enabled, the dram_init() function is implemented
- * in sdram_common.c.
+ * in sdram.c.
  */
 int dram_init(void)
 {
arch/arm/mach-rockchip/rk3288/rk3288.c +1 -1
index 057ce92080..3e84523379 100644
@@ -15,7 +15,7 @@
 #include <asm/arch-rockchip/grf_rk3288.h>
 #include <asm/arch-rockchip/pmu_rk3288.h>
 #include <asm/arch-rockchip/qos_rk3288.h>
-#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
arch/arm/mach-rockchip/sdram.c renamed from arch/arm/mach-rockchip/sdram_common.c +1 -1
similarity index 99%
rename from arch/arm/mach-rockchip/sdram_common.c
rename to arch/arm/mach-rockchip/sdram.c
index 22a4aca940..acb1af765e 100644
@@ -7,7 +7,7 @@
 #include <dm.h>
 #include <ram.h>
 #include <asm/io.h>
-#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram.h>
 #include <dm/uclass-internal.h>
 
 DECLARE_GLOBAL_DATA_PTR;
drivers/ram/rockchip/dmc-rk3368.c +1 -1
index 16d170adf8..9df8f8f4af 100644
@@ -16,8 +16,8 @@
 #include <asm/arch-rockchip/cru_rk3368.h>
 #include <asm/arch-rockchip/grf_rk3368.h>
 #include <asm/arch-rockchip/ddr_rk3368.h>
+#include <asm/arch-rockchip/sdram.h>
 #include <asm/arch-rockchip/sdram_rk3288.h>
-#include <asm/arch-rockchip/sdram_common.h>
 
 struct dram_info {
 	struct ram_info info;
drivers/ram/rockchip/sdram_debug.c +1 -1
index 9cf662675b..133d1938d5 100644
@@ -7,7 +7,7 @@
 
 #include <common.h>
 #include <debug_uart.h>
-#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram.h>
 
 void sdram_print_dram_type(unsigned char dramtype)
 {
drivers/ram/rockchip/sdram_rk3128.c +1 -1
index bfabc22a7d..8486653c6f 100644
@@ -9,7 +9,7 @@
 #include <syscon.h>
 #include <asm/arch-rockchip/clock.h>
 #include <asm/arch-rockchip/grf_rk3128.h>
-#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram.h>
 
 struct dram_info {
 	struct ram_info info;
drivers/ram/rockchip/sdram_rk3188.c +1 -1
index 03e34331e1..d3e4316ef0 100644
@@ -20,8 +20,8 @@
 #include <asm/arch-rockchip/ddr_rk3188.h>
 #include <asm/arch-rockchip/grf_rk3188.h>
 #include <asm/arch-rockchip/pmu_rk3188.h>
+#include <asm/arch-rockchip/sdram.h>
 #include <asm/arch-rockchip/sdram_rk3288.h>
-#include <asm/arch-rockchip/sdram_common.h>
 #include <linux/err.h>
 
 struct chan_info {
drivers/ram/rockchip/sdram_rk322x.c +1 -1
index 94893e17cf..223f048161 100644
@@ -17,7 +17,7 @@
 #include <asm/arch-rockchip/hardware.h>
 #include <asm/arch-rockchip/sdram_rk322x.h>
 #include <asm/arch-rockchip/uart.h>
-#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram.h>
 #include <asm/types.h>
 #include <linux/err.h>
 
drivers/ram/rockchip/sdram_rk3288.c +1 -1
index 3b6c4a050d..690751d074 100644
@@ -20,8 +20,8 @@
 #include <asm/arch-rockchip/ddr_rk3288.h>
 #include <asm/arch-rockchip/grf_rk3288.h>
 #include <asm/arch-rockchip/pmu_rk3288.h>
+#include <asm/arch-rockchip/sdram.h>
 #include <asm/arch-rockchip/sdram_rk3288.h>
-#include <asm/arch-rockchip/sdram_common.h>
 #include <linux/err.h>
 #include <power/regulator.h>
 #include <power/rk8xx_pmic.h>
drivers/ram/rockchip/sdram_rk3328.c +1 -1
index e84c9be6a2..e7919337ea 100644
@@ -14,7 +14,7 @@
 #include <asm/arch-rockchip/clock.h>
 #include <asm/arch-rockchip/cru_rk3328.h>
 #include <asm/arch-rockchip/grf_rk3328.h>
-#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram.h>
 #include <asm/arch-rockchip/sdram_rk3328.h>
 #include <asm/arch-rockchip/uart.h>
 
drivers/ram/rockchip/sdram_rk3399.c +1 -1
index ed70137ce7..9b7de4ae41 100644
@@ -18,7 +18,7 @@
 #include <asm/arch-rockchip/grf_rk3399.h>
 #include <asm/arch-rockchip/pmu_rk3399.h>
 #include <asm/arch-rockchip/hardware.h>
-#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram.h>
 #include <asm/arch-rockchip/sdram_rk3399.h>
 #include <linux/err.h>
 #include <time.h>
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH v2 3/17 rockchip: sdram: move cap structure and debug function to sdram_common.h

In reply to Kever Yang

The sdram.h suppose to be helper file for sdram.c which including dram size decode and some u-boot related dram init interface, and all structure and function for dram driver move to sdram_common.h

---

Changes in v2: None

 arch/arm/include/asm/arch-rockchip/sdram.h    | 48 ---------------
 .../include/asm/arch-rockchip/sdram_common.h  | 59 +++++++++++++++++++
 .../include/asm/arch-rockchip/sdram_rk3328.h  |  1 +
 .../include/asm/arch-rockchip/sdram_rk3399.h  |  1 +
 4 files changed, 61 insertions(+), 48 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_common.h
arch/arm/include/asm/arch-rockchip/sdram.h +0 -48
index f3933f3598..01fc353d81 100644
@@ -15,34 +15,6 @@ enum {
 	UNUSED = 0xFF
 };
 
-struct sdram_cap_info {
-	unsigned int rank;
-	/* dram column number, 0 means this channel is invalid */
-	unsigned int col;
-	/* dram bank number, 3:8bank, 2:4bank */
-	unsigned int bk;
-	/* channel buswidth, 2:32bit, 1:16bit, 0:8bit */
-	unsigned int bw;
-	/* die buswidth, 2:32bit, 1:16bit, 0:8bit */
-	unsigned int dbw;
-	/*
-	 * row_3_4 = 1: 6Gb or 12Gb die
-	 * row_3_4 = 0: normal die, power of 2
-	 */
-	unsigned int row_3_4;
-	unsigned int cs0_row;
-	unsigned int cs1_row;
-	unsigned int ddrconfig;
-};
-
-struct sdram_base_params {
-	unsigned int ddr_freq;
-	unsigned int dramtype;
-	unsigned int num_channels;
-	unsigned int stride;
-	unsigned int odt;
-};
-
 /*
  * sys_reg bitfield struct
  * [31]		row_3_4_ch1
@@ -124,24 +96,4 @@ size_t rockchip_sdram_size(phys_addr_t reg);
 /* Called by U-Boot board_init_r for Rockchip SoCs */
 int dram_init(void);
 
-#if !defined(CONFIG_RAM_ROCKCHIP_DEBUG)
-inline void sdram_print_dram_type(unsigned char dramtype)
-{
-}
-
-inline void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
-				 struct sdram_base_params *base)
-{
-}
-
-inline void sdram_print_stride(unsigned int stride)
-{
-}
-#else
-void sdram_print_dram_type(unsigned char dramtype);
-void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
-			  struct sdram_base_params *base);
-void sdram_print_stride(unsigned int stride);
-#endif /* CONFIG_RAM_ROCKCHIP_DEBUG */
-
 #endif
arch/arm/include/asm/arch-rockchip/sdram_common.h new file +59 -0

59 lines not on this page · raw message

arch/arm/include/asm/arch-rockchip/sdram_rk3328.h +1 -0
index 11411ead10..c747b461a1 100644
@@ -6,6 +6,7 @@
 
 #ifndef _ASM_ARCH_SDRAM_RK3328_H
 #define _ASM_ARCH_SDRAM_RK3328_H
+#include <asm/arch-rockchip/sdram_common.h>
 
 #define SR_IDLE		93
 #define PD_IDLE		13
arch/arm/include/asm/arch-rockchip/sdram_rk3399.h +1 -0
index dc65ae7924..485bb3d889 100644
@@ -5,6 +5,7 @@
 
 #ifndef _ASM_ARCH_SDRAM_RK3399_H
 #define _ASM_ARCH_SDRAM_RK3399_H
+#include <asm/arch-rockchip/sdram_common.h>
 
 struct rk3399_ddr_pctl_regs {
 	u32 denali_ctl[332];
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH v2 4/17 rockchip: sdram: extend to use sys_reg3 for capacity info

In reply to Kever Yang

Since we have new DRAM type and to support different DRAM size in different CS, we need more bits, so introduce sys_reg3 to record the info. Note that the info in sys_reg3 is extension to sys_reg2 and the info in sys_reg2 is the same as before. We define the DRAM_INFO with sys_reg3 as VERSION2.
All the ENC macro are moved to sdram_common.h since the sdram.c only need to do the info decode.

---

Changes in v2: None

 arch/arm/include/asm/arch-rockchip/sdram.h    | 61 +++++++---------
 .../include/asm/arch-rockchip/sdram_common.h  | 69 +++++++++++++++++++
 arch/arm/mach-rockchip/sdram.c                | 69 ++++++++++++++++---
 3 files changed, 152 insertions(+), 47 deletions(-)
arch/arm/include/asm/arch-rockchip/sdram.h +24 -37
index 01fc353d81..cf2a7b7d10 100644
@@ -16,79 +16,66 @@ enum {
 };
 
 /*
- * sys_reg bitfield struct
+ * sys_reg2 bitfield struct
  * [31]		row_3_4_ch1
  * [30]		row_3_4_ch0
  * [29:28]	chinfo
  * [27]		rank_ch1
  * [26:25]	col_ch1
  * [24]		bk_ch1
- * [23:22]	cs0_row_ch1
- * [21:20]	cs1_row_ch1
+ * [23:22]	low bits of cs0_row_ch1
+ * [21:20]	low bits of cs1_row_ch1
  * [19:18]	bw_ch1
  * [17:16]	dbw_ch1;
  * [15:13]	ddrtype
  * [12]		channelnum
  * [11]		rank_ch0
- * [10:9]	col_ch0
+ * [10:9]	col_ch0,
  * [8]		bk_ch0
- * [7:6]	cs0_row_ch0
- * [5:4]	cs1_row_ch0
+ * [7:6]	low bits of cs0_row_ch0
+ * [5:4]	low bits of cs1_row_ch0
  * [3:2]	bw_ch0
  * [1:0]	dbw_ch0
-*/
+ */
 #define SYS_REG_DDRTYPE_SHIFT		13
-#define DDR_SYS_REG_VERSION		2
 #define SYS_REG_DDRTYPE_MASK		7
 #define SYS_REG_NUM_CH_SHIFT		12
 #define SYS_REG_NUM_CH_MASK		1
 #define SYS_REG_ROW_3_4_SHIFT(ch)	(30 + (ch))
 #define SYS_REG_ROW_3_4_MASK		1
-#define SYS_REG_ENC_ROW_3_4(n, ch)	((n) << (30 + (ch)))
 #define SYS_REG_CHINFO_SHIFT(ch)	(28 + (ch))
-#define SYS_REG_ENC_CHINFO(ch)		(1 << SYS_REG_CHINFO_SHIFT(ch))
-#define SYS_REG_ENC_DDRTYPE(n)		((n) << SYS_REG_DDRTYPE_SHIFT)
-#define SYS_REG_ENC_NUM_CH(n)		(((n) - SYS_REG_NUM_CH_MASK) << \
-					SYS_REG_NUM_CH_SHIFT)
 #define SYS_REG_RANK_SHIFT(ch)		(11 + (ch) * 16)
 #define SYS_REG_RANK_MASK		1
-#define SYS_REG_ENC_RANK(n, ch)		(((n) - SYS_REG_RANK_MASK) << \
-					 SYS_REG_RANK_SHIFT(ch))
 #define SYS_REG_COL_SHIFT(ch)		(9 + (ch) * 16)
 #define SYS_REG_COL_MASK		3
-#define SYS_REG_ENC_COL(n, ch)		(((n) - 9) << SYS_REG_COL_SHIFT(ch))
 #define SYS_REG_BK_SHIFT(ch)		(8 + (ch) * 16)
 #define SYS_REG_BK_MASK			1
-#define SYS_REG_ENC_BK(n, ch)		(((n) == 3 ? 0 : 1) << \
-					SYS_REG_BK_SHIFT(ch))
 #define SYS_REG_CS0_ROW_SHIFT(ch)	(6 + (ch) * 16)
 #define SYS_REG_CS0_ROW_MASK		3
 #define SYS_REG_CS1_ROW_SHIFT(ch)	(4 + (ch) * 16)
 #define SYS_REG_CS1_ROW_MASK		3
 #define SYS_REG_BW_SHIFT(ch)		(2 + (ch) * 16)
 #define SYS_REG_BW_MASK			3
-#define SYS_REG_ENC_BW(n, ch)		((2 >> (n)) << SYS_REG_BW_SHIFT(ch))
 #define SYS_REG_DBW_SHIFT(ch)		((ch) * 16)
 #define SYS_REG_DBW_MASK		3
-#define SYS_REG_ENC_DBW(n, ch)		((2 >> (n)) << SYS_REG_DBW_SHIFT(ch))
-
-#define SYS_REG_ENC_VERSION(n)		((n) << 28)
-#define SYS_REG_ENC_CS0_ROW(n, os_reg2, os_reg3, ch) do { \
-			(os_reg2) |= (((n) - 13) & 0x3) << (6 + 16 * (ch)); \
-			(os_reg3) |= ((((n) - 13) & 0x4) >> 2) << \
-				     (5 + 2 * (ch)); \
-		} while (0)
-
-#define SYS_REG_ENC_CS1_ROW(n, os_reg2, os_reg3, ch) do { \
-			(os_reg2) &= (~(0x3 << (4 + 16 * (ch)))); \
-			(os_reg3) &= (~(0x1 << (4 + 2 * (ch)))); \
-			(os_reg2) |= (((n) - 13) & 0x3) << (4 + 16 * (ch)); \
-			(os_reg3) |= ((((n) - 13) & 0x4) >> 2) << \
-				     (4 + 2 * (ch)); \
-		} while (0)
 
-#define SYS_REG_CS1_COL_SHIFT(ch)	(0 + 2 * (ch))
-#define SYS_REG_ENC_CS1_COL(n, ch)      (((n) - 9) << SYS_REG_CS1_COL_SHIFT(ch))
+/*
+ * sys_reg3 bitfield struct
+ * [7]		high bit of cs0_row_ch1
+ * [6]		high bit of cs1_row_ch1
+ * [5]		high bit of cs0_row_ch0
+ * [4]		high bit of cs1_row_ch0
+ * [3:2]	cs1_col_ch1
+ * [1:0]	cs1_col_ch0
+ */
+#define SYS_REG_VERSION_SHIFT			28
+#define SYS_REG_VERSION_MASK			0xf
+#define SYS_REG_EXTEND_CS0_ROW_SHIFT(ch)	(5 + (ch) * 2)
+#define SYS_REG_EXTEND_CS0_ROW_MASK		1
+#define SYS_REG_EXTEND_CS1_ROW_SHIFT(ch)	(4 + (ch) * 2)
+#define SYS_REG_EXTEND_CS1_ROW_MASK		1
+#define SYS_REG_CS1_COL_SHIFT(ch)		(0 + (ch) * 2)
+#define SYS_REG_CS1_COL_MASK			3
 
 /* Get sdram size decode from reg */
 size_t rockchip_sdram_size(phys_addr_t reg);
arch/arm/include/asm/arch-rockchip/sdram_common.h +69 -0

75 lines not on this page · raw message

arch/arm/mach-rockchip/sdram.c +59 -10

98 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#5 lore raw

PATCH v2 5/17 rockchip: sdram: update the sys_reg to sys_reg2

In reply to Kever Yang

We are using sys_reg2 and sys_reg3 as ddr cap info, sync the variable name to what we real use to avoid confuse people.

---

Changes in v2: None

 arch/arm/mach-rockchip/sdram.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
arch/arm/mach-rockchip/sdram.c +16 -16
index 8e5a572dba..af00a6b637 100644
@@ -83,60 +83,60 @@ size_t rockchip_sdram_size(phys_addr_t reg)
 	u32 cs1_col = 0;
 	u32 bg = 0;
 	u32 dbw, dram_type;
-	u32 sys_reg = readl(reg);
+	u32 sys_reg2 = readl(reg);
 	u32 sys_reg3 = readl(reg + 4);
-	u32 ch_num = 1 + ((sys_reg >> SYS_REG_NUM_CH_SHIFT)
+	u32 ch_num = 1 + ((sys_reg2 >> SYS_REG_NUM_CH_SHIFT)
 		       & SYS_REG_NUM_CH_MASK);
 
-	dram_type = (sys_reg >> SYS_REG_DDRTYPE_SHIFT) & SYS_REG_DDRTYPE_MASK;
-	debug("%s %x %x\n", __func__, (u32)reg, sys_reg);
+	dram_type = (sys_reg2 >> SYS_REG_DDRTYPE_SHIFT) & SYS_REG_DDRTYPE_MASK;
+	debug("%s %x %x\n", __func__, (u32)reg, sys_reg2);
 	for (ch = 0; ch < ch_num; ch++) {
-		rank = 1 + (sys_reg >> SYS_REG_RANK_SHIFT(ch) &
+		rank = 1 + (sys_reg2 >> SYS_REG_RANK_SHIFT(ch) &
 			SYS_REG_RANK_MASK);
-		cs0_col = 9 + (sys_reg >> SYS_REG_COL_SHIFT(ch) &
+		cs0_col = 9 + (sys_reg2 >> SYS_REG_COL_SHIFT(ch) &
 			  SYS_REG_COL_MASK);
 		cs1_col = cs0_col;
-		bk = 3 - ((sys_reg >> SYS_REG_BK_SHIFT(ch)) & SYS_REG_BK_MASK);
+		bk = 3 - ((sys_reg2 >> SYS_REG_BK_SHIFT(ch)) & SYS_REG_BK_MASK);
 		if ((sys_reg3 >> SYS_REG_VERSION_SHIFT &
 		     SYS_REG_VERSION_MASK) == 0x2) {
 			cs1_col = 9 + (sys_reg3 >> SYS_REG_CS1_COL_SHIFT(ch) &
 				  SYS_REG_CS1_COL_MASK);
 			if (((sys_reg3 >> SYS_REG_EXTEND_CS0_ROW_SHIFT(ch) &
-			    SYS_REG_EXTEND_CS0_ROW_MASK) << 2) + (sys_reg >>
+			    SYS_REG_EXTEND_CS0_ROW_MASK) << 2) + (sys_reg2 >>
 			    SYS_REG_CS0_ROW_SHIFT(ch) &
 			    SYS_REG_CS0_ROW_MASK) == 7)
 				cs0_row = 12;
 			else
-				cs0_row = 13 + (sys_reg >>
+				cs0_row = 13 + (sys_reg2 >>
 					  SYS_REG_CS0_ROW_SHIFT(ch) &
 					  SYS_REG_CS0_ROW_MASK) +
 					  ((sys_reg3 >>
 					  SYS_REG_EXTEND_CS0_ROW_SHIFT(ch) &
 					  SYS_REG_EXTEND_CS0_ROW_MASK) << 2);
 			if (((sys_reg3 >> SYS_REG_EXTEND_CS1_ROW_SHIFT(ch) &
-			    SYS_REG_EXTEND_CS1_ROW_MASK) << 2) + (sys_reg >>
+			    SYS_REG_EXTEND_CS1_ROW_MASK) << 2) + (sys_reg2 >>
 			    SYS_REG_CS1_ROW_SHIFT(ch) &
 			    SYS_REG_CS1_ROW_MASK) == 7)
 				cs1_row = 12;
 			else
-				cs1_row = 13 + (sys_reg >>
+				cs1_row = 13 + (sys_reg2 >>
 					  SYS_REG_CS1_ROW_SHIFT(ch) &
 					  SYS_REG_CS1_ROW_MASK) +
 					  ((sys_reg3 >>
 					  SYS_REG_EXTEND_CS1_ROW_SHIFT(ch) &
 					  SYS_REG_EXTEND_CS1_ROW_MASK) << 2);
 		} else {
-			cs0_row = 13 + (sys_reg >> SYS_REG_CS0_ROW_SHIFT(ch) &
+			cs0_row = 13 + (sys_reg2 >> SYS_REG_CS0_ROW_SHIFT(ch) &
 				SYS_REG_CS0_ROW_MASK);
-			cs1_row = 13 + (sys_reg >> SYS_REG_CS1_ROW_SHIFT(ch) &
+			cs1_row = 13 + (sys_reg2 >> SYS_REG_CS1_ROW_SHIFT(ch) &
 				SYS_REG_CS1_ROW_MASK);
 		}
-		bw = (2 >> ((sys_reg >> SYS_REG_BW_SHIFT(ch)) &
+		bw = (2 >> ((sys_reg2 >> SYS_REG_BW_SHIFT(ch)) &
 			SYS_REG_BW_MASK));
-		row_3_4 = sys_reg >> SYS_REG_ROW_3_4_SHIFT(ch) &
+		row_3_4 = sys_reg2 >> SYS_REG_ROW_3_4_SHIFT(ch) &
 			SYS_REG_ROW_3_4_MASK;
 		if (dram_type == DDR4) {
-			dbw = (sys_reg >> SYS_REG_DBW_SHIFT(ch)) &
+			dbw = (sys_reg2 >> SYS_REG_DBW_SHIFT(ch)) &
 				SYS_REG_DBW_MASK;
 			bg = (dbw == 2) ? 2 : 1;
 		}
Signature · 1 line
2.17.1
author
#6 lore raw

PATCH v2 6/17 ram: rockchip: add common code for sdram driver

In reply to Kever Yang

There are some function like os_reg setting, capacity detect functions, can be used as common code for different Rockchip SoCs, add a sdram_common.c for all these functions.

---

Changes in v2: None

 .../include/asm/arch-rockchip/sdram_common.h  |  31 ++
 drivers/ram/rockchip/Kconfig                  |   6 +
 drivers/ram/rockchip/Makefile                 |   2 +-
 drivers/ram/rockchip/sdram_common.c           | 285 ++++++++++++++++++
 4 files changed, 323 insertions(+), 1 deletion(-)
 create mode 100644 drivers/ram/rockchip/sdram_common.c
arch/arm/include/asm/arch-rockchip/sdram_common.h +31 -0
index cd3d7f97d8..36d31156be 100644
@@ -6,6 +6,15 @@
 #ifndef _ASM_ARCH_SDRAM_COMMON_H
 #define _ASM_ARCH_SDRAM_COMMON_H
 
+#ifndef MHZ
+#define MHZ		(1000 * 1000)
+#endif
+
+#define PATTERN		(0x5aa5f00f)
+
+#define MIN(a, b)	(((a) > (b)) ? (b) : (a))
+#define MAX(a, b)	(((a) > (b)) ? (a) : (b))
+
 struct sdram_cap_info {
 	unsigned int rank;
 	/* dram column number, 0 means this channel is invalid */
@@ -125,4 +134,26 @@ void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
 void sdram_print_stride(unsigned int stride);
 #endif /* CONFIG_RAM_ROCKCHIP_DEBUG */
 
+void sdram_org_config(struct sdram_cap_info *cap_info,
+		      struct sdram_base_params *base,
+		      u32 *p_os_reg2, u32 *p_os_reg3, u32 channel);
+
+int sdram_detect_bw(struct sdram_cap_info *cap_info);
+int sdram_detect_cs(struct sdram_cap_info *cap_info);
+int sdram_detect_col(struct sdram_cap_info *cap_info,
+		     u32 coltmp);
+int sdram_detect_bank(struct sdram_cap_info *cap_info,
+		      u32 coltmp, u32 bktmp);
+int sdram_detect_bg(struct sdram_cap_info *cap_info,
+		    u32 coltmp);
+int sdram_detect_dbw(struct sdram_cap_info *cap_info, u32 dram_type);
+int sdram_detect_row(struct sdram_cap_info *cap_info,
+		     u32 coltmp, u32 bktmp, u32 rowtmp);
+int sdram_detect_row_3_4(struct sdram_cap_info *cap_info,
+			 u32 coltmp, u32 bktmp);
+int sdram_detect_high_row(struct sdram_cap_info *cap_info);
+int sdram_detect_cs1_row(struct sdram_cap_info *cap_info, u32 dram_type);
+u64 sdram_get_cs_cap(struct sdram_cap_info *cap_info, u32 cs, u32 dram_type);
+void sdram_copy_to_reg(u32 *dest, const u32 *src, u32 n);
+
 #endif
drivers/ram/rockchip/Kconfig +6 -0
index 4f274e01b3..dcc06b3fd3 100644
@@ -5,6 +5,12 @@ config RAM_ROCKCHIP
 	help
 	  This enables support for ram drivers Rockchip SoCs.
 
+config ROCKCHIP_SDRAM_COMMON
+	bool "Enable rockchip sdram common driver"
+	depends on TPL_RAM || SPL_RAM
+	help
+	  This enable sdram common driver
+
 if RAM_ROCKCHIP
 
 config RAM_ROCKCHIP_DEBUG
drivers/ram/rockchip/Makefile +1 -1
index feb1f82d00..3d4f2f4ebf 100644
@@ -2,7 +2,7 @@
 #
 # Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
 #
-
+obj-$(CONFIG_ROCKCHIP_SDRAM_COMMON) += sdram_common.o
 obj-$(CONFIG_RAM_ROCKCHIP_DEBUG) += sdram_debug.o
 obj-$(CONFIG_ROCKCHIP_RK3368) = dmc-rk3368.o
 obj-$(CONFIG_ROCKCHIP_RK3128) = sdram_rk3128.o
drivers/ram/rockchip/sdram_common.c new file +285 -0

285 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#7 lore raw

PATCH v2 7/17 ram: rockchip: move sdram_debug function into sdram_common

In reply to Kever Yang

The functions for dram info print are part of common code.

---

Changes in v2: None

 drivers/ram/rockchip/Makefile       |   1 -
 drivers/ram/rockchip/sdram_common.c | 144 +++++++++++++++++++++++++++
 drivers/ram/rockchip/sdram_debug.c  | 147 ----------------------------
 3 files changed, 144 insertions(+), 148 deletions(-)
 delete mode 100644 drivers/ram/rockchip/sdram_debug.c
drivers/ram/rockchip/Makefile +0 -1
index 3d4f2f4ebf..483660e570 100644
@@ -3,7 +3,6 @@
 # Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
 #
 obj-$(CONFIG_ROCKCHIP_SDRAM_COMMON) += sdram_common.o
-obj-$(CONFIG_RAM_ROCKCHIP_DEBUG) += sdram_debug.o
 obj-$(CONFIG_ROCKCHIP_RK3368) = dmc-rk3368.o
 obj-$(CONFIG_ROCKCHIP_RK3128) = sdram_rk3128.o
 obj-$(CONFIG_ROCKCHIP_RK3188) = sdram_rk3188.o
drivers/ram/rockchip/sdram_common.c +144 -0

150 lines not on this page · raw message

drivers/ram/rockchip/sdram_debug.c deleted +0 -147

147 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#8 lore raw

PATCH v2 8/17 ram: rockchip: add controller code for PX30

In reply to Kever Yang

This sdram_pctl_px30.c is based on PX30 SoC, the functions are common for controller, other SoCs with similar hardware could re-use it.

---

Changes in v2: None

 .../asm/arch-rockchip/sdram_pctl_px30.h       | 139 ++++++++++++
 drivers/ram/rockchip/sdram_pctl_px30.c        | 205 ++++++++++++++++++
 2 files changed, 344 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_pctl_px30.h
 create mode 100644 drivers/ram/rockchip/sdram_pctl_px30.c
arch/arm/include/asm/arch-rockchip/sdram_pctl_px30.h new file +139 -0
new file mode 100644
index 0000000000..9781881738
@@ -0,0 +1,139 @@
+/* SPDX-License-Identifier:     GPL-2.0+ */
+/*
+ * Copyright (C) 2018 Rockchip Electronics Co., Ltd
+ */
+
+#ifndef _ASM_ARCH_SDRAM_PCTL_PX30_H
+#define _ASM_ARCH_SDRAM_PCTL_PX30_H
+#include <asm/arch-rockchip/sdram_common.h>
+
+struct ddr_pctl_regs {
+	u32 pctl[30][2];
+};
+
+/* ddr pctl registers define */
+#define DDR_PCTL2_MSTR			0x0
+#define DDR_PCTL2_STAT			0x4
+#define DDR_PCTL2_MSTR1			0x8
+#define DDR_PCTL2_MRCTRL0		0x10
+#define DDR_PCTL2_MRCTRL1		0x14
+#define DDR_PCTL2_MRSTAT		0x18
+#define DDR_PCTL2_MRCTRL2		0x1c
+#define DDR_PCTL2_DERATEEN		0x20
+#define DDR_PCTL2_DERATEINT		0x24
+#define DDR_PCTL2_PWRCTL		0x30
+#define DDR_PCTL2_PWRTMG		0x34
+#define DDR_PCTL2_HWLPCTL		0x38
+#define DDR_PCTL2_RFSHCTL0		0x50
+#define DDR_PCTL2_RFSHCTL1		0x54
+#define DDR_PCTL2_RFSHCTL2		0x58
+#define DDR_PCTL2_RFSHCTL4		0x5c
+#define DDR_PCTL2_RFSHCTL3		0x60
+#define DDR_PCTL2_RFSHTMG		0x64
+#define DDR_PCTL2_RFSHTMG1		0x68
+#define DDR_PCTL2_RFSHCTL5		0x6c
+#define DDR_PCTL2_INIT0			0xd0
+#define DDR_PCTL2_INIT1			0xd4
+#define DDR_PCTL2_INIT2			0xd8
+#define DDR_PCTL2_INIT3			0xdc
+#define DDR_PCTL2_INIT4			0xe0
+#define DDR_PCTL2_INIT5			0xe4
+#define DDR_PCTL2_INIT6			0xe8
+#define DDR_PCTL2_INIT7			0xec
+#define DDR_PCTL2_DIMMCTL		0xf0
+#define DDR_PCTL2_RANKCTL		0xf4
+#define DDR_PCTL2_CHCTL			0xfc
+#define DDR_PCTL2_DRAMTMG0		0x100
+#define DDR_PCTL2_DRAMTMG1		0x104
+#define DDR_PCTL2_DRAMTMG2		0x108
+#define DDR_PCTL2_DRAMTMG3		0x10c
+#define DDR_PCTL2_DRAMTMG4		0x110
+#define DDR_PCTL2_DRAMTMG5		0x114
+#define DDR_PCTL2_DRAMTMG6		0x118
+#define DDR_PCTL2_DRAMTMG7		0x11c
+#define DDR_PCTL2_DRAMTMG8		0x120
+#define DDR_PCTL2_DRAMTMG9		0x124
+#define DDR_PCTL2_DRAMTMG10		0x128
+#define DDR_PCTL2_DRAMTMG11		0x12c
+#define DDR_PCTL2_DRAMTMG12		0x130
+#define DDR_PCTL2_DRAMTMG13		0x134
+#define DDR_PCTL2_DRAMTMG14		0x138
+#define DDR_PCTL2_DRAMTMG15		0x13c
+#define DDR_PCTL2_DRAMTMG16		0x140
+#define DDR_PCTL2_ZQCTL0		0x180
+#define DDR_PCTL2_ZQCTL1		0x184
+#define DDR_PCTL2_ZQCTL2		0x188
+#define DDR_PCTL2_ZQSTAT		0x18c
+#define DDR_PCTL2_DFITMG0		0x190
+#define DDR_PCTL2_DFITMG1		0x194
+#define DDR_PCTL2_DFILPCFG0		0x198
+#define DDR_PCTL2_DFILPCFG1		0x19c
+#define DDR_PCTL2_DFIUPD0		0x1a0
+#define DDR_PCTL2_DFIUPD1		0x1a4
+#define DDR_PCTL2_DFIUPD2		0x1a8
+#define DDR_PCTL2_DFIMISC		0x1b0
+#define DDR_PCTL2_DFITMG2		0x1b4
+#define DDR_PCTL2_DFITMG3		0x1b8
+#define DDR_PCTL2_DFISTAT		0x1bc
+#define DDR_PCTL2_DBICTL		0x1c0
+#define DDR_PCTL2_ADDRMAP0		0x200
+#define DDR_PCTL2_ADDRMAP1		0x204
+#define DDR_PCTL2_ADDRMAP2		0x208
+#define DDR_PCTL2_ADDRMAP3		0x20c
+#define DDR_PCTL2_ADDRMAP4		0x210
+#define DDR_PCTL2_ADDRMAP5		0x214
+#define DDR_PCTL2_ADDRMAP6		0x218
+#define DDR_PCTL2_ADDRMAP7		0x21c
+#define DDR_PCTL2_ADDRMAP8		0x220
+#define DDR_PCTL2_ADDRMAP9		0x224
+#define DDR_PCTL2_ADDRMAP10		0x228
+#define DDR_PCTL2_ADDRMAP11		0x22c
+#define DDR_PCTL2_ODTCFG		0x240
+#define DDR_PCTL2_ODTMAP		0x244
+#define DDR_PCTL2_SCHED			0x250
+#define DDR_PCTL2_SCHED1		0x254
+#define DDR_PCTL2_PERFHPR1		0x25c
+#define DDR_PCTL2_PERFLPR1		0x264
+#define DDR_PCTL2_PERFWR1		0x26c
+#define DDR_PCTL2_DQMAP0		0x280
+#define DDR_PCTL2_DQMAP1		0x284
+#define DDR_PCTL2_DQMAP2		0x288
+#define DDR_PCTL2_DQMAP3		0x28c
+#define DDR_PCTL2_DQMAP4		0x290
+#define DDR_PCTL2_DQMAP5		0x294
+#define DDR_PCTL2_DBG0			0x300
+#define DDR_PCTL2_DBG1			0x304
+#define DDR_PCTL2_DBGCAM		0x308
+#define DDR_PCTL2_DBGCMD		0x30c
+#define DDR_PCTL2_DBGSTAT		0x310
+#define DDR_PCTL2_SWCTL			0x320
+#define DDR_PCTL2_SWSTAT		0x324
+#define DDR_PCTL2_POISONCFG		0x36c
+#define DDR_PCTL2_POISONSTAT		0x370
+#define DDR_PCTL2_ADVECCINDEX		0x374
+#define DDR_PCTL2_ADVECCSTAT		0x378
+#define DDR_PCTL2_PSTAT			0x3fc
+#define DDR_PCTL2_PCCFG			0x400
+#define DDR_PCTL2_PCFGR_n		0x404
+#define DDR_PCTL2_PCFGW_n		0x408
+#define DDR_PCTL2_PCTRL_n		0x490
+
+/* PCTL2_MRSTAT */
+#define MR_WR_BUSY			BIT(0)
+
+void pctl_read_mr(void __iomem *pctl_base, u32 rank, u32 mr_num);
+int pctl_write_mr(void __iomem *pctl_base, u32 rank, u32 mr_num, u32 arg,
+		  u32 dramtype);
+int pctl_write_vrefdq(void __iomem *pctl_base, u32 rank, u32 vrefrate,
+		      u32 dramtype);
+
+u32 pctl_dis_zqcs_aref(void __iomem *pctl_base);
+void pctl_rest_zqcs_aref(void __iomem *pctl_base, u32 dis_auto_zq);
+
+u32 pctl_remodify_sdram_params(struct ddr_pctl_regs *pctl_regs,
+			       struct sdram_cap_info *cap_info,
+			       u32 dram_type);
+int pctl_cfg(void __iomem *pctl_base, struct ddr_pctl_regs *pctl_regs,
+	     u32 sr_idle, u32 pd_idle);
+
+#endif
drivers/ram/rockchip/sdram_pctl_px30.c new file +205 -0

205 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#9 lore raw

PATCH v2 9/17 ram: rockchip: add phy driver code for PX30

In reply to Kever Yang

This sdram_phy_px30.c is based on PX30 SoC, the functions are common for phy, other SoCs with similar hardware could re-use it.

---

Changes in v2: None

 .../asm/arch-rockchip/sdram_phy_px30.h        |  62 ++++++
 .../arch-rockchip/sdram_phy_ron_rtt_px30.h    |  59 +++++
 drivers/ram/rockchip/sdram_phy_px30.c         | 205 ++++++++++++++++++
 3 files changed, 326 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_phy_px30.h
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_phy_ron_rtt_px30.h
 create mode 100644 drivers/ram/rockchip/sdram_phy_px30.c
arch/arm/include/asm/arch-rockchip/sdram_phy_px30.h new file +62 -0
new file mode 100644
index 0000000000..c75a633c91
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier:     GPL-2.0+ */
+/*
+ * Copyright (C) 2018 Rockchip Electronics Co., Ltd
+ */
+
+#ifndef _ASM_ARCH_SDRAM_PHY_PX30_H
+#define _ASM_ARCH_SDRAM_PHY_PX30_H
+#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram_phy_ron_rtt_px30.h>
+
+struct ddr_phy_regs {
+	u32 phy[5][2];
+};
+
+#define PHY_REG(base, n)		((base) + 4 * (n))
+
+/* PHY_REG0 */
+#define DIGITAL_DERESET			BIT(3)
+#define ANALOG_DERESET			BIT(2)
+#define DIGITAL_RESET			(0 << 3)
+#define ANALOG_RESET			(0 << 2)
+
+/* PHY_REG1 */
+#define PHY_DDR2			(0)
+#define PHY_LPDDR2			(1)
+#define PHY_DDR3			(2)
+#define PHY_LPDDR3			(3)
+#define PHY_DDR4			(4)
+#define PHY_BL_4			(0 << 2)
+#define PHY_BL_8			BIT(2)
+
+/* PHY_REG2 */
+#define PHY_DTT_EN			BIT(0)
+#define PHY_DTT_DISB			(0 << 0)
+#define PHY_WRITE_LEVELING_EN		BIT(2)
+#define PHY_WRITE_LEVELING_DISB		(0 << 2)
+#define PHY_SELECT_CS0			(2)
+#define PHY_SELECT_CS1			(1)
+#define PHY_SELECT_CS0_1		(0)
+#define PHY_WRITE_LEVELING_SELECTCS(n)	((n) << 6)
+#define PHY_DATA_TRAINING_SELECTCS(n)	((n) << 4)
+
+struct ddr_phy_skew {
+	u32 a0_a1_skew[15];
+	u32 cs0_dm0_skew[11];
+	u32 cs0_dm1_skew[11];
+	u32 cs0_dm2_skew[11];
+	u32 cs0_dm3_skew[11];
+	u32 cs1_dm0_skew[11];
+	u32 cs1_dm1_skew[11];
+	u32 cs1_dm2_skew[11];
+	u32 cs1_dm3_skew[11];
+};
+
+void phy_soft_reset(void __iomem *phy_base);
+void phy_dram_set_bw(void __iomem *phy_base, u32 bw);
+void phy_cfg(void __iomem *phy_base,
+	     struct ddr_phy_regs *phy_regs, struct ddr_phy_skew *skew,
+	     struct sdram_base_params *base, u32 bw);
+int phy_data_training(void __iomem *phy_base, u32 cs, u32 dramtype);
+
+#endif
arch/arm/include/asm/arch-rockchip/sdram_phy_ron_rtt_px30.h new file +59 -0

59 lines not on this page · raw message

drivers/ram/rockchip/sdram_phy_px30.c new file +205 -0

205 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#10 lore raw

PATCH v2 10/17 ram: rockchip: add common msch reg definition

In reply to Kever Yang

The noc register bit definition may be the same for different SoC while the offset of the register may be different, add the struction definition as common code.

---

Changes in v2: None

 .../include/asm/arch-rockchip/sdram_msch.h    | 85 +++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_msch.h
arch/arm/include/asm/arch-rockchip/sdram_msch.h new file +85 -0
new file mode 100644
index 0000000000..cfb3d9cc86
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier:     GPL-2.0+ */
+/*
+ * Copyright (C) 2019 Rockchip Electronics Co., Ltd
+ */
+
+#ifndef _ASM_ARCH_SDRAM_MSCH_H
+#define _ASM_ARCH_SDRAM_MSCH_H
+
+union noc_ddrtiminga0 {
+	u32 d32;
+	struct {
+		unsigned acttoact : 6;
+		unsigned reserved0 : 2;
+		unsigned rdtomiss : 6;
+		unsigned reserved1 : 2;
+		unsigned wrtomiss : 6;
+		unsigned reserved2 : 2;
+		unsigned readlatency : 8;
+	} b;
+};
+
+union noc_ddrtimingb0 {
+	u32 d32;
+	struct {
+		unsigned rdtowr : 5;
+		unsigned reserved0 : 3;
+		unsigned wrtord : 5;
+		unsigned reserved1 : 3;
+		unsigned rrd : 4;
+		unsigned reserved2 : 4;
+		unsigned faw : 6;
+		unsigned reserved3 : 2;
+	} b;
+};
+
+union noc_ddrtimingc0 {
+	u32 d32;
+	struct {
+		unsigned burstpenalty : 4;
+		unsigned reserved0 : 4;
+		unsigned wrtomwr : 6;
+		unsigned reserved1 : 18;
+	} b;
+};
+
+union noc_devtodev0 {
+	u32 d32;
+	struct {
+		unsigned busrdtord : 3;
+		unsigned reserved0 : 1;
+		unsigned busrdtowr : 3;
+		unsigned reserved1 : 1;
+		unsigned buswrtord : 3;
+		unsigned reserved2 : 1;
+		unsigned buswrtowr : 3;
+		unsigned reserved3 : 17;
+	} b;
+};
+
+union noc_ddrmode {
+	u32 d32;
+	struct {
+		unsigned autoprecharge : 1;
+		unsigned bypassfiltering : 1;
+		unsigned fawbank : 1;
+		unsigned burstsize : 2;
+		unsigned mwrsize : 2;
+		unsigned reserved2 : 1;
+		unsigned forceorder : 8;
+		unsigned forceorderstate : 8;
+		unsigned reserved3 : 8;
+	} b;
+};
+
+union noc_ddr4timing {
+	u32 d32;
+	struct {
+		unsigned ccdl : 3;
+		unsigned wrtordl : 5;
+		unsigned rrdl : 4;
+		unsigned reserved1 : 20;
+	} b;
+};
+
+#endif
Signature · 1 line
2.17.1
author
#11 lore raw

PATCH v2 11/17 ram: px30: add sdram driver

In reply to Kever Yang

From: YouMin Chen <[email protected]>

Add the sdram driver for PX30 to support ddr3, ddr4, lpddr2 and lpddr3. The PX30 SoC support driver is suppose to follow up later.

---

Changes in v2: None

 .../include/asm/arch-rockchip/sdram_px30.h    | 212 ++++++
 .../rockchip/sdram-px30-ddr3-detect-333.inc   |  72 ++
 .../rockchip/sdram-px30-ddr4-detect-333.inc   |  75 ++
 drivers/ram/rockchip/sdram-px30-ddr_skew.inc  | 121 ++++
 .../rockchip/sdram-px30-lpddr2-detect-333.inc |  73 ++
 .../rockchip/sdram-px30-lpddr3-detect-333.inc |  74 ++
 drivers/ram/rockchip/sdram_px30.c             | 669 ++++++++++++++++++
 7 files changed, 1296 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sdram_px30.h
 create mode 100644 drivers/ram/rockchip/sdram-px30-ddr3-detect-333.inc
 create mode 100644 drivers/ram/rockchip/sdram-px30-ddr4-detect-333.inc
 create mode 100644 drivers/ram/rockchip/sdram-px30-ddr_skew.inc
 create mode 100644 drivers/ram/rockchip/sdram-px30-lpddr2-detect-333.inc
 create mode 100644 drivers/ram/rockchip/sdram-px30-lpddr3-detect-333.inc
 create mode 100644 drivers/ram/rockchip/sdram_px30.c
arch/arm/include/asm/arch-rockchip/sdram_px30.h new file +212 -0
new file mode 100644
index 0000000000..9b608a9224
@@ -0,0 +1,212 @@
+/* SPDX-License-Identifier:     GPL-2.0+ */
+/*
+ * Copyright (C) 2018 Rockchip Electronics Co., Ltd
+ */
+
+#ifndef _ASM_ARCH_SDRAM_PX30_H
+#define _ASM_ARCH_SDRAM_PX30_H
+#include <asm/arch-rockchip/sdram_common.h>
+#include <asm/arch-rockchip/sdram_msch.h>
+#include <asm/arch-rockchip/sdram_pctl_px30.h>
+#include <asm/arch-rockchip/sdram_phy_px30.h>
+#include <asm/arch-rockchip/sdram_phy_ron_rtt_px30.h>
+
+#define SR_IDLE				93
+#define PD_IDLE				13
+
+/* PMUGRF */
+#define PMUGRF_OS_REG0			(0x200)
+#define PMUGRF_OS_REG(n)		(PMUGRF_OS_REG0 + (n) * 4)
+
+/* DDR GRF */
+#define DDR_GRF_CON(n)			(0 + (n) * 4)
+#define DDR_GRF_STATUS_BASE		(0X100)
+#define DDR_GRF_STATUS(n)		(DDR_GRF_STATUS_BASE + (n) * 4)
+#define DDR_GRF_LP_CON			(0x20)
+
+#define SPLIT_MODE_32_L16_VALID		(0)
+#define SPLIT_MODE_32_H16_VALID		(1)
+#define SPLIT_MODE_16_L8_VALID		(2)
+#define SPLIT_MODE_16_H8_VALID		(3)
+
+#define DDR_GRF_SPLIT_CON		(0x8)
+#define SPLIT_MODE_MASK			(0x3)
+#define SPLIT_MODE_OFFSET		(9)
+#define SPLIT_BYPASS_MASK		(1)
+#define SPLIT_BYPASS_OFFSET		(8)
+#define SPLIT_SIZE_MASK			(0xff)
+#define SPLIT_SIZE_OFFSET		(0)
+
+/* CRU define */
+/* CRU_PLL_CON0 */
+#define PB(n)				((0x1 << (15 + 16)) | ((n) << 15))
+#define POSTDIV1(n)			((0x7 << (12 + 16)) | ((n) << 12))
+#define FBDIV(n)			((0xFFF << 16) | (n))
+
+/* CRU_PLL_CON1 */
+#define RSTMODE(n)			((0x1 << (15 + 16)) | ((n) << 15))
+#define RST(n)				((0x1 << (14 + 16)) | ((n) << 14))
+#define PD(n)				((0x1 << (13 + 16)) | ((n) << 13))
+#define DSMPD(n)			((0x1 << (12 + 16)) | ((n) << 12))
+#define LOCK(n)				(((n) >> 10) & 0x1)
+#define POSTDIV2(n)			((0x7 << (6 + 16)) | ((n) << 6))
+#define REFDIV(n)			((0x3F << 16) | (n))
+
+/* CRU_MODE */
+#define CLOCK_FROM_XIN_OSC		(0)
+#define CLOCK_FROM_PLL			(1)
+#define CLOCK_FROM_RTC_32K		(2)
+#define DPLL_MODE(n)			((0x3 << (4 + 16)) | ((n) << 4))
+
+/* CRU_SOFTRESET_CON1 */
+#define upctl2_psrstn_req(n)		(((0x1 << 6) << 16) | ((n) << 6))
+#define upctl2_asrstn_req(n)		(((0x1 << 5) << 16) | ((n) << 5))
+#define upctl2_srstn_req(n)		(((0x1 << 4) << 16) | ((n) << 4))
+
+/* CRU_SOFTRESET_CON2 */
+#define ddrphy_psrstn_req(n)		(((0x1 << 2) << 16) | ((n) << 2))
+#define ddrphy_srstn_req(n)		(((0x1 << 0) << 16) | ((n) << 0))
+
+/* CRU register */
+#define CRU_PLL_CON(pll_id, n)		((pll_id)  * 0x20 + (n) * 4)
+#define CRU_MODE			(0xa0)
+#define CRU_GLB_CNT_TH			(0xb0)
+#define CRU_CLKSEL_CON_BASE		0x100
+#define CRU_CLKSELS_CON(i)		(CRU_CLKSEL_CON_BASE + ((i) * 4))
+#define CRU_CLKGATE_CON_BASE		0x200
+#define CRU_CLKGATE_CON(i)		(CRU_CLKGATE_CON_BASE + ((i) * 4))
+#define CRU_CLKSFTRST_CON_BASE		0x300
+#define CRU_CLKSFTRST_CON(i)		(CRU_CLKSFTRST_CON_BASE + ((i) * 4))
+
+u8 ddr_cfg_2_rbc[] = {
+	/*
+	 * [6:4] max row: 13+n
+	 * [3]  bank(0:4bank,1:8bank)
+	 * [2:0]    col(10+n)
+	 */
+	((5 << 4) | (1 << 3) | 0), /* 0 */
+	((5 << 4) | (1 << 3) | 1), /* 1 */
+	((4 << 4) | (1 << 3) | 2), /* 2 */
+	((3 << 4) | (1 << 3) | 3), /* 3 */
+	((2 << 4) | (1 << 3) | 4), /* 4 */
+	((5 << 4) | (0 << 3) | 2), /* 5 */
+	((4 << 4) | (1 << 3) | 2), /* 6 */
+	/*((0<<3)|3),*/	 /* 12 for ddr4 */
+	/*((1<<3)|1),*/  /* 13 B,C exchange for rkvdec */
+};
+
+/*
+ * for ddr4 if ddrconfig=7, upctl should set 7 and noc should
+ * set to 1 for more efficient.
+ * noc ddrconf, upctl addrmap
+ * 1  7
+ * 2  8
+ * 3  9
+ * 12 10
+ * 5  11
+ */
+u8 d4_rbc_2_d3_rbc[] = {
+	1, /* 7 */
+	2, /* 8 */
+	3, /* 9 */
+	12, /* 10 */
+	5, /* 11 */
+};
+
+/*
+ * row higher than cs should be disabled by set to 0xf
+ * rank addrmap calculate by real cap.
+ */
+u32 addrmap[][8] = {
+	/* map0 map1,   map2,       map3,       map4,      map5
+	 * map6,        map7,       map8
+	 * -------------------------------------------------------
+	 * bk2-0       col 5-2     col 9-6    col 11-10   row 11-0
+	 * row 15-12   row 17-16   bg1,0
+	 * -------------------------------------------------------
+	 * 4,3,2       5-2         9-6                    6
+	 *                         3,2
+	 */
+	{0x00060606, 0x00000000, 0x1f1f0000, 0x00001f1f, 0x05050505,
+		0x05050505, 0x00000505, 0x3f3f}, /* 0 */
+	{0x00070707, 0x00000000, 0x1f000000, 0x00001f1f, 0x06060606,
+		0x06060606, 0x06060606, 0x3f3f}, /* 1 */
+	{0x00080808, 0x00000000, 0x00000000, 0x00001f1f, 0x07070707,
+		0x07070707, 0x00000f07, 0x3f3f}, /* 2 */
+	{0x00090909, 0x00000000, 0x00000000, 0x00001f00, 0x08080808,
+		0x08080808, 0x00000f0f, 0x3f3f}, /* 3 */
+	{0x000a0a0a, 0x00000000, 0x00000000, 0x00000000, 0x09090909,
+		0x0f090909, 0x00000f0f, 0x3f3f}, /* 4 */
+	{0x00080808, 0x00000000, 0x00000000, 0x00001f1f, 0x06060606,
+		0x06060606, 0x00000606, 0x3f3f}, /* 5 */
+	{0x00080808, 0x00000000, 0x00000000, 0x00001f1f, 0x07070707,
+		0x07070707, 0x00000f0f, 0x3f3f}, /* 6 */
+	{0x003f0808, 0x00000006, 0x1f1f0000, 0x00001f1f, 0x06060606,
+		0x06060606, 0x00000606, 0x0600}, /* 7 */
+	{0x003f0909, 0x00000007, 0x1f000000, 0x00001f1f, 0x07070707,
+		0x07070707, 0x00000f07, 0x0700}, /* 8 */
+	{0x003f0a0a, 0x01010100, 0x01010101, 0x00001f1f, 0x08080808,
+		0x08080808, 0x00000f0f, 0x0801}, /* 9 */
+	{0x003f0909, 0x01010100, 0x01010101, 0x00001f1f, 0x07070707,
+		0x07070707, 0x00000f07, 0x3f01}, /* 10 */
+	{0x003f0808, 0x00000007, 0x1f000000, 0x00001f1f, 0x06060606,
+		0x06060606, 0x00000606, 0x3f00}, /* 11 */
+	/* when ddr4 12 map to 10, when ddr3 12 unused */
+	{0x003f0909, 0x01010100, 0x01010101, 0x00001f1f, 0x07070707,
+		0x07070707, 0x00000f07, 0x3f01}, /* 10 */
+	{0x00070706, 0x00000000, 0x1f010000, 0x00001f1f, 0x06060606,
+		0x06060606, 0x00000606, 0x3f3f}, /* 13 */
+};
+
+struct px30_ddr_grf_regs {
+	u32 ddr_grf_con[4];
+	u32 reserved1[(0x20 - 0x10) / 4];
+	u32 ddr_grf_lp_con;
+	u32 reserved2[(0x100 - 0x24) / 4];
+	u32 ddr_grf_status[11];
+};
+
+struct msch_regs {
+	u32 coreid;
+	u32 revisionid;
+	u32 deviceconf;
+	u32 devicesize;
+	u32 ddrtiminga0;
+	u32 ddrtimingb0;
+	u32 ddrtimingc0;
+	u32 devtodev0;
+	u32 reserved1[(0x110 - 0x20) / 4];
+	u32 ddrmode;
+	u32 ddr4timing;
+	u32 reserved2[(0x1000 - 0x118) / 4];
+	u32 agingx0;
+	u32 reserved3[(0x1040 - 0x1004) / 4];
+	u32 aging0;
+	u32 aging1;
+	u32 aging2;
+	u32 aging3;
+};
+
+struct sdram_msch_timings {
+	union noc_ddrtiminga0 ddrtiminga0;
+	union noc_ddrtimingb0 ddrtimingb0;
+	union noc_ddrtimingc0 ddrtimingc0;
+	union noc_devtodev0 devtodev0;
+	union noc_ddrmode ddrmode;
+	union noc_ddr4timing ddr4timing;
+	u32 agingx0;
+};
+
+struct px30_sdram_channel {
+	struct sdram_cap_info cap_info;
+	struct sdram_msch_timings noc_timings;
+};
+
+struct px30_sdram_params {
+	struct px30_sdram_channel ch;
+	struct sdram_base_params base;
+	struct ddr_pctl_regs pctl_regs;
+	struct ddr_phy_regs phy_regs;
+	struct ddr_phy_skew *skew;
+};
+#endif
drivers/ram/rockchip/sdram-px30-ddr3-detect-333.inc new file +72 -0

72 lines not on this page · raw message

drivers/ram/rockchip/sdram-px30-ddr4-detect-333.inc new file +75 -0

76 lines not on this page · raw message

drivers/ram/rockchip/sdram-px30-ddr_skew.inc new file +121 -0

121 lines not on this page · raw message

drivers/ram/rockchip/sdram-px30-lpddr2-detect-333.inc new file +73 -0

73 lines not on this page · raw message

drivers/ram/rockchip/sdram-px30-lpddr3-detect-333.inc new file +74 -0

74 lines not on this page · raw message

drivers/ram/rockchip/sdram_px30.c new file +669 -0

669 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#12 lore raw

PATCH v2 12/17 ram: rk3328: use common sdram driver

In reply to Kever Yang

From: YouMin Chen <[email protected]>

RK3328 has a similar controller and phy with PX30, so we can use the common driver for it and remove the duplicate codes.

---

Changes in v2: None

 arch/arm/dts/rk3328-sdram-ddr3-666.dtsi       |   4 +
 arch/arm/dts/rk3328-sdram-lpddr3-1600.dtsi    |   4 +
 arch/arm/dts/rk3328-sdram-lpddr3-666.dtsi     |   4 +
 .../include/asm/arch-rockchip/sdram_rk3328.h  | 419 +++-------
 arch/arm/mach-rockchip/Kconfig                |   1 +
 configs/evb-rk3328_defconfig                  |   2 +-
 configs/rock64-rk3328_defconfig               |   2 +-
 drivers/ram/rockchip/Makefile                 |   2 +-
 drivers/ram/rockchip/sdram_rk3328.c           | 763 ++++--------------
 9 files changed, 295 insertions(+), 906 deletions(-)
arch/arm/dts/rk3328-sdram-ddr3-666.dtsi +4 -0
index d99e7e0352..3e88ed443b 100644
@@ -14,6 +14,8 @@
 		0x0
 		0x10
 		0x10
+		0x10
+		0x10
 		0
 
 		0x9028b189
@@ -26,6 +28,8 @@
 
 		333
 		3
+		1
+		0
 		0
 
 		0x00000000
arch/arm/dts/rk3328-sdram-lpddr3-1600.dtsi +4 -0
index cc0011cf7b..d63c761a02 100644
@@ -14,6 +14,8 @@
 		0x0
 		0x10
 		0x10
+		0x10
+		0x10
 		0
 
 		0x98899459
@@ -27,6 +29,8 @@
 		800
 		6
 		1
+		0
+		1
 
 		0x00000000
 		0x43041008
arch/arm/dts/rk3328-sdram-lpddr3-666.dtsi +4 -0
index 62d809e833..b9d3b3b948 100644
@@ -14,6 +14,8 @@
 		0x0
 		0x10
 		0x10
+		0x10
+		0x10
 		0
 
 		0x0c48a18a
@@ -26,6 +28,8 @@
 
 		333
 		6
+		1
+		0
 		0
 
 		0x00000000
arch/arm/include/asm/arch-rockchip/sdram_rk3328.h +121 -298

465 lines not on this page · raw message

arch/arm/mach-rockchip/Kconfig +1 -0
index f5a80b4f0c..5f1ad51cac 100644
@@ -115,6 +115,7 @@ config ROCKCHIP_RK3328
 	select TPL_NEEDS_SEPARATE_TEXT_BASE if TPL
 	select TPL_NEEDS_SEPARATE_STACK if TPL
 	imply ROCKCHIP_COMMON_BOARD
+	imply ROCKCHIP_SDRAM_COMMON
 	imply SPL_ROCKCHIP_COMMON_BOARD
 	imply SPL_SERIAL_SUPPORT
 	imply TPL_SERIAL_SUPPORT
configs/evb-rk3328_defconfig +1 -1
index 37610774c1..fdabee842d 100644
@@ -46,7 +46,6 @@ CONFIG_SPL_SYSCON=y
 CONFIG_TPL_SYSCON=y
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
-CONFIG_TPL_CLK=y
 CONFIG_FASTBOOT_BUF_ADDR=0x800800
 CONFIG_FASTBOOT_FLASH=y
 CONFIG_FASTBOOT_FLASH_MMC_DEV=1
@@ -77,6 +76,7 @@ CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_DEBUG_UART_SKIP_INIT=y
 CONFIG_SYSRESET=y
+# CONFIG_TPL_SYSRESET is not set
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
configs/rock64-rk3328_defconfig +1 -1
index 3ab0af1158..0fb4b42c6e 100644
@@ -49,7 +49,6 @@ CONFIG_SPL_SYSCON=y
 CONFIG_TPL_SYSCON=y
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
-CONFIG_TPL_CLK=y
 CONFIG_FASTBOOT_BUF_ADDR=0x800800
 CONFIG_FASTBOOT_FLASH=y
 CONFIG_FASTBOOT_FLASH_MMC_DEV=1
@@ -79,6 +78,7 @@ CONFIG_DM_RESET=y
 CONFIG_BAUDRATE=1500000
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_SYSRESET=y
+# CONFIG_TPL_SYSRESET is not set
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
drivers/ram/rockchip/Makefile +1 -1
index 483660e570..b42ef91c21 100644
@@ -8,5 +8,5 @@ obj-$(CONFIG_ROCKCHIP_RK3128) = sdram_rk3128.o
 obj-$(CONFIG_ROCKCHIP_RK3188) = sdram_rk3188.o
 obj-$(CONFIG_ROCKCHIP_RK322X) = sdram_rk322x.o
 obj-$(CONFIG_ROCKCHIP_RK3288) = sdram_rk3288.o
-obj-$(CONFIG_ROCKCHIP_RK3328) = sdram_rk3328.o
+obj-$(CONFIG_ROCKCHIP_RK3328) += sdram_rk3328.o sdram_pctl_px30.o sdram_phy_px30.o
 obj-$(CONFIG_RAM_RK3399) += sdram_rk3399.o
drivers/ram/rockchip/sdram_rk3328.c +158 -605

944 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#13 lore raw

PATCH v2 13/17 ram: rk3399: use common sdram driver

In reply to Kever Yang

From: YouMin Chen <[email protected]>

RK3399's controller and phy are able to re-use the common code, migrate to use the common driver and remove duplicated code.

---

Changes in v2: None

 arch/arm/dts/rk3399-sdram-ddr3-1333.dtsi      |   4 +
 arch/arm/dts/rk3399-sdram-ddr3-1600.dtsi      |   4 +
 arch/arm/dts/rk3399-sdram-ddr3-1866.dtsi      |   4 +
 .../arm/dts/rk3399-sdram-lpddr3-2GB-1600.dtsi |   4 +
 .../arm/dts/rk3399-sdram-lpddr3-4GB-1600.dtsi |   4 +
 .../rk3399-sdram-lpddr3-samsung-4GB-1866.dtsi |   4 +
 arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi     |   4 +
 .../include/asm/arch-rockchip/sdram_rk3399.h  |  97 +-
 arch/arm/mach-rockchip/Kconfig                |   1 +
 drivers/ram/rockchip/Kconfig                  |  21 +-
 drivers/ram/rockchip/Makefile                 |   2 +-
 .../ram/rockchip/sdram-rk3399-lpddr4-400.inc  |  28 +-
 .../ram/rockchip/sdram-rk3399-lpddr4-800.inc  |  28 +-
 drivers/ram/rockchip/sdram_debug.c            | 147 +++
 drivers/ram/rockchip/sdram_rk3399.c           | 968 ++++++++++++------
 15 files changed, 932 insertions(+), 388 deletions(-)
 create mode 100644 drivers/ram/rockchip/sdram_debug.c
arch/arm/dts/rk3399-sdram-ddr3-1333.dtsi +4 -0
index 3708bd674b..7fae249536 100644
@@ -13,6 +13,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x80120e12
 		0x11030802
@@ -28,6 +30,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x80120e12
 		0x11030802
arch/arm/dts/rk3399-sdram-ddr3-1600.dtsi +4 -0
index fcd01f8b46..23c7c34a9a 100644
@@ -13,6 +13,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x80151015
 		0x14040902
@@ -28,6 +30,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x80151015
 		0x14040902
arch/arm/dts/rk3399-sdram-ddr3-1866.dtsi +4 -0
index c46c1996be..ea029ca90a 100644
@@ -13,6 +13,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x80181219
 		0x17050a03
@@ -28,6 +30,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x80181219
 		0x17050a03
arch/arm/dts/rk3399-sdram-lpddr3-2GB-1600.dtsi +4 -0
index d14e833d22..7296dbb80e 100644
@@ -14,6 +14,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x1d191519
 		0x14040808
@@ -29,6 +31,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x1d191519
 		0x14040808
arch/arm/dts/rk3399-sdram-lpddr3-4GB-1600.dtsi +4 -0
index fc4cccb6a0..bf429c21e4 100644
@@ -13,6 +13,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x1d191519
 		0x14040808
@@ -28,6 +30,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x1d191519
 		0x14040808
arch/arm/dts/rk3399-sdram-lpddr3-samsung-4GB-1866.dtsi +4 -0
index 2a627e1be5..96f459fd0b 100644
@@ -13,6 +13,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 
 		0x801d181e
@@ -30,6 +32,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 
 		0x801d181e
arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi +4 -0
index 4a4414a960..f0c478d189 100644
@@ -15,6 +15,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x80241d22
 		0x15050f08
@@ -30,6 +32,8 @@
 		0x0
 		0xf
 		0xf
+		0xf
+		0xf
 		1
 		0x80241d22
 		0x15050f08
arch/arm/include/asm/arch-rockchip/sdram_rk3399.h +41 -56

127 lines not on this page · raw message

arch/arm/mach-rockchip/Kconfig +1 -0
index 5f1ad51cac..7746b661e5 100644
@@ -184,6 +184,7 @@ config ROCKCHIP_RK3399
 	select DM_REGULATOR_FIXED
 	select BOARD_LATE_INIT
 	imply ROCKCHIP_COMMON_BOARD
+	imply ROCKCHIP_SDRAM_COMMON
 	imply SPL_ROCKCHIP_COMMON_BOARD
 	imply TPL_SERIAL_SUPPORT
 	imply TPL_LIBCOMMON_SUPPORT
drivers/ram/rockchip/Kconfig +1 -20
index dcc06b3fd3..3f44fb3fce 100644
@@ -11,29 +11,10 @@ config ROCKCHIP_SDRAM_COMMON
 	help
 	  This enable sdram common driver
 
-if RAM_ROCKCHIP
-
-config RAM_ROCKCHIP_DEBUG
-	bool "Rockchip ram drivers debugging"
-	help
-	  This enables debugging ram driver API's for the platforms
-	  based on Rockchip SoCs.
-
-	  This is an option for developers to understand the ram drivers
-	  initialization, configurations and etc.
-
-config RAM_RK3399
-	bool "Ram driver for Rockchip RK3399"
-	default ROCKCHIP_RK3399
-	help
-	  This enables ram drivers support for the platforms based on
-	  Rockchip RK3399 SoC.
-
 config RAM_RK3399_LPDDR4
 	bool "LPDDR4 support for Rockchip RK3399"
-	depends on RAM_RK3399
+	depends on RAM_ROCKCHIP && ROCKCHIP_RK3399
 	help
 	  This enables LPDDR4 sdram code support for the platforms based
 	  on Rockchip RK3399 SoC.
 
-endif # RAM_ROCKCHIP
drivers/ram/rockchip/Makefile +1 -1
index b42ef91c21..47b9b1bebb 100644
@@ -9,4 +9,4 @@ obj-$(CONFIG_ROCKCHIP_RK3188) = sdram_rk3188.o
 obj-$(CONFIG_ROCKCHIP_RK322X) = sdram_rk322x.o
 obj-$(CONFIG_ROCKCHIP_RK3288) = sdram_rk3288.o
 obj-$(CONFIG_ROCKCHIP_RK3328) += sdram_rk3328.o sdram_pctl_px30.o sdram_phy_px30.o
-obj-$(CONFIG_RAM_RK3399) += sdram_rk3399.o
+obj-$(CONFIG_ROCKCHIP_RK3399) += sdram_rk3399.o
drivers/ram/rockchip/sdram-rk3399-lpddr4-400.inc +22 -6
index c50a03d9dd..6ddc01c49d 100644
@@ -16,15 +16,23 @@
 				.row_3_4 = 0x0,
 				.cs0_row = 0xF,
 				.cs1_row = 0xF,
+				.cs0_high16bit_row = 0xF,
+				.cs1_high16bit_row = 0xF,
 				.ddrconfig = 1,
 			},
 			{
-				.ddrtiminga0 = 0x80241d22,
-				.ddrtimingb0 = 0x15050f08,
+				.ddrtiminga0 = {
+					0x80241d22,
+				},
+				.ddrtimingb0 = {
+					0x15050f08,
+				},
 				.ddrtimingc0 = {
 					0x00000602,
 				},
-				.devtodev0 = 0x00002122,
+				.devtodev0 = {
+					0x00002122,
+				},
 				.ddrmode = {
 					0x0000004c,
 				},
@@ -41,15 +49,23 @@
 				.row_3_4 = 0x0,
 				.cs0_row = 0xF,
 				.cs1_row = 0xF,
+				.cs0_high16bit_row = 0xF,
+				.cs1_high16bit_row = 0xF,
 				.ddrconfig = 1,
 			},
 			{
-				.ddrtiminga0 = 0x80241d22,
-				.ddrtimingb0 = 0x15050f08,
+				.ddrtiminga0 = {
+					0x80241d22,
+				},
+				.ddrtimingb0 = {
+					0x15050f08,
+				},
 				.ddrtimingc0 = {
 					0x00000602,
 				},
-				.devtodev0 = 0x00002122,
+				.devtodev0 = {
+					0x00002122,
+				},
 				.ddrmode = {
 					0x0000004c,
 				},
drivers/ram/rockchip/sdram-rk3399-lpddr4-800.inc +22 -6
index d8ae3359a3..307f6ee458 100644
@@ -16,15 +16,23 @@
 				.row_3_4 = 0x0,
 				.cs0_row = 0xF,
 				.cs1_row = 0xF,
+				.cs0_high16bit_row = 0xF,
+				.cs1_high16bit_row = 0xF,
 				.ddrconfig = 1,
 			},
 			{
-				.ddrtiminga0 = 0x80241d22,
-				.ddrtimingb0 = 0x15050f08,
+				.ddrtiminga0 = {
+					0x80241d22,
+				},
+				.ddrtimingb0 = {
+					0x15050f08,
+				},
 				.ddrtimingc0 = {
 					0x00000602,
 				},
-				.devtodev0 = 0x00002122,
+				.devtodev0 = {
+					0x00002122,
+				},
 				.ddrmode = {
 					0x0000004c,
 				},
@@ -41,15 +49,23 @@
 				.row_3_4 = 0x0,
 				.cs0_row = 0xF,
 				.cs1_row = 0xF,
+				.cs0_high16bit_row = 0xF,
+				.cs1_high16bit_row = 0xF,
 				.ddrconfig = 1,
 			},
 			{
-				.ddrtiminga0 = 0x80241d22,
-				.ddrtimingb0 = 0x15050f08,
+				.ddrtiminga0 = {
+					0x80241d22,
+				},
+				.ddrtimingb0 = {
+					0x15050f08,
+				},
 				.ddrtimingc0 = {
 					0x00000602,
 				},
-				.devtodev0 = 0x00002122,
+				.devtodev0 = {
+					0x00002122,
+				},
 				.ddrmode = {
 					0x0000004c,
 				},
drivers/ram/rockchip/sdram_debug.c new file +147 -0

147 lines not on this page · raw message

drivers/ram/rockchip/sdram_rk3399.c +669 -299

1,364 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#14 lore raw

PATCH v2 14/17 ram: rockchip: update lpddr4 timing for rk3399

In reply to Kever Yang

Update lpddr timing in lpddr4-400 and lpddr4-800 file from rockchip vendor code;

---

Changes in v2: None

 drivers/ram/rockchip/sdram-rk3399-lpddr4-400.inc | 12 ++++++------
 drivers/ram/rockchip/sdram-rk3399-lpddr4-800.inc |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/ram/rockchip/sdram-rk3399-lpddr4-400.inc +6 -6
index 6ddc01c49d..209ef57228 100644
@@ -22,16 +22,16 @@
 			},
 			{
 				.ddrtiminga0 = {
-					0x80241d22,
+					0x8010100d,
 				},
 				.ddrtimingb0 = {
-					0x15050f08,
+					0x08020b04,
 				},
 				.ddrtimingc0 = {
 					0x00000602,
 				},
 				.devtodev0 = {
-					0x00002122,
+					0x00002562,
 				},
 				.ddrmode = {
 					0x0000004c,
@@ -55,16 +55,16 @@
 			},
 			{
 				.ddrtiminga0 = {
-					0x80241d22,
+					0x8010100d,
 				},
 				.ddrtimingb0 = {
-					0x15050f08,
+					0x08020b04,
 				},
 				.ddrtimingc0 = {
 					0x00000602,
 				},
 				.devtodev0 = {
-					0x00002122,
+					0x00002562,
 				},
 				.ddrmode = {
 					0x0000004c,
drivers/ram/rockchip/sdram-rk3399-lpddr4-800.inc +3 -3
index 307f6ee458..7d11b4c563 100644
@@ -22,16 +22,16 @@
 			},
 			{
 				.ddrtiminga0 = {
-					0x80241d22,
+					0x801c1819,
 				},
 				.ddrtimingb0 = {
-					0x15050f08,
+					0x10040c05,
 				},
 				.ddrtimingc0 = {
 					0x00000602,
 				},
 				.devtodev0 = {
-					0x00002122,
+					0x00002672,
 				},
 				.ddrmode = {
 					0x0000004c,
Signature · 1 line
2.17.1
author
#15 lore raw

PATCH v2 15/17 ram: rk3399: Sync the io setting from Rockchip vendor code

In reply to Kever Yang

The io setting are updated after some bugfix in different rk3399 boards, sync the code from vendor.

---

Changes in v2: None

 drivers/ram/rockchip/sdram_rk3399.c | 44 +++++++++--------------------
 1 file changed, 14 insertions(+), 30 deletions(-)
drivers/ram/rockchip/sdram_rk3399.c +14 -30
index 073fba0990..43b72fc658 100644
@@ -149,38 +149,21 @@ struct io_setting {
 		32,	/* rd_vref; (unit %, range 3.3% - 48.7%) */
 	},
 	{
-		800 * MHz,
+		933 * MHz,
 		0,
 		/* dram side */
 		1,	/* dq_odt; */
 		0,	/* ca_odt; */
-		1,	/* pdds; */
+		3,	/* pdds; */
 		0x72,	/* dq_vref; */
 		0x72,	/* ca_vref; */
 		/* phy side */
-		PHY_DRV_ODT_40,	/* rd_odt; */
-		PHY_DRV_ODT_48,	/* wr_dq_drv; */
+		PHY_DRV_ODT_80,	/* rd_odt; */
+		PHY_DRV_ODT_40,	/* wr_dq_drv; */
 		PHY_DRV_ODT_40,	/* wr_ca_drv; */
 		PHY_DRV_ODT_40,	/* wr_ckcs_drv; */
 		1,	/* rd_odt_en; */
-		17,	/* rd_vref; (unit %, range 3.3% - 48.7%) */
-	},
-	{
-		933 * MHz,
-		0,
-		/* dram side */
-		3,	/* dq_odt; */
-		0,	/* ca_odt; */
-		6,	/* pdds; */
-		0x59,	/* dq_vref; 32% */
-		0x72,	/* ca_vref; */
-		/* phy side */
-		PHY_DRV_ODT_HI_Z,	/* rd_odt; */
-		PHY_DRV_ODT_48,	/* wr_dq_drv; */
-		PHY_DRV_ODT_40,	/* wr_ca_drv; */
-		PHY_DRV_ODT_40,	/* wr_ckcs_drv; */
-		0,	/* rd_odt_en; */
-		32,	/* rd_vref; (unit %, range 3.3% - 48.7%) */
+		20,	/* rd_vref; (unit %, range 3.3% - 48.7%) */
 	},
 	{
 		1066 * MHz,
@@ -188,16 +171,16 @@ struct io_setting {
 		/* dram side */
 		6,	/* dq_odt; */
 		0,	/* ca_odt; */
-		1,	/* pdds; */
+		3,	/* pdds; */
 		0x10,	/* dq_vref; */
 		0x72,	/* ca_vref; */
 		/* phy side */
-		PHY_DRV_ODT_40,	/* rd_odt; */
+		PHY_DRV_ODT_80,	/* rd_odt; */
 		PHY_DRV_ODT_60,	/* wr_dq_drv; */
 		PHY_DRV_ODT_40,	/* wr_ca_drv; */
 		PHY_DRV_ODT_40,	/* wr_ckcs_drv; */
 		1,	/* rd_odt_en; */
-		17,	/* rd_vref; (unit %, range 3.3% - 48.7%) */
+		20,	/* rd_vref; (unit %, range 3.3% - 48.7%) */
 	},
 };
 
@@ -599,16 +582,17 @@ static void set_ds_odt(const struct chan_info *chan,
 		tsel_rd_select_n = io->rd_odt;
 
 		tsel_idle_select_p = PHY_DRV_ODT_HI_Z;
-		tsel_idle_select_n = PHY_DRV_ODT_240;
+		tsel_idle_select_n = PHY_DRV_ODT_HI_Z;
 
 		tsel_wr_select_dq_p = io->wr_dq_drv;
-		tsel_wr_select_dq_n = PHY_DRV_ODT_40;
+		tsel_wr_select_dq_n = PHY_DRV_ODT_34_3;
 
 		tsel_wr_select_ca_p = io->wr_ca_drv;
-		tsel_wr_select_ca_n = PHY_DRV_ODT_40;
+		tsel_wr_select_ca_n = PHY_DRV_ODT_34_3;
 
 		tsel_ckcs_select_p = io->wr_ckcs_drv;
 		tsel_ckcs_select_n = PHY_DRV_ODT_34_3;
+
 		switch (tsel_rd_select_n) {
 		case PHY_DRV_ODT_240:
 			soc_odt = 1;
@@ -648,8 +632,8 @@ static void set_ds_odt(const struct chan_info *chan,
 		tsel_wr_select_dq_p = PHY_DRV_ODT_34_3;
 		tsel_wr_select_dq_n = PHY_DRV_ODT_34_3;
 
-		tsel_wr_select_ca_p = PHY_DRV_ODT_48;
-		tsel_wr_select_ca_n = PHY_DRV_ODT_48;
+		tsel_wr_select_ca_p = PHY_DRV_ODT_34_3;
+		tsel_wr_select_ca_n = PHY_DRV_ODT_34_3;
 
 		tsel_ckcs_select_p = PHY_DRV_ODT_34_3;
 		tsel_ckcs_select_n = PHY_DRV_ODT_34_3;
Signature · 1 line
2.17.1
author
#16 lore raw

PATCH v2 16/17 ram: rk3399: update calculate_stride

In reply to Kever Yang

Update the calculation of the stride to support all the DRAM case.

---

Changes in v2: None

 drivers/ram/rockchip/sdram_rk3399.c | 158 +++++++++++++++++++++-------
 1 file changed, 119 insertions(+), 39 deletions(-)
drivers/ram/rockchip/sdram_rk3399.c +119 -39
index 43b72fc658..9e6194f34a 100644
@@ -2770,15 +2770,20 @@ error:
 
 static unsigned char calculate_stride(struct rk3399_sdram_params *params)
 {
-	unsigned int stride = params->base.stride;
-	unsigned int channel, chinfo = 0;
+	unsigned int gstride_type;
+	unsigned int channel;
+	unsigned int chinfo = 0;
+	unsigned int cap = 0;
+	unsigned int stride = -1;
 	unsigned int ch_cap[2] = {0, 0};
-	u64 cap;
+
+	gstride_type = STRIDE_256B;
 
 	for (channel = 0; channel < 2; channel++) {
 		unsigned int cs0_cap = 0;
 		unsigned int cs1_cap = 0;
-		struct sdram_cap_info *cap_info = &params->ch[channel].cap_info;
+		struct sdram_cap_info *cap_info =
+			&params->ch[channel].cap_info;
 
 		if (cap_info->col == 0)
 			continue;
@@ -2796,49 +2801,124 @@ static unsigned char calculate_stride(struct rk3399_sdram_params *params)
 		chinfo |= 1 << channel;
 	}
 
-	/* stride calculation for 1 channel */
-	if (params->base.num_channels == 1 && chinfo & 1)
-		return 0x17;	/* channel a */
-
-	/* stride calculation for 2 channels, default gstride type is 256B */
-	if (ch_cap[0] == ch_cap[1]) {
-		cap = ch_cap[0] + ch_cap[1];
-		switch (cap) {
-		/* 512MB */
-		case 512:
-			stride = 0;
-			break;
-		/* 1GB */
-		case 1024:
-			stride = 0x5;
-			break;
+	cap = ch_cap[0] + ch_cap[1];
+	if (params->base.num_channels == 1) {
+		if (chinfo & 1) /* channel a only */
+			stride = 0x17;
+		else /* channel b only */
+			stride = 0x18;
+	} else {/* 2 channel */
+		if (ch_cap[0] == ch_cap[1]) {
+			/* interleaved */
+			if (gstride_type == PART_STRIDE) {
+			/*
+			 * first 64MB no interleaved other 256B interleaved
+			 * if 786M+768M.useful space from 0-1280MB and
+			 * 1536MB-1792MB
+			 * if 1.5G+1.5G(continuous).useful space from 0-2560MB
+			 * and 3072MB-3584MB
+			 */
+				stride = 0x1F;
+			} else {
+				switch (cap) {
+				/* 512MB */
+				case 512:
+					stride = 0;
+					break;
+				/* 1GB unstride or 256B stride*/
+				case 1024:
+					stride = (gstride_type == UN_STRIDE) ?
+						0x1 : 0x5;
+					break;
+				/*
+				 * 768MB + 768MB same as total 2GB memory
+				 * useful space: 0-768MB 1GB-1792MB
+				 */
+				case 1536:
+				/* 2GB unstride or 256B or 512B stride */
+				case 2048:
+					stride = (gstride_type == UN_STRIDE) ?
+						0x2 :
+						((gstride_type == STRIDE_512B) ?
+						 0xA : 0x9);
+					break;
+				/* 1536MB + 1536MB */
+				case 3072:
+					stride = (gstride_type == UN_STRIDE) ?
+						0x3 :
+						((gstride_type == STRIDE_512B) ?
+						 0x12 : 0x11);
+					break;
+				/* 4GB  unstride or 128B,256B,512B,4KB stride */
+				case 4096:
+					stride = (gstride_type == UN_STRIDE) ?
+						0x3 : (0xC + gstride_type);
+					break;
+				}
+			}
+		}
+		if (ch_cap[0] == 2048 && ch_cap[1] == 1024) {
+			/* 2GB + 1GB */
+			stride = (gstride_type == UN_STRIDE) ? 0x3 : 0x19;
+		}
 		/*
-		 * 768MB + 768MB same as total 2GB memory
-		 * useful space: 0-768MB 1GB-1792MB
+		 * remain two channel capability not equal OR capability
+		 * power function of 2
 		 */
-		case 1536:
-		/* 2GB */
-		case 2048:
-			stride = 0x9;
-			break;
-		/* 1536MB + 1536MB */
-		case 3072:
-			stride = 0x11;
-			break;
-		/* 4GB */
-		case 4096:
-			stride = 0xD;
-			break;
-		default:
-			printf("%s: Unable to calculate stride for ", __func__);
-			print_size((cap * (1 << 20)), " capacity\n");
-			break;
+		if (stride == (-1)) {
+			switch ((ch_cap[0] > ch_cap[1]) ?
+				ch_cap[0] : ch_cap[1]) {
+			case 256: /* 256MB + 128MB */
+				stride = 0;
+				break;
+			case 512: /* 512MB + 256MB */
+				stride = 1;
+				break;
+			case 1024:/* 1GB + 128MB/256MB/384MB/512MB/768MB */
+				stride = 2;
+				break;
+			case 2048: /* 2GB + 128MB/256MB/384MB/512MB/768MB/1GB */
+				stride = 3;
+				break;
+			default:
+				break;
+			}
 		}
+		if (stride == (-1))
+			goto error;
+	}
+	switch (stride) {
+	case 0xc:
+		printf("128B stride\n");
+		break;
+	case 5:
+	case 9:
+	case 0xd:
+	case 0x11:
+	case 0x19:
+		printf("256B stride\n");
+		break;
+	case 0xa:
+	case 0xe:
+	case 0x12:
+		printf("512B stride\n");
+		break;
+	case 0xf:
+		printf("4K stride\n");
+		break;
+	case 0x1f:
+		printf("32MB + 256B stride\n");
+		break;
+	default:
+		printf("no stride\n");
 	}
 
 	sdram_print_stride(stride);
 
 	return stride;
+error:
+	printf("Cap not support!\n");
+	return (-1);
 }
 
 static void clear_channel_params(struct rk3399_sdram_params *params, u8 channel)
Signature · 1 line
2.17.1
author
#17 lore raw

PATCH v2 17/17 ram: rk3399: Sync code from rockchip vendor code

In reply to Kever Yang

From: YouMin Chen <[email protected]>

There are some code different with rockchip vendor code which may lead to different bugs, including:
1) Fix setting error about LPDDR3 dram size ODT.
2) Set phy io speed to 0x2.
3) Fix setting error about phy_pad_fdbk_drive.
4) Fix setting error about PI_WDQLVL_VREF_EN

---

Changes in v2:
- Split the patches into multi smaller patches for easy to maintain, review and test;
- Keep the DRAM_ROCKCHIP_DEBUG macro and enable it by default;
- Update the rockchip_sdram_size to support sys_reg3;

 drivers/ram/rockchip/sdram_rk3399.c | 41 ++++++++++++++---------------
 1 file changed, 20 insertions(+), 21 deletions(-)
drivers/ram/rockchip/sdram_rk3399.c +20 -21
index 9e6194f34a..09ab13826a 100644
@@ -44,6 +44,11 @@
 #define CS0_MR22_VAL		0
 #define CS1_MR22_VAL		3
 
+/* LPDDR3 DRAM DS */
+#define LPDDR3_DS_34		0x1
+#define LPDDR3_DS_40		0x2
+#define LPDDR3_DS_48		0x3
+
 #define CRU_SFTRST_DDR_CTRL(ch, n)	((0x1 << (8 + 16 + (ch) * 4)) | \
 					((n) << (8 + (ch) * 4)))
 #define CRU_SFTRST_DDR_PHY(ch, n)	((0x1 << (9 + 16 + (ch) * 4)) | \
@@ -291,7 +296,8 @@ static void set_memory_map(const struct chan_info *chan, u32 channel,
 	if (sdram_ch->cap_info.ddrconfig < 2 ||
 	    sdram_ch->cap_info.ddrconfig == 4)
 		row = 16;
-	else if (sdram_ch->cap_info.ddrconfig == 3)
+	else if (sdram_ch->cap_info.ddrconfig == 3 ||
+		 sdram_ch->cap_info.ddrconfig == 5)
 		row = 14;
 	else
 		row = 15;
@@ -335,11 +341,12 @@ static int phy_io_config(const struct chan_info *chan,
 			 const struct rk3399_sdram_params *params, u32 mr5)
 {
 	u32 *denali_phy = chan->publ->denali_phy;
+	u32 *denali_ctl = chan->pctl->denali_ctl;
 	u32 vref_mode_dq, vref_value_dq, vref_mode_ac, vref_value_ac;
 	u32 mode_sel;
-	u32 reg_value;
-	u32 drv_value, odt_value;
 	u32 speed;
+	u32 reg_value;
+	u32 ds_value, odt_value;
 
 	/* vref setting & mode setting */
 	if (params->base.dramtype == LPDDR4) {
@@ -365,12 +372,12 @@ static int phy_io_config(const struct chan_info *chan,
 	} else if (params->base.dramtype == LPDDR3) {
 		if (params->base.odt == 1) {
 			vref_mode_dq = 0x5;  /* LPDDR3 ODT */
-			drv_value = (readl(&denali_phy[6]) >> 12) & 0xf;
+			ds_value = readl(&denali_ctl[138]) & 0xf;
 			odt_value = (readl(&denali_phy[6]) >> 4) & 0xf;
-			if (drv_value == PHY_DRV_ODT_48) {
+			if (ds_value == LPDDR3_DS_48) {
 				switch (odt_value) {
 				case PHY_DRV_ODT_240:
-					vref_value_dq = 0x16;
+					vref_value_dq = 0x1B;
 					break;
 				case PHY_DRV_ODT_120:
 					vref_value_dq = 0x26;
@@ -382,7 +389,7 @@ static int phy_io_config(const struct chan_info *chan,
 					debug("Invalid ODT value.\n");
 					return -EINVAL;
 				}
-			} else if (drv_value == PHY_DRV_ODT_40) {
+			} else if (ds_value == LPDDR3_DS_40) {
 				switch (odt_value) {
 				case PHY_DRV_ODT_240:
 					vref_value_dq = 0x19;
@@ -397,7 +404,7 @@ static int phy_io_config(const struct chan_info *chan,
 					debug("Invalid ODT value.\n");
 					return -EINVAL;
 				}
-			} else if (drv_value == PHY_DRV_ODT_34_3) {
+			} else if (ds_value == LPDDR3_DS_34) {
 				switch (odt_value) {
 				case PHY_DRV_ODT_240:
 					vref_value_dq = 0x17;
@@ -509,14 +516,7 @@ static int phy_io_config(const struct chan_info *chan,
 	}
 
 	/* speed setting */
-	if (params->base.ddr_freq < 400)
-		speed = 0x0;
-	else if (params->base.ddr_freq < 800)
-		speed = 0x1;
-	else if (params->base.ddr_freq < 1200)
-		speed = 0x2;
-	else
-		speed = 0x3;
+	speed = 0x2;
 
 	/* PHY_924 PHY_PAD_FDBK_DRIVE */
 	clrsetbits_le32(&denali_phy[924], 0x3 << 21, speed << 21);
@@ -739,9 +739,9 @@ static void set_ds_odt(const struct chan_info *chan,
 
 	/* phy_pad_fdbk_drive 23bit DENALI_PHY_924/925 */
 	clrsetbits_le32(&denali_phy[924], 0xff,
-			tsel_wr_select_dq_n | (tsel_wr_select_dq_p << 4));
+			tsel_wr_select_ca_n | (tsel_wr_select_ca_p << 4));
 	clrsetbits_le32(&denali_phy[925], 0xff,
-			tsel_rd_select_n | (tsel_rd_select_p << 4));
+			tsel_wr_select_dq_n | (tsel_wr_select_dq_p << 4));
 
 	/* phy_dq_tsel_enable_X 3bits DENALI_PHY_5/133/261/389 offset_16 */
 	reg_value = (tsel_rd_en | (tsel_wr_en << 1) | (tsel_idle_en << 2))
@@ -1340,10 +1340,9 @@ static int data_training_wdql(const struct chan_info *chan, u32 channel,
 
 		/*
 		 * disable PI_WDQLVL_VREF_EN before wdq leveling?
-		 * PI_181 PI_WDQLVL_VREF_EN:RW:8:1
+		 * PI_117 PI_WDQLVL_VREF_EN:RW:8:1
 		 */
-		clrbits_le32(&denali_pi[181], 0x1 << 8);
-
+		clrbits_le32(&denali_pi[117], 0x1 << 8);
 		/* PI_124 PI_WDQLVL_EN:RW:16:2 */
 		clrsetbits_le32(&denali_pi[124], 0x3 << 16, 0x2 << 16);
 
Signature · 1 line
2.17.1