patch_atihdmi.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. #define CVT_NID 0x02 /* audio converter */
  35. #define PIN_NID 0x03 /* HDMI output pin */
  36. static struct hda_verb atihdmi_basic_init[] = {
  37. /* enable digital output on pin widget */
  38. { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  39. {} /* terminator */
  40. };
  41. /*
  42. * Controls
  43. */
  44. static int atihdmi_build_controls(struct hda_codec *codec)
  45. {
  46. struct atihdmi_spec *spec = codec->spec;
  47. int err;
  48. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  49. if (err < 0)
  50. return err;
  51. return 0;
  52. }
  53. static int atihdmi_init(struct hda_codec *codec)
  54. {
  55. snd_hda_sequence_write(codec, atihdmi_basic_init);
  56. /* SI codec requires to unmute the pin */
  57. if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP)
  58. snd_hda_codec_write(codec, PIN_NID, 0,
  59. AC_VERB_SET_AMP_GAIN_MUTE,
  60. AMP_OUT_UNMUTE);
  61. return 0;
  62. }
  63. /*
  64. * Digital out
  65. */
  66. static int atihdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  67. struct hda_codec *codec,
  68. struct snd_pcm_substream *substream)
  69. {
  70. struct atihdmi_spec *spec = codec->spec;
  71. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  72. }
  73. static int atihdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  74. struct hda_codec *codec,
  75. struct snd_pcm_substream *substream)
  76. {
  77. struct atihdmi_spec *spec = codec->spec;
  78. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  79. }
  80. static int atihdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  81. struct hda_codec *codec,
  82. unsigned int stream_tag,
  83. unsigned int format,
  84. struct snd_pcm_substream *substream)
  85. {
  86. struct atihdmi_spec *spec = codec->spec;
  87. int chans = substream->runtime->channels;
  88. int i, err;
  89. err = snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  90. format, substream);
  91. if (err < 0)
  92. return err;
  93. snd_hda_codec_write(codec, CVT_NID, 0, AC_VERB_SET_CVT_CHAN_COUNT,
  94. chans - 1);
  95. /* FIXME: XXX */
  96. for (i = 0; i < chans; i++) {
  97. snd_hda_codec_write(codec, CVT_NID, 0,
  98. AC_VERB_SET_HDMI_CHAN_SLOT,
  99. (i << 4) | i);
  100. }
  101. return 0;
  102. }
  103. static struct hda_pcm_stream atihdmi_pcm_digital_playback = {
  104. .substreams = 1,
  105. .channels_min = 2,
  106. .channels_max = 2,
  107. .nid = CVT_NID, /* NID to query formats and rates and setup streams */
  108. .ops = {
  109. .open = atihdmi_dig_playback_pcm_open,
  110. .close = atihdmi_dig_playback_pcm_close,
  111. .prepare = atihdmi_dig_playback_pcm_prepare
  112. },
  113. };
  114. static int atihdmi_build_pcms(struct hda_codec *codec)
  115. {
  116. struct atihdmi_spec *spec = codec->spec;
  117. struct hda_pcm *info = &spec->pcm_rec;
  118. unsigned int chans;
  119. codec->num_pcms = 1;
  120. codec->pcm_info = info;
  121. info->name = "ATI HDMI";
  122. info->pcm_type = HDA_PCM_TYPE_HDMI;
  123. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
  124. /* FIXME: we must check ELD and change the PCM parameters dynamically
  125. */
  126. chans = get_wcaps(codec, CVT_NID);
  127. chans = (chans & AC_WCAP_CHAN_CNT_EXT) >> 13;
  128. chans = ((chans << 1) | 1) + 1;
  129. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
  130. return 0;
  131. }
  132. static void atihdmi_free(struct hda_codec *codec)
  133. {
  134. kfree(codec->spec);
  135. }
  136. static struct hda_codec_ops atihdmi_patch_ops = {
  137. .build_controls = atihdmi_build_controls,
  138. .build_pcms = atihdmi_build_pcms,
  139. .init = atihdmi_init,
  140. .free = atihdmi_free,
  141. };
  142. static int patch_atihdmi(struct hda_codec *codec)
  143. {
  144. struct atihdmi_spec *spec;
  145. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  146. if (spec == NULL)
  147. return -ENOMEM;
  148. codec->spec = spec;
  149. spec->multiout.num_dacs = 0; /* no analog */
  150. spec->multiout.max_channels = 2;
  151. /* NID for copying analog to digital,
  152. * seems to be unused in pure-digital
  153. * case.
  154. */
  155. spec->multiout.dig_out_nid = CVT_NID;
  156. codec->patch_ops = atihdmi_patch_ops;
  157. return 0;
  158. }
  159. /*
  160. * patch entries
  161. */
  162. struct hda_codec_preset snd_hda_preset_atihdmi[] = {
  163. { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
  164. { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
  165. { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
  166. { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi },
  167. { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_atihdmi },
  168. { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi },
  169. { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi },
  170. {} /* terminator */
  171. };