pci-sh7780.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Low-Level PCI Support for the SH7780
  3. *
  4. * Dustin McIntire (dustin@sensoria.com)
  5. * Derived from arch/i386/kernel/pci-*.c which bore the message:
  6. * (c) 1999--2000 Martin Mares <mj@ucw.cz>
  7. *
  8. * Ported to the new API by Paul Mundt <lethal@linux-sh.org>
  9. * With cleanup by Paul van Gool <pvangool@mimotech.com>
  10. *
  11. * May be copied or modified under the terms of the GNU General Public
  12. * License. See linux/COPYING for more information.
  13. *
  14. */
  15. #undef DEBUG
  16. #include <linux/config.h>
  17. #include <linux/types.h>
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/pci.h>
  21. #include <linux/errno.h>
  22. #include <linux/delay.h>
  23. #include "pci-sh4.h"
  24. /*
  25. * Initialization. Try all known PCI access methods. Note that we support
  26. * using both PCI BIOS and direct access: in such cases, we use I/O ports
  27. * to access config space.
  28. *
  29. * Note that the platform specific initialization (BSC registers, and memory
  30. * space mapping) will be called via the platform defined function
  31. * pcibios_init_platform().
  32. */
  33. static int __init sh7780_pci_init(void)
  34. {
  35. unsigned int id;
  36. int ret;
  37. pr_debug("PCI: Starting intialization.\n");
  38. outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */
  39. /* check for SH7780/SH7780R hardware */
  40. id = pci_read_reg(SH7780_PCIVID);
  41. if ((id != ((SH7780_DEVICE_ID << 16) | SH7780_VENDOR_ID)) &&
  42. (id != ((SH7781_DEVICE_ID << 16) | SH7780_VENDOR_ID))) {
  43. printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id);
  44. return -ENODEV;
  45. }
  46. /* Setup the INTC */
  47. ctrl_outl(0x00200000, INTC_ICR0); /* INTC SH-4 Mode */
  48. ctrl_outl(0x00078000, INTC_INT2MSKCR); /* enable PCIINTA - PCIINTD */
  49. ctrl_outl(0x40000000, INTC_INTMSK1); /* disable IRL4-7 Interrupt */
  50. ctrl_outl(0x0000fffe, INTC_INTMSK2); /* disable IRL4-7 Interrupt */
  51. ctrl_outl(0x80000000, INTC_INTMSKCLR1); /* enable IRL0-3 Interrupt */
  52. ctrl_outl(0xfffe0000, INTC_INTMSKCLR2); /* enable IRL0-3 Interrupt */
  53. if ((ret = sh4_pci_check_direct()) != 0)
  54. return ret;
  55. return pcibios_init_platform();
  56. }
  57. core_initcall(sh7780_pci_init);
  58. int __init sh7780_pcic_init(struct sh4_pci_address_map *map)
  59. {
  60. u32 word;
  61. /*
  62. * This code is unused for some boards as it is done in the
  63. * bootloader and doing it here means the MAC addresses loaded
  64. * by the bootloader get lost.
  65. */
  66. if (!(map->flags & SH4_PCIC_NO_RESET)) {
  67. /* toggle PCI reset pin */
  68. word = SH4_PCICR_PREFIX | SH4_PCICR_PRST;
  69. pci_write_reg(word, SH4_PCICR);
  70. /* Wait for a long time... not 1 sec. but long enough */
  71. mdelay(100);
  72. word = SH4_PCICR_PREFIX;
  73. pci_write_reg(word, SH4_PCICR);
  74. }
  75. /* set the command/status bits to:
  76. * Wait Cycle Control + Parity Enable + Bus Master +
  77. * Mem space enable
  78. */
  79. pci_write_reg(0x00000046, SH7780_PCICMD);
  80. /* define this host as the host bridge */
  81. word = PCI_BASE_CLASS_BRIDGE << 24;
  82. pci_write_reg(word, SH7780_PCIRID);
  83. /* Set IO and Mem windows to local address
  84. * Make PCI and local address the same for easy 1 to 1 mapping
  85. * Window0 = map->window0.size @ non-cached area base = SDRAM
  86. * Window1 = map->window1.size @ cached area base = SDRAM
  87. */
  88. word = ((map->window0.size - 1) & 0x1ff00001) | 0x01;
  89. pci_write_reg(0x07f00001, SH4_PCILSR0);
  90. word = ((map->window1.size - 1) & 0x1ff00001) | 0x01;
  91. pci_write_reg(0x00000001, SH4_PCILSR1);
  92. /* Set the values on window 0 PCI config registers */
  93. word = P2SEGADDR(map->window0.base);
  94. pci_write_reg(0xa8000000, SH4_PCILAR0);
  95. pci_write_reg(0x08000000, SH7780_PCIMBAR0);
  96. /* Set the values on window 1 PCI config registers */
  97. word = P2SEGADDR(map->window1.base);
  98. pci_write_reg(0x00000000, SH4_PCILAR1);
  99. pci_write_reg(0x00000000, SH7780_PCIMBAR1);
  100. /* Map IO space into PCI IO window
  101. * The IO window is 64K-PCIBIOS_MIN_IO in size
  102. * IO addresses will be translated to the
  103. * PCI IO window base address
  104. */
  105. pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n",
  106. PCIBIOS_MIN_IO, (64 << 10),
  107. SH7780_PCI_IO_BASE + PCIBIOS_MIN_IO);
  108. /* NOTE: I'm ignoring the PCI error IRQs for now..
  109. * TODO: add support for the internal error interrupts and
  110. * DMA interrupts...
  111. */
  112. #ifdef CONFIG_SH_R7780RP
  113. pci_fixup_pcic();
  114. #endif
  115. /* SH7780 init done, set central function init complete */
  116. /* use round robin mode to stop a device starving/overruning */
  117. word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
  118. pci_write_reg(word, SH4_PCICR);
  119. return 1;
  120. }