wdenk | affae2b | 2002-08-17 09:36:01 +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 | affae2b | 2002-08-17 09:36:01 +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 | affae2b | 2002-08-17 09:36:01 +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 | */ |
| 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); |
| 22 | |
| 23 | /*----------------------------------------------------------------------- |
| 24 | */ |
| 25 | |
| 26 | unsigned long flash_init (void) |
| 27 | { |
| 28 | unsigned long size_b0, size_b1; |
| 29 | int i; |
| 30 | |
| 31 | /* Init: no FLASHes known */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 32 | for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 33 | 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, |
wdenk | b9a83a9 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 67 | FLASH_BASE0_PRELIM+size_b0-monitor_flash_len, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 68 | 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, |
wdenk | b9a83a9 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 80 | FLASH_BASE0_PRELIM+size_b0+size_b1-monitor_flash_len, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 81 | FLASH_BASE0_PRELIM+size_b0+size_b1-1, |
| 82 | &flash_info[1]); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 83 | /* monitor protection OFF by default (one is enough) */ |
| 84 | flash_protect(FLAG_PROTECT_CLEAR, |
wdenk | b9a83a9 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 85 | FLASH_BASE0_PRELIM+size_b0-monitor_flash_len, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 86 | 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 | } |