blob: 99942e6aac23945653da556e89e3553b33ed762b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Kever Yang1a94b9e2017-09-27 16:38:22 +08002/*
3 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
Kever Yang1a94b9e2017-09-27 16:38:22 +08004 */
5#ifndef _ASM_ARCH_SDRAM_RK322X_H
6#define _ASM_ARCH_SDRAM_RK322X_H
7
Kever Yang1a94b9e2017-09-27 16:38:22 +08008struct rk322x_sdram_channel {
9 /*
10 * bit width in address, eg:
11 * 8 banks using 3 bit to address,
12 * 2 cs using 1 bit to address.
13 */
14 u8 rank;
15 u8 col;
16 u8 bk;
17 u8 bw;
18 u8 dbw;
19 u8 row_3_4;
20 u8 cs0_row;
21 u8 cs1_row;
22#if CONFIG_IS_ENABLED(OF_PLATDATA)
23 /*
24 * For of-platdata, which would otherwise convert this into two
25 * byte-swapped integers. With a size of 9 bytes, this struct will
26 * appear in of-platdata as a byte array.
27 *
28 * If OF_PLATDATA enabled, need to add a dummy byte in dts.(i.e 0xff)
29 */
30 u8 dummy;
31#endif
32};
33
34struct rk322x_ddr_pctl {
35 u32 scfg;
36 u32 sctl;
37 u32 stat;
38 u32 intrstat;
39 u32 reserved0[(0x40 - 0x10) / 4];
40 u32 mcmd;
41 u32 powctl;
42 u32 powstat;
43 u32 cmdtstat;
44 u32 cmdtstaten;
45 u32 reserved1[(0x60 - 0x54) / 4];
46 u32 mrrcfg0;
47 u32 mrrstat0;
48 u32 mrrstat1;
49 u32 reserved2[(0x7c - 0x6c) / 4];
50
51 u32 mcfg1;
52 u32 mcfg;
53 u32 ppcfg;
54 u32 mstat;
55 u32 lpddr2zqcfg;
56 u32 reserved3;
57
58 u32 dtupdes;
59 u32 dtuna;
60 u32 dtune;
61 u32 dtuprd0;
62 u32 dtuprd1;
63 u32 dtuprd2;
64 u32 dtuprd3;
65 u32 dtuawdt;
66 u32 reserved4[(0xc0 - 0xb4) / 4];
67
68 u32 togcnt1u;
69 u32 tinit;
70 u32 trsth;
71 u32 togcnt100n;
72 u32 trefi;
73 u32 tmrd;
74 u32 trfc;
75 u32 trp;
76 u32 trtw;
77 u32 tal;
78 u32 tcl;
79 u32 tcwl;
80 u32 tras;
81 u32 trc;
82 u32 trcd;
83 u32 trrd;
84 u32 trtp;
85 u32 twr;
86 u32 twtr;
87 u32 texsr;
88 u32 txp;
89 u32 txpdll;
90 u32 tzqcs;
91 u32 tzqcsi;
92 u32 tdqs;
93 u32 tcksre;
94 u32 tcksrx;
95 u32 tcke;
96 u32 tmod;
97 u32 trstl;
98 u32 tzqcl;
99 u32 tmrr;
100 u32 tckesr;
101 u32 tdpd;
102 u32 tref_mem_ddr3;
103 u32 reserved5[(0x180 - 0x14c) / 4];
104 u32 ecccfg;
105 u32 ecctst;
106 u32 eccclr;
107 u32 ecclog;
108 u32 reserved6[(0x200 - 0x190) / 4];
109 u32 dtuwactl;
110 u32 dturactl;
111 u32 dtucfg;
112 u32 dtuectl;
113 u32 dtuwd0;
114 u32 dtuwd1;
115 u32 dtuwd2;
116 u32 dtuwd3;
117 u32 dtuwdm;
118 u32 dturd0;
119 u32 dturd1;
120 u32 dturd2;
121 u32 dturd3;
122 u32 dtulfsrwd;
123 u32 dtulfsrrd;
124 u32 dtueaf;
125 /* dfi control registers */
126 u32 dfitctrldelay;
127 u32 dfiodtcfg;
128 u32 dfiodtcfg1;
129 u32 dfiodtrankmap;
130 /* dfi write data registers */
131 u32 dfitphywrdata;
132 u32 dfitphywrlat;
133 u32 reserved7[(0x260 - 0x258) / 4];
134 u32 dfitrddataen;
135 u32 dfitphyrdlat;
136 u32 reserved8[(0x270 - 0x268) / 4];
137 u32 dfitphyupdtype0;
138 u32 dfitphyupdtype1;
139 u32 dfitphyupdtype2;
140 u32 dfitphyupdtype3;
141 u32 dfitctrlupdmin;
142 u32 dfitctrlupdmax;
143 u32 dfitctrlupddly;
144 u32 reserved9;
145 u32 dfiupdcfg;
146 u32 dfitrefmski;
147 u32 dfitctrlupdi;
148 u32 reserved10[(0x2ac - 0x29c) / 4];
149 u32 dfitrcfg0;
150 u32 dfitrstat0;
151 u32 dfitrwrlvlen;
152 u32 dfitrrdlvlen;
153 u32 dfitrrdlvlgateen;
154 u32 dfiststat0;
155 u32 dfistcfg0;
156 u32 dfistcfg1;
157 u32 reserved11;
158 u32 dfitdramclken;
159 u32 dfitdramclkdis;
160 u32 dfistcfg2;
161 u32 dfistparclr;
162 u32 dfistparlog;
163 u32 reserved12[(0x2f0 - 0x2e4) / 4];
164
165 u32 dfilpcfg0;
166 u32 reserved13[(0x300 - 0x2f4) / 4];
167 u32 dfitrwrlvlresp0;
168 u32 dfitrwrlvlresp1;
169 u32 dfitrwrlvlresp2;
170 u32 dfitrrdlvlresp0;
171 u32 dfitrrdlvlresp1;
172 u32 dfitrrdlvlresp2;
173 u32 dfitrwrlvldelay0;
174 u32 dfitrwrlvldelay1;
175 u32 dfitrwrlvldelay2;
176 u32 dfitrrdlvldelay0;
177 u32 dfitrrdlvldelay1;
178 u32 dfitrrdlvldelay2;
179 u32 dfitrrdlvlgatedelay0;
180 u32 dfitrrdlvlgatedelay1;
181 u32 dfitrrdlvlgatedelay2;
182 u32 dfitrcmd;
183 u32 reserved14[(0x3f8 - 0x340) / 4];
184 u32 ipvr;
185 u32 iptr;
186};
187check_member(rk322x_ddr_pctl, iptr, 0x03fc);
188
189struct rk322x_ddr_phy {
190 u32 ddrphy_reg[0x100];
191};
192
193struct rk322x_pctl_timing {
194 u32 togcnt1u;
195 u32 tinit;
196 u32 trsth;
197 u32 togcnt100n;
198 u32 trefi;
199 u32 tmrd;
200 u32 trfc;
201 u32 trp;
202 u32 trtw;
203 u32 tal;
204 u32 tcl;
205 u32 tcwl;
206 u32 tras;
207 u32 trc;
208 u32 trcd;
209 u32 trrd;
210 u32 trtp;
211 u32 twr;
212 u32 twtr;
213 u32 texsr;
214 u32 txp;
215 u32 txpdll;
216 u32 tzqcs;
217 u32 tzqcsi;
218 u32 tdqs;
219 u32 tcksre;
220 u32 tcksrx;
221 u32 tcke;
222 u32 tmod;
223 u32 trstl;
224 u32 tzqcl;
225 u32 tmrr;
226 u32 tckesr;
227 u32 tdpd;
228 u32 trefi_mem_ddr3;
229};
230
231struct rk322x_phy_timing {
232 u32 mr[4];
233 u32 mr11;
234 u32 bl;
235 u32 cl_al;
236};
237
238struct rk322x_msch_timings {
239 u32 ddrtiming;
240 u32 ddrmode;
241 u32 readlatency;
242 u32 activate;
243 u32 devtodev;
244};
245
246struct rk322x_service_sys {
247 u32 id_coreid;
248 u32 id_revisionid;
249 u32 ddrconf;
250 u32 ddrtiming;
251 u32 ddrmode;
252 u32 readlatency;
253 u32 activate;
254 u32 devtodev;
255};
256
257struct rk322x_base_params {
258 struct rk322x_msch_timings noc_timing;
259 u32 ddrconfig;
260 u32 ddr_freq;
261 u32 dramtype;
262 /*
263 * unused for rk322x
264 */
265 u32 stride;
266 u32 odt;
267};
268
269/* PCT_DFISTCFG0 */
270#define DFI_INIT_START BIT(0)
271#define DFI_DATA_BYTE_DISABLE_EN BIT(2)
272
273/* PCT_DFISTCFG1 */
274#define DFI_DRAM_CLK_SR_EN BIT(0)
275#define DFI_DRAM_CLK_DPD_EN BIT(1)
276
277/* PCT_DFISTCFG2 */
278#define DFI_PARITY_INTR_EN BIT(0)
279#define DFI_PARITY_EN BIT(1)
280
281/* PCT_DFILPCFG0 */
282#define TLP_RESP_TIME_SHIFT 16
283#define LP_SR_EN BIT(8)
284#define LP_PD_EN BIT(0)
285
286/* PCT_DFITCTRLDELAY */
287#define TCTRL_DELAY_TIME_SHIFT 0
288
289/* PCT_DFITPHYWRDATA */
290#define TPHY_WRDATA_TIME_SHIFT 0
291
292/* PCT_DFITPHYRDLAT */
293#define TPHY_RDLAT_TIME_SHIFT 0
294
295/* PCT_DFITDRAMCLKDIS */
296#define TDRAM_CLK_DIS_TIME_SHIFT 0
297
298/* PCT_DFITDRAMCLKEN */
299#define TDRAM_CLK_EN_TIME_SHIFT 0
300
301/* PCTL_DFIODTCFG */
302#define RANK0_ODT_WRITE_SEL BIT(3)
303#define RANK1_ODT_WRITE_SEL BIT(11)
304
305/* PCTL_DFIODTCFG1 */
306#define ODT_LEN_BL8_W_SHIFT 16
307
308/* PUBL_ACDLLCR */
309#define ACDLLCR_DLLDIS BIT(31)
310#define ACDLLCR_DLLSRST BIT(30)
311
312/* PUBL_DXDLLCR */
313#define DXDLLCR_DLLDIS BIT(31)
314#define DXDLLCR_DLLSRST BIT(30)
315
316/* PUBL_DLLGCR */
317#define DLLGCR_SBIAS BIT(30)
318
319/* PUBL_DXGCR */
320#define DQSRTT BIT(9)
321#define DQRTT BIT(10)
322
323/* PIR */
324#define PIR_INIT BIT(0)
325#define PIR_DLLSRST BIT(1)
326#define PIR_DLLLOCK BIT(2)
327#define PIR_ZCAL BIT(3)
328#define PIR_ITMSRST BIT(4)
329#define PIR_DRAMRST BIT(5)
330#define PIR_DRAMINIT BIT(6)
331#define PIR_QSTRN BIT(7)
332#define PIR_RVTRN BIT(8)
333#define PIR_ICPC BIT(16)
334#define PIR_DLLBYP BIT(17)
335#define PIR_CTLDINIT BIT(18)
336#define PIR_CLRSR BIT(28)
337#define PIR_LOCKBYP BIT(29)
338#define PIR_ZCALBYP BIT(30)
339#define PIR_INITBYP BIT(31)
340
341/* PGCR */
342#define PGCR_DFTLMT_SHIFT 3
343#define PGCR_DFTCMP_SHIFT 2
344#define PGCR_DQSCFG_SHIFT 1
345#define PGCR_ITMDMD_SHIFT 0
346
347/* PGSR */
348#define PGSR_IDONE BIT(0)
349#define PGSR_DLDONE BIT(1)
350#define PGSR_ZCDONE BIT(2)
351#define PGSR_DIDONE BIT(3)
352#define PGSR_DTDONE BIT(4)
353#define PGSR_DTERR BIT(5)
354#define PGSR_DTIERR BIT(6)
355#define PGSR_DFTERR BIT(7)
356#define PGSR_RVERR BIT(8)
357#define PGSR_RVEIRR BIT(9)
358
359/* PTR0 */
360#define PRT_ITMSRST_SHIFT 18
361#define PRT_DLLLOCK_SHIFT 6
362#define PRT_DLLSRST_SHIFT 0
363
364/* PTR1 */
365#define PRT_DINIT0_SHIFT 0
366#define PRT_DINIT1_SHIFT 19
367
368/* PTR2 */
369#define PRT_DINIT2_SHIFT 0
370#define PRT_DINIT3_SHIFT 17
371
372/* DCR */
373#define DDRMD_LPDDR 0
374#define DDRMD_DDR 1
375#define DDRMD_DDR2 2
376#define DDRMD_DDR3 3
377#define DDRMD_LPDDR2_LPDDR3 4
378#define DDRMD_MASK 7
379#define DDRMD_SHIFT 0
380#define PDQ_MASK 7
381#define PDQ_SHIFT 4
382
383/* DXCCR */
384#define DQSNRES_MASK 0xf
385#define DQSNRES_SHIFT 8
386#define DQSRES_MASK 0xf
387#define DQSRES_SHIFT 4
388
389/* DTPR */
390#define TDQSCKMAX_SHIFT 27
391#define TDQSCKMAX_MASK 7
392#define TDQSCK_SHIFT 24
393#define TDQSCK_MASK 7
394
395/* DSGCR */
396#define DQSGX_SHIFT 5
397#define DQSGX_MASK 7
398#define DQSGE_SHIFT 8
399#define DQSGE_MASK 7
400
401/* SCTL */
402#define INIT_STATE 0
403#define CFG_STATE 1
404#define GO_STATE 2
405#define SLEEP_STATE 3
406#define WAKEUP_STATE 4
407
408/* STAT */
409#define LP_TRIG_SHIFT 4
410#define LP_TRIG_MASK 7
411#define PCTL_STAT_MASK 7
412#define INIT_MEM 0
413#define CONFIG 1
414#define CONFIG_REQ 2
415#define ACCESS 3
416#define ACCESS_REQ 4
417#define LOW_POWER 5
418#define LOW_POWER_ENTRY_REQ 6
419#define LOW_POWER_EXIT_REQ 7
420
421/* ZQCR*/
422#define PD_OUTPUT_SHIFT 0
423#define PU_OUTPUT_SHIFT 5
424#define PD_ONDIE_SHIFT 10
425#define PU_ONDIE_SHIFT 15
426#define ZDEN_SHIFT 28
427
428/* DDLGCR */
429#define SBIAS_BYPASS BIT(23)
430
431/* MCFG */
432#define MDDR_LPDDR2_CLK_STOP_IDLE_SHIFT 24
433#define PD_IDLE_SHIFT 8
434#define MDDR_EN (2 << 22)
435#define LPDDR2_EN (3 << 22)
436#define LPDDR3_EN (1 << 22)
437#define DDR2_EN (0 << 5)
438#define DDR3_EN (1 << 5)
439#define LPDDR2_S2 (0 << 6)
440#define LPDDR2_S4 (1 << 6)
441#define MDDR_LPDDR2_BL_2 (0 << 20)
442#define MDDR_LPDDR2_BL_4 (1 << 20)
443#define MDDR_LPDDR2_BL_8 (2 << 20)
444#define MDDR_LPDDR2_BL_16 (3 << 20)
445#define DDR2_DDR3_BL_4 0
446#define DDR2_DDR3_BL_8 1
447#define TFAW_SHIFT 18
448#define PD_EXIT_SLOW (0 << 17)
449#define PD_EXIT_FAST (1 << 17)
450#define PD_TYPE_SHIFT 16
451#define BURSTLENGTH_SHIFT 20
452
453/* POWCTL */
454#define POWER_UP_START BIT(0)
455
456/* POWSTAT */
457#define POWER_UP_DONE BIT(0)
458
459/* MCMD */
460enum {
461 DESELECT_CMD = 0,
462 PREA_CMD,
463 REF_CMD,
464 MRS_CMD,
465 ZQCS_CMD,
466 ZQCL_CMD,
467 RSTL_CMD,
468 MRR_CMD = 8,
469 DPDE_CMD,
470};
471
472#define BANK_ADDR_MASK 7
473#define BANK_ADDR_SHIFT 17
474#define CMD_ADDR_MASK 0x1fff
475#define CMD_ADDR_SHIFT 4
476
477#define LPDDR23_MA_SHIFT 4
478#define LPDDR23_MA_MASK 0xff
479#define LPDDR23_OP_SHIFT 12
480#define LPDDR23_OP_MASK 0xff
481
482#define START_CMD (1u << 31)
483
484/* DDRPHY REG */
485enum {
486 /* DDRPHY_REG0 */
487 SOFT_RESET_MASK = 3,
488 SOFT_DERESET_ANALOG = 1 << 2,
489 SOFT_DERESET_DIGITAL = 1 << 3,
490 SOFT_RESET_SHIFT = 2,
491
492 /* DDRPHY REG1 */
493 PHY_DDR3 = 0,
494 PHY_DDR2 = 1,
495 PHY_LPDDR3 = 2,
496 PHY_LPDDR2 = 3,
497
498 PHT_BL_8 = 1 << 2,
499 PHY_BL_4 = 0 << 2,
500
501 /* DDRPHY_REG2 */
502 MEMORY_SELECT_DDR3 = 0 << 0,
503 MEMORY_SELECT_LPDDR3 = 2 << 0,
504 MEMORY_SELECT_LPDDR2 = 3 << 0,
505 DQS_SQU_CAL_SEL_CS0_CS1 = 0 << 4,
506 DQS_SQU_CAL_SEL_CS1 = 1 << 4,
507 DQS_SQU_CAL_SEL_CS0 = 2 << 4,
508 DQS_SQU_CAL_NORMAL_MODE = 0 << 1,
509 DQS_SQU_CAL_BYPASS_MODE = 1 << 1,
510 DQS_SQU_CAL_START = 1 << 0,
511 DQS_SQU_NO_CAL = 0 << 0,
512};
513
514/* CK pull up/down driver strength control */
515enum {
516 PHY_RON_RTT_DISABLE = 0,
517 PHY_RON_RTT_451OHM = 1,
518 PHY_RON_RTT_225OHM,
519 PHY_RON_RTT_150OHM,
520 PHY_RON_RTT_112OHM,
521 PHY_RON_RTT_90OHM,
522 PHY_RON_RTT_75OHM,
523 PHY_RON_RTT_64OHM = 7,
524
525 PHY_RON_RTT_56OHM = 16,
526 PHY_RON_RTT_50OHM,
527 PHY_RON_RTT_45OHM,
528 PHY_RON_RTT_41OHM,
529 PHY_RON_RTT_37OHM,
530 PHY_RON_RTT_34OHM,
531 PHY_RON_RTT_33OHM,
532 PHY_RON_RTT_30OHM = 23,
533
534 PHY_RON_RTT_28OHM = 24,
535 PHY_RON_RTT_26OHM,
536 PHY_RON_RTT_25OHM,
537 PHY_RON_RTT_23OHM,
538 PHY_RON_RTT_22OHM,
539 PHY_RON_RTT_21OHM,
540 PHY_RON_RTT_20OHM,
541 PHY_RON_RTT_19OHM = 31,
542};
543
544/* DQS squelch DLL delay */
545enum {
546 DQS_DLL_NO_DELAY = 0,
547 DQS_DLL_22P5_DELAY,
548 DQS_DLL_45_DELAY,
549 DQS_DLL_67P5_DELAY,
550 DQS_DLL_90_DELAY,
551 DQS_DLL_112P5_DELAY,
552 DQS_DLL_135_DELAY,
553 DQS_DLL_157P5_DELAY,
554};
555
556/* GRF_SOC_CON0 */
557#define GRF_DDR_16BIT_EN (((0x1 << 0) << 16) | (0x1 << 0))
558#define GRF_DDR_32BIT_EN (((0x1 << 0) << 16) | (0x0 << 0))
559#define GRF_MSCH_NOC_16BIT_EN (((0x1 << 7) << 16) | (0x1 << 7))
560#define GRF_MSCH_NOC_32BIT_EN (((0x1 << 7) << 16) | (0x0 << 7))
561
562#define GRF_DDRPHY_BUFFEREN_CORE_EN (((0x1 << 8) << 16) | (0x0 << 8))
563#define GRF_DDRPHY_BUFFEREN_CORE_DIS (((0x1 << 8) << 16) | (0x1 << 8))
564
565#define GRF_DDR3_EN (((0x1 << 6) << 16) | (0x1 << 6))
566#define GRF_LPDDR2_3_EN (((0x1 << 6) << 16) | (0x0 << 6))
567
568#define PHY_DRV_ODT_SET(n) (((n) << 4) | (n))
569#define DDR3_DLL_RESET (1 << 8)
570
571#endif /* _ASM_ARCH_SDRAM_RK322X_H */