1*5a469608STimur Tabi /**
2*5a469608STimur Tabi  * Copyright 2010 Freescale Semiconductor
3*5a469608STimur Tabi  * Author: Timur Tabi <timur@freescale.com>
4*5a469608STimur Tabi  *
5*5a469608STimur Tabi  * This program is free software; you can redistribute it and/or modify it
6*5a469608STimur Tabi  * under the terms of the GNU General Public License as published by the Free
7*5a469608STimur Tabi  * Software Foundation; either version 2 of the License, or (at your option)
8*5a469608STimur Tabi  * any later version.
9*5a469608STimur Tabi  *
10*5a469608STimur Tabi  * This file provides support for the ngPIXIS, a board-specific FPGA used on
11*5a469608STimur Tabi  * some Freescale reference boards.
12*5a469608STimur Tabi  *
13*5a469608STimur Tabi  * A "switch" is black rectangular block on the motherboard.  It contains
14*5a469608STimur Tabi  * eight "bits".  The ngPIXIS has a set of memory-mapped registers (SWx) that
15*5a469608STimur Tabi  * shadow the actual physical switches.  There is also another set of
16*5a469608STimur Tabi  * registers (ENx) that tell the ngPIXIS which bits of SWx should actually be
17*5a469608STimur Tabi  * used to override the values of the bits in the physical switches.
18*5a469608STimur Tabi  *
19*5a469608STimur Tabi  * The following macros need to be defined:
20*5a469608STimur Tabi  *
21*5a469608STimur Tabi  * PIXIS_BASE - The virtual address of the base of the PIXIS register map
22*5a469608STimur Tabi  *
23*5a469608STimur Tabi  * PIXIS_LBMAP_SWITCH - The switch number (i.e. the "x" in "SWx"). This value
24*5a469608STimur Tabi  *    is used in the PIXIS_SW() macro to determine which offset in
25*5a469608STimur Tabi  *    the PIXIS register map corresponds to the physical switch that controls
26*5a469608STimur Tabi  *    the boot bank.
27*5a469608STimur Tabi  *
28*5a469608STimur Tabi  * PIXIS_LBMAP_MASK - A bit mask the defines which bits in SWx to use.
29*5a469608STimur Tabi  *
30*5a469608STimur Tabi  * PIXIS_LBMAP_SHIFT - The shift value that corresponds to PIXIS_LBMAP_MASK.
31*5a469608STimur Tabi  *
32*5a469608STimur Tabi  * PIXIS_LBMAP_ALTBANK - The value to program into SWx to tell the ngPIXIS to
33*5a469608STimur Tabi  *    boot from the alternate bank.
34*5a469608STimur Tabi  */
35*5a469608STimur Tabi 
36*5a469608STimur Tabi #include <common.h>
37*5a469608STimur Tabi #include <command.h>
38*5a469608STimur Tabi #include <watchdog.h>
39*5a469608STimur Tabi #include <asm/cache.h>
40*5a469608STimur Tabi #include <asm/io.h>
41*5a469608STimur Tabi 
42*5a469608STimur Tabi #include "ngpixis.h"
43*5a469608STimur Tabi 
44*5a469608STimur Tabi /*
45*5a469608STimur Tabi  * Reset the board. This ignores the ENx registers.
46*5a469608STimur Tabi  */
47*5a469608STimur Tabi void pixis_reset(void)
48*5a469608STimur Tabi {
49*5a469608STimur Tabi 	out_8(&pixis->rst, 0);
50*5a469608STimur Tabi 
51*5a469608STimur Tabi 	while (1);
52*5a469608STimur Tabi }
53*5a469608STimur Tabi 
54*5a469608STimur Tabi /*
55*5a469608STimur Tabi  * Reset the board.  Like pixis_reset(), but it honors the ENx registers.
56*5a469608STimur Tabi  */
57*5a469608STimur Tabi void pixis_bank_reset(void)
58*5a469608STimur Tabi {
59*5a469608STimur Tabi 	out_8(&pixis->vctl, 0);
60*5a469608STimur Tabi 	out_8(&pixis->vctl, 1);
61*5a469608STimur Tabi 
62*5a469608STimur Tabi 	while (1);
63*5a469608STimur Tabi }
64*5a469608STimur Tabi 
65*5a469608STimur Tabi /**
66*5a469608STimur Tabi  * Set the boot bank to the power-on default bank
67*5a469608STimur Tabi  */
68*5a469608STimur Tabi void clear_altbank(void)
69*5a469608STimur Tabi {
70*5a469608STimur Tabi 	/* Tell the ngPIXIS to use this the bits in the physical switch for the
71*5a469608STimur Tabi 	 * boot bank value, instead of the SWx register.  We need to be careful
72*5a469608STimur Tabi 	 * only to set the bits in SWx that correspond to the boot bank.
73*5a469608STimur Tabi 	 */
74*5a469608STimur Tabi 	clrbits_8(&PIXIS_EN(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK);
75*5a469608STimur Tabi }
76*5a469608STimur Tabi 
77*5a469608STimur Tabi /**
78*5a469608STimur Tabi  * Set the boot bank to the alternate bank
79*5a469608STimur Tabi  */
80*5a469608STimur Tabi void set_altbank(void)
81*5a469608STimur Tabi {
82*5a469608STimur Tabi 	/* Program the alternate bank number into the SWx register.
83*5a469608STimur Tabi 	 */
84*5a469608STimur Tabi 	clrsetbits_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK,
85*5a469608STimur Tabi 		     PIXIS_LBMAP_ALTBANK);
86*5a469608STimur Tabi 
87*5a469608STimur Tabi 	/* Tell the ngPIXIS to use this the bits in the SWx register for the
88*5a469608STimur Tabi 	 * boot bank value, instead of the physical switch.  We need to be
89*5a469608STimur Tabi 	 * careful only to set the bits in SWx that correspond to the boot bank.
90*5a469608STimur Tabi 	 */
91*5a469608STimur Tabi 	setbits_8(&PIXIS_EN(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK);
92*5a469608STimur Tabi }
93*5a469608STimur Tabi 
94*5a469608STimur Tabi 
95*5a469608STimur Tabi int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
96*5a469608STimur Tabi {
97*5a469608STimur Tabi 	unsigned int i;
98*5a469608STimur Tabi 	char *p_altbank = NULL;
99*5a469608STimur Tabi 	char *unknown_param = NULL;
100*5a469608STimur Tabi 
101*5a469608STimur Tabi 	/* No args is a simple reset request.
102*5a469608STimur Tabi 	 */
103*5a469608STimur Tabi 	if (argc <= 1)
104*5a469608STimur Tabi 		pixis_reset();
105*5a469608STimur Tabi 
106*5a469608STimur Tabi 	for (i = 1; i < argc; i++) {
107*5a469608STimur Tabi 		if (strcmp(argv[i], "altbank") == 0) {
108*5a469608STimur Tabi 			p_altbank = argv[i];
109*5a469608STimur Tabi 			continue;
110*5a469608STimur Tabi 		}
111*5a469608STimur Tabi 
112*5a469608STimur Tabi 		unknown_param = argv[i];
113*5a469608STimur Tabi 	}
114*5a469608STimur Tabi 
115*5a469608STimur Tabi 	if (unknown_param) {
116*5a469608STimur Tabi 		printf("Invalid option: %s\n", unknown_param);
117*5a469608STimur Tabi 		return 1;
118*5a469608STimur Tabi 	}
119*5a469608STimur Tabi 
120*5a469608STimur Tabi 	if (p_altbank)
121*5a469608STimur Tabi 		set_altbank();
122*5a469608STimur Tabi 	else
123*5a469608STimur Tabi 		clear_altbank();
124*5a469608STimur Tabi 
125*5a469608STimur Tabi 	pixis_bank_reset();
126*5a469608STimur Tabi 
127*5a469608STimur Tabi 	/* Shouldn't be reached. */
128*5a469608STimur Tabi 	return 0;
129*5a469608STimur Tabi }
130*5a469608STimur Tabi 
131*5a469608STimur Tabi U_BOOT_CMD(
132*5a469608STimur Tabi 	pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
133*5a469608STimur Tabi 	"Reset the board using the FPGA sequencer",
134*5a469608STimur Tabi 	"- hard reset to default bank\n"
135*5a469608STimur Tabi 	"pixis_reset altbank - reset to alternate bank\n"
136*5a469608STimur Tabi 	);
137