pci-sh7780.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Low-Level PCI Support for the SH7780
  3. *
  4. * Copyright (C) 2005 - 2010 Paul Mundt
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/pci.h>
  14. #include <linux/errno.h>
  15. #include <linux/delay.h>
  16. #include <linux/log2.h>
  17. #include "pci-sh4.h"
  18. #include <asm/mmu.h>
  19. #include <asm/sizes.h>
  20. static struct resource sh7785_io_resource = {
  21. .name = "SH7785_IO",
  22. .start = 0x1000,
  23. .end = SH7780_PCI_IO_SIZE - 1,
  24. .flags = IORESOURCE_IO
  25. };
  26. static struct resource sh7785_mem_resource = {
  27. .name = "SH7785_mem",
  28. .start = SH7780_PCI_MEMORY_BASE,
  29. .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
  30. .flags = IORESOURCE_MEM
  31. };
  32. static struct pci_channel sh7780_pci_controller = {
  33. .pci_ops = &sh4_pci_ops,
  34. .mem_resource = &sh7785_mem_resource,
  35. .mem_offset = 0x00000000,
  36. .io_resource = &sh7785_io_resource,
  37. .io_offset = 0x00000000,
  38. .io_map_base = SH7780_PCI_IO_BASE,
  39. };
  40. static int __init sh7780_pci_init(void)
  41. {
  42. struct pci_channel *chan = &sh7780_pci_controller;
  43. phys_addr_t memphys;
  44. size_t memsize;
  45. unsigned int id;
  46. const char *type;
  47. printk(KERN_NOTICE "PCI: Starting intialization.\n");
  48. chan->reg_base = 0xfe040000;
  49. /* Enable CPU access to the PCIC registers. */
  50. __raw_writel(PCIECR_ENBL, PCIECR);
  51. /* Reset */
  52. __raw_writel(SH4_PCICR_PREFIX | SH4_PCICR_PRST,
  53. chan->reg_base + SH4_PCICR);
  54. /*
  55. * Wait for it to come back up. The spec says to allow for up to
  56. * 1 second after toggling the reset pin, but in practice 100ms
  57. * is more than enough.
  58. */
  59. mdelay(100);
  60. id = __raw_readw(chan->reg_base + PCI_VENDOR_ID);
  61. if (id != PCI_VENDOR_ID_RENESAS) {
  62. printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id);
  63. return -ENODEV;
  64. }
  65. id = __raw_readw(chan->reg_base + PCI_DEVICE_ID);
  66. type = (id == PCI_DEVICE_ID_RENESAS_SH7763) ? "SH7763" :
  67. (id == PCI_DEVICE_ID_RENESAS_SH7780) ? "SH7780" :
  68. (id == PCI_DEVICE_ID_RENESAS_SH7781) ? "SH7781" :
  69. (id == PCI_DEVICE_ID_RENESAS_SH7785) ? "SH7785" :
  70. NULL;
  71. if (unlikely(!type)) {
  72. printk(KERN_ERR "PCI: Found an unsupported Renesas host "
  73. "controller, device id 0x%04x.\n", id);
  74. return -EINVAL;
  75. }
  76. printk(KERN_NOTICE "PCI: Found a Renesas %s host "
  77. "controller, revision %d.\n", type,
  78. __raw_readb(chan->reg_base + PCI_REVISION_ID));
  79. /*
  80. * Now throw it in to register initialization mode and
  81. * start the real work.
  82. */
  83. __raw_writel(SH4_PCICR_PREFIX, chan->reg_base + SH4_PCICR);
  84. __raw_writel(0, chan->reg_base + PCI_BASE_ADDRESS_0);
  85. memphys = __pa(memory_start);
  86. memsize = roundup_pow_of_two(memory_end - memory_start);
  87. /*
  88. * If there's more than 512MB of memory, we need to roll over to
  89. * LAR1/LSR1.
  90. */
  91. if (memsize > SZ_512M) {
  92. __raw_writel(memphys + SZ_512M, chan->reg_base + SH4_PCILAR1);
  93. __raw_writel((((memsize - SZ_512M) - SZ_1M) & 0x1ff00000) | 1,
  94. chan->reg_base + SH4_PCILSR1);
  95. memsize = SZ_512M;
  96. } else {
  97. /*
  98. * Otherwise just zero it out and disable it.
  99. */
  100. __raw_writel(0, chan->reg_base + SH4_PCILAR1);
  101. __raw_writel(0, chan->reg_base + SH4_PCILSR1);
  102. }
  103. /*
  104. * LAR0/LSR0 covers up to the first 512MB, which is enough to
  105. * cover all of lowmem on most platforms.
  106. */
  107. __raw_writel(memphys, chan->reg_base + SH4_PCILAR0);
  108. __raw_writel(((memsize - SZ_1M) & 0x1ff00000) | 1,
  109. chan->reg_base + SH4_PCILSR0);
  110. /* Clear out PCI arbiter IRQs */
  111. __raw_writel(0, chan->reg_base + SH4_PCIAINT);
  112. /* Unmask all of the arbiter IRQs. */
  113. __raw_writel(SH4_PCIAINT_MBKN | SH4_PCIAINT_TBTO | SH4_PCIAINT_MBTO | \
  114. SH4_PCIAINT_TABT | SH4_PCIAINT_MABT | SH4_PCIAINT_RDPE | \
  115. SH4_PCIAINT_WDPE, chan->reg_base + SH4_PCIAINTM);
  116. /* Clear all error conditions */
  117. __raw_writew(PCI_STATUS_DETECTED_PARITY | \
  118. PCI_STATUS_SIG_SYSTEM_ERROR | \
  119. PCI_STATUS_REC_MASTER_ABORT | \
  120. PCI_STATUS_REC_TARGET_ABORT | \
  121. PCI_STATUS_SIG_TARGET_ABORT | \
  122. PCI_STATUS_PARITY, chan->reg_base + PCI_STATUS);
  123. __raw_writew(PCI_COMMAND_SERR | PCI_COMMAND_WAIT | \
  124. PCI_COMMAND_PARITY | PCI_COMMAND_MASTER | \
  125. PCI_COMMAND_MEMORY, chan->reg_base + PCI_COMMAND);
  126. /* Unmask all of the PCI IRQs */
  127. __raw_writel(SH4_PCIINTM_TTADIM | SH4_PCIINTM_TMTOIM | \
  128. SH4_PCIINTM_MDEIM | SH4_PCIINTM_APEDIM | \
  129. SH4_PCIINTM_SDIM | SH4_PCIINTM_DPEITWM | \
  130. SH4_PCIINTM_PEDITRM | SH4_PCIINTM_TADIMM | \
  131. SH4_PCIINTM_MADIMM | SH4_PCIINTM_MWPDIM | \
  132. SH4_PCIINTM_MRDPEIM, chan->reg_base + SH4_PCIINTM);
  133. /*
  134. * Disable the cache snoop controller for non-coherent DMA.
  135. */
  136. __raw_writel(0, chan->reg_base + SH7780_PCICSCR0);
  137. __raw_writel(0, chan->reg_base + SH7780_PCICSAR0);
  138. __raw_writel(0, chan->reg_base + SH7780_PCICSCR1);
  139. __raw_writel(0, chan->reg_base + SH7780_PCICSAR1);
  140. __raw_writel(0xfd000000, chan->reg_base + SH7780_PCIMBR0);
  141. __raw_writel(0x00fc0000, chan->reg_base + SH7780_PCIMBMR0);
  142. __raw_writel(0, chan->reg_base + SH7780_PCIIOBR);
  143. __raw_writel(0, chan->reg_base + SH7780_PCIIOBMR);
  144. /*
  145. * Initialization mode complete, release the control register and
  146. * enable round robin mode to stop device overruns/starvation.
  147. */
  148. __raw_writel(SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO,
  149. chan->reg_base + SH4_PCICR);
  150. register_pci_controller(chan);
  151. return 0;
  152. }
  153. arch_initcall(sh7780_pci_init);