pcihost_wrapper.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Sonics Silicon Backplane
  3. * PCI Hostdevice wrapper
  4. *
  5. * Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
  6. * Copyright (c) 2005 Stefano Brivio <st3@riseup.net>
  7. * Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
  8. * Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  9. * Copyright (c) 2005-2007 Michael Buesch <m@bues.ch>
  10. *
  11. * Licensed under the GNU/GPL. See COPYING for details.
  12. */
  13. #include <linux/pci.h>
  14. #include <linux/export.h>
  15. #include <linux/slab.h>
  16. #include <linux/ssb/ssb.h>
  17. #ifdef CONFIG_PM
  18. static int ssb_pcihost_suspend(struct pci_dev *dev, pm_message_t state)
  19. {
  20. struct ssb_bus *ssb = pci_get_drvdata(dev);
  21. int err;
  22. err = ssb_bus_suspend(ssb);
  23. if (err)
  24. return err;
  25. pci_save_state(dev);
  26. pci_disable_device(dev);
  27. pci_set_power_state(dev, pci_choose_state(dev, state));
  28. return 0;
  29. }
  30. static int ssb_pcihost_resume(struct pci_dev *dev)
  31. {
  32. struct ssb_bus *ssb = pci_get_drvdata(dev);
  33. int err;
  34. pci_set_power_state(dev, 0);
  35. err = pci_enable_device(dev);
  36. if (err)
  37. return err;
  38. pci_restore_state(dev);
  39. err = ssb_bus_resume(ssb);
  40. if (err)
  41. return err;
  42. return 0;
  43. }
  44. #else /* CONFIG_PM */
  45. # define ssb_pcihost_suspend NULL
  46. # define ssb_pcihost_resume NULL
  47. #endif /* CONFIG_PM */
  48. static int __devinit ssb_pcihost_probe(struct pci_dev *dev,
  49. const struct pci_device_id *id)
  50. {
  51. struct ssb_bus *ssb;
  52. int err = -ENOMEM;
  53. const char *name;
  54. u32 val;
  55. ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
  56. if (!ssb)
  57. goto out;
  58. err = pci_enable_device(dev);
  59. if (err)
  60. goto err_kfree_ssb;
  61. name = dev_name(&dev->dev);
  62. if (dev->driver && dev->driver->name)
  63. name = dev->driver->name;
  64. err = pci_request_regions(dev, name);
  65. if (err)
  66. goto err_pci_disable;
  67. pci_set_master(dev);
  68. /* Disable the RETRY_TIMEOUT register (0x41) to keep
  69. * PCI Tx retries from interfering with C3 CPU state */
  70. pci_read_config_dword(dev, 0x40, &val);
  71. if ((val & 0x0000ff00) != 0)
  72. pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
  73. err = ssb_bus_pcibus_register(ssb, dev);
  74. if (err)
  75. goto err_pci_release_regions;
  76. pci_set_drvdata(dev, ssb);
  77. out:
  78. return err;
  79. err_pci_release_regions:
  80. pci_release_regions(dev);
  81. err_pci_disable:
  82. pci_disable_device(dev);
  83. err_kfree_ssb:
  84. kfree(ssb);
  85. return err;
  86. }
  87. static void ssb_pcihost_remove(struct pci_dev *dev)
  88. {
  89. struct ssb_bus *ssb = pci_get_drvdata(dev);
  90. ssb_bus_unregister(ssb);
  91. pci_release_regions(dev);
  92. pci_disable_device(dev);
  93. kfree(ssb);
  94. pci_set_drvdata(dev, NULL);
  95. }
  96. int __devinit ssb_pcihost_register(struct pci_driver *driver)
  97. {
  98. driver->probe = ssb_pcihost_probe;
  99. driver->remove = ssb_pcihost_remove;
  100. driver->suspend = ssb_pcihost_suspend;
  101. driver->resume = ssb_pcihost_resume;
  102. return pci_register_driver(driver);
  103. }
  104. EXPORT_SYMBOL(ssb_pcihost_register);