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 flash_init (void)
28 unsigned long size_b0, size_b1;
31 unsigned long base_b0, base_b1;
33 /* Init: no FLASHes known */
34 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
35 flash_info[i].flash_id = FLASH_UNKNOWN;
38 /* Static FLASH Bank configuration here - FIXME XXX */
40 base_b0 = FLASH_BASE0_PRELIM;
41 size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
43 if (flash_info[0].flash_id == FLASH_UNKNOWN) {
44 printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
45 size_b0, size_b0 << 20);
48 base_b1 = FLASH_BASE1_PRELIM;
49 size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
51 /* Re-do sizing to get full correct info */
54 mtdcr (EBC0_CFGADDR, PB0CR);
55 pbcr = mfdcr (EBC0_CFGDATA);
56 mtdcr (EBC0_CFGADDR, PB0CR);
58 pbcr = (pbcr & 0x0001ffff) | base_b1 |
59 (((size_b1 / 1024 / 1024) - 1) << 17);
60 mtdcr (EBC0_CFGDATA, pbcr);
61 /* printf("PB1CR = %x\n", pbcr); */
65 mtdcr (EBC0_CFGADDR, PB1CR);
66 pbcr = mfdcr (EBC0_CFGDATA);
67 mtdcr (EBC0_CFGADDR, PB1CR);
68 base_b0 = base_b1 - size_b0;
69 pbcr = (pbcr & 0x0001ffff) | base_b0 |
70 (((size_b0 / 1024 / 1024) - 1) << 17);
71 mtdcr (EBC0_CFGDATA, pbcr);
72 /* printf("PB0CR = %x\n", pbcr); */
75 size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
77 flash_get_offsets (base_b0, &flash_info[0]);
79 /* monitor protection ON by default */
80 flash_protect (FLAG_PROTECT_SET,
81 base_b0 + size_b0 - monitor_flash_len,
82 base_b0 + size_b0 - 1, &flash_info[0]);
85 /* Re-do sizing to get full correct info */
86 size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
88 flash_get_offsets (base_b1, &flash_info[1]);
90 /* monitor protection ON by default */
91 flash_protect (FLAG_PROTECT_SET,
92 base_b1 + size_b1 - monitor_flash_len,
93 base_b1 + size_b1 - 1, &flash_info[1]);
94 /* monitor protection OFF by default (one is enough) */
95 flash_protect (FLAG_PROTECT_CLEAR,
96 base_b0 + size_b0 - monitor_flash_len,
97 base_b0 + size_b0 - 1, &flash_info[0]);
99 flash_info[1].flash_id = FLASH_UNKNOWN;
100 flash_info[1].sector_count = -1;
103 flash_info[0].size = size_b0;
104 flash_info[1].size = size_b1;
106 return (size_b0 + size_b1);