blob: 716c93b2c240734ce0dd4a67ea33241ad1b4eaf0 [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
4 * Author: Shengzhou Liu <Shengzhou.Liu@freescale.com>
5 *
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +08006 * This file provides support for the QIXIS of some Freescale reference boards.
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +08007 */
8
9#include <common.h>
10#include <command.h>
11#include <asm/io.h>
Tom Rinid5a73852018-01-03 08:57:50 -050012#include <linux/compiler.h>
Prabhakar Kushwahaa98dcc72012-12-23 19:24:47 +000013#include <linux/time.h>
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000014#include <i2c.h>
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +080015#include "qixis.h"
16
Abhimanyu Sainie94cc3c2016-06-03 18:41:33 +053017#ifndef QIXIS_LBMAP_BRDCFG_REG
18/*
19 * For consistency with existing platforms
20 */
21#define QIXIS_LBMAP_BRDCFG_REG 0x00
22#endif
23
Yuantian Tang66e344a2019-06-19 14:39:28 +080024#ifndef QIXIS_RCFG_CTL_RECONFIG_IDLE
25#define QIXIS_RCFG_CTL_RECONFIG_IDLE 0x20
26#endif
27#ifndef QIXIS_RCFG_CTL_RECONFIG_START
28#define QIXIS_RCFG_CTL_RECONFIG_START 0x21
29#endif
30
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000031#ifdef CONFIG_SYS_I2C_FPGA_ADDR
32u8 qixis_read_i2c(unsigned int reg)
33{
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080034#ifndef CONFIG_DM_I2C
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000035 return i2c_reg_read(CONFIG_SYS_I2C_FPGA_ADDR, reg);
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080036#else
37 struct udevice *dev;
38
39 if (i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_FPGA_ADDR, 1, &dev))
40 return 0xff;
41
42 return dm_i2c_reg_read(dev, reg);
43#endif
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000044}
45
46void qixis_write_i2c(unsigned int reg, u8 value)
47{
48 u8 val = value;
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080049#ifndef CONFIG_DM_I2C
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000050 i2c_reg_write(CONFIG_SYS_I2C_FPGA_ADDR, reg, val);
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080051#else
52 struct udevice *dev;
53
54 if (!i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_FPGA_ADDR, 1, &dev))
55 dm_i2c_reg_write(dev, reg, val);
56#endif
57
Prabhakar Kushwaha5af1fe22013-01-23 17:59:37 +000058}
59#endif
60
Abhimanyu Saini973a7892016-06-03 18:41:32 +053061#ifdef QIXIS_BASE
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +080062u8 qixis_read(unsigned int reg)
63{
64 void *p = (void *)QIXIS_BASE;
65
66 return in_8(p + reg);
67}
68
69void qixis_write(unsigned int reg, u8 value)
70{
71 void *p = (void *)QIXIS_BASE;
72
73 out_8(p + reg, value);
74}
Abhimanyu Saini973a7892016-06-03 18:41:32 +053075#endif
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +080076
Prabhakar Kushwahaa98dcc72012-12-23 19:24:47 +000077u16 qixis_read_minor(void)
78{
79 u16 minor;
80
81 /* this data is in little endian */
82 QIXIS_WRITE(tagdata, 5);
83 minor = QIXIS_READ(tagdata);
84 QIXIS_WRITE(tagdata, 6);
85 minor += QIXIS_READ(tagdata) << 8;
86
87 return minor;
88}
89
90char *qixis_read_time(char *result)
91{
92 time_t time = 0;
93 int i;
94
95 /* timestamp is in 32-bit big endian */
96 for (i = 8; i <= 11; i++) {
97 QIXIS_WRITE(tagdata, i);
98 time = (time << 8) + QIXIS_READ(tagdata);
99 }
100
101 return ctime_r(&time, result);
102}
103
104char *qixis_read_tag(char *buf)
105{
106 int i;
107 char tag, *ptr = buf;
108
109 for (i = 16; i <= 63; i++) {
110 QIXIS_WRITE(tagdata, i);
111 tag = QIXIS_READ(tagdata);
112 *(ptr++) = tag;
113 if (!tag)
114 break;
115 }
116 if (i > 63)
117 *ptr = '\0';
118
119 return buf;
120}
121
Shaveta Leekha31955b72012-12-23 19:25:35 +0000122/*
123 * return the string of binary of u8 in the format of
124 * 1010 10_0. The masked bit is filled as underscore.
125 */
126const char *byte_to_binary_mask(u8 val, u8 mask, char *buf)
127{
128 char *ptr;
129 int i;
130
131 ptr = buf;
132 for (i = 0x80; i > 0x08 ; i >>= 1, ptr++)
133 *ptr = (val & i) ? '1' : ((mask & i) ? '_' : '0');
134 *(ptr++) = ' ';
135 for (i = 0x08; i > 0 ; i >>= 1, ptr++)
136 *ptr = (val & i) ? '1' : ((mask & i) ? '_' : '0');
137
138 *ptr = '\0';
139
140 return buf;
141}
142
York Sun5e155552013-06-25 11:37:48 -0700143#ifdef QIXIS_RST_FORCE_MEM
144void board_assert_mem_reset(void)
145{
146 u8 rst;
147
148 rst = QIXIS_READ(rst_frc[0]);
149 if (!(rst & QIXIS_RST_FORCE_MEM))
150 QIXIS_WRITE(rst_frc[0], rst | QIXIS_RST_FORCE_MEM);
151}
152
153void board_deassert_mem_reset(void)
154{
155 u8 rst;
156
157 rst = QIXIS_READ(rst_frc[0]);
158 if (rst & QIXIS_RST_FORCE_MEM)
159 QIXIS_WRITE(rst_frc[0], rst & ~QIXIS_RST_FORCE_MEM);
160}
161#endif
162
Tom Rinid5a73852018-01-03 08:57:50 -0500163#ifndef CONFIG_SPL_BUILD
164static void qixis_reset(void)
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800165{
Prabhakar Kushwaha8d0412a2012-09-17 17:30:31 +0000166 QIXIS_WRITE(rst_ctl, QIXIS_RST_CTL_RESET);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800167}
168
Yuantian Tang66e344a2019-06-19 14:39:28 +0800169#ifdef QIXIS_LBMAP_ALTBANK
Tom Rinid5a73852018-01-03 08:57:50 -0500170static void qixis_bank_reset(void)
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800171{
Prabhakar Kushwaha8d0412a2012-09-17 17:30:31 +0000172 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
173 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800174}
Yuantian Tang66e344a2019-06-19 14:39:28 +0800175#endif
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800176
Scott Woodbfee2e72015-03-20 19:28:29 -0700177static void __maybe_unused set_lbmap(int lbmap)
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800178{
179 u8 reg;
180
Abhimanyu Sainie94cc3c2016-06-03 18:41:33 +0530181 reg = QIXIS_READ(brdcfg[QIXIS_LBMAP_BRDCFG_REG]);
Scott Woodbfee2e72015-03-20 19:28:29 -0700182 reg = (reg & ~QIXIS_LBMAP_MASK) | lbmap;
Abhimanyu Sainie94cc3c2016-06-03 18:41:33 +0530183 QIXIS_WRITE(brdcfg[QIXIS_LBMAP_BRDCFG_REG], reg);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800184}
185
Scott Woodbfee2e72015-03-20 19:28:29 -0700186static void __maybe_unused set_rcw_src(int rcw_src)
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800187{
Yuantian Tang66e344a2019-06-19 14:39:28 +0800188#ifdef CONFIG_NXP_LSCH3_2
189 QIXIS_WRITE(dutcfg[0], (rcw_src & 0xff));
190#else
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800191 u8 reg;
192
Scott Woodbfee2e72015-03-20 19:28:29 -0700193 reg = QIXIS_READ(dutcfg[1]);
194 reg = (reg & ~1) | (rcw_src & 1);
195 QIXIS_WRITE(dutcfg[1], reg);
196 QIXIS_WRITE(dutcfg[0], (rcw_src >> 1) & 0xff);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800197#endif
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800198}
199
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800200static void qixis_dump_regs(void)
201{
202 int i;
203
204 printf("id = %02x\n", QIXIS_READ(id));
205 printf("arch = %02x\n", QIXIS_READ(arch));
206 printf("scver = %02x\n", QIXIS_READ(scver));
207 printf("model = %02x\n", QIXIS_READ(model));
208 printf("rst_ctl = %02x\n", QIXIS_READ(rst_ctl));
209 printf("aux = %02x\n", QIXIS_READ(aux));
210 for (i = 0; i < 16; i++)
211 printf("brdcfg%02d = %02x\n", i, QIXIS_READ(brdcfg[i]));
212 for (i = 0; i < 16; i++)
213 printf("dutcfg%02d = %02x\n", i, QIXIS_READ(dutcfg[i]));
214 printf("sclk = %02x%02x%02x\n", QIXIS_READ(sclk[0]),
215 QIXIS_READ(sclk[1]), QIXIS_READ(sclk[2]));
216 printf("dclk = %02x%02x%02x\n", QIXIS_READ(dclk[0]),
217 QIXIS_READ(dclk[1]), QIXIS_READ(dclk[2]));
218 printf("aux = %02x\n", QIXIS_READ(aux));
219 printf("watch = %02x\n", QIXIS_READ(watch));
220 printf("ctl_sys = %02x\n", QIXIS_READ(ctl_sys));
221 printf("rcw_ctl = %02x\n", QIXIS_READ(rcw_ctl));
222 printf("present = %02x\n", QIXIS_READ(present));
Shengzhou Liuc82392d2012-10-07 20:21:02 +0000223 printf("present2 = %02x\n", QIXIS_READ(present2));
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800224 printf("clk_spd = %02x\n", QIXIS_READ(clk_spd));
225 printf("stat_dut = %02x\n", QIXIS_READ(stat_dut));
226 printf("stat_sys = %02x\n", QIXIS_READ(stat_sys));
227 printf("stat_alrm = %02x\n", QIXIS_READ(stat_alrm));
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800228}
Shaveta Leekha31955b72012-12-23 19:25:35 +0000229
Tom Rinid5a73852018-01-03 08:57:50 -0500230void __weak qixis_dump_switch(void)
Shaveta Leekha31955b72012-12-23 19:25:35 +0000231{
232 puts("Reverse engineering switch is not implemented for this board\n");
233}
234
Tom Rinid5a73852018-01-03 08:57:50 -0500235static int qixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800236{
237 int i;
238
239 if (argc <= 1) {
Scott Woodbfee2e72015-03-20 19:28:29 -0700240 set_lbmap(QIXIS_LBMAP_DFLTBANK);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800241 qixis_reset();
242 } else if (strcmp(argv[1], "altbank") == 0) {
Yuantian Tang66e344a2019-06-19 14:39:28 +0800243#ifdef QIXIS_LBMAP_ALTBANK
Scott Woodbfee2e72015-03-20 19:28:29 -0700244 set_lbmap(QIXIS_LBMAP_ALTBANK);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800245 qixis_bank_reset();
Yuantian Tang66e344a2019-06-19 14:39:28 +0800246#else
247 printf("No Altbank!\n");
248#endif
Scott Woodbfee2e72015-03-20 19:28:29 -0700249 } else if (strcmp(argv[1], "nand") == 0) {
250#ifdef QIXIS_LBMAP_NAND
251 QIXIS_WRITE(rst_ctl, 0x30);
252 QIXIS_WRITE(rcfg_ctl, 0);
253 set_lbmap(QIXIS_LBMAP_NAND);
254 set_rcw_src(QIXIS_RCW_SRC_NAND);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800255 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
256 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Scott Woodbfee2e72015-03-20 19:28:29 -0700257#else
258 printf("Not implemented\n");
259#endif
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800260 } else if (strcmp(argv[1], "sd") == 0) {
261#ifdef QIXIS_LBMAP_SD
262 QIXIS_WRITE(rst_ctl, 0x30);
263 QIXIS_WRITE(rcfg_ctl, 0);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000264#ifdef NON_EXTENDED_DUTCFG
265 QIXIS_WRITE(dutcfg[0], QIXIS_RCW_SRC_SD);
266#else
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800267 set_lbmap(QIXIS_LBMAP_SD);
268 set_rcw_src(QIXIS_RCW_SRC_SD);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000269#endif
Yuantian Tang66e344a2019-06-19 14:39:28 +0800270 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
271 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800272#else
273 printf("Not implemented\n");
274#endif
Ashish Kumarb58cdc92018-01-17 12:16:36 +0530275 } else if (strcmp(argv[1], "ifc") == 0) {
276#ifdef QIXIS_LBMAP_IFC
277 QIXIS_WRITE(rst_ctl, 0x30);
278 QIXIS_WRITE(rcfg_ctl, 0);
279 set_lbmap(QIXIS_LBMAP_IFC);
280 set_rcw_src(QIXIS_RCW_SRC_IFC);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800281 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
282 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Ashish Kumarb58cdc92018-01-17 12:16:36 +0530283#else
284 printf("Not implemented\n");
285#endif
286 } else if (strcmp(argv[1], "emmc") == 0) {
287#ifdef QIXIS_LBMAP_EMMC
288 QIXIS_WRITE(rst_ctl, 0x30);
289 QIXIS_WRITE(rcfg_ctl, 0);
290 set_lbmap(QIXIS_LBMAP_EMMC);
291 set_rcw_src(QIXIS_RCW_SRC_EMMC);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800292 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
293 QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
Ashish Kumarb58cdc92018-01-17 12:16:36 +0530294#else
295 printf("Not implemented\n");
296#endif
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800297 } else if (strcmp(argv[1], "sd_qspi") == 0) {
298#ifdef QIXIS_LBMAP_SD_QSPI
299 QIXIS_WRITE(rst_ctl, 0x30);
300 QIXIS_WRITE(rcfg_ctl, 0);
301 set_lbmap(QIXIS_LBMAP_SD_QSPI);
302 set_rcw_src(QIXIS_RCW_SRC_SD);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800303 qixis_write_i2c(offsetof(struct qixis, rcfg_ctl),
304 QIXIS_RCFG_CTL_RECONFIG_IDLE);
305 qixis_write_i2c(offsetof(struct qixis, rcfg_ctl),
306 QIXIS_RCFG_CTL_RECONFIG_START);
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800307#else
308 printf("Not implemented\n");
309#endif
310 } else if (strcmp(argv[1], "qspi") == 0) {
311#ifdef QIXIS_LBMAP_QSPI
312 QIXIS_WRITE(rst_ctl, 0x30);
313 QIXIS_WRITE(rcfg_ctl, 0);
314 set_lbmap(QIXIS_LBMAP_QSPI);
315 set_rcw_src(QIXIS_RCW_SRC_QSPI);
Yuantian Tang66e344a2019-06-19 14:39:28 +0800316 qixis_write_i2c(offsetof(struct qixis, rcfg_ctl),
317 QIXIS_RCFG_CTL_RECONFIG_IDLE);
318 qixis_write_i2c(offsetof(struct qixis, rcfg_ctl),
319 QIXIS_RCFG_CTL_RECONFIG_START);
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800320#else
321 printf("Not implemented\n");
322#endif
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800323 } else if (strcmp(argv[1], "watchdog") == 0) {
324 static char *period[9] = {"2s", "4s", "8s", "16s", "32s",
325 "1min", "2min", "4min", "8min"};
326 u8 rcfg = QIXIS_READ(rcfg_ctl);
327
328 if (argv[2] == NULL) {
329 printf("qixis watchdog <watchdog_period>\n");
330 return 0;
331 }
332 for (i = 0; i < ARRAY_SIZE(period); i++) {
333 if (strcmp(argv[2], period[i]) == 0) {
334 /* disable watchdog */
Prabhakar Kushwaha8d0412a2012-09-17 17:30:31 +0000335 QIXIS_WRITE(rcfg_ctl,
336 rcfg & ~QIXIS_RCFG_CTL_WATCHDOG_ENBLE);
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800337 QIXIS_WRITE(watch, ((i<<2) - 1));
338 QIXIS_WRITE(rcfg_ctl, rcfg);
339 return 0;
340 }
341 }
Shaveta Leekha31955b72012-12-23 19:25:35 +0000342 } else if (strcmp(argv[1], "dump") == 0) {
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800343 qixis_dump_regs();
344 return 0;
Shaveta Leekha31955b72012-12-23 19:25:35 +0000345 } else if (strcmp(argv[1], "switch") == 0) {
346 qixis_dump_switch();
347 return 0;
348 } else {
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800349 printf("Invalid option: %s\n", argv[1]);
350 return 1;
351 }
352
353 return 0;
354}
355
356U_BOOT_CMD(
357 qixis_reset, CONFIG_SYS_MAXARGS, 1, qixis_reset_cmd,
358 "Reset the board using the FPGA sequencer",
359 "- hard reset to default bank\n"
360 "qixis_reset altbank - reset to alternate bank\n"
Scott Woodbfee2e72015-03-20 19:28:29 -0700361 "qixis_reset nand - reset to nand\n"
Gong Qianyu28f5cc42015-12-31 18:29:02 +0800362 "qixis_reset sd - reset to sd\n"
363 "qixis_reset sd_qspi - reset to sd with qspi support\n"
364 "qixis_reset qspi - reset to qspi\n"
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800365 "qixis watchdog <watchdog_period> - set the watchdog period\n"
366 " period: 1s 2s 4s 8s 16s 32s 1min 2min 4min 8min\n"
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800367 "qixis_reset dump - display the QIXIS registers\n"
Shaveta Leekha31955b72012-12-23 19:25:35 +0000368 "qixis_reset switch - display switch\n"
Shengzhou Liu1d6b35c2011-11-22 16:51:13 +0800369 );
Tom Rinid5a73852018-01-03 08:57:50 -0500370#endif