ac97_plugin_ad1980.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. ac97_plugin_ad1980.c Copyright (C) 2003 Red Hat, Inc. All rights reserved.
  3. The contents of this file are subject to the Open Software License version 1.1
  4. that can be found at http://www.opensource.org/licenses/osl-1.1.txt and is
  5. included herein by reference.
  6. Alternatively, the contents of this file may be used under the
  7. terms of the GNU General Public License version 2 (the "GPL") as
  8. distributed in the kernel source COPYING file, in which
  9. case the provisions of the GPL are applicable instead of the
  10. above. If you wish to allow the use of your version of this file
  11. only under the terms of the GPL and not to allow others to use
  12. your version of this file under the OSL, indicate your decision
  13. by deleting the provisions above and replace them with the notice
  14. and other provisions required by the GPL. If you do not delete
  15. the provisions above, a recipient may use your version of this
  16. file under either the OSL or the GPL.
  17. Authors: Alan Cox <alan@redhat.com>
  18. This is an example codec plugin. This one switches the connections
  19. around to match the setups some vendors use with audio switched to
  20. non standard front connectors not the normal rear ones
  21. This code primarily exists to demonstrate how to use the codec
  22. interface
  23. */
  24. #include <linux/config.h>
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/kernel.h>
  28. #include <linux/ac97_codec.h>
  29. /**
  30. * ad1980_remove - codec remove callback
  31. * @codec: The codec that is being removed
  32. *
  33. * This callback occurs when an AC97 codec is being removed. A
  34. * codec remove call will not occur for a codec during that codec
  35. * probe callback.
  36. *
  37. * Most drivers will need to lock their remove versus their
  38. * use of the codec after the probe function.
  39. */
  40. static void __devexit ad1980_remove(struct ac97_codec *codec, struct ac97_driver *driver)
  41. {
  42. /* Nothing to do in the simple example */
  43. }
  44. /**
  45. * ad1980_probe - codec found callback
  46. * @codec: ac97 codec matching the idents
  47. * @driver: ac97_driver it matched
  48. *
  49. * This entry point is called when a codec is found which matches
  50. * the driver. At the point it is called the codec is basically
  51. * operational, mixer operations have been initialised and can
  52. * be overriden. Called in process context. The field driver_private
  53. * is available for the driver to use to store stuff.
  54. *
  55. * The caller can claim the device by returning zero, or return
  56. * a negative error code.
  57. */
  58. static int ad1980_probe(struct ac97_codec *codec, struct ac97_driver *driver)
  59. {
  60. u16 control;
  61. #define AC97_AD_MISC 0x76
  62. /* Switch the inputs/outputs over (from Dell code) */
  63. control = codec->codec_read(codec, AC97_AD_MISC);
  64. codec->codec_write(codec, AC97_AD_MISC, control | 0x4420);
  65. /* We could refuse the device since we dont need to hang around,
  66. but we will claim it */
  67. return 0;
  68. }
  69. static struct ac97_driver ad1980_driver = {
  70. .codec_id = 0x41445370,
  71. .codec_mask = 0xFFFFFFFF,
  72. .name = "AD1980 example",
  73. .probe = ad1980_probe,
  74. .remove = __devexit_p(ad1980_remove),
  75. };
  76. /**
  77. * ad1980_exit - module exit path
  78. *
  79. * Our module is being unloaded. At this point unregister_driver
  80. * will call back our remove handler for any existing codecs. You
  81. * may not unregister_driver from interrupt context or from a
  82. * probe/remove callback.
  83. */
  84. static void ad1980_exit(void)
  85. {
  86. ac97_unregister_driver(&ad1980_driver);
  87. }
  88. /**
  89. * ad1980_init - set up ad1980 handlers
  90. *
  91. * After we call the register function it will call our probe
  92. * function for each existing matching device before returning to us.
  93. * Any devices appearing afterwards whose id's match the codec_id
  94. * will also cause the probe function to be called.
  95. * You may not register_driver from interrupt context or from a
  96. * probe/remove callback.
  97. */
  98. static int ad1980_init(void)
  99. {
  100. return ac97_register_driver(&ad1980_driver);
  101. }
  102. module_init(ad1980_init);
  103. module_exit(ad1980_exit);
  104. MODULE_LICENSE("GPL");