blob: b1db12ecc8b24a9ae7007f129b800ba0f316814f [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2001
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +00006 */
7
8#include <common.h>
Stefan Roese247e9d72010-09-09 19:18:00 +02009#include <asm/ppc4xx.h>
wdenkaffae2b2002-08-17 09:36:01 +000010#include <asm/processor.h>
11
12/*
13 * include common flash code (for esd boards)
14 */
15#include "../common/flash.c"
16
17/*-----------------------------------------------------------------------
18 * Functions
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 unsigned long size_b0, size_b1;
29 int i;
30
31 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020032 for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
wdenkaffae2b2002-08-17 09:36:01 +000033 flash_info[i].flash_id = FLASH_UNKNOWN;
34 }
35
36 size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);
37
38 if (flash_info[0].flash_id == FLASH_UNKNOWN) {
39 printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
40 size_b0, size_b0<<20);
41 }
42
43 size_b1 = flash_get_size((vu_long *)FLASH_BASE1_PRELIM, &flash_info[1]);
44
45 if (size_b1 > size_b0) {
46 printf ("## ERROR: "
47 "Bank 1 (0x%08lx = %ld MB) > Bank 0 (0x%08lx = %ld MB)\n",
48 size_b1, size_b1<<20,
49 size_b0, size_b0<<20
50 );
51 flash_info[0].flash_id = FLASH_UNKNOWN;
52 flash_info[1].flash_id = FLASH_UNKNOWN;
53 flash_info[0].sector_count = -1;
54 flash_info[1].sector_count = -1;
55 flash_info[0].size = 0;
56 flash_info[1].size = 0;
57 return (0);
58 }
59
60 /* Re-do sizing to get full correct info */
61 size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);
62
63 flash_get_offsets (FLASH_BASE0_PRELIM, &flash_info[0]);
64
65 /* monitor protection ON by default */
66 flash_protect(FLAG_PROTECT_SET,
wdenkb9a83a92003-05-30 12:48:29 +000067 FLASH_BASE0_PRELIM+size_b0-monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +000068 FLASH_BASE0_PRELIM+size_b0-1,
69 &flash_info[0]);
70
71 if (size_b1) {
72 /* Re-do sizing to get full correct info */
73 size_b1 = flash_get_size((vu_long *)(FLASH_BASE0_PRELIM + size_b0),
74 &flash_info[1]);
75
76 flash_get_offsets (FLASH_BASE0_PRELIM + size_b0, &flash_info[1]);
77
78 /* monitor protection ON by default */
79 flash_protect(FLAG_PROTECT_SET,
wdenkb9a83a92003-05-30 12:48:29 +000080 FLASH_BASE0_PRELIM+size_b0+size_b1-monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +000081 FLASH_BASE0_PRELIM+size_b0+size_b1-1,
82 &flash_info[1]);
wdenk57b2d802003-06-27 21:31:46 +000083 /* monitor protection OFF by default (one is enough) */
84 flash_protect(FLAG_PROTECT_CLEAR,
wdenkb9a83a92003-05-30 12:48:29 +000085 FLASH_BASE0_PRELIM+size_b0-monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +000086 FLASH_BASE0_PRELIM+size_b0-1,
87 &flash_info[0]);
88 } else {
89 flash_info[1].flash_id = FLASH_UNKNOWN;
90 flash_info[1].sector_count = -1;
91 }
92
93 flash_info[0].size = size_b0;
94 flash_info[1].size = size_b1;
95
96 return (size_b0 + size_b1);
97}