wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Stefan Roese | 247e9d7 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 9 | #include <asm/ppc4xx.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 10 | #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 | */ |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 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); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 22 | |
| 23 | /*----------------------------------------------------------------------- |
| 24 | */ |
| 25 | |
| 26 | unsigned long flash_init (void) |
| 27 | { |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 28 | unsigned long size_b0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 29 | int i; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 30 | uint pbcr; |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 31 | unsigned long base_b0; |
| 32 | int size_val = 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 33 | |
| 34 | /* Init: no FLASHes known */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 35 | for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 36 | flash_info[i].flash_id = FLASH_UNKNOWN; |
| 37 | } |
| 38 | |
| 39 | /* Static FLASH Bank configuration here - FIXME XXX */ |
| 40 | |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 41 | size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 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 | |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 48 | /* Setup offsets */ |
| 49 | flash_get_offsets (-size_b0, &flash_info[0]); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 50 | |
| 51 | /* Re-do sizing to get full correct info */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 52 | mtdcr(EBC0_CFGADDR, PB0CR); |
| 53 | pbcr = mfdcr(EBC0_CFGDATA); |
| 54 | mtdcr(EBC0_CFGADDR, PB0CR); |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 55 | 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 Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 74 | mtdcr(EBC0_CFGDATA, pbcr); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 75 | |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 76 | /* Monitor protection ON by default */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 77 | (void)flash_protect(FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | -CONFIG_SYS_MONITOR_LEN, |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 79 | 0xffffffff, |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 80 | &flash_info[0]); |
| 81 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 82 | flash_info[0].size = size_b0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 83 | |
stroese | 0191b3c | 2004-09-16 12:34:51 +0000 | [diff] [blame] | 84 | return (size_b0); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 85 | } |