]> git.sur5r.net Git - u-boot/blob - board/mpc8568mds/mpc8568mds.c
Update MPC8568 MDS to use libfdt
[u-boot] / board / mpc8568mds / mpc8568mds.c
1 /*
2  * Copyright 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.h>
31 #include <i2c.h>
32 #include <ioports.h>
33 #include <libfdt.h>
34 #include <fdt_support.h>
35
36 #include "bcsr.h"
37
38 const qe_iop_conf_t qe_iop_conf_tab[] = {
39         /* GETH1 */
40         {4, 10, 1, 0, 2}, /* TxD0 */
41         {4,  9, 1, 0, 2}, /* TxD1 */
42         {4,  8, 1, 0, 2}, /* TxD2 */
43         {4,  7, 1, 0, 2}, /* TxD3 */
44         {4, 23, 1, 0, 2}, /* TxD4 */
45         {4, 22, 1, 0, 2}, /* TxD5 */
46         {4, 21, 1, 0, 2}, /* TxD6 */
47         {4, 20, 1, 0, 2}, /* TxD7 */
48         {4, 15, 2, 0, 2}, /* RxD0 */
49         {4, 14, 2, 0, 2}, /* RxD1 */
50         {4, 13, 2, 0, 2}, /* RxD2 */
51         {4, 12, 2, 0, 2}, /* RxD3 */
52         {4, 29, 2, 0, 2}, /* RxD4 */
53         {4, 28, 2, 0, 2}, /* RxD5 */
54         {4, 27, 2, 0, 2}, /* RxD6 */
55         {4, 26, 2, 0, 2}, /* RxD7 */
56         {4, 11, 1, 0, 2}, /* TX_EN */
57         {4, 24, 1, 0, 2}, /* TX_ER */
58         {4, 16, 2, 0, 2}, /* RX_DV */
59         {4, 30, 2, 0, 2}, /* RX_ER */
60         {4, 17, 2, 0, 2}, /* RX_CLK */
61         {4, 19, 1, 0, 2}, /* GTX_CLK */
62         {1, 31, 2, 0, 3}, /* GTX125 */
63
64         /* GETH2 */
65         {5, 10, 1, 0, 2}, /* TxD0 */
66         {5,  9, 1, 0, 2}, /* TxD1 */
67         {5,  8, 1, 0, 2}, /* TxD2 */
68         {5,  7, 1, 0, 2}, /* TxD3 */
69         {5, 23, 1, 0, 2}, /* TxD4 */
70         {5, 22, 1, 0, 2}, /* TxD5 */
71         {5, 21, 1, 0, 2}, /* TxD6 */
72         {5, 20, 1, 0, 2}, /* TxD7 */
73         {5, 15, 2, 0, 2}, /* RxD0 */
74         {5, 14, 2, 0, 2}, /* RxD1 */
75         {5, 13, 2, 0, 2}, /* RxD2 */
76         {5, 12, 2, 0, 2}, /* RxD3 */
77         {5, 29, 2, 0, 2}, /* RxD4 */
78         {5, 28, 2, 0, 2}, /* RxD5 */
79         {5, 27, 2, 0, 3}, /* RxD6 */
80         {5, 26, 2, 0, 2}, /* RxD7 */
81         {5, 11, 1, 0, 2}, /* TX_EN */
82         {5, 24, 1, 0, 2}, /* TX_ER */
83         {5, 16, 2, 0, 2}, /* RX_DV */
84         {5, 30, 2, 0, 2}, /* RX_ER */
85         {5, 17, 2, 0, 2}, /* RX_CLK */
86         {5, 19, 1, 0, 2}, /* GTX_CLK */
87         {1, 31, 2, 0, 3}, /* GTX125 */
88         {4,  6, 3, 0, 2}, /* MDIO */
89         {4,  5, 1, 0, 2}, /* MDC */
90         {0,  0, 0, 0, QE_IOP_TAB_END}, /* END of table */
91 };
92
93
94 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
95 extern void ddr_enable_ecc(unsigned int dram_size);
96 #endif
97
98 extern long int spd_sdram(void);
99
100 void local_bus_init(void);
101 void sdram_init(void);
102
103 int board_early_init_f (void)
104 {
105         /*
106          * Initialize local bus.
107          */
108         local_bus_init ();
109
110         enable_8568mds_duart();
111         enable_8568mds_flash_write();
112 #if defined(CONFIG_QE) && !defined(CONFIG_eTSEC_MDIO_BUS)
113         enable_8568mds_qe_mdio();
114 #endif
115
116 #ifdef CFG_I2C2_OFFSET
117         /* Enable I2C2_SCL and I2C2_SDA */
118         volatile struct par_io *port_c;
119         port_c = (struct par_io*)(CFG_IMMR + 0xe0140);
120         port_c->cpdir2 |= 0x0f000000;
121         port_c->cppar2 &= ~0x0f000000;
122         port_c->cppar2 |= 0x0a000000;
123 #endif
124
125         return 0;
126 }
127
128 int checkboard (void)
129 {
130         printf ("Board: 8568 MDS\n");
131
132         return 0;
133 }
134
135 long int
136 initdram(int board_type)
137 {
138         long dram_size = 0;
139
140         puts("Initializing\n");
141
142 #if defined(CONFIG_DDR_DLL)
143         {
144                 /*
145                  * Work around to stabilize DDR DLL MSYNC_IN.
146                  * Errata DDR9 seems to have been fixed.
147                  * This is now the workaround for Errata DDR11:
148                  *    Override DLL = 1, Course Adj = 1, Tap Select = 0
149                  */
150
151                 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
152
153                 gur->ddrdllcr = 0x81000000;
154                 asm("sync;isync;msync");
155                 udelay(200);
156         }
157 #endif
158         dram_size = spd_sdram();
159
160 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
161         /*
162          * Initialize and enable DDR ECC.
163          */
164         ddr_enable_ecc(dram_size);
165 #endif
166         /*
167          * SDRAM Initialization
168          */
169         sdram_init();
170
171         puts("    DDR: ");
172         return dram_size;
173 }
174
175 /*
176  * Initialize Local Bus
177  */
178 void
179 local_bus_init(void)
180 {
181         volatile immap_t *immap = (immap_t *)CFG_IMMR;
182         volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
183         volatile ccsr_lbc_t *lbc = &immap->im_lbc;
184
185         uint clkdiv;
186         uint lbc_hz;
187         sys_info_t sysinfo;
188
189         get_sys_info(&sysinfo);
190         clkdiv = (lbc->lcrr & 0x0f) * 2;
191         lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
192
193         gur->lbiuiplldcr1 = 0x00078080;
194         if (clkdiv == 16) {
195                 gur->lbiuiplldcr0 = 0x7c0f1bf0;
196         } else if (clkdiv == 8) {
197                 gur->lbiuiplldcr0 = 0x6c0f1bf0;
198         } else if (clkdiv == 4) {
199                 gur->lbiuiplldcr0 = 0x5c0f1bf0;
200         }
201
202         lbc->lcrr |= 0x00030000;
203
204         asm("sync;isync;msync");
205 }
206
207 /*
208  * Initialize SDRAM memory on the Local Bus.
209  */
210 void
211 sdram_init(void)
212 {
213 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
214
215         uint idx;
216         volatile immap_t *immap = (immap_t *)CFG_IMMR;
217         volatile ccsr_lbc_t *lbc = &immap->im_lbc;
218         uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
219         uint lsdmr_common;
220
221         puts("    SDRAM: ");
222
223         print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
224
225         /*
226          * Setup SDRAM Base and Option Registers
227          */
228         lbc->or2 = CFG_OR2_PRELIM;
229         asm("msync");
230
231         lbc->br2 = CFG_BR2_PRELIM;
232         asm("msync");
233
234         lbc->lbcr = CFG_LBC_LBCR;
235         asm("msync");
236
237
238         lbc->lsrt = CFG_LBC_LSRT;
239         lbc->mrtpr = CFG_LBC_MRTPR;
240         asm("msync");
241
242         /*
243          * MPC8568 uses "new" 15-16 style addressing.
244          */
245         lsdmr_common = CFG_LBC_LSDMR_COMMON;
246         lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
247
248         /*
249          * Issue PRECHARGE ALL command.
250          */
251         lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
252         asm("sync;msync");
253         *sdram_addr = 0xff;
254         ppcDcbf((unsigned long) sdram_addr);
255         udelay(100);
256
257         /*
258          * Issue 8 AUTO REFRESH commands.
259          */
260         for (idx = 0; idx < 8; idx++) {
261                 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
262                 asm("sync;msync");
263                 *sdram_addr = 0xff;
264                 ppcDcbf((unsigned long) sdram_addr);
265                 udelay(100);
266         }
267
268         /*
269          * Issue 8 MODE-set command.
270          */
271         lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
272         asm("sync;msync");
273         *sdram_addr = 0xff;
274         ppcDcbf((unsigned long) sdram_addr);
275         udelay(100);
276
277         /*
278          * Issue NORMAL OP command.
279          */
280         lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
281         asm("sync;msync");
282         *sdram_addr = 0xff;
283         ppcDcbf((unsigned long) sdram_addr);
284         udelay(200);    /* Overkill. Must wait > 200 bus cycles */
285
286 #endif  /* enable SDRAM init */
287 }
288
289 #if defined(CFG_DRAM_TEST)
290 int
291 testdram(void)
292 {
293         uint *pstart = (uint *) CFG_MEMTEST_START;
294         uint *pend = (uint *) CFG_MEMTEST_END;
295         uint *p;
296
297         printf("Testing DRAM from 0x%08x to 0x%08x\n",
298                CFG_MEMTEST_START,
299                CFG_MEMTEST_END);
300
301         printf("DRAM test phase 1:\n");
302         for (p = pstart; p < pend; p++)
303                 *p = 0xaaaaaaaa;
304
305         for (p = pstart; p < pend; p++) {
306                 if (*p != 0xaaaaaaaa) {
307                         printf ("DRAM test fails at: %08x\n", (uint) p);
308                         return 1;
309                 }
310         }
311
312         printf("DRAM test phase 2:\n");
313         for (p = pstart; p < pend; p++)
314                 *p = 0x55555555;
315
316         for (p = pstart; p < pend; p++) {
317                 if (*p != 0x55555555) {
318                         printf ("DRAM test fails at: %08x\n", (uint) p);
319                         return 1;
320                 }
321         }
322
323         printf("DRAM test passed.\n");
324         return 0;
325 }
326 #endif
327
328 #if defined(CONFIG_PCI)
329 #ifndef CONFIG_PCI_PNP
330 static struct pci_config_table pci_mpc8568mds_config_table[] = {
331         {
332          PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
333          pci_cfgfunc_config_device,
334          {PCI_ENET0_IOADDR,
335           PCI_ENET0_MEMADDR,
336           PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
337          },
338         {}
339 };
340 #endif
341
342 static struct pci_controller pci1_hose = {
343 #ifndef CONFIG_PCI_PNP
344         config_table: pci_mpc8568mds_config_table,
345 #endif
346 };
347 #endif  /* CONFIG_PCI */
348
349 #ifdef CONFIG_PCIE1
350 static struct pci_controller pcie1_hose;
351 #endif  /* CONFIG_PCIE1 */
352
353 int first_free_busno = 0;
354
355 /*
356  * pib_init() -- Initialize the PCA9555 IO expander on the PIB board
357  */
358 void
359 pib_init(void)
360 {
361         u8 val8, orig_i2c_bus;
362         /*
363          * Assign PIB PMC2/3 to PCI bus
364          */
365
366         /*switch temporarily to I2C bus #2 */
367         orig_i2c_bus = i2c_get_bus_num();
368         i2c_set_bus_num(1);
369
370         val8 = 0x00;
371         i2c_write(0x23, 0x6, 1, &val8, 1);
372         i2c_write(0x23, 0x7, 1, &val8, 1);
373         val8 = 0xff;
374         i2c_write(0x23, 0x2, 1, &val8, 1);
375         i2c_write(0x23, 0x3, 1, &val8, 1);
376
377         val8 = 0x00;
378         i2c_write(0x26, 0x6, 1, &val8, 1);
379         val8 = 0x34;
380         i2c_write(0x26, 0x7, 1, &val8, 1);
381         val8 = 0xf9;
382         i2c_write(0x26, 0x2, 1, &val8, 1);
383         val8 = 0xff;
384         i2c_write(0x26, 0x3, 1, &val8, 1);
385
386         val8 = 0x00;
387         i2c_write(0x27, 0x6, 1, &val8, 1);
388         i2c_write(0x27, 0x7, 1, &val8, 1);
389         val8 = 0xff;
390         i2c_write(0x27, 0x2, 1, &val8, 1);
391         val8 = 0xef;
392         i2c_write(0x27, 0x3, 1, &val8, 1);
393
394         asm("eieio");
395 }
396
397 #ifdef CONFIG_PCI
398 void
399 pci_init_board(void)
400 {
401         volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
402         uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
403         uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
404
405 #ifdef CONFIG_PCI1
406 {
407         pib_init();
408
409         volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
410         extern void fsl_pci_init(struct pci_controller *hose);
411         struct pci_controller *hose = &pci1_hose;
412
413         uint pci_32 = 1;      /* PORDEVSR[15] */
414         uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;       /* PORDEVSR[14] */
415         uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;   /* PORPLLSR[16] */
416
417         uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
418
419         uint pci_speed = 66666000;
420
421         if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
422                 printf ("    PCI: %d bit, %s MHz, %s, %s, %s\n",
423                         (pci_32) ? 32 : 64,
424                         (pci_speed == 33333000) ? "33" :
425                         (pci_speed == 66666000) ? "66" : "unknown",
426                         pci_clk_sel ? "sync" : "async",
427                         pci_agent ? "agent" : "host",
428                         pci_arb ? "arbiter" : "external-arbiter"
429                         );
430
431                 /* inbound */
432                 pci_set_region(hose->regions + 0,
433                                 CFG_PCI_MEMORY_BUS,
434                                 CFG_PCI_MEMORY_PHYS,
435                                 CFG_PCI_MEMORY_SIZE,
436                                 PCI_REGION_MEM | PCI_REGION_MEMORY);
437
438                 /* outbound memory */
439                 pci_set_region(hose->regions + 1,
440                                 CFG_PCI1_MEM_BASE,
441                                 CFG_PCI1_MEM_PHYS,
442                                 CFG_PCI1_MEM_SIZE,
443                                 PCI_REGION_MEM);
444
445                 /* outbound io */
446                 pci_set_region(hose->regions + 2,
447                                 CFG_PCI1_IO_BASE,
448                                 CFG_PCI1_IO_PHYS,
449                                 CFG_PCI1_IO_SIZE,
450                                 PCI_REGION_IO);
451
452                 hose->region_count = 3;
453
454                 hose->first_busno = first_free_busno;
455                 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
456
457                 fsl_pci_init(hose);
458                 first_free_busno = hose->last_busno+1;
459                 printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
460         } else {
461         printf ("    PCI: disabled\n");
462         }
463 }
464 #else
465         gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
466 #endif
467
468 #ifdef CONFIG_PCIE1
469 {
470         volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
471         extern void fsl_pci_init(struct pci_controller *hose);
472         struct pci_controller *hose = &pcie1_hose;
473         int pcie_ep =  (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
474
475         int pcie_configured  = io_sel >= 1;
476
477         if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
478                 printf ("\n    PCIE connected to slot as %s (base address %x)",
479                         pcie_ep ? "End Point" : "Root Complex",
480                         (uint)pci);
481
482                 if (pci->pme_msg_det) {
483                         pci->pme_msg_det = 0xffffffff;
484                         debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
485                 }
486                 printf ("\n");
487
488                 /* inbound */
489                 pci_set_region(hose->regions + 0,
490                                 CFG_PCI_MEMORY_BUS,
491                                 CFG_PCI_MEMORY_PHYS,
492                                 CFG_PCI_MEMORY_SIZE,
493                                 PCI_REGION_MEM | PCI_REGION_MEMORY);
494
495                 /* outbound memory */
496                 pci_set_region(hose->regions + 1,
497                                 CFG_PCIE1_MEM_BASE,
498                                 CFG_PCIE1_MEM_PHYS,
499                                 CFG_PCIE1_MEM_SIZE,
500                                 PCI_REGION_MEM);
501
502                 /* outbound io */
503                 pci_set_region(hose->regions + 2,
504                                 CFG_PCIE1_IO_BASE,
505                                 CFG_PCIE1_IO_PHYS,
506                                 CFG_PCIE1_IO_SIZE,
507                                 PCI_REGION_IO);
508
509                 hose->region_count = 3;
510
511                 hose->first_busno=first_free_busno;
512                 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
513
514                 fsl_pci_init(hose);
515                 printf ("PCIE on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
516
517                 first_free_busno=hose->last_busno+1;
518
519         } else {
520                 printf ("    PCIE: disabled\n");
521         }
522 }
523 #else
524         gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
525 #endif
526 }
527 #endif /* CONFIG_PCI */
528
529 #if defined(CONFIG_OF_BOARD_SETUP)
530 void
531 ft_board_setup(void *blob, bd_t *bd)
532 {
533         int node, tmp[2];
534         const char *path;
535
536         ft_cpu_setup(blob, bd);
537
538         node = fdt_path_offset(blob, "/aliases");
539         tmp[0] = 0;
540         if (node >= 0) {
541 #ifdef CONFIG_PCI1
542                 path = fdt_getprop(blob, node, "pci0", NULL);
543                 if (path) {
544                         tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
545                         do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
546                 }
547 #endif
548 #ifdef CONFIG_PCIE1
549                 path = fdt_getprop(blob, node, "pci1", NULL);
550                 if (path) {
551                         tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
552                         do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
553                 }
554 #endif
555         }
556 }
557 #endif