snd_ac97_compat.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/list.h>
  9. #include <linux/slab.h>
  10. #include <sound/ac97/codec.h>
  11. #include <sound/ac97/compat.h>
  12. #include <sound/ac97/controller.h>
  13. #include <sound/soc.h>
  14. #include "ac97_core.h"
  15. static void compat_ac97_release(struct device *dev)
  16. {
  17. kfree(to_ac97_t(dev));
  18. }
  19. static void compat_ac97_reset(struct snd_ac97 *ac97)
  20. {
  21. struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
  22. struct ac97_controller *actrl = adev->ac97_ctrl;
  23. if (actrl->ops->reset)
  24. actrl->ops->reset(actrl);
  25. }
  26. static void compat_ac97_warm_reset(struct snd_ac97 *ac97)
  27. {
  28. struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
  29. struct ac97_controller *actrl = adev->ac97_ctrl;
  30. if (actrl->ops->warm_reset)
  31. actrl->ops->warm_reset(actrl);
  32. }
  33. static void compat_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
  34. unsigned short val)
  35. {
  36. struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
  37. struct ac97_controller *actrl = adev->ac97_ctrl;
  38. actrl->ops->write(actrl, ac97->num, reg, val);
  39. }
  40. static unsigned short compat_ac97_read(struct snd_ac97 *ac97,
  41. unsigned short reg)
  42. {
  43. struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
  44. struct ac97_controller *actrl = adev->ac97_ctrl;
  45. return actrl->ops->read(actrl, ac97->num, reg);
  46. }
  47. static struct snd_ac97_bus_ops compat_snd_ac97_bus_ops = {
  48. .reset = compat_ac97_reset,
  49. .warm_reset = compat_ac97_warm_reset,
  50. .write = compat_ac97_write,
  51. .read = compat_ac97_read,
  52. };
  53. static struct snd_ac97_bus compat_soc_ac97_bus = {
  54. .ops = &compat_snd_ac97_bus_ops,
  55. };
  56. struct snd_ac97 *snd_ac97_compat_alloc(struct ac97_codec_device *adev)
  57. {
  58. struct snd_ac97 *ac97;
  59. int ret;
  60. ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
  61. if (ac97 == NULL)
  62. return ERR_PTR(-ENOMEM);
  63. ac97->private_data = adev;
  64. ac97->bus = &compat_soc_ac97_bus;
  65. ac97->dev.parent = &adev->dev;
  66. ac97->dev.release = compat_ac97_release;
  67. dev_set_name(&ac97->dev, "%s-compat", dev_name(&adev->dev));
  68. ret = device_register(&ac97->dev);
  69. if (ret) {
  70. put_device(&ac97->dev);
  71. return ERR_PTR(ret);
  72. }
  73. return ac97;
  74. }
  75. EXPORT_SYMBOL_GPL(snd_ac97_compat_alloc);
  76. void snd_ac97_compat_release(struct snd_ac97 *ac97)
  77. {
  78. device_unregister(&ac97->dev);
  79. }
  80. EXPORT_SYMBOL_GPL(snd_ac97_compat_release);
  81. int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,
  82. unsigned int id_mask)
  83. {
  84. struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
  85. struct ac97_controller *actrl = adev->ac97_ctrl;
  86. unsigned int scanned;
  87. if (try_warm) {
  88. compat_ac97_warm_reset(ac97);
  89. scanned = snd_ac97_bus_scan_one(actrl, adev->num);
  90. if (ac97_ids_match(scanned, adev->vendor_id, id_mask))
  91. return 1;
  92. }
  93. compat_ac97_reset(ac97);
  94. compat_ac97_warm_reset(ac97);
  95. scanned = snd_ac97_bus_scan_one(actrl, adev->num);
  96. if (ac97_ids_match(scanned, adev->vendor_id, id_mask))
  97. return 0;
  98. return -ENODEV;
  99. }
  100. EXPORT_SYMBOL_GPL(snd_ac97_reset);