Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 1 | /* |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 2 | * Copyright (C) 2006-2009 Freescale Semiconductor, Inc. |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 9 | #include <asm/mmu.h> |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <mpc83xx.h> |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 12 | #include <pci.h> |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 13 | #include <i2c.h> |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 14 | #include <asm/fsl_i2c.h> |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 18 | static struct pci_region pci1_regions[] = { |
| 19 | { |
| 20 | bus_start: CONFIG_SYS_PCI1_MEM_BASE, |
| 21 | phys_start: CONFIG_SYS_PCI1_MEM_PHYS, |
| 22 | size: CONFIG_SYS_PCI1_MEM_SIZE, |
| 23 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 24 | }, |
| 25 | { |
| 26 | bus_start: CONFIG_SYS_PCI1_IO_BASE, |
| 27 | phys_start: CONFIG_SYS_PCI1_IO_PHYS, |
| 28 | size: CONFIG_SYS_PCI1_IO_SIZE, |
| 29 | flags: PCI_REGION_IO |
| 30 | }, |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 31 | { |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 32 | bus_start: CONFIG_SYS_PCI1_MMIO_BASE, |
| 33 | phys_start: CONFIG_SYS_PCI1_MMIO_PHYS, |
| 34 | size: CONFIG_SYS_PCI1_MMIO_SIZE, |
| 35 | flags: PCI_REGION_MEM |
| 36 | }, |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 37 | }; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 38 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 39 | #ifdef CONFIG_MPC83XX_PCI2 |
| 40 | static struct pci_region pci2_regions[] = { |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 41 | { |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 42 | bus_start: CONFIG_SYS_PCI2_MEM_BASE, |
| 43 | phys_start: CONFIG_SYS_PCI2_MEM_PHYS, |
| 44 | size: CONFIG_SYS_PCI2_MEM_SIZE, |
| 45 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 46 | }, |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 47 | { |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 48 | bus_start: CONFIG_SYS_PCI2_IO_BASE, |
| 49 | phys_start: CONFIG_SYS_PCI2_IO_PHYS, |
| 50 | size: CONFIG_SYS_PCI2_IO_SIZE, |
| 51 | flags: PCI_REGION_IO |
| 52 | }, |
| 53 | { |
| 54 | bus_start: CONFIG_SYS_PCI2_MMIO_BASE, |
| 55 | phys_start: CONFIG_SYS_PCI2_MMIO_PHYS, |
| 56 | size: CONFIG_SYS_PCI2_MMIO_SIZE, |
| 57 | flags: PCI_REGION_MEM |
| 58 | }, |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 59 | }; |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 60 | #endif |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 61 | |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 62 | void pci_init_board(void) |
| 63 | { |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 64 | volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; |
| 65 | volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; |
| 66 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
| 67 | #ifndef CONFIG_MPC83XX_PCI2 |
| 68 | struct pci_region *reg[] = { pci1_regions }; |
| 69 | #else |
| 70 | struct pci_region *reg[] = { pci1_regions, pci2_regions }; |
| 71 | #endif |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 72 | u8 reg8; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 73 | |
Heiko Schocher | f285074 | 2012-10-24 13:48:22 +0200 | [diff] [blame] | 74 | #if defined(CONFIG_SYS_I2C) |
Timur Tabi | ab34754 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 75 | i2c_set_bus_num(1); |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 76 | /* Read the PCI_M66EN jumper setting */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 77 | if ((i2c_read(CONFIG_SYS_I2C_8574_ADDR2, 0, 0, ®8, sizeof(reg8)) == 0) || |
| 78 | (i2c_read(CONFIG_SYS_I2C_8574A_ADDR2, 0, 0, ®8, sizeof(reg8)) == 0)) { |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 79 | if (reg8 & I2C_8574_PCI66) |
| 80 | clk->occr = 0xff000000; /* 66 MHz PCI */ |
| 81 | else |
| 82 | clk->occr = 0xff600001; /* 33 MHz PCI */ |
| 83 | } else { |
| 84 | clk->occr = 0xff600001; /* 33 MHz PCI */ |
| 85 | } |
| 86 | #else |
| 87 | clk->occr = 0xff000000; /* 66 MHz PCI */ |
| 88 | #endif |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 89 | udelay(2000); |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 90 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 91 | /* Configure PCI Local Access Windows */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 93 | pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G; |
| 94 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR; |
Timur Tabi | e9b04f0 | 2006-10-31 19:14:41 -0600 | [diff] [blame] | 96 | pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_32M; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 97 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 98 | udelay(2000); |
Kim Phillips | 2141681 | 2007-08-15 22:30:33 -0500 | [diff] [blame] | 99 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 100 | #ifndef CONFIG_MPC83XX_PCI2 |
Peter Tyser | e228332 | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 101 | mpc83xx_pci_init(1, reg); |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 102 | #else |
Peter Tyser | e228332 | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 103 | mpc83xx_pci_init(2, reg); |
Kim Phillips | 2141681 | 2007-08-15 22:30:33 -0500 | [diff] [blame] | 104 | #endif |
Kim Phillips | 774e1b5 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 105 | } |