pci.c 3.7 KB

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