blob: 20f2aac332da8d421e97d15cbcf044b4fb12059c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +02002/*
Lukasz Majewski70eb7972019-02-13 22:46:47 +01003 * (C) Copyright 2018
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de.
5 *
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +02006 * Copyright 2013 Freescale Semiconductor, Inc.
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +02007 */
8
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +020011#include <asm/io.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/iomux-vf610.h>
14#include <asm/arch/ddrmc-vf610.h>
15#include <asm/arch/crm_regs.h>
16#include <asm/arch/clock.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060017#include <env.h>
Lukasz Majewski3caa5b82019-02-13 22:46:57 +010018#include <led.h>
Lukasz Majewski4b155a92019-02-13 22:46:59 +010019#include <miiphy.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060020#include <linux/bitops.h>
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +020021
22DECLARE_GLOBAL_DATA_PTR;
23
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +020024static struct ddrmc_cr_setting pcm052_cr_settings[] = {
25 /* not in the datasheets, but in the original code */
26 { 0x00002000, 105 },
27 { 0x00000020, 110 },
28 /* AXI */
29 { DDRMC_CR117_AXI0_W_PRI(1) | DDRMC_CR117_AXI0_R_PRI(1), 117 },
30 { DDRMC_CR118_AXI1_W_PRI(1) | DDRMC_CR118_AXI1_R_PRI(1), 118 },
31 { DDRMC_CR120_AXI0_PRI1_RPRI(2) |
32 DDRMC_CR120_AXI0_PRI0_RPRI(2), 120 },
33 { DDRMC_CR121_AXI0_PRI3_RPRI(2) |
34 DDRMC_CR121_AXI0_PRI2_RPRI(2), 121 },
35 { DDRMC_CR122_AXI1_PRI1_RPRI(1) | DDRMC_CR122_AXI1_PRI0_RPRI(1) |
36 DDRMC_CR122_AXI0_PRIRLX(100), 122 },
37 { DDRMC_CR123_AXI1_P_ODR_EN | DDRMC_CR123_AXI1_PRI3_RPRI(1) |
38 DDRMC_CR123_AXI1_PRI2_RPRI(1), 123 },
39 { DDRMC_CR124_AXI1_PRIRLX(100), 124 },
40 { DDRMC_CR126_PHY_RDLAT(11), 126 },
41 { DDRMC_CR132_WRLAT_ADJ(5) | DDRMC_CR132_RDLAT_ADJ(6), 132 },
42 { DDRMC_CR137_PHYCTL_DL(2), 137 },
43 { DDRMC_CR139_PHY_WRLV_RESPLAT(4) | DDRMC_CR139_PHY_WRLV_LOAD(7) |
44 DDRMC_CR139_PHY_WRLV_DLL(3) |
45 DDRMC_CR139_PHY_WRLV_EN(3), 139 },
46 { DDRMC_CR154_PAD_ZQ_EARLY_CMP_EN_TIMER(13) |
47 DDRMC_CR154_PAD_ZQ_MODE(1) |
48 DDRMC_CR154_DDR_SEL_PAD_CONTR(3) |
49 DDRMC_CR154_PAD_ZQ_HW_FOR(0), 154 },
50 { DDRMC_CR155_PAD_ODT_BYTE1(5) | DDRMC_CR155_PAD_ODT_BYTE0(5), 155 },
51 { DDRMC_CR158_TWR(6), 158 },
52 { DDRMC_CR161_ODT_EN(0) | DDRMC_CR161_TODTH_RD(0) |
53 DDRMC_CR161_TODTH_WR(6), 161 },
54 /* end marker */
55 { 0, -1 }
56};
57
58/* PHY settings -- most of them differ from default in imx-regs.h */
59
60#define PCM052_DDRMC_PHY_DQ_TIMING 0x00002213
61#define PCM052_DDRMC_PHY_CTRL 0x00290000
62#define PCM052_DDRMC_PHY_SLAVE_CTRL 0x00002c00
63#define PCM052_DDRMC_PHY_PROC_PAD_ODT 0x00010020
64
65static struct ddrmc_phy_setting pcm052_phy_settings[] = {
66 { PCM052_DDRMC_PHY_DQ_TIMING, 0 },
67 { PCM052_DDRMC_PHY_DQ_TIMING, 16 },
68 { PCM052_DDRMC_PHY_DQ_TIMING, 32 },
69 { PCM052_DDRMC_PHY_DQ_TIMING, 48 },
70 { DDRMC_PHY_DQS_TIMING, 1 },
71 { DDRMC_PHY_DQS_TIMING, 17 },
72 { DDRMC_PHY_DQS_TIMING, 33 },
73 { DDRMC_PHY_DQS_TIMING, 49 },
74 { PCM052_DDRMC_PHY_CTRL, 2 },
75 { PCM052_DDRMC_PHY_CTRL, 18 },
76 { PCM052_DDRMC_PHY_CTRL, 34 },
77 { DDRMC_PHY_MASTER_CTRL, 3 },
78 { DDRMC_PHY_MASTER_CTRL, 19 },
79 { DDRMC_PHY_MASTER_CTRL, 35 },
80 { PCM052_DDRMC_PHY_SLAVE_CTRL, 4 },
81 { PCM052_DDRMC_PHY_SLAVE_CTRL, 20 },
82 { PCM052_DDRMC_PHY_SLAVE_CTRL, 36 },
83 { DDRMC_PHY50_DDR3_MODE | DDRMC_PHY50_EN_SW_HALF_CYCLE, 50 },
84 { PCM052_DDRMC_PHY_PROC_PAD_ODT, 52 },
85
86 /* end marker */
87 { 0, -1 }
88};
89
90int dram_init(void)
91{
Albert ARIBAUD \(3ADEV\)ddef3b62016-09-26 09:08:08 +020092#if defined(CONFIG_TARGET_PCM052)
93
94 static const struct ddr3_jedec_timings pcm052_ddr_timings = {
95 .tinit = 5,
96 .trst_pwron = 80000,
97 .cke_inactive = 200000,
98 .wrlat = 5,
99 .caslat_lin = 12,
100 .trc = 6,
101 .trrd = 4,
102 .tccd = 4,
103 .tbst_int_interval = 4,
104 .tfaw = 18,
105 .trp = 6,
106 .twtr = 4,
107 .tras_min = 15,
108 .tmrd = 4,
109 .trtp = 4,
110 .tras_max = 14040,
111 .tmod = 12,
112 .tckesr = 4,
113 .tcke = 3,
114 .trcd_int = 6,
115 .tras_lockout = 1,
116 .tdal = 10,
117 .bstlen = 3,
118 .tdll = 512,
119 .trp_ab = 6,
120 .tref = 1542,
121 .trfc = 64,
122 .tref_int = 5,
123 .tpdex = 3,
124 .txpdll = 10,
125 .txsnr = 68,
126 .txsr = 506,
127 .cksrx = 5,
128 .cksre = 5,
129 .freq_chg_en = 1,
130 .zqcl = 256,
131 .zqinit = 512,
132 .zqcs = 64,
133 .ref_per_zq = 64,
134 .zqcs_rotate = 1,
135 .aprebit = 10,
136 .cmd_age_cnt = 255,
137 .age_cnt = 255,
138 .q_fullness = 0,
139 .odt_rd_mapcs0 = 1,
140 .odt_wr_mapcs0 = 1,
141 .wlmrd = 40,
142 .wldqsen = 25,
143 };
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200144
Albert ARIBAUD \(3ADEV\)79731202017-02-01 14:46:00 +0100145 const int row_diff = 2;
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200146
Albert ARIBAUD \(3ADEV\)ddef3b62016-09-26 09:08:08 +0200147#elif defined(CONFIG_TARGET_BK4R1)
148
149 static const struct ddr3_jedec_timings pcm052_ddr_timings = {
150 .tinit = 5,
151 .trst_pwron = 80000,
152 .cke_inactive = 200000,
153 .wrlat = 5,
154 .caslat_lin = 12,
155 .trc = 6,
156 .trrd = 4,
157 .tccd = 4,
158 .tbst_int_interval = 0,
159 .tfaw = 16,
160 .trp = 6,
161 .twtr = 4,
162 .tras_min = 15,
163 .tmrd = 4,
164 .trtp = 4,
165 .tras_max = 28080,
166 .tmod = 12,
167 .tckesr = 4,
168 .tcke = 3,
169 .trcd_int = 6,
170 .tras_lockout = 1,
171 .tdal = 12,
172 .bstlen = 3,
173 .tdll = 512,
174 .trp_ab = 6,
175 .tref = 3120,
176 .trfc = 104,
177 .tref_int = 0,
178 .tpdex = 3,
179 .txpdll = 10,
180 .txsnr = 108,
181 .txsr = 512,
182 .cksrx = 5,
183 .cksre = 5,
184 .freq_chg_en = 1,
185 .zqcl = 256,
186 .zqinit = 512,
187 .zqcs = 64,
188 .ref_per_zq = 64,
189 .zqcs_rotate = 1,
190 .aprebit = 10,
191 .cmd_age_cnt = 255,
192 .age_cnt = 255,
193 .q_fullness = 0,
194 .odt_rd_mapcs0 = 1,
195 .odt_wr_mapcs0 = 1,
196 .wlmrd = 40,
197 .wldqsen = 25,
198 };
199
Albert ARIBAUD \(3ADEV\)79731202017-02-01 14:46:00 +0100200 const int row_diff = 1;
Albert ARIBAUD \(3ADEV\)ddef3b62016-09-26 09:08:08 +0200201
202#else /* Unknown PCM052 variant */
203
204#error DDR characteristics undefined for this target. Please define them.
205
206#endif
207
Albert ARIBAUD \(3ADEV\)79731202017-02-01 14:46:00 +0100208 ddrmc_ctrl_init_ddr3(&pcm052_ddr_timings, pcm052_cr_settings,
209 pcm052_phy_settings, 1, row_diff);
210
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200211 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
212
213 return 0;
214}
215
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200216static void clock_init(void)
217{
218 struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
219 struct anadig_reg *anadig = (struct anadig_reg *)ANADIG_BASE_ADDR;
220
221 clrsetbits_le32(&ccm->ccgr0, CCM_REG_CTRL_MASK,
222 CCM_CCGR0_UART1_CTRL_MASK);
223 clrsetbits_le32(&ccm->ccgr1, CCM_REG_CTRL_MASK,
224 CCM_CCGR1_PIT_CTRL_MASK | CCM_CCGR1_WDOGA5_CTRL_MASK);
225 clrsetbits_le32(&ccm->ccgr2, CCM_REG_CTRL_MASK,
226 CCM_CCGR2_IOMUXC_CTRL_MASK | CCM_CCGR2_PORTA_CTRL_MASK |
227 CCM_CCGR2_PORTB_CTRL_MASK | CCM_CCGR2_PORTC_CTRL_MASK |
228 CCM_CCGR2_PORTD_CTRL_MASK | CCM_CCGR2_PORTE_CTRL_MASK |
229 CCM_CCGR2_QSPI0_CTRL_MASK);
230 clrsetbits_le32(&ccm->ccgr3, CCM_REG_CTRL_MASK,
231 CCM_CCGR3_ANADIG_CTRL_MASK | CCM_CCGR3_SCSC_CTRL_MASK);
232 clrsetbits_le32(&ccm->ccgr4, CCM_REG_CTRL_MASK,
233 CCM_CCGR4_WKUP_CTRL_MASK | CCM_CCGR4_CCM_CTRL_MASK |
234 CCM_CCGR4_GPC_CTRL_MASK);
235 clrsetbits_le32(&ccm->ccgr6, CCM_REG_CTRL_MASK,
236 CCM_CCGR6_OCOTP_CTRL_MASK | CCM_CCGR6_DDRMC_CTRL_MASK);
237 clrsetbits_le32(&ccm->ccgr7, CCM_REG_CTRL_MASK,
238 CCM_CCGR7_SDHC1_CTRL_MASK);
239 clrsetbits_le32(&ccm->ccgr9, CCM_REG_CTRL_MASK,
240 CCM_CCGR9_FEC0_CTRL_MASK | CCM_CCGR9_FEC1_CTRL_MASK);
241 clrsetbits_le32(&ccm->ccgr10, CCM_REG_CTRL_MASK,
Lukasz Majewski48dbe322019-02-13 22:46:42 +0100242 CCM_CCGR10_NFC_CTRL_MASK);
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200243
244 clrsetbits_le32(&anadig->pll2_ctrl, ANADIG_PLL2_CTRL_POWERDOWN,
245 ANADIG_PLL2_CTRL_ENABLE | ANADIG_PLL2_CTRL_DIV_SELECT);
246 clrsetbits_le32(&anadig->pll1_ctrl, ANADIG_PLL1_CTRL_POWERDOWN,
247 ANADIG_PLL1_CTRL_ENABLE | ANADIG_PLL1_CTRL_DIV_SELECT);
248
249 clrsetbits_le32(&ccm->ccr, CCM_CCR_OSCNT_MASK,
250 CCM_CCR_FIRC_EN | CCM_CCR_OSCNT(5));
251 clrsetbits_le32(&ccm->ccsr, CCM_REG_CTRL_MASK,
252 CCM_CCSR_PLL1_PFD_CLK_SEL(3) | CCM_CCSR_PLL2_PFD4_EN |
253 CCM_CCSR_PLL2_PFD3_EN | CCM_CCSR_PLL2_PFD2_EN |
254 CCM_CCSR_PLL2_PFD1_EN | CCM_CCSR_PLL1_PFD4_EN |
255 CCM_CCSR_PLL1_PFD3_EN | CCM_CCSR_PLL1_PFD2_EN |
256 CCM_CCSR_PLL1_PFD1_EN | CCM_CCSR_DDRC_CLK_SEL(1) |
257 CCM_CCSR_FAST_CLK_SEL(1) | CCM_CCSR_SYS_CLK_SEL(4));
258 clrsetbits_le32(&ccm->cacrr, CCM_REG_CTRL_MASK,
259 CCM_CACRR_IPG_CLK_DIV(1) | CCM_CACRR_BUS_CLK_DIV(2) |
260 CCM_CACRR_ARM_CLK_DIV(0));
261 clrsetbits_le32(&ccm->cscmr1, CCM_REG_CTRL_MASK,
262 CCM_CSCMR1_ESDHC1_CLK_SEL(3) |
263 CCM_CSCMR1_QSPI0_CLK_SEL(3) |
264 CCM_CSCMR1_NFC_CLK_SEL(0));
265 clrsetbits_le32(&ccm->cscdr1, CCM_REG_CTRL_MASK,
266 CCM_CSCDR1_RMII_CLK_EN);
267 clrsetbits_le32(&ccm->cscdr2, CCM_REG_CTRL_MASK,
268 CCM_CSCDR2_ESDHC1_EN | CCM_CSCDR2_ESDHC1_CLK_DIV(0) |
269 CCM_CSCDR2_NFC_EN);
270 clrsetbits_le32(&ccm->cscdr3, CCM_REG_CTRL_MASK,
271 CCM_CSCDR3_QSPI0_EN | CCM_CSCDR3_QSPI0_DIV(1) |
272 CCM_CSCDR3_QSPI0_X2_DIV(1) |
273 CCM_CSCDR3_QSPI0_X4_DIV(3) |
274 CCM_CSCDR3_NFC_PRE_DIV(5));
275 clrsetbits_le32(&ccm->cscmr2, CCM_REG_CTRL_MASK,
276 CCM_CSCMR2_RMII_CLK_SEL(0));
277}
278
279static void mscm_init(void)
280{
281 struct mscm_ir *mscmir = (struct mscm_ir *)MSCM_IR_BASE_ADDR;
282 int i;
283
284 for (i = 0; i < MSCM_IRSPRC_NUM; i++)
285 writew(MSCM_IRSPRC_CP0_EN, &mscmir->irsprc[i]);
286}
287
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200288int board_early_init_f(void)
289{
290 clock_init();
291 mscm_init();
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200292
293 return 0;
294}
295
296int board_init(void)
297{
298 struct scsc_reg *scsc = (struct scsc_reg *)SCSC_BASE_ADDR;
299
300 /* address of boot parameters */
301 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
302
303 /*
304 * Enable external 32K Oscillator
305 *
306 * The internal clock experiences significant drift
307 * so we must use the external oscillator in order
308 * to maintain correct time in the hwclock
309 */
310 setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
311
312 return 0;
313}
314
Lukasz Majewski8df96a22019-02-13 22:46:56 +0100315#ifdef CONFIG_TARGET_BK4R1
Lukasz Majewski92a98b62019-02-13 22:46:58 +0100316void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
317{
318 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
319 struct fuse_bank *bank = &ocotp->bank[4];
320 struct fuse_bank4_regs *fuse =
321 (struct fuse_bank4_regs *)bank->fuse_regs;
322 u32 value;
323
324 /*
325 * BK4 has different layout of stored MAC address
326 * than one used in imx_get_mac_from_fuse() @ generic.c
327 */
328
329 switch (dev_id) {
330 case 0:
331 value = readl(&fuse->mac_addr1);
332
333 mac[0] = value >> 8;
334 mac[1] = value;
335
336 value = readl(&fuse->mac_addr0);
337 mac[2] = value >> 24;
338 mac[3] = value >> 16;
339 mac[4] = value >> 8;
340 mac[5] = value;
341 break;
342 case 1:
343 value = readl(&fuse->mac_addr2);
344
345 mac[0] = value >> 24;
346 mac[1] = value >> 16;
347 mac[2] = value >> 8;
348 mac[3] = value;
349
350 value = readl(&fuse->mac_addr1);
351 mac[4] = value >> 24;
352 mac[5] = value >> 16;
353 break;
354 }
355}
356
Lukasz Majewski8df96a22019-02-13 22:46:56 +0100357int board_late_init(void)
358{
359 struct src *psrc = (struct src *)SRC_BASE_ADDR;
360 u32 reg;
361
362 /*
363 * BK4r1 handle emergency/service SD card boot
364 * Checking the SBMR1 register BOOTCFG1 byte:
365 * NAND:
366 * bit [2] - NAND data width - 16
367 * bit [5] - NAND fast boot
368 * bit [7] = 1 - NAND as a source of booting
369 * SD card (0x64):
370 * bit [4] = 0 - SD card source
371 * bit [6] = 1 - SD/MMC source
372 */
373
374 reg = readl(&psrc->sbmr1);
375 if ((reg & SRC_SBMR1_BOOTCFG1_SDMMC) &&
376 !(reg & SRC_SBMR1_BOOTCFG1_MMC)) {
377 printf("------ SD card boot -------\n");
Simon Glass97385862019-08-01 09:47:00 -0600378 env_set_default("!LVFBootloader", 0);
Lukasz Majewski8df96a22019-02-13 22:46:56 +0100379 env_set("bootcmd",
380 "run prepare_install_bk4r1_envs; run install_bk4r1rs");
381 }
382
383 return 0;
384}
Lukasz Majewski4b155a92019-02-13 22:46:59 +0100385
386/**
387 * KSZ8081
388 */
389#define MII_KSZ8081_REFERENCE_CLOCK_SELECT 0x1f
390#define RMII_50MHz_CLOCK 0x8180
391
392int board_phy_config(struct phy_device *phydev)
393{
394 /* Set 50 MHz reference clock */
395 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ8081_REFERENCE_CLOCK_SELECT,
396 RMII_50MHz_CLOCK);
397
398 return genphy_config(phydev);
399}
Lukasz Majewski8df96a22019-02-13 22:46:56 +0100400#endif /* CONFIG_TARGET_BK4R1 */
401
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200402int checkboard(void)
403{
Lukasz Majewski5399dc32019-02-13 22:46:45 +0100404#ifdef CONFIG_TARGET_BK4R1
Lukasz Majewski3546c972019-07-28 00:17:05 +0200405 u32 *gpio3_pdir = (u32 *)(GPIO3_BASE_ADDR + 0x10);
406
407 /*
408 * USB_RESET_N (PTC30 - GPIO103 - PORT3[7]):
409 * L333 -> pull up added -> read 1
410 * L320 -> no pull up -> read 0
411 *
412 * Default iomuxc_ptc30 value after reset: 0x300061 -> RCON28
413 * - input enabled, pull (up/down) disabled
414 */
415 if (*gpio3_pdir & BIT(7))
416 puts("Board: BK4r1 (L333)\n");
417 else
418 puts("Board: BK4r1 (L320)\n");
Lukasz Majewski5399dc32019-02-13 22:46:45 +0100419#else
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200420 puts("Board: PCM-052\n");
Lukasz Majewski5399dc32019-02-13 22:46:45 +0100421#endif
Albert ARIBAUD \(3ADEV\)26ffbef2015-09-21 22:43:39 +0200422 return 0;
423}