1
2
3
4
5
6
7
8
9
10
11
12#ifndef _SUNXI_DRAM_SUN50I_H616_H
13#define _SUNXI_DRAM_SUN50I_H616_H
14
15#include <stdbool.h>
16#ifndef __ASSEMBLY__
17#include <linux/bitops.h>
18#endif
19
20enum sunxi_dram_type {
21 SUNXI_DRAM_TYPE_DDR3 = 3,
22 SUNXI_DRAM_TYPE_DDR4,
23 SUNXI_DRAM_TYPE_LPDDR3 = 7,
24 SUNXI_DRAM_TYPE_LPDDR4
25};
26
27
28struct sunxi_mctl_com_reg {
29 u32 cr;
30 u8 reserved_0x004[4];
31 u32 unk_0x008;
32 u32 tmr;
33 u8 reserved_0x010[4];
34 u32 unk_0x014;
35 u8 reserved_0x018[8];
36 u32 maer0;
37 u32 maer1;
38 u32 maer2;
39 u8 reserved_0x02c[468];
40 u32 bwcr;
41 u8 reserved_0x204[12];
42
43
44
45
46 struct {
47 u32 cfg0;
48 u32 cfg1;
49 u8 reserved_0x8[8];
50 } master[41];
51 u8 reserved_0x4a0[96];
52 u32 unk_0x500;
53};
54check_member(sunxi_mctl_com_reg, unk_0x500, 0x500);
55
56
57
58
59
60struct sunxi_mctl_ctl_reg {
61 u32 mstr;
62 u32 statr;
63 u32 mstr1;
64 u32 clken;
65 u32 mrctrl0;
66 u32 mrctrl1;
67 u32 mrstatr;
68 u32 mrctrl2;
69 u32 derateen;
70 u32 derateint;
71 u8 reserved_0x028[8];
72 u32 pwrctl;
73 u32 pwrtmg;
74 u32 hwlpctl;
75 u8 reserved_0x03c[20];
76 u32 rfshctl0;
77 u32 rfshctl1;
78 u8 reserved_0x058[8];
79 u32 rfshctl3;
80 u32 rfshtmg;
81 u8 reserved_0x068[104];
82 u32 init[8];
83 u32 dimmctl;
84 u32 rankctl;
85 u8 reserved_0x0f8[8];
86 u32 dramtmg[17];
87 u8 reserved_0x144[60];
88 u32 zqctl[3];
89 u32 zqstat;
90 u32 dfitmg0;
91 u32 dfitmg1;
92 u32 dfilpcfg[2];
93 u32 dfiupd[3];
94 u32 reserved_0x1ac;
95 u32 dfimisc;
96 u32 dfitmg2;
97 u32 dfitmg3;
98 u32 dfistat;
99 u32 dbictl;
100 u8 reserved_0x1c4[60];
101 u32 addrmap[12];
102 u8 reserved_0x230[16];
103 u32 odtcfg;
104 u32 odtmap;
105 u8 reserved_0x248[8];
106 u32 sched[2];
107 u8 reserved_0x258[180];
108 u32 dbgcmd;
109 u32 dbgstat;
110 u8 reserved_0x314[12];
111 u32 swctl;
112 u32 swstat;
113 u8 reserved_0x328[7768];
114 u32 unk_0x2180;
115 u8 reserved_0x2184[188];
116 u32 unk_0x2240;
117 u8 reserved_0x2244[3900];
118 u32 unk_0x3180;
119 u8 reserved_0x3184[188];
120 u32 unk_0x3240;
121 u8 reserved_0x3244[3900];
122 u32 unk_0x4180;
123 u8 reserved_0x4184[188];
124 u32 unk_0x4240;
125};
126check_member(sunxi_mctl_ctl_reg, swstat, 0x324);
127check_member(sunxi_mctl_ctl_reg, unk_0x4240, 0x4240);
128
129#define MSTR_DEVICETYPE_DDR3 BIT(0)
130#define MSTR_DEVICETYPE_LPDDR2 BIT(2)
131#define MSTR_DEVICETYPE_LPDDR3 BIT(3)
132#define MSTR_DEVICETYPE_DDR4 BIT(4)
133#define MSTR_DEVICETYPE_MASK GENMASK(5, 0)
134#define MSTR_2TMODE BIT(10)
135#define MSTR_BUSWIDTH_FULL (0 << 12)
136#define MSTR_BUSWIDTH_HALF (1 << 12)
137#define MSTR_ACTIVE_RANKS(x) (((x == 2) ? 3 : 1) << 24)
138#define MSTR_BURST_LENGTH(x) (((x) >> 1) << 16)
139
140#define TPR10_CA_BIT_DELAY BIT(16)
141#define TPR10_DX_BIT_DELAY0 BIT(17)
142#define TPR10_DX_BIT_DELAY1 BIT(18)
143#define TPR10_WRITE_LEVELING BIT(20)
144#define TPR10_READ_CALIBRATION BIT(21)
145#define TPR10_READ_TRAINING BIT(22)
146#define TPR10_WRITE_TRAINING BIT(23)
147
148struct dram_para {
149 u32 clk;
150 enum sunxi_dram_type type;
151 u8 cols;
152 u8 rows;
153 u8 ranks;
154 u8 bus_full_width;
155 u32 dx_odt;
156 u32 dx_dri;
157 u32 ca_dri;
158 u32 odt_en;
159 u32 tpr0;
160 u32 tpr2;
161 u32 tpr10;
162 u32 tpr11;
163 u32 tpr12;
164};
165
166
167static inline int ns_to_t(int nanoseconds)
168{
169 const unsigned int ctrl_freq = CONFIG_DRAM_CLK / 2;
170
171 return DIV_ROUND_UP(ctrl_freq * nanoseconds, 1000);
172}
173
174void mctl_set_timing_params(struct dram_para *para);
175
176#endif
177