1
2
3
4
5
6
7
8#include <common.h>
9#include <asm/ppc4xx.h>
10#include <asm/processor.h>
11
12
13
14
15#include "../common/flash.c"
16
17
18
19
20static ulong flash_get_size (vu_long * addr, flash_info_t * info);
21static void flash_get_offsets (ulong base, flash_info_t * info);
22
23
24
25
26unsigned long flash_init (void)
27{
28#ifdef __DEBUG_START_FROM_SRAM__
29 return CONFIG_SYS_DUMMY_FLASH_SIZE;
30#else
31 unsigned long size;
32 int i;
33 uint pbcr;
34 unsigned long base;
35 int size_val = 0;
36
37 debug("[%s, %d] Entering ...\n", __FUNCTION__, __LINE__);
38 debug("[%s, %d] flash_info = 0x%p ...\n", __func__, __LINE__,
39 flash_info);
40
41
42 for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
43 flash_info[i].flash_id = FLASH_UNKNOWN;
44 }
45
46
47
48 debug("[%s, %d] Calling flash_get_size ...\n", __FUNCTION__, __LINE__);
49 size = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);
50
51 if (flash_info[0].flash_id == FLASH_UNKNOWN) {
52 printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
53 size, size<<20);
54 }
55
56 debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__);
57
58
59 flash_get_offsets (-size, &flash_info[0]);
60 debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__);
61
62
63 mtdcr(EBC0_CFGADDR, PB0CR);
64 pbcr = mfdcr(EBC0_CFGDATA);
65 mtdcr(EBC0_CFGADDR, PB0CR);
66 base = -size;
67 switch (size) {
68 case 1 << 20:
69 size_val = 0;
70 break;
71 case 2 << 20:
72 size_val = 1;
73 break;
74 case 4 << 20:
75 size_val = 2;
76 break;
77 case 8 << 20:
78 size_val = 3;
79 break;
80 case 16 << 20:
81 size_val = 4;
82 break;
83 }
84 pbcr = (pbcr & 0x0001ffff) | base | (size_val << 17);
85 mtdcr(EBC0_CFGDATA, pbcr);
86 debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__);
87
88
89 (void)flash_protect(FLAG_PROTECT_SET,
90 -CONFIG_SYS_MONITOR_LEN,
91 0xffffffff,
92 &flash_info[0]);
93
94 debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__);
95 flash_info[0].size = size;
96
97 return (size);
98#endif
99}
100