pci_sh7751.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * SH7751 PCI Controller (PCIC) for U-Boot.
  3. * (C) Dustin McIntire (dustin@sensoria.com)
  4. * (C) 2007,2008 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <pci.h>
  26. #include <asm/processor.h>
  27. #include <asm/io.h>
  28. #include <asm/pci.h>
  29. /* Register addresses and such */
  30. #define SH7751_BCR1 (vu_long *)0xFF800000
  31. #define SH7751_BCR2 (vu_short *)0xFF800004
  32. #define SH7751_WCR1 (vu_long *)0xFF800008
  33. #define SH7751_WCR2 (vu_long *)0xFF80000C
  34. #define SH7751_WCR3 (vu_long *)0xFF800010
  35. #define SH7751_MCR (vu_long *)0xFF800014
  36. #define SH7751_BCR3 (vu_short *)0xFF800050
  37. #define SH7751_PCICONF0 (vu_long *)0xFE200000
  38. #define SH7751_PCICONF1 (vu_long *)0xFE200004
  39. #define SH7751_PCICONF2 (vu_long *)0xFE200008
  40. #define SH7751_PCICONF3 (vu_long *)0xFE20000C
  41. #define SH7751_PCICONF4 (vu_long *)0xFE200010
  42. #define SH7751_PCICONF5 (vu_long *)0xFE200014
  43. #define SH7751_PCICONF6 (vu_long *)0xFE200018
  44. #define SH7751_PCICR (vu_long *)0xFE200100
  45. #define SH7751_PCILSR0 (vu_long *)0xFE200104
  46. #define SH7751_PCILSR1 (vu_long *)0xFE200108
  47. #define SH7751_PCILAR0 (vu_long *)0xFE20010C
  48. #define SH7751_PCILAR1 (vu_long *)0xFE200110
  49. #define SH7751_PCIMBR (vu_long *)0xFE2001C4
  50. #define SH7751_PCIIOBR (vu_long *)0xFE2001C8
  51. #define SH7751_PCIPINT (vu_long *)0xFE2001CC
  52. #define SH7751_PCIPINTM (vu_long *)0xFE2001D0
  53. #define SH7751_PCICLKR (vu_long *)0xFE2001D4
  54. #define SH7751_PCIBCR1 (vu_long *)0xFE2001E0
  55. #define SH7751_PCIBCR2 (vu_long *)0xFE2001E4
  56. #define SH7751_PCIWCR1 (vu_long *)0xFE2001E8
  57. #define SH7751_PCIWCR2 (vu_long *)0xFE2001EC
  58. #define SH7751_PCIWCR3 (vu_long *)0xFE2001F0
  59. #define SH7751_PCIMCR (vu_long *)0xFE2001F4
  60. #define SH7751_PCIBCR3 (vu_long *)0xFE2001F8
  61. #define BCR1_BREQEN 0x00080000
  62. #define PCI_SH7751_ID 0x35051054
  63. #define PCI_SH7751R_ID 0x350E1054
  64. #define SH7751_PCICONF1_WCC 0x00000080
  65. #define SH7751_PCICONF1_PER 0x00000040
  66. #define SH7751_PCICONF1_BUM 0x00000004
  67. #define SH7751_PCICONF1_MES 0x00000002
  68. #define SH7751_PCICONF1_CMDS 0x000000C6
  69. #define SH7751_PCI_HOST_BRIDGE 0x6
  70. #define SH7751_PCICR_PREFIX 0xa5000000
  71. #define SH7751_PCICR_PRST 0x00000002
  72. #define SH7751_PCICR_CFIN 0x00000001
  73. #define SH7751_PCIPINT_D3 0x00000002
  74. #define SH7751_PCIPINT_D0 0x00000001
  75. #define SH7751_PCICLKR_PREFIX 0xa5000000
  76. #define SH7751_PCI_MEM_BASE 0xFD000000
  77. #define SH7751_PCI_MEM_SIZE 0x01000000
  78. #define SH7751_PCI_IO_BASE 0xFE240000
  79. #define SH7751_PCI_IO_SIZE 0x00040000
  80. #define SH7751_CS3_BASE_ADDR 0x0C000000
  81. #define SH7751_P2CS3_BASE_ADDR 0xAC000000
  82. #define SH7751_PCIPAR (vu_long *)0xFE2001C0
  83. #define SH7751_PCIPDR (vu_long *)0xFE200220
  84. #define p4_in(addr) (*addr)
  85. #define p4_out(data, addr) (*addr) = (data)
  86. /* Double word */
  87. int pci_sh4_read_config_dword(struct pci_controller *hose,
  88. pci_dev_t dev, int offset, u32 *value)
  89. {
  90. u32 par_data = 0x80000000 | dev;
  91. p4_out(par_data | (offset & 0xfc), SH7751_PCIPAR);
  92. *value = p4_in(SH7751_PCIPDR);
  93. return 0;
  94. }
  95. int pci_sh4_write_config_dword(struct pci_controller *hose,
  96. pci_dev_t dev, int offset, u32 value)
  97. {
  98. u32 par_data = 0x80000000 | dev;
  99. p4_out(par_data | (offset & 0xfc), SH7751_PCIPAR);
  100. p4_out(value, SH7751_PCIPDR);
  101. return 0;
  102. }
  103. int pci_sh7751_init(struct pci_controller *hose)
  104. {
  105. /* Double-check that we're a 7751 or 7751R chip */
  106. if (p4_in(SH7751_PCICONF0) != PCI_SH7751_ID
  107. && p4_in(SH7751_PCICONF0) != PCI_SH7751R_ID) {
  108. printf("PCI: Unknown PCI host bridge.\n");
  109. return 1;
  110. }
  111. printf("PCI: SH7751 PCI host bridge found.\n");
  112. /* Double-check some BSC config settings */
  113. /* (Area 3 non-MPX 32-bit, PCI bus pins) */
  114. if ((p4_in(SH7751_BCR1) & 0x20008) == 0x20000) {
  115. printf("SH7751_BCR1 value is wrong(0x%08X)\n",
  116. (unsigned int)p4_in(SH7751_BCR1));
  117. return 2;
  118. }
  119. if ((p4_in(SH7751_BCR2) & 0xC0) != 0xC0) {
  120. printf("SH7751_BCR2 value is wrong(0x%08X)\n",
  121. (unsigned int)p4_in(SH7751_BCR2));
  122. return 3;
  123. }
  124. if (p4_in(SH7751_BCR2) & 0x01) {
  125. printf("SH7751_BCR2 value is wrong(0x%08X)\n",
  126. (unsigned int)p4_in(SH7751_BCR2));
  127. return 4;
  128. }
  129. /* Force BREQEN in BCR1 to allow PCIC access */
  130. p4_out((p4_in(SH7751_BCR1) | BCR1_BREQEN), SH7751_BCR1);
  131. /* Toggle PCI reset pin */
  132. p4_out((SH7751_PCICR_PREFIX | SH7751_PCICR_PRST), SH7751_PCICR);
  133. udelay(32);
  134. p4_out(SH7751_PCICR_PREFIX, SH7751_PCICR);
  135. /* Set cmd bits: WCC, PER, BUM, MES */
  136. /* (Addr/Data stepping, Parity enabled, Bus Master, Memory enabled) */
  137. p4_out(0xfb900047, SH7751_PCICONF1); /* K.Kino */
  138. /* Define this host as the host bridge */
  139. p4_out((SH7751_PCI_HOST_BRIDGE << 24), SH7751_PCICONF2);
  140. /* Force PCI clock(s) on */
  141. p4_out(0, SH7751_PCICLKR);
  142. p4_out(0x03, SH7751_PCICLKR);
  143. /* Clear powerdown IRQs, also mask them (unused) */
  144. p4_out((SH7751_PCIPINT_D0 | SH7751_PCIPINT_D3), SH7751_PCIPINT);
  145. p4_out(0, SH7751_PCIPINTM);
  146. p4_out(0xab000001, SH7751_PCICONF4);
  147. /* Set up target memory mappings (for external DMA access) */
  148. /* Map both P0 and P2 range to Area 3 RAM for ease of use */
  149. p4_out((64 - 1) << 20, SH7751_PCILSR0);
  150. p4_out(SH7751_CS3_BASE_ADDR, SH7751_PCILAR0);
  151. p4_out(0, SH7751_PCILSR1);
  152. p4_out(0, SH7751_PCILAR1);
  153. p4_out(SH7751_CS3_BASE_ADDR, SH7751_PCICONF5);
  154. p4_out(0xd0000000, SH7751_PCICONF6);
  155. /* Map memory window to same address on PCI bus */
  156. p4_out(SH7751_PCI_MEM_BASE, SH7751_PCIMBR);
  157. /* Map IO window to same address on PCI bus */
  158. p4_out(0x2000 & 0xfffc0000, SH7751_PCIIOBR);
  159. /* set BREQEN */
  160. p4_out(inl(SH7751_BCR1) | 0x00080000, SH7751_BCR1);
  161. /* Copy BSC registers into PCI BSC */
  162. p4_out(inl(SH7751_BCR1), SH7751_PCIBCR1);
  163. p4_out(inl(SH7751_BCR2), SH7751_PCIBCR2);
  164. p4_out(inl(SH7751_BCR3), SH7751_PCIBCR3);
  165. p4_out(inl(SH7751_WCR1), SH7751_PCIWCR1);
  166. p4_out(inl(SH7751_WCR2), SH7751_PCIWCR2);
  167. p4_out(inl(SH7751_WCR3), SH7751_PCIWCR3);
  168. p4_out(inl(SH7751_MCR), SH7751_PCIMCR);
  169. /* Finally, set central function init complete */
  170. p4_out((SH7751_PCICR_PREFIX | SH7751_PCICR_CFIN), SH7751_PCICR);
  171. pci_sh4_init(hose);
  172. return 0;
  173. }