blob: 091652b6232c452259f2e6be6c2044a469400b49 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
stroese6f4474e2003-03-20 15:31:19 +00002 * (C) Copyright 2001-2003
wdenkaffae2b2002-08-17 09:36:01 +00003 * 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
stroese6f4474e2003-03-20 15:31:19 +000026unsigned 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
wdenkaffae2b2002-08-17 09:36:01 +000045unsigned 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;
wdenkaffae2b2002-08-17 09:36:01 +000051
52 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
wdenkaffae2b2002-08-17 09:36:01 +000054 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) {
stroese6f4474e2003-03-20 15:31:19 +000073 if (size_b1 < (1 << 20)) {
74 /* minimum CS size on PPC405GP is 1MB !!! */
75 size_b1 = 1 << 20;
76 }
stroesed4629c82003-05-23 11:30:39 +000077 base_b1 = -size_b1;
Stefan Roesed1c3b272009-09-09 16:25:29 +020078 mtdcr (EBC0_CFGADDR, PB0CR);
79 pbcr = mfdcr (EBC0_CFGDATA);
80 mtdcr (EBC0_CFGADDR, PB0CR);
stroese6f4474e2003-03-20 15:31:19 +000081 pbcr = (pbcr & 0x0001ffff) | base_b1 | (calc_size(size_b1) << 17);
Stefan Roesed1c3b272009-09-09 16:25:29 +020082 mtdcr (EBC0_CFGDATA, pbcr);
stroese6f4474e2003-03-20 15:31:19 +000083#if 0 /* test-only */
Stefan Roesed1c3b272009-09-09 16:25:29 +020084 printf("size_b1=%x base_b1=%x PB1CR = %x\n",
stroese6f4474e2003-03-20 15:31:19 +000085 size_b1, base_b1, pbcr); /* test-only */
86#endif
wdenkaffae2b2002-08-17 09:36:01 +000087 }
88
89 if (size_b0) {
stroese6f4474e2003-03-20 15:31:19 +000090 if (size_b0 < (1 << 20)) {
91 /* minimum CS size on PPC405GP is 1MB !!! */
92 size_b0 = 1 << 20;
93 }
stroesed4629c82003-05-23 11:30:39 +000094 base_b0 = base_b1 - size_b0;
Stefan Roesed1c3b272009-09-09 16:25:29 +020095 mtdcr (EBC0_CFGADDR, PB1CR);
96 pbcr = mfdcr (EBC0_CFGDATA);
97 mtdcr (EBC0_CFGADDR, PB1CR);
stroese6f4474e2003-03-20 15:31:19 +000098 pbcr = (pbcr & 0x0001ffff) | base_b0 | (calc_size(size_b0) << 17);
Stefan Roesed1c3b272009-09-09 16:25:29 +020099 mtdcr (EBC0_CFGDATA, pbcr);
stroese6f4474e2003-03-20 15:31:19 +0000100#if 0 /* test-only */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200101 printf("size_b0=%x base_b0=%x PB0CR = %x\n",
stroese6f4474e2003-03-20 15:31:19 +0000102 size_b0, base_b0, pbcr); /* test-only */
103#endif
wdenkaffae2b2002-08-17 09:36:01 +0000104 }
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,
wdenk3b57fe02003-05-30 12:48:29 +0000112 base_b0 + size_b0 - monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +0000113 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,
wdenk3b57fe02003-05-30 12:48:29 +0000123 base_b1 + size_b1 - monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +0000124 base_b1 + size_b1 - 1, &flash_info[1]);
125 /* monitor protection OFF by default (one is enough) */
126 flash_protect (FLAG_PROTECT_CLEAR,
wdenk3b57fe02003-05-30 12:48:29 +0000127 base_b0 + size_b0 - monitor_flash_len,
wdenkaffae2b2002-08-17 09:36:01 +0000128 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}