blob: f5e4de3c4183203f77823ea22793a12e94382565 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocherac1956e2006-04-20 08:42:42 +02002/*
Jens Scharsig772d9b02009-07-24 10:31:48 +02003 * (C) Copyright 2005-2009
Heiko Schocherac1956e2006-04-20 08:42:42 +02004 * 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 Schocherac1956e2006-04-20 08:42:42 +02008 */
9
10#include <common.h>
11#include <command.h>
12#include "asm/m5282.h"
Jens Scharsig772d9b02009-07-24 10:31:48 +020013#include <bmp_layout.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060014#include <env.h>
Simon Glass0ffd9db2019-12-28 10:45:06 -070015#include <init.h>
Jens Scharsig772d9b02009-07-24 10:31:48 +020016#include <status_led.h>
17#include <bus_vcxk.h>
18
19/*---------------------------------------------------------------------------*/
20
21DECLARE_GLOBAL_DATA_PTR;
22
Anatolij Gustschin3d471a12020-10-18 20:32:35 +020023#if IS_ENABLED(CONFIG_VIDEO_VCXK)
Jens Scharsig772d9b02009-07-24 10:31:48 +020024unsigned long display_width;
25unsigned long display_height;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000026#endif
Jens Scharsig772d9b02009-07-24 10:31:48 +020027
28/*---------------------------------------------------------------------------*/
Heiko Schocherac1956e2006-04-20 08:42:42 +020029
30int checkboard (void)
31{
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000032 puts("Board: EB+CPU5282 (BuS Elektronik GmbH & Co. KG)\n");
Wolfgang Denk0708bc62010-10-07 21:51:12 +020033#if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000034 puts(" Boot from Internal FLASH\n");
Heiko Schocherac1956e2006-04-20 08:42:42 +020035#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +020036 return 0;
37}
38
Simon Glassd35f3382017-04-06 12:47:05 -060039int dram_init(void)
Heiko Schocherac1956e2006-04-20 08:42:42 +020040{
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020041 int size, i;
Heiko Schocherac1956e2006-04-20 08:42:42 +020042
43 size = 0;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000044 MCFSDRAMC_DCR = MCFSDRAMC_DCR_RTIM_6 |
45 MCFSDRAMC_DCR_RC((15 * CONFIG_SYS_CLK / 1000000) >> 4);
46 asm (" nop");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020047#ifdef CONFIG_SYS_SDRAM_BASE0
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000048 MCFSDRAMC_DACR0 = MCFSDRAMC_DACR_BASE(CONFIG_SYS_SDRAM_BASE0)|
49 MCFSDRAMC_DACR_CASL(1) | MCFSDRAMC_DACR_CBM(3) |
50 MCFSDRAMC_DACR_PS_32;
51 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020052
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020053 MCFSDRAMC_DMR0 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000054 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020055
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020056 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000057 asm (" nop");
58 for (i = 0; i < 10; i++)
59 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020060
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000061 *(unsigned long *)(CONFIG_SYS_SDRAM_BASE0) = 0xA5A5A5A5;
62 asm (" nop");
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020063 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000064 asm (" nop");
65
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020066 for (i = 0; i < 2000; i++)
67 asm (" nop");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000068
69 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IMRS;
70 asm (" nop");
71 /* write SDRAM mode register */
72 *(unsigned long *)(CONFIG_SYS_SDRAM_BASE0 + 0x80440) = 0xA5A5A5A5;
73 asm (" nop");
74 size += CONFIG_SYS_SDRAM_SIZE0 * 1024 * 1024;
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020075#endif
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000076#ifdef CONFIG_SYS_SDRAM_BASE1xx
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020077 MCFSDRAMC_DACR1 = MCFSDRAMC_DACR_BASE (CONFIG_SYS_SDRAM_BASE1)
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020078 | MCFSDRAMC_DACR_CASL (1)
79 | MCFSDRAMC_DACR_CBM (3)
80 | MCFSDRAMC_DACR_PS_16;
Heiko Schocherac1956e2006-04-20 08:42:42 +020081
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020082 MCFSDRAMC_DMR1 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
Heiko Schocherac1956e2006-04-20 08:42:42 +020083
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020084 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IP;
85
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086 *(unsigned short *) (CONFIG_SYS_SDRAM_BASE1) = 0xA5A5;
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020087 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_RE;
88
89 for (i = 0; i < 2000; i++)
90 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020091
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020092 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IMRS;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093 *(unsigned int *) (CONFIG_SYS_SDRAM_BASE1 + 0x220) = 0xA5A5;
94 size += CONFIG_SYS_SDRAM_SIZE1 * 1024 * 1024;
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020095#endif
Simon Glass39f90ba2017-03-31 08:40:25 -060096 gd->ram_size = size;
97
98 return 0;
Heiko Schocherac1956e2006-04-20 08:42:42 +020099}
100
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101#if defined(CONFIG_SYS_DRAM_TEST)
Simon Glass0ffd9db2019-12-28 10:45:06 -0700102int testdram(void)
Heiko Schocherac1956e2006-04-20 08:42:42 +0200103{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
105 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Heiko Schocherac1956e2006-04-20 08:42:42 +0200106 uint *p;
107
108 printf("SDRAM test phase 1:\n");
109 for (p = pstart; p < pend; p++)
110 *p = 0xaaaaaaaa;
111
112 for (p = pstart; p < pend; p++) {
113 if (*p != 0xaaaaaaaa) {
114 printf ("SDRAM test fails at: %08x\n", (uint) p);
115 return 1;
116 }
117 }
118
119 printf("SDRAM test phase 2:\n");
120 for (p = pstart; p < pend; p++)
121 *p = 0x55555555;
122
123 for (p = pstart; p < pend; p++) {
124 if (*p != 0x55555555) {
125 printf ("SDRAM test fails at: %08x\n", (uint) p);
126 return 1;
127 }
128 }
129
130 printf("SDRAM test passed.\n");
131 return 0;
132}
133#endif
134
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000135#if defined(CONFIG_HW_WATCHDOG)
136
137void hw_watchdog_init(void)
138{
139 char *s;
140 int enable;
141
142 enable = 1;
Simon Glass64b723f2017-08-03 12:22:12 -0600143 s = env_get("watchdog");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000144 if (s != NULL)
145 if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0", 1) == 0))
146 enable = 0;
147 if (enable)
148 MCFGPTA_GPTDDR |= (1<<2);
149 else
150 MCFGPTA_GPTDDR &= ~(1<<2);
151}
152
153void hw_watchdog_reset(void)
154{
155 MCFGPTA_GPTPORT ^= (1<<2);
156}
157#endif
158
Heiko Schocherac1956e2006-04-20 08:42:42 +0200159int misc_init_r(void)
160{
Jens Scharsig772d9b02009-07-24 10:31:48 +0200161#ifdef CONFIG_HW_WATCHDOG
162 hw_watchdog_init();
163#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +0200164 return 1;
165}
Jens Scharsig772d9b02009-07-24 10:31:48 +0200166
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000167void __led_toggle(led_id_t mask)
168{
169 MCFGPTA_GPTPORT ^= (1 << 3);
170}
171
172void __led_init(led_id_t mask, int state)
173{
174 __led_set(mask, state);
175 MCFGPTA_GPTDDR |= (1 << 3);
176}
Jens Scharsig772d9b02009-07-24 10:31:48 +0200177
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000178void __led_set(led_id_t mask, int state)
179{
Uri Mashiach4892d392017-01-19 10:51:45 +0200180 if (state == CONFIG_LED_STATUS_ON)
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000181 MCFGPTA_GPTPORT |= (1 << 3);
182 else
183 MCFGPTA_GPTPORT &= ~(1 << 3);
184}
185
Anatolij Gustschin3d471a12020-10-18 20:32:35 +0200186#if IS_ENABLED(CONFIG_VIDEO_VCXK)
Jens Scharsig772d9b02009-07-24 10:31:48 +0200187int drv_video_init(void)
188{
189 char *s;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000190#ifdef CONFIG_SPLASH_SCREEN
Jens Scharsig772d9b02009-07-24 10:31:48 +0200191 unsigned long splash;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000192#endif
Jens Scharsig772d9b02009-07-24 10:31:48 +0200193 printf("Init Video as ");
Simon Glass64b723f2017-08-03 12:22:12 -0600194 s = env_get("displaywidth");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000195 if (s != NULL)
Jens Scharsig772d9b02009-07-24 10:31:48 +0200196 display_width = simple_strtoul(s, NULL, 10);
197 else
198 display_width = 256;
199
Simon Glass64b723f2017-08-03 12:22:12 -0600200 s = env_get("displayheight");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000201 if (s != NULL)
Jens Scharsig772d9b02009-07-24 10:31:48 +0200202 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 Glass64b723f2017-08-03 12:22:12 -0600214 s = env_get("splashimage");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000215 if (s != NULL) {
Jens Scharsig772d9b02009-07-24 10:31:48 +0200216 splash = simple_strtoul(s, NULL, 16);
Jens Scharsig772d9b02009-07-24 10:31:48 +0200217 vcxk_acknowledge_wait();
218 video_display_bitmap(splash, 0, 0);
219 }
220#endif
221 return 0;
222}
223#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +0200224
225/*---------------------------------------------------------------------------*/
226
Anatolij Gustschin3d471a12020-10-18 20:32:35 +0200227#if IS_ENABLED(CONFIG_VIDEO_VCXK)
Simon Glassed38aef2020-05-10 11:40:03 -0600228int do_brightness(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Heiko Schocherac1956e2006-04-20 08:42:42 +0200229{
230 int rcode = 0;
Jens Scharsig772d9b02009-07-24 10:31:48 +0200231 ulong side;
232 ulong bright;
Heiko Schocherac1956e2006-04-20 08:42:42 +0200233
234 switch (argc) {
Jens Scharsig772d9b02009-07-24 10:31:48 +0200235 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 Schocherac1956e2006-04-20 08:42:42 +0200247 break;
248 default:
Jens Scharsig772d9b02009-07-24 10:31:48 +0200249 printf("Usage:\n%s\n", cmdtp->usage);
Heiko Schocherac1956e2006-04-20 08:42:42 +0200250 rcode = 1;
251 break;
252 }
253 return rcode;
254}
255
Jens Scharsig772d9b02009-07-24 10:31:48 +0200256/*---------------------------------------------------------------------------*/
Heiko Schocherac1956e2006-04-20 08:42:42 +0200257
258U_BOOT_CMD(
Jens Scharsig772d9b02009-07-24 10:31:48 +0200259 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 Schocherac1956e2006-04-20 08:42:42 +0200262);
263
Jens Scharsig772d9b02009-07-24 10:31:48 +0200264#endif
265
266/* EOF EB+MCF-EV123.c */