Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 2 | /* |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 3 | * (C) Copyright 2005-2009 |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 4 | * BuS Elektronik GmbH & Co.KG <esw@bus-elektonik.de> |
| 5 | * |
| 6 | * (C) Copyright 2000-2003 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 13 | #include "asm/m5282.h" |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 14 | #include <bmp_layout.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 15 | #include <env.h> |
Simon Glass | 0ffd9db | 2019-12-28 10:45:06 -0700 | [diff] [blame] | 16 | #include <init.h> |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 17 | #include <status_led.h> |
| 18 | #include <bus_vcxk.h> |
| 19 | |
| 20 | /*---------------------------------------------------------------------------*/ |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 24 | /*---------------------------------------------------------------------------*/ |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 25 | |
| 26 | int checkboard (void) |
| 27 | { |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 28 | puts("Board: EB+CPU5282 (BuS Elektronik GmbH & Co. KG)\n"); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 29 | #if (CONFIG_TEXT_BASE == CFG_SYS_INT_FLASH_BASE) |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 30 | puts(" Boot from Internal FLASH\n"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 31 | #endif |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 32 | return 0; |
| 33 | } |
| 34 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 35 | int dram_init(void) |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 36 | { |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 37 | int size, i; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 38 | |
| 39 | size = 0; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 40 | MCFSDRAMC_DCR = MCFSDRAMC_DCR_RTIM_6 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 41 | MCFSDRAMC_DCR_RC((15 * CFG_SYS_CLK / 1000000) >> 4); |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 42 | asm (" nop"); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 43 | #ifdef CFG_SYS_SDRAM_BASE0 |
| 44 | MCFSDRAMC_DACR0 = MCFSDRAMC_DACR_BASE(CFG_SYS_SDRAM_BASE0)| |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 45 | MCFSDRAMC_DACR_CASL(1) | MCFSDRAMC_DACR_CBM(3) | |
| 46 | MCFSDRAMC_DACR_PS_32; |
| 47 | asm (" nop"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 48 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 49 | MCFSDRAMC_DMR0 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 50 | asm (" nop"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 51 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 52 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 53 | asm (" nop"); |
| 54 | for (i = 0; i < 10; i++) |
| 55 | asm (" nop"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 56 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 57 | *(unsigned long *)(CFG_SYS_SDRAM_BASE0) = 0xA5A5A5A5; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 58 | asm (" nop"); |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 59 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 60 | asm (" nop"); |
| 61 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 62 | for (i = 0; i < 2000; i++) |
| 63 | asm (" nop"); |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 64 | |
| 65 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IMRS; |
| 66 | asm (" nop"); |
| 67 | /* write SDRAM mode register */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 68 | *(unsigned long *)(CFG_SYS_SDRAM_BASE0 + 0x80440) = 0xA5A5A5A5; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 69 | asm (" nop"); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 70 | size += CFG_SYS_SDRAM_SIZE0 * 1024 * 1024; |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 71 | #endif |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 72 | #ifdef CFG_SYS_SDRAM_BASE1xx |
| 73 | MCFSDRAMC_DACR1 = MCFSDRAMC_DACR_BASE (CFG_SYS_SDRAM_BASE1) |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 74 | | MCFSDRAMC_DACR_CASL (1) |
| 75 | | MCFSDRAMC_DACR_CBM (3) |
| 76 | | MCFSDRAMC_DACR_PS_16; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 77 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 78 | MCFSDRAMC_DMR1 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 79 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 80 | MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IP; |
| 81 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 82 | *(unsigned short *) (CFG_SYS_SDRAM_BASE1) = 0xA5A5; |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 83 | MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_RE; |
| 84 | |
| 85 | for (i = 0; i < 2000; i++) |
| 86 | asm (" nop"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 87 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 88 | MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IMRS; |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 89 | *(unsigned int *) (CFG_SYS_SDRAM_BASE1 + 0x220) = 0xA5A5; |
| 90 | size += CFG_SYS_SDRAM_SIZE1 * 1024 * 1024; |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 91 | #endif |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 92 | gd->ram_size = size; |
| 93 | |
| 94 | return 0; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 97 | #if defined(CFG_SYS_DRAM_TEST) |
Simon Glass | 0ffd9db | 2019-12-28 10:45:06 -0700 | [diff] [blame] | 98 | int testdram(void) |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 99 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 100 | uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START; |
| 101 | uint *pend = (uint *) CONFIG_SYS_MEMTEST_END; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 102 | uint *p; |
| 103 | |
| 104 | printf("SDRAM test phase 1:\n"); |
| 105 | for (p = pstart; p < pend; p++) |
| 106 | *p = 0xaaaaaaaa; |
| 107 | |
| 108 | for (p = pstart; p < pend; p++) { |
| 109 | if (*p != 0xaaaaaaaa) { |
| 110 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 111 | return 1; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | printf("SDRAM test phase 2:\n"); |
| 116 | for (p = pstart; p < pend; p++) |
| 117 | *p = 0x55555555; |
| 118 | |
| 119 | for (p = pstart; p < pend; p++) { |
| 120 | if (*p != 0x55555555) { |
| 121 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 122 | return 1; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | printf("SDRAM test passed.\n"); |
| 127 | return 0; |
| 128 | } |
| 129 | #endif |
| 130 | |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 131 | #if defined(CONFIG_HW_WATCHDOG) |
| 132 | |
| 133 | void hw_watchdog_init(void) |
| 134 | { |
| 135 | char *s; |
| 136 | int enable; |
| 137 | |
| 138 | enable = 1; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 139 | s = env_get("watchdog"); |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 140 | if (s != NULL) |
| 141 | if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0", 1) == 0)) |
| 142 | enable = 0; |
| 143 | if (enable) |
| 144 | MCFGPTA_GPTDDR |= (1<<2); |
| 145 | else |
| 146 | MCFGPTA_GPTDDR &= ~(1<<2); |
| 147 | } |
| 148 | |
| 149 | void hw_watchdog_reset(void) |
| 150 | { |
| 151 | MCFGPTA_GPTPORT ^= (1<<2); |
| 152 | } |
| 153 | #endif |
| 154 | |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 155 | int misc_init_r(void) |
| 156 | { |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 157 | #ifdef CONFIG_HW_WATCHDOG |
| 158 | hw_watchdog_init(); |
| 159 | #endif |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 160 | return 1; |
| 161 | } |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 162 | |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 163 | void __led_toggle(led_id_t mask) |
| 164 | { |
| 165 | MCFGPTA_GPTPORT ^= (1 << 3); |
| 166 | } |
| 167 | |
| 168 | void __led_init(led_id_t mask, int state) |
| 169 | { |
| 170 | __led_set(mask, state); |
| 171 | MCFGPTA_GPTDDR |= (1 << 3); |
| 172 | } |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 173 | |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 174 | void __led_set(led_id_t mask, int state) |
| 175 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 176 | if (state == CONFIG_LED_STATUS_ON) |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 177 | MCFGPTA_GPTPORT |= (1 << 3); |
| 178 | else |
| 179 | MCFGPTA_GPTPORT &= ~(1 << 3); |
| 180 | } |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 181 | |
| 182 | /*---------------------------------------------------------------------------*/ |
| 183 | |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 184 | |
| 185 | /* EOF EB+MCF-EV123.c */ |