15a469608STimur Tabi /** 2*aa8d3fb8STimur 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 42*aa8d3fb8STimur Tabi static u8 __pixis_read(unsigned int reg) 43*aa8d3fb8STimur Tabi { 44*aa8d3fb8STimur Tabi void *p = (void *)PIXIS_BASE; 45*aa8d3fb8STimur Tabi 46*aa8d3fb8STimur Tabi return in_8(p + reg); 47*aa8d3fb8STimur Tabi } 48*aa8d3fb8STimur Tabi u8 pixis_read(unsigned int reg) __attribute__((weak, alias("__pixis_read"))); 49*aa8d3fb8STimur Tabi 50*aa8d3fb8STimur Tabi static void __pixis_write(unsigned int reg, u8 value) 51*aa8d3fb8STimur Tabi { 52*aa8d3fb8STimur Tabi void *p = (void *)PIXIS_BASE; 53*aa8d3fb8STimur Tabi 54*aa8d3fb8STimur Tabi out_8(p + reg, value); 55*aa8d3fb8STimur Tabi } 56*aa8d3fb8STimur Tabi void pixis_write(unsigned int reg, u8 value) 57*aa8d3fb8STimur Tabi __attribute__((weak, alias("__pixis_write"))); 58*aa8d3fb8STimur Tabi 595a469608STimur Tabi /* 605a469608STimur Tabi * Reset the board. This ignores the ENx registers. 615a469608STimur Tabi */ 62*aa8d3fb8STimur Tabi void __pixis_reset(void) 635a469608STimur Tabi { 64*aa8d3fb8STimur Tabi PIXIS_WRITE(rst, 0); 655a469608STimur Tabi 665a469608STimur Tabi while (1); 675a469608STimur Tabi } 68*aa8d3fb8STimur 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 */ 73*aa8d3fb8STimur Tabi void __pixis_bank_reset(void) 745a469608STimur Tabi { 75*aa8d3fb8STimur Tabi PIXIS_WRITE(vctl, 0); 76*aa8d3fb8STimur Tabi PIXIS_WRITE(vctl, 1); 775a469608STimur Tabi 785a469608STimur Tabi while (1); 795a469608STimur Tabi } 80*aa8d3fb8STimur 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 */ 85*aa8d3fb8STimur Tabi void __clear_altbank(void) 865a469608STimur Tabi { 87*aa8d3fb8STimur Tabi u8 reg; 88*aa8d3fb8STimur 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 */ 93*aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en); 94*aa8d3fb8STimur Tabi reg &= ~PIXIS_LBMAP_MASK; 95*aa8d3fb8STimur Tabi PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg); 965a469608STimur Tabi } 97*aa8d3fb8STimur 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 */ 102*aa8d3fb8STimur Tabi void __set_altbank(void) 1035a469608STimur Tabi { 104*aa8d3fb8STimur Tabi u8 reg; 105*aa8d3fb8STimur Tabi 1065a469608STimur Tabi /* Program the alternate bank number into the SWx register. 1075a469608STimur Tabi */ 108*aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].sw); 109*aa8d3fb8STimur Tabi reg = (reg & ~PIXIS_LBMAP_MASK) | PIXIS_LBMAP_ALTBANK; 110*aa8d3fb8STimur 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 */ 116*aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en); 117*aa8d3fb8STimur Tabi reg |= PIXIS_LBMAP_MASK; 118*aa8d3fb8STimur Tabi PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg); 1195a469608STimur Tabi } 120*aa8d3fb8STimur Tabi void set_altbank(void) __attribute__((weak, alias("__set_altbank"))); 1215a469608STimur Tabi 1225a469608STimur Tabi 12354841ab5SWolfgang Denk int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 1245a469608STimur Tabi { 1255a469608STimur Tabi unsigned int i; 1265a469608STimur Tabi char *p_altbank = NULL; 1275a469608STimur Tabi char *unknown_param = NULL; 1285a469608STimur Tabi 1295a469608STimur Tabi /* No args is a simple reset request. 1305a469608STimur Tabi */ 1315a469608STimur Tabi if (argc <= 1) 1325a469608STimur Tabi pixis_reset(); 1335a469608STimur Tabi 1345a469608STimur Tabi for (i = 1; i < argc; i++) { 1355a469608STimur Tabi if (strcmp(argv[i], "altbank") == 0) { 1365a469608STimur Tabi p_altbank = argv[i]; 1375a469608STimur Tabi continue; 1385a469608STimur Tabi } 1395a469608STimur Tabi 1405a469608STimur Tabi unknown_param = argv[i]; 1415a469608STimur Tabi } 1425a469608STimur Tabi 1435a469608STimur Tabi if (unknown_param) { 1445a469608STimur Tabi printf("Invalid option: %s\n", unknown_param); 1455a469608STimur Tabi return 1; 1465a469608STimur Tabi } 1475a469608STimur Tabi 1485a469608STimur Tabi if (p_altbank) 1495a469608STimur Tabi set_altbank(); 1505a469608STimur Tabi else 1515a469608STimur Tabi clear_altbank(); 1525a469608STimur Tabi 1535a469608STimur Tabi pixis_bank_reset(); 1545a469608STimur Tabi 1555a469608STimur Tabi /* Shouldn't be reached. */ 1565a469608STimur Tabi return 0; 1575a469608STimur Tabi } 1585a469608STimur Tabi 1595a469608STimur Tabi U_BOOT_CMD( 1605a469608STimur Tabi pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd, 1615a469608STimur Tabi "Reset the board using the FPGA sequencer", 1625a469608STimur Tabi "- hard reset to default bank\n" 1635a469608STimur Tabi "pixis_reset altbank - reset to alternate bank\n" 1645a469608STimur Tabi ); 165