pci.c 3.6 KB

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