ac97_bus.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #include <sound/ac97_codec.h>
  18. /*
  19. * snd_ac97_check_id() - Reads and checks the vendor ID of the device
  20. * @ac97: The AC97 device to check
  21. * @id: The ID to compare to
  22. * @id_mask: Mask that is applied to the device ID before comparing to @id
  23. *
  24. * If @id is 0 this function returns true if the read device vendor ID is
  25. * a valid ID. If @id is non 0 this functions returns true if @id
  26. * matches the read vendor ID. Otherwise the function returns false.
  27. */
  28. static bool snd_ac97_check_id(struct snd_ac97 *ac97, unsigned int id,
  29. unsigned int id_mask)
  30. {
  31. ac97->id = ac97->bus->ops->read(ac97, AC97_VENDOR_ID1) << 16;
  32. ac97->id |= ac97->bus->ops->read(ac97, AC97_VENDOR_ID2);
  33. if (ac97->id == 0x0 || ac97->id == 0xffffffff)
  34. return false;
  35. if (id != 0 && id != (ac97->id & id_mask))
  36. return false;
  37. return true;
  38. }
  39. /**
  40. * snd_ac97_reset() - Reset AC'97 device
  41. * @ac97: The AC'97 device to reset
  42. * @try_warm: Try a warm reset first
  43. * @id: Expected device vendor ID
  44. * @id_mask: Mask that is applied to the device ID before comparing to @id
  45. *
  46. * This function resets the AC'97 device. If @try_warm is true the function
  47. * first performs a warm reset. If the warm reset is successful the function
  48. * returns 1. Otherwise or if @try_warm is false the function issues cold reset
  49. * followed by a warm reset. If this is successful the function returns 0,
  50. * otherwise a negative error code. If @id is 0 any valid device ID will be
  51. * accepted, otherwise only the ID that matches @id and @id_mask is accepted.
  52. */
  53. int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,
  54. unsigned int id_mask)
  55. {
  56. struct snd_ac97_bus_ops *ops = ac97->bus->ops;
  57. if (try_warm && ops->warm_reset) {
  58. ops->warm_reset(ac97);
  59. if (snd_ac97_check_id(ac97, id, id_mask))
  60. return 1;
  61. }
  62. if (ops->reset)
  63. ops->reset(ac97);
  64. if (ops->warm_reset)
  65. ops->warm_reset(ac97);
  66. if (snd_ac97_check_id(ac97, id, id_mask))
  67. return 0;
  68. return -ENODEV;
  69. }
  70. EXPORT_SYMBOL_GPL(snd_ac97_reset);
  71. /*
  72. * Let drivers decide whether they want to support given codec from their
  73. * probe method. Drivers have direct access to the struct snd_ac97
  74. * structure and may decide based on the id field amongst other things.
  75. */
  76. static int ac97_bus_match(struct device *dev, struct device_driver *drv)
  77. {
  78. return 1;
  79. }
  80. struct bus_type ac97_bus_type = {
  81. .name = "ac97",
  82. .match = ac97_bus_match,
  83. };
  84. static int __init ac97_bus_init(void)
  85. {
  86. return bus_register(&ac97_bus_type);
  87. }
  88. subsys_initcall(ac97_bus_init);
  89. static void __exit ac97_bus_exit(void)
  90. {
  91. bus_unregister(&ac97_bus_type);
  92. }
  93. module_exit(ac97_bus_exit);
  94. EXPORT_SYMBOL(ac97_bus_type);
  95. MODULE_LICENSE("GPL");