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 | |
Anatolij Gustschin | 3d471a1 | 2020-10-18 20:32:35 +0200 | [diff] [blame] | 24 | #if IS_ENABLED(CONFIG_VIDEO_VCXK) |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 25 | unsigned long display_width; |
| 26 | unsigned long display_height; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 27 | #endif |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 28 | |
| 29 | /*---------------------------------------------------------------------------*/ |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 30 | |
| 31 | int checkboard (void) |
| 32 | { |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 33 | puts("Board: EB+CPU5282 (BuS Elektronik GmbH & Co. KG)\n"); |
Wolfgang Denk | 0708bc6 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 34 | #if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 35 | puts(" Boot from Internal FLASH\n"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 36 | #endif |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 37 | return 0; |
| 38 | } |
| 39 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 40 | int dram_init(void) |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 41 | { |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 42 | int size, i; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 43 | |
| 44 | size = 0; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 45 | MCFSDRAMC_DCR = MCFSDRAMC_DCR_RTIM_6 | |
| 46 | MCFSDRAMC_DCR_RC((15 * CONFIG_SYS_CLK / 1000000) >> 4); |
| 47 | asm (" nop"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | #ifdef CONFIG_SYS_SDRAM_BASE0 |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 49 | MCFSDRAMC_DACR0 = MCFSDRAMC_DACR_BASE(CONFIG_SYS_SDRAM_BASE0)| |
| 50 | MCFSDRAMC_DACR_CASL(1) | MCFSDRAMC_DACR_CBM(3) | |
| 51 | MCFSDRAMC_DACR_PS_32; |
| 52 | asm (" nop"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 53 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 54 | MCFSDRAMC_DMR0 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 55 | asm (" nop"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 56 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 57 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 58 | asm (" nop"); |
| 59 | for (i = 0; i < 10; i++) |
| 60 | asm (" nop"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 61 | |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 62 | *(unsigned long *)(CONFIG_SYS_SDRAM_BASE0) = 0xA5A5A5A5; |
| 63 | asm (" nop"); |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 64 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 65 | asm (" nop"); |
| 66 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 67 | for (i = 0; i < 2000; i++) |
| 68 | asm (" nop"); |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 69 | |
| 70 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IMRS; |
| 71 | asm (" nop"); |
| 72 | /* write SDRAM mode register */ |
| 73 | *(unsigned long *)(CONFIG_SYS_SDRAM_BASE0 + 0x80440) = 0xA5A5A5A5; |
| 74 | asm (" nop"); |
| 75 | size += CONFIG_SYS_SDRAM_SIZE0 * 1024 * 1024; |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 76 | #endif |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 77 | #ifdef CONFIG_SYS_SDRAM_BASE1xx |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | MCFSDRAMC_DACR1 = MCFSDRAMC_DACR_BASE (CONFIG_SYS_SDRAM_BASE1) |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 79 | | MCFSDRAMC_DACR_CASL (1) |
| 80 | | MCFSDRAMC_DACR_CBM (3) |
| 81 | | MCFSDRAMC_DACR_PS_16; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 82 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 83 | MCFSDRAMC_DMR1 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 84 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 85 | MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IP; |
| 86 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 87 | *(unsigned short *) (CONFIG_SYS_SDRAM_BASE1) = 0xA5A5; |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 88 | MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_RE; |
| 89 | |
| 90 | for (i = 0; i < 2000; i++) |
| 91 | asm (" nop"); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 92 | |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 93 | MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IMRS; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 94 | *(unsigned int *) (CONFIG_SYS_SDRAM_BASE1 + 0x220) = 0xA5A5; |
| 95 | size += CONFIG_SYS_SDRAM_SIZE1 * 1024 * 1024; |
Wolfgang Denk | c4f55ee | 2008-07-14 20:38:26 +0200 | [diff] [blame] | 96 | #endif |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 97 | gd->ram_size = size; |
| 98 | |
| 99 | return 0; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 102 | #if defined(CONFIG_SYS_DRAM_TEST) |
Simon Glass | 0ffd9db | 2019-12-28 10:45:06 -0700 | [diff] [blame] | 103 | int testdram(void) |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 104 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 105 | uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START; |
| 106 | uint *pend = (uint *) CONFIG_SYS_MEMTEST_END; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 107 | uint *p; |
| 108 | |
| 109 | printf("SDRAM test phase 1:\n"); |
| 110 | for (p = pstart; p < pend; p++) |
| 111 | *p = 0xaaaaaaaa; |
| 112 | |
| 113 | for (p = pstart; p < pend; p++) { |
| 114 | if (*p != 0xaaaaaaaa) { |
| 115 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 116 | return 1; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | printf("SDRAM test phase 2:\n"); |
| 121 | for (p = pstart; p < pend; p++) |
| 122 | *p = 0x55555555; |
| 123 | |
| 124 | for (p = pstart; p < pend; p++) { |
| 125 | if (*p != 0x55555555) { |
| 126 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 127 | return 1; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | printf("SDRAM test passed.\n"); |
| 132 | return 0; |
| 133 | } |
| 134 | #endif |
| 135 | |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 136 | #if defined(CONFIG_HW_WATCHDOG) |
| 137 | |
| 138 | void hw_watchdog_init(void) |
| 139 | { |
| 140 | char *s; |
| 141 | int enable; |
| 142 | |
| 143 | enable = 1; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 144 | s = env_get("watchdog"); |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 145 | if (s != NULL) |
| 146 | if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0", 1) == 0)) |
| 147 | enable = 0; |
| 148 | if (enable) |
| 149 | MCFGPTA_GPTDDR |= (1<<2); |
| 150 | else |
| 151 | MCFGPTA_GPTDDR &= ~(1<<2); |
| 152 | } |
| 153 | |
| 154 | void hw_watchdog_reset(void) |
| 155 | { |
| 156 | MCFGPTA_GPTPORT ^= (1<<2); |
| 157 | } |
| 158 | #endif |
| 159 | |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 160 | int misc_init_r(void) |
| 161 | { |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 162 | #ifdef CONFIG_HW_WATCHDOG |
| 163 | hw_watchdog_init(); |
| 164 | #endif |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 165 | return 1; |
| 166 | } |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 167 | |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 168 | void __led_toggle(led_id_t mask) |
| 169 | { |
| 170 | MCFGPTA_GPTPORT ^= (1 << 3); |
| 171 | } |
| 172 | |
| 173 | void __led_init(led_id_t mask, int state) |
| 174 | { |
| 175 | __led_set(mask, state); |
| 176 | MCFGPTA_GPTDDR |= (1 << 3); |
| 177 | } |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 178 | |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 179 | void __led_set(led_id_t mask, int state) |
| 180 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 181 | if (state == CONFIG_LED_STATUS_ON) |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 182 | MCFGPTA_GPTPORT |= (1 << 3); |
| 183 | else |
| 184 | MCFGPTA_GPTPORT &= ~(1 << 3); |
| 185 | } |
| 186 | |
Anatolij Gustschin | 3d471a1 | 2020-10-18 20:32:35 +0200 | [diff] [blame] | 187 | #if IS_ENABLED(CONFIG_VIDEO_VCXK) |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 188 | int drv_video_init(void) |
| 189 | { |
| 190 | char *s; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 191 | #ifdef CONFIG_SPLASH_SCREEN |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 192 | unsigned long splash; |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 193 | #endif |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 194 | printf("Init Video as "); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 195 | s = env_get("displaywidth"); |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 196 | if (s != NULL) |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 197 | display_width = simple_strtoul(s, NULL, 10); |
| 198 | else |
| 199 | display_width = 256; |
| 200 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 201 | s = env_get("displayheight"); |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 202 | if (s != NULL) |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 203 | display_height = simple_strtoul(s, NULL, 10); |
| 204 | else |
| 205 | display_height = 256; |
| 206 | |
| 207 | printf("%lu x %lu pixel matrix\n", display_width, display_height); |
| 208 | |
| 209 | MCFCCM_CCR &= ~MCFCCM_CCR_SZEN; |
| 210 | MCFGPIO_PEPAR &= ~MCFGPIO_PEPAR_PEPA2; |
| 211 | |
| 212 | vcxk_init(display_width, display_height); |
| 213 | |
| 214 | #ifdef CONFIG_SPLASH_SCREEN |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 215 | s = env_get("splashimage"); |
Jens Scharsig (BuS Elektronik) | e5e5837 | 2012-10-30 00:46:05 +0000 | [diff] [blame] | 216 | if (s != NULL) { |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 217 | splash = simple_strtoul(s, NULL, 16); |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 218 | vcxk_acknowledge_wait(); |
| 219 | video_display_bitmap(splash, 0, 0); |
| 220 | } |
| 221 | #endif |
| 222 | return 0; |
| 223 | } |
| 224 | #endif |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 225 | |
| 226 | /*---------------------------------------------------------------------------*/ |
| 227 | |
Anatolij Gustschin | 3d471a1 | 2020-10-18 20:32:35 +0200 | [diff] [blame] | 228 | #if IS_ENABLED(CONFIG_VIDEO_VCXK) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 229 | int do_brightness(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 230 | { |
| 231 | int rcode = 0; |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 232 | ulong side; |
| 233 | ulong bright; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 234 | |
| 235 | switch (argc) { |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 236 | case 3: |
| 237 | side = simple_strtoul(argv[1], NULL, 10); |
| 238 | bright = simple_strtoul(argv[2], NULL, 10); |
| 239 | if ((side >= 0) && (side <= 3) && |
| 240 | (bright >= 0) && (bright <= 1000)) { |
| 241 | vcxk_setbrightness(side, bright); |
| 242 | rcode = 0; |
| 243 | } else { |
| 244 | printf("parameters out of range\n"); |
| 245 | printf("Usage:\n%s\n", cmdtp->usage); |
| 246 | rcode = 1; |
| 247 | } |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 248 | break; |
| 249 | default: |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 250 | printf("Usage:\n%s\n", cmdtp->usage); |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 251 | rcode = 1; |
| 252 | break; |
| 253 | } |
| 254 | return rcode; |
| 255 | } |
| 256 | |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 257 | /*---------------------------------------------------------------------------*/ |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 258 | |
| 259 | U_BOOT_CMD( |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 260 | bright, 3, 0, do_brightness, |
| 261 | "sets the display brightness\n", |
| 262 | " <side> <0..1000>\n side: 0/3=both; 1=first; 2=second\n" |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 263 | ); |
| 264 | |
Jens Scharsig | 772d9b0 | 2009-07-24 10:31:48 +0200 | [diff] [blame] | 265 | #endif |
| 266 | |
| 267 | /* EOF EB+MCF-EV123.c */ |