patch_intelhdmi.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
  62. return 0;
  63. }
  64. static int intel_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  65. struct hda_codec *codec,
  66. struct snd_pcm_substream *substream)
  67. {
  68. return 0;
  69. }
  70. static struct hda_pcm_stream intel_hdmi_pcm_playback = {
  71. .substreams = 1,
  72. .channels_min = 2,
  73. .ops = {
  74. .prepare = intel_hdmi_playback_pcm_prepare,
  75. .cleanup = intel_hdmi_playback_pcm_cleanup,
  76. },
  77. };
  78. static int intel_hdmi_build_pcms(struct hda_codec *codec)
  79. {
  80. struct hdmi_spec *spec = codec->spec;
  81. struct hda_pcm *info = spec->pcm_rec;
  82. int i;
  83. codec->num_pcms = spec->num_cvts;
  84. codec->pcm_info = info;
  85. for (i = 0; i < codec->num_pcms; i++, info++) {
  86. unsigned int chans;
  87. chans = get_wcaps(codec, spec->cvt[i]);
  88. chans = get_wcaps_channels(chans);
  89. info->name = intel_hdmi_pcm_names[i];
  90. info->pcm_type = HDA_PCM_TYPE_HDMI;
  91. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  92. intel_hdmi_pcm_playback;
  93. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i];
  94. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
  95. }
  96. return 0;
  97. }
  98. static int intel_hdmi_build_controls(struct hda_codec *codec)
  99. {
  100. struct hdmi_spec *spec = codec->spec;
  101. int err;
  102. int i;
  103. for (i = 0; i < codec->num_pcms; i++) {
  104. err = snd_hda_create_spdif_out_ctls(codec, spec->cvt[i]);
  105. if (err < 0)
  106. return err;
  107. }
  108. return 0;
  109. }
  110. static int intel_hdmi_init(struct hda_codec *codec)
  111. {
  112. struct hdmi_spec *spec = codec->spec;
  113. int i;
  114. for (i = 0; spec->pin[i]; i++) {
  115. hdmi_enable_output(codec, spec->pin[i]);
  116. snd_hda_codec_write(codec, spec->pin[i], 0,
  117. AC_VERB_SET_UNSOLICITED_ENABLE,
  118. AC_USRSP_EN | spec->pin[i]);
  119. }
  120. return 0;
  121. }
  122. static void intel_hdmi_free(struct hda_codec *codec)
  123. {
  124. struct hdmi_spec *spec = codec->spec;
  125. int i;
  126. for (i = 0; i < spec->num_pins; i++)
  127. snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
  128. kfree(spec);
  129. }
  130. static struct hda_codec_ops intel_hdmi_patch_ops = {
  131. .init = intel_hdmi_init,
  132. .free = intel_hdmi_free,
  133. .build_pcms = intel_hdmi_build_pcms,
  134. .build_controls = intel_hdmi_build_controls,
  135. .unsol_event = hdmi_unsol_event,
  136. };
  137. static int patch_intel_hdmi(struct hda_codec *codec)
  138. {
  139. struct hdmi_spec *spec;
  140. int i;
  141. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  142. if (spec == NULL)
  143. return -ENOMEM;
  144. codec->spec = spec;
  145. if (hdmi_parse_codec(codec) < 0) {
  146. codec->spec = NULL;
  147. kfree(spec);
  148. return -EINVAL;
  149. }
  150. codec->patch_ops = intel_hdmi_patch_ops;
  151. for (i = 0; i < spec->num_pins; i++)
  152. snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
  153. init_channel_allocations();
  154. return 0;
  155. }
  156. static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
  157. { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_intel_hdmi },
  158. { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_intel_hdmi },
  159. { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_intel_hdmi },
  160. { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_intel_hdmi },
  161. { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_intel_hdmi },
  162. { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_intel_hdmi },
  163. { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_intel_hdmi },
  164. { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
  165. {} /* terminator */
  166. };
  167. MODULE_ALIAS("snd-hda-codec-id:808629fb");
  168. MODULE_ALIAS("snd-hda-codec-id:80862801");
  169. MODULE_ALIAS("snd-hda-codec-id:80862802");
  170. MODULE_ALIAS("snd-hda-codec-id:80862803");
  171. MODULE_ALIAS("snd-hda-codec-id:80862804");
  172. MODULE_ALIAS("snd-hda-codec-id:80862805");
  173. MODULE_ALIAS("snd-hda-codec-id:80860054");
  174. MODULE_ALIAS("snd-hda-codec-id:10951392");
  175. MODULE_LICENSE("GPL");
  176. MODULE_DESCRIPTION("Intel HDMI HD-audio codec");
  177. static struct hda_codec_preset_list intel_list = {
  178. .preset = snd_hda_preset_intelhdmi,
  179. .owner = THIS_MODULE,
  180. };
  181. static int __init patch_intelhdmi_init(void)
  182. {
  183. return snd_hda_add_codec_preset(&intel_list);
  184. }
  185. static void __exit patch_intelhdmi_exit(void)
  186. {
  187. snd_hda_delete_codec_preset(&intel_list);
  188. }
  189. module_init(patch_intelhdmi_init)
  190. module_exit(patch_intelhdmi_exit)