patch_atihdmi.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for ATI HDMI codecs
  5. *
  6. * Copyright (c) 2006 ATI Technologies Inc.
  7. *
  8. *
  9. * This driver is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This driver is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. #include "hda_patch.h"
  30. struct atihdmi_spec {
  31. struct hda_multi_out multiout;
  32. struct hda_pcm pcm_rec;
  33. };
  34. static struct hda_verb atihdmi_basic_init[] = {
  35. /* enable digital output on pin widget */
  36. { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  37. {} /* terminator */
  38. };
  39. /*
  40. * Controls
  41. */
  42. static int atihdmi_build_controls(struct hda_codec *codec)
  43. {
  44. struct atihdmi_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 atihdmi_init(struct hda_codec *codec)
  52. {
  53. snd_hda_sequence_write(codec, atihdmi_basic_init);
  54. /* SI codec requires to unmute the pin */
  55. if (get_wcaps(codec, 0x03) & AC_WCAP_OUT_AMP)
  56. snd_hda_codec_write(codec, 0x03, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  57. AMP_OUT_UNMUTE);
  58. return 0;
  59. }
  60. /*
  61. * Digital out
  62. */
  63. static int atihdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  64. struct hda_codec *codec,
  65. struct snd_pcm_substream *substream)
  66. {
  67. struct atihdmi_spec *spec = codec->spec;
  68. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  69. }
  70. static int atihdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  71. struct hda_codec *codec,
  72. struct snd_pcm_substream *substream)
  73. {
  74. struct atihdmi_spec *spec = codec->spec;
  75. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  76. }
  77. static int atihdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  78. struct hda_codec *codec,
  79. unsigned int stream_tag,
  80. unsigned int format,
  81. struct snd_pcm_substream *substream)
  82. {
  83. struct atihdmi_spec *spec = codec->spec;
  84. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  85. format, substream);
  86. }
  87. static struct hda_pcm_stream atihdmi_pcm_digital_playback = {
  88. .substreams = 1,
  89. .channels_min = 2,
  90. .channels_max = 2,
  91. .nid = 0x2, /* NID to query formats and rates and setup streams */
  92. .ops = {
  93. .open = atihdmi_dig_playback_pcm_open,
  94. .close = atihdmi_dig_playback_pcm_close,
  95. .prepare = atihdmi_dig_playback_pcm_prepare
  96. },
  97. };
  98. static int atihdmi_build_pcms(struct hda_codec *codec)
  99. {
  100. struct atihdmi_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 = "ATI HDMI";
  105. info->pcm_type = HDA_PCM_TYPE_HDMI;
  106. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
  107. return 0;
  108. }
  109. static void atihdmi_free(struct hda_codec *codec)
  110. {
  111. kfree(codec->spec);
  112. }
  113. static struct hda_codec_ops atihdmi_patch_ops = {
  114. .build_controls = atihdmi_build_controls,
  115. .build_pcms = atihdmi_build_pcms,
  116. .init = atihdmi_init,
  117. .free = atihdmi_free,
  118. };
  119. static int patch_atihdmi(struct hda_codec *codec)
  120. {
  121. struct atihdmi_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 = 0x2; /* NID for copying analog to digital,
  129. * seems to be unused in pure-digital
  130. * case. */
  131. codec->patch_ops = atihdmi_patch_ops;
  132. return 0;
  133. }
  134. /*
  135. * patch entries
  136. */
  137. struct hda_codec_preset snd_hda_preset_atihdmi[] = {
  138. { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
  139. { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
  140. { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
  141. { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi },
  142. { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi },
  143. { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi },
  144. {} /* terminator */
  145. };