85xx: remove the unused ddr_enable_ecc in the board file
[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/mmu.h>
29 #include <asm/immap_85xx.h>
30 #include <asm/immap_fsl_pci.h>
31 #include <asm/fsl_ddr_sdram.h>
32 #include <spd_sdram.h>
33 #include <miiphy.h>
34 #include <libfdt.h>
35 #include <fdt_support.h>
36
37 #include "../common/cadmus.h"
38 #include "../common/eeprom.h"
39 #include "../common/via.h"
40
41 DECLARE_GLOBAL_DATA_PTR;
42
43 void local_bus_init(void);
44 void sdram_init(void);
45
46 int checkboard (void)
47 {
48         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
49         volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
50
51         /* PCI slot in USER bits CSR[6:7] by convention. */
52         uint pci_slot = get_pci_slot ();
53
54         uint cpu_board_rev = get_cpu_board_revision ();
55         uint svr;
56
57         printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
58                 get_board_version (), pci_slot);
59
60         printf ("CPU Board Revision %d.%d (0x%04x)\n",
61                 MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
62                 MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
63         /*
64          * Initialize local bus.
65          */
66         local_bus_init ();
67
68         svr = get_svr();
69
70         /*
71          * Fix CPU2 errata: A core hang possible while executing a
72          * msync instruction and a snoopable transaction from an I/O
73          * master tagged to make quick forward progress is present.
74          * Fixed in Silicon Rev.2.1
75          */
76         if (!(SVR_MAJ(svr) >= 2 && SVR_MIN(svr) >= 1))
77                 ecm->eebpcr |= (1 << 16);
78
79         /*
80          * Hack TSEC 3 and 4 IO voltages.
81          */
82         gur->tsec34ioovcr = 0xe7e0;     /*  1110 0111 1110 0xxx */
83
84         ecm->eedr = 0xffffffff;         /* clear ecm errors */
85         ecm->eeer = 0xffffffff;         /* enable ecm errors */
86         return 0;
87 }
88
89 phys_size_t
90 initdram(int board_type)
91 {
92         long dram_size = 0;
93
94         puts("Initializing\n");
95
96 #if defined(CONFIG_DDR_DLL)
97         {
98                 /*
99                  * Work around to stabilize DDR DLL MSYNC_IN.
100                  * Errata DDR9 seems to have been fixed.
101                  * This is now the workaround for Errata DDR11:
102                  *    Override DLL = 1, Course Adj = 1, Tap Select = 0
103                  */
104
105                 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
106
107                 gur->ddrdllcr = 0x81000000;
108                 asm("sync;isync;msync");
109                 udelay(200);
110         }
111 #endif
112
113         dram_size = fsl_ddr_sdram();
114         dram_size = setup_ddr_tlbs(dram_size / 0x100000);
115         dram_size *= 0x100000;
116
117         /*
118          * SDRAM Initialization
119          */
120         sdram_init();
121
122         puts("    DDR: ");
123         return dram_size;
124 }
125
126 /*
127  * Initialize Local Bus
128  */
129 void
130 local_bus_init(void)
131 {
132         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
133         volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
134
135         uint clkdiv;
136         uint lbc_hz;
137         sys_info_t sysinfo;
138
139         get_sys_info(&sysinfo);
140         clkdiv = (lbc->lcrr & 0x0f) * 2;
141         lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
142
143         gur->lbiuiplldcr1 = 0x00078080;
144         if (clkdiv == 16) {
145                 gur->lbiuiplldcr0 = 0x7c0f1bf0;
146         } else if (clkdiv == 8) {
147                 gur->lbiuiplldcr0 = 0x6c0f1bf0;
148         } else if (clkdiv == 4) {
149                 gur->lbiuiplldcr0 = 0x5c0f1bf0;
150         }
151
152         lbc->lcrr |= 0x00030000;
153
154         asm("sync;isync;msync");
155
156         lbc->ltesr = 0xffffffff;        /* Clear LBC error interrupts */
157         lbc->lteir = 0xffffffff;        /* Enable LBC error interrupts */
158 }
159
160 /*
161  * Initialize SDRAM memory on the Local Bus.
162  */
163 void
164 sdram_init(void)
165 {
166 #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
167
168         uint idx;
169         volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
170         uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
171         uint cpu_board_rev;
172         uint lsdmr_common;
173
174         puts("    SDRAM: ");
175
176         print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
177
178         /*
179          * Setup SDRAM Base and Option Registers
180          */
181         lbc->or2 = CONFIG_SYS_OR2_PRELIM;
182         asm("msync");
183
184         lbc->br2 = CONFIG_SYS_BR2_PRELIM;
185         asm("msync");
186
187         lbc->lbcr = CONFIG_SYS_LBC_LBCR;
188         asm("msync");
189
190
191         lbc->lsrt = CONFIG_SYS_LBC_LSRT;
192         lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
193         asm("msync");
194
195         /*
196          * MPC8548 uses "new" 15-16 style addressing.
197          */
198         cpu_board_rev = get_cpu_board_revision();
199         lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
200         lsdmr_common |= CONFIG_SYS_LBC_LSDMR_BSMA1516;
201
202         /*
203          * Issue PRECHARGE ALL command.
204          */
205         lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_PCHALL;
206         asm("sync;msync");
207         *sdram_addr = 0xff;
208         ppcDcbf((unsigned long) sdram_addr);
209         udelay(100);
210
211         /*
212          * Issue 8 AUTO REFRESH commands.
213          */
214         for (idx = 0; idx < 8; idx++) {
215                 lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_ARFRSH;
216                 asm("sync;msync");
217                 *sdram_addr = 0xff;
218                 ppcDcbf((unsigned long) sdram_addr);
219                 udelay(100);
220         }
221
222         /*
223          * Issue 8 MODE-set command.
224          */
225         lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_MRW;
226         asm("sync;msync");
227         *sdram_addr = 0xff;
228         ppcDcbf((unsigned long) sdram_addr);
229         udelay(100);
230
231         /*
232          * Issue NORMAL OP command.
233          */
234         lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_NORMAL;
235         asm("sync;msync");
236         *sdram_addr = 0xff;
237         ppcDcbf((unsigned long) sdram_addr);
238         udelay(200);    /* Overkill. Must wait > 200 bus cycles */
239
240 #endif  /* enable SDRAM init */
241 }
242
243 #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
244 /* For some reason the Tundra PCI bridge shows up on itself as a
245  * different device.  Work around that by refusing to configure it.
246  */
247 void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
248
249 static struct pci_config_table pci_mpc85xxcds_config_table[] = {
250         {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
251         {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
252         {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
253                 mpc85xx_config_via_usbide, {0,0,0}},
254         {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
255                 mpc85xx_config_via_usb, {0,0,0}},
256         {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
257                 mpc85xx_config_via_usb2, {0,0,0}},
258         {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
259                 mpc85xx_config_via_power, {0,0,0}},
260         {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
261                 mpc85xx_config_via_ac97, {0,0,0}},
262         {},
263 };
264
265 static struct pci_controller pci1_hose = {
266         config_table: pci_mpc85xxcds_config_table};
267 #endif  /* CONFIG_PCI */
268
269 #ifdef CONFIG_PCI2
270 static struct pci_controller pci2_hose;
271 #endif  /* CONFIG_PCI2 */
272
273 #ifdef CONFIG_PCIE1
274 static struct pci_controller pcie1_hose;
275 #endif  /* CONFIG_PCIE1 */
276
277 extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
278 extern void fsl_pci_init(struct pci_controller *hose);
279
280 int first_free_busno=0;
281
282 void
283 pci_init_board(void)
284 {
285         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
286         uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
287         uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
288
289
290 #ifdef CONFIG_PCI1
291 {
292         volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
293         struct pci_controller *hose = &pci1_hose;
294         struct pci_config_table *table;
295         struct pci_region *r = hose->regions;
296
297         uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;      /* PORDEVSR[15] */
298         uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;       /* PORDEVSR[14] */
299         uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;   /* PORPLLSR[16] */
300
301         uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
302
303         uint pci_speed = get_clock_freq ();     /* PCI PSPEED in [4:5] */
304
305         if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
306                 printf ("    PCI: %d bit, %s MHz, %s, %s, %s\n",
307                         (pci_32) ? 32 : 64,
308                         (pci_speed == 33333000) ? "33" :
309                         (pci_speed == 66666000) ? "66" : "unknown",
310                         pci_clk_sel ? "sync" : "async",
311                         pci_agent ? "agent" : "host",
312                         pci_arb ? "arbiter" : "external-arbiter"
313                         );
314
315
316                 /* inbound */
317                 r += fsl_pci_setup_inbound_windows(r);
318
319                 /* outbound memory */
320                 pci_set_region(r++,
321                                CONFIG_SYS_PCI1_MEM_BASE,
322                                CONFIG_SYS_PCI1_MEM_PHYS,
323                                CONFIG_SYS_PCI1_MEM_SIZE,
324                                PCI_REGION_MEM);
325
326                 /* outbound io */
327                 pci_set_region(r++,
328                                CONFIG_SYS_PCI1_IO_BASE,
329                                CONFIG_SYS_PCI1_IO_PHYS,
330                                CONFIG_SYS_PCI1_IO_SIZE,
331                                PCI_REGION_IO);
332                 hose->region_count = r - hose->regions;
333
334                 /* relocate config table pointers */
335                 hose->config_table = \
336                         (struct pci_config_table *)((uint)hose->config_table + gd->reloc_off);
337                 for (table = hose->config_table; table && table->vendor; table++)
338                         table->config_device += gd->reloc_off;
339
340                 hose->first_busno=first_free_busno;
341                 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
342
343                 fsl_pci_init(hose);
344                 first_free_busno=hose->last_busno+1;
345                 printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
346 #ifdef CONFIG_PCIX_CHECK
347                 if (!(gur->pordevsr & PORDEVSR_PCI)) {
348                         /* PCI-X init */
349                         if (CONFIG_SYS_CLK_FREQ < 66000000)
350                                 printf("PCI-X will only work at 66 MHz\n");
351
352                         reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
353                                 | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
354                         pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
355                 }
356 #endif
357         } else {
358                 printf ("    PCI: disabled\n");
359         }
360 }
361 #else
362         gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
363 #endif
364
365 #ifdef CONFIG_PCI2
366 {
367         uint pci2_clk_sel = gur->porpllsr & 0x4000;     /* PORPLLSR[17] */
368         uint pci_dual = get_pci_dual ();        /* PCI DUAL in CM_PCI[3] */
369         if (pci_dual) {
370                 printf ("    PCI2: 32 bit, 66 MHz, %s\n",
371                         pci2_clk_sel ? "sync" : "async");
372         } else {
373                 printf ("    PCI2: disabled\n");
374         }
375 }
376 #else
377         gur->devdisr |= MPC85xx_DEVDISR_PCI2; /* disable */
378 #endif /* CONFIG_PCI2 */
379
380 #ifdef CONFIG_PCIE1
381 {
382         volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
383         struct pci_controller *hose = &pcie1_hose;
384         int pcie_ep =  (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
385         struct pci_region *r = hose->regions;
386
387         int pcie_configured  = io_sel >= 1;
388
389         if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
390                 printf ("\n    PCIE connected to slot as %s (base address %x)",
391                         pcie_ep ? "End Point" : "Root Complex",
392                         (uint)pci);
393
394                 if (pci->pme_msg_det) {
395                         pci->pme_msg_det = 0xffffffff;
396                         debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
397                 }
398                 printf ("\n");
399
400                 /* inbound */
401                 r += fsl_pci_setup_inbound_windows(r);
402
403                 /* outbound memory */
404                 pci_set_region(r++,
405                                CONFIG_SYS_PCIE1_MEM_BASE,
406                                CONFIG_SYS_PCIE1_MEM_PHYS,
407                                CONFIG_SYS_PCIE1_MEM_SIZE,
408                                PCI_REGION_MEM);
409
410                 /* outbound io */
411                 pci_set_region(r++,
412                                CONFIG_SYS_PCIE1_IO_BASE,
413                                CONFIG_SYS_PCIE1_IO_PHYS,
414                                CONFIG_SYS_PCIE1_IO_SIZE,
415                                PCI_REGION_IO);
416
417                 hose->region_count = r - hose->regions;
418
419                 hose->first_busno=first_free_busno;
420                 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
421
422                 fsl_pci_init(hose);
423                 printf ("PCIE on bus %d - %d\n",hose->first_busno,hose->last_busno);
424
425                 first_free_busno=hose->last_busno+1;
426
427         } else {
428                 printf ("    PCIE: disabled\n");
429         }
430  }
431 #else
432         gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
433 #endif
434
435 }
436
437 int last_stage_init(void)
438 {
439         unsigned short temp;
440
441         /* Change the resistors for the PHY */
442         /* This is needed to get the RGMII working for the 1.3+
443          * CDS cards */
444         if (get_board_version() ==  0x13) {
445                 miiphy_write(CONFIG_TSEC1_NAME,
446                                 TSEC1_PHY_ADDR, 29, 18);
447
448                 miiphy_read(CONFIG_TSEC1_NAME,
449                                 TSEC1_PHY_ADDR, 30, &temp);
450
451                 temp = (temp & 0xf03f);
452                 temp |= 2 << 9;         /* 36 ohm */
453                 temp |= 2 << 6;         /* 39 ohm */
454
455                 miiphy_write(CONFIG_TSEC1_NAME,
456                                 TSEC1_PHY_ADDR, 30, temp);
457
458                 miiphy_write(CONFIG_TSEC1_NAME,
459                                 TSEC1_PHY_ADDR, 29, 3);
460
461                 miiphy_write(CONFIG_TSEC1_NAME,
462                                 TSEC1_PHY_ADDR, 30, 0x8000);
463         }
464
465         return 0;
466 }
467
468
469 #if defined(CONFIG_OF_BOARD_SETUP)
470 extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
471                         struct pci_controller *hose);
472
473 void ft_pci_setup(void *blob, bd_t *bd)
474 {
475 #ifdef CONFIG_PCI1
476         ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
477 #endif
478 #ifdef CONFIG_PCIE1
479         ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
480 #endif
481 }
482 #endif