patch_intelhdmi.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. *
  3. * patch_intelhdmi.c - Patch for Intel HDMI codecs
  4. *
  5. * Copyright(c) 2008 Intel Corporation. All rights reserved.
  6. *
  7. * Authors:
  8. * Jiang Zhe <zhe.jiang@intel.com>
  9. * Wu Fengguang <wfg@linux.intel.com>
  10. *
  11. * Maintained by:
  12. * Wu Fengguang <wfg@linux.intel.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the Free
  16. * Software Foundation; either version 2 of the License, or (at your option)
  17. * any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful, but
  20. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  21. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  22. * for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software Foundation,
  26. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. */
  28. #include <linux/init.h>
  29. #include <linux/delay.h>
  30. #include <linux/slab.h>
  31. #include <sound/core.h>
  32. #include "hda_codec.h"
  33. #include "hda_local.h"
  34. /*
  35. * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
  36. * could support two independent pipes, each of them can be connected to one or
  37. * more ports (DVI, HDMI or DisplayPort).
  38. *
  39. * The HDA correspondence of pipes/ports are converter/pin nodes.
  40. */
  41. #define MAX_HDMI_CVTS 3
  42. #define MAX_HDMI_PINS 3
  43. #include "patch_hdmi.c"
  44. static char *intel_hdmi_pcm_names[MAX_HDMI_CVTS] = {
  45. "INTEL HDMI 0",
  46. "INTEL HDMI 1",
  47. "INTEL HDMI 2",
  48. };
  49. /*
  50. * HDMI callbacks
  51. */
  52. static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  53. struct hda_codec *codec,
  54. unsigned int stream_tag,
  55. unsigned int format,
  56. struct snd_pcm_substream *substream)
  57. {
  58. hdmi_set_channel_count(codec, hinfo->nid,
  59. substream->runtime->channels);
  60. hdmi_setup_audio_infoframe(codec, hinfo->nid, substream);
  61. return hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
  62. }
  63. static struct hda_pcm_stream intel_hdmi_pcm_playback = {
  64. .substreams = 1,
  65. .channels_min = 2,
  66. .ops = {
  67. .open = hdmi_pcm_open,
  68. .prepare = intel_hdmi_playback_pcm_prepare,
  69. },
  70. };
  71. static int intel_hdmi_build_pcms(struct hda_codec *codec)
  72. {
  73. struct hdmi_spec *spec = codec->spec;
  74. struct hda_pcm *info = spec->pcm_rec;
  75. int i;
  76. codec->num_pcms = spec->num_cvts;
  77. codec->pcm_info = info;
  78. for (i = 0; i < codec->num_pcms; i++, info++) {
  79. unsigned int chans;
  80. chans = get_wcaps(codec, spec->cvt[i]);
  81. chans = get_wcaps_channels(chans);
  82. info->name = intel_hdmi_pcm_names[i];
  83. info->pcm_type = HDA_PCM_TYPE_HDMI;
  84. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  85. intel_hdmi_pcm_playback;
  86. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i];
  87. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
  88. }
  89. return 0;
  90. }
  91. static int intel_hdmi_build_controls(struct hda_codec *codec)
  92. {
  93. struct hdmi_spec *spec = codec->spec;
  94. int err;
  95. int i;
  96. for (i = 0; i < codec->num_pcms; i++) {
  97. err = snd_hda_create_spdif_out_ctls(codec, spec->cvt[i]);
  98. if (err < 0)
  99. return err;
  100. }
  101. return 0;
  102. }
  103. static int intel_hdmi_init(struct hda_codec *codec)
  104. {
  105. struct hdmi_spec *spec = codec->spec;
  106. int i;
  107. for (i = 0; spec->pin[i]; i++) {
  108. hdmi_enable_output(codec, spec->pin[i]);
  109. snd_hda_codec_write(codec, spec->pin[i], 0,
  110. AC_VERB_SET_UNSOLICITED_ENABLE,
  111. AC_USRSP_EN | spec->pin[i]);
  112. }
  113. return 0;
  114. }
  115. static void intel_hdmi_free(struct hda_codec *codec)
  116. {
  117. struct hdmi_spec *spec = codec->spec;
  118. int i;
  119. for (i = 0; i < spec->num_pins; i++)
  120. snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
  121. kfree(spec);
  122. }
  123. static struct hda_codec_ops intel_hdmi_patch_ops = {
  124. .init = intel_hdmi_init,
  125. .free = intel_hdmi_free,
  126. .build_pcms = intel_hdmi_build_pcms,
  127. .build_controls = intel_hdmi_build_controls,
  128. .unsol_event = hdmi_unsol_event,
  129. };
  130. static int patch_intel_hdmi(struct hda_codec *codec)
  131. {
  132. struct hdmi_spec *spec;
  133. int i;
  134. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  135. if (spec == NULL)
  136. return -ENOMEM;
  137. codec->spec = spec;
  138. if (hdmi_parse_codec(codec) < 0) {
  139. codec->spec = NULL;
  140. kfree(spec);
  141. return -EINVAL;
  142. }
  143. codec->patch_ops = intel_hdmi_patch_ops;
  144. for (i = 0; i < spec->num_pins; i++)
  145. snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
  146. init_channel_allocations();
  147. return 0;
  148. }
  149. static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
  150. { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_intel_hdmi },
  151. { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_intel_hdmi },
  152. { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_intel_hdmi },
  153. { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_intel_hdmi },
  154. { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_intel_hdmi },
  155. { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_intel_hdmi },
  156. { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_intel_hdmi },
  157. { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
  158. {} /* terminator */
  159. };
  160. MODULE_ALIAS("snd-hda-codec-id:808629fb");
  161. MODULE_ALIAS("snd-hda-codec-id:80862801");
  162. MODULE_ALIAS("snd-hda-codec-id:80862802");
  163. MODULE_ALIAS("snd-hda-codec-id:80862803");
  164. MODULE_ALIAS("snd-hda-codec-id:80862804");
  165. MODULE_ALIAS("snd-hda-codec-id:80862805");
  166. MODULE_ALIAS("snd-hda-codec-id:80860054");
  167. MODULE_ALIAS("snd-hda-codec-id:10951392");
  168. MODULE_LICENSE("GPL");
  169. MODULE_DESCRIPTION("Intel HDMI HD-audio codec");
  170. static struct hda_codec_preset_list intel_list = {
  171. .preset = snd_hda_preset_intelhdmi,
  172. .owner = THIS_MODULE,
  173. };
  174. static int __init patch_intelhdmi_init(void)
  175. {
  176. return snd_hda_add_codec_preset(&intel_list);
  177. }
  178. static void __exit patch_intelhdmi_exit(void)
  179. {
  180. snd_hda_delete_codec_preset(&intel_list);
  181. }
  182. module_init(patch_intelhdmi_init)
  183. module_exit(patch_intelhdmi_exit)