1 /*
2  * (C) Copyright 2005-2009
3  * 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  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26 
27 #include <common.h>
28 #include <command.h>
29 #include "asm/m5282.h"
30 #include <bmp_layout.h>
31 #include <status_led.h>
32 #include <bus_vcxk.h>
33 
34 /*---------------------------------------------------------------------------*/
35 
36 DECLARE_GLOBAL_DATA_PTR;
37 
38 #ifdef CONFIG_VIDEO
39 unsigned long display_width;
40 unsigned long display_height;
41 #endif
42 
43 /*---------------------------------------------------------------------------*/
44 
45 int checkboard (void)
46 {
47 	puts("Board: EB+CPU5282 (BuS Elektronik GmbH & Co. KG)\n");
48 #if (CONFIG_SYS_TEXT_BASE ==  CONFIG_SYS_INT_FLASH_BASE)
49 	puts("       Boot from Internal FLASH\n");
50 #endif
51 	return 0;
52 }
53 
54 phys_size_t initdram (int board_type)
55 {
56 	int size, i;
57 
58 	size = 0;
59 	MCFSDRAMC_DCR = MCFSDRAMC_DCR_RTIM_6 |
60 			MCFSDRAMC_DCR_RC((15 * CONFIG_SYS_CLK / 1000000) >> 4);
61 	asm (" nop");
62 #ifdef CONFIG_SYS_SDRAM_BASE0
63 	MCFSDRAMC_DACR0 = MCFSDRAMC_DACR_BASE(CONFIG_SYS_SDRAM_BASE0)|
64 		MCFSDRAMC_DACR_CASL(1) | MCFSDRAMC_DACR_CBM(3) |
65 		MCFSDRAMC_DACR_PS_32;
66 	asm (" nop");
67 
68 	MCFSDRAMC_DMR0 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
69 	asm (" nop");
70 
71 	MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP;
72 	asm (" nop");
73 	for (i = 0; i < 10; i++)
74 		asm (" nop");
75 
76 	*(unsigned long *)(CONFIG_SYS_SDRAM_BASE0) = 0xA5A5A5A5;
77 	asm (" nop");
78 	MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE;
79 	asm (" nop");
80 
81 	for (i = 0; i < 2000; i++)
82 		asm (" nop");
83 
84 	MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IMRS;
85 	asm (" nop");
86 	/* write SDRAM mode register */
87 	*(unsigned long *)(CONFIG_SYS_SDRAM_BASE0 + 0x80440) = 0xA5A5A5A5;
88 	asm (" nop");
89 	size += CONFIG_SYS_SDRAM_SIZE0 * 1024 * 1024;
90 #endif
91 #ifdef CONFIG_SYS_SDRAM_BASE1xx
92 	MCFSDRAMC_DACR1 = MCFSDRAMC_DACR_BASE (CONFIG_SYS_SDRAM_BASE1)
93 			| MCFSDRAMC_DACR_CASL (1)
94 			| MCFSDRAMC_DACR_CBM (3)
95 			| MCFSDRAMC_DACR_PS_16;
96 
97 	MCFSDRAMC_DMR1 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
98 
99 	MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IP;
100 
101 	*(unsigned short *) (CONFIG_SYS_SDRAM_BASE1) = 0xA5A5;
102 	MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_RE;
103 
104 	for (i = 0; i < 2000; i++)
105 		asm (" nop");
106 
107 	MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IMRS;
108 	*(unsigned int *) (CONFIG_SYS_SDRAM_BASE1 + 0x220) = 0xA5A5;
109 	size += CONFIG_SYS_SDRAM_SIZE1 * 1024 * 1024;
110 #endif
111 	return size;
112 }
113 
114 #if defined(CONFIG_SYS_DRAM_TEST)
115 int testdram (void)
116 {
117 	uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
118 	uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
119 	uint *p;
120 
121 	printf("SDRAM test phase 1:\n");
122 	for (p = pstart; p < pend; p++)
123 		*p = 0xaaaaaaaa;
124 
125 	for (p = pstart; p < pend; p++) {
126 		if (*p != 0xaaaaaaaa) {
127 			printf ("SDRAM test fails at: %08x\n", (uint) p);
128 			return 1;
129 		}
130 	}
131 
132 	printf("SDRAM test phase 2:\n");
133 	for (p = pstart; p < pend; p++)
134 		*p = 0x55555555;
135 
136 	for (p = pstart; p < pend; p++) {
137 		if (*p != 0x55555555) {
138 			printf ("SDRAM test fails at: %08x\n", (uint) p);
139 			return 1;
140 		}
141 	}
142 
143 	printf("SDRAM test passed.\n");
144 	return 0;
145 }
146 #endif
147 
148 #if defined(CONFIG_HW_WATCHDOG)
149 
150 void hw_watchdog_init(void)
151 {
152 	char *s;
153 	int enable;
154 
155 	enable = 1;
156 	s = getenv("watchdog");
157 	if (s != NULL)
158 		if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0", 1) == 0))
159 			enable = 0;
160 	if (enable)
161 		MCFGPTA_GPTDDR  |= (1<<2);
162 	else
163 		MCFGPTA_GPTDDR  &= ~(1<<2);
164 }
165 
166 void hw_watchdog_reset(void)
167 {
168 	MCFGPTA_GPTPORT  ^= (1<<2);
169 }
170 #endif
171 
172 int misc_init_r(void)
173 {
174 #ifdef	CONFIG_HW_WATCHDOG
175 	hw_watchdog_init();
176 #endif
177 	return 1;
178 }
179 
180 void __led_toggle(led_id_t mask)
181 {
182 	MCFGPTA_GPTPORT ^= (1 << 3);
183 }
184 
185 void __led_init(led_id_t mask, int state)
186 {
187 	__led_set(mask, state);
188 	MCFGPTA_GPTDDR  |= (1 << 3);
189 }
190 
191 void __led_set(led_id_t mask, int state)
192 {
193 	if (state == STATUS_LED_ON)
194 		MCFGPTA_GPTPORT |= (1 << 3);
195 	else
196 		MCFGPTA_GPTPORT &= ~(1 << 3);
197 }
198 
199 #if defined(CONFIG_VIDEO)
200 
201 int drv_video_init(void)
202 {
203 	char *s;
204 #ifdef CONFIG_SPLASH_SCREEN
205 	unsigned long splash;
206 #endif
207 	printf("Init Video as ");
208 	s = getenv("displaywidth");
209 	if (s != NULL)
210 		display_width = simple_strtoul(s, NULL, 10);
211 	else
212 		display_width = 256;
213 
214 	s = getenv("displayheight");
215 	if (s != NULL)
216 		display_height = simple_strtoul(s, NULL, 10);
217 	else
218 		display_height = 256;
219 
220 	printf("%lu x %lu pixel matrix\n", display_width, display_height);
221 
222 	MCFCCM_CCR &= ~MCFCCM_CCR_SZEN;
223 	MCFGPIO_PEPAR &= ~MCFGPIO_PEPAR_PEPA2;
224 
225 	vcxk_init(display_width, display_height);
226 
227 #ifdef CONFIG_SPLASH_SCREEN
228 	s = getenv("splashimage");
229 	if (s != NULL) {
230 		splash = simple_strtoul(s, NULL, 16);
231 		vcxk_acknowledge_wait();
232 		video_display_bitmap(splash, 0, 0);
233 	}
234 #endif
235 	return 0;
236 }
237 #endif
238 
239 /*---------------------------------------------------------------------------*/
240 
241 #ifdef CONFIG_VIDEO
242 int do_brightness(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
243 {
244 	int rcode = 0;
245 	ulong side;
246 	ulong bright;
247 
248 	switch (argc) {
249 	case 3:
250 		side = simple_strtoul(argv[1], NULL, 10);
251 		bright = simple_strtoul(argv[2], NULL, 10);
252 		if ((side >= 0) && (side <= 3) &&
253 			(bright >= 0) && (bright <= 1000)) {
254 			vcxk_setbrightness(side, bright);
255 			rcode = 0;
256 		} else {
257 			printf("parameters out of range\n");
258 			printf("Usage:\n%s\n", cmdtp->usage);
259 			rcode = 1;
260 		}
261 		break;
262 	default:
263 		printf("Usage:\n%s\n", cmdtp->usage);
264 		rcode = 1;
265 		break;
266 	}
267 	return rcode;
268 }
269 
270 /*---------------------------------------------------------------------------*/
271 
272 U_BOOT_CMD(
273 	bright,	3,	0,	do_brightness,
274 	"sets the display brightness\n",
275 	" <side> <0..1000>\n        side: 0/3=both; 1=first; 2=second\n"
276 );
277 
278 #endif
279 
280 /* EOF EB+MCF-EV123.c */
281