pci.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2009 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <pci.h>
  25. #include <asm/immap_85xx.h>
  26. #include <asm/io.h>
  27. #include <asm/fsl_pci.h>
  28. #include <libfdt.h>
  29. #include <fdt_support.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. #ifdef CONFIG_PCIE1
  32. static struct pci_controller pcie1_hose;
  33. #endif
  34. #ifdef CONFIG_PCIE2
  35. static struct pci_controller pcie2_hose;
  36. #endif
  37. void pci_init_board(void)
  38. {
  39. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  40. struct fsl_pci_info pci_info[2];
  41. u32 devdisr, pordevsr, io_sel, host_agent;
  42. int first_free_busno = 0;
  43. int num = 0;
  44. int pcie_ep, pcie_configured;
  45. devdisr = in_be32(&gur->devdisr);
  46. pordevsr = in_be32(&gur->pordevsr);
  47. io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  48. host_agent = (in_be32(&gur->porbmsr) & MPC85xx_PORBMSR_HA) >> 16;
  49. debug (" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  50. devdisr, io_sel, host_agent);
  51. if (!(pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
  52. printf (" eTSEC2 is in sgmii mode.\n");
  53. puts("\n");
  54. #ifdef CONFIG_PCIE2
  55. pcie_ep = is_fsl_pci_agent(LAW_TRGT_IF_PCIE_2, host_agent);
  56. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_2, io_sel);
  57. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  58. SET_STD_PCIE_INFO(pci_info[num], 2);
  59. printf(" PCIE2 connected to Slot 1 as %s (base addr %lx)\n",
  60. pcie_ep ? "End Point" : "Root Complex",
  61. pci_info[num].regs);
  62. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  63. &pcie2_hose, first_free_busno);
  64. } else {
  65. printf (" PCIE2: disabled\n");
  66. }
  67. puts("\n");
  68. #else
  69. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE2); /* disable */
  70. #endif
  71. #ifdef CONFIG_PCIE1
  72. pcie_ep = is_fsl_pci_agent(LAW_TRGT_IF_PCIE_1, host_agent);
  73. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
  74. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  75. SET_STD_PCIE_INFO(pci_info[num], 1);
  76. printf(" PCIE1 connected to Slot 2 as %s (base addr %lx)\n",
  77. pcie_ep ? "End Point" : "Root Complex",
  78. pci_info[num].regs);
  79. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  80. &pcie1_hose, first_free_busno);
  81. } else {
  82. printf (" PCIE1: disabled\n");
  83. }
  84. puts("\n");
  85. #else
  86. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
  87. #endif
  88. }
  89. void ft_pci_board_setup(void *blob)
  90. {
  91. /* According to h/w manual, PCIE2 is at lower address(0x9000)
  92. * than PCIE1(0xa000).
  93. * Hence PCIE2 is made to occupy the pci1 position in dts to
  94. * keep the addresses sorted there.
  95. * Generally the case with all FSL SOCs.
  96. */
  97. #ifdef CONFIG_PCIE2
  98. ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
  99. #endif
  100. #ifdef CONFIG_PCIE1
  101. ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
  102. #endif
  103. }