pcihost_wrapper.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/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. const char *name;
  60. u32 val;
  61. ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
  62. if (!ssb)
  63. goto out;
  64. err = pci_enable_device(dev);
  65. if (err)
  66. goto err_kfree_ssb;
  67. name = dev_name(&dev->dev);
  68. if (dev->driver && dev->driver->name)
  69. name = dev->driver->name;
  70. err = pci_request_regions(dev, name);
  71. if (err)
  72. goto err_pci_disable;
  73. pci_set_master(dev);
  74. /* Disable the RETRY_TIMEOUT register (0x41) to keep
  75. * PCI Tx retries from interfering with C3 CPU state */
  76. pci_read_config_dword(dev, 0x40, &val);
  77. if ((val & 0x0000ff00) != 0)
  78. pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
  79. err = ssb_bus_pcibus_register(ssb, dev);
  80. if (err)
  81. goto err_pci_release_regions;
  82. pci_set_drvdata(dev, ssb);
  83. out:
  84. return err;
  85. err_pci_release_regions:
  86. pci_release_regions(dev);
  87. err_pci_disable:
  88. pci_disable_device(dev);
  89. err_kfree_ssb:
  90. kfree(ssb);
  91. return err;
  92. }
  93. static void ssb_pcihost_remove(struct pci_dev *dev)
  94. {
  95. struct ssb_bus *ssb = pci_get_drvdata(dev);
  96. ssb_bus_unregister(ssb);
  97. pci_release_regions(dev);
  98. pci_disable_device(dev);
  99. kfree(ssb);
  100. pci_set_drvdata(dev, NULL);
  101. }
  102. int ssb_pcihost_register(struct pci_driver *driver)
  103. {
  104. driver->probe = ssb_pcihost_probe;
  105. driver->remove = ssb_pcihost_remove;
  106. #ifdef CONFIG_PM_SLEEP
  107. driver->driver.pm = &ssb_pcihost_pm_ops;
  108. #endif
  109. return pci_register_driver(driver);
  110. }
  111. EXPORT_SYMBOL(ssb_pcihost_register);