pci.c 4.0 KB

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