blob: 23e81642e02d7951a1a125264b5f0249cd3855c5 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +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+
wdenkfe8c2802002-11-03 00:38:21 +00006 */
7
8#include <common.h>
Stefan Roese247e9d72010-09-09 19:18:00 +02009#include <asm/ppc4xx.h>
wdenkfe8c2802002-11-03 00:38:21 +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 */
stroese0191b3c2004-09-16 12:34:51 +000020static ulong flash_get_size (vu_long * addr, flash_info_t * info);
21static void flash_get_offsets (ulong base, flash_info_t * info);
wdenkfe8c2802002-11-03 00:38:21 +000022
23/*-----------------------------------------------------------------------
24 */
25
26unsigned long flash_init (void)
27{
stroese0191b3c2004-09-16 12:34:51 +000028 unsigned long size_b0;
wdenkfe8c2802002-11-03 00:38:21 +000029 int i;
wdenk57b2d802003-06-27 21:31:46 +000030 uint pbcr;
stroese0191b3c2004-09-16 12:34:51 +000031 unsigned long base_b0;
32 int size_val = 0;
wdenkfe8c2802002-11-03 00:38:21 +000033
34 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020035 for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
wdenkfe8c2802002-11-03 00:38:21 +000036 flash_info[i].flash_id = FLASH_UNKNOWN;
37 }
38
39 /* Static FLASH Bank configuration here - FIXME XXX */
40
stroese0191b3c2004-09-16 12:34:51 +000041 size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);
wdenkfe8c2802002-11-03 00:38:21 +000042
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
stroese0191b3c2004-09-16 12:34:51 +000048 /* Setup offsets */
49 flash_get_offsets (-size_b0, &flash_info[0]);
wdenkfe8c2802002-11-03 00:38:21 +000050
51 /* Re-do sizing to get full correct info */
Stefan Roese918010a2009-09-09 16:25:29 +020052 mtdcr(EBC0_CFGADDR, PB0CR);
53 pbcr = mfdcr(EBC0_CFGDATA);
54 mtdcr(EBC0_CFGADDR, PB0CR);
stroese0191b3c2004-09-16 12:34:51 +000055 base_b0 = -size_b0;
56 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 Roese918010a2009-09-09 16:25:29 +020074 mtdcr(EBC0_CFGDATA, pbcr);
wdenkfe8c2802002-11-03 00:38:21 +000075
stroese0191b3c2004-09-16 12:34:51 +000076 /* Monitor protection ON by default */
wdenkfe8c2802002-11-03 00:38:21 +000077 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020078 -CONFIG_SYS_MONITOR_LEN,
stroese0191b3c2004-09-16 12:34:51 +000079 0xffffffff,
wdenkfe8c2802002-11-03 00:38:21 +000080 &flash_info[0]);
81
wdenkfe8c2802002-11-03 00:38:21 +000082 flash_info[0].size = size_b0;
wdenkfe8c2802002-11-03 00:38:21 +000083
stroese0191b3c2004-09-16 12:34:51 +000084 return (size_b0);
wdenkfe8c2802002-11-03 00:38:21 +000085}