patch_atihdmi.c 5.9 KB

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