blob: 113111d3a65fdd2deeabe8805f4be9991101cde4 [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 Denk1a459662013-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 Roeseb36df562010-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;
29 int i;
wdenk8bde7f72003-06-27 21:31:46 +000030 uint pbcr;
31 unsigned long base_b0;
wdenkaffae2b2002-08-17 09:36:01 +000032 int size_val = 0;
33
34 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020035 for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
wdenkaffae2b2002-08-17 09:36:01 +000036 flash_info[i].flash_id = FLASH_UNKNOWN;
37 }
38
39 /* Static FLASH Bank configuration here - FIXME XXX */
40
41 size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);
42
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);
46 }
47
wdenk8bde7f72003-06-27 21:31:46 +000048 /* Setup offsets */
49 flash_get_offsets (-size_b0, &flash_info[0]);
wdenkaffae2b2002-08-17 09:36:01 +000050
wdenk8bde7f72003-06-27 21:31:46 +000051 /* Re-do sizing to get full correct info */
Stefan Roesed1c3b272009-09-09 16:25:29 +020052 mtdcr(EBC0_CFGADDR, PB0CR);
53 pbcr = mfdcr(EBC0_CFGDATA);
54 mtdcr(EBC0_CFGADDR, PB0CR);
wdenk8bde7f72003-06-27 21:31:46 +000055 base_b0 = -size_b0;
wdenkaffae2b2002-08-17 09:36:01 +000056 switch (size_b0) {
57 case 1 << 20:
58 size_val = 0;
59 break;
60 case 2 << 20:
61 size_val = 1;
62 break;
63 case 4 << 20:
64 size_val = 2;
65 break;
66 case 8 << 20:
67 size_val = 3;
68 break;
69 case 16 << 20:
70 size_val = 4;
71 break;
72 }
73 pbcr = (pbcr & 0x0001ffff) | base_b0 | (size_val << 17);
Stefan Roesed1c3b272009-09-09 16:25:29 +020074 mtdcr(EBC0_CFGDATA, pbcr);
wdenkaffae2b2002-08-17 09:36:01 +000075
wdenk8bde7f72003-06-27 21:31:46 +000076 /* Monitor protection ON by default */
77 (void)flash_protect(FLAG_PROTECT_SET,
78 -monitor_flash_len,
79 0xffffffff,
80 &flash_info[0]);
wdenkaffae2b2002-08-17 09:36:01 +000081
wdenk8bde7f72003-06-27 21:31:46 +000082 flash_info[0].size = size_b0;
wdenkaffae2b2002-08-17 09:36:01 +000083
84 return (size_b0);
85}