wdenk | 232fe0b | 2003-09-02 22:48:03 +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 | 232fe0b | 2003-09-02 22:48:03 +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 | 232fe0b | 2003-09-02 22:48:03 +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 | #ifdef __DEBUG_START_FROM_SRAM__ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 29 | return CONFIG_SYS_DUMMY_FLASH_SIZE; |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 30 | #else |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 31 | unsigned long size; |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 32 | int i; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 33 | uint pbcr; |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 34 | unsigned long base; |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 35 | int size_val = 0; |
| 36 | |
wdenk | 99874b4 | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 37 | debug("[%s, %d] Entering ...\n", __FUNCTION__, __LINE__); |
Marek Vasut | c6ce705 | 2011-10-21 14:17:29 +0000 | [diff] [blame] | 38 | debug("[%s, %d] flash_info = 0x%p ...\n", __func__, __LINE__, |
| 39 | flash_info); |
wdenk | 99874b4 | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 40 | |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 41 | /* Init: no FLASHes known */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) { |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 43 | flash_info[i].flash_id = FLASH_UNKNOWN; |
| 44 | } |
| 45 | |
| 46 | /* Static FLASH Bank configuration here - FIXME XXX */ |
| 47 | |
wdenk | 99874b4 | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 48 | debug("[%s, %d] Calling flash_get_size ...\n", __FUNCTION__, __LINE__); |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 49 | size = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]); |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 50 | |
| 51 | if (flash_info[0].flash_id == FLASH_UNKNOWN) { |
| 52 | printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n", |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 53 | size, size<<20); |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 54 | } |
| 55 | |
wdenk | 99874b4 | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 56 | debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__); |
| 57 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 58 | /* Setup offsets */ |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 59 | flash_get_offsets (-size, &flash_info[0]); |
wdenk | 99874b4 | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 60 | debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__); |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 61 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 62 | /* Re-do sizing to get full correct info */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 63 | mtdcr(EBC0_CFGADDR, PB0CR); |
| 64 | pbcr = mfdcr(EBC0_CFGDATA); |
| 65 | mtdcr(EBC0_CFGADDR, PB0CR); |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 66 | base = -size; |
| 67 | switch (size) { |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 68 | 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 | } |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 84 | pbcr = (pbcr & 0x0001ffff) | base | (size_val << 17); |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 85 | mtdcr(EBC0_CFGDATA, pbcr); |
wdenk | 99874b4 | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 86 | debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__); |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 87 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 88 | /* Monitor protection ON by default */ |
| 89 | (void)flash_protect(FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | -CONFIG_SYS_MONITOR_LEN, |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 91 | 0xffffffff, |
| 92 | &flash_info[0]); |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 93 | |
wdenk | 99874b4 | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 94 | debug("[%s, %d] Test point ...\n", __FUNCTION__, __LINE__); |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 95 | flash_info[0].size = size; |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 96 | |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 97 | return (size); |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 98 | #endif |
| 99 | } |