1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+ 25a469608STimur Tabi /** 3aa8d3fb8STimur Tabi * Copyright 2010-2011 Freescale Semiconductor 45a469608STimur Tabi * Author: Timur Tabi <timur@freescale.com> 55a469608STimur Tabi * 65a469608STimur Tabi * This file provides support for the ngPIXIS, a board-specific FPGA used on 75a469608STimur Tabi * some Freescale reference boards. 85a469608STimur Tabi * 95a469608STimur Tabi * A "switch" is black rectangular block on the motherboard. It contains 105a469608STimur Tabi * eight "bits". The ngPIXIS has a set of memory-mapped registers (SWx) that 115a469608STimur Tabi * shadow the actual physical switches. There is also another set of 125a469608STimur Tabi * registers (ENx) that tell the ngPIXIS which bits of SWx should actually be 135a469608STimur Tabi * used to override the values of the bits in the physical switches. 145a469608STimur Tabi * 155a469608STimur Tabi * The following macros need to be defined: 165a469608STimur Tabi * 175a469608STimur Tabi * PIXIS_BASE - The virtual address of the base of the PIXIS register map 185a469608STimur Tabi * 195a469608STimur Tabi * PIXIS_LBMAP_SWITCH - The switch number (i.e. the "x" in "SWx"). This value 205a469608STimur Tabi * is used in the PIXIS_SW() macro to determine which offset in 215a469608STimur Tabi * the PIXIS register map corresponds to the physical switch that controls 225a469608STimur Tabi * the boot bank. 235a469608STimur Tabi * 245a469608STimur Tabi * PIXIS_LBMAP_MASK - A bit mask the defines which bits in SWx to use. 255a469608STimur Tabi * 265a469608STimur Tabi * PIXIS_LBMAP_SHIFT - The shift value that corresponds to PIXIS_LBMAP_MASK. 275a469608STimur Tabi * 285a469608STimur Tabi * PIXIS_LBMAP_ALTBANK - The value to program into SWx to tell the ngPIXIS to 295a469608STimur Tabi * boot from the alternate bank. 305a469608STimur Tabi */ 315a469608STimur Tabi 325a469608STimur Tabi #include <common.h> 335a469608STimur Tabi #include <command.h> 345a469608STimur Tabi #include <asm/io.h> 355a469608STimur Tabi 365a469608STimur Tabi #include "ngpixis.h" 375a469608STimur Tabi 38aa8d3fb8STimur Tabi static u8 __pixis_read(unsigned int reg) 39aa8d3fb8STimur Tabi { 40aa8d3fb8STimur Tabi void *p = (void *)PIXIS_BASE; 41aa8d3fb8STimur Tabi 42aa8d3fb8STimur Tabi return in_8(p + reg); 43aa8d3fb8STimur Tabi } 44aa8d3fb8STimur Tabi u8 pixis_read(unsigned int reg) __attribute__((weak, alias("__pixis_read"))); 45aa8d3fb8STimur Tabi 46aa8d3fb8STimur Tabi static void __pixis_write(unsigned int reg, u8 value) 47aa8d3fb8STimur Tabi { 48aa8d3fb8STimur Tabi void *p = (void *)PIXIS_BASE; 49aa8d3fb8STimur Tabi 50aa8d3fb8STimur Tabi out_8(p + reg, value); 51aa8d3fb8STimur Tabi } 52aa8d3fb8STimur Tabi void pixis_write(unsigned int reg, u8 value) 53aa8d3fb8STimur Tabi __attribute__((weak, alias("__pixis_write"))); 54aa8d3fb8STimur Tabi 555a469608STimur Tabi /* 565a469608STimur Tabi * Reset the board. This ignores the ENx registers. 575a469608STimur Tabi */ 58aa8d3fb8STimur Tabi void __pixis_reset(void) 595a469608STimur Tabi { 60aa8d3fb8STimur Tabi PIXIS_WRITE(rst, 0); 615a469608STimur Tabi 625a469608STimur Tabi while (1); 635a469608STimur Tabi } 64aa8d3fb8STimur Tabi void pixis_reset(void) __attribute__((weak, alias("__pixis_reset"))); 655a469608STimur Tabi 665a469608STimur Tabi /* 675a469608STimur Tabi * Reset the board. Like pixis_reset(), but it honors the ENx registers. 685a469608STimur Tabi */ 69aa8d3fb8STimur Tabi void __pixis_bank_reset(void) 705a469608STimur Tabi { 71aa8d3fb8STimur Tabi PIXIS_WRITE(vctl, 0); 72aa8d3fb8STimur Tabi PIXIS_WRITE(vctl, 1); 735a469608STimur Tabi 745a469608STimur Tabi while (1); 755a469608STimur Tabi } 76aa8d3fb8STimur Tabi void pixis_bank_reset(void) __attribute__((weak, alias("__pixis_bank_reset"))); 775a469608STimur Tabi 785a469608STimur Tabi /** 795a469608STimur Tabi * Set the boot bank to the power-on default bank 805a469608STimur Tabi */ 81aa8d3fb8STimur Tabi void __clear_altbank(void) 825a469608STimur Tabi { 83aa8d3fb8STimur Tabi u8 reg; 84aa8d3fb8STimur Tabi 855a469608STimur Tabi /* Tell the ngPIXIS to use this the bits in the physical switch for the 865a469608STimur Tabi * boot bank value, instead of the SWx register. We need to be careful 875a469608STimur Tabi * only to set the bits in SWx that correspond to the boot bank. 885a469608STimur Tabi */ 89aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en); 90aa8d3fb8STimur Tabi reg &= ~PIXIS_LBMAP_MASK; 91aa8d3fb8STimur Tabi PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg); 925a469608STimur Tabi } 93aa8d3fb8STimur Tabi void clear_altbank(void) __attribute__((weak, alias("__clear_altbank"))); 945a469608STimur Tabi 955a469608STimur Tabi /** 965a469608STimur Tabi * Set the boot bank to the alternate bank 975a469608STimur Tabi */ 98aa8d3fb8STimur Tabi void __set_altbank(void) 995a469608STimur Tabi { 100aa8d3fb8STimur Tabi u8 reg; 101aa8d3fb8STimur Tabi 1025a469608STimur Tabi /* Program the alternate bank number into the SWx register. 1035a469608STimur Tabi */ 104aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].sw); 105aa8d3fb8STimur Tabi reg = (reg & ~PIXIS_LBMAP_MASK) | PIXIS_LBMAP_ALTBANK; 106aa8d3fb8STimur Tabi PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].sw, reg); 1075a469608STimur Tabi 1085a469608STimur Tabi /* Tell the ngPIXIS to use this the bits in the SWx register for the 1095a469608STimur Tabi * boot bank value, instead of the physical switch. We need to be 1105a469608STimur Tabi * careful only to set the bits in SWx that correspond to the boot bank. 1115a469608STimur Tabi */ 112aa8d3fb8STimur Tabi reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en); 113aa8d3fb8STimur Tabi reg |= PIXIS_LBMAP_MASK; 114aa8d3fb8STimur Tabi PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg); 1155a469608STimur Tabi } 116aa8d3fb8STimur Tabi void set_altbank(void) __attribute__((weak, alias("__set_altbank"))); 1175a469608STimur Tabi 11882c9dfdcSTimur Tabi #ifdef DEBUG 11982c9dfdcSTimur Tabi static void pixis_dump_regs(void) 12082c9dfdcSTimur Tabi { 12182c9dfdcSTimur Tabi unsigned int i; 12282c9dfdcSTimur Tabi 12382c9dfdcSTimur Tabi printf("id=%02x\n", PIXIS_READ(id)); 12482c9dfdcSTimur Tabi printf("arch=%02x\n", PIXIS_READ(arch)); 12582c9dfdcSTimur Tabi printf("scver=%02x\n", PIXIS_READ(scver)); 12682c9dfdcSTimur Tabi printf("csr=%02x\n", PIXIS_READ(csr)); 12782c9dfdcSTimur Tabi printf("rst=%02x\n", PIXIS_READ(rst)); 12882c9dfdcSTimur Tabi printf("aux=%02x\n", PIXIS_READ(aux)); 12982c9dfdcSTimur Tabi printf("spd=%02x\n", PIXIS_READ(spd)); 13082c9dfdcSTimur Tabi printf("brdcfg0=%02x\n", PIXIS_READ(brdcfg0)); 13182c9dfdcSTimur Tabi printf("brdcfg1=%02x\n", PIXIS_READ(brdcfg1)); 13282c9dfdcSTimur Tabi printf("addr=%02x\n", PIXIS_READ(addr)); 13382c9dfdcSTimur Tabi printf("data=%02x\n", PIXIS_READ(data)); 13482c9dfdcSTimur Tabi printf("led=%02x\n", PIXIS_READ(led)); 13582c9dfdcSTimur Tabi printf("vctl=%02x\n", PIXIS_READ(vctl)); 13682c9dfdcSTimur Tabi printf("vstat=%02x\n", PIXIS_READ(vstat)); 13782c9dfdcSTimur Tabi printf("vcfgen0=%02x\n", PIXIS_READ(vcfgen0)); 13882c9dfdcSTimur Tabi printf("ocmcsr=%02x\n", PIXIS_READ(ocmcsr)); 13982c9dfdcSTimur Tabi printf("ocmmsg=%02x\n", PIXIS_READ(ocmmsg)); 14082c9dfdcSTimur Tabi printf("gmdbg=%02x\n", PIXIS_READ(gmdbg)); 14182c9dfdcSTimur Tabi printf("sclk=%02x%02x%02x\n", 14282c9dfdcSTimur Tabi PIXIS_READ(sclk[0]), PIXIS_READ(sclk[1]), PIXIS_READ(sclk[2])); 14382c9dfdcSTimur Tabi printf("dclk=%02x%02x%02x\n", 14482c9dfdcSTimur Tabi PIXIS_READ(dclk[0]), PIXIS_READ(dclk[1]), PIXIS_READ(dclk[2])); 14582c9dfdcSTimur Tabi printf("watch=%02x\n", PIXIS_READ(watch)); 14682c9dfdcSTimur Tabi 14782c9dfdcSTimur Tabi for (i = 0; i < 8; i++) { 14882c9dfdcSTimur Tabi printf("SW%u=%02x/%02x ", i + 1, 14982c9dfdcSTimur Tabi PIXIS_READ(s[i].sw), PIXIS_READ(s[i].en)); 15082c9dfdcSTimur Tabi } 15182c9dfdcSTimur Tabi putc('\n'); 15282c9dfdcSTimur Tabi } 15382c9dfdcSTimur Tabi #endif 1545a469608STimur Tabi 15571775d3bSJerry Huang void pixis_sysclk_set(unsigned long sysclk) 15671775d3bSJerry Huang { 15771775d3bSJerry Huang unsigned long freq_word; 15871775d3bSJerry Huang u8 sclk0, sclk1, sclk2; 15971775d3bSJerry Huang 16071775d3bSJerry Huang freq_word = ics307_sysclk_calculator(sysclk); 16171775d3bSJerry Huang sclk2 = freq_word & 0xff; 16271775d3bSJerry Huang sclk1 = (freq_word >> 8) & 0xff; 16371775d3bSJerry Huang sclk0 = (freq_word >> 16) & 0xff; 16471775d3bSJerry Huang 16571775d3bSJerry Huang /* set SYSCLK enable bit */ 16671775d3bSJerry Huang PIXIS_WRITE(vcfgen0, 0x01); 16771775d3bSJerry Huang 16871775d3bSJerry Huang /* SYSCLK to required frequency */ 16971775d3bSJerry Huang PIXIS_WRITE(sclk[0], sclk0); 17071775d3bSJerry Huang PIXIS_WRITE(sclk[1], sclk1); 17171775d3bSJerry Huang PIXIS_WRITE(sclk[2], sclk2); 17271775d3bSJerry Huang } 17371775d3bSJerry Huang 17454841ab5SWolfgang Denk int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 1755a469608STimur Tabi { 1765a469608STimur Tabi unsigned int i; 17771775d3bSJerry Huang unsigned long sysclk; 1785a469608STimur Tabi char *p_altbank = NULL; 17982c9dfdcSTimur Tabi #ifdef DEBUG 18082c9dfdcSTimur Tabi char *p_dump = NULL; 18182c9dfdcSTimur Tabi #endif 1825a469608STimur Tabi char *unknown_param = NULL; 1835a469608STimur Tabi 1845a469608STimur Tabi /* No args is a simple reset request. 1855a469608STimur Tabi */ 1865a469608STimur Tabi if (argc <= 1) 1875a469608STimur Tabi pixis_reset(); 1885a469608STimur Tabi 1895a469608STimur Tabi for (i = 1; i < argc; i++) { 1905a469608STimur Tabi if (strcmp(argv[i], "altbank") == 0) { 1915a469608STimur Tabi p_altbank = argv[i]; 1925a469608STimur Tabi continue; 1935a469608STimur Tabi } 1945a469608STimur Tabi 19582c9dfdcSTimur Tabi #ifdef DEBUG 19682c9dfdcSTimur Tabi if (strcmp(argv[i], "dump") == 0) { 19782c9dfdcSTimur Tabi p_dump = argv[i]; 19882c9dfdcSTimur Tabi continue; 19982c9dfdcSTimur Tabi } 20082c9dfdcSTimur Tabi #endif 20171775d3bSJerry Huang if (strcmp(argv[i], "sysclk") == 0) { 20271775d3bSJerry Huang sysclk = simple_strtoul(argv[i + 1], NULL, 0); 20371775d3bSJerry Huang i += 1; 20471775d3bSJerry Huang pixis_sysclk_set(sysclk); 20571775d3bSJerry Huang continue; 20671775d3bSJerry Huang } 20782c9dfdcSTimur Tabi 2085a469608STimur Tabi unknown_param = argv[i]; 2095a469608STimur Tabi } 2105a469608STimur Tabi 2115a469608STimur Tabi if (unknown_param) { 2125a469608STimur Tabi printf("Invalid option: %s\n", unknown_param); 2135a469608STimur Tabi return 1; 2145a469608STimur Tabi } 2155a469608STimur Tabi 21682c9dfdcSTimur Tabi #ifdef DEBUG 21782c9dfdcSTimur Tabi if (p_dump) { 21882c9dfdcSTimur Tabi pixis_dump_regs(); 21982c9dfdcSTimur Tabi 22082c9dfdcSTimur Tabi /* 'dump' ignores other commands */ 22182c9dfdcSTimur Tabi return 0; 22282c9dfdcSTimur Tabi } 22382c9dfdcSTimur Tabi #endif 22482c9dfdcSTimur Tabi 2255a469608STimur Tabi if (p_altbank) 2265a469608STimur Tabi set_altbank(); 2275a469608STimur Tabi else 2285a469608STimur Tabi clear_altbank(); 2295a469608STimur Tabi 2305a469608STimur Tabi pixis_bank_reset(); 2315a469608STimur Tabi 2325a469608STimur Tabi /* Shouldn't be reached. */ 2335a469608STimur Tabi return 0; 2345a469608STimur Tabi } 2355a469608STimur Tabi 236e56143e5SKim Phillips #ifdef CONFIG_SYS_LONGHELP 237e56143e5SKim Phillips static char pixis_help_text[] = 2385a469608STimur Tabi "- hard reset to default bank\n" 2395a469608STimur Tabi "pixis_reset altbank - reset to alternate bank\n" 24082c9dfdcSTimur Tabi #ifdef DEBUG 24182c9dfdcSTimur Tabi "pixis_reset dump - display the PIXIS registers\n" 24282c9dfdcSTimur Tabi #endif 243e56143e5SKim Phillips "pixis_reset sysclk <SYSCLK_freq> - reset with SYSCLK frequency(KHz)\n"; 244e56143e5SKim Phillips #endif 245e56143e5SKim Phillips 246e56143e5SKim Phillips U_BOOT_CMD( 247e56143e5SKim Phillips pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd, 248e56143e5SKim Phillips "Reset the board using the FPGA sequencer", pixis_help_text 2495a469608STimur Tabi ); 250