pci.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <asm/mmu.h>
  7. #include <asm/io.h>
  8. #include <common.h>
  9. #include <mpc83xx.h>
  10. #include <pci.h>
  11. #include <i2c.h>
  12. #include <fdt_support.h>
  13. #include <asm/fsl_i2c.h>
  14. #include <asm/fsl_mpc83xx_serdes.h>
  15. static struct pci_region pci_regions[] = {
  16. {
  17. bus_start: CONFIG_SYS_PCI_MEM_BASE,
  18. phys_start: CONFIG_SYS_PCI_MEM_PHYS,
  19. size: CONFIG_SYS_PCI_MEM_SIZE,
  20. flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
  21. },
  22. {
  23. bus_start: CONFIG_SYS_PCI_MMIO_BASE,
  24. phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
  25. size: CONFIG_SYS_PCI_MMIO_SIZE,
  26. flags: PCI_REGION_MEM
  27. },
  28. {
  29. bus_start: CONFIG_SYS_PCI_IO_BASE,
  30. phys_start: CONFIG_SYS_PCI_IO_PHYS,
  31. size: CONFIG_SYS_PCI_IO_SIZE,
  32. flags: PCI_REGION_IO
  33. }
  34. };
  35. static struct pci_region pcie_regions_0[] = {
  36. {
  37. .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
  38. .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
  39. .size = CONFIG_SYS_PCIE1_MEM_SIZE,
  40. .flags = PCI_REGION_MEM,
  41. },
  42. {
  43. .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
  44. .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
  45. .size = CONFIG_SYS_PCIE1_IO_SIZE,
  46. .flags = PCI_REGION_IO,
  47. },
  48. };
  49. static struct pci_region pcie_regions_1[] = {
  50. {
  51. .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
  52. .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
  53. .size = CONFIG_SYS_PCIE2_MEM_SIZE,
  54. .flags = PCI_REGION_MEM,
  55. },
  56. {
  57. .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
  58. .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
  59. .size = CONFIG_SYS_PCIE2_IO_SIZE,
  60. .flags = PCI_REGION_IO,
  61. },
  62. };
  63. static int is_pex_x2(void)
  64. {
  65. const char *pex_x2 = getenv("pex_x2");
  66. if (pex_x2 && !strcmp(pex_x2, "yes"))
  67. return 1;
  68. return 0;
  69. }
  70. void pci_init_board(void)
  71. {
  72. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  73. volatile sysconf83xx_t *sysconf = &immr->sysconf;
  74. volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
  75. volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
  76. volatile law83xx_t *pcie_law = sysconf->pcielaw;
  77. struct pci_region *reg[] = { pci_regions };
  78. struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
  79. u32 spridr = in_be32(&immr->sysconf.spridr);
  80. int pex2 = is_pex_x2();
  81. if (board_pci_host_broken())
  82. goto skip_pci;
  83. /* Enable all 5 PCI_CLK_OUTPUTS */
  84. clk->occr |= 0xf8000000;
  85. udelay(2000);
  86. /* Configure PCI Local Access Windows */
  87. pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
  88. pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
  89. pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
  90. pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
  91. udelay(2000);
  92. mpc83xx_pci_init(1, reg);
  93. skip_pci:
  94. /* There is no PEX in MPC8379 parts. */
  95. if (PARTID_NO_E(spridr) == SPR_8379)
  96. return;
  97. if (pex2)
  98. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX_X2,
  99. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  100. else
  101. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
  102. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  103. /* Configure the clock for PCIE controller */
  104. clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
  105. SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
  106. /* Deassert the resets in the control register */
  107. out_be32(&sysconf->pecr1, 0xE0008000);
  108. if (!pex2)
  109. out_be32(&sysconf->pecr2, 0xE0008000);
  110. udelay(2000);
  111. /* Configure PCI Express Local Access Windows */
  112. out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
  113. out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
  114. out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
  115. out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
  116. mpc83xx_pcie_init(pex2 ? 1 : 2, pcie_reg);
  117. }
  118. void ft_pcie_fixup(void *blob, bd_t *bd)
  119. {
  120. const char *status = "disabled (PCIE1 is x2)";
  121. if (!is_pex_x2())
  122. return;
  123. do_fixup_by_path(blob, "pci2", "status", status,
  124. strlen(status) + 1, 1);
  125. }