pci.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (C) Freescale Semiconductor, Inc. 2006, 2007. All rights reserved.
  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. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <asm/mmu.h>
  24. #include <asm/global_data.h>
  25. #include <pci.h>
  26. #if defined(CONFIG_OF_LIBFDT)
  27. #include <libfdt.h>
  28. #include <fdt_support.h>
  29. #endif
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /* System RAM mapped to PCI space */
  32. #define CONFIG_PCI_SYS_MEM_BUS CONFIG_SYS_SDRAM_BASE
  33. #define CONFIG_PCI_SYS_MEM_PHYS CONFIG_SYS_SDRAM_BASE
  34. static struct pci_controller pci_hose;
  35. /**************************************************************************
  36. * pci_init_board()
  37. *
  38. */
  39. void
  40. pci_init_board(void)
  41. {
  42. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  43. volatile law512x_t *pci_law;
  44. volatile pot512x_t *pci_pot;
  45. volatile pcictrl512x_t *pci_ctrl;
  46. volatile pciconf512x_t *pci_conf;
  47. u16 reg16;
  48. u32 reg32;
  49. u32 dev;
  50. struct pci_controller *hose;
  51. /* Set PCI divider for 33MHz */
  52. reg32 = immr->clk.scfr[0];
  53. reg32 &= ~(SCFR1_PCI_DIV_MASK);
  54. reg32 |= SCFR1_PCI_DIV << SCFR1_PCI_DIV_SHIFT;
  55. immr->clk.scfr[0] = reg32;
  56. pci_law = immr->sysconf.pcilaw;
  57. pci_pot = immr->ios.pot;
  58. pci_ctrl = &immr->pci_ctrl;
  59. pci_conf = &immr->pci_conf;
  60. hose = &pci_hose;
  61. /*
  62. * Release PCI RST Output signal
  63. */
  64. pci_ctrl->gcr = 0;
  65. udelay(2000);
  66. pci_ctrl->gcr = 1;
  67. /* We need to wait at least a 1sec based on PCI specs */
  68. {
  69. int i;
  70. for (i = 0; i < 1000; i++)
  71. udelay(1000);
  72. }
  73. /*
  74. * Configure PCI Local Access Windows
  75. */
  76. pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
  77. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
  78. pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
  79. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_16M;
  80. /*
  81. * Configure PCI Outbound Translation Windows
  82. */
  83. /* PCI mem space - prefetch */
  84. pci_pot[0].potar = (CONFIG_SYS_PCI_MEM_BASE >> 12) & POTAR_TA_MASK;
  85. pci_pot[0].pobar = (CONFIG_SYS_PCI_MEM_PHYS >> 12) & POBAR_BA_MASK;
  86. pci_pot[0].pocmr = POCMR_EN | POCMR_PRE | POCMR_CM_256M;
  87. /* PCI IO space */
  88. pci_pot[1].potar = (CONFIG_SYS_PCI_IO_BASE >> 12) & POTAR_TA_MASK;
  89. pci_pot[1].pobar = (CONFIG_SYS_PCI_IO_PHYS >> 12) & POBAR_BA_MASK;
  90. pci_pot[1].pocmr = POCMR_EN | POCMR_IO | POCMR_CM_16M;
  91. /* PCI mmio - non-prefetch mem space */
  92. pci_pot[2].potar = (CONFIG_SYS_PCI_MMIO_BASE >> 12) & POTAR_TA_MASK;
  93. pci_pot[2].pobar = (CONFIG_SYS_PCI_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  94. pci_pot[2].pocmr = POCMR_EN | POCMR_CM_256M;
  95. /*
  96. * Configure PCI Inbound Translation Windows
  97. */
  98. /* we need RAM mapped to PCI space for the devices to
  99. * access main memory */
  100. pci_ctrl[0].pitar1 = 0x0;
  101. pci_ctrl[0].pibar1 = 0x0;
  102. pci_ctrl[0].piebar1 = 0x0;
  103. pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  104. PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
  105. hose->first_busno = 0;
  106. hose->last_busno = 0xff;
  107. /* PCI memory prefetch space */
  108. pci_set_region(hose->regions + 0,
  109. CONFIG_SYS_PCI_MEM_BASE,
  110. CONFIG_SYS_PCI_MEM_PHYS,
  111. CONFIG_SYS_PCI_MEM_SIZE,
  112. PCI_REGION_MEM|PCI_REGION_PREFETCH);
  113. /* PCI memory space */
  114. pci_set_region(hose->regions + 1,
  115. CONFIG_SYS_PCI_MMIO_BASE,
  116. CONFIG_SYS_PCI_MMIO_PHYS,
  117. CONFIG_SYS_PCI_MMIO_SIZE,
  118. PCI_REGION_MEM);
  119. /* PCI IO space */
  120. pci_set_region(hose->regions + 2,
  121. CONFIG_SYS_PCI_IO_BASE,
  122. CONFIG_SYS_PCI_IO_PHYS,
  123. CONFIG_SYS_PCI_IO_SIZE,
  124. PCI_REGION_IO);
  125. /* System memory space */
  126. pci_set_region(hose->regions + 3,
  127. CONFIG_PCI_SYS_MEM_BUS,
  128. CONFIG_PCI_SYS_MEM_PHYS,
  129. gd->ram_size,
  130. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  131. hose->region_count = 4;
  132. pci_setup_indirect(hose,
  133. (CONFIG_SYS_IMMR + 0x8300),
  134. (CONFIG_SYS_IMMR + 0x8304));
  135. pci_register_hose(hose);
  136. /*
  137. * Write to Command register
  138. */
  139. reg16 = 0xff;
  140. dev = PCI_BDF(hose->first_busno, 0, 0);
  141. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
  142. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  143. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  144. /*
  145. * Clear non-reserved bits in status register.
  146. */
  147. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  148. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  149. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  150. #ifdef CONFIG_PCI_SCAN_SHOW
  151. printf("PCI: Bus Dev VenId DevId Class Int\n");
  152. #endif
  153. /*
  154. * Hose scan.
  155. */
  156. hose->last_busno = pci_hose_scan(hose);
  157. }
  158. #if defined(CONFIG_OF_LIBFDT)
  159. void ft_pci_setup(void *blob, bd_t *bd)
  160. {
  161. int nodeoffset;
  162. int tmp[2];
  163. const char *path;
  164. nodeoffset = fdt_path_offset(blob, "/aliases");
  165. if (nodeoffset >= 0) {
  166. path = fdt_getprop(blob, nodeoffset, "pci", NULL);
  167. if (path) {
  168. tmp[0] = cpu_to_be32(pci_hose.first_busno);
  169. tmp[1] = cpu_to_be32(pci_hose.last_busno);
  170. do_fixup_by_path(blob, path, "bus-range",
  171. &tmp, sizeof(tmp), 1);
  172. tmp[0] = cpu_to_be32(gd->pci_clk);
  173. do_fixup_by_path(blob, path, "clock-frequency",
  174. &tmp, sizeof(tmp[0]), 1);
  175. }
  176. }
  177. }
  178. #endif /* CONFIG_OF_LIBFDT */