blob: 79960bf46f8b1ff95f9fac3d195d4bbb6ee2acee [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vaibhav Hiremath598f7022010-06-07 15:20:53 -04002/*
3 * Author :
4 * Vaibhav Hiremath <hvaibhav@ti.com>
5 *
6 * Based on mem.c and sdrc.c
7 *
8 * Copyright (C) 2010
Nishanth Menoneaa39c62023-11-01 15:56:03 -05009 * Texas Instruments Incorporated - https://www.ti.com/
Vaibhav Hiremath598f7022010-06-07 15:20:53 -040010 */
11
Tom Riniefd9f332024-04-30 07:35:39 -060012#include <config.h>
Simon Glass97589732020-05-10 11:40:02 -060013#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Tom Riniefd9f332024-04-30 07:35:39 -060015#include <asm/u-boot.h>
Vaibhav Hiremath598f7022010-06-07 15:20:53 -040016#include <asm/io.h>
17#include <asm/arch/mem.h>
18#include <asm/arch/sys_proto.h>
19#include <asm/arch/emif4.h>
20
Nishanth Menonedded0e42010-12-11 11:41:42 -050021DECLARE_GLOBAL_DATA_PTR;
Vaibhav Hiremath598f7022010-06-07 15:20:53 -040022extern omap3_sysinfo sysinfo;
23
24static emif4_t *emif4_base = (emif4_t *)OMAP34XX_SDRC_BASE;
25
26/*
27 * is_mem_sdr -
28 * - Return 1 if mem type in use is SDR
29 */
30u32 is_mem_sdr(void)
31{
32 return 0;
33}
34
35/*
36 * get_sdr_cs_size -
37 * - Get size of chip select 0/1
38 */
Adam Ford3a8059e2022-02-12 06:12:41 -060039static u32 get_sdr_cs_size(u32 cs)
Vaibhav Hiremath598f7022010-06-07 15:20:53 -040040{
Vaibhav Hiremath83139462010-11-29 16:36:10 -050041 u32 size = 0;
Vaibhav Hiremath598f7022010-06-07 15:20:53 -040042
43 /* TODO: Calculate the size based on EMIF4 configuration */
Vaibhav Hiremath83139462010-11-29 16:36:10 -050044 if (cs == CS0)
Tom Rinicb2a32a2022-06-27 13:35:48 -040045 size = 256 * 1024 * 1024;
Vaibhav Hiremath598f7022010-06-07 15:20:53 -040046
47 return size;
48}
49
50/*
51 * get_sdr_cs_offset -
52 * - Get offset of cs from cs0 start
53 */
54u32 get_sdr_cs_offset(u32 cs)
55{
56 u32 offset = 0;
57
58 return offset;
59}
60
61/*
62 * do_emif4_init -
63 * - Init the emif4 module for DDR access
64 * - Early init routines, called from flash or SRAM.
65 */
Jeroen Hofsteecbc75622014-10-08 22:57:41 +020066static void do_emif4_init(void)
Vaibhav Hiremath598f7022010-06-07 15:20:53 -040067{
68 unsigned int regval;
69 /* Set the DDR PHY parameters in PHY ctrl registers */
70 regval = (EMIF4_DDR1_READ_LAT | EMIF4_DDR1_PWRDN_DIS |
71 EMIF4_DDR1_EXT_STRB_DIS);
72 writel(regval, &emif4_base->ddr_phyctrl1);
73 writel(regval, &emif4_base->ddr_phyctrl1_shdw);
74 writel(0, &emif4_base->ddr_phyctrl2);
75
76 /* Reset the DDR PHY and wait till completed */
77 regval = readl(&emif4_base->sdram_iodft_tlgc);
78 regval |= (1<<10);
79 writel(regval, &emif4_base->sdram_iodft_tlgc);
80 /*Wait till that bit clears*/
xypron.glpk@gmx.de9b5f2592017-04-15 16:11:12 +020081 while ((readl(&emif4_base->sdram_iodft_tlgc) & (1<<10)) != 0x0);
Vaibhav Hiremath598f7022010-06-07 15:20:53 -040082 /*Re-verify the DDR PHY status*/
83 while ((readl(&emif4_base->sdram_sts) & (1<<2)) == 0x0);
84
85 regval |= (1<<0);
86 writel(regval, &emif4_base->sdram_iodft_tlgc);
87 /* Set SDR timing registers */
88 regval = (EMIF4_TIM1_T_WTR | EMIF4_TIM1_T_RRD |
89 EMIF4_TIM1_T_RC | EMIF4_TIM1_T_RAS |
90 EMIF4_TIM1_T_WR | EMIF4_TIM1_T_RCD |
91 EMIF4_TIM1_T_RP);
92 writel(regval, &emif4_base->sdram_time1);
93 writel(regval, &emif4_base->sdram_time1_shdw);
94
95 regval = (EMIF4_TIM2_T_CKE | EMIF4_TIM2_T_RTP |
96 EMIF4_TIM2_T_XSRD | EMIF4_TIM2_T_XSNR |
97 EMIF4_TIM2_T_ODT | EMIF4_TIM2_T_XP);
98 writel(regval, &emif4_base->sdram_time2);
99 writel(regval, &emif4_base->sdram_time2_shdw);
100
101 regval = (EMIF4_TIM3_T_RAS_MAX | EMIF4_TIM3_T_RFC);
102 writel(regval, &emif4_base->sdram_time3);
103 writel(regval, &emif4_base->sdram_time3_shdw);
104
105 /* Set the PWR control register */
106 regval = (EMIF4_PWR_PM_TIM | EMIF4_PWR_LP_MODE |
107 EMIF4_PWR_DPD_DIS | EMIF4_PWR_IDLE_MODE);
108 writel(regval, &emif4_base->sdram_pwr_mgmt);
109 writel(regval, &emif4_base->sdram_pwr_mgmt_shdw);
110
111 /* Set the DDR refresh rate control register */
112 regval = (EMIF4_REFRESH_RATE | EMIF4_INITREF_DIS);
113 writel(regval, &emif4_base->sdram_refresh_ctrl);
114 writel(regval, &emif4_base->sdram_refresh_ctrl_shdw);
115
116 /* set the SDRAM configuration register */
117 regval = (EMIF4_CFG_PGSIZE | EMIF4_CFG_EBANK |
118 EMIF4_CFG_IBANK | EMIF4_CFG_ROWSIZE |
119 EMIF4_CFG_CL | EMIF4_CFG_NARROW_MD |
120 EMIF4_CFG_SDR_DRV | EMIF4_CFG_DDR_DIS_DLL |
121 EMIF4_CFG_DDR2_DDQS | EMIF4_CFG_DDR_TERM |
122 EMIF4_CFG_IBANK_POS | EMIF4_CFG_SDRAM_TYP);
123 writel(regval, &emif4_base->sdram_config);
124}
125
126/*
127 * dram_init -
128 * - Sets uboots idea of sdram size
129 */
130int dram_init(void)
131{
Vaibhav Hiremath598f7022010-06-07 15:20:53 -0400132 unsigned int size0 = 0, size1 = 0;
133
134 size0 = get_sdr_cs_size(CS0);
135 /*
136 * If a second bank of DDR is attached to CS1 this is
137 * where it can be started. Early init code will init
138 * memory on CS0.
139 */
140 if ((sysinfo.mtype == DDR_COMBO) || (sysinfo.mtype == DDR_STACKED))
141 size1 = get_sdr_cs_size(CS1);
142
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200143 gd->ram_size = size0 + size1;
144 return 0;
145}
146
Simon Glass2f949c32017-03-31 08:40:32 -0600147int dram_init_banksize(void)
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200148{
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200149 unsigned int size0 = 0, size1 = 0;
150
151 size0 = get_sdr_cs_size(CS0);
152 size1 = get_sdr_cs_size(CS1);
153
154 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
155 gd->bd->bi_dram[0].size = size0;
156 gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
157 gd->bd->bi_dram[1].size = size1;
Simon Glass2f949c32017-03-31 08:40:32 -0600158
159 return 0;
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200160}
Vaibhav Hiremath598f7022010-06-07 15:20:53 -0400161
162/*
Maxim Uvarov74dde142023-12-26 21:46:18 +0600163 * omap3_mem_init() -
Vaibhav Hiremath598f7022010-06-07 15:20:53 -0400164 * - Initialize memory subsystem
165 */
Maxim Uvarov74dde142023-12-26 21:46:18 +0600166void omap3_mem_init(void)
Vaibhav Hiremath598f7022010-06-07 15:20:53 -0400167{
168 do_emif4_init();
169}