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