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