host_pci.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Broadcom specific AMBA
  3. * PCI Host
  4. *
  5. * Licensed under the GNU/GPL. See COPYING for details.
  6. */
  7. #include "bcma_private.h"
  8. #include <linux/bcma/bcma.h>
  9. #include <linux/pci.h>
  10. static void bcma_host_pci_switch_core(struct bcma_device *core)
  11. {
  12. pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN,
  13. core->addr);
  14. pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN2,
  15. core->wrap);
  16. core->bus->mapped_core = core;
  17. pr_debug("Switched to core: 0x%X\n", core->id.id);
  18. }
  19. static u8 bcma_host_pci_read8(struct bcma_device *core, u16 offset)
  20. {
  21. if (core->bus->mapped_core != core)
  22. bcma_host_pci_switch_core(core);
  23. return ioread8(core->bus->mmio + offset);
  24. }
  25. static u16 bcma_host_pci_read16(struct bcma_device *core, u16 offset)
  26. {
  27. if (core->bus->mapped_core != core)
  28. bcma_host_pci_switch_core(core);
  29. return ioread16(core->bus->mmio + offset);
  30. }
  31. static u32 bcma_host_pci_read32(struct bcma_device *core, u16 offset)
  32. {
  33. if (core->bus->mapped_core != core)
  34. bcma_host_pci_switch_core(core);
  35. return ioread32(core->bus->mmio + offset);
  36. }
  37. static void bcma_host_pci_write8(struct bcma_device *core, u16 offset,
  38. u8 value)
  39. {
  40. if (core->bus->mapped_core != core)
  41. bcma_host_pci_switch_core(core);
  42. iowrite8(value, core->bus->mmio + offset);
  43. }
  44. static void bcma_host_pci_write16(struct bcma_device *core, u16 offset,
  45. u16 value)
  46. {
  47. if (core->bus->mapped_core != core)
  48. bcma_host_pci_switch_core(core);
  49. iowrite16(value, core->bus->mmio + offset);
  50. }
  51. static void bcma_host_pci_write32(struct bcma_device *core, u16 offset,
  52. u32 value)
  53. {
  54. if (core->bus->mapped_core != core)
  55. bcma_host_pci_switch_core(core);
  56. iowrite32(value, core->bus->mmio + offset);
  57. }
  58. static u32 bcma_host_pci_aread32(struct bcma_device *core, u16 offset)
  59. {
  60. if (core->bus->mapped_core != core)
  61. bcma_host_pci_switch_core(core);
  62. return ioread32(core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
  63. }
  64. static void bcma_host_pci_awrite32(struct bcma_device *core, u16 offset,
  65. u32 value)
  66. {
  67. if (core->bus->mapped_core != core)
  68. bcma_host_pci_switch_core(core);
  69. iowrite32(value, core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
  70. }
  71. const struct bcma_host_ops bcma_host_pci_ops = {
  72. .read8 = bcma_host_pci_read8,
  73. .read16 = bcma_host_pci_read16,
  74. .read32 = bcma_host_pci_read32,
  75. .write8 = bcma_host_pci_write8,
  76. .write16 = bcma_host_pci_write16,
  77. .write32 = bcma_host_pci_write32,
  78. .aread32 = bcma_host_pci_aread32,
  79. .awrite32 = bcma_host_pci_awrite32,
  80. };
  81. static int bcma_host_pci_probe(struct pci_dev *dev,
  82. const struct pci_device_id *id)
  83. {
  84. struct bcma_bus *bus;
  85. int err = -ENOMEM;
  86. const char *name;
  87. u32 val;
  88. /* Alloc */
  89. bus = kzalloc(sizeof(*bus), GFP_KERNEL);
  90. if (!bus)
  91. goto out;
  92. /* Basic PCI configuration */
  93. err = pci_enable_device(dev);
  94. if (err)
  95. goto err_kfree_bus;
  96. name = dev_name(&dev->dev);
  97. if (dev->driver && dev->driver->name)
  98. name = dev->driver->name;
  99. err = pci_request_regions(dev, name);
  100. if (err)
  101. goto err_pci_disable;
  102. pci_set_master(dev);
  103. /* Disable the RETRY_TIMEOUT register (0x41) to keep
  104. * PCI Tx retries from interfering with C3 CPU state */
  105. pci_read_config_dword(dev, 0x40, &val);
  106. if ((val & 0x0000ff00) != 0)
  107. pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
  108. /* SSB needed additional powering up, do we have any AMBA PCI cards? */
  109. if (!pci_is_pcie(dev))
  110. pr_err("PCI card detected, report problems.\n");
  111. /* Map MMIO */
  112. err = -ENOMEM;
  113. bus->mmio = pci_iomap(dev, 0, ~0UL);
  114. if (!bus->mmio)
  115. goto err_pci_release_regions;
  116. /* Host specific */
  117. bus->host_pci = dev;
  118. bus->hosttype = BCMA_HOSTTYPE_PCI;
  119. bus->ops = &bcma_host_pci_ops;
  120. /* Register */
  121. err = bcma_bus_register(bus);
  122. if (err)
  123. goto err_pci_unmap_mmio;
  124. pci_set_drvdata(dev, bus);
  125. out:
  126. return err;
  127. err_pci_unmap_mmio:
  128. pci_iounmap(dev, bus->mmio);
  129. err_pci_release_regions:
  130. pci_release_regions(dev);
  131. err_pci_disable:
  132. pci_disable_device(dev);
  133. err_kfree_bus:
  134. kfree(bus);
  135. return err;
  136. }
  137. static void bcma_host_pci_remove(struct pci_dev *dev)
  138. {
  139. struct bcma_bus *bus = pci_get_drvdata(dev);
  140. bcma_bus_unregister(bus);
  141. pci_iounmap(dev, bus->mmio);
  142. pci_release_regions(dev);
  143. pci_disable_device(dev);
  144. kfree(bus);
  145. pci_set_drvdata(dev, NULL);
  146. }
  147. static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
  148. { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4331) },
  149. { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) },
  150. { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) },
  151. { 0, },
  152. };
  153. MODULE_DEVICE_TABLE(pci, bcma_pci_bridge_tbl);
  154. static struct pci_driver bcma_pci_bridge_driver = {
  155. .name = "bcma-pci-bridge",
  156. .id_table = bcma_pci_bridge_tbl,
  157. .probe = bcma_host_pci_probe,
  158. .remove = bcma_host_pci_remove,
  159. };
  160. int __init bcma_host_pci_init(void)
  161. {
  162. return pci_register_driver(&bcma_pci_bridge_driver);
  163. }
  164. void __exit bcma_host_pci_exit(void)
  165. {
  166. pci_unregister_driver(&bcma_pci_bridge_driver);
  167. }