Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 1 | /* CPU specific code for the LEON3 CPU |
| 2 | * |
Francois Retief | e3051d9 | 2015-10-28 14:29:32 +0200 | [diff] [blame] | 3 | * (C) Copyright 2007, 2015 |
| 4 | * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <watchdog.h> |
| 11 | #include <command.h> |
Ben Warren | 2f2b6b6 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 12 | #include <netdev.h> |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 13 | |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/processor.h> |
Daniel Hellstrom | cbb7de6 | 2010-01-22 13:25:03 +0100 | [diff] [blame] | 16 | #include <ambapp.h> |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 20 | extern void _reset_reloc(void); |
| 21 | |
Daniel Hellstrom | cbb7de6 | 2010-01-22 13:25:03 +0100 | [diff] [blame] | 22 | int leon_cpu_cnt = 1; |
| 23 | int leon_ver = 3; |
| 24 | unsigned int leon_cpu_freq = CONFIG_SYS_CLK_FREQ; |
| 25 | |
| 26 | int cpu_freq(void) |
| 27 | { |
| 28 | ambapp_ahbdev dev; |
| 29 | |
| 30 | if (leon_ver == 3) { |
| 31 | ambapp_ahbmst_find(&ambapp_plb, VENDOR_GAISLER, |
| 32 | GAISLER_LEON3, 0, &dev); |
| 33 | } else { |
| 34 | ambapp_ahbmst_find(&ambapp_plb, VENDOR_GAISLER, |
| 35 | GAISLER_LEON4, 0, &dev); |
| 36 | } |
| 37 | |
| 38 | leon_cpu_freq = ambapp_bus_freq(&ambapp_plb, dev.ahb_bus_index); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 43 | int checkcpu(void) |
| 44 | { |
Daniel Hellstrom | cbb7de6 | 2010-01-22 13:25:03 +0100 | [diff] [blame] | 45 | int cnt; |
| 46 | char str[4]; |
| 47 | |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 48 | /* check LEON version here */ |
Daniel Hellstrom | cbb7de6 | 2010-01-22 13:25:03 +0100 | [diff] [blame] | 49 | cnt = ambapp_ahbmst_count(&ambapp_plb, VENDOR_GAISLER, GAISLER_LEON3); |
| 50 | if (cnt <= 0) { |
| 51 | cnt = ambapp_ahbmst_count(&ambapp_plb, VENDOR_GAISLER, |
| 52 | GAISLER_LEON4); |
| 53 | if (cnt > 0) |
| 54 | leon_ver = 4; |
| 55 | } |
| 56 | |
| 57 | cpu_freq(); |
| 58 | |
| 59 | str[0] = '\0'; |
| 60 | if (cnt > 1) { |
| 61 | leon_cpu_cnt = cnt; |
| 62 | str[0] = '0' + cnt; |
| 63 | str[1] = 'x'; |
| 64 | str[2] = '\0'; |
| 65 | } |
| 66 | printf("CPU: %sLEON%d @ %dMHz\n", str, leon_ver, |
| 67 | leon_cpu_freq / 1000000); |
| 68 | |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
Francois Retief | 703d024 | 2015-10-28 16:49:02 +0200 | [diff] [blame] | 72 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 73 | |
| 74 | int print_cpuinfo(void) |
| 75 | { |
| 76 | printf("CPU: LEON3\n"); |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | #endif |
| 81 | |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 82 | /* ------------------------------------------------------------------------- */ |
| 83 | |
| 84 | void cpu_reset(void) |
| 85 | { |
| 86 | /* Interrupts off */ |
| 87 | disable_interrupts(); |
| 88 | |
| 89 | /* jump to restart in flash */ |
| 90 | _reset_reloc(); |
| 91 | } |
| 92 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 93 | int do_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Daniel Hellstrom | b552dbe | 2008-03-26 22:51:29 +0100 | [diff] [blame] | 94 | { |
| 95 | cpu_reset(); |
| 96 | |
| 97 | return 1; |
| 98 | |
| 99 | } |
| 100 | |
| 101 | u64 flash_read64(void *addr) |
| 102 | { |
| 103 | return __raw_readq(addr); |
| 104 | } |
| 105 | |
| 106 | /* ------------------------------------------------------------------------- */ |
Ben Warren | 8c042b6 | 2008-07-09 01:04:19 -0700 | [diff] [blame] | 107 | |
| 108 | #ifdef CONFIG_GRETH |
| 109 | int cpu_eth_init(bd_t *bis) |
| 110 | { |
| 111 | return greth_initialize(bis); |
| 112 | } |
| 113 | #endif |