Timur Tabi | 4f332d2 | 2010-04-01 10:49:42 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2010 Freescale Semiconductor |
| 3 | * 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> |
| 38 | #include <watchdog.h> |
| 39 | #include <asm/cache.h> |
| 40 | #include <asm/io.h> |
| 41 | |
| 42 | #include "ngpixis.h" |
| 43 | |
| 44 | /* |
| 45 | * Reset the board. This ignores the ENx registers. |
| 46 | */ |
| 47 | void pixis_reset(void) |
| 48 | { |
| 49 | out_8(&pixis->rst, 0); |
| 50 | |
| 51 | while (1); |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Reset the board. Like pixis_reset(), but it honors the ENx registers. |
| 56 | */ |
| 57 | void pixis_bank_reset(void) |
| 58 | { |
| 59 | out_8(&pixis->vctl, 0); |
| 60 | out_8(&pixis->vctl, 1); |
| 61 | |
| 62 | while (1); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Set the boot bank to the power-on default bank |
| 67 | */ |
| 68 | void clear_altbank(void) |
| 69 | { |
| 70 | /* Tell the ngPIXIS to use this the bits in the physical switch for the |
| 71 | * boot bank value, instead of the SWx register. We need to be careful |
| 72 | * only to set the bits in SWx that correspond to the boot bank. |
| 73 | */ |
| 74 | clrbits_8(&PIXIS_EN(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Set the boot bank to the alternate bank |
| 79 | */ |
| 80 | void set_altbank(void) |
| 81 | { |
| 82 | /* Program the alternate bank number into the SWx register. |
| 83 | */ |
| 84 | clrsetbits_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK, |
| 85 | PIXIS_LBMAP_ALTBANK); |
| 86 | |
| 87 | /* Tell the ngPIXIS to use this the bits in the SWx register for the |
| 88 | * boot bank value, instead of the physical switch. We need to be |
| 89 | * careful only to set the bits in SWx that correspond to the boot bank. |
| 90 | */ |
| 91 | setbits_8(&PIXIS_EN(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 96 | { |
| 97 | unsigned int i; |
| 98 | char *p_altbank = NULL; |
| 99 | char *unknown_param = NULL; |
| 100 | |
| 101 | /* No args is a simple reset request. |
| 102 | */ |
| 103 | if (argc <= 1) |
| 104 | pixis_reset(); |
| 105 | |
| 106 | for (i = 1; i < argc; i++) { |
| 107 | if (strcmp(argv[i], "altbank") == 0) { |
| 108 | p_altbank = argv[i]; |
| 109 | continue; |
| 110 | } |
| 111 | |
| 112 | unknown_param = argv[i]; |
| 113 | } |
| 114 | |
| 115 | if (unknown_param) { |
| 116 | printf("Invalid option: %s\n", unknown_param); |
| 117 | return 1; |
| 118 | } |
| 119 | |
| 120 | if (p_altbank) |
| 121 | set_altbank(); |
| 122 | else |
| 123 | clear_altbank(); |
| 124 | |
| 125 | pixis_bank_reset(); |
| 126 | |
| 127 | /* Shouldn't be reached. */ |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | U_BOOT_CMD( |
| 132 | pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd, |
| 133 | "Reset the board using the FPGA sequencer", |
| 134 | "- hard reset to default bank\n" |
| 135 | "pixis_reset altbank - reset to alternate bank\n" |
| 136 | ); |