pci.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (C) Freescale Semiconductor, Inc. 2006, 2007. All rights reserved.
  3. * Copyright (C) 2009 DENX Software Engineering <wd@denx.de>
  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. volatile pciconf512x_t *pci_conf;
  49. u16 reg16;
  50. u32 reg32;
  51. u32 dev;
  52. int i;
  53. struct pci_controller *hose;
  54. /* Set PCI divider for 33MHz */
  55. reg32 = im->clk.scfr[0];
  56. reg32 &= ~(SCFR1_PCI_DIV_MASK);
  57. reg32 |= SCFR1_PCI_DIV << SCFR1_PCI_DIV_SHIFT;
  58. im->clk.scfr[0] = reg32;
  59. clrsetbits_be32(&im->clk.scfr[0],
  60. SCFR1_PCI_DIV_MASK,
  61. SCFR1_PCI_DIV << SCFR1_PCI_DIV_SHIFT
  62. );
  63. pci_law = im->sysconf.pcilaw;
  64. pci_pot = im->ios.pot;
  65. pci_ctrl = &im->pci_ctrl;
  66. pci_conf = &im->pci_conf;
  67. hose = &pci_hose;
  68. /*
  69. * Release PCI RST Output signal
  70. */
  71. out_be32(&pci_ctrl->gcr, 0);
  72. udelay(2000);
  73. out_be32(&pci_ctrl->gcr, 1);
  74. /* We need to wait at least a 1sec based on PCI specs */
  75. for (i = 0; i < 1000; i++)
  76. udelay(1000);
  77. /*
  78. * Configure PCI Local Access Windows
  79. */
  80. out_be32(&pci_law[0].bar, CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR);
  81. out_be32(&pci_law[0].ar, LAWAR_EN | LAWAR_SIZE_512M);
  82. out_be32(&pci_law[1].bar, CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR);
  83. out_be32(&pci_law[1].ar, LAWAR_EN | LAWAR_SIZE_16M);
  84. /*
  85. * Configure PCI Outbound Translation Windows
  86. */
  87. /* PCI mem space - prefetch */
  88. out_be32(&pci_pot[0].potar,
  89. (CONFIG_SYS_PCI_MEM_BASE >> 12) & POTAR_TA_MASK);
  90. out_be32(&pci_pot[0].pobar,
  91. (CONFIG_SYS_PCI_MEM_PHYS >> 12) & POBAR_BA_MASK);
  92. out_be32(&pci_pot[0].pocmr,
  93. POCMR_EN | POCMR_PRE | POCMR_CM_256M);
  94. /* PCI IO space */
  95. out_be32(&pci_pot[1].potar,
  96. (CONFIG_SYS_PCI_IO_BASE >> 12) & POTAR_TA_MASK);
  97. out_be32(&pci_pot[1].pobar,
  98. (CONFIG_SYS_PCI_IO_PHYS >> 12) & POBAR_BA_MASK);
  99. out_be32(&pci_pot[1].pocmr,
  100. POCMR_EN | POCMR_IO | POCMR_CM_16M);
  101. /* PCI mmio - non-prefetch mem space */
  102. out_be32(&pci_pot[2].potar,
  103. (CONFIG_SYS_PCI_MMIO_BASE >> 12) & POTAR_TA_MASK);
  104. out_be32(&pci_pot[2].pobar,
  105. (CONFIG_SYS_PCI_MMIO_PHYS >> 12) & POBAR_BA_MASK);
  106. out_be32(&pci_pot[2].pocmr,
  107. POCMR_EN | POCMR_CM_256M);
  108. /*
  109. * Configure PCI Inbound Translation Windows
  110. */
  111. /* we need RAM mapped to PCI space for the devices to
  112. * access main memory */
  113. out_be32(&pci_ctrl[0].pitar1, 0x0);
  114. out_be32(&pci_ctrl[0].pibar1, 0x0);
  115. out_be32(&pci_ctrl[0].piebar1, 0x0);
  116. out_be32(&pci_ctrl[0].piwar1,
  117. PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  118. PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1));
  119. hose->first_busno = 0;
  120. hose->last_busno = 0xff;
  121. /* PCI memory prefetch space */
  122. pci_set_region(hose->regions + 0,
  123. CONFIG_SYS_PCI_MEM_BASE,
  124. CONFIG_SYS_PCI_MEM_PHYS,
  125. CONFIG_SYS_PCI_MEM_SIZE,
  126. PCI_REGION_MEM|PCI_REGION_PREFETCH);
  127. /* PCI memory space */
  128. pci_set_region(hose->regions + 1,
  129. CONFIG_SYS_PCI_MMIO_BASE,
  130. CONFIG_SYS_PCI_MMIO_PHYS,
  131. CONFIG_SYS_PCI_MMIO_SIZE,
  132. PCI_REGION_MEM);
  133. /* PCI IO space */
  134. pci_set_region(hose->regions + 2,
  135. CONFIG_SYS_PCI_IO_BASE,
  136. CONFIG_SYS_PCI_IO_PHYS,
  137. CONFIG_SYS_PCI_IO_SIZE,
  138. PCI_REGION_IO);
  139. /* System memory space */
  140. pci_set_region(hose->regions + 3,
  141. CONFIG_PCI_SYS_MEM_BUS,
  142. CONFIG_PCI_SYS_MEM_PHYS,
  143. gd->ram_size,
  144. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  145. hose->region_count = 4;
  146. pci_setup_indirect(hose,
  147. (CONFIG_SYS_IMMR + 0x8300),
  148. (CONFIG_SYS_IMMR + 0x8304));
  149. pci_register_hose(hose);
  150. /*
  151. * Write to Command register
  152. */
  153. reg16 = 0xff;
  154. dev = PCI_BDF(hose->first_busno, 0, 0);
  155. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
  156. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  157. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  158. /*
  159. * Clear non-reserved bits in status register.
  160. */
  161. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  162. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  163. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  164. #ifdef CONFIG_PCI_SCAN_SHOW
  165. printf("PCI: Bus Dev VenId DevId Class Int\n");
  166. #endif
  167. /*
  168. * Hose scan.
  169. */
  170. hose->last_busno = pci_hose_scan(hose);
  171. }
  172. #if defined(CONFIG_OF_LIBFDT)
  173. void ft_pci_setup(void *blob, bd_t *bd)
  174. {
  175. int nodeoffset;
  176. int tmp[2];
  177. const char *path;
  178. nodeoffset = fdt_path_offset(blob, "/aliases");
  179. if (nodeoffset >= 0) {
  180. path = fdt_getprop(blob, nodeoffset, "pci", NULL);
  181. if (path) {
  182. tmp[0] = cpu_to_be32(pci_hose.first_busno);
  183. tmp[1] = cpu_to_be32(pci_hose.last_busno);
  184. do_fixup_by_path(blob, path, "bus-range",
  185. &tmp, sizeof(tmp), 1);
  186. tmp[0] = cpu_to_be32(gd->pci_clk);
  187. do_fixup_by_path(blob, path, "clock-frequency",
  188. &tmp, sizeof(tmp[0]), 1);
  189. }
  190. }
  191. }
  192. #endif /* CONFIG_OF_LIBFDT */