patch_nvhdmi.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for NVIDIA HDMI codecs
  5. *
  6. * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
  7. * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
  8. *
  9. *
  10. * This driver is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This driver is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/slab.h>
  27. #include <sound/core.h>
  28. #include "hda_codec.h"
  29. #include "hda_local.h"
  30. struct nvhdmi_spec {
  31. struct hda_multi_out multiout;
  32. struct hda_pcm pcm_rec;
  33. };
  34. static struct hda_verb nvhdmi_basic_init[] = {
  35. /* enable digital output on pin widget */
  36. { 0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  37. {} /* terminator */
  38. };
  39. /*
  40. * Controls
  41. */
  42. static int nvhdmi_build_controls(struct hda_codec *codec)
  43. {
  44. struct nvhdmi_spec *spec = codec->spec;
  45. int err;
  46. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  47. if (err < 0)
  48. return err;
  49. return 0;
  50. }
  51. static int nvhdmi_init(struct hda_codec *codec)
  52. {
  53. snd_hda_sequence_write(codec, nvhdmi_basic_init);
  54. return 0;
  55. }
  56. /*
  57. * Digital out
  58. */
  59. static int nvhdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  60. struct hda_codec *codec,
  61. struct snd_pcm_substream *substream)
  62. {
  63. struct nvhdmi_spec *spec = codec->spec;
  64. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  65. }
  66. static int nvhdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  67. struct hda_codec *codec,
  68. struct snd_pcm_substream *substream)
  69. {
  70. struct nvhdmi_spec *spec = codec->spec;
  71. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  72. }
  73. static int nvhdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  74. struct hda_codec *codec,
  75. unsigned int stream_tag,
  76. unsigned int format,
  77. struct snd_pcm_substream *substream)
  78. {
  79. struct nvhdmi_spec *spec = codec->spec;
  80. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  81. format, substream);
  82. }
  83. static struct hda_pcm_stream nvhdmi_pcm_digital_playback = {
  84. .substreams = 1,
  85. .channels_min = 2,
  86. .channels_max = 2,
  87. .nid = 0x4, /* NID to query formats and rates and setup streams */
  88. .rates = SNDRV_PCM_RATE_48000,
  89. .maxbps = 16,
  90. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  91. .ops = {
  92. .open = nvhdmi_dig_playback_pcm_open,
  93. .close = nvhdmi_dig_playback_pcm_close,
  94. .prepare = nvhdmi_dig_playback_pcm_prepare
  95. },
  96. };
  97. static int nvhdmi_build_pcms(struct hda_codec *codec)
  98. {
  99. struct nvhdmi_spec *spec = codec->spec;
  100. struct hda_pcm *info = &spec->pcm_rec;
  101. codec->num_pcms = 1;
  102. codec->pcm_info = info;
  103. info->name = "NVIDIA HDMI";
  104. info->pcm_type = HDA_PCM_TYPE_HDMI;
  105. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
  106. return 0;
  107. }
  108. static void nvhdmi_free(struct hda_codec *codec)
  109. {
  110. kfree(codec->spec);
  111. }
  112. static struct hda_codec_ops nvhdmi_patch_ops = {
  113. .build_controls = nvhdmi_build_controls,
  114. .build_pcms = nvhdmi_build_pcms,
  115. .init = nvhdmi_init,
  116. .free = nvhdmi_free,
  117. };
  118. static int patch_nvhdmi(struct hda_codec *codec)
  119. {
  120. struct nvhdmi_spec *spec;
  121. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  122. if (spec == NULL)
  123. return -ENOMEM;
  124. codec->spec = spec;
  125. spec->multiout.num_dacs = 0; /* no analog */
  126. spec->multiout.max_channels = 2;
  127. spec->multiout.dig_out_nid = 0x4; /* NID for copying analog to digital,
  128. * seems to be unused in pure-digital
  129. * case. */
  130. codec->patch_ops = nvhdmi_patch_ops;
  131. return 0;
  132. }
  133. /*
  134. * patch entries
  135. */
  136. static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
  137. { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi },
  138. { .id = 0x10de0006, .name = "MCP78 HDMI", .patch = patch_nvhdmi },
  139. { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi },
  140. { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi },
  141. { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi },
  142. {} /* terminator */
  143. };
  144. MODULE_ALIAS("snd-hda-codec-id:10de0002");
  145. MODULE_ALIAS("snd-hda-codec-id:10de0006");
  146. MODULE_ALIAS("snd-hda-codec-id:10de0007");
  147. MODULE_ALIAS("snd-hda-codec-id:10de0067");
  148. MODULE_ALIAS("snd-hda-codec-id:10de8001");
  149. MODULE_LICENSE("GPL");
  150. MODULE_DESCRIPTION("Nvidia HDMI HD-audio codec");
  151. static struct hda_codec_preset_list nvhdmi_list = {
  152. .preset = snd_hda_preset_nvhdmi,
  153. .owner = THIS_MODULE,
  154. };
  155. static int __init patch_nvhdmi_init(void)
  156. {
  157. return snd_hda_add_codec_preset(&nvhdmi_list);
  158. }
  159. static void __exit patch_nvhdmi_exit(void)
  160. {
  161. snd_hda_delete_codec_preset(&nvhdmi_list);
  162. }
  163. module_init(patch_nvhdmi_init)
  164. module_exit(patch_nvhdmi_exit)