blob: 2164b52dee0926e979ace5b8501411a27dd285de [file] [log] [blame]
Heiko Schocherac1956e2006-04-20 08:42:42 +02001/*
Jens Scharsig772d9b02009-07-24 10:31:48 +02002 * (C) Copyright 2005-2009
Heiko Schocherac1956e2006-04-20 08:42:42 +02003 * BuS Elektronik GmbH & Co.KG <esw@bus-elektonik.de>
4 *
5 * (C) Copyright 2000-2003
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Heiko Schocherac1956e2006-04-20 08:42:42 +02009 */
10
11#include <common.h>
12#include <command.h>
13#include "asm/m5282.h"
Jens Scharsig772d9b02009-07-24 10:31:48 +020014#include <bmp_layout.h>
15#include <status_led.h>
16#include <bus_vcxk.h>
17
18/*---------------------------------------------------------------------------*/
19
20DECLARE_GLOBAL_DATA_PTR;
21
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000022#ifdef CONFIG_VIDEO
Jens Scharsig772d9b02009-07-24 10:31:48 +020023unsigned long display_width;
24unsigned long display_height;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000025#endif
Jens Scharsig772d9b02009-07-24 10:31:48 +020026
27/*---------------------------------------------------------------------------*/
Heiko Schocherac1956e2006-04-20 08:42:42 +020028
29int checkboard (void)
30{
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000031 puts("Board: EB+CPU5282 (BuS Elektronik GmbH & Co. KG)\n");
Wolfgang Denk0708bc62010-10-07 21:51:12 +020032#if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000033 puts(" Boot from Internal FLASH\n");
Heiko Schocherac1956e2006-04-20 08:42:42 +020034#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +020035 return 0;
36}
37
Becky Brucebd99ae72008-06-09 16:03:40 -050038phys_size_t initdram (int board_type)
Heiko Schocherac1956e2006-04-20 08:42:42 +020039{
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020040 int size, i;
Heiko Schocherac1956e2006-04-20 08:42:42 +020041
42 size = 0;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000043 MCFSDRAMC_DCR = MCFSDRAMC_DCR_RTIM_6 |
44 MCFSDRAMC_DCR_RC((15 * CONFIG_SYS_CLK / 1000000) >> 4);
45 asm (" nop");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020046#ifdef CONFIG_SYS_SDRAM_BASE0
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000047 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 Schocherac1956e2006-04-20 08:42:42 +020051
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020052 MCFSDRAMC_DMR0 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000053 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020054
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020055 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000056 asm (" nop");
57 for (i = 0; i < 10; i++)
58 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020059
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000060 *(unsigned long *)(CONFIG_SYS_SDRAM_BASE0) = 0xA5A5A5A5;
61 asm (" nop");
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020062 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000063 asm (" nop");
64
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020065 for (i = 0; i < 2000; i++)
66 asm (" nop");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000067
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 Denkc4f55ee2008-07-14 20:38:26 +020074#endif
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000075#ifdef CONFIG_SYS_SDRAM_BASE1xx
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020076 MCFSDRAMC_DACR1 = MCFSDRAMC_DACR_BASE (CONFIG_SYS_SDRAM_BASE1)
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020077 | MCFSDRAMC_DACR_CASL (1)
78 | MCFSDRAMC_DACR_CBM (3)
79 | MCFSDRAMC_DACR_PS_16;
Heiko Schocherac1956e2006-04-20 08:42:42 +020080
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020081 MCFSDRAMC_DMR1 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
Heiko Schocherac1956e2006-04-20 08:42:42 +020082
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020083 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IP;
84
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085 *(unsigned short *) (CONFIG_SYS_SDRAM_BASE1) = 0xA5A5;
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020086 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_RE;
87
88 for (i = 0; i < 2000; i++)
89 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020090
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020091 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IMRS;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020092 *(unsigned int *) (CONFIG_SYS_SDRAM_BASE1 + 0x220) = 0xA5A5;
93 size += CONFIG_SYS_SDRAM_SIZE1 * 1024 * 1024;
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020094#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +020095 return size;
96}
97
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098#if defined(CONFIG_SYS_DRAM_TEST)
Heiko Schocherac1956e2006-04-20 08:42:42 +020099int testdram (void)
100{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
102 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Heiko Schocherac1956e2006-04-20 08:42:42 +0200103 uint *p;
104
105 printf("SDRAM test phase 1:\n");
106 for (p = pstart; p < pend; p++)
107 *p = 0xaaaaaaaa;
108
109 for (p = pstart; p < pend; p++) {
110 if (*p != 0xaaaaaaaa) {
111 printf ("SDRAM test fails at: %08x\n", (uint) p);
112 return 1;
113 }
114 }
115
116 printf("SDRAM test phase 2:\n");
117 for (p = pstart; p < pend; p++)
118 *p = 0x55555555;
119
120 for (p = pstart; p < pend; p++) {
121 if (*p != 0x55555555) {
122 printf ("SDRAM test fails at: %08x\n", (uint) p);
123 return 1;
124 }
125 }
126
127 printf("SDRAM test passed.\n");
128 return 0;
129}
130#endif
131
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000132#if defined(CONFIG_HW_WATCHDOG)
133
134void hw_watchdog_init(void)
135{
136 char *s;
137 int enable;
138
139 enable = 1;
140 s = getenv("watchdog");
141 if (s != NULL)
142 if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0", 1) == 0))
143 enable = 0;
144 if (enable)
145 MCFGPTA_GPTDDR |= (1<<2);
146 else
147 MCFGPTA_GPTDDR &= ~(1<<2);
148}
149
150void hw_watchdog_reset(void)
151{
152 MCFGPTA_GPTPORT ^= (1<<2);
153}
154#endif
155
Heiko Schocherac1956e2006-04-20 08:42:42 +0200156int misc_init_r(void)
157{
Jens Scharsig772d9b02009-07-24 10:31:48 +0200158#ifdef CONFIG_HW_WATCHDOG
159 hw_watchdog_init();
160#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +0200161 return 1;
162}
Jens Scharsig772d9b02009-07-24 10:31:48 +0200163
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000164void __led_toggle(led_id_t mask)
165{
166 MCFGPTA_GPTPORT ^= (1 << 3);
167}
168
169void __led_init(led_id_t mask, int state)
170{
171 __led_set(mask, state);
172 MCFGPTA_GPTDDR |= (1 << 3);
173}
Jens Scharsig772d9b02009-07-24 10:31:48 +0200174
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000175void __led_set(led_id_t mask, int state)
176{
177 if (state == STATUS_LED_ON)
178 MCFGPTA_GPTPORT |= (1 << 3);
179 else
180 MCFGPTA_GPTPORT &= ~(1 << 3);
181}
182
183#if defined(CONFIG_VIDEO)
Jens Scharsig772d9b02009-07-24 10:31:48 +0200184
185int drv_video_init(void)
186{
187 char *s;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000188#ifdef CONFIG_SPLASH_SCREEN
Jens Scharsig772d9b02009-07-24 10:31:48 +0200189 unsigned long splash;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000190#endif
Jens Scharsig772d9b02009-07-24 10:31:48 +0200191 printf("Init Video as ");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000192 s = getenv("displaywidth");
193 if (s != NULL)
Jens Scharsig772d9b02009-07-24 10:31:48 +0200194 display_width = simple_strtoul(s, NULL, 10);
195 else
196 display_width = 256;
197
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000198 s = getenv("displayheight");
199 if (s != NULL)
Jens Scharsig772d9b02009-07-24 10:31:48 +0200200 display_height = simple_strtoul(s, NULL, 10);
201 else
202 display_height = 256;
203
204 printf("%lu x %lu pixel matrix\n", display_width, display_height);
205
206 MCFCCM_CCR &= ~MCFCCM_CCR_SZEN;
207 MCFGPIO_PEPAR &= ~MCFGPIO_PEPAR_PEPA2;
208
209 vcxk_init(display_width, display_height);
210
211#ifdef CONFIG_SPLASH_SCREEN
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000212 s = getenv("splashimage");
213 if (s != NULL) {
Jens Scharsig772d9b02009-07-24 10:31:48 +0200214 splash = simple_strtoul(s, NULL, 16);
Jens Scharsig772d9b02009-07-24 10:31:48 +0200215 vcxk_acknowledge_wait();
216 video_display_bitmap(splash, 0, 0);
217 }
218#endif
219 return 0;
220}
221#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +0200222
223/*---------------------------------------------------------------------------*/
224
Jens Scharsig772d9b02009-07-24 10:31:48 +0200225#ifdef CONFIG_VIDEO
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200226int do_brightness(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocherac1956e2006-04-20 08:42:42 +0200227{
228 int rcode = 0;
Jens Scharsig772d9b02009-07-24 10:31:48 +0200229 ulong side;
230 ulong bright;
Heiko Schocherac1956e2006-04-20 08:42:42 +0200231
232 switch (argc) {
Jens Scharsig772d9b02009-07-24 10:31:48 +0200233 case 3:
234 side = simple_strtoul(argv[1], NULL, 10);
235 bright = simple_strtoul(argv[2], NULL, 10);
236 if ((side >= 0) && (side <= 3) &&
237 (bright >= 0) && (bright <= 1000)) {
238 vcxk_setbrightness(side, bright);
239 rcode = 0;
240 } else {
241 printf("parameters out of range\n");
242 printf("Usage:\n%s\n", cmdtp->usage);
243 rcode = 1;
244 }
Heiko Schocherac1956e2006-04-20 08:42:42 +0200245 break;
246 default:
Jens Scharsig772d9b02009-07-24 10:31:48 +0200247 printf("Usage:\n%s\n", cmdtp->usage);
Heiko Schocherac1956e2006-04-20 08:42:42 +0200248 rcode = 1;
249 break;
250 }
251 return rcode;
252}
253
Jens Scharsig772d9b02009-07-24 10:31:48 +0200254/*---------------------------------------------------------------------------*/
Heiko Schocherac1956e2006-04-20 08:42:42 +0200255
256U_BOOT_CMD(
Jens Scharsig772d9b02009-07-24 10:31:48 +0200257 bright, 3, 0, do_brightness,
258 "sets the display brightness\n",
259 " <side> <0..1000>\n side: 0/3=both; 1=first; 2=second\n"
Heiko Schocherac1956e2006-04-20 08:42:42 +0200260);
261
Jens Scharsig772d9b02009-07-24 10:31:48 +0200262#endif
263
264/* EOF EB+MCF-EV123.c */