blob: dd1ee90b3c764eb532a6e3e8376a9c4badeb0a2a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +08002/*
3 * Copyright 2011 Freescale Semiconductor
Meenakshi Aggarwal74bd4992020-01-23 17:55:10 +05304 * Copyright 2020 NXP
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +08005 * Author: Shengzhou Liu <Shengzhou.Liu@freescale.com>
6 *
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +08007 * This file provides support for the QIXIS of some Freescale reference boards.
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +08008 */
9
10#include <common.h>
11#include <command.h>
12#include <asm/io.h>
Tom Rinid5a73852018-01-03 08:57:50 -050013#include <linux/compiler.h>
Prabhakar Kushwahaa98dcc72012-12-23 19:24:47 +000014#include <linux/time.h>
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000015#include <i2c.h>
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +080016#include "qixis.h"
17
Abhimanyu Sainie94cc3c2016-06-03 18:41:33 +053018#ifndef QIXIS_LBMAP_BRDCFG_REG
19/*
20 * For consistency with existing platforms
21 */
22#define QIXIS_LBMAP_BRDCFG_REG 0x00
23#endif
24
Yuantian Tang66e344a2019-06-19 14:39:28 +080025#ifndef QIXIS_RCFG_CTL_RECONFIG_IDLE
26#define QIXIS_RCFG_CTL_RECONFIG_IDLE 0x20
27#endif
28#ifndef QIXIS_RCFG_CTL_RECONFIG_START
29#define QIXIS_RCFG_CTL_RECONFIG_START 0x21
30#endif
31
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000032#ifdef CONFIG_SYS_I2C_FPGA_ADDR
33u8 qixis_read_i2c(unsigned int reg)
34{
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080035#ifndef CONFIG_DM_I2C
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000036 return i2c_reg_read(CONFIG_SYS_I2C_FPGA_ADDR, reg);
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080037#else
38 struct udevice *dev;
39
40 if (i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_FPGA_ADDR, 1, &dev))
41 return 0xff;
42
43 return dm_i2c_reg_read(dev, reg);
44#endif
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000045}
46
47void qixis_write_i2c(unsigned int reg, u8 value)
48{
49 u8 val = value;
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080050#ifndef CONFIG_DM_I2C
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000051 i2c_reg_write(CONFIG_SYS_I2C_FPGA_ADDR, reg, val);
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080052#else
53 struct udevice *dev;
54
55 if (!i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_FPGA_ADDR, 1, &dev))
56 dm_i2c_reg_write(dev, reg, val);
57#endif
58
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000059}
60#endif
61
Abhimanyu Saini973a7892016-06-03 18:41:32 +053062#ifdef QIXIS_BASE
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +080063u8 qixis_read(unsigned int reg)
64{
65 void *p = (void *)QIXIS_BASE;
66
67 return in_8(p + reg);
68}
69
70void qixis_write(unsigned int reg, u8 value)
71{
72 void *p = (void *)QIXIS_BASE;
73
74 out_8(p + reg, value);
75}
Abhimanyu Saini973a7892016-06-03 18:41:32 +053076#endif
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +080077
Prabhakar Kushwahaa98dcc72012-12-23 19:24:47 +000078u16 qixis_read_minor(void)
79{
80 u16 minor;
81
82 /* this data is in little endian */
83 QIXIS_WRITE(tagdata, 5);
84 minor = QIXIS_READ(tagdata);
85 QIXIS_WRITE(tagdata, 6);
86 minor += QIXIS_READ(tagdata) << 8;
87
88 return minor;
89}
90
91char *qixis_read_time(char *result)
92{
93 time_t time = 0;
94 int i;
95
96 /* timestamp is in 32-bit big endian */
97 for (i = 8; i <= 11; i++) {
98 QIXIS_WRITE(tagdata, i);
99 time = (time << 8) + QIXIS_READ(tagdata);
100 }
101
102 return ctime_r(&time, result);
103}
104
105char *qixis_read_tag(char *buf)
106{
107 int i;
108 char tag, *ptr = buf;
109
110 for (i = 16; i <= 63; i++) {
111 QIXIS_WRITE(tagdata, i);
112 tag = QIXIS_READ(tagdata);
113 *(ptr++) = tag;
114 if (!tag)
115 break;
116 }
117 if (i > 63)
118 *ptr = '\0';
119
120 return buf;
121}
122
Shaveta Leekha31955b72012-12-23 19:25:35 +0000123/*
124 * return the string of binary of u8 in the format of
125 * 1010 10_0. The masked bit is filled as underscore.
126 */
127const char *byte_to_binary_mask(u8 val, u8 mask, char *buf)
128{
129 char *ptr;
130 int i;
131
132 ptr = buf;
133 for (i = 0x80; i > 0x08 ; i >>= 1, ptr++)
134 *ptr = (val & i) ? '1' : ((mask & i) ? '_' : '0');
135 *(ptr++) = ' ';
136 for (i = 0x08; i > 0 ; i >>= 1, ptr++)
137 *ptr = (val & i) ? '1' : ((mask & i) ? '_' : '0');
138
139 *ptr = '\0';
140
141 return buf;
142}
143
York Sun5e155552013-06-25 11:37:48 -0700144#ifdef QIXIS_RST_FORCE_MEM
145void board_assert_mem_reset(void)
146{
147 u8 rst;
148
149 rst = QIXIS_READ(rst_frc[0]);
150 if (!(rst & QIXIS_RST_FORCE_MEM))
151 QIXIS_WRITE(rst_frc[0], rst | QIXIS_RST_FORCE_MEM);
152}
153
154void board_deassert_mem_reset(void)
155{
156 u8 rst;
157
158 rst = QIXIS_READ(rst_frc[0]);
159 if (rst & QIXIS_RST_FORCE_MEM)
160 QIXIS_WRITE(rst_frc[0], rst & ~QIXIS_RST_FORCE_MEM);
161}
162#endif
163
Tom Rinid5a73852018-01-03 08:57:50 -0500164#ifndef CONFIG_SPL_BUILD
165static void qixis_reset(void)
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800166{
Prabhakar Kushwaha8d0412a2012-09-17 17:30:31 +0000167 QIXIS_WRITE(rst_ctl, QIXIS_RST_CTL_RESET);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800168}
169
Yuantian Tang66e344a2019-06-19 14:39:28 +0800170#ifdef QIXIS_LBMAP_ALTBANK
Tom Rinid5a73852018-01-03 08:57:50 -0500171static void qixis_bank_reset(void)
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800172{
Prabhakar Kushwaha8d0412a2012-09-17 17:30:31 +0000173 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
174 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800175}
Yuantian Tang66e344a2019-06-19 14:39:28 +0800176#endif
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800177
Scott Woodbfee2e72015-03-20 19:28:29 -0700178static void __maybe_unused set_lbmap(int lbmap)
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800179{
180 u8 reg;
181
Abhimanyu Sainie94cc3c2016-06-03 18:41:33 +0530182 reg = QIXIS_READ(brdcfg[QIXIS_LBMAP_BRDCFG_REG]);
Scott Woodbfee2e72015-03-20 19:28:29 -0700183 reg = (reg & ~QIXIS_LBMAP_MASK) | lbmap;
Abhimanyu Sainie94cc3c2016-06-03 18:41:33 +0530184 QIXIS_WRITE(brdcfg[QIXIS_LBMAP_BRDCFG_REG], reg);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800185}
186
Scott Woodbfee2e72015-03-20 19:28:29 -0700187static void __maybe_unused set_rcw_src(int rcw_src)
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800188{
Yuantian Tang66e344a2019-06-19 14:39:28 +0800189#ifdef CONFIG_NXP_LSCH3_2
190 QIXIS_WRITE(dutcfg[0], (rcw_src & 0xff));
191#else
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800192 u8 reg;
193
Scott Woodbfee2e72015-03-20 19:28:29 -0700194 reg = QIXIS_READ(dutcfg[1]);
195 reg = (reg & ~1) | (rcw_src & 1);
196 QIXIS_WRITE(dutcfg[1], reg);
197 QIXIS_WRITE(dutcfg[0], (rcw_src >> 1) & 0xff);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800198#endif
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800199}
200
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800201static void qixis_dump_regs(void)
202{
203 int i;
204
205 printf("id = %02x\n", QIXIS_READ(id));
206 printf("arch = %02x\n", QIXIS_READ(arch));
207 printf("scver = %02x\n", QIXIS_READ(scver));
208 printf("model = %02x\n", QIXIS_READ(model));
209 printf("rst_ctl = %02x\n", QIXIS_READ(rst_ctl));
210 printf("aux = %02x\n", QIXIS_READ(aux));
211 for (i = 0; i < 16; i++)
212 printf("brdcfg%02d = %02x\n", i, QIXIS_READ(brdcfg[i]));
213 for (i = 0; i < 16; i++)
214 printf("dutcfg%02d = %02x\n", i, QIXIS_READ(dutcfg[i]));
215 printf("sclk = %02x%02x%02x\n", QIXIS_READ(sclk[0]),
216 QIXIS_READ(sclk[1]), QIXIS_READ(sclk[2]));
217 printf("dclk = %02x%02x%02x\n", QIXIS_READ(dclk[0]),
218 QIXIS_READ(dclk[1]), QIXIS_READ(dclk[2]));
219 printf("aux = %02x\n", QIXIS_READ(aux));
220 printf("watch = %02x\n", QIXIS_READ(watch));
221 printf("ctl_sys = %02x\n", QIXIS_READ(ctl_sys));
222 printf("rcw_ctl = %02x\n", QIXIS_READ(rcw_ctl));
223 printf("present = %02x\n", QIXIS_READ(present));
Shengzhou Liuc82392d2012-10-07 20:21:02 +0000224 printf("present2 = %02x\n", QIXIS_READ(present2));
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800225 printf("clk_spd = %02x\n", QIXIS_READ(clk_spd));
226 printf("stat_dut = %02x\n", QIXIS_READ(stat_dut));
227 printf("stat_sys = %02x\n", QIXIS_READ(stat_sys));
228 printf("stat_alrm = %02x\n", QIXIS_READ(stat_alrm));
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800229}
Shaveta Leekha31955b72012-12-23 19:25:35 +0000230
Tom Rinid5a73852018-01-03 08:57:50 -0500231void __weak qixis_dump_switch(void)
Shaveta Leekha31955b72012-12-23 19:25:35 +0000232{
233 puts("Reverse engineering switch is not implemented for this board\n");
234}
235
Tom Rinid5a73852018-01-03 08:57:50 -0500236static int qixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800237{
238 int i;
239
240 if (argc <= 1) {
Scott Woodbfee2e72015-03-20 19:28:29 -0700241 set_lbmap(QIXIS_LBMAP_DFLTBANK);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800242 qixis_reset();
243 } else if (strcmp(argv[1], "altbank") == 0) {
Yuantian Tang66e344a2019-06-19 14:39:28 +0800244#ifdef QIXIS_LBMAP_ALTBANK
Scott Woodbfee2e72015-03-20 19:28:29 -0700245 set_lbmap(QIXIS_LBMAP_ALTBANK);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800246 qixis_bank_reset();
Yuantian Tang66e344a2019-06-19 14:39:28 +0800247#else
248 printf("No Altbank!\n");
249#endif
Scott Woodbfee2e72015-03-20 19:28:29 -0700250 } else if (strcmp(argv[1], "nand") == 0) {
251#ifdef QIXIS_LBMAP_NAND
252 QIXIS_WRITE(rst_ctl, 0x30);
253 QIXIS_WRITE(rcfg_ctl, 0);
254 set_lbmap(QIXIS_LBMAP_NAND);
255 set_rcw_src(QIXIS_RCW_SRC_NAND);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800256 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
257 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Scott Woodbfee2e72015-03-20 19:28:29 -0700258#else
259 printf("Not implemented\n");
260#endif
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800261 } else if (strcmp(argv[1], "sd") == 0) {
262#ifdef QIXIS_LBMAP_SD
263 QIXIS_WRITE(rst_ctl, 0x30);
264 QIXIS_WRITE(rcfg_ctl, 0);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000265#ifdef NON_EXTENDED_DUTCFG
266 QIXIS_WRITE(dutcfg[0], QIXIS_RCW_SRC_SD);
267#else
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800268 set_lbmap(QIXIS_LBMAP_SD);
269 set_rcw_src(QIXIS_RCW_SRC_SD);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000270#endif
Yuantian Tang66e344a2019-06-19 14:39:28 +0800271 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
272 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800273#else
274 printf("Not implemented\n");
275#endif
Ashish Kumarb58cdc92018-01-17 12:16:36 +0530276 } else if (strcmp(argv[1], "ifc") == 0) {
277#ifdef QIXIS_LBMAP_IFC
278 QIXIS_WRITE(rst_ctl, 0x30);
279 QIXIS_WRITE(rcfg_ctl, 0);
280 set_lbmap(QIXIS_LBMAP_IFC);
281 set_rcw_src(QIXIS_RCW_SRC_IFC);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800282 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
283 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Ashish Kumarb58cdc92018-01-17 12:16:36 +0530284#else
285 printf("Not implemented\n");
286#endif
287 } else if (strcmp(argv[1], "emmc") == 0) {
288#ifdef QIXIS_LBMAP_EMMC
289 QIXIS_WRITE(rst_ctl, 0x30);
290 QIXIS_WRITE(rcfg_ctl, 0);
Meenakshi Aggarwal74bd4992020-01-23 17:55:10 +0530291#ifndef NON_EXTENDED_DUTCFG
Ashish Kumarb58cdc92018-01-17 12:16:36 +0530292 set_lbmap(QIXIS_LBMAP_EMMC);
Meenakshi Aggarwal74bd4992020-01-23 17:55:10 +0530293#endif
Ashish Kumarb58cdc92018-01-17 12:16:36 +0530294 set_rcw_src(QIXIS_RCW_SRC_EMMC);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800295 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
296 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Ashish Kumarb58cdc92018-01-17 12:16:36 +0530297#else
298 printf("Not implemented\n");
299#endif
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800300 } else if (strcmp(argv[1], "sd_qspi") == 0) {
301#ifdef QIXIS_LBMAP_SD_QSPI
302 QIXIS_WRITE(rst_ctl, 0x30);
303 QIXIS_WRITE(rcfg_ctl, 0);
304 set_lbmap(QIXIS_LBMAP_SD_QSPI);
305 set_rcw_src(QIXIS_RCW_SRC_SD);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800306 qixis_write_i2c(offsetof(struct qixis, rcfg_ctl),
307 QIXIS_RCFG_CTL_RECONFIG_IDLE);
308 qixis_write_i2c(offsetof(struct qixis, rcfg_ctl),
309 QIXIS_RCFG_CTL_RECONFIG_START);
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800310#else
311 printf("Not implemented\n");
312#endif
313 } else if (strcmp(argv[1], "qspi") == 0) {
314#ifdef QIXIS_LBMAP_QSPI
315 QIXIS_WRITE(rst_ctl, 0x30);
316 QIXIS_WRITE(rcfg_ctl, 0);
317 set_lbmap(QIXIS_LBMAP_QSPI);
318 set_rcw_src(QIXIS_RCW_SRC_QSPI);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800319 qixis_write_i2c(offsetof(struct qixis, rcfg_ctl),
320 QIXIS_RCFG_CTL_RECONFIG_IDLE);
321 qixis_write_i2c(offsetof(struct qixis, rcfg_ctl),
322 QIXIS_RCFG_CTL_RECONFIG_START);
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800323#else
324 printf("Not implemented\n");
325#endif
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800326 } else if (strcmp(argv[1], "watchdog") == 0) {
327 static char *period[9] = {"2s", "4s", "8s", "16s", "32s",
328 "1min", "2min", "4min", "8min"};
329 u8 rcfg = QIXIS_READ(rcfg_ctl);
330
331 if (argv[2] == NULL) {
332 printf("qixis watchdog <watchdog_period>\n");
333 return 0;
334 }
335 for (i = 0; i < ARRAY_SIZE(period); i++) {
336 if (strcmp(argv[2], period[i]) == 0) {
337 /* disable watchdog */
Prabhakar Kushwaha8d0412a2012-09-17 17:30:31 +0000338 QIXIS_WRITE(rcfg_ctl,
339 rcfg & ~QIXIS_RCFG_CTL_WATCHDOG_ENBLE);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800340 QIXIS_WRITE(watch, ((i<<2) - 1));
341 QIXIS_WRITE(rcfg_ctl, rcfg);
342 return 0;
343 }
344 }
Shaveta Leekha31955b72012-12-23 19:25:35 +0000345 } else if (strcmp(argv[1], "dump") == 0) {
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800346 qixis_dump_regs();
347 return 0;
Shaveta Leekha31955b72012-12-23 19:25:35 +0000348 } else if (strcmp(argv[1], "switch") == 0) {
349 qixis_dump_switch();
350 return 0;
351 } else {
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800352 printf("Invalid option: %s\n", argv[1]);
353 return 1;
354 }
355
356 return 0;
357}
358
359U_BOOT_CMD(
360 qixis_reset, CONFIG_SYS_MAXARGS, 1, qixis_reset_cmd,
361 "Reset the board using the FPGA sequencer",
362 "- hard reset to default bank\n"
363 "qixis_reset altbank - reset to alternate bank\n"
Scott Woodbfee2e72015-03-20 19:28:29 -0700364 "qixis_reset nand - reset to nand\n"
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800365 "qixis_reset sd - reset to sd\n"
366 "qixis_reset sd_qspi - reset to sd with qspi support\n"
367 "qixis_reset qspi - reset to qspi\n"
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800368 "qixis watchdog <watchdog_period> - set the watchdog period\n"
369 " period: 1s 2s 4s 8s 16s 32s 1min 2min 4min 8min\n"
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800370 "qixis_reset dump - display the QIXIS registers\n"
Meenakshi Aggarwal74bd4992020-01-23 17:55:10 +0530371 "qixis_reset emmc - reset to emmc\n"
Shaveta Leekha31955b72012-12-23 19:25:35 +0000372 "qixis_reset switch - display switch\n"
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800373 );
Tom Rinid5a73852018-01-03 08:57:50 -0500374#endif