blob: adac14f946464274fb163df81340e7d98f0bc329 [file] [log] [blame]
Lokesh Vutlac49bffb2018-11-02 19:51:02 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Texas Instruments' AM654 DDRSS driver
4 *
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 */
8
9#include <common.h>
10#include <clk.h>
11#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Lokesh Vutlac49bffb2018-11-02 19:51:02 +053013#include <ram.h>
14#include <asm/io.h>
15#include <power-domain.h>
Lokesh Vutlac49bffb2018-11-02 19:51:02 +053016#include <asm/arch/sys_proto.h>
Simon Glass9bc15642020-02-03 07:36:16 -070017#include <dm/device_compat.h>
Lokesh Vutlac49bffb2018-11-02 19:51:02 +053018#include <power/regulator.h>
19#include "k3-am654-ddrss.h"
20
Andrew Davis9c6e7552023-04-06 11:38:19 -050021void sdelay(unsigned long loops);
22u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
23 u32 bound);
24
Lokesh Vutlac49bffb2018-11-02 19:51:02 +053025#define LDELAY 10000
26
27/* DDRSS PHY configuration register fixed values */
28#define DDRSS_DDRPHY_RANKIDR_RANK0 0
29
30/**
31 * struct am654_ddrss_desc - Description of ddrss integration.
32 * @dev: DDRSS device pointer
33 * @ddrss_ss_cfg: DDRSS wrapper logic region base address
34 * @ddrss_ctl_cfg: DDRSS controller region base address
35 * @ddrss_phy_cfg: DDRSS PHY region base address
36 * @ddrss_clk: DDRSS clock description
37 * @vtt_supply: VTT Supply regulator
38 * @ddrss_pwrdmn: DDRSS power domain description
39 * @params: SDRAM configuration parameters
40 */
41struct am654_ddrss_desc {
42 struct udevice *dev;
43 void __iomem *ddrss_ss_cfg;
44 void __iomem *ddrss_ctl_cfg;
45 void __iomem *ddrss_phy_cfg;
46 struct clk ddrss_clk;
47 struct udevice *vtt_supply;
48 struct power_domain ddrcfg_pwrdmn;
49 struct power_domain ddrdata_pwrdmn;
50 struct ddrss_params params;
51};
52
53static inline u32 ddrss_readl(void __iomem *addr, unsigned int offset)
54{
55 return readl(addr + offset);
56}
57
58static inline void ddrss_writel(void __iomem *addr, unsigned int offset,
59 u32 data)
60{
61 debug("%s: addr = 0x%p, value = 0x%x\n", __func__, addr + offset, data);
62 writel(data, addr + offset);
63}
64
65#define ddrss_ctl_writel(off, val) ddrss_writel(ddrss->ddrss_ctl_cfg, off, val)
66#define ddrss_ctl_readl(off) ddrss_readl(ddrss->ddrss_ctl_cfg, off)
67
68static inline u32 am654_ddrss_get_type(struct am654_ddrss_desc *ddrss)
69{
70 return ddrss_ctl_readl(DDRSS_DDRCTL_MSTR) & MSTR_DDR_TYPE_MASK;
71}
72
73/**
74 * am654_ddrss_dram_wait_for_init_complete() - Wait for init to complete
75 *
76 * After detecting the DDR type this function will pause until the
77 * initialization is complete. Each DDR type has mask of multiple bits.
78 * The size of the field depends on the DDR Type. If the initialization
79 * does not complete and error will be returned and will cause the boot to halt.
80 *
81 */
82static int am654_ddrss_dram_wait_for_init_complt(struct am654_ddrss_desc *ddrss)
83{
84 u32 val, mask;
85
86 val = am654_ddrss_get_type(ddrss);
87
88 switch (val) {
89 case DDR_TYPE_LPDDR4:
90 case DDR_TYPE_DDR4:
91 mask = DDR4_STAT_MODE_MASK;
92 break;
93 case DDR_TYPE_DDR3:
94 mask = DDR3_STAT_MODE_MASK;
95 break;
96 default:
97 printf("Unsupported DDR type 0x%x\n", val);
98 return -EINVAL;
99 }
100
101 if (!wait_on_value(mask, DDR_MODE_NORMAL,
102 ddrss->ddrss_ctl_cfg + DDRSS_DDRCTL_STAT, LDELAY))
103 return -ETIMEDOUT;
104
105 return 0;
106}
107
108/**
109 * am654_ddrss_ctrl_configuration() - Configure Controller specific registers
110 * @dev: corresponding ddrss device
111 */
112static void am654_ddrss_ctrl_configuration(struct am654_ddrss_desc *ddrss)
113{
114 struct ddrss_ddrctl_timing_params *tmg = &ddrss->params.ctl_timing;
115 struct ddrss_ddrctl_reg_params *reg = &ddrss->params.ctl_reg;
116 struct ddrss_ddrctl_ecc_params *ecc = &ddrss->params.ctl_ecc;
117 struct ddrss_ddrctl_crc_params *crc = &ddrss->params.ctl_crc;
118 struct ddrss_ddrctl_map_params *map = &ddrss->params.ctl_map;
119 u32 val;
120
121 debug("%s: DDR controller register configuration started\n", __func__);
122
123 ddrss_ctl_writel(DDRSS_DDRCTL_MSTR, reg->ddrctl_mstr);
124 ddrss_ctl_writel(DDRSS_DDRCTL_RFSHCTL0, reg->ddrctl_rfshctl0);
125 ddrss_ctl_writel(DDRSS_DDRCTL_RFSHTMG, reg->ddrctl_rfshtmg);
126
127 ddrss_ctl_writel(DDRSS_DDRCTL_ECCCFG0, ecc->ddrctl_ecccfg0);
128 ddrss_ctl_writel(DDRSS_DDRCTL_CRCPARCTL0, crc->ddrctl_crcparctl0);
129 ddrss_ctl_writel(DDRSS_DDRCTL_CRCPARCTL1, crc->ddrctl_crcparctl1);
130 ddrss_ctl_writel(DDRSS_DDRCTL_CRCPARCTL2, crc->ddrctl_crcparctl2);
131
132 ddrss_ctl_writel(DDRSS_DDRCTL_INIT0, reg->ddrctl_init0);
133 ddrss_ctl_writel(DDRSS_DDRCTL_INIT1, reg->ddrctl_init1);
134 ddrss_ctl_writel(DDRSS_DDRCTL_INIT3, reg->ddrctl_init3);
135 ddrss_ctl_writel(DDRSS_DDRCTL_INIT4, reg->ddrctl_init4);
136 ddrss_ctl_writel(DDRSS_DDRCTL_INIT5, reg->ddrctl_init5);
137 ddrss_ctl_writel(DDRSS_DDRCTL_INIT6, reg->ddrctl_init6);
138 ddrss_ctl_writel(DDRSS_DDRCTL_INIT7, reg->ddrctl_init7);
139
140 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG0, tmg->ddrctl_dramtmg0);
141 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG1, tmg->ddrctl_dramtmg1);
142 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG2, tmg->ddrctl_dramtmg2);
143 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG3, tmg->ddrctl_dramtmg3);
144 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG4, tmg->ddrctl_dramtmg4);
145 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG5, tmg->ddrctl_dramtmg5);
146 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG8, tmg->ddrctl_dramtmg8);
147 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG9, tmg->ddrctl_dramtmg9);
148 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG11, tmg->ddrctl_dramtmg11);
149 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG12, tmg->ddrctl_dramtmg12);
150 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG13, tmg->ddrctl_dramtmg13);
James Doublesinb6a19f02019-10-07 14:04:26 +0530151 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG14, tmg->ddrctl_dramtmg14);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530152 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG15, tmg->ddrctl_dramtmg15);
153 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG17, tmg->ddrctl_dramtmg17);
154
155 ddrss_ctl_writel(DDRSS_DDRCTL_ZQCTL0, reg->ddrctl_zqctl0);
156 ddrss_ctl_writel(DDRSS_DDRCTL_ZQCTL1, reg->ddrctl_zqctl1);
157
158 ddrss_ctl_writel(DDRSS_DDRCTL_DFITMG0, reg->ddrctl_dfitmg0);
159 ddrss_ctl_writel(DDRSS_DDRCTL_DFITMG1, reg->ddrctl_dfitmg1);
160 ddrss_ctl_writel(DDRSS_DDRCTL_DFITMG2, reg->ddrctl_dfitmg2);
James Doublesinb6a19f02019-10-07 14:04:26 +0530161 ddrss_ctl_writel(DDRSS_DDRCTL_DFIMISC, reg->ddrctl_dfimisc);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530162
163 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP0, map->ddrctl_addrmap0);
164 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP1, map->ddrctl_addrmap1);
165 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP2, map->ddrctl_addrmap2);
166 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP3, map->ddrctl_addrmap3);
167 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP4, map->ddrctl_addrmap4);
168 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP5, map->ddrctl_addrmap5);
169 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP6, map->ddrctl_addrmap6);
170 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP7, map->ddrctl_addrmap7);
171 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP8, map->ddrctl_addrmap8);
172 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP9, map->ddrctl_addrmap9);
173 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP10, map->ddrctl_addrmap10);
174 ddrss_ctl_writel(DDRSS_DDRCTL_ADDRMAP11, map->ddrctl_addrmap11);
175
176 ddrss_ctl_writel(DDRSS_DDRCTL_ODTCFG, reg->ddrctl_odtcfg);
177 ddrss_ctl_writel(DDRSS_DDRCTL_ODTMAP, reg->ddrctl_odtmap);
178
179 /* Disable refreshes */
180 val = ddrss_ctl_readl(DDRSS_DDRCTL_RFSHCTL3);
181 val |= 0x01;
182 ddrss_ctl_writel(DDRSS_DDRCTL_RFSHCTL3, val);
183
184 debug("%s: DDR controller configuration completed\n", __func__);
185}
186
187#define ddrss_phy_writel(off, val) \
188 do { \
189 ddrss_writel(ddrss->ddrss_phy_cfg, off, val); \
190 sdelay(10); /* Delay at least 20 clock cycles */ \
191 } while (0)
192
193#define ddrss_phy_readl(off) \
194 ({ \
195 u32 val = ddrss_readl(ddrss->ddrss_phy_cfg, off); \
196 sdelay(10); /* Delay at least 20 clock cycles */ \
197 val; \
198 })
199
200/**
201 * am654_ddrss_phy_configuration() - Configure PHY specific registers
202 * @ddrss: corresponding ddrss device
203 */
204static void am654_ddrss_phy_configuration(struct am654_ddrss_desc *ddrss)
205{
206 struct ddrss_ddrphy_ioctl_params *ioctl = &ddrss->params.phy_ioctl;
207 struct ddrss_ddrphy_timing_params *tmg = &ddrss->params.phy_timing;
208 struct ddrss_ddrphy_ctrl_params *ctrl = &ddrss->params.phy_ctrl;
209 struct ddrss_ddrphy_cfg_params *cfg = &ddrss->params.phy_cfg;
210 struct ddrss_ddrphy_zq_params *zq = &ddrss->params.phy_zq;
211
212 debug("%s: DDR phy register configuration started\n", __func__);
213
James Doublesinb6a19f02019-10-07 14:04:26 +0530214 ddrss_phy_writel(DDRSS_DDRPHY_PGCR0, cfg->ddrphy_pgcr0);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530215 ddrss_phy_writel(DDRSS_DDRPHY_PGCR1, cfg->ddrphy_pgcr1);
216 ddrss_phy_writel(DDRSS_DDRPHY_PGCR2, cfg->ddrphy_pgcr2);
217 ddrss_phy_writel(DDRSS_DDRPHY_PGCR3, cfg->ddrphy_pgcr3);
218 ddrss_phy_writel(DDRSS_DDRPHY_PGCR6, cfg->ddrphy_pgcr6);
219
James Doublesinb6a19f02019-10-07 14:04:26 +0530220 ddrss_phy_writel(DDRSS_DDRPHY_PTR2, tmg->ddrphy_ptr2);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530221 ddrss_phy_writel(DDRSS_DDRPHY_PTR3, tmg->ddrphy_ptr3);
222 ddrss_phy_writel(DDRSS_DDRPHY_PTR4, tmg->ddrphy_ptr4);
223 ddrss_phy_writel(DDRSS_DDRPHY_PTR5, tmg->ddrphy_ptr5);
224 ddrss_phy_writel(DDRSS_DDRPHY_PTR6, tmg->ddrphy_ptr6);
225
226 ddrss_phy_writel(DDRSS_DDRPHY_PLLCR0, ctrl->ddrphy_pllcr0);
227
228 ddrss_phy_writel(DDRSS_DDRPHY_DXCCR, cfg->ddrphy_dxccr);
229 ddrss_phy_writel(DDRSS_DDRPHY_DSGCR, cfg->ddrphy_dsgcr);
230
231 ddrss_phy_writel(DDRSS_DDRPHY_DCR, cfg->ddrphy_dcr);
232
233 ddrss_phy_writel(DDRSS_DDRPHY_DTPR0, tmg->ddrphy_dtpr0);
234 ddrss_phy_writel(DDRSS_DDRPHY_DTPR1, tmg->ddrphy_dtpr1);
235 ddrss_phy_writel(DDRSS_DDRPHY_DTPR2, tmg->ddrphy_dtpr2);
236 ddrss_phy_writel(DDRSS_DDRPHY_DTPR3, tmg->ddrphy_dtpr3);
237 ddrss_phy_writel(DDRSS_DDRPHY_DTPR4, tmg->ddrphy_dtpr4);
238 ddrss_phy_writel(DDRSS_DDRPHY_DTPR5, tmg->ddrphy_dtpr5);
239 ddrss_phy_writel(DDRSS_DDRPHY_DTPR6, tmg->ddrphy_dtpr6);
240
241 ddrss_phy_writel(DDRSS_DDRPHY_ZQCR, zq->ddrphy_zqcr);
242 ddrss_phy_writel(DDRSS_DDRPHY_ZQ0PR0, zq->ddrphy_zq0pr0);
243 ddrss_phy_writel(DDRSS_DDRPHY_ZQ1PR0, zq->ddrphy_zq1pr0);
244
245 ddrss_phy_writel(DDRSS_DDRPHY_MR0, ctrl->ddrphy_mr0);
246 ddrss_phy_writel(DDRSS_DDRPHY_MR1, ctrl->ddrphy_mr1);
247 ddrss_phy_writel(DDRSS_DDRPHY_MR2, ctrl->ddrphy_mr2);
248 ddrss_phy_writel(DDRSS_DDRPHY_MR3, ctrl->ddrphy_mr3);
249 ddrss_phy_writel(DDRSS_DDRPHY_MR4, ctrl->ddrphy_mr4);
250 ddrss_phy_writel(DDRSS_DDRPHY_MR5, ctrl->ddrphy_mr5);
251 ddrss_phy_writel(DDRSS_DDRPHY_MR6, ctrl->ddrphy_mr6);
James Doublesinb6a19f02019-10-07 14:04:26 +0530252 ddrss_phy_writel(DDRSS_DDRPHY_MR11, ctrl->ddrphy_mr11);
253 ddrss_phy_writel(DDRSS_DDRPHY_MR12, ctrl->ddrphy_mr12);
254 ddrss_phy_writel(DDRSS_DDRPHY_MR13, ctrl->ddrphy_mr13);
255 ddrss_phy_writel(DDRSS_DDRPHY_MR14, ctrl->ddrphy_mr14);
256 ddrss_phy_writel(DDRSS_DDRPHY_MR22, ctrl->ddrphy_mr22);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530257
258 ddrss_phy_writel(DDRSS_DDRPHY_VTCR0, ctrl->ddrphy_vtcr0);
259
260 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL0PLLCR0, cfg->ddrphy_dx8sl0pllcr0);
261 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL1PLLCR0, cfg->ddrphy_dx8sl1pllcr0);
262 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL2PLLCR0, cfg->ddrphy_dx8sl2pllcr0);
263
264 ddrss_phy_writel(DDRSS_DDRPHY_DTCR0, ctrl->ddrphy_dtcr0);
265 ddrss_phy_writel(DDRSS_DDRPHY_DTCR1, ctrl->ddrphy_dtcr1);
266
James Doublesin2c85dfd12019-10-07 14:04:27 +0530267 ddrss_phy_writel(DDRSS_DDRPHY_ACIOCR0, ioctl->ddrphy_aciocr0);
268 ddrss_phy_writel(DDRSS_DDRPHY_ACIOCR3, ioctl->ddrphy_aciocr3);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530269 ddrss_phy_writel(DDRSS_DDRPHY_ACIOCR5, ioctl->ddrphy_aciocr5);
270 ddrss_phy_writel(DDRSS_DDRPHY_IOVCR0, ioctl->ddrphy_iovcr0);
271
Dominic Ratha7c86a72022-03-23 16:04:27 +0100272 ddrss_phy_writel(DDRSS_DDRPHY_DX2GCR0, cfg->ddrphy_dx2gcr0);
273 ddrss_phy_writel(DDRSS_DDRPHY_DX2GCR1, cfg->ddrphy_dx2gcr1);
274 ddrss_phy_writel(DDRSS_DDRPHY_DX2GCR2, cfg->ddrphy_dx2gcr2);
275 ddrss_phy_writel(DDRSS_DDRPHY_DX2GCR3, cfg->ddrphy_dx2gcr3);
276
277 ddrss_phy_writel(DDRSS_DDRPHY_DX3GCR0, cfg->ddrphy_dx3gcr0);
278 ddrss_phy_writel(DDRSS_DDRPHY_DX3GCR1, cfg->ddrphy_dx3gcr1);
279 ddrss_phy_writel(DDRSS_DDRPHY_DX3GCR2, cfg->ddrphy_dx3gcr2);
280 ddrss_phy_writel(DDRSS_DDRPHY_DX3GCR3, cfg->ddrphy_dx3gcr3);
281
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530282 ddrss_phy_writel(DDRSS_DDRPHY_DX4GCR0, cfg->ddrphy_dx4gcr0);
283 ddrss_phy_writel(DDRSS_DDRPHY_DX4GCR1, cfg->ddrphy_dx4gcr1);
284 ddrss_phy_writel(DDRSS_DDRPHY_DX4GCR2, cfg->ddrphy_dx4gcr2);
285 ddrss_phy_writel(DDRSS_DDRPHY_DX4GCR3, cfg->ddrphy_dx4gcr3);
286
287 ddrss_phy_writel(DDRSS_DDRPHY_DX0GCR4, cfg->ddrphy_dx0gcr4);
288 ddrss_phy_writel(DDRSS_DDRPHY_DX1GCR4, cfg->ddrphy_dx1gcr4);
289 ddrss_phy_writel(DDRSS_DDRPHY_DX2GCR4, cfg->ddrphy_dx2gcr4);
290 ddrss_phy_writel(DDRSS_DDRPHY_DX3GCR4, cfg->ddrphy_dx3gcr4);
291
292 ddrss_phy_writel(DDRSS_DDRPHY_PGCR5, cfg->ddrphy_pgcr5);
293 ddrss_phy_writel(DDRSS_DDRPHY_DX0GCR5, cfg->ddrphy_dx0gcr5);
294 ddrss_phy_writel(DDRSS_DDRPHY_DX1GCR5, cfg->ddrphy_dx1gcr5);
295 ddrss_phy_writel(DDRSS_DDRPHY_DX2GCR5, cfg->ddrphy_dx2gcr5);
296 ddrss_phy_writel(DDRSS_DDRPHY_DX3GCR5, cfg->ddrphy_dx3gcr5);
297
298 ddrss_phy_writel(DDRSS_DDRPHY_RANKIDR, DDRSS_DDRPHY_RANKIDR_RANK0);
299
300 ddrss_phy_writel(DDRSS_DDRPHY_DX0GTR0, cfg->ddrphy_dx0gtr0);
301 ddrss_phy_writel(DDRSS_DDRPHY_DX1GTR0, cfg->ddrphy_dx1gtr0);
302 ddrss_phy_writel(DDRSS_DDRPHY_DX2GTR0, cfg->ddrphy_dx2gtr0);
303 ddrss_phy_writel(DDRSS_DDRPHY_DX3GTR0, cfg->ddrphy_dx3gtr0);
304 ddrss_phy_writel(DDRSS_DDRPHY_ODTCR, cfg->ddrphy_odtcr);
305
306 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL0IOCR, cfg->ddrphy_dx8sl0iocr);
307 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL1IOCR, cfg->ddrphy_dx8sl1iocr);
308 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL2IOCR, cfg->ddrphy_dx8sl2iocr);
309
310 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL0DXCTL2, cfg->ddrphy_dx8sl0dxctl2);
311 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL1DXCTL2, cfg->ddrphy_dx8sl1dxctl2);
312 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL2DXCTL2, cfg->ddrphy_dx8sl2dxctl2);
313
James Doublesin2c85dfd12019-10-07 14:04:27 +0530314 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL0DQSCTL, cfg->ddrphy_dx8sl0dqsctl);
315 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL1DQSCTL, cfg->ddrphy_dx8sl1dqsctl);
316 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL2DQSCTL, cfg->ddrphy_dx8sl2dqsctl);
317
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530318 debug("%s: DDR phy register configuration completed\n", __func__);
319}
320
321static int __phy_builtin_init_routine(struct am654_ddrss_desc *ddrss,
322 u32 init_value, u32 sts_mask,
323 u32 err_mask)
324{
325 int ret;
326
327 ddrss_phy_writel(DDRSS_DDRPHY_PIR, init_value | PIR_INIT_MASK);
328
329 sdelay(5); /* Delay at least 10 clock cycles */
330
331 if (!wait_on_value(sts_mask, sts_mask,
332 ddrss->ddrss_phy_cfg + DDRSS_DDRPHY_PGSR0, LDELAY))
333 return -ETIMEDOUT;
334
335 sdelay(16); /* Delay at least 32 clock cycles */
336
337 ret = ddrss_phy_readl(DDRSS_DDRPHY_PGSR0);
338 debug("%s: PGSR0 val = 0x%x\n", __func__, ret);
339 if (ret & err_mask)
340 return -EINVAL;
341
342 return 0;
343}
344
345int write_leveling(struct am654_ddrss_desc *ddrss)
346{
347 int ret;
348
349 debug("%s: Write leveling started\n", __func__);
350
351 ret = __phy_builtin_init_routine(ddrss, PIR_WL_MASK, PGSR0_WLDONE_MASK,
352 PGSR0_WLERR_MASK);
353 if (ret) {
354 if (ret == -ETIMEDOUT)
355 printf("%s: ERROR: Write leveling timedout\n",
356 __func__);
357 else
358 printf("%s:ERROR: Write leveling failed\n", __func__);
359 return ret;
360 }
361
362 debug("%s: Write leveling completed\n", __func__);
363 return 0;
364}
365
366int read_dqs_training(struct am654_ddrss_desc *ddrss)
367{
368 int ret;
369
370 debug("%s: Read DQS training started\n", __func__);
371
372 ret = __phy_builtin_init_routine(ddrss, PIR_QSGATE_MASK,
373 PGSR0_QSGDONE_MASK, PGSR0_QSGERR_MASK);
374 if (ret) {
375 if (ret == -ETIMEDOUT)
376 printf("%s: ERROR: Read DQS timedout\n", __func__);
377 else
378 printf("%s:ERROR: Read DQS Gate training failed\n",
379 __func__);
380 return ret;
381 }
382
383 debug("%s: Read DQS training completed\n", __func__);
384 return 0;
385}
386
James Doublesinb6a19f02019-10-07 14:04:26 +0530387int dqs2dq_training(struct am654_ddrss_desc *ddrss)
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530388{
389 int ret;
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530390
James Doublesinb6a19f02019-10-07 14:04:26 +0530391 debug("%s: DQS2DQ training started\n", __func__);
392
393 ret = __phy_builtin_init_routine(ddrss, PIR_DQS2DQ_MASK,
394 PGSR0_DQS2DQDONE_MASK,
395 PGSR0_DQS2DQERR_MASK);
396 if (ret) {
397 if (ret == -ETIMEDOUT)
398 printf("%s: ERROR: DQS2DQ training timedout\n",
399 __func__);
400 else
401 printf("%s:ERROR: DQS2DQ training failed\n",
402 __func__);
403 return ret;
404 }
405
406 debug("%s: DQS2DQ training completed\n", __func__);
407 return 0;
408}
409
410int write_leveling_adjustment(struct am654_ddrss_desc *ddrss)
411{
412 int ret;
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530413
414 debug("%s: Write Leveling adjustment\n", __func__);
415 ret = __phy_builtin_init_routine(ddrss, PIR_WLADJ_MASK,
416 PGSR0_WLADONE_MASK, PGSR0_WLAERR_MASK);
417 if (ret) {
418 if (ret == -ETIMEDOUT)
419 printf("%s:ERROR: Write Leveling adjustment timedout\n",
420 __func__);
421 else
422 printf("%s: ERROR: Write Leveling adjustment failed\n",
423 __func__);
424 return ret;
425 }
James Doublesinb6a19f02019-10-07 14:04:26 +0530426 return 0;
427}
428
429int rest_training(struct am654_ddrss_desc *ddrss)
430{
431 int ret;
432
433 debug("%s: Rest of the training started\n", __func__);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530434
435 debug("%s: Read Deskew adjustment\n", __func__);
436 ret = __phy_builtin_init_routine(ddrss, PIR_RDDSKW_MASK,
437 PGSR0_RDDONE_MASK, PGSR0_RDERR_MASK);
438 if (ret) {
439 if (ret == -ETIMEDOUT)
440 printf("%s: ERROR: Read Deskew timedout\n", __func__);
441 else
442 printf("%s: ERROR: Read Deskew failed\n", __func__);
443 return ret;
444 }
445
446 debug("%s: Write Deskew adjustment\n", __func__);
447 ret = __phy_builtin_init_routine(ddrss, PIR_WRDSKW_MASK,
448 PGSR0_WDDONE_MASK, PGSR0_WDERR_MASK);
449 if (ret) {
450 if (ret == -ETIMEDOUT)
451 printf("%s: ERROR: Write Deskew timedout\n", __func__);
452 else
453 printf("%s: ERROR: Write Deskew failed\n", __func__);
454 return ret;
455 }
456
457 debug("%s: Read Eye training\n", __func__);
458 ret = __phy_builtin_init_routine(ddrss, PIR_RDEYE_MASK,
459 PGSR0_REDONE_MASK, PGSR0_REERR_MASK);
460 if (ret) {
461 if (ret == -ETIMEDOUT)
462 printf("%s: ERROR: Read Eye training timedout\n",
463 __func__);
464 else
465 printf("%s: ERROR: Read Eye training failed\n",
466 __func__);
467 return ret;
468 }
469
470 debug("%s: Write Eye training\n", __func__);
471 ret = __phy_builtin_init_routine(ddrss, PIR_WREYE_MASK,
472 PGSR0_WEDONE_MASK, PGSR0_WEERR_MASK);
473 if (ret) {
474 if (ret == -ETIMEDOUT)
475 printf("%s: ERROR: Write Eye training timedout\n",
476 __func__);
477 else
478 printf("%s: ERROR: Write Eye training failed\n",
479 __func__);
480 return ret;
481 }
James Doublesinb6a19f02019-10-07 14:04:26 +0530482 return 0;
483}
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530484
James Doublesinb6a19f02019-10-07 14:04:26 +0530485int VREF_training(struct am654_ddrss_desc *ddrss)
486{
487 int ret;
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530488 debug("%s: VREF training\n", __func__);
489 ret = __phy_builtin_init_routine(ddrss, PIR_VREF_MASK, PGSR0_VDONE_MASK,
490 PGSR0_VERR_MASK);
491 if (ret) {
492 if (ret == -ETIMEDOUT)
493 printf("%s: ERROR: VREF training timedout\n", __func__);
494 else
495 printf("%s: ERROR: VREF training failed\n", __func__);
496 return ret;
497 }
James Doublesinb6a19f02019-10-07 14:04:26 +0530498 return 0;
499}
500
501int enable_dqs_pd(struct am654_ddrss_desc *ddrss)
502{
James Doublesin2c85dfd12019-10-07 14:04:27 +0530503 u32 val;
504
505 val = ddrss_phy_readl(DDRSS_DDRPHY_DX8SL0DQSCTL);
506 val &= ~0xFF;
507 val |= 0xF7;
508 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL0DQSCTL, val);
509
510 val = ddrss_phy_readl(DDRSS_DDRPHY_DX8SL1DQSCTL);
511 val &= ~0xFF;
512 val |= 0xF7;
513 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL1DQSCTL, val);
514
515 val = ddrss_phy_readl(DDRSS_DDRPHY_DX8SL2DQSCTL);
516 val &= ~0xFF;
517 val |= 0xF7;
518 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL2DQSCTL, val);
519
James Doublesinb6a19f02019-10-07 14:04:26 +0530520 sdelay(16);
521 return 0;
522}
523
524int disable_dqs_pd(struct am654_ddrss_desc *ddrss)
525{
James Doublesin2c85dfd12019-10-07 14:04:27 +0530526 u32 val;
527
528 val = ddrss_phy_readl(DDRSS_DDRPHY_DX8SL0DQSCTL);
529 val &= ~0xFF;
530 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL0DQSCTL, val);
531
532 val = ddrss_phy_readl(DDRSS_DDRPHY_DX8SL1DQSCTL);
533 val &= ~0xFF;
534 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL1DQSCTL, val);
535
536 val = ddrss_phy_readl(DDRSS_DDRPHY_DX8SL2DQSCTL);
537 val &= ~0xFF;
538 ddrss_phy_writel(DDRSS_DDRPHY_DX8SL2DQSCTL, val);
539
James Doublesinb6a19f02019-10-07 14:04:26 +0530540 sdelay(16);
541 return 0;
542}
543
544int cleanup_training(struct am654_ddrss_desc *ddrss)
545{
546 u32 val;
547 u32 dgsl0, dgsl1, dgsl2, dgsl3, rddly, rd2wr_wr2rd;
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530548
549 ddrss_phy_writel(DDRSS_DDRPHY_RANKIDR, 0x00000000);
550 dgsl0 = (ddrss_phy_readl(DDRSS_DDRPHY_DX0GTR0) & 0x1F) >> 2;
551 dgsl1 = (ddrss_phy_readl(DDRSS_DDRPHY_DX1GTR0) & 0x1F) >> 2;
552 dgsl2 = (ddrss_phy_readl(DDRSS_DDRPHY_DX2GTR0) & 0x1F) >> 2;
553 dgsl3 = (ddrss_phy_readl(DDRSS_DDRPHY_DX3GTR0) & 0x1F) >> 2;
554
555 rddly = dgsl0;
556 if (dgsl1 < rddly)
557 rddly = dgsl1;
558 if (dgsl2 < rddly)
559 rddly = dgsl2;
560 if (dgsl3 < rddly)
561 rddly = dgsl3;
562
563 rddly += 5;
564
565 /* Update rddly based on dgsl values */
566 val = (ddrss_phy_readl(DDRSS_DDRPHY_DX0GCR0) & ~0xF00000);
567 val |= (rddly << 20);
568 ddrss_phy_writel(DDRSS_DDRPHY_DX0GCR0, val);
569
570 val = (ddrss_phy_readl(DDRSS_DDRPHY_DX1GCR0) & ~0xF00000);
571 val |= (rddly << 20);
572 ddrss_phy_writel(DDRSS_DDRPHY_DX1GCR0, val);
573
574 val = (ddrss_phy_readl(DDRSS_DDRPHY_DX2GCR0) & ~0xF00000);
575 val |= (rddly << 20);
576 ddrss_phy_writel(DDRSS_DDRPHY_DX2GCR0, val);
577
578 val = (ddrss_phy_readl(DDRSS_DDRPHY_DX3GCR0) & ~0xF00000);
579 val |= (rddly << 20);
580 ddrss_phy_writel(DDRSS_DDRPHY_DX3GCR0, val);
581
582 /*
583 * Add system latency derived from training back into rd2wr and wr2rd
584 * rd2wr = RL + BL/2 + 1 + WR_PREAMBLE - WL + max(DXnGTR0.DGSL) / 2
585 * wr2rd = CWL + PL + BL/2 + tWTR_L + max(DXnGTR0.DGSL) / 2
586 */
587
588 /* Select rank 0 */
589 ddrss_phy_writel(DDRSS_DDRPHY_RANKIDR, 0x00000000);
590
591 dgsl0 = (ddrss_phy_readl(DDRSS_DDRPHY_DX0GTR0) & 0x1F);
592 dgsl1 = (ddrss_phy_readl(DDRSS_DDRPHY_DX1GTR0) & 0x1F);
593 dgsl2 = (ddrss_phy_readl(DDRSS_DDRPHY_DX2GTR0) & 0x1F);
594 dgsl3 = (ddrss_phy_readl(DDRSS_DDRPHY_DX3GTR0) & 0x1F);
595
596 /* Find maximum value across all bytes */
597 rd2wr_wr2rd = dgsl0;
598 if (dgsl1 > rd2wr_wr2rd)
599 rd2wr_wr2rd = dgsl1;
600 if (dgsl2 > rd2wr_wr2rd)
601 rd2wr_wr2rd = dgsl2;
602 if (dgsl3 > rd2wr_wr2rd)
603 rd2wr_wr2rd = dgsl3;
604
605 rd2wr_wr2rd >>= 1;
606
607 /* Now add in adjustment to DRAMTMG2 bit fields for rd2wr and wr2rd */
608 /* Clear VSWCTL.sw_done */
609 ddrss_ctl_writel(DDRSS_DDRCTL_SWCTL,
610 ddrss_ctl_readl(DDRSS_DDRCTL_SWCTL) & ~0x1);
611 /* Adjust rd2wr */
612 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG2,
613 ddrss_ctl_readl(DDRSS_DDRCTL_DRAMTMG2) +
614 (rd2wr_wr2rd << 8));
615 /* Adjust wr2rd */
616 ddrss_ctl_writel(DDRSS_DDRCTL_DRAMTMG2,
617 ddrss_ctl_readl(DDRSS_DDRCTL_DRAMTMG2) +
618 rd2wr_wr2rd);
619 /* Set VSWCTL.sw_done */
620 ddrss_ctl_writel(DDRSS_DDRCTL_SWCTL,
621 ddrss_ctl_readl(DDRSS_DDRCTL_SWCTL) | 0x1);
622 /* Wait until settings are applied */
623 while (!(ddrss_ctl_readl(DDRSS_DDRCTL_SWSTAT) & 0x1)) {
624 /* Do nothing */
625 };
626
627 debug("%s: Rest of the training completed\n", __func__);
628 return 0;
629}
630
631/**
632 * am654_ddrss_init() - Initialization sequence for enabling the SDRAM
633 * device attached to ddrss.
634 * @dev: corresponding ddrss device
635 *
636 * Does all the initialization sequence that is required to get attached
637 * ddr in a working state. After this point, ddr should be accessible.
638 * Return: 0 if all went ok, else corresponding error message.
639 */
640static int am654_ddrss_init(struct am654_ddrss_desc *ddrss)
641{
642 int ret;
James Doublesinb6a19f02019-10-07 14:04:26 +0530643 u32 val;
James Doublesin2c85dfd12019-10-07 14:04:27 +0530644 struct ddrss_ss_reg_params *reg = &ddrss->params.ss_reg;
James Doublesinb6a19f02019-10-07 14:04:26 +0530645
646 debug("Starting DDR initialization...\n");
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530647
648 debug("%s(ddrss=%p)\n", __func__, ddrss);
649
James Doublesin2c85dfd12019-10-07 14:04:27 +0530650 ddrss_writel(ddrss->ddrss_ss_cfg, DDRSS_V2H_CTL_REG,
651 reg->ddrss_v2h_ctl_reg);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530652
653 am654_ddrss_ctrl_configuration(ddrss);
654
655 /* Release the reset to the controller */
656 clrbits_le32(ddrss->ddrss_ss_cfg + DDRSS_SS_CTL_REG,
657 SS_CTL_REG_CTL_ARST_MASK);
658
659 am654_ddrss_phy_configuration(ddrss);
660
James Doublesinb6a19f02019-10-07 14:04:26 +0530661 debug("Starting DDR training...\n");
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530662 ret = __phy_builtin_init_routine(ddrss, PIR_PHY_INIT, 0x1, 0);
663 if (ret) {
664 dev_err(ddrss->dev, "PHY initialization failed %d\n", ret);
665 return ret;
666 }
667
668 ret = __phy_builtin_init_routine(ddrss, PIR_DRAM_INIT,
669 PGSR0_DRAM_INIT_MASK, 0);
670 if (ret) {
671 dev_err(ddrss->dev, "DRAM initialization failed %d\n", ret);
672 return ret;
673 }
674
675 ret = am654_ddrss_dram_wait_for_init_complt(ddrss);
676 if (ret) {
677 printf("%s: ERROR: DRAM Wait for init complete timedout\n",
678 __func__);
679 return ret;
680 }
681
James Doublesinb6a19f02019-10-07 14:04:26 +0530682 val = am654_ddrss_get_type(ddrss);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530683
James Doublesinb6a19f02019-10-07 14:04:26 +0530684 switch (val) {
685 case DDR_TYPE_LPDDR4:
686
687 ret = __phy_builtin_init_routine(ddrss, PIR_DRAM_INIT,
688 PGSR0_DRAM_INIT_MASK, 0);
689 if (ret) {
690 dev_err(ddrss->dev, "DRAM initialization failed %d\n",
691 ret);
692 return ret;
693 }
694
695 /* must perform DRAM_INIT twice for LPDDR4 */
696 ret = __phy_builtin_init_routine(ddrss, PIR_DRAM_INIT,
697 PGSR0_DRAM_INIT_MASK, 0);
698 if (ret) {
699 dev_err(ddrss->dev, "DRAM initialization failed %d\n",
700 ret);
701 return ret;
702 }
703
704 ret = am654_ddrss_dram_wait_for_init_complt(ddrss);
705 if (ret) {
706 printf("%s: ERROR: DRAM Wait for init complete timedout\n",
707 __func__);
708 return ret;
709 }
710
711 ret = write_leveling(ddrss);
712 if (ret)
713 return ret;
714
715 ret = enable_dqs_pd(ddrss);
716 if (ret)
717 return ret;
718
719 ret = read_dqs_training(ddrss);
720 if (ret)
721 return ret;
722
723 ret = disable_dqs_pd(ddrss);
724 if (ret)
725 return ret;
726
727 ret = dqs2dq_training(ddrss);
728 if (ret)
729 return ret;
730
731 ret = write_leveling_adjustment(ddrss);
732 if (ret)
733 return ret;
734
735 ret = rest_training(ddrss);
736 if (ret)
737 return ret;
738
739 ret = VREF_training(ddrss);
740 if (ret)
741 return ret;
742
743 debug("LPDDR4 training complete\n");
744 break;
745
746 case DDR_TYPE_DDR4:
747
748 debug("Starting DDR4 training\n");
749
750 ret = __phy_builtin_init_routine(ddrss, PIR_DRAM_INIT,
751 PGSR0_DRAM_INIT_MASK, 0);
752 if (ret) {
753 dev_err(ddrss->dev, "DRAM initialization failed %d\n",
754 ret);
755 return ret;
756 }
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530757
James Doublesinb6a19f02019-10-07 14:04:26 +0530758 ret = am654_ddrss_dram_wait_for_init_complt(ddrss);
759 if (ret) {
760 printf("%s: ERROR: DRAM Wait for init complete timedout\n",
761 __func__);
762 return ret;
763 }
764
765 ret = write_leveling(ddrss);
766 if (ret)
767 return ret;
768
769 ret = read_dqs_training(ddrss);
770 if (ret)
771 return ret;
772
773 ret = write_leveling_adjustment(ddrss);
774 if (ret)
775 return ret;
776
777 ret = rest_training(ddrss);
778 if (ret)
779 return ret;
780
781 ret = VREF_training(ddrss);
782 if (ret)
783 return ret;
784 debug("DDR4 training complete\n");
785 break;
786
787 case DDR_TYPE_DDR3:
788
789 debug("Starting DDR3 training\n");
790
791 ret = __phy_builtin_init_routine(ddrss, PIR_DRAM_INIT,
792 PGSR0_DRAM_INIT_MASK, 0);
793 if (ret) {
794 dev_err(ddrss->dev, "DRAM initialization failed %d\n",
795 ret);
796 return ret;
797 }
798
799 ret = am654_ddrss_dram_wait_for_init_complt(ddrss);
800 if (ret) {
801 printf("%s: ERROR: DRAM Wait for init complete timedout\n",
802 __func__);
803 return ret;
804 }
805
806 ret = write_leveling(ddrss);
807 if (ret)
808 return ret;
809
810 ret = enable_dqs_pd(ddrss);
811 if (ret)
812 return ret;
813
814 ret = read_dqs_training(ddrss);
815 if (ret)
816 return ret;
817
818 ret = disable_dqs_pd(ddrss);
819 if (ret)
820 return ret;
821
822 ret = write_leveling_adjustment(ddrss);
823 if (ret)
824 return ret;
825
826 ret = rest_training(ddrss);
827 if (ret)
828 return ret;
829
830 debug("DDR3 training complete\n");
831 break;
832 default:
833 printf("%s: ERROR: Unsupported DDR type\n", __func__);
834 return -EINVAL;
835 }
836
837 ret = cleanup_training(ddrss);
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530838 if (ret)
839 return ret;
840
841 /* Enabling refreshes after training is done */
842 ddrss_ctl_writel(DDRSS_DDRCTL_RFSHCTL3,
843 ddrss_ctl_readl(DDRSS_DDRCTL_RFSHCTL3) & ~0x1);
844
845 /* Disable PUBMODE after training is done */
846 ddrss_phy_writel(DDRSS_DDRPHY_PGCR1,
847 ddrss_phy_readl(DDRSS_DDRPHY_PGCR1) & ~0x40);
848
James Doublesinb6a19f02019-10-07 14:04:26 +0530849 debug("Completed DDR training\n");
850
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530851 return 0;
852}
853
854/**
855 * am654_ddrss_power_on() - Enable power and clocks for ddrss
856 * @dev: corresponding ddrss device
857 *
858 * Tries to enable all the corresponding clocks to the ddrss and sets it
859 * to the right frequency and then power on the ddrss.
860 * Return: 0 if all went ok, else corresponding error message.
861 */
862static int am654_ddrss_power_on(struct am654_ddrss_desc *ddrss)
863{
864 int ret;
865
866 debug("%s(ddrss=%p)\n", __func__, ddrss);
867
868 ret = clk_enable(&ddrss->ddrss_clk);
869 if (ret) {
870 dev_err(ddrss->dev, "clk_enable() failed: %d\n", ret);
871 return ret;
872 }
873
874 ret = power_domain_on(&ddrss->ddrcfg_pwrdmn);
875 if (ret) {
876 dev_err(ddrss->dev, "power_domain_on() failed: %d\n", ret);
877 return ret;
878 }
879
880 ret = power_domain_on(&ddrss->ddrdata_pwrdmn);
881 if (ret) {
882 dev_err(ddrss->dev, "power_domain_on() failed: %d\n", ret);
883 return ret;
884 }
885
886 /* VTT enable */
887#if CONFIG_IS_ENABLED(DM_REGULATOR)
888 device_get_supply_regulator(ddrss->dev, "vtt-supply",
889 &ddrss->vtt_supply);
890 ret = regulator_set_value(ddrss->vtt_supply, 3300000);
Christian Gmeiner477c4172022-03-23 16:04:28 +0100891 if (ret == 0)
892 debug("VTT regulator enabled\n");
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530893#endif
894
895 return 0;
896}
897
898/**
899 * am654_ddrss_ofdata_to_priv() - generate private data from device tree
900 * @dev: corresponding ddrss device
901 *
902 * Return: 0 if all went ok, else corresponding error message.
903 */
904static int am654_ddrss_ofdata_to_priv(struct udevice *dev)
905{
906 struct am654_ddrss_desc *ddrss = dev_get_priv(dev);
907 phys_addr_t reg;
908 int ret;
909
910 debug("%s(dev=%p)\n", __func__, dev);
911
912 ret = clk_get_by_index(dev, 0, &ddrss->ddrss_clk);
913 if (ret) {
914 dev_err(dev, "clk_get failed: %d\n", ret);
915 return ret;
916 }
917
918 ret = power_domain_get_by_index(dev, &ddrss->ddrcfg_pwrdmn, 0);
919 if (ret) {
920 dev_err(dev, "power_domain_get() failed: %d\n", ret);
921 return ret;
922 }
923
924 ret = power_domain_get_by_index(dev, &ddrss->ddrdata_pwrdmn, 1);
925 if (ret) {
926 dev_err(dev, "power_domain_get() failed: %d\n", ret);
927 return ret;
928 }
929
930 reg = devfdt_get_addr_name(dev, "ss");
931 if (reg == FDT_ADDR_T_NONE) {
932 dev_err(dev, "No reg property for DDRSS wrapper logic\n");
933 return -EINVAL;
934 }
935 ddrss->ddrss_ss_cfg = (void *)reg;
936
937 reg = devfdt_get_addr_name(dev, "ctl");
938 if (reg == FDT_ADDR_T_NONE) {
939 dev_err(dev, "No reg property for Controller region\n");
940 return -EINVAL;
941 }
942 ddrss->ddrss_ctl_cfg = (void *)reg;
943
944 reg = devfdt_get_addr_name(dev, "phy");
945 if (reg == FDT_ADDR_T_NONE) {
946 dev_err(dev, "No reg property for PHY region\n");
947 return -EINVAL;
948 }
949 ddrss->ddrss_phy_cfg = (void *)reg;
950
James Doublesin2c85dfd12019-10-07 14:04:27 +0530951 ret = dev_read_u32_array(dev, "ti,ss-reg",
952 (u32 *)&ddrss->params.ss_reg,
953 sizeof(ddrss->params.ss_reg) / sizeof(u32));
954 if (ret) {
955 dev_err(dev, "Cannot read ti,ss-reg params\n");
956 return ret;
957 }
958
Lokesh Vutlac49bffb2018-11-02 19:51:02 +0530959 ret = dev_read_u32_array(dev, "ti,ctl-reg",
960 (u32 *)&ddrss->params.ctl_reg,
961 sizeof(ddrss->params.ctl_reg) / sizeof(u32));
962 if (ret) {
963 dev_err(dev, "Cannot read ti,ctl-reg params\n");
964 return ret;
965 }
966
967 ret = dev_read_u32_array(dev, "ti,ctl-crc",
968 (u32 *)&ddrss->params.ctl_crc,
969 sizeof(ddrss->params.ctl_crc) / sizeof(u32));
970 if (ret) {
971 dev_err(dev, "Cannot read ti,ctl-crc params\n");
972 return ret;
973 }
974
975 ret = dev_read_u32_array(dev, "ti,ctl-ecc",
976 (u32 *)&ddrss->params.ctl_ecc,
977 sizeof(ddrss->params.ctl_ecc) / sizeof(u32));
978 if (ret) {
979 dev_err(dev, "Cannot read ti,ctl-ecc params\n");
980 return ret;
981 }
982
983 ret = dev_read_u32_array(dev, "ti,ctl-map",
984 (u32 *)&ddrss->params.ctl_map,
985 sizeof(ddrss->params.ctl_map) / sizeof(u32));
986 if (ret) {
987 dev_err(dev, "Cannot read ti,ctl-map params\n");
988 return ret;
989 }
990
991 ret = dev_read_u32_array(dev, "ti,ctl-pwr",
992 (u32 *)&ddrss->params.ctl_pwr,
993 sizeof(ddrss->params.ctl_pwr) / sizeof(u32));
994 if (ret) {
995 dev_err(dev, "Cannot read ti,ctl-pwr params\n");
996 return ret;
997 }
998
999 ret = dev_read_u32_array(dev, "ti,ctl-timing",
1000 (u32 *)&ddrss->params.ctl_timing,
1001 sizeof(ddrss->params.ctl_timing) /
1002 sizeof(u32));
1003 if (ret) {
1004 dev_err(dev, "Cannot read ti,ctl-timing params\n");
1005 return ret;
1006 }
1007
1008 ret = dev_read_u32_array(dev, "ti,phy-cfg",
1009 (u32 *)&ddrss->params.phy_cfg,
1010 sizeof(ddrss->params.phy_cfg) / sizeof(u32));
1011 if (ret) {
1012 dev_err(dev, "Cannot read ti,phy-cfg params\n");
1013 return ret;
1014 }
1015
1016 ret = dev_read_u32_array(dev, "ti,phy-ctl",
1017 (u32 *)&ddrss->params.phy_ctrl,
1018 sizeof(ddrss->params.phy_ctrl) / sizeof(u32));
1019 if (ret) {
1020 dev_err(dev, "Cannot read ti,phy-ctl params\n");
1021 return ret;
1022 }
1023
1024 ret = dev_read_u32_array(dev, "ti,phy-ioctl",
1025 (u32 *)&ddrss->params.phy_ioctl,
1026 sizeof(ddrss->params.phy_ioctl) / sizeof(u32));
1027 if (ret) {
1028 dev_err(dev, "Cannot read ti,phy-ioctl params\n");
1029 return ret;
1030 }
1031
1032 ret = dev_read_u32_array(dev, "ti,phy-timing",
1033 (u32 *)&ddrss->params.phy_timing,
1034 sizeof(ddrss->params.phy_timing) /
1035 sizeof(u32));
1036 if (ret) {
1037 dev_err(dev, "Cannot read ti,phy-timing params\n");
1038 return ret;
1039 }
1040
1041 ret = dev_read_u32_array(dev, "ti,phy-zq", (u32 *)&ddrss->params.phy_zq,
1042 sizeof(ddrss->params.phy_zq) / sizeof(u32));
1043 if (ret) {
1044 dev_err(dev, "Cannot read ti,phy-zq params\n");
1045 return ret;
1046 }
1047
1048 return ret;
1049}
1050
1051/**
1052 * am654_ddrss_probe() - Basic probe
1053 * @dev: corresponding ddrss device
1054 *
1055 * Return: 0 if all went ok, else corresponding error message
1056 */
1057static int am654_ddrss_probe(struct udevice *dev)
1058{
1059 struct am654_ddrss_desc *ddrss = dev_get_priv(dev);
1060 int ret;
1061
1062 debug("%s(dev=%p)\n", __func__, dev);
1063
1064 ret = am654_ddrss_ofdata_to_priv(dev);
1065 if (ret)
1066 return ret;
1067
1068 ddrss->dev = dev;
1069 ret = am654_ddrss_power_on(ddrss);
1070 if (ret)
1071 return ret;
1072
1073 ret = am654_ddrss_init(ddrss);
1074
1075 return ret;
1076}
1077
1078static int am654_ddrss_get_info(struct udevice *dev, struct ram_info *info)
1079{
1080 return 0;
1081}
1082
1083static struct ram_ops am654_ddrss_ops = {
1084 .get_info = am654_ddrss_get_info,
1085};
1086
1087static const struct udevice_id am654_ddrss_ids[] = {
1088 { .compatible = "ti,am654-ddrss" },
1089 { }
1090};
1091
1092U_BOOT_DRIVER(am654_ddrss) = {
1093 .name = "am654_ddrss",
1094 .id = UCLASS_RAM,
1095 .of_match = am654_ddrss_ids,
1096 .ops = &am654_ddrss_ops,
1097 .probe = am654_ddrss_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -07001098 .priv_auto = sizeof(struct am654_ddrss_desc),
Lokesh Vutlac49bffb2018-11-02 19:51:02 +05301099};