blob: 279746e57b019f2d120eafe8e1af1f95871440ab [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2001
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +00006 */
7
8#include <common.h>
Stefan Roeseb36df562010-09-09 19:18:00 +02009#include <asm/ppc4xx.h>
wdenkaffae2b2002-08-17 09:36:01 +000010#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 */
20static ulong flash_get_size (vu_long * addr, flash_info_t * info);
21static void flash_get_offsets (ulong base, flash_info_t * info);
22
23/*-----------------------------------------------------------------------
24 */
25
26unsigned 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-VILLARD6d0f6bc2008-10-16 15:01:15 +020035 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
wdenkaffae2b2002-08-17 09:36:01 +000036 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 Roesed1c3b272009-09-09 16:25:29 +020055 mtdcr (EBC0_CFGADDR, PB0CR);
56 pbcr = mfdcr (EBC0_CFGDATA);
57 mtdcr (EBC0_CFGADDR, PB0CR);
wdenkaffae2b2002-08-17 09:36:01 +000058 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 Roesed1c3b272009-09-09 16:25:29 +020077 mtdcr (EBC0_CFGDATA, pbcr);
78 /* printf("PB1CR = %x\n", pbcr); */
wdenkaffae2b2002-08-17 09:36:01 +000079 }
80
81 if (size_b0) {
Stefan Roesed1c3b272009-09-09 16:25:29 +020082 mtdcr (EBC0_CFGADDR, PB1CR);
83 pbcr = mfdcr (EBC0_CFGDATA);
84 mtdcr (EBC0_CFGADDR, PB1CR);
wdenkaffae2b2002-08-17 09:36:01 +000085 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 Roesed1c3b272009-09-09 16:25:29 +0200104 mtdcr (EBC0_CFGDATA, pbcr);
105 /* printf("PB0CR = %x\n", pbcr); */
wdenkaffae2b2002-08-17 09:36:01 +0000106 }
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,
wdenk3b57fe02003-05-30 12:48:29 +0000114 base_b0 + size_b0 - monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +0000115 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,
wdenk3b57fe02003-05-30 12:48:29 +0000125 base_b1 + size_b1 - monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +0000126 base_b1 + size_b1 - 1, &flash_info[1]);
127 /* monitor protection OFF by default (one is enough) */
128 flash_protect (FLAG_PROTECT_CLEAR,
wdenk3b57fe02003-05-30 12:48:29 +0000129 base_b0 + size_b0 - monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +0000130 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}