pcihost_wrapper.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Sonics Silicon Backplane
  3. * PCI Hostdevice wrapper
  4. *
  5. * Copyright (c) 2005 Martin Langer <[email protected]>
  6. * Copyright (c) 2005 Stefano Brivio <[email protected]>
  7. * Copyright (c) 2005 Danny van Dyk <[email protected]>
  8. * Copyright (c) 2005 Andreas Jaggi <[email protected]>
  9. * Copyright (c) 2005-2007 Michael Buesch <[email protected]>
  10. *
  11. * Licensed under the GNU/GPL. See COPYING for details.
  12. */
  13. #include <linux/pm.h>
  14. #include <linux/pci.h>
  15. #include <linux/export.h>
  16. #include <linux/slab.h>
  17. #include <linux/ssb/ssb.h>
  18. #ifdef CONFIG_PM_SLEEP
  19. static int ssb_pcihost_suspend(struct device *d)
  20. {
  21. struct pci_dev *dev = to_pci_dev(d);
  22. struct ssb_bus *ssb = pci_get_drvdata(dev);
  23. int err;
  24. err = ssb_bus_suspend(ssb);
  25. if (err)
  26. return err;
  27. pci_save_state(dev);
  28. pci_disable_device(dev);
  29. /* if there is a wakeup enabled child device on ssb bus,
  30. enable pci wakeup posibility. */
  31. device_set_wakeup_enable(d, d->power.wakeup_path);
  32. pci_prepare_to_sleep(dev);
  33. return 0;
  34. }
  35. static int ssb_pcihost_resume(struct device *d)
  36. {
  37. struct pci_dev *dev = to_pci_dev(d);
  38. struct ssb_bus *ssb = pci_get_drvdata(dev);
  39. int err;
  40. pci_back_from_sleep(dev);
  41. err = pci_enable_device(dev);
  42. if (err)
  43. return err;
  44. pci_restore_state(dev);
  45. err = ssb_bus_resume(ssb);
  46. if (err)
  47. return err;
  48. return 0;
  49. }
  50. static const struct dev_pm_ops ssb_pcihost_pm_ops = {
  51. SET_SYSTEM_SLEEP_PM_OPS(ssb_pcihost_suspend, ssb_pcihost_resume)
  52. };
  53. #endif /* CONFIG_PM_SLEEP */
  54. static int ssb_pcihost_probe(struct pci_dev *dev,
  55. const struct pci_device_id *id)
  56. {
  57. struct ssb_bus *ssb;
  58. int err = -ENOMEM;
  59. u32 val;
  60. ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
  61. if (!ssb)
  62. goto out;
  63. err = pci_enable_device(dev);
  64. if (err)
  65. goto err_kfree_ssb;
  66. err = pci_request_regions(dev, dev_driver_string(&dev->dev));
  67. if (err)
  68. goto err_pci_disable;
  69. pci_set_master(dev);
  70. /* Disable the RETRY_TIMEOUT register (0x41) to keep
  71. * PCI Tx retries from interfering with C3 CPU state */
  72. pci_read_config_dword(dev, 0x40, &val);
  73. if ((val & 0x0000ff00) != 0)
  74. pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
  75. err = ssb_bus_pcibus_register(ssb, dev);
  76. if (err)
  77. goto err_pci_release_regions;
  78. pci_set_drvdata(dev, ssb);
  79. out:
  80. return err;
  81. err_pci_release_regions:
  82. pci_release_regions(dev);
  83. err_pci_disable:
  84. pci_disable_device(dev);
  85. err_kfree_ssb:
  86. kfree(ssb);
  87. return err;
  88. }
  89. static void ssb_pcihost_remove(struct pci_dev *dev)
  90. {
  91. struct ssb_bus *ssb = pci_get_drvdata(dev);
  92. ssb_bus_unregister(ssb);
  93. pci_release_regions(dev);
  94. pci_disable_device(dev);
  95. kfree(ssb);
  96. pci_set_drvdata(dev, NULL);
  97. }
  98. int ssb_pcihost_register(struct pci_driver *driver)
  99. {
  100. driver->probe = ssb_pcihost_probe;
  101. driver->remove = ssb_pcihost_remove;
  102. #ifdef CONFIG_PM_SLEEP
  103. driver->driver.pm = &ssb_pcihost_pm_ops;
  104. #endif
  105. return pci_register_driver(driver);
  106. }
  107. EXPORT_SYMBOL(ssb_pcihost_register);