blob: 74c345807e64128a7efa12db09425f0edc2f06b0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Timur Tabi4f332d22010-04-01 10:49:42 -05002/**
Timur Tabi746e2f32011-01-21 16:03:57 -06003 * Copyright 2010-2011 Freescale Semiconductor
Timur Tabi4f332d22010-04-01 10:49:42 -05004 * Author: Timur Tabi <timur@freescale.com>
5 *
Timur Tabi4f332d22010-04-01 10:49:42 -05006 * This file provides support for the ngPIXIS, a board-specific FPGA used on
7 * some Freescale reference boards.
8 *
9 * A "switch" is black rectangular block on the motherboard. It contains
10 * eight "bits". The ngPIXIS has a set of memory-mapped registers (SWx) that
11 * shadow the actual physical switches. There is also another set of
12 * registers (ENx) that tell the ngPIXIS which bits of SWx should actually be
13 * used to override the values of the bits in the physical switches.
14 *
15 * The following macros need to be defined:
16 *
17 * PIXIS_BASE - The virtual address of the base of the PIXIS register map
18 *
19 * PIXIS_LBMAP_SWITCH - The switch number (i.e. the "x" in "SWx"). This value
20 * is used in the PIXIS_SW() macro to determine which offset in
21 * the PIXIS register map corresponds to the physical switch that controls
22 * the boot bank.
23 *
24 * PIXIS_LBMAP_MASK - A bit mask the defines which bits in SWx to use.
25 *
26 * PIXIS_LBMAP_SHIFT - The shift value that corresponds to PIXIS_LBMAP_MASK.
27 *
28 * PIXIS_LBMAP_ALTBANK - The value to program into SWx to tell the ngPIXIS to
29 * boot from the alternate bank.
30 */
31
Timur Tabi4f332d22010-04-01 10:49:42 -050032#include <command.h>
Timur Tabi4f332d22010-04-01 10:49:42 -050033#include <asm/io.h>
34
35#include "ngpixis.h"
36
Timur Tabi746e2f32011-01-21 16:03:57 -060037static u8 __pixis_read(unsigned int reg)
38{
39 void *p = (void *)PIXIS_BASE;
40
41 return in_8(p + reg);
42}
43u8 pixis_read(unsigned int reg) __attribute__((weak, alias("__pixis_read")));
44
45static void __pixis_write(unsigned int reg, u8 value)
46{
47 void *p = (void *)PIXIS_BASE;
48
49 out_8(p + reg, value);
50}
51void pixis_write(unsigned int reg, u8 value)
52 __attribute__((weak, alias("__pixis_write")));
53
Timur Tabi4f332d22010-04-01 10:49:42 -050054/*
55 * Reset the board. This ignores the ENx registers.
56 */
Timur Tabi746e2f32011-01-21 16:03:57 -060057void __pixis_reset(void)
Timur Tabi4f332d22010-04-01 10:49:42 -050058{
Timur Tabi746e2f32011-01-21 16:03:57 -060059 PIXIS_WRITE(rst, 0);
Timur Tabi4f332d22010-04-01 10:49:42 -050060
61 while (1);
62}
Timur Tabi746e2f32011-01-21 16:03:57 -060063void pixis_reset(void) __attribute__((weak, alias("__pixis_reset")));
Timur Tabi4f332d22010-04-01 10:49:42 -050064
65/*
66 * Reset the board. Like pixis_reset(), but it honors the ENx registers.
67 */
Timur Tabi746e2f32011-01-21 16:03:57 -060068void __pixis_bank_reset(void)
Timur Tabi4f332d22010-04-01 10:49:42 -050069{
Timur Tabi746e2f32011-01-21 16:03:57 -060070 PIXIS_WRITE(vctl, 0);
71 PIXIS_WRITE(vctl, 1);
Timur Tabi4f332d22010-04-01 10:49:42 -050072
73 while (1);
74}
Timur Tabi746e2f32011-01-21 16:03:57 -060075void pixis_bank_reset(void) __attribute__((weak, alias("__pixis_bank_reset")));
Timur Tabi4f332d22010-04-01 10:49:42 -050076
77/**
78 * Set the boot bank to the power-on default bank
79 */
Timur Tabi746e2f32011-01-21 16:03:57 -060080void __clear_altbank(void)
Timur Tabi4f332d22010-04-01 10:49:42 -050081{
Timur Tabi746e2f32011-01-21 16:03:57 -060082 u8 reg;
83
Timur Tabi4f332d22010-04-01 10:49:42 -050084 /* Tell the ngPIXIS to use this the bits in the physical switch for the
85 * boot bank value, instead of the SWx register. We need to be careful
86 * only to set the bits in SWx that correspond to the boot bank.
87 */
Timur Tabi746e2f32011-01-21 16:03:57 -060088 reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en);
89 reg &= ~PIXIS_LBMAP_MASK;
90 PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg);
Timur Tabi4f332d22010-04-01 10:49:42 -050091}
Timur Tabi746e2f32011-01-21 16:03:57 -060092void clear_altbank(void) __attribute__((weak, alias("__clear_altbank")));
Timur Tabi4f332d22010-04-01 10:49:42 -050093
94/**
95 * Set the boot bank to the alternate bank
96 */
Timur Tabi746e2f32011-01-21 16:03:57 -060097void __set_altbank(void)
Timur Tabi4f332d22010-04-01 10:49:42 -050098{
Timur Tabi746e2f32011-01-21 16:03:57 -060099 u8 reg;
100
Timur Tabi4f332d22010-04-01 10:49:42 -0500101 /* Program the alternate bank number into the SWx register.
102 */
Timur Tabi746e2f32011-01-21 16:03:57 -0600103 reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].sw);
104 reg = (reg & ~PIXIS_LBMAP_MASK) | PIXIS_LBMAP_ALTBANK;
105 PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].sw, reg);
Timur Tabi4f332d22010-04-01 10:49:42 -0500106
107 /* Tell the ngPIXIS to use this the bits in the SWx register for the
108 * boot bank value, instead of the physical switch. We need to be
109 * careful only to set the bits in SWx that correspond to the boot bank.
110 */
Timur Tabi746e2f32011-01-21 16:03:57 -0600111 reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en);
112 reg |= PIXIS_LBMAP_MASK;
113 PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg);
Timur Tabi4f332d22010-04-01 10:49:42 -0500114}
Timur Tabi746e2f32011-01-21 16:03:57 -0600115void set_altbank(void) __attribute__((weak, alias("__set_altbank")));
Timur Tabi4f332d22010-04-01 10:49:42 -0500116
Timur Tabi093bf2d2011-02-09 16:28:48 -0600117#ifdef DEBUG
118static void pixis_dump_regs(void)
119{
120 unsigned int i;
121
122 printf("id=%02x\n", PIXIS_READ(id));
123 printf("arch=%02x\n", PIXIS_READ(arch));
124 printf("scver=%02x\n", PIXIS_READ(scver));
125 printf("csr=%02x\n", PIXIS_READ(csr));
126 printf("rst=%02x\n", PIXIS_READ(rst));
127 printf("aux=%02x\n", PIXIS_READ(aux));
128 printf("spd=%02x\n", PIXIS_READ(spd));
129 printf("brdcfg0=%02x\n", PIXIS_READ(brdcfg0));
130 printf("brdcfg1=%02x\n", PIXIS_READ(brdcfg1));
131 printf("addr=%02x\n", PIXIS_READ(addr));
132 printf("data=%02x\n", PIXIS_READ(data));
133 printf("led=%02x\n", PIXIS_READ(led));
134 printf("vctl=%02x\n", PIXIS_READ(vctl));
135 printf("vstat=%02x\n", PIXIS_READ(vstat));
136 printf("vcfgen0=%02x\n", PIXIS_READ(vcfgen0));
137 printf("ocmcsr=%02x\n", PIXIS_READ(ocmcsr));
138 printf("ocmmsg=%02x\n", PIXIS_READ(ocmmsg));
139 printf("gmdbg=%02x\n", PIXIS_READ(gmdbg));
140 printf("sclk=%02x%02x%02x\n",
141 PIXIS_READ(sclk[0]), PIXIS_READ(sclk[1]), PIXIS_READ(sclk[2]));
142 printf("dclk=%02x%02x%02x\n",
143 PIXIS_READ(dclk[0]), PIXIS_READ(dclk[1]), PIXIS_READ(dclk[2]));
144 printf("watch=%02x\n", PIXIS_READ(watch));
145
146 for (i = 0; i < 8; i++) {
147 printf("SW%u=%02x/%02x ", i + 1,
148 PIXIS_READ(s[i].sw), PIXIS_READ(s[i].en));
149 }
150 putc('\n');
151}
152#endif
Timur Tabi4f332d22010-04-01 10:49:42 -0500153
Jerry Huangc0b43cf2011-11-03 15:18:06 +0800154void pixis_sysclk_set(unsigned long sysclk)
155{
156 unsigned long freq_word;
157 u8 sclk0, sclk1, sclk2;
158
159 freq_word = ics307_sysclk_calculator(sysclk);
160 sclk2 = freq_word & 0xff;
161 sclk1 = (freq_word >> 8) & 0xff;
162 sclk0 = (freq_word >> 16) & 0xff;
163
164 /* set SYSCLK enable bit */
165 PIXIS_WRITE(vcfgen0, 0x01);
166
167 /* SYSCLK to required frequency */
168 PIXIS_WRITE(sclk[0], sclk0);
169 PIXIS_WRITE(sclk[1], sclk1);
170 PIXIS_WRITE(sclk[2], sclk2);
171}
172
Simon Glassed38aef2020-05-10 11:40:03 -0600173int pixis_reset_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
174 char *const argv[])
Timur Tabi4f332d22010-04-01 10:49:42 -0500175{
176 unsigned int i;
Jerry Huangc0b43cf2011-11-03 15:18:06 +0800177 unsigned long sysclk;
Timur Tabi4f332d22010-04-01 10:49:42 -0500178 char *p_altbank = NULL;
Timur Tabi093bf2d2011-02-09 16:28:48 -0600179#ifdef DEBUG
180 char *p_dump = NULL;
181#endif
Timur Tabi4f332d22010-04-01 10:49:42 -0500182 char *unknown_param = NULL;
183
184 /* No args is a simple reset request.
185 */
186 if (argc <= 1)
187 pixis_reset();
188
189 for (i = 1; i < argc; i++) {
190 if (strcmp(argv[i], "altbank") == 0) {
191 p_altbank = argv[i];
192 continue;
193 }
194
Timur Tabi093bf2d2011-02-09 16:28:48 -0600195#ifdef DEBUG
196 if (strcmp(argv[i], "dump") == 0) {
197 p_dump = argv[i];
198 continue;
199 }
200#endif
Jerry Huangc0b43cf2011-11-03 15:18:06 +0800201 if (strcmp(argv[i], "sysclk") == 0) {
202 sysclk = simple_strtoul(argv[i + 1], NULL, 0);
203 i += 1;
204 pixis_sysclk_set(sysclk);
205 continue;
206 }
Timur Tabi093bf2d2011-02-09 16:28:48 -0600207
Timur Tabi4f332d22010-04-01 10:49:42 -0500208 unknown_param = argv[i];
209 }
210
211 if (unknown_param) {
212 printf("Invalid option: %s\n", unknown_param);
213 return 1;
214 }
215
Timur Tabi093bf2d2011-02-09 16:28:48 -0600216#ifdef DEBUG
217 if (p_dump) {
218 pixis_dump_regs();
219
220 /* 'dump' ignores other commands */
221 return 0;
222 }
223#endif
224
Timur Tabi4f332d22010-04-01 10:49:42 -0500225 if (p_altbank)
226 set_altbank();
227 else
228 clear_altbank();
229
230 pixis_bank_reset();
231
232 /* Shouldn't be reached. */
233 return 0;
234}
235
Tom Rini03f146c2023-10-07 15:13:08 -0400236U_BOOT_LONGHELP(pixis,
Timur Tabi4f332d22010-04-01 10:49:42 -0500237 "- hard reset to default bank\n"
238 "pixis_reset altbank - reset to alternate bank\n"
Timur Tabi093bf2d2011-02-09 16:28:48 -0600239#ifdef DEBUG
240 "pixis_reset dump - display the PIXIS registers\n"
241#endif
Tom Rini03f146c2023-10-07 15:13:08 -0400242 "pixis_reset sysclk <SYSCLK_freq> - reset with SYSCLK frequency(KHz)\n");
Kim Phillips402673f2012-10-29 13:34:38 +0000243
244U_BOOT_CMD(
245 pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
246 "Reset the board using the FPGA sequencer", pixis_help_text
Timur Tabi4f332d22010-04-01 10:49:42 -0500247 );