]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/ivm/ivm.c
Merge git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / board / ivm / ivm.c
1 /*
2  * (C) Copyright 2000, 2001
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  * Ulrich Lutz, Speech Design GmbH, ulutz@datalab.de.
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <mpc8xx.h>
11 #include <commproc.h>
12
13 #ifdef CONFIG_STATUS_LED
14 # include <status_led.h>
15 #endif
16
17 /* ------------------------------------------------------------------------- */
18
19 static long int dram_size (long int, long int *, long int);
20
21 /* ------------------------------------------------------------------------- */
22
23 #define _NOT_USED_      0xFFFFFFFF
24
25 /*
26  * 50 MHz SHARC access using UPM A
27  */
28 const uint sharc_table[] = {
29         /*
30          * Single Read. (Offset 0 in UPM RAM)
31          */
32         0x0FF3FC04, 0x0FF3EC00, 0x7FFFEC04, 0xFFFFEC04,
33         0xFFFFEC05,             /* last */
34         _NOT_USED_, _NOT_USED_, _NOT_USED_,
35         /*
36          * Burst Read. (Offset 8 in UPM RAM)
37          */
38         /* last */
39         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
40         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
41         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
42         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
43         /*
44          * Single Write. (Offset 18 in UPM RAM)
45          */
46         0x0FAFFC04, 0x0FAFEC00, 0x7FFFEC04, 0xFFFFEC04,
47         0xFFFFEC05,             /* last */
48         _NOT_USED_, _NOT_USED_, _NOT_USED_,
49         /*
50          * Burst Write. (Offset 20 in UPM RAM)
51          */
52         /* last */
53         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
54         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
55         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
56         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
57         /*
58          * Refresh  (Offset 30 in UPM RAM)
59          */
60         /* last */
61         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
62         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
63         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
64         /*
65          * Exception. (Offset 3c in UPM RAM)
66          */
67         0x7FFFFC07,             /* last */
68         _NOT_USED_, _NOT_USED_, _NOT_USED_,
69 };
70
71
72 /*
73  * 50 MHz SDRAM access using UPM B
74  */
75 const uint sdram_table[] = {
76         /*
77          * Single Read. (Offset 0 in UPM RAM)
78          */
79         0x0E26FC04, 0x11ADFC04, 0xEFBBBC00, 0x1FF77C45, /* last */
80         _NOT_USED_,
81         /*
82          * SDRAM Initialization (offset 5 in UPM RAM)
83          *
84          * This is no UPM entry point. The following definition uses
85          * the remaining space to establish an initialization
86          * sequence, which is executed by a RUN command.
87          *
88          */
89         0x1FF77C35, 0xEFEABC34, 0x1FB57C35,     /* last */
90         /*
91          * Burst Read. (Offset 8 in UPM RAM)
92          */
93         0x0E26FC04, 0x10ADFC04, 0xF0AFFC00, 0xF0AFFC00,
94         0xF1AFFC00, 0xEFBBBC00, 0x1FF77C45,     /* last */
95         _NOT_USED_,
96         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
97         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
98         /*
99          * Single Write. (Offset 18 in UPM RAM)
100          */
101         0x1F27FC04, 0xEEAEBC04, 0x01B93C00, 0x1FF77C45, /* last */
102         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
103         /*
104          * Burst Write. (Offset 20 in UPM RAM)
105          */
106         0x0E26BC00, 0x10AD7C00, 0xF0AFFC00, 0xF0AFFC00,
107         0xE1BBBC04, 0x1FF77C45, /* last */
108         _NOT_USED_, _NOT_USED_,
109         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
110         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
111         /*
112          * Refresh  (Offset 30 in UPM RAM)
113          */
114         0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC84,
115         0xFFFFFC05,             /* last */
116         _NOT_USED_, _NOT_USED_, _NOT_USED_,
117         _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
118         /*
119          * Exception. (Offset 3c in UPM RAM)
120          */
121         0x7FFFFC07,             /* last */
122         _NOT_USED_, _NOT_USED_, _NOT_USED_,
123 };
124
125 /* ------------------------------------------------------------------------- */
126
127
128 /*
129  * Check Board Identity:
130  *
131  */
132
133 int checkboard (void)
134 {
135 #ifdef CONFIG_IVMS8
136         puts ("Board: IVMS8\n");
137 #endif
138 #ifdef CONFIG_IVML24
139         puts ("Board: IVM-L8/24\n");
140 #endif
141         return (0);
142 }
143
144 /* ------------------------------------------------------------------------- */
145
146 phys_size_t initdram (int board_type)
147 {
148         volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
149         volatile memctl8xx_t *memctl = &immr->im_memctl;
150         long int size_b0;
151
152         /* enable SDRAM clock ("switch on" SDRAM) */
153         immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_SDRAM_CLKE);   /* GPIO */
154         immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_SDRAM_CLKE);   /* active output */
155         immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_SDRAM_CLKE;      /* output */
156         immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_SDRAM_CLKE;      /* assert SDRAM CLKE */
157         udelay (1);
158
159         /*
160          * Map controller bank 1 for ELIC SACCO
161          */
162         memctl->memc_or1 = CONFIG_SYS_OR1;
163         memctl->memc_br1 = CONFIG_SYS_BR1;
164
165         /*
166          * Map controller bank 2 for ELIC EPIC
167          */
168         memctl->memc_or2 = CONFIG_SYS_OR2;
169         memctl->memc_br2 = CONFIG_SYS_BR2;
170
171         /*
172          * Configure UPMA for SHARC
173          */
174         upmconfig (UPMA, (uint *) sharc_table,
175                    sizeof (sharc_table) / sizeof (uint));
176
177 #if defined(CONFIG_IVML24)
178         /*
179          * Map controller bank 4 for HDLC Address space
180          */
181         memctl->memc_or4 = CONFIG_SYS_OR4;
182         memctl->memc_br4 = CONFIG_SYS_BR4;
183 #endif
184
185         /*
186          * Map controller bank 5 for SHARC
187          */
188         memctl->memc_or5 = CONFIG_SYS_OR5;
189         memctl->memc_br5 = CONFIG_SYS_BR5;
190
191         memctl->memc_mamr = 0x00001000;
192
193         /*
194          * Configure UPMB for SDRAM
195          */
196         upmconfig (UPMB, (uint *) sdram_table,
197                    sizeof (sdram_table) / sizeof (uint));
198
199         memctl->memc_mptpr = CONFIG_SYS_MPTPR_1BK_8K;
200
201         memctl->memc_mar = 0x00000088;
202
203         /*
204          * Map controller bank 3 to the SDRAM bank at preliminary address.
205          */
206         memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
207         memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
208
209         memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL;       /* refresh not enabled yet */
210
211         udelay (200);
212         memctl->memc_mcr = 0x80806105;  /* precharge */
213         udelay (1);
214         memctl->memc_mcr = 0x80806106;  /* load mode register */
215         udelay (1);
216         memctl->memc_mcr = 0x80806130;  /* autorefresh */
217         udelay (1);
218         memctl->memc_mcr = 0x80806130;  /* autorefresh */
219         udelay (1);
220         memctl->memc_mcr = 0x80806130;  /* autorefresh */
221         udelay (1);
222         memctl->memc_mcr = 0x80806130;  /* autorefresh */
223         udelay (1);
224         memctl->memc_mcr = 0x80806130;  /* autorefresh */
225         udelay (1);
226         memctl->memc_mcr = 0x80806130;  /* autorefresh */
227         udelay (1);
228         memctl->memc_mcr = 0x80806130;  /* autorefresh */
229         udelay (1);
230         memctl->memc_mcr = 0x80806130;  /* autorefresh */
231
232         memctl->memc_mbmr |= MBMR_PTBE; /* refresh enabled */
233
234         /*
235          * Check Bank 0 Memory Size for re-configuration
236          */
237         size_b0 =
238                 dram_size (CONFIG_SYS_MBMR_8COL, (long *) SDRAM_BASE3_PRELIM,
239                            SDRAM_MAX_SIZE);
240
241         memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL | MBMR_PTBE;
242
243         return (size_b0);
244 }
245
246 /* ------------------------------------------------------------------------- */
247
248 /*
249  * Check memory range for valid RAM. A simple memory test determines
250  * the actually available RAM size between addresses `base' and
251  * `base + maxsize'. Some (not all) hardware errors are detected:
252  * - short between address lines
253  * - short between data lines
254  */
255
256 static long int dram_size (long int mamr_value, long int *base,
257                            long int maxsize)
258 {
259         volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
260         volatile memctl8xx_t *memctl = &immr->im_memctl;
261
262         memctl->memc_mbmr = mamr_value;
263
264         return (get_ram_size (base, maxsize));
265 }
266
267 /* ------------------------------------------------------------------------- */
268
269 void reset_phy (void)
270 {
271         immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
272
273         /* De-assert Ethernet Powerdown */
274         immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_ETH_POWERDOWN);        /* GPIO */
275         immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_ETH_POWERDOWN);        /* active output */
276         immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_ETH_POWERDOWN;   /* output */
277         immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_ETH_POWERDOWN);        /* Enable PHY power */
278         udelay (1000);
279
280         /*
281          * RESET is implemented by a positive pulse of at least 1 us
282          * at the reset pin.
283          *
284          * Configure RESET pins for NS DP83843 PHY, and RESET chip.
285          *
286          * Note: The RESET pin is high active, but there is an
287          *       inverter on the SPD823TS board...
288          */
289         immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_ETH_RESET);
290         immr->im_ioport.iop_pcdir |= CONFIG_SYS_PC_ETH_RESET;
291         /* assert RESET signal of PHY */
292         immr->im_ioport.iop_pcdat &= ~(CONFIG_SYS_PC_ETH_RESET);
293         udelay (10);
294         /* de-assert RESET signal of PHY */
295         immr->im_ioport.iop_pcdat |= CONFIG_SYS_PC_ETH_RESET;
296         udelay (10);
297 }
298
299 /* ------------------------------------------------------------------------- */
300
301 void show_boot_progress (int status)
302 {
303 #if defined(CONFIG_STATUS_LED)
304 # if defined(STATUS_LED_YELLOW)
305         status_led_set (STATUS_LED_YELLOW,
306                         (status < 0) ? STATUS_LED_ON : STATUS_LED_OFF);
307 # endif /* STATUS_LED_YELLOW */
308 # if defined(STATUS_LED_BOOT)
309         if (status == BOOTSTAGE_ID_DECOMP_IMAGE)
310                 status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
311 # endif /* STATUS_LED_BOOT */
312 #endif /* CONFIG_STATUS_LED */
313 }
314
315 /* ------------------------------------------------------------------------- */
316
317 void ide_set_reset (int on)
318 {
319         volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
320         int i;
321
322         /*
323          * Configure PC for IDE Reset Pin
324          */
325         if (on) {               /* assert RESET */
326                 immr->im_ioport.iop_pcdat &= ~(CONFIG_SYS_PC_IDE_RESET);
327
328 #ifdef CONFIG_SYS_PB_12V_ENABLE
329                 /* 12V Enable output OFF */
330                 immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_12V_ENABLE);
331
332                 immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_12V_ENABLE);
333                 immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_12V_ENABLE);
334                 immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_12V_ENABLE;
335
336                 /* wait 500 ms for the voltage to stabilize */
337                 for (i = 0; i < 500; ++i)
338                         udelay(1000);
339 #endif /* CONFIG_SYS_PB_12V_ENABLE */
340         } else {                /* release RESET */
341 #ifdef CONFIG_SYS_PB_12V_ENABLE
342                 /* 12V Enable output ON */
343                 immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_12V_ENABLE;
344 #endif /* CONFIG_SYS_PB_12V_ENABLE */
345
346 #ifdef CONFIG_SYS_PB_IDE_MOTOR
347                 /* configure IDE Motor voltage monitor pin as input */
348                 immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_IDE_MOTOR);
349                 immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_IDE_MOTOR);
350                 immr->im_cpm.cp_pbdir &= ~(CONFIG_SYS_PB_IDE_MOTOR);
351
352 /* wait up to 1 s for the motor voltage to stabilize */
353                 for (i = 0; i < 1000; ++i) {
354                         if ((immr->im_cpm.cp_pbdat
355                                         & CONFIG_SYS_PB_IDE_MOTOR) != 0)
356                                 break;
357                         udelay(1000);
358                 }
359
360                 if (i == 1000) {        /* Timeout */
361                         printf("\nWarning: 5V for IDE Motor missing\n");
362 #ifdef CONFIG_STATUS_LED
363 #ifdef STATUS_LED_YELLOW
364                         status_led_set(STATUS_LED_YELLOW, STATUS_LED_ON);
365 #endif
366 #ifdef STATUS_LED_GREEN
367                         status_led_set(STATUS_LED_GREEN, STATUS_LED_OFF);
368 #endif
369 #endif /* CONFIG_STATUS_LED */
370                 }
371 #endif /* CONFIG_SYS_PB_IDE_MOTOR */
372
373                 immr->im_ioport.iop_pcdat |= CONFIG_SYS_PC_IDE_RESET;
374         }
375
376         /* program port pin as GPIO output */
377         immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_IDE_RESET);
378         immr->im_ioport.iop_pcso &= ~(CONFIG_SYS_PC_IDE_RESET);
379         immr->im_ioport.iop_pcdir |= CONFIG_SYS_PC_IDE_RESET;
380 }
381
382 /* ------------------------------------------------------------------------- */