pcihost_wrapper.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 <mbuesch@freenet.de>
  10. *
  11. * Licensed under the GNU/GPL. See COPYING for details.
  12. */
  13. #include <linux/pci.h>
  14. #include <linux/slab.h>
  15. #include <linux/ssb/ssb.h>
  16. #ifdef CONFIG_PM
  17. static int ssb_pcihost_suspend(struct pci_dev *dev, pm_message_t state)
  18. {
  19. struct ssb_bus *ssb = pci_get_drvdata(dev);
  20. int err;
  21. err = ssb_bus_suspend(ssb);
  22. if (err)
  23. return err;
  24. pci_save_state(dev);
  25. pci_disable_device(dev);
  26. pci_set_power_state(dev, pci_choose_state(dev, state));
  27. return 0;
  28. }
  29. static int ssb_pcihost_resume(struct pci_dev *dev)
  30. {
  31. struct ssb_bus *ssb = pci_get_drvdata(dev);
  32. int err;
  33. pci_set_power_state(dev, 0);
  34. err = pci_enable_device(dev);
  35. if (err)
  36. return err;
  37. pci_restore_state(dev);
  38. err = ssb_bus_resume(ssb);
  39. if (err)
  40. return err;
  41. return 0;
  42. }
  43. #else /* CONFIG_PM */
  44. # define ssb_pcihost_suspend NULL
  45. # define ssb_pcihost_resume NULL
  46. #endif /* CONFIG_PM */
  47. static int ssb_pcihost_probe(struct pci_dev *dev,
  48. const struct pci_device_id *id)
  49. {
  50. struct ssb_bus *ssb;
  51. int err = -ENOMEM;
  52. const char *name;
  53. u32 val;
  54. ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
  55. if (!ssb)
  56. goto out;
  57. err = pci_enable_device(dev);
  58. if (err)
  59. goto err_kfree_ssb;
  60. name = dev_name(&dev->dev);
  61. if (dev->driver && dev->driver->name)
  62. name = dev->driver->name;
  63. err = pci_request_regions(dev, name);
  64. if (err)
  65. goto err_pci_disable;
  66. pci_set_master(dev);
  67. /* Disable the RETRY_TIMEOUT register (0x41) to keep
  68. * PCI Tx retries from interfering with C3 CPU state */
  69. pci_read_config_dword(dev, 0x40, &val);
  70. if ((val & 0x0000ff00) != 0)
  71. pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
  72. err = ssb_bus_pcibus_register(ssb, dev);
  73. if (err)
  74. goto err_pci_release_regions;
  75. pci_set_drvdata(dev, ssb);
  76. out:
  77. return err;
  78. err_pci_release_regions:
  79. pci_release_regions(dev);
  80. err_pci_disable:
  81. pci_disable_device(dev);
  82. err_kfree_ssb:
  83. kfree(ssb);
  84. return err;
  85. }
  86. static void ssb_pcihost_remove(struct pci_dev *dev)
  87. {
  88. struct ssb_bus *ssb = pci_get_drvdata(dev);
  89. ssb_bus_unregister(ssb);
  90. pci_release_regions(dev);
  91. pci_disable_device(dev);
  92. kfree(ssb);
  93. pci_set_drvdata(dev, NULL);
  94. }
  95. int ssb_pcihost_register(struct pci_driver *driver)
  96. {
  97. driver->probe = ssb_pcihost_probe;
  98. driver->remove = ssb_pcihost_remove;
  99. driver->suspend = ssb_pcihost_suspend;
  100. driver->resume = ssb_pcihost_resume;
  101. return pci_register_driver(driver);
  102. }
  103. EXPORT_SYMBOL(ssb_pcihost_register);