Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / board / BuS / eb_cpu5282 / eb_cpu5282.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2005-2009
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.
8  */
9
10 #include <common.h>
11 #include <command.h>
12 #include "asm/m5282.h"
13 #include <bmp_layout.h>
14 #include <env.h>
15 #include <init.h>
16 #include <status_led.h>
17 #include <bus_vcxk.h>
18
19 /*---------------------------------------------------------------------------*/
20
21 DECLARE_GLOBAL_DATA_PTR;
22
23 #ifdef CONFIG_VIDEO
24 unsigned long display_width;
25 unsigned long display_height;
26 #endif
27
28 /*---------------------------------------------------------------------------*/
29
30 int checkboard (void)
31 {
32         puts("Board: EB+CPU5282 (BuS Elektronik GmbH & Co. KG)\n");
33 #if (CONFIG_SYS_TEXT_BASE ==  CONFIG_SYS_INT_FLASH_BASE)
34         puts("       Boot from Internal FLASH\n");
35 #endif
36         return 0;
37 }
38
39 int dram_init(void)
40 {
41         int size, i;
42
43         size = 0;
44         MCFSDRAMC_DCR = MCFSDRAMC_DCR_RTIM_6 |
45                         MCFSDRAMC_DCR_RC((15 * CONFIG_SYS_CLK / 1000000) >> 4);
46         asm (" nop");
47 #ifdef CONFIG_SYS_SDRAM_BASE0
48         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");
52
53         MCFSDRAMC_DMR0 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
54         asm (" nop");
55
56         MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP;
57         asm (" nop");
58         for (i = 0; i < 10; i++)
59                 asm (" nop");
60
61         *(unsigned long *)(CONFIG_SYS_SDRAM_BASE0) = 0xA5A5A5A5;
62         asm (" nop");
63         MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE;
64         asm (" nop");
65
66         for (i = 0; i < 2000; i++)
67                 asm (" nop");
68
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;
75 #endif
76 #ifdef CONFIG_SYS_SDRAM_BASE1xx
77         MCFSDRAMC_DACR1 = MCFSDRAMC_DACR_BASE (CONFIG_SYS_SDRAM_BASE1)
78                         | MCFSDRAMC_DACR_CASL (1)
79                         | MCFSDRAMC_DACR_CBM (3)
80                         | MCFSDRAMC_DACR_PS_16;
81
82         MCFSDRAMC_DMR1 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
83
84         MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IP;
85
86         *(unsigned short *) (CONFIG_SYS_SDRAM_BASE1) = 0xA5A5;
87         MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_RE;
88
89         for (i = 0; i < 2000; i++)
90                 asm (" nop");
91
92         MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IMRS;
93         *(unsigned int *) (CONFIG_SYS_SDRAM_BASE1 + 0x220) = 0xA5A5;
94         size += CONFIG_SYS_SDRAM_SIZE1 * 1024 * 1024;
95 #endif
96         gd->ram_size = size;
97
98         return 0;
99 }
100
101 #if defined(CONFIG_SYS_DRAM_TEST)
102 int testdram(void)
103 {
104         uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
105         uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
106         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
135 #if defined(CONFIG_HW_WATCHDOG)
136
137 void hw_watchdog_init(void)
138 {
139         char *s;
140         int enable;
141
142         enable = 1;
143         s = env_get("watchdog");
144         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
153 void hw_watchdog_reset(void)
154 {
155         MCFGPTA_GPTPORT  ^= (1<<2);
156 }
157 #endif
158
159 int misc_init_r(void)
160 {
161 #ifdef  CONFIG_HW_WATCHDOG
162         hw_watchdog_init();
163 #endif
164         return 1;
165 }
166
167 void __led_toggle(led_id_t mask)
168 {
169         MCFGPTA_GPTPORT ^= (1 << 3);
170 }
171
172 void __led_init(led_id_t mask, int state)
173 {
174         __led_set(mask, state);
175         MCFGPTA_GPTDDR  |= (1 << 3);
176 }
177
178 void __led_set(led_id_t mask, int state)
179 {
180         if (state == CONFIG_LED_STATUS_ON)
181                 MCFGPTA_GPTPORT |= (1 << 3);
182         else
183                 MCFGPTA_GPTPORT &= ~(1 << 3);
184 }
185
186 #if defined(CONFIG_VIDEO)
187
188 int drv_video_init(void)
189 {
190         char *s;
191 #ifdef CONFIG_SPLASH_SCREEN
192         unsigned long splash;
193 #endif
194         printf("Init Video as ");
195         s = env_get("displaywidth");
196         if (s != NULL)
197                 display_width = simple_strtoul(s, NULL, 10);
198         else
199                 display_width = 256;
200
201         s = env_get("displayheight");
202         if (s != NULL)
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
215         s = env_get("splashimage");
216         if (s != NULL) {
217                 splash = simple_strtoul(s, NULL, 16);
218                 vcxk_acknowledge_wait();
219                 video_display_bitmap(splash, 0, 0);
220         }
221 #endif
222         return 0;
223 }
224 #endif
225
226 /*---------------------------------------------------------------------------*/
227
228 #ifdef CONFIG_VIDEO
229 int do_brightness(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
230 {
231         int rcode = 0;
232         ulong side;
233         ulong bright;
234
235         switch (argc) {
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                 }
248                 break;
249         default:
250                 printf("Usage:\n%s\n", cmdtp->usage);
251                 rcode = 1;
252                 break;
253         }
254         return rcode;
255 }
256
257 /*---------------------------------------------------------------------------*/
258
259 U_BOOT_CMD(
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"
263 );
264
265 #endif
266
267 /* EOF EB+MCF-EV123.c */