ac97_bus.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Linux driver model AC97 bus interface
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Jan 14, 2005
  6. * Copyright: (C) MontaVista Software Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/device.h>
  16. #include <linux/string.h>
  17. /*
  18. * Codec families have names seperated by commas, so we search for an
  19. * individual codec name within the family string.
  20. */
  21. static int ac97_bus_match(struct device *dev, struct device_driver *drv)
  22. {
  23. return (strstr(dev->bus_id, drv->name) != NULL);
  24. }
  25. static int ac97_bus_suspend(struct device *dev, pm_message_t state)
  26. {
  27. int ret = 0;
  28. if (dev->driver && dev->driver->suspend) {
  29. ret = dev->driver->suspend(dev, state, SUSPEND_DISABLE);
  30. if (ret == 0)
  31. ret = dev->driver->suspend(dev, state, SUSPEND_SAVE_STATE);
  32. if (ret == 0)
  33. ret = dev->driver->suspend(dev, state, SUSPEND_POWER_DOWN);
  34. }
  35. return ret;
  36. }
  37. static int ac97_bus_resume(struct device *dev)
  38. {
  39. int ret = 0;
  40. if (dev->driver && dev->driver->resume) {
  41. ret = dev->driver->resume(dev, RESUME_POWER_ON);
  42. if (ret == 0)
  43. ret = dev->driver->resume(dev, RESUME_RESTORE_STATE);
  44. if (ret == 0)
  45. ret = dev->driver->resume(dev, RESUME_ENABLE);
  46. }
  47. return ret;
  48. }
  49. struct bus_type ac97_bus_type = {
  50. .name = "ac97",
  51. .match = ac97_bus_match,
  52. .suspend = ac97_bus_suspend,
  53. .resume = ac97_bus_resume,
  54. };
  55. static int __init ac97_bus_init(void)
  56. {
  57. return bus_register(&ac97_bus_type);
  58. }
  59. subsys_initcall(ac97_bus_init);
  60. static void __exit ac97_bus_exit(void)
  61. {
  62. bus_unregister(&ac97_bus_type);
  63. }
  64. module_exit(ac97_bus_exit);
  65. EXPORT_SYMBOL(ac97_bus_type);
  66. MODULE_LICENSE("GPL");