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