15a469608STimur Tabi /**
25a469608STimur Tabi  * Copyright 2010 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 <watchdog.h>
395a469608STimur Tabi #include <asm/cache.h>
405a469608STimur Tabi #include <asm/io.h>
415a469608STimur Tabi 
425a469608STimur Tabi #include "ngpixis.h"
435a469608STimur Tabi 
445a469608STimur Tabi /*
455a469608STimur Tabi  * Reset the board. This ignores the ENx registers.
465a469608STimur Tabi  */
475a469608STimur Tabi void pixis_reset(void)
485a469608STimur Tabi {
495a469608STimur Tabi 	out_8(&pixis->rst, 0);
505a469608STimur Tabi 
515a469608STimur Tabi 	while (1);
525a469608STimur Tabi }
535a469608STimur Tabi 
545a469608STimur Tabi /*
555a469608STimur Tabi  * Reset the board.  Like pixis_reset(), but it honors the ENx registers.
565a469608STimur Tabi  */
575a469608STimur Tabi void pixis_bank_reset(void)
585a469608STimur Tabi {
595a469608STimur Tabi 	out_8(&pixis->vctl, 0);
605a469608STimur Tabi 	out_8(&pixis->vctl, 1);
615a469608STimur Tabi 
625a469608STimur Tabi 	while (1);
635a469608STimur Tabi }
645a469608STimur Tabi 
655a469608STimur Tabi /**
665a469608STimur Tabi  * Set the boot bank to the power-on default bank
675a469608STimur Tabi  */
685a469608STimur Tabi void clear_altbank(void)
695a469608STimur Tabi {
705a469608STimur Tabi 	/* Tell the ngPIXIS to use this the bits in the physical switch for the
715a469608STimur Tabi 	 * boot bank value, instead of the SWx register.  We need to be careful
725a469608STimur Tabi 	 * only to set the bits in SWx that correspond to the boot bank.
735a469608STimur Tabi 	 */
745a469608STimur Tabi 	clrbits_8(&PIXIS_EN(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK);
755a469608STimur Tabi }
765a469608STimur Tabi 
775a469608STimur Tabi /**
785a469608STimur Tabi  * Set the boot bank to the alternate bank
795a469608STimur Tabi  */
805a469608STimur Tabi void set_altbank(void)
815a469608STimur Tabi {
825a469608STimur Tabi 	/* Program the alternate bank number into the SWx register.
835a469608STimur Tabi 	 */
845a469608STimur Tabi 	clrsetbits_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK,
855a469608STimur Tabi 		     PIXIS_LBMAP_ALTBANK);
865a469608STimur Tabi 
875a469608STimur Tabi 	/* Tell the ngPIXIS to use this the bits in the SWx register for the
885a469608STimur Tabi 	 * boot bank value, instead of the physical switch.  We need to be
895a469608STimur Tabi 	 * careful only to set the bits in SWx that correspond to the boot bank.
905a469608STimur Tabi 	 */
915a469608STimur Tabi 	setbits_8(&PIXIS_EN(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK);
925a469608STimur Tabi }
935a469608STimur Tabi 
945a469608STimur Tabi 
95*54841ab5SWolfgang Denk int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
965a469608STimur Tabi {
975a469608STimur Tabi 	unsigned int i;
985a469608STimur Tabi 	char *p_altbank = NULL;
995a469608STimur Tabi 	char *unknown_param = NULL;
1005a469608STimur Tabi 
1015a469608STimur Tabi 	/* No args is a simple reset request.
1025a469608STimur Tabi 	 */
1035a469608STimur Tabi 	if (argc <= 1)
1045a469608STimur Tabi 		pixis_reset();
1055a469608STimur Tabi 
1065a469608STimur Tabi 	for (i = 1; i < argc; i++) {
1075a469608STimur Tabi 		if (strcmp(argv[i], "altbank") == 0) {
1085a469608STimur Tabi 			p_altbank = argv[i];
1095a469608STimur Tabi 			continue;
1105a469608STimur Tabi 		}
1115a469608STimur Tabi 
1125a469608STimur Tabi 		unknown_param = argv[i];
1135a469608STimur Tabi 	}
1145a469608STimur Tabi 
1155a469608STimur Tabi 	if (unknown_param) {
1165a469608STimur Tabi 		printf("Invalid option: %s\n", unknown_param);
1175a469608STimur Tabi 		return 1;
1185a469608STimur Tabi 	}
1195a469608STimur Tabi 
1205a469608STimur Tabi 	if (p_altbank)
1215a469608STimur Tabi 		set_altbank();
1225a469608STimur Tabi 	else
1235a469608STimur Tabi 		clear_altbank();
1245a469608STimur Tabi 
1255a469608STimur Tabi 	pixis_bank_reset();
1265a469608STimur Tabi 
1275a469608STimur Tabi 	/* Shouldn't be reached. */
1285a469608STimur Tabi 	return 0;
1295a469608STimur Tabi }
1305a469608STimur Tabi 
1315a469608STimur Tabi U_BOOT_CMD(
1325a469608STimur Tabi 	pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
1335a469608STimur Tabi 	"Reset the board using the FPGA sequencer",
1345a469608STimur Tabi 	"- hard reset to default bank\n"
1355a469608STimur Tabi 	"pixis_reset altbank - reset to alternate bank\n"
1365a469608STimur Tabi 	);
137