pci-sh7780.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Low-Level PCI Support for the SH7780
  3. *
  4. * Copyright (C) 2005 - 2009 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 "pci-sh4.h"
  17. extern u8 pci_cache_line_size;
  18. static struct resource sh7785_io_resource = {
  19. .name = "SH7785_IO",
  20. .start = SH7780_PCI_IO_BASE,
  21. .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1,
  22. .flags = IORESOURCE_IO
  23. };
  24. static struct resource sh7785_mem_resource = {
  25. .name = "SH7785_mem",
  26. .start = SH7780_PCI_MEMORY_BASE,
  27. .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
  28. .flags = IORESOURCE_MEM
  29. };
  30. static struct pci_channel sh7780_pci_controller = {
  31. .pci_ops = &sh4_pci_ops,
  32. .mem_resource = &sh7785_mem_resource,
  33. .mem_offset = 0x00000000,
  34. .io_resource = &sh7785_io_resource,
  35. .io_offset = 0x00000000,
  36. };
  37. static struct sh4_pci_address_map sh7780_pci_map = {
  38. .window0 = {
  39. #if defined(CONFIG_32BIT)
  40. .base = SH7780_32BIT_DDR_BASE_ADDR,
  41. .size = 0x40000000,
  42. #else
  43. .base = SH7780_CS0_BASE_ADDR,
  44. .size = 0x20000000,
  45. #endif
  46. },
  47. };
  48. static int __init sh7780_pci_init(void)
  49. {
  50. struct pci_channel *chan = &sh7780_pci_controller;
  51. unsigned int id;
  52. const char *type = NULL;
  53. int ret;
  54. u32 word;
  55. printk(KERN_NOTICE "PCI: Starting intialization.\n");
  56. chan->reg_base = 0xfe040000;
  57. /* Enable CPU access to the PCIC registers. */
  58. __raw_writel(PCIECR_ENBL, PCIECR);
  59. id = __raw_readw(chan->reg_base + SH7780_PCIVID);
  60. if (id != SH7780_VENDOR_ID) {
  61. printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id);
  62. return -ENODEV;
  63. }
  64. id = __raw_readw(chan->reg_base + SH7780_PCIDID);
  65. type = (id == SH7763_DEVICE_ID) ? "SH7763" :
  66. (id == SH7780_DEVICE_ID) ? "SH7780" :
  67. (id == SH7781_DEVICE_ID) ? "SH7781" :
  68. (id == SH7785_DEVICE_ID) ? "SH7785" :
  69. NULL;
  70. if (unlikely(!type)) {
  71. printk(KERN_ERR "PCI: Found an unsupported Renesas host "
  72. "controller, device id 0x%04x.\n", id);
  73. return -EINVAL;
  74. }
  75. printk(KERN_NOTICE "PCI: Found a Renesas %s host "
  76. "controller, revision %d.\n", type,
  77. __raw_readb(chan->reg_base + SH7780_PCIRID));
  78. if ((ret = sh4_pci_check_direct(chan)) != 0)
  79. return ret;
  80. /*
  81. * Set the class and sub-class codes.
  82. */
  83. __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8,
  84. chan->reg_base + SH7780_PCIBCC);
  85. __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff,
  86. chan->reg_base + SH7780_PCISUB);
  87. pci_cache_line_size = pci_read_reg(chan, SH7780_PCICLS) / 4;
  88. /*
  89. * Set IO and Mem windows to local address
  90. * Make PCI and local address the same for easy 1 to 1 mapping
  91. */
  92. pci_write_reg(chan, sh7780_pci_map.window0.size - 0xfffff, SH4_PCILSR0);
  93. /* Set the values on window 0 PCI config registers */
  94. pci_write_reg(chan, sh7780_pci_map.window0.base, SH4_PCILAR0);
  95. pci_write_reg(chan, sh7780_pci_map.window0.base, SH7780_PCIMBAR0);
  96. pci_write_reg(chan, 0x0000380f, SH4_PCIAINTM);
  97. /* Set up standard PCI config registers */
  98. __raw_writew(0xFB00, chan->reg_base + SH7780_PCISTATUS);
  99. __raw_writew(0x0047, chan->reg_base + SH7780_PCICMD);
  100. __raw_writew(0x1912, chan->reg_base + SH7780_PCISVID);
  101. __raw_writew(0x0001, chan->reg_base + SH7780_PCISID);
  102. __raw_writeb(0x00, chan->reg_base + SH7780_PCIPIF);
  103. /* Apply any last-minute PCIC fixups */
  104. pci_fixup_pcic(chan);
  105. pci_write_reg(chan, 0xfd000000, SH7780_PCIMBR0);
  106. pci_write_reg(chan, 0x00fc0000, SH7780_PCIMBMR0);
  107. #ifdef CONFIG_32BIT
  108. pci_write_reg(chan, 0xc0000000, SH7780_PCIMBR2);
  109. pci_write_reg(chan, 0x20000000 - SH7780_PCI_IO_SIZE, SH7780_PCIMBMR2);
  110. #endif
  111. /* Set IOBR for windows containing area specified in pci.h */
  112. pci_write_reg(chan, chan->io_resource->start & ~(SH7780_PCI_IO_SIZE-1),
  113. SH7780_PCIIOBR);
  114. pci_write_reg(chan, ((SH7780_PCI_IO_SIZE-1) & (7<<18)),
  115. SH7780_PCIIOBMR);
  116. /* SH7780 init done, set central function init complete */
  117. /* use round robin mode to stop a device starving/overruning */
  118. word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
  119. pci_write_reg(chan, word, SH4_PCICR);
  120. __set_io_port_base(SH7780_PCI_IO_BASE);
  121. register_pci_controller(chan);
  122. return 0;
  123. }
  124. arch_initcall(sh7780_pci_init);