pci.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 <libfdt_env.h>
  30. #elif defined(CONFIG_OF_FLAT_TREE)
  31. #include <ft_build.h>
  32. #endif
  33. #include <asm/mpc8349_pci.h>
  34. #ifdef CONFIG_83XX_GENERIC_PCI
  35. #define MAX_BUSES 2
  36. DECLARE_GLOBAL_DATA_PTR;
  37. static struct pci_controller pci_hose[MAX_BUSES];
  38. static int pci_num_buses;
  39. static void pci_init_bus(int bus, struct pci_region *reg)
  40. {
  41. volatile immap_t *immr = (volatile immap_t *)CFG_IMMR;
  42. volatile pot83xx_t *pot = immr->ios.pot;
  43. volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[bus];
  44. struct pci_controller *hose = &pci_hose[bus];
  45. u32 dev;
  46. u16 reg16;
  47. int i;
  48. if (bus == 1)
  49. pot += 3;
  50. /* Setup outbound translation windows */
  51. for (i = 0; i < 3; i++, reg++, pot++) {
  52. if (reg->size == 0)
  53. break;
  54. hose->regions[i] = *reg;
  55. hose->region_count++;
  56. pot->potar = reg->bus_start >> 12;
  57. pot->pobar = reg->phys_start >> 12;
  58. pot->pocmr = ~(reg->size - 1) >> 12;
  59. if (reg->flags & PCI_REGION_IO)
  60. pot->pocmr |= POCMR_IO;
  61. #ifdef CONFIG_83XX_PCI_STREAMING
  62. else if (reg->flags & PCI_REGION_PREFETCH)
  63. pot->pocmr |= POCMR_SE;
  64. #endif
  65. if (bus == 1)
  66. pot->pocmr |= POCMR_DST;
  67. pot->pocmr |= POCMR_EN;
  68. }
  69. /* Point inbound translation at RAM */
  70. pci_ctrl->pitar1 = 0;
  71. pci_ctrl->pibar1 = 0;
  72. pci_ctrl->piebar1 = 0;
  73. pci_ctrl->piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  74. PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
  75. i = hose->region_count++;
  76. hose->regions[i].bus_start = 0;
  77. hose->regions[i].phys_start = 0;
  78. hose->regions[i].size = gd->ram_size;
  79. hose->regions[i].flags = PCI_REGION_MEM | PCI_REGION_MEMORY;
  80. hose->first_busno = 0;
  81. hose->last_busno = 0xff;
  82. pci_setup_indirect(hose, CFG_IMMR + 0x8300 + bus * 0x80,
  83. CFG_IMMR + 0x8304 + bus * 0x80);
  84. pci_register_hose(hose);
  85. /*
  86. * Write to Command register
  87. */
  88. reg16 = 0xff;
  89. dev = PCI_BDF(hose->first_busno, 0, 0);
  90. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
  91. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  92. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  93. /*
  94. * Clear non-reserved bits in status register.
  95. */
  96. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  97. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  98. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  99. #ifdef CONFIG_PCI_SCAN_SHOW
  100. printf("PCI: Bus Dev VenId DevId Class Int\n");
  101. #endif
  102. /*
  103. * Hose scan.
  104. */
  105. hose->last_busno = pci_hose_scan(hose);
  106. }
  107. /*
  108. * The caller must have already set OCCR, and the PCI_LAW BARs
  109. * must have been set to cover all of the requested regions.
  110. *
  111. * If fewer than three regions are requested, then the region
  112. * list is terminated with a region of size 0.
  113. */
  114. void mpc83xx_pci_init(int num_buses, struct pci_region **reg, int warmboot)
  115. {
  116. volatile immap_t *immr = (volatile immap_t *)CFG_IMMR;
  117. int i;
  118. if (num_buses > MAX_BUSES) {
  119. printf("%d PCI buses requsted, %d supported\n",
  120. num_buses, MAX_BUSES);
  121. num_buses = MAX_BUSES;
  122. }
  123. pci_num_buses = num_buses;
  124. /*
  125. * Release PCI RST Output signal.
  126. * Power on to RST high must be at least 100 ms as per PCI spec.
  127. * On warm boots only 1 ms is required.
  128. */
  129. udelay(warmboot ? 1000 : 100000);
  130. for (i = 0; i < num_buses; i++)
  131. immr->pci_ctrl[i].gcr = 1;
  132. /*
  133. * RST high to first config access must be at least 2^25 cycles
  134. * as per PCI spec. This could be cut in half if we know we're
  135. * running at 66MHz. This could be insufficiently long if we're
  136. * running the PCI bus at significantly less than 33MHz.
  137. */
  138. udelay(1020000);
  139. for (i = 0; i < num_buses; i++)
  140. pci_init_bus(i, reg[i]);
  141. }
  142. #if defined(CONFIG_OF_LIBFDT)
  143. void ft_pci_setup(void *blob, bd_t *bd)
  144. {
  145. int nodeoffset;
  146. int err;
  147. int tmp[2];
  148. if (pci_num_buses < 1)
  149. return;
  150. nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8500");
  151. if (nodeoffset >= 0) {
  152. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  153. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  154. err = fdt_setprop(blob, nodeoffset, "bus-range", tmp, sizeof(tmp));
  155. }
  156. if (pci_num_buses < 2)
  157. return;
  158. nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8600");
  159. if (nodeoffset >= 0) {
  160. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  161. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  162. err = fdt_setprop(blob, nodeoffset, "bus-range", tmp, sizeof(tmp));
  163. }
  164. }
  165. #elif CONFIG_OF_FLAT_TREE
  166. void ft_pci_setup(void *blob, bd_t *bd)
  167. {
  168. u32 *p;
  169. int len;
  170. if (pci_num_buses < 1)
  171. return;
  172. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
  173. if (p) {
  174. p[0] = pci_hose[0].first_busno;
  175. p[1] = pci_hose[0].last_busno;
  176. }
  177. if (pci_num_buses < 2)
  178. return;
  179. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8600/bus-range", &len);
  180. if (p) {
  181. p[0] = pci_hose[1].first_busno;
  182. p[1] = pci_hose[1].last_busno;
  183. }
  184. }
  185. #endif /* CONFIG_OF_FLAT_TREE */
  186. #endif /* CONFIG_83XX_GENERIC_PCI */