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 | uint pbcr; |
| 31 | unsigned long base_b0, base_b1; |
| 32 | int size_val = 0; |
| 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 | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 36 | flash_info[i].flash_id = FLASH_UNKNOWN; |
| 37 | } |
| 38 | |
| 39 | /* Static FLASH Bank configuration here - FIXME XXX */ |
| 40 | |
| 41 | base_b0 = FLASH_BASE0_PRELIM; |
| 42 | size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]); |
| 43 | |
| 44 | if (flash_info[0].flash_id == FLASH_UNKNOWN) { |
| 45 | printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n", |
| 46 | size_b0, size_b0 << 20); |
| 47 | } |
| 48 | |
| 49 | base_b1 = FLASH_BASE1_PRELIM; |
| 50 | size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]); |
| 51 | |
| 52 | /* Re-do sizing to get full correct info */ |
| 53 | |
| 54 | if (size_b1) { |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 55 | mtdcr (EBC0_CFGADDR, PB0CR); |
| 56 | pbcr = mfdcr (EBC0_CFGDATA); |
| 57 | mtdcr (EBC0_CFGADDR, PB0CR); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 58 | base_b1 = -size_b1; |
| 59 | switch (size_b1) { |
| 60 | case 1 << 20: |
| 61 | size_val = 0; |
| 62 | break; |
| 63 | case 2 << 20: |
| 64 | size_val = 1; |
| 65 | break; |
| 66 | case 4 << 20: |
| 67 | size_val = 2; |
| 68 | break; |
| 69 | case 8 << 20: |
| 70 | size_val = 3; |
| 71 | break; |
| 72 | case 16 << 20: |
| 73 | size_val = 4; |
| 74 | break; |
| 75 | } |
| 76 | pbcr = (pbcr & 0x0001ffff) | base_b1 | (size_val << 17); |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 77 | mtdcr (EBC0_CFGDATA, pbcr); |
| 78 | /* printf("PB1CR = %x\n", pbcr); */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | if (size_b0) { |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 82 | mtdcr (EBC0_CFGADDR, PB1CR); |
| 83 | pbcr = mfdcr (EBC0_CFGDATA); |
| 84 | mtdcr (EBC0_CFGADDR, PB1CR); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 85 | base_b0 = base_b1 - size_b0; |
| 86 | switch (size_b1) { |
| 87 | case 1 << 20: |
| 88 | size_val = 0; |
| 89 | break; |
| 90 | case 2 << 20: |
| 91 | size_val = 1; |
| 92 | break; |
| 93 | case 4 << 20: |
| 94 | size_val = 2; |
| 95 | break; |
| 96 | case 8 << 20: |
| 97 | size_val = 3; |
| 98 | break; |
| 99 | case 16 << 20: |
| 100 | size_val = 4; |
| 101 | break; |
| 102 | } |
| 103 | pbcr = (pbcr & 0x0001ffff) | base_b0 | (size_val << 17); |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 104 | mtdcr (EBC0_CFGDATA, pbcr); |
| 105 | /* printf("PB0CR = %x\n", pbcr); */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]); |
| 109 | |
| 110 | flash_get_offsets (base_b0, &flash_info[0]); |
| 111 | |
| 112 | /* monitor protection ON by default */ |
| 113 | flash_protect (FLAG_PROTECT_SET, |
wdenk | b9a83a9 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 114 | base_b0 + size_b0 - monitor_flash_len, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 115 | base_b0 + size_b0 - 1, &flash_info[0]); |
| 116 | |
| 117 | if (size_b1) { |
| 118 | /* Re-do sizing to get full correct info */ |
| 119 | size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]); |
| 120 | |
| 121 | flash_get_offsets (base_b1, &flash_info[1]); |
| 122 | |
| 123 | /* monitor protection ON by default */ |
| 124 | flash_protect (FLAG_PROTECT_SET, |
wdenk | b9a83a9 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 125 | base_b1 + size_b1 - monitor_flash_len, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 126 | base_b1 + size_b1 - 1, &flash_info[1]); |
| 127 | /* monitor protection OFF by default (one is enough) */ |
| 128 | flash_protect (FLAG_PROTECT_CLEAR, |
wdenk | b9a83a9 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 129 | base_b0 + size_b0 - monitor_flash_len, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 130 | base_b0 + size_b0 - 1, &flash_info[0]); |
| 131 | } else { |
| 132 | flash_info[1].flash_id = FLASH_UNKNOWN; |
| 133 | flash_info[1].sector_count = -1; |
| 134 | } |
| 135 | |
| 136 | flash_info[0].size = size_b0; |
| 137 | flash_info[1].size = size_b1; |
| 138 | |
| 139 | return (size_b0 + size_b1); |
| 140 | } |