15a469608STimur Tabi /** 2aa8d3fb8STimur Tabi * Copyright 2010-2011 Freescale Semiconductor 35a469608STimur Tabi * Author: Timur Tabi <timur@freescale.com> 45a469608STimur Tabi * 55a469608STimur Tabi * This program is free software; you can redistribute it and/or modify it 65a469608STimur Tabi * under the terms of the GNU General Public License as published by the Free 75a469608STimur Tabi * Software Foundation; either version 2 of the License, or (at your option) 85a469608STimur Tabi * any later version. 95a469608STimur Tabi * 105a469608STimur Tabi * This file provides support for the ngPIXIS, a board-specific FPGA used on 115a469608STimur Tabi * some Freescale reference boards. 125a469608STimur Tabi * 135a469608STimur Tabi * A "switch" is black rectangular block on the motherboard. It contains 145a469608STimur Tabi * eight "bits". The ngPIXIS has a set of memory-mapped registers (SWx) that 155a469608STimur Tabi * shadow the actual physical switches. There is also another set of 165a469608STimur Tabi * registers (ENx) that tell the ngPIXIS which bits of SWx should actually be 175a469608STimur Tabi * used to override the values of the bits in the physical switches. 185a469608STimur Tabi * 195a469608STimur Tabi * The following macros need to be defined: 205a469608STimur Tabi * 215a469608STimur Tabi * PIXIS_BASE - The virtual address of the base of the PIXIS register map 225a469608STimur Tabi * 235a469608STimur Tabi * PIXIS_LBMAP_SWITCH - The switch number (i.e. the "x" in "SWx"). This value 245a469608STimur Tabi * is used in the PIXIS_SW() macro to determine which offset in 255a469608STimur Tabi * the PIXIS register map corresponds to the physical switch that controls 265a469608STimur Tabi * the boot bank. 275a469608STimur Tabi * 285a469608STimur Tabi * PIXIS_LBMAP_MASK - A bit mask the defines which bits in SWx to use. 295a469608STimur Tabi * 305a469608STimur Tabi * PIXIS_LBMAP_SHIFT - The shift value that corresponds to PIXIS_LBMAP_MASK. 315a469608STimur Tabi * 325a469608STimur Tabi * PIXIS_LBMAP_ALTBANK - The value to program into SWx to tell the ngPIXIS to 335a469608STimur Tabi * boot from the alternate bank. 345a469608STimur Tabi */ 355a469608STimur Tabi 365a469608STimur Tabi #include <common.h> 375a469608STimur Tabi #include <command.h> 385a469608STimur Tabi #include <asm/io.h> 395a469608STimur Tabi 405a469608STimur Tabi #include "ngpixis.h" 415a469608STimur Tabi 42aa8d3fb8STimur Tabi static u8 __pixis_read(unsigned int reg) 43aa8d3fb8STimur Tabi { 44aa8d3fb8STimur Tabi void *p = (void *)PIXIS_BASE; 45aa8d3fb8STimur Tabi 46aa8d3fb8STimur Tabi return in_8(p + reg); 47aa8d3fb8STimur Tabi } 48aa8d3fb8STimur Tabi u8 pixis_read(unsigned int reg) __attribute__((weak, alias("__pixis_read"))); 49aa8d3fb8STimur Tabi 50aa8d3fb8STimur Tabi static void __pixis_write(unsigned int reg, u8 value) 51aa8d3fb8STimur Tabi { 52aa8d3fb8STimur Tabi void *p = (void *)PIXIS_BASE; 53aa8d3fb8STimur Tabi 54aa8d3fb8STimur Tabi out_8(p + reg, value); 55aa8d3fb8STimur Tabi } 56aa8d3fb8STimur Tabi void pixis_write(unsigned int reg, u8 value) 57aa8d3fb8STimur Tabi __attribute__((weak, alias("__pixis_write"))); 58aa8d3fb8STimur Tabi 595a469608STimur Tabi /* 605a469608STimur Tabi * Reset the board. This ignores the ENx registers. 615a469608STimur Tabi */ 62aa8d3fb8STimur Tabi void __pixis_reset(void) 635a469608STimur Tabi { 64aa8d3fb8STimur Tabi PIXIS_WRITE(rst, 0); 655a469608STimur Tabi 665a469608STimur Tabi while (1); 675a469608STimur Tabi } 68aa8d3fb8STimur Tabi void pixis_reset(void) __attribute__((weak, alias("__pixis_reset"))); 695a469608STimur Tabi 705a469608STimur Tabi /* 715a469608STimur Tabi * Reset the board. Like pixis_reset(), but it honors the ENx registers. 725a469608STimur Tabi */ 73aa8d3fb8STimur Tabi void __pixis_bank_reset(void) 745a469608STimur Tabi { 75aa8d3fb8STimur Tabi PIXIS_WRITE(vctl, 0); 76aa8d3fb8STimur Tabi PIXIS_WRITE(vctl, 1); 775a469608STimur Tabi 785a469608STimur Tabi while (1); 795a469608STimur Tabi } 80aa8d3fb8STimur Tabi void pixis_bank_reset(void) __attribute__((weak, alias("__pixis_bank_reset"))); 815a469608STimur Tabi 825a469608STimur Tabi /** 835a469608STimur Tabi * Set the boot bank to the power-on default bank 845a469608STimur Tabi */ 85aa8d3fb8STimur Tabi void __clear_altbank(void) 865a469608STimur Tabi { 87aa8d3fb8STimur Tabi u8 reg; 88aa8d3fb8STimur Tabi 895a469608STimur Tabi /* Tell the ngPIXIS to use this the bits in the physical switch for the 905a469608STimur Tabi * boot bank value, instead of the SWx register. We need to be careful 915a469608STimur Tabi * only to set the bits in SWx that correspond to the boot bank. 925a469608STimur Tabi */ 93aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en); 94aa8d3fb8STimur Tabi reg &= ~PIXIS_LBMAP_MASK; 95aa8d3fb8STimur Tabi PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg); 965a469608STimur Tabi } 97aa8d3fb8STimur Tabi void clear_altbank(void) __attribute__((weak, alias("__clear_altbank"))); 985a469608STimur Tabi 995a469608STimur Tabi /** 1005a469608STimur Tabi * Set the boot bank to the alternate bank 1015a469608STimur Tabi */ 102aa8d3fb8STimur Tabi void __set_altbank(void) 1035a469608STimur Tabi { 104aa8d3fb8STimur Tabi u8 reg; 105aa8d3fb8STimur Tabi 1065a469608STimur Tabi /* Program the alternate bank number into the SWx register. 1075a469608STimur Tabi */ 108aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].sw); 109aa8d3fb8STimur Tabi reg = (reg & ~PIXIS_LBMAP_MASK) | PIXIS_LBMAP_ALTBANK; 110aa8d3fb8STimur Tabi PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].sw, reg); 1115a469608STimur Tabi 1125a469608STimur Tabi /* Tell the ngPIXIS to use this the bits in the SWx register for the 1135a469608STimur Tabi * boot bank value, instead of the physical switch. We need to be 1145a469608STimur Tabi * careful only to set the bits in SWx that correspond to the boot bank. 1155a469608STimur Tabi */ 116aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en); 117aa8d3fb8STimur Tabi reg |= PIXIS_LBMAP_MASK; 118aa8d3fb8STimur Tabi PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg); 1195a469608STimur Tabi } 120aa8d3fb8STimur Tabi void set_altbank(void) __attribute__((weak, alias("__set_altbank"))); 1215a469608STimur Tabi 122*82c9dfdcSTimur Tabi #ifdef DEBUG 123*82c9dfdcSTimur Tabi static void pixis_dump_regs(void) 124*82c9dfdcSTimur Tabi { 125*82c9dfdcSTimur Tabi unsigned int i; 126*82c9dfdcSTimur Tabi 127*82c9dfdcSTimur Tabi printf("id=%02x\n", PIXIS_READ(id)); 128*82c9dfdcSTimur Tabi printf("arch=%02x\n", PIXIS_READ(arch)); 129*82c9dfdcSTimur Tabi printf("scver=%02x\n", PIXIS_READ(scver)); 130*82c9dfdcSTimur Tabi printf("csr=%02x\n", PIXIS_READ(csr)); 131*82c9dfdcSTimur Tabi printf("rst=%02x\n", PIXIS_READ(rst)); 132*82c9dfdcSTimur Tabi printf("aux=%02x\n", PIXIS_READ(aux)); 133*82c9dfdcSTimur Tabi printf("spd=%02x\n", PIXIS_READ(spd)); 134*82c9dfdcSTimur Tabi printf("brdcfg0=%02x\n", PIXIS_READ(brdcfg0)); 135*82c9dfdcSTimur Tabi printf("brdcfg1=%02x\n", PIXIS_READ(brdcfg1)); 136*82c9dfdcSTimur Tabi printf("addr=%02x\n", PIXIS_READ(addr)); 137*82c9dfdcSTimur Tabi printf("data=%02x\n", PIXIS_READ(data)); 138*82c9dfdcSTimur Tabi printf("led=%02x\n", PIXIS_READ(led)); 139*82c9dfdcSTimur Tabi printf("vctl=%02x\n", PIXIS_READ(vctl)); 140*82c9dfdcSTimur Tabi printf("vstat=%02x\n", PIXIS_READ(vstat)); 141*82c9dfdcSTimur Tabi printf("vcfgen0=%02x\n", PIXIS_READ(vcfgen0)); 142*82c9dfdcSTimur Tabi printf("ocmcsr=%02x\n", PIXIS_READ(ocmcsr)); 143*82c9dfdcSTimur Tabi printf("ocmmsg=%02x\n", PIXIS_READ(ocmmsg)); 144*82c9dfdcSTimur Tabi printf("gmdbg=%02x\n", PIXIS_READ(gmdbg)); 145*82c9dfdcSTimur Tabi printf("sclk=%02x%02x%02x\n", 146*82c9dfdcSTimur Tabi PIXIS_READ(sclk[0]), PIXIS_READ(sclk[1]), PIXIS_READ(sclk[2])); 147*82c9dfdcSTimur Tabi printf("dclk=%02x%02x%02x\n", 148*82c9dfdcSTimur Tabi PIXIS_READ(dclk[0]), PIXIS_READ(dclk[1]), PIXIS_READ(dclk[2])); 149*82c9dfdcSTimur Tabi printf("watch=%02x\n", PIXIS_READ(watch)); 150*82c9dfdcSTimur Tabi 151*82c9dfdcSTimur Tabi for (i = 0; i < 8; i++) { 152*82c9dfdcSTimur Tabi printf("SW%u=%02x/%02x ", i + 1, 153*82c9dfdcSTimur Tabi PIXIS_READ(s[i].sw), PIXIS_READ(s[i].en)); 154*82c9dfdcSTimur Tabi } 155*82c9dfdcSTimur Tabi putc('\n'); 156*82c9dfdcSTimur Tabi } 157*82c9dfdcSTimur Tabi #endif 1585a469608STimur Tabi 15954841ab5SWolfgang Denk int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 1605a469608STimur Tabi { 1615a469608STimur Tabi unsigned int i; 1625a469608STimur Tabi char *p_altbank = NULL; 163*82c9dfdcSTimur Tabi #ifdef DEBUG 164*82c9dfdcSTimur Tabi char *p_dump = NULL; 165*82c9dfdcSTimur Tabi #endif 1665a469608STimur Tabi char *unknown_param = NULL; 1675a469608STimur Tabi 1685a469608STimur Tabi /* No args is a simple reset request. 1695a469608STimur Tabi */ 1705a469608STimur Tabi if (argc <= 1) 1715a469608STimur Tabi pixis_reset(); 1725a469608STimur Tabi 1735a469608STimur Tabi for (i = 1; i < argc; i++) { 1745a469608STimur Tabi if (strcmp(argv[i], "altbank") == 0) { 1755a469608STimur Tabi p_altbank = argv[i]; 1765a469608STimur Tabi continue; 1775a469608STimur Tabi } 1785a469608STimur Tabi 179*82c9dfdcSTimur Tabi #ifdef DEBUG 180*82c9dfdcSTimur Tabi if (strcmp(argv[i], "dump") == 0) { 181*82c9dfdcSTimur Tabi p_dump = argv[i]; 182*82c9dfdcSTimur Tabi continue; 183*82c9dfdcSTimur Tabi } 184*82c9dfdcSTimur Tabi #endif 185*82c9dfdcSTimur Tabi 1865a469608STimur Tabi unknown_param = argv[i]; 1875a469608STimur Tabi } 1885a469608STimur Tabi 1895a469608STimur Tabi if (unknown_param) { 1905a469608STimur Tabi printf("Invalid option: %s\n", unknown_param); 1915a469608STimur Tabi return 1; 1925a469608STimur Tabi } 1935a469608STimur Tabi 194*82c9dfdcSTimur Tabi #ifdef DEBUG 195*82c9dfdcSTimur Tabi if (p_dump) { 196*82c9dfdcSTimur Tabi pixis_dump_regs(); 197*82c9dfdcSTimur Tabi 198*82c9dfdcSTimur Tabi /* 'dump' ignores other commands */ 199*82c9dfdcSTimur Tabi return 0; 200*82c9dfdcSTimur Tabi } 201*82c9dfdcSTimur Tabi #endif 202*82c9dfdcSTimur Tabi 2035a469608STimur Tabi if (p_altbank) 2045a469608STimur Tabi set_altbank(); 2055a469608STimur Tabi else 2065a469608STimur Tabi clear_altbank(); 2075a469608STimur Tabi 2085a469608STimur Tabi pixis_bank_reset(); 2095a469608STimur Tabi 2105a469608STimur Tabi /* Shouldn't be reached. */ 2115a469608STimur Tabi return 0; 2125a469608STimur Tabi } 2135a469608STimur Tabi 2145a469608STimur Tabi U_BOOT_CMD( 2155a469608STimur Tabi pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd, 2165a469608STimur Tabi "Reset the board using the FPGA sequencer", 2175a469608STimur Tabi "- hard reset to default bank\n" 2185a469608STimur Tabi "pixis_reset altbank - reset to alternate bank\n" 219*82c9dfdcSTimur Tabi #ifdef DEBUG 220*82c9dfdcSTimur Tabi "pixis_reset dump - display the PIXIS registers\n" 221*82c9dfdcSTimur Tabi #endif 2225a469608STimur Tabi ); 223