patch_nvhdmi.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #include "hda_patch.h"
  31. struct nvhdmi_spec {
  32. struct hda_multi_out multiout;
  33. struct hda_pcm pcm_rec;
  34. };
  35. static struct hda_verb nvhdmi_basic_init[] = {
  36. /* enable digital output on pin widget */
  37. { 0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  38. {} /* terminator */
  39. };
  40. /*
  41. * Controls
  42. */
  43. static int nvhdmi_build_controls(struct hda_codec *codec)
  44. {
  45. struct nvhdmi_spec *spec = codec->spec;
  46. int err;
  47. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  48. if (err < 0)
  49. return err;
  50. return 0;
  51. }
  52. static int nvhdmi_init(struct hda_codec *codec)
  53. {
  54. snd_hda_sequence_write(codec, nvhdmi_basic_init);
  55. return 0;
  56. }
  57. /*
  58. * Digital out
  59. */
  60. static int nvhdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  61. struct hda_codec *codec,
  62. struct snd_pcm_substream *substream)
  63. {
  64. struct nvhdmi_spec *spec = codec->spec;
  65. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  66. }
  67. static int nvhdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  68. struct hda_codec *codec,
  69. struct snd_pcm_substream *substream)
  70. {
  71. struct nvhdmi_spec *spec = codec->spec;
  72. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  73. }
  74. static int nvhdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  75. struct hda_codec *codec,
  76. unsigned int stream_tag,
  77. unsigned int format,
  78. struct snd_pcm_substream *substream)
  79. {
  80. struct nvhdmi_spec *spec = codec->spec;
  81. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  82. format, substream);
  83. }
  84. static struct hda_pcm_stream nvhdmi_pcm_digital_playback = {
  85. .substreams = 1,
  86. .channels_min = 2,
  87. .channels_max = 2,
  88. .nid = 0x4, /* NID to query formats and rates and setup streams */
  89. .rates = SNDRV_PCM_RATE_48000,
  90. .maxbps = 16,
  91. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  92. .ops = {
  93. .open = nvhdmi_dig_playback_pcm_open,
  94. .close = nvhdmi_dig_playback_pcm_close,
  95. .prepare = nvhdmi_dig_playback_pcm_prepare
  96. },
  97. };
  98. static int nvhdmi_build_pcms(struct hda_codec *codec)
  99. {
  100. struct nvhdmi_spec *spec = codec->spec;
  101. struct hda_pcm *info = &spec->pcm_rec;
  102. codec->num_pcms = 1;
  103. codec->pcm_info = info;
  104. info->name = "NVIDIA HDMI";
  105. info->pcm_type = HDA_PCM_TYPE_HDMI;
  106. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
  107. return 0;
  108. }
  109. static void nvhdmi_free(struct hda_codec *codec)
  110. {
  111. kfree(codec->spec);
  112. }
  113. static struct hda_codec_ops nvhdmi_patch_ops = {
  114. .build_controls = nvhdmi_build_controls,
  115. .build_pcms = nvhdmi_build_pcms,
  116. .init = nvhdmi_init,
  117. .free = nvhdmi_free,
  118. };
  119. static int patch_nvhdmi(struct hda_codec *codec)
  120. {
  121. struct nvhdmi_spec *spec;
  122. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  123. if (spec == NULL)
  124. return -ENOMEM;
  125. codec->spec = spec;
  126. spec->multiout.num_dacs = 0; /* no analog */
  127. spec->multiout.max_channels = 2;
  128. spec->multiout.dig_out_nid = 0x4; /* NID for copying analog to digital,
  129. * seems to be unused in pure-digital
  130. * case. */
  131. codec->patch_ops = nvhdmi_patch_ops;
  132. return 0;
  133. }
  134. /*
  135. * patch entries
  136. */
  137. struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
  138. { .id = 0x10de0002, .name = "NVIDIA MCP78 HDMI", .patch = patch_nvhdmi },
  139. { .id = 0x10de0007, .name = "NVIDIA MCP7A HDMI", .patch = patch_nvhdmi },
  140. {} /* terminator */
  141. };