pci_mpc85xx.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * (C) Copyright 2019
  4. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  5. *
  6. */
  7. #include <common.h>
  8. #include <asm/bitops.h>
  9. #include <asm/cpm_85xx.h>
  10. #include <pci.h>
  11. #include <dm.h>
  12. #include <asm/fsl_law.h>
  13. struct mpc85xx_pci_priv {
  14. void __iomem *cfg_addr;
  15. void __iomem *cfg_data;
  16. };
  17. static int mpc85xx_pci_dm_read_config(const struct udevice *dev, pci_dev_t bdf,
  18. uint offset, ulong *value,
  19. enum pci_size_t size)
  20. {
  21. struct mpc85xx_pci_priv *priv = dev_get_priv(dev);
  22. u32 addr;
  23. addr = bdf | (offset & 0xfc) | ((offset & 0xf00) << 16) | 0x80000000;
  24. out_be32(priv->cfg_addr, addr);
  25. sync();
  26. *value = pci_conv_32_to_size(in_le32(priv->cfg_data), offset, size);
  27. return 0;
  28. }
  29. static int mpc85xx_pci_dm_write_config(struct udevice *dev, pci_dev_t bdf,
  30. uint offset, ulong value,
  31. enum pci_size_t size)
  32. {
  33. struct mpc85xx_pci_priv *priv = dev_get_priv(dev);
  34. u32 addr;
  35. addr = bdf | (offset & 0xfc) | ((offset & 0xf00) << 16) | 0x80000000;
  36. out_be32(priv->cfg_addr, addr);
  37. sync();
  38. out_le32(priv->cfg_data, pci_conv_size_to_32(0, value, offset, size));
  39. return 0;
  40. }
  41. static int
  42. mpc85xx_pci_dm_setup_laws(struct pci_region *io, struct pci_region *mem,
  43. struct pci_region *pre)
  44. {
  45. /*
  46. * Unfortunately we have defines for this addresse,
  47. * as we have to setup the TLB, and at this stage
  48. * we have no access to DT ... may we check here
  49. * if the value in the define is the same ?
  50. */
  51. if (mem)
  52. set_next_law(mem->phys_start, law_size_bits(mem->size),
  53. LAW_TRGT_IF_PCI);
  54. if (io)
  55. set_next_law(io->phys_start, law_size_bits(io->size),
  56. LAW_TRGT_IF_PCI);
  57. if (pre)
  58. set_next_law(pre->phys_start, law_size_bits(pre->size),
  59. LAW_TRGT_IF_PCI);
  60. return 0;
  61. }
  62. static int mpc85xx_pci_dm_probe(struct udevice *dev)
  63. {
  64. struct mpc85xx_pci_priv *priv = dev_get_priv(dev);
  65. struct pci_region *io;
  66. struct pci_region *mem;
  67. struct pci_region *pre;
  68. int count;
  69. ccsr_pcix_t *pcix;
  70. count = pci_get_regions(dev, &io, &mem, &pre);
  71. if (count != 2) {
  72. printf("%s: wrong count of regions %d only 2 allowed\n",
  73. __func__, count);
  74. return -EINVAL;
  75. }
  76. mpc85xx_pci_dm_setup_laws(io, mem, pre);
  77. pcix = priv->cfg_addr;
  78. /* BAR 1: memory */
  79. out_be32(&pcix->potar1, (mem->bus_start >> 12) & 0x000fffff);
  80. out_be32(&pcix->potear1, 0);
  81. out_be32(&pcix->powbar1, (mem->phys_start >> 12) & 0x000fffff);
  82. out_be32(&pcix->powbear1, 0);
  83. out_be32(&pcix->powar1, (POWAR_EN | POWAR_MEM_READ |
  84. POWAR_MEM_WRITE | (__ilog2(mem->size) - 1)));
  85. /* BAR 1: IO */
  86. out_be32(&pcix->potar2, (io->bus_start >> 12) & 0x000fffff);
  87. out_be32(&pcix->potear2, 0);
  88. out_be32(&pcix->powbar2, (io->phys_start >> 12) & 0x000fffff);
  89. out_be32(&pcix->powbear2, 0);
  90. out_be32(&pcix->powar2, (POWAR_EN | POWAR_IO_READ |
  91. POWAR_IO_WRITE | (__ilog2(io->size) - 1)));
  92. out_be32(&pcix->pitar1, 0);
  93. out_be32(&pcix->piwbar1, 0);
  94. out_be32(&pcix->piwar1, (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
  95. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G));
  96. out_be32(&pcix->powar3, 0);
  97. out_be32(&pcix->powar4, 0);
  98. out_be32(&pcix->piwar2, 0);
  99. out_be32(&pcix->piwar3, 0);
  100. return 0;
  101. }
  102. static int mpc85xx_pci_dm_remove(struct udevice *dev)
  103. {
  104. return 0;
  105. }
  106. static int mpc85xx_pci_ofdata_to_platdata(struct udevice *dev)
  107. {
  108. struct mpc85xx_pci_priv *priv = dev_get_priv(dev);
  109. fdt_addr_t addr;
  110. addr = devfdt_get_addr_index(dev, 0);
  111. if (addr == FDT_ADDR_T_NONE)
  112. return -EINVAL;
  113. priv->cfg_addr = (void __iomem *)addr;
  114. addr += 4;
  115. priv->cfg_data = (void __iomem *)addr;
  116. return 0;
  117. }
  118. static const struct dm_pci_ops mpc85xx_pci_ops = {
  119. .read_config = mpc85xx_pci_dm_read_config,
  120. .write_config = mpc85xx_pci_dm_write_config,
  121. };
  122. static const struct udevice_id mpc85xx_pci_ids[] = {
  123. { .compatible = "fsl,mpc8540-pci" },
  124. { }
  125. };
  126. U_BOOT_DRIVER(mpc85xx_pci) = {
  127. .name = "mpc85xx_pci",
  128. .id = UCLASS_PCI,
  129. .of_match = mpc85xx_pci_ids,
  130. .ops = &mpc85xx_pci_ops,
  131. .probe = mpc85xx_pci_dm_probe,
  132. .remove = mpc85xx_pci_dm_remove,
  133. .ofdata_to_platdata = mpc85xx_pci_ofdata_to_platdata,
  134. .priv_auto_alloc_size = sizeof(struct mpc85xx_pci_priv),
  135. };