host_pci.c 4.8 KB

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