pci-sh7780.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/types.h>
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/pci.h>
  20. #include <linux/errno.h>
  21. #include <linux/delay.h>
  22. #include "pci-sh4.h"
  23. #define INTC_BASE 0xffd00000
  24. #define INTC_ICR0 (INTC_BASE+0x0)
  25. #define INTC_ICR1 (INTC_BASE+0x1c)
  26. #define INTC_INTPRI (INTC_BASE+0x10)
  27. #define INTC_INTREQ (INTC_BASE+0x24)
  28. #define INTC_INTMSK0 (INTC_BASE+0x44)
  29. #define INTC_INTMSK1 (INTC_BASE+0x48)
  30. #define INTC_INTMSK2 (INTC_BASE+0x40080)
  31. #define INTC_INTMSKCLR0 (INTC_BASE+0x64)
  32. #define INTC_INTMSKCLR1 (INTC_BASE+0x68)
  33. #define INTC_INTMSKCLR2 (INTC_BASE+0x40084)
  34. #define INTC_INT2MSKR (INTC_BASE+0x40038)
  35. #define INTC_INT2MSKCR (INTC_BASE+0x4003c)
  36. /*
  37. * Initialization. Try all known PCI access methods. Note that we support
  38. * using both PCI BIOS and direct access: in such cases, we use I/O ports
  39. * to access config space.
  40. *
  41. * Note that the platform specific initialization (BSC registers, and memory
  42. * space mapping) will be called via the platform defined function
  43. * pcibios_init_platform().
  44. */
  45. int __init sh7780_pci_init(struct pci_channel *chan)
  46. {
  47. unsigned int id;
  48. int ret, match = 0;
  49. pr_debug("PCI: Starting intialization.\n");
  50. chan->reg_base = 0xfe040000;
  51. chan->io_base = 0xfe200000;
  52. ctrl_outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */
  53. /* check for SH7780/SH7780R hardware */
  54. id = pci_read_reg(chan, SH7780_PCIVID);
  55. if ((id & 0xffff) == SH7780_VENDOR_ID) {
  56. switch ((id >> 16) & 0xffff) {
  57. case SH7763_DEVICE_ID:
  58. case SH7780_DEVICE_ID:
  59. case SH7781_DEVICE_ID:
  60. case SH7785_DEVICE_ID:
  61. match = 1;
  62. break;
  63. }
  64. }
  65. if (unlikely(!match)) {
  66. printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id);
  67. return -ENODEV;
  68. }
  69. /* Setup the INTC */
  70. if (mach_is_7780se()) {
  71. /* ICR0: IRL=use separately */
  72. ctrl_outl(0x00C00020, INTC_ICR0);
  73. /* ICR1: detect low level(for 2ndcut) */
  74. ctrl_outl(0xAAAA0000, INTC_ICR1);
  75. /* INTPRI: priority=3(all) */
  76. ctrl_outl(0x33333333, INTC_INTPRI);
  77. }
  78. if ((ret = sh4_pci_check_direct(chan)) != 0)
  79. return ret;
  80. return pcibios_init_platform();
  81. }
  82. int __init sh7780_pcic_init(struct pci_channel *chan,
  83. struct sh4_pci_address_map *map)
  84. {
  85. u32 word;
  86. /* set the command/status bits to:
  87. * Wait Cycle Control + Parity Enable + Bus Master +
  88. * Mem space enable
  89. */
  90. pci_write_reg(chan, 0x00000046, SH7780_PCICMD);
  91. /* define this host as the host bridge */
  92. word = PCI_BASE_CLASS_BRIDGE << 24;
  93. pci_write_reg(chan, word, SH7780_PCIRID);
  94. /* Set IO and Mem windows to local address
  95. * Make PCI and local address the same for easy 1 to 1 mapping
  96. */
  97. pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0);
  98. pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1);
  99. /* Set the values on window 0 PCI config registers */
  100. pci_write_reg(chan, map->window0.base, SH4_PCILAR0);
  101. pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0);
  102. /* Set the values on window 1 PCI config registers */
  103. pci_write_reg(chan, map->window1.base, SH4_PCILAR1);
  104. pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1);
  105. /* Map IO space into PCI IO window:
  106. * IO addresses will be translated to the PCI IO window base address
  107. */
  108. pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%lx\n",
  109. chan->io_resource->start, chan->io_resource->end,
  110. chan->io_base + chan->io_resource->start);
  111. /* NOTE: I'm ignoring the PCI error IRQs for now..
  112. * TODO: add support for the internal error interrupts and
  113. * DMA interrupts...
  114. */
  115. /* Apply any last-minute PCIC fixups */
  116. pci_fixup_pcic(chan);
  117. /* SH7780 init done, set central function init complete */
  118. /* use round robin mode to stop a device starving/overruning */
  119. word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
  120. pci_write_reg(chan, word, SH4_PCICR);
  121. return 0;
  122. }