blob: c747b461a1515ed960a56a30fef04a394e1a85a9 [file] [log] [blame]
Kever Yang9228f282019-08-02 10:39:59 +03001/*
2 * Copyright (C) 2016-2017 Rockchip Electronics Co., Ltd
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#ifndef _ASM_ARCH_SDRAM_RK3328_H
8#define _ASM_ARCH_SDRAM_RK3328_H
Kever Yang38a99b62019-11-15 11:04:34 +08009#include <asm/arch-rockchip/sdram_common.h>
Kever Yang9228f282019-08-02 10:39:59 +030010
11#define SR_IDLE 93
12#define PD_IDLE 13
13#define SDRAM_ADDR 0x00000000
14#define PATTERN (0x5aa5f00f)
15
16/* ddr pctl registers define */
17#define DDR_PCTL2_MSTR 0x0
18#define DDR_PCTL2_STAT 0x4
19#define DDR_PCTL2_MSTR1 0x8
20#define DDR_PCTL2_MRCTRL0 0x10
21#define DDR_PCTL2_MRCTRL1 0x14
22#define DDR_PCTL2_MRSTAT 0x18
23#define DDR_PCTL2_MRCTRL2 0x1c
24#define DDR_PCTL2_DERATEEN 0x20
25#define DDR_PCTL2_DERATEINT 0x24
26#define DDR_PCTL2_PWRCTL 0x30
27#define DDR_PCTL2_PWRTMG 0x34
28#define DDR_PCTL2_HWLPCTL 0x38
29#define DDR_PCTL2_RFSHCTL0 0x50
30#define DDR_PCTL2_RFSHCTL1 0x54
31#define DDR_PCTL2_RFSHCTL2 0x58
32#define DDR_PCTL2_RFSHCTL4 0x5c
33#define DDR_PCTL2_RFSHCTL3 0x60
34#define DDR_PCTL2_RFSHTMG 0x64
35#define DDR_PCTL2_RFSHTMG1 0x68
36#define DDR_PCTL2_RFSHCTL5 0x6c
37#define DDR_PCTL2_INIT0 0xd0
38#define DDR_PCTL2_INIT1 0xd4
39#define DDR_PCTL2_INIT2 0xd8
40#define DDR_PCTL2_INIT3 0xdc
41#define DDR_PCTL2_INIT4 0xe0
42#define DDR_PCTL2_INIT5 0xe4
43#define DDR_PCTL2_INIT6 0xe8
44#define DDR_PCTL2_INIT7 0xec
45#define DDR_PCTL2_DIMMCTL 0xf0
46#define DDR_PCTL2_RANKCTL 0xf4
47#define DDR_PCTL2_CHCTL 0xfc
48#define DDR_PCTL2_DRAMTMG0 0x100
49#define DDR_PCTL2_DRAMTMG1 0x104
50#define DDR_PCTL2_DRAMTMG2 0x108
51#define DDR_PCTL2_DRAMTMG3 0x10c
52#define DDR_PCTL2_DRAMTMG4 0x110
53#define DDR_PCTL2_DRAMTMG5 0x114
54#define DDR_PCTL2_DRAMTMG6 0x118
55#define DDR_PCTL2_DRAMTMG7 0x11c
56#define DDR_PCTL2_DRAMTMG8 0x120
57#define DDR_PCTL2_DRAMTMG9 0x124
58#define DDR_PCTL2_DRAMTMG10 0x128
59#define DDR_PCTL2_DRAMTMG11 0x12c
60#define DDR_PCTL2_DRAMTMG12 0x130
61#define DDR_PCTL2_DRAMTMG13 0x134
62#define DDR_PCTL2_DRAMTMG14 0x138
63#define DDR_PCTL2_DRAMTMG15 0x13c
64#define DDR_PCTL2_DRAMTMG16 0x140
65#define DDR_PCTL2_ZQCTL0 0x180
66#define DDR_PCTL2_ZQCTL1 0x184
67#define DDR_PCTL2_ZQCTL2 0x188
68#define DDR_PCTL2_ZQSTAT 0x18c
69#define DDR_PCTL2_DFITMG0 0x190
70#define DDR_PCTL2_DFITMG1 0x194
71#define DDR_PCTL2_DFILPCFG0 0x198
72#define DDR_PCTL2_DFILPCFG1 0x19c
73#define DDR_PCTL2_DFIUPD0 0x1a0
74#define DDR_PCTL2_DFIUPD1 0x1a4
75#define DDR_PCTL2_DFIUPD2 0x1a8
76#define DDR_PCTL2_DFIMISC 0x1b0
77#define DDR_PCTL2_DFITMG2 0x1b4
78#define DDR_PCTL2_DFITMG3 0x1b8
79#define DDR_PCTL2_DFISTAT 0x1bc
80#define DDR_PCTL2_DBICTL 0x1c0
81#define DDR_PCTL2_ADDRMAP0 0x200
82#define DDR_PCTL2_ADDRMAP1 0x204
83#define DDR_PCTL2_ADDRMAP2 0x208
84#define DDR_PCTL2_ADDRMAP3 0x20c
85#define DDR_PCTL2_ADDRMAP4 0x210
86#define DDR_PCTL2_ADDRMAP5 0x214
87#define DDR_PCTL2_ADDRMAP6 0x218
88#define DDR_PCTL2_ADDRMAP7 0x21c
89#define DDR_PCTL2_ADDRMAP8 0x220
90#define DDR_PCTL2_ADDRMAP9 0x224
91#define DDR_PCTL2_ADDRMAP10 0x228
92#define DDR_PCTL2_ADDRMAP11 0x22c
93#define DDR_PCTL2_ODTCFG 0x240
94#define DDR_PCTL2_ODTMAP 0x244
95#define DDR_PCTL2_SCHED 0x250
96#define DDR_PCTL2_SCHED1 0x254
97#define DDR_PCTL2_PERFHPR1 0x25c
98#define DDR_PCTL2_PERFLPR1 0x264
99#define DDR_PCTL2_PERFWR1 0x26c
100#define DDR_PCTL2_DQMAP0 0x280
101#define DDR_PCTL2_DQMAP1 0x284
102#define DDR_PCTL2_DQMAP2 0x288
103#define DDR_PCTL2_DQMAP3 0x28c
104#define DDR_PCTL2_DQMAP4 0x290
105#define DDR_PCTL2_DQMAP5 0x294
106#define DDR_PCTL2_DBG0 0x300
107#define DDR_PCTL2_DBG1 0x304
108#define DDR_PCTL2_DBGCAM 0x308
109#define DDR_PCTL2_DBGCMD 0x30c
110#define DDR_PCTL2_DBGSTAT 0x310
111#define DDR_PCTL2_SWCTL 0x320
112#define DDR_PCTL2_SWSTAT 0x324
113#define DDR_PCTL2_POISONCFG 0x36c
114#define DDR_PCTL2_POISONSTAT 0x370
115#define DDR_PCTL2_ADVECCINDEX 0x374
116#define DDR_PCTL2_ADVECCSTAT 0x378
117#define DDR_PCTL2_PSTAT 0x3fc
118#define DDR_PCTL2_PCCFG 0x400
119#define DDR_PCTL2_PCFGR_n 0x404
120#define DDR_PCTL2_PCFGW_n 0x408
121#define DDR_PCTL2_PCTRL_n 0x490
122
123/* PCTL2_MRSTAT */
124#define MR_WR_BUSY BIT(0)
125
126/* PHY_REG0 */
127#define DIGITAL_DERESET BIT(3)
128#define ANALOG_DERESET BIT(2)
129#define DIGITAL_RESET (0 << 3)
130#define ANALOG_RESET (0 << 2)
131
132/* PHY_REG1 */
133#define PHY_DDR2 (0)
134#define PHY_LPDDR2 (1)
135#define PHY_DDR3 (2)
136#define PHY_LPDDR3 (3)
137#define PHY_DDR4 (4)
138#define PHY_BL_4 (0 << 2)
139#define PHY_BL_8 BIT(2)
140
141/* PHY_REG2 */
142#define PHY_DTT_EN BIT(0)
143#define PHY_DTT_DISB (0 << 0)
144#define PHY_WRITE_LEVELING_EN BIT(2)
145#define PHY_WRITE_LEVELING_DISB (0 << 2)
146#define PHY_SELECT_CS0 (2)
147#define PHY_SELECT_CS1 (1)
148#define PHY_SELECT_CS0_1 (0)
149#define PHY_WRITE_LEVELING_SELECTCS(n) (n << 6)
150#define PHY_DATA_TRAINING_SELECTCS(n) (n << 4)
151
152#define PHY_DDR3_RON_RTT_DISABLE (0)
153#define PHY_DDR3_RON_RTT_451ohm (1)
154#define PHY_DDR3_RON_RTT_225ohm (2)
155#define PHY_DDR3_RON_RTT_150ohm (3)
156#define PHY_DDR3_RON_RTT_112ohm (4)
157#define PHY_DDR3_RON_RTT_90ohm (5)
158#define PHY_DDR3_RON_RTT_75ohm (6)
159#define PHY_DDR3_RON_RTT_64ohm (7)
160#define PHY_DDR3_RON_RTT_56ohm (16)
161#define PHY_DDR3_RON_RTT_50ohm (17)
162#define PHY_DDR3_RON_RTT_45ohm (18)
163#define PHY_DDR3_RON_RTT_41ohm (19)
164#define PHY_DDR3_RON_RTT_37ohm (20)
165#define PHY_DDR3_RON_RTT_34ohm (21)
166#define PHY_DDR3_RON_RTT_33ohm (22)
167#define PHY_DDR3_RON_RTT_30ohm (23)
168#define PHY_DDR3_RON_RTT_28ohm (24)
169#define PHY_DDR3_RON_RTT_26ohm (25)
170#define PHY_DDR3_RON_RTT_25ohm (26)
171#define PHY_DDR3_RON_RTT_23ohm (27)
172#define PHY_DDR3_RON_RTT_22ohm (28)
173#define PHY_DDR3_RON_RTT_21ohm (29)
174#define PHY_DDR3_RON_RTT_20ohm (30)
175#define PHY_DDR3_RON_RTT_19ohm (31)
176
177#define PHY_DDR4_LPDDR3_RON_RTT_DISABLE (0)
178#define PHY_DDR4_LPDDR3_RON_RTT_480ohm (1)
179#define PHY_DDR4_LPDDR3_RON_RTT_240ohm (2)
180#define PHY_DDR4_LPDDR3_RON_RTT_160ohm (3)
181#define PHY_DDR4_LPDDR3_RON_RTT_120ohm (4)
182#define PHY_DDR4_LPDDR3_RON_RTT_96ohm (5)
183#define PHY_DDR4_LPDDR3_RON_RTT_80ohm (6)
184#define PHY_DDR4_LPDDR3_RON_RTT_68ohm (7)
185#define PHY_DDR4_LPDDR3_RON_RTT_60ohm (16)
186#define PHY_DDR4_LPDDR3_RON_RTT_53ohm (17)
187#define PHY_DDR4_LPDDR3_RON_RTT_48ohm (18)
188#define PHY_DDR4_LPDDR3_RON_RTT_43ohm (19)
189#define PHY_DDR4_LPDDR3_RON_RTT_40ohm (20)
190#define PHY_DDR4_LPDDR3_RON_RTT_37ohm (21)
191#define PHY_DDR4_LPDDR3_RON_RTT_34ohm (22)
192#define PHY_DDR4_LPDDR3_RON_RTT_32ohm (23)
193#define PHY_DDR4_LPDDR3_RON_RTT_30ohm (24)
194#define PHY_DDR4_LPDDR3_RON_RTT_28ohm (25)
195#define PHY_DDR4_LPDDR3_RON_RTT_26ohm (26)
196#define PHY_DDR4_LPDDR3_RON_RTT_25ohm (27)
197#define PHY_DDR4_LPDDR3_RON_RTT_24ohm (28)
198#define PHY_DDR4_LPDDR3_RON_RTT_22ohm (29)
199#define PHY_DDR4_LPDDR3_RON_RTT_21ohm (30)
200#define PHY_DDR4_LPDDR3_RON_RTT_20ohm (31)
201
202/* noc registers define */
203#define DDRCONF 0x8
204#define DDRTIMING 0xc
205#define DDRMODE 0x10
206#define READLATENCY 0x14
207#define AGING0 0x18
208#define AGING1 0x1c
209#define AGING2 0x20
210#define AGING3 0x24
211#define AGING4 0x28
212#define AGING5 0x2c
213#define ACTIVATE 0x38
214#define DEVTODEV 0x3c
215#define DDR4TIMING 0x40
216
217/* DDR GRF */
218#define DDR_GRF_CON(n) (0 + (n) * 4)
219#define DDR_GRF_STATUS_BASE (0X100)
220#define DDR_GRF_STATUS(n) (DDR_GRF_STATUS_BASE + (n) * 4)
221
222/* CRU_SOFTRESET_CON5 */
223#define ddrphy_psrstn_req(n) (((0x1 << 15) << 16) | (n << 15))
224#define ddrphy_srstn_req(n) (((0x1 << 14) << 16) | (n << 14))
225#define ddrctrl_psrstn_req(n) (((0x1 << 13) << 16) | (n << 13))
226#define ddrctrl_srstn_req(n) (((0x1 << 12) << 16) | (n << 12))
227#define ddrmsch_srstn_req(n) (((0x1 << 11) << 16) | (n << 11))
228#define msch_srstn_req(n) (((0x1 << 9) << 16) | (n << 9))
229#define dfimon_srstn_req(n) (((0x1 << 8) << 16) | (n << 8))
230#define grf_ddr_srstn_req(n) (((0x1 << 7) << 16) | (n << 7))
231/* CRU_SOFTRESET_CON9 */
232#define ddrctrl_asrstn_req(n) (((0x1 << 9) << 16) | (n << 9))
233
234/* CRU register */
235#define CRU_PLL_CON(pll_id, n) ((pll_id) * 0x20 + (n) * 4)
236#define CRU_MODE (0x80)
237#define CRU_GLB_CNT_TH (0x90)
238#define CRU_CLKSEL_CON_BASE 0x100
239#define CRU_CLKSELS_CON(i) (CRU_CLKSEL_CON_BASE + ((i) * 4))
240#define CRU_CLKGATE_CON_BASE 0x200
241#define CRU_CLKGATE_CON(i) (CRU_CLKGATE_CON_BASE + ((i) * 4))
242#define CRU_CLKSFTRST_CON_BASE 0x300
243#define CRU_CLKSFTRST_CON(i) (CRU_CLKSFTRST_CON_BASE + ((i) * 4))
244
245/* CRU_PLL_CON0 */
246#define PB(n) ((0x1 << (15 + 16)) | ((n) << 15))
247#define POSTDIV1(n) ((0x7 << (12 + 16)) | ((n) << 12))
248#define FBDIV(n) ((0xFFF << 16) | (n))
249
250/* CRU_PLL_CON1 */
251#define RSTMODE(n) ((0x1 << (15 + 16)) | ((n) << 15))
252#define RST(n) ((0x1 << (14 + 16)) | ((n) << 14))
253#define PD(n) ((0x1 << (13 + 16)) | ((n) << 13))
254#define DSMPD(n) ((0x1 << (12 + 16)) | ((n) << 12))
255#define LOCK(n) (((n) >> 10) & 0x1)
256#define POSTDIV2(n) ((0x7 << (6 + 16)) | ((n) << 6))
257#define REFDIV(n) ((0x3F << 16) | (n))
258
259union noc_ddrtiming {
260 u32 d32;
261 struct {
262 unsigned acttoact:6;
263 unsigned rdtomiss:6;
264 unsigned wrtomiss:6;
265 unsigned burstlen:3;
266 unsigned rdtowr:5;
267 unsigned wrtord:5;
268 unsigned bwratio:1;
269 } b;
270} NOC_TIMING_T;
271
272union noc_activate {
273 u32 d32;
274 struct {
275 unsigned rrd:4;
276 unsigned faw:6;
277 unsigned fawbank:1;
278 unsigned reserved1:21;
279 } b;
280};
281
282union noc_devtodev {
283 u32 d32;
284 struct {
285 unsigned busrdtord:2;
286 unsigned busrdtowr:2;
287 unsigned buswrtord:2;
288 unsigned reserved2:26;
289 } b;
290};
291
292union noc_ddr4timing {
293 u32 d32;
294 struct {
295 unsigned ccdl:3;
296 unsigned wrtordl:5;
297 unsigned rrdl:4;
298 unsigned reserved2:20;
299 } b;
300};
301
302union noc_ddrmode {
303 u32 d32;
304 struct {
305 unsigned autoprecharge:1;
306 unsigned bwratioextended:1;
307 unsigned reserved3:30;
308 } b;
309};
310
311u32 addrmap[21][9] = {
312 /* map0 map1 map2 map3 map4 map5 map6 map7 map8 */
313 {22, 0x00070707, 0x00000000, 0x1f000000, 0x00001f1f, 0x06060606,
314 0x06060606, 0x00000f0f, 0x3f3f},
315 {23, 0x00080808, 0x00000000, 0x00000000, 0x00001f1f, 0x07070707,
316 0x07070707, 0x00000f0f, 0x3f3f},
317 {23, 0x00090909, 0x00000000, 0x00000000, 0x00001f00, 0x08080808,
318 0x0f080808, 0x00000f0f, 0x3f3f},
319 {24, 0x00090909, 0x00000000, 0x00000000, 0x00001f00, 0x08080808,
320 0x08080808, 0x00000f0f, 0x3f3f},
321 {24, 0x000a0a0a, 0x00000000, 0x00000000, 0x00000000, 0x09090909,
322 0x0f090909, 0x00000f0f, 0x3f3f},
323 {6, 0x00070707, 0x00000000, 0x1f000000, 0x00001f1f, 0x07070707,
324 0x07070707, 0x00000f0f, 0x3f3f},
325 {7, 0x00080808, 0x00000000, 0x00000000, 0x00001f1f, 0x08080808,
326 0x08080808, 0x00000f0f, 0x3f3f},
327 {8, 0x00090909, 0x00000000, 0x00000000, 0x00001f00, 0x09090909,
328 0x0f090909, 0x00000f0f, 0x3f3f},
329 {22, 0x001f0808, 0x00000000, 0x00000000, 0x00001f1f, 0x06060606,
330 0x06060606, 0x00000f0f, 0x3f3f},
331 {23, 0x00080808, 0x00000000, 0x00000000, 0x00001f1f, 0x07070707,
332 0x0f070707, 0x00000f0f, 0x3f3f},
333
334 {24, 0x003f0a0a, 0x01010100, 0x01010101, 0x00001f1f, 0x08080808,
335 0x08080808, 0x00000f0f, 0x0801},
336 {23, 0x003f0a0a, 0x01010100, 0x01010101, 0x00001f1f, 0x08080808,
337 0x0f080808, 0x00000f0f, 0x0801},
338 {24, 0x003f0909, 0x00000007, 0x1f000000, 0x00001f1f, 0x07070707,
339 0x07070707, 0x00000f07, 0x0700},
340 {23, 0x003f0909, 0x00000007, 0x1f000000, 0x00001f1f, 0x07070707,
341 0x07070707, 0x00000f0f, 0x0700},
342 {24, 0x003f0909, 0x01010100, 0x01010101, 0x00001f1f, 0x07070707,
343 0x07070707, 0x00000f07, 0x3f01},
344 {23, 0x003f0909, 0x01010100, 0x01010101, 0x00001f1f, 0x07070707,
345 0x07070707, 0x00000f0f, 0x3f01},
346 {24, 0x003f0808, 0x00000007, 0x1f000000, 0x00001f1f, 0x06060606,
347 0x06060606, 0x00000f06, 0x3f00},
348 {8, 0x003f0a0a, 0x01010100, 0x01010101, 0x00001f1f, 0x09090909,
349 0x0f090909, 0x00000f0f, 0x0801},
350 {7, 0x003f0909, 0x00000007, 0x1f000000, 0x00001f1f, 0x08080808,
351 0x08080808, 0x00000f0f, 0x0700},
352 {7, 0x003f0909, 0x01010100, 0x01010101, 0x00001f1f, 0x08080808,
353 0x08080808, 0x00000f0f, 0x3f01},
354
355 {6, 0x003f0808, 0x00000007, 0x1f000000, 0x00001f1f, 0x07070707,
356 0x07070707, 0x00000f07, 0x3f00}
357};
358
359struct rk3328_msch_timings {
360 union noc_ddrtiming ddrtiming;
361 union noc_ddrmode ddrmode;
362 u32 readlatency;
363 union noc_activate activate;
364 union noc_devtodev devtodev;
365 union noc_ddr4timing ddr4timing;
366 u32 agingx0;
367};
368
369struct rk3328_msch_regs {
370 u32 coreid;
371 u32 revisionid;
372 u32 ddrconf;
373 u32 ddrtiming;
374 u32 ddrmode;
375 u32 readlatency;
376 u32 aging0;
377 u32 aging1;
378 u32 aging2;
379 u32 aging3;
380 u32 aging4;
381 u32 aging5;
382 u32 reserved[2];
383 u32 activate;
384 u32 devtodev;
385 u32 ddr4_timing;
386};
387
388struct rk3328_ddr_grf_regs {
389 u32 ddr_grf_con[4];
390 u32 reserved[(0x100 - 0x10) / 4];
391 u32 ddr_grf_status[11];
392};
393
394struct rk3328_ddr_pctl_regs {
395 u32 pctl[30][2];
396};
397
398struct rk3328_ddr_phy_regs {
399 u32 phy[5][2];
400};
401
402struct rk3328_ddr_skew {
403 u32 a0_a1_skew[15];
404 u32 cs0_dm0_skew[11];
405 u32 cs0_dm1_skew[11];
406 u32 cs0_dm2_skew[11];
407 u32 cs0_dm3_skew[11];
408 u32 cs1_dm0_skew[11];
409 u32 cs1_dm1_skew[11];
410 u32 cs1_dm2_skew[11];
411 u32 cs1_dm3_skew[11];
412};
413
414struct rk3328_sdram_channel {
415 unsigned int rank;
416 unsigned int col;
417 /* 3:8bank, 2:4bank */
418 unsigned int bk;
419 /* channel buswidth, 2:32bit, 1:16bit, 0:8bit */
420 unsigned int bw;
421 /* die buswidth, 2:32bit, 1:16bit, 0:8bit */
422 unsigned int dbw;
423 unsigned int row_3_4;
424 unsigned int cs0_row;
425 unsigned int cs1_row;
426 unsigned int ddrconfig;
427 struct rk3328_msch_timings noc_timings;
428};
429
430struct rk3328_sdram_params {
431 struct rk3328_sdram_channel ch;
432 unsigned int ddr_freq;
433 unsigned int dramtype;
434 unsigned int odt;
435 struct rk3328_ddr_pctl_regs pctl_regs;
436 struct rk3328_ddr_phy_regs phy_regs;
437 struct rk3328_ddr_skew skew;
438};
439
440#define PHY_REG(base, n) (base + 4 * (n))
441
442#endif