pci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
  4. */
  5. /*
  6. * PCI Configuration space access support for MPC83xx PCI Bridge
  7. */
  8. #include <asm/mmu.h>
  9. #include <asm/io.h>
  10. #include <common.h>
  11. #include <mpc83xx.h>
  12. #include <pci.h>
  13. #include <i2c.h>
  14. #include <asm/fsl_i2c.h>
  15. #include "../common/pq-mds-pib.h"
  16. static struct pci_region pci1_regions[] = {
  17. {
  18. bus_start: CONFIG_SYS_PCI1_MEM_BASE,
  19. phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
  20. size: CONFIG_SYS_PCI1_MEM_SIZE,
  21. flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
  22. },
  23. {
  24. bus_start: CONFIG_SYS_PCI1_IO_BASE,
  25. phys_start: CONFIG_SYS_PCI1_IO_PHYS,
  26. size: CONFIG_SYS_PCI1_IO_SIZE,
  27. flags: PCI_REGION_IO
  28. },
  29. {
  30. bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
  31. phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
  32. size: CONFIG_SYS_PCI1_MMIO_SIZE,
  33. flags: PCI_REGION_MEM
  34. },
  35. };
  36. #ifdef CONFIG_MPC83XX_PCI2
  37. static struct pci_region pci2_regions[] = {
  38. {
  39. bus_start: CONFIG_SYS_PCI2_MEM_BASE,
  40. phys_start: CONFIG_SYS_PCI2_MEM_PHYS,
  41. size: CONFIG_SYS_PCI2_MEM_SIZE,
  42. flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
  43. },
  44. {
  45. bus_start: CONFIG_SYS_PCI2_IO_BASE,
  46. phys_start: CONFIG_SYS_PCI2_IO_PHYS,
  47. size: CONFIG_SYS_PCI2_IO_SIZE,
  48. flags: PCI_REGION_IO
  49. },
  50. {
  51. bus_start: CONFIG_SYS_PCI2_MMIO_BASE,
  52. phys_start: CONFIG_SYS_PCI2_MMIO_PHYS,
  53. size: CONFIG_SYS_PCI2_MMIO_SIZE,
  54. flags: PCI_REGION_MEM
  55. },
  56. };
  57. #endif
  58. void pci_init_board(void)
  59. #ifdef CONFIG_PCISLAVE
  60. {
  61. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  62. volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
  63. volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[0];
  64. struct pci_region *reg[] = { pci1_regions };
  65. /* Configure PCI Local Access Windows */
  66. pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
  67. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  68. pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
  69. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
  70. mpc83xx_pci_init(1, reg);
  71. /*
  72. * Configure PCI Inbound Translation Windows
  73. */
  74. pci_ctrl[0].pitar0 = 0x0;
  75. pci_ctrl[0].pibar0 = 0x0;
  76. pci_ctrl[0].piwar0 = PIWAR_EN | PIWAR_RTT_SNOOP |
  77. PIWAR_WTT_SNOOP | PIWAR_IWS_4K;
  78. pci_ctrl[0].pitar1 = 0x0;
  79. pci_ctrl[0].pibar1 = 0x0;
  80. pci_ctrl[0].piebar1 = 0x0;
  81. pci_ctrl[0].piwar1 &= ~PIWAR_EN;
  82. pci_ctrl[0].pitar2 = 0x0;
  83. pci_ctrl[0].pibar2 = 0x0;
  84. pci_ctrl[0].piebar2 = 0x0;
  85. pci_ctrl[0].piwar2 &= ~PIWAR_EN;
  86. /* Unlock the configuration bit */
  87. mpc83xx_pcislave_unlock(0);
  88. printf("PCI: Agent mode enabled\n");
  89. }
  90. #else
  91. {
  92. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  93. volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
  94. volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
  95. #ifndef CONFIG_MPC83XX_PCI2
  96. struct pci_region *reg[] = { pci1_regions };
  97. #else
  98. struct pci_region *reg[] = { pci1_regions, pci2_regions };
  99. #endif
  100. /* initialize the PCA9555PW IO expander on the PIB board */
  101. pib_init();
  102. #if defined(CONFIG_PCI_66M)
  103. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
  104. printf("PCI clock is 66MHz\n");
  105. #elif defined(CONFIG_PCI_33M)
  106. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2 |
  107. OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 | OCCR_PCICR;
  108. printf("PCI clock is 33MHz\n");
  109. #else
  110. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
  111. printf("PCI clock is 66MHz\n");
  112. #endif
  113. udelay(2000);
  114. /* Configure PCI Local Access Windows */
  115. pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
  116. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
  117. pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
  118. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_1M;
  119. udelay(2000);
  120. #ifndef CONFIG_MPC83XX_PCI2
  121. mpc83xx_pci_init(1, reg);
  122. #else
  123. mpc83xx_pci_init(2, reg);
  124. #endif
  125. }
  126. #endif /* CONFIG_PCISLAVE */