Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * amirix.c: ppcboot platform support for AMIRIX board |
| 3 | * |
| 4 | * Copyright 2002 Mind NV |
| 5 | * Copyright 2003 AMIRIX Systems Inc. |
| 6 | * |
| 7 | * http://www.mind.be/ |
| 8 | * http://www.amirix.com/ |
| 9 | * |
| 10 | * Author : Peter De Schrijver (p2@mind.be) |
| 11 | * Frank Smith (smith@amirix.com) |
| 12 | * |
| 13 | * Derived from : Other platform support files in this tree, ml2 |
| 14 | * |
| 15 | * This software may be used and distributed according to the terms of |
| 16 | * the GNU General Public License (GPL) version 2, incorporated herein by |
| 17 | * reference. Drivers based on or derived from this code fall under the GPL |
| 18 | * and must retain the authorship, copyright and this license notice. This |
| 19 | * file is not a complete program and may only be used when the entire |
| 20 | * program is licensed under the GPL. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <asm/processor.h> |
| 27 | |
| 28 | #include "powerspan.h" |
| 29 | #include "ap1000.h" |
| 30 | |
| 31 | int board_pre_init (void) |
| 32 | { |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 33 | return 0; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /** serial number and platform display at startup */ |
| 37 | int checkboard (void) |
| 38 | { |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 39 | unsigned char *s = getenv ("serial#"); |
| 40 | unsigned char *e; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 41 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 42 | /* After a loadace command, the SystemAce control register is left in a wonky state. */ |
| 43 | /* this code did not work in board_pre_init */ |
| 44 | unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 45 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 46 | p[SYSACE_CTRLREG0] = 0x0; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 47 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 48 | /* add platform and device to banner */ |
| 49 | switch (get_device ()) { |
| 50 | case AP1xx_AP107_TARGET: |
| 51 | puts (AP1xx_AP107_TARGET_STR); |
| 52 | break; |
| 53 | case AP1xx_AP120_TARGET: |
| 54 | puts (AP1xx_AP120_TARGET_STR); |
| 55 | break; |
| 56 | case AP1xx_AP130_TARGET: |
| 57 | puts (AP1xx_AP130_TARGET_STR); |
| 58 | break; |
| 59 | case AP1xx_AP1070_TARGET: |
| 60 | puts (AP1xx_AP1070_TARGET_STR); |
| 61 | break; |
| 62 | case AP1xx_AP1100_TARGET: |
| 63 | puts (AP1xx_AP1100_TARGET_STR); |
| 64 | break; |
| 65 | default: |
| 66 | puts (AP1xx_UNKNOWN_STR); |
| 67 | break; |
| 68 | } |
| 69 | puts (AP1xx_TARGET_STR); |
| 70 | puts (" with "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 71 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 72 | switch (get_platform ()) { |
| 73 | case AP100_BASELINE_PLATFORM: |
| 74 | case AP1000_BASELINE_PLATFORM: |
| 75 | puts (AP1xx_BASELINE_PLATFORM_STR); |
| 76 | break; |
| 77 | case AP1xx_QUADGE_PLATFORM: |
| 78 | puts (AP1xx_QUADGE_PLATFORM_STR); |
| 79 | break; |
| 80 | case AP1xx_MGT_REF_PLATFORM: |
| 81 | puts (AP1xx_MGT_REF_PLATFORM_STR); |
| 82 | break; |
| 83 | case AP1xx_STANDARD_PLATFORM: |
| 84 | puts (AP1xx_STANDARD_PLATFORM_STR); |
| 85 | break; |
| 86 | case AP1xx_DUAL_PLATFORM: |
| 87 | puts (AP1xx_DUAL_PLATFORM_STR); |
| 88 | break; |
| 89 | case AP1xx_BASE_SRAM_PLATFORM: |
| 90 | puts (AP1xx_BASE_SRAM_PLATFORM_STR); |
| 91 | break; |
| 92 | case AP1xx_PCI_PCB_TESTPLATFORM: |
| 93 | case AP1000_PCI_PCB_TESTPLATFORM: |
| 94 | puts (AP1xx_PCI_PCB_TESTPLATFORM_STR); |
| 95 | break; |
| 96 | case AP1xx_DUAL_GE_MEZZ_TESTPLATFORM: |
| 97 | puts (AP1xx_DUAL_GE_MEZZ_TESTPLATFORM_STR); |
| 98 | break; |
| 99 | case AP1xx_SFP_MEZZ_TESTPLATFORM: |
| 100 | puts (AP1xx_SFP_MEZZ_TESTPLATFORM_STR); |
| 101 | break; |
| 102 | default: |
| 103 | puts (AP1xx_UNKNOWN_STR); |
| 104 | break; |
| 105 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 106 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 107 | if ((get_platform () & AP1xx_TESTPLATFORM_MASK) != 0) { |
| 108 | puts (AP1xx_TESTPLATFORM_STR); |
| 109 | } else { |
| 110 | puts (AP1xx_PLATFORM_STR); |
| 111 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 112 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 113 | putc ('\n'); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 114 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 115 | puts ("Serial#: "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 116 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 117 | if (!s) { |
| 118 | printf ("### No HW ID - assuming AMIRIX"); |
| 119 | } else { |
| 120 | for (e = s; *e; ++e) { |
| 121 | if (*e == ' ') |
| 122 | break; |
| 123 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 124 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 125 | for (; s < e; ++s) { |
| 126 | putc (*s); |
| 127 | } |
| 128 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 129 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 130 | putc ('\n'); |
| 131 | |
| 132 | return (0); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | |
| 136 | long int initdram (int board_type) |
| 137 | { |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 138 | unsigned char *s = getenv ("dramsize"); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 139 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 140 | if (s != NULL) { |
| 141 | if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) { |
| 142 | s += 2; |
| 143 | } |
| 144 | return simple_strtoul (s, NULL, 16); |
| 145 | } else { |
| 146 | /* give all 64 MB */ |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 147 | return 64 * 1024 * 1024; |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 148 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 151 | unsigned int get_platform (void) |
| 152 | { |
| 153 | unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR; |
| 154 | |
| 155 | return (*revision_reg_ptr & AP1xx_PLATFORM_MASK); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 158 | unsigned int get_device (void) |
| 159 | { |
| 160 | unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 161 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 162 | return (*revision_reg_ptr & AP1xx_TARGET_MASK); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 165 | #if 0 /* loadace is not working; it appears to be a hardware issue with the system ace. */ |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 166 | /* |
| 167 | This function loads FPGA configurations from the SystemACE CompactFlash |
| 168 | */ |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 169 | int do_loadace (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 170 | { |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 171 | unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE; |
| 172 | int cfg; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 173 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 174 | if ((p[SYSACE_STATREG0] & 0x10) == 0) { |
| 175 | p[SYSACE_CTRLREG0] = 0x80; |
| 176 | printf ("\nNo CompactFlash Detected\n\n"); |
| 177 | p[SYSACE_CTRLREG0] = 0x00; |
| 178 | return 1; |
| 179 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 180 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 181 | /* reset configuration controller: | 0x80 */ |
| 182 | /* select cpflash & ~0x40 */ |
| 183 | /* cfg start | 0x20 */ |
| 184 | /* wait for cfgstart & ~0x10 */ |
| 185 | /* force cfgmode: | 0x08 */ |
| 186 | /* do no force cfgaddr: & ~0x04 */ |
| 187 | /* clear mpulock: & ~0x02 */ |
| 188 | /* do not force lock request & ~0x01 */ |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 189 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 190 | p[SYSACE_CTRLREG0] = 0x80 | 0x20 | 0x08; |
| 191 | p[SYSACE_CTRLREG1] = 0x00; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 192 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 193 | /* force config address if arg2 exists */ |
| 194 | if (argc == 2) { |
| 195 | cfg = simple_strtoul (argv[1], NULL, 10); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 196 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 197 | if (cfg > 7) { |
| 198 | printf ("\nInvalid Configuration\n\n"); |
| 199 | p[SYSACE_CTRLREG0] = 0x00; |
| 200 | return 1; |
| 201 | } |
| 202 | /* Set config address */ |
| 203 | p[SYSACE_CTRLREG1] = (cfg << 5); |
| 204 | /* force cfgaddr */ |
| 205 | p[SYSACE_CTRLREG0] |= 0x04; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 206 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 207 | } else { |
| 208 | cfg = (p[SYSACE_STATREG1] & 0xE0) >> 5; |
| 209 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 210 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 211 | /* release configuration controller */ |
| 212 | printf ("\nLoading V2PRO with config %d...\n", cfg); |
| 213 | p[SYSACE_CTRLREG0] &= ~0x80; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 214 | |
| 215 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 216 | while ((p[SYSACE_STATREG1] & 0x01) == 0) { |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 217 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 218 | if (p[SYSACE_ERRREG0] & 0x80) { |
| 219 | /* attempting to load an invalid configuration makes the cpflash */ |
| 220 | /* appear to be removed. Reset here to avoid that problem */ |
| 221 | p[SYSACE_CTRLREG0] = 0x80; |
| 222 | printf ("\nConfiguration %d Read Error\n\n", cfg); |
| 223 | p[SYSACE_CTRLREG0] = 0x00; |
| 224 | return 1; |
| 225 | } |
| 226 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 227 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 228 | p[SYSACE_CTRLREG0] |= 0x20; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 229 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 230 | return 0; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 231 | } |
| 232 | #endif |
| 233 | |
| 234 | /** Console command to display and set the software reconfigure byte |
| 235 | * <pre> |
| 236 | * swconfig - display the current value of the software reconfigure byte |
| 237 | * swconfig [#] - change the software reconfigure byte to # |
| 238 | * </pre> |
| 239 | * @param *cmdtp [IN] as passed by run_command (ignored) |
| 240 | * @param flag [IN] as passed by run_command (ignored) |
| 241 | * @param argc [IN] as passed by run_command if 1, display, if 2 change |
| 242 | * @param *argv[] [IN] contains the parameters to use |
| 243 | * @return |
| 244 | * <pre> |
| 245 | * 0 if passed |
| 246 | * -1 if failed |
| 247 | * </pre> |
| 248 | */ |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 249 | int do_swconfigbyte (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 250 | { |
| 251 | unsigned char *sector_buffer = NULL; |
| 252 | unsigned char input_char; |
| 253 | int write_result; |
| 254 | unsigned int input_uint; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 255 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 256 | /* display value if no argument */ |
| 257 | if (argc < 2) { |
| 258 | printf ("Software configuration byte is currently: 0x%02x\n", |
| 259 | *((unsigned char *) (SW_BYTE_SECTOR_ADDR + |
| 260 | SW_BYTE_SECTOR_OFFSET))); |
| 261 | return 0; |
| 262 | } else if (argc > 3) { |
| 263 | printf ("Too many arguments\n"); |
| 264 | return -1; |
| 265 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 266 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 267 | /* if 3 arguments, 3rd argument is the address to use */ |
| 268 | if (argc == 3) { |
| 269 | input_uint = simple_strtoul (argv[1], NULL, 16); |
| 270 | sector_buffer = (unsigned char *) input_uint; |
| 271 | } else { |
| 272 | sector_buffer = (unsigned char *) DEFAULT_TEMP_ADDR; |
| 273 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 274 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 275 | input_char = simple_strtoul (argv[1], NULL, 0); |
| 276 | if ((input_char & ~SW_BYTE_MASK) != 0) { |
| 277 | printf ("Input of 0x%02x will be masked to 0x%02x\n", |
| 278 | input_char, (input_char & SW_BYTE_MASK)); |
| 279 | input_char = input_char & SW_BYTE_MASK; |
| 280 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 281 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 282 | memcpy (sector_buffer, (void *) SW_BYTE_SECTOR_ADDR, |
| 283 | SW_BYTE_SECTOR_SIZE); |
| 284 | sector_buffer[SW_BYTE_SECTOR_OFFSET] = input_char; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 285 | |
| 286 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 287 | printf ("Erasing Flash..."); |
| 288 | if (flash_sect_erase |
| 289 | (SW_BYTE_SECTOR_ADDR, |
| 290 | (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET))) { |
| 291 | return -1; |
| 292 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 293 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 294 | printf ("Writing to Flash... "); |
| 295 | write_result = |
| 296 | flash_write (sector_buffer, SW_BYTE_SECTOR_ADDR, |
| 297 | SW_BYTE_SECTOR_SIZE); |
| 298 | if (write_result != 0) { |
| 299 | flash_perror (write_result); |
| 300 | return -1; |
| 301 | } else { |
| 302 | printf ("done\n"); |
| 303 | printf ("Software configuration byte is now: 0x%02x\n", |
| 304 | *((unsigned char *) (SW_BYTE_SECTOR_ADDR + |
| 305 | SW_BYTE_SECTOR_OFFSET))); |
| 306 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 307 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 308 | return 0; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | #define ONE_SECOND 1000000 |
| 312 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 313 | int do_pause (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 314 | { |
| 315 | int pause_time; |
| 316 | unsigned int delay_time; |
| 317 | int break_loop = 0; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 318 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 319 | /* display value if no argument */ |
| 320 | if (argc < 2) { |
| 321 | pause_time = 1; |
| 322 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 323 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 324 | else if (argc > 2) { |
| 325 | printf ("Too many arguments\n"); |
| 326 | return -1; |
| 327 | } else { |
| 328 | pause_time = simple_strtoul (argv[1], NULL, 0); |
| 329 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 330 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 331 | printf ("Pausing with a poll time of %d, press any key to reactivate\n", pause_time); |
| 332 | delay_time = pause_time * ONE_SECOND; |
| 333 | while (break_loop == 0) { |
| 334 | udelay (delay_time); |
| 335 | if (serial_tstc () != 0) { |
| 336 | break_loop = 1; |
| 337 | /* eat user key presses */ |
| 338 | while (serial_tstc () != 0) { |
| 339 | serial_getc (); |
| 340 | } |
| 341 | } |
| 342 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 343 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 344 | return 0; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 347 | int do_swreconfig (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 348 | { |
| 349 | printf ("Triggering software reconfigure (software config byte is 0x%02x)...\n", |
| 350 | *((unsigned char *) (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET))); |
| 351 | udelay (1000); |
| 352 | *((unsigned char *) AP1000_CPLD_BASE) = 1; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 353 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 354 | return 0; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | #define GET_DECIMAL(low_byte) ((low_byte >> 5) * 125) |
| 358 | #define TEMP_BUSY_BIT 0x80 |
| 359 | #define TEMP_LHIGH_BIT 0x40 |
| 360 | #define TEMP_LLOW_BIT 0x20 |
| 361 | #define TEMP_EHIGH_BIT 0x10 |
| 362 | #define TEMP_ELOW_BIT 0x08 |
| 363 | #define TEMP_OPEN_BIT 0x04 |
| 364 | #define TEMP_ETHERM_BIT 0x02 |
| 365 | #define TEMP_LTHERM_BIT 0x01 |
| 366 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 367 | int do_temp_sensor (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 368 | { |
| 369 | char cmd; |
| 370 | int ret_val = 0; |
| 371 | unsigned char temp_byte; |
| 372 | int temp; |
| 373 | int temp_low; |
| 374 | int low; |
| 375 | int low_low; |
| 376 | int high; |
| 377 | int high_low; |
| 378 | int therm; |
| 379 | unsigned char user_data[4] = { 0 }; |
| 380 | int user_data_count = 0; |
| 381 | int ii; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 382 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 383 | if (argc > 1) { |
| 384 | cmd = argv[1][0]; |
| 385 | } else { |
| 386 | cmd = 's'; /* default to status */ |
| 387 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 388 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 389 | user_data_count = argc - 2; |
| 390 | for (ii = 0; ii < user_data_count; ii++) { |
| 391 | user_data[ii] = simple_strtoul (argv[2 + ii], NULL, 0); |
| 392 | } |
| 393 | switch (cmd) { |
| 394 | case 's': |
| 395 | if (I2CAccess |
| 396 | (0x2, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 397 | &temp_byte, I2C_READ) != 0) { |
| 398 | goto fail; |
| 399 | } |
| 400 | printf ("Status : 0x%02x ", temp_byte); |
| 401 | if (temp_byte & TEMP_BUSY_BIT) |
| 402 | printf ("BUSY "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 403 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 404 | if (temp_byte & TEMP_LHIGH_BIT) |
| 405 | printf ("LHIGH "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 406 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 407 | if (temp_byte & TEMP_LLOW_BIT) |
| 408 | printf ("LLOW "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 409 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 410 | if (temp_byte & TEMP_EHIGH_BIT) |
| 411 | printf ("EHIGH "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 412 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 413 | if (temp_byte & TEMP_ELOW_BIT) |
| 414 | printf ("ELOW "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 415 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 416 | if (temp_byte & TEMP_OPEN_BIT) |
| 417 | printf ("OPEN "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 418 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 419 | if (temp_byte & TEMP_ETHERM_BIT) |
| 420 | printf ("ETHERM "); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 421 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 422 | if (temp_byte & TEMP_LTHERM_BIT) |
| 423 | printf ("LTHERM"); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 424 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 425 | printf ("\n"); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 426 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 427 | if (I2CAccess |
| 428 | (0x3, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 429 | &temp_byte, I2C_READ) != 0) { |
| 430 | goto fail; |
| 431 | } |
| 432 | printf ("Config : 0x%02x ", temp_byte); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 433 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 434 | if (I2CAccess |
| 435 | (0x4, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 436 | &temp_byte, I2C_READ) != 0) { |
| 437 | printf ("\n"); |
| 438 | goto fail; |
| 439 | } |
| 440 | printf ("Conversion: 0x%02x\n", temp_byte); |
| 441 | if (I2CAccess |
| 442 | (0x22, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 443 | &temp_byte, I2C_READ) != 0) { |
| 444 | goto fail; |
| 445 | } |
| 446 | printf ("Cons Alert: 0x%02x ", temp_byte); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 447 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 448 | if (I2CAccess |
| 449 | (0x21, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 450 | &temp_byte, I2C_READ) != 0) { |
| 451 | printf ("\n"); |
| 452 | goto fail; |
| 453 | } |
| 454 | printf ("Therm Hyst: %d\n", temp_byte); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 455 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 456 | if (I2CAccess |
| 457 | (0x0, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 458 | &temp_byte, I2C_READ) != 0) { |
| 459 | goto fail; |
| 460 | } |
| 461 | temp = temp_byte; |
| 462 | if (I2CAccess |
| 463 | (0x6, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 464 | &temp_byte, I2C_READ) != 0) { |
| 465 | goto fail; |
| 466 | } |
| 467 | low = temp_byte; |
| 468 | if (I2CAccess |
| 469 | (0x5, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 470 | &temp_byte, I2C_READ) != 0) { |
| 471 | goto fail; |
| 472 | } |
| 473 | high = temp_byte; |
| 474 | if (I2CAccess |
| 475 | (0x20, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 476 | &temp_byte, I2C_READ) != 0) { |
| 477 | goto fail; |
| 478 | } |
| 479 | therm = temp_byte; |
| 480 | printf ("Local Temp: %2d Low: %2d High: %2d THERM: %2d\n", temp, low, high, therm); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 481 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 482 | if (I2CAccess |
| 483 | (0x1, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 484 | &temp_byte, I2C_READ) != 0) { |
| 485 | goto fail; |
| 486 | } |
| 487 | temp = temp_byte; |
| 488 | if (I2CAccess |
| 489 | (0x10, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 490 | &temp_byte, I2C_READ) != 0) { |
| 491 | goto fail; |
| 492 | } |
| 493 | temp_low = temp_byte; |
| 494 | if (I2CAccess |
| 495 | (0x8, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 496 | &temp_byte, I2C_READ) != 0) { |
| 497 | goto fail; |
| 498 | } |
| 499 | low = temp_byte; |
| 500 | if (I2CAccess |
| 501 | (0x14, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 502 | &temp_byte, I2C_READ) != 0) { |
| 503 | goto fail; |
| 504 | } |
| 505 | low_low = temp_byte; |
| 506 | if (I2CAccess |
| 507 | (0x7, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 508 | &temp_byte, I2C_READ) != 0) { |
| 509 | goto fail; |
| 510 | } |
| 511 | high = temp_byte; |
| 512 | if (I2CAccess |
| 513 | (0x13, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 514 | &temp_byte, I2C_READ) != 0) { |
| 515 | goto fail; |
| 516 | } |
| 517 | high_low = temp_byte; |
| 518 | if (I2CAccess |
| 519 | (0x19, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 520 | &temp_byte, I2C_READ) != 0) { |
| 521 | goto fail; |
| 522 | } |
| 523 | therm = temp_byte; |
| 524 | if (I2CAccess |
| 525 | (0x11, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 526 | &temp_byte, I2C_READ) != 0) { |
| 527 | goto fail; |
| 528 | } |
| 529 | printf ("Ext Temp : %2d.%03d Low: %2d.%03d High: %2d.%03d THERM: %2d Offset: %2d\n", temp, GET_DECIMAL (temp_low), low, GET_DECIMAL (low_low), high, GET_DECIMAL (high_low), therm, temp_byte); |
| 530 | break; |
| 531 | case 'l': /* alter local limits : low, high, therm */ |
| 532 | if (argc < 3) { |
| 533 | goto usage; |
| 534 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 535 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 536 | /* low */ |
| 537 | if (I2CAccess |
| 538 | (0xC, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 539 | &user_data[0], I2C_WRITE) != 0) { |
| 540 | goto fail; |
| 541 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 542 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 543 | if (user_data_count > 1) { |
| 544 | /* high */ |
| 545 | if (I2CAccess |
| 546 | (0xB, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 547 | &user_data[1], I2C_WRITE) != 0) { |
| 548 | goto fail; |
| 549 | } |
| 550 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 551 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 552 | if (user_data_count > 2) { |
| 553 | /* therm */ |
| 554 | if (I2CAccess |
| 555 | (0x20, I2C_SENSOR_DEV, |
| 556 | I2C_SENSOR_CHIP_SEL, &user_data[2], |
| 557 | I2C_WRITE) != 0) { |
| 558 | goto fail; |
| 559 | } |
| 560 | } |
| 561 | break; |
| 562 | case 'e': /* alter external limits: low, high, therm, offset */ |
| 563 | if (argc < 3) { |
| 564 | goto usage; |
| 565 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 566 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 567 | /* low */ |
| 568 | if (I2CAccess |
| 569 | (0xE, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 570 | &user_data[0], I2C_WRITE) != 0) { |
| 571 | goto fail; |
| 572 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 573 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 574 | if (user_data_count > 1) { |
| 575 | /* high */ |
| 576 | if (I2CAccess |
| 577 | (0xD, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 578 | &user_data[1], I2C_WRITE) != 0) { |
| 579 | goto fail; |
| 580 | } |
| 581 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 582 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 583 | if (user_data_count > 2) { |
| 584 | /* therm */ |
| 585 | if (I2CAccess |
| 586 | (0x19, I2C_SENSOR_DEV, |
| 587 | I2C_SENSOR_CHIP_SEL, &user_data[2], |
| 588 | I2C_WRITE) != 0) { |
| 589 | goto fail; |
| 590 | } |
| 591 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 592 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 593 | if (user_data_count > 3) { |
| 594 | /* offset */ |
| 595 | if (I2CAccess |
| 596 | (0x11, I2C_SENSOR_DEV, |
| 597 | I2C_SENSOR_CHIP_SEL, &user_data[3], |
| 598 | I2C_WRITE) != 0) { |
| 599 | goto fail; |
| 600 | } |
| 601 | } |
| 602 | break; |
| 603 | case 'c': /* alter config settings: config, conv, cons alert, therm hyst */ |
| 604 | if (argc < 3) { |
| 605 | goto usage; |
| 606 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 607 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 608 | /* config */ |
| 609 | if (I2CAccess |
| 610 | (0x9, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 611 | &user_data[0], I2C_WRITE) != 0) { |
| 612 | goto fail; |
| 613 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 614 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 615 | if (user_data_count > 1) { |
| 616 | /* conversion */ |
| 617 | if (I2CAccess |
| 618 | (0xA, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL, |
| 619 | &user_data[1], I2C_WRITE) != 0) { |
| 620 | goto fail; |
| 621 | } |
| 622 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 623 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 624 | if (user_data_count > 2) { |
| 625 | /* cons alert */ |
| 626 | if (I2CAccess |
| 627 | (0x22, I2C_SENSOR_DEV, |
| 628 | I2C_SENSOR_CHIP_SEL, &user_data[2], |
| 629 | I2C_WRITE) != 0) { |
| 630 | goto fail; |
| 631 | } |
| 632 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 633 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 634 | if (user_data_count > 3) { |
| 635 | /* therm hyst */ |
| 636 | if (I2CAccess |
| 637 | (0x21, I2C_SENSOR_DEV, |
| 638 | I2C_SENSOR_CHIP_SEL, &user_data[3], |
| 639 | I2C_WRITE) != 0) { |
| 640 | goto fail; |
| 641 | } |
| 642 | } |
| 643 | break; |
| 644 | default: |
| 645 | goto usage; |
| 646 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 647 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 648 | goto done; |
| 649 | fail: |
| 650 | printf ("Access to sensor failed\n"); |
| 651 | ret_val = -1; |
| 652 | goto done; |
| 653 | usage: |
| 654 | printf ("Usage:\n%s\n", cmdtp->help); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 655 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 656 | done: |
| 657 | return ret_val; |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 658 | } |
| 659 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 660 | U_BOOT_CMD (temp, 6, 0, do_temp_sensor, |
| 661 | "temp - interact with the temperature sensor\n", |
| 662 | "temp [s]\n" |
| 663 | " - Show status.\n" |
| 664 | "temp l LOW [HIGH] [THERM]\n" |
| 665 | " - Set local limits.\n" |
| 666 | "temp e LOW [HIGH] [THERM] [OFFSET]\n" |
| 667 | " - Set external limits.\n" |
| 668 | "temp c CONFIG [CONVERSION] [CONS. ALERT] [THERM HYST]\n" |
| 669 | " - Set config options.\n" |
| 670 | "\n" |
| 671 | "All values can be decimal or hex (hex preceded with 0x).\n" |
| 672 | "Only whole numbers are supported for external limits.\n"); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 673 | |
| 674 | #if 0 |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 675 | U_BOOT_CMD (loadace, 2, 0, do_loadace, |
| 676 | "loadace - load fpga configuration from System ACE compact flash\n", |
| 677 | "N\n" |
| 678 | " - Load configuration N (0-7) from System ACE compact flash\n" |
| 679 | "loadace\n" " - loads default configuration\n"); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 680 | #endif |
| 681 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 682 | U_BOOT_CMD (swconfig, 2, 0, do_swconfigbyte, |
| 683 | "swconfig- display or modify the software configuration byte\n", |
| 684 | "N [ADDRESS]\n" |
| 685 | " - set software configuration byte to N, optionally use ADDRESS as\n" |
| 686 | " location of buffer for flash copy\n" |
| 687 | "swconfig\n" " - display software configuration byte\n"); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 688 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 689 | U_BOOT_CMD (pause, 2, 0, do_pause, |
| 690 | "pause - sleep processor until any key is pressed with poll time of N seconds\n", |
| 691 | "N\n" |
| 692 | " - sleep processor until any key is pressed with poll time of N seconds\n" |
| 693 | "pause\n" |
| 694 | " - sleep processor until any key is pressed with poll time of 1 second\n"); |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 695 | |
Wolfgang Denk | 3193a65 | 2005-10-09 01:41:48 +0200 | [diff] [blame^] | 696 | U_BOOT_CMD (swrecon, 1, 0, do_swreconfig, |
| 697 | "swrecon - trigger a board reconfigure to the software selected configuration\n", |
| 698 | "\n" |
| 699 | " - trigger a board reconfigure to the software selected configuration\n"); |