85xx: Remove unused and unconfigured memory test code.
[platform/kernel/u-boot.git] / board / freescale / mpc8548cds / mpc8548cds.c
1 /*
2  * Copyright 2004, 2007 Freescale Semiconductor.
3  *
4  * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  */
24
25 #include <common.h>
26 #include <pci.h>
27 #include <asm/processor.h>
28 #include <asm/immap_85xx.h>
29 #include <asm/immap_fsl_pci.h>
30 #include <spd_sdram.h>
31 #include <miiphy.h>
32 #include <libfdt.h>
33 #include <fdt_support.h>
34
35 #include "../common/cadmus.h"
36 #include "../common/eeprom.h"
37 #include "../common/via.h"
38
39 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
40 extern void ddr_enable_ecc(unsigned int dram_size);
41 #endif
42
43 DECLARE_GLOBAL_DATA_PTR;
44
45 void local_bus_init(void);
46 void sdram_init(void);
47
48 int board_early_init_f (void)
49 {
50         return 0;
51 }
52
53 int checkboard (void)
54 {
55         volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
56         volatile ccsr_local_ecm_t *ecm = (void *)(CFG_MPC85xx_ECM_ADDR);
57
58         /* PCI slot in USER bits CSR[6:7] by convention. */
59         uint pci_slot = get_pci_slot ();
60
61         uint cpu_board_rev = get_cpu_board_revision ();
62         uint svr;
63
64         printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
65                 get_board_version (), pci_slot);
66
67         printf ("CPU Board Revision %d.%d (0x%04x)\n",
68                 MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
69                 MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
70         /*
71          * Initialize local bus.
72          */
73         local_bus_init ();
74
75         svr = get_svr();
76
77         /*
78          * Fix CPU2 errata: A core hang possible while executing a
79          * msync instruction and a snoopable transaction from an I/O
80          * master tagged to make quick forward progress is present.
81          * Fixed in Silicon Rev.2.1
82          */
83         if (!(SVR_MAJ(svr) >= 2 && SVR_MIN(svr) >= 1))
84                 ecm->eebpcr |= (1 << 16);
85
86         /*
87          * Hack TSEC 3 and 4 IO voltages.
88          */
89         gur->tsec34ioovcr = 0xe7e0;     /*  1110 0111 1110 0xxx */
90
91         ecm->eedr = 0xffffffff;         /* clear ecm errors */
92         ecm->eeer = 0xffffffff;         /* enable ecm errors */
93         return 0;
94 }
95
96 long int
97 initdram(int board_type)
98 {
99         long dram_size = 0;
100
101         puts("Initializing\n");
102
103 #if defined(CONFIG_DDR_DLL)
104         {
105                 /*
106                  * Work around to stabilize DDR DLL MSYNC_IN.
107                  * Errata DDR9 seems to have been fixed.
108                  * This is now the workaround for Errata DDR11:
109                  *    Override DLL = 1, Course Adj = 1, Tap Select = 0
110                  */
111
112                 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
113
114                 gur->ddrdllcr = 0x81000000;
115                 asm("sync;isync;msync");
116                 udelay(200);
117         }
118 #endif
119         dram_size = spd_sdram();
120
121 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
122         /*
123          * Initialize and enable DDR ECC.
124          */
125         ddr_enable_ecc(dram_size);
126 #endif
127         /*
128          * SDRAM Initialization
129          */
130         sdram_init();
131
132         puts("    DDR: ");
133         return dram_size;
134 }
135
136 /*
137  * Initialize Local Bus
138  */
139 void
140 local_bus_init(void)
141 {
142         volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
143         volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
144
145         uint clkdiv;
146         uint lbc_hz;
147         sys_info_t sysinfo;
148
149         get_sys_info(&sysinfo);
150         clkdiv = (lbc->lcrr & 0x0f) * 2;
151         lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
152
153         gur->lbiuiplldcr1 = 0x00078080;
154         if (clkdiv == 16) {
155                 gur->lbiuiplldcr0 = 0x7c0f1bf0;
156         } else if (clkdiv == 8) {
157                 gur->lbiuiplldcr0 = 0x6c0f1bf0;
158         } else if (clkdiv == 4) {
159                 gur->lbiuiplldcr0 = 0x5c0f1bf0;
160         }
161
162         lbc->lcrr |= 0x00030000;
163
164         asm("sync;isync;msync");
165
166         lbc->ltesr = 0xffffffff;        /* Clear LBC error interrupts */
167         lbc->lteir = 0xffffffff;        /* Enable LBC error interrupts */
168 }
169
170 /*
171  * Initialize SDRAM memory on the Local Bus.
172  */
173 void
174 sdram_init(void)
175 {
176 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
177
178         uint idx;
179         volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
180         uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
181         uint cpu_board_rev;
182         uint lsdmr_common;
183
184         puts("    SDRAM: ");
185
186         print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
187
188         /*
189          * Setup SDRAM Base and Option Registers
190          */
191         lbc->or2 = CFG_OR2_PRELIM;
192         asm("msync");
193
194         lbc->br2 = CFG_BR2_PRELIM;
195         asm("msync");
196
197         lbc->lbcr = CFG_LBC_LBCR;
198         asm("msync");
199
200
201         lbc->lsrt = CFG_LBC_LSRT;
202         lbc->mrtpr = CFG_LBC_MRTPR;
203         asm("msync");
204
205         /*
206          * MPC8548 uses "new" 15-16 style addressing.
207          */
208         cpu_board_rev = get_cpu_board_revision();
209         lsdmr_common = CFG_LBC_LSDMR_COMMON;
210         lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
211
212         /*
213          * Issue PRECHARGE ALL command.
214          */
215         lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
216         asm("sync;msync");
217         *sdram_addr = 0xff;
218         ppcDcbf((unsigned long) sdram_addr);
219         udelay(100);
220
221         /*
222          * Issue 8 AUTO REFRESH commands.
223          */
224         for (idx = 0; idx < 8; idx++) {
225                 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
226                 asm("sync;msync");
227                 *sdram_addr = 0xff;
228                 ppcDcbf((unsigned long) sdram_addr);
229                 udelay(100);
230         }
231
232         /*
233          * Issue 8 MODE-set command.
234          */
235         lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
236         asm("sync;msync");
237         *sdram_addr = 0xff;
238         ppcDcbf((unsigned long) sdram_addr);
239         udelay(100);
240
241         /*
242          * Issue NORMAL OP command.
243          */
244         lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
245         asm("sync;msync");
246         *sdram_addr = 0xff;
247         ppcDcbf((unsigned long) sdram_addr);
248         udelay(200);    /* Overkill. Must wait > 200 bus cycles */
249
250 #endif  /* enable SDRAM init */
251 }
252
253 #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
254 /* For some reason the Tundra PCI bridge shows up on itself as a
255  * different device.  Work around that by refusing to configure it.
256  */
257 void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
258
259 static struct pci_config_table pci_mpc85xxcds_config_table[] = {
260         {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
261         {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
262         {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
263                 mpc85xx_config_via_usbide, {0,0,0}},
264         {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
265                 mpc85xx_config_via_usb, {0,0,0}},
266         {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
267                 mpc85xx_config_via_usb2, {0,0,0}},
268         {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
269                 mpc85xx_config_via_power, {0,0,0}},
270         {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
271                 mpc85xx_config_via_ac97, {0,0,0}},
272         {},
273 };
274
275 static struct pci_controller pci1_hose = {
276         config_table: pci_mpc85xxcds_config_table};
277 #endif  /* CONFIG_PCI */
278
279 #ifdef CONFIG_PCI2
280 static struct pci_controller pci2_hose;
281 #endif  /* CONFIG_PCI2 */
282
283 #ifdef CONFIG_PCIE1
284 static struct pci_controller pcie1_hose;
285 #endif  /* CONFIG_PCIE1 */
286
287 int first_free_busno=0;
288
289 void
290 pci_init_board(void)
291 {
292         volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
293         uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
294         uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
295
296
297 #ifdef CONFIG_PCI1
298 {
299         volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
300         extern void fsl_pci_init(struct pci_controller *hose);
301         struct pci_controller *hose = &pci1_hose;
302         struct pci_config_table *table;
303
304         uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;      /* PORDEVSR[15] */
305         uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;       /* PORDEVSR[14] */
306         uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;   /* PORPLLSR[16] */
307
308         uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
309
310         uint pci_speed = get_clock_freq ();     /* PCI PSPEED in [4:5] */
311
312         if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
313                 printf ("    PCI: %d bit, %s MHz, %s, %s, %s\n",
314                         (pci_32) ? 32 : 64,
315                         (pci_speed == 33333000) ? "33" :
316                         (pci_speed == 66666000) ? "66" : "unknown",
317                         pci_clk_sel ? "sync" : "async",
318                         pci_agent ? "agent" : "host",
319                         pci_arb ? "arbiter" : "external-arbiter"
320                         );
321
322
323                 /* inbound */
324                 pci_set_region(hose->regions + 0,
325                                CFG_PCI_MEMORY_BUS,
326                                CFG_PCI_MEMORY_PHYS,
327                                CFG_PCI_MEMORY_SIZE,
328                                PCI_REGION_MEM | PCI_REGION_MEMORY);
329
330
331                 /* outbound memory */
332                 pci_set_region(hose->regions + 1,
333                                CFG_PCI1_MEM_BASE,
334                                CFG_PCI1_MEM_PHYS,
335                                CFG_PCI1_MEM_SIZE,
336                                PCI_REGION_MEM);
337
338                 /* outbound io */
339                 pci_set_region(hose->regions + 2,
340                                CFG_PCI1_IO_BASE,
341                                CFG_PCI1_IO_PHYS,
342                                CFG_PCI1_IO_SIZE,
343                                PCI_REGION_IO);
344                 hose->region_count = 3;
345
346                 /* relocate config table pointers */
347                 hose->config_table = \
348                         (struct pci_config_table *)((uint)hose->config_table + gd->reloc_off);
349                 for (table = hose->config_table; table && table->vendor; table++)
350                         table->config_device += gd->reloc_off;
351
352                 hose->first_busno=first_free_busno;
353                 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
354
355                 fsl_pci_init(hose);
356                 first_free_busno=hose->last_busno+1;
357                 printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
358 #ifdef CONFIG_PCIX_CHECK
359                 if (!(gur->pordevsr & PORDEVSR_PCI)) {
360                         /* PCI-X init */
361                         if (CONFIG_SYS_CLK_FREQ < 66000000)
362                                 printf("PCI-X will only work at 66 MHz\n");
363
364                         reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
365                                 | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
366                         pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
367                 }
368 #endif
369         } else {
370                 printf ("    PCI: disabled\n");
371         }
372 }
373 #else
374         gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
375 #endif
376
377 #ifdef CONFIG_PCI2
378 {
379         uint pci2_clk_sel = gur->porpllsr & 0x4000;     /* PORPLLSR[17] */
380         uint pci_dual = get_pci_dual ();        /* PCI DUAL in CM_PCI[3] */
381         if (pci_dual) {
382                 printf ("    PCI2: 32 bit, 66 MHz, %s\n",
383                         pci2_clk_sel ? "sync" : "async");
384         } else {
385                 printf ("    PCI2: disabled\n");
386         }
387 }
388 #else
389         gur->devdisr |= MPC85xx_DEVDISR_PCI2; /* disable */
390 #endif /* CONFIG_PCI2 */
391
392 #ifdef CONFIG_PCIE1
393 {
394         volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
395         extern void fsl_pci_init(struct pci_controller *hose);
396         struct pci_controller *hose = &pcie1_hose;
397         int pcie_ep =  (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
398
399         int pcie_configured  = io_sel >= 1;
400
401         if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
402                 printf ("\n    PCIE connected to slot as %s (base address %x)",
403                         pcie_ep ? "End Point" : "Root Complex",
404                         (uint)pci);
405
406                 if (pci->pme_msg_det) {
407                         pci->pme_msg_det = 0xffffffff;
408                         debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
409                 }
410                 printf ("\n");
411
412                 /* inbound */
413                 pci_set_region(hose->regions + 0,
414                                CFG_PCI_MEMORY_BUS,
415                                CFG_PCI_MEMORY_PHYS,
416                                CFG_PCI_MEMORY_SIZE,
417                                PCI_REGION_MEM | PCI_REGION_MEMORY);
418
419                 /* outbound memory */
420                 pci_set_region(hose->regions + 1,
421                                CFG_PCIE1_MEM_BASE,
422                                CFG_PCIE1_MEM_PHYS,
423                                CFG_PCIE1_MEM_SIZE,
424                                PCI_REGION_MEM);
425
426                 /* outbound io */
427                 pci_set_region(hose->regions + 2,
428                                CFG_PCIE1_IO_BASE,
429                                CFG_PCIE1_IO_PHYS,
430                                CFG_PCIE1_IO_SIZE,
431                                PCI_REGION_IO);
432
433                 hose->region_count = 3;
434
435                 hose->first_busno=first_free_busno;
436                 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
437
438                 fsl_pci_init(hose);
439                 printf ("PCIE on bus %d - %d\n",hose->first_busno,hose->last_busno);
440
441                 first_free_busno=hose->last_busno+1;
442
443         } else {
444                 printf ("    PCIE: disabled\n");
445         }
446  }
447 #else
448         gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
449 #endif
450
451 }
452
453 int last_stage_init(void)
454 {
455         unsigned short temp;
456
457         /* Change the resistors for the PHY */
458         /* This is needed to get the RGMII working for the 1.3+
459          * CDS cards */
460         if (get_board_version() ==  0x13) {
461                 miiphy_write(CONFIG_TSEC1_NAME,
462                                 TSEC1_PHY_ADDR, 29, 18);
463
464                 miiphy_read(CONFIG_TSEC1_NAME,
465                                 TSEC1_PHY_ADDR, 30, &temp);
466
467                 temp = (temp & 0xf03f);
468                 temp |= 2 << 9;         /* 36 ohm */
469                 temp |= 2 << 6;         /* 39 ohm */
470
471                 miiphy_write(CONFIG_TSEC1_NAME,
472                                 TSEC1_PHY_ADDR, 30, temp);
473
474                 miiphy_write(CONFIG_TSEC1_NAME,
475                                 TSEC1_PHY_ADDR, 29, 3);
476
477                 miiphy_write(CONFIG_TSEC1_NAME,
478                                 TSEC1_PHY_ADDR, 30, 0x8000);
479         }
480
481         return 0;
482 }
483
484
485 #if defined(CONFIG_OF_BOARD_SETUP)
486 void
487 ft_pci_setup(void *blob, bd_t *bd)
488 {
489         int node, tmp[2];
490         const char *path;
491
492         node = fdt_path_offset(blob, "/aliases");
493         tmp[0] = 0;
494         if (node >= 0) {
495 #ifdef CONFIG_PCI1
496                 path = fdt_getprop(blob, node, "pci0", NULL);
497                 if (path) {
498                         tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
499                         do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
500                 }
501 #endif
502 #ifdef CONFIG_PCIE1
503                 path = fdt_getprop(blob, node, "pci1", NULL);
504                 if (path) {
505                         tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
506                         do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
507                 }
508 #endif
509         }
510 }
511 #endif