pci.c 5.9 KB

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