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