blob: a60c825b2b5fb693a197016eb4a9d24a4b8e4cc2 [file] [log] [blame]
wdenkf8cac652002-08-26 22:36:39 +00001/*
2 * (C) Copyright 2001
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <mpc8xx.h>
26#include <commproc.h>
27#include <i2c.h>
28#include <command.h>
wdenkf8cac652002-08-26 22:36:39 +000029
30/* ------------------------------------------------------------------------- */
31
32static long int dram_size (long int, long int *, long int);
33static void puma_status (void);
34static void puma_set_mode (int mode);
wdenk87249ba2004-01-06 22:38:14 +000035static int puma_init_done (void);
wdenkf8cac652002-08-26 22:36:39 +000036static void puma_load (ulong addr, ulong len);
37
38/* ------------------------------------------------------------------------- */
39
40#define _NOT_USED_ 0xFFFFFFFF
41
42/*
43 * 50 MHz SDRAM access using UPM A
44 */
wdenk87249ba2004-01-06 22:38:14 +000045const uint sdram_table[] = {
wdenkf8cac652002-08-26 22:36:39 +000046 /*
47 * Single Read. (Offset 0 in UPM RAM)
48 */
49 0x1f0dfc04, 0xeeafbc04, 0x11af7c04, 0xefbeec00,
wdenk87249ba2004-01-06 22:38:14 +000050 0x1ffddc47, /* last */
wdenkf8cac652002-08-26 22:36:39 +000051 /*
52 * SDRAM Initialization (offset 5 in UPM RAM)
53 *
wdenk57b2d802003-06-27 21:31:46 +000054 * This is no UPM entry point. The following definition uses
55 * the remaining space to establish an initialization
56 * sequence, which is executed by a RUN command.
wdenkf8cac652002-08-26 22:36:39 +000057 *
58 */
wdenk87249ba2004-01-06 22:38:14 +000059 0x1ffddc35, 0xefceac34, 0x1f3d5c35, /* last */
wdenkf8cac652002-08-26 22:36:39 +000060 /*
61 * Burst Read. (Offset 8 in UPM RAM)
62 */
63 0x1f0dfc04, 0xeeafbc04, 0x10af7c04, 0xf0affc00,
wdenk87249ba2004-01-06 22:38:14 +000064 0xf0affc00, 0xf1affc00, 0xefbeec00, 0x1ffddc47, /* last */
wdenkf8cac652002-08-26 22:36:39 +000065 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
66 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
67
68 /*
69 * Single Write. (Offset 18 in UPM RAM)
70 */
wdenk87249ba2004-01-06 22:38:14 +000071 0x1f0dfc04, 0xeeafac00, 0x01be4c04, 0x1ffddc47, /* last */
wdenkf8cac652002-08-26 22:36:39 +000072 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
73 /*
74 * Burst Write. (Offset 20 in UPM RAM)
75 */
76 0x1f0dfc04, 0xeeafac00, 0x10af5c00, 0xf0affc00,
wdenk87249ba2004-01-06 22:38:14 +000077 0xf0affc00, 0xe1beec04, 0x1ffddc47, /* last */
78 _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +000079 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
80 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
81 /*
82 * Refresh (Offset 30 in UPM RAM)
83 */
84 0x1ffd7c84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
wdenk87249ba2004-01-06 22:38:14 +000085 0xfffffc84, 0xfffffc07, /* last */
86 _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +000087 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
88 /*
89 * Exception. (Offset 3c in UPM RAM)
90 */
wdenk87249ba2004-01-06 22:38:14 +000091 0x7ffffc07, /* last */
92 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +000093};
94
95/* ------------------------------------------------------------------------- */
96
97/*
98 * PUMA access using UPM B
99 */
wdenk87249ba2004-01-06 22:38:14 +0000100const uint puma_table[] = {
wdenkf8cac652002-08-26 22:36:39 +0000101 /*
102 * Single Read. (Offset 0 in UPM RAM)
103 */
104 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
105 _NOT_USED_,
106 /*
107 * Precharge and MRS
108 */
wdenk87249ba2004-01-06 22:38:14 +0000109 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +0000110 /*
111 * Burst Read. (Offset 8 in UPM RAM)
112 */
113 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
114 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
115 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
116 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
117 /*
118 * Single Write. (Offset 18 in UPM RAM)
119 */
wdenk87249ba2004-01-06 22:38:14 +0000120 0x0ffff804, 0x0ffff400, 0x3ffffc47, /* last */
121 _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +0000122 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
123 /*
124 * Burst Write. (Offset 20 in UPM RAM)
125 */
126 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
127 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
128 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
129 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
130 /*
131 * Refresh (Offset 30 in UPM RAM)
132 */
133 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
134 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
135 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
136 /*
137 * Exception. (Offset 3c in UPM RAM)
138 */
wdenk87249ba2004-01-06 22:38:14 +0000139 0x7ffffc07, /* last */
140 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkf8cac652002-08-26 22:36:39 +0000141};
142
143/* ------------------------------------------------------------------------- */
144
145
146/*
147 * Check Board Identity:
148 *
149 */
150
151int checkboard (void)
152{
153 puts ("Board: Siemens PCU E\n");
154 return (0);
155}
156
157/* ------------------------------------------------------------------------- */
158
Becky Brucebd99ae72008-06-09 16:03:40 -0500159phys_size_t initdram (int board_type)
wdenkf8cac652002-08-26 22:36:39 +0000160{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200161 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk87249ba2004-01-06 22:38:14 +0000162 volatile memctl8xx_t *memctl = &immr->im_memctl;
163 long int size_b0, reg;
164 int i;
wdenkf8cac652002-08-26 22:36:39 +0000165
wdenk87249ba2004-01-06 22:38:14 +0000166 /*
167 * Configure UPMA for SDRAM
168 */
169 upmconfig (UPMA, (uint *) sdram_table,
170 sizeof (sdram_table) / sizeof (uint));
wdenkf8cac652002-08-26 22:36:39 +0000171
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
wdenkf8cac652002-08-26 22:36:39 +0000173
wdenk87249ba2004-01-06 22:38:14 +0000174 /* burst length=4, burst type=sequential, CAS latency=2 */
175 memctl->memc_mar = 0x00000088;
wdenkf8cac652002-08-26 22:36:39 +0000176
wdenk87249ba2004-01-06 22:38:14 +0000177 /*
178 * Map controller bank 2 to the SDRAM bank at preliminary address.
179 */
wdenkf8cac652002-08-26 22:36:39 +0000180#if PCU_E_WITH_SWAPPED_CS /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200181 memctl->memc_or5 = CONFIG_SYS_OR5_PRELIM;
182 memctl->memc_br5 = CONFIG_SYS_BR5_PRELIM;
wdenk87249ba2004-01-06 22:38:14 +0000183#else /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200184 memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
185 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
wdenk87249ba2004-01-06 22:38:14 +0000186#endif /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000187
wdenk87249ba2004-01-06 22:38:14 +0000188 /* initialize memory address register */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200189 memctl->memc_mamr = CONFIG_SYS_MAMR; /* refresh not enabled yet */
wdenkf8cac652002-08-26 22:36:39 +0000190
wdenk87249ba2004-01-06 22:38:14 +0000191 /* mode initialization (offset 5) */
wdenkf8cac652002-08-26 22:36:39 +0000192#if PCU_E_WITH_SWAPPED_CS /* XXX */
wdenk87249ba2004-01-06 22:38:14 +0000193 udelay (200); /* 0x8000A105 */
194 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS5 | MCR_MLCF (1) | MCR_MAD (0x05);
195#else /* XXX */
196 udelay (200); /* 0x80004105 */
197 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS2 | MCR_MLCF (1) | MCR_MAD (0x05);
198#endif /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000199
wdenk87249ba2004-01-06 22:38:14 +0000200 /* run 2 refresh sequence with 4-beat refresh burst (offset 0x30) */
wdenkf8cac652002-08-26 22:36:39 +0000201#if PCU_E_WITH_SWAPPED_CS /* XXX */
wdenk87249ba2004-01-06 22:38:14 +0000202 udelay (1); /* 0x8000A830 */
203 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS5 | MCR_MLCF (8) | MCR_MAD (0x30);
204#else /* XXX */
205 udelay (1); /* 0x80004830 */
206 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS2 | MCR_MLCF (8) | MCR_MAD (0x30);
207#endif /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000208
209#if PCU_E_WITH_SWAPPED_CS /* XXX */
wdenk87249ba2004-01-06 22:38:14 +0000210 udelay (1); /* 0x8000A106 */
211 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS5 | MCR_MLCF (1) | MCR_MAD (0x06);
212#else /* XXX */
213 udelay (1); /* 0x80004106 */
214 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS2 | MCR_MLCF (1) | MCR_MAD (0x06);
215#endif /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000216
wdenk87249ba2004-01-06 22:38:14 +0000217 reg = memctl->memc_mamr;
218 reg &= ~MAMR_TLFA_MSK; /* switch timer loop ... */
219 reg |= MAMR_TLFA_4X; /* ... to 4x */
220 reg |= MAMR_PTAE; /* enable refresh */
221 memctl->memc_mamr = reg;
wdenkf8cac652002-08-26 22:36:39 +0000222
wdenk87249ba2004-01-06 22:38:14 +0000223 udelay (200);
wdenkf8cac652002-08-26 22:36:39 +0000224
wdenk87249ba2004-01-06 22:38:14 +0000225 /* Need at least 10 DRAM accesses to stabilize */
226 for (i = 0; i < 10; ++i) {
wdenkf8cac652002-08-26 22:36:39 +0000227#if PCU_E_WITH_SWAPPED_CS /* XXX */
wdenk87249ba2004-01-06 22:38:14 +0000228 volatile unsigned long *addr =
229 (volatile unsigned long *) SDRAM_BASE5_PRELIM;
230#else /* XXX */
231 volatile unsigned long *addr =
232 (volatile unsigned long *) SDRAM_BASE2_PRELIM;
233#endif /* XXX */
234 unsigned long val;
wdenkf8cac652002-08-26 22:36:39 +0000235
wdenk87249ba2004-01-06 22:38:14 +0000236 val = *(addr + i);
237 *(addr + i) = val;
238 }
wdenkf8cac652002-08-26 22:36:39 +0000239
wdenk87249ba2004-01-06 22:38:14 +0000240 /*
241 * Check Bank 0 Memory Size for re-configuration
242 */
wdenkf8cac652002-08-26 22:36:39 +0000243#if PCU_E_WITH_SWAPPED_CS /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200244 size_b0 = dram_size (CONFIG_SYS_MAMR, (long *) SDRAM_BASE5_PRELIM, SDRAM_MAX_SIZE);
wdenk87249ba2004-01-06 22:38:14 +0000245#else /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200246 size_b0 = dram_size (CONFIG_SYS_MAMR, (long *) SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
wdenk87249ba2004-01-06 22:38:14 +0000247#endif /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000248
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200249 memctl->memc_mamr = CONFIG_SYS_MAMR | MAMR_PTAE;
wdenkf8cac652002-08-26 22:36:39 +0000250
wdenk87249ba2004-01-06 22:38:14 +0000251 /*
252 * Final mapping:
253 */
wdenkf8cac652002-08-26 22:36:39 +0000254
255#if PCU_E_WITH_SWAPPED_CS /* XXX */
wdenk87249ba2004-01-06 22:38:14 +0000256 memctl->memc_or5 = ((-size_b0) & 0xFFFF0000) | SDRAM_TIMING;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200257 memctl->memc_br5 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenk87249ba2004-01-06 22:38:14 +0000258#else /* XXX */
259 memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | SDRAM_TIMING;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200260 memctl->memc_br2 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenk87249ba2004-01-06 22:38:14 +0000261#endif /* XXX */
262 udelay (1000);
wdenkf8cac652002-08-26 22:36:39 +0000263
wdenk87249ba2004-01-06 22:38:14 +0000264 /*
265 * Configure UPMB for PUMA
266 */
267 upmconfig (UPMB, (uint *) puma_table,
268 sizeof (puma_table) / sizeof (uint));
wdenkf8cac652002-08-26 22:36:39 +0000269
wdenk87249ba2004-01-06 22:38:14 +0000270 return (size_b0);
wdenkf8cac652002-08-26 22:36:39 +0000271}
272
273/* ------------------------------------------------------------------------- */
274
275/*
276 * Check memory range for valid RAM. A simple memory test determines
277 * the actually available RAM size between addresses `base' and
278 * `base + maxsize'. Some (not all) hardware errors are detected:
279 * - short between address lines
280 * - short between data lines
281 */
282
wdenk87249ba2004-01-06 22:38:14 +0000283static long int dram_size (long int mamr_value, long int *base,
284 long int maxsize)
wdenkf8cac652002-08-26 22:36:39 +0000285{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200286 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk87249ba2004-01-06 22:38:14 +0000287 volatile memctl8xx_t *memctl = &immr->im_memctl;
wdenkf8cac652002-08-26 22:36:39 +0000288
wdenk87249ba2004-01-06 22:38:14 +0000289 memctl->memc_mamr = mamr_value;
wdenkf8cac652002-08-26 22:36:39 +0000290
wdenk87249ba2004-01-06 22:38:14 +0000291 return (get_ram_size (base, maxsize));
wdenkf8cac652002-08-26 22:36:39 +0000292}
293
294/* ------------------------------------------------------------------------- */
295
wdenk87249ba2004-01-06 22:38:14 +0000296#if PCU_E_WITH_SWAPPED_CS /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200297#define ETH_CFG_BITS (CONFIG_SYS_PB_ETH_CFG1 | CONFIG_SYS_PB_ETH_CFG2 | CONFIG_SYS_PB_ETH_CFG3 )
wdenk87249ba2004-01-06 22:38:14 +0000298#else /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200299#define ETH_CFG_BITS (CONFIG_SYS_PB_ETH_MDDIS | CONFIG_SYS_PB_ETH_CFG1 | \
300 CONFIG_SYS_PB_ETH_CFG2 | CONFIG_SYS_PB_ETH_CFG3 )
wdenkf8cac652002-08-26 22:36:39 +0000301#endif /* XXX */
302
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200303#define ETH_ALL_BITS (ETH_CFG_BITS | CONFIG_SYS_PB_ETH_POWERDOWN | CONFIG_SYS_PB_ETH_RESET)
wdenkf8cac652002-08-26 22:36:39 +0000304
wdenk87249ba2004-01-06 22:38:14 +0000305void reset_phy (void)
wdenkf8cac652002-08-26 22:36:39 +0000306{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200307 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenkf8cac652002-08-26 22:36:39 +0000308 ulong value;
309
310 /* Configure all needed port pins for GPIO */
wdenk87249ba2004-01-06 22:38:14 +0000311#if PCU_E_WITH_SWAPPED_CS /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200312# ifdef CONFIG_SYS_ETH_MDDIS_VALUE
313 immr->im_ioport.iop_padat |= CONFIG_SYS_PA_ETH_MDDIS;
wdenkf8cac652002-08-26 22:36:39 +0000314# else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200315 immr->im_ioport.iop_padat &= ~(CONFIG_SYS_PA_ETH_MDDIS); /* Set low */
wdenkf8cac652002-08-26 22:36:39 +0000316# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200317 immr->im_ioport.iop_papar &= ~(CONFIG_SYS_PA_ETH_MDDIS); /* GPIO */
318 immr->im_ioport.iop_paodr &= ~(CONFIG_SYS_PA_ETH_MDDIS); /* active output */
319 immr->im_ioport.iop_padir |= CONFIG_SYS_PA_ETH_MDDIS; /* output */
wdenkf8cac652002-08-26 22:36:39 +0000320#endif /* XXX */
321 immr->im_cpm.cp_pbpar &= ~(ETH_ALL_BITS); /* GPIO */
322 immr->im_cpm.cp_pbodr &= ~(ETH_ALL_BITS); /* active output */
323
wdenk87249ba2004-01-06 22:38:14 +0000324 value = immr->im_cpm.cp_pbdat;
wdenkf8cac652002-08-26 22:36:39 +0000325
326 /* Assert Powerdown and Reset signals */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200327 value |= CONFIG_SYS_PB_ETH_POWERDOWN;
328 value &= ~(CONFIG_SYS_PB_ETH_RESET);
wdenkf8cac652002-08-26 22:36:39 +0000329
330 /* PHY configuration includes MDDIS and CFG1 ... CFG3 */
331#if !PCU_E_WITH_SWAPPED_CS
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200332# ifdef CONFIG_SYS_ETH_MDDIS_VALUE
333 value |= CONFIG_SYS_PB_ETH_MDDIS;
wdenkf8cac652002-08-26 22:36:39 +0000334# else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200335 value &= ~(CONFIG_SYS_PB_ETH_MDDIS);
wdenkf8cac652002-08-26 22:36:39 +0000336# endif
337#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200338#ifdef CONFIG_SYS_ETH_CFG1_VALUE
339 value |= CONFIG_SYS_PB_ETH_CFG1;
wdenkf8cac652002-08-26 22:36:39 +0000340#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200341 value &= ~(CONFIG_SYS_PB_ETH_CFG1);
wdenkf8cac652002-08-26 22:36:39 +0000342#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200343#ifdef CONFIG_SYS_ETH_CFG2_VALUE
344 value |= CONFIG_SYS_PB_ETH_CFG2;
wdenkf8cac652002-08-26 22:36:39 +0000345#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200346 value &= ~(CONFIG_SYS_PB_ETH_CFG2);
wdenkf8cac652002-08-26 22:36:39 +0000347#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200348#ifdef CONFIG_SYS_ETH_CFG3_VALUE
349 value |= CONFIG_SYS_PB_ETH_CFG3;
wdenkf8cac652002-08-26 22:36:39 +0000350#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200351 value &= ~(CONFIG_SYS_PB_ETH_CFG3);
wdenkf8cac652002-08-26 22:36:39 +0000352#endif
353
354 /* Drive output signals to initial state */
wdenk87249ba2004-01-06 22:38:14 +0000355 immr->im_cpm.cp_pbdat = value;
wdenkf8cac652002-08-26 22:36:39 +0000356 immr->im_cpm.cp_pbdir |= ETH_ALL_BITS;
357 udelay (10000);
358
359 /* De-assert Ethernet Powerdown */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200360 immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_ETH_POWERDOWN); /* Enable PHY power */
wdenkf8cac652002-08-26 22:36:39 +0000361 udelay (10000);
362
363 /* de-assert RESET signal of PHY */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200364 immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_ETH_RESET;
wdenkf8cac652002-08-26 22:36:39 +0000365 udelay (1000);
366}
367
368/*-----------------------------------------------------------------------
369 * Board Special Commands: access functions for "PUMA" FPGA
370 */
Jon Loeligere11c1232007-07-09 18:45:16 -0500371#if defined(CONFIG_CMD_BSP)
wdenkf8cac652002-08-26 22:36:39 +0000372
373#define PUMA_READ_MODE 0
374#define PUMA_LOAD_MODE 1
375
wdenk87249ba2004-01-06 22:38:14 +0000376int do_puma (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
wdenkf8cac652002-08-26 22:36:39 +0000377{
378 ulong addr, len;
379
380 switch (argc) {
wdenk87249ba2004-01-06 22:38:14 +0000381 case 2: /* PUMA reset */
382 if (strncmp (argv[1], "stat", 4) == 0) { /* Reset */
wdenkf8cac652002-08-26 22:36:39 +0000383 puma_status ();
384 return 0;
385 }
386 break;
wdenk87249ba2004-01-06 22:38:14 +0000387 case 4: /* PUMA load addr len */
388 if (strcmp (argv[1], "load") != 0)
wdenkf8cac652002-08-26 22:36:39 +0000389 break;
390
wdenk87249ba2004-01-06 22:38:14 +0000391 addr = simple_strtoul (argv[2], NULL, 16);
392 len = simple_strtoul (argv[3], NULL, 16);
wdenkf8cac652002-08-26 22:36:39 +0000393
394 printf ("PUMA load: addr %08lX len %ld (0x%lX): ",
395 addr, len, len);
396 puma_load (addr, len);
397
398 return 0;
399 default:
400 break;
401 }
402 printf ("Usage:\n%s\n", cmdtp->usage);
403 return 1;
404}
wdenk87249ba2004-01-06 22:38:14 +0000405
406U_BOOT_CMD (puma, 4, 1, do_puma,
407 "puma - access PUMA FPGA\n",
408 "status - print PUMA status\n"
409 "puma load addr len - load PUMA configuration data\n");
wdenkf8cac652002-08-26 22:36:39 +0000410
Jon Loeliger761ea742007-07-10 10:48:22 -0500411#endif
wdenkf8cac652002-08-26 22:36:39 +0000412
413/* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
414
415static void puma_set_mode (int mode)
416{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200417 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenkf8cac652002-08-26 22:36:39 +0000418 volatile memctl8xx_t *memctl = &immr->im_memctl;
419
420 /* disable PUMA in memory controller */
421#if PCU_E_WITH_SWAPPED_CS /* XXX */
wdenk87249ba2004-01-06 22:38:14 +0000422 memctl->memc_br3 = 0;
423#else /* XXX */
424 memctl->memc_br4 = 0;
425#endif /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000426
427 switch (mode) {
428 case PUMA_READ_MODE:
429#if PCU_E_WITH_SWAPPED_CS /* XXX */
430 memctl->memc_or3 = PUMA_CONF_OR_READ;
431 memctl->memc_br3 = PUMA_CONF_BR_READ;
wdenk87249ba2004-01-06 22:38:14 +0000432#else /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000433 memctl->memc_or4 = PUMA_CONF_OR_READ;
434 memctl->memc_br4 = PUMA_CONF_BR_READ;
wdenk87249ba2004-01-06 22:38:14 +0000435#endif /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000436 break;
437 case PUMA_LOAD_MODE:
438#if PCU_E_WITH_SWAPPED_CS /* XXX */
439 memctl->memc_or3 = PUMA_CONF_OR_LOAD;
440 memctl->memc_br3 = PUMA_CONF_BR_LOAD;
wdenk87249ba2004-01-06 22:38:14 +0000441#else /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000442 memctl->memc_or4 = PUMA_CONF_OR_READ;
443 memctl->memc_br4 = PUMA_CONF_BR_READ;
wdenk87249ba2004-01-06 22:38:14 +0000444#endif /* XXX */
wdenkf8cac652002-08-26 22:36:39 +0000445 break;
446 }
447}
448
449/* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
450
451#define PUMA_INIT_TIMEOUT 1000 /* max. 1000 ms = 1 second */
452
453static void puma_load (ulong addr, ulong len)
454{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200455 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk87249ba2004-01-06 22:38:14 +0000456 volatile uchar *fpga_addr = (volatile uchar *) PUMA_CONF_BASE; /* XXX ??? */
457 uchar *data = (uchar *) addr;
wdenkf8cac652002-08-26 22:36:39 +0000458 int i;
459
460 /* align length */
461 if (len & 1)
462 ++len;
463
464 /* Reset FPGA */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200465 immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_PUMA_INIT); /* make input */
466 immr->im_ioport.iop_pcso &= ~(CONFIG_SYS_PC_PUMA_INIT);
467 immr->im_ioport.iop_pcdir &= ~(CONFIG_SYS_PC_PUMA_INIT);
wdenkf8cac652002-08-26 22:36:39 +0000468
wdenk87249ba2004-01-06 22:38:14 +0000469#if PCU_E_WITH_SWAPPED_CS /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200470 immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_PUMA_PROG); /* GPIO */
471 immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_PUMA_PROG); /* active output */
472 immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_PUMA_PROG); /* Set low */
473 immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_PUMA_PROG; /* output */
wdenkf8cac652002-08-26 22:36:39 +0000474#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200475 immr->im_ioport.iop_papar &= ~(CONFIG_SYS_PA_PUMA_PROG); /* GPIO */
476 immr->im_ioport.iop_padat &= ~(CONFIG_SYS_PA_PUMA_PROG); /* Set low */
477 immr->im_ioport.iop_paodr &= ~(CONFIG_SYS_PA_PUMA_PROG); /* active output */
478 immr->im_ioport.iop_padir |= CONFIG_SYS_PA_PUMA_PROG; /* output */
wdenkf8cac652002-08-26 22:36:39 +0000479#endif /* XXX */
480 udelay (100);
481
wdenk87249ba2004-01-06 22:38:14 +0000482#if PCU_E_WITH_SWAPPED_CS /* XXX */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200483 immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_PUMA_PROG; /* release reset */
wdenkf8cac652002-08-26 22:36:39 +0000484#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200485 immr->im_ioport.iop_padat |= CONFIG_SYS_PA_PUMA_PROG; /* release reset */
wdenkf8cac652002-08-26 22:36:39 +0000486#endif /* XXX */
487
488 /* wait until INIT indicates completion of reset */
wdenk87249ba2004-01-06 22:38:14 +0000489 for (i = 0; i < PUMA_INIT_TIMEOUT; ++i) {
wdenkf8cac652002-08-26 22:36:39 +0000490 udelay (1000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200491 if (immr->im_ioport.iop_pcdat & CONFIG_SYS_PC_PUMA_INIT)
wdenkf8cac652002-08-26 22:36:39 +0000492 break;
493 }
494 if (i == PUMA_INIT_TIMEOUT) {
495 printf ("*** PUMA init timeout ***\n");
496 return;
497 }
498
499 puma_set_mode (PUMA_LOAD_MODE);
500
501 while (len--)
502 *fpga_addr = *data++;
503
504 puma_set_mode (PUMA_READ_MODE);
505
506 puma_status ();
507}
508
509/* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
510
511static void puma_status (void)
512{
513 /* Check state */
514 printf ("PUMA initialization is %scomplete\n",
wdenk87249ba2004-01-06 22:38:14 +0000515 puma_init_done ()? "" : "NOT ");
wdenkf8cac652002-08-26 22:36:39 +0000516}
517
518/* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
519
520static int puma_init_done (void)
521{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200522 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenkf8cac652002-08-26 22:36:39 +0000523
524 /* make sure pin is GPIO input */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200525 immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_PUMA_DONE);
526 immr->im_ioport.iop_pcso &= ~(CONFIG_SYS_PC_PUMA_DONE);
527 immr->im_ioport.iop_pcdir &= ~(CONFIG_SYS_PC_PUMA_DONE);
wdenkf8cac652002-08-26 22:36:39 +0000528
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200529 return (immr->im_ioport.iop_pcdat & CONFIG_SYS_PC_PUMA_DONE) ? 1 : 0;
wdenkf8cac652002-08-26 22:36:39 +0000530}
531
532/* ------------------------------------------------------------------------- */
533
534int misc_init_r (void)
535{
536 ulong addr = 0;
wdenk87249ba2004-01-06 22:38:14 +0000537 ulong len = 0;
wdenkf8cac652002-08-26 22:36:39 +0000538 char *s;
539
540 printf ("PUMA: ");
wdenk87249ba2004-01-06 22:38:14 +0000541 if (puma_init_done ()) {
wdenkf8cac652002-08-26 22:36:39 +0000542 printf ("initialized\n");
543 return 0;
544 }
545
wdenk87249ba2004-01-06 22:38:14 +0000546 if ((s = getenv ("puma_addr")) != NULL)
547 addr = simple_strtoul (s, NULL, 16);
wdenkf8cac652002-08-26 22:36:39 +0000548
wdenk87249ba2004-01-06 22:38:14 +0000549 if ((s = getenv ("puma_len")) != NULL)
550 len = simple_strtoul (s, NULL, 16);
wdenkf8cac652002-08-26 22:36:39 +0000551
552 if ((!addr) || (!len)) {
553 printf ("net list undefined\n");
554 return 0;
555 }
556
557 printf ("loading... ");
558
559 puma_load (addr, len);
560 return (0);
561}
562
563/* ------------------------------------------------------------------------- */