5 #include <soc/addressmap.h>
231 #define DFI_INIT_START (1 << 0)
234 #define DFI_DRAM_CLK_SR_EN (1 << 0)
235 #define DFI_DRAM_CLK_DPD_EN (1 << 1)
238 #define DFI_PARITY_INTR_EN (1 << 0)
239 #define DFI_PARITY_EN (1 << 1)
242 #define TLP_RESP_TIME(n) (n << 16)
243 #define LP_SR_EN (1 << 8)
244 #define LP_PD_EN (1 << 0)
247 #define TCTRL_DELAY_TIME(n) (n << 0)
250 #define TPHY_WRDATA_TIME(n) (n << 0)
253 #define TPHY_RDLAT_TIME(n) (n << 0)
256 #define TDRAM_CLK_DIS_TIME(n) (n << 0)
259 #define TDRAM_CLK_EN_TIME(n) (n << 0)
262 #define RANK0_ODT_WRITE_SEL (1 << 3)
263 #define RANK1_ODT_WRITE_SEL (1 << 11)
266 #define ODT_LEN_BL8_W(n) (n<<16)
269 #define ACDLLCR_DLLDIS (1 << 31)
270 #define ACDLLCR_DLLSRST (1 << 30)
273 #define DXDLLCR_DLLDIS (1 << 31)
274 #define DXDLLCR_DLLSRST (1 << 30)
277 #define DLLGCR_SBIAS (1 << 30)
280 #define DQSRTT (1 << 9)
281 #define DQRTT (1 << 10)
284 #define PIR_INIT (1 << 0)
285 #define PIR_DLLSRST (1 << 1)
286 #define PIR_DLLLOCK (1 << 2)
287 #define PIR_ZCAL (1 << 3)
288 #define PIR_ITMSRST (1 << 4)
289 #define PIR_DRAMRST (1 << 5)
290 #define PIR_DRAMINIT (1 << 6)
291 #define PIR_QSTRN (1 << 7)
292 #define PIR_RVTRN (1 << 8)
293 #define PIR_ICPC (1 << 16)
294 #define PIR_DLLBYP (1 << 17)
295 #define PIR_CTLDINIT (1 << 18)
296 #define PIR_CLRSR (1 << 28)
297 #define PIR_LOCKBYP (1 << 29)
298 #define PIR_ZCALBYP (1 << 30)
299 #define PIR_INITBYP (1u << 31)
302 #define PGCR_DFTLMT(n) ((n) << 3)
303 #define PGCR_DFTCMP(n) ((n) << 2)
304 #define PGCR_DQSCFG(n) ((n) << 1)
305 #define PGCR_ITMDMD(n) ((n) << 0)
308 #define PGSR_IDONE (1 << 0)
309 #define PGSR_DLDONE (1 << 1)
310 #define PGSR_ZCDONE (1 << 2)
311 #define PGSR_DIDONE (1 << 3)
312 #define PGSR_DTDONE (1 << 4)
313 #define PGSR_DTERR (1 << 5)
314 #define PGSR_DTIERR (1 << 6)
315 #define PGSR_DFTERR (1 << 7)
316 #define PGSR_RVERR (1 << 8)
317 #define PGSR_RVEIRR (1 << 9)
320 #define PRT_ITMSRST(n) ((n) << 18)
321 #define PRT_DLLLOCK(n) ((n) << 6)
322 #define PRT_DLLSRST(n) ((n) << 0)
325 #define PRT_DINIT0(n) ((n) << 0)
326 #define PRT_DINIT1(n) ((n) << 19)
329 #define PRT_DINIT2(n) ((n) << 0)
330 #define PRT_DINIT3(n) ((n) << 17)
333 #define DDRMD_LPDDR 0
337 #define DDRMD_LPDDR2_LPDDR3 4
338 #define DDRMD_MSK (7 << 0)
339 #define DDRMD_CFG(n) ((n) << 0)
340 #define PDQ_MSK (7 << 4)
341 #define PDQ_CFG(n) ((n) << 4)
344 #define DQSNRES_MSK (0x0f << 8)
345 #define DQSNRES_CFG(n) ((n) << 8)
346 #define DQSRES_MSK (0x0f << 4)
347 #define DQSRES_CFG(n) ((n) << 4)
350 #define TDQSCKMAX_VAL(n) (((n) >> 27) & 7)
351 #define TDQSCK_VAL(n) (((n) >> 24) & 7)
354 #define DQSGX_MSK (0x07 << 5)
355 #define DQSGX_CFG(n) ((n) << 5)
356 #define DQSGE_MSK (0x07 << 8)
357 #define DQSGE_CFG(n) ((n) << 8)
360 #define INIT_STATE (0)
361 #define CFG_STATE (1)
363 #define SLEEP_STATE (3)
364 #define WAKEUP_STATE (4)
367 #define LP_TRIG_VAL(n) (((n) >> 4) & 7)
368 #define PCTL_STAT_MSK (7)
373 #define ACCESS_REQ (4)
374 #define LOW_POWER (5)
375 #define LOW_POWER_ENTRY_REQ (6)
376 #define LOW_POWER_EXIT_REQ (7)
379 #define PD_OUTPUT(n) ((n) << 0)
380 #define PU_OUTPUT(n) ((n) << 5)
381 #define PD_ONDIE(n) ((n) << 10)
382 #define PU_ONDIE(n) ((n) << 15)
383 #define ZDEN(n) ((n) << 28)
386 #define SBIAS_BYPASS (1 << 23)
389 #define MDDR_LPDDR2_CLK_STOP_IDLE(n) ((n) << 24)
390 #define PD_IDLE(n) ((n) << 8)
391 #define MDDR_EN (2 << 22)
392 #define LPDDR2_EN (3 << 22)
393 #define DDR2_EN (0 << 5)
394 #define DDR3_EN (1 << 5)
395 #define LPDDR2_S2 (0 << 6)
396 #define LPDDR2_S4 (1 << 6)
397 #define MDDR_LPDDR2_BL_2 (0 << 20)
398 #define MDDR_LPDDR2_BL_4 (1 << 20)
399 #define MDDR_LPDDR2_BL_8 (2 << 20)
400 #define MDDR_LPDDR2_BL_16 (3 << 20)
401 #define DDR2_DDR3_BL_4 (0)
402 #define DDR2_DDR3_BL_8 (1)
403 #define TFAW_CFG(n) (((n)-4) << 18)
404 #define PD_EXIT_SLOW (0 << 17)
405 #define PD_EXIT_FAST (1 << 17)
406 #define PD_TYPE(n) ((n) << 16)
407 #define BURSTLENGTH_CFG(n) (((n) >> 1) << 20)
410 #define POWER_UP_START (1 << 0)
413 #define POWER_UP_DONE (1 << 0)
416 #define DESELECT_CMD (0)
426 #define LPDDR2_MA(n) (((n) & 0xff) << 4)
427 #define LPDDR2_OP(n) (((n) & 0xff) << 12)
429 #define START_CMD (1u << 31)
432 #define BUSWRTORD(n) ((n) << 4)
433 #define BUSRDTOWR(n) ((n) << 2)
434 #define BUSRDTORD(n) ((n) << 0)
437 #define MSCH_MAINDDR3(ch, n) (((n) << (3 + (ch))) \
438 | ((1 << (3 + (ch))) << 16))
441 #define PCTL_LPDDR3_ODT_EN(ch, n) RK_CLRSETBITS(1 << (10 + (3 * (ch))), \
442 (n) << (10 + (3 * (ch))))
443 #define PCTL_BST_DISABLE(ch, n) RK_CLRSETBITS(1 << (9 + (3 * (ch))), \
444 (n) << (9 + (3 * (ch))))
445 #define PUBL_LPDDR3_EN(ch, n) RK_CLRSETBITS(1 << (8 + (3 * (ch))), \
446 (n) << (8 + (3 * (ch))))
449 #define DDR3_DLL_ENABLE (0)
450 #define DDR3_DLL_DISABLE (1)
474 #define SYS_REG_ENC_ROW_3_4(n, ch) ((n) << (30 + (ch)))
475 #define SYS_REG_DEC_ROW_3_4(n, ch) ((n >> (30 + ch)) & 0x1)
476 #define SYS_REG_ENC_CHINFO(ch) (1 << (28 + (ch)))
477 #define SYS_REG_ENC_DDRTYPE(n) ((n) << 13)
478 #define SYS_REG_ENC_NUM_CH(n) (((n) - 1) << 12)
479 #define SYS_REG_DEC_NUM_CH(n) (1 + ((n >> 12) & 0x1))
480 #define SYS_REG_ENC_RANK(n, ch) (((n) - 1) << (11 + ((ch) * 16)))
481 #define SYS_REG_DEC_RANK(n, ch) (1 + ((n >> (11 + 16 * ch)) & 0x1))
482 #define SYS_REG_ENC_COL(n, ch) (((n) - 9) << (9 + ((ch) * 16)))
483 #define SYS_REG_DEC_COL(n, ch) (9 + ((n >> (9 + 16 * ch)) & 0x3))
484 #define SYS_REG_ENC_BK(n, ch) (((n) == 3 ? 0 : 1) \
485 << (8 + ((ch) * 16)))
486 #define SYS_REG_DEC_BK(n, ch) (3 - ((n >> (8 + 16 * ch)) & 0x1))
487 #define SYS_REG_ENC_CS0_ROW(n, ch) (((n) - 13) << (6 + ((ch) * 16)))
488 #define SYS_REG_DEC_CS0_ROW(n, ch) (13 + ((n >> (6 + 16 * ch)) & 0x3))
489 #define SYS_REG_ENC_CS1_ROW(n, ch) (((n) - 13) << (4 + ((ch) * 16)))
490 #define SYS_REG_DEC_CS1_ROW(n, ch) (13 + ((n >> (4 + 16 * ch)) & 0x3))
491 #define SYS_REG_ENC_BW(n, ch) ((2 >> (n)) << (2 + ((ch) * 16)))
492 #define SYS_REG_DEC_BW(n, ch) (2 >> ((n >> (2 + 16 * ch)) & 0x3))
493 #define SYS_REG_ENC_DBW(n, ch) ((2 >> (n)) << (0 + ((ch) * 16)))
494 #define SYS_REG_DEC_DBW(n, ch) (2 >> ((n >> (0 + 16 * ch)) & 0x3))
499 for (i = 0; i < n /
sizeof(
u32); i++) {
513 for (i = 0; i < 4; i++)
518 for (i = 0; i < 4; i++)
538 for (i = 0; i < 4; i++)
546 for (i = 0; i < 4; i++)
582 unsigned int burstlen;
678 for (i = 0; i < 4; i++)
683 for (i = 0; i < 4; i++)
855 for (i = 0; i < (rank > 1 ? 8 : 4); i++)
929 unsigned int channel;
933 for (channel = 0; channel <
sdram_params->num_channels; channel++) {
963 die(
"SDRAM frequency is to high!");
967 for (channel = 0; channel < 2; channel++) {
1042 die(
"SDRAM initialization failed!");
1053 die(
"SDRAM initialization failed!");
1059 for (i = 0; i < 17; i++)
1071 u32 rank, col, bk, cs0_row, cs1_row, bw, row_3_4;
1072 size_t chipsize_mb = 0;
1073 static size_t size_mb = 0;
1081 for (
ch = 0;
ch < ch_num;
ch++) {
1090 chipsize_mb = (1 << (cs0_row + col + bk + bw - 20));
1093 chipsize_mb += chipsize_mb >>
1094 (cs0_row - cs1_row);
1096 chipsize_mb = chipsize_mb * 3 / 4;
1097 size_mb += chipsize_mb;
1105 size_mb =
MIN(size_mb, 0xff000000/
MiB);
static void write32(void *addr, uint32_t val)
static uint32_t read32(const void *addr)
#define DIV_ROUND_UP(x, y)
size_t sdram_size_mb(void)
#define printk(level,...)
void __noreturn die(const char *fmt,...)
static struct smmstore_params_info info
#define setbits32(addr, set)
#define clrsetbits32(addr, clear, set)
#define clrbits32(addr, clear)
#define BIOS_INFO
BIOS_INFO - Expected events.
static struct dramc_channel const ch[2]
void sdram_init(const struct sdram_params *param)
static struct rk3288_pmu_regs *const rk3288_pmu
static struct rk3288_grf_regs *const rk3288_grf
static struct rk3288_sgrf_regs *const rk3288_sgrf
#define RK_CLRSETBITS(clr, set)
#define RANK1_ODT_WRITE_SEL
#define MDDR_LPDDR2_CLK_STOP_IDLE(n)
static struct rk3288_ddr_pctl_regs *const rk3288_ddr_pctl[2]
#define PCTL_LPDDR3_ODT_EN(ch, n)
#define DDRMD_LPDDR2_LPDDR3
#define DFI_DRAM_CLK_DPD_EN
#define TPHY_WRDATA_TIME(n)
static void copy_to_reg(u32 *dest, const u32 *src, u32 n)
#define DFI_PARITY_INTR_EN
#define MSCH_MAINDDR3(ch, n)
#define TDRAM_CLK_DIS_TIME(n)
static void dram_all_config(const struct rk3288_sdram_params *sdram_params)
check_member(rk3288_ddr_pctl_regs, iptr, 0x03fc)
#define SYS_REG_ENC_CHINFO(ch)
static void memory_init(struct rk3288_ddr_publ_regs *ddr_publ_regs, u32 dramtype)
#define PUBL_LPDDR3_EN(ch, n)
#define SYS_REG_ENC_COL(n, ch)
#define SYS_REG_DEC_BW(n, ch)
static struct rk3288_ddr_publ_regs *const rk3288_ddr_publ[2]
static void phy_pctrl_reset(struct rk3288_ddr_publ_regs *ddr_publ_regs, u32 channel)
#define TPHY_RDLAT_TIME(n)
#define SYS_REG_DEC_RANK(n, ch)
#define SYS_REG_DEC_ROW_3_4(n, ch)
#define PCTL_BST_DISABLE(ch, n)
#define RANK0_ODT_WRITE_SEL
#define SYS_REG_DEC_CS0_ROW(n, ch)
#define SYS_REG_ENC_NUM_CH(n)
#define SYS_REG_DEC_BK(n, ch)
#define SYS_REG_DEC_CS1_ROW(n, ch)
#define SYS_REG_ENC_ROW_3_4(n, ch)
#define SYS_REG_ENC_DDRTYPE(n)
static void send_command(struct rk3288_ddr_pctl_regs *ddr_pctl_regs, u32 rank, u32 cmd, u32 arg)
#define TCTRL_DELAY_TIME(n)
static void phy_dll_bypass_set(struct rk3288_ddr_publ_regs *ddr_publ_regs, u32 freq)
static void pctl_cfg(u32 channel, const struct rk3288_sdram_params *sdram_params)
static void phy_init(struct rk3288_ddr_publ_regs *ddr_publ_regs)
static int data_training(u32 channel, const struct rk3288_sdram_params *sdram_params)
#define TDRAM_CLK_EN_TIME(n)
static void dram_cfg_rbc(u32 chnum, const struct rk3288_sdram_params *sdram_params)
#define SYS_REG_ENC_CS1_ROW(n, ch)
#define SYS_REG_DEC_NUM_CH(n)
#define SYS_REG_DEC_COL(n, ch)
#define SYS_REG_ENC_BK(n, ch)
static void dfi_cfg(struct rk3288_ddr_pctl_regs *ddr_pctl_regs, u32 dramtype)
static struct rk3288_msch_regs *const rk3288_msch[2]
#define SYS_REG_ENC_BW(n, ch)
#define SYS_REG_ENC_RANK(n, ch)
#define BURSTLENGTH_CFG(n)
static void set_bandwidth_ratio(u32 channel, u32 n)
#define SYS_REG_ENC_DBW(n, ch)
#define DFI_DRAM_CLK_SR_EN
static void move_to_access_state(u32 chnum)
#define SYS_REG_ENC_CS0_ROW(n, ch)
static void phy_cfg(u32 channel, const struct rk3288_sdram_params *sdram_params)
static void move_to_config_state(struct rk3288_ddr_publ_regs *ddr_publ_regs, struct rk3288_ddr_pctl_regs *ddr_pctl_regs)
void rkclk_ddr_phy_ctl_reset(u32 ch, u32 n)
void rkclk_ddr_reset(u32 ch, u32 ctl, u32 phy)
void rkclk_configure_ddr(unsigned int hz)
struct rk3288_ddr_publ_datx datx8[4]
Defines the SDRAM parameter structure.