pci.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * (C) Copyright 2001
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/ppc4xx.h>
  9. #include <asm/processor.h>
  10. #include <pci.h>
  11. u_long pci9054_iobase;
  12. #define PCI_PRIMARY_CAR (0x500000dc) /* PCI config address reg */
  13. #define PCI_PRIMARY_CDR (0x80000000) /* PCI config data reg */
  14. /*-----------------------------------------------------------------------------+
  15. | Subroutine: pci9054_read_config_dword
  16. | Description: Read a PCI configuration register
  17. | Inputs:
  18. | hose PCI Controller
  19. | dev PCI Bus+Device+Function number
  20. | offset Configuration register number
  21. | value Address of the configuration register value
  22. | Return value:
  23. | 0 Successful
  24. +-----------------------------------------------------------------------------*/
  25. int pci9054_read_config_dword(struct pci_controller *hose,
  26. pci_dev_t dev, int offset, u32* value)
  27. {
  28. unsigned long conAdrVal;
  29. unsigned long val;
  30. /* generate coded value for CON_ADR register */
  31. conAdrVal = dev | (offset & 0xfc) | 0x80000000;
  32. /* Load the CON_ADR (CAR) value first, then read from CON_DATA (CDR) */
  33. *(unsigned long *)PCI_PRIMARY_CAR = conAdrVal;
  34. /* Note: *pResult comes back as -1 if machine check happened */
  35. val = in32r(PCI_PRIMARY_CDR);
  36. *value = (unsigned long) val;
  37. out32r(PCI_PRIMARY_CAR, 0);
  38. if ((*(unsigned long *)0x50000304) & 0x60000000)
  39. {
  40. /* clear pci master/target abort bits */
  41. *(unsigned long *)0x50000304 = *(unsigned long *)0x50000304;
  42. }
  43. return 0;
  44. }
  45. /*-----------------------------------------------------------------------------+
  46. | Subroutine: pci9054_write_config_dword
  47. | Description: Write a PCI configuration register.
  48. | Inputs:
  49. | hose PCI Controller
  50. | dev PCI Bus+Device+Function number
  51. | offset Configuration register number
  52. | Value Configuration register value
  53. | Return value:
  54. | 0 Successful
  55. | Updated for pass2 errata #6. Need to disable interrupts and clear the
  56. | PCICFGADR reg after writing the PCICFGDATA reg.
  57. +-----------------------------------------------------------------------------*/
  58. int pci9054_write_config_dword(struct pci_controller *hose,
  59. pci_dev_t dev, int offset, u32 value)
  60. {
  61. unsigned long conAdrVal;
  62. conAdrVal = dev | (offset & 0xfc) | 0x80000000;
  63. *(unsigned long *)PCI_PRIMARY_CAR = conAdrVal;
  64. out32r(PCI_PRIMARY_CDR, value);
  65. out32r(PCI_PRIMARY_CAR, 0);
  66. /* clear pci master/target abort bits */
  67. *(unsigned long *)0x50000304 = *(unsigned long *)0x50000304;
  68. return (0);
  69. }
  70. /*-----------------------------------------------------------------------
  71. */
  72. #ifdef CONFIG_DASA_SIM
  73. static void pci_dasa_sim_config_pci9054(struct pci_controller *hose, pci_dev_t dev,
  74. struct pci_config_table *_)
  75. {
  76. unsigned int iobase;
  77. unsigned short status = 0;
  78. unsigned char timer;
  79. /*
  80. * Configure PLX PCI9054
  81. */
  82. pci_read_config_word(CONFIG_SYS_PCI9054_DEV_FN, PCI_COMMAND, &status);
  83. status |= PCI_COMMAND_MASTER | PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
  84. pci_write_config_word(CONFIG_SYS_PCI9054_DEV_FN, PCI_COMMAND, status);
  85. /* Check the latency timer for values >= 0x60.
  86. */
  87. pci_read_config_byte(CONFIG_SYS_PCI9054_DEV_FN, PCI_LATENCY_TIMER, &timer);
  88. if (timer < 0x60)
  89. {
  90. pci_write_config_byte(CONFIG_SYS_PCI9054_DEV_FN, PCI_LATENCY_TIMER, 0x60);
  91. }
  92. /* Set I/O base register.
  93. */
  94. pci_write_config_dword(CONFIG_SYS_PCI9054_DEV_FN, PCI_BASE_ADDRESS_0, CONFIG_SYS_PCI9054_IOBASE);
  95. pci_read_config_dword(CONFIG_SYS_PCI9054_DEV_FN, PCI_BASE_ADDRESS_0, &iobase);
  96. pci9054_iobase = pci_mem_to_phys(CONFIG_SYS_PCI9054_DEV_FN, iobase & PCI_BASE_ADDRESS_MEM_MASK);
  97. if (pci9054_iobase == 0xffffffff)
  98. {
  99. printf("Error: Can not set I/O base register.\n");
  100. return;
  101. }
  102. }
  103. #endif
  104. static struct pci_config_table pci9054_config_table[] = {
  105. #ifndef CONFIG_PCI_PNP
  106. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  107. PCI_BUS(CONFIG_SYS_ETH_DEV_FN), PCI_DEV(CONFIG_SYS_ETH_DEV_FN), PCI_FUNC(CONFIG_SYS_ETH_DEV_FN),
  108. pci_cfgfunc_config_device, { CONFIG_SYS_ETH_IOBASE,
  109. CONFIG_SYS_ETH_IOBASE,
  110. PCI_COMMAND_IO | PCI_COMMAND_MASTER }},
  111. #ifdef CONFIG_DASA_SIM
  112. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  113. PCI_BUS(CONFIG_SYS_PCI9054_DEV_FN), PCI_DEV(CONFIG_SYS_PCI9054_DEV_FN), PCI_FUNC(CONFIG_SYS_PCI9054_DEV_FN),
  114. pci_dasa_sim_config_pci9054 },
  115. #endif
  116. #endif
  117. { }
  118. };
  119. static struct pci_controller pci9054_hose = {
  120. config_table: pci9054_config_table,
  121. };
  122. void pci_init_board(void)
  123. {
  124. struct pci_controller *hose = &pci9054_hose;
  125. /*
  126. * Register the hose
  127. */
  128. hose->first_busno = 0;
  129. hose->last_busno = 0xff;
  130. /* System memory space */
  131. pci_set_region(hose->regions + 0,
  132. 0x00000000, 0x00000000, 0x01000000,
  133. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  134. /* PCI Memory space */
  135. pci_set_region(hose->regions + 1,
  136. 0x00000000, 0xc0000000, 0x10000000,
  137. PCI_REGION_MEM);
  138. pci_set_ops(hose,
  139. pci_hose_read_config_byte_via_dword,
  140. pci_hose_read_config_word_via_dword,
  141. pci9054_read_config_dword,
  142. pci_hose_write_config_byte_via_dword,
  143. pci_hose_write_config_word_via_dword,
  144. pci9054_write_config_dword);
  145. hose->region_count = 2;
  146. pci_register_hose(hose);
  147. hose->last_busno = pci_hose_scan(hose);
  148. }