pci.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright (C) Freescale Semiconductor, Inc. 2007
  3. *
  4. * Author: Scott Wood <scottwood@freescale.com>,
  5. * with some bits from older board-specific PCI initialization.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <pci.h>
  27. #if defined(CONFIG_OF_LIBFDT)
  28. #include <libfdt.h>
  29. #include <fdt_support.h>
  30. #endif
  31. #include <asm/mpc8349_pci.h>
  32. #define MAX_BUSES 2
  33. DECLARE_GLOBAL_DATA_PTR;
  34. static struct pci_controller pci_hose[MAX_BUSES];
  35. static int pci_num_buses;
  36. static void pci_init_bus(int bus, struct pci_region *reg)
  37. {
  38. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  39. volatile pot83xx_t *pot = immr->ios.pot;
  40. volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[bus];
  41. struct pci_controller *hose = &pci_hose[bus];
  42. u32 dev;
  43. u16 reg16;
  44. int i;
  45. if (bus == 1)
  46. pot += 3;
  47. /* Setup outbound translation windows */
  48. for (i = 0; i < 3; i++, reg++, pot++) {
  49. if (reg->size == 0)
  50. break;
  51. hose->regions[i] = *reg;
  52. hose->region_count++;
  53. pot->potar = reg->bus_start >> 12;
  54. pot->pobar = reg->phys_start >> 12;
  55. pot->pocmr = ~(reg->size - 1) >> 12;
  56. if (reg->flags & PCI_REGION_IO)
  57. pot->pocmr |= POCMR_IO;
  58. #ifdef CONFIG_83XX_PCI_STREAMING
  59. else if (reg->flags & PCI_REGION_PREFETCH)
  60. pot->pocmr |= POCMR_SE;
  61. #endif
  62. if (bus == 1)
  63. pot->pocmr |= POCMR_DST;
  64. pot->pocmr |= POCMR_EN;
  65. }
  66. /* Point inbound translation at RAM */
  67. pci_ctrl->pitar1 = 0;
  68. pci_ctrl->pibar1 = 0;
  69. pci_ctrl->piebar1 = 0;
  70. pci_ctrl->piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  71. PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size - 1));
  72. i = hose->region_count++;
  73. hose->regions[i].bus_start = 0;
  74. hose->regions[i].phys_start = 0;
  75. hose->regions[i].size = gd->ram_size;
  76. hose->regions[i].flags = PCI_REGION_MEM | PCI_REGION_MEMORY;
  77. hose->first_busno = 0;
  78. hose->last_busno = 0xff;
  79. pci_setup_indirect(hose, CONFIG_SYS_IMMR + 0x8300 + bus * 0x80,
  80. CONFIG_SYS_IMMR + 0x8304 + bus * 0x80);
  81. pci_register_hose(hose);
  82. /*
  83. * Write to Command register
  84. */
  85. reg16 = 0xff;
  86. dev = PCI_BDF(hose->first_busno, 0, 0);
  87. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
  88. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  89. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  90. /*
  91. * Clear non-reserved bits in status register.
  92. */
  93. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  94. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  95. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  96. #ifdef CONFIG_PCI_SCAN_SHOW
  97. printf("PCI: Bus Dev VenId DevId Class Int\n");
  98. #endif
  99. /*
  100. * Hose scan.
  101. */
  102. hose->last_busno = pci_hose_scan(hose);
  103. }
  104. /*
  105. * The caller must have already set OCCR, and the PCI_LAW BARs
  106. * must have been set to cover all of the requested regions.
  107. *
  108. * If fewer than three regions are requested, then the region
  109. * list is terminated with a region of size 0.
  110. */
  111. void mpc83xx_pci_init(int num_buses, struct pci_region **reg, int warmboot)
  112. {
  113. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  114. int i;
  115. if (num_buses > MAX_BUSES) {
  116. printf("%d PCI buses requsted, %d supported\n",
  117. num_buses, MAX_BUSES);
  118. num_buses = MAX_BUSES;
  119. }
  120. pci_num_buses = num_buses;
  121. /*
  122. * Release PCI RST Output signal.
  123. * Power on to RST high must be at least 100 ms as per PCI spec.
  124. * On warm boots only 1 ms is required.
  125. */
  126. udelay(warmboot ? 1000 : 100000);
  127. for (i = 0; i < num_buses; i++)
  128. immr->pci_ctrl[i].gcr = 1;
  129. /*
  130. * RST high to first config access must be at least 2^25 cycles
  131. * as per PCI spec. This could be cut in half if we know we're
  132. * running at 66MHz. This could be insufficiently long if we're
  133. * running the PCI bus at significantly less than 33MHz.
  134. */
  135. udelay(1020000);
  136. for (i = 0; i < num_buses; i++)
  137. pci_init_bus(i, reg[i]);
  138. }
  139. #ifdef CONFIG_PCISLAVE
  140. #define PCI_FUNCTION_CONFIG 0x44
  141. #define PCI_FUNCTION_CFG_LOCK 0x20
  142. /*
  143. * Unlock the configuration bit so that the host system can begin booting
  144. *
  145. * This should be used after you have:
  146. * 1) Called mpc83xx_pci_init()
  147. * 2) Set up your inbound translation windows to the appropriate size
  148. */
  149. void mpc83xx_pcislave_unlock(int bus)
  150. {
  151. struct pci_controller *hose = &pci_hose[bus];
  152. u32 dev;
  153. u16 reg16;
  154. /* Unlock configuration lock in PCI function configuration register */
  155. dev = PCI_BDF(hose->first_busno, 0, 0);
  156. pci_hose_read_config_word (hose, dev, PCI_FUNCTION_CONFIG, &reg16);
  157. reg16 &= ~(PCI_FUNCTION_CFG_LOCK);
  158. pci_hose_write_config_word (hose, dev, PCI_FUNCTION_CONFIG, reg16);
  159. }
  160. #endif
  161. #if defined(CONFIG_OF_LIBFDT)
  162. void ft_pci_setup(void *blob, bd_t *bd)
  163. {
  164. int nodeoffset;
  165. int tmp[2];
  166. const char *path;
  167. if (pci_num_buses < 1)
  168. return;
  169. nodeoffset = fdt_path_offset(blob, "/aliases");
  170. if (nodeoffset >= 0) {
  171. path = fdt_getprop(blob, nodeoffset, "pci0", NULL);
  172. if (path) {
  173. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  174. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  175. do_fixup_by_path(blob, path, "bus-range",
  176. &tmp, sizeof(tmp), 1);
  177. tmp[0] = cpu_to_be32(gd->pci_clk);
  178. do_fixup_by_path(blob, path, "clock-frequency",
  179. &tmp, sizeof(tmp[0]), 1);
  180. }
  181. if (pci_num_buses < 2)
  182. return;
  183. path = fdt_getprop(blob, nodeoffset, "pci1", NULL);
  184. if (path) {
  185. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  186. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  187. do_fixup_by_path(blob, path, "bus-range",
  188. &tmp, sizeof(tmp), 1);
  189. tmp[0] = cpu_to_be32(gd->pci_clk);
  190. do_fixup_by_path(blob, path, "clock-frequency",
  191. &tmp, sizeof(tmp[0]), 1);
  192. }
  193. }
  194. }
  195. #endif /* CONFIG_OF_LIBFDT */