Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Extreme Engineering Solutions, Inc. |
| 3 | * Copyright 2007-2008 Freescale Semiconductor, Inc. |
| 4 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <pci.h> |
Kumar Gala | c851462 | 2009-04-02 13:22:48 -0500 | [diff] [blame] | 10 | #include <asm/fsl_pci.h> |
Kumar Gala | 5d27e02 | 2010-12-15 04:55:20 -0600 | [diff] [blame] | 11 | #include <asm/fsl_serdes.h> |
Peter Tyser | 1bb61b6 | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 12 | #include <asm/io.h> |
Peter Tyser | 9660c5d | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 13 | #include <linux/compiler.h> |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 14 | #include <libfdt.h> |
| 15 | #include <fdt_support.h> |
| 16 | |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 17 | |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 18 | #ifdef CONFIG_PCI1 |
| 19 | static struct pci_controller pci1_hose; |
| 20 | #endif |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 21 | |
| 22 | void pci_init_board(void) |
| 23 | { |
Peter Tyser | 9660c5d | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 24 | int first_free_busno = 0; |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 25 | |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 26 | #ifdef CONFIG_PCI1 |
Kumar Gala | 6635709 | 2010-12-17 10:23:03 -0600 | [diff] [blame] | 27 | int pcie_ep; |
| 28 | struct fsl_pci_info pci_info; |
| 29 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 30 | u32 devdisr = in_be32(&gur->devdisr); |
Peter Tyser | 1bb61b6 | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 31 | uint pci_spd_norm = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_SPD; |
| 32 | uint pci_32 = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_PCI32; |
| 33 | uint pci_arb = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_ARB; |
| 34 | uint pcix = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1; |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 35 | uint freq = CONFIG_SYS_CLK_FREQ / 1000 / 1000; |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 36 | |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 37 | if (!(devdisr & MPC85xx_DEVDISR_PCI1)) { |
Kumar Gala | 6635709 | 2010-12-17 10:23:03 -0600 | [diff] [blame] | 38 | SET_STD_PCI_INFO(pci_info, 1); |
| 39 | set_next_law(pci_info.mem_phys, |
| 40 | law_size_bits(pci_info.mem_size), pci_info.law); |
| 41 | set_next_law(pci_info.io_phys, |
| 42 | law_size_bits(pci_info.io_size), pci_info.law); |
| 43 | |
| 44 | pcie_ep = fsl_setup_hose(&pci1_hose, pci_info.regs); |
Peter Tyser | 8ca78f2 | 2010-10-29 17:59:24 -0500 | [diff] [blame] | 45 | printf("PCI1: %d bit %s, %s %d MHz, %s, %s\n", |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 46 | pci_32 ? 32 : 64, |
| 47 | pcix ? "PCIX" : "PCI", |
Peter Tyser | 1bb61b6 | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 48 | pci_spd_norm ? ">=" : "<=", |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 49 | pcix ? freq * 2 : freq, |
Peter Tyser | 9660c5d | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 50 | pcie_ep ? "agent" : "host", |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 51 | pci_arb ? "arbiter" : "external-arbiter"); |
| 52 | |
Kumar Gala | 6635709 | 2010-12-17 10:23:03 -0600 | [diff] [blame] | 53 | first_free_busno = fsl_pci_init_port(&pci_info, |
Peter Tyser | 9660c5d | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 54 | &pci1_hose, first_free_busno); |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 55 | } else { |
Peter Tyser | 8ca78f2 | 2010-10-29 17:59:24 -0500 | [diff] [blame] | 56 | printf("PCI1: disabled\n"); |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 57 | } |
| 58 | #elif defined CONFIG_MPC8548 |
Kumar Gala | 6635709 | 2010-12-17 10:23:03 -0600 | [diff] [blame] | 59 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 60 | /* PCI1 not present on MPC8572 */ |
Peter Tyser | 1bb61b6 | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 61 | setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); |
Peter Tyser | 78bbc5c | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 62 | #endif |
Peter Tyser | 9660c5d | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 63 | |
Kumar Gala | 6635709 | 2010-12-17 10:23:03 -0600 | [diff] [blame] | 64 | fsl_pcie_init_board(first_free_busno); |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | #if defined(CONFIG_OF_BOARD_SETUP) |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 68 | void ft_board_pci_setup(void *blob, bd_t *bd) |
| 69 | { |
Kumar Gala | 6525d51 | 2010-07-08 22:37:44 -0500 | [diff] [blame] | 70 | FT_FSL_PCI_SETUP; |
Peter Tyser | ccf0fdd | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 71 | } |
| 72 | #endif /* CONFIG_OF_BOARD_SETUP */ |