pci-sh7780.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 void __init sh7780_pci66_init(struct pci_channel *hose)
  41. {
  42. unsigned int tmp;
  43. if (!pci_is_66mhz_capable(hose, 0, 0))
  44. return;
  45. /* Enable register access */
  46. tmp = __raw_readl(hose->reg_base + SH4_PCICR);
  47. tmp |= SH4_PCICR_PREFIX;
  48. __raw_writel(tmp, hose->reg_base + SH4_PCICR);
  49. /* Enable 66MHz operation */
  50. tmp = __raw_readw(hose->reg_base + PCI_STATUS);
  51. tmp |= PCI_STATUS_66MHZ;
  52. __raw_writew(tmp, hose->reg_base + PCI_STATUS);
  53. /* Done */
  54. tmp = __raw_readl(hose->reg_base + SH4_PCICR);
  55. tmp |= SH4_PCICR_PREFIX | SH4_PCICR_CFIN;
  56. __raw_writel(tmp, hose->reg_base + SH4_PCICR);
  57. }
  58. static int __init sh7780_pci_init(void)
  59. {
  60. struct pci_channel *chan = &sh7780_pci_controller;
  61. phys_addr_t memphys;
  62. size_t memsize;
  63. unsigned int id;
  64. const char *type;
  65. printk(KERN_NOTICE "PCI: Starting intialization.\n");
  66. chan->reg_base = 0xfe040000;
  67. /* Enable CPU access to the PCIC registers. */
  68. __raw_writel(PCIECR_ENBL, PCIECR);
  69. /* Reset */
  70. __raw_writel(SH4_PCICR_PREFIX | SH4_PCICR_PRST,
  71. chan->reg_base + SH4_PCICR);
  72. /*
  73. * Wait for it to come back up. The spec says to allow for up to
  74. * 1 second after toggling the reset pin, but in practice 100ms
  75. * is more than enough.
  76. */
  77. mdelay(100);
  78. id = __raw_readw(chan->reg_base + PCI_VENDOR_ID);
  79. if (id != PCI_VENDOR_ID_RENESAS) {
  80. printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id);
  81. return -ENODEV;
  82. }
  83. id = __raw_readw(chan->reg_base + PCI_DEVICE_ID);
  84. type = (id == PCI_DEVICE_ID_RENESAS_SH7763) ? "SH7763" :
  85. (id == PCI_DEVICE_ID_RENESAS_SH7780) ? "SH7780" :
  86. (id == PCI_DEVICE_ID_RENESAS_SH7781) ? "SH7781" :
  87. (id == PCI_DEVICE_ID_RENESAS_SH7785) ? "SH7785" :
  88. NULL;
  89. if (unlikely(!type)) {
  90. printk(KERN_ERR "PCI: Found an unsupported Renesas host "
  91. "controller, device id 0x%04x.\n", id);
  92. return -EINVAL;
  93. }
  94. printk(KERN_NOTICE "PCI: Found a Renesas %s host "
  95. "controller, revision %d.\n", type,
  96. __raw_readb(chan->reg_base + PCI_REVISION_ID));
  97. /*
  98. * Now throw it in to register initialization mode and
  99. * start the real work.
  100. */
  101. __raw_writel(SH4_PCICR_PREFIX, chan->reg_base + SH4_PCICR);
  102. __raw_writel(0, chan->reg_base + PCI_BASE_ADDRESS_0);
  103. memphys = __pa(memory_start);
  104. memsize = roundup_pow_of_two(memory_end - memory_start);
  105. /*
  106. * If there's more than 512MB of memory, we need to roll over to
  107. * LAR1/LSR1.
  108. */
  109. if (memsize > SZ_512M) {
  110. __raw_writel(memphys + SZ_512M, chan->reg_base + SH4_PCILAR1);
  111. __raw_writel((((memsize - SZ_512M) - SZ_1M) & 0x1ff00000) | 1,
  112. chan->reg_base + SH4_PCILSR1);
  113. memsize = SZ_512M;
  114. } else {
  115. /*
  116. * Otherwise just zero it out and disable it.
  117. */
  118. __raw_writel(0, chan->reg_base + SH4_PCILAR1);
  119. __raw_writel(0, chan->reg_base + SH4_PCILSR1);
  120. }
  121. /*
  122. * LAR0/LSR0 covers up to the first 512MB, which is enough to
  123. * cover all of lowmem on most platforms.
  124. */
  125. __raw_writel(memphys, chan->reg_base + SH4_PCILAR0);
  126. __raw_writel(((memsize - SZ_1M) & 0x1ff00000) | 1,
  127. chan->reg_base + SH4_PCILSR0);
  128. /* Clear out PCI arbiter IRQs */
  129. __raw_writel(0, chan->reg_base + SH4_PCIAINT);
  130. /* Unmask all of the arbiter IRQs. */
  131. __raw_writel(SH4_PCIAINT_MBKN | SH4_PCIAINT_TBTO | SH4_PCIAINT_MBTO | \
  132. SH4_PCIAINT_TABT | SH4_PCIAINT_MABT | SH4_PCIAINT_RDPE | \
  133. SH4_PCIAINT_WDPE, chan->reg_base + SH4_PCIAINTM);
  134. /* Clear all error conditions */
  135. __raw_writew(PCI_STATUS_DETECTED_PARITY | \
  136. PCI_STATUS_SIG_SYSTEM_ERROR | \
  137. PCI_STATUS_REC_MASTER_ABORT | \
  138. PCI_STATUS_REC_TARGET_ABORT | \
  139. PCI_STATUS_SIG_TARGET_ABORT | \
  140. PCI_STATUS_PARITY, chan->reg_base + PCI_STATUS);
  141. __raw_writew(PCI_COMMAND_SERR | PCI_COMMAND_WAIT | \
  142. PCI_COMMAND_PARITY | PCI_COMMAND_MASTER | \
  143. PCI_COMMAND_MEMORY, chan->reg_base + PCI_COMMAND);
  144. /* Unmask all of the PCI IRQs */
  145. __raw_writel(SH4_PCIINTM_TTADIM | SH4_PCIINTM_TMTOIM | \
  146. SH4_PCIINTM_MDEIM | SH4_PCIINTM_APEDIM | \
  147. SH4_PCIINTM_SDIM | SH4_PCIINTM_DPEITWM | \
  148. SH4_PCIINTM_PEDITRM | SH4_PCIINTM_TADIMM | \
  149. SH4_PCIINTM_MADIMM | SH4_PCIINTM_MWPDIM | \
  150. SH4_PCIINTM_MRDPEIM, chan->reg_base + SH4_PCIINTM);
  151. /*
  152. * Disable the cache snoop controller for non-coherent DMA.
  153. */
  154. __raw_writel(0, chan->reg_base + SH7780_PCICSCR0);
  155. __raw_writel(0, chan->reg_base + SH7780_PCICSAR0);
  156. __raw_writel(0, chan->reg_base + SH7780_PCICSCR1);
  157. __raw_writel(0, chan->reg_base + SH7780_PCICSAR1);
  158. __raw_writel(0xfd000000, chan->reg_base + SH7780_PCIMBR0);
  159. __raw_writel(0x00fc0000, chan->reg_base + SH7780_PCIMBMR0);
  160. __raw_writel(0, chan->reg_base + SH7780_PCIIOBR);
  161. __raw_writel(0, chan->reg_base + SH7780_PCIIOBMR);
  162. /*
  163. * Initialization mode complete, release the control register and
  164. * enable round robin mode to stop device overruns/starvation.
  165. */
  166. __raw_writel(SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO,
  167. chan->reg_base + SH4_PCICR);
  168. register_pci_controller(chan);
  169. sh7780_pci66_init(chan);
  170. printk(KERN_NOTICE "PCI: Running at %dMHz.\n",
  171. (__raw_readw(chan->reg_base + PCI_STATUS) & PCI_STATUS_66MHZ) ?
  172. 66 : 33);
  173. return 0;
  174. }
  175. arch_initcall(sh7780_pci_init);