blob: c254da62bf4385418d599a42c1dda9e8fe64f0c7 [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
Tom Rinidec7ea02024-05-20 13:35:03 -060010#include <config.h>
Heiko Schocherac1956e2006-04-20 08:42:42 +020011#include <command.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Heiko Schocherac1956e2006-04-20 08:42:42 +020013#include "asm/m5282.h"
Jens Scharsig772d9b02009-07-24 10:31:48 +020014#include <bmp_layout.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060015#include <env.h>
Simon Glass0ffd9db2019-12-28 10:45:06 -070016#include <init.h>
Jens Scharsig772d9b02009-07-24 10:31:48 +020017#include <status_led.h>
18#include <bus_vcxk.h>
19
20/*---------------------------------------------------------------------------*/
21
22DECLARE_GLOBAL_DATA_PTR;
23
Jens Scharsig772d9b02009-07-24 10:31:48 +020024/*---------------------------------------------------------------------------*/
Heiko Schocherac1956e2006-04-20 08:42:42 +020025
26int checkboard (void)
27{
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000028 puts("Board: EB+CPU5282 (BuS Elektronik GmbH & Co. KG)\n");
Tom Rini6a5dccc2022-11-16 13:10:41 -050029#if (CONFIG_TEXT_BASE == CFG_SYS_INT_FLASH_BASE)
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000030 puts(" Boot from Internal FLASH\n");
Heiko Schocherac1956e2006-04-20 08:42:42 +020031#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +020032 return 0;
33}
34
Simon Glassd35f3382017-04-06 12:47:05 -060035int dram_init(void)
Heiko Schocherac1956e2006-04-20 08:42:42 +020036{
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020037 int size, i;
Heiko Schocherac1956e2006-04-20 08:42:42 +020038
39 size = 0;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000040 MCFSDRAMC_DCR = MCFSDRAMC_DCR_RTIM_6 |
Tom Rini6a5dccc2022-11-16 13:10:41 -050041 MCFSDRAMC_DCR_RC((15 * CFG_SYS_CLK / 1000000) >> 4);
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000042 asm (" nop");
Tom Rinibb4dd962022-11-16 13:10:37 -050043#ifdef CFG_SYS_SDRAM_BASE0
44 MCFSDRAMC_DACR0 = MCFSDRAMC_DACR_BASE(CFG_SYS_SDRAM_BASE0)|
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000045 MCFSDRAMC_DACR_CASL(1) | MCFSDRAMC_DACR_CBM(3) |
46 MCFSDRAMC_DACR_PS_32;
47 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020048
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020049 MCFSDRAMC_DMR0 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000050 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020051
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020052 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000053 asm (" nop");
54 for (i = 0; i < 10; i++)
55 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020056
Tom Rinibb4dd962022-11-16 13:10:37 -050057 *(unsigned long *)(CFG_SYS_SDRAM_BASE0) = 0xA5A5A5A5;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000058 asm (" nop");
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020059 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000060 asm (" nop");
61
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020062 for (i = 0; i < 2000; i++)
63 asm (" nop");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000064
65 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IMRS;
66 asm (" nop");
67 /* write SDRAM mode register */
Tom Rinibb4dd962022-11-16 13:10:37 -050068 *(unsigned long *)(CFG_SYS_SDRAM_BASE0 + 0x80440) = 0xA5A5A5A5;
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +000069 asm (" nop");
Tom Rinibb4dd962022-11-16 13:10:37 -050070 size += CFG_SYS_SDRAM_SIZE0 * 1024 * 1024;
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020071#endif
Tom Rinibb4dd962022-11-16 13:10:37 -050072#ifdef CFG_SYS_SDRAM_BASE1xx
73 MCFSDRAMC_DACR1 = MCFSDRAMC_DACR_BASE (CFG_SYS_SDRAM_BASE1)
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020074 | MCFSDRAMC_DACR_CASL (1)
75 | MCFSDRAMC_DACR_CBM (3)
76 | MCFSDRAMC_DACR_PS_16;
Heiko Schocherac1956e2006-04-20 08:42:42 +020077
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020078 MCFSDRAMC_DMR1 = MCFSDRAMC_DMR_BAM_16M | MCFSDRAMC_DMR_V;
Heiko Schocherac1956e2006-04-20 08:42:42 +020079
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020080 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IP;
81
Tom Rinibb4dd962022-11-16 13:10:37 -050082 *(unsigned short *) (CFG_SYS_SDRAM_BASE1) = 0xA5A5;
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020083 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_RE;
84
85 for (i = 0; i < 2000; i++)
86 asm (" nop");
Heiko Schocherac1956e2006-04-20 08:42:42 +020087
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020088 MCFSDRAMC_DACR1 |= MCFSDRAMC_DACR_IMRS;
Tom Rinibb4dd962022-11-16 13:10:37 -050089 *(unsigned int *) (CFG_SYS_SDRAM_BASE1 + 0x220) = 0xA5A5;
90 size += CFG_SYS_SDRAM_SIZE1 * 1024 * 1024;
Wolfgang Denkc4f55ee2008-07-14 20:38:26 +020091#endif
Simon Glass39f90ba2017-03-31 08:40:25 -060092 gd->ram_size = size;
93
94 return 0;
Heiko Schocherac1956e2006-04-20 08:42:42 +020095}
96
Tom Rini6a5dccc2022-11-16 13:10:41 -050097#if defined(CFG_SYS_DRAM_TEST)
Simon Glass0ffd9db2019-12-28 10:45:06 -070098int testdram(void)
Heiko Schocherac1956e2006-04-20 08:42:42 +020099{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
101 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Heiko Schocherac1956e2006-04-20 08:42:42 +0200102 uint *p;
103
104 printf("SDRAM test phase 1:\n");
105 for (p = pstart; p < pend; p++)
106 *p = 0xaaaaaaaa;
107
108 for (p = pstart; p < pend; p++) {
109 if (*p != 0xaaaaaaaa) {
110 printf ("SDRAM test fails at: %08x\n", (uint) p);
111 return 1;
112 }
113 }
114
115 printf("SDRAM test phase 2:\n");
116 for (p = pstart; p < pend; p++)
117 *p = 0x55555555;
118
119 for (p = pstart; p < pend; p++) {
120 if (*p != 0x55555555) {
121 printf ("SDRAM test fails at: %08x\n", (uint) p);
122 return 1;
123 }
124 }
125
126 printf("SDRAM test passed.\n");
127 return 0;
128}
129#endif
130
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000131#if defined(CONFIG_HW_WATCHDOG)
132
133void hw_watchdog_init(void)
134{
135 char *s;
136 int enable;
137
138 enable = 1;
Simon Glass64b723f2017-08-03 12:22:12 -0600139 s = env_get("watchdog");
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000140 if (s != NULL)
141 if ((strncmp(s, "off", 3) == 0) || (strncmp(s, "0", 1) == 0))
142 enable = 0;
143 if (enable)
144 MCFGPTA_GPTDDR |= (1<<2);
145 else
146 MCFGPTA_GPTDDR &= ~(1<<2);
147}
148
149void hw_watchdog_reset(void)
150{
151 MCFGPTA_GPTPORT ^= (1<<2);
152}
153#endif
154
Heiko Schocherac1956e2006-04-20 08:42:42 +0200155int misc_init_r(void)
156{
Jens Scharsig772d9b02009-07-24 10:31:48 +0200157#ifdef CONFIG_HW_WATCHDOG
158 hw_watchdog_init();
159#endif
Heiko Schocherac1956e2006-04-20 08:42:42 +0200160 return 1;
161}
Jens Scharsig772d9b02009-07-24 10:31:48 +0200162
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000163void __led_toggle(led_id_t mask)
164{
165 MCFGPTA_GPTPORT ^= (1 << 3);
166}
167
168void __led_init(led_id_t mask, int state)
169{
170 __led_set(mask, state);
171 MCFGPTA_GPTDDR |= (1 << 3);
172}
Jens Scharsig772d9b02009-07-24 10:31:48 +0200173
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000174void __led_set(led_id_t mask, int state)
175{
Uri Mashiach4892d392017-01-19 10:51:45 +0200176 if (state == CONFIG_LED_STATUS_ON)
Jens Scharsig (BuS Elektronik)e5e58372012-10-30 00:46:05 +0000177 MCFGPTA_GPTPORT |= (1 << 3);
178 else
179 MCFGPTA_GPTPORT &= ~(1 << 3);
180}
Heiko Schocherac1956e2006-04-20 08:42:42 +0200181
182/*---------------------------------------------------------------------------*/
183
Jens Scharsig772d9b02009-07-24 10:31:48 +0200184/* EOF EB+MCF-EV123.c */