pci.c 3.9 KB

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