pci-excite.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2004 by Basler Vision Technologies AG
  3. * Author: Thomas Koeller <thomas.koeller@baslerweb.com>
  4. * Based on the PMC-Sierra Yosemite board support by Ralf Baechle.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/pci.h>
  24. #include <linux/bitops.h>
  25. #include <asm/rm9k-ocd.h>
  26. #include <excite.h>
  27. extern struct pci_ops titan_pci_ops;
  28. static struct resource
  29. mem_resource = {
  30. .name = "PCI memory",
  31. .start = EXCITE_PHYS_PCI_MEM,
  32. .end = EXCITE_PHYS_PCI_MEM + EXCITE_SIZE_PCI_MEM - 1,
  33. .flags = IORESOURCE_MEM
  34. },
  35. io_resource = {
  36. .name = "PCI I/O",
  37. .start = EXCITE_PHYS_PCI_IO,
  38. .end = EXCITE_PHYS_PCI_IO + EXCITE_SIZE_PCI_IO - 1,
  39. .flags = IORESOURCE_IO
  40. };
  41. static struct pci_controller bx_controller = {
  42. .pci_ops = &titan_pci_ops,
  43. .mem_resource = &mem_resource,
  44. .mem_offset = 0x00000000UL,
  45. .io_resource = &io_resource,
  46. .io_offset = 0x00000000UL
  47. };
  48. static char
  49. iopage_failed[] __initdata = "Cannot allocate PCI I/O page",
  50. modebits_no_pci[] __initdata = "PCI is not configured in mode bits";
  51. #define RM9000x2_OCD_HTSC 0x0604
  52. #define RM9000x2_OCD_HTBHL 0x060c
  53. #define RM9000x2_OCD_PCIHRST 0x078c
  54. #define RM9K_OCD_MODEBIT1 0x00d4 /* (MODEBIT1) Mode Bit 1 */
  55. #define RM9K_OCD_CPHDCR 0x00f4 /* CPU-PCI/HT Data Control. */
  56. #define PCISC_FB2B 0x00000200
  57. #define PCISC_MWICG 0x00000010
  58. #define PCISC_EMC 0x00000004
  59. #define PCISC_ERMA 0x00000002
  60. static int __init basler_excite_pci_setup(void)
  61. {
  62. const unsigned int fullbars = memsize / (256 << 20);
  63. unsigned int i;
  64. /* Check modebits to see if PCI is really enabled. */
  65. if (!((ocd_readl(RM9K_OCD_MODEBIT1) >> (47-32)) & 0x1))
  66. panic(modebits_no_pci);
  67. if (NULL == request_mem_region(EXCITE_PHYS_PCI_IO, EXCITE_SIZE_PCI_IO,
  68. "Memory-mapped PCI I/O page"))
  69. panic(iopage_failed);
  70. /* Enable PCI 0 as master for config cycles */
  71. ocd_writel(PCISC_EMC | PCISC_ERMA, RM9000x2_OCD_HTSC);
  72. /* Set up latency timer */
  73. ocd_writel(0x8008, RM9000x2_OCD_HTBHL);
  74. /* Setup host IO and Memory space */
  75. ocd_writel((EXCITE_PHYS_PCI_IO >> 4) | 1, LKB7);
  76. ocd_writel(((EXCITE_SIZE_PCI_IO >> 4) & 0x7fffff00) - 0x100, LKM7);
  77. ocd_writel((EXCITE_PHYS_PCI_MEM >> 4) | 1, LKB8);
  78. ocd_writel(((EXCITE_SIZE_PCI_MEM >> 4) & 0x7fffff00) - 0x100, LKM8);
  79. /* Set up PCI BARs to map all installed memory */
  80. for (i = 0; i < 6; i++) {
  81. const unsigned int bar = 0x610 + i * 4;
  82. if (i < fullbars) {
  83. ocd_writel(0x10000000 * i, bar);
  84. ocd_writel(0x01000000 * i, bar + 0x140);
  85. ocd_writel(0x0ffff029, bar + 0x100);
  86. continue;
  87. }
  88. if (i == fullbars) {
  89. int o;
  90. u32 mask;
  91. const unsigned long rem = memsize - i * 0x10000000;
  92. if (!rem) {
  93. ocd_writel(0x00000000, bar + 0x100);
  94. continue;
  95. }
  96. o = ffs(rem) - 1;
  97. if (rem & ~(0x1 << o))
  98. o++;
  99. mask = ((0x1 << o) & 0x0ffff000) - 0x1000;
  100. ocd_writel(0x10000000 * i, bar);
  101. ocd_writel(0x01000000 * i, bar + 0x140);
  102. ocd_writel(0x00000029 | mask, bar + 0x100);
  103. continue;
  104. }
  105. ocd_writel(0x00000000, bar + 0x100);
  106. }
  107. /* Finally, enable the PCI interrupt */
  108. #if USB_IRQ > 7
  109. set_c0_intcontrol(1 << USB_IRQ);
  110. #else
  111. set_c0_status(1 << (USB_IRQ + 8));
  112. #endif
  113. ioport_resource.start = EXCITE_PHYS_PCI_IO;
  114. ioport_resource.end = EXCITE_PHYS_PCI_IO + EXCITE_SIZE_PCI_IO - 1;
  115. set_io_port_base((unsigned long) ioremap_nocache(EXCITE_PHYS_PCI_IO, EXCITE_SIZE_PCI_IO));
  116. register_pci_controller(&bx_controller);
  117. return 0;
  118. }
  119. arch_initcall(basler_excite_pci_setup);