blob: 771151b80b05658430559c0dd4dd01bbbc47f9e5 [file] [log] [blame]
wdenk232fe0b2003-09-02 22:48:03 +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+
wdenk232fe0b2003-09-02 22:48:03 +00006 */
7
8#include <common.h>
Stefan Roese247e9d72010-09-09 19:18:00 +02009#include <asm/ppc4xx.h>
wdenk232fe0b2003-09-02 22:48:03 +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#ifdef __DEBUG_START_FROM_SRAM__
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029 return CONFIG_SYS_DUMMY_FLASH_SIZE;
wdenk232fe0b2003-09-02 22:48:03 +000030#else
wdenk9e076902004-06-17 18:50:45 +000031 unsigned long size;
wdenk232fe0b2003-09-02 22:48:03 +000032 int i;
wdenk9c53f402003-10-15 23:53:47 +000033 uint pbcr;
wdenk9e076902004-06-17 18:50:45 +000034 unsigned long base;
wdenk232fe0b2003-09-02 22:48:03 +000035 int size_val = 0;
36
wdenk99874b42004-07-01 21:40:08 +000037 debug("[%s, %d] Entering ...\n", __FUNCTION__, __LINE__);
Marek Vasutc6ce7052011-10-21 14:17:29 +000038 debug("[%s, %d] flash_info = 0x%p ...\n", __func__, __LINE__,
39 flash_info);
wdenk99874b42004-07-01 21:40:08 +000040
wdenk232fe0b2003-09-02 22:48:03 +000041 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042 for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
wdenk232fe0b2003-09-02 22:48:03 +000043 flash_info[i].flash_id = FLASH_UNKNOWN;
44 }
45
46 /* Static FLASH Bank configuration here - FIXME XXX */
47
wdenk99874b42004-07-01 21:40:08 +000048 debug("[%s, %d] Calling flash_get_size ...\n", __FUNCTION__, __LINE__);
wdenk9e076902004-06-17 18:50:45 +000049 size = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);
wdenk232fe0b2003-09-02 22:48:03 +000050
51 if (flash_info[0].flash_id == FLASH_UNKNOWN) {
52 printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
wdenk9e076902004-06-17 18:50:45 +000053 size, size<<20);
wdenk232fe0b2003-09-02 22:48:03 +000054 }
55
wdenk99874b42004-07-01 21:40:08 +000056 debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__);
57
wdenk9c53f402003-10-15 23:53:47 +000058 /* Setup offsets */
wdenk9e076902004-06-17 18:50:45 +000059 flash_get_offsets (-size, &flash_info[0]);
wdenk99874b42004-07-01 21:40:08 +000060 debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__);
wdenk232fe0b2003-09-02 22:48:03 +000061
wdenk9c53f402003-10-15 23:53:47 +000062 /* Re-do sizing to get full correct info */
Stefan Roese918010a2009-09-09 16:25:29 +020063 mtdcr(EBC0_CFGADDR, PB0CR);
64 pbcr = mfdcr(EBC0_CFGDATA);
65 mtdcr(EBC0_CFGADDR, PB0CR);
wdenk9e076902004-06-17 18:50:45 +000066 base = -size;
67 switch (size) {
wdenk232fe0b2003-09-02 22:48:03 +000068 case 1 << 20:
69 size_val = 0;
70 break;
71 case 2 << 20:
72 size_val = 1;
73 break;
74 case 4 << 20:
75 size_val = 2;
76 break;
77 case 8 << 20:
78 size_val = 3;
79 break;
80 case 16 << 20:
81 size_val = 4;
82 break;
83 }
wdenk9e076902004-06-17 18:50:45 +000084 pbcr = (pbcr & 0x0001ffff) | base | (size_val << 17);
Stefan Roese918010a2009-09-09 16:25:29 +020085 mtdcr(EBC0_CFGDATA, pbcr);
wdenk99874b42004-07-01 21:40:08 +000086 debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__);
wdenk232fe0b2003-09-02 22:48:03 +000087
wdenk9c53f402003-10-15 23:53:47 +000088 /* Monitor protection ON by default */
89 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090 -CONFIG_SYS_MONITOR_LEN,
wdenk9c53f402003-10-15 23:53:47 +000091 0xffffffff,
92 &flash_info[0]);
wdenk232fe0b2003-09-02 22:48:03 +000093
wdenk99874b42004-07-01 21:40:08 +000094 debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__);
wdenk9e076902004-06-17 18:50:45 +000095 flash_info[0].size = size;
wdenk232fe0b2003-09-02 22:48:03 +000096
wdenk9e076902004-06-17 18:50:45 +000097 return (size);
wdenk232fe0b2003-09-02 22:48:03 +000098#endif
99}