pci-bcm63xx.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
  7. */
  8. #include <linux/types.h>
  9. #include <linux/pci.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <asm/bootinfo.h>
  13. #include "pci-bcm63xx.h"
  14. /*
  15. * Allow PCI to be disabled at runtime depending on board nvram
  16. * configuration
  17. */
  18. int bcm63xx_pci_enabled;
  19. static struct resource bcm_pci_mem_resource = {
  20. .name = "bcm63xx PCI memory space",
  21. .start = BCM_PCI_MEM_BASE_PA,
  22. .end = BCM_PCI_MEM_END_PA,
  23. .flags = IORESOURCE_MEM
  24. };
  25. static struct resource bcm_pci_io_resource = {
  26. .name = "bcm63xx PCI IO space",
  27. .start = BCM_PCI_IO_BASE_PA,
  28. #ifdef CONFIG_CARDBUS
  29. .end = BCM_PCI_IO_HALF_PA,
  30. #else
  31. .end = BCM_PCI_IO_END_PA,
  32. #endif
  33. .flags = IORESOURCE_IO
  34. };
  35. struct pci_controller bcm63xx_controller = {
  36. .pci_ops = &bcm63xx_pci_ops,
  37. .io_resource = &bcm_pci_io_resource,
  38. .mem_resource = &bcm_pci_mem_resource,
  39. };
  40. /*
  41. * We handle cardbus via a fake Cardbus bridge, memory and io spaces
  42. * have to be clearly separated from PCI one since we have different
  43. * memory decoder.
  44. */
  45. #ifdef CONFIG_CARDBUS
  46. static struct resource bcm_cb_mem_resource = {
  47. .name = "bcm63xx Cardbus memory space",
  48. .start = BCM_CB_MEM_BASE_PA,
  49. .end = BCM_CB_MEM_END_PA,
  50. .flags = IORESOURCE_MEM
  51. };
  52. static struct resource bcm_cb_io_resource = {
  53. .name = "bcm63xx Cardbus IO space",
  54. .start = BCM_PCI_IO_HALF_PA + 1,
  55. .end = BCM_PCI_IO_END_PA,
  56. .flags = IORESOURCE_IO
  57. };
  58. struct pci_controller bcm63xx_cb_controller = {
  59. .pci_ops = &bcm63xx_cb_ops,
  60. .io_resource = &bcm_cb_io_resource,
  61. .mem_resource = &bcm_cb_mem_resource,
  62. };
  63. #endif
  64. static u32 bcm63xx_int_cfg_readl(u32 reg)
  65. {
  66. u32 tmp;
  67. tmp = reg & MPI_PCICFGCTL_CFGADDR_MASK;
  68. tmp |= MPI_PCICFGCTL_WRITEEN_MASK;
  69. bcm_mpi_writel(tmp, MPI_PCICFGCTL_REG);
  70. iob();
  71. return bcm_mpi_readl(MPI_PCICFGDATA_REG);
  72. }
  73. static void bcm63xx_int_cfg_writel(u32 val, u32 reg)
  74. {
  75. u32 tmp;
  76. tmp = reg & MPI_PCICFGCTL_CFGADDR_MASK;
  77. tmp |= MPI_PCICFGCTL_WRITEEN_MASK;
  78. bcm_mpi_writel(tmp, MPI_PCICFGCTL_REG);
  79. bcm_mpi_writel(val, MPI_PCICFGDATA_REG);
  80. }
  81. void __iomem *pci_iospace_start;
  82. static int __init bcm63xx_pci_init(void)
  83. {
  84. unsigned int mem_size;
  85. u32 val;
  86. if (!BCMCPU_IS_6348() && !BCMCPU_IS_6358() && !BCMCPU_IS_6368())
  87. return -ENODEV;
  88. if (!bcm63xx_pci_enabled)
  89. return -ENODEV;
  90. /*
  91. * configuration access are done through IO space, remap 4
  92. * first bytes to access it from CPU.
  93. *
  94. * this means that no io access from CPU should happen while
  95. * we do a configuration cycle, but there's no way we can add
  96. * a spinlock for each io access, so this is currently kind of
  97. * broken on SMP.
  98. */
  99. pci_iospace_start = ioremap_nocache(BCM_PCI_IO_BASE_PA, 4);
  100. if (!pci_iospace_start)
  101. return -ENOMEM;
  102. /* setup local bus to PCI access (PCI memory) */
  103. val = BCM_PCI_MEM_BASE_PA & MPI_L2P_BASE_MASK;
  104. bcm_mpi_writel(val, MPI_L2PMEMBASE1_REG);
  105. bcm_mpi_writel(~(BCM_PCI_MEM_SIZE - 1), MPI_L2PMEMRANGE1_REG);
  106. bcm_mpi_writel(val | MPI_L2PREMAP_ENABLED_MASK, MPI_L2PMEMREMAP1_REG);
  107. /* set Cardbus IDSEL (type 0 cfg access on primary bus for
  108. * this IDSEL will be done on Cardbus instead) */
  109. val = bcm_pcmcia_readl(PCMCIA_C1_REG);
  110. val &= ~PCMCIA_C1_CBIDSEL_MASK;
  111. val |= (CARDBUS_PCI_IDSEL << PCMCIA_C1_CBIDSEL_SHIFT);
  112. bcm_pcmcia_writel(val, PCMCIA_C1_REG);
  113. #ifdef CONFIG_CARDBUS
  114. /* setup local bus to PCI access (Cardbus memory) */
  115. val = BCM_CB_MEM_BASE_PA & MPI_L2P_BASE_MASK;
  116. bcm_mpi_writel(val, MPI_L2PMEMBASE2_REG);
  117. bcm_mpi_writel(~(BCM_CB_MEM_SIZE - 1), MPI_L2PMEMRANGE2_REG);
  118. val |= MPI_L2PREMAP_ENABLED_MASK | MPI_L2PREMAP_IS_CARDBUS_MASK;
  119. bcm_mpi_writel(val, MPI_L2PMEMREMAP2_REG);
  120. #else
  121. /* disable second access windows */
  122. bcm_mpi_writel(0, MPI_L2PMEMREMAP2_REG);
  123. #endif
  124. /* setup local bus to PCI access (IO memory), we have only 1
  125. * IO window for both PCI and cardbus, but it cannot handle
  126. * both at the same time, assume standard PCI for now, if
  127. * cardbus card has IO zone, PCI fixup will change window to
  128. * cardbus */
  129. val = BCM_PCI_IO_BASE_PA & MPI_L2P_BASE_MASK;
  130. bcm_mpi_writel(val, MPI_L2PIOBASE_REG);
  131. bcm_mpi_writel(~(BCM_PCI_IO_SIZE - 1), MPI_L2PIORANGE_REG);
  132. bcm_mpi_writel(val | MPI_L2PREMAP_ENABLED_MASK, MPI_L2PIOREMAP_REG);
  133. /* enable PCI related GPIO pins */
  134. bcm_mpi_writel(MPI_LOCBUSCTL_EN_PCI_GPIO_MASK, MPI_LOCBUSCTL_REG);
  135. /* setup PCI to local bus access, used by PCI device to target
  136. * local RAM while bus mastering */
  137. bcm63xx_int_cfg_writel(0, PCI_BASE_ADDRESS_3);
  138. if (BCMCPU_IS_6358() || BCMCPU_IS_6368())
  139. val = MPI_SP0_REMAP_ENABLE_MASK;
  140. else
  141. val = 0;
  142. bcm_mpi_writel(val, MPI_SP0_REMAP_REG);
  143. bcm63xx_int_cfg_writel(0x0, PCI_BASE_ADDRESS_4);
  144. bcm_mpi_writel(0, MPI_SP1_REMAP_REG);
  145. mem_size = bcm63xx_get_memory_size();
  146. /* 6348 before rev b0 exposes only 16 MB of RAM memory through
  147. * PCI, throw a warning if we have more memory */
  148. if (BCMCPU_IS_6348() && (bcm63xx_get_cpu_rev() & 0xf0) == 0xa0) {
  149. if (mem_size > (16 * 1024 * 1024))
  150. printk(KERN_WARNING "bcm63xx: this CPU "
  151. "revision cannot handle more than 16MB "
  152. "of RAM for PCI bus mastering\n");
  153. } else {
  154. /* setup sp0 range to local RAM size */
  155. bcm_mpi_writel(~(mem_size - 1), MPI_SP0_RANGE_REG);
  156. bcm_mpi_writel(0, MPI_SP1_RANGE_REG);
  157. }
  158. /* change host bridge retry counter to infinite number of
  159. * retry, needed for some broadcom wifi cards with Silicon
  160. * Backplane bus where access to srom seems very slow */
  161. val = bcm63xx_int_cfg_readl(BCMPCI_REG_TIMERS);
  162. val &= ~REG_TIMER_RETRY_MASK;
  163. bcm63xx_int_cfg_writel(val, BCMPCI_REG_TIMERS);
  164. /* enable memory decoder and bus mastering */
  165. val = bcm63xx_int_cfg_readl(PCI_COMMAND);
  166. val |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  167. bcm63xx_int_cfg_writel(val, PCI_COMMAND);
  168. /* enable read prefetching & disable byte swapping for bus
  169. * mastering transfers */
  170. val = bcm_mpi_readl(MPI_PCIMODESEL_REG);
  171. val &= ~MPI_PCIMODESEL_BAR1_NOSWAP_MASK;
  172. val &= ~MPI_PCIMODESEL_BAR2_NOSWAP_MASK;
  173. val &= ~MPI_PCIMODESEL_PREFETCH_MASK;
  174. val |= (8 << MPI_PCIMODESEL_PREFETCH_SHIFT);
  175. bcm_mpi_writel(val, MPI_PCIMODESEL_REG);
  176. /* enable pci interrupt */
  177. val = bcm_mpi_readl(MPI_LOCINT_REG);
  178. val |= MPI_LOCINT_MASK(MPI_LOCINT_EXT_PCI_INT);
  179. bcm_mpi_writel(val, MPI_LOCINT_REG);
  180. register_pci_controller(&bcm63xx_controller);
  181. #ifdef CONFIG_CARDBUS
  182. register_pci_controller(&bcm63xx_cb_controller);
  183. #endif
  184. /* mark memory space used for IO mapping as reserved */
  185. request_mem_region(BCM_PCI_IO_BASE_PA, BCM_PCI_IO_SIZE,
  186. "bcm63xx PCI IO space");
  187. return 0;
  188. }
  189. arch_initcall(bcm63xx_pci_init);