2 * (C) Copyright 2001-2003
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/ppc4xx.h>
10 #include <asm/processor.h>
13 * include common flash code (for esd boards)
15 #include "../common/flash.c"
17 /*-----------------------------------------------------------------------
20 static ulong flash_get_size (vu_long * addr, flash_info_t * info);
21 static void flash_get_offsets (ulong base, flash_info_t * info);
23 /*-----------------------------------------------------------------------
26 unsigned long calc_size(unsigned long size)
45 unsigned long flash_init (void)
47 unsigned long size_b0, size_b1;
50 unsigned long base_b0, base_b1;
52 /* Init: no FLASHes known */
53 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
54 flash_info[i].flash_id = FLASH_UNKNOWN;
57 /* Static FLASH Bank configuration here - FIXME XXX */
59 base_b0 = FLASH_BASE0_PRELIM;
60 size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
62 if (flash_info[0].flash_id == FLASH_UNKNOWN) {
63 printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
64 size_b0, size_b0 << 20);
67 base_b1 = FLASH_BASE1_PRELIM;
68 size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
70 /* Re-do sizing to get full correct info */
73 if (size_b1 < (1 << 20)) {
74 /* minimum CS size on PPC405GP is 1MB !!! */
78 mtdcr (EBC0_CFGADDR, PB0CR);
79 pbcr = mfdcr (EBC0_CFGDATA);
80 mtdcr (EBC0_CFGADDR, PB0CR);
81 pbcr = (pbcr & 0x0001ffff) | base_b1 | (calc_size(size_b1) << 17);
82 mtdcr (EBC0_CFGDATA, pbcr);
84 printf("size_b1=%x base_b1=%x PB1CR = %x\n",
85 size_b1, base_b1, pbcr); /* test-only */
90 if (size_b0 < (1 << 20)) {
91 /* minimum CS size on PPC405GP is 1MB !!! */
94 base_b0 = base_b1 - size_b0;
95 mtdcr (EBC0_CFGADDR, PB1CR);
96 pbcr = mfdcr (EBC0_CFGDATA);
97 mtdcr (EBC0_CFGADDR, PB1CR);
98 pbcr = (pbcr & 0x0001ffff) | base_b0 | (calc_size(size_b0) << 17);
99 mtdcr (EBC0_CFGDATA, pbcr);
100 #if 0 /* test-only */
101 printf("size_b0=%x base_b0=%x PB0CR = %x\n",
102 size_b0, base_b0, pbcr); /* test-only */
106 size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
108 flash_get_offsets (base_b0, &flash_info[0]);
110 /* monitor protection ON by default */
111 flash_protect (FLAG_PROTECT_SET,
112 base_b0 + size_b0 - monitor_flash_len,
113 base_b0 + size_b0 - 1, &flash_info[0]);
116 /* Re-do sizing to get full correct info */
117 size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
119 flash_get_offsets (base_b1, &flash_info[1]);
121 /* monitor protection ON by default */
122 flash_protect (FLAG_PROTECT_SET,
123 base_b1 + size_b1 - monitor_flash_len,
124 base_b1 + size_b1 - 1, &flash_info[1]);
125 /* monitor protection OFF by default (one is enough) */
126 flash_protect (FLAG_PROTECT_CLEAR,
127 base_b0 + size_b0 - monitor_flash_len,
128 base_b0 + size_b0 - 1, &flash_info[0]);
130 flash_info[1].flash_id = FLASH_UNKNOWN;
131 flash_info[1].sector_count = -1;
134 flash_info[0].size = size_b0;
135 flash_info[1].size = size_b1;
137 return (size_b0 + size_b1);