blob: 4e01e5a0a2e6660eb202b5d9514c8ac4876ad788 [file] [log] [blame]
Timur Tabi5a469602010-04-01 10:49:42 -05001/**
Timur Tabiaa8d3fb2011-01-21 16:03:57 -06002 * Copyright 2010-2011 Freescale Semiconductor
Timur Tabi5a469602010-04-01 10:49:42 -05003 * Author: Timur Tabi <timur@freescale.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This file provides support for the ngPIXIS, a board-specific FPGA used on
11 * some Freescale reference boards.
12 *
13 * A "switch" is black rectangular block on the motherboard. It contains
14 * eight "bits". The ngPIXIS has a set of memory-mapped registers (SWx) that
15 * shadow the actual physical switches. There is also another set of
16 * registers (ENx) that tell the ngPIXIS which bits of SWx should actually be
17 * used to override the values of the bits in the physical switches.
18 *
19 * The following macros need to be defined:
20 *
21 * PIXIS_BASE - The virtual address of the base of the PIXIS register map
22 *
23 * PIXIS_LBMAP_SWITCH - The switch number (i.e. the "x" in "SWx"). This value
24 * is used in the PIXIS_SW() macro to determine which offset in
25 * the PIXIS register map corresponds to the physical switch that controls
26 * the boot bank.
27 *
28 * PIXIS_LBMAP_MASK - A bit mask the defines which bits in SWx to use.
29 *
30 * PIXIS_LBMAP_SHIFT - The shift value that corresponds to PIXIS_LBMAP_MASK.
31 *
32 * PIXIS_LBMAP_ALTBANK - The value to program into SWx to tell the ngPIXIS to
33 * boot from the alternate bank.
34 */
35
36#include <common.h>
37#include <command.h>
Timur Tabi5a469602010-04-01 10:49:42 -050038#include <asm/io.h>
39
40#include "ngpixis.h"
41
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060042static u8 __pixis_read(unsigned int reg)
43{
44 void *p = (void *)PIXIS_BASE;
45
46 return in_8(p + reg);
47}
48u8 pixis_read(unsigned int reg) __attribute__((weak, alias("__pixis_read")));
49
50static void __pixis_write(unsigned int reg, u8 value)
51{
52 void *p = (void *)PIXIS_BASE;
53
54 out_8(p + reg, value);
55}
56void pixis_write(unsigned int reg, u8 value)
57 __attribute__((weak, alias("__pixis_write")));
58
Timur Tabi5a469602010-04-01 10:49:42 -050059/*
60 * Reset the board. This ignores the ENx registers.
61 */
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060062void __pixis_reset(void)
Timur Tabi5a469602010-04-01 10:49:42 -050063{
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060064 PIXIS_WRITE(rst, 0);
Timur Tabi5a469602010-04-01 10:49:42 -050065
66 while (1);
67}
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060068void pixis_reset(void) __attribute__((weak, alias("__pixis_reset")));
Timur Tabi5a469602010-04-01 10:49:42 -050069
70/*
71 * Reset the board. Like pixis_reset(), but it honors the ENx registers.
72 */
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060073void __pixis_bank_reset(void)
Timur Tabi5a469602010-04-01 10:49:42 -050074{
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060075 PIXIS_WRITE(vctl, 0);
76 PIXIS_WRITE(vctl, 1);
Timur Tabi5a469602010-04-01 10:49:42 -050077
78 while (1);
79}
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060080void pixis_bank_reset(void) __attribute__((weak, alias("__pixis_bank_reset")));
Timur Tabi5a469602010-04-01 10:49:42 -050081
82/**
83 * Set the boot bank to the power-on default bank
84 */
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060085void __clear_altbank(void)
Timur Tabi5a469602010-04-01 10:49:42 -050086{
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060087 u8 reg;
88
Timur Tabi5a469602010-04-01 10:49:42 -050089 /* Tell the ngPIXIS to use this the bits in the physical switch for the
90 * boot bank value, instead of the SWx register. We need to be careful
91 * only to set the bits in SWx that correspond to the boot bank.
92 */
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060093 reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en);
94 reg &= ~PIXIS_LBMAP_MASK;
95 PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg);
Timur Tabi5a469602010-04-01 10:49:42 -050096}
Timur Tabiaa8d3fb2011-01-21 16:03:57 -060097void clear_altbank(void) __attribute__((weak, alias("__clear_altbank")));
Timur Tabi5a469602010-04-01 10:49:42 -050098
99/**
100 * Set the boot bank to the alternate bank
101 */
Timur Tabiaa8d3fb2011-01-21 16:03:57 -0600102void __set_altbank(void)
Timur Tabi5a469602010-04-01 10:49:42 -0500103{
Timur Tabiaa8d3fb2011-01-21 16:03:57 -0600104 u8 reg;
105
Timur Tabi5a469602010-04-01 10:49:42 -0500106 /* Program the alternate bank number into the SWx register.
107 */
Timur Tabiaa8d3fb2011-01-21 16:03:57 -0600108 reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].sw);
109 reg = (reg & ~PIXIS_LBMAP_MASK) | PIXIS_LBMAP_ALTBANK;
110 PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].sw, reg);
Timur Tabi5a469602010-04-01 10:49:42 -0500111
112 /* Tell the ngPIXIS to use this the bits in the SWx register for the
113 * boot bank value, instead of the physical switch. We need to be
114 * careful only to set the bits in SWx that correspond to the boot bank.
115 */
Timur Tabiaa8d3fb2011-01-21 16:03:57 -0600116 reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en);
117 reg |= PIXIS_LBMAP_MASK;
118 PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg);
Timur Tabi5a469602010-04-01 10:49:42 -0500119}
Timur Tabiaa8d3fb2011-01-21 16:03:57 -0600120void set_altbank(void) __attribute__((weak, alias("__set_altbank")));
Timur Tabi5a469602010-04-01 10:49:42 -0500121
122
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200123int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Timur Tabi5a469602010-04-01 10:49:42 -0500124{
125 unsigned int i;
126 char *p_altbank = NULL;
127 char *unknown_param = NULL;
128
129 /* No args is a simple reset request.
130 */
131 if (argc <= 1)
132 pixis_reset();
133
134 for (i = 1; i < argc; i++) {
135 if (strcmp(argv[i], "altbank") == 0) {
136 p_altbank = argv[i];
137 continue;
138 }
139
140 unknown_param = argv[i];
141 }
142
143 if (unknown_param) {
144 printf("Invalid option: %s\n", unknown_param);
145 return 1;
146 }
147
148 if (p_altbank)
149 set_altbank();
150 else
151 clear_altbank();
152
153 pixis_bank_reset();
154
155 /* Shouldn't be reached. */
156 return 0;
157}
158
159U_BOOT_CMD(
160 pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
161 "Reset the board using the FPGA sequencer",
162 "- hard reset to default bank\n"
163 "pixis_reset altbank - reset to alternate bank\n"
164 );