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